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; |
Chinmay Dhodapkar | 66262c4 | 2023-03-10 15:47:41 -0800 | [diff] [blame] | 54 | import android.os.DropBoxManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 55 | import android.os.Handler; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 56 | import android.os.IBinder; |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 57 | import android.os.ICancellationSignal; |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 58 | import android.os.LocaleList; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 59 | import android.os.Looper; |
| 60 | import android.os.Message; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 61 | import android.os.Messenger; |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 62 | import android.os.ParcelFileDescriptor; |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 63 | import android.os.ParcelUuid; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 64 | import android.os.PersistableBundle; |
Shuo Qian | cd19c46 | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 65 | import android.os.Process; |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 66 | import android.os.RemoteException; |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 67 | import android.os.ResultReceiver; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 68 | import android.os.ServiceSpecificException; |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 69 | import android.os.SystemClock; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 70 | import android.os.UserHandle; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 71 | import android.os.UserManager; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 72 | import android.os.WorkSource; |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 73 | import android.preference.PreferenceManager; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 74 | import android.provider.DeviceConfig; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 75 | import android.provider.Settings; |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 76 | import android.provider.Telephony; |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 77 | import android.service.carrier.CarrierIdentifier; |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 78 | import android.sysprop.TelephonyProperties; |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 79 | import android.telecom.PhoneAccount; |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 80 | import android.telecom.PhoneAccountHandle; |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 81 | import android.telecom.TelecomManager; |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 82 | import android.telephony.AccessNetworkConstants; |
| 83 | import android.telephony.ActivityStatsTechSpecificInfo; |
Chen Xu | 227e06f | 2019-09-26 22:48:11 -0700 | [diff] [blame] | 84 | import android.telephony.Annotation.ApnType; |
Jack Yu | 0eda684 | 2022-04-18 00:34:46 -0700 | [diff] [blame] | 85 | import android.telephony.Annotation.DataActivityType; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 86 | import android.telephony.Annotation.ThermalMitigationResult; |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 87 | import android.telephony.AnomalyReporter; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 88 | import android.telephony.CallForwardingInfo; |
Junda Liu | 12f7d80 | 2015-05-01 12:06:44 -0700 | [diff] [blame] | 89 | import android.telephony.CarrierConfigManager; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 90 | import android.telephony.CarrierRestrictionRules; |
Hui Wang | 9b5793a | 2022-12-05 14:38:06 -0600 | [diff] [blame] | 91 | import android.telephony.CellBroadcastIdRange; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 92 | import android.telephony.CellIdentity; |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 93 | import android.telephony.CellIdentityCdma; |
| 94 | import android.telephony.CellIdentityGsm; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 95 | import android.telephony.CellInfo; |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 96 | import android.telephony.CellInfoGsm; |
| 97 | import android.telephony.CellInfoWcdma; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 98 | import android.telephony.ClientRequestStats; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 99 | import android.telephony.DataThrottlingRequest; |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 100 | import android.telephony.IBootstrapAuthenticationCallback; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 101 | import android.telephony.ICellInfoCallback; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 102 | import android.telephony.IccOpenLogicalChannelResponse; |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 103 | import android.telephony.LocationAccessPolicy; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 104 | import android.telephony.ModemActivityInfo; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 105 | import android.telephony.NeighboringCellInfo; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 106 | import android.telephony.NetworkScanRequest; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 107 | import android.telephony.PhoneCapability; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 108 | import android.telephony.PhoneNumberRange; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 109 | import android.telephony.RadioAccessFamily; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 110 | import android.telephony.RadioAccessSpecifier; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 111 | import android.telephony.ServiceState; |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 112 | import android.telephony.SignalStrength; |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 113 | import android.telephony.SignalStrengthUpdateRequest; |
| 114 | import android.telephony.SignalThresholdInfo; |
Wink Saville | 0f3b5fc | 2014-11-11 08:40:49 -0800 | [diff] [blame] | 115 | import android.telephony.SubscriptionInfo; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 116 | import android.telephony.SubscriptionManager; |
Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 117 | import android.telephony.TelephonyFrameworkInitializer; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 118 | import android.telephony.TelephonyHistogram; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 119 | import android.telephony.TelephonyManager; |
Jack Yu | f5badd9 | 2022-12-08 00:50:53 -0800 | [diff] [blame] | 120 | import android.telephony.TelephonyManager.SimState; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 121 | import android.telephony.TelephonyScanManager; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 122 | import android.telephony.ThermalMitigationRequest; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 123 | import android.telephony.UiccCardInfo; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 124 | import android.telephony.UiccPortInfo; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 125 | import android.telephony.UiccSlotInfo; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 126 | import android.telephony.UiccSlotMapping; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 127 | import android.telephony.UssdResponse; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 128 | import android.telephony.VisualVoicemailSmsFilterSettings; |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 129 | import android.telephony.data.NetworkSlicingConfig; |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 130 | import android.telephony.emergency.EmergencyNumber; |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 131 | import android.telephony.gba.GbaAuthRequest; |
| 132 | import android.telephony.gba.UaSecurityProtocolIdentifier; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 133 | import android.telephony.ims.ImsException; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 134 | import android.telephony.ims.ProvisioningManager; |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 135 | import android.telephony.ims.RcsClientConfiguration; |
Brad Ebinger | 14d467f | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 136 | import android.telephony.ims.RcsContactUceCapability; |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 137 | import android.telephony.ims.RegistrationManager; |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 138 | import android.telephony.ims.aidl.IFeatureProvisioningCallback; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 139 | import android.telephony.ims.aidl.IImsCapabilityCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 140 | import android.telephony.ims.aidl.IImsConfig; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 141 | import android.telephony.ims.aidl.IImsConfigCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 142 | import android.telephony.ims.aidl.IImsRegistration; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 143 | import android.telephony.ims.aidl.IImsRegistrationCallback; |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 144 | import android.telephony.ims.aidl.IRcsConfigCallback; |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 145 | import android.telephony.ims.feature.ImsFeature; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 146 | import android.telephony.ims.stub.ImsConfigImplBase; |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 147 | import android.telephony.ims.stub.ImsRegistrationImplBase; |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 148 | import android.telephony.satellite.ISatelliteDatagramCallback; |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 149 | import android.telephony.satellite.ISatelliteProvisionStateCallback; |
| 150 | import android.telephony.satellite.ISatelliteStateCallback; |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 151 | import android.telephony.satellite.ISatelliteTransmissionUpdateCallback; |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 152 | import android.telephony.satellite.SatelliteCapabilities; |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 153 | import android.telephony.satellite.SatelliteDatagram; |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 154 | import android.telephony.satellite.SatelliteDatagramCallback; |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 155 | import android.telephony.satellite.SatelliteManager; |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 156 | import android.telephony.satellite.SatelliteProvisionStateCallback; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 157 | import android.text.TextUtils; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 158 | import android.util.ArraySet; |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 159 | import android.util.EventLog; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 160 | import android.util.Log; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 161 | import android.util.Pair; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 162 | |
Andrew Lee | 312e817 | 2014-10-23 17:01:36 -0700 | [diff] [blame] | 163 | import com.android.ims.ImsManager; |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 164 | import com.android.ims.internal.IImsServiceFeatureCallback; |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 165 | import com.android.ims.rcs.uce.eab.EabUtil; |
SongFerngWang | fd89b10 | 2021-05-27 22:44:54 +0800 | [diff] [blame] | 166 | import com.android.internal.annotations.VisibleForTesting; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 167 | import com.android.internal.telephony.CallForwardInfo; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 168 | import com.android.internal.telephony.CallManager; |
Tyler Gunn | 52dcf77 | 2017-04-26 11:30:31 -0700 | [diff] [blame] | 169 | import com.android.internal.telephony.CallStateException; |
Tyler Gunn | d433926 | 2021-05-03 14:46:49 -0700 | [diff] [blame] | 170 | import com.android.internal.telephony.CallTracker; |
Rambo Wang | 9c9ffdd | 2022-01-13 21:51:44 -0800 | [diff] [blame] | 171 | import com.android.internal.telephony.CarrierPrivilegesTracker; |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 172 | import com.android.internal.telephony.CarrierResolver; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 173 | import com.android.internal.telephony.CellNetworkScanResult; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 174 | import com.android.internal.telephony.CommandException; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 175 | import com.android.internal.telephony.CommandsInterface; |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 176 | import com.android.internal.telephony.GbaManager; |
Shuo Qian | ccbaf74 | 2021-02-22 18:32:21 -0800 | [diff] [blame] | 177 | import com.android.internal.telephony.GsmCdmaPhone; |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 178 | import com.android.internal.telephony.HalVersion; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 179 | import com.android.internal.telephony.IBooleanConsumer; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 180 | import com.android.internal.telephony.ICallForwardingInfoCallback; |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 181 | import com.android.internal.telephony.IImsStateCallback; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 182 | import com.android.internal.telephony.IIntegerConsumer; |
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; |
Peter Wang | 59571be | 2020-01-27 12:35:15 +0800 | [diff] [blame] | 204 | import com.android.internal.telephony.TelephonyIntents; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 205 | import com.android.internal.telephony.TelephonyPermissions; |
Jack Yu | 27422a5 | 2022-03-21 10:38:05 -0700 | [diff] [blame] | 206 | import com.android.internal.telephony.data.DataUtils; |
Hunsuk Choi | 42cc62a | 2022-10-16 06:03:40 +0000 | [diff] [blame] | 207 | import com.android.internal.telephony.domainselection.DomainSelectionResolver; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 208 | import com.android.internal.telephony.emergency.EmergencyNumberTracker; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 209 | import com.android.internal.telephony.euicc.EuiccConnector; |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 210 | import com.android.internal.telephony.ims.ImsResolver; |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 211 | import com.android.internal.telephony.imsphone.ImsPhone; |
| 212 | import com.android.internal.telephony.imsphone.ImsPhoneCallTracker; |
joonhunshin | 3e15424 | 2021-09-17 06:33:39 +0000 | [diff] [blame] | 213 | import com.android.internal.telephony.metrics.RcsStats; |
Pengquan Meng | 6c2dc9f | 2019-02-06 11:12:53 -0800 | [diff] [blame] | 214 | import com.android.internal.telephony.metrics.TelephonyMetrics; |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 215 | import com.android.internal.telephony.satellite.SatelliteController; |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 216 | import com.android.internal.telephony.subscription.SubscriptionInfoInternal; |
| 217 | import com.android.internal.telephony.subscription.SubscriptionManagerService; |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 218 | import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 219 | import com.android.internal.telephony.uicc.IccIoResult; |
| 220 | import com.android.internal.telephony.uicc.IccUtils; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 221 | import com.android.internal.telephony.uicc.SIMRecords; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 222 | import com.android.internal.telephony.uicc.UiccCard; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 223 | import com.android.internal.telephony.uicc.UiccCardApplication; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 224 | import com.android.internal.telephony.uicc.UiccController; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 225 | import com.android.internal.telephony.uicc.UiccPort; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 226 | import com.android.internal.telephony.uicc.UiccProfile; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 227 | import com.android.internal.telephony.uicc.UiccSlot; |
zoey chen | c730df8 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 228 | import com.android.internal.telephony.util.LocaleUtils; |
Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame] | 229 | import com.android.internal.telephony.util.TelephonyUtils; |
fionaxu | 7ed723d | 2017-05-30 18:58:54 -0700 | [diff] [blame] | 230 | import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 231 | import com.android.internal.util.FunctionalUtils; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 232 | import com.android.internal.util.HexDump; |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 233 | import com.android.phone.callcomposer.CallComposerPictureManager; |
| 234 | import com.android.phone.callcomposer.CallComposerPictureTransfer; |
| 235 | import com.android.phone.callcomposer.ImageData; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 236 | import com.android.phone.settings.PickSmsSubscriptionActivity; |
Sarah Chin | 46355ba | 2022-11-01 23:51:16 -0700 | [diff] [blame] | 237 | import com.android.phone.slice.SlicePurchaseController; |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 238 | import com.android.phone.utils.CarrierAllowListInfo; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 239 | import com.android.phone.vvm.PhoneAccountHandleConverter; |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 240 | import com.android.phone.vvm.RemoteVvmTaskManager; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 241 | import com.android.phone.vvm.VisualVoicemailSettingsUtil; |
Ta-wei Yen | c890531 | 2017-03-28 11:14:45 -0700 | [diff] [blame] | 242 | import com.android.phone.vvm.VisualVoicemailSmsFilterConfig; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 243 | import com.android.services.telephony.TelecomAccountRegistry; |
| 244 | import com.android.services.telephony.TelephonyConnectionService; |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 245 | import com.android.telephony.Rlog; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 246 | |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 247 | import java.io.ByteArrayOutputStream; |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 248 | import java.io.FileDescriptor; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 249 | import java.io.IOException; |
| 250 | import java.io.InputStream; |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 251 | import java.io.PrintWriter; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 252 | import java.util.ArrayList; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 253 | import java.util.Arrays; |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 254 | import java.util.Collection; |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 255 | import java.util.Collections; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 256 | import java.util.HashMap; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 257 | import java.util.HashSet; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 258 | import java.util.List; |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 259 | import java.util.Locale; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 260 | import java.util.Map; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 261 | import java.util.NoSuchElementException; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 262 | import java.util.Objects; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 263 | import java.util.Set; |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 264 | import java.util.UUID; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 265 | import java.util.concurrent.Executors; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 266 | import java.util.concurrent.atomic.AtomicBoolean; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 267 | import java.util.function.Consumer; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 268 | |
| 269 | /** |
| 270 | * Implementation of the ITelephony interface. |
| 271 | */ |
Santos Cordon | 117fee7 | 2014-05-16 17:56:12 -0700 | [diff] [blame] | 272 | public class PhoneInterfaceManager extends ITelephony.Stub { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 273 | private static final String LOG_TAG = "PhoneInterfaceManager"; |
| 274 | private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2); |
| 275 | private static final boolean DBG_LOC = false; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 276 | private static final boolean DBG_MERGE = false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 277 | |
| 278 | // Message codes used with mMainThreadHandler |
| 279 | private static final int CMD_HANDLE_PIN_MMI = 1; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 280 | private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7; |
| 281 | private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 282 | private static final int CMD_OPEN_CHANNEL = 9; |
| 283 | private static final int EVENT_OPEN_CHANNEL_DONE = 10; |
| 284 | private static final int CMD_CLOSE_CHANNEL = 11; |
| 285 | private static final int EVENT_CLOSE_CHANNEL_DONE = 12; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 286 | private static final int CMD_NV_READ_ITEM = 13; |
| 287 | private static final int EVENT_NV_READ_ITEM_DONE = 14; |
| 288 | private static final int CMD_NV_WRITE_ITEM = 15; |
| 289 | private static final int EVENT_NV_WRITE_ITEM_DONE = 16; |
| 290 | private static final int CMD_NV_WRITE_CDMA_PRL = 17; |
| 291 | private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 292 | private static final int CMD_RESET_MODEM_CONFIG = 19; |
| 293 | private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 294 | private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21; |
| 295 | private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22; |
Sailesh Nepal | 35b5945 | 2014-03-06 09:26:56 -0800 | [diff] [blame] | 296 | private static final int CMD_SEND_ENVELOPE = 25; |
| 297 | private static final int EVENT_SEND_ENVELOPE_DONE = 26; |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 298 | private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27; |
| 299 | private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28; |
Derek Tan | 6b088ee | 2014-09-05 14:15:18 -0700 | [diff] [blame] | 300 | private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29; |
| 301 | private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30; |
| 302 | private static final int CMD_EXCHANGE_SIM_IO = 31; |
| 303 | private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 304 | private static final int CMD_SET_VOICEMAIL_NUMBER = 33; |
| 305 | private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 306 | private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35; |
| 307 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 308 | private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37; |
| 309 | private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 310 | private static final int CMD_PERFORM_NETWORK_SCAN = 39; |
| 311 | private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40; |
| 312 | private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41; |
| 313 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 314 | private static final int CMD_SET_ALLOWED_CARRIERS = 43; |
| 315 | private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44; |
| 316 | private static final int CMD_GET_ALLOWED_CARRIERS = 45; |
| 317 | private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 318 | private static final int CMD_HANDLE_USSD_REQUEST = 47; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 319 | private static final int CMD_GET_FORBIDDEN_PLMNS = 48; |
| 320 | private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 321 | private static final int CMD_SWITCH_SLOTS = 50; |
| 322 | private static final int EVENT_SWITCH_SLOTS_DONE = 51; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 323 | private static final int CMD_GET_NETWORK_SELECTION_MODE = 52; |
| 324 | private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53; |
| 325 | private static final int CMD_GET_CDMA_ROAMING_MODE = 54; |
| 326 | private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55; |
| 327 | private static final int CMD_SET_CDMA_ROAMING_MODE = 56; |
| 328 | private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57; |
| 329 | private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58; |
| 330 | private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 331 | private static final int CMD_GET_ALL_CELL_INFO = 60; |
| 332 | private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61; |
| 333 | private static final int CMD_GET_CELL_LOCATION = 62; |
| 334 | private static final int EVENT_GET_CELL_LOCATION_DONE = 63; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 335 | private static final int CMD_MODEM_REBOOT = 64; |
| 336 | private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 337 | private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66; |
| 338 | private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 339 | private static final int CMD_REQUEST_ENABLE_MODEM = 68; |
| 340 | private static final int EVENT_ENABLE_MODEM_DONE = 69; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 341 | private static final int CMD_GET_MODEM_STATUS = 70; |
| 342 | private static final int EVENT_GET_MODEM_STATUS_DONE = 71; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 343 | private static final int CMD_SET_FORBIDDEN_PLMNS = 72; |
| 344 | private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 345 | private static final int CMD_ERASE_MODEM_CONFIG = 74; |
| 346 | private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75; |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 347 | private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76; |
| 348 | private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77; |
| 349 | private static final int CMD_SET_ICC_LOCK_ENABLED = 78; |
| 350 | private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 351 | private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80; |
| 352 | private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 353 | private static final int MSG_NOTIFY_USER_ACTIVITY = 82; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 354 | private static final int CMD_GET_CALL_FORWARDING = 83; |
| 355 | private static final int EVENT_GET_CALL_FORWARDING_DONE = 84; |
| 356 | private static final int CMD_SET_CALL_FORWARDING = 85; |
| 357 | private static final int EVENT_SET_CALL_FORWARDING_DONE = 86; |
| 358 | private static final int CMD_GET_CALL_WAITING = 87; |
| 359 | private static final int EVENT_GET_CALL_WAITING_DONE = 88; |
| 360 | private static final int CMD_SET_CALL_WAITING = 89; |
| 361 | private static final int EVENT_SET_CALL_WAITING_DONE = 90; |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 362 | private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91; |
| 363 | private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92; |
| 364 | private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93; |
| 365 | private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 366 | private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95; |
| 367 | private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 368 | private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97; |
| 369 | private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 370 | private static final int CMD_SET_DATA_THROTTLING = 99; |
| 371 | private static final int EVENT_SET_DATA_THROTTLING_DONE = 100; |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 372 | private static final int CMD_SET_SIM_POWER = 101; |
| 373 | private static final int EVENT_SET_SIM_POWER_DONE = 102; |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 374 | private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103; |
| 375 | private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104; |
| 376 | private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105; |
| 377 | private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 378 | private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107; |
| 379 | 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] | 380 | private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 381 | private static final int CMD_GET_SLICING_CONFIG = 110; |
| 382 | private static final int EVENT_GET_SLICING_CONFIG_DONE = 111; |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 383 | private static final int CMD_ERASE_DATA_SHARED_PREFERENCES = 112; |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 384 | private static final int CMD_ENABLE_VONR = 113; |
| 385 | private static final int EVENT_ENABLE_VONR_DONE = 114; |
| 386 | private static final int CMD_IS_VONR_ENABLED = 115; |
| 387 | private static final int EVENT_IS_VONR_ENABLED_DONE = 116; |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 388 | private static final int CMD_PURCHASE_PREMIUM_CAPABILITY = 117; |
| 389 | private static final int EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE = 118; |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 390 | |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 391 | // Parameters of select command. |
| 392 | private static final int SELECT_COMMAND = 0xA4; |
| 393 | private static final int SELECT_P1 = 0x04; |
| 394 | private static final int SELECT_P2 = 0; |
| 395 | private static final int SELECT_P3 = 0x10; |
| 396 | |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 397 | // Toggling null cipher and integrity support was added in IRadioNetwork 2.1 |
| 398 | private static final int MIN_NULL_CIPHER_AND_INTEGRITY_VERSION = 201; |
| 399 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 400 | /** The singleton instance. */ |
| 401 | private static PhoneInterfaceManager sInstance; |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 402 | private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 403 | |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 404 | private final PhoneGlobals mApp; |
| 405 | private final CallManager mCM; |
| 406 | private final ImsResolver mImsResolver; |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 407 | |
| 408 | private final SatelliteController mSatelliteController; |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 409 | private final UserManager mUserManager; |
| 410 | private final AppOpsManager mAppOps; |
| 411 | private final MainThreadHandler mMainThreadHandler; |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 412 | private final SharedPreferences mTelephonySharedPreferences; |
| 413 | private final PhoneConfigurationManager mPhoneConfigurationManager; |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 414 | private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 415 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 416 | /** User Activity */ |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 417 | private final AtomicBoolean mNotifyUserActivity; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 418 | private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200; |
| 419 | |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 420 | private final Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>(); |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 421 | |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 422 | private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_"; |
| 423 | private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_"; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 424 | private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_"; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 425 | private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_"; |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 426 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 427 | // String to store multi SIM allowed |
| 428 | private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted"; |
| 429 | |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 430 | // The AID of ISD-R. |
| 431 | private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100"; |
| 432 | |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 433 | private NetworkScanRequestTracker mNetworkScanRequestTracker; |
| 434 | |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 435 | private static final int TYPE_ALLOCATION_CODE_LENGTH = 8; |
| 436 | private static final int MANUFACTURER_CODE_LENGTH = 8; |
| 437 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 438 | private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1; |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 439 | 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] | 440 | |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 441 | private static final String PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID = |
| 442 | "24bf97a6-e8a6-44d8-a6a4-255d7548733c"; |
| 443 | |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 444 | /** |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 445 | * Experiment flag to enable erase modem config on reset network, default value is false |
| 446 | */ |
| 447 | public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED = |
| 448 | "reset_network_erase_modem_config_enabled"; |
| 449 | |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 450 | 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] | 451 | |
Gary Jian | 76280a4 | 2022-12-07 16:18:33 +0800 | [diff] [blame] | 452 | private static final int MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS = 50; |
| 453 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 454 | /** |
| 455 | * With support for MEP(multiple enabled profile) in Android T, a SIM card can have more than |
| 456 | * one ICCID active at the same time. |
| 457 | * Apps should use below API signatures if targeting SDK is T and beyond. |
| 458 | * |
| 459 | * @hide |
| 460 | */ |
| 461 | @ChangeId |
| 462 | @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU) |
| 463 | public static final long GET_API_SIGNATURES_FROM_UICC_PORT_INFO = 202110963L; |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 464 | |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 465 | /** |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 466 | * Apps targeting on Android T and beyond will get exception whenever icc close channel |
| 467 | * operation fails. |
| 468 | */ |
| 469 | @ChangeId |
| 470 | @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU) |
| 471 | public static final long ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE = 208739934L; |
| 472 | |
| 473 | /** |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 474 | * A request object to use for transmitting data to an ICC. |
| 475 | */ |
| 476 | private static final class IccAPDUArgument { |
| 477 | public int channel, cla, command, p1, p2, p3; |
| 478 | public String data; |
| 479 | |
| 480 | public IccAPDUArgument(int channel, int cla, int command, |
| 481 | int p1, int p2, int p3, String data) { |
| 482 | this.channel = channel; |
| 483 | this.cla = cla; |
| 484 | this.command = command; |
| 485 | this.p1 = p1; |
| 486 | this.p2 = p2; |
| 487 | this.p3 = p3; |
| 488 | this.data = data; |
| 489 | } |
| 490 | } |
| 491 | |
| 492 | /** |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 493 | * A request object to use for transmitting data to an ICC. |
| 494 | */ |
| 495 | private static final class ManualNetworkSelectionArgument { |
| 496 | public OperatorInfo operatorInfo; |
| 497 | public boolean persistSelection; |
| 498 | |
| 499 | public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) { |
| 500 | this.operatorInfo = operatorInfo; |
| 501 | this.persistSelection = persistSelection; |
| 502 | } |
| 503 | } |
| 504 | |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 505 | private static final class PurchasePremiumCapabilityArgument { |
| 506 | public @TelephonyManager.PremiumCapability int capability; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 507 | public @NonNull IIntegerConsumer callback; |
| 508 | |
| 509 | PurchasePremiumCapabilityArgument(@TelephonyManager.PremiumCapability int capability, |
Sarah Chin | b8218c2 | 2023-01-04 13:35:29 -0800 | [diff] [blame] | 510 | @NonNull IIntegerConsumer callback) { |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 511 | this.capability = capability; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 512 | this.callback = callback; |
| 513 | } |
| 514 | } |
| 515 | |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 516 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 517 | * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the |
| 518 | * request after sending. The main thread will notify the request when it is complete. |
| 519 | */ |
| 520 | private static final class MainThreadRequest { |
| 521 | /** The argument to use for the request */ |
| 522 | public Object argument; |
| 523 | /** The result of the request that is run on the main thread */ |
| 524 | public Object result; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 525 | // The subscriber id that this request applies to. Defaults to |
| 526 | // SubscriptionManager.INVALID_SUBSCRIPTION_ID |
| 527 | public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 528 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 529 | // In cases where subId is unavailable, the caller needs to specify the phone. |
| 530 | public Phone phone; |
| 531 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 532 | public WorkSource workSource; |
| 533 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 534 | public MainThreadRequest(Object argument) { |
| 535 | this.argument = argument; |
| 536 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 537 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 538 | MainThreadRequest(Object argument, Phone phone, WorkSource workSource) { |
| 539 | this.argument = argument; |
| 540 | if (phone != null) { |
| 541 | this.phone = phone; |
| 542 | } |
| 543 | this.workSource = workSource; |
| 544 | } |
| 545 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 546 | MainThreadRequest(Object argument, Integer subId, WorkSource workSource) { |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 547 | this.argument = argument; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 548 | if (subId != null) { |
| 549 | this.subId = subId; |
| 550 | } |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 551 | this.workSource = workSource; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 552 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 553 | } |
| 554 | |
Sailesh Nepal | cc0375f | 2013-11-13 09:15:18 -0800 | [diff] [blame] | 555 | private static final class IncomingThirdPartyCallArgs { |
| 556 | public final ComponentName component; |
| 557 | public final String callId; |
| 558 | public final String callerDisplayName; |
| 559 | |
| 560 | public IncomingThirdPartyCallArgs(ComponentName component, String callId, |
| 561 | String callerDisplayName) { |
| 562 | this.component = component; |
| 563 | this.callId = callId; |
| 564 | this.callerDisplayName = callerDisplayName; |
| 565 | } |
| 566 | } |
| 567 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 568 | /** |
| 569 | * A handler that processes messages on the main thread in the phone process. Since many |
| 570 | * of the Phone calls are not thread safe this is needed to shuttle the requests from the |
| 571 | * inbound binder threads to the main thread in the phone process. The Binder thread |
| 572 | * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting |
| 573 | * on, which will be notified when the operation completes and will contain the result of the |
| 574 | * request. |
| 575 | * |
| 576 | * <p>If a MainThreadRequest object is provided in the msg.obj field, |
| 577 | * note that request.result must be set to something non-null for the calling thread to |
| 578 | * unblock. |
| 579 | */ |
| 580 | private final class MainThreadHandler extends Handler { |
| 581 | @Override |
| 582 | public void handleMessage(Message msg) { |
| 583 | MainThreadRequest request; |
| 584 | Message onCompleted; |
| 585 | AsyncResult ar; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 586 | UiccPort uiccPort; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 587 | IccAPDUArgument iccArgument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 588 | final Phone defaultPhone = getDefaultPhone(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 589 | |
| 590 | switch (msg.what) { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 591 | case CMD_HANDLE_USSD_REQUEST: { |
| 592 | request = (MainThreadRequest) msg.obj; |
| 593 | final Phone phone = getPhoneFromRequest(request); |
| 594 | Pair<String, ResultReceiver> ussdObject = (Pair) request.argument; |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 595 | String ussdRequest = ussdObject.first; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 596 | ResultReceiver wrappedCallback = ussdObject.second; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 597 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 598 | if (!isUssdApiAllowed(request.subId)) { |
| 599 | // Carrier does not support use of this API, return failure. |
| 600 | Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis."); |
| 601 | UssdResponse response = new UssdResponse(ussdRequest, null); |
| 602 | Bundle returnData = new Bundle(); |
| 603 | returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response); |
| 604 | wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 605 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 606 | request.result = true; |
| 607 | notifyRequester(request); |
| 608 | return; |
| 609 | } |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 610 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 611 | try { |
| 612 | request.result = phone != null |
| 613 | ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false; |
| 614 | } catch (CallStateException cse) { |
| 615 | request.result = false; |
| 616 | } |
| 617 | // Wake up the requesting thread |
| 618 | notifyRequester(request); |
| 619 | break; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 620 | } |
| 621 | |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 622 | case CMD_HANDLE_PIN_MMI: { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 623 | request = (MainThreadRequest) msg.obj; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 624 | final Phone phone = getPhoneFromRequest(request); |
| 625 | request.result = phone != null ? |
| 626 | getPhoneFromRequest(request).handlePinMmi((String) request.argument) |
| 627 | : false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 628 | // Wake up the requesting thread |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 629 | notifyRequester(request); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 630 | break; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 631 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 632 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 633 | case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 634 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 635 | iccArgument = (IccAPDUArgument) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 636 | uiccPort = getUiccPortFromRequest(request); |
| 637 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 638 | loge("iccTransmitApduLogicalChannel: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 639 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 640 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 641 | } else { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 642 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE, |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 643 | request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 644 | uiccPort.iccTransmitApduLogicalChannel( |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 645 | iccArgument.channel, iccArgument.cla, iccArgument.command, |
| 646 | iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data, |
| 647 | onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 648 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 649 | break; |
| 650 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 651 | case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 652 | ar = (AsyncResult) msg.obj; |
| 653 | request = (MainThreadRequest) ar.userObj; |
| 654 | if (ar.exception == null && ar.result != null) { |
| 655 | request.result = ar.result; |
| 656 | } else { |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 657 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 658 | if (ar.result == null) { |
| 659 | loge("iccTransmitApduLogicalChannel: Empty response"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 660 | } else if (ar.exception instanceof CommandException) { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 661 | loge("iccTransmitApduLogicalChannel: CommandException: " + |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 662 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 663 | } else { |
| 664 | loge("iccTransmitApduLogicalChannel: Unknown exception"); |
| 665 | } |
| 666 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 667 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 668 | break; |
| 669 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 670 | case CMD_TRANSMIT_APDU_BASIC_CHANNEL: |
| 671 | request = (MainThreadRequest) msg.obj; |
| 672 | iccArgument = (IccAPDUArgument) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 673 | uiccPort = getUiccPortFromRequest(request); |
| 674 | if (uiccPort == null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 675 | loge("iccTransmitApduBasicChannel: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 676 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 677 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 678 | } else { |
| 679 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE, |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 680 | request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 681 | uiccPort.iccTransmitApduBasicChannel( |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 682 | iccArgument.cla, iccArgument.command, iccArgument.p1, |
| 683 | iccArgument.p2, |
| 684 | iccArgument.p3, iccArgument.data, onCompleted); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 685 | } |
| 686 | break; |
| 687 | |
| 688 | case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE: |
| 689 | ar = (AsyncResult) msg.obj; |
| 690 | request = (MainThreadRequest) ar.userObj; |
| 691 | if (ar.exception == null && ar.result != null) { |
| 692 | request.result = ar.result; |
| 693 | } else { |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 694 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 695 | if (ar.result == null) { |
| 696 | loge("iccTransmitApduBasicChannel: Empty response"); |
| 697 | } else if (ar.exception instanceof CommandException) { |
| 698 | loge("iccTransmitApduBasicChannel: CommandException: " + |
| 699 | ar.exception); |
| 700 | } else { |
| 701 | loge("iccTransmitApduBasicChannel: Unknown exception"); |
| 702 | } |
| 703 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 704 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 705 | break; |
| 706 | |
| 707 | case CMD_EXCHANGE_SIM_IO: |
| 708 | request = (MainThreadRequest) msg.obj; |
| 709 | iccArgument = (IccAPDUArgument) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 710 | uiccPort = getUiccPortFromRequest(request); |
| 711 | if (uiccPort == null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 712 | loge("iccExchangeSimIO: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 713 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 714 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 715 | } else { |
| 716 | onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE, |
| 717 | request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 718 | uiccPort.iccExchangeSimIO(iccArgument.cla, /* fileID */ |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 719 | iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3, |
| 720 | iccArgument.data, onCompleted); |
| 721 | } |
| 722 | break; |
| 723 | |
| 724 | case EVENT_EXCHANGE_SIM_IO_DONE: |
| 725 | ar = (AsyncResult) msg.obj; |
| 726 | request = (MainThreadRequest) ar.userObj; |
| 727 | if (ar.exception == null && ar.result != null) { |
| 728 | request.result = ar.result; |
| 729 | } else { |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 730 | request.result = new IccIoResult(0x6f, 0, (byte[]) null); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 731 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 732 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 733 | break; |
| 734 | |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 735 | case CMD_SEND_ENVELOPE: |
| 736 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 737 | uiccPort = getUiccPortFromRequest(request); |
| 738 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 739 | loge("sendEnvelopeWithStatus: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 740 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 741 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 742 | } else { |
| 743 | onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 744 | uiccPort.sendEnvelopeWithStatus((String) request.argument, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 745 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 746 | break; |
| 747 | |
| 748 | case EVENT_SEND_ENVELOPE_DONE: |
| 749 | ar = (AsyncResult) msg.obj; |
| 750 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 751 | if (ar.exception == null && ar.result != null) { |
| 752 | request.result = ar.result; |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 753 | } else { |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 754 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 755 | if (ar.result == null) { |
| 756 | loge("sendEnvelopeWithStatus: Empty response"); |
| 757 | } else if (ar.exception instanceof CommandException) { |
| 758 | loge("sendEnvelopeWithStatus: CommandException: " + |
| 759 | ar.exception); |
| 760 | } else { |
| 761 | loge("sendEnvelopeWithStatus: exception:" + ar.exception); |
| 762 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 763 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 764 | notifyRequester(request); |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 765 | break; |
| 766 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 767 | case CMD_OPEN_CHANNEL: |
| 768 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 769 | uiccPort = getUiccPortFromRequest(request); |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 770 | IccLogicalChannelRequest openChannelRequest = |
| 771 | (IccLogicalChannelRequest) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 772 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 773 | loge("iccOpenLogicalChannel: No UICC"); |
Shishir Agrawal | fc0492a | 2016-02-17 11:15:33 -0800 | [diff] [blame] | 774 | request.result = new IccOpenLogicalChannelResponse(-1, |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 775 | IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 776 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 777 | } else { |
| 778 | onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request); |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 779 | uiccPort.iccOpenLogicalChannel(openChannelRequest.aid, |
| 780 | openChannelRequest.p2, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 781 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 782 | break; |
| 783 | |
| 784 | case EVENT_OPEN_CHANNEL_DONE: |
| 785 | ar = (AsyncResult) msg.obj; |
| 786 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 787 | IccOpenLogicalChannelResponse openChannelResp; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 788 | if (ar.exception == null && ar.result != null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 789 | int[] result = (int[]) ar.result; |
| 790 | int channelId = result[0]; |
| 791 | byte[] selectResponse = null; |
| 792 | if (result.length > 1) { |
| 793 | selectResponse = new byte[result.length - 1]; |
| 794 | for (int i = 1; i < result.length; ++i) { |
| 795 | selectResponse[i - 1] = (byte) result[i]; |
| 796 | } |
| 797 | } |
| 798 | openChannelResp = new IccOpenLogicalChannelResponse(channelId, |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 799 | IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse); |
Rambo Wang | 3b77c4c | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 800 | |
| 801 | uiccPort = getUiccPortFromRequest(request); |
Rambo Wang | e53e07d | 2022-05-10 13:01:13 -0700 | [diff] [blame] | 802 | if (uiccPort == null) { |
| 803 | loge("EVENT_OPEN_CHANNEL_DONE: UiccPort is null"); |
| 804 | } else { |
| 805 | IccLogicalChannelRequest channelRequest = |
| 806 | (IccLogicalChannelRequest) request.argument; |
| 807 | channelRequest.channel = channelId; |
| 808 | uiccPort.onLogicalChannelOpened(channelRequest); |
| 809 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 810 | } else { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 811 | if (ar.result == null) { |
| 812 | loge("iccOpenLogicalChannel: Empty response"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 813 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 814 | if (ar.exception != null) { |
| 815 | loge("iccOpenLogicalChannel: Exception: " + ar.exception); |
| 816 | } |
| 817 | |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 818 | int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 819 | if (ar.exception instanceof CommandException) { |
| 820 | CommandException.Error error = |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 821 | ((CommandException) (ar.exception)).getCommandError(); |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 822 | if (error == CommandException.Error.MISSING_RESOURCE) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 823 | errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 824 | } else if (error == CommandException.Error.NO_SUCH_ELEMENT) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 825 | errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 826 | } |
| 827 | } |
| 828 | openChannelResp = new IccOpenLogicalChannelResponse( |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 829 | IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 830 | } |
Shishir Agrawal | 82c8a46 | 2014-07-31 18:13:17 -0700 | [diff] [blame] | 831 | request.result = openChannelResp; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 832 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 833 | break; |
| 834 | |
| 835 | case CMD_CLOSE_CHANNEL: |
| 836 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 837 | uiccPort = getUiccPortFromRequest(request); |
| 838 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 839 | loge("iccCloseLogicalChannel: No UICC"); |
Chen Xu | a8f0dff | 2022-02-12 00:34:15 -0800 | [diff] [blame] | 840 | request.result = new IllegalArgumentException( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 841 | "iccCloseLogicalChannel: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 842 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 843 | } else { |
| 844 | onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 845 | uiccPort.iccCloseLogicalChannel((Integer) request.argument, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 846 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 847 | break; |
| 848 | |
| 849 | case EVENT_CLOSE_CHANNEL_DONE: |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 850 | ar = (AsyncResult) msg.obj; |
| 851 | request = (MainThreadRequest) ar.userObj; |
| 852 | if (ar.exception == null) { |
| 853 | request.result = true; |
Rambo Wang | 3b77c4c | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 854 | uiccPort = getUiccPortFromRequest(request); |
Rambo Wang | e53e07d | 2022-05-10 13:01:13 -0700 | [diff] [blame] | 855 | if (uiccPort == null) { |
| 856 | loge("EVENT_CLOSE_CHANNEL_DONE: UiccPort is null"); |
| 857 | } else { |
| 858 | final int channelId = (Integer) request.argument; |
| 859 | uiccPort.onLogicalChannelClosed(channelId); |
| 860 | } |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 861 | } else { |
| 862 | request.result = false; |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 863 | Exception exception = null; |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 864 | if (ar.exception instanceof CommandException) { |
| 865 | loge("iccCloseLogicalChannel: CommandException: " + ar.exception); |
| 866 | CommandException.Error error = |
| 867 | ((CommandException) (ar.exception)).getCommandError(); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 868 | if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 869 | // should only throw exceptions from the binder threads. |
| 870 | exception = new IllegalArgumentException( |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 871 | "iccCloseLogicalChannel: invalid argument "); |
| 872 | } |
| 873 | } else { |
| 874 | loge("iccCloseLogicalChannel: Unknown exception"); |
| 875 | } |
Chen Xu | a8f0dff | 2022-02-12 00:34:15 -0800 | [diff] [blame] | 876 | request.result = (exception != null) ? exception : |
| 877 | new IllegalStateException( |
| 878 | "exception from modem to close iccLogical Channel"); |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 879 | } |
| 880 | notifyRequester(request); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 881 | break; |
| 882 | |
| 883 | case CMD_NV_READ_ITEM: |
| 884 | request = (MainThreadRequest) msg.obj; |
| 885 | onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 886 | defaultPhone.nvReadItem((Integer) request.argument, onCompleted, |
| 887 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 888 | break; |
| 889 | |
| 890 | case EVENT_NV_READ_ITEM_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 891 | ar = (AsyncResult) msg.obj; |
| 892 | request = (MainThreadRequest) ar.userObj; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 893 | if (ar.exception == null && ar.result != null) { |
| 894 | request.result = ar.result; // String |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 895 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 896 | request.result = ""; |
| 897 | if (ar.result == null) { |
| 898 | loge("nvReadItem: Empty response"); |
| 899 | } else if (ar.exception instanceof CommandException) { |
| 900 | loge("nvReadItem: CommandException: " + |
| 901 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 902 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 903 | loge("nvReadItem: Unknown exception"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 904 | } |
| 905 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 906 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 907 | break; |
| 908 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 909 | case CMD_NV_WRITE_ITEM: |
| 910 | request = (MainThreadRequest) msg.obj; |
| 911 | onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request); |
| 912 | Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 913 | defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 914 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 915 | break; |
| 916 | |
| 917 | case EVENT_NV_WRITE_ITEM_DONE: |
| 918 | handleNullReturnEvent(msg, "nvWriteItem"); |
| 919 | break; |
| 920 | |
| 921 | case CMD_NV_WRITE_CDMA_PRL: |
| 922 | request = (MainThreadRequest) msg.obj; |
| 923 | onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 924 | defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 925 | break; |
| 926 | |
| 927 | case EVENT_NV_WRITE_CDMA_PRL_DONE: |
| 928 | handleNullReturnEvent(msg, "nvWriteCdmaPrl"); |
| 929 | break; |
| 930 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 931 | case CMD_RESET_MODEM_CONFIG: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 932 | request = (MainThreadRequest) msg.obj; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 933 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 934 | defaultPhone.resetModemConfig(onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 935 | break; |
| 936 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 937 | case EVENT_RESET_MODEM_CONFIG_DONE: |
| 938 | handleNullReturnEvent(msg, "resetModemConfig"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 939 | break; |
| 940 | |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 941 | case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: { |
| 942 | request = (MainThreadRequest) msg.obj; |
| 943 | onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE, |
| 944 | request); |
| 945 | Phone phone = getPhoneFromRequest(request); |
| 946 | if (phone != null) { |
| 947 | phone.isNrDualConnectivityEnabled(onCompleted, request.workSource); |
| 948 | } else { |
| 949 | loge("isNRDualConnectivityEnabled: No phone object"); |
| 950 | request.result = false; |
| 951 | notifyRequester(request); |
| 952 | } |
| 953 | break; |
| 954 | } |
| 955 | |
| 956 | case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE: |
| 957 | ar = (AsyncResult) msg.obj; |
| 958 | request = (MainThreadRequest) ar.userObj; |
| 959 | if (ar.exception == null && ar.result != null) { |
| 960 | request.result = ar.result; |
| 961 | } else { |
| 962 | // request.result must be set to something non-null |
| 963 | // for the calling thread to unblock |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 964 | if (ar.result != null) { |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 965 | request.result = ar.result; |
| 966 | } else { |
| 967 | request.result = false; |
| 968 | } |
| 969 | if (ar.result == null) { |
| 970 | loge("isNRDualConnectivityEnabled: Empty response"); |
| 971 | } else if (ar.exception instanceof CommandException) { |
| 972 | loge("isNRDualConnectivityEnabled: CommandException: " |
| 973 | + ar.exception); |
| 974 | } else { |
| 975 | loge("isNRDualConnectivityEnabled: Unknown exception"); |
| 976 | } |
| 977 | } |
| 978 | notifyRequester(request); |
| 979 | break; |
| 980 | |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 981 | case CMD_IS_VONR_ENABLED: { |
| 982 | request = (MainThreadRequest) msg.obj; |
| 983 | onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE, |
| 984 | request); |
| 985 | Phone phone = getPhoneFromRequest(request); |
| 986 | if (phone != null) { |
| 987 | phone.isVoNrEnabled(onCompleted, request.workSource); |
| 988 | } else { |
| 989 | loge("isVoNrEnabled: No phone object"); |
| 990 | request.result = false; |
| 991 | notifyRequester(request); |
| 992 | } |
| 993 | break; |
| 994 | } |
| 995 | |
| 996 | case EVENT_IS_VONR_ENABLED_DONE: |
| 997 | ar = (AsyncResult) msg.obj; |
| 998 | request = (MainThreadRequest) ar.userObj; |
| 999 | if (ar.exception == null && ar.result != null) { |
| 1000 | request.result = ar.result; |
| 1001 | } else { |
| 1002 | // request.result must be set to something non-null |
| 1003 | // for the calling thread to unblock |
| 1004 | if (ar.result != null) { |
| 1005 | request.result = ar.result; |
| 1006 | } else { |
| 1007 | request.result = false; |
| 1008 | } |
| 1009 | if (ar.result == null) { |
| 1010 | loge("isVoNrEnabled: Empty response"); |
| 1011 | } else if (ar.exception instanceof CommandException) { |
| 1012 | loge("isVoNrEnabled: CommandException: " |
| 1013 | + ar.exception); |
| 1014 | } else { |
| 1015 | loge("isVoNrEnabled: Unknown exception"); |
| 1016 | } |
| 1017 | } |
| 1018 | notifyRequester(request); |
| 1019 | break; |
| 1020 | |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 1021 | case CMD_ENABLE_NR_DUAL_CONNECTIVITY: { |
| 1022 | request = (MainThreadRequest) msg.obj; |
| 1023 | onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request); |
| 1024 | Phone phone = getPhoneFromRequest(request); |
| 1025 | if (phone != null) { |
| 1026 | phone.setNrDualConnectivityState((int) request.argument, onCompleted, |
| 1027 | request.workSource); |
| 1028 | } else { |
| 1029 | loge("enableNrDualConnectivity: No phone object"); |
| 1030 | request.result = |
| 1031 | TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE; |
| 1032 | notifyRequester(request); |
| 1033 | } |
| 1034 | break; |
| 1035 | } |
| 1036 | |
| 1037 | case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: { |
| 1038 | ar = (AsyncResult) msg.obj; |
| 1039 | request = (MainThreadRequest) ar.userObj; |
| 1040 | if (ar.exception == null) { |
| 1041 | request.result = |
| 1042 | TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS; |
| 1043 | } else { |
| 1044 | request.result = |
| 1045 | TelephonyManager |
| 1046 | .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR; |
| 1047 | if (ar.exception instanceof CommandException) { |
| 1048 | CommandException.Error error = |
| 1049 | ((CommandException) (ar.exception)).getCommandError(); |
| 1050 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1051 | request.result = |
| 1052 | TelephonyManager |
| 1053 | .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE; |
Sooraj Sasindran | 2965416 | 2021-03-03 23:00:01 +0000 | [diff] [blame] | 1054 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1055 | request.result = |
| 1056 | TelephonyManager |
| 1057 | .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED; |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 1058 | } |
| 1059 | loge("enableNrDualConnectivity" + ": CommandException: " |
| 1060 | + ar.exception); |
| 1061 | } else { |
| 1062 | loge("enableNrDualConnectivity" + ": Unknown exception"); |
| 1063 | } |
| 1064 | } |
| 1065 | notifyRequester(request); |
| 1066 | break; |
| 1067 | } |
| 1068 | |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 1069 | case CMD_ENABLE_VONR: { |
| 1070 | request = (MainThreadRequest) msg.obj; |
| 1071 | onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request); |
| 1072 | Phone phone = getPhoneFromRequest(request); |
| 1073 | if (phone != null) { |
| 1074 | phone.setVoNrEnabled((boolean) request.argument, onCompleted, |
| 1075 | request.workSource); |
| 1076 | } else { |
| 1077 | loge("setVoNrEnabled: No phone object"); |
| 1078 | request.result = |
| 1079 | TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE; |
| 1080 | notifyRequester(request); |
| 1081 | } |
| 1082 | break; |
| 1083 | } |
| 1084 | |
| 1085 | case EVENT_ENABLE_VONR_DONE: { |
| 1086 | ar = (AsyncResult) msg.obj; |
| 1087 | request = (MainThreadRequest) ar.userObj; |
| 1088 | if (ar.exception == null) { |
| 1089 | request.result = TelephonyManager.ENABLE_VONR_SUCCESS; |
| 1090 | } else { |
| 1091 | request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR; |
| 1092 | if (ar.exception instanceof CommandException) { |
| 1093 | CommandException.Error error = |
| 1094 | ((CommandException) (ar.exception)).getCommandError(); |
| 1095 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1096 | request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE; |
| 1097 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1098 | request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED; |
| 1099 | } else { |
| 1100 | request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR; |
| 1101 | } |
| 1102 | loge("setVoNrEnabled" + ": CommandException: " |
| 1103 | + ar.exception); |
| 1104 | } else { |
| 1105 | loge("setVoNrEnabled" + ": Unknown exception"); |
| 1106 | } |
| 1107 | } |
| 1108 | notifyRequester(request); |
| 1109 | break; |
| 1110 | } |
| 1111 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1112 | case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1113 | request = (MainThreadRequest) msg.obj; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1114 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE, |
| 1115 | request); |
| 1116 | getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1117 | break; |
| 1118 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1119 | case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1120 | ar = (AsyncResult) msg.obj; |
| 1121 | request = (MainThreadRequest) ar.userObj; |
| 1122 | if (ar.exception == null && ar.result != null) { |
| 1123 | request.result = ar.result; // Integer |
| 1124 | } else { |
Nazish Tabassum | e8ba43a | 2020-07-28 14:49:25 +0530 | [diff] [blame] | 1125 | // request.result must be set to something non-null |
| 1126 | // for the calling thread to unblock |
| 1127 | request.result = new int[]{-1}; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1128 | if (ar.result == null) { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1129 | loge("getAllowedNetworkTypesBitmask: Empty response"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1130 | } else if (ar.exception instanceof CommandException) { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1131 | loge("getAllowedNetworkTypesBitmask: CommandException: " |
| 1132 | + ar.exception); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1133 | } else { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1134 | loge("getAllowedNetworkTypesBitmask: Unknown exception"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1135 | } |
| 1136 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1137 | notifyRequester(request); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1138 | break; |
| 1139 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1140 | case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1141 | request = (MainThreadRequest) msg.obj; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1142 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE, |
| 1143 | request); |
| 1144 | Pair<Integer, Long> reasonWithNetworkTypes = |
| 1145 | (Pair<Integer, Long>) request.argument; |
| 1146 | getPhoneFromRequest(request).setAllowedNetworkTypes( |
| 1147 | reasonWithNetworkTypes.first, |
| 1148 | reasonWithNetworkTypes.second, |
| 1149 | onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1150 | break; |
| 1151 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1152 | case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE: |
| 1153 | handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1154 | break; |
| 1155 | |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 1156 | case CMD_INVOKE_OEM_RIL_REQUEST_RAW: |
| 1157 | request = (MainThreadRequest)msg.obj; |
| 1158 | onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1159 | defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 1160 | break; |
| 1161 | |
| 1162 | case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE: |
| 1163 | ar = (AsyncResult)msg.obj; |
| 1164 | request = (MainThreadRequest)ar.userObj; |
| 1165 | request.result = ar; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1166 | notifyRequester(request); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 1167 | break; |
| 1168 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1169 | case CMD_SET_VOICEMAIL_NUMBER: |
| 1170 | request = (MainThreadRequest) msg.obj; |
| 1171 | onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request); |
| 1172 | Pair<String, String> tagNum = (Pair<String, String>) request.argument; |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1173 | getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second, |
| 1174 | onCompleted); |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1175 | break; |
| 1176 | |
| 1177 | case EVENT_SET_VOICEMAIL_NUMBER_DONE: |
| 1178 | handleNullReturnEvent(msg, "setVoicemailNumber"); |
| 1179 | break; |
| 1180 | |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 1181 | case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC: |
| 1182 | request = (MainThreadRequest) msg.obj; |
| 1183 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE, |
| 1184 | request); |
| 1185 | getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted); |
| 1186 | break; |
| 1187 | |
| 1188 | case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE: |
| 1189 | handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic"); |
| 1190 | break; |
| 1191 | |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1192 | case CMD_PERFORM_NETWORK_SCAN: |
| 1193 | request = (MainThreadRequest) msg.obj; |
| 1194 | onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request); |
| 1195 | getPhoneFromRequest(request).getAvailableNetworks(onCompleted); |
| 1196 | break; |
| 1197 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1198 | case CMD_GET_CALL_FORWARDING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1199 | request = (MainThreadRequest) msg.obj; |
| 1200 | onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1201 | Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args = |
| 1202 | (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>) |
| 1203 | request.argument; |
| 1204 | int callForwardingReason = args.first; |
| 1205 | request.phone.getCallForwardingOption(callForwardingReason, onCompleted); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1206 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1207 | } |
| 1208 | case EVENT_GET_CALL_FORWARDING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1209 | ar = (AsyncResult) msg.obj; |
| 1210 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1211 | TelephonyManager.CallForwardingInfoCallback callback = |
| 1212 | ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>) |
| 1213 | request.argument).second; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1214 | if (ar.exception == null && ar.result != null) { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1215 | CallForwardingInfo callForwardingInfo = null; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1216 | CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result; |
| 1217 | for (CallForwardInfo callForwardInfo : callForwardInfos) { |
| 1218 | // Service Class is a bit mask per 3gpp 27.007. Search for |
| 1219 | // any service for voice call. |
| 1220 | if ((callForwardInfo.serviceClass |
| 1221 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0) { |
Yuchen Dong | 69cc141 | 2021-09-27 20:27:01 +0800 | [diff] [blame] | 1222 | callForwardingInfo = new CallForwardingInfo( |
| 1223 | callForwardInfo.status |
| 1224 | == CommandsInterface.CF_ACTION_ENABLE, |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1225 | callForwardInfo.reason, |
| 1226 | callForwardInfo.number, |
| 1227 | callForwardInfo.timeSeconds); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1228 | break; |
| 1229 | } |
| 1230 | } |
| 1231 | // Didn't find a call forward info for voice call. |
| 1232 | if (callForwardingInfo == null) { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1233 | callForwardingInfo = new CallForwardingInfo(false /* enabled */, |
| 1234 | 0 /* reason */, null /* number */, 0 /* timeout */); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1235 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1236 | callback.onCallForwardingInfoAvailable(callForwardingInfo); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1237 | } else { |
| 1238 | if (ar.result == null) { |
| 1239 | loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response"); |
| 1240 | } |
| 1241 | if (ar.exception != null) { |
| 1242 | loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception); |
| 1243 | } |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1244 | int errorCode = TelephonyManager |
| 1245 | .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1246 | if (ar.exception instanceof CommandException) { |
| 1247 | CommandException.Error error = |
| 1248 | ((CommandException) (ar.exception)).getCommandError(); |
| 1249 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1250 | errorCode = TelephonyManager |
| 1251 | .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1252 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1253 | errorCode = TelephonyManager |
| 1254 | .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1255 | } |
| 1256 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1257 | callback.onError(errorCode); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1258 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1259 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1260 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1261 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1262 | case CMD_SET_CALL_FORWARDING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1263 | request = (MainThreadRequest) msg.obj; |
| 1264 | onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1265 | request = (MainThreadRequest) msg.obj; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1266 | CallForwardingInfo callForwardingInfoToSet = |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1267 | ((Pair<CallForwardingInfo, Consumer<Integer>>) |
| 1268 | request.argument).first; |
| 1269 | request.phone.setCallForwardingOption( |
| 1270 | callForwardingInfoToSet.isEnabled() |
Calvin Pan | 258f1f7 | 2021-07-28 21:46:56 +0800 | [diff] [blame] | 1271 | ? CommandsInterface.CF_ACTION_REGISTRATION |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1272 | : CommandsInterface.CF_ACTION_DISABLE, |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1273 | callForwardingInfoToSet.getReason(), |
| 1274 | callForwardingInfoToSet.getNumber(), |
| 1275 | callForwardingInfoToSet.getTimeoutSeconds(), onCompleted); |
| 1276 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1277 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1278 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1279 | case EVENT_SET_CALL_FORWARDING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1280 | ar = (AsyncResult) msg.obj; |
| 1281 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1282 | Consumer<Integer> callback = |
| 1283 | ((Pair<CallForwardingInfo, Consumer<Integer>>) |
| 1284 | request.argument).second; |
| 1285 | if (ar.exception != null) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1286 | loge("setCallForwarding exception: " + ar.exception); |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1287 | int errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1288 | .RESULT_ERROR_UNKNOWN; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1289 | if (ar.exception instanceof CommandException) { |
| 1290 | CommandException.Error error = |
| 1291 | ((CommandException) (ar.exception)).getCommandError(); |
| 1292 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1293 | errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1294 | .RESULT_ERROR_FDN_CHECK_FAILURE; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1295 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1296 | errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1297 | .RESULT_ERROR_NOT_SUPPORTED; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1298 | } |
| 1299 | } |
| 1300 | callback.accept(errorCode); |
| 1301 | } else { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1302 | callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1303 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1304 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1305 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1306 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1307 | case CMD_GET_CALL_WAITING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1308 | request = (MainThreadRequest) msg.obj; |
| 1309 | onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request); |
| 1310 | getPhoneFromRequest(request).getCallWaiting(onCompleted); |
| 1311 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1312 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1313 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1314 | case EVENT_GET_CALL_WAITING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1315 | ar = (AsyncResult) msg.obj; |
| 1316 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1317 | Consumer<Integer> callback = (Consumer<Integer>) request.argument; |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1318 | int callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1319 | if (ar.exception == null && ar.result != null) { |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1320 | int[] callForwardResults = (int[]) ar.result; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1321 | // Service Class is a bit mask per 3gpp 27.007. |
| 1322 | // Search for any service for voice call. |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1323 | if (callForwardResults.length > 1 |
| 1324 | && ((callForwardResults[1] |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1325 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) { |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1326 | callWaitingStatus = callForwardResults[0] == 0 |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1327 | ? TelephonyManager.CALL_WAITING_STATUS_DISABLED |
| 1328 | : TelephonyManager.CALL_WAITING_STATUS_ENABLED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1329 | } else { |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1330 | callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1331 | } |
| 1332 | } else { |
| 1333 | if (ar.result == null) { |
| 1334 | loge("EVENT_GET_CALL_WAITING_DONE: Empty response"); |
| 1335 | } |
| 1336 | if (ar.exception != null) { |
| 1337 | loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception); |
| 1338 | } |
| 1339 | if (ar.exception instanceof CommandException) { |
| 1340 | CommandException.Error error = |
| 1341 | ((CommandException) (ar.exception)).getCommandError(); |
| 1342 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1343 | callWaitingStatus = |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1344 | TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED; |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1345 | } else if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
| 1346 | callWaitingStatus = |
| 1347 | TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1348 | } |
| 1349 | } |
| 1350 | } |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1351 | callback.accept(callWaitingStatus); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1352 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1353 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1354 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1355 | case CMD_SET_CALL_WAITING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1356 | request = (MainThreadRequest) msg.obj; |
| 1357 | onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1358 | boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first; |
| 1359 | getPhoneFromRequest(request).setCallWaiting(enable, onCompleted); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1360 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1361 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1362 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1363 | case EVENT_SET_CALL_WAITING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1364 | ar = (AsyncResult) msg.obj; |
| 1365 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1366 | boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first; |
| 1367 | Consumer<Integer> callback = |
| 1368 | ((Pair<Boolean, Consumer<Integer>>) request.argument).second; |
| 1369 | if (ar.exception != null) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1370 | loge("setCallWaiting exception: " + ar.exception); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1371 | if (ar.exception instanceof CommandException) { |
| 1372 | CommandException.Error error = |
| 1373 | ((CommandException) (ar.exception)).getCommandError(); |
| 1374 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1375 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED); |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1376 | } else if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
| 1377 | callback.accept( |
| 1378 | TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1379 | } else { |
| 1380 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 1381 | } |
| 1382 | } else { |
| 1383 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 1384 | } |
| 1385 | } else { |
| 1386 | callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED |
| 1387 | : TelephonyManager.CALL_WAITING_STATUS_DISABLED); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1388 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1389 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1390 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1391 | case EVENT_PERFORM_NETWORK_SCAN_DONE: |
| 1392 | ar = (AsyncResult) msg.obj; |
| 1393 | request = (MainThreadRequest) ar.userObj; |
| 1394 | CellNetworkScanResult cellScanResult; |
| 1395 | if (ar.exception == null && ar.result != null) { |
| 1396 | cellScanResult = new CellNetworkScanResult( |
| 1397 | CellNetworkScanResult.STATUS_SUCCESS, |
| 1398 | (List<OperatorInfo>) ar.result); |
| 1399 | } else { |
| 1400 | if (ar.result == null) { |
| 1401 | loge("getCellNetworkScanResults: Empty response"); |
| 1402 | } |
| 1403 | if (ar.exception != null) { |
| 1404 | loge("getCellNetworkScanResults: Exception: " + ar.exception); |
| 1405 | } |
| 1406 | int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR; |
| 1407 | if (ar.exception instanceof CommandException) { |
| 1408 | CommandException.Error error = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 1409 | ((CommandException) (ar.exception)).getCommandError(); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1410 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1411 | errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE; |
| 1412 | } else if (error == CommandException.Error.GENERIC_FAILURE) { |
| 1413 | errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE; |
| 1414 | } |
| 1415 | } |
| 1416 | cellScanResult = new CellNetworkScanResult(errorCode, null); |
| 1417 | } |
| 1418 | request.result = cellScanResult; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1419 | notifyRequester(request); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1420 | break; |
| 1421 | |
| 1422 | case CMD_SET_NETWORK_SELECTION_MODE_MANUAL: |
| 1423 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1424 | ManualNetworkSelectionArgument selArg = |
| 1425 | (ManualNetworkSelectionArgument) request.argument; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1426 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE, |
| 1427 | request); |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1428 | getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo, |
| 1429 | selArg.persistSelection, onCompleted); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1430 | break; |
| 1431 | |
| 1432 | case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE: |
Pengquan Meng | e3d01e2 | 2018-09-20 15:25:35 -0700 | [diff] [blame] | 1433 | ar = (AsyncResult) msg.obj; |
| 1434 | request = (MainThreadRequest) ar.userObj; |
| 1435 | if (ar.exception == null) { |
| 1436 | request.result = true; |
| 1437 | } else { |
| 1438 | request.result = false; |
| 1439 | loge("setNetworkSelectionModeManual " + ar.exception); |
| 1440 | } |
| 1441 | notifyRequester(request); |
| 1442 | mApp.onNetworkSelectionChanged(request.subId); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1443 | break; |
| 1444 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1445 | case CMD_GET_MODEM_ACTIVITY_INFO: |
| 1446 | request = (MainThreadRequest) msg.obj; |
| 1447 | onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1448 | if (defaultPhone != null) { |
| 1449 | defaultPhone.getModemActivityInfo(onCompleted, request.workSource); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1450 | } else { |
| 1451 | ResultReceiver result = (ResultReceiver) request.argument; |
| 1452 | Bundle bundle = new Bundle(); |
| 1453 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 1454 | new ModemActivityInfo(0, 0, 0, |
| 1455 | new int[ModemActivityInfo.getNumTxPowerLevels()], 0)); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1456 | result.send(0, bundle); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1457 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1458 | break; |
| 1459 | |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1460 | case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: { |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1461 | ar = (AsyncResult) msg.obj; |
| 1462 | request = (MainThreadRequest) ar.userObj; |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1463 | ResultReceiver result = (ResultReceiver) request.argument; |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1464 | int error = 0; |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 1465 | ModemActivityInfo ret = null; |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1466 | if (mLastModemActivityInfo == null) { |
| 1467 | mLastModemActivitySpecificInfo = new ActivityStatsTechSpecificInfo[1]; |
| 1468 | mLastModemActivitySpecificInfo[0] = |
| 1469 | new ActivityStatsTechSpecificInfo( |
| 1470 | 0, |
| 1471 | 0, |
| 1472 | new int[ModemActivityInfo.getNumTxPowerLevels()], |
| 1473 | 0); |
| 1474 | mLastModemActivityInfo = |
| 1475 | new ModemActivityInfo(0, 0, 0, mLastModemActivitySpecificInfo); |
| 1476 | } |
| 1477 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1478 | if (ar.exception == null && ar.result != null) { |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1479 | // Update the last modem activity info and the result of the request. |
| 1480 | ModemActivityInfo info = (ModemActivityInfo) ar.result; |
| 1481 | if (isModemActivityInfoValid(info)) { |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1482 | mergeModemActivityInfo(info); |
Gary Jian | 76280a4 | 2022-12-07 16:18:33 +0800 | [diff] [blame] | 1483 | } else { |
| 1484 | loge("queryModemActivityInfo: invalid response"); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1485 | } |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 1486 | // This is needed to decouple ret from mLastModemActivityInfo |
| 1487 | // We don't want to return mLastModemActivityInfo which is updated |
| 1488 | // inside mergeModemActivityInfo() |
| 1489 | ret = new ModemActivityInfo( |
| 1490 | mLastModemActivityInfo.getTimestampMillis(), |
| 1491 | mLastModemActivityInfo.getSleepTimeMillis(), |
| 1492 | mLastModemActivityInfo.getIdleTimeMillis(), |
| 1493 | deepCopyModemActivitySpecificInfo(mLastModemActivitySpecificInfo)); |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1494 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1495 | } else { |
| 1496 | if (ar.result == null) { |
| 1497 | loge("queryModemActivityInfo: Empty response"); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1498 | error = TelephonyManager.ModemActivityInfoException |
| 1499 | .ERROR_INVALID_INFO_RECEIVED; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1500 | } else if (ar.exception instanceof CommandException) { |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1501 | loge("queryModemActivityInfo: CommandException: " + ar.exception); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1502 | error = TelephonyManager.ModemActivityInfoException |
| 1503 | .ERROR_MODEM_RESPONSE_ERROR; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1504 | } else { |
| 1505 | loge("queryModemActivityInfo: Unknown exception"); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1506 | error = TelephonyManager.ModemActivityInfoException |
| 1507 | .ERROR_UNKNOWN; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1508 | } |
| 1509 | } |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1510 | Bundle bundle = new Bundle(); |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 1511 | if (ret != null) { |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1512 | bundle.putParcelable( |
| 1513 | TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 1514 | ret); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1515 | } else { |
| 1516 | bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error); |
| 1517 | } |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1518 | result.send(0, bundle); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1519 | notifyRequester(request); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1520 | break; |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1521 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1522 | |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 1523 | case CMD_SET_ALLOWED_CARRIERS: { |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1524 | request = (MainThreadRequest) msg.obj; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1525 | CarrierRestrictionRules argument = |
| 1526 | (CarrierRestrictionRules) request.argument; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1527 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request); |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1528 | defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1529 | break; |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 1530 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1531 | |
| 1532 | case EVENT_SET_ALLOWED_CARRIERS_DONE: |
| 1533 | ar = (AsyncResult) msg.obj; |
| 1534 | request = (MainThreadRequest) ar.userObj; |
| 1535 | if (ar.exception == null && ar.result != null) { |
| 1536 | request.result = ar.result; |
| 1537 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1538 | request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR; |
| 1539 | if (ar.exception instanceof CommandException) { |
| 1540 | loge("setAllowedCarriers: CommandException: " + ar.exception); |
| 1541 | CommandException.Error error = |
| 1542 | ((CommandException) (ar.exception)).getCommandError(); |
| 1543 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1544 | request.result = |
| 1545 | TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED; |
| 1546 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1547 | } else { |
| 1548 | loge("setAllowedCarriers: Unknown exception"); |
| 1549 | } |
| 1550 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1551 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1552 | break; |
| 1553 | |
| 1554 | case CMD_GET_ALLOWED_CARRIERS: |
| 1555 | request = (MainThreadRequest) msg.obj; |
| 1556 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1557 | defaultPhone.getAllowedCarriers(onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1558 | break; |
| 1559 | |
| 1560 | case EVENT_GET_ALLOWED_CARRIERS_DONE: |
| 1561 | ar = (AsyncResult) msg.obj; |
| 1562 | request = (MainThreadRequest) ar.userObj; |
| 1563 | if (ar.exception == null && ar.result != null) { |
| 1564 | request.result = ar.result; |
| 1565 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1566 | request.result = new IllegalStateException( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 1567 | "Failed to get carrier restrictions"); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1568 | if (ar.result == null) { |
| 1569 | loge("getAllowedCarriers: Empty response"); |
| 1570 | } else if (ar.exception instanceof CommandException) { |
| 1571 | loge("getAllowedCarriers: CommandException: " + |
| 1572 | ar.exception); |
| 1573 | } else { |
| 1574 | loge("getAllowedCarriers: Unknown exception"); |
| 1575 | } |
| 1576 | } |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 1577 | if (request.argument != null) { |
| 1578 | // This is for the implementation of carrierRestrictionStatus. |
| 1579 | CallerCallbackInfo callbackInfo = (CallerCallbackInfo) request.argument; |
| 1580 | Consumer<Integer> callback = callbackInfo.getConsumer(); |
| 1581 | int callerCarrierId = callbackInfo.getCarrierId(); |
| 1582 | int lockStatus = TelephonyManager.CARRIER_RESTRICTION_STATUS_UNKNOWN; |
| 1583 | if (ar.exception == null && ar.result instanceof CarrierRestrictionRules) { |
| 1584 | CarrierRestrictionRules carrierRestrictionRules = |
| 1585 | (CarrierRestrictionRules) ar.result; |
| 1586 | int carrierId = -1; |
| 1587 | try { |
| 1588 | CarrierIdentifier carrierIdentifier = |
| 1589 | carrierRestrictionRules.getAllowedCarriers().get(0); |
| 1590 | carrierId = CarrierResolver.getCarrierIdFromIdentifier(mApp, |
| 1591 | carrierIdentifier); |
| 1592 | } catch (NullPointerException | IndexOutOfBoundsException ex) { |
| 1593 | Rlog.e(LOG_TAG, "CarrierIdentifier exception = " + ex); |
| 1594 | } |
| 1595 | lockStatus = carrierRestrictionRules.getCarrierRestrictionStatus(); |
| 1596 | if (carrierId != -1 && callerCarrierId == carrierId && lockStatus |
| 1597 | == TelephonyManager.CARRIER_RESTRICTION_STATUS_RESTRICTED) { |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 1598 | lockStatus = TelephonyManager |
| 1599 | .CARRIER_RESTRICTION_STATUS_RESTRICTED_TO_CALLER; |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 1600 | } |
| 1601 | } else { |
| 1602 | Rlog.e(LOG_TAG, |
| 1603 | "getCarrierRestrictionStatus: exception ex = " + ar.exception); |
| 1604 | } |
| 1605 | callback.accept(lockStatus); |
| 1606 | } else { |
| 1607 | // This is for the implementation of getAllowedCarriers. |
| 1608 | notifyRequester(request); |
| 1609 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1610 | break; |
| 1611 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1612 | case EVENT_GET_FORBIDDEN_PLMNS_DONE: |
| 1613 | ar = (AsyncResult) msg.obj; |
| 1614 | request = (MainThreadRequest) ar.userObj; |
| 1615 | if (ar.exception == null && ar.result != null) { |
| 1616 | request.result = ar.result; |
| 1617 | } else { |
| 1618 | request.result = new IllegalArgumentException( |
| 1619 | "Failed to retrieve Forbidden Plmns"); |
| 1620 | if (ar.result == null) { |
| 1621 | loge("getForbiddenPlmns: Empty response"); |
| 1622 | } else { |
| 1623 | loge("getForbiddenPlmns: Unknown exception"); |
| 1624 | } |
| 1625 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1626 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1627 | break; |
| 1628 | |
| 1629 | case CMD_GET_FORBIDDEN_PLMNS: |
| 1630 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1631 | uiccPort = getUiccPortFromRequest(request); |
| 1632 | if (uiccPort == null) { |
| 1633 | loge("getForbiddenPlmns() UiccPort is null"); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1634 | request.result = new IllegalArgumentException( |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1635 | "getForbiddenPlmns() UiccPort is null"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1636 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1637 | break; |
| 1638 | } |
| 1639 | Integer appType = (Integer) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1640 | UiccCardApplication uiccApp = uiccPort.getApplicationByType(appType); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1641 | if (uiccApp == null) { |
| 1642 | loge("getForbiddenPlmns() no app with specified type -- " |
| 1643 | + appType); |
| 1644 | request.result = new IllegalArgumentException("Failed to get UICC App"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1645 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1646 | break; |
| 1647 | } else { |
| 1648 | if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid() |
| 1649 | + " specified type -- " + appType); |
| 1650 | } |
| 1651 | onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request); |
| 1652 | ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 1653 | onCompleted); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1654 | break; |
| 1655 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1656 | case CMD_SWITCH_SLOTS: |
| 1657 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 1658 | List<UiccSlotMapping> slotMapping = (List<UiccSlotMapping>) request.argument; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1659 | onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 1660 | UiccController.getInstance().switchSlots(slotMapping, onCompleted); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1661 | break; |
| 1662 | |
| 1663 | case EVENT_SWITCH_SLOTS_DONE: |
| 1664 | ar = (AsyncResult) msg.obj; |
| 1665 | request = (MainThreadRequest) ar.userObj; |
| 1666 | request.result = (ar.exception == null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1667 | notifyRequester(request); |
| 1668 | break; |
| 1669 | case CMD_GET_NETWORK_SELECTION_MODE: |
| 1670 | request = (MainThreadRequest) msg.obj; |
| 1671 | onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request); |
| 1672 | getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted); |
| 1673 | break; |
| 1674 | |
| 1675 | case EVENT_GET_NETWORK_SELECTION_MODE_DONE: |
| 1676 | ar = (AsyncResult) msg.obj; |
| 1677 | request = (MainThreadRequest) ar.userObj; |
| 1678 | if (ar.exception != null) { |
| 1679 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 1680 | } else { |
| 1681 | int mode = ((int[]) ar.result)[0]; |
| 1682 | if (mode == 0) { |
| 1683 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO; |
| 1684 | } else { |
| 1685 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL; |
| 1686 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1687 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1688 | notifyRequester(request); |
| 1689 | break; |
| 1690 | case CMD_GET_CDMA_ROAMING_MODE: |
| 1691 | request = (MainThreadRequest) msg.obj; |
| 1692 | onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request); |
| 1693 | getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted); |
| 1694 | break; |
| 1695 | case EVENT_GET_CDMA_ROAMING_MODE_DONE: |
| 1696 | ar = (AsyncResult) msg.obj; |
| 1697 | request = (MainThreadRequest) ar.userObj; |
| 1698 | if (ar.exception != null) { |
| 1699 | request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT; |
| 1700 | } else { |
| 1701 | request.result = ((int[]) ar.result)[0]; |
| 1702 | } |
| 1703 | notifyRequester(request); |
| 1704 | break; |
| 1705 | case CMD_SET_CDMA_ROAMING_MODE: |
| 1706 | request = (MainThreadRequest) msg.obj; |
| 1707 | onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request); |
| 1708 | int mode = (int) request.argument; |
| 1709 | getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted); |
| 1710 | break; |
| 1711 | case EVENT_SET_CDMA_ROAMING_MODE_DONE: |
| 1712 | ar = (AsyncResult) msg.obj; |
| 1713 | request = (MainThreadRequest) ar.userObj; |
| 1714 | request.result = ar.exception == null; |
| 1715 | notifyRequester(request); |
| 1716 | break; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 1717 | case CMD_GET_CDMA_SUBSCRIPTION_MODE: |
| 1718 | request = (MainThreadRequest) msg.obj; |
| 1719 | onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1720 | getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted); |
| 1721 | break; |
| 1722 | case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1723 | ar = (AsyncResult) msg.obj; |
| 1724 | request = (MainThreadRequest) ar.userObj; |
| 1725 | if (ar.exception != null) { |
| 1726 | request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM; |
| 1727 | } else { |
| 1728 | request.result = ((int[]) ar.result)[0]; |
| 1729 | } |
| 1730 | notifyRequester(request); |
| 1731 | break; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1732 | case CMD_SET_CDMA_SUBSCRIPTION_MODE: |
| 1733 | request = (MainThreadRequest) msg.obj; |
| 1734 | onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1735 | int subscriptionMode = (int) request.argument; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 1736 | getPhoneFromRequest(request).setCdmaSubscriptionMode( |
| 1737 | subscriptionMode, onCompleted); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1738 | break; |
| 1739 | case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1740 | ar = (AsyncResult) msg.obj; |
| 1741 | request = (MainThreadRequest) ar.userObj; |
| 1742 | request.result = ar.exception == null; |
| 1743 | notifyRequester(request); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1744 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1745 | case CMD_GET_ALL_CELL_INFO: |
| 1746 | request = (MainThreadRequest) msg.obj; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1747 | onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1748 | request.phone.requestCellInfoUpdate(request.workSource, onCompleted); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1749 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1750 | case EVENT_GET_ALL_CELL_INFO_DONE: |
| 1751 | ar = (AsyncResult) msg.obj; |
| 1752 | request = (MainThreadRequest) ar.userObj; |
Nathan Harold | 8d0f174 | 2018-10-02 12:14:47 -0700 | [diff] [blame] | 1753 | // If a timeout occurs, the response will be null |
| 1754 | request.result = (ar.exception == null && ar.result != null) |
| 1755 | ? ar.result : new ArrayList<CellInfo>(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1756 | synchronized (request) { |
| 1757 | request.notifyAll(); |
| 1758 | } |
| 1759 | break; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1760 | case CMD_REQUEST_CELL_INFO_UPDATE: |
| 1761 | request = (MainThreadRequest) msg.obj; |
| 1762 | request.phone.requestCellInfoUpdate(request.workSource, |
| 1763 | obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request)); |
| 1764 | break; |
| 1765 | case EVENT_REQUEST_CELL_INFO_UPDATE_DONE: |
| 1766 | ar = (AsyncResult) msg.obj; |
| 1767 | request = (MainThreadRequest) ar.userObj; |
| 1768 | ICellInfoCallback cb = (ICellInfoCallback) request.argument; |
| 1769 | try { |
| 1770 | if (ar.exception != null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1771 | Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception); |
Meng Wang | d8921f4 | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1772 | cb.onError( |
| 1773 | TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR, |
| 1774 | ar.exception.getClass().getName(), |
| 1775 | ar.exception.toString()); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1776 | } else if (ar.result == null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1777 | Log.w(LOG_TAG, "Timeout Waiting for CellInfo!"); |
Meng Wang | d8921f4 | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1778 | cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1779 | } else { |
| 1780 | // use the result as returned |
| 1781 | cb.onCellInfo((List<CellInfo>) ar.result); |
| 1782 | } |
| 1783 | } catch (RemoteException re) { |
| 1784 | Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException"); |
| 1785 | } |
| 1786 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1787 | case CMD_GET_CELL_LOCATION: { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1788 | request = (MainThreadRequest) msg.obj; |
| 1789 | WorkSource ws = (WorkSource) request.argument; |
| 1790 | Phone phone = getPhoneFromRequest(request); |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1791 | phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request)); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1792 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1793 | } |
| 1794 | case EVENT_GET_CELL_LOCATION_DONE: { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1795 | ar = (AsyncResult) msg.obj; |
| 1796 | request = (MainThreadRequest) ar.userObj; |
| 1797 | if (ar.exception == null) { |
| 1798 | request.result = ar.result; |
| 1799 | } else { |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1800 | Phone phone = getPhoneFromRequest(request); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1801 | request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1802 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1803 | } |
| 1804 | |
| 1805 | synchronized (request) { |
| 1806 | request.notifyAll(); |
| 1807 | } |
| 1808 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1809 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1810 | case CMD_MODEM_REBOOT: |
| 1811 | request = (MainThreadRequest) msg.obj; |
| 1812 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1813 | defaultPhone.rebootModem(onCompleted); |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1814 | break; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1815 | case EVENT_CMD_MODEM_REBOOT_DONE: |
| 1816 | handleNullReturnEvent(msg, "rebootModem"); |
| 1817 | break; |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 1818 | case CMD_REQUEST_ENABLE_MODEM: { |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1819 | request = (MainThreadRequest) msg.obj; |
| 1820 | boolean enable = (boolean) request.argument; |
| 1821 | onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1822 | onCompleted.arg1 = enable ? 1 : 0; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1823 | PhoneConfigurationManager.getInstance() |
| 1824 | .enablePhone(request.phone, enable, onCompleted); |
| 1825 | break; |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 1826 | } |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1827 | case EVENT_ENABLE_MODEM_DONE: { |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1828 | ar = (AsyncResult) msg.obj; |
| 1829 | request = (MainThreadRequest) ar.userObj; |
| 1830 | request.result = (ar.exception == null); |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1831 | int phoneId = request.phone.getPhoneId(); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1832 | //update the cache as modem status has changed |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1833 | if ((boolean) request.result) { |
| 1834 | mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1); |
| 1835 | updateModemStateMetrics(); |
| 1836 | } else { |
| 1837 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1838 | + ar.exception); |
| 1839 | } |
| 1840 | notifyRequester(request); |
| 1841 | break; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1842 | } |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1843 | case CMD_GET_MODEM_STATUS: |
| 1844 | request = (MainThreadRequest) msg.obj; |
| 1845 | onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request); |
| 1846 | PhoneConfigurationManager.getInstance() |
| 1847 | .getPhoneStatusFromModem(request.phone, onCompleted); |
| 1848 | break; |
| 1849 | case EVENT_GET_MODEM_STATUS_DONE: |
| 1850 | ar = (AsyncResult) msg.obj; |
| 1851 | request = (MainThreadRequest) ar.userObj; |
| 1852 | int id = request.phone.getPhoneId(); |
| 1853 | if (ar.exception == null && ar.result != null) { |
| 1854 | request.result = ar.result; |
| 1855 | //update the cache as modem status has changed |
| 1856 | mPhoneConfigurationManager.addToPhoneStatusCache(id, |
| 1857 | (boolean) request.result); |
| 1858 | } else { |
| 1859 | // Return true if modem status cannot be retrieved. For most cases, |
| 1860 | // modem status is on. And for older version modems, GET_MODEM_STATUS |
| 1861 | // and disable modem are not supported. Modem is always on. |
| 1862 | // TODO: this should be fixed in R to support a third |
| 1863 | // status UNKNOWN b/131631629 |
| 1864 | request.result = true; |
| 1865 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1866 | + ar.exception); |
| 1867 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1868 | notifyRequester(request); |
| 1869 | break; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 1870 | case CMD_SET_SYSTEM_SELECTION_CHANNELS: { |
| 1871 | request = (MainThreadRequest) msg.obj; |
| 1872 | onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request); |
| 1873 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 1874 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 1875 | request.phone.setSystemSelectionChannels(args.first, onCompleted); |
| 1876 | break; |
| 1877 | } |
| 1878 | case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: { |
| 1879 | ar = (AsyncResult) msg.obj; |
| 1880 | request = (MainThreadRequest) ar.userObj; |
| 1881 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 1882 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 1883 | args.second.accept(ar.exception == null); |
| 1884 | notifyRequester(request); |
| 1885 | break; |
| 1886 | } |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1887 | case CMD_GET_SYSTEM_SELECTION_CHANNELS: { |
| 1888 | request = (MainThreadRequest) msg.obj; |
| 1889 | onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request); |
| 1890 | Phone phone = getPhoneFromRequest(request); |
| 1891 | if (phone != null) { |
| 1892 | phone.getSystemSelectionChannels(onCompleted); |
| 1893 | } else { |
| 1894 | loge("getSystemSelectionChannels: No phone object"); |
| 1895 | request.result = new ArrayList<RadioAccessSpecifier>(); |
| 1896 | notifyRequester(request); |
| 1897 | } |
| 1898 | break; |
| 1899 | } |
| 1900 | case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE: |
| 1901 | ar = (AsyncResult) msg.obj; |
| 1902 | request = (MainThreadRequest) ar.userObj; |
| 1903 | if (ar.exception == null && ar.result != null) { |
| 1904 | request.result = ar.result; |
| 1905 | } else { |
Sarah Chin | 428d1d6 | 2021-03-13 03:17:40 -0800 | [diff] [blame] | 1906 | request.result = new IllegalStateException( |
| 1907 | "Failed to retrieve system selecton channels"); |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1908 | if (ar.result == null) { |
| 1909 | loge("getSystemSelectionChannels: Empty response"); |
| 1910 | } else { |
| 1911 | loge("getSystemSelectionChannels: Unknown exception"); |
| 1912 | } |
| 1913 | } |
| 1914 | notifyRequester(request); |
| 1915 | break; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1916 | case EVENT_SET_FORBIDDEN_PLMNS_DONE: |
| 1917 | ar = (AsyncResult) msg.obj; |
| 1918 | request = (MainThreadRequest) ar.userObj; |
| 1919 | if (ar.exception == null && ar.result != null) { |
| 1920 | request.result = ar.result; |
| 1921 | } else { |
| 1922 | request.result = -1; |
| 1923 | loge("Failed to set Forbidden Plmns"); |
| 1924 | if (ar.result == null) { |
| 1925 | loge("setForbidenPlmns: Empty response"); |
| 1926 | } else if (ar.exception != null) { |
| 1927 | loge("setForbiddenPlmns: Exception: " + ar.exception); |
| 1928 | request.result = -1; |
| 1929 | } else { |
| 1930 | loge("setForbiddenPlmns: Unknown exception"); |
| 1931 | } |
| 1932 | } |
| 1933 | notifyRequester(request); |
| 1934 | break; |
| 1935 | case CMD_SET_FORBIDDEN_PLMNS: |
| 1936 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1937 | uiccPort = getUiccPortFromRequest(request); |
| 1938 | if (uiccPort == null) { |
| 1939 | loge("setForbiddenPlmns: UiccPort is null"); |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1940 | request.result = -1; |
| 1941 | notifyRequester(request); |
| 1942 | break; |
| 1943 | } |
| 1944 | Pair<Integer, List<String>> setFplmnsArgs = |
| 1945 | (Pair<Integer, List<String>>) request.argument; |
| 1946 | appType = setFplmnsArgs.first; |
| 1947 | List<String> fplmns = setFplmnsArgs.second; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1948 | uiccApp = uiccPort.getApplicationByType(appType); |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1949 | if (uiccApp == null) { |
| 1950 | loge("setForbiddenPlmns: no app with specified type -- " + appType); |
| 1951 | request.result = -1; |
| 1952 | loge("Failed to get UICC App"); |
| 1953 | notifyRequester(request); |
| 1954 | } else { |
| 1955 | onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request); |
| 1956 | ((SIMRecords) uiccApp.getIccRecords()) |
| 1957 | .setForbiddenPlmns(onCompleted, fplmns); |
| 1958 | } |
yinchengzhao | 4d163c0 | 2019-12-12 15:21:47 -0800 | [diff] [blame] | 1959 | break; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 1960 | case CMD_ERASE_MODEM_CONFIG: |
| 1961 | request = (MainThreadRequest) msg.obj; |
| 1962 | onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request); |
| 1963 | defaultPhone.eraseModemConfig(onCompleted); |
| 1964 | break; |
| 1965 | case EVENT_ERASE_MODEM_CONFIG_DONE: |
| 1966 | handleNullReturnEvent(msg, "eraseModemConfig"); |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1967 | break; |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1968 | |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 1969 | case CMD_ERASE_DATA_SHARED_PREFERENCES: |
| 1970 | request = (MainThreadRequest) msg.obj; |
| 1971 | request.result = defaultPhone.eraseDataInSharedPreferences(); |
| 1972 | notifyRequester(request); |
| 1973 | break; |
| 1974 | |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1975 | case CMD_CHANGE_ICC_LOCK_PASSWORD: |
| 1976 | request = (MainThreadRequest) msg.obj; |
| 1977 | onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request); |
| 1978 | Pair<String, String> changed = (Pair<String, String>) request.argument; |
| 1979 | getPhoneFromRequest(request).getIccCard().changeIccLockPassword( |
| 1980 | changed.first, changed.second, onCompleted); |
| 1981 | break; |
| 1982 | case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE: |
| 1983 | ar = (AsyncResult) msg.obj; |
| 1984 | request = (MainThreadRequest) ar.userObj; |
| 1985 | if (ar.exception == null) { |
| 1986 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1987 | // If the operation is successful, update the PIN storage |
| 1988 | Pair<String, String> passwords = (Pair<String, String>) request.argument; |
| 1989 | int phoneId = getPhoneFromRequest(request).getPhoneId(); |
Jon Spivack | 9c3bc76 | 2021-10-06 20:53:09 +0000 | [diff] [blame] | 1990 | UiccController.getInstance().getPinStorage() |
| 1991 | .storePin(passwords.second, phoneId); |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1992 | } else { |
| 1993 | request.result = msg.arg1; |
| 1994 | } |
| 1995 | notifyRequester(request); |
| 1996 | break; |
| 1997 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1998 | case CMD_SET_ICC_LOCK_ENABLED: { |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1999 | request = (MainThreadRequest) msg.obj; |
| 2000 | onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request); |
| 2001 | Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument; |
| 2002 | getPhoneFromRequest(request).getIccCard().setIccLockEnabled( |
| 2003 | enabled.first, enabled.second, onCompleted); |
| 2004 | break; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2005 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 2006 | case EVENT_SET_ICC_LOCK_ENABLED_DONE: |
| 2007 | ar = (AsyncResult) msg.obj; |
| 2008 | request = (MainThreadRequest) ar.userObj; |
| 2009 | if (ar.exception == null) { |
| 2010 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2011 | // If the operation is successful, update the PIN storage |
| 2012 | Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument; |
| 2013 | int phoneId = getPhoneFromRequest(request).getPhoneId(); |
| 2014 | if (enabled.first) { |
Jon Spivack | 9c3bc76 | 2021-10-06 20:53:09 +0000 | [diff] [blame] | 2015 | UiccController.getInstance().getPinStorage() |
| 2016 | .storePin(enabled.second, phoneId); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2017 | } else { |
| 2018 | UiccController.getInstance().getPinStorage().clearPin(phoneId); |
| 2019 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 2020 | } else { |
| 2021 | request.result = msg.arg1; |
| 2022 | } |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2023 | |
| 2024 | |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 2025 | notifyRequester(request); |
| 2026 | break; |
| 2027 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 2028 | case MSG_NOTIFY_USER_ACTIVITY: |
| 2029 | removeMessages(MSG_NOTIFY_USER_ACTIVITY); |
Peter Wang | 59571be | 2020-01-27 12:35:15 +0800 | [diff] [blame] | 2030 | Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION); |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 2031 | intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY); |
| 2032 | getDefaultPhone().getContext().sendBroadcastAsUser( |
| 2033 | intent, UserHandle.ALL, permission.USER_ACTIVITY); |
| 2034 | break; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 2035 | |
| 2036 | case CMD_SET_DATA_THROTTLING: { |
| 2037 | request = (MainThreadRequest) msg.obj; |
| 2038 | onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request); |
| 2039 | DataThrottlingRequest dataThrottlingRequest = |
| 2040 | (DataThrottlingRequest) request.argument; |
| 2041 | Phone phone = getPhoneFromRequest(request); |
| 2042 | if (phone != null) { |
| 2043 | phone.setDataThrottling(onCompleted, |
| 2044 | request.workSource, dataThrottlingRequest.getDataThrottlingAction(), |
| 2045 | dataThrottlingRequest.getCompletionDurationMillis()); |
| 2046 | } else { |
| 2047 | loge("setDataThrottling: No phone object"); |
| 2048 | request.result = |
| 2049 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 2050 | notifyRequester(request); |
| 2051 | } |
| 2052 | |
| 2053 | break; |
| 2054 | } |
| 2055 | case EVENT_SET_DATA_THROTTLING_DONE: |
| 2056 | ar = (AsyncResult) msg.obj; |
| 2057 | request = (MainThreadRequest) ar.userObj; |
| 2058 | |
| 2059 | if (ar.exception == null) { |
| 2060 | request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 2061 | } else if (ar.exception instanceof CommandException) { |
| 2062 | loge("setDataThrottling: CommandException: " + ar.exception); |
| 2063 | CommandException.Error error = |
| 2064 | ((CommandException) (ar.exception)).getCommandError(); |
| 2065 | |
| 2066 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 2067 | request.result = TelephonyManager |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2068 | .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 2069 | } else if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 2070 | request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS; |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 2071 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 2072 | request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 2073 | } else { |
| 2074 | request.result = |
| 2075 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 2076 | } |
| 2077 | } else { |
| 2078 | request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 2079 | } |
| 2080 | Log.w(LOG_TAG, "DataThrottlingResult = " + request.result); |
| 2081 | notifyRequester(request); |
| 2082 | break; |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 2083 | |
| 2084 | case CMD_SET_SIM_POWER: { |
| 2085 | request = (MainThreadRequest) msg.obj; |
| 2086 | onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request); |
| 2087 | request = (MainThreadRequest) msg.obj; |
| 2088 | int stateToSet = |
| 2089 | ((Pair<Integer, IIntegerConsumer>) |
| 2090 | request.argument).first; |
| 2091 | request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource); |
| 2092 | break; |
| 2093 | } |
| 2094 | case EVENT_SET_SIM_POWER_DONE: { |
| 2095 | ar = (AsyncResult) msg.obj; |
| 2096 | request = (MainThreadRequest) ar.userObj; |
| 2097 | IIntegerConsumer callback = |
| 2098 | ((Pair<Integer, IIntegerConsumer>) request.argument).second; |
| 2099 | if (ar.exception != null) { |
| 2100 | loge("setSimPower exception: " + ar.exception); |
| 2101 | int errorCode = TelephonyManager.CallForwardingInfoCallback |
| 2102 | .RESULT_ERROR_UNKNOWN; |
| 2103 | if (ar.exception instanceof CommandException) { |
| 2104 | CommandException.Error error = |
| 2105 | ((CommandException) (ar.exception)).getCommandError(); |
| 2106 | if (error == CommandException.Error.SIM_ERR) { |
| 2107 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR; |
| 2108 | } else if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 2109 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE; |
| 2110 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 2111 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED; |
| 2112 | } else { |
| 2113 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR; |
| 2114 | } |
| 2115 | } |
| 2116 | try { |
| 2117 | callback.accept(errorCode); |
| 2118 | } catch (RemoteException e) { |
| 2119 | // Ignore if the remote process is no longer available to call back. |
| 2120 | Log.w(LOG_TAG, "setSimPower: callback not available."); |
| 2121 | } |
| 2122 | } else { |
| 2123 | try { |
| 2124 | callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS); |
| 2125 | } catch (RemoteException e) { |
| 2126 | // Ignore if the remote process is no longer available to call back. |
| 2127 | Log.w(LOG_TAG, "setSimPower: callback not available."); |
| 2128 | } |
| 2129 | } |
| 2130 | break; |
| 2131 | } |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 2132 | case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: { |
| 2133 | request = (MainThreadRequest) msg.obj; |
| 2134 | |
| 2135 | final Phone phone = getPhoneFromRequest(request); |
| 2136 | if (phone == null || phone.getServiceStateTracker() == null) { |
| 2137 | request.result = new IllegalStateException("Phone or SST is null"); |
| 2138 | notifyRequester(request); |
| 2139 | break; |
| 2140 | } |
| 2141 | |
| 2142 | Pair<Integer, SignalStrengthUpdateRequest> pair = |
| 2143 | (Pair<Integer, SignalStrengthUpdateRequest>) request.argument; |
| 2144 | onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE, |
| 2145 | request); |
Rambo Wang | 6568f17 | 2021-02-03 16:56:47 -0800 | [diff] [blame] | 2146 | phone.getSignalStrengthController().setSignalStrengthUpdateRequest( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2147 | request.subId, pair.first /*callingUid*/, |
| 2148 | pair.second /*request*/, onCompleted); |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 2149 | break; |
| 2150 | } |
| 2151 | case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: { |
| 2152 | ar = (AsyncResult) msg.obj; |
| 2153 | request = (MainThreadRequest) ar.userObj; |
| 2154 | // request.result will be the exception of ar if present, true otherwise. |
| 2155 | // Be cautious not to leave result null which will wait() forever |
| 2156 | request.result = ar.exception != null ? ar.exception : true; |
| 2157 | notifyRequester(request); |
| 2158 | break; |
| 2159 | } |
| 2160 | case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: { |
| 2161 | request = (MainThreadRequest) msg.obj; |
| 2162 | |
| 2163 | Phone phone = getPhoneFromRequest(request); |
| 2164 | if (phone == null || phone.getServiceStateTracker() == null) { |
| 2165 | request.result = new IllegalStateException("Phone or SST is null"); |
| 2166 | notifyRequester(request); |
| 2167 | break; |
| 2168 | } |
| 2169 | |
| 2170 | Pair<Integer, SignalStrengthUpdateRequest> pair = |
| 2171 | (Pair<Integer, SignalStrengthUpdateRequest>) request.argument; |
| 2172 | onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE, |
| 2173 | request); |
Rambo Wang | 6568f17 | 2021-02-03 16:56:47 -0800 | [diff] [blame] | 2174 | phone.getSignalStrengthController().clearSignalStrengthUpdateRequest( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2175 | request.subId, pair.first /*callingUid*/, |
| 2176 | pair.second /*request*/, onCompleted); |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 2177 | break; |
| 2178 | } |
| 2179 | case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: { |
| 2180 | ar = (AsyncResult) msg.obj; |
| 2181 | request = (MainThreadRequest) ar.userObj; |
| 2182 | request.result = ar.exception != null ? ar.exception : true; |
| 2183 | notifyRequester(request); |
| 2184 | break; |
| 2185 | } |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 2186 | |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2187 | case CMD_GET_SLICING_CONFIG: { |
| 2188 | request = (MainThreadRequest) msg.obj; |
| 2189 | onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request); |
| 2190 | request.phone.getSlicingConfig(onCompleted); |
| 2191 | break; |
| 2192 | } |
| 2193 | case EVENT_GET_SLICING_CONFIG_DONE: { |
| 2194 | ar = (AsyncResult) msg.obj; |
| 2195 | request = (MainThreadRequest) ar.userObj; |
| 2196 | ResultReceiver result = (ResultReceiver) request.argument; |
| 2197 | |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2198 | NetworkSlicingConfig slicingConfig = null; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2199 | Bundle bundle = new Bundle(); |
| 2200 | int resultCode = 0; |
| 2201 | if (ar.exception != null) { |
| 2202 | Log.e(LOG_TAG, "Exception retrieving slicing configuration=" |
| 2203 | + ar.exception); |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2204 | resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2205 | } else if (ar.result == null) { |
| 2206 | Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!"); |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2207 | resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2208 | } else { |
| 2209 | // use the result as returned |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2210 | resultCode = TelephonyManager.NetworkSlicingException.SUCCESS; |
| 2211 | slicingConfig = (NetworkSlicingConfig) ar.result; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2212 | } |
| 2213 | |
| 2214 | if (slicingConfig == null) { |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2215 | slicingConfig = new NetworkSlicingConfig(); |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2216 | } |
| 2217 | bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig); |
| 2218 | result.send(resultCode, bundle); |
| 2219 | notifyRequester(request); |
| 2220 | break; |
| 2221 | } |
| 2222 | |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2223 | case CMD_PURCHASE_PREMIUM_CAPABILITY: { |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2224 | request = (MainThreadRequest) msg.obj; |
| 2225 | onCompleted = obtainMessage(EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE, request); |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2226 | PurchasePremiumCapabilityArgument arg = |
| 2227 | (PurchasePremiumCapabilityArgument) request.argument; |
Sarah Chin | 46355ba | 2022-11-01 23:51:16 -0700 | [diff] [blame] | 2228 | SlicePurchaseController.getInstance(request.phone).purchasePremiumCapability( |
Sarah Chin | b8218c2 | 2023-01-04 13:35:29 -0800 | [diff] [blame] | 2229 | arg.capability, onCompleted); |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2230 | break; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2231 | } |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2232 | |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2233 | case EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE: { |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2234 | ar = (AsyncResult) msg.obj; |
| 2235 | request = (MainThreadRequest) ar.userObj; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2236 | PurchasePremiumCapabilityArgument arg = |
| 2237 | (PurchasePremiumCapabilityArgument) request.argument; |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2238 | try { |
| 2239 | int result = (int) ar.result; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2240 | arg.callback.accept(result); |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2241 | log("purchasePremiumCapability: capability=" |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2242 | + TelephonyManager.convertPremiumCapabilityToString(arg.capability) |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2243 | + ", result= " |
| 2244 | + TelephonyManager.convertPurchaseResultToString(result)); |
| 2245 | } catch (RemoteException e) { |
| 2246 | String logStr = "Purchase premium capability " |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2247 | + TelephonyManager.convertPremiumCapabilityToString(arg.capability) |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2248 | + " failed: " + e; |
| 2249 | if (DBG) log(logStr); |
| 2250 | AnomalyReporter.reportAnomaly( |
| 2251 | UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr); |
| 2252 | } |
| 2253 | break; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2254 | } |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2255 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2256 | case CMD_PREPARE_UNATTENDED_REBOOT: |
| 2257 | request = (MainThreadRequest) msg.obj; |
| 2258 | request.result = |
Rafael Higuera Silva | d963064 | 2021-09-20 15:32:01 +0000 | [diff] [blame] | 2259 | UiccController.getInstance().getPinStorage() |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2260 | .prepareUnattendedReboot(request.workSource); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2261 | notifyRequester(request); |
| 2262 | break; |
| 2263 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2264 | default: |
| 2265 | Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what); |
| 2266 | break; |
| 2267 | } |
| 2268 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2269 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 2270 | private void notifyRequester(MainThreadRequest request) { |
| 2271 | synchronized (request) { |
| 2272 | request.notifyAll(); |
| 2273 | } |
| 2274 | } |
| 2275 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2276 | private void handleNullReturnEvent(Message msg, String command) { |
| 2277 | AsyncResult ar = (AsyncResult) msg.obj; |
| 2278 | MainThreadRequest request = (MainThreadRequest) ar.userObj; |
| 2279 | if (ar.exception == null) { |
| 2280 | request.result = true; |
| 2281 | } else { |
| 2282 | request.result = false; |
| 2283 | if (ar.exception instanceof CommandException) { |
| 2284 | loge(command + ": CommandException: " + ar.exception); |
| 2285 | } else { |
| 2286 | loge(command + ": Unknown exception"); |
| 2287 | } |
| 2288 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 2289 | notifyRequester(request); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2290 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2291 | } |
| 2292 | |
| 2293 | /** |
| 2294 | * Posts the specified command to be executed on the main thread, |
| 2295 | * waits for the request to complete, and returns the result. |
| 2296 | * @see #sendRequestAsync |
| 2297 | */ |
| 2298 | private Object sendRequest(int command, Object argument) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2299 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, |
| 2300 | null, -1 /*timeoutInMs*/); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 2301 | } |
| 2302 | |
| 2303 | /** |
| 2304 | * Posts the specified command to be executed on the main thread, |
| 2305 | * waits for the request to complete, and returns the result. |
| 2306 | * @see #sendRequestAsync |
| 2307 | */ |
| 2308 | private Object sendRequest(int command, Object argument, WorkSource workSource) { |
| 2309 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2310 | null, workSource, -1 /*timeoutInMs*/); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2311 | } |
| 2312 | |
| 2313 | /** |
| 2314 | * Posts the specified command to be executed on the main thread, |
| 2315 | * waits for the request to complete, and returns the result. |
| 2316 | * @see #sendRequestAsync |
| 2317 | */ |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2318 | private Object sendRequest(int command, Object argument, Integer subId) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2319 | return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/); |
| 2320 | } |
| 2321 | |
| 2322 | /** |
| 2323 | * Posts the specified command to be executed on the main thread, |
| 2324 | * waits for the request to complete for at most {@code timeoutInMs}, and returns the result |
| 2325 | * if not timeout or null otherwise. |
| 2326 | * @see #sendRequestAsync |
| 2327 | */ |
| 2328 | private @Nullable Object sendRequest(int command, Object argument, Integer subId, |
| 2329 | long timeoutInMs) { |
| 2330 | return sendRequest(command, argument, subId, null, null, timeoutInMs); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 2331 | } |
| 2332 | |
| 2333 | /** |
| 2334 | * Posts the specified command to be executed on the main thread, |
| 2335 | * waits for the request to complete, and returns the result. |
| 2336 | * @see #sendRequestAsync |
| 2337 | */ |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2338 | private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2339 | return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2340 | } |
| 2341 | |
| 2342 | /** |
| 2343 | * Posts the specified command to be executed on the main thread, |
| 2344 | * waits for the request to complete, and returns the result. |
| 2345 | * @see #sendRequestAsync |
| 2346 | */ |
| 2347 | private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2348 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, |
| 2349 | workSource, -1 /*timeoutInMs*/); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2350 | } |
| 2351 | |
| 2352 | /** |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2353 | * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is |
| 2354 | * negative, waits for the request to complete, and returns the result. Otherwise, wait for |
| 2355 | * maximum of {@code timeoutInMs} milliseconds, interrupt and return null. |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2356 | * @see #sendRequestAsync |
| 2357 | */ |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2358 | private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone, |
| 2359 | WorkSource workSource, long timeoutInMs) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2360 | if (Looper.myLooper() == mMainThreadHandler.getLooper()) { |
| 2361 | throw new RuntimeException("This method will deadlock if called from the main thread."); |
| 2362 | } |
| 2363 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2364 | MainThreadRequest request = null; |
| 2365 | if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) { |
| 2366 | throw new IllegalArgumentException("subId and phone cannot both be specified!"); |
| 2367 | } else if (phone != null) { |
| 2368 | request = new MainThreadRequest(argument, phone, workSource); |
| 2369 | } else { |
| 2370 | request = new MainThreadRequest(argument, subId, workSource); |
| 2371 | } |
| 2372 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2373 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 2374 | msg.sendToTarget(); |
| 2375 | |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2376 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2377 | synchronized (request) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2378 | if (timeoutInMs >= 0) { |
| 2379 | // Wait for at least timeoutInMs before returning null request result |
| 2380 | long now = SystemClock.elapsedRealtime(); |
| 2381 | long deadline = now + timeoutInMs; |
Grace Jia | 8a0a1e8 | 2021-05-23 22:59:52 -0700 | [diff] [blame] | 2382 | while (request.result == null && now < deadline) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2383 | try { |
| 2384 | request.wait(deadline - now); |
| 2385 | } catch (InterruptedException e) { |
| 2386 | // Do nothing, go back and check if request is completed or timeout |
| 2387 | } finally { |
| 2388 | now = SystemClock.elapsedRealtime(); |
| 2389 | } |
| 2390 | } |
| 2391 | } else { |
| 2392 | // Wait for the request to complete |
| 2393 | while (request.result == null) { |
| 2394 | try { |
| 2395 | request.wait(); |
| 2396 | } catch (InterruptedException e) { |
| 2397 | // Do nothing, go back and wait until the request is complete |
| 2398 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2399 | } |
| 2400 | } |
| 2401 | } |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2402 | if (request.result == null) { |
| 2403 | Log.wtf(LOG_TAG, |
| 2404 | "sendRequest: Blocking command timed out. Something has gone terribly wrong."); |
| 2405 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2406 | return request.result; |
| 2407 | } |
| 2408 | |
| 2409 | /** |
| 2410 | * Asynchronous ("fire and forget") version of sendRequest(): |
| 2411 | * Posts the specified command to be executed on the main thread, and |
| 2412 | * returns immediately. |
| 2413 | * @see #sendRequest |
| 2414 | */ |
| 2415 | private void sendRequestAsync(int command) { |
| 2416 | mMainThreadHandler.sendEmptyMessage(command); |
| 2417 | } |
| 2418 | |
| 2419 | /** |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2420 | * Same as {@link #sendRequestAsync(int)} except it takes an argument. |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2421 | * @see {@link #sendRequest(int)} |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2422 | */ |
| 2423 | private void sendRequestAsync(int command, Object argument) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2424 | sendRequestAsync(command, argument, null, null); |
| 2425 | } |
| 2426 | |
| 2427 | /** |
| 2428 | * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource. |
| 2429 | * @see {@link #sendRequest(int,Object)} |
| 2430 | */ |
| 2431 | private void sendRequestAsync( |
| 2432 | int command, Object argument, Phone phone, WorkSource workSource) { |
| 2433 | MainThreadRequest request = new MainThreadRequest(argument, phone, workSource); |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2434 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 2435 | msg.sendToTarget(); |
| 2436 | } |
| 2437 | |
| 2438 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2439 | * Initialize the singleton PhoneInterfaceManager instance. |
| 2440 | * This is only done once, at startup, from PhoneApp.onCreate(). |
| 2441 | */ |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2442 | /* package */ static PhoneInterfaceManager init(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2443 | synchronized (PhoneInterfaceManager.class) { |
| 2444 | if (sInstance == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2445 | sInstance = new PhoneInterfaceManager(app); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2446 | } else { |
| 2447 | Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance); |
| 2448 | } |
| 2449 | return sInstance; |
| 2450 | } |
| 2451 | } |
| 2452 | |
| 2453 | /** Private constructor; @see init() */ |
Jordan Liu | 1979a04 | 2020-03-20 21:39:35 +0000 | [diff] [blame] | 2454 | private PhoneInterfaceManager(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2455 | mApp = app; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2456 | mCM = PhoneGlobals.getInstance().mCM; |
Brad Ebinger | d1947d8 | 2021-05-17 20:54:49 +0000 | [diff] [blame] | 2457 | mImsResolver = ImsResolver.getInstance(); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 2458 | mSatelliteController = SatelliteController.getInstance(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 2459 | mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2460 | mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE); |
| 2461 | mMainThreadHandler = new MainThreadHandler(); |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 2462 | mTelephonySharedPreferences = PreferenceManager.getDefaultSharedPreferences(mApp); |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 2463 | mNetworkScanRequestTracker = new NetworkScanRequestTracker(); |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 2464 | mPhoneConfigurationManager = PhoneConfigurationManager.getInstance(); |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 2465 | mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance(); |
Peter Wang | a3cf4ac | 2020-01-27 09:39:46 +0800 | [diff] [blame] | 2466 | mNotifyUserActivity = new AtomicBoolean(false); |
Tyler Gunn | 64144d9 | 2022-03-17 14:16:41 -0700 | [diff] [blame] | 2467 | PropertyInvalidatedCache.invalidateCache(TelephonyManager.CACHE_KEY_PHONE_ACCOUNT_TO_SUBID); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2468 | publish(); |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 2469 | CarrierAllowListInfo.loadInstance(mApp); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2470 | } |
| 2471 | |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 2472 | @VisibleForTesting |
| 2473 | public SharedPreferences getSharedPreferences() { |
| 2474 | return mTelephonySharedPreferences; |
| 2475 | } |
| 2476 | |
Gil Cukierman | 92cc7db | 2023-01-06 19:25:53 +0000 | [diff] [blame] | 2477 | /** |
| 2478 | * Get the default phone for this device. |
| 2479 | */ |
| 2480 | @VisibleForTesting |
| 2481 | public Phone getDefaultPhone() { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2482 | Phone thePhone = getPhone(getDefaultSubscription()); |
| 2483 | return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone(); |
| 2484 | } |
| 2485 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2486 | private void publish() { |
| 2487 | if (DBG) log("publish: " + this); |
| 2488 | |
Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 2489 | TelephonyFrameworkInitializer |
| 2490 | .getTelephonyServiceManager() |
| 2491 | .getTelephonyServiceRegisterer() |
| 2492 | .register(this); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2493 | } |
| 2494 | |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 2495 | private Phone getPhoneFromRequest(MainThreadRequest request) { |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 2496 | if (request.phone != null) { |
| 2497 | return request.phone; |
| 2498 | } else { |
| 2499 | return getPhoneFromSubId(request.subId); |
| 2500 | } |
| 2501 | } |
| 2502 | |
| 2503 | private Phone getPhoneFromSubId(int subId) { |
| 2504 | return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) |
| 2505 | ? getDefaultPhone() : getPhone(subId); |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 2506 | } |
| 2507 | |
Aishwarya Mallampati | 5e581e1 | 2023-01-17 21:57:06 +0000 | [diff] [blame] | 2508 | /** |
| 2509 | * Get phone object associated with a subscription. |
| 2510 | * Return default phone if phone object associated with subscription is null |
| 2511 | * @param subId - subscriptionId |
| 2512 | * @return phone object associated with a subscription or default phone if null. |
| 2513 | */ |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 2514 | private @NonNull Phone getPhoneFromSubIdOrDefault(int subId) { |
Aishwarya Mallampati | 5e581e1 | 2023-01-17 21:57:06 +0000 | [diff] [blame] | 2515 | Phone phone = getPhoneFromSubId(subId); |
| 2516 | if (phone == null) { |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 2517 | loge("Called with invalid subId: " + subId + ". Retrying with default phone."); |
Aishwarya Mallampati | 5e581e1 | 2023-01-17 21:57:06 +0000 | [diff] [blame] | 2518 | phone = getDefaultPhone(); |
| 2519 | } |
| 2520 | return phone; |
| 2521 | } |
| 2522 | |
Rambo Wang | e53e07d | 2022-05-10 13:01:13 -0700 | [diff] [blame] | 2523 | @Nullable |
| 2524 | private UiccPort getUiccPortFromRequest(@NonNull MainThreadRequest request) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2525 | Phone phone = getPhoneFromRequest(request); |
| 2526 | return phone == null ? null : |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 2527 | UiccController.getInstance().getUiccPort(phone.getPhoneId()); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2528 | } |
| 2529 | |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 2530 | /** |
| 2531 | * @param subId The sub Id that associates the phone. If the device has no active SIM, passing |
| 2532 | * in {@link SubscriptionManager#DEFAULT_SUBSCRIPTION_ID} or any sub <= |
| 2533 | * {@link SubscriptionManager#INVALID_SUBSCRIPTION_ID} will return {@code null}. |
| 2534 | * @return The Phone associated the sub Id |
| 2535 | */ |
| 2536 | private @Nullable Phone getPhone(int subId) { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 2537 | return PhoneFactory.getPhone(SubscriptionManager.getPhoneId(subId)); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2538 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2539 | |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 2540 | private void sendEraseModemConfig(@NonNull Phone phone) { |
| 2541 | Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null); |
| 2542 | if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 2543 | } |
| 2544 | |
| 2545 | private void sendEraseDataInSharedPreferences(@NonNull Phone phone) { |
| 2546 | Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null); |
| 2547 | if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail")); |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 2548 | } |
| 2549 | |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 2550 | private boolean isImsAvailableOnDevice() { |
| 2551 | PackageManager pm = getDefaultPhone().getContext().getPackageManager(); |
| 2552 | if (pm == null) { |
| 2553 | // For some reason package manger is not available.. This will fail internally anyway, |
| 2554 | // so do not throw error and allow. |
| 2555 | return true; |
| 2556 | } |
| 2557 | return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0); |
| 2558 | } |
| 2559 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2560 | public void dial(String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2561 | dialForSubscriber(getPreferredVoiceSubscription(), number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2562 | } |
| 2563 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2564 | public void dialForSubscriber(int subId, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2565 | if (DBG) log("dial: " + number); |
| 2566 | // No permission check needed here: This is just a wrapper around the |
| 2567 | // ACTION_DIAL intent, which is available to any app since it puts up |
| 2568 | // the UI before it does anything. |
| 2569 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2570 | final long identity = Binder.clearCallingIdentity(); |
| 2571 | try { |
| 2572 | String url = createTelUrl(number); |
| 2573 | if (url == null) { |
| 2574 | return; |
| 2575 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2576 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2577 | // PENDING: should we just silently fail if phone is offhook or ringing? |
| 2578 | PhoneConstants.State state = mCM.getState(subId); |
| 2579 | if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) { |
| 2580 | Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url)); |
| 2581 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2582 | mApp.startActivity(intent); |
| 2583 | } |
| 2584 | } finally { |
| 2585 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2586 | } |
| 2587 | } |
| 2588 | |
| 2589 | public void call(String callingPackage, String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2590 | callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2591 | } |
| 2592 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2593 | public void callForSubscriber(int subId, String callingPackage, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2594 | if (DBG) log("call: " + number); |
| 2595 | |
| 2596 | // This is just a wrapper around the ACTION_CALL intent, but we still |
| 2597 | // need to do a permission check since we're calling startActivity() |
| 2598 | // from the context of the phone app. |
| 2599 | enforceCallPermission(); |
| 2600 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 2601 | if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage) |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2602 | != AppOpsManager.MODE_ALLOWED) { |
| 2603 | return; |
| 2604 | } |
| 2605 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2606 | final long identity = Binder.clearCallingIdentity(); |
| 2607 | try { |
| 2608 | String url = createTelUrl(number); |
| 2609 | if (url == null) { |
| 2610 | return; |
| 2611 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2612 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2613 | boolean isValid = false; |
| 2614 | final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged(); |
| 2615 | if (slist != null) { |
| 2616 | for (SubscriptionInfo subInfoRecord : slist) { |
| 2617 | if (subInfoRecord.getSubscriptionId() == subId) { |
| 2618 | isValid = true; |
| 2619 | break; |
| 2620 | } |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 2621 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 2622 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2623 | if (!isValid) { |
| 2624 | return; |
| 2625 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 2626 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2627 | Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url)); |
| 2628 | intent.putExtra(SUBSCRIPTION_KEY, subId); |
| 2629 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2630 | mApp.startActivity(intent); |
| 2631 | } finally { |
| 2632 | Binder.restoreCallingIdentity(identity); |
| 2633 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2634 | } |
| 2635 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2636 | public boolean supplyPinForSubscriber(int subId, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2637 | int [] resultArray = supplyPinReportResultForSubscriber(subId, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2638 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 2639 | } |
| 2640 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2641 | public boolean supplyPukForSubscriber(int subId, String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2642 | int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2643 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 2644 | } |
| 2645 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2646 | public int[] supplyPinReportResultForSubscriber(int subId, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2647 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2648 | |
| 2649 | final long identity = Binder.clearCallingIdentity(); |
| 2650 | try { |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2651 | Phone phone = getPhone(subId); |
| 2652 | final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2653 | checkSimPin.start(); |
| 2654 | return checkSimPin.unlockSim(null, pin); |
| 2655 | } finally { |
| 2656 | Binder.restoreCallingIdentity(identity); |
| 2657 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2658 | } |
| 2659 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2660 | public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2661 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2662 | |
| 2663 | final long identity = Binder.clearCallingIdentity(); |
| 2664 | try { |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2665 | Phone phone = getPhone(subId); |
| 2666 | final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2667 | checkSimPuk.start(); |
| 2668 | return checkSimPuk.unlockSim(puk, pin); |
| 2669 | } finally { |
| 2670 | Binder.restoreCallingIdentity(identity); |
| 2671 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2672 | } |
| 2673 | |
| 2674 | /** |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2675 | * Helper thread to turn async call to SimCard#supplyPin into |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2676 | * a synchronous one. |
| 2677 | */ |
| 2678 | private static class UnlockSim extends Thread { |
| 2679 | |
| 2680 | private final IccCard mSimCard; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2681 | private final int mPhoneId; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2682 | |
| 2683 | private boolean mDone = false; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2684 | private int mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 2685 | private int mRetryCount = -1; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2686 | |
| 2687 | // For replies from SimCard interface |
| 2688 | private Handler mHandler; |
| 2689 | |
| 2690 | // For async handler to identify request type |
| 2691 | private static final int SUPPLY_PIN_COMPLETE = 100; |
| 2692 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2693 | UnlockSim(int phoneId, IccCard simCard) { |
| 2694 | mPhoneId = phoneId; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2695 | mSimCard = simCard; |
| 2696 | } |
| 2697 | |
| 2698 | @Override |
| 2699 | public void run() { |
| 2700 | Looper.prepare(); |
| 2701 | synchronized (UnlockSim.this) { |
| 2702 | mHandler = new Handler() { |
| 2703 | @Override |
| 2704 | public void handleMessage(Message msg) { |
| 2705 | AsyncResult ar = (AsyncResult) msg.obj; |
| 2706 | switch (msg.what) { |
| 2707 | case SUPPLY_PIN_COMPLETE: |
| 2708 | Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE"); |
| 2709 | synchronized (UnlockSim.this) { |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2710 | mRetryCount = msg.arg1; |
| 2711 | if (ar.exception != null) { |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2712 | CommandException.Error error = null; |
| 2713 | if (ar.exception instanceof CommandException) { |
| 2714 | error = ((CommandException) (ar.exception)) |
| 2715 | .getCommandError(); |
| 2716 | } |
| 2717 | if (error == CommandException.Error.PASSWORD_INCORRECT) { |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2718 | mResult = PhoneConstants.PIN_PASSWORD_INCORRECT; |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2719 | } else if (error == CommandException.Error.ABORTED) { |
| 2720 | /* When UiccCardApp dispose, handle message and return |
| 2721 | exception */ |
vivi.li | b5e9ada | 2019-09-12 16:04:24 +0800 | [diff] [blame] | 2722 | mResult = PhoneConstants.PIN_OPERATION_ABORTED; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2723 | } else { |
| 2724 | mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 2725 | } |
| 2726 | } else { |
| 2727 | mResult = PhoneConstants.PIN_RESULT_SUCCESS; |
| 2728 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2729 | mDone = true; |
| 2730 | UnlockSim.this.notifyAll(); |
| 2731 | } |
| 2732 | break; |
| 2733 | } |
| 2734 | } |
| 2735 | }; |
| 2736 | UnlockSim.this.notifyAll(); |
| 2737 | } |
| 2738 | Looper.loop(); |
| 2739 | } |
| 2740 | |
| 2741 | /* |
| 2742 | * Use PIN or PUK to unlock SIM card |
| 2743 | * |
| 2744 | * If PUK is null, unlock SIM card with PIN |
| 2745 | * |
| 2746 | * If PUK is not null, unlock SIM card with PUK and set PIN code |
| 2747 | */ |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2748 | synchronized int[] unlockSim(String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2749 | |
| 2750 | while (mHandler == null) { |
| 2751 | try { |
| 2752 | wait(); |
| 2753 | } catch (InterruptedException e) { |
| 2754 | Thread.currentThread().interrupt(); |
| 2755 | } |
| 2756 | } |
| 2757 | Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE); |
| 2758 | |
| 2759 | if (puk == null) { |
| 2760 | mSimCard.supplyPin(pin, callback); |
| 2761 | } else { |
| 2762 | mSimCard.supplyPuk(puk, pin, callback); |
| 2763 | } |
| 2764 | |
| 2765 | while (!mDone) { |
| 2766 | try { |
| 2767 | Log.d(LOG_TAG, "wait for done"); |
| 2768 | wait(); |
| 2769 | } catch (InterruptedException e) { |
| 2770 | // Restore the interrupted status |
| 2771 | Thread.currentThread().interrupt(); |
| 2772 | } |
| 2773 | } |
| 2774 | Log.d(LOG_TAG, "done"); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2775 | int[] resultArray = new int[2]; |
| 2776 | resultArray[0] = mResult; |
| 2777 | resultArray[1] = mRetryCount; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2778 | |
| 2779 | if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) { |
Jon Spivack | 9c3bc76 | 2021-10-06 20:53:09 +0000 | [diff] [blame] | 2780 | UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2781 | } |
| 2782 | |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2783 | return resultArray; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2784 | } |
| 2785 | } |
| 2786 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2787 | /** |
| 2788 | * This method has been removed due to privacy and stability concerns. |
| 2789 | */ |
| 2790 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2791 | public void updateServiceLocation() { |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2792 | Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()"); |
| 2793 | return; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2794 | } |
| 2795 | |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2796 | @Override |
| 2797 | public void updateServiceLocationWithPackageName(String callingPackage) { |
| 2798 | mApp.getSystemService(AppOpsManager.class) |
| 2799 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 2800 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 2801 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2802 | if (targetSdk > android.os.Build.VERSION_CODES.R) { |
| 2803 | // Callers targeting S have no business invoking this method. |
| 2804 | return; |
| 2805 | } |
| 2806 | |
| 2807 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2808 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2809 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2810 | .setCallingPackage(callingPackage) |
| 2811 | .setCallingFeatureId(null) |
| 2812 | .setCallingPid(Binder.getCallingPid()) |
| 2813 | .setCallingUid(Binder.getCallingUid()) |
| 2814 | .setMethod("updateServiceLocation") |
| 2815 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
| 2816 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2817 | .build()); |
| 2818 | // Apps that lack location permission have no business calling this method; |
| 2819 | // however, because no permission was declared in the public API, denials must |
| 2820 | // all be "soft". |
| 2821 | switch (locationResult) { |
| 2822 | case DENIED_HARD: /* fall through */ |
| 2823 | case DENIED_SOFT: |
| 2824 | return; |
| 2825 | } |
| 2826 | |
| 2827 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2828 | final long identity = Binder.clearCallingIdentity(); |
| 2829 | try { |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 2830 | getPhoneFromSubIdOrDefault(getDefaultSubscription()).updateServiceLocation(workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2831 | } finally { |
| 2832 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2833 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2834 | } |
| 2835 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2836 | @Deprecated |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2837 | @Override |
| 2838 | public boolean isRadioOn(String callingPackage) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2839 | return isRadioOnWithFeature(callingPackage, null); |
| 2840 | } |
| 2841 | |
| 2842 | |
| 2843 | @Override |
| 2844 | public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) { |
| 2845 | return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage, |
| 2846 | callingFeatureId); |
| 2847 | } |
| 2848 | |
| 2849 | @Deprecated |
| 2850 | @Override |
| 2851 | public boolean isRadioOnForSubscriber(int subId, String callingPackage) { |
| 2852 | return isRadioOnForSubscriberWithFeature(subId, callingPackage, null); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2853 | } |
| 2854 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2855 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2856 | public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage, |
| 2857 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2858 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2859 | mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2860 | return false; |
| 2861 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2862 | |
| 2863 | final long identity = Binder.clearCallingIdentity(); |
| 2864 | try { |
| 2865 | return isRadioOnForSubscriber(subId); |
| 2866 | } finally { |
| 2867 | Binder.restoreCallingIdentity(identity); |
| 2868 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2869 | } |
| 2870 | |
| 2871 | private boolean isRadioOnForSubscriber(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2872 | final long identity = Binder.clearCallingIdentity(); |
| 2873 | try { |
| 2874 | final Phone phone = getPhone(subId); |
| 2875 | if (phone != null) { |
| 2876 | return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF; |
| 2877 | } else { |
| 2878 | return false; |
| 2879 | } |
| 2880 | } finally { |
| 2881 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2882 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2883 | } |
| 2884 | |
| 2885 | public void toggleRadioOnOff() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2886 | toggleRadioOnOffForSubscriber(getDefaultSubscription()); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2887 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2888 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2889 | public void toggleRadioOnOffForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2890 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2891 | |
| 2892 | final long identity = Binder.clearCallingIdentity(); |
| 2893 | try { |
| 2894 | final Phone phone = getPhone(subId); |
| 2895 | if (phone != null) { |
| 2896 | phone.setRadioPower(!isRadioOnForSubscriber(subId)); |
| 2897 | } |
| 2898 | } finally { |
| 2899 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2900 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2901 | } |
| 2902 | |
| 2903 | public boolean setRadio(boolean turnOn) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2904 | return setRadioForSubscriber(getDefaultSubscription(), turnOn); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2905 | } |
| 2906 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2907 | public boolean setRadioForSubscriber(int subId, boolean turnOn) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2908 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2909 | |
| 2910 | final long identity = Binder.clearCallingIdentity(); |
| 2911 | try { |
| 2912 | final Phone phone = getPhone(subId); |
| 2913 | if (phone == null) { |
| 2914 | return false; |
| 2915 | } |
| 2916 | if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) { |
| 2917 | toggleRadioOnOffForSubscriber(subId); |
| 2918 | } |
| 2919 | return true; |
| 2920 | } finally { |
| 2921 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2922 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2923 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2924 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2925 | public boolean needMobileRadioShutdown() { |
Shuo Qian | fa7b6b3 | 2019-12-10 10:40:38 -0800 | [diff] [blame] | 2926 | enforceReadPrivilegedPermission("needMobileRadioShutdown"); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2927 | /* |
| 2928 | * If any of the Radios are available, it will need to be |
| 2929 | * shutdown. So return true if any Radio is available. |
| 2930 | */ |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2931 | final long identity = Binder.clearCallingIdentity(); |
| 2932 | try { |
| 2933 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 2934 | Phone phone = PhoneFactory.getPhone(i); |
| 2935 | if (phone != null && phone.isRadioAvailable()) return true; |
| 2936 | } |
| 2937 | logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown."); |
| 2938 | return false; |
| 2939 | } finally { |
| 2940 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2941 | } |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2942 | } |
| 2943 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2944 | @Override |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2945 | public void shutdownMobileRadios() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2946 | enforceModifyPermission(); |
| 2947 | |
| 2948 | final long identity = Binder.clearCallingIdentity(); |
| 2949 | try { |
| 2950 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 2951 | logv("Shutting down Phone " + i); |
| 2952 | shutdownRadioUsingPhoneId(i); |
| 2953 | } |
| 2954 | } finally { |
| 2955 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2956 | } |
| 2957 | } |
| 2958 | |
| 2959 | private void shutdownRadioUsingPhoneId(int phoneId) { |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2960 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 2961 | if (phone != null && phone.isRadioAvailable()) { |
| 2962 | phone.shutdownRadio(); |
| 2963 | } |
| 2964 | } |
| 2965 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2966 | public boolean setRadioPower(boolean turnOn) { |
Jack Yu | b4e1616 | 2017-05-15 12:48:40 -0700 | [diff] [blame] | 2967 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2968 | |
Ling Ma | 83dc5ea | 2023-01-12 15:06:04 -0800 | [diff] [blame] | 2969 | if (!turnOn) { |
| 2970 | log("setRadioPower off: callingPackage=" + getCurrentPackageName()); |
| 2971 | } |
| 2972 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2973 | final long identity = Binder.clearCallingIdentity(); |
| 2974 | try { |
| 2975 | final Phone defaultPhone = PhoneFactory.getDefaultPhone(); |
| 2976 | if (defaultPhone != null) { |
| 2977 | defaultPhone.setRadioPower(turnOn); |
| 2978 | return true; |
| 2979 | } else { |
| 2980 | loge("There's no default phone."); |
| 2981 | return false; |
| 2982 | } |
| 2983 | } finally { |
| 2984 | Binder.restoreCallingIdentity(identity); |
Wei Liu | 9ae2a06 | 2016-08-08 11:09:34 -0700 | [diff] [blame] | 2985 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2986 | } |
| 2987 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2988 | public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2989 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2990 | |
Ling Ma | 83dc5ea | 2023-01-12 15:06:04 -0800 | [diff] [blame] | 2991 | if (!turnOn) { |
| 2992 | log("setRadioPowerForSubscriber off: subId=" + subId |
| 2993 | + ",callingPackage=" + getCurrentPackageName()); |
| 2994 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2995 | final long identity = Binder.clearCallingIdentity(); |
| 2996 | try { |
| 2997 | final Phone phone = getPhone(subId); |
| 2998 | if (phone != null) { |
| 2999 | phone.setRadioPower(turnOn); |
| 3000 | return true; |
| 3001 | } else { |
| 3002 | return false; |
| 3003 | } |
| 3004 | } finally { |
| 3005 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3006 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3007 | } |
| 3008 | |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3009 | /** |
| 3010 | * Vote on powering off the radio for a reason. The radio will be turned on only when there is |
| 3011 | * no reason to power it off. When any of the voters want to power it off, it will be turned |
| 3012 | * off. In case of emergency, the radio will be turned on even if there are some reasons for |
| 3013 | * powering it off, and these radio off votes will be cleared. |
| 3014 | * Multiple apps can vote for the same reason and the last vote will take effect. Each app is |
| 3015 | * responsible for its vote. A powering-off vote of a reason will be maintained until it is |
| 3016 | * cleared by calling {@link clearRadioPowerOffForReason} for that reason, or an emergency call |
| 3017 | * is made, or the device is rebooted. When an app comes backup from a crash, it needs to make |
| 3018 | * sure if its vote is as expected. An app can use the API {@link getRadioPowerOffReasons} to |
| 3019 | * check its vote. |
| 3020 | * |
| 3021 | * @param subId The subscription ID. |
| 3022 | * @param reason The reason for powering off radio. |
| 3023 | * @return true on success and false on failure. |
| 3024 | */ |
| 3025 | public boolean requestRadioPowerOffForReason(int subId, |
| 3026 | @TelephonyManager.RadioPowerReason int reason) { |
| 3027 | enforceModifyPermission(); |
| 3028 | |
Ling Ma | 83dc5ea | 2023-01-12 15:06:04 -0800 | [diff] [blame] | 3029 | log("requestRadioPowerOffForReason: subId=" + subId |
| 3030 | + ",reason=" + reason + ",callingPackage=" + getCurrentPackageName()); |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3031 | final long identity = Binder.clearCallingIdentity(); |
| 3032 | try { |
Thomas Nguyen | b47fc3c | 2023-04-06 13:30:32 -0700 | [diff] [blame] | 3033 | final Phone phone = getPhoneFromSubIdOrDefault(subId); |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3034 | if (phone != null) { |
| 3035 | phone.setRadioPowerForReason(false, reason); |
| 3036 | return true; |
| 3037 | } else { |
Thomas Nguyen | b47fc3c | 2023-04-06 13:30:32 -0700 | [diff] [blame] | 3038 | loge("requestRadioPowerOffForReason: phone is null"); |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3039 | return false; |
| 3040 | } |
| 3041 | } finally { |
| 3042 | Binder.restoreCallingIdentity(identity); |
| 3043 | } |
| 3044 | } |
| 3045 | |
| 3046 | /** |
| 3047 | * Remove the vote on powering off the radio for a reason, as requested by |
| 3048 | * {@link requestRadioPowerOffForReason}. |
| 3049 | * |
| 3050 | * @param subId The subscription ID. |
| 3051 | * @param reason The reason for powering off radio. |
| 3052 | * @return true on success and false on failure. |
| 3053 | */ |
| 3054 | public boolean clearRadioPowerOffForReason(int subId, |
| 3055 | @TelephonyManager.RadioPowerReason int reason) { |
| 3056 | enforceModifyPermission(); |
| 3057 | |
| 3058 | final long identity = Binder.clearCallingIdentity(); |
| 3059 | try { |
Thomas Nguyen | b47fc3c | 2023-04-06 13:30:32 -0700 | [diff] [blame] | 3060 | final Phone phone = getPhoneFromSubIdOrDefault(subId); |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3061 | if (phone != null) { |
| 3062 | phone.setRadioPowerForReason(true, reason); |
| 3063 | return true; |
| 3064 | } else { |
Thomas Nguyen | b47fc3c | 2023-04-06 13:30:32 -0700 | [diff] [blame] | 3065 | loge("clearRadioPowerOffForReason: phone is null"); |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3066 | return false; |
| 3067 | } |
| 3068 | } finally { |
| 3069 | Binder.restoreCallingIdentity(identity); |
| 3070 | } |
| 3071 | } |
| 3072 | |
| 3073 | /** |
| 3074 | * Get reasons for powering off radio, as requested by {@link requestRadioPowerOffForReason}. |
| 3075 | * |
| 3076 | * @param subId The subscription ID. |
| 3077 | * @param callingPackage The package making the call. |
| 3078 | * @param callingFeatureId The feature in the package. |
| 3079 | * @return List of reasons for powering off radio. |
| 3080 | */ |
| 3081 | public List getRadioPowerOffReasons(int subId, String callingPackage, String callingFeatureId) { |
| 3082 | enforceReadPrivilegedPermission("getRadioPowerOffReasons"); |
| 3083 | |
| 3084 | final long identity = Binder.clearCallingIdentity(); |
| 3085 | List result = new ArrayList(); |
| 3086 | try { |
| 3087 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, |
| 3088 | callingPackage, callingFeatureId, "getRadioPowerOffReasons")) { |
| 3089 | return result; |
| 3090 | } |
| 3091 | |
Thomas Nguyen | b47fc3c | 2023-04-06 13:30:32 -0700 | [diff] [blame] | 3092 | final Phone phone = getPhoneFromSubIdOrDefault(subId); |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3093 | if (phone != null) { |
| 3094 | result.addAll(phone.getRadioPowerOffReasons()); |
Thomas Nguyen | b47fc3c | 2023-04-06 13:30:32 -0700 | [diff] [blame] | 3095 | } else { |
| 3096 | loge("getRadioPowerOffReasons: phone is null"); |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 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 { |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 3211 | Phone phone = getPhoneFromSubIdOrDefault(getDefaultSubscription()); |
| 3212 | return PhoneConstantConversions.convertCallState(phone.getState()); |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 3213 | } finally { |
| 3214 | Binder.restoreCallingIdentity(identity); |
| 3215 | } |
| 3216 | } |
| 3217 | |
| 3218 | @Override |
| 3219 | public int getCallStateForSubscription(int subId, String callingPackage, String featureId) { |
| 3220 | if (CompatChanges.isChangeEnabled( |
| 3221 | TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION, |
| 3222 | Binder.getCallingUid())) { |
| 3223 | // Check READ_PHONE_STATE for API version 31+ |
| 3224 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage, |
| 3225 | featureId, "getCallStateForSubscription")) { |
| 3226 | throw new SecurityException("getCallState requires READ_PHONE_STATE for apps " |
| 3227 | + "targeting API level 31+."); |
| 3228 | } |
| 3229 | } |
| 3230 | final long identity = Binder.clearCallingIdentity(); |
| 3231 | try { |
| 3232 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3233 | return phone == null ? TelephonyManager.CALL_STATE_IDLE : |
| 3234 | PhoneConstantConversions.convertCallState(phone.getState()); |
| 3235 | } finally { |
| 3236 | Binder.restoreCallingIdentity(identity); |
| 3237 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3238 | } |
| 3239 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3240 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 3241 | public int getDataState() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3242 | return getDataStateForSubId(SubscriptionManager.getDefaultDataSubscriptionId()); |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 3243 | } |
| 3244 | |
| 3245 | @Override |
| 3246 | public int getDataStateForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3247 | final long identity = Binder.clearCallingIdentity(); |
| 3248 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 3249 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3250 | if (phone != null) { |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 3251 | return phone.getDataNetworkController().getInternetDataNetworkState(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3252 | } else { |
| 3253 | return PhoneConstantConversions.convertDataState( |
| 3254 | PhoneConstants.DataState.DISCONNECTED); |
| 3255 | } |
| 3256 | } finally { |
| 3257 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3258 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3259 | } |
| 3260 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3261 | @Override |
Jack Yu | 0eda684 | 2022-04-18 00:34:46 -0700 | [diff] [blame] | 3262 | public @DataActivityType int getDataActivity() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3263 | return getDataActivityForSubId(SubscriptionManager.getDefaultDataSubscriptionId()); |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 3264 | } |
| 3265 | |
| 3266 | @Override |
Jack Yu | 0eda684 | 2022-04-18 00:34:46 -0700 | [diff] [blame] | 3267 | public @DataActivityType int getDataActivityForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3268 | final long identity = Binder.clearCallingIdentity(); |
| 3269 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 3270 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3271 | if (phone != null) { |
Jack Yu | 0eda684 | 2022-04-18 00:34:46 -0700 | [diff] [blame] | 3272 | return phone.getDataActivityState(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3273 | } else { |
| 3274 | return TelephonyManager.DATA_ACTIVITY_NONE; |
| 3275 | } |
| 3276 | } finally { |
| 3277 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3278 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3279 | } |
| 3280 | |
| 3281 | @Override |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 3282 | public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3283 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 3284 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3285 | |
| 3286 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 3287 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 3288 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 3289 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3290 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3291 | .setCallingPid(Binder.getCallingPid()) |
| 3292 | .setCallingUid(Binder.getCallingUid()) |
| 3293 | .setMethod("getCellLocation") |
Hall Liu | 773ba02 | 2020-01-24 18:07:12 -0800 | [diff] [blame] | 3294 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3295 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 3296 | .build()); |
| 3297 | switch (locationResult) { |
| 3298 | case DENIED_HARD: |
| 3299 | throw new SecurityException("Not allowed to access cell location"); |
| 3300 | case DENIED_SOFT: |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 3301 | return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
| 3302 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3303 | } |
| 3304 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 3305 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3306 | final long identity = Binder.clearCallingIdentity(); |
| 3307 | try { |
| 3308 | if (DBG_LOC) log("getCellLocation: is active user"); |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3309 | int subId = SubscriptionManager.getDefaultDataSubscriptionId(); |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 3310 | return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3311 | } finally { |
| 3312 | Binder.restoreCallingIdentity(identity); |
| 3313 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 3314 | } |
| 3315 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3316 | @Override |
Jack Yu | eb1e7fe | 2020-02-22 19:38:58 -0800 | [diff] [blame] | 3317 | public String getNetworkCountryIsoForPhone(int phoneId) { |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3318 | // Reporting the correct network country is ambiguous when IWLAN could conflict with |
| 3319 | // registered cell info, so return a NULL country instead. |
| 3320 | final long identity = Binder.clearCallingIdentity(); |
| 3321 | try { |
Malcolm Chen | 3732c2b | 2018-07-18 20:15:24 -0700 | [diff] [blame] | 3322 | if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) { |
| 3323 | // Get default phone in this case. |
| 3324 | phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX; |
| 3325 | } |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3326 | final int subId = SubscriptionManager.getSubscriptionId(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3327 | Phone phone = PhoneFactory.getPhone(phoneId); |
Nathan Harold | 532f51c | 2020-04-21 19:31:10 -0700 | [diff] [blame] | 3328 | if (phone == null) return ""; |
| 3329 | ServiceStateTracker sst = phone.getServiceStateTracker(); |
| 3330 | if (sst == null) return ""; |
| 3331 | LocaleTracker lt = sst.getLocaleTracker(); |
| 3332 | if (lt == null) return ""; |
Shuo Qian | 9418a92 | 2021-03-09 11:21:16 -0800 | [diff] [blame] | 3333 | return lt.getCurrentCountry(); |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3334 | } finally { |
| 3335 | Binder.restoreCallingIdentity(identity); |
| 3336 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3337 | } |
| 3338 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 3339 | /** |
| 3340 | * This method was removed due to potential issues caused by performing partial |
| 3341 | * updates of service state, and lack of a credible use case. |
| 3342 | * |
| 3343 | * This has the ability to break the telephony implementation by disabling notification of |
| 3344 | * changes in device connectivity. DO NOT USE THIS! |
| 3345 | */ |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3346 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3347 | public void enableLocationUpdates() { |
| 3348 | mApp.enforceCallingOrSelfPermission( |
| 3349 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3350 | } |
| 3351 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 3352 | /** |
| 3353 | * This method was removed due to potential issues caused by performing partial |
| 3354 | * updates of service state, and lack of a credible use case. |
| 3355 | * |
| 3356 | * This has the ability to break the telephony implementation by disabling notification of |
| 3357 | * changes in device connectivity. DO NOT USE THIS! |
| 3358 | */ |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3359 | @Override |
| 3360 | public void disableLocationUpdates() { |
| 3361 | mApp.enforceCallingOrSelfPermission( |
| 3362 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3363 | } |
| 3364 | |
| 3365 | @Override |
| 3366 | @SuppressWarnings("unchecked") |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3367 | public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage, |
| 3368 | String callingFeatureId) { |
Nathan Harold | b55f63b | 2021-07-27 11:27:38 -0700 | [diff] [blame] | 3369 | try { |
| 3370 | mApp.getSystemService(AppOpsManager.class) |
| 3371 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 3372 | } catch (SecurityException e) { |
| 3373 | EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid()); |
| 3374 | throw e; |
| 3375 | } |
| 3376 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3377 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | dbea45a | 2018-08-30 14:35:07 -0700 | [diff] [blame] | 3378 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 3379 | throw new SecurityException( |
| 3380 | "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels."); |
| 3381 | } |
Nathan Harold | b4d5561 | 2018-07-20 13:13:08 -0700 | [diff] [blame] | 3382 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 3383 | if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(), |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3384 | callingPackage) != AppOpsManager.MODE_ALLOWED) { |
| 3385 | return null; |
| 3386 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 3387 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 3388 | if (DBG_LOC) log("getNeighboringCellInfo: is active user"); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3389 | |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3390 | List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId); |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 3391 | if (info == null) return null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3392 | |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 3393 | List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>(); |
| 3394 | for (CellInfo ci : info) { |
| 3395 | if (ci instanceof CellInfoGsm) { |
| 3396 | neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci)); |
| 3397 | } else if (ci instanceof CellInfoWcdma) { |
| 3398 | neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci)); |
| 3399 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3400 | } |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 3401 | return (neighbors.size()) > 0 ? neighbors : null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3402 | } |
| 3403 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3404 | private List<CellInfo> getCachedCellInfo() { |
| 3405 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 3406 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3407 | List<CellInfo> info = phone.getAllCellInfo(); |
| 3408 | if (info != null) cellInfos.addAll(info); |
| 3409 | } |
| 3410 | return cellInfos; |
| 3411 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3412 | |
| 3413 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3414 | public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3415 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 3416 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3417 | |
| 3418 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 3419 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 3420 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 3421 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3422 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3423 | .setCallingPid(Binder.getCallingPid()) |
| 3424 | .setCallingUid(Binder.getCallingUid()) |
| 3425 | .setMethod("getAllCellInfo") |
Nathan Harold | 5ae50b5 | 2019-02-20 15:46:36 -0800 | [diff] [blame] | 3426 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3427 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 3428 | .build()); |
| 3429 | switch (locationResult) { |
| 3430 | case DENIED_HARD: |
| 3431 | throw new SecurityException("Not allowed to access cell info"); |
| 3432 | case DENIED_SOFT: |
| 3433 | return new ArrayList<>(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3434 | } |
| 3435 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3436 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3437 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 3438 | return getCachedCellInfo(); |
| 3439 | } |
| 3440 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 3441 | if (DBG_LOC) log("getAllCellInfo: is active user"); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 3442 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3443 | final long identity = Binder.clearCallingIdentity(); |
| 3444 | try { |
| 3445 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 3446 | for (Phone phone : PhoneFactory.getPhones()) { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 3447 | final List<CellInfo> info = (List<CellInfo>) sendRequest( |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 3448 | CMD_GET_ALL_CELL_INFO, null, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3449 | if (info != null) cellInfos.addAll(info); |
| 3450 | } |
| 3451 | return cellInfos; |
| 3452 | } finally { |
| 3453 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3454 | } |
| 3455 | } |
| 3456 | |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 3457 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3458 | public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage, |
| 3459 | String callingFeatureId) { |
| 3460 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, |
| 3461 | getWorkSource(Binder.getCallingUid())); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3462 | } |
| 3463 | |
| 3464 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3465 | public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb, |
| 3466 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3467 | enforceModifyPermission(); |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3468 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3469 | } |
| 3470 | |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3471 | private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb, |
| 3472 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3473 | mApp.getSystemService(AppOpsManager.class) |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3474 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3475 | |
| 3476 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 3477 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 3478 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 3479 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3480 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3481 | .setCallingPid(Binder.getCallingPid()) |
| 3482 | .setCallingUid(Binder.getCallingUid()) |
| 3483 | .setMethod("requestCellInfoUpdate") |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 3484 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
| 3485 | .setMinSdkVersionForFine(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3486 | .build()); |
| 3487 | switch (locationResult) { |
| 3488 | case DENIED_HARD: |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3489 | if (TelephonyPermissions |
| 3490 | .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) { |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 3491 | // Safetynet logging for b/154934934 |
| 3492 | EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid()); |
| 3493 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3494 | throw new SecurityException("Not allowed to access cell info"); |
| 3495 | case DENIED_SOFT: |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3496 | if (TelephonyPermissions |
| 3497 | .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) { |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 3498 | // Safetynet logging for b/154934934 |
| 3499 | EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid()); |
| 3500 | } |
Nathan Harold | 5320c42 | 2019-05-09 10:26:08 -0700 | [diff] [blame] | 3501 | try { |
| 3502 | cb.onCellInfo(new ArrayList<CellInfo>()); |
| 3503 | } catch (RemoteException re) { |
| 3504 | // Drop without consequences |
| 3505 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3506 | return; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3507 | } |
| 3508 | |
Nathan Harold | a939a96 | 2019-05-09 10:13:47 -0700 | [diff] [blame] | 3509 | |
| 3510 | final Phone phone = getPhoneFromSubId(subId); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3511 | if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
| 3512 | |
| 3513 | sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource); |
| 3514 | } |
| 3515 | |
| 3516 | @Override |
Aishwarya Mallampati | 0603fb1 | 2022-08-24 21:16:56 +0000 | [diff] [blame] | 3517 | public void setCellInfoListRate(int rateInMillis, int subId) { |
Jack Yu | a8d8cb8 | 2017-01-16 10:15:34 -0800 | [diff] [blame] | 3518 | enforceModifyPermission(); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 3519 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3520 | |
| 3521 | final long identity = Binder.clearCallingIdentity(); |
| 3522 | try { |
Aishwarya Mallampati | 0603fb1 | 2022-08-24 21:16:56 +0000 | [diff] [blame] | 3523 | Phone phone = getPhone(subId); |
| 3524 | if (phone == null) { |
| 3525 | getDefaultPhone().setCellInfoListRate(rateInMillis, workSource); |
| 3526 | } else { |
| 3527 | phone.setCellInfoListRate(rateInMillis, workSource); |
| 3528 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3529 | } finally { |
| 3530 | Binder.restoreCallingIdentity(identity); |
| 3531 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3532 | } |
| 3533 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3534 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3535 | public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3536 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3537 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3538 | return null; |
| 3539 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3540 | int subId = phone.getSubId(); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3541 | enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot"); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 3542 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3543 | callingPackage, callingFeatureId, "getImeiForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3544 | return null; |
| 3545 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3546 | |
| 3547 | final long identity = Binder.clearCallingIdentity(); |
| 3548 | try { |
| 3549 | return phone.getImei(); |
| 3550 | } finally { |
| 3551 | Binder.restoreCallingIdentity(identity); |
| 3552 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3553 | } |
| 3554 | |
| 3555 | @Override |
arunvoddu | d5c6ce0 | 2022-12-11 06:03:12 +0000 | [diff] [blame] | 3556 | public String getPrimaryImei(String callingPackage, String callingFeatureId) { |
| 3557 | enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getPrimaryImei"); |
| 3558 | if (!checkCallingOrSelfReadDeviceIdentifiersForAnySub(mApp, callingPackage, |
| 3559 | callingFeatureId, "getPrimaryImei")) { |
| 3560 | throw new SecurityException("Caller does not have permission"); |
| 3561 | } |
| 3562 | final long identity = Binder.clearCallingIdentity(); |
| 3563 | try { |
| 3564 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3565 | if (phone.getImeiType() == Phone.IMEI_TYPE_PRIMARY) { |
| 3566 | return phone.getImei(); |
| 3567 | } |
| 3568 | } |
| 3569 | throw new UnsupportedOperationException("Operation not supported"); |
| 3570 | } finally { |
| 3571 | Binder.restoreCallingIdentity(identity); |
| 3572 | } |
| 3573 | } |
| 3574 | |
| 3575 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3576 | public String getTypeAllocationCodeForSlot(int slotIndex) { |
| 3577 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3578 | String tac = null; |
| 3579 | if (phone != null) { |
| 3580 | String imei = phone.getImei(); |
Vala Zadeh | ab00555 | 2021-09-21 15:54:29 -0700 | [diff] [blame] | 3581 | try { |
| 3582 | tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH); |
| 3583 | } catch (IndexOutOfBoundsException e) { |
| 3584 | Log.e(LOG_TAG, "IMEI length shorter than upper index."); |
| 3585 | return null; |
| 3586 | } |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3587 | } |
| 3588 | return tac; |
| 3589 | } |
| 3590 | |
| 3591 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3592 | public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Shuo Qian | 13d8915 | 2021-05-10 23:58:11 -0700 | [diff] [blame] | 3593 | try { |
| 3594 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 3595 | } catch (SecurityException se) { |
| 3596 | EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid()); |
| 3597 | throw new SecurityException("Package " + callingPackage + " does not belong to " |
| 3598 | + Binder.getCallingUid()); |
| 3599 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3600 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3601 | if (phone == null) { |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 3602 | return null; |
| 3603 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3604 | |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3605 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 3606 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3607 | callingPackage, callingFeatureId, "getMeidForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3608 | return null; |
| 3609 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3610 | |
| 3611 | final long identity = Binder.clearCallingIdentity(); |
| 3612 | try { |
| 3613 | return phone.getMeid(); |
| 3614 | } finally { |
| 3615 | Binder.restoreCallingIdentity(identity); |
| 3616 | } |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 3617 | } |
| 3618 | |
| 3619 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3620 | public String getManufacturerCodeForSlot(int slotIndex) { |
| 3621 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3622 | String manufacturerCode = null; |
| 3623 | if (phone != null) { |
| 3624 | String meid = phone.getMeid(); |
Vala Zadeh | ab00555 | 2021-09-21 15:54:29 -0700 | [diff] [blame] | 3625 | try { |
| 3626 | manufacturerCode = |
| 3627 | meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH); |
| 3628 | } catch (IndexOutOfBoundsException e) { |
| 3629 | Log.e(LOG_TAG, "MEID length shorter than upper index."); |
| 3630 | return null; |
| 3631 | } |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3632 | } |
| 3633 | return manufacturerCode; |
| 3634 | } |
| 3635 | |
| 3636 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3637 | public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage, |
| 3638 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3639 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3640 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3641 | return null; |
| 3642 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3643 | int subId = phone.getSubId(); |
| 3644 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3645 | mApp, subId, callingPackage, callingFeatureId, |
| 3646 | "getDeviceSoftwareVersionForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3647 | return null; |
| 3648 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3649 | |
| 3650 | final long identity = Binder.clearCallingIdentity(); |
| 3651 | try { |
| 3652 | return phone.getDeviceSvn(); |
| 3653 | } finally { |
| 3654 | Binder.restoreCallingIdentity(identity); |
| 3655 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3656 | } |
| 3657 | |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3658 | @Override |
| 3659 | public int getSubscriptionCarrierId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3660 | final long identity = Binder.clearCallingIdentity(); |
| 3661 | try { |
| 3662 | final Phone phone = getPhone(subId); |
| 3663 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId(); |
| 3664 | } finally { |
| 3665 | Binder.restoreCallingIdentity(identity); |
| 3666 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3667 | } |
| 3668 | |
| 3669 | @Override |
| 3670 | public String getSubscriptionCarrierName(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3671 | final long identity = Binder.clearCallingIdentity(); |
| 3672 | try { |
| 3673 | final Phone phone = getPhone(subId); |
| 3674 | return phone == null ? null : phone.getCarrierName(); |
| 3675 | } finally { |
| 3676 | Binder.restoreCallingIdentity(identity); |
| 3677 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3678 | } |
| 3679 | |
calvinpan | ffe225e | 2018-11-01 19:43:06 +0800 | [diff] [blame] | 3680 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3681 | public int getSubscriptionSpecificCarrierId(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3682 | final long identity = Binder.clearCallingIdentity(); |
| 3683 | try { |
| 3684 | final Phone phone = getPhone(subId); |
| 3685 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3686 | : phone.getSpecificCarrierId(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3687 | } finally { |
| 3688 | Binder.restoreCallingIdentity(identity); |
| 3689 | } |
| 3690 | } |
| 3691 | |
| 3692 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3693 | public String getSubscriptionSpecificCarrierName(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3694 | final long identity = Binder.clearCallingIdentity(); |
| 3695 | try { |
| 3696 | final Phone phone = getPhone(subId); |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3697 | return phone == null ? null : phone.getSpecificCarrierName(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3698 | } finally { |
| 3699 | Binder.restoreCallingIdentity(identity); |
| 3700 | } |
| 3701 | } |
| 3702 | |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 3703 | @Override |
chen xu | 864e11c | 2018-12-06 22:10:03 -0800 | [diff] [blame] | 3704 | public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) { |
| 3705 | if (!isSubscriptionMccMnc) { |
| 3706 | enforceReadPrivilegedPermission("getCarrierIdFromMccMnc"); |
| 3707 | } |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 3708 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3709 | if (phone == null) { |
| 3710 | return TelephonyManager.UNKNOWN_CARRIER_ID; |
| 3711 | } |
| 3712 | final long identity = Binder.clearCallingIdentity(); |
| 3713 | try { |
| 3714 | return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc); |
| 3715 | } finally { |
| 3716 | Binder.restoreCallingIdentity(identity); |
| 3717 | } |
| 3718 | } |
| 3719 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3720 | // |
| 3721 | // Internal helper methods. |
| 3722 | // |
| 3723 | |
Sanket Padawe | ee13a9b | 2016-03-08 17:30:28 -0800 | [diff] [blame] | 3724 | /** |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3725 | * Make sure the caller is the calling package itself |
| 3726 | * |
| 3727 | * @throws SecurityException if the caller is not the calling package |
| 3728 | */ |
| 3729 | private void enforceCallingPackage(String callingPackage, int callingUid, String message) { |
| 3730 | int packageUid = -1; |
Grace Jia | dbefca0 | 2021-04-26 15:13:31 -0700 | [diff] [blame] | 3731 | PackageManager pm = mApp.getBaseContext().createContextAsUser( |
| 3732 | UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager(); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3733 | try { |
Grace Jia | dbefca0 | 2021-04-26 15:13:31 -0700 | [diff] [blame] | 3734 | packageUid = pm.getPackageUid(callingPackage, 0); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3735 | } catch (PackageManager.NameNotFoundException e) { |
| 3736 | // packageUid is -1 |
| 3737 | } |
| 3738 | if (packageUid != callingUid) { |
| 3739 | throw new SecurityException(message + ": Package " + callingPackage |
| 3740 | + " does not belong to " + callingUid); |
| 3741 | } |
| 3742 | } |
| 3743 | |
| 3744 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3745 | * Make sure the caller has the MODIFY_PHONE_STATE permission. |
| 3746 | * |
| 3747 | * @throws SecurityException if the caller does not have the required permission |
| 3748 | */ |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 3749 | @VisibleForTesting |
| 3750 | public void enforceModifyPermission() { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3751 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null); |
| 3752 | } |
| 3753 | |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 3754 | /** |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 3755 | * Make sure the caller has the READ_PHONE_STATE permission. |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 3756 | * |
| 3757 | * @throws SecurityException if the caller does not have the required permission |
| 3758 | */ |
| 3759 | @VisibleForTesting |
| 3760 | public void enforceReadPermission() { |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 3761 | enforceReadPermission(null); |
| 3762 | } |
| 3763 | |
| 3764 | /** |
| 3765 | * Make sure the caller has the READ_PHONE_STATE permissions. |
| 3766 | * |
| 3767 | * @throws SecurityException if the caller does not have the READ_PHONE_STATE permission. |
| 3768 | */ |
| 3769 | @VisibleForTesting |
| 3770 | public void enforceReadPermission(String msg) { |
| 3771 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, msg); |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 3772 | } |
| 3773 | |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 3774 | private void enforceActiveEmergencySessionPermission() { |
| 3775 | mApp.enforceCallingOrSelfPermission( |
| 3776 | android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null); |
| 3777 | } |
| 3778 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3779 | /** |
| 3780 | * Make sure the caller has the CALL_PHONE permission. |
| 3781 | * |
| 3782 | * @throws SecurityException if the caller does not have the required permission |
| 3783 | */ |
| 3784 | private void enforceCallPermission() { |
| 3785 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null); |
| 3786 | } |
| 3787 | |
paulhu | 5a77360 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 3788 | private void enforceSettingsPermission() { |
| 3789 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 3790 | } |
| 3791 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 3792 | private void enforceRebootPermission() { |
| 3793 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null); |
| 3794 | } |
| 3795 | |
Aishwarya Mallampati | 60fe113 | 2023-01-24 19:07:21 +0000 | [diff] [blame] | 3796 | /** |
| 3797 | * Make sure the caller has SATELLITE_COMMUNICATION permission. |
| 3798 | * @param message - log message to print. |
| 3799 | * @throws SecurityException if the caller does not have the required permission |
| 3800 | */ |
| 3801 | private void enforceSatelliteCommunicationPermission(String message) { |
| 3802 | mApp.enforceCallingOrSelfPermission(permission.SATELLITE_COMMUNICATION, message); |
| 3803 | } |
| 3804 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3805 | private String createTelUrl(String number) { |
| 3806 | if (TextUtils.isEmpty(number)) { |
| 3807 | return null; |
| 3808 | } |
| 3809 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3810 | return "tel:" + number; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3811 | } |
| 3812 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3813 | private static void log(String msg) { |
Ling Ma | 83dc5ea | 2023-01-12 15:06:04 -0800 | [diff] [blame] | 3814 | Log.d(LOG_TAG, msg); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3815 | } |
| 3816 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3817 | private static void logv(String msg) { |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 3818 | Log.v(LOG_TAG, msg); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3819 | } |
| 3820 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3821 | private static void loge(String msg) { |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 3822 | Log.e(LOG_TAG, msg); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3823 | } |
| 3824 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3825 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3826 | public int getActivePhoneType() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3827 | return getActivePhoneTypeForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3828 | } |
| 3829 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3830 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3831 | public int getActivePhoneTypeForSlot(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3832 | final long identity = Binder.clearCallingIdentity(); |
| 3833 | try { |
| 3834 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3835 | if (phone == null) { |
| 3836 | return PhoneConstants.PHONE_TYPE_NONE; |
| 3837 | } else { |
| 3838 | return phone.getPhoneType(); |
| 3839 | } |
| 3840 | } finally { |
| 3841 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3842 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3843 | } |
| 3844 | |
| 3845 | /** |
| 3846 | * Returns the CDMA ERI icon index to display |
| 3847 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3848 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3849 | public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) { |
| 3850 | return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage, |
| 3851 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3852 | } |
| 3853 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3854 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3855 | public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage, |
| 3856 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3857 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3858 | mApp, subId, callingPackage, callingFeatureId, |
| 3859 | "getCdmaEriIconIndexForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3860 | return -1; |
| 3861 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3862 | |
| 3863 | final long identity = Binder.clearCallingIdentity(); |
| 3864 | try { |
| 3865 | final Phone phone = getPhone(subId); |
| 3866 | if (phone != null) { |
| 3867 | return phone.getCdmaEriIconIndex(); |
| 3868 | } else { |
| 3869 | return -1; |
| 3870 | } |
| 3871 | } finally { |
| 3872 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3873 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3874 | } |
| 3875 | |
| 3876 | /** |
| 3877 | * Returns the CDMA ERI icon mode, |
| 3878 | * 0 - ON |
| 3879 | * 1 - FLASHING |
| 3880 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3881 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3882 | public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) { |
| 3883 | return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 3884 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3885 | } |
| 3886 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3887 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3888 | public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage, |
| 3889 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3890 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3891 | mApp, subId, callingPackage, callingFeatureId, |
| 3892 | "getCdmaEriIconModeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3893 | return -1; |
| 3894 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3895 | |
| 3896 | final long identity = Binder.clearCallingIdentity(); |
| 3897 | try { |
| 3898 | final Phone phone = getPhone(subId); |
| 3899 | if (phone != null) { |
| 3900 | return phone.getCdmaEriIconMode(); |
| 3901 | } else { |
| 3902 | return -1; |
| 3903 | } |
| 3904 | } finally { |
| 3905 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3906 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3907 | } |
| 3908 | |
| 3909 | /** |
| 3910 | * Returns the CDMA ERI text, |
| 3911 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3912 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3913 | public String getCdmaEriText(String callingPackage, String callingFeatureId) { |
| 3914 | return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage, |
| 3915 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3916 | } |
| 3917 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3918 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3919 | public String getCdmaEriTextForSubscriber(int subId, String callingPackage, |
| 3920 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3921 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3922 | mApp, subId, callingPackage, callingFeatureId, |
| 3923 | "getCdmaEriIconTextForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3924 | return null; |
| 3925 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3926 | |
| 3927 | final long identity = Binder.clearCallingIdentity(); |
| 3928 | try { |
| 3929 | final Phone phone = getPhone(subId); |
| 3930 | if (phone != null) { |
| 3931 | return phone.getCdmaEriText(); |
| 3932 | } else { |
| 3933 | return null; |
| 3934 | } |
| 3935 | } finally { |
| 3936 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3937 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3938 | } |
| 3939 | |
| 3940 | /** |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3941 | * Returns the CDMA MDN. |
| 3942 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3943 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3944 | public String getCdmaMdn(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3945 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3946 | mApp, subId, "getCdmaMdn"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3947 | |
| 3948 | final long identity = Binder.clearCallingIdentity(); |
| 3949 | try { |
| 3950 | final Phone phone = getPhone(subId); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3951 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3952 | return phone.getLine1Number(); |
| 3953 | } else { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3954 | loge("getCdmaMdn: no phone found. Invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3955 | return null; |
| 3956 | } |
| 3957 | } finally { |
| 3958 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3959 | } |
| 3960 | } |
| 3961 | |
| 3962 | /** |
| 3963 | * Returns the CDMA MIN. |
| 3964 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3965 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3966 | public String getCdmaMin(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3967 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3968 | mApp, subId, "getCdmaMin"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3969 | |
| 3970 | final long identity = Binder.clearCallingIdentity(); |
| 3971 | try { |
| 3972 | final Phone phone = getPhone(subId); |
| 3973 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
| 3974 | return phone.getCdmaMin(); |
| 3975 | } else { |
| 3976 | return null; |
| 3977 | } |
| 3978 | } finally { |
| 3979 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3980 | } |
| 3981 | } |
| 3982 | |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3983 | @Override |
| 3984 | public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis, |
| 3985 | INumberVerificationCallback callback, String callingPackage) { |
| 3986 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 3987 | != PERMISSION_GRANTED) { |
| 3988 | throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission"); |
| 3989 | } |
| 3990 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 3991 | |
| 3992 | String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp); |
| 3993 | if (!TextUtils.equals(callingPackage, authorizedPackage)) { |
Hall Liu | b9d8feb | 2021-01-13 10:28:04 -0800 | [diff] [blame] | 3994 | throw new SecurityException("Calling package must be configured in the device config: " |
| 3995 | + "calling package: " + callingPackage |
| 3996 | + ", configured package: " + authorizedPackage); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3997 | } |
| 3998 | |
| 3999 | if (range == null) { |
| 4000 | throw new NullPointerException("Range must be non-null"); |
| 4001 | } |
| 4002 | |
| 4003 | timeoutMillis = Math.min(timeoutMillis, |
Hall Liu | bd069e3 | 2019-02-28 18:56:30 -0800 | [diff] [blame] | 4004 | TelephonyManager.getMaxNumberVerificationTimeoutMillis()); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 4005 | |
| 4006 | NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis); |
| 4007 | } |
| 4008 | |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 4009 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4010 | * Returns true if CDMA provisioning needs to run. |
| 4011 | */ |
| 4012 | public boolean needsOtaServiceProvisioning() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4013 | final long identity = Binder.clearCallingIdentity(); |
| 4014 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4015 | return getDefaultPhone().needsOtaServiceProvisioning(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4016 | } finally { |
| 4017 | Binder.restoreCallingIdentity(identity); |
| 4018 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4019 | } |
| 4020 | |
| 4021 | /** |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 4022 | * Sets the voice mail number of a given subId. |
| 4023 | */ |
| 4024 | @Override |
| 4025 | public boolean setVoiceMailNumber(int subId, String alphaTag, String number) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 4026 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 4027 | mApp, subId, "setVoiceMailNumber"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4028 | |
| 4029 | final long identity = Binder.clearCallingIdentity(); |
| 4030 | try { |
| 4031 | Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER, |
| 4032 | new Pair<String, String>(alphaTag, number), new Integer(subId)); |
| 4033 | return success; |
| 4034 | } finally { |
| 4035 | Binder.restoreCallingIdentity(identity); |
| 4036 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 4037 | } |
| 4038 | |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 4039 | @Override |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 4040 | public Bundle getVisualVoicemailSettings(String callingPackage, int subId) { |
| 4041 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 4042 | TelecomManager tm = mApp.getSystemService(TelecomManager.class); |
| 4043 | String systemDialer = tm.getSystemDialerPackage(); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 4044 | if (!TextUtils.equals(callingPackage, systemDialer)) { |
| 4045 | throw new SecurityException("caller must be system dialer"); |
| 4046 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4047 | |
| 4048 | final long identity = Binder.clearCallingIdentity(); |
| 4049 | try { |
| 4050 | PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId); |
| 4051 | if (phoneAccountHandle == null) { |
| 4052 | return null; |
| 4053 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4054 | return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4055 | } finally { |
| 4056 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 4057 | } |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 4058 | } |
| 4059 | |
| 4060 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4061 | public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId, |
| 4062 | int subId) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 4063 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4064 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4065 | mApp, subId, callingPackage, callingFeatureId, |
| 4066 | "getVisualVoicemailPackageName")) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 4067 | return null; |
| 4068 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4069 | |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 4070 | final long identity = Binder.clearCallingIdentity(); |
| 4071 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4072 | return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName(); |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 4073 | } finally { |
| 4074 | Binder.restoreCallingIdentity(identity); |
| 4075 | } |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 4076 | } |
| 4077 | |
| 4078 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 4079 | public void enableVisualVoicemailSmsFilter(String callingPackage, int subId, |
| 4080 | VisualVoicemailSmsFilterSettings settings) { |
| 4081 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4082 | |
| 4083 | final long identity = Binder.clearCallingIdentity(); |
| 4084 | try { |
| 4085 | VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4086 | mApp, callingPackage, subId, settings); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4087 | } finally { |
| 4088 | Binder.restoreCallingIdentity(identity); |
| 4089 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 4090 | } |
| 4091 | |
| 4092 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 4093 | public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) { |
| 4094 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4095 | |
| 4096 | final long identity = Binder.clearCallingIdentity(); |
| 4097 | try { |
| 4098 | VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4099 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4100 | } finally { |
| 4101 | Binder.restoreCallingIdentity(identity); |
| 4102 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 4103 | } |
| 4104 | |
| 4105 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 4106 | public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings( |
| 4107 | String callingPackage, int subId) { |
| 4108 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4109 | |
| 4110 | final long identity = Binder.clearCallingIdentity(); |
| 4111 | try { |
| 4112 | return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4113 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4114 | } finally { |
| 4115 | Binder.restoreCallingIdentity(identity); |
| 4116 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 4117 | } |
| 4118 | |
| 4119 | @Override |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 4120 | public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4121 | enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4122 | |
| 4123 | final long identity = Binder.clearCallingIdentity(); |
| 4124 | try { |
| 4125 | return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4126 | mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4127 | } finally { |
| 4128 | Binder.restoreCallingIdentity(identity); |
| 4129 | } |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 4130 | } |
| 4131 | |
| 4132 | @Override |
Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 4133 | public void sendVisualVoicemailSmsForSubscriber(String callingPackage, |
| 4134 | String callingAttributionTag, int subId, String number, int port, String text, |
| 4135 | PendingIntent sentIntent) { |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 4136 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 4137 | enforceVisualVoicemailPackage(callingPackage, subId); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 4138 | enforceSendSmsPermission(); |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 4139 | SmsController smsController = PhoneFactory.getSmsController(); |
Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 4140 | smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag, |
| 4141 | subId, number, port, text, sentIntent); |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 4142 | } |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 4143 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 4144 | /** |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4145 | * Sets the voice activation state of a given subId. |
| 4146 | */ |
| 4147 | @Override |
| 4148 | public void setVoiceActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4149 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4150 | mApp, subId, "setVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4151 | |
| 4152 | final long identity = Binder.clearCallingIdentity(); |
| 4153 | try { |
| 4154 | final Phone phone = getPhone(subId); |
| 4155 | if (phone != null) { |
| 4156 | phone.setVoiceActivationState(activationState); |
| 4157 | } else { |
| 4158 | loge("setVoiceActivationState fails with invalid subId: " + subId); |
| 4159 | } |
| 4160 | } finally { |
| 4161 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4162 | } |
| 4163 | } |
| 4164 | |
| 4165 | /** |
| 4166 | * Sets the data activation state of a given subId. |
| 4167 | */ |
| 4168 | @Override |
| 4169 | public void setDataActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4170 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4171 | mApp, subId, "setDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4172 | |
| 4173 | final long identity = Binder.clearCallingIdentity(); |
| 4174 | try { |
| 4175 | final Phone phone = getPhone(subId); |
| 4176 | if (phone != null) { |
| 4177 | phone.setDataActivationState(activationState); |
| 4178 | } else { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 4179 | loge("setDataActivationState fails with invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4180 | } |
| 4181 | } finally { |
| 4182 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4183 | } |
| 4184 | } |
| 4185 | |
| 4186 | /** |
| 4187 | * Returns the voice activation state of a given subId. |
| 4188 | */ |
| 4189 | @Override |
| 4190 | public int getVoiceActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4191 | enforceReadPrivilegedPermission("getVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4192 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4193 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4194 | final long identity = Binder.clearCallingIdentity(); |
| 4195 | try { |
| 4196 | if (phone != null) { |
| 4197 | return phone.getVoiceActivationState(); |
| 4198 | } else { |
| 4199 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 4200 | } |
| 4201 | } finally { |
| 4202 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4203 | } |
| 4204 | } |
| 4205 | |
| 4206 | /** |
| 4207 | * Returns the data activation state of a given subId. |
| 4208 | */ |
| 4209 | @Override |
| 4210 | public int getDataActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4211 | enforceReadPrivilegedPermission("getDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4212 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4213 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4214 | final long identity = Binder.clearCallingIdentity(); |
| 4215 | try { |
| 4216 | if (phone != null) { |
| 4217 | return phone.getDataActivationState(); |
| 4218 | } else { |
| 4219 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 4220 | } |
| 4221 | } finally { |
| 4222 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4223 | } |
| 4224 | } |
| 4225 | |
| 4226 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4227 | * Returns the unread count of voicemails for a subId |
| 4228 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4229 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4230 | public int getVoiceMessageCountForSubscriber(int subId, String callingPackage, |
| 4231 | String callingFeatureId) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 4232 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4233 | mApp, subId, callingPackage, callingFeatureId, |
| 4234 | "getVoiceMessageCountForSubscriber")) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 4235 | return 0; |
| 4236 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4237 | final long identity = Binder.clearCallingIdentity(); |
| 4238 | try { |
| 4239 | final Phone phone = getPhone(subId); |
| 4240 | if (phone != null) { |
| 4241 | return phone.getVoiceMessageCount(); |
| 4242 | } else { |
| 4243 | return 0; |
| 4244 | } |
| 4245 | } finally { |
| 4246 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4247 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4248 | } |
| 4249 | |
| 4250 | /** |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 4251 | * returns true, if the device is in a state where both voice and data |
| 4252 | * are supported simultaneously. This can change based on location or network condition. |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 4253 | */ |
| 4254 | @Override |
| 4255 | public boolean isConcurrentVoiceAndDataAllowed(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4256 | final long identity = Binder.clearCallingIdentity(); |
| 4257 | try { |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 4258 | return getPhoneFromSubIdOrDefault(subId).isConcurrentVoiceAndDataAllowed(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4259 | } finally { |
| 4260 | Binder.restoreCallingIdentity(identity); |
| 4261 | } |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 4262 | } |
| 4263 | |
| 4264 | /** |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4265 | * Send the dialer code if called from the current default dialer or the caller has |
| 4266 | * carrier privilege. |
| 4267 | * @param inputCode The dialer code to send |
| 4268 | */ |
| 4269 | @Override |
| 4270 | public void sendDialerSpecialCode(String callingPackage, String inputCode) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4271 | final Phone defaultPhone = getDefaultPhone(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4272 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 4273 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 4274 | String defaultDialer = tm.getDefaultDialerPackage(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4275 | if (!TextUtils.equals(callingPackage, defaultDialer)) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 4276 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4277 | getDefaultSubscription(), "sendDialerSpecialCode"); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4278 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4279 | |
| 4280 | final long identity = Binder.clearCallingIdentity(); |
| 4281 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4282 | defaultPhone.sendDialerSpecialCode(inputCode); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4283 | } finally { |
| 4284 | Binder.restoreCallingIdentity(identity); |
| 4285 | } |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4286 | } |
| 4287 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 4288 | @Override |
| 4289 | public int getNetworkSelectionMode(int subId) { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 4290 | TelephonyPermissions |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 4291 | .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4292 | mApp, subId, "getNetworkSelectionMode"); |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 4293 | final long identity = Binder.clearCallingIdentity(); |
| 4294 | try { |
| 4295 | if (!isActiveSubscription(subId)) { |
| 4296 | return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 4297 | } |
| 4298 | return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId); |
| 4299 | } finally { |
| 4300 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 4301 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 4302 | } |
| 4303 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4304 | @Override |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 4305 | public boolean isInEmergencySmsMode() { |
| 4306 | enforceReadPrivilegedPermission("isInEmergencySmsMode"); |
| 4307 | final long identity = Binder.clearCallingIdentity(); |
| 4308 | try { |
| 4309 | for (Phone phone : PhoneFactory.getPhones()) { |
| 4310 | if (phone.isInEmergencySmsMode()) { |
| 4311 | return true; |
| 4312 | } |
| 4313 | } |
| 4314 | } finally { |
| 4315 | Binder.restoreCallingIdentity(identity); |
| 4316 | } |
| 4317 | return false; |
| 4318 | } |
| 4319 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4320 | /** |
| 4321 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4322 | * @param subId The subscription to use to check the configuration. |
| 4323 | * @param c The callback that will be used to send the result. |
| 4324 | */ |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 4325 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4326 | public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c) |
| 4327 | throws RemoteException { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4328 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4329 | mApp, subId, "registerImsRegistrationCallback"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4330 | |
| 4331 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4332 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4333 | "IMS not available on device."); |
| 4334 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4335 | final long token = Binder.clearCallingIdentity(); |
| 4336 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4337 | int slotId = getSlotIndexOrException(subId); |
| 4338 | verifyImsMmTelConfiguredOrThrow(slotId); |
joonhunshin | 49f0aed | 2022-08-05 08:33:05 +0000 | [diff] [blame] | 4339 | |
| 4340 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4341 | if (controller != null) { |
| 4342 | ImsManager imsManager = controller.getImsManager(subId); |
| 4343 | if (imsManager != null) { |
| 4344 | imsManager.addRegistrationCallbackForSubscription(c, subId); |
| 4345 | } else { |
| 4346 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE); |
| 4347 | } |
| 4348 | } else { |
| 4349 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION); |
| 4350 | } |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4351 | } catch (ImsException e) { |
| 4352 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4353 | } finally { |
| 4354 | Binder.restoreCallingIdentity(token); |
| 4355 | } |
| 4356 | } |
| 4357 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4358 | /** |
| 4359 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4360 | * @param subId The subscription to use to check the configuration. |
| 4361 | * @param c The callback that will be used to send the result. |
| 4362 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4363 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4364 | public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4365 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4366 | mApp, subId, "unregisterImsRegistrationCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4367 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4368 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4369 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4370 | final long token = Binder.clearCallingIdentity(); |
joonhunshin | 49f0aed | 2022-08-05 08:33:05 +0000 | [diff] [blame] | 4371 | |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4372 | try { |
joonhunshin | 49f0aed | 2022-08-05 08:33:05 +0000 | [diff] [blame] | 4373 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4374 | if (controller != null) { |
| 4375 | ImsManager imsManager = controller.getImsManager(subId); |
| 4376 | if (imsManager != null) { |
| 4377 | imsManager.removeRegistrationCallbackForSubscription(c, subId); |
| 4378 | } else { |
| 4379 | Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId |
| 4380 | + "is inactive, ignoring unregister."); |
| 4381 | // If the ImsManager is not valid, just return, since the callback |
| 4382 | // will already have been removed internally. |
| 4383 | } |
| 4384 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4385 | } finally { |
| 4386 | Binder.restoreCallingIdentity(token); |
| 4387 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4388 | } |
| 4389 | |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 4390 | /** |
| 4391 | * Get the IMS service registration state for the MmTelFeature associated with this sub id. |
| 4392 | */ |
| 4393 | @Override |
| 4394 | public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) { |
| 4395 | enforceReadPrivilegedPermission("getImsMmTelRegistrationState"); |
| 4396 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4397 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4398 | "IMS not available on device."); |
| 4399 | } |
| 4400 | final long token = Binder.clearCallingIdentity(); |
| 4401 | try { |
| 4402 | Phone phone = getPhone(subId); |
| 4403 | if (phone == null) { |
| 4404 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 4405 | + subId + "'"); |
| 4406 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 4407 | } |
| 4408 | phone.getImsRegistrationState(regState -> { |
| 4409 | try { |
| 4410 | consumer.accept((regState == null) |
| 4411 | ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState); |
| 4412 | } catch (RemoteException e) { |
| 4413 | // Ignore if the remote process is no longer available to call back. |
| 4414 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 4415 | } |
| 4416 | }); |
| 4417 | } finally { |
| 4418 | Binder.restoreCallingIdentity(token); |
| 4419 | } |
| 4420 | } |
| 4421 | |
| 4422 | /** |
| 4423 | * Get the transport type for the IMS service registration state. |
| 4424 | */ |
| 4425 | @Override |
| 4426 | public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4427 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4428 | mApp, subId, "getImsMmTelRegistrationTransportType"); |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 4429 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4430 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4431 | "IMS not available on device."); |
| 4432 | } |
| 4433 | final long token = Binder.clearCallingIdentity(); |
| 4434 | try { |
| 4435 | Phone phone = getPhone(subId); |
| 4436 | if (phone == null) { |
| 4437 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 4438 | + subId + "'"); |
| 4439 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 4440 | } |
| 4441 | phone.getImsRegistrationTech(regTech -> { |
| 4442 | // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager |
| 4443 | int regTechConverted = (regTech == null) |
| 4444 | ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech; |
| 4445 | regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get( |
| 4446 | regTechConverted); |
| 4447 | try { |
| 4448 | consumer.accept(regTechConverted); |
| 4449 | } catch (RemoteException e) { |
| 4450 | // Ignore if the remote process is no longer available to call back. |
| 4451 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 4452 | } |
| 4453 | }); |
| 4454 | } finally { |
| 4455 | Binder.restoreCallingIdentity(token); |
| 4456 | } |
| 4457 | } |
| 4458 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4459 | /** |
| 4460 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4461 | * @param subId The subscription to use to check the configuration. |
| 4462 | * @param c The callback that will be used to send the result. |
| 4463 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4464 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4465 | public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) |
| 4466 | throws RemoteException { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4467 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4468 | mApp, subId, "registerMmTelCapabilityCallback"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4469 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4470 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4471 | "IMS not available on device."); |
| 4472 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4473 | final long token = Binder.clearCallingIdentity(); |
| 4474 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4475 | int slotId = getSlotIndexOrException(subId); |
| 4476 | verifyImsMmTelConfiguredOrThrow(slotId); |
Hwangoo Park | 8646b0d | 2023-01-13 02:42:34 +0000 | [diff] [blame] | 4477 | |
| 4478 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4479 | if (controller != null) { |
| 4480 | ImsManager imsManager = controller.getImsManager(subId); |
| 4481 | if (imsManager != null) { |
| 4482 | imsManager.addCapabilitiesCallbackForSubscription(c, subId); |
| 4483 | } else { |
| 4484 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE); |
| 4485 | } |
| 4486 | } else { |
| 4487 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION); |
| 4488 | } |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4489 | } catch (ImsException e) { |
| 4490 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4491 | } finally { |
| 4492 | Binder.restoreCallingIdentity(token); |
| 4493 | } |
| 4494 | } |
| 4495 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4496 | /** |
| 4497 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4498 | * @param subId The subscription to use to check the configuration. |
| 4499 | * @param c The callback that will be used to send the result. |
| 4500 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4501 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4502 | public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4503 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4504 | mApp, subId, "unregisterMmTelCapabilityCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4505 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4506 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4507 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4508 | |
| 4509 | final long token = Binder.clearCallingIdentity(); |
| 4510 | try { |
Hwangoo Park | 8646b0d | 2023-01-13 02:42:34 +0000 | [diff] [blame] | 4511 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4512 | if (controller != null) { |
| 4513 | ImsManager imsManager = controller.getImsManager(subId); |
| 4514 | if (imsManager != null) { |
| 4515 | imsManager.removeCapabilitiesCallbackForSubscription(c, subId); |
| 4516 | } else { |
| 4517 | Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId |
| 4518 | + " is inactive, ignoring unregister."); |
| 4519 | // If the ImsManager is not valid, just return, since the callback |
| 4520 | // will already have been removed internally. |
| 4521 | } |
| 4522 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4523 | } finally { |
| 4524 | Binder.restoreCallingIdentity(token); |
| 4525 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4526 | } |
| 4527 | |
| 4528 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4529 | public boolean isCapable(int subId, int capability, int regTech) { |
| 4530 | enforceReadPrivilegedPermission("isCapable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4531 | final long token = Binder.clearCallingIdentity(); |
| 4532 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4533 | int slotId = getSlotIndexOrException(subId); |
| 4534 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 4535 | return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech); |
| 4536 | } catch (com.android.ims.ImsException e) { |
| 4537 | Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage()); |
| 4538 | return false; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4539 | } catch (ImsException e) { |
Brad Ebinger | 6b5ac22 | 2019-02-04 14:36:52 -0800 | [diff] [blame] | 4540 | Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false."); |
| 4541 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4542 | } finally { |
| 4543 | Binder.restoreCallingIdentity(token); |
| 4544 | } |
| 4545 | } |
| 4546 | |
| 4547 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4548 | public boolean isAvailable(int subId, int capability, int regTech) { |
| 4549 | enforceReadPrivilegedPermission("isAvailable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4550 | final long token = Binder.clearCallingIdentity(); |
| 4551 | try { |
| 4552 | Phone phone = getPhone(subId); |
| 4553 | if (phone == null) return false; |
| 4554 | return phone.isImsCapabilityAvailable(capability, regTech); |
Daniel Bright | 5e40e4e | 2020-03-11 16:35:39 -0700 | [diff] [blame] | 4555 | } catch (com.android.ims.ImsException e) { |
| 4556 | Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage()); |
| 4557 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4558 | } finally { |
| 4559 | Binder.restoreCallingIdentity(token); |
| 4560 | } |
| 4561 | } |
| 4562 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4563 | /** |
| 4564 | * Determines if the MmTel feature capability is supported by the carrier configuration for this |
| 4565 | * subscription. |
| 4566 | * @param subId The subscription to use to check the configuration. |
| 4567 | * @param callback The callback that will be used to send the result. |
| 4568 | * @param capability The MmTelFeature capability that will be used to send the result. |
| 4569 | * @param transportType The transport type of the MmTelFeature capability. |
| 4570 | */ |
| 4571 | @Override |
| 4572 | public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability, |
| 4573 | int transportType) { |
| 4574 | enforceReadPrivilegedPermission("isMmTelCapabilitySupported"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4575 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4576 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4577 | "IMS not available on device."); |
| 4578 | } |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4579 | final long token = Binder.clearCallingIdentity(); |
| 4580 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4581 | int slotId = getSlotIndex(subId); |
| 4582 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4583 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '" |
| 4584 | + subId + "'"); |
| 4585 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 4586 | } |
| 4587 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 4588 | ImsManager.getInstance(mApp, slotId).isSupported(capability, |
| 4589 | transportType, aBoolean -> { |
| 4590 | try { |
| 4591 | callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0)); |
| 4592 | } catch (RemoteException e) { |
| 4593 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not " |
| 4594 | + "running. Ignore"); |
| 4595 | } |
| 4596 | }); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4597 | } catch (ImsException e) { |
| 4598 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4599 | } finally { |
| 4600 | Binder.restoreCallingIdentity(token); |
| 4601 | } |
| 4602 | } |
| 4603 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4604 | /** |
| 4605 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4606 | * @param subId The subscription to use to check the configuration. |
| 4607 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4608 | @Override |
| 4609 | public boolean isAdvancedCallingSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4610 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4611 | mApp, subId, "isAdvancedCallingSettingEnabled"); |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4612 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4613 | final long token = Binder.clearCallingIdentity(); |
| 4614 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4615 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4616 | // 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] | 4617 | return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4618 | } catch (ImsException e) { |
| 4619 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4620 | } finally { |
| 4621 | Binder.restoreCallingIdentity(token); |
| 4622 | } |
| 4623 | } |
| 4624 | |
| 4625 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4626 | public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4627 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4628 | "setAdvancedCallingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4629 | final long identity = Binder.clearCallingIdentity(); |
| 4630 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4631 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4632 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4633 | // 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] | 4634 | ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4635 | } catch (ImsException e) { |
| 4636 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4637 | } finally { |
| 4638 | Binder.restoreCallingIdentity(identity); |
| 4639 | } |
| 4640 | } |
| 4641 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4642 | /** |
| 4643 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4644 | * @param subId The subscription to use to check the configuration. |
| 4645 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4646 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4647 | public boolean isVtSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4648 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4649 | mApp, subId, "isVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4650 | final long identity = Binder.clearCallingIdentity(); |
| 4651 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4652 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4653 | // 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] | 4654 | return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4655 | } catch (ImsException e) { |
| 4656 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4657 | } finally { |
| 4658 | Binder.restoreCallingIdentity(identity); |
| 4659 | } |
| 4660 | } |
| 4661 | |
| 4662 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4663 | public void setVtSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4664 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4665 | "setVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4666 | final long identity = Binder.clearCallingIdentity(); |
| 4667 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4668 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4669 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4670 | // 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] | 4671 | ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4672 | } catch (ImsException e) { |
| 4673 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4674 | } finally { |
| 4675 | Binder.restoreCallingIdentity(identity); |
| 4676 | } |
| 4677 | } |
| 4678 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4679 | /** |
| 4680 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4681 | * @param subId The subscription to use to check the configuration. |
| 4682 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4683 | @Override |
| 4684 | public boolean isVoWiFiSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4685 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4686 | mApp, subId, "isVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4687 | final long identity = Binder.clearCallingIdentity(); |
| 4688 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4689 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4690 | // 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] | 4691 | return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4692 | } catch (ImsException e) { |
| 4693 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4694 | } finally { |
| 4695 | Binder.restoreCallingIdentity(identity); |
| 4696 | } |
| 4697 | } |
| 4698 | |
| 4699 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4700 | public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4701 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4702 | "setVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4703 | final long identity = Binder.clearCallingIdentity(); |
| 4704 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4705 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4706 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4707 | // 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] | 4708 | ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4709 | } catch (ImsException e) { |
| 4710 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4711 | } finally { |
| 4712 | Binder.restoreCallingIdentity(identity); |
| 4713 | } |
| 4714 | } |
| 4715 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4716 | /** |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 4717 | * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not |
| 4718 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4719 | * @param subId The subscription to use to check the configuration. |
| 4720 | */ |
| 4721 | @Override |
| 4722 | public boolean isCrossSimCallingEnabledByUser(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4723 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 4724 | mApp, subId, "isCrossSimCallingEnabledByUser"); |
| 4725 | final long identity = Binder.clearCallingIdentity(); |
| 4726 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4727 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4728 | // 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] | 4729 | return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser(); |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 4730 | } catch (ImsException e) { |
| 4731 | throw new ServiceSpecificException(e.getCode()); |
| 4732 | } finally { |
| 4733 | Binder.restoreCallingIdentity(identity); |
| 4734 | } |
| 4735 | } |
| 4736 | |
| 4737 | /** |
| 4738 | * Sets the user's setting for whether or not Voice over Cross SIM is enabled. |
| 4739 | * Requires MODIFY_PHONE_STATE permission. |
| 4740 | * @param subId The subscription to use to check the configuration. |
| 4741 | * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled, |
| 4742 | * false otherwise |
| 4743 | */ |
| 4744 | @Override |
| 4745 | public void setCrossSimCallingEnabled(int subId, boolean isEnabled) { |
| 4746 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4747 | "setCrossSimCallingEnabled"); |
| 4748 | final long identity = Binder.clearCallingIdentity(); |
| 4749 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4750 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4751 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4752 | // 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] | 4753 | ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled); |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 4754 | } catch (ImsException e) { |
| 4755 | throw new ServiceSpecificException(e.getCode()); |
| 4756 | } finally { |
| 4757 | Binder.restoreCallingIdentity(identity); |
| 4758 | } |
| 4759 | } |
| 4760 | |
| 4761 | /** |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4762 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4763 | * @param subId The subscription to use to check the configuration. |
| 4764 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4765 | @Override |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4766 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4767 | public boolean isVoWiFiRoamingSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4768 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4769 | mApp, subId, "isVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4770 | final long identity = Binder.clearCallingIdentity(); |
| 4771 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4772 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4773 | // 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] | 4774 | return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4775 | } catch (ImsException e) { |
| 4776 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4777 | } finally { |
| 4778 | Binder.restoreCallingIdentity(identity); |
| 4779 | } |
| 4780 | } |
| 4781 | |
| 4782 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4783 | public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4784 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4785 | "setVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4786 | final long identity = Binder.clearCallingIdentity(); |
| 4787 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4788 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4789 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4790 | // 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] | 4791 | ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4792 | } catch (ImsException e) { |
| 4793 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4794 | } finally { |
| 4795 | Binder.restoreCallingIdentity(identity); |
| 4796 | } |
| 4797 | } |
| 4798 | |
| 4799 | @Override |
| 4800 | public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) { |
| 4801 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4802 | "setVoWiFiNonPersistent"); |
| 4803 | final long identity = Binder.clearCallingIdentity(); |
| 4804 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4805 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4806 | // This setting will be ignored if the ImsService isn't up. |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4807 | ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4808 | } catch (ImsException e) { |
| 4809 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4810 | } finally { |
| 4811 | Binder.restoreCallingIdentity(identity); |
| 4812 | } |
| 4813 | } |
| 4814 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4815 | /** |
| 4816 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4817 | * @param subId The subscription to use to check the configuration. |
| 4818 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4819 | @Override |
| 4820 | public int getVoWiFiModeSetting(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4821 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4822 | mApp, subId, "getVoWiFiModeSetting"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4823 | final long identity = Binder.clearCallingIdentity(); |
| 4824 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4825 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4826 | // 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] | 4827 | return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4828 | } catch (ImsException e) { |
| 4829 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4830 | } finally { |
| 4831 | Binder.restoreCallingIdentity(identity); |
| 4832 | } |
| 4833 | } |
| 4834 | |
| 4835 | @Override |
| 4836 | public void setVoWiFiModeSetting(int subId, int mode) { |
| 4837 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4838 | "setVoWiFiModeSetting"); |
| 4839 | final long identity = Binder.clearCallingIdentity(); |
| 4840 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4841 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4842 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4843 | // 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] | 4844 | ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4845 | } catch (ImsException e) { |
| 4846 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4847 | } finally { |
| 4848 | Binder.restoreCallingIdentity(identity); |
| 4849 | } |
| 4850 | } |
| 4851 | |
| 4852 | @Override |
| 4853 | public int getVoWiFiRoamingModeSetting(int subId) { |
| 4854 | enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting"); |
| 4855 | final long identity = Binder.clearCallingIdentity(); |
| 4856 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4857 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4858 | // 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] | 4859 | return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4860 | } catch (ImsException e) { |
| 4861 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4862 | } finally { |
| 4863 | Binder.restoreCallingIdentity(identity); |
| 4864 | } |
| 4865 | } |
| 4866 | |
| 4867 | @Override |
| 4868 | public void setVoWiFiRoamingModeSetting(int subId, int mode) { |
| 4869 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4870 | "setVoWiFiRoamingModeSetting"); |
| 4871 | final long identity = Binder.clearCallingIdentity(); |
| 4872 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4873 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4874 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4875 | // 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] | 4876 | ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4877 | } catch (ImsException e) { |
| 4878 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4879 | } finally { |
| 4880 | Binder.restoreCallingIdentity(identity); |
| 4881 | } |
| 4882 | } |
| 4883 | |
| 4884 | @Override |
| 4885 | public void setRttCapabilitySetting(int subId, boolean isEnabled) { |
| 4886 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4887 | "setRttCapabilityEnabled"); |
| 4888 | final long identity = Binder.clearCallingIdentity(); |
| 4889 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4890 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4891 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4892 | // 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] | 4893 | ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4894 | } catch (ImsException e) { |
| 4895 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4896 | } finally { |
| 4897 | Binder.restoreCallingIdentity(identity); |
| 4898 | } |
| 4899 | } |
| 4900 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4901 | /** |
| 4902 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4903 | * @param subId The subscription to use to check the configuration. |
| 4904 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4905 | @Override |
| 4906 | public boolean isTtyOverVolteEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4907 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4908 | mApp, subId, "isTtyOverVolteEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4909 | final long identity = Binder.clearCallingIdentity(); |
| 4910 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4911 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4912 | // 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] | 4913 | return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4914 | } catch (ImsException e) { |
| 4915 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4916 | } finally { |
| 4917 | Binder.restoreCallingIdentity(identity); |
| 4918 | } |
| 4919 | } |
| 4920 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4921 | @Override |
| 4922 | public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 4923 | enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4924 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4925 | final long identity = Binder.clearCallingIdentity(); |
| 4926 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4927 | if (!isImsAvailableOnDevice()) { |
| 4928 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4929 | "IMS not available on device."); |
| 4930 | } |
| 4931 | int slotId = getSlotIndexOrException(subId); |
| 4932 | verifyImsMmTelConfiguredOrThrow(slotId); |
Hwangoo Park | 8646b0d | 2023-01-13 02:42:34 +0000 | [diff] [blame] | 4933 | |
| 4934 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4935 | if (controller != null) { |
| 4936 | ImsManager imsManager = controller.getImsManager(subId); |
| 4937 | if (imsManager != null) { |
| 4938 | imsManager.addProvisioningCallbackForSubscription(callback, subId); |
| 4939 | } else { |
| 4940 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE); |
| 4941 | } |
| 4942 | } else { |
| 4943 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION); |
| 4944 | } |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4945 | } catch (ImsException e) { |
| 4946 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4947 | } finally { |
| 4948 | Binder.restoreCallingIdentity(identity); |
| 4949 | } |
| 4950 | } |
| 4951 | |
| 4952 | @Override |
| 4953 | public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 4954 | enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4955 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4956 | final long identity = Binder.clearCallingIdentity(); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4957 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4958 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4959 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4960 | try { |
Hwangoo Park | 8646b0d | 2023-01-13 02:42:34 +0000 | [diff] [blame] | 4961 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4962 | if (controller != null) { |
| 4963 | ImsManager imsManager = controller.getImsManager(subId); |
| 4964 | if (imsManager != null) { |
| 4965 | imsManager.removeProvisioningCallbackForSubscription(callback, subId); |
| 4966 | } else { |
| 4967 | Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId |
| 4968 | + " is inactive, ignoring unregister."); |
| 4969 | // If the ImsManager is not valid, just return, since the callback will already |
| 4970 | // have been removed internally. |
| 4971 | } |
| 4972 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4973 | } finally { |
| 4974 | Binder.restoreCallingIdentity(identity); |
| 4975 | } |
| 4976 | } |
| 4977 | |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4978 | @Override |
| 4979 | public void registerFeatureProvisioningChangedCallback(int subId, |
| 4980 | IFeatureProvisioningCallback callback) { |
| 4981 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4982 | mApp, subId, "registerFeatureProvisioningChangedCallback"); |
| 4983 | |
| 4984 | final long identity = Binder.clearCallingIdentity(); |
| 4985 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4986 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4987 | } |
| 4988 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 4989 | try { |
| 4990 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 4991 | if (controller == null) { |
| 4992 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4993 | "Device does not support IMS"); |
| 4994 | } |
| 4995 | controller.addFeatureProvisioningChangedCallback(subId, callback); |
| 4996 | } finally { |
| 4997 | Binder.restoreCallingIdentity(identity); |
| 4998 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4999 | } |
| 5000 | |
| 5001 | @Override |
| 5002 | public void unregisterFeatureProvisioningChangedCallback(int subId, |
| 5003 | IFeatureProvisioningCallback callback) { |
| 5004 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5005 | mApp, subId, "unregisterFeatureProvisioningChangedCallback"); |
| 5006 | |
| 5007 | final long identity = Binder.clearCallingIdentity(); |
| 5008 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5009 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 5010 | } |
| 5011 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5012 | try { |
| 5013 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5014 | if (controller == null) { |
| 5015 | loge("unregisterFeatureProvisioningChangedCallback: Device does not support IMS"); |
| 5016 | return; |
| 5017 | } |
| 5018 | controller.removeFeatureProvisioningChangedCallback(subId, callback); |
| 5019 | } finally { |
| 5020 | Binder.restoreCallingIdentity(identity); |
| 5021 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5022 | } |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5023 | |
| 5024 | private void checkModifyPhoneStatePermission(int subId, String message) { |
| 5025 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5026 | message); |
| 5027 | } |
| 5028 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5029 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5030 | public void setRcsProvisioningStatusForCapability(int subId, int capability, int tech, |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5031 | boolean isProvisioned) { |
| 5032 | checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability"); |
| 5033 | |
| 5034 | final long identity = Binder.clearCallingIdentity(); |
| 5035 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5036 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5037 | if (controller == null) { |
| 5038 | loge("setRcsProvisioningStatusForCapability: Device does not support IMS"); |
| 5039 | return; |
| 5040 | } |
| 5041 | controller.setRcsProvisioningStatusForCapability( |
| 5042 | subId, capability, tech, isProvisioned); |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5043 | } finally { |
| 5044 | Binder.restoreCallingIdentity(identity); |
| 5045 | } |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5046 | } |
| 5047 | |
| 5048 | |
| 5049 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5050 | public boolean getRcsProvisioningStatusForCapability(int subId, int capability, int tech) { |
| 5051 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5052 | mApp, subId, "getRcsProvisioningStatusForCapability"); |
| 5053 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5054 | final long identity = Binder.clearCallingIdentity(); |
| 5055 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5056 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5057 | if (controller == null) { |
| 5058 | loge("getRcsProvisioningStatusForCapability: Device does not support IMS"); |
| 5059 | |
| 5060 | // device does not support IMS, this method will return true always. |
| 5061 | return true; |
| 5062 | } |
| 5063 | return controller.getRcsProvisioningStatusForCapability(subId, capability, tech); |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5064 | } finally { |
| 5065 | Binder.restoreCallingIdentity(identity); |
| 5066 | } |
| 5067 | } |
| 5068 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5069 | @Override |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5070 | public void setImsProvisioningStatusForCapability(int subId, int capability, int tech, |
| 5071 | boolean isProvisioned) { |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5072 | checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5073 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5074 | final long identity = Binder.clearCallingIdentity(); |
| 5075 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5076 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5077 | if (controller == null) { |
| 5078 | loge("setImsProvisioningStatusForCapability: Device does not support IMS"); |
| 5079 | return; |
| 5080 | } |
| 5081 | controller.setImsProvisioningStatusForCapability( |
| 5082 | subId, capability, tech, isProvisioned); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5083 | } finally { |
| 5084 | Binder.restoreCallingIdentity(identity); |
| 5085 | } |
| 5086 | } |
| 5087 | |
| 5088 | @Override |
| 5089 | public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) { |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5090 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5091 | mApp, subId, "getProvisioningStatusForCapability"); |
| 5092 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5093 | final long identity = Binder.clearCallingIdentity(); |
| 5094 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5095 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5096 | if (controller == null) { |
| 5097 | loge("getImsProvisioningStatusForCapability: Device does not support IMS"); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5098 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5099 | // device does not support IMS, this method will return true always. |
| 5100 | return true; |
| 5101 | } |
| 5102 | return controller.getImsProvisioningStatusForCapability(subId, capability, tech); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5103 | } finally { |
| 5104 | Binder.restoreCallingIdentity(identity); |
| 5105 | } |
| 5106 | } |
| 5107 | |
| 5108 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5109 | public boolean isProvisioningRequiredForCapability(int subId, int capability, int tech) { |
| 5110 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5111 | mApp, subId, "isProvisioningRequiredForCapability"); |
| 5112 | |
| 5113 | final long identity = Binder.clearCallingIdentity(); |
| 5114 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5115 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5116 | if (controller == null) { |
| 5117 | loge("isProvisioningRequiredForCapability: Device does not support IMS"); |
| 5118 | |
| 5119 | // device does not support IMS, this method will return false |
| 5120 | return false; |
| 5121 | } |
| 5122 | return controller.isImsProvisioningRequiredForCapability(subId, capability, tech); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5123 | } finally { |
| 5124 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5125 | } |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5126 | } |
| 5127 | |
| 5128 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5129 | public boolean isRcsProvisioningRequiredForCapability(int subId, int capability, int tech) { |
| 5130 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5131 | mApp, subId, "isProvisioningRequiredForCapability"); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5132 | |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5133 | final long identity = Binder.clearCallingIdentity(); |
| 5134 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5135 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5136 | if (controller == null) { |
| 5137 | loge("isRcsProvisioningRequiredForCapability: Device does not support IMS"); |
| 5138 | |
| 5139 | // device does not support IMS, this method will return false |
| 5140 | return false; |
| 5141 | } |
| 5142 | return controller.isRcsProvisioningRequiredForCapability(subId, capability, tech); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5143 | } finally { |
| 5144 | Binder.restoreCallingIdentity(identity); |
| 5145 | } |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5146 | } |
| 5147 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5148 | @Override |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5149 | public int getImsProvisioningInt(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5150 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5151 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 5152 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5153 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5154 | mApp, subId, "getImsProvisioningInt"); |
| 5155 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5156 | final long identity = Binder.clearCallingIdentity(); |
| 5157 | try { |
| 5158 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5159 | int slotId = getSlotIndex(subId); |
| 5160 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5161 | Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '" |
| 5162 | + subId + "' for key:" + key); |
| 5163 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
| 5164 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5165 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5166 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5167 | if (controller == null) { |
| 5168 | loge("getImsProvisioningInt: Device does not support IMS"); |
| 5169 | |
| 5170 | // device does not support IMS, this method will return CONFIG_RESULT_UNKNOWN. |
| 5171 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
| 5172 | } |
| 5173 | int retVal = controller.getProvisioningValue(subId, key); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5174 | if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) { |
| 5175 | return retVal; |
| 5176 | } |
| 5177 | |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5178 | return ImsManager.getInstance(mApp, slotId).getConfigInt(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5179 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5180 | Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '" |
| 5181 | + subId + "' for key:" + key); |
| 5182 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5183 | } finally { |
| 5184 | Binder.restoreCallingIdentity(identity); |
| 5185 | } |
| 5186 | } |
| 5187 | |
| 5188 | @Override |
| 5189 | public String getImsProvisioningString(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5190 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5191 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 5192 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5193 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5194 | mApp, subId, "getImsProvisioningString"); |
| 5195 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5196 | final long identity = Binder.clearCallingIdentity(); |
| 5197 | try { |
| 5198 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5199 | int slotId = getSlotIndex(subId); |
| 5200 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5201 | Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '" |
| 5202 | + subId + "' for key:" + key); |
| 5203 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC; |
| 5204 | } |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5205 | return ImsManager.getInstance(mApp, slotId).getConfigString(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5206 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5207 | Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '" |
| 5208 | + subId + "' for key:" + key); |
| 5209 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5210 | } finally { |
| 5211 | Binder.restoreCallingIdentity(identity); |
| 5212 | } |
| 5213 | } |
| 5214 | |
| 5215 | @Override |
| 5216 | public int setImsProvisioningInt(int subId, int key, int value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5217 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5218 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 5219 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 5220 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5221 | "setImsProvisioningInt"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5222 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5223 | final long identity = Binder.clearCallingIdentity(); |
| 5224 | try { |
| 5225 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5226 | int slotId = getSlotIndex(subId); |
| 5227 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5228 | Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '" |
| 5229 | + subId + "' for key:" + key); |
| 5230 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 5231 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5232 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5233 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5234 | if (controller == null) { |
| 5235 | loge("setImsProvisioningInt: Device does not support IMS"); |
| 5236 | |
| 5237 | // device does not support IMS, this method will return CONFIG_RESULT_FAILED. |
| 5238 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 5239 | } |
| 5240 | int retVal = controller.setProvisioningValue(subId, key, value); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5241 | if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) { |
| 5242 | return retVal; |
| 5243 | } |
| 5244 | |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5245 | return ImsManager.getInstance(mApp, slotId).setConfig(key, value); |
| 5246 | } catch (com.android.ims.ImsException | RemoteException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5247 | Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5248 | + "' for key:" + key, e); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5249 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5250 | } finally { |
| 5251 | Binder.restoreCallingIdentity(identity); |
| 5252 | } |
| 5253 | } |
| 5254 | |
| 5255 | @Override |
| 5256 | public int setImsProvisioningString(int subId, int key, String value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5257 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5258 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 5259 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 5260 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5261 | "setImsProvisioningString"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5262 | final long identity = Binder.clearCallingIdentity(); |
| 5263 | try { |
| 5264 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5265 | int slotId = getSlotIndex(subId); |
| 5266 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5267 | Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '" |
| 5268 | + subId + "' for key:" + key); |
| 5269 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 5270 | } |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5271 | return ImsManager.getInstance(mApp, slotId).setConfig(key, value); |
| 5272 | } catch (com.android.ims.ImsException | RemoteException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5273 | Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5274 | + "' for key:" + key, e); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5275 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5276 | } finally { |
| 5277 | Binder.restoreCallingIdentity(identity); |
| 5278 | } |
| 5279 | } |
| 5280 | |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5281 | /** |
| 5282 | * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL |
| 5283 | * for the given slot ID or no ImsResolver instance has been created. |
| 5284 | * @param slotId The slot ID that the IMS service is created for. |
| 5285 | * @throws ImsException If there is no ImsService configured for this slot. |
| 5286 | */ |
| 5287 | private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException { |
| 5288 | if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId, |
| 5289 | ImsFeature.FEATURE_MMTEL)) { |
| 5290 | throw new ImsException("This subscription does not support MMTEL over IMS", |
| 5291 | ImsException.CODE_ERROR_UNSUPPORTED_OPERATION); |
| 5292 | } |
| 5293 | } |
| 5294 | |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5295 | private int getSlotIndexOrException(int subId) throws ImsException { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5296 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 5297 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5298 | throw new ImsException("Invalid Subscription Id, subId=" + subId, |
| 5299 | ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5300 | } |
| 5301 | return slotId; |
| 5302 | } |
| 5303 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5304 | private int getSlotIndex(int subId) { |
| 5305 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 5306 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
| 5307 | return SubscriptionManager.INVALID_SIM_SLOT_INDEX; |
| 5308 | } |
| 5309 | return slotId; |
| 5310 | } |
| 5311 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5312 | /** |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 5313 | * Returns the data network type for a subId; does not throw SecurityException. |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5314 | */ |
| 5315 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5316 | public int getNetworkTypeForSubscriber(int subId, String callingPackage, |
| 5317 | String callingFeatureId) { |
Shuo Qian | 13d8915 | 2021-05-10 23:58:11 -0700 | [diff] [blame] | 5318 | try { |
| 5319 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 5320 | } catch (SecurityException se) { |
| 5321 | EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid()); |
| 5322 | throw new SecurityException("Package " + callingPackage + " does not belong to " |
| 5323 | + Binder.getCallingUid()); |
| 5324 | } |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 5325 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 5326 | if (targetSdk > android.os.Build.VERSION_CODES.Q) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5327 | return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 5328 | } else if (targetSdk == android.os.Build.VERSION_CODES.Q |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 5329 | && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 5330 | mApp, subId, callingPackage, callingFeatureId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5331 | "getNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5332 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5333 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 5334 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5335 | final long identity = Binder.clearCallingIdentity(); |
| 5336 | try { |
| 5337 | final Phone phone = getPhone(subId); |
| 5338 | if (phone != null) { |
| 5339 | return phone.getServiceState().getDataNetworkType(); |
| 5340 | } else { |
| 5341 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5342 | } |
| 5343 | } finally { |
| 5344 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5345 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5346 | } |
| 5347 | |
| 5348 | /** |
| 5349 | * Returns the data network type |
| 5350 | */ |
| 5351 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5352 | public int getDataNetworkType(String callingPackage, String callingFeatureId) { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5353 | return getDataNetworkTypeForSubscriber(SubscriptionManager.getDefaultDataSubscriptionId(), |
Zoey Chen | fd61f7f | 2021-04-21 13:42:10 +0800 | [diff] [blame] | 5354 | callingPackage, callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5355 | } |
| 5356 | |
| 5357 | /** |
| 5358 | * Returns the data network type for a subId |
| 5359 | */ |
| 5360 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5361 | public int getDataNetworkTypeForSubscriber(int subId, String callingPackage, |
| 5362 | String callingFeatureId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 5363 | String functionName = "getDataNetworkTypeForSubscriber"; |
| 5364 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 5365 | mApp, functionName)) { |
| 5366 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 5367 | mApp, subId, callingPackage, callingFeatureId, functionName)) { |
| 5368 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5369 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5370 | } |
| 5371 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5372 | final long identity = Binder.clearCallingIdentity(); |
| 5373 | try { |
| 5374 | final Phone phone = getPhone(subId); |
| 5375 | if (phone != null) { |
| 5376 | return phone.getServiceState().getDataNetworkType(); |
| 5377 | } else { |
| 5378 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5379 | } |
| 5380 | } finally { |
| 5381 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5382 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5383 | } |
| 5384 | |
| 5385 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5386 | * Returns the Voice network type for a subId |
| 5387 | */ |
| 5388 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5389 | public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage, |
| 5390 | String callingFeatureId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 5391 | String functionName = "getVoiceNetworkTypeForSubscriber"; |
| 5392 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 5393 | mApp, functionName)) { |
| 5394 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 5395 | mApp, subId, callingPackage, callingFeatureId, functionName)) { |
| 5396 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5397 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 5398 | } |
| 5399 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5400 | final long identity = Binder.clearCallingIdentity(); |
| 5401 | try { |
| 5402 | final Phone phone = getPhone(subId); |
| 5403 | if (phone != null) { |
| 5404 | return phone.getServiceState().getVoiceNetworkType(); |
| 5405 | } else { |
| 5406 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5407 | } |
| 5408 | } finally { |
| 5409 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5410 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5411 | } |
| 5412 | |
| 5413 | /** |
| 5414 | * @return true if a ICC card is present |
| 5415 | */ |
| 5416 | public boolean hasIccCard() { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5417 | // FIXME Make changes to pass defaultSimId of type int |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5418 | return hasIccCardUsingSlotIndex(SubscriptionManager.getSlotIndex( |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5419 | getDefaultSubscription())); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5420 | } |
| 5421 | |
| 5422 | /** |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5423 | * @return true if a ICC card is present for a slotIndex |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5424 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5425 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5426 | public boolean hasIccCardUsingSlotIndex(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5427 | final long identity = Binder.clearCallingIdentity(); |
| 5428 | try { |
| 5429 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5430 | if (phone != null) { |
| 5431 | return phone.getIccCard().hasIccCard(); |
| 5432 | } else { |
| 5433 | return false; |
| 5434 | } |
| 5435 | } finally { |
| 5436 | Binder.restoreCallingIdentity(identity); |
Amit Mahajan | a6fc2a8 | 2015-01-06 11:53:51 -0800 | [diff] [blame] | 5437 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5438 | } |
| 5439 | |
| 5440 | /** |
| 5441 | * Return if the current radio is LTE on CDMA. This |
| 5442 | * is a tri-state return value as for a period of time |
| 5443 | * the mode may be unknown. |
| 5444 | * |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5445 | * @param callingPackage the name of the package making the call. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5446 | * @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] | 5447 | * or {@link Phone#LTE_ON_CDMA_TRUE} |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5448 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5449 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5450 | public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) { |
| 5451 | return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 5452 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5453 | } |
| 5454 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5455 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5456 | public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage, |
| 5457 | String callingFeatureId) { |
Sarah Chin | 790d292 | 2020-01-16 12:17:23 -0800 | [diff] [blame] | 5458 | try { |
| 5459 | enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber"); |
| 5460 | } catch (SecurityException e) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5461 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 5462 | } |
| 5463 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5464 | final long identity = Binder.clearCallingIdentity(); |
| 5465 | try { |
| 5466 | final Phone phone = getPhone(subId); |
| 5467 | if (phone == null) { |
| 5468 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 5469 | } else { |
Nathan Harold | 05ad633 | 2020-07-10 11:54:36 -0700 | [diff] [blame] | 5470 | return TelephonyProperties.lte_on_cdma_device() |
| 5471 | .orElse(PhoneConstants.LTE_ON_CDMA_FALSE); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5472 | } |
| 5473 | } finally { |
| 5474 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5475 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5476 | } |
| 5477 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5478 | /** |
| 5479 | * {@hide} |
| 5480 | * Returns Default subId, 0 in the case of single standby. |
| 5481 | */ |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 5482 | private int getDefaultSubscription() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5483 | return SubscriptionManager.getDefaultSubscriptionId(); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5484 | } |
| 5485 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 5486 | private int getSlotForDefaultSubscription() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5487 | return SubscriptionManager.getPhoneId(getDefaultSubscription()); |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 5488 | } |
| 5489 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 5490 | private int getPreferredVoiceSubscription() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5491 | return SubscriptionManager.getDefaultVoiceSubscriptionId(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5492 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5493 | |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 5494 | private boolean isActiveSubscription(int subId) { |
Jack Yu | 3beaf9d | 2023-04-14 09:17:27 -0700 | [diff] [blame] | 5495 | return getSubscriptionManagerService().isActiveSubId(subId, |
| 5496 | mApp.getOpPackageName(), mApp.getFeatureId()); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 5497 | } |
| 5498 | |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5499 | /** |
| 5500 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 5501 | */ |
| 5502 | public int getWhenToMakeWifiCalls() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5503 | final long identity = Binder.clearCallingIdentity(); |
| 5504 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5505 | return Settings.System.getInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5506 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, |
| 5507 | getWhenToMakeWifiCallsDefaultPreference()); |
| 5508 | } finally { |
| 5509 | Binder.restoreCallingIdentity(identity); |
| 5510 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5511 | } |
| 5512 | |
| 5513 | /** |
| 5514 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 5515 | */ |
| 5516 | public void setWhenToMakeWifiCalls(int preference) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5517 | final long identity = Binder.clearCallingIdentity(); |
| 5518 | try { |
| 5519 | if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5520 | Settings.System.putInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5521 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference); |
| 5522 | } finally { |
| 5523 | Binder.restoreCallingIdentity(identity); |
| 5524 | } |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 5525 | } |
| 5526 | |
Sailesh Nepal | d1e6815 | 2013-12-12 19:08:02 -0800 | [diff] [blame] | 5527 | private static int getWhenToMakeWifiCallsDefaultPreference() { |
Santos Cordon | da120f4 | 2014-08-06 04:44:34 -0700 | [diff] [blame] | 5528 | // TODO: Use a build property to choose this value. |
Evan Charlton | 9829e88 | 2013-12-19 15:30:38 -0800 | [diff] [blame] | 5529 | return TelephonyManager.WifiCallingChoices.ALWAYS_USE; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5530 | } |
Shishir Agrawal | 69f6812 | 2013-12-16 17:25:49 -0800 | [diff] [blame] | 5531 | |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5532 | private Phone getPhoneFromSlotPortIndexOrThrowException(int slotIndex, int portIndex) { |
| 5533 | int phoneId = UiccController.getInstance().getPhoneIdFromSlotPortIndex(slotIndex, |
| 5534 | portIndex); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5535 | if (phoneId == -1) { |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5536 | throw new IllegalArgumentException("Given slot index: " + slotIndex + " port index: " |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 5537 | + portIndex + " does not correspond to an active phone"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5538 | } |
| 5539 | return PhoneFactory.getPhone(phoneId); |
| 5540 | } |
| 5541 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5542 | @Override |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 5543 | public IccOpenLogicalChannelResponse iccOpenLogicalChannel( |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5544 | @NonNull IccLogicalChannelRequest request) { |
| 5545 | Phone phone = getPhoneFromValidIccLogicalChannelRequest(request, |
| 5546 | /*message=*/ "iccOpenLogicalChannel"); |
| 5547 | |
| 5548 | if (DBG) log("iccOpenLogicalChannel: request=" + request); |
| 5549 | // Verify that the callingPackage in the request belongs to the calling UID |
| 5550 | mAppOps.checkPackage(Binder.getCallingUid(), request.callingPackage); |
| 5551 | |
| 5552 | return iccOpenLogicalChannelWithPermission(phone, request); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5553 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5554 | |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5555 | private Phone getPhoneFromValidIccLogicalChannelRequest( |
| 5556 | @NonNull IccLogicalChannelRequest request, String message) { |
| 5557 | Phone phone; |
| 5558 | if (request.subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) { |
| 5559 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5560 | mApp, request.subId, message); |
| 5561 | phone = getPhoneFromSubId(request.subId); |
| 5562 | } else if (request.slotIndex != SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5563 | enforceModifyPermission(); |
| 5564 | phone = getPhoneFromSlotPortIndexOrThrowException(request.slotIndex, request.portIndex); |
| 5565 | } else { |
| 5566 | throw new IllegalArgumentException("Both subId and slotIndex in request are invalid."); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5567 | } |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5568 | return phone; |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5569 | } |
| 5570 | |
| 5571 | private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone, |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5572 | IccLogicalChannelRequest channelRequest) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5573 | final long identity = Binder.clearCallingIdentity(); |
| 5574 | try { |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5575 | if (TextUtils.equals(ISDR_AID, channelRequest.aid)) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5576 | // Only allows LPA to open logical channel to ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5577 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 5578 | .getContext().getPackageManager()); |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5579 | if (bestComponent == null || !TextUtils.equals(channelRequest.callingPackage, |
| 5580 | bestComponent.packageName)) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5581 | loge("The calling package is not allowed to access ISD-R."); |
| 5582 | throw new SecurityException( |
| 5583 | "The calling package is not allowed to access ISD-R."); |
| 5584 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 5585 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 5586 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5587 | IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest( |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5588 | CMD_OPEN_CHANNEL, channelRequest, phone, null /* workSource */); |
| 5589 | if (DBG) log("iccOpenLogicalChannelWithPermission: response=" + response); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5590 | return response; |
| 5591 | } finally { |
| 5592 | Binder.restoreCallingIdentity(identity); |
| 5593 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5594 | } |
| 5595 | |
| 5596 | @Override |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5597 | public boolean iccCloseLogicalChannel(@NonNull IccLogicalChannelRequest request) { |
| 5598 | Phone phone = getPhoneFromValidIccLogicalChannelRequest(request, |
| 5599 | /*message=*/"iccCloseLogicalChannel"); |
| 5600 | |
| 5601 | if (DBG) log("iccCloseLogicalChannel: request=" + request); |
| 5602 | |
| 5603 | return iccCloseLogicalChannelWithPermission(phone, request); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5604 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5605 | |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5606 | private boolean iccCloseLogicalChannelWithPermission(Phone phone, |
| 5607 | IccLogicalChannelRequest request) { |
Chen Xu | a8f0dff | 2022-02-12 00:34:15 -0800 | [diff] [blame] | 5608 | // before this feature is enabled, this API should only return false if |
| 5609 | // the operation fails instead of throwing runtime exception for |
| 5610 | // backward-compatibility. |
| 5611 | final boolean shouldThrowExceptionOnFailure = CompatChanges.isChangeEnabled( |
| 5612 | ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE, Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5613 | final long identity = Binder.clearCallingIdentity(); |
| 5614 | try { |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5615 | if (request.channel < 0) { |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 5616 | throw new IllegalArgumentException("request.channel is less than 0"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5617 | } |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 5618 | Object result = sendRequest(CMD_CLOSE_CHANNEL, request.channel, phone, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5619 | null /* workSource */); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 5620 | Boolean success = false; |
| 5621 | if (result instanceof RuntimeException) { |
| 5622 | // if there is an exception returned, throw from the binder thread here. |
Chen Xu | a8f0dff | 2022-02-12 00:34:15 -0800 | [diff] [blame] | 5623 | if (shouldThrowExceptionOnFailure) { |
| 5624 | throw (RuntimeException) result; |
| 5625 | } else { |
| 5626 | return false; |
| 5627 | } |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 5628 | } else if (result instanceof Boolean) { |
| 5629 | success = (Boolean) result; |
| 5630 | } else { |
| 5631 | loge("iccCloseLogicalChannelWithPermission: supported return type " + result); |
| 5632 | } |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5633 | if (DBG) log("iccCloseLogicalChannelWithPermission: success=" + success); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5634 | return success; |
| 5635 | } finally { |
| 5636 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5637 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5638 | } |
| 5639 | |
| 5640 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5641 | public String iccTransmitApduLogicalChannel(int subId, int channel, int cla, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5642 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5643 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5644 | mApp, subId, "iccTransmitApduLogicalChannel"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5645 | if (DBG) { |
| 5646 | log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel |
| 5647 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 5648 | + p3 + " data=" + data); |
| 5649 | } |
| 5650 | return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla, |
| 5651 | command, p1, p2, p3, data); |
| 5652 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5653 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5654 | @Override |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5655 | public String iccTransmitApduLogicalChannelByPort(int slotIndex, int portIndex, int channel, |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 5656 | int cla, int command, int p1, int p2, int p3, String data) { |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5657 | enforceModifyPermission(); |
| 5658 | if (DBG) { |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5659 | log("iccTransmitApduLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex=" |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 5660 | + portIndex + " chnl=" + channel + " cla=" + cla + " cmd=" + command + " p1=" |
| 5661 | + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5662 | } |
| 5663 | return iccTransmitApduLogicalChannelWithPermission( |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5664 | getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel, cla, |
| 5665 | command, p1, p2, p3, data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5666 | } |
| 5667 | |
| 5668 | private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla, |
| 5669 | int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5670 | final long identity = Binder.clearCallingIdentity(); |
| 5671 | try { |
Hall Liu | 4fd771b | 2019-05-02 09:16:29 -0700 | [diff] [blame] | 5672 | if (channel <= 0) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5673 | return ""; |
| 5674 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5675 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5676 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5677 | new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone, |
| 5678 | null /* workSource */); |
| 5679 | if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response); |
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 | // Append the returned status code to the end of the response payload. |
| 5682 | String s = Integer.toHexString( |
| 5683 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 5684 | if (response.payload != null) { |
| 5685 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 5686 | } |
| 5687 | return s; |
| 5688 | } finally { |
| 5689 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 5690 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5691 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5692 | |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5693 | @Override |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 5694 | public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla, |
| 5695 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5696 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5697 | mApp, subId, "iccTransmitApduBasicChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5698 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5699 | if (DBG) { |
| 5700 | log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" |
| 5701 | + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
| 5702 | } |
| 5703 | return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage, |
| 5704 | cla, command, p1, p2, p3, data); |
| 5705 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5706 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5707 | @Override |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5708 | public String iccTransmitApduBasicChannelByPort(int slotIndex, int portIndex, |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 5709 | 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] | 5710 | enforceModifyPermission(); |
| 5711 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 5712 | if (DBG) { |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5713 | log("iccTransmitApduBasicChannelByPort: slotIndex=" + slotIndex + " portIndex=" |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 5714 | + portIndex + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" |
| 5715 | + p2 + " p3=" + p3 + " data=" + data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5716 | } |
| 5717 | |
| 5718 | return iccTransmitApduBasicChannelWithPermission( |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5719 | getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), callingPackage, |
| 5720 | cla, command, p1, p2, p3, data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5721 | } |
| 5722 | |
| 5723 | // open APDU basic channel assuming the caller has sufficient permissions |
| 5724 | private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage, |
| 5725 | int cla, int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5726 | final long identity = Binder.clearCallingIdentity(); |
| 5727 | try { |
| 5728 | if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3 |
| 5729 | && TextUtils.equals(ISDR_AID, data)) { |
| 5730 | // Only allows LPA to select ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5731 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 5732 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5733 | if (bestComponent == null |
| 5734 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 5735 | loge("The calling package is not allowed to select ISD-R."); |
| 5736 | throw new SecurityException( |
| 5737 | "The calling package is not allowed to select ISD-R."); |
| 5738 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 5739 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 5740 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5741 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5742 | new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone, |
| 5743 | null /* workSource */); |
| 5744 | if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5745 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5746 | // Append the returned status code to the end of the response payload. |
| 5747 | String s = Integer.toHexString( |
| 5748 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 5749 | if (response.payload != null) { |
| 5750 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 5751 | } |
| 5752 | return s; |
| 5753 | } finally { |
| 5754 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 5755 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5756 | } |
| 5757 | |
| 5758 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5759 | 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] | 5760 | String filePath) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5761 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5762 | mApp, subId, "iccExchangeSimIO"); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5763 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5764 | final long identity = Binder.clearCallingIdentity(); |
| 5765 | try { |
| 5766 | if (DBG) { |
| 5767 | log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " |
| 5768 | + p1 + " " + p2 + " " + p3 + ":" + filePath); |
| 5769 | } |
| 5770 | |
| 5771 | IccIoResult response = |
| 5772 | (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO, |
| 5773 | new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath), |
| 5774 | subId); |
| 5775 | |
| 5776 | if (DBG) { |
| 5777 | log("Exchange SIM_IO [R]" + response); |
| 5778 | } |
| 5779 | |
| 5780 | byte[] result = null; |
| 5781 | int length = 2; |
| 5782 | if (response.payload != null) { |
| 5783 | length = 2 + response.payload.length; |
| 5784 | result = new byte[length]; |
| 5785 | System.arraycopy(response.payload, 0, result, 0, response.payload.length); |
| 5786 | } else { |
| 5787 | result = new byte[length]; |
| 5788 | } |
| 5789 | |
| 5790 | result[length - 1] = (byte) response.sw2; |
| 5791 | result[length - 2] = (byte) response.sw1; |
| 5792 | return result; |
| 5793 | } finally { |
| 5794 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5795 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5796 | } |
| 5797 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5798 | /** |
| 5799 | * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM) |
| 5800 | * on a particular subscription |
| 5801 | */ |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5802 | public String[] getForbiddenPlmns(int subId, int appType, String callingPackage, |
| 5803 | String callingFeatureId) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 5804 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5805 | mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 5806 | return null; |
| 5807 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5808 | |
| 5809 | final long identity = Binder.clearCallingIdentity(); |
| 5810 | try { |
| 5811 | if (appType != TelephonyManager.APPTYPE_USIM |
| 5812 | && appType != TelephonyManager.APPTYPE_SIM) { |
| 5813 | loge("getForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 5814 | return null; |
| 5815 | } |
| 5816 | Object response = sendRequest( |
| 5817 | CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId); |
| 5818 | if (response instanceof String[]) { |
| 5819 | return (String[]) response; |
| 5820 | } |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5821 | // Response is an Exception of some kind |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5822 | // which is signalled to the user as a NULL retval |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5823 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5824 | } finally { |
| 5825 | Binder.restoreCallingIdentity(identity); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5826 | } |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5827 | } |
| 5828 | |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5829 | /** |
| 5830 | * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular |
| 5831 | * subscription. |
| 5832 | * |
| 5833 | * @param subId the id of the subscription. |
| 5834 | * @param appType the uicc app type, must be USIM or SIM. |
| 5835 | * @param fplmns the Forbiden plmns list that needed to be written to the SIM. |
| 5836 | * @param callingPackage the op Package name. |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5837 | * @param callingFeatureId the feature in the package. |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5838 | * @return number of fplmns that is successfully written to the SIM. |
| 5839 | */ |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5840 | public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage, |
| 5841 | String callingFeatureId) { |
Jayachandran C | 5b0d75a | 2021-10-21 22:15:27 -0700 | [diff] [blame] | 5842 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5843 | mApp, subId, "setForbiddenPlmns"); |
| 5844 | |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5845 | if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) { |
| 5846 | loge("setForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 5847 | throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM"); |
| 5848 | } |
| 5849 | if (fplmns == null) { |
| 5850 | throw new IllegalArgumentException("Fplmn List provided is null"); |
| 5851 | } |
| 5852 | for (String fplmn : fplmns) { |
| 5853 | if (!CellIdentity.isValidPlmn(fplmn)) { |
| 5854 | throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn); |
| 5855 | } |
| 5856 | } |
| 5857 | final long identity = Binder.clearCallingIdentity(); |
| 5858 | try { |
| 5859 | Object response = sendRequest( |
| 5860 | CMD_SET_FORBIDDEN_PLMNS, |
| 5861 | new Pair<Integer, List<String>>(new Integer(appType), fplmns), |
| 5862 | subId); |
| 5863 | return (int) response; |
| 5864 | } finally { |
| 5865 | Binder.restoreCallingIdentity(identity); |
| 5866 | } |
| 5867 | } |
| 5868 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5869 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5870 | public String sendEnvelopeWithStatus(int subId, String content) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5871 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5872 | mApp, subId, "sendEnvelopeWithStatus"); |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5873 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5874 | final long identity = Binder.clearCallingIdentity(); |
| 5875 | try { |
| 5876 | IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId); |
| 5877 | if (response.payload == null) { |
| 5878 | return ""; |
| 5879 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5880 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5881 | // Append the returned status code to the end of the response payload. |
| 5882 | String s = Integer.toHexString( |
| 5883 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 5884 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 5885 | return s; |
| 5886 | } finally { |
| 5887 | Binder.restoreCallingIdentity(identity); |
| 5888 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5889 | } |
| 5890 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5891 | /** |
| 5892 | * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 5893 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 5894 | * |
| 5895 | * @param itemID the ID of the item to read |
| 5896 | * @return the NV item as a String, or null on error. |
| 5897 | */ |
| 5898 | @Override |
| 5899 | public String nvReadItem(int itemID) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5900 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5901 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5902 | mApp, getDefaultSubscription(), "nvReadItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5903 | |
| 5904 | final long identity = Binder.clearCallingIdentity(); |
| 5905 | try { |
| 5906 | if (DBG) log("nvReadItem: item " + itemID); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5907 | String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5908 | if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"'); |
| 5909 | return value; |
| 5910 | } finally { |
| 5911 | Binder.restoreCallingIdentity(identity); |
| 5912 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5913 | } |
| 5914 | |
| 5915 | /** |
| 5916 | * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 5917 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 5918 | * |
| 5919 | * @param itemID the ID of the item to read |
| 5920 | * @param itemValue the value to write, as a String |
| 5921 | * @return true on success; false on any failure |
| 5922 | */ |
| 5923 | @Override |
| 5924 | public boolean nvWriteItem(int itemID, String itemValue) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5925 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5926 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5927 | mApp, getDefaultSubscription(), "nvWriteItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5928 | |
| 5929 | final long identity = Binder.clearCallingIdentity(); |
| 5930 | try { |
| 5931 | if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"'); |
| 5932 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5933 | new Pair<Integer, String>(itemID, itemValue), workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5934 | if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail")); |
| 5935 | return success; |
| 5936 | } finally { |
| 5937 | Binder.restoreCallingIdentity(identity); |
| 5938 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5939 | } |
| 5940 | |
| 5941 | /** |
| 5942 | * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage. |
| 5943 | * Used for device configuration by some CDMA operators. |
| 5944 | * |
| 5945 | * @param preferredRoamingList byte array containing the new PRL |
| 5946 | * @return true on success; false on any failure |
| 5947 | */ |
| 5948 | @Override |
| 5949 | public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5950 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5951 | mApp, getDefaultSubscription(), "nvWriteCdmaPrl"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5952 | |
| 5953 | final long identity = Binder.clearCallingIdentity(); |
| 5954 | try { |
| 5955 | if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList)); |
| 5956 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList); |
| 5957 | if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail")); |
| 5958 | return success; |
| 5959 | } finally { |
| 5960 | Binder.restoreCallingIdentity(identity); |
| 5961 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5962 | } |
| 5963 | |
| 5964 | /** |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5965 | * 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] | 5966 | * Used for device configuration by some CDMA operators. |
| 5967 | * |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5968 | * @param slotIndex - device slot. |
| 5969 | * |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5970 | * @return true on success; false on any failure |
| 5971 | */ |
| 5972 | @Override |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5973 | public boolean resetModemConfig(int slotIndex) { |
| 5974 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5975 | if (phone != null) { |
| 5976 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5977 | mApp, phone.getSubId(), "resetModemConfig"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5978 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5979 | final long identity = Binder.clearCallingIdentity(); |
| 5980 | try { |
| 5981 | Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null); |
| 5982 | if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 5983 | return success; |
| 5984 | } finally { |
| 5985 | Binder.restoreCallingIdentity(identity); |
| 5986 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5987 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5988 | return false; |
| 5989 | } |
| 5990 | |
| 5991 | /** |
| 5992 | * Generate a radio modem reset. Used for device configuration by some CDMA operators. |
| 5993 | * |
| 5994 | * @param slotIndex - device slot. |
| 5995 | * |
| 5996 | * @return true on success; false on any failure |
| 5997 | */ |
| 5998 | @Override |
| 5999 | public boolean rebootModem(int slotIndex) { |
| 6000 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 6001 | if (phone != null) { |
| 6002 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6003 | mApp, phone.getSubId(), "rebootModem"); |
| 6004 | |
| 6005 | final long identity = Binder.clearCallingIdentity(); |
| 6006 | try { |
| 6007 | Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null); |
| 6008 | if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail")); |
| 6009 | return success; |
| 6010 | } finally { |
| 6011 | Binder.restoreCallingIdentity(identity); |
| 6012 | } |
| 6013 | } |
| 6014 | return false; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 6015 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 6016 | |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 6017 | /** |
Grace Jia | aa2eb6b | 2020-01-09 16:26:08 -0800 | [diff] [blame] | 6018 | * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and |
| 6019 | * {@link #disableIms(int)}. |
| 6020 | * @param slotIndex device slot. |
| 6021 | */ |
| 6022 | public void resetIms(int slotIndex) { |
| 6023 | enforceModifyPermission(); |
| 6024 | |
| 6025 | final long identity = Binder.clearCallingIdentity(); |
| 6026 | try { |
| 6027 | if (mImsResolver == null) { |
| 6028 | // may happen if the does not support IMS. |
| 6029 | return; |
| 6030 | } |
Hyunho | a17ac7c | 2022-08-30 12:03:04 +0000 | [diff] [blame] | 6031 | mImsResolver.resetIms(slotIndex); |
Grace Jia | aa2eb6b | 2020-01-09 16:26:08 -0800 | [diff] [blame] | 6032 | } finally { |
| 6033 | Binder.restoreCallingIdentity(identity); |
| 6034 | } |
| 6035 | } |
| 6036 | |
| 6037 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6038 | * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability |
| 6039 | * status updates, if not already enabled. |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 6040 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6041 | public void enableIms(int slotId) { |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 6042 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6043 | |
| 6044 | final long identity = Binder.clearCallingIdentity(); |
| 6045 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6046 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6047 | // may happen if the device does not support IMS. |
| 6048 | return; |
| 6049 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6050 | mImsResolver.enableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6051 | } finally { |
| 6052 | Binder.restoreCallingIdentity(identity); |
| 6053 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 6054 | } |
| 6055 | |
| 6056 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6057 | * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature |
| 6058 | * status updates to disabled. |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 6059 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6060 | public void disableIms(int slotId) { |
| 6061 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6062 | |
| 6063 | final long identity = Binder.clearCallingIdentity(); |
| 6064 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6065 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6066 | // may happen if the device does not support IMS. |
| 6067 | return; |
| 6068 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6069 | mImsResolver.disableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6070 | } finally { |
| 6071 | Binder.restoreCallingIdentity(identity); |
| 6072 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6073 | } |
| 6074 | |
| 6075 | /** |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 6076 | * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback |
| 6077 | * callback. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6078 | */ |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 6079 | @Override |
Brad Ebinger | f6aca00 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 6080 | public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) { |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 6081 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6082 | |
| 6083 | final long identity = Binder.clearCallingIdentity(); |
| 6084 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6085 | if (mImsResolver == null) { |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 6086 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 6087 | "Device does not support IMS"); |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6088 | } |
Brad Ebinger | f6aca00 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 6089 | mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6090 | } finally { |
| 6091 | Binder.restoreCallingIdentity(identity); |
| 6092 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 6093 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 6094 | /** |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 6095 | * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature. |
| 6096 | */ |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 6097 | @Override |
| 6098 | public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) { |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 6099 | enforceModifyPermission(); |
| 6100 | |
| 6101 | final long identity = Binder.clearCallingIdentity(); |
| 6102 | try { |
| 6103 | if (mImsResolver == null) return; |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 6104 | mImsResolver.unregisterImsFeatureCallback(callback); |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 6105 | } finally { |
| 6106 | Binder.restoreCallingIdentity(identity); |
| 6107 | } |
| 6108 | } |
| 6109 | |
| 6110 | /** |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 6111 | * Returns the {@link IImsRegistration} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6112 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 6113 | */ |
| 6114 | public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException { |
| 6115 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6116 | |
| 6117 | final long identity = Binder.clearCallingIdentity(); |
| 6118 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6119 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6120 | // may happen if the device does not support IMS. |
| 6121 | return null; |
| 6122 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6123 | return mImsResolver.getImsRegistration(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6124 | } finally { |
| 6125 | Binder.restoreCallingIdentity(identity); |
| 6126 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 6127 | } |
| 6128 | |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6129 | /** |
| 6130 | * Returns the {@link IImsConfig} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6131 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6132 | */ |
| 6133 | public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException { |
| 6134 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6135 | |
| 6136 | final long identity = Binder.clearCallingIdentity(); |
| 6137 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6138 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6139 | // may happen if the device does not support IMS. |
| 6140 | return null; |
| 6141 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6142 | return mImsResolver.getImsConfig(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6143 | } finally { |
| 6144 | Binder.restoreCallingIdentity(identity); |
| 6145 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6146 | } |
| 6147 | |
Brad Ebinger | 884c07b | 2018-02-15 16:17:40 -0800 | [diff] [blame] | 6148 | /** |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6149 | * Sets the ImsService Package Name that Telephony will bind to. |
| 6150 | * |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6151 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 6152 | * @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] | 6153 | * ImsService is the device default ImsService. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6154 | * @param featureTypes An integer array of feature types associated with a packageName. |
| 6155 | * @param packageName The name of the package that the current configuration will be replaced |
| 6156 | * with. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6157 | * @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] | 6158 | */ |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6159 | public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService, |
| 6160 | int[] featureTypes, String packageName) { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6161 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 6162 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
Jack Yu | 00ece8c | 2022-11-19 22:29:12 -0800 | [diff] [blame] | 6163 | SubscriptionManager.getSubscriptionId(slotIndex), "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 6164 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6165 | final long identity = Binder.clearCallingIdentity(); |
| 6166 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6167 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6168 | // may happen if the device does not support IMS. |
| 6169 | return false; |
| 6170 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6171 | Map<Integer, String> featureConfig = new HashMap<>(); |
| 6172 | for (int featureType : featureTypes) { |
| 6173 | featureConfig.put(featureType, packageName); |
| 6174 | } |
| 6175 | return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService, |
| 6176 | featureConfig); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6177 | } finally { |
| 6178 | Binder.restoreCallingIdentity(identity); |
| 6179 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6180 | } |
| 6181 | |
| 6182 | /** |
Brad Ebinger | 999d330 | 2020-11-25 14:31:39 -0800 | [diff] [blame] | 6183 | * Clears any carrier ImsService overrides for the slot index specified that were previously |
| 6184 | * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}. |
| 6185 | * |
| 6186 | * This should only be used for testing. |
| 6187 | * |
| 6188 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 6189 | * @return true if clearing the carrier ImsService override succeeded or false if it did not. |
| 6190 | */ |
| 6191 | @Override |
| 6192 | public boolean clearCarrierImsServiceOverride(int slotIndex) { |
Brad Ebinger | 999d330 | 2020-11-25 14:31:39 -0800 | [diff] [blame] | 6193 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 6194 | "clearCarrierImsServiceOverride"); |
| 6195 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
Jack Yu | 00ece8c | 2022-11-19 22:29:12 -0800 | [diff] [blame] | 6196 | SubscriptionManager.getSubscriptionId(slotIndex), "clearCarrierImsServiceOverride"); |
Brad Ebinger | 999d330 | 2020-11-25 14:31:39 -0800 | [diff] [blame] | 6197 | |
| 6198 | final long identity = Binder.clearCallingIdentity(); |
| 6199 | try { |
| 6200 | if (mImsResolver == null) { |
| 6201 | // may happen if the device does not support IMS. |
| 6202 | return false; |
| 6203 | } |
| 6204 | return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex); |
| 6205 | } finally { |
| 6206 | Binder.restoreCallingIdentity(identity); |
| 6207 | } |
| 6208 | } |
| 6209 | |
| 6210 | /** |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6211 | * Return the package name of the currently bound ImsService. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6212 | * |
| 6213 | * @param slotId The slot that the ImsService is associated with. |
| 6214 | * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is |
| 6215 | * the device default. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6216 | * @param featureType The feature associated with the queried configuration. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6217 | * @return the package name of the ImsService configuration. |
| 6218 | */ |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6219 | public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService, |
| 6220 | @ImsFeature.FeatureType int featureType) { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6221 | TelephonyPermissions |
Jack Yu | 00ece8c | 2022-11-19 22:29:12 -0800 | [diff] [blame] | 6222 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(mApp, |
| 6223 | SubscriptionManager.getSubscriptionId(slotId), "getBoundImsServicePackage"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 6224 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6225 | final long identity = Binder.clearCallingIdentity(); |
| 6226 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6227 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6228 | // may happen if the device does not support IMS. |
| 6229 | return ""; |
| 6230 | } |
Brad Ebinger | a80c331 | 2019-12-02 10:59:39 -0800 | [diff] [blame] | 6231 | // TODO: change API to query RCS separately. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6232 | return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService, |
| 6233 | featureType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6234 | } finally { |
| 6235 | Binder.restoreCallingIdentity(identity); |
| 6236 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6237 | } |
| 6238 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6239 | /** |
| 6240 | * Get the MmTelFeature state associated with the requested subscription id. |
| 6241 | * @param subId The subscription that the MmTelFeature is associated with. |
| 6242 | * @param callback A callback with an integer containing the |
| 6243 | * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature. |
| 6244 | */ |
| 6245 | @Override |
| 6246 | public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) { |
| 6247 | enforceReadPrivilegedPermission("getImsMmTelFeatureState"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 6248 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 6249 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 6250 | "IMS not available on device."); |
| 6251 | } |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6252 | final long token = Binder.clearCallingIdentity(); |
| 6253 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 6254 | int slotId = getSlotIndex(subId); |
| 6255 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 6256 | Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '" |
| 6257 | + subId + "'"); |
| 6258 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 6259 | } |
| 6260 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 6261 | ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> { |
| 6262 | try { |
| 6263 | callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger); |
| 6264 | } catch (RemoteException e) { |
| 6265 | Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. " |
| 6266 | + "Ignore"); |
| 6267 | } |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6268 | }); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 6269 | } catch (ImsException e) { |
| 6270 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6271 | } finally { |
| 6272 | Binder.restoreCallingIdentity(token); |
| 6273 | } |
| 6274 | } |
| 6275 | |
Daniel Bright | bb5840b | 2021-01-12 15:48:18 -0800 | [diff] [blame] | 6276 | /** |
| 6277 | * Sets the ims registration state on all valid {@link Phone}s. |
| 6278 | */ |
| 6279 | public void setImsRegistrationState(final boolean registered) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 6280 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6281 | |
| 6282 | final long identity = Binder.clearCallingIdentity(); |
| 6283 | try { |
Daniel Bright | bb5840b | 2021-01-12 15:48:18 -0800 | [diff] [blame] | 6284 | // NOTE: Before S, this method only set the default phone. |
| 6285 | for (final Phone phone : PhoneFactory.getPhones()) { |
| 6286 | if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) { |
| 6287 | phone.setImsRegistrationState(registered); |
| 6288 | } |
| 6289 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6290 | } finally { |
| 6291 | Binder.restoreCallingIdentity(identity); |
| 6292 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 6293 | } |
| 6294 | |
| 6295 | /** |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 6296 | * Set the network selection mode to automatic. |
| 6297 | * |
| 6298 | */ |
| 6299 | @Override |
| 6300 | public void setNetworkSelectionModeAutomatic(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6301 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6302 | mApp, subId, "setNetworkSelectionModeAutomatic"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6303 | |
| 6304 | final long identity = Binder.clearCallingIdentity(); |
| 6305 | try { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 6306 | if (!isActiveSubscription(subId)) { |
| 6307 | return; |
| 6308 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6309 | if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId); |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 6310 | sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId, |
| 6311 | SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6312 | } finally { |
| 6313 | Binder.restoreCallingIdentity(identity); |
| 6314 | } |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 6315 | } |
| 6316 | |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 6317 | /** |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6318 | * Ask the radio to connect to the input network and change selection mode to manual. |
| 6319 | * |
| 6320 | * @param subId the id of the subscription. |
| 6321 | * @param operatorInfo the operator information, included the PLMN, long name and short name of |
| 6322 | * the operator to attach to. |
| 6323 | * @param persistSelection whether the selection will persist until reboot. If true, only allows |
| 6324 | * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume |
| 6325 | * normal network selection next time. |
| 6326 | * @return {@code true} on success; {@code true} on any failure. |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6327 | */ |
| 6328 | @Override |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6329 | public boolean setNetworkSelectionModeManual( |
| 6330 | int subId, OperatorInfo operatorInfo, boolean persistSelection) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6331 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6332 | mApp, subId, "setNetworkSelectionModeManual"); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 6333 | |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 6334 | final long identity = Binder.clearCallingIdentity(); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 6335 | if (!isActiveSubscription(subId)) { |
| 6336 | return false; |
| 6337 | } |
| 6338 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6339 | try { |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6340 | ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6341 | persistSelection); |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6342 | if (DBG) { |
| 6343 | log("setNetworkSelectionModeManual: subId: " + subId |
| 6344 | + " operator: " + operatorInfo); |
| 6345 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6346 | return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId); |
| 6347 | } finally { |
| 6348 | Binder.restoreCallingIdentity(identity); |
| 6349 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6350 | } |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6351 | /** |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6352 | * Get the manual network selection |
| 6353 | * |
| 6354 | * @param subId the id of the subscription. |
| 6355 | * |
| 6356 | * @return the previously saved user selected PLMN |
| 6357 | */ |
| 6358 | @Override |
| 6359 | public String getManualNetworkSelectionPlmn(int subId) { |
| 6360 | TelephonyPermissions |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6361 | .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 6362 | mApp, subId, "getManualNetworkSelectionPlmn"); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6363 | |
| 6364 | final long identity = Binder.clearCallingIdentity(); |
| 6365 | try { |
| 6366 | if (!isActiveSubscription(subId)) { |
shilu | fa1c259 | 2020-03-10 10:59:43 -0700 | [diff] [blame] | 6367 | throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6368 | } |
| 6369 | |
| 6370 | final Phone phone = getPhone(subId); |
| 6371 | if (phone == null) { |
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 | OperatorInfo networkSelection = phone.getSavedNetworkSelection(); |
| 6375 | return TextUtils.isEmpty(networkSelection.getOperatorNumeric()) |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6376 | ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric(); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6377 | } finally { |
| 6378 | Binder.restoreCallingIdentity(identity); |
| 6379 | } |
| 6380 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6381 | |
| 6382 | /** |
| 6383 | * Scans for available networks. |
| 6384 | */ |
| 6385 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6386 | public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage, |
| 6387 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6388 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6389 | mApp, subId, "getCellNetworkScanResults"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6390 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 6391 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 6392 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 6393 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6394 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6395 | .setCallingPid(Binder.getCallingPid()) |
| 6396 | .setCallingUid(Binder.getCallingUid()) |
| 6397 | .setMethod("getCellNetworkScanResults") |
| 6398 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
Hall Liu | c4a3e42 | 2020-05-26 17:18:03 -0700 | [diff] [blame] | 6399 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 6400 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6401 | .build()); |
| 6402 | switch (locationResult) { |
| 6403 | case DENIED_HARD: |
| 6404 | throw new SecurityException("Not allowed to access scan results -- location"); |
| 6405 | case DENIED_SOFT: |
| 6406 | return null; |
| 6407 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6408 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6409 | long identity = Binder.clearCallingIdentity(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6410 | try { |
| 6411 | if (DBG) log("getCellNetworkScanResults: subId " + subId); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6412 | return (CellNetworkScanResult) sendRequest( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6413 | CMD_PERFORM_NETWORK_SCAN, null, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6414 | } finally { |
| 6415 | Binder.restoreCallingIdentity(identity); |
| 6416 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6417 | } |
| 6418 | |
| 6419 | /** |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6420 | * Get the call forwarding info, given the call forwarding reason. |
| 6421 | */ |
| 6422 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6423 | public void getCallForwarding(int subId, int callForwardingReason, |
| 6424 | ICallForwardingInfoCallback callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6425 | enforceReadPrivilegedPermission("getCallForwarding"); |
| 6426 | long identity = Binder.clearCallingIdentity(); |
| 6427 | try { |
| 6428 | if (DBG) { |
| 6429 | log("getCallForwarding: subId " + subId |
| 6430 | + " callForwardingReason" + callForwardingReason); |
| 6431 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6432 | |
| 6433 | Phone phone = getPhone(subId); |
| 6434 | if (phone == null) { |
| 6435 | try { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 6436 | callback.onError( |
| 6437 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6438 | } catch (RemoteException e) { |
| 6439 | // ignore |
| 6440 | } |
| 6441 | return; |
| 6442 | } |
| 6443 | |
| 6444 | Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create( |
| 6445 | callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() { |
| 6446 | @Override |
| 6447 | public void onCallForwardingInfoAvailable(CallForwardingInfo info) { |
| 6448 | try { |
| 6449 | callback.onCallForwardingInfoAvailable(info); |
| 6450 | } catch (RemoteException e) { |
| 6451 | // ignore |
| 6452 | } |
| 6453 | } |
| 6454 | |
| 6455 | @Override |
| 6456 | public void onError(int error) { |
| 6457 | try { |
| 6458 | callback.onError(error); |
| 6459 | } catch (RemoteException e) { |
| 6460 | // ignore |
| 6461 | } |
| 6462 | } |
| 6463 | }); |
| 6464 | sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6465 | } finally { |
| 6466 | Binder.restoreCallingIdentity(identity); |
| 6467 | } |
| 6468 | } |
| 6469 | |
| 6470 | /** |
| 6471 | * Sets the voice call forwarding info including status (enable/disable), call forwarding |
| 6472 | * reason, the number to forward, and the timeout before the forwarding is attempted. |
| 6473 | */ |
| 6474 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6475 | public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo, |
| 6476 | IIntegerConsumer callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6477 | enforceModifyPermission(); |
| 6478 | long identity = Binder.clearCallingIdentity(); |
| 6479 | try { |
| 6480 | if (DBG) { |
| 6481 | log("setCallForwarding: subId " + subId |
| 6482 | + " callForwardingInfo" + callForwardingInfo); |
| 6483 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6484 | |
| 6485 | Phone phone = getPhone(subId); |
| 6486 | if (phone == null) { |
| 6487 | try { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 6488 | callback.accept( |
| 6489 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6490 | } catch (RemoteException e) { |
| 6491 | // ignore |
| 6492 | } |
| 6493 | return; |
| 6494 | } |
| 6495 | |
| 6496 | Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo, |
| 6497 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 6498 | |
| 6499 | sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6500 | } finally { |
| 6501 | Binder.restoreCallingIdentity(identity); |
| 6502 | } |
| 6503 | } |
| 6504 | |
| 6505 | /** |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6506 | * Get the call waiting status for a subId. |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6507 | */ |
| 6508 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6509 | public void getCallWaitingStatus(int subId, IIntegerConsumer callback) { |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6510 | enforceReadPrivilegedPermission("getCallWaitingStatus"); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6511 | long identity = Binder.clearCallingIdentity(); |
| 6512 | try { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6513 | Phone phone = getPhone(subId); |
| 6514 | if (phone == null) { |
| 6515 | try { |
| 6516 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 6517 | } catch (RemoteException e) { |
| 6518 | // ignore |
| 6519 | } |
| 6520 | return; |
| 6521 | } |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6522 | CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext()); |
| 6523 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 6524 | boolean requireUssd = c.getBoolean( |
| 6525 | CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6526 | |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6527 | if (DBG) log("getCallWaitingStatus: subId " + subId); |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6528 | if (requireUssd) { |
| 6529 | CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(), |
| 6530 | getSubscriptionCarrierId(subId)); |
| 6531 | String newUssdCommand = ""; |
| 6532 | try { |
| 6533 | newUssdCommand = carrierXmlParser.getFeature( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6534 | CarrierXmlParser.FEATURE_CALL_WAITING) |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6535 | .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null); |
| 6536 | } catch (NullPointerException e) { |
| 6537 | loge("Failed to generate USSD number" + e); |
| 6538 | } |
| 6539 | ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver( |
| 6540 | mMainThreadHandler, callback, carrierXmlParser, |
| 6541 | CarrierXmlParser.SsEntry.SSAction.QUERY); |
| 6542 | final String ussdCommand = newUssdCommand; |
| 6543 | Executors.newSingleThreadExecutor().execute(() -> { |
| 6544 | handleUssdRequest(subId, ussdCommand, wrappedCallback); |
| 6545 | }); |
| 6546 | } else { |
| 6547 | Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException( |
| 6548 | callback::accept); |
| 6549 | sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null); |
| 6550 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6551 | } finally { |
| 6552 | Binder.restoreCallingIdentity(identity); |
| 6553 | } |
| 6554 | } |
| 6555 | |
| 6556 | /** |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6557 | * Sets whether call waiting is enabled for a given subId. |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6558 | */ |
| 6559 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6560 | public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6561 | enforceModifyPermission(); |
| 6562 | long identity = Binder.clearCallingIdentity(); |
| 6563 | try { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6564 | if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable); |
| 6565 | |
| 6566 | Phone phone = getPhone(subId); |
| 6567 | if (phone == null) { |
| 6568 | try { |
| 6569 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 6570 | } catch (RemoteException e) { |
| 6571 | // ignore |
| 6572 | } |
| 6573 | return; |
| 6574 | } |
| 6575 | |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6576 | CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext()); |
| 6577 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 6578 | boolean requireUssd = c.getBoolean( |
| 6579 | CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6580 | |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6581 | if (DBG) log("getCallWaitingStatus: subId " + subId); |
| 6582 | if (requireUssd) { |
| 6583 | CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(), |
| 6584 | getSubscriptionCarrierId(subId)); |
| 6585 | CarrierXmlParser.SsEntry.SSAction ssAction = |
| 6586 | enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE |
| 6587 | : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE; |
| 6588 | String newUssdCommand = ""; |
| 6589 | try { |
| 6590 | newUssdCommand = carrierXmlParser.getFeature( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6591 | CarrierXmlParser.FEATURE_CALL_WAITING) |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6592 | .makeCommand(ssAction, null); |
| 6593 | } catch (NullPointerException e) { |
| 6594 | loge("Failed to generate USSD number" + e); |
| 6595 | } |
| 6596 | ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver( |
| 6597 | mMainThreadHandler, callback, carrierXmlParser, ssAction); |
| 6598 | final String ussdCommand = newUssdCommand; |
| 6599 | Executors.newSingleThreadExecutor().execute(() -> { |
| 6600 | handleUssdRequest(subId, ussdCommand, wrappedCallback); |
| 6601 | }); |
| 6602 | } else { |
| 6603 | Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable, |
| 6604 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 6605 | |
| 6606 | sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null); |
| 6607 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6608 | } finally { |
| 6609 | Binder.restoreCallingIdentity(identity); |
| 6610 | } |
| 6611 | } |
| 6612 | |
| 6613 | /** |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 6614 | * Starts a new network scan and returns the id of this scan. |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6615 | * |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 6616 | * @param subId id of the subscription |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 6617 | * @param renounceFineLocationAccess Set this to true if the caller would not like to receive |
| 6618 | * location related information which will be sent if the caller already possess |
| 6619 | * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 6620 | * @param request contains the radio access networks with bands/channels to scan |
| 6621 | * @param messenger callback messenger for scan results or errors |
| 6622 | * @param binder for the purpose of auto clean when the user thread crashes |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6623 | * @return the id of the requested scan which can be used to stop the scan. |
| 6624 | */ |
| 6625 | @Override |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 6626 | public int requestNetworkScan(int subId, boolean renounceFineLocationAccess, |
| 6627 | NetworkScanRequest request, Messenger messenger, |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6628 | IBinder binder, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6629 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6630 | mApp, subId, "requestNetworkScan"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6631 | LocationAccessPolicy.LocationPermissionResult locationResult = |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 6632 | LocationAccessPolicy.LocationPermissionResult.DENIED_HARD; |
| 6633 | if (!renounceFineLocationAccess) { |
| 6634 | locationResult = LocationAccessPolicy.checkLocationPermission(mApp, |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6635 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 6636 | .setCallingPackage(callingPackage) |
| 6637 | .setCallingFeatureId(callingFeatureId) |
| 6638 | .setCallingPid(Binder.getCallingPid()) |
| 6639 | .setCallingUid(Binder.getCallingUid()) |
| 6640 | .setMethod("requestNetworkScan") |
| 6641 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 6642 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 6643 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 6644 | .build()); |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 6645 | } |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6646 | if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) { |
Nathan Harold | 1c11dba | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 6647 | SecurityException e = checkNetworkRequestForSanitizedLocationAccess( |
| 6648 | request, subId, callingPackage); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6649 | if (e != null) { |
| 6650 | if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) { |
| 6651 | throw e; |
| 6652 | } else { |
Hall Liu | 0e5abaf | 2019-04-04 01:25:30 -0700 | [diff] [blame] | 6653 | loge(e.getMessage()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6654 | return TelephonyScanManager.INVALID_SCAN_ID; |
| 6655 | } |
| 6656 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6657 | } |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6658 | int callingUid = Binder.getCallingUid(); |
| 6659 | int callingPid = Binder.getCallingPid(); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 6660 | final long identity = Binder.clearCallingIdentity(); |
| 6661 | try { |
| 6662 | return mNetworkScanRequestTracker.startNetworkScan( |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 6663 | renounceFineLocationAccess, request, messenger, binder, |
| 6664 | getPhoneFromSubIdOrDefault(subId), |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6665 | callingUid, callingPid, callingPackage); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 6666 | } finally { |
| 6667 | Binder.restoreCallingIdentity(identity); |
| 6668 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6669 | } |
| 6670 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6671 | private SecurityException checkNetworkRequestForSanitizedLocationAccess( |
Nathan Harold | 1c11dba | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 6672 | NetworkScanRequest request, int subId, String callingPackage) { |
Rambo Wang | 3dee30a | 2022-10-20 16:52:29 +0000 | [diff] [blame] | 6673 | boolean hasCarrierPriv; |
| 6674 | final long identity = Binder.clearCallingIdentity(); |
| 6675 | try { |
| 6676 | hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage) |
| 6677 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 6678 | } finally { |
| 6679 | Binder.restoreCallingIdentity(identity); |
| 6680 | } |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 6681 | boolean hasNetworkScanPermission = |
| 6682 | mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN) |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6683 | == PERMISSION_GRANTED; |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 6684 | |
| 6685 | if (!hasCarrierPriv && !hasNetworkScanPermission) { |
| 6686 | return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed" |
| 6687 | + " for network scans without location access."); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6688 | } |
| 6689 | |
| 6690 | if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) { |
| 6691 | for (RadioAccessSpecifier ras : request.getSpecifiers()) { |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6692 | if (ras.getChannels() != null && ras.getChannels().length > 0) { |
| 6693 | return new SecurityException("Specific channels must not be" |
| 6694 | + " scanned without location access."); |
| 6695 | } |
| 6696 | } |
| 6697 | } |
| 6698 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6699 | return null; |
| 6700 | } |
| 6701 | |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6702 | /** |
| 6703 | * Stops an existing network scan with the given scanId. |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 6704 | * |
| 6705 | * @param subId id of the subscription |
| 6706 | * @param scanId id of the scan that needs to be stopped |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6707 | */ |
| 6708 | @Override |
| 6709 | public void stopNetworkScan(int subId, int scanId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6710 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6711 | mApp, subId, "stopNetworkScan"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6712 | |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6713 | int callingUid = Binder.getCallingUid(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6714 | final long identity = Binder.clearCallingIdentity(); |
| 6715 | try { |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6716 | mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6717 | } finally { |
| 6718 | Binder.restoreCallingIdentity(identity); |
| 6719 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6720 | } |
| 6721 | |
| 6722 | /** |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6723 | * Get the allowed network types bitmask. |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 6724 | * |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6725 | * @return the allowed network types bitmask, defined in RILConstants.java. |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 6726 | */ |
| 6727 | @Override |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6728 | public int getAllowedNetworkTypesBitmask(int subId) { |
Pengquan Meng | a4009cb | 2018-12-20 11:00:24 -0800 | [diff] [blame] | 6729 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 6730 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6731 | mApp, subId, "getAllowedNetworkTypesBitmask"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6732 | |
| 6733 | final long identity = Binder.clearCallingIdentity(); |
| 6734 | try { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6735 | if (DBG) log("getAllowedNetworkTypesBitmask"); |
| 6736 | int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId); |
| 6737 | int networkTypesBitmask = (result != null ? result[0] : -1); |
| 6738 | if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask); |
| 6739 | return networkTypesBitmask; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6740 | } finally { |
| 6741 | Binder.restoreCallingIdentity(identity); |
| 6742 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 6743 | } |
| 6744 | |
| 6745 | /** |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6746 | * Get the allowed network types for certain reason. |
| 6747 | * |
| 6748 | * @param subId the id of the subscription. |
| 6749 | * @param reason the reason the allowed network type change is taking place |
| 6750 | * @return the allowed network types. |
| 6751 | */ |
| 6752 | @Override |
| 6753 | public long getAllowedNetworkTypesForReason(int subId, |
| 6754 | @TelephonyManager.AllowedNetworkTypesReason int reason) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 6755 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 6756 | mApp, subId, "getAllowedNetworkTypesForReason"); |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6757 | final long identity = Binder.clearCallingIdentity(); |
| 6758 | try { |
Jack Yu | 7247ac8 | 2023-03-02 23:52:10 -0800 | [diff] [blame] | 6759 | return getPhoneFromSubIdOrDefault(subId).getAllowedNetworkTypes(reason); |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6760 | } finally { |
| 6761 | Binder.restoreCallingIdentity(identity); |
| 6762 | } |
| 6763 | } |
| 6764 | |
| 6765 | /** |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6766 | * Enable/Disable E-UTRA-NR Dual Connectivity |
| 6767 | * @param subId subscription id of the sim card |
| 6768 | * @param nrDualConnectivityState expected NR dual connectivity state |
| 6769 | * This can be passed following states |
| 6770 | * <ol> |
| 6771 | * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE} |
| 6772 | * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE} |
| 6773 | * <li>Disable NR dual connectivity and force secondary cell to be released |
| 6774 | * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE} |
| 6775 | * </ol> |
| 6776 | * @return operation result. |
| 6777 | */ |
| 6778 | @Override |
| 6779 | public int setNrDualConnectivityState(int subId, |
| 6780 | @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) { |
| 6781 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6782 | mApp, subId, "enableNRDualConnectivity"); |
Sooraj Sasindran | 0e4e00a | 2021-03-16 18:02:32 -0700 | [diff] [blame] | 6783 | if (!isRadioInterfaceCapabilitySupported( |
Sooraj Sasindran | dfd595b | 2021-03-11 17:38:13 -0800 | [diff] [blame] | 6784 | TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) { |
| 6785 | return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED; |
| 6786 | } |
| 6787 | |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6788 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 6789 | final long identity = Binder.clearCallingIdentity(); |
| 6790 | try { |
| 6791 | int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY, |
| 6792 | nrDualConnectivityState, subId, |
| 6793 | workSource); |
| 6794 | if (DBG) log("enableNRDualConnectivity result: " + result); |
| 6795 | return result; |
| 6796 | } finally { |
| 6797 | Binder.restoreCallingIdentity(identity); |
| 6798 | } |
| 6799 | } |
| 6800 | |
| 6801 | /** |
| 6802 | * Is E-UTRA-NR Dual Connectivity enabled |
| 6803 | * @return true if dual connectivity is enabled else false |
| 6804 | */ |
| 6805 | @Override |
| 6806 | public boolean isNrDualConnectivityEnabled(int subId) { |
| 6807 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 6808 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6809 | mApp, subId, "isNRDualConnectivityEnabled"); |
Sooraj Sasindran | 0e4e00a | 2021-03-16 18:02:32 -0700 | [diff] [blame] | 6810 | if (!isRadioInterfaceCapabilitySupported( |
Sooraj Sasindran | dfd595b | 2021-03-11 17:38:13 -0800 | [diff] [blame] | 6811 | TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) { |
| 6812 | return false; |
| 6813 | } |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6814 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 6815 | final long identity = Binder.clearCallingIdentity(); |
| 6816 | try { |
| 6817 | boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED, |
| 6818 | null, subId, workSource); |
| 6819 | if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled); |
| 6820 | return isEnabled; |
| 6821 | } finally { |
| 6822 | Binder.restoreCallingIdentity(identity); |
| 6823 | } |
| 6824 | } |
| 6825 | |
| 6826 | /** |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6827 | * Set the allowed network types of the device and |
| 6828 | * provide the reason triggering the allowed network change. |
| 6829 | * |
| 6830 | * @param subId the id of the subscription. |
| 6831 | * @param reason the reason the allowed network type change is taking place |
| 6832 | * @param allowedNetworkTypes the allowed network types. |
| 6833 | * @return true on success; false on any failure. |
| 6834 | */ |
| 6835 | @Override |
| 6836 | public boolean setAllowedNetworkTypesForReason(int subId, |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6837 | @TelephonyManager.AllowedNetworkTypesReason int reason, |
| 6838 | @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) { |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6839 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6840 | mApp, subId, "setAllowedNetworkTypesForReason"); |
Gil Cukierman | 1d3d375 | 2022-10-03 21:31:33 +0000 | [diff] [blame] | 6841 | // If the caller only has carrier privileges, then they should not be able to override |
| 6842 | // any network types which were set for security reasons. |
| 6843 | if (mApp.checkCallingOrSelfPermission(Manifest.permission.MODIFY_PHONE_STATE) |
| 6844 | != PERMISSION_GRANTED |
Gil Cukierman | 2a8f48b | 2023-01-26 20:26:20 +0000 | [diff] [blame] | 6845 | && reason == TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_ENABLE_2G) { |
Gil Cukierman | 1d3d375 | 2022-10-03 21:31:33 +0000 | [diff] [blame] | 6846 | throw new SecurityException( |
| 6847 | "setAllowedNetworkTypesForReason cannot be called with carrier privileges for" |
Gil Cukierman | 2a8f48b | 2023-01-26 20:26:20 +0000 | [diff] [blame] | 6848 | + " reason " + reason); |
Gil Cukierman | 1d3d375 | 2022-10-03 21:31:33 +0000 | [diff] [blame] | 6849 | } |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6850 | if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) { |
Jack Yu | 5b49433 | 2023-01-23 18:18:04 +0000 | [diff] [blame] | 6851 | loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason); |
SongFerngWang | 7ffc273 | 2021-04-15 19:46:33 +0800 | [diff] [blame] | 6852 | return false; |
| 6853 | } |
| 6854 | if (!SubscriptionManager.isUsableSubscriptionId(subId)) { |
| 6855 | loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId); |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6856 | return false; |
| 6857 | } |
| 6858 | |
Jack Yu | 5b49433 | 2023-01-23 18:18:04 +0000 | [diff] [blame] | 6859 | log("setAllowedNetworkTypesForReason: subId=" + subId + ", reason=" + reason + " value: " |
| 6860 | + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes)); |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 6861 | |
Jack Yu | e37dd26 | 2022-12-16 11:53:37 -0800 | [diff] [blame] | 6862 | Phone phone = getPhone(subId); |
| 6863 | if (phone == null) { |
| 6864 | return false; |
| 6865 | } |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 6866 | |
Jack Yu | e37dd26 | 2022-12-16 11:53:37 -0800 | [diff] [blame] | 6867 | if (allowedNetworkTypes == phone.getAllowedNetworkTypes(reason)) { |
Jack Yu | 5b49433 | 2023-01-23 18:18:04 +0000 | [diff] [blame] | 6868 | log("setAllowedNetworkTypesForReason: " + reason + "does not change value"); |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 6869 | return true; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6870 | } |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 6871 | |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6872 | final long identity = Binder.clearCallingIdentity(); |
| 6873 | try { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6874 | Boolean success = (Boolean) sendRequest( |
| 6875 | CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON, |
| 6876 | new Pair<Integer, Long>(reason, allowedNetworkTypes), subId); |
| 6877 | |
| 6878 | if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail")); |
| 6879 | return success; |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6880 | } finally { |
| 6881 | Binder.restoreCallingIdentity(identity); |
| 6882 | } |
| 6883 | } |
| 6884 | |
| 6885 | /** |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6886 | * Check whether DUN APN is required for tethering with subId. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6887 | * |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6888 | * @param subId the id of the subscription to require tethering. |
Amit Mahajan | fe58cdf | 2017-07-11 12:01:53 -0700 | [diff] [blame] | 6889 | * @return {@code true} if DUN APN is required for tethering. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6890 | * @hide |
| 6891 | */ |
| 6892 | @Override |
SongFerngWang | f08d812 | 2019-11-15 14:58:44 +0800 | [diff] [blame] | 6893 | public boolean isTetheringApnRequiredForSubscriber(int subId) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6894 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6895 | final long identity = Binder.clearCallingIdentity(); |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6896 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6897 | try { |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6898 | if (phone != null) { |
| 6899 | return phone.hasMatchedTetherApnSetting(); |
| 6900 | } else { |
| 6901 | return false; |
| 6902 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6903 | } finally { |
| 6904 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6905 | } |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6906 | } |
| 6907 | |
| 6908 | /** |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6909 | * Get the user enabled state of Mobile Data. |
| 6910 | * |
| 6911 | * TODO: remove and use isUserDataEnabled. |
| 6912 | * This can't be removed now because some vendor codes |
| 6913 | * calls through ITelephony directly while they should |
| 6914 | * use TelephonyManager. |
| 6915 | * |
| 6916 | * @return true on enabled |
| 6917 | */ |
| 6918 | @Override |
| 6919 | public boolean getDataEnabled(int subId) { |
| 6920 | return isUserDataEnabled(subId); |
| 6921 | } |
| 6922 | |
| 6923 | /** |
| 6924 | * Get whether mobile data is enabled per user setting. |
| 6925 | * |
| 6926 | * There are other factors deciding whether mobile data is actually enabled, but they are |
| 6927 | * not considered here. See {@link #isDataEnabled(int)} for more details. |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6928 | * |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6929 | * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE |
| 6930 | * or carrier privileges. |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 6931 | * |
| 6932 | * @return {@code true} if data is enabled else {@code false} |
| 6933 | */ |
| 6934 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6935 | public boolean isUserDataEnabled(int subId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6936 | String functionName = "isUserDataEnabled"; |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6937 | try { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6938 | try { |
| 6939 | mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE, |
| 6940 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 6941 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6942 | mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName); |
| 6943 | } |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 6944 | } catch (SecurityException e) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6945 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6946 | mApp, subId, functionName); |
| 6947 | |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6948 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6949 | |
| 6950 | final long identity = Binder.clearCallingIdentity(); |
| 6951 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 6952 | int phoneId = SubscriptionManager.getPhoneId(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6953 | if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 6954 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6955 | if (phone != null) { |
| 6956 | boolean retVal = phone.isUserDataEnabled(); |
| 6957 | if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 6958 | return retVal; |
| 6959 | } else { |
| 6960 | if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 6961 | return false; |
| 6962 | } |
| 6963 | } finally { |
| 6964 | Binder.restoreCallingIdentity(identity); |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6965 | } |
| 6966 | } |
| 6967 | |
| 6968 | /** |
Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 6969 | * Checks if the device is capable of mobile data by considering whether whether the |
| 6970 | * user has enabled mobile data, whether the carrier has enabled mobile data, and |
| 6971 | * whether the network policy allows data connections. |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6972 | * |
Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 6973 | * @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] | 6974 | */ |
| 6975 | @Override |
| 6976 | public boolean isDataEnabled(int subId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6977 | String functionName = "isDataEnabled"; |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6978 | try { |
| 6979 | try { |
| 6980 | mApp.enforceCallingOrSelfPermission( |
| 6981 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6982 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 6983 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6984 | try { |
| 6985 | mApp.enforceCallingOrSelfPermission( |
| 6986 | android.Manifest.permission.READ_PHONE_STATE, |
| 6987 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 6988 | } catch (SecurityException e2) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6989 | mApp.enforceCallingOrSelfPermission( |
| 6990 | permission.READ_BASIC_PHONE_STATE, functionName); |
| 6991 | } |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6992 | } |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 6993 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6994 | enforceReadPrivilegedPermission(functionName); |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6995 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6996 | |
| 6997 | final long identity = Binder.clearCallingIdentity(); |
| 6998 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 6999 | int phoneId = SubscriptionManager.getPhoneId(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7000 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 7001 | if (phone != null) { |
Sarah Chin | e04784a | 2022-10-31 20:32:34 -0700 | [diff] [blame] | 7002 | boolean retVal = phone.getDataSettingsManager().isDataEnabled(); |
Jack Yu | 4ad64e5 | 2021-12-03 14:23:53 -0800 | [diff] [blame] | 7003 | if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7004 | return retVal; |
| 7005 | } else { |
| 7006 | if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 7007 | return false; |
| 7008 | } |
| 7009 | } finally { |
| 7010 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 7011 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 7012 | } |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 7013 | |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7014 | /** |
| 7015 | * Check if data is enabled for a specific reason |
| 7016 | * @param subId Subscription index |
| 7017 | * @param reason the reason the data enable change is taking place |
| 7018 | * @return {@code true} if the overall data is enabled; {@code false} if not. |
| 7019 | */ |
| 7020 | @Override |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7021 | public boolean isDataEnabledForReason(int subId, |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7022 | @TelephonyManager.DataEnabledReason int reason) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7023 | String functionName = "isDataEnabledForReason"; |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7024 | try { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7025 | try { |
| 7026 | mApp.enforceCallingOrSelfPermission( |
| 7027 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 7028 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7029 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7030 | mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE, |
| 7031 | functionName); |
| 7032 | } |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7033 | } catch (SecurityException e) { |
Sooraj Sasindran | 0d909a0 | 2021-11-08 12:01:16 -0800 | [diff] [blame] | 7034 | try { |
| 7035 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7036 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7037 | } catch (SecurityException e2) { |
Sooraj Sasindran | 0d909a0 | 2021-11-08 12:01:16 -0800 | [diff] [blame] | 7038 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7039 | mApp, subId, functionName); |
Sooraj Sasindran | 0d909a0 | 2021-11-08 12:01:16 -0800 | [diff] [blame] | 7040 | } |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7041 | } |
| 7042 | |
| 7043 | |
| 7044 | final long identity = Binder.clearCallingIdentity(); |
| 7045 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 7046 | int phoneId = SubscriptionManager.getPhoneId(subId); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7047 | if (DBG) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7048 | log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7049 | + " reason=" + reason); |
| 7050 | } |
| 7051 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 7052 | if (phone != null) { |
| 7053 | boolean retVal; |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 7054 | retVal = phone.getDataSettingsManager().isDataEnabledForReason(reason); |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7055 | if (DBG) log("isDataEnabledForReason: retVal=" + retVal); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7056 | return retVal; |
| 7057 | } else { |
| 7058 | if (DBG) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7059 | loge("isDataEnabledForReason: no phone subId=" |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7060 | + subId + " retVal=false"); |
| 7061 | } |
| 7062 | return false; |
| 7063 | } |
| 7064 | } finally { |
| 7065 | Binder.restoreCallingIdentity(identity); |
| 7066 | } |
| 7067 | } |
| 7068 | |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 7069 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7070 | public int getCarrierPrivilegeStatus(int subId) { |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7071 | // No permission needed; this only lets the caller inspect their own status. |
| 7072 | return getCarrierPrivilegeStatusForUidWithPermission(subId, Binder.getCallingUid()); |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 7073 | } |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 7074 | |
| 7075 | @Override |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7076 | public int getCarrierPrivilegeStatusForUid(int subId, int uid) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 7077 | enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid"); |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7078 | return getCarrierPrivilegeStatusForUidWithPermission(subId, uid); |
| 7079 | } |
| 7080 | |
| 7081 | private int getCarrierPrivilegeStatusForUidWithPermission(int subId, int uid) { |
| 7082 | Phone phone = getPhone(subId); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7083 | if (phone == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 7084 | loge("getCarrierPrivilegeStatusForUid: Invalid subId"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7085 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 7086 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7087 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7088 | if (cpt == null) { |
| 7089 | loge("getCarrierPrivilegeStatusForUid: No CarrierPrivilegesTracker"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7090 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 7091 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7092 | return cpt.getCarrierPrivilegeStatusForUid(uid); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7093 | } |
| 7094 | |
| 7095 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7096 | public int checkCarrierPrivilegesForPackage(int subId, String pkgName) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 7097 | enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage"); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7098 | if (TextUtils.isEmpty(pkgName)) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 7099 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7100 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7101 | Phone phone = getPhone(subId); |
| 7102 | if (phone == null) { |
| 7103 | loge("checkCarrierPrivilegesForPackage: Invalid subId"); |
| 7104 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 7105 | } |
| 7106 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7107 | if (cpt == null) { |
| 7108 | loge("checkCarrierPrivilegesForPackage: No CarrierPrivilegesTracker"); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 7109 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 7110 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7111 | return cpt.getCarrierPrivilegeStatusForPackage(pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 7112 | } |
| 7113 | |
| 7114 | @Override |
| 7115 | public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) { |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7116 | enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackageAnyPhone"); |
Rambo Wang | e7209ce | 2022-02-23 13:41:02 -0800 | [diff] [blame] | 7117 | return checkCarrierPrivilegesForPackageAnyPhoneWithPermission(pkgName); |
| 7118 | } |
| 7119 | |
| 7120 | private int checkCarrierPrivilegesForPackageAnyPhoneWithPermission(String pkgName) { |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7121 | if (TextUtils.isEmpty(pkgName)) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 7122 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7123 | } |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 7124 | int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7125 | for (int phoneId = 0; phoneId < TelephonyManager.getDefault().getPhoneCount(); phoneId++) { |
| 7126 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 7127 | if (phone == null) { |
| 7128 | continue; |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 7129 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7130 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7131 | if (cpt == null) { |
| 7132 | continue; |
| 7133 | } |
| 7134 | result = cpt.getCarrierPrivilegeStatusForPackage(pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 7135 | if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 7136 | break; |
| 7137 | } |
| 7138 | } |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 7139 | return result; |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 7140 | } |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 7141 | |
| 7142 | @Override |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 7143 | public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 7144 | enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone"); |
Rambo Wang | 8a247eb | 2022-02-08 21:11:18 +0000 | [diff] [blame] | 7145 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 7146 | if (phone == null) { |
| 7147 | return Collections.emptyList(); |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 7148 | } |
Rambo Wang | 8a247eb | 2022-02-08 21:11:18 +0000 | [diff] [blame] | 7149 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7150 | if (cpt == null) { |
| 7151 | return Collections.emptyList(); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 7152 | } |
Rambo Wang | 8a247eb | 2022-02-08 21:11:18 +0000 | [diff] [blame] | 7153 | return cpt.getCarrierPackageNamesForIntent(intent); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 7154 | } |
| 7155 | |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 7156 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7157 | public List<String> getPackagesWithCarrierPrivileges(int phoneId) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 7158 | enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges"); |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7159 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 7160 | if (phone == null) { |
| 7161 | return Collections.emptyList(); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 7162 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7163 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7164 | if (cpt == null) { |
| 7165 | return Collections.emptyList(); |
| 7166 | } |
| 7167 | return new ArrayList<>(cpt.getPackagesWithCarrierPrivileges()); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 7168 | } |
| 7169 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7170 | @Override |
| 7171 | public List<String> getPackagesWithCarrierPrivilegesForAllPhones() { |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 7172 | enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones"); |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7173 | Set<String> privilegedPackages = new ArraySet<>(); |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 7174 | final long identity = Binder.clearCallingIdentity(); |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 7175 | try { |
| 7176 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 7177 | privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i)); |
| 7178 | } |
| 7179 | } finally { |
| 7180 | Binder.restoreCallingIdentity(identity); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7181 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7182 | return new ArrayList<>(privilegedPackages); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7183 | } |
| 7184 | |
Rambo Wang | 6812ffb | 2022-03-15 16:54:17 -0700 | [diff] [blame] | 7185 | @Override |
| 7186 | public @Nullable String getCarrierServicePackageNameForLogicalSlot(int logicalSlotIndex) { |
| 7187 | enforceReadPrivilegedPermission("getCarrierServicePackageNameForLogicalSlot"); |
| 7188 | |
| 7189 | final Phone phone = PhoneFactory.getPhone(logicalSlotIndex); |
| 7190 | if (phone == null) { |
| 7191 | return null; |
| 7192 | } |
| 7193 | final CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7194 | if (cpt == null) { |
| 7195 | return null; |
| 7196 | } |
| 7197 | return cpt.getCarrierServicePackageName(); |
| 7198 | } |
| 7199 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 7200 | private String getIccId(int subId) { |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 7201 | final Phone phone = getPhone(subId); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 7202 | UiccPort port = phone == null ? null : phone.getUiccPort(); |
| 7203 | if (port == null) { |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7204 | return null; |
| 7205 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 7206 | String iccId = port.getIccId(); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7207 | if (TextUtils.isEmpty(iccId)) { |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7208 | return null; |
| 7209 | } |
| 7210 | return iccId; |
| 7211 | } |
| 7212 | |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 7213 | @Override |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 7214 | public void setCallComposerStatus(int subId, int status) { |
| 7215 | enforceModifyPermission(); |
| 7216 | |
| 7217 | final long identity = Binder.clearCallingIdentity(); |
| 7218 | try { |
| 7219 | Phone phone = getPhone(subId); |
| 7220 | if (phone != null) { |
| 7221 | Phone defaultPhone = phone.getImsPhone(); |
| 7222 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 7223 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 7224 | imsPhone.setCallComposerStatus(status); |
Shuo Qian | 284ae75 | 2020-12-22 19:10:14 -0800 | [diff] [blame] | 7225 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| 7226 | .updateImsServiceConfig(); |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 7227 | } |
| 7228 | } |
Shuo Qian | 284ae75 | 2020-12-22 19:10:14 -0800 | [diff] [blame] | 7229 | } catch (ImsException e) { |
| 7230 | throw new ServiceSpecificException(e.getCode()); |
| 7231 | } finally { |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 7232 | Binder.restoreCallingIdentity(identity); |
| 7233 | } |
| 7234 | } |
| 7235 | |
| 7236 | @Override |
| 7237 | public int getCallComposerStatus(int subId) { |
| 7238 | enforceReadPrivilegedPermission("getCallComposerStatus"); |
| 7239 | |
| 7240 | final long identity = Binder.clearCallingIdentity(); |
| 7241 | try { |
| 7242 | Phone phone = getPhone(subId); |
| 7243 | if (phone != null) { |
| 7244 | Phone defaultPhone = phone.getImsPhone(); |
| 7245 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 7246 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 7247 | return imsPhone.getCallComposerStatus(); |
| 7248 | } |
| 7249 | } |
| 7250 | } finally { |
| 7251 | Binder.restoreCallingIdentity(identity); |
| 7252 | } |
| 7253 | return TelephonyManager.CALL_COMPOSER_STATUS_OFF; |
| 7254 | } |
| 7255 | |
| 7256 | @Override |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7257 | public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag, |
| 7258 | String number) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 7259 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7260 | subId, "setLine1NumberForDisplayForSubscriber"); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7261 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7262 | final long identity = Binder.clearCallingIdentity(); |
| 7263 | try { |
| 7264 | final String iccId = getIccId(subId); |
| 7265 | final Phone phone = getPhone(subId); |
| 7266 | if (phone == null) { |
| 7267 | return false; |
| 7268 | } |
| 7269 | final String subscriberId = phone.getSubscriberId(); |
| 7270 | |
| 7271 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 7272 | Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId=" |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7273 | + subscriberId + " to " + number); |
| 7274 | } |
| 7275 | |
| 7276 | if (TextUtils.isEmpty(iccId)) { |
| 7277 | return false; |
| 7278 | } |
| 7279 | |
| 7280 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 7281 | |
| 7282 | final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 7283 | if (alphaTag == null) { |
| 7284 | editor.remove(alphaTagPrefKey); |
| 7285 | } else { |
| 7286 | editor.putString(alphaTagPrefKey, alphaTag); |
| 7287 | } |
| 7288 | |
| 7289 | // Record both the line number and IMSI for this ICCID, since we need to |
| 7290 | // track all merged IMSIs based on line number |
| 7291 | final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 7292 | final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 7293 | if (number == null) { |
| 7294 | editor.remove(numberPrefKey); |
| 7295 | editor.remove(subscriberPrefKey); |
| 7296 | } else { |
| 7297 | editor.putString(numberPrefKey, number); |
| 7298 | editor.putString(subscriberPrefKey, subscriberId); |
| 7299 | } |
| 7300 | |
| 7301 | editor.commit(); |
| 7302 | return true; |
| 7303 | } finally { |
| 7304 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 7305 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7306 | } |
| 7307 | |
| 7308 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7309 | public String getLine1NumberForDisplay(int subId, String callingPackage, |
| 7310 | String callingFeatureId) { |
Makoto Onuki | fee6934 | 2015-06-29 14:44:50 -0700 | [diff] [blame] | 7311 | // This is open to apps with WRITE_SMS. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7312 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7313 | mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) { |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 7314 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission"); |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 7315 | return null; |
| 7316 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7317 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7318 | final long identity = Binder.clearCallingIdentity(); |
| 7319 | try { |
| 7320 | String iccId = getIccId(subId); |
| 7321 | if (iccId != null) { |
| 7322 | String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 7323 | if (DBG_MERGE) { |
| 7324 | log("getLine1NumberForDisplay returning " |
| 7325 | + mTelephonySharedPreferences.getString(numberPrefKey, null)); |
| 7326 | } |
| 7327 | return mTelephonySharedPreferences.getString(numberPrefKey, null); |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 7328 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7329 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null"); |
| 7330 | return null; |
| 7331 | } finally { |
| 7332 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7333 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7334 | } |
| 7335 | |
| 7336 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7337 | public String getLine1AlphaTagForDisplay(int subId, String callingPackage, |
| 7338 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7339 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7340 | mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 7341 | return null; |
| 7342 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7343 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7344 | final long identity = Binder.clearCallingIdentity(); |
| 7345 | try { |
| 7346 | String iccId = getIccId(subId); |
| 7347 | if (iccId != null) { |
| 7348 | String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 7349 | return mTelephonySharedPreferences.getString(alphaTagPrefKey, null); |
| 7350 | } |
| 7351 | return null; |
| 7352 | } finally { |
| 7353 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7354 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7355 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 7356 | |
| 7357 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7358 | public String[] getMergedSubscriberIds(int subId, String callingPackage, |
| 7359 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7360 | // This API isn't public, so no need to provide a valid subscription ID - we're not worried |
| 7361 | // about carrier-privileged callers not having access. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7362 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7363 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7364 | callingFeatureId, "getMergedSubscriberIds")) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7365 | return null; |
| 7366 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7367 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 7368 | // Clear calling identity, when calling TelephonyManager, because callerUid must be |
| 7369 | // the process, where TelephonyManager was instantiated. |
| 7370 | // Otherwise AppOps check will fail. |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7371 | final long identity = Binder.clearCallingIdentity(); |
| 7372 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7373 | final Context context = mApp; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7374 | final TelephonyManager tele = TelephonyManager.from(context); |
| 7375 | final SubscriptionManager sub = SubscriptionManager.from(context); |
| 7376 | |
| 7377 | // Figure out what subscribers are currently active |
| 7378 | final ArraySet<String> activeSubscriberIds = new ArraySet<>(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7379 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 7380 | // Only consider subs which match the current subId |
| 7381 | // This logic can be simplified. See b/131189269 for progress. |
| 7382 | if (isActiveSubscription(subId)) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7383 | activeSubscriberIds.add(tele.getSubscriberId(subId)); |
| 7384 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7385 | |
| 7386 | // First pass, find a number override for an active subscriber |
| 7387 | String mergeNumber = null; |
| 7388 | final Map<String, ?> prefs = mTelephonySharedPreferences.getAll(); |
| 7389 | for (String key : prefs.keySet()) { |
| 7390 | if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) { |
| 7391 | final String subscriberId = (String) prefs.get(key); |
| 7392 | if (activeSubscriberIds.contains(subscriberId)) { |
| 7393 | final String iccId = key.substring( |
| 7394 | PREF_CARRIERS_SUBSCRIBER_PREFIX.length()); |
| 7395 | final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 7396 | mergeNumber = (String) prefs.get(numberKey); |
| 7397 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 7398 | Rlog.d(LOG_TAG, "Found line number " + mergeNumber |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7399 | + " for active subscriber " + subscriberId); |
| 7400 | } |
| 7401 | if (!TextUtils.isEmpty(mergeNumber)) { |
| 7402 | break; |
| 7403 | } |
| 7404 | } |
| 7405 | } |
| 7406 | } |
| 7407 | |
| 7408 | // Shortcut when no active merged subscribers |
| 7409 | if (TextUtils.isEmpty(mergeNumber)) { |
| 7410 | return null; |
| 7411 | } |
| 7412 | |
| 7413 | // Second pass, find all subscribers under that line override |
| 7414 | final ArraySet<String> result = new ArraySet<>(); |
| 7415 | for (String key : prefs.keySet()) { |
| 7416 | if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) { |
| 7417 | final String number = (String) prefs.get(key); |
| 7418 | if (mergeNumber.equals(number)) { |
| 7419 | final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length()); |
| 7420 | final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 7421 | final String subscriberId = (String) prefs.get(subscriberKey); |
| 7422 | if (!TextUtils.isEmpty(subscriberId)) { |
| 7423 | result.add(subscriberId); |
| 7424 | } |
| 7425 | } |
| 7426 | } |
| 7427 | } |
| 7428 | |
| 7429 | final String[] resultArray = result.toArray(new String[result.size()]); |
| 7430 | Arrays.sort(resultArray); |
| 7431 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 7432 | Rlog.d(LOG_TAG, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7433 | "Found subscribers " + Arrays.toString(resultArray) + " after merge"); |
| 7434 | } |
| 7435 | return resultArray; |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7436 | } finally { |
| 7437 | Binder.restoreCallingIdentity(identity); |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7438 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7439 | } |
| 7440 | |
| 7441 | @Override |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 7442 | public String[] getMergedImsisFromGroup(int subId, String callingPackage) { |
| 7443 | enforceReadPrivilegedPermission("getMergedImsisFromGroup"); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7444 | |
| 7445 | final long identity = Binder.clearCallingIdentity(); |
| 7446 | try { |
| 7447 | final TelephonyManager telephonyManager = mApp.getSystemService( |
| 7448 | TelephonyManager.class); |
| 7449 | String subscriberId = telephonyManager.getSubscriberId(subId); |
| 7450 | if (subscriberId == null) { |
| 7451 | if (DBG) { |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 7452 | log("getMergedImsisFromGroup can't find subscriberId for subId " |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7453 | + subId); |
| 7454 | } |
| 7455 | return null; |
| 7456 | } |
| 7457 | |
Jack Yu | 3beaf9d | 2023-04-14 09:17:27 -0700 | [diff] [blame] | 7458 | final SubscriptionInfo info = getSubscriptionManagerService() |
| 7459 | .getSubscriptionInfo(subId); |
| 7460 | ParcelUuid groupUuid = info.getGroupUuid(); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7461 | // If it doesn't belong to any group, return just subscriberId of itself. |
| 7462 | if (groupUuid == null) { |
| 7463 | return new String[]{subscriberId}; |
| 7464 | } |
| 7465 | |
| 7466 | // Get all subscriberIds from the group. |
| 7467 | final List<String> mergedSubscriberIds = new ArrayList<>(); |
Jack Yu | 3beaf9d | 2023-04-14 09:17:27 -0700 | [diff] [blame] | 7468 | List<SubscriptionInfo> groupInfos = getSubscriptionManagerService() |
| 7469 | .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(), |
| 7470 | mApp.getAttributionTag()); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7471 | for (SubscriptionInfo subInfo : groupInfos) { |
| 7472 | subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId()); |
| 7473 | if (subscriberId != null) { |
| 7474 | mergedSubscriberIds.add(subscriberId); |
| 7475 | } |
| 7476 | } |
| 7477 | |
| 7478 | return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]); |
| 7479 | } finally { |
| 7480 | Binder.restoreCallingIdentity(identity); |
| 7481 | |
| 7482 | } |
| 7483 | } |
| 7484 | |
| 7485 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7486 | public boolean setOperatorBrandOverride(int subId, String brand) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 7487 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7488 | subId, "setOperatorBrandOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7489 | |
| 7490 | final long identity = Binder.clearCallingIdentity(); |
| 7491 | try { |
| 7492 | final Phone phone = getPhone(subId); |
| 7493 | return phone == null ? false : phone.setOperatorBrandOverride(brand); |
| 7494 | } finally { |
| 7495 | Binder.restoreCallingIdentity(identity); |
| 7496 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 7497 | } |
Steven Liu | 4bf01bc | 2014-07-17 11:05:29 -0500 | [diff] [blame] | 7498 | |
| 7499 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7500 | public boolean setRoamingOverride(int subId, List<String> gsmRoamingList, |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 7501 | List<String> gsmNonRoamingList, List<String> cdmaRoamingList, |
| 7502 | List<String> cdmaNonRoamingList) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 7503 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 7504 | mApp, subId, "setRoamingOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7505 | |
| 7506 | final long identity = Binder.clearCallingIdentity(); |
| 7507 | try { |
| 7508 | final Phone phone = getPhone(subId); |
| 7509 | if (phone == null) { |
| 7510 | return false; |
| 7511 | } |
| 7512 | return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList, |
| 7513 | cdmaNonRoamingList); |
| 7514 | } finally { |
| 7515 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7516 | } |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 7517 | } |
| 7518 | |
| 7519 | @Override |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 7520 | @Deprecated |
| 7521 | public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) { |
| 7522 | enforceModifyPermission(); |
| 7523 | |
| 7524 | int returnValue = 0; |
| 7525 | try { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7526 | AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 7527 | if(result.exception == null) { |
| 7528 | if (result.result != null) { |
| 7529 | byte[] responseData = (byte[])(result.result); |
| 7530 | if(responseData.length > oemResp.length) { |
| 7531 | Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " + |
| 7532 | responseData.length + "bytes. Buffer Size is " + |
| 7533 | oemResp.length + "bytes."); |
| 7534 | } |
| 7535 | System.arraycopy(responseData, 0, oemResp, 0, responseData.length); |
| 7536 | returnValue = responseData.length; |
| 7537 | } |
| 7538 | } else { |
| 7539 | CommandException ex = (CommandException) result.exception; |
| 7540 | returnValue = ex.getCommandError().ordinal(); |
| 7541 | if(returnValue > 0) returnValue *= -1; |
| 7542 | } |
| 7543 | } catch (RuntimeException e) { |
| 7544 | Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception"); |
| 7545 | returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal()); |
| 7546 | if(returnValue > 0) returnValue *= -1; |
| 7547 | } |
| 7548 | |
| 7549 | return returnValue; |
| 7550 | } |
| 7551 | |
| 7552 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 7553 | public int getRadioAccessFamily(int phoneId, String callingPackage) { |
Aishwarya Mallampati | 11e8287 | 2023-03-13 21:04:00 +0000 | [diff] [blame] | 7554 | int raf = RadioAccessFamily.RAF_UNKNOWN; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7555 | Phone phone = PhoneFactory.getPhone(phoneId); |
Aishwarya Mallampati | 11e8287 | 2023-03-13 21:04:00 +0000 | [diff] [blame] | 7556 | if (phone == null) { |
| 7557 | return raf; |
| 7558 | } |
| 7559 | |
Shuo Qian | dee5340 | 2020-05-29 14:08:15 -0700 | [diff] [blame] | 7560 | try { |
| 7561 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 7562 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Shuo Qian | dee5340 | 2020-05-29 14:08:15 -0700 | [diff] [blame] | 7563 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 7564 | } catch (SecurityException e) { |
| 7565 | EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission"); |
| 7566 | throw e; |
| 7567 | } |
Aishwarya Mallampati | 11e8287 | 2023-03-13 21:04:00 +0000 | [diff] [blame] | 7568 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7569 | final long identity = Binder.clearCallingIdentity(); |
| 7570 | try { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7571 | raf = ProxyController.getInstance().getRadioAccessFamily(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7572 | } finally { |
| 7573 | Binder.restoreCallingIdentity(identity); |
| 7574 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7575 | return raf; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 7576 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7577 | |
| 7578 | @Override |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7579 | public void uploadCallComposerPicture(int subscriptionId, String callingPackage, |
Hall Liu | e31bac6 | 2020-12-23 19:16:10 -0800 | [diff] [blame] | 7580 | String contentType, ParcelFileDescriptor fd, ResultReceiver callback) { |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7581 | try { |
| 7582 | if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0), |
| 7583 | Binder.getCallingUid())) { |
Tyler Gunn | b87925a | 2021-06-10 14:54:27 -0700 | [diff] [blame] | 7584 | throw new SecurityException("Invalid package:" + callingPackage); |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7585 | } |
| 7586 | } catch (PackageManager.NameNotFoundException e) { |
Tyler Gunn | b87925a | 2021-06-10 14:54:27 -0700 | [diff] [blame] | 7587 | throw new SecurityException("Invalid package:" + callingPackage); |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7588 | } |
| 7589 | RoleManager rm = mApp.getSystemService(RoleManager.class); |
| 7590 | List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER); |
| 7591 | if (!dialerRoleHolders.contains(callingPackage)) { |
| 7592 | throw new SecurityException("App must be the dialer role holder to" |
| 7593 | + " upload a call composer pic"); |
| 7594 | } |
| 7595 | |
| 7596 | Executors.newSingleThreadExecutor().execute(() -> { |
| 7597 | ByteArrayOutputStream output = new ByteArrayOutputStream( |
| 7598 | (int) TelephonyManager.getMaximumCallComposerPictureSize()); |
| 7599 | InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd); |
| 7600 | boolean readUntilEnd = false; |
| 7601 | int totalBytesRead = 0; |
| 7602 | byte[] buffer = new byte[16 * 1024]; |
| 7603 | while (true) { |
| 7604 | int numRead; |
| 7605 | try { |
| 7606 | numRead = input.read(buffer); |
| 7607 | } catch (IOException e) { |
| 7608 | try { |
| 7609 | fd.checkError(); |
| 7610 | callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED, |
| 7611 | null); |
| 7612 | } catch (IOException e1) { |
| 7613 | // This means that the other side closed explicitly with an error. If this |
| 7614 | // happens, log and ignore. |
| 7615 | loge("Remote end of call composer picture pipe closed: " + e1); |
| 7616 | } |
| 7617 | break; |
| 7618 | } |
| 7619 | if (numRead == -1) { |
| 7620 | readUntilEnd = true; |
| 7621 | break; |
| 7622 | } |
| 7623 | totalBytesRead += numRead; |
| 7624 | if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) { |
| 7625 | loge("Too many bytes read for call composer picture: " + totalBytesRead); |
| 7626 | try { |
| 7627 | input.close(); |
| 7628 | } catch (IOException e) { |
| 7629 | // ignore |
| 7630 | } |
| 7631 | break; |
| 7632 | } |
| 7633 | output.write(buffer, 0, numRead); |
| 7634 | } |
| 7635 | // Generally, the remote end will close the file descriptors. The only case where we |
| 7636 | // close is above, where the picture size is too big. |
| 7637 | |
| 7638 | try { |
| 7639 | fd.checkError(); |
| 7640 | } catch (IOException e) { |
| 7641 | loge("Remote end for call composer closed with an error: " + e); |
| 7642 | return; |
| 7643 | } |
| 7644 | |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 7645 | if (!readUntilEnd) { |
| 7646 | loge("Did not finish reading entire image; aborting"); |
| 7647 | return; |
| 7648 | } |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7649 | |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 7650 | ImageData imageData = new ImageData(output.toByteArray(), contentType, null); |
| 7651 | CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer( |
| 7652 | new CallComposerPictureTransfer.Factory() {}, |
| 7653 | imageData, |
| 7654 | (result) -> { |
| 7655 | if (result.first != null) { |
| 7656 | ParcelUuid parcelUuid = new ParcelUuid(result.first); |
| 7657 | Bundle outputResult = new Bundle(); |
| 7658 | outputResult.putParcelable( |
| 7659 | TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid); |
| 7660 | callback.send(TelephonyManager.CallComposerException.SUCCESS, |
| 7661 | outputResult); |
| 7662 | } else { |
| 7663 | callback.send(result.second, null); |
| 7664 | } |
| 7665 | } |
| 7666 | ); |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7667 | }); |
| 7668 | } |
| 7669 | |
| 7670 | @Override |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7671 | public void enableVideoCalling(boolean enable) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7672 | final Phone defaultPhone = getDefaultPhone(); |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7673 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7674 | |
| 7675 | final long identity = Binder.clearCallingIdentity(); |
| 7676 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7677 | ImsManager.getInstance(defaultPhone.getContext(), |
| 7678 | defaultPhone.getPhoneId()).setVtSetting(enable); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7679 | } finally { |
| 7680 | Binder.restoreCallingIdentity(identity); |
| 7681 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7682 | } |
| 7683 | |
| 7684 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7685 | public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7686 | final Phone defaultPhone = getDefaultPhone(); |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7687 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 7688 | callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 7689 | return false; |
| 7690 | } |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 7691 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7692 | final long identity = Binder.clearCallingIdentity(); |
| 7693 | try { |
| 7694 | // Check the user preference and the system-level IMS setting. Even if the user has |
| 7695 | // enabled video calling, if IMS is disabled we aren't able to support video calling. |
| 7696 | // In the long run, we may instead need to check if there exists a connection service |
| 7697 | // which can support video calling. |
| 7698 | ImsManager imsManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7699 | ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7700 | return imsManager.isVtEnabledByPlatform() |
| 7701 | && imsManager.isEnhanced4gLteModeSettingEnabledByUser() |
| 7702 | && imsManager.isVtEnabledByUser(); |
| 7703 | } finally { |
| 7704 | Binder.restoreCallingIdentity(identity); |
| 7705 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7706 | } |
Libin.Tang@motorola.com | afe8264 | 2014-12-18 13:27:53 -0600 | [diff] [blame] | 7707 | |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7708 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7709 | public boolean canChangeDtmfToneLength(int subId, String callingPackage, |
| 7710 | String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7711 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7712 | mApp, subId, callingPackage, callingFeatureId, |
| 7713 | "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7714 | return false; |
| 7715 | } |
| 7716 | |
| 7717 | final long identity = Binder.clearCallingIdentity(); |
| 7718 | try { |
| 7719 | CarrierConfigManager configManager = |
| 7720 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7721 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7722 | .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL); |
| 7723 | } finally { |
| 7724 | Binder.restoreCallingIdentity(identity); |
| 7725 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7726 | } |
| 7727 | |
| 7728 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7729 | public boolean isWorldPhone(int subId, String callingPackage, 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, "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7732 | return false; |
| 7733 | } |
| 7734 | |
| 7735 | final long identity = Binder.clearCallingIdentity(); |
| 7736 | try { |
| 7737 | CarrierConfigManager configManager = |
| 7738 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7739 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7740 | .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL); |
| 7741 | } finally { |
| 7742 | Binder.restoreCallingIdentity(identity); |
| 7743 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7744 | } |
| 7745 | |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7746 | @Override |
| 7747 | public boolean isTtyModeSupported() { |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 7748 | TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class); |
Wooki Wu | 1f82f7a | 2016-02-15 15:59:58 +0800 | [diff] [blame] | 7749 | return telecomManager.isTtySupported(); |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7750 | } |
| 7751 | |
| 7752 | @Override |
| 7753 | public boolean isHearingAidCompatibilitySupported() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7754 | final long identity = Binder.clearCallingIdentity(); |
| 7755 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7756 | return mApp.getResources().getBoolean(R.bool.hac_enabled); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7757 | } finally { |
| 7758 | Binder.restoreCallingIdentity(identity); |
| 7759 | } |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7760 | } |
| 7761 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 7762 | /** |
| 7763 | * Determines whether the device currently supports RTT (Real-time text). Based both on carrier |
| 7764 | * support for the feature and device firmware support. |
| 7765 | * |
| 7766 | * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise. |
| 7767 | */ |
| 7768 | @Override |
| 7769 | public boolean isRttSupported(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7770 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7771 | final Phone phone = getPhone(subscriptionId); |
| 7772 | if (phone == null) { |
| 7773 | loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId); |
| 7774 | return false; |
| 7775 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7776 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7777 | boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7778 | CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL); |
| 7779 | boolean isDeviceSupported = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7780 | phone.getContext().getResources().getBoolean(R.bool.config_support_rtt); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7781 | return isCarrierSupported && isDeviceSupported; |
| 7782 | } finally { |
| 7783 | Binder.restoreCallingIdentity(identity); |
| 7784 | } |
Hall Liu | 9818758 | 2018-01-22 19:15:32 -0800 | [diff] [blame] | 7785 | } |
| 7786 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 7787 | /** |
Hall Liu | f2daa02 | 2019-07-23 18:39:00 -0700 | [diff] [blame] | 7788 | * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set |
| 7789 | * RTT setting, will return true if the device and carrier both support RTT. |
| 7790 | * 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] | 7791 | */ |
| 7792 | public boolean isRttEnabled(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7793 | final long identity = Binder.clearCallingIdentity(); |
| 7794 | try { |
Hall Liu | 5bab75c | 2019-12-11 23:58:20 +0000 | [diff] [blame] | 7795 | boolean isRttSupported = isRttSupported(subscriptionId); |
| 7796 | boolean isUserRttSettingOn = Settings.Secure.getInt( |
| 7797 | mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0; |
| 7798 | boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId) |
| 7799 | .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL); |
| 7800 | return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7801 | } finally { |
| 7802 | Binder.restoreCallingIdentity(identity); |
| 7803 | } |
Hall Liu | 3ad5f01 | 2018-04-06 16:23:39 -0700 | [diff] [blame] | 7804 | } |
| 7805 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7806 | @Deprecated |
| 7807 | @Override |
| 7808 | public String getDeviceId(String callingPackage) { |
| 7809 | return getDeviceIdWithFeature(callingPackage, null); |
| 7810 | } |
| 7811 | |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7812 | /** |
| 7813 | * Returns the unique device ID of phone, for example, the IMEI for |
| 7814 | * GSM and the MEID for CDMA phones. Return null if device ID is not available. |
| 7815 | * |
| 7816 | * <p>Requires Permission: |
| 7817 | * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} |
| 7818 | */ |
| 7819 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7820 | public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) { |
Shuo Qian | 13d8915 | 2021-05-10 23:58:11 -0700 | [diff] [blame] | 7821 | try { |
| 7822 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 7823 | } catch (SecurityException se) { |
| 7824 | EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid()); |
| 7825 | throw new SecurityException("Package " + callingPackage + " does not belong to " |
| 7826 | + Binder.getCallingUid()); |
| 7827 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7828 | final Phone phone = PhoneFactory.getPhone(0); |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7829 | if (phone == null) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7830 | return null; |
| 7831 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7832 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 7833 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7834 | callingPackage, callingFeatureId, "getDeviceId")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7835 | return null; |
| 7836 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7837 | |
| 7838 | final long identity = Binder.clearCallingIdentity(); |
| 7839 | try { |
| 7840 | return phone.getDeviceId(); |
| 7841 | } finally { |
| 7842 | Binder.restoreCallingIdentity(identity); |
| 7843 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7844 | } |
| 7845 | |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 7846 | /** |
| 7847 | * {@hide} |
| 7848 | * Returns the IMS Registration Status on a particular subid |
| 7849 | * |
| 7850 | * @param subId |
| 7851 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7852 | public boolean isImsRegistered(int subId) { |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 7853 | Phone phone = getPhone(subId); |
| 7854 | if (phone != null) { |
| 7855 | return phone.isImsRegistered(); |
| 7856 | } else { |
| 7857 | return false; |
| 7858 | } |
| 7859 | } |
| 7860 | |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 7861 | @Override |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7862 | public int getSubIdForPhoneAccountHandle( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7863 | PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) { |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7864 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(), |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7865 | callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) { |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7866 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 7867 | } |
| 7868 | final long identity = Binder.clearCallingIdentity(); |
| 7869 | try { |
| 7870 | return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle); |
| 7871 | } finally { |
| 7872 | Binder.restoreCallingIdentity(identity); |
| 7873 | } |
| 7874 | } |
| 7875 | |
| 7876 | @Override |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 7877 | public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) { |
Alireza Forouzan | 4ac4f98 | 2021-03-16 22:18:52 -0700 | [diff] [blame] | 7878 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 7879 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 7880 | mApp, |
| 7881 | subscriptionId, |
| 7882 | "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: " |
| 7883 | + subscriptionId); |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 7884 | final long identity = Binder.clearCallingIdentity(); |
| 7885 | try { |
| 7886 | Phone phone = getPhone(subscriptionId); |
| 7887 | if (phone == null) { |
| 7888 | return null; |
| 7889 | } |
| 7890 | return PhoneUtils.makePstnPhoneAccountHandle(phone); |
| 7891 | } finally { |
| 7892 | Binder.restoreCallingIdentity(identity); |
| 7893 | } |
| 7894 | } |
| 7895 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7896 | /** |
| 7897 | * @return the VoWiFi calling availability. |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 7898 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7899 | public boolean isWifiCallingAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7900 | final long identity = Binder.clearCallingIdentity(); |
| 7901 | try { |
| 7902 | Phone phone = getPhone(subId); |
| 7903 | if (phone != null) { |
| 7904 | return phone.isWifiCallingEnabled(); |
| 7905 | } else { |
| 7906 | return false; |
| 7907 | } |
| 7908 | } finally { |
| 7909 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7910 | } |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 7911 | } |
| 7912 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7913 | /** |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7914 | * @return the VT calling availability. |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 7915 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7916 | public boolean isVideoTelephonyAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7917 | final long identity = Binder.clearCallingIdentity(); |
| 7918 | try { |
| 7919 | Phone phone = getPhone(subId); |
| 7920 | if (phone != null) { |
| 7921 | return phone.isVideoEnabled(); |
| 7922 | } else { |
| 7923 | return false; |
| 7924 | } |
| 7925 | } finally { |
| 7926 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7927 | } |
| 7928 | } |
| 7929 | |
| 7930 | /** |
| 7931 | * @return the IMS registration technology for the MMTEL feature. Valid return values are |
| 7932 | * defined in {@link ImsRegistrationImplBase}. |
| 7933 | */ |
| 7934 | public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7935 | final long identity = Binder.clearCallingIdentity(); |
| 7936 | try { |
| 7937 | Phone phone = getPhone(subId); |
| 7938 | if (phone != null) { |
| 7939 | return phone.getImsRegistrationTech(); |
| 7940 | } else { |
| 7941 | return ImsRegistrationImplBase.REGISTRATION_TECH_NONE; |
| 7942 | } |
| 7943 | } finally { |
| 7944 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7945 | } |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 7946 | } |
| 7947 | |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 7948 | @Override |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 7949 | public void factoryReset(int subId, String callingPackage) { |
paulhu | 5a77360 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 7950 | enforceSettingsPermission(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 7951 | if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) { |
| 7952 | return; |
| 7953 | } |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 7954 | Phone defaultPhone = getDefaultPhone(); |
| 7955 | if (defaultPhone != null) { |
| 7956 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7957 | mApp, getDefaultPhone().getSubId(), "factoryReset"); |
| 7958 | } |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7959 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7960 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7961 | try { |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 7962 | if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction( |
| 7963 | UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7964 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 7965 | getDefaultDataEnabled(), callingPackage); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7966 | setNetworkSelectionModeAutomatic(subId); |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 7967 | Phone phone = getPhone(subId); |
SongFerngWang | fd89b10 | 2021-05-27 22:44:54 +0800 | [diff] [blame] | 7968 | cleanUpAllowedNetworkTypes(phone, subId); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7969 | setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId)); |
Jordan Liu | 857e73a | 2021-03-05 16:24:04 -0800 | [diff] [blame] | 7970 | getPhone(subId).resetCarrierKeysForImsiEncryption(); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7971 | } |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 7972 | // There has been issues when Sms raw table somehow stores orphan |
| 7973 | // fragments. They lead to garbled message when new fragments come |
| 7974 | // in and combined with those stale ones. In case this happens again, |
| 7975 | // user can reset all network settings which will clean up this table. |
| 7976 | cleanUpSmsRawTable(getDefaultPhone().getContext()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 7977 | // Clean up IMS settings as well here. |
| 7978 | int slotId = getSlotIndex(subId); |
| 7979 | if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 7980 | ImsManager.getInstance(mApp, slotId).factoryReset(); |
| 7981 | } |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 7982 | |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 7983 | if (defaultPhone == null) { |
| 7984 | return; |
| 7985 | } |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 7986 | // Erase modem config if erase modem on network setting is enabled. |
| 7987 | String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY, |
| 7988 | RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED); |
| 7989 | if (configValue != null && Boolean.parseBoolean(configValue)) { |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 7990 | sendEraseModemConfig(defaultPhone); |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 7991 | } |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 7992 | |
| 7993 | sendEraseDataInSharedPreferences(defaultPhone); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7994 | } finally { |
| 7995 | Binder.restoreCallingIdentity(identity); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 7996 | } |
| 7997 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7998 | |
SongFerngWang | fd89b10 | 2021-05-27 22:44:54 +0800 | [diff] [blame] | 7999 | @VisibleForTesting |
| 8000 | void cleanUpAllowedNetworkTypes(Phone phone, int subId) { |
| 8001 | if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) { |
| 8002 | return; |
| 8003 | } |
| 8004 | long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType( |
| 8005 | RILConstants.PREFERRED_NETWORK_MODE); |
| 8006 | SubscriptionManager.setSubscriptionProperty(subId, |
| 8007 | SubscriptionManager.ALLOWED_NETWORK_TYPES, |
| 8008 | "user=" + defaultNetworkType); |
| 8009 | phone.loadAllowedNetworksFromSubscriptionDatabase(); |
| 8010 | phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER, |
| 8011 | defaultNetworkType, null); |
| 8012 | } |
| 8013 | |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 8014 | private void cleanUpSmsRawTable(Context context) { |
| 8015 | ContentResolver resolver = context.getContentResolver(); |
| 8016 | Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete"); |
| 8017 | resolver.delete(uri, null, null); |
| 8018 | } |
| 8019 | |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 8020 | @Override |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 8021 | public String getSimLocaleForSubscriber(int subId) { |
| 8022 | enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId); |
| 8023 | final Phone phone = getPhone(subId); |
| 8024 | if (phone == null) { |
| 8025 | log("getSimLocaleForSubscriber, invalid subId"); |
chen xu | 2bb91e4 | 2019-01-24 14:35:54 -0800 | [diff] [blame] | 8026 | return null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 8027 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8028 | final long identity = Binder.clearCallingIdentity(); |
| 8029 | try { |
Jack Yu | 3beaf9d | 2023-04-14 09:17:27 -0700 | [diff] [blame] | 8030 | SubscriptionInfo info = getSubscriptionManagerService().getActiveSubscriptionInfo(subId, |
| 8031 | phone.getContext().getOpPackageName(), |
| 8032 | phone.getContext().getAttributionTag()); |
| 8033 | if (info == null) { |
| 8034 | log("getSimLocaleForSubscriber, inactive subId: " + subId); |
| 8035 | return null; |
chen xu | 6291c47 | 2019-02-04 12:55:53 -0800 | [diff] [blame] | 8036 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8037 | // Try and fetch the locale from the carrier properties or from the SIM language |
| 8038 | // preferences (EF-PL and EF-LI)... |
| 8039 | final int mcc = info.getMcc(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8040 | String simLanguage = null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 8041 | final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs(); |
| 8042 | if (localeFromDefaultSim != null) { |
| 8043 | if (!localeFromDefaultSim.getCountry().isEmpty()) { |
| 8044 | if (DBG) log("Using locale from subId: " + subId + " locale: " |
| 8045 | + localeFromDefaultSim); |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 8046 | return matchLocaleFromSupportedLocaleList(phone, localeFromDefaultSim); |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 8047 | } else { |
| 8048 | simLanguage = localeFromDefaultSim.getLanguage(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8049 | } |
| 8050 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 8051 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8052 | // The SIM language preferences only store a language (e.g. fr = French), not an |
| 8053 | // exact locale (e.g. fr_FR = French/France). So, if the locale returned from |
| 8054 | // the SIM and carrier preferences does not include a country we add the country |
| 8055 | // determined from the SIM MCC to provide an exact locale. |
zoey chen | c730df8 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 8056 | final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8057 | if (mccLocale != null) { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 8058 | if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale); |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 8059 | return matchLocaleFromSupportedLocaleList(phone, mccLocale); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8060 | } |
| 8061 | |
| 8062 | if (DBG) log("No locale found - returning null"); |
| 8063 | return null; |
| 8064 | } finally { |
| 8065 | Binder.restoreCallingIdentity(identity); |
| 8066 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 8067 | } |
| 8068 | |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 8069 | @VisibleForTesting |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 8070 | String matchLocaleFromSupportedLocaleList(Phone phone, @NonNull Locale inputLocale) { |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 8071 | String[] supportedLocale = com.android.internal.app.LocalePicker.getSupportedLocales( |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 8072 | phone.getContext()); |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 8073 | for (String localeTag : supportedLocale) { |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 8074 | if (LocaleList.matchesLanguageAndScript(inputLocale, Locale.forLanguageTag(localeTag)) |
| 8075 | && TextUtils.equals(inputLocale.getCountry(), |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 8076 | Locale.forLanguageTag(localeTag).getCountry())) { |
| 8077 | return localeTag; |
| 8078 | } |
| 8079 | } |
| 8080 | return inputLocale.toLanguageTag(); |
| 8081 | } |
| 8082 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8083 | /** |
| 8084 | * NOTE: this method assumes permission checks are done and caller identity has been cleared. |
| 8085 | */ |
| 8086 | private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() { |
Jack Yu | 3beaf9d | 2023-04-14 09:17:27 -0700 | [diff] [blame] | 8087 | return getSubscriptionManagerService().getActiveSubscriptionInfoList( |
| 8088 | mApp.getOpPackageName(), mApp.getAttributionTag()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 8089 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 8090 | |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8091 | private ActivityStatsTechSpecificInfo[] mLastModemActivitySpecificInfo = null; |
| 8092 | private ModemActivityInfo mLastModemActivityInfo = null; |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 8093 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 8094 | /** |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 8095 | * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object |
| 8096 | * representing the state of the modem. |
| 8097 | * |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 8098 | * NOTE: The underlying implementation clears the modem state, so there should only ever be one |
| 8099 | * caller to it. Everyone should call this class to get cumulative data. |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 8100 | * @hide |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 8101 | */ |
| 8102 | @Override |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 8103 | public void requestModemActivityInfo(ResultReceiver result) { |
| 8104 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8105 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8106 | |
| 8107 | final long identity = Binder.clearCallingIdentity(); |
| 8108 | try { |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 8109 | sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8110 | } finally { |
| 8111 | Binder.restoreCallingIdentity(identity); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 8112 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 8113 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8114 | |
Gary Jian | 76280a4 | 2022-12-07 16:18:33 +0800 | [diff] [blame] | 8115 | // Checks that ModemActivityInfo is valid. Sleep time and Idle time should be |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 8116 | // less than total activity duration. |
| 8117 | private boolean isModemActivityInfoValid(ModemActivityInfo info) { |
| 8118 | if (info == null) { |
| 8119 | return false; |
| 8120 | } |
| 8121 | int activityDurationMs = |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 8122 | (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis()); |
Gary Jian | 76280a4 | 2022-12-07 16:18:33 +0800 | [diff] [blame] | 8123 | activityDurationMs += MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS; |
| 8124 | |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 8125 | int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum(); |
| 8126 | |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 8127 | return (info.isValid() |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 8128 | && (info.getSleepTimeMillis() <= activityDurationMs) |
| 8129 | && (info.getIdleTimeMillis() <= activityDurationMs)); |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 8130 | } |
| 8131 | |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8132 | private void updateLastModemActivityInfo(ModemActivityInfo info, int rat, int freq) { |
| 8133 | int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()]; |
| 8134 | int[] txTimeMs = info.getTransmitTimeMillis(rat, freq); |
| 8135 | int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat, freq); |
| 8136 | |
| 8137 | for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) { |
| 8138 | mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl]; |
| 8139 | } |
| 8140 | |
| 8141 | mLastModemActivityInfo.setTransmitTimeMillis(rat, freq, mergedTxTimeMs); |
| 8142 | mLastModemActivityInfo.setReceiveTimeMillis( |
| 8143 | rat, |
| 8144 | freq, |
| 8145 | info.getReceiveTimeMillis(rat, freq) |
| 8146 | + mLastModemActivityInfo.getReceiveTimeMillis(rat, freq)); |
| 8147 | } |
| 8148 | |
| 8149 | private void updateLastModemActivityInfo(ModemActivityInfo info, int rat) { |
| 8150 | int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()]; |
| 8151 | int[] txTimeMs = info.getTransmitTimeMillis(rat); |
| 8152 | int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat); |
| 8153 | |
| 8154 | for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) { |
| 8155 | mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl]; |
| 8156 | } |
| 8157 | mLastModemActivityInfo.setTransmitTimeMillis(rat, mergedTxTimeMs); |
| 8158 | mLastModemActivityInfo.setReceiveTimeMillis( |
| 8159 | rat, |
| 8160 | info.getReceiveTimeMillis(rat) + mLastModemActivityInfo.getReceiveTimeMillis(rat)); |
| 8161 | } |
| 8162 | |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 8163 | /** |
| 8164 | * Merge this ModemActivityInfo with mLastModemActivitySpecificInfo |
| 8165 | * @param info recent ModemActivityInfo |
| 8166 | */ |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8167 | private void mergeModemActivityInfo(ModemActivityInfo info) { |
| 8168 | List<ActivityStatsTechSpecificInfo> merged = new ArrayList<>(); |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 8169 | ActivityStatsTechSpecificInfo deltaSpecificInfo; |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8170 | boolean matched; |
| 8171 | for (int i = 0; i < info.getSpecificInfoLength(); i++) { |
| 8172 | matched = false; |
| 8173 | int rat = info.getSpecificInfoRat(i); |
| 8174 | int freq = info.getSpecificInfoFrequencyRange(i); |
| 8175 | //Check each ActivityStatsTechSpecificInfo in this ModemActivityInfo for new rat returns |
| 8176 | //Add a new ActivityStatsTechSpecificInfo if is a new rat, and merge with the original |
| 8177 | //if it already exists |
| 8178 | for (int j = 0; j < mLastModemActivitySpecificInfo.length; j++) { |
| 8179 | if (rat == mLastModemActivityInfo.getSpecificInfoRat(j) && !matched) { |
| 8180 | //Merged based on frequency range (MMWAVE vs SUB6) for 5G |
| 8181 | if (rat == AccessNetworkConstants.AccessNetworkType.NGRAN) { |
| 8182 | if (freq == mLastModemActivityInfo.getSpecificInfoFrequencyRange(j)) { |
| 8183 | updateLastModemActivityInfo(info, rat, freq); |
| 8184 | matched = true; |
| 8185 | } |
| 8186 | } else { |
| 8187 | updateLastModemActivityInfo(info, rat); |
| 8188 | matched = true; |
| 8189 | } |
| 8190 | } |
| 8191 | } |
| 8192 | |
| 8193 | if (!matched) { |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 8194 | deltaSpecificInfo = |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8195 | new ActivityStatsTechSpecificInfo( |
| 8196 | rat, |
| 8197 | freq, |
| 8198 | info.getTransmitTimeMillis(rat, freq), |
| 8199 | (int) info.getReceiveTimeMillis(rat, freq)); |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 8200 | merged.addAll(Arrays.asList(deltaSpecificInfo)); |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8201 | } |
| 8202 | } |
| 8203 | merged.addAll(Arrays.asList(mLastModemActivitySpecificInfo)); |
| 8204 | mLastModemActivitySpecificInfo = |
| 8205 | new ActivityStatsTechSpecificInfo[merged.size()]; |
| 8206 | merged.toArray(mLastModemActivitySpecificInfo); |
| 8207 | |
| 8208 | mLastModemActivityInfo.setTimestamp(info.getTimestampMillis()); |
| 8209 | mLastModemActivityInfo.setSleepTimeMillis( |
| 8210 | info.getSleepTimeMillis() |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 8211 | + mLastModemActivityInfo.getSleepTimeMillis()); |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8212 | mLastModemActivityInfo.setIdleTimeMillis( |
| 8213 | info.getIdleTimeMillis() |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 8214 | + mLastModemActivityInfo.getIdleTimeMillis()); |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 8215 | |
| 8216 | mLastModemActivityInfo = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 8217 | new ModemActivityInfo( |
| 8218 | mLastModemActivityInfo.getTimestampMillis(), |
| 8219 | mLastModemActivityInfo.getSleepTimeMillis(), |
| 8220 | mLastModemActivityInfo.getIdleTimeMillis(), |
| 8221 | mLastModemActivitySpecificInfo); |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 8222 | } |
| 8223 | |
| 8224 | private ActivityStatsTechSpecificInfo[] deepCopyModemActivitySpecificInfo( |
| 8225 | ActivityStatsTechSpecificInfo[] info) { |
| 8226 | int infoSize = info.length; |
| 8227 | ActivityStatsTechSpecificInfo[] ret = new ActivityStatsTechSpecificInfo[infoSize]; |
| 8228 | for (int i = 0; i < infoSize; i++) { |
| 8229 | ret[i] = new ActivityStatsTechSpecificInfo( |
| 8230 | info[i].getRat(), info[i].getFrequencyRange(), |
| 8231 | info[i].getTransmitTimeMillis(), |
| 8232 | (int) info[i].getReceiveTimeMillis()); |
| 8233 | } |
| 8234 | return ret; |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8235 | } |
| 8236 | |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8237 | /** |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8238 | * Returns the service state information on specified subscription. |
| 8239 | */ |
| 8240 | @Override |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 8241 | public ServiceState getServiceStateForSubscriber(int subId, |
| 8242 | boolean renounceFineLocationAccess, boolean renounceCoarseLocationAccess, |
| 8243 | String callingPackage, String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8244 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8245 | mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) { |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8246 | return null; |
| 8247 | } |
| 8248 | |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 8249 | boolean hasFinePermission = false; |
| 8250 | boolean hasCoarsePermission = false; |
| 8251 | if (!renounceFineLocationAccess) { |
| 8252 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 8253 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 8254 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 8255 | .setCallingPackage(callingPackage) |
| 8256 | .setCallingFeatureId(callingFeatureId) |
| 8257 | .setCallingPid(Binder.getCallingPid()) |
| 8258 | .setCallingUid(Binder.getCallingUid()) |
| 8259 | .setMethod("getServiceStateForSubscriber") |
| 8260 | .setLogAsInfo(true) |
| 8261 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 8262 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 8263 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 8264 | .build()); |
| 8265 | hasFinePermission = |
| 8266 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 8267 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 8268 | |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 8269 | if (!renounceCoarseLocationAccess) { |
| 8270 | LocationAccessPolicy.LocationPermissionResult coarseLocationResult = |
| 8271 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 8272 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 8273 | .setCallingPackage(callingPackage) |
| 8274 | .setCallingFeatureId(callingFeatureId) |
| 8275 | .setCallingPid(Binder.getCallingPid()) |
| 8276 | .setCallingUid(Binder.getCallingUid()) |
| 8277 | .setMethod("getServiceStateForSubscriber") |
| 8278 | .setLogAsInfo(true) |
| 8279 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 8280 | .setMinSdkVersionForFine(Integer.MAX_VALUE) |
| 8281 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 8282 | .build()); |
| 8283 | hasCoarsePermission = |
| 8284 | coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 8285 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 8286 | |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 8287 | final Phone phone = getPhone(subId); |
| 8288 | if (phone == null) { |
| 8289 | return null; |
| 8290 | } |
| 8291 | |
Jordan Liu | 0f2bc44 | 2020-11-18 16:47:37 -0800 | [diff] [blame] | 8292 | final long identity = Binder.clearCallingIdentity(); |
| 8293 | |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 8294 | boolean isCallingPackageDataService = phone.getDataServicePackages() |
| 8295 | .contains(callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8296 | try { |
Jordan Liu | c437b19 | 2020-08-17 10:59:12 -0700 | [diff] [blame] | 8297 | // isActiveSubId requires READ_PHONE_STATE, which we already check for above |
Jack Yu | 3beaf9d | 2023-04-14 09:17:27 -0700 | [diff] [blame] | 8298 | SubscriptionInfoInternal subInfo = getSubscriptionManagerService() |
| 8299 | .getSubscriptionInfoInternal(subId); |
| 8300 | if (subInfo == null || !subInfo.isActive()) { |
| 8301 | Rlog.d(LOG_TAG, "getServiceStateForSubscriber returning null for inactive " |
| 8302 | + "subId=" + subId); |
| 8303 | return null; |
Jordan Liu | c437b19 | 2020-08-17 10:59:12 -0700 | [diff] [blame] | 8304 | } |
| 8305 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 8306 | ServiceState ss = phone.getServiceState(); |
| 8307 | |
| 8308 | // Scrub out the location info in ServiceState depending on what level of access |
| 8309 | // the caller has. |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 8310 | if (hasFinePermission || isCallingPackageDataService) return ss; |
Malcolm Chen | 5052de6 | 2019-12-30 13:56:38 -0800 | [diff] [blame] | 8311 | if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false); |
| 8312 | return ss.createLocationInfoSanitizedCopy(true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8313 | } finally { |
| 8314 | Binder.restoreCallingIdentity(identity); |
| 8315 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8316 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8317 | |
| 8318 | /** |
| 8319 | * Returns the URI for the per-account voicemail ringtone set in Phone settings. |
| 8320 | * |
| 8321 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 8322 | * voicemail ringtone. |
| 8323 | * @return The URI for the ringtone to play when receiving a voicemail from a specific |
| 8324 | * PhoneAccount. |
| 8325 | */ |
| 8326 | @Override |
| 8327 | public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8328 | final long identity = Binder.clearCallingIdentity(); |
| 8329 | try { |
| 8330 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 8331 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8332 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8333 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8334 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8335 | return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext()); |
| 8336 | } finally { |
| 8337 | Binder.restoreCallingIdentity(identity); |
| 8338 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8339 | } |
| 8340 | |
| 8341 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8342 | * Sets the per-account voicemail ringtone. |
| 8343 | * |
| 8344 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 8345 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 8346 | * |
| 8347 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 8348 | * voicemail ringtone. |
| 8349 | * @param uri The URI for the ringtone to play when receiving a voicemail from a specific |
| 8350 | * PhoneAccount. |
| 8351 | */ |
| 8352 | @Override |
| 8353 | public void setVoicemailRingtoneUri(String callingPackage, |
| 8354 | PhoneAccountHandle phoneAccountHandle, Uri uri) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8355 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8356 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 8357 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 8358 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8359 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8360 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 8361 | "setVoicemailRingtoneUri"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8362 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8363 | |
| 8364 | final long identity = Binder.clearCallingIdentity(); |
| 8365 | try { |
| 8366 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 8367 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8368 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8369 | } |
| 8370 | VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri); |
| 8371 | } finally { |
| 8372 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8373 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8374 | } |
| 8375 | |
| 8376 | /** |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8377 | * Returns whether vibration is set for voicemail notification in Phone settings. |
| 8378 | * |
| 8379 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 8380 | * voicemail vibration setting. |
| 8381 | * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise. |
| 8382 | */ |
| 8383 | @Override |
| 8384 | public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8385 | final long identity = Binder.clearCallingIdentity(); |
| 8386 | try { |
| 8387 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 8388 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8389 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8390 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8391 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8392 | return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext()); |
| 8393 | } finally { |
| 8394 | Binder.restoreCallingIdentity(identity); |
| 8395 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8396 | } |
| 8397 | |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8398 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8399 | * Sets the per-account voicemail vibration. |
| 8400 | * |
| 8401 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 8402 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 8403 | * |
| 8404 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 8405 | * voicemail vibration setting. |
| 8406 | * @param enabled Whether to enable or disable vibration for voicemail notifications from a |
| 8407 | * specific PhoneAccount. |
| 8408 | */ |
| 8409 | @Override |
| 8410 | public void setVoicemailVibrationEnabled(String callingPackage, |
| 8411 | PhoneAccountHandle phoneAccountHandle, boolean enabled) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8412 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8413 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 8414 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 8415 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8416 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8417 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 8418 | "setVoicemailVibrationEnabled"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8419 | } |
| 8420 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8421 | final long identity = Binder.clearCallingIdentity(); |
| 8422 | try { |
| 8423 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 8424 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8425 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8426 | } |
| 8427 | VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled); |
| 8428 | } finally { |
| 8429 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8430 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8431 | } |
| 8432 | |
| 8433 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8434 | * Make sure either called from same process as self (phone) or IPC caller has read privilege. |
| 8435 | * |
| 8436 | * @throws SecurityException if the caller does not have the required permission |
| 8437 | */ |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 8438 | @VisibleForTesting |
| 8439 | public void enforceReadPrivilegedPermission(String message) { |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8440 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8441 | message); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8442 | } |
| 8443 | |
| 8444 | /** |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 8445 | * Make sure either called from same process as self (phone) or IPC caller has send SMS |
| 8446 | * permission. |
| 8447 | * |
| 8448 | * @throws SecurityException if the caller does not have the required permission |
| 8449 | */ |
| 8450 | private void enforceSendSmsPermission() { |
| 8451 | mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null); |
| 8452 | } |
| 8453 | |
| 8454 | /** |
Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame] | 8455 | * Make sure either called from same process as self (phone) or IPC caller has interact across |
| 8456 | * users permission. |
| 8457 | * |
| 8458 | * @throws SecurityException if the caller does not have the required permission |
| 8459 | */ |
| 8460 | private void enforceInteractAcrossUsersPermission(String message) { |
| 8461 | mApp.enforceCallingOrSelfPermission(permission.INTERACT_ACROSS_USERS, message); |
| 8462 | } |
| 8463 | |
| 8464 | /** |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 8465 | * Make sure called from the package in charge of visual voicemail. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 8466 | * |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 8467 | * @throws SecurityException if the caller is not the visual voicemail package. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 8468 | */ |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 8469 | private void enforceVisualVoicemailPackage(String callingPackage, int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8470 | final long identity = Binder.clearCallingIdentity(); |
| 8471 | try { |
| 8472 | ComponentName componentName = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8473 | RemoteVvmTaskManager.getRemotePackage(mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8474 | if (componentName == null) { |
| 8475 | throw new SecurityException( |
| 8476 | "Caller not current active visual voicemail package[null]"); |
| 8477 | } |
| 8478 | String vvmPackage = componentName.getPackageName(); |
| 8479 | if (!callingPackage.equals(vvmPackage)) { |
Hui Wang | 7f65755 | 2022-08-16 16:58:25 +0000 | [diff] [blame] | 8480 | throw new SecurityException("Caller not current active visual voicemail package"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8481 | } |
| 8482 | } finally { |
| 8483 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 8484 | } |
| 8485 | } |
| 8486 | |
| 8487 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8488 | * Return the application ID for the app type. |
| 8489 | * |
| 8490 | * @param subId the subscription ID that this request applies to. |
| 8491 | * @param appType the uicc app type. |
| 8492 | * @return Application ID for specificied app type, or null if no uicc. |
| 8493 | */ |
| 8494 | @Override |
| 8495 | public String getAidForAppType(int subId, int appType) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8496 | enforceReadPrivilegedPermission("getAidForAppType"); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8497 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8498 | |
| 8499 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8500 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8501 | if (phone == null) { |
| 8502 | return null; |
| 8503 | } |
| 8504 | String aid = null; |
| 8505 | try { |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 8506 | aid = UiccController.getInstance().getUiccPort(phone.getPhoneId()) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8507 | .getApplicationByType(appType).getAid(); |
| 8508 | } catch (Exception e) { |
| 8509 | Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e); |
| 8510 | } |
| 8511 | return aid; |
| 8512 | } finally { |
| 8513 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8514 | } |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8515 | } |
| 8516 | |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8517 | /** |
| 8518 | * Return the Electronic Serial Number. |
| 8519 | * |
| 8520 | * @param subId the subscription ID that this request applies to. |
| 8521 | * @return ESN or null if error. |
| 8522 | */ |
| 8523 | @Override |
| 8524 | public String getEsn(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8525 | enforceReadPrivilegedPermission("getEsn"); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8526 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8527 | |
| 8528 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8529 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8530 | if (phone == null) { |
| 8531 | return null; |
| 8532 | } |
| 8533 | String esn = null; |
| 8534 | try { |
| 8535 | esn = phone.getEsn(); |
| 8536 | } catch (Exception e) { |
| 8537 | Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e); |
| 8538 | } |
| 8539 | return esn; |
| 8540 | } finally { |
| 8541 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8542 | } |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8543 | } |
| 8544 | |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 8545 | /** |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8546 | * Return the Preferred Roaming List Version. |
| 8547 | * |
| 8548 | * @param subId the subscription ID that this request applies to. |
| 8549 | * @return PRLVersion or null if error. |
| 8550 | */ |
| 8551 | @Override |
| 8552 | public String getCdmaPrlVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8553 | enforceReadPrivilegedPermission("getCdmaPrlVersion"); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8554 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8555 | |
| 8556 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8557 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8558 | if (phone == null) { |
| 8559 | return null; |
| 8560 | } |
| 8561 | String cdmaPrlVersion = null; |
| 8562 | try { |
| 8563 | cdmaPrlVersion = phone.getCdmaPrlVersion(); |
| 8564 | } catch (Exception e) { |
| 8565 | Log.e(LOG_TAG, "Not getting PRLVersion", e); |
| 8566 | } |
| 8567 | return cdmaPrlVersion; |
| 8568 | } finally { |
| 8569 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8570 | } |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8571 | } |
| 8572 | |
| 8573 | /** |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 8574 | * Get snapshot of Telephony histograms |
| 8575 | * @return List of Telephony histograms |
| 8576 | * @hide |
| 8577 | */ |
| 8578 | @Override |
| 8579 | public List<TelephonyHistogram> getTelephonyHistograms() { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8580 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8581 | mApp, getDefaultSubscription(), "getTelephonyHistograms"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8582 | |
| 8583 | final long identity = Binder.clearCallingIdentity(); |
| 8584 | try { |
| 8585 | return RIL.getTelephonyRILTimingHistograms(); |
| 8586 | } finally { |
| 8587 | Binder.restoreCallingIdentity(identity); |
| 8588 | } |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 8589 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8590 | |
| 8591 | /** |
| 8592 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8593 | * Set the allowed carrier list and the excluded carrier list, indicating the priority between |
| 8594 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8595 | * Require system privileges. In the future we may add this to carrier APIs. |
| 8596 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8597 | * @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] | 8598 | */ |
| 8599 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8600 | @TelephonyManager.SetCarrierRestrictionResult |
| 8601 | public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) { |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8602 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8603 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8604 | |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8605 | if (carrierRestrictionRules == null) { |
| 8606 | throw new NullPointerException("carrier restriction cannot be null"); |
Meng Wang | 9b7c4e9 | 2017-02-17 11:41:27 -0800 | [diff] [blame] | 8607 | } |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8608 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8609 | final long identity = Binder.clearCallingIdentity(); |
| 8610 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8611 | return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8612 | workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8613 | } finally { |
| 8614 | Binder.restoreCallingIdentity(identity); |
| 8615 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8616 | } |
| 8617 | |
| 8618 | /** |
| 8619 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8620 | * Get the allowed carrier list and the excluded carrier list, including the priority between |
| 8621 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8622 | * Require system privileges. In the future we may add this to carrier APIs. |
| 8623 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8624 | * @return {@link android.telephony.CarrierRestrictionRules} |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8625 | */ |
| 8626 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8627 | public CarrierRestrictionRules getAllowedCarriers() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8628 | enforceReadPrivilegedPermission("getAllowedCarriers"); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8629 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8630 | |
| 8631 | final long identity = Binder.clearCallingIdentity(); |
| 8632 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8633 | Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource); |
| 8634 | if (response instanceof CarrierRestrictionRules) { |
| 8635 | return (CarrierRestrictionRules) response; |
| 8636 | } |
| 8637 | // Response is an Exception of some kind, |
| 8638 | // which is signalled to the user as a NULL retval |
| 8639 | return null; |
| 8640 | } catch (Exception e) { |
| 8641 | Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e); |
| 8642 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8643 | } finally { |
| 8644 | Binder.restoreCallingIdentity(identity); |
| 8645 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8646 | } |
| 8647 | |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 8648 | /** |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 8649 | * Fetches the carrier restriction status of the device and sends the status to the caller |
| 8650 | * through the callback. |
| 8651 | * |
| 8652 | * @param callback The callback that will be used to send the result. |
| 8653 | * @throws SecurityException if the caller does not have the required permission/privileges or |
| 8654 | * the caller is not allowlisted. |
| 8655 | */ |
| 8656 | @Override |
| 8657 | public void getCarrierRestrictionStatus(IIntegerConsumer callback, String packageName) { |
| 8658 | enforceReadPermission("getCarrierRestrictionStatus"); |
| 8659 | int carrierId = validateCallerAndGetCarrierId(packageName); |
| 8660 | if (carrierId == CarrierAllowListInfo.INVALID_CARRIER_ID) { |
| 8661 | Rlog.e(LOG_TAG, "getCarrierRestrictionStatus: caller is not registered"); |
| 8662 | throw new SecurityException("Not an authorized caller"); |
| 8663 | } |
| 8664 | final long identity = Binder.clearCallingIdentity(); |
| 8665 | try { |
| 8666 | Consumer<Integer> consumer = FunctionalUtils.ignoreRemoteException(callback::accept); |
| 8667 | CallerCallbackInfo callbackInfo = new CallerCallbackInfo(consumer, carrierId); |
| 8668 | sendRequestAsync(CMD_GET_ALLOWED_CARRIERS, callbackInfo); |
| 8669 | } finally { |
| 8670 | Binder.restoreCallingIdentity(identity); |
| 8671 | } |
| 8672 | } |
| 8673 | |
arunvoddu | 567f2b4 | 2023-04-25 17:22:00 +0000 | [diff] [blame^] | 8674 | @Override |
| 8675 | public List<String> getShaIdFromAllowList(String pkgName, int carrierId) { |
| 8676 | enforceReadPrivilegedPermission("checkCarrierRestrictionFileForNoChange"); |
| 8677 | CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp); |
| 8678 | return allowListInfo.getShaIdList(pkgName, carrierId); |
| 8679 | } |
| 8680 | |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 8681 | @VisibleForTesting |
| 8682 | public int validateCallerAndGetCarrierId(String packageName) { |
| 8683 | CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp); |
| 8684 | return allowListInfo.validateCallerAndGetCarrierId(packageName); |
| 8685 | } |
| 8686 | |
| 8687 | /** |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 8688 | * Action set from carrier signalling broadcast receivers to enable/disable radio |
| 8689 | * @param subId the subscription ID that this action applies to. |
| 8690 | * @param enabled control enable or disable radio. |
| 8691 | * {@hide} |
| 8692 | */ |
| 8693 | @Override |
| 8694 | public void carrierActionSetRadioEnabled(int subId, boolean enabled) { |
| 8695 | enforceModifyPermission(); |
| 8696 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8697 | |
| 8698 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 8699 | if (phone == null) { |
| 8700 | loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId); |
| 8701 | return; |
| 8702 | } |
| 8703 | try { |
| 8704 | phone.carrierActionSetRadioEnabled(enabled); |
| 8705 | } catch (Exception e) { |
| 8706 | Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8707 | } finally { |
| 8708 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 8709 | } |
| 8710 | } |
| 8711 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 8712 | /** |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 8713 | * Enable or disable Voice over NR (VoNR) |
| 8714 | * @param subId the subscription ID that this action applies to. |
| 8715 | * @param enabled enable or disable VoNR. |
| 8716 | * @return operation result. |
| 8717 | */ |
| 8718 | @Override |
| 8719 | public int setVoNrEnabled(int subId, boolean enabled) { |
| 8720 | enforceModifyPermission(); |
| 8721 | final Phone phone = getPhone(subId); |
| 8722 | |
| 8723 | final long identity = Binder.clearCallingIdentity(); |
| 8724 | if (phone == null) { |
| 8725 | loge("setVoNrEnabled fails with no phone object for subId: " + subId); |
| 8726 | return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE; |
| 8727 | } |
| 8728 | |
| 8729 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8730 | try { |
| 8731 | int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId, |
| 8732 | workSource); |
| 8733 | if (DBG) log("setVoNrEnabled result: " + result); |
Gary Jian | 8dd305f | 2021-10-14 16:31:35 +0800 | [diff] [blame] | 8734 | |
| 8735 | if (result == TelephonyManager.ENABLE_VONR_SUCCESS) { |
| 8736 | if (DBG) { |
| 8737 | log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled); |
| 8738 | } |
| 8739 | SubscriptionManager.setSubscriptionProperty( |
| 8740 | subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED, |
| 8741 | (enabled ? "1" : "0")); |
| 8742 | } |
| 8743 | |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 8744 | return result; |
| 8745 | } finally { |
| 8746 | Binder.restoreCallingIdentity(identity); |
| 8747 | } |
| 8748 | } |
| 8749 | |
| 8750 | /** |
| 8751 | * Is voice over NR enabled |
| 8752 | * @return true if VoNR is enabled else false |
| 8753 | */ |
| 8754 | @Override |
| 8755 | public boolean isVoNrEnabled(int subId) { |
| 8756 | enforceReadPrivilegedPermission("isVoNrEnabled"); |
| 8757 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8758 | final long identity = Binder.clearCallingIdentity(); |
| 8759 | try { |
| 8760 | boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED, |
| 8761 | null, subId, workSource); |
| 8762 | if (DBG) log("isVoNrEnabled: " + isEnabled); |
| 8763 | return isEnabled; |
| 8764 | } finally { |
| 8765 | Binder.restoreCallingIdentity(identity); |
| 8766 | } |
| 8767 | } |
| 8768 | |
| 8769 | /** |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 8770 | * Action set from carrier signalling broadcast receivers to start/stop reporting the default |
| 8771 | * network status based on which carrier apps could apply actions accordingly, |
| 8772 | * enable/disable default url handler for example. |
| 8773 | * |
| 8774 | * @param subId the subscription ID that this action applies to. |
| 8775 | * @param report control start/stop reporting the default network status. |
| 8776 | * {@hide} |
| 8777 | */ |
| 8778 | @Override |
| 8779 | public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) { |
| 8780 | enforceModifyPermission(); |
| 8781 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8782 | |
| 8783 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 8784 | if (phone == null) { |
| 8785 | loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId); |
| 8786 | return; |
| 8787 | } |
| 8788 | try { |
| 8789 | phone.carrierActionReportDefaultNetworkStatus(report); |
| 8790 | } catch (Exception e) { |
| 8791 | Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8792 | } finally { |
| 8793 | Binder.restoreCallingIdentity(identity); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 8794 | } |
| 8795 | } |
| 8796 | |
| 8797 | /** |
fionaxu | d962228 | 2017-07-17 17:51:30 -0700 | [diff] [blame] | 8798 | * Action set from carrier signalling broadcast receivers to reset all carrier actions |
| 8799 | * @param subId the subscription ID that this action applies to. |
| 8800 | * {@hide} |
| 8801 | */ |
| 8802 | @Override |
| 8803 | public void carrierActionResetAll(int subId) { |
| 8804 | enforceModifyPermission(); |
| 8805 | final Phone phone = getPhone(subId); |
| 8806 | if (phone == null) { |
| 8807 | loge("carrierAction: ResetAll fails with invalid sibId: " + subId); |
| 8808 | return; |
| 8809 | } |
| 8810 | try { |
| 8811 | phone.carrierActionResetAll(); |
| 8812 | } catch (Exception e) { |
| 8813 | Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e); |
| 8814 | } |
| 8815 | } |
| 8816 | |
| 8817 | /** |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 8818 | * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a |
| 8819 | * bug report is being generated. |
| 8820 | */ |
| 8821 | @Override |
Ta-wei Yen | 99282e0 | 2016-06-21 18:19:35 -0700 | [diff] [blame] | 8822 | protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8823 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 8824 | != PackageManager.PERMISSION_GRANTED) { |
dcashman | 22b950d | 2016-06-27 11:39:02 -0700 | [diff] [blame] | 8825 | writer.println("Permission Denial: can't dump Phone from pid=" |
| 8826 | + Binder.getCallingPid() |
| 8827 | + ", uid=" + Binder.getCallingUid() |
| 8828 | + "without permission " |
| 8829 | + android.Manifest.permission.DUMP); |
| 8830 | return; |
| 8831 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8832 | DumpsysHandler.dump(mApp, fd, writer, args); |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 8833 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 8834 | |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 8835 | @Override |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 8836 | public int handleShellCommand(@NonNull ParcelFileDescriptor in, |
| 8837 | @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err, |
| 8838 | @NonNull String[] args) { |
| 8839 | return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec( |
| 8840 | this, in.getFileDescriptor(), out.getFileDescriptor(), |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 8841 | err.getFileDescriptor(), args); |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 8842 | } |
| 8843 | |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 8844 | /** |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8845 | * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason} |
Greg Kaiser | 17f4175 | 2020-05-05 16:47:47 +0000 | [diff] [blame] | 8846 | * @param subId Subscription index |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 8847 | * @param reason The reason the data enable change is taking place. |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8848 | * @param enabled True if enabling the data, otherwise disabling. |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 8849 | * @param callingPackage The package that changed the data enabled state. |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8850 | * @hide |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 8851 | */ |
| 8852 | @Override |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 8853 | public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 8854 | boolean enabled, String callingPackage) { |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8855 | if (reason == TelephonyManager.DATA_ENABLED_REASON_USER |
| 8856 | || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 8857 | try { |
| 8858 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 8859 | mApp, subId, "setDataEnabledForReason"); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8860 | } catch (SecurityException se) { |
| 8861 | enforceModifyPermission(); |
| 8862 | } |
| 8863 | } else { |
| 8864 | enforceModifyPermission(); |
| 8865 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8866 | |
| 8867 | final long identity = Binder.clearCallingIdentity(); |
| 8868 | try { |
| 8869 | Phone phone = getPhone(subId); |
| 8870 | if (phone != null) { |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8871 | if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 8872 | phone.carrierActionSetMeteredApnsEnabled(enabled); |
| 8873 | } else { |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 8874 | phone.getDataSettingsManager().setDataEnabled( |
| 8875 | reason, enabled, callingPackage); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8876 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8877 | } |
| 8878 | } finally { |
| 8879 | Binder.restoreCallingIdentity(identity); |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 8880 | } |
| 8881 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8882 | |
| 8883 | /** |
| 8884 | * Get Client request stats |
| 8885 | * @return List of Client Request Stats |
| 8886 | * @hide |
| 8887 | */ |
| 8888 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8889 | public List<ClientRequestStats> getClientRequestStats(String callingPackage, |
| 8890 | String callingFeatureId, int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8891 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8892 | mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) { |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8893 | return null; |
| 8894 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8895 | Phone phone = getPhone(subId); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8896 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8897 | final long identity = Binder.clearCallingIdentity(); |
| 8898 | try { |
| 8899 | if (phone != null) { |
| 8900 | return phone.getClientRequestStats(); |
| 8901 | } |
| 8902 | |
| 8903 | return null; |
| 8904 | } finally { |
| 8905 | Binder.restoreCallingIdentity(identity); |
| 8906 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8907 | } |
| 8908 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 8909 | private WorkSource getWorkSource(int uid) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8910 | String packageName = mApp.getPackageManager().getNameForUid(uid); |
Hunter Knepshield | d03383b | 2022-03-29 22:47:54 +0000 | [diff] [blame] | 8911 | if (uid == Process.ROOT_UID && packageName == null) { |
| 8912 | // Downstream WorkSource attribution inside the RIL requires both a UID and package name |
| 8913 | // to be set for wakelock tracking, otherwise RIL requests fail with a runtime |
| 8914 | // exception. ROOT_UID seems not to have a valid package name returned by |
| 8915 | // PackageManager, so just fake it here to avoid issues when running telephony shell |
| 8916 | // commands that plumb through the RIL as root, like so: |
| 8917 | // $ adb root |
| 8918 | // $ adb shell cmd phone ... |
| 8919 | packageName = "root"; |
| 8920 | } |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 8921 | return new WorkSource(uid, packageName); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8922 | } |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8923 | |
| 8924 | /** |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 8925 | * Set SIM card power state. |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8926 | * |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8927 | * @param slotIndex SIM slot id. |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 8928 | * @param state State of SIM (power down, power up, pass through) |
| 8929 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 8930 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 8931 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8932 | * |
| 8933 | **/ |
| 8934 | @Override |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 8935 | public void setSimPowerStateForSlot(int slotIndex, int state) { |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8936 | enforceModifyPermission(); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8937 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8938 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8939 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8940 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8941 | final long identity = Binder.clearCallingIdentity(); |
| 8942 | try { |
| 8943 | if (phone != null) { |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 8944 | phone.setSimPowerState(state, null, workSource); |
| 8945 | } |
| 8946 | } finally { |
| 8947 | Binder.restoreCallingIdentity(identity); |
| 8948 | } |
| 8949 | } |
| 8950 | |
| 8951 | /** |
| 8952 | * Set SIM card power state. |
| 8953 | * |
| 8954 | * @param slotIndex SIM slot id. |
| 8955 | * @param state State of SIM (power down, power up, pass through) |
| 8956 | * @param callback callback to trigger after success or failure |
| 8957 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 8958 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 8959 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
| 8960 | * |
| 8961 | **/ |
| 8962 | @Override |
| 8963 | public void setSimPowerStateForSlotWithCallback(int slotIndex, int state, |
| 8964 | IIntegerConsumer callback) { |
| 8965 | enforceModifyPermission(); |
| 8966 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8967 | |
| 8968 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8969 | |
| 8970 | final long identity = Binder.clearCallingIdentity(); |
| 8971 | try { |
| 8972 | if (phone != null) { |
| 8973 | Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback); |
| 8974 | sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8975 | } |
| 8976 | } finally { |
| 8977 | Binder.restoreCallingIdentity(identity); |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8978 | } |
| 8979 | } |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8980 | |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 8981 | private boolean isUssdApiAllowed(int subId) { |
| 8982 | CarrierConfigManager configManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8983 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 8984 | if (configManager == null) { |
| 8985 | return false; |
| 8986 | } |
| 8987 | PersistableBundle pb = configManager.getConfigForSubId(subId); |
| 8988 | if (pb == null) { |
| 8989 | return false; |
| 8990 | } |
| 8991 | return pb.getBoolean( |
| 8992 | CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL); |
| 8993 | } |
| 8994 | |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8995 | /** |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 8996 | * Check if phone is in emergency callback mode. |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8997 | * @return true if phone is in emergency callback mode |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 8998 | * @param subId sub Id, but the check is in fact irrlevant to sub Id. |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8999 | */ |
goneil | 9c5f487 | 2017-12-05 14:07:56 -0800 | [diff] [blame] | 9000 | @Override |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 9001 | public boolean getEmergencyCallbackMode(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 9002 | enforceReadPrivilegedPermission("getEmergencyCallbackMode"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9003 | final long identity = Binder.clearCallingIdentity(); |
| 9004 | try { |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 9005 | return getPhoneFromSubIdOrDefault(subId).isInEcm(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9006 | } finally { |
| 9007 | Binder.restoreCallingIdentity(identity); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 9008 | } |
| 9009 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 9010 | |
| 9011 | /** |
| 9012 | * Get the current signal strength information for the given subscription. |
| 9013 | * Because this information is not updated when the device is in a low power state |
| 9014 | * it should not be relied-upon to be current. |
| 9015 | * @param subId Subscription index |
| 9016 | * @return the most recent cached signal strength info from the modem |
| 9017 | */ |
| 9018 | @Override |
| 9019 | public SignalStrength getSignalStrength(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9020 | final long identity = Binder.clearCallingIdentity(); |
| 9021 | try { |
| 9022 | Phone p = getPhone(subId); |
| 9023 | if (p == null) { |
| 9024 | return null; |
| 9025 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 9026 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9027 | return p.getSignalStrength(); |
| 9028 | } finally { |
| 9029 | Binder.restoreCallingIdentity(identity); |
| 9030 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 9031 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9032 | |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9033 | /** |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 9034 | * Get the current modem radio state for the given slot. |
| 9035 | * @param slotIndex slot index. |
| 9036 | * @param callingPackage the name of the package making the call. |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9037 | * @param callingFeatureId The feature in the package. |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 9038 | * @return the current radio power state from the modem |
| 9039 | */ |
| 9040 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9041 | public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 9042 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 9043 | if (phone != null) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9044 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(), |
| 9045 | callingPackage, callingFeatureId, "getRadioPowerState")) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 9046 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 9047 | } |
| 9048 | |
| 9049 | final long identity = Binder.clearCallingIdentity(); |
| 9050 | try { |
| 9051 | return phone.getRadioPowerState(); |
| 9052 | } finally { |
| 9053 | Binder.restoreCallingIdentity(identity); |
| 9054 | } |
| 9055 | } |
| 9056 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 9057 | } |
| 9058 | |
| 9059 | /** |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9060 | * Checks if data roaming is enabled on the subscription with id {@code subId}. |
| 9061 | * |
| 9062 | * <p>Requires one of the following permissions: |
| 9063 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}, |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 9064 | * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE}, |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9065 | * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier |
| 9066 | * privileges. |
| 9067 | * |
| 9068 | * @param subId subscription id |
| 9069 | * @return {@code true} if data roaming is enabled on this subscription, otherwise return |
| 9070 | * {@code false}. |
| 9071 | */ |
| 9072 | @Override |
| 9073 | public boolean isDataRoamingEnabled(int subId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 9074 | String functionName = "isDataRoamingEnabled"; |
Shuo Qian | 093013d | 2020-08-13 15:42:55 -0700 | [diff] [blame] | 9075 | try { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 9076 | try { |
| 9077 | mApp.enforceCallingOrSelfPermission( |
| 9078 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 9079 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 9080 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 9081 | mApp.enforceCallingOrSelfPermission( |
| 9082 | permission.READ_BASIC_PHONE_STATE, functionName); |
| 9083 | } |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 9084 | } catch (SecurityException e) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9085 | TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 9086 | mApp, subId, functionName); |
Shuo Qian | 093013d | 2020-08-13 15:42:55 -0700 | [diff] [blame] | 9087 | } |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 9088 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9089 | boolean isEnabled = false; |
| 9090 | final long identity = Binder.clearCallingIdentity(); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9091 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9092 | Phone phone = getPhone(subId); |
| 9093 | isEnabled = phone != null ? phone.getDataRoamingEnabled() : false; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9094 | } finally { |
| 9095 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9096 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9097 | return isEnabled; |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9098 | } |
| 9099 | |
| 9100 | |
| 9101 | /** |
| 9102 | * Enables/Disables the data roaming on the subscription with id {@code subId}. |
| 9103 | * |
| 9104 | * <p> Requires permission: |
| 9105 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier |
| 9106 | * privileges. |
| 9107 | * |
| 9108 | * @param subId subscription id |
| 9109 | * @param isEnabled {@code true} means enable, {@code false} means disable. |
| 9110 | */ |
| 9111 | @Override |
| 9112 | public void setDataRoamingEnabled(int subId, boolean isEnabled) { |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 9113 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9114 | mApp, subId, "setDataRoamingEnabled"); |
| 9115 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9116 | final long identity = Binder.clearCallingIdentity(); |
| 9117 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9118 | Phone phone = getPhone(subId); |
| 9119 | if (phone != null) { |
| 9120 | phone.setDataRoamingEnabled(isEnabled); |
| 9121 | } |
| 9122 | } finally { |
| 9123 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9124 | } |
| 9125 | } |
| 9126 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9127 | @Override |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 9128 | public boolean isManualNetworkSelectionAllowed(int subId) { |
tom hsu | c91afc7 | 2020-01-06 23:46:07 +0800 | [diff] [blame] | 9129 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9130 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 9131 | mApp, subId, "isManualNetworkSelectionAllowed"); |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 9132 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 9133 | boolean isAllowed = true; |
| 9134 | final long identity = Binder.clearCallingIdentity(); |
| 9135 | try { |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 9136 | Phone phone = getPhone(subId); |
| 9137 | if (phone != null) { |
| 9138 | isAllowed = phone.isCspPlmnEnabled(); |
| 9139 | } |
| 9140 | } finally { |
| 9141 | Binder.restoreCallingIdentity(identity); |
| 9142 | } |
| 9143 | return isAllowed; |
| 9144 | } |
| 9145 | |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9146 | private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) { |
| 9147 | UiccProfile profile = port.getUiccProfile(); |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 9148 | if (profile == null) { |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9149 | return false; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9150 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 9151 | Phone phone = PhoneFactory.getPhone(profile.getPhoneId()); |
| 9152 | if (phone == null) { |
| 9153 | return false; |
| 9154 | } |
| 9155 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 9156 | return cpt != null && cpt.getCarrierPrivilegeStatusForPackage(callingPackage) |
| 9157 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9158 | } |
| 9159 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 9160 | @Override |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 9161 | public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) { |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9162 | // Verify that the callingPackage belongs to the calling UID |
Jordan Liu | 4cda455 | 2020-03-23 11:55:07 -0700 | [diff] [blame] | 9163 | mApp.getSystemService(AppOpsManager.class) |
| 9164 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 9165 | |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9166 | boolean hasReadPermission = false; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9167 | boolean isIccIdAccessRestricted = false; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 9168 | try { |
| 9169 | enforceReadPrivilegedPermission("getUiccCardsInfo"); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9170 | hasReadPermission = true; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 9171 | } catch (SecurityException e) { |
| 9172 | // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller |
| 9173 | // has carrier privileges on an active UICC |
Rambo Wang | e7209ce | 2022-02-23 13:41:02 -0800 | [diff] [blame] | 9174 | if (checkCarrierPrivilegesForPackageAnyPhoneWithPermission(callingPackage) |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 9175 | != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9176 | throw new SecurityException("Caller does not have permission."); |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 9177 | } |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 9178 | } |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9179 | // checking compatibility, if calling app's target SDK is T and beyond. |
| 9180 | if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO, |
| 9181 | Binder.getCallingUid())) { |
| 9182 | isIccIdAccessRestricted = true; |
| 9183 | } |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 9184 | final long identity = Binder.clearCallingIdentity(); |
| 9185 | try { |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 9186 | UiccController uiccController = UiccController.getInstance(); |
| 9187 | ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos(); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9188 | if (hasReadPermission) { |
| 9189 | return cardInfos; |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 9190 | } |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9191 | |
| 9192 | // Remove private info if the caller doesn't have access |
| 9193 | ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>(); |
| 9194 | for (UiccCardInfo cardInfo : cardInfos) { |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9195 | //setting the value after compatibility check |
| 9196 | cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9197 | // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo |
| 9198 | // is available |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9199 | UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex()); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9200 | if (card == null) { |
| 9201 | // assume no access if the card is unavailable |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9202 | filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo)); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9203 | continue; |
| 9204 | } |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9205 | Collection<UiccPortInfo> portInfos = cardInfo.getPorts(); |
| 9206 | if (portInfos.isEmpty()) { |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9207 | filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo)); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9208 | continue; |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9209 | } |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9210 | List<UiccPortInfo> uiccPortInfos = new ArrayList<>(); |
| 9211 | for (UiccPortInfo portInfo : portInfos) { |
| 9212 | UiccPort port = uiccController.getUiccPortForSlot( |
| 9213 | cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex()); |
| 9214 | if (port == null) { |
| 9215 | // assume no access if port is null |
| 9216 | uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo)); |
| 9217 | continue; |
| 9218 | } |
| 9219 | if (haveCarrierPrivilegeAccess(port, callingPackage)) { |
| 9220 | uiccPortInfos.add(portInfo); |
| 9221 | } else { |
| 9222 | uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo)); |
| 9223 | } |
| 9224 | } |
| 9225 | filteredInfos.add(new UiccCardInfo( |
| 9226 | cardInfo.isEuicc(), |
| 9227 | cardInfo.getCardId(), |
| 9228 | null, |
| 9229 | cardInfo.getPhysicalSlotIndex(), |
| 9230 | cardInfo.isRemovable(), |
| 9231 | cardInfo.isMultipleEnabledProfilesSupported(), |
| 9232 | uiccPortInfos)); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9233 | } |
| 9234 | return filteredInfos; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 9235 | } finally { |
| 9236 | Binder.restoreCallingIdentity(identity); |
| 9237 | } |
| 9238 | } |
| 9239 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9240 | /** |
| 9241 | * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are |
| 9242 | * generally private and require carrier privileges to view. |
| 9243 | * |
| 9244 | * @hide |
| 9245 | */ |
| 9246 | @NonNull |
| 9247 | public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) { |
| 9248 | List<UiccPortInfo> portinfo = new ArrayList<>(); |
| 9249 | for (UiccPortInfo portinfos : cardInfo.getPorts()) { |
| 9250 | portinfo.add(getUiccPortInfoUnPrivileged(portinfos)); |
| 9251 | } |
| 9252 | return new UiccCardInfo( |
| 9253 | cardInfo.isEuicc(), |
| 9254 | cardInfo.getCardId(), |
| 9255 | null, |
| 9256 | cardInfo.getPhysicalSlotIndex(), |
| 9257 | cardInfo.isRemovable(), |
| 9258 | cardInfo.isMultipleEnabledProfilesSupported(), |
| 9259 | portinfo |
| 9260 | ); |
| 9261 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9262 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9263 | /** |
| 9264 | * @hide |
| 9265 | * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}. |
| 9266 | * These values are generally private and require carrier privileges to view. |
| 9267 | */ |
| 9268 | @NonNull |
| 9269 | public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) { |
| 9270 | return new UiccPortInfo( |
| 9271 | UiccPortInfo.ICCID_REDACTED, |
| 9272 | portInfo.getPortIndex(), |
| 9273 | portInfo.getLogicalSlotIndex(), |
| 9274 | portInfo.isActive() |
| 9275 | ); |
| 9276 | } |
| 9277 | @Override |
| 9278 | public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) { |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9279 | // Verify that the callingPackage belongs to the calling UID |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9280 | mApp.getSystemService(AppOpsManager.class) |
| 9281 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 9282 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9283 | boolean isLogicalSlotAccessRestricted = false; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9284 | |
Aman Gupta | f3c90b3 | 2022-03-17 04:54:16 +0000 | [diff] [blame] | 9285 | // This will make sure caller has the READ_PRIVILEGED_PHONE_STATE. Do not remove this as |
| 9286 | // we are reading iccId which is PII data. |
| 9287 | enforceReadPrivilegedPermission("getUiccSlotsInfo"); |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9288 | |
| 9289 | // checking compatibility, if calling app's target SDK is T and beyond. |
| 9290 | if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO, |
| 9291 | Binder.getCallingUid())) { |
| 9292 | isLogicalSlotAccessRestricted = true; |
| 9293 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9294 | final long identity = Binder.clearCallingIdentity(); |
| 9295 | try { |
| 9296 | UiccSlot[] slots = UiccController.getInstance().getUiccSlots(); |
Muralidhar Reddy | d196bbf | 2022-01-17 17:56:30 +0000 | [diff] [blame] | 9297 | if (slots == null || slots.length == 0) { |
| 9298 | Rlog.i(LOG_TAG, "slots is null or empty."); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9299 | return null; |
| 9300 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9301 | UiccSlotInfo[] infos = new UiccSlotInfo[slots.length]; |
| 9302 | for (int i = 0; i < slots.length; i++) { |
| 9303 | UiccSlot slot = slots[i]; |
| 9304 | if (slot == null) { |
| 9305 | continue; |
| 9306 | } |
| 9307 | |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 9308 | String cardId; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9309 | UiccCard card = slot.getUiccCard(); |
| 9310 | if (card != null) { |
| 9311 | cardId = card.getCardId(); |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 9312 | } else { |
Jordan Liu | 01bd00d | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 9313 | cardId = slot.getEid(); |
| 9314 | if (TextUtils.isEmpty(cardId)) { |
Aman Gupta | f3c90b3 | 2022-03-17 04:54:16 +0000 | [diff] [blame] | 9315 | // If cardId is null, use iccId of default port as cardId. |
| 9316 | cardId = slot.getIccId(TelephonyManager.DEFAULT_PORT_INDEX); |
Jordan Liu | 01bd00d | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 9317 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9318 | } |
| 9319 | |
Jordan Liu | 857451f | 2019-05-09 16:35:35 -0700 | [diff] [blame] | 9320 | if (cardId != null) { |
| 9321 | // if cardId is an ICCID, strip off trailing Fs before exposing to user |
| 9322 | // if cardId is an EID, it's all digits so this is fine |
| 9323 | cardId = IccUtils.stripTrailingFs(cardId); |
| 9324 | } |
| 9325 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9326 | int cardState = 0; |
| 9327 | switch (slot.getCardState()) { |
| 9328 | case CARDSTATE_ABSENT: |
| 9329 | cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT; |
| 9330 | break; |
| 9331 | case CARDSTATE_PRESENT: |
| 9332 | cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT; |
| 9333 | break; |
| 9334 | case CARDSTATE_ERROR: |
| 9335 | cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR; |
| 9336 | break; |
| 9337 | case CARDSTATE_RESTRICTED: |
| 9338 | cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED; |
| 9339 | break; |
| 9340 | default: |
| 9341 | break; |
| 9342 | |
| 9343 | } |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9344 | List<UiccPortInfo> portInfos = new ArrayList<>(); |
| 9345 | int[] portIndexes = slot.getPortList(); |
| 9346 | for (int portIdx : portIndexes) { |
| 9347 | String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx, |
Aman Gupta | f3c90b3 | 2022-03-17 04:54:16 +0000 | [diff] [blame] | 9348 | callingPackage, /* hasReadPermission= */ true)); |
Muralidhar Reddy | fbcff0c | 2022-01-19 13:07:57 +0000 | [diff] [blame] | 9349 | portInfos.add(new UiccPortInfo(iccId, portIdx, |
| 9350 | slot.getPhoneIdFromPortIndex(portIdx), slot.isPortActive(portIdx))); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9351 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9352 | infos[i] = new UiccSlotInfo( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9353 | slot.isEuicc(), |
| 9354 | cardId, |
| 9355 | cardState, |
Jordan Liu | a261958 | 2019-02-14 12:56:40 -0800 | [diff] [blame] | 9356 | slot.isExtendedApduSupported(), |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9357 | slot.isRemovable(), portInfos); |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9358 | //setting the value after compatibility check |
| 9359 | infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9360 | } |
| 9361 | return infos; |
| 9362 | } finally { |
| 9363 | Binder.restoreCallingIdentity(identity); |
Holly Jiuyu Sun | 1d957c5 | 2018-04-04 13:52:42 -0700 | [diff] [blame] | 9364 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9365 | } |
| 9366 | |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9367 | /* Returns null if doesn't have read permission or carrier privilege access. */ |
| 9368 | private String getIccId(UiccSlot slot, int portIndex, String callingPackage, |
| 9369 | boolean hasReadPermission) { |
| 9370 | String iccId = slot.getIccId(portIndex); |
| 9371 | if (hasReadPermission) { // if has read permission |
| 9372 | return iccId; |
| 9373 | } else { |
| 9374 | if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) { |
| 9375 | UiccPort port = slot.getUiccCard().getUiccPort(portIndex); |
| 9376 | // if no read permission, checking carrier privilege access |
| 9377 | if (haveCarrierPrivilegeAccess(port, callingPackage)) { |
| 9378 | return iccId; |
| 9379 | } |
| 9380 | } |
| 9381 | } |
| 9382 | // No read permission or carrier privilege access. |
| 9383 | return UiccPortInfo.ICCID_REDACTED; |
| 9384 | } |
| 9385 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9386 | @Override |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9387 | @Deprecated |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9388 | public boolean switchSlots(int[] physicalSlots) { |
| 9389 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9390 | |
| 9391 | final long identity = Binder.clearCallingIdentity(); |
| 9392 | try { |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9393 | List<UiccSlotMapping> slotMappings = new ArrayList<>(); |
| 9394 | for (int i = 0; i < physicalSlots.length; i++) { |
| 9395 | // Deprecated API, hence MEP is not supported. Adding default portIndex 0. |
| 9396 | slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX, |
| 9397 | physicalSlots[i], i)); |
| 9398 | } |
| 9399 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9400 | } finally { |
| 9401 | Binder.restoreCallingIdentity(identity); |
| 9402 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9403 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 9404 | |
| 9405 | @Override |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9406 | @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 9407 | public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) { |
| 9408 | enforceModifyPermission(); |
| 9409 | |
| 9410 | final long identity = Binder.clearCallingIdentity(); |
| 9411 | try { |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9412 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping); |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9413 | } finally { |
| 9414 | Binder.restoreCallingIdentity(identity); |
| 9415 | } |
| 9416 | } |
| 9417 | |
| 9418 | @Override |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 9419 | public int getCardIdForDefaultEuicc(int subId, String callingPackage) { |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 9420 | final long identity = Binder.clearCallingIdentity(); |
| 9421 | try { |
| 9422 | return UiccController.getInstance().getCardIdForDefaultEuicc(); |
| 9423 | } finally { |
| 9424 | Binder.restoreCallingIdentity(identity); |
| 9425 | } |
| 9426 | } |
| 9427 | |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9428 | /** |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 9429 | * A test API to reload the UICC profile. |
| 9430 | * |
| 9431 | * <p>Requires that the calling app has permission |
| 9432 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 9433 | * @hide |
| 9434 | */ |
| 9435 | @Override |
| 9436 | public void refreshUiccProfile(int subId) { |
| 9437 | enforceModifyPermission(); |
| 9438 | |
| 9439 | final long identity = Binder.clearCallingIdentity(); |
| 9440 | try { |
| 9441 | Phone phone = getPhone(subId); |
| 9442 | if (phone == null) { |
| 9443 | return; |
| 9444 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9445 | UiccPort uiccPort = phone.getUiccPort(); |
| 9446 | if (uiccPort == null) { |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 9447 | return; |
| 9448 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9449 | UiccProfile uiccProfile = uiccPort.getUiccProfile(); |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 9450 | if (uiccProfile == null) { |
| 9451 | return; |
| 9452 | } |
| 9453 | uiccProfile.refresh(); |
| 9454 | } finally { |
| 9455 | Binder.restoreCallingIdentity(identity); |
| 9456 | } |
| 9457 | } |
| 9458 | |
| 9459 | /** |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9460 | * Returns false if the mobile data is disabled by default, otherwise return true. |
| 9461 | */ |
| 9462 | private boolean getDefaultDataEnabled() { |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 9463 | return TelephonyProperties.mobile_data().orElse(true); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9464 | } |
| 9465 | |
| 9466 | /** |
| 9467 | * Returns true if the data roaming is enabled by default, i.e the system property |
| 9468 | * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of |
| 9469 | * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true. |
| 9470 | */ |
| 9471 | private boolean getDefaultDataRoamingEnabled(int subId) { |
| 9472 | final CarrierConfigManager configMgr = (CarrierConfigManager) |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9473 | mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Shuo Qian | 1d84a0e | 2020-07-15 12:36:44 -0700 | [diff] [blame] | 9474 | boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9475 | isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean( |
| 9476 | CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL); |
| 9477 | return isDataRoamingEnabled; |
| 9478 | } |
| 9479 | |
| 9480 | /** |
| 9481 | * Returns the default network type for the given {@code subId}, if the default network type is |
| 9482 | * not set, return {@link Phone#PREFERRED_NT_MODE}. |
| 9483 | */ |
| 9484 | private int getDefaultNetworkType(int subId) { |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 9485 | List<Integer> list = TelephonyProperties.default_network(); |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 9486 | int phoneId = SubscriptionManager.getPhoneId(subId); |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 9487 | if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) { |
| 9488 | return list.get(phoneId); |
| 9489 | } |
| 9490 | return Phone.PREFERRED_NT_MODE; |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9491 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9492 | |
| 9493 | @Override |
| 9494 | public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 9495 | gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) { |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9496 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9497 | |
| 9498 | final long identity = Binder.clearCallingIdentity(); |
| 9499 | try { |
| 9500 | final Phone phone = getPhone(subId); |
| 9501 | if (phone == null) { |
| 9502 | loge("setCarrierTestOverride fails with invalid subId: " + subId); |
| 9503 | return; |
| 9504 | } |
Rambo Wang | 9c9ffdd | 2022-01-13 21:51:44 -0800 | [diff] [blame] | 9505 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 9506 | if (cpt != null) { |
| 9507 | cpt.setTestOverrideCarrierPrivilegeRules(carrierPrivilegeRules); |
| 9508 | } |
| 9509 | // 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] | 9510 | phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn, |
| 9511 | carrierPrivilegeRules, apn); |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 9512 | if (carrierPrivilegeRules == null) { |
| 9513 | mCarrierPrivilegeTestOverrideSubIds.remove(subId); |
| 9514 | } else { |
| 9515 | mCarrierPrivilegeTestOverrideSubIds.add(subId); |
| 9516 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9517 | } finally { |
| 9518 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9519 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9520 | } |
| 9521 | |
| 9522 | @Override |
Benedict Wong | 6647762 | 2023-02-03 23:30:57 +0000 | [diff] [blame] | 9523 | public void setCarrierServicePackageOverride( |
| 9524 | int subId, String carrierServicePackage, String callingPackage) { |
| 9525 | TelephonyPermissions.enforceShellOnly( |
| 9526 | Binder.getCallingUid(), "setCarrierServicePackageOverride"); |
| 9527 | |
| 9528 | // Verify that the callingPackage belongs to the calling UID |
| 9529 | mApp.getSystemService(AppOpsManager.class) |
| 9530 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 9531 | |
| 9532 | final long identity = Binder.clearCallingIdentity(); |
| 9533 | try { |
| 9534 | final Phone phone = getPhone(subId); |
| 9535 | if (phone == null || phone.getSubId() != subId) { |
| 9536 | loge("setCarrierServicePackageOverride fails with invalid subId: " + subId); |
| 9537 | throw new IllegalArgumentException("No phone for subid"); |
| 9538 | } |
| 9539 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 9540 | if (cpt == null) { |
| 9541 | loge("setCarrierServicePackageOverride failed with no CPT for phone"); |
| 9542 | throw new IllegalStateException("No CPT for phone"); |
| 9543 | } |
| 9544 | cpt.setTestOverrideCarrierServicePackage(carrierServicePackage); |
| 9545 | } finally { |
| 9546 | Binder.restoreCallingIdentity(identity); |
| 9547 | } |
| 9548 | } |
| 9549 | |
| 9550 | @Override |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9551 | public int getCarrierIdListVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 9552 | enforceReadPrivilegedPermission("getCarrierIdListVersion"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9553 | |
| 9554 | final long identity = Binder.clearCallingIdentity(); |
| 9555 | try { |
| 9556 | final Phone phone = getPhone(subId); |
| 9557 | if (phone == null) { |
| 9558 | loge("getCarrierIdListVersion fails with invalid subId: " + subId); |
| 9559 | return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION; |
| 9560 | } |
| 9561 | return phone.getCarrierIdListVersion(); |
| 9562 | } finally { |
| 9563 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9564 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9565 | } |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 9566 | |
| 9567 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9568 | public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage, |
| 9569 | String callingFeatureId) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 9570 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9571 | mApp, subId, callingPackage, callingFeatureId, |
| 9572 | "getNumberOfModemsWithSimultaneousDataConnections")) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 9573 | return -1; |
| 9574 | } |
| 9575 | |
| 9576 | final long identity = Binder.clearCallingIdentity(); |
| 9577 | try { |
| 9578 | return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections(); |
| 9579 | } finally { |
| 9580 | Binder.restoreCallingIdentity(identity); |
| 9581 | } |
| 9582 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9583 | |
| 9584 | @Override |
| 9585 | public int getCdmaRoamingMode(int subId) { |
zoey chen | 7e6d4e5 | 2019-12-17 18:18:59 +0800 | [diff] [blame] | 9586 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9587 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 9588 | mApp, subId, "getCdmaRoamingMode"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9589 | |
| 9590 | final long identity = Binder.clearCallingIdentity(); |
| 9591 | try { |
| 9592 | return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId); |
| 9593 | } finally { |
| 9594 | Binder.restoreCallingIdentity(identity); |
| 9595 | } |
| 9596 | } |
| 9597 | |
| 9598 | @Override |
| 9599 | public boolean setCdmaRoamingMode(int subId, int mode) { |
| 9600 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9601 | mApp, subId, "setCdmaRoamingMode"); |
| 9602 | |
| 9603 | final long identity = Binder.clearCallingIdentity(); |
| 9604 | try { |
| 9605 | return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId); |
| 9606 | } finally { |
| 9607 | Binder.restoreCallingIdentity(identity); |
| 9608 | } |
| 9609 | } |
| 9610 | |
| 9611 | @Override |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 9612 | public int getCdmaSubscriptionMode(int subId) { |
| 9613 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9614 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 9615 | mApp, subId, "getCdmaSubscriptionMode"); |
| 9616 | |
| 9617 | final long identity = Binder.clearCallingIdentity(); |
| 9618 | try { |
| 9619 | return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId); |
| 9620 | } finally { |
| 9621 | Binder.restoreCallingIdentity(identity); |
| 9622 | } |
| 9623 | } |
| 9624 | |
| 9625 | @Override |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9626 | public boolean setCdmaSubscriptionMode(int subId, int mode) { |
| 9627 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9628 | mApp, subId, "setCdmaSubscriptionMode"); |
| 9629 | |
| 9630 | final long identity = Binder.clearCallingIdentity(); |
| 9631 | try { |
| 9632 | return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId); |
| 9633 | } finally { |
| 9634 | Binder.restoreCallingIdentity(identity); |
| 9635 | } |
| 9636 | } |
Makoto Onuki | da3bf79 | 2018-09-18 16:06:29 -0700 | [diff] [blame] | 9637 | |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 9638 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 9639 | public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9640 | String callingPackage, String callingFeatureId) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9641 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9642 | mApp, getDefaultSubscription(), callingPackage, callingFeatureId, |
| 9643 | "getEmergencyNumberList")) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9644 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 9645 | } |
| 9646 | final long identity = Binder.clearCallingIdentity(); |
| 9647 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 9648 | Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>(); |
| 9649 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9650 | if (phone.getEmergencyNumberTracker() != null |
| 9651 | && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) { |
| 9652 | emergencyNumberListInternal.put( |
| 9653 | phone.getSubId(), |
| 9654 | phone.getEmergencyNumberTracker().getEmergencyNumberList()); |
| 9655 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9656 | } |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 9657 | return emergencyNumberListInternal; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9658 | } finally { |
| 9659 | Binder.restoreCallingIdentity(identity); |
| 9660 | } |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 9661 | } |
| 9662 | |
| 9663 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 9664 | public boolean isEmergencyNumber(String number, boolean exactMatch) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9665 | final Phone defaultPhone = getDefaultPhone(); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9666 | if (!exactMatch) { |
| 9667 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9668 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 9669 | mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)"); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9670 | } |
| 9671 | final long identity = Binder.clearCallingIdentity(); |
| 9672 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 9673 | for (Phone phone: PhoneFactory.getPhones()) { |
Chinmay Dhodapkar | d521bb1 | 2022-08-16 15:49:54 -0700 | [diff] [blame] | 9674 | //Note: we ignore passed in param exactMatch. We can remove it once |
| 9675 | // TelephonyManager#isPotentialEmergencyNumber is removed completely |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 9676 | if (phone.getEmergencyNumberTracker() != null |
Taesu Lee | e050c00 | 2020-10-13 17:19:35 +0900 | [diff] [blame] | 9677 | && phone.getEmergencyNumberTracker() |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 9678 | .isEmergencyNumber(number)) { |
Taesu Lee | e050c00 | 2020-10-13 17:19:35 +0900 | [diff] [blame] | 9679 | return true; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9680 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9681 | } |
| 9682 | return false; |
| 9683 | } finally { |
| 9684 | Binder.restoreCallingIdentity(identity); |
| 9685 | } |
| 9686 | } |
| 9687 | |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 9688 | /** |
Shuo Qian | ccbaf74 | 2021-02-22 18:32:21 -0800 | [diff] [blame] | 9689 | * Start emergency callback mode for GsmCdmaPhone for testing. |
| 9690 | */ |
| 9691 | @Override |
| 9692 | public void startEmergencyCallbackMode() { |
| 9693 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9694 | "startEmergencyCallbackMode"); |
| 9695 | enforceModifyPermission(); |
| 9696 | final long identity = Binder.clearCallingIdentity(); |
| 9697 | try { |
| 9698 | for (Phone phone : PhoneFactory.getPhones()) { |
| 9699 | Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType()); |
| 9700 | if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM) |
| 9701 | || (phone.getPhoneType() == PHONE_TYPE_CDMA))) { |
| 9702 | GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone; |
| 9703 | gsmCdmaPhone.obtainMessage( |
| 9704 | GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget(); |
| 9705 | Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered"); |
| 9706 | } |
| 9707 | } |
| 9708 | } finally { |
| 9709 | Binder.restoreCallingIdentity(identity); |
| 9710 | } |
| 9711 | } |
| 9712 | |
| 9713 | /** |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 9714 | * Update emergency number list for test mode. |
| 9715 | */ |
| 9716 | @Override |
| 9717 | public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) { |
| 9718 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9719 | "updateEmergencyNumberListTestMode"); |
| 9720 | |
| 9721 | final long identity = Binder.clearCallingIdentity(); |
| 9722 | try { |
| 9723 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9724 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9725 | if (tracker != null) { |
| 9726 | tracker.executeEmergencyNumberTestModeCommand(action, num); |
| 9727 | } |
| 9728 | } |
| 9729 | } finally { |
| 9730 | Binder.restoreCallingIdentity(identity); |
| 9731 | } |
| 9732 | } |
| 9733 | |
| 9734 | /** |
| 9735 | * Get the full emergency number list for test mode. |
| 9736 | */ |
| 9737 | @Override |
| 9738 | public List<String> getEmergencyNumberListTestMode() { |
| 9739 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9740 | "getEmergencyNumberListTestMode"); |
| 9741 | |
| 9742 | final long identity = Binder.clearCallingIdentity(); |
| 9743 | try { |
| 9744 | Set<String> emergencyNumbers = new HashSet<>(); |
| 9745 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9746 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9747 | if (tracker != null) { |
| 9748 | for (EmergencyNumber num : tracker.getEmergencyNumberList()) { |
| 9749 | emergencyNumbers.add(num.getNumber()); |
| 9750 | } |
| 9751 | } |
| 9752 | } |
| 9753 | return new ArrayList<>(emergencyNumbers); |
| 9754 | } finally { |
| 9755 | Binder.restoreCallingIdentity(identity); |
| 9756 | } |
| 9757 | } |
| 9758 | |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 9759 | @Override |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 9760 | public int getEmergencyNumberDbVersion(int subId) { |
| 9761 | enforceReadPrivilegedPermission("getEmergencyNumberDbVersion"); |
| 9762 | |
| 9763 | final long identity = Binder.clearCallingIdentity(); |
| 9764 | try { |
| 9765 | final Phone phone = getPhone(subId); |
| 9766 | if (phone == null) { |
| 9767 | loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId); |
| 9768 | return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION; |
| 9769 | } |
| 9770 | return phone.getEmergencyNumberDbVersion(); |
| 9771 | } finally { |
| 9772 | Binder.restoreCallingIdentity(identity); |
| 9773 | } |
| 9774 | } |
| 9775 | |
| 9776 | @Override |
| 9777 | public void notifyOtaEmergencyNumberDbInstalled() { |
| 9778 | enforceModifyPermission(); |
| 9779 | |
| 9780 | final long identity = Binder.clearCallingIdentity(); |
| 9781 | try { |
| 9782 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9783 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9784 | if (tracker != null) { |
| 9785 | tracker.updateOtaEmergencyNumberDatabase(); |
| 9786 | } |
| 9787 | } |
| 9788 | } finally { |
| 9789 | Binder.restoreCallingIdentity(identity); |
| 9790 | } |
| 9791 | } |
| 9792 | |
| 9793 | @Override |
Shuo Qian | c373f11 | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 9794 | public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) { |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 9795 | enforceActiveEmergencySessionPermission(); |
| 9796 | |
| 9797 | final long identity = Binder.clearCallingIdentity(); |
| 9798 | try { |
| 9799 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9800 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9801 | if (tracker != null) { |
Shuo Qian | c373f11 | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 9802 | tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor); |
| 9803 | } |
| 9804 | } |
| 9805 | } finally { |
| 9806 | Binder.restoreCallingIdentity(identity); |
| 9807 | } |
| 9808 | } |
| 9809 | |
| 9810 | @Override |
| 9811 | public void resetOtaEmergencyNumberDbFilePath() { |
| 9812 | enforceActiveEmergencySessionPermission(); |
| 9813 | |
| 9814 | final long identity = Binder.clearCallingIdentity(); |
| 9815 | try { |
| 9816 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9817 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9818 | if (tracker != null) { |
| 9819 | tracker.resetOtaEmergencyNumberDbFilePath(); |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 9820 | } |
| 9821 | } |
| 9822 | } finally { |
| 9823 | Binder.restoreCallingIdentity(identity); |
| 9824 | } |
| 9825 | } |
| 9826 | |
| 9827 | @Override |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 9828 | public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) { |
| 9829 | enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules"); |
| 9830 | Phone phone = getPhone(subId); |
| 9831 | if (phone == null) { |
| 9832 | return null; |
| 9833 | } |
| 9834 | final long identity = Binder.clearCallingIdentity(); |
| 9835 | try { |
| 9836 | UiccProfile profile = UiccController.getInstance() |
| 9837 | .getUiccProfileForPhone(phone.getPhoneId()); |
| 9838 | if (profile != null) { |
| 9839 | return profile.getCertsFromCarrierPrivilegeAccessRules(); |
| 9840 | } |
| 9841 | } finally { |
| 9842 | Binder.restoreCallingIdentity(identity); |
| 9843 | } |
| 9844 | return null; |
| 9845 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 9846 | |
| 9847 | /** |
| 9848 | * Enable or disable a modem stack. |
| 9849 | */ |
| 9850 | @Override |
| 9851 | public boolean enableModemForSlot(int slotIndex, boolean enable) { |
| 9852 | enforceModifyPermission(); |
| 9853 | |
| 9854 | final long identity = Binder.clearCallingIdentity(); |
| 9855 | try { |
| 9856 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 9857 | if (phone == null) { |
| 9858 | return false; |
| 9859 | } else { |
| 9860 | return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null); |
| 9861 | } |
| 9862 | } finally { |
| 9863 | Binder.restoreCallingIdentity(identity); |
| 9864 | } |
| 9865 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9866 | |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 9867 | /** |
| 9868 | * Whether a modem stack is enabled or not. |
| 9869 | */ |
| 9870 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9871 | public boolean isModemEnabledForSlot(int slotIndex, String callingPackage, |
| 9872 | String callingFeatureId) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 9873 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 9874 | if (phone == null) return false; |
| 9875 | |
| 9876 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9877 | mApp, phone.getSubId(), callingPackage, callingFeatureId, |
| 9878 | "isModemEnabledForSlot")) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 9879 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 9880 | } |
| 9881 | |
| 9882 | final long identity = Binder.clearCallingIdentity(); |
| 9883 | try { |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 9884 | try { |
| 9885 | return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId()); |
| 9886 | } catch (NoSuchElementException ex) { |
| 9887 | return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null); |
| 9888 | } |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 9889 | } finally { |
| 9890 | Binder.restoreCallingIdentity(identity); |
| 9891 | } |
| 9892 | } |
| 9893 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9894 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9895 | public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) { |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9896 | enforceModifyPermission(); |
| 9897 | |
| 9898 | final long identity = Binder.clearCallingIdentity(); |
| 9899 | try { |
| 9900 | mTelephonySharedPreferences.edit() |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9901 | .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted) |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9902 | .commit(); |
| 9903 | } finally { |
| 9904 | Binder.restoreCallingIdentity(identity); |
| 9905 | } |
| 9906 | } |
| 9907 | |
| 9908 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9909 | @TelephonyManager.IsMultiSimSupportedResult |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9910 | public int isMultiSimSupported(String callingPackage, String callingFeatureId) { |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 9911 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9912 | getDefaultPhone().getSubId(), callingPackage, callingFeatureId, |
| 9913 | "isMultiSimSupported")) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9914 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 9915 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9916 | |
| 9917 | final long identity = Binder.clearCallingIdentity(); |
| 9918 | try { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9919 | return isMultiSimSupportedInternal(); |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9920 | } finally { |
| 9921 | Binder.restoreCallingIdentity(identity); |
| 9922 | } |
| 9923 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9924 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9925 | @TelephonyManager.IsMultiSimSupportedResult |
| 9926 | private int isMultiSimSupportedInternal() { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9927 | // If the device has less than 2 SIM cards, indicate that multisim is restricted. |
| 9928 | int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length; |
| 9929 | if (numPhysicalSlots < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9930 | loge("isMultiSimSupportedInternal: requires at least 2 cards"); |
| 9931 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9932 | } |
| 9933 | // Check if the hardware supports multisim functionality. If usage of multisim is not |
| 9934 | // supported by the modem, indicate that it is restricted. |
| 9935 | PhoneCapability staticCapability = |
| 9936 | mPhoneConfigurationManager.getStaticPhoneCapability(); |
| 9937 | if (staticCapability == null) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9938 | loge("isMultiSimSupportedInternal: no static configuration available"); |
| 9939 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9940 | } |
SongFerngWang | 8236caa | 2021-01-17 21:51:44 +0800 | [diff] [blame] | 9941 | if (staticCapability.getLogicalModemList().size() < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9942 | loge("isMultiSimSupportedInternal: maximum number of modem is < 2"); |
| 9943 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9944 | } |
| 9945 | // Check if support of multiple SIMs is restricted by carrier |
| 9946 | if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9947 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9948 | } |
| 9949 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9950 | return TelephonyManager.MULTISIM_ALLOWED; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9951 | } |
| 9952 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9953 | /** |
| 9954 | * Switch configs to enable multi-sim or switch back to single-sim |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 9955 | * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE |
| 9956 | * permission, but the other way around is possible with either MODIFY_PHONE_STATE |
| 9957 | * or carrier privileges |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9958 | * @param numOfSims number of active sims we want to switch to |
| 9959 | */ |
| 9960 | @Override |
| 9961 | public void switchMultiSimConfig(int numOfSims) { |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 9962 | if (numOfSims == 1) { |
| 9963 | enforceModifyPermission(); |
| 9964 | } else { |
| 9965 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9966 | mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig"); |
| 9967 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9968 | final long identity = Binder.clearCallingIdentity(); |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9969 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9970 | try { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9971 | //only proceed if multi-sim is not restricted |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9972 | if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9973 | loge("switchMultiSimConfig not possible. It is restricted or not supported."); |
| 9974 | return; |
| 9975 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9976 | mPhoneConfigurationManager.switchMultiSimConfig(numOfSims); |
| 9977 | } finally { |
| 9978 | Binder.restoreCallingIdentity(identity); |
| 9979 | } |
| 9980 | } |
| 9981 | |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 9982 | @Override |
| 9983 | public boolean isApplicationOnUicc(int subId, int appType) { |
| 9984 | enforceReadPrivilegedPermission("isApplicationOnUicc"); |
| 9985 | Phone phone = getPhone(subId); |
| 9986 | if (phone == null) { |
| 9987 | return false; |
| 9988 | } |
| 9989 | final long identity = Binder.clearCallingIdentity(); |
| 9990 | try { |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9991 | UiccPort uiccPort = phone.getUiccPort(); |
| 9992 | if (uiccPort == null) { |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 9993 | return false; |
| 9994 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9995 | UiccProfile uiccProfile = uiccPort.getUiccProfile(); |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 9996 | if (uiccProfile == null) { |
| 9997 | return false; |
| 9998 | } |
| 9999 | if (TelephonyManager.APPTYPE_SIM <= appType |
| 10000 | && appType <= TelephonyManager.APPTYPE_ISIM) { |
| 10001 | return uiccProfile.isApplicationOnIcc(AppType.values()[appType]); |
| 10002 | } |
| 10003 | return false; |
| 10004 | } finally { |
| 10005 | Binder.restoreCallingIdentity(identity); |
| 10006 | } |
| 10007 | } |
| 10008 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 10009 | /** |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 10010 | * Get whether making changes to modem configurations will trigger reboot. |
| 10011 | * Return value defaults to true. |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 10012 | */ |
| 10013 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10014 | public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage, |
| 10015 | String callingFeatureId) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 10016 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10017 | mApp, subId, callingPackage, callingFeatureId, |
| 10018 | "doesSwitchMultiSimConfigTriggerReboot")) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 10019 | return false; |
| 10020 | } |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 10021 | final long identity = Binder.clearCallingIdentity(); |
| 10022 | try { |
| 10023 | return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange(); |
| 10024 | } finally { |
| 10025 | Binder.restoreCallingIdentity(identity); |
| 10026 | } |
| 10027 | } |
| 10028 | |
Nathan Harold | 29f5f05 | 2019-02-15 13:41:57 -0800 | [diff] [blame] | 10029 | private void updateModemStateMetrics() { |
| 10030 | TelephonyMetrics metrics = TelephonyMetrics.getInstance(); |
| 10031 | // TODO: check the state for each modem if the api is ready. |
| 10032 | metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1); |
| 10033 | } |
| 10034 | |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10035 | @Override |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 10036 | public List<UiccSlotMapping> getSlotsMapping(String callingPackage) { |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10037 | enforceReadPrivilegedPermission("getSlotsMapping"); |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 10038 | // Verify that the callingPackage belongs to the calling UID |
| 10039 | mApp.getSystemService(AppOpsManager.class) |
| 10040 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10041 | final long identity = Binder.clearCallingIdentity(); |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 10042 | List<UiccSlotMapping> slotMap = new ArrayList<>(); |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10043 | try { |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 10044 | UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName()); |
| 10045 | if (slotInfos != null) { |
| 10046 | for (int i = 0; i < slotInfos.length; i++) { |
| 10047 | for (UiccPortInfo portInfo : slotInfos[i].getPorts()) { |
| 10048 | if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) { |
| 10049 | slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i, |
| 10050 | portInfo.getLogicalSlotIndex())); |
| 10051 | } |
| 10052 | } |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10053 | } |
| 10054 | } |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 10055 | return slotMap; |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10056 | } finally { |
| 10057 | Binder.restoreCallingIdentity(identity); |
| 10058 | } |
| 10059 | } |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 10060 | |
| 10061 | /** |
| 10062 | * Get the IRadio HAL Version |
jimsun | f9ec162 | 2022-09-13 21:18:43 +0800 | [diff] [blame] | 10063 | * @deprecated use getHalVersion instead |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 10064 | */ |
jimsun | f9ec162 | 2022-09-13 21:18:43 +0800 | [diff] [blame] | 10065 | @Deprecated |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 10066 | @Override |
| 10067 | public int getRadioHalVersion() { |
jimsun | f9ec162 | 2022-09-13 21:18:43 +0800 | [diff] [blame] | 10068 | return getHalVersion(HAL_SERVICE_RADIO); |
| 10069 | } |
| 10070 | |
| 10071 | /** |
| 10072 | * Get the HAL Version of a specific service |
| 10073 | */ |
| 10074 | @Override |
| 10075 | public int getHalVersion(int service) { |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 10076 | Phone phone = getDefaultPhone(); |
| 10077 | if (phone == null) return -1; |
jimsun | f9ec162 | 2022-09-13 21:18:43 +0800 | [diff] [blame] | 10078 | HalVersion hv = phone.getHalVersion(service); |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 10079 | if (hv.equals(HalVersion.UNKNOWN)) return -1; |
| 10080 | return hv.major * 100 + hv.minor; |
| 10081 | } |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 10082 | |
| 10083 | /** |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 10084 | * Get the current calling package name. |
| 10085 | * @return the current calling package name |
| 10086 | */ |
| 10087 | @Override |
| 10088 | public String getCurrentPackageName() { |
| 10089 | return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0]; |
| 10090 | } |
| 10091 | |
| 10092 | /** |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10093 | * Return whether data is enabled for certain APN type. This will tell if framework will accept |
| 10094 | * corresponding network requests on a subId. |
| 10095 | * |
| 10096 | * Data is enabled if: |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 10097 | * 1) user data is turned on, or |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10098 | * 2) APN is un-metered for this subscription, or |
| 10099 | * 3) APN type is whitelisted. E.g. MMS is whitelisted if |
Hall Liu | 746e03c | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 10100 | * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled. |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10101 | * |
| 10102 | * @return whether data is allowed for a apn type. |
| 10103 | * |
| 10104 | * @hide |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 10105 | */ |
| 10106 | @Override |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10107 | public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) { |
Amit Mahajan | 5d4e192 | 2019-10-07 16:20:43 -0700 | [diff] [blame] | 10108 | enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for " |
| 10109 | + "isDataEnabledForApn"); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 10110 | |
| 10111 | // Now that all security checks passes, perform the operation as ourselves. |
| 10112 | final long identity = Binder.clearCallingIdentity(); |
| 10113 | try { |
| 10114 | Phone phone = getPhone(subId); |
| 10115 | if (phone == null) return false; |
| 10116 | |
Jack Yu | 27422a5 | 2022-03-21 10:38:05 -0700 | [diff] [blame] | 10117 | boolean isMetered; |
Jack Yu | 99e8733 | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 10118 | boolean isDataEnabled; |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 10119 | isMetered = phone.getDataNetworkController().getDataConfigManager() |
| 10120 | .isMeteredCapability(DataUtils.apnTypeToNetworkCapability(apnType), |
| 10121 | phone.getServiceState().getDataRoaming()); |
| 10122 | isDataEnabled = phone.getDataSettingsManager().isDataEnabled(apnType); |
Jack Yu | 99e8733 | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 10123 | return !isMetered || isDataEnabled; |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10124 | } finally { |
| 10125 | Binder.restoreCallingIdentity(identity); |
| 10126 | } |
| 10127 | } |
| 10128 | |
| 10129 | @Override |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 10130 | public boolean isApnMetered(@ApnType int apnType, int subId) { |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10131 | enforceReadPrivilegedPermission("isApnMetered"); |
| 10132 | |
| 10133 | // Now that all security checks passes, perform the operation as ourselves. |
| 10134 | final long identity = Binder.clearCallingIdentity(); |
| 10135 | try { |
| 10136 | Phone phone = getPhone(subId); |
| 10137 | if (phone == null) return true; // By default return true. |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 10138 | return phone.getDataNetworkController().getDataConfigManager().isMeteredCapability( |
| 10139 | DataUtils.apnTypeToNetworkCapability(apnType), |
| 10140 | phone.getServiceState().getDataRoaming()); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 10141 | } finally { |
| 10142 | Binder.restoreCallingIdentity(identity); |
| 10143 | } |
| 10144 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 10145 | |
| 10146 | @Override |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 10147 | public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers, |
| 10148 | int subscriptionId, IBooleanConsumer resultCallback) { |
| 10149 | enforceModifyPermission(); |
| 10150 | long token = Binder.clearCallingIdentity(); |
| 10151 | try { |
| 10152 | Phone phone = getPhone(subscriptionId); |
| 10153 | if (phone == null) { |
| 10154 | try { |
| 10155 | if (resultCallback != null) { |
| 10156 | resultCallback.accept(false); |
| 10157 | } |
| 10158 | } catch (RemoteException e) { |
| 10159 | // ignore |
| 10160 | } |
| 10161 | return; |
| 10162 | } |
| 10163 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument = |
| 10164 | Pair.create(specifiers, (x) -> { |
| 10165 | try { |
| 10166 | if (resultCallback != null) { |
| 10167 | resultCallback.accept(x); |
| 10168 | } |
| 10169 | } catch (RemoteException e) { |
| 10170 | // ignore |
| 10171 | } |
| 10172 | }); |
| 10173 | sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null); |
| 10174 | } finally { |
| 10175 | Binder.restoreCallingIdentity(token); |
| 10176 | } |
| 10177 | } |
| 10178 | |
| 10179 | @Override |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 10180 | public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) { |
| 10181 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 10182 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 10183 | mApp, subId, "getSystemSelectionChannels"); |
| 10184 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 10185 | final long identity = Binder.clearCallingIdentity(); |
| 10186 | try { |
Sarah Chin | 428d1d6 | 2021-03-13 03:17:40 -0800 | [diff] [blame] | 10187 | Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource); |
| 10188 | if (result instanceof IllegalStateException) { |
| 10189 | throw (IllegalStateException) result; |
| 10190 | } |
| 10191 | List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 10192 | if (DBG) log("getSystemSelectionChannels: " + specifiers); |
| 10193 | return specifiers; |
| 10194 | } finally { |
| 10195 | Binder.restoreCallingIdentity(identity); |
| 10196 | } |
| 10197 | } |
| 10198 | |
| 10199 | @Override |
Jack Yu | 8b766fc | 2022-03-21 09:42:33 -0700 | [diff] [blame] | 10200 | public boolean isMvnoMatched(int slotIndex, int mvnoType, @NonNull String mvnoMatchData) { |
changbetty | ca3d40d | 2020-03-03 16:27:31 +0800 | [diff] [blame] | 10201 | enforceReadPrivilegedPermission("isMvnoMatched"); |
Jack Yu | 8b766fc | 2022-03-21 09:42:33 -0700 | [diff] [blame] | 10202 | return UiccController.getInstance().mvnoMatches(slotIndex, mvnoType, mvnoMatchData); |
changbetty | 7157e9e | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 10203 | } |
| 10204 | |
| 10205 | @Override |
Philip P. Moltmann | d02b737 | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 10206 | public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag, |
| 10207 | IIntegerConsumer pendingSubIdResult) { |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 10208 | if (callingPackage == null) { |
| 10209 | callingPackage = getCurrentPackageName(); |
| 10210 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 10211 | SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp, |
| 10212 | (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE)); |
Philip P. Moltmann | d02b737 | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 10213 | if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag, |
| 10214 | "Sending message")) { |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 10215 | throw new SecurityException("Requires SEND_SMS permission to perform this operation"); |
| 10216 | } |
| 10217 | PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult); |
| 10218 | Intent intent = new Intent(); |
| 10219 | intent.setClass(mApp, PickSmsSubscriptionActivity.class); |
| 10220 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 10221 | // Bring up choose default SMS subscription dialog right now |
| 10222 | intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY, |
| 10223 | PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE); |
| 10224 | mApp.startActivity(intent); |
| 10225 | } |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 10226 | |
| 10227 | @Override |
Ayush Sharma | 787854b | 2022-12-12 14:55:02 +0000 | [diff] [blame] | 10228 | public void showSwitchToManagedProfileDialog() { |
| 10229 | enforceModifyPermission(); |
| 10230 | |
| 10231 | Intent intent = new Intent(); |
| 10232 | intent.setClass(mApp, ErrorDialogActivity.class); |
| 10233 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 10234 | mApp.startActivity(intent); |
| 10235 | } |
| 10236 | |
| 10237 | @Override |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 10238 | public String getMmsUAProfUrl(int subId) { |
| 10239 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 10240 | final long identity = Binder.clearCallingIdentity(); |
| 10241 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 10242 | String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString( |
| 10243 | CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING); |
| 10244 | if (!TextUtils.isEmpty(carrierUAProfUrl)) { |
| 10245 | return carrierUAProfUrl; |
| 10246 | } |
Daniel Bright | ebb4eb7 | 2020-02-18 15:16:33 -0800 | [diff] [blame] | 10247 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 10248 | .getString(com.android.internal.R.string.config_mms_user_agent_profile_url); |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 10249 | } finally { |
| 10250 | Binder.restoreCallingIdentity(identity); |
| 10251 | } |
| 10252 | } |
| 10253 | |
| 10254 | @Override |
| 10255 | public String getMmsUserAgent(int subId) { |
| 10256 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 10257 | final long identity = Binder.clearCallingIdentity(); |
| 10258 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 10259 | String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString( |
| 10260 | CarrierConfigManager.KEY_MMS_USER_AGENT_STRING); |
| 10261 | if (!TextUtils.isEmpty(carrierUserAgent)) { |
| 10262 | return carrierUserAgent; |
| 10263 | } |
Daniel Bright | ebb4eb7 | 2020-02-18 15:16:33 -0800 | [diff] [blame] | 10264 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 10265 | .getString(com.android.internal.R.string.config_mms_user_agent); |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 10266 | } finally { |
| 10267 | Binder.restoreCallingIdentity(identity); |
| 10268 | } |
| 10269 | } |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 10270 | |
| 10271 | @Override |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 10272 | public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) { |
| 10273 | enforceReadPrivilegedPermission("isMobileDataPolicyEnabled"); |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 10274 | |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 10275 | final long identity = Binder.clearCallingIdentity(); |
| 10276 | try { |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 10277 | Phone phone = getPhone(subscriptionId); |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 10278 | if (phone == null) return false; |
| 10279 | |
Ling Ma | f188d50 | 2022-09-16 15:22:36 -0700 | [diff] [blame] | 10280 | return phone.getDataSettingsManager().isMobileDataPolicyEnabled(policy); |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 10281 | } finally { |
| 10282 | Binder.restoreCallingIdentity(identity); |
| 10283 | } |
| 10284 | } |
| 10285 | |
| 10286 | @Override |
Hall Liu | c66bb11 | 2021-02-02 12:09:32 -0800 | [diff] [blame] | 10287 | public void setMobileDataPolicyEnabled(int subscriptionId, int policy, |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 10288 | boolean enabled) { |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 10289 | enforceModifyPermission(); |
| 10290 | |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 10291 | final long identity = Binder.clearCallingIdentity(); |
| 10292 | try { |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 10293 | Phone phone = getPhone(subscriptionId); |
| 10294 | if (phone == null) return; |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 10295 | |
Ling Ma | f188d50 | 2022-09-16 15:22:36 -0700 | [diff] [blame] | 10296 | phone.getDataSettingsManager().setMobileDataPolicy(policy, enabled); |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 10297 | } finally { |
| 10298 | Binder.restoreCallingIdentity(identity); |
| 10299 | } |
| 10300 | } |
| 10301 | |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 10302 | /** |
Hall Liu | 746e03c | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 10303 | * Updates whether conference event package handling is enabled. |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 10304 | * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false} |
| 10305 | * otherwise. |
| 10306 | */ |
| 10307 | @Override |
| 10308 | public void setCepEnabled(boolean isCepEnabled) { |
| 10309 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled"); |
| 10310 | |
| 10311 | final long identity = Binder.clearCallingIdentity(); |
| 10312 | try { |
| 10313 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled); |
| 10314 | for (Phone phone : PhoneFactory.getPhones()) { |
| 10315 | Phone defaultPhone = phone.getImsPhone(); |
| 10316 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 10317 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 10318 | ImsPhoneCallTracker imsPhoneCallTracker = |
| 10319 | (ImsPhoneCallTracker) imsPhone.getCallTracker(); |
| 10320 | imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled); |
| 10321 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone " |
| 10322 | + imsPhone.getMsisdn()); |
| 10323 | } |
| 10324 | } |
| 10325 | } finally { |
| 10326 | Binder.restoreCallingIdentity(identity); |
| 10327 | } |
| 10328 | } |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 10329 | |
| 10330 | /** |
| 10331 | * Notify that an RCS autoconfiguration XML file has been received for provisioning. |
| 10332 | * |
| 10333 | * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed. |
| 10334 | * @param isCompressed The XML file is compressed in gzip format and must be decompressed |
| 10335 | * before being read. |
| 10336 | */ |
| 10337 | @Override |
| 10338 | public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean |
| 10339 | isCompressed) { |
| 10340 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 10341 | mApp, subId, "notifyRcsAutoConfigurationReceived"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10342 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10343 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10344 | } |
| 10345 | if (!isImsAvailableOnDevice()) { |
joonhunshin | 46b49a3 | 2022-12-21 05:33:23 +0000 | [diff] [blame] | 10346 | // ProvisioningManager can not handle ServiceSpecificException. |
| 10347 | // Throw the IllegalStateException and annotate ProvisioningManager. |
| 10348 | throw new IllegalStateException("IMS not available on device."); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10349 | } |
| 10350 | |
| 10351 | final long identity = Binder.clearCallingIdentity(); |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 10352 | try { |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10353 | RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed); |
| 10354 | } finally { |
| 10355 | Binder.restoreCallingIdentity(identity); |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 10356 | } |
| 10357 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 10358 | |
| 10359 | @Override |
| 10360 | public boolean isIccLockEnabled(int subId) { |
| 10361 | enforceReadPrivilegedPermission("isIccLockEnabled"); |
| 10362 | |
| 10363 | // Now that all security checks passes, perform the operation as ourselves. |
| 10364 | final long identity = Binder.clearCallingIdentity(); |
| 10365 | try { |
| 10366 | Phone phone = getPhone(subId); |
| 10367 | if (phone != null && phone.getIccCard() != null) { |
| 10368 | return phone.getIccCard().getIccLockEnabled(); |
| 10369 | } else { |
| 10370 | return false; |
| 10371 | } |
| 10372 | } finally { |
| 10373 | Binder.restoreCallingIdentity(identity); |
| 10374 | } |
| 10375 | } |
| 10376 | |
| 10377 | /** |
| 10378 | * Set the ICC pin lock enabled or disabled. |
| 10379 | * |
| 10380 | * @return an integer representing the status of IccLock enabled or disabled in the following |
| 10381 | * three cases: |
| 10382 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock |
| 10383 | * successfully. |
| 10384 | * - Positive number and zero for remaining password attempts. |
| 10385 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
| 10386 | * |
| 10387 | */ |
| 10388 | @Override |
| 10389 | public int setIccLockEnabled(int subId, boolean enabled, String password) { |
| 10390 | enforceModifyPermission(); |
| 10391 | |
| 10392 | Phone phone = getPhone(subId); |
| 10393 | if (phone == null) { |
| 10394 | return 0; |
| 10395 | } |
| 10396 | // Now that all security checks passes, perform the operation as ourselves. |
| 10397 | final long identity = Binder.clearCallingIdentity(); |
| 10398 | try { |
| 10399 | int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED, |
| 10400 | new Pair<Boolean, String>(enabled, password), phone, null); |
| 10401 | return attemptsRemaining; |
| 10402 | |
| 10403 | } catch (Exception e) { |
| 10404 | Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e); |
| 10405 | } finally { |
| 10406 | Binder.restoreCallingIdentity(identity); |
| 10407 | } |
| 10408 | return 0; |
| 10409 | } |
| 10410 | |
| 10411 | /** |
| 10412 | * Change the ICC password used in ICC pin lock. |
| 10413 | * |
| 10414 | * @return an integer representing the status of IccLock changed in the following three cases: |
| 10415 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully. |
| 10416 | * - Positive number and zero for remaining password attempts. |
| 10417 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
| 10418 | * |
| 10419 | */ |
| 10420 | @Override |
| 10421 | public int changeIccLockPassword(int subId, String oldPassword, String newPassword) { |
| 10422 | enforceModifyPermission(); |
| 10423 | |
| 10424 | Phone phone = getPhone(subId); |
| 10425 | if (phone == null) { |
| 10426 | return 0; |
| 10427 | } |
| 10428 | // Now that all security checks passes, perform the operation as ourselves. |
| 10429 | final long identity = Binder.clearCallingIdentity(); |
| 10430 | try { |
| 10431 | int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD, |
| 10432 | new Pair<String, String>(oldPassword, newPassword), phone, null); |
| 10433 | return attemptsRemaining; |
| 10434 | |
| 10435 | } catch (Exception e) { |
| 10436 | Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e); |
| 10437 | } finally { |
| 10438 | Binder.restoreCallingIdentity(identity); |
| 10439 | } |
| 10440 | return 0; |
| 10441 | } |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 10442 | |
| 10443 | /** |
| 10444 | * Request for receiving user activity notification |
| 10445 | */ |
| 10446 | @Override |
| 10447 | public void requestUserActivityNotification() { |
| 10448 | if (!mNotifyUserActivity.get() |
| 10449 | && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) { |
| 10450 | mNotifyUserActivity.set(true); |
| 10451 | } |
| 10452 | } |
| 10453 | |
| 10454 | /** |
| 10455 | * Called when userActivity is signalled in the power manager. |
| 10456 | * This is safe to call from any thread, with any window manager locks held or not. |
| 10457 | */ |
| 10458 | @Override |
| 10459 | public void userActivity() { |
| 10460 | // *************************************** |
| 10461 | // * Inherited from PhoneWindowManager * |
| 10462 | // *************************************** |
| 10463 | // THIS IS CALLED FROM DEEP IN THE POWER MANAGER |
| 10464 | // WITH ITS LOCKS HELD. |
| 10465 | // |
| 10466 | // This code must be VERY careful about the locks |
| 10467 | // it acquires. |
| 10468 | // In fact, the current code acquires way too many, |
| 10469 | // and probably has lurking deadlocks. |
| 10470 | |
| 10471 | if (Binder.getCallingUid() != Process.SYSTEM_UID) { |
| 10472 | throw new SecurityException("Only the OS may call notifyUserActivity()"); |
| 10473 | } |
| 10474 | |
| 10475 | if (mNotifyUserActivity.getAndSet(false)) { |
| 10476 | mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY, |
| 10477 | USER_ACTIVITY_NOTIFICATION_DELAY); |
| 10478 | } |
| 10479 | } |
Malcolm Chen | 4639c56 | 2020-04-13 11:59:40 -0700 | [diff] [blame] | 10480 | |
| 10481 | @Override |
| 10482 | public boolean canConnectTo5GInDsdsMode() { |
| 10483 | return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode); |
| 10484 | } |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 10485 | |
| 10486 | @Override |
| 10487 | public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage, |
| 10488 | String callingFeatureId) { |
| 10489 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 10490 | mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) { |
| 10491 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 10492 | } |
| 10493 | |
| 10494 | Phone phone = getPhone(subId); |
| 10495 | if (phone == null) { |
| 10496 | throw new RuntimeException("phone is not available"); |
| 10497 | } |
| 10498 | // Now that all security checks passes, perform the operation as ourselves. |
| 10499 | final long identity = Binder.clearCallingIdentity(); |
| 10500 | try { |
| 10501 | return phone.getEquivalentHomePlmns(); |
| 10502 | } finally { |
| 10503 | Binder.restoreCallingIdentity(identity); |
| 10504 | } |
| 10505 | } |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 10506 | |
| 10507 | @Override |
| 10508 | public boolean isRadioInterfaceCapabilitySupported( |
Daniel Bright | 95a4c1f | 2021-02-11 09:57:16 -0800 | [diff] [blame] | 10509 | final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) { |
| 10510 | Set<String> radioInterfaceCapabilities = |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 10511 | mRadioInterfaceCapabilities.getCapabilities(); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 10512 | if (radioInterfaceCapabilities == null) { |
| 10513 | throw new RuntimeException("radio interface capabilities are not available"); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 10514 | } |
Daniel Bright | 95a4c1f | 2021-02-11 09:57:16 -0800 | [diff] [blame] | 10515 | return radioInterfaceCapabilities.contains(capability); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 10516 | } |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10517 | |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 10518 | @Override |
| 10519 | public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl, |
| 10520 | UaSecurityProtocolIdentifier securityProtocol, |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10521 | boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) { |
| 10522 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 10523 | Binder.getCallingUid(), "bootstrapAuthenticationRequest", |
| 10524 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 10525 | Manifest.permission.MODIFY_PHONE_STATE); |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 10526 | if (DBG) { |
| 10527 | log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:" |
| 10528 | + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol |
| 10529 | + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback); |
| 10530 | } |
| 10531 | |
| 10532 | if (!SubscriptionManager.isValidSubscriptionId(subId) |
| 10533 | || appType < TelephonyManager.APPTYPE_UNKNOWN |
| 10534 | || appType > TelephonyManager.APPTYPE_ISIM |
| 10535 | || nafUrl == null || securityProtocol == null || callback == null) { |
| 10536 | Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters"); |
| 10537 | if (callback != null) { |
| 10538 | try { |
| 10539 | callback.onAuthenticationFailure( |
| 10540 | 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED); |
| 10541 | } catch (RemoteException exception) { |
| 10542 | log("Fail to notify onAuthenticationFailure due to " + exception); |
| 10543 | } |
| 10544 | return; |
| 10545 | } |
| 10546 | } |
| 10547 | |
| 10548 | final long token = Binder.clearCallingIdentity(); |
| 10549 | try { |
| 10550 | getGbaManager(subId).bootstrapAuthenticationRequest( |
| 10551 | new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(), |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 10552 | forceBootStrapping, callback)); |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 10553 | } finally { |
| 10554 | Binder.restoreCallingIdentity(token); |
| 10555 | } |
| 10556 | } |
| 10557 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10558 | /** |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10559 | * Attempts to set the radio power state for all phones for thermal reason. |
| 10560 | * This does not guarantee that the |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10561 | * requested radio power state will actually be set. See {@link |
| 10562 | * PhoneInternalInterface#setRadioPowerForReason} for more details. |
| 10563 | * |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10564 | * @param enable {@code true} if trying to turn radio on. |
| 10565 | * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code |
| 10566 | * false}. |
| 10567 | */ |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10568 | private boolean setRadioPowerForThermal(boolean enable) { |
| 10569 | boolean isPhoneAvailable = false; |
| 10570 | for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) { |
| 10571 | Phone phone = PhoneFactory.getPhone(i); |
| 10572 | if (phone != null) { |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 10573 | phone.setRadioPowerForReason(enable, TelephonyManager.RADIO_POWER_REASON_THERMAL); |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10574 | isPhoneAvailable = true; |
| 10575 | } |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10576 | } |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10577 | |
| 10578 | // return true if successfully informed the phone object about the thermal radio power |
| 10579 | // request. |
| 10580 | return isPhoneAvailable; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10581 | } |
| 10582 | |
| 10583 | private int handleDataThrottlingRequest(int subId, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 10584 | DataThrottlingRequest dataThrottlingRequest, String callingPackage) { |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10585 | boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported( |
| 10586 | TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING); |
| 10587 | if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction() |
| 10588 | != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) { |
| 10589 | throw new IllegalArgumentException("modem does not support data throttling"); |
| 10590 | } |
| 10591 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10592 | // Ensure that radio is on. If not able to power on due to phone being unavailable, return |
| 10593 | // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10594 | if (!setRadioPowerForThermal(true)) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10595 | return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 10596 | } |
| 10597 | |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 10598 | setDataEnabledForReason( |
| 10599 | subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true, callingPackage); |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10600 | |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10601 | if (isDataThrottlingSupported) { |
| 10602 | int thermalMitigationResult = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 10603 | (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId); |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10604 | if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) { |
| 10605 | throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS"); |
| 10606 | } else if (thermalMitigationResult |
| 10607 | == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) { |
Jack Nudelman | 760d096 | 2021-05-20 13:57:30 -0700 | [diff] [blame] | 10608 | log("Modem likely does not support data throttling on secondary carrier. Data " + |
| 10609 | "throttling action = " + dataThrottlingRequest.getDataThrottlingAction()); |
| 10610 | return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10611 | } |
| 10612 | return thermalMitigationResult; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10613 | } |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10614 | |
| 10615 | return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10616 | } |
| 10617 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10618 | private static List<String> getThermalMitigationAllowlist(Context context) { |
| 10619 | if (sThermalMitigationAllowlistedPackages.isEmpty()) { |
| 10620 | for (String pckg : context.getResources() |
| 10621 | .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) { |
| 10622 | sThermalMitigationAllowlistedPackages.add(pckg); |
| 10623 | } |
| 10624 | } |
| 10625 | |
| 10626 | return sThermalMitigationAllowlistedPackages; |
| 10627 | } |
| 10628 | |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 10629 | private boolean isAnyPhoneInEmergencyState() { |
| 10630 | TelecomManager tm = mApp.getSystemService(TelecomManager.class); |
| 10631 | if (tm.isInEmergencyCall()) { |
| 10632 | Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call"); |
| 10633 | return true; |
| 10634 | } |
| 10635 | for (Phone phone : PhoneFactory.getPhones()) { |
| 10636 | if (phone.isInEmergencySmsMode() || phone.isInEcm()) { |
| 10637 | Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = " |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 10638 | + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = " |
| 10639 | + phone.isInEcm()); |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 10640 | return true; |
| 10641 | } |
| 10642 | } |
| 10643 | |
| 10644 | return false; |
| 10645 | } |
| 10646 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10647 | /** |
| 10648 | * Used by shell commands to add an authorized package name for thermal mitigation. |
| 10649 | * @param packageName name of package to be allowlisted |
| 10650 | * @param context |
| 10651 | */ |
| 10652 | static void addPackageToThermalMitigationAllowlist(String packageName, Context context) { |
| 10653 | sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context); |
| 10654 | sThermalMitigationAllowlistedPackages.add(packageName); |
| 10655 | } |
| 10656 | |
| 10657 | /** |
| 10658 | * Used by shell commands to remove an authorized package name for thermal mitigation. |
| 10659 | * @param packageName name of package to remove from allowlist |
| 10660 | * @param context |
| 10661 | */ |
| 10662 | static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) { |
| 10663 | sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context); |
| 10664 | sThermalMitigationAllowlistedPackages.remove(packageName); |
| 10665 | } |
| 10666 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10667 | /** |
| 10668 | * Thermal mitigation request to control functionalities at modem. |
| 10669 | * |
| 10670 | * @param subId the id of the subscription. |
| 10671 | * @param thermalMitigationRequest holds all necessary information to be passed down to modem. |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10672 | * @param callingPackage the package name of the calling package. |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10673 | * |
| 10674 | * @return thermalMitigationResult enum as defined in android.telephony.Annotation. |
| 10675 | */ |
| 10676 | @Override |
| 10677 | @ThermalMitigationResult |
| 10678 | public int sendThermalMitigationRequest( |
| 10679 | int subId, |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10680 | ThermalMitigationRequest thermalMitigationRequest, |
| 10681 | String callingPackage) throws IllegalArgumentException { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10682 | enforceModifyPermission(); |
| 10683 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10684 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 10685 | if (!getThermalMitigationAllowlist(getDefaultPhone().getContext()) |
| 10686 | .contains(callingPackage)) { |
| 10687 | throw new SecurityException("Calling package must be configured in the device config. " |
| 10688 | + "calling package: " + callingPackage); |
| 10689 | } |
| 10690 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10691 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 10692 | final long identity = Binder.clearCallingIdentity(); |
| 10693 | |
| 10694 | int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR; |
| 10695 | try { |
| 10696 | int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction(); |
| 10697 | switch (thermalMitigationAction) { |
| 10698 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING: |
| 10699 | thermalMitigationResult = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 10700 | handleDataThrottlingRequest(subId, |
| 10701 | thermalMitigationRequest.getDataThrottlingRequest(), |
| 10702 | callingPackage); |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10703 | break; |
| 10704 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY: |
| 10705 | if (thermalMitigationRequest.getDataThrottlingRequest() != null) { |
| 10706 | throw new IllegalArgumentException("dataThrottlingRequest must be null for " |
| 10707 | + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY"); |
| 10708 | } |
| 10709 | |
| 10710 | // Ensure that radio is on. If not able to power on due to phone being |
| 10711 | // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10712 | if (!setRadioPowerForThermal(true)) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10713 | thermalMitigationResult = |
| 10714 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 10715 | break; |
| 10716 | } |
| 10717 | |
| 10718 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 10719 | false, callingPackage); |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10720 | thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 10721 | break; |
| 10722 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF: |
| 10723 | if (thermalMitigationRequest.getDataThrottlingRequest() != null) { |
| 10724 | throw new IllegalArgumentException("dataThrottlingRequest must be null for" |
| 10725 | + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF"); |
| 10726 | } |
| 10727 | |
| 10728 | TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null); |
| 10729 | if (registry != null) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10730 | Phone phone = getPhone(subId); |
| 10731 | if (phone == null) { |
| 10732 | thermalMitigationResult = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 10733 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10734 | break; |
| 10735 | } |
| 10736 | |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 10737 | TelephonyConnectionService service = |
| 10738 | registry.getTelephonyConnectionService(); |
Jack Nudelman | b30ac30 | 2021-06-17 15:39:58 -0700 | [diff] [blame] | 10739 | if (service != null && service.isEmergencyCallPending()) { |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 10740 | Log.e(LOG_TAG, "An emergency call is pending"); |
| 10741 | thermalMitigationResult = |
| 10742 | TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE; |
| 10743 | break; |
| 10744 | } else if (isAnyPhoneInEmergencyState()) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10745 | thermalMitigationResult = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 10746 | TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10747 | break; |
| 10748 | } |
| 10749 | } else { |
| 10750 | thermalMitigationResult = |
| 10751 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 10752 | break; |
| 10753 | } |
| 10754 | |
| 10755 | // Turn radio off. If not able to power off due to phone being unavailable, |
| 10756 | // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10757 | if (!setRadioPowerForThermal(false)) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10758 | thermalMitigationResult = |
| 10759 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 10760 | break; |
| 10761 | } |
| 10762 | thermalMitigationResult = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 10763 | TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10764 | break; |
| 10765 | default: |
| 10766 | throw new IllegalArgumentException("the requested thermalMitigationAction does " |
| 10767 | + "not exist. Requested action: " + thermalMitigationAction); |
| 10768 | } |
| 10769 | } catch (IllegalArgumentException e) { |
| 10770 | throw e; |
| 10771 | } catch (Exception e) { |
| 10772 | Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e); |
| 10773 | thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 10774 | } finally { |
| 10775 | Binder.restoreCallingIdentity(identity); |
| 10776 | } |
| 10777 | |
| 10778 | if (DBG) { |
| 10779 | log("thermalMitigationRequest returning with thermalMitigationResult: " |
| 10780 | + thermalMitigationResult); |
| 10781 | } |
| 10782 | |
| 10783 | return thermalMitigationResult; |
| 10784 | } |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 10785 | |
| 10786 | /** |
| 10787 | * Set the GbaService Package Name that Telephony will bind to. |
| 10788 | * |
| 10789 | * @param subId The sim that the GbaService is associated with. |
| 10790 | * @param packageName The name of the package to be replaced with. |
| 10791 | * @return true if setting the GbaService to bind to succeeded, false if it did not. |
| 10792 | */ |
| 10793 | @Override |
| 10794 | public boolean setBoundGbaServiceOverride(int subId, String packageName) { |
| 10795 | enforceModifyPermission(); |
| 10796 | |
| 10797 | final long identity = Binder.clearCallingIdentity(); |
| 10798 | try { |
| 10799 | return getGbaManager(subId).overrideServicePackage(packageName); |
| 10800 | } finally { |
| 10801 | Binder.restoreCallingIdentity(identity); |
| 10802 | } |
| 10803 | } |
| 10804 | |
| 10805 | /** |
| 10806 | * Return the package name of the currently bound GbaService. |
| 10807 | * |
| 10808 | * @param subId The sim that the GbaService is associated with. |
| 10809 | * @return the package name of the GbaService configuration, null if GBA is not supported. |
| 10810 | */ |
| 10811 | @Override |
| 10812 | public String getBoundGbaService(int subId) { |
| 10813 | enforceReadPrivilegedPermission("getBoundGbaServicePackage"); |
| 10814 | |
| 10815 | final long identity = Binder.clearCallingIdentity(); |
| 10816 | try { |
| 10817 | return getGbaManager(subId).getServicePackage(); |
| 10818 | } finally { |
| 10819 | Binder.restoreCallingIdentity(identity); |
| 10820 | } |
| 10821 | } |
| 10822 | |
| 10823 | /** |
| 10824 | * Set the release time for telephony to unbind GbaService. |
| 10825 | * |
| 10826 | * @param subId The sim that the GbaService is associated with. |
| 10827 | * @param interval The release time to unbind GbaService by millisecond. |
| 10828 | * @return true if setting the GbaService to bind to succeeded, false if it did not. |
| 10829 | */ |
| 10830 | @Override |
| 10831 | public boolean setGbaReleaseTimeOverride(int subId, int interval) { |
| 10832 | enforceModifyPermission(); |
| 10833 | |
| 10834 | final long identity = Binder.clearCallingIdentity(); |
| 10835 | try { |
| 10836 | return getGbaManager(subId).overrideReleaseTime(interval); |
| 10837 | } finally { |
| 10838 | Binder.restoreCallingIdentity(identity); |
| 10839 | } |
| 10840 | } |
| 10841 | |
| 10842 | /** |
| 10843 | * Return the release time for telephony to unbind GbaService. |
| 10844 | * |
| 10845 | * @param subId The sim that the GbaService is associated with. |
| 10846 | * @return The release time to unbind GbaService by millisecond. |
| 10847 | */ |
| 10848 | @Override |
| 10849 | public int getGbaReleaseTime(int subId) { |
| 10850 | enforceReadPrivilegedPermission("getGbaReleaseTime"); |
| 10851 | |
| 10852 | final long identity = Binder.clearCallingIdentity(); |
| 10853 | try { |
| 10854 | return getGbaManager(subId).getReleaseTime(); |
| 10855 | } finally { |
| 10856 | Binder.restoreCallingIdentity(identity); |
| 10857 | } |
| 10858 | } |
| 10859 | |
| 10860 | private GbaManager getGbaManager(int subId) { |
| 10861 | GbaManager instance = GbaManager.getInstance(subId); |
| 10862 | if (instance == null) { |
| 10863 | String packageName = mApp.getResources().getString(R.string.config_gba_package); |
| 10864 | int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time); |
| 10865 | instance = GbaManager.make(mApp, subId, packageName, releaseTime); |
| 10866 | } |
| 10867 | return instance; |
| 10868 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10869 | |
| 10870 | /** |
| 10871 | * indicate whether the device and the carrier can support |
| 10872 | * RCS VoLTE single registration. |
| 10873 | */ |
| 10874 | @Override |
| 10875 | public boolean isRcsVolteSingleRegistrationCapable(int subId) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10876 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 10877 | Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable", |
| 10878 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 10879 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10880 | |
| 10881 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10882 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10883 | } |
| 10884 | |
| 10885 | final long identity = Binder.clearCallingIdentity(); |
| 10886 | try { |
| 10887 | RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance(); |
| 10888 | if (rpm != null) { |
Hui Wang | 67af90e | 2021-06-04 16:57:15 -0700 | [diff] [blame] | 10889 | Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId); |
| 10890 | if (isCapable != null) { |
| 10891 | return isCapable; |
| 10892 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10893 | } |
Hui Wang | 67af90e | 2021-06-04 16:57:15 -0700 | [diff] [blame] | 10894 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE, |
| 10895 | "service is temporarily unavailable."); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10896 | } finally { |
| 10897 | Binder.restoreCallingIdentity(identity); |
| 10898 | } |
| 10899 | } |
| 10900 | |
| 10901 | /** |
| 10902 | * Register RCS provisioning callback. |
| 10903 | */ |
| 10904 | @Override |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10905 | public void registerRcsProvisioningCallback(int subId, |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10906 | IRcsConfigCallback callback) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10907 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10908 | Binder.getCallingUid(), "registerRcsProvisioningCallback", |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10909 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 10910 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10911 | |
| 10912 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10913 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10914 | } |
| 10915 | if (!isImsAvailableOnDevice()) { |
| 10916 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 10917 | "IMS not available on device."); |
| 10918 | } |
| 10919 | |
| 10920 | final long identity = Binder.clearCallingIdentity(); |
| 10921 | try { |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 10922 | if (!RcsProvisioningMonitor.getInstance() |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10923 | .registerRcsProvisioningCallback(subId, callback)) { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 10924 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION, |
| 10925 | "Active subscription not found."); |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 10926 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10927 | } finally { |
| 10928 | Binder.restoreCallingIdentity(identity); |
| 10929 | } |
| 10930 | } |
| 10931 | |
| 10932 | /** |
| 10933 | * Unregister RCS provisioning callback. |
| 10934 | */ |
| 10935 | @Override |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10936 | public void unregisterRcsProvisioningCallback(int subId, |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10937 | IRcsConfigCallback callback) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10938 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10939 | Binder.getCallingUid(), "unregisterRcsProvisioningCallback", |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10940 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 10941 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10942 | |
| 10943 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10944 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10945 | } |
| 10946 | if (!isImsAvailableOnDevice()) { |
joonhunshin | 46b49a3 | 2022-12-21 05:33:23 +0000 | [diff] [blame] | 10947 | // operation failed silently |
| 10948 | Rlog.w(LOG_TAG, "IMS not available on device."); |
| 10949 | return; |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10950 | } |
| 10951 | |
| 10952 | final long identity = Binder.clearCallingIdentity(); |
| 10953 | try { |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 10954 | RcsProvisioningMonitor.getInstance() |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10955 | .unregisterRcsProvisioningCallback(subId, callback); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10956 | } finally { |
| 10957 | Binder.restoreCallingIdentity(identity); |
| 10958 | } |
| 10959 | } |
| 10960 | |
| 10961 | /** |
| 10962 | * trigger RCS reconfiguration. |
| 10963 | */ |
| 10964 | public void triggerRcsReconfiguration(int subId) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10965 | TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(), |
| 10966 | "triggerRcsReconfiguration", |
| 10967 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10968 | |
| 10969 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10970 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10971 | } |
| 10972 | if (!isImsAvailableOnDevice()) { |
joonhunshin | 46b49a3 | 2022-12-21 05:33:23 +0000 | [diff] [blame] | 10973 | // ProvisioningManager can not handle ServiceSpecificException. |
| 10974 | // Throw the IllegalStateException and annotate ProvisioningManager. |
| 10975 | throw new IllegalStateException("IMS not available on device."); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10976 | } |
| 10977 | |
| 10978 | final long identity = Binder.clearCallingIdentity(); |
| 10979 | try { |
| 10980 | RcsProvisioningMonitor.getInstance().requestReconfig(subId); |
| 10981 | } finally { |
| 10982 | Binder.restoreCallingIdentity(identity); |
| 10983 | } |
| 10984 | } |
| 10985 | |
| 10986 | /** |
| 10987 | * Provide the client configuration parameters of the RCS application. |
| 10988 | */ |
| 10989 | public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10990 | TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(), |
| 10991 | "setRcsClientConfiguration", |
| 10992 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10993 | |
| 10994 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10995 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10996 | } |
| 10997 | if (!isImsAvailableOnDevice()) { |
| 10998 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 10999 | "IMS not available on device."); |
| 11000 | } |
| 11001 | |
| 11002 | final long identity = Binder.clearCallingIdentity(); |
| 11003 | |
| 11004 | try { |
| 11005 | IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS); |
| 11006 | if (configBinder == null) { |
| 11007 | Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration"); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 11008 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION, |
| 11009 | "could not find the requested subscription"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11010 | } else { |
| 11011 | configBinder.setRcsClientConfiguration(rcc); |
| 11012 | } |
joonhunshin | 3e15424 | 2021-09-17 06:33:39 +0000 | [diff] [blame] | 11013 | |
| 11014 | RcsStats.getInstance().onRcsClientProvisioningStats(subId, |
| 11015 | RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11016 | } catch (RemoteException e) { |
| 11017 | Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage()); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 11018 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE, |
| 11019 | "service is temporarily unavailable."); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11020 | } finally { |
| 11021 | Binder.restoreCallingIdentity(identity); |
| 11022 | } |
| 11023 | } |
| 11024 | |
| 11025 | /** |
Hui Wang | baaee6a | 2021-02-19 20:45:36 -0800 | [diff] [blame] | 11026 | * Enables or disables the test mode for RCS VoLTE single registration. |
| 11027 | */ |
| 11028 | @Override |
| 11029 | public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) { |
| 11030 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11031 | "setRcsSingleRegistrationTestModeEnabled"); |
| 11032 | |
| 11033 | RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled); |
| 11034 | } |
| 11035 | |
| 11036 | /** |
| 11037 | * Gets the test mode for RCS VoLTE single registration. |
| 11038 | */ |
| 11039 | @Override |
| 11040 | public boolean getRcsSingleRegistrationTestModeEnabled() { |
| 11041 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11042 | "getRcsSingleRegistrationTestModeEnabled"); |
| 11043 | |
| 11044 | return RcsProvisioningMonitor.getInstance().getTestModeEnabled(); |
| 11045 | } |
| 11046 | |
| 11047 | /** |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11048 | * Overrides the config of RCS VoLTE single registration enabled for the device. |
| 11049 | */ |
| 11050 | @Override |
| 11051 | public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) { |
| 11052 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11053 | "setDeviceSingleRegistrationEnabledOverride"); |
| 11054 | enforceModifyPermission(); |
| 11055 | |
| 11056 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 11057 | : Boolean.parseBoolean(enabledStr); |
| 11058 | RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled); |
Brad Ebinger | 49a72b4 | 2021-01-29 00:55:24 +0000 | [diff] [blame] | 11059 | mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11060 | } |
| 11061 | |
| 11062 | /** |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 11063 | * Sends a device to device communication message. Only usable via shell. |
| 11064 | * @param message message to send. |
| 11065 | * @param value message value. |
| 11066 | */ |
| 11067 | @Override |
| 11068 | public void sendDeviceToDeviceMessage(int message, int value) { |
| 11069 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
Tyler Gunn | babbda0 | 2021-02-10 11:05:02 -0800 | [diff] [blame] | 11070 | "sendDeviceToDeviceMessage"); |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 11071 | enforceModifyPermission(); |
| 11072 | |
| 11073 | final long identity = Binder.clearCallingIdentity(); |
| 11074 | try { |
| 11075 | TelephonyConnectionService service = |
| 11076 | TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService(); |
| 11077 | if (service == null) { |
| 11078 | Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call."); |
| 11079 | return; |
| 11080 | } |
| 11081 | service.sendTestDeviceToDeviceMessage(message, value); |
| 11082 | } finally { |
| 11083 | Binder.restoreCallingIdentity(identity); |
| 11084 | } |
| 11085 | } |
| 11086 | |
Tyler Gunn | babbda0 | 2021-02-10 11:05:02 -0800 | [diff] [blame] | 11087 | /** |
| 11088 | * Sets the specified device to device transport active. |
| 11089 | * @param transport The transport to set active. |
| 11090 | */ |
| 11091 | @Override |
| 11092 | public void setActiveDeviceToDeviceTransport(@NonNull String transport) { |
| 11093 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11094 | "setActiveDeviceToDeviceTransport"); |
| 11095 | enforceModifyPermission(); |
| 11096 | |
| 11097 | final long identity = Binder.clearCallingIdentity(); |
| 11098 | try { |
| 11099 | TelephonyConnectionService service = |
| 11100 | TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService(); |
| 11101 | if (service == null) { |
| 11102 | Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call."); |
| 11103 | return; |
| 11104 | } |
| 11105 | service.setActiveDeviceToDeviceTransport(transport); |
| 11106 | } finally { |
| 11107 | Binder.restoreCallingIdentity(identity); |
| 11108 | } |
| 11109 | } |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 11110 | |
Tyler Gunn | d433926 | 2021-05-03 14:46:49 -0700 | [diff] [blame] | 11111 | @Override |
| 11112 | public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) { |
| 11113 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11114 | "setDeviceToDeviceForceEnabled"); |
| 11115 | |
| 11116 | final long identity = Binder.clearCallingIdentity(); |
| 11117 | try { |
| 11118 | Arrays.stream(PhoneFactory.getPhones()).forEach( |
| 11119 | p -> { |
| 11120 | Phone thePhone = p.getImsPhone(); |
| 11121 | if (thePhone != null && thePhone instanceof ImsPhone) { |
| 11122 | ImsPhone imsPhone = (ImsPhone) thePhone; |
| 11123 | CallTracker tracker = imsPhone.getCallTracker(); |
| 11124 | if (tracker != null && tracker instanceof ImsPhoneCallTracker) { |
| 11125 | ImsPhoneCallTracker imsPhoneCallTracker = |
| 11126 | (ImsPhoneCallTracker) tracker; |
| 11127 | imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled); |
| 11128 | } |
| 11129 | } |
| 11130 | } |
| 11131 | ); |
| 11132 | } finally { |
| 11133 | Binder.restoreCallingIdentity(identity); |
| 11134 | } |
| 11135 | } |
| 11136 | |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 11137 | /** |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11138 | * Gets the config of RCS VoLTE single registration enabled for the device. |
| 11139 | */ |
| 11140 | @Override |
| 11141 | public boolean getDeviceSingleRegistrationEnabled() { |
| 11142 | enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled"); |
| 11143 | return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled(); |
| 11144 | } |
| 11145 | |
| 11146 | /** |
| 11147 | * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription. |
| 11148 | */ |
| 11149 | @Override |
| 11150 | public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) { |
| 11151 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11152 | "setCarrierSingleRegistrationEnabledOverride"); |
| 11153 | enforceModifyPermission(); |
| 11154 | |
| 11155 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 11156 | : Boolean.parseBoolean(enabledStr); |
| 11157 | return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled( |
| 11158 | subId, enabled); |
| 11159 | } |
| 11160 | |
| 11161 | /** |
| 11162 | * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription. |
| 11163 | */ |
| 11164 | @Override |
| 11165 | public boolean getCarrierSingleRegistrationEnabled(int subId) { |
| 11166 | enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled"); |
| 11167 | return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId); |
| 11168 | } |
Chiachang Wang | d6d3477 | 2020-12-22 11:38:27 +0800 | [diff] [blame] | 11169 | |
| 11170 | /** |
Hui Wang | b647abe | 2021-02-26 09:33:38 -0800 | [diff] [blame] | 11171 | * Overrides the ims feature validation result |
| 11172 | */ |
| 11173 | @Override |
| 11174 | public boolean setImsFeatureValidationOverride(int subId, String enabledStr) { |
| 11175 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11176 | "setImsFeatureValidationOverride"); |
| 11177 | |
| 11178 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 11179 | : Boolean.parseBoolean(enabledStr); |
| 11180 | return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation( |
| 11181 | subId, enabled); |
| 11182 | } |
| 11183 | |
| 11184 | /** |
| 11185 | * Gets the ims feature validation override value |
| 11186 | */ |
| 11187 | @Override |
| 11188 | public boolean getImsFeatureValidationOverride(int subId) { |
| 11189 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11190 | "getImsFeatureValidationOverride"); |
| 11191 | return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId); |
| 11192 | } |
| 11193 | |
| 11194 | /** |
Chiachang Wang | d6d3477 | 2020-12-22 11:38:27 +0800 | [diff] [blame] | 11195 | * Get the mobile provisioning url that is used to launch a browser to allow users to manage |
| 11196 | * their mobile plan. |
| 11197 | */ |
| 11198 | @Override |
| 11199 | public String getMobileProvisioningUrl() { |
| 11200 | enforceReadPrivilegedPermission("getMobileProvisioningUrl"); |
| 11201 | final long identity = Binder.clearCallingIdentity(); |
| 11202 | try { |
| 11203 | return getDefaultPhone().getMobileProvisioningUrl(); |
| 11204 | } finally { |
| 11205 | Binder.restoreCallingIdentity(identity); |
| 11206 | } |
| 11207 | } |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11208 | |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 11209 | /** |
calvinpan | e4a8a1d | 2021-01-25 13:51:18 +0800 | [diff] [blame] | 11210 | * Get the EAB contact from the EAB database. |
| 11211 | */ |
| 11212 | @Override |
| 11213 | public String getContactFromEab(String contact) { |
| 11214 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab"); |
| 11215 | enforceModifyPermission(); |
| 11216 | final long identity = Binder.clearCallingIdentity(); |
| 11217 | try { |
| 11218 | return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact); |
| 11219 | } finally { |
| 11220 | Binder.restoreCallingIdentity(identity); |
| 11221 | } |
| 11222 | } |
| 11223 | |
| 11224 | /** |
Calvin Pan | a143432 | 2021-07-01 19:27:01 +0800 | [diff] [blame] | 11225 | * Get the EAB capability from the EAB database. |
| 11226 | */ |
| 11227 | @Override |
| 11228 | public String getCapabilityFromEab(String contact) { |
| 11229 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab"); |
| 11230 | enforceModifyPermission(); |
| 11231 | final long identity = Binder.clearCallingIdentity(); |
| 11232 | try { |
| 11233 | return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact); |
| 11234 | } finally { |
| 11235 | Binder.restoreCallingIdentity(identity); |
| 11236 | } |
| 11237 | } |
| 11238 | |
| 11239 | /** |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 11240 | * Remove the EAB contacts from the EAB database. |
| 11241 | */ |
| 11242 | @Override |
| 11243 | public int removeContactFromEab(int subId, String contacts) { |
| 11244 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab"); |
| 11245 | enforceModifyPermission(); |
| 11246 | final long identity = Binder.clearCallingIdentity(); |
| 11247 | try { |
| 11248 | return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext()); |
| 11249 | } finally { |
| 11250 | Binder.restoreCallingIdentity(identity); |
| 11251 | } |
| 11252 | } |
| 11253 | |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11254 | @Override |
James.cf Lin | 4b784aa | 2021-01-31 03:25:15 +0800 | [diff] [blame] | 11255 | public boolean getDeviceUceEnabled() { |
| 11256 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled"); |
| 11257 | final long identity = Binder.clearCallingIdentity(); |
| 11258 | try { |
| 11259 | return mApp.getDeviceUceEnabled(); |
| 11260 | } finally { |
| 11261 | Binder.restoreCallingIdentity(identity); |
| 11262 | } |
| 11263 | } |
| 11264 | |
| 11265 | @Override |
| 11266 | public void setDeviceUceEnabled(boolean isEnabled) { |
| 11267 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled"); |
| 11268 | final long identity = Binder.clearCallingIdentity(); |
| 11269 | try { |
| 11270 | mApp.setDeviceUceEnabled(isEnabled); |
| 11271 | } finally { |
| 11272 | Binder.restoreCallingIdentity(identity); |
| 11273 | } |
| 11274 | } |
| 11275 | |
Brad Ebinger | 14d467f | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 11276 | /** |
| 11277 | * Add new feature tags to the Set used to calculate the capabilities in PUBLISH. |
| 11278 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 11279 | */ |
| 11280 | // Used for SHELL command only right now. |
| 11281 | @Override |
| 11282 | public RcsContactUceCapability addUceRegistrationOverrideShell(int subId, |
| 11283 | List<String> featureTags) { |
| 11284 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11285 | "addUceRegistrationOverrideShell"); |
| 11286 | final long identity = Binder.clearCallingIdentity(); |
| 11287 | try { |
| 11288 | return mApp.imsRcsController.addUceRegistrationOverrideShell(subId, |
| 11289 | new ArraySet<>(featureTags)); |
| 11290 | } catch (ImsException e) { |
| 11291 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 11292 | } finally { |
| 11293 | Binder.restoreCallingIdentity(identity); |
| 11294 | } |
| 11295 | } |
| 11296 | |
| 11297 | /** |
| 11298 | * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH. |
| 11299 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 11300 | */ |
| 11301 | // Used for SHELL command only right now. |
| 11302 | @Override |
| 11303 | public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId, |
| 11304 | List<String> featureTags) { |
| 11305 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11306 | "removeUceRegistrationOverrideShell"); |
| 11307 | final long identity = Binder.clearCallingIdentity(); |
| 11308 | try { |
| 11309 | return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId, |
| 11310 | new ArraySet<>(featureTags)); |
| 11311 | } catch (ImsException e) { |
| 11312 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 11313 | } finally { |
| 11314 | Binder.restoreCallingIdentity(identity); |
| 11315 | } |
| 11316 | } |
| 11317 | |
| 11318 | /** |
| 11319 | * Clear all overrides in 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 clearUceRegistrationOverrideShell(int subId) { |
| 11325 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11326 | "clearUceRegistrationOverrideShell"); |
| 11327 | final long identity = Binder.clearCallingIdentity(); |
| 11328 | try { |
| 11329 | return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId); |
| 11330 | } catch (ImsException e) { |
| 11331 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 11332 | } finally { |
| 11333 | Binder.restoreCallingIdentity(identity); |
| 11334 | } |
| 11335 | } |
| 11336 | |
| 11337 | /** |
| 11338 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 11339 | */ |
| 11340 | // Used for SHELL command only right now. |
| 11341 | @Override |
| 11342 | public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) { |
| 11343 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11344 | "getLatestRcsContactUceCapabilityShell"); |
| 11345 | final long identity = Binder.clearCallingIdentity(); |
| 11346 | try { |
| 11347 | return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId); |
| 11348 | } catch (ImsException e) { |
| 11349 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 11350 | } finally { |
| 11351 | Binder.restoreCallingIdentity(identity); |
| 11352 | } |
| 11353 | } |
| 11354 | |
| 11355 | /** |
| 11356 | * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the |
| 11357 | * device does not have an active PUBLISH. |
| 11358 | */ |
| 11359 | // Used for SHELL command only right now. |
| 11360 | @Override |
| 11361 | public String getLastUcePidfXmlShell(int subId) { |
| 11362 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml"); |
| 11363 | final long identity = Binder.clearCallingIdentity(); |
| 11364 | try { |
| 11365 | return mApp.imsRcsController.getLastUcePidfXmlShell(subId); |
| 11366 | } catch (ImsException e) { |
| 11367 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 11368 | } finally { |
| 11369 | Binder.restoreCallingIdentity(identity); |
| 11370 | } |
| 11371 | } |
| 11372 | |
James.cf Lin | e8713a4 | 2021-04-29 16:04:26 +0800 | [diff] [blame] | 11373 | /** |
| 11374 | * Remove UCE requests cannot be sent to the network status. |
| 11375 | */ |
| 11376 | // Used for SHELL command only right now. |
| 11377 | @Override |
| 11378 | public boolean removeUceRequestDisallowedStatus(int subId) { |
| 11379 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus"); |
| 11380 | final long identity = Binder.clearCallingIdentity(); |
| 11381 | try { |
| 11382 | return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId); |
| 11383 | } catch (ImsException e) { |
| 11384 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 11385 | } finally { |
| 11386 | Binder.restoreCallingIdentity(identity); |
| 11387 | } |
| 11388 | } |
| 11389 | |
James.cf Lin | 18bb900 | 2021-05-25 01:37:38 +0800 | [diff] [blame] | 11390 | /** |
| 11391 | * Remove UCE requests cannot be sent to the network status. |
| 11392 | */ |
| 11393 | // Used for SHELL command only. |
| 11394 | @Override |
| 11395 | public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) { |
| 11396 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout"); |
| 11397 | final long identity = Binder.clearCallingIdentity(); |
| 11398 | try { |
| 11399 | return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs); |
| 11400 | } catch (ImsException e) { |
| 11401 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 11402 | } finally { |
| 11403 | Binder.restoreCallingIdentity(identity); |
| 11404 | } |
| 11405 | } |
Brad Ebinger | 14d467f | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 11406 | |
James.cf Lin | 4b784aa | 2021-01-31 03:25:15 +0800 | [diff] [blame] | 11407 | @Override |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11408 | public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request, |
| 11409 | String callingPackage) { |
| 11410 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 11411 | mApp, subId, "setSignalStrengthUpdateRequest"); |
| 11412 | |
| 11413 | final int callingUid = Binder.getCallingUid(); |
| 11414 | // Verify that tha callingPackage belongs to the calling UID |
| 11415 | mApp.getSystemService(AppOpsManager.class) |
| 11416 | .checkPackage(callingUid, callingPackage); |
| 11417 | |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 11418 | validateSignalStrengthUpdateRequest(mApp, request, callingUid); |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11419 | |
| 11420 | final long identity = Binder.clearCallingIdentity(); |
| 11421 | try { |
| 11422 | Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST, |
| 11423 | new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId); |
| 11424 | |
| 11425 | if (result instanceof IllegalStateException) { |
| 11426 | throw (IllegalStateException) result; |
| 11427 | } |
| 11428 | } finally { |
| 11429 | Binder.restoreCallingIdentity(identity); |
| 11430 | } |
| 11431 | } |
| 11432 | |
| 11433 | @Override |
| 11434 | public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request, |
| 11435 | String callingPackage) { |
| 11436 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 11437 | mApp, subId, "clearSignalStrengthUpdateRequest"); |
| 11438 | |
| 11439 | final int callingUid = Binder.getCallingUid(); |
| 11440 | // Verify that tha callingPackage belongs to the calling UID |
| 11441 | mApp.getSystemService(AppOpsManager.class) |
| 11442 | .checkPackage(callingUid, callingPackage); |
| 11443 | |
| 11444 | final long identity = Binder.clearCallingIdentity(); |
| 11445 | try { |
| 11446 | Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST, |
| 11447 | new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId); |
| 11448 | |
| 11449 | if (result instanceof IllegalStateException) { |
| 11450 | throw (IllegalStateException) result; |
| 11451 | } |
| 11452 | } finally { |
| 11453 | Binder.restoreCallingIdentity(identity); |
| 11454 | } |
| 11455 | } |
| 11456 | |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 11457 | private static void validateSignalStrengthUpdateRequest(Context context, |
| 11458 | SignalStrengthUpdateRequest request, int callingUid) { |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11459 | if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) { |
| 11460 | // phone/system process do not have further restriction on request |
| 11461 | return; |
| 11462 | } |
| 11463 | |
| 11464 | // Applications has restrictions on how to use the request: |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 11465 | // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11466 | if (request.isSystemThresholdReportingRequestedWhileIdle()) { |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 11467 | context.enforceCallingOrSelfPermission( |
| 11468 | android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH, |
| 11469 | "validateSignalStrengthUpdateRequest"); |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11470 | } |
| 11471 | |
| 11472 | for (SignalThresholdInfo info : request.getSignalThresholdInfos()) { |
Nagendra Prasad Nagarle Basavaraju | fee544c | 2022-12-07 16:34:52 +0000 | [diff] [blame] | 11473 | // Only system caller can set mHysteresisMs/mIsEnabled. |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11474 | if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11475 | || info.isEnabled()) { |
| 11476 | throw new IllegalArgumentException( |
| 11477 | "Only system can set hide fields in SignalThresholdInfo"); |
| 11478 | } |
| 11479 | |
| 11480 | // Thresholds length for each RAN need in range. This has been validated in |
| 11481 | // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method |
| 11482 | // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds |
| 11483 | final int[] thresholds = info.getThresholds(); |
| 11484 | Objects.requireNonNull(thresholds); |
| 11485 | if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed() |
| 11486 | || thresholds.length |
| 11487 | > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) { |
| 11488 | throw new IllegalArgumentException( |
| 11489 | "thresholds length is out of range: " + thresholds.length); |
| 11490 | } |
| 11491 | } |
| 11492 | } |
SongFerngWang | 8236caa | 2021-01-17 21:51:44 +0800 | [diff] [blame] | 11493 | |
| 11494 | /** |
| 11495 | * Gets the current phone capability. |
| 11496 | * |
| 11497 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 11498 | * @return the PhoneCapability which describes the data connection capability of modem. |
| 11499 | * It's used to evaluate possible phone config change, for example from single |
| 11500 | * SIM device to multi-SIM device. |
| 11501 | */ |
| 11502 | @Override |
| 11503 | public PhoneCapability getPhoneCapability() { |
| 11504 | enforceReadPrivilegedPermission("getPhoneCapability"); |
| 11505 | final long identity = Binder.clearCallingIdentity(); |
| 11506 | try { |
| 11507 | return mPhoneConfigurationManager.getCurrentPhoneCapability(); |
| 11508 | } finally { |
| 11509 | Binder.restoreCallingIdentity(identity); |
| 11510 | } |
| 11511 | } |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 11512 | |
| 11513 | /** |
| 11514 | * Prepare TelephonyManager for an unattended reboot. The reboot is |
| 11515 | * required to be done shortly after the API is invoked. |
| 11516 | */ |
| 11517 | @Override |
| 11518 | @TelephonyManager.PrepareUnattendedRebootResult |
| 11519 | public int prepareForUnattendedReboot() { |
Rafael Higuera Silva | d963064 | 2021-09-20 15:32:01 +0000 | [diff] [blame] | 11520 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 11521 | enforceRebootPermission(); |
| 11522 | |
| 11523 | final long identity = Binder.clearCallingIdentity(); |
| 11524 | try { |
Rafael Higuera Silva | d963064 | 2021-09-20 15:32:01 +0000 | [diff] [blame] | 11525 | return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 11526 | } finally { |
| 11527 | Binder.restoreCallingIdentity(identity); |
| 11528 | } |
| 11529 | } |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 11530 | |
| 11531 | /** |
| 11532 | * Request to get the current slicing configuration including URSP rules and |
| 11533 | * NSSAIs (configured, allowed and rejected). |
| 11534 | * |
| 11535 | * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission. |
| 11536 | */ |
| 11537 | @Override |
| 11538 | public void getSlicingConfig(ResultReceiver callback) { |
Hongbo Zeng | 1b2063d | 2022-02-21 01:33:03 +0000 | [diff] [blame] | 11539 | TelephonyPermissions |
| 11540 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 11541 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, "getSlicingConfig"); |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 11542 | |
| 11543 | final long identity = Binder.clearCallingIdentity(); |
| 11544 | try { |
| 11545 | Phone phone = getDefaultPhone(); |
| 11546 | sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null); |
| 11547 | } finally { |
| 11548 | Binder.restoreCallingIdentity(identity); |
| 11549 | } |
| 11550 | } |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 11551 | |
| 11552 | /** |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 11553 | * Check whether the given premium capability is available for purchase from the carrier. |
| 11554 | * |
| 11555 | * @param capability The premium capability to check. |
| 11556 | * @param subId The subId to check the premium capability for. |
| 11557 | * |
| 11558 | * @return Whether the given premium capability is available to purchase. |
| 11559 | */ |
| 11560 | @Override |
| 11561 | public boolean isPremiumCapabilityAvailableForPurchase(int capability, int subId) { |
| 11562 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 11563 | mApp, "isPremiumCapabilityAvailableForPurchase")) { |
| 11564 | log("Premium capability " |
| 11565 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 11566 | + " is not available for purchase due to missing permissions."); |
| 11567 | throw new SecurityException("isPremiumCapabilityAvailableForPurchase requires " |
| 11568 | + "permission READ_BASIC_PHONE_STATE."); |
| 11569 | } |
| 11570 | |
| 11571 | Phone phone = getPhone(subId); |
Thomas Nguyen | 7216ed6 | 2022-11-29 16:45:31 -0800 | [diff] [blame] | 11572 | if (phone == null) { |
| 11573 | loge("isPremiumCapabilityAvailableForPurchase: phone is null, subId=" + subId); |
| 11574 | return false; |
| 11575 | } |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 11576 | final long identity = Binder.clearCallingIdentity(); |
| 11577 | try { |
Sarah Chin | 46355ba | 2022-11-01 23:51:16 -0700 | [diff] [blame] | 11578 | return SlicePurchaseController.getInstance(phone) |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 11579 | .isPremiumCapabilityAvailableForPurchase(capability); |
| 11580 | } finally { |
| 11581 | Binder.restoreCallingIdentity(identity); |
| 11582 | } |
| 11583 | } |
| 11584 | |
| 11585 | /** |
| 11586 | * Purchase the given premium capability from the carrier. |
| 11587 | * |
| 11588 | * @param capability The premium capability to purchase. |
| 11589 | * @param callback The result of the purchase request. |
| 11590 | * @param subId The subId to purchase the premium capability for. |
| 11591 | */ |
| 11592 | @Override |
| 11593 | public void purchasePremiumCapability(int capability, IIntegerConsumer callback, int subId) { |
| 11594 | log("purchasePremiumCapability: capability=" |
| 11595 | + TelephonyManager.convertPremiumCapabilityToString(capability) + ", caller=" |
| 11596 | + getCurrentPackageName()); |
| 11597 | |
| 11598 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 11599 | mApp, "purchasePremiumCapability")) { |
| 11600 | log("purchasePremiumCapability " |
| 11601 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 11602 | + " failed due to missing permissions."); |
| 11603 | throw new SecurityException("purchasePremiumCapability requires permission " |
| 11604 | + "READ_BASIC_PHONE_STATE."); |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 11605 | } else if (!TelephonyPermissions.checkInternetPermissionNoThrow( |
| 11606 | mApp, "purchasePremiumCapability")) { |
| 11607 | log("purchasePremiumCapability " |
| 11608 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 11609 | + " failed due to missing permissions."); |
| 11610 | throw new SecurityException("purchasePremiumCapability requires permission INTERNET."); |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 11611 | } |
| 11612 | |
| 11613 | Phone phone = getPhone(subId); |
Sarah Chin | 1969411 | 2022-12-06 15:41:37 -0800 | [diff] [blame] | 11614 | if (phone == null) { |
| 11615 | try { |
| 11616 | int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_REQUEST_FAILED; |
| 11617 | callback.accept(result); |
| 11618 | loge("purchasePremiumCapability: phone is null, subId=" + subId); |
| 11619 | } catch (RemoteException e) { |
| 11620 | String logStr = "Purchase premium capability " |
| 11621 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 11622 | + " failed due to RemoteException handling null phone: " + e; |
| 11623 | if (DBG) log(logStr); |
| 11624 | AnomalyReporter.reportAnomaly( |
| 11625 | UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr); |
| 11626 | } |
| 11627 | return; |
| 11628 | } |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 11629 | |
| 11630 | String callingProcess; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 11631 | try { |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 11632 | callingProcess = mApp.getPackageManager().getApplicationInfo( |
| 11633 | getCurrentPackageName(), 0).processName; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 11634 | } catch (PackageManager.NameNotFoundException e) { |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 11635 | callingProcess = getCurrentPackageName(); |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 11636 | } |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 11637 | |
| 11638 | boolean isVisible = false; |
| 11639 | ActivityManager am = mApp.getSystemService(ActivityManager.class); |
| 11640 | if (am != null) { |
| 11641 | List<ActivityManager.RunningAppProcessInfo> processes = am.getRunningAppProcesses(); |
| 11642 | if (processes != null) { |
| 11643 | for (ActivityManager.RunningAppProcessInfo process : processes) { |
| 11644 | log("purchasePremiumCapability: process " + process.processName |
| 11645 | + "has importance " + process.importance); |
| 11646 | if (process.processName.equals(callingProcess) && process.importance |
| 11647 | <= ActivityManager.RunningAppProcessInfo.IMPORTANCE_VISIBLE) { |
| 11648 | isVisible = true; |
| 11649 | break; |
| 11650 | } |
| 11651 | } |
| 11652 | } |
| 11653 | } |
| 11654 | |
| 11655 | if (!isVisible) { |
| 11656 | try { |
| 11657 | int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_NOT_FOREGROUND; |
| 11658 | callback.accept(result); |
| 11659 | loge("purchasePremiumCapability: " + callingProcess + " is not in the foreground."); |
| 11660 | } catch (RemoteException e) { |
| 11661 | String logStr = "Purchase premium capability " |
| 11662 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 11663 | + " failed due to RemoteException handling background application: " + e; |
| 11664 | if (DBG) log(logStr); |
| 11665 | AnomalyReporter.reportAnomaly( |
| 11666 | UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr); |
| 11667 | } |
| 11668 | return; |
| 11669 | } |
| 11670 | |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 11671 | sendRequestAsync(CMD_PURCHASE_PREMIUM_CAPABILITY, |
Sarah Chin | b8218c2 | 2023-01-04 13:35:29 -0800 | [diff] [blame] | 11672 | new PurchasePremiumCapabilityArgument(capability, callback), phone, null); |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 11673 | } |
| 11674 | |
| 11675 | /** |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 11676 | * Register an IMS connection state callback |
| 11677 | */ |
| 11678 | @Override |
Hunsuk Choi | 89bd22c | 2021-11-01 13:04:54 +0000 | [diff] [blame] | 11679 | public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb, |
| 11680 | String callingPackage) { |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 11681 | if (feature == ImsFeature.FEATURE_MMTEL) { |
| 11682 | // ImsMmTelManager |
| 11683 | // The following also checks READ_PRIVILEGED_PHONE_STATE. |
| 11684 | TelephonyPermissions |
| 11685 | .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 11686 | mApp, subId, "registerImsStateCallback"); |
| 11687 | } else if (feature == ImsFeature.FEATURE_RCS) { |
| 11688 | // ImsRcsManager or SipDelegateManager |
| 11689 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 11690 | Binder.getCallingUid(), "registerImsStateCallback", |
| 11691 | Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
| 11692 | Manifest.permission.READ_PRECISE_PHONE_STATE, |
| 11693 | Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE, |
| 11694 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
| 11695 | } |
| 11696 | |
| 11697 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 11698 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 11699 | "IMS not available on device."); |
| 11700 | } |
| 11701 | |
| 11702 | if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) { |
| 11703 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 11704 | } |
| 11705 | |
| 11706 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 11707 | if (controller == null) { |
| 11708 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 11709 | "IMS not available on device."); |
| 11710 | } |
| 11711 | |
Hunsuk Choi | 89bd22c | 2021-11-01 13:04:54 +0000 | [diff] [blame] | 11712 | if (callingPackage == null) { |
| 11713 | callingPackage = getCurrentPackageName(); |
| 11714 | } |
| 11715 | |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 11716 | final long token = Binder.clearCallingIdentity(); |
| 11717 | try { |
| 11718 | int slotId = getSlotIndexOrException(subId); |
Hunsuk Choi | 89bd22c | 2021-11-01 13:04:54 +0000 | [diff] [blame] | 11719 | controller.registerImsStateCallback(subId, feature, cb, callingPackage); |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 11720 | } catch (ImsException e) { |
| 11721 | throw new ServiceSpecificException(e.getCode()); |
| 11722 | } finally { |
| 11723 | Binder.restoreCallingIdentity(token); |
| 11724 | } |
| 11725 | } |
| 11726 | |
| 11727 | /** |
| 11728 | * Unregister an IMS connection state callback |
| 11729 | */ |
| 11730 | @Override |
| 11731 | public void unregisterImsStateCallback(IImsStateCallback cb) { |
| 11732 | final long token = Binder.clearCallingIdentity(); |
| 11733 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 11734 | if (controller == null) { |
| 11735 | return; |
| 11736 | } |
| 11737 | try { |
| 11738 | controller.unregisterImsStateCallback(cb); |
| 11739 | } finally { |
| 11740 | Binder.restoreCallingIdentity(token); |
| 11741 | } |
| 11742 | } |
Sooraj Sasindran | fae41b3 | 2021-10-26 02:10:05 -0700 | [diff] [blame] | 11743 | |
| 11744 | /** |
| 11745 | * @return {@CellIdentity} last known cell identity {@CellIdentity}. |
| 11746 | * |
| 11747 | * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and |
| 11748 | * com.android.phone.permission.ACCESS_LAST_KNOWN_CELL_ID, otherwise throws |
| 11749 | * SecurityException. |
| 11750 | * If there is current registered network this value will be same as the registered cell |
| 11751 | * identity. If the device goes out of service the previous cell identity is cached and |
| 11752 | * will be returned. If the cache age of the Cell identity is more than 24 hours |
| 11753 | * it will be cleared and null will be returned. |
| 11754 | * |
| 11755 | */ |
| 11756 | @Override |
| 11757 | public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage, |
| 11758 | String callingFeatureId) { |
| 11759 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 11760 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 11761 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 11762 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 11763 | .setCallingPackage(callingPackage) |
| 11764 | .setCallingFeatureId(callingFeatureId) |
| 11765 | .setCallingPid(Binder.getCallingPid()) |
| 11766 | .setCallingUid(Binder.getCallingUid()) |
| 11767 | .setMethod("getLastKnownCellIdentity") |
| 11768 | .setLogAsInfo(true) |
| 11769 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 11770 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 11771 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 11772 | .build()); |
| 11773 | |
| 11774 | boolean hasFinePermission = |
| 11775 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 11776 | if (!hasFinePermission |
| 11777 | || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) { |
| 11778 | throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION " |
Rambo Wang | 918993a | 2022-04-27 09:08:36 -0700 | [diff] [blame] | 11779 | + "and ACCESS_LAST_KNOWN_CELL_ID permission."); |
Sooraj Sasindran | fae41b3 | 2021-10-26 02:10:05 -0700 | [diff] [blame] | 11780 | } |
| 11781 | |
| 11782 | final long identity = Binder.clearCallingIdentity(); |
| 11783 | try { |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 11784 | ServiceStateTracker sst = getPhoneFromSubIdOrDefault(subId).getServiceStateTracker(); |
Sooraj Sasindran | fae41b3 | 2021-10-26 02:10:05 -0700 | [diff] [blame] | 11785 | if (sst == null) return null; |
| 11786 | return sst.getLastKnownCellIdentity(); |
| 11787 | } finally { |
| 11788 | Binder.restoreCallingIdentity(identity); |
| 11789 | } |
| 11790 | } |
Jack Yu | 4c0a550 | 2021-12-03 23:58:26 -0800 | [diff] [blame] | 11791 | |
jimsun | 3b9ccac | 2021-10-26 15:01:23 +0800 | [diff] [blame] | 11792 | /** |
| 11793 | * Sets the modem service class Name that Telephony will bind to. |
| 11794 | * |
| 11795 | * @param serviceName The class name of the modem service. |
| 11796 | * @return true if the operation is succeed, otherwise false. |
| 11797 | */ |
| 11798 | public boolean setModemService(String serviceName) { |
| 11799 | Log.d(LOG_TAG, "setModemService - " + serviceName); |
| 11800 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService"); |
| 11801 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 11802 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 11803 | "setModemService"); |
jimsun | 3b9ccac | 2021-10-26 15:01:23 +0800 | [diff] [blame] | 11804 | return mPhoneConfigurationManager.setModemService(serviceName); |
| 11805 | } |
| 11806 | |
| 11807 | /** |
| 11808 | * Return the class name of the currently bounded modem service. |
| 11809 | * |
| 11810 | * @return the class name of the modem service. |
| 11811 | */ |
| 11812 | public String getModemService() { |
| 11813 | String result; |
| 11814 | Log.d(LOG_TAG, "getModemService"); |
| 11815 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService"); |
| 11816 | TelephonyPermissions |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 11817 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
jimsun | 3b9ccac | 2021-10-26 15:01:23 +0800 | [diff] [blame] | 11818 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 11819 | "getModemService"); |
| 11820 | result = mPhoneConfigurationManager.getModemService(); |
| 11821 | Log.d(LOG_TAG, "result = " + result); |
| 11822 | return result; |
| 11823 | } |
Hunter Knepshield | 2b076fa | 2022-01-19 02:26:22 -0800 | [diff] [blame] | 11824 | |
| 11825 | @Override |
| 11826 | public void setVoiceServiceStateOverride(int subId, boolean hasService, String callingPackage) { |
| 11827 | // Only telecom (and shell, for CTS purposes) is allowed to call this method. |
| 11828 | mApp.enforceCallingOrSelfPermission( |
| 11829 | permission.BIND_TELECOM_CONNECTION_SERVICE, "setVoiceServiceStateOverride"); |
| 11830 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 11831 | |
| 11832 | final long identity = Binder.clearCallingIdentity(); |
| 11833 | try { |
| 11834 | Phone phone = getPhone(subId); |
| 11835 | if (phone == null) return; |
Grant Menke | 63ade12 | 2023-01-20 14:31:54 -0800 | [diff] [blame] | 11836 | Log.i(LOG_TAG, "setVoiceServiceStateOverride: subId=" + subId + ", phone=" + phone |
| 11837 | + ", hasService=" + hasService + ", callingPackage=" + callingPackage); |
Hunter Knepshield | 2b076fa | 2022-01-19 02:26:22 -0800 | [diff] [blame] | 11838 | phone.setVoiceServiceStateOverride(hasService); |
| 11839 | } finally { |
| 11840 | Binder.restoreCallingIdentity(identity); |
| 11841 | } |
| 11842 | } |
Muralidhar Reddy | 4e5a801 | 2022-05-11 14:49:00 +0000 | [diff] [blame] | 11843 | |
| 11844 | /** |
| 11845 | * set removable eSIM as default eUICC. |
| 11846 | * |
| 11847 | * @hide |
| 11848 | */ |
| 11849 | @Override |
| 11850 | public void setRemovableEsimAsDefaultEuicc(boolean isDefault, String callingPackage) { |
| 11851 | enforceModifyPermission(); |
| 11852 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 11853 | |
| 11854 | final long identity = Binder.clearCallingIdentity(); |
| 11855 | try { |
| 11856 | UiccController.getInstance().setRemovableEsimAsDefaultEuicc(isDefault); |
| 11857 | } finally { |
| 11858 | Binder.restoreCallingIdentity(identity); |
| 11859 | } |
| 11860 | } |
| 11861 | |
| 11862 | /** |
| 11863 | * Returns whether the removable eSIM is default eUICC or not. |
| 11864 | * |
| 11865 | * @hide |
| 11866 | */ |
| 11867 | @Override |
| 11868 | public boolean isRemovableEsimDefaultEuicc(String callingPackage) { |
| 11869 | enforceReadPrivilegedPermission("isRemovableEsimDefaultEuicc"); |
| 11870 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 11871 | |
| 11872 | final long identity = Binder.clearCallingIdentity(); |
| 11873 | try { |
| 11874 | return UiccController.getInstance().isRemovableEsimDefaultEuicc(); |
| 11875 | } finally { |
| 11876 | Binder.restoreCallingIdentity(identity); |
| 11877 | } |
| 11878 | } |
| 11879 | |
Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame] | 11880 | /** |
| 11881 | * Get the component name of the default app to direct respond-via-message intent for the |
| 11882 | * user associated with this subscription, update the cache if there is no respond-via-message |
| 11883 | * application currently configured for this user. |
| 11884 | * @return component name of the app and class to direct Respond Via Message intent to, or |
| 11885 | * {@code null} if the functionality is not supported. |
| 11886 | * @hide |
| 11887 | */ |
| 11888 | @Override |
| 11889 | public @Nullable ComponentName getDefaultRespondViaMessageApplication(int subId, |
| 11890 | boolean updateIfNeeded) { |
| 11891 | enforceInteractAcrossUsersPermission("getDefaultRespondViaMessageApplication"); |
Muralidhar Reddy | 4e5a801 | 2022-05-11 14:49:00 +0000 | [diff] [blame] | 11892 | |
Aishwarya Mallampati | 5e581e1 | 2023-01-17 21:57:06 +0000 | [diff] [blame] | 11893 | Context context = getPhoneFromSubIdOrDefault(subId).getContext(); |
| 11894 | |
Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame] | 11895 | UserHandle userHandle = null; |
| 11896 | final long identity = Binder.clearCallingIdentity(); |
| 11897 | try { |
| 11898 | userHandle = TelephonyUtils.getSubscriptionUserHandle(context, subId); |
| 11899 | } finally { |
| 11900 | Binder.restoreCallingIdentity(identity); |
| 11901 | } |
| 11902 | return SmsApplication.getDefaultRespondViaMessageApplicationAsUser(context, |
| 11903 | updateIfNeeded, userHandle); |
| 11904 | } |
Jack Yu | f5badd9 | 2022-12-08 00:50:53 -0800 | [diff] [blame] | 11905 | |
| 11906 | /** |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 11907 | * Set whether the device is able to connect with null ciphering or integrity |
| 11908 | * algorithms. This is a global setting and will apply to all active subscriptions |
| 11909 | * and all new subscriptions after this. |
| 11910 | * |
| 11911 | * @param enabled when true, null cipher and integrity algorithms are allowed. |
| 11912 | * @hide |
| 11913 | */ |
| 11914 | @Override |
| 11915 | @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 11916 | public void setNullCipherAndIntegrityEnabled(boolean enabled) { |
| 11917 | enforceModifyPermission(); |
| 11918 | checkForNullCipherAndIntegritySupport(); |
| 11919 | |
| 11920 | // Persist the state of our preference. Each GsmCdmaPhone instance is responsible |
| 11921 | // for listening to these preference changes and applying them immediately. |
| 11922 | SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 11923 | editor.putBoolean(Phone.PREF_NULL_CIPHER_AND_INTEGRITY_ENABLED, enabled); |
| 11924 | editor.apply(); |
| 11925 | |
| 11926 | for (Phone phone: PhoneFactory.getPhones()) { |
| 11927 | phone.handleNullCipherEnabledChange(); |
| 11928 | } |
| 11929 | } |
| 11930 | |
| 11931 | |
| 11932 | /** |
| 11933 | * Get whether the device is able to connect with null ciphering or integrity |
| 11934 | * algorithms. Note that this retrieves the phone-global preference and not |
| 11935 | * the state of the radio. |
| 11936 | * |
| 11937 | * @throws SecurityException if {@link permission#MODIFY_PHONE_STATE} is not satisfied |
| 11938 | * @throws UnsupportedOperationException if the device does not support the minimum HAL |
| 11939 | * version for this feature. |
| 11940 | * @hide |
| 11941 | */ |
| 11942 | @Override |
| 11943 | @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) |
| 11944 | public boolean isNullCipherAndIntegrityPreferenceEnabled() { |
| 11945 | enforceReadPermission(); |
| 11946 | checkForNullCipherAndIntegritySupport(); |
| 11947 | return getDefaultPhone().getNullCipherAndIntegrityEnabledPreference(); |
| 11948 | } |
| 11949 | |
| 11950 | private void checkForNullCipherAndIntegritySupport() { |
| 11951 | if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_NULL_CIPHER_AND_INTEGRITY_VERSION) { |
| 11952 | throw new UnsupportedOperationException( |
| 11953 | "Null cipher and integrity operations require HAL 2.1 or above"); |
| 11954 | } |
Gil Cukierman | 92cc7db | 2023-01-06 19:25:53 +0000 | [diff] [blame] | 11955 | if (!getDefaultPhone().isNullCipherAndIntegritySupported()) { |
| 11956 | throw new UnsupportedOperationException( |
| 11957 | "Null cipher and integrity operations unsupported by modem"); |
| 11958 | } |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 11959 | } |
| 11960 | |
| 11961 | /** |
Jack Yu | f5badd9 | 2022-12-08 00:50:53 -0800 | [diff] [blame] | 11962 | * Get the SIM state for the slot index. |
| 11963 | * For Remote-SIMs, this method returns {@link IccCardConstants.State#UNKNOWN} |
| 11964 | * |
| 11965 | * @return SIM state as the ordinal of {@link IccCardConstants.State} |
| 11966 | */ |
| 11967 | @Override |
| 11968 | @SimState |
| 11969 | public int getSimStateForSlotIndex(int slotIndex) { |
| 11970 | IccCardConstants.State simState; |
| 11971 | if (slotIndex < 0) { |
| 11972 | simState = IccCardConstants.State.UNKNOWN; |
| 11973 | } else { |
| 11974 | Phone phone = null; |
| 11975 | try { |
| 11976 | phone = PhoneFactory.getPhone(slotIndex); |
| 11977 | } catch (IllegalStateException e) { |
| 11978 | // ignore |
| 11979 | } |
| 11980 | if (phone == null) { |
| 11981 | simState = IccCardConstants.State.UNKNOWN; |
| 11982 | } else { |
| 11983 | IccCard icc = phone.getIccCard(); |
| 11984 | if (icc == null) { |
| 11985 | simState = IccCardConstants.State.UNKNOWN; |
| 11986 | } else { |
| 11987 | simState = icc.getState(); |
| 11988 | } |
| 11989 | } |
| 11990 | } |
| 11991 | return simState.ordinal(); |
| 11992 | } |
Hui Wang | 9b5793a | 2022-12-05 14:38:06 -0600 | [diff] [blame] | 11993 | |
Chinmay Dhodapkar | 3e11ced | 2023-03-03 19:44:00 -0800 | [diff] [blame] | 11994 | private void persistEmergencyCallDiagnosticDataInternal(@NonNull String dropboxTag, |
| 11995 | boolean enableLogcat, |
| 11996 | long logcatStartTimestampMillis, boolean enableTelecomDump, |
| 11997 | boolean enableTelephonyDump) { |
Chinmay Dhodapkar | 66262c4 | 2023-03-10 15:47:41 -0800 | [diff] [blame] | 11998 | DropBoxManager db = mApp.getSystemService(DropBoxManager.class); |
| 11999 | TelephonyManager.EmergencyCallDiagnosticParams edp = |
| 12000 | new TelephonyManager.EmergencyCallDiagnosticParams(); |
| 12001 | edp.setLogcatCollection(enableLogcat, logcatStartTimestampMillis); |
| 12002 | edp.setTelephonyDumpSysCollection(enableTelephonyDump); |
| 12003 | edp.setTelecomDumpSysCollection(enableTelecomDump); |
| 12004 | Log.d(LOG_TAG, "persisting with Params " + edp.toString()); |
| 12005 | DiagnosticDataCollector ddc = new DiagnosticDataCollector(Runtime.getRuntime(), |
| 12006 | Executors.newCachedThreadPool(), db, |
| 12007 | mApp.getSystemService(ActivityManager.class).isLowRamDevice()); |
| 12008 | ddc.persistEmergencyDianosticData(new DataCollectorConfig.Adapter(), edp, dropboxTag); |
Chinmay Dhodapkar | 3e11ced | 2023-03-03 19:44:00 -0800 | [diff] [blame] | 12009 | } |
| 12010 | |
| 12011 | /** |
| 12012 | * Request telephony to persist state for debugging emergency call failures. |
| 12013 | * |
| 12014 | * @param dropBoxTag Tag to use when persisting data to dropbox service. |
| 12015 | * @param enableLogcat whether to collect logcat output |
| 12016 | * @param logcatStartTimestampMillis timestamp from when logcat buffers would be persisted |
| 12017 | * @param enableTelecomDump whether to collect telecom dumpsys |
| 12018 | * @param enableTelephonyDump whether to collect telephony dumpsys |
| 12019 | */ |
| 12020 | @Override |
| 12021 | @RequiresPermission(android.Manifest.permission.DUMP) |
| 12022 | public void persistEmergencyCallDiagnosticData(@NonNull String dropboxTag, boolean enableLogcat, |
| 12023 | long logcatStartTimestampMillis, boolean enableTelecomDump, |
| 12024 | boolean enableTelephonyDump) { |
| 12025 | mApp.enforceCallingPermission(android.Manifest.permission.DUMP, |
| 12026 | "persistEmergencyCallDiagnosticData"); |
| 12027 | final long identity = Binder.clearCallingIdentity(); |
| 12028 | try { |
| 12029 | persistEmergencyCallDiagnosticDataInternal(dropboxTag, enableLogcat, |
| 12030 | logcatStartTimestampMillis, enableTelecomDump, enableTelephonyDump); |
| 12031 | |
| 12032 | } finally { |
| 12033 | Binder.restoreCallingIdentity(identity); |
| 12034 | } |
| 12035 | } |
| 12036 | |
Hui Wang | 9b5793a | 2022-12-05 14:38:06 -0600 | [diff] [blame] | 12037 | /** |
| 12038 | * Get current cell broadcast ranges. |
| 12039 | */ |
| 12040 | @Override |
| 12041 | @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS) |
| 12042 | public List<CellBroadcastIdRange> getCellBroadcastIdRanges(int subId) { |
| 12043 | mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS, |
| 12044 | "getCellBroadcastIdRanges"); |
| 12045 | final long identity = Binder.clearCallingIdentity(); |
| 12046 | try { |
| 12047 | return getPhone(subId).getCellBroadcastIdRanges(); |
| 12048 | } finally { |
| 12049 | Binder.restoreCallingIdentity(identity); |
| 12050 | } |
| 12051 | } |
| 12052 | |
| 12053 | /** |
| 12054 | * Set reception of cell broadcast messages with the list of the given ranges |
| 12055 | * |
| 12056 | * @param ranges the list of {@link CellBroadcastIdRange} to be enabled |
| 12057 | */ |
| 12058 | @Override |
| 12059 | @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS) |
| 12060 | public void setCellBroadcastIdRanges(int subId, @NonNull List<CellBroadcastIdRange> ranges, |
| 12061 | @Nullable IIntegerConsumer callback) { |
| 12062 | mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS, |
| 12063 | "setCellBroadcastIdRanges"); |
| 12064 | final long identity = Binder.clearCallingIdentity(); |
| 12065 | try { |
| 12066 | Phone phone = getPhoneFromSubId(subId); |
| 12067 | if (DBG) { |
| 12068 | log("setCellBroadcastIdRanges for subId :" + subId + ", phone:" + phone); |
| 12069 | } |
| 12070 | phone.setCellBroadcastIdRanges(ranges, result -> { |
| 12071 | if (callback != null) { |
| 12072 | try { |
| 12073 | callback.accept(result); |
| 12074 | } catch (RemoteException e) { |
| 12075 | Log.w(LOG_TAG, "setCellBroadcastIdRanges: callback not available."); |
| 12076 | } |
| 12077 | } |
| 12078 | }); |
| 12079 | } finally { |
| 12080 | Binder.restoreCallingIdentity(identity); |
| 12081 | } |
| 12082 | } |
Hunsuk Choi | 42cc62a | 2022-10-16 06:03:40 +0000 | [diff] [blame] | 12083 | |
| 12084 | /** |
| 12085 | * Returns whether the device supports the domain selection service. |
| 12086 | * |
| 12087 | * @return {@code true} if the device supports the domain selection service. |
| 12088 | */ |
| 12089 | @Override |
| 12090 | public boolean isDomainSelectionSupported() { |
| 12091 | mApp.enforceCallingOrSelfPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
| 12092 | "isDomainSelectionSupported"); |
| 12093 | |
| 12094 | final long identity = Binder.clearCallingIdentity(); |
| 12095 | try { |
| 12096 | return DomainSelectionResolver.getInstance().isDomainSelectionSupported(); |
| 12097 | } finally { |
| 12098 | Binder.restoreCallingIdentity(identity); |
| 12099 | } |
| 12100 | } |
arunvoddu | d5c6ce0 | 2022-12-11 06:03:12 +0000 | [diff] [blame] | 12101 | |
| 12102 | /** |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 12103 | * Request to enable or disable the satellite modem and demo mode. If the satellite modem is |
| 12104 | * enabled, this may also disable the cellular modem, and if the satellite modem is disabled, |
| 12105 | * this may also re-enable the cellular modem. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12106 | * |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12107 | * @param subId The subId of the subscription to set satellite enabled for. |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 12108 | * @param enableSatellite {@code true} to enable the satellite modem and |
| 12109 | * {@code false} to disable. |
| 12110 | * @param enableDemoMode {@code true} to enable demo mode and {@code false} to disable. |
| 12111 | * @param callback The callback to get the result of the request. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12112 | * |
| 12113 | * @throws SecurityException if the caller doesn't have the required permission. |
| 12114 | */ |
| 12115 | @Override |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 12116 | public void requestSatelliteEnabled(int subId, boolean enableSatellite, boolean enableDemoMode, |
| 12117 | @NonNull IIntegerConsumer callback) { |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 12118 | enforceSatelliteCommunicationPermission("requestSatelliteEnabled"); |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 12119 | mSatelliteController.requestSatelliteEnabled(subId, enableSatellite, enableDemoMode, |
| 12120 | callback); |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12121 | } |
| 12122 | |
| 12123 | /** |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12124 | * Request to get whether the satellite modem is enabled. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12125 | * |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12126 | * @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] | 12127 | * @param result The result receiver that returns whether the satellite modem is enabled |
| 12128 | * 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] | 12129 | * |
| 12130 | * @throws SecurityException if the caller doesn't have the required permission. |
| 12131 | */ |
| 12132 | @Override |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12133 | public void requestIsSatelliteEnabled(int subId, @NonNull ResultReceiver result) { |
| 12134 | enforceSatelliteCommunicationPermission("requestIsSatelliteEnabled"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 12135 | mSatelliteController.requestIsSatelliteEnabled(subId, result); |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12136 | } |
| 12137 | |
| 12138 | /** |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 12139 | * Request to get whether the satellite service demo mode is enabled. |
| 12140 | * |
| 12141 | * @param subId The subId of the subscription to check whether the satellite demo mode |
| 12142 | * is enabled for. |
| 12143 | * @param result The result receiver that returns whether the satellite demo mode is enabled |
| 12144 | * if the request is successful or an error code if the request failed. |
| 12145 | * |
| 12146 | * @throws SecurityException if the caller doesn't have the required permission. |
| 12147 | */ |
| 12148 | @Override |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 12149 | public void requestIsDemoModeEnabled(int subId, @NonNull ResultReceiver result) { |
| 12150 | enforceSatelliteCommunicationPermission("requestIsDemoModeEnabled"); |
| 12151 | mSatelliteController.requestIsDemoModeEnabled(subId, result); |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 12152 | } |
| 12153 | |
| 12154 | /** |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12155 | * Request to get whether the satellite service is supported on the device. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12156 | * |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12157 | * @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] | 12158 | * @param result The result receiver that returns whether the satellite service is supported on |
| 12159 | * 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] | 12160 | */ |
| 12161 | @Override |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12162 | public void requestIsSatelliteSupported(int subId, @NonNull ResultReceiver result) { |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 12163 | mSatelliteController.requestIsSatelliteSupported(subId, result); |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12164 | } |
| 12165 | |
| 12166 | /** |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12167 | * Request to get the {@link SatelliteCapabilities} of the satellite service. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12168 | * |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12169 | * @param subId The subId of the subscription to get the satellite capabilities for. |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12170 | * @param result The result receiver that returns the {@link SatelliteCapabilities} |
| 12171 | * 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] | 12172 | * |
| 12173 | * @throws SecurityException if the caller doesn't have required permission. |
| 12174 | */ |
| 12175 | @Override |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12176 | public void requestSatelliteCapabilities(int subId, @NonNull ResultReceiver result) { |
| 12177 | enforceSatelliteCommunicationPermission("requestSatelliteCapabilities"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 12178 | mSatelliteController.requestSatelliteCapabilities(subId, result); |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12179 | } |
| 12180 | |
| 12181 | /** |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 12182 | * Start receiving satellite transmission updates. |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 12183 | * This can be called by the pointing UI when the user starts pointing to the satellite. |
| 12184 | * Modem should continue to report the pointing input as the device or satellite moves. |
| 12185 | * |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 12186 | * @param subId The subId of the subscription to start satellite transmission updates for. |
| 12187 | * @param resultCallback The callback to get the result of the request. |
| 12188 | * @param callback The callback to notify of satellite transmission updates. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12189 | * |
| 12190 | * @throws SecurityException if the caller doesn't have the required permission. |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 12191 | */ |
| 12192 | @Override |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 12193 | public void startSatelliteTransmissionUpdates(int subId, |
| 12194 | @NonNull IIntegerConsumer resultCallback, |
| 12195 | @NonNull ISatelliteTransmissionUpdateCallback callback) { |
| 12196 | enforceSatelliteCommunicationPermission("startSatelliteTransmissionUpdates"); |
| 12197 | mSatelliteController.startSatelliteTransmissionUpdates(subId, resultCallback, callback); |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 12198 | } |
| 12199 | |
| 12200 | /** |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 12201 | * Stop receiving satellite transmission updates. |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 12202 | * This can be called by the pointing UI when the user stops pointing to the satellite. |
| 12203 | * |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 12204 | * @param subId The subId of the subscription to stop satellite transmission updates for. |
| 12205 | * @param resultCallback The callback to get the result of the request. |
| 12206 | * @param callback The callback that was passed to {@link #startSatelliteTransmissionUpdates( |
| 12207 | * int, IIntegerConsumer, ISatelliteTransmissionUpdateCallback)}. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12208 | * |
| 12209 | * @throws SecurityException if the caller doesn't have the required permission. |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 12210 | */ |
| 12211 | @Override |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 12212 | public void stopSatelliteTransmissionUpdates(int subId, |
| 12213 | @NonNull IIntegerConsumer resultCallback, |
| 12214 | @NonNull ISatelliteTransmissionUpdateCallback callback) { |
| 12215 | enforceSatelliteCommunicationPermission("stopSatelliteTransmissionUpdates"); |
| 12216 | mSatelliteController.stopSatelliteTransmissionUpdates(subId, resultCallback, callback); |
Aishwarya Mallampati | 60fe113 | 2023-01-24 19:07:21 +0000 | [diff] [blame] | 12217 | } |
| 12218 | |
| 12219 | /** |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12220 | * Register the subscription with a satellite provider. |
| 12221 | * This is needed to register the subscription if the provider allows dynamic registration. |
| 12222 | * |
| 12223 | * @param subId The subId of the subscription to be provisioned. |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame] | 12224 | * @param token The token to be used as a unique identifier for provisioning with satellite |
| 12225 | * gateway. |
Aishwarya Mallampati | 8b2310c | 2023-03-28 22:01:43 +0000 | [diff] [blame] | 12226 | * @param provisionData Data from the provisioning app that can be used by provisioning server |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 12227 | * @param callback The callback to get the result of the request. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12228 | * |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12229 | * @return The signal transport used by the caller to cancel the provision request, |
| 12230 | * or {@code null} if the request failed. |
| 12231 | * |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12232 | * @throws SecurityException if the caller doesn't have the required permission. |
| 12233 | */ |
| 12234 | @Override |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12235 | @Nullable public ICancellationSignal provisionSatelliteService(int subId, |
Aishwarya Mallampati | 8b2310c | 2023-03-28 22:01:43 +0000 | [diff] [blame] | 12236 | @NonNull String token, @NonNull byte[] provisionData, |
| 12237 | @NonNull IIntegerConsumer callback) { |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12238 | enforceSatelliteCommunicationPermission("provisionSatelliteService"); |
Aishwarya Mallampati | 8b2310c | 2023-03-28 22:01:43 +0000 | [diff] [blame] | 12239 | return mSatelliteController.provisionSatelliteService(subId, token, provisionData, |
| 12240 | callback); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12241 | } |
| 12242 | |
| 12243 | /** |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame] | 12244 | * Unregister the device/subscription with the satellite provider. |
| 12245 | * This is needed if the provider allows dynamic registration. Once deprovisioned, |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 12246 | * {@link SatelliteProvisionStateCallback#onSatelliteProvisionStateChanged(boolean)} |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame] | 12247 | * should report as deprovisioned. |
| 12248 | * |
| 12249 | * @param subId The subId of the subscription to be deprovisioned. |
| 12250 | * @param token The token of the device/subscription to be deprovisioned. |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 12251 | * @param callback The callback to get the result of the request. |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame] | 12252 | * |
| 12253 | * @throws SecurityException if the caller doesn't have the required permission. |
| 12254 | */ |
| 12255 | @Override |
| 12256 | public void deprovisionSatelliteService(int subId, |
| 12257 | @NonNull String token, @NonNull IIntegerConsumer callback) { |
| 12258 | enforceSatelliteCommunicationPermission("deprovisionSatelliteService"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 12259 | mSatelliteController.deprovisionSatelliteService(subId, token, callback); |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame] | 12260 | } |
| 12261 | |
| 12262 | /** |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 12263 | * Registers for the satellite provision state changed. |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12264 | * |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 12265 | * @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] | 12266 | * @param callback The callback to handle the satellite provision state changed event. |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12267 | * |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12268 | * @return The {@link SatelliteManager.SatelliteError} result of the operation. |
| 12269 | * |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12270 | * @throws SecurityException if the caller doesn't have the required permission. |
| 12271 | */ |
| 12272 | @Override |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12273 | @SatelliteManager.SatelliteError public int registerForSatelliteProvisionStateChanged(int subId, |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 12274 | @NonNull ISatelliteProvisionStateCallback callback) { |
Thomas Nguyen | e77de6d | 2023-02-10 17:42:43 -0800 | [diff] [blame] | 12275 | enforceSatelliteCommunicationPermission("registerForSatelliteProvisionStateChanged"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 12276 | return mSatelliteController.registerForSatelliteProvisionStateChanged(subId, callback); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12277 | } |
| 12278 | |
| 12279 | /** |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 12280 | * Unregisters for the satellite provision state changed. |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 12281 | * If callback was not registered before, the request will be ignored. |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12282 | * |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 12283 | * @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] | 12284 | * @param callback The callback that was passed to |
| 12285 | * {@link #registerForSatelliteProvisionStateChanged(int, ISatelliteProvisionStateCallback)}. |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12286 | * |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12287 | * @throws SecurityException if the caller doesn't have the required permission. |
| 12288 | */ |
| 12289 | @Override |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 12290 | public void unregisterForSatelliteProvisionStateChanged( |
| 12291 | int subId, @NonNull ISatelliteProvisionStateCallback callback) { |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12292 | enforceSatelliteCommunicationPermission("unregisterForSatelliteProvisionStateChanged"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 12293 | mSatelliteController.unregisterForSatelliteProvisionStateChanged(subId, callback); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12294 | } |
| 12295 | |
| 12296 | /** |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12297 | * Request to get whether the device is provisioned with a satellite provider. |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12298 | * |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12299 | * @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] | 12300 | * @param result The result receiver that returns whether the device is provisioned with a |
| 12301 | * satellite provider if the request is successful or an error code if the |
| 12302 | * request failed. |
| 12303 | * |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12304 | * @throws SecurityException if the caller doesn't have the required permission. |
| 12305 | */ |
| 12306 | @Override |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12307 | public void requestIsSatelliteProvisioned(int subId, @NonNull ResultReceiver result) { |
| 12308 | enforceSatelliteCommunicationPermission("requestIsSatelliteProvisioned"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 12309 | mSatelliteController.requestIsSatelliteProvisioned(subId, result); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12310 | } |
| 12311 | |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 12312 | /** |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 12313 | * Registers for modem state changed from satellite modem. |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 12314 | * |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 12315 | * @param subId The subId of the subscription to register for satellite modem state changed. |
| 12316 | * @param callback The callback to handle the satellite modem state changed event. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12317 | * |
| 12318 | * @return The {@link SatelliteManager.SatelliteError} result of the operation. |
| 12319 | * |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 12320 | * @throws SecurityException if the caller doesn't have the required permission. |
| 12321 | */ |
| 12322 | @Override |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 12323 | @SatelliteManager.SatelliteError public int registerForSatelliteModemStateChanged(int subId, |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 12324 | @NonNull ISatelliteStateCallback callback) { |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 12325 | enforceSatelliteCommunicationPermission("registerForSatelliteModemStateChanged"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 12326 | return mSatelliteController.registerForSatelliteModemStateChanged(subId, callback); |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 12327 | } |
| 12328 | |
| 12329 | /** |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 12330 | * Unregisters for modem state changed from satellite modem. |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 12331 | * If callback was not registered before, the request will be ignored. |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 12332 | * |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 12333 | * @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] | 12334 | * @param callback The callback that was passed to |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 12335 | * {@link #registerForSatelliteModemStateChanged(int, ISatelliteStateCallback)}. |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 12336 | * |
| 12337 | * @throws SecurityException if the caller doesn't have the required permission. |
| 12338 | */ |
| 12339 | @Override |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 12340 | public void unregisterForSatelliteModemStateChanged(int subId, |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 12341 | @NonNull ISatelliteStateCallback callback) { |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 12342 | enforceSatelliteCommunicationPermission("unregisterForSatelliteModemStateChanged"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 12343 | mSatelliteController.unregisterForSatelliteModemStateChanged(subId, callback); |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 12344 | } |
| 12345 | |
| 12346 | /** |
| 12347 | * Register to receive incoming datagrams over satellite. |
| 12348 | * |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12349 | * @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] | 12350 | * @param callback The callback to handle incoming datagrams over satellite. |
| 12351 | * |
| 12352 | * @return The {@link SatelliteManager.SatelliteError} result of the operation. |
| 12353 | * |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 12354 | * @throws SecurityException if the caller doesn't have the required permission. |
| 12355 | */ |
| 12356 | @Override |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12357 | @SatelliteManager.SatelliteError public int registerForSatelliteDatagram(int subId, |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 12358 | @NonNull ISatelliteDatagramCallback callback) { |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 12359 | enforceSatelliteCommunicationPermission("registerForSatelliteDatagram"); |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 12360 | return mSatelliteController.registerForSatelliteDatagram(subId, callback); |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 12361 | } |
| 12362 | |
| 12363 | /** |
| 12364 | * Unregister to stop receiving incoming datagrams over satellite. |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 12365 | * If callback was not registered before, the request will be ignored. |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 12366 | * |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12367 | * @param subId The subId of the subscription to unregister for incoming satellite datagrams. |
| 12368 | * @param callback The callback that was passed to |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 12369 | * {@link #registerForSatelliteDatagram(int, ISatelliteDatagramCallback)}. |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 12370 | * |
| 12371 | * @throws SecurityException if the caller doesn't have the required permission. |
| 12372 | */ |
| 12373 | @Override |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 12374 | public void unregisterForSatelliteDatagram(int subId, |
| 12375 | @NonNull ISatelliteDatagramCallback callback) { |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 12376 | enforceSatelliteCommunicationPermission("unregisterForSatelliteDatagram"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 12377 | mSatelliteController.unregisterForSatelliteDatagram(subId, callback); |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 12378 | } |
| 12379 | |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 12380 | /** |
| 12381 | * Poll pending satellite datagrams over satellite. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12382 | * |
Aishwarya Mallampati | 224317a | 2023-02-13 22:09:30 +0000 | [diff] [blame] | 12383 | * This method requests modem to check if there are any pending datagrams to be received over |
| 12384 | * satellite. If there are any incoming datagrams, they will be received via |
Aishwarya Mallampati | 0a78dfb | 2023-03-28 20:29:26 +0000 | [diff] [blame] | 12385 | * {@link SatelliteDatagramCallback#onSatelliteDatagramReceived(long, SatelliteDatagram, int, Consumer)})} |
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 | /** |
Hakjun Choi | ae36597 | 2023-04-25 11:00:31 +0000 | [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 | |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12460 | /** |
Hakjun Choi | ae36597 | 2023-04-25 11:00:31 +0000 | [diff] [blame] | 12461 | * Inform that Device is aligned to satellite for demo mode. |
| 12462 | * |
| 12463 | * @param subId The subId to get the time after which the satellite will be visible for. |
| 12464 | * @param isAligned {@code true} Device is aligned with the satellite for demo mode |
| 12465 | * {@code false} Device fails to align with the satellite for demo mode. |
| 12466 | * |
| 12467 | * @throws SecurityException if the caller doesn't have required permission. |
| 12468 | */ |
| 12469 | @RequiresPermission(Manifest.permission.SATELLITE_COMMUNICATION) |
| 12470 | |
| 12471 | public void onDeviceAlignedWithSatellite(int subId, @NonNull boolean isAligned) { |
| 12472 | enforceSatelliteCommunicationPermission("informDeviceAlignedToSatellite"); |
| 12473 | mSatelliteController.onDeviceAlignedWithSatellite(subId, isAligned); |
| 12474 | } |
| 12475 | |
| 12476 | /** |
Thomas Nguyen | d34a5fc | 2023-03-23 21:07:03 -0700 | [diff] [blame] | 12477 | * This API can be used by only CTS to update satellite vendor service package name. |
| 12478 | * |
| 12479 | * @param servicePackageName The package name of the satellite vendor service. |
| 12480 | * @return {@code true} if the satellite vendor service is set successfully, |
| 12481 | * {@code false} otherwise. |
| 12482 | */ |
| 12483 | public boolean setSatelliteServicePackageName(String servicePackageName) { |
| 12484 | Log.d(LOG_TAG, "setSatelliteServicePackageName - " + servicePackageName); |
| 12485 | TelephonyPermissions.enforceShellOnly( |
| 12486 | Binder.getCallingUid(), "setSatelliteServicePackageName"); |
| 12487 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 12488 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 12489 | "setSatelliteServicePackageName"); |
| 12490 | return mSatelliteController.setSatelliteServicePackageName(servicePackageName); |
| 12491 | } |
| 12492 | |
| 12493 | /** |
Thomas Nguyen | 1854a5a | 2023-04-04 09:31:47 -0700 | [diff] [blame] | 12494 | * This API can be used by only CTS to update satellite gateway service package name. |
| 12495 | * |
| 12496 | * @param servicePackageName The package name of the satellite gateway service. |
| 12497 | * @return {@code true} if the satellite gateway service is set successfully, |
| 12498 | * {@code false} otherwise. |
| 12499 | */ |
| 12500 | public boolean setSatelliteGatewayServicePackageName(@Nullable String servicePackageName) { |
| 12501 | Log.d(LOG_TAG, "setSatelliteGatewayServicePackageName - " + servicePackageName); |
| 12502 | TelephonyPermissions.enforceShellOnly( |
| 12503 | Binder.getCallingUid(), "setSatelliteGatewayServicePackageName"); |
| 12504 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 12505 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 12506 | "setSatelliteGatewayServicePackageName"); |
| 12507 | return mSatelliteController.setSatelliteGatewayServicePackageName(servicePackageName); |
| 12508 | } |
| 12509 | |
| 12510 | /** |
Thomas Nguyen | 87dce73 | 2023-04-20 18:27:16 -0700 | [diff] [blame] | 12511 | * This API can be used by only CTS to update satellite pointing UI app package and class names. |
| 12512 | * |
| 12513 | * @param packageName The package name of the satellite pointing UI app. |
| 12514 | * @param className The class name of the satellite pointing UI app. |
| 12515 | * @return {@code true} if the satellite pointing UI app package and class is set successfully, |
| 12516 | * {@code false} otherwise. |
| 12517 | */ |
| 12518 | public boolean setSatellitePointingUiClassName( |
| 12519 | @Nullable String packageName, @Nullable String className) { |
| 12520 | Log.d(LOG_TAG, "setSatellitePointingUiClassName: packageName=" + packageName |
| 12521 | + ", className=" + className); |
| 12522 | TelephonyPermissions.enforceShellOnly( |
| 12523 | Binder.getCallingUid(), "setSatellitePointingUiClassName"); |
| 12524 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 12525 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 12526 | "setSatelliteGatewayServicePackageName"); |
| 12527 | return mSatelliteController.setSatellitePointingUiClassName(packageName, className); |
| 12528 | } |
| 12529 | |
| 12530 | /** |
Thomas Nguyen | f9a533c | 2023-04-06 20:48:41 -0700 | [diff] [blame] | 12531 | * This API can be used by only CTS to update the timeout duration in milliseconds that |
| 12532 | * satellite should stay at listening mode to wait for the next incoming page before disabling |
| 12533 | * listening mode. |
| 12534 | * |
| 12535 | * @param timeoutMillis The timeout duration in millisecond. |
| 12536 | * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise. |
| 12537 | */ |
| 12538 | public boolean setSatelliteListeningTimeoutDuration(long timeoutMillis) { |
| 12539 | Log.d(LOG_TAG, "setSatelliteListeningTimeoutDuration - " + timeoutMillis); |
| 12540 | TelephonyPermissions.enforceShellOnly( |
| 12541 | Binder.getCallingUid(), "setSatelliteListeningTimeoutDuration"); |
| 12542 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 12543 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 12544 | "setSatelliteListeningTimeoutDuration"); |
| 12545 | return mSatelliteController.setSatelliteListeningTimeoutDuration(timeoutMillis); |
| 12546 | } |
| 12547 | |
| 12548 | /** |
Hakjun Choi | ae36597 | 2023-04-25 11:00:31 +0000 | [diff] [blame] | 12549 | * This API can be used by only CTS to update the timeout duration in milliseconds whether |
| 12550 | * the device is aligned with the satellite for demo mode |
| 12551 | * |
| 12552 | * @param timeoutMillis The timeout duration in millisecond. |
| 12553 | * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise. |
| 12554 | */ |
| 12555 | public boolean setSatelliteDeviceAlignedTimeoutDuration(long timeoutMillis) { |
| 12556 | Log.d(LOG_TAG, "setDeviceAlignedTimeoutDuration - " + timeoutMillis); |
| 12557 | TelephonyPermissions.enforceShellOnly( |
| 12558 | Binder.getCallingUid(), "setDeviceAlignedTimeoutDuration"); |
| 12559 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 12560 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 12561 | "setDeviceAlignedTimeoutDuration"); |
| 12562 | return mSatelliteController.setSatelliteDeviceAlignedTimeoutDuration(timeoutMillis); |
| 12563 | } |
| 12564 | |
| 12565 | /** |
arunvoddu | d5c6ce0 | 2022-12-11 06:03:12 +0000 | [diff] [blame] | 12566 | * Check whether the caller (or self, if not processing an IPC) can read device identifiers. |
| 12567 | * |
| 12568 | * <p>This method behaves in one of the following ways: |
| 12569 | * <ul> |
| 12570 | * <li>return true : if the calling package has the appop permission {@link |
| 12571 | * Manifest.permission#USE_ICC_AUTH_WITH_DEVICE_IDENTIFIER} in the manifest </> |
| 12572 | * <li>return true : if any one subscription has the READ_PRIVILEGED_PHONE_STATE |
| 12573 | * permission, the calling package passes a DevicePolicyManager Device Owner / Profile |
| 12574 | * Owner device identifier access check, or the calling package has carrier privileges</> |
| 12575 | * <li>throw SecurityException: if the caller does not meet any of the requirements. |
| 12576 | * </ul> |
| 12577 | */ |
| 12578 | private static boolean checkCallingOrSelfReadDeviceIdentifiersForAnySub(Context context, |
| 12579 | String callingPackage, @Nullable String callingFeatureId, String message) { |
| 12580 | for (Phone phone : PhoneFactory.getPhones()) { |
| 12581 | if (TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(context, |
| 12582 | phone.getSubId(), callingPackage, callingFeatureId, message)) { |
| 12583 | return true; |
| 12584 | } |
| 12585 | } |
| 12586 | return false; |
| 12587 | } |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 12588 | |
| 12589 | /** |
Jack Yu | fa8ed01 | 2023-02-11 15:42:28 -0800 | [diff] [blame] | 12590 | * @return The subscription manager service instance. |
| 12591 | */ |
| 12592 | public SubscriptionManagerService getSubscriptionManagerService() { |
| 12593 | return SubscriptionManagerService.getInstance(); |
| 12594 | } |
| 12595 | |
| 12596 | /** |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 12597 | * Class binds the consumer[callback] and carrierId. |
| 12598 | */ |
| 12599 | private static class CallerCallbackInfo { |
| 12600 | private final Consumer<Integer> mConsumer; |
| 12601 | private final int mCarrierId; |
| 12602 | |
| 12603 | public CallerCallbackInfo(Consumer<Integer> consumer, int carrierId) { |
| 12604 | mConsumer = consumer; |
| 12605 | mCarrierId = carrierId; |
| 12606 | } |
| 12607 | |
| 12608 | public Consumer<Integer> getConsumer() { |
| 12609 | return mConsumer; |
| 12610 | } |
| 12611 | |
| 12612 | public int getCarrierId() { |
| 12613 | return mCarrierId; |
| 12614 | } |
| 12615 | } |
Jack Yu | fa8ed01 | 2023-02-11 15:42:28 -0800 | [diff] [blame] | 12616 | } |