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; |
Anthony Alridge | 70ba557 | 2023-05-02 12:14:14 +0000 | [diff] [blame] | 42 | import android.content.ActivityNotFoundException; |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 43 | import android.content.ComponentName; |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 44 | import android.content.ContentResolver; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 45 | import android.content.Context; |
| 46 | import android.content.Intent; |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 47 | import android.content.SharedPreferences; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 48 | import android.content.pm.ComponentInfo; |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 49 | import android.content.pm.PackageManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 50 | import android.net.Uri; |
| 51 | import android.os.AsyncResult; |
| 52 | import android.os.Binder; |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 53 | import android.os.Build; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 54 | import android.os.Bundle; |
Chinmay Dhodapkar | 66262c4 | 2023-03-10 15:47:41 -0800 | [diff] [blame] | 55 | import android.os.DropBoxManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 56 | import android.os.Handler; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 57 | import android.os.IBinder; |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 58 | import android.os.ICancellationSignal; |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 59 | import android.os.LocaleList; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 60 | import android.os.Looper; |
| 61 | import android.os.Message; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 62 | import android.os.Messenger; |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 63 | import android.os.ParcelFileDescriptor; |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 64 | import android.os.ParcelUuid; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 65 | import android.os.PersistableBundle; |
Shuo Qian | cd19c46 | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 66 | import android.os.Process; |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 67 | import android.os.RemoteException; |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 68 | import android.os.ResultReceiver; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 69 | import android.os.ServiceSpecificException; |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 70 | import android.os.SystemClock; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 71 | import android.os.UserHandle; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 72 | import android.os.UserManager; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 73 | import android.os.WorkSource; |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 74 | import android.preference.PreferenceManager; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 75 | import android.provider.DeviceConfig; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 76 | import android.provider.Settings; |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 77 | import android.provider.Telephony; |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 78 | import android.service.carrier.CarrierIdentifier; |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 79 | import android.sysprop.TelephonyProperties; |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 80 | import android.telecom.PhoneAccount; |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 81 | import android.telecom.PhoneAccountHandle; |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 82 | import android.telecom.TelecomManager; |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 83 | import android.telephony.AccessNetworkConstants; |
| 84 | import android.telephony.ActivityStatsTechSpecificInfo; |
Chen Xu | 227e06f | 2019-09-26 22:48:11 -0700 | [diff] [blame] | 85 | import android.telephony.Annotation.ApnType; |
Jack Yu | 0eda684 | 2022-04-18 00:34:46 -0700 | [diff] [blame] | 86 | import android.telephony.Annotation.DataActivityType; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 87 | import android.telephony.Annotation.ThermalMitigationResult; |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 88 | import android.telephony.AnomalyReporter; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 89 | import android.telephony.CallForwardingInfo; |
Junda Liu | 12f7d80 | 2015-05-01 12:06:44 -0700 | [diff] [blame] | 90 | import android.telephony.CarrierConfigManager; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 91 | import android.telephony.CarrierRestrictionRules; |
Hui Wang | 9b5793a | 2022-12-05 14:38:06 -0600 | [diff] [blame] | 92 | import android.telephony.CellBroadcastIdRange; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 93 | import android.telephony.CellIdentity; |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 94 | import android.telephony.CellIdentityCdma; |
| 95 | import android.telephony.CellIdentityGsm; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 96 | import android.telephony.CellInfo; |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 97 | import android.telephony.CellInfoGsm; |
| 98 | import android.telephony.CellInfoWcdma; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 99 | import android.telephony.ClientRequestStats; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 100 | import android.telephony.DataThrottlingRequest; |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 101 | import android.telephony.IBootstrapAuthenticationCallback; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 102 | import android.telephony.ICellInfoCallback; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 103 | import android.telephony.IccOpenLogicalChannelResponse; |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 104 | import android.telephony.LocationAccessPolicy; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 105 | import android.telephony.ModemActivityInfo; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 106 | import android.telephony.NeighboringCellInfo; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 107 | import android.telephony.NetworkScanRequest; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 108 | import android.telephony.PhoneCapability; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 109 | import android.telephony.PhoneNumberRange; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 110 | import android.telephony.RadioAccessFamily; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 111 | import android.telephony.RadioAccessSpecifier; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 112 | import android.telephony.ServiceState; |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 113 | import android.telephony.SignalStrength; |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 114 | import android.telephony.SignalStrengthUpdateRequest; |
| 115 | import android.telephony.SignalThresholdInfo; |
Wink Saville | 0f3b5fc | 2014-11-11 08:40:49 -0800 | [diff] [blame] | 116 | import android.telephony.SubscriptionInfo; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 117 | import android.telephony.SubscriptionManager; |
Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 118 | import android.telephony.TelephonyFrameworkInitializer; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 119 | import android.telephony.TelephonyHistogram; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 120 | import android.telephony.TelephonyManager; |
Jack Yu | f5badd9 | 2022-12-08 00:50:53 -0800 | [diff] [blame] | 121 | import android.telephony.TelephonyManager.SimState; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 122 | import android.telephony.TelephonyScanManager; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 123 | import android.telephony.ThermalMitigationRequest; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 124 | import android.telephony.UiccCardInfo; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 125 | import android.telephony.UiccPortInfo; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 126 | import android.telephony.UiccSlotInfo; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 127 | import android.telephony.UiccSlotMapping; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 128 | import android.telephony.UssdResponse; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 129 | import android.telephony.VisualVoicemailSmsFilterSettings; |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 130 | import android.telephony.data.NetworkSlicingConfig; |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 131 | import android.telephony.emergency.EmergencyNumber; |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 132 | import android.telephony.gba.GbaAuthRequest; |
| 133 | import android.telephony.gba.UaSecurityProtocolIdentifier; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 134 | import android.telephony.ims.ImsException; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 135 | import android.telephony.ims.ProvisioningManager; |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 136 | import android.telephony.ims.RcsClientConfiguration; |
Brad Ebinger | 14d467f | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 137 | import android.telephony.ims.RcsContactUceCapability; |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 138 | import android.telephony.ims.RegistrationManager; |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 139 | import android.telephony.ims.aidl.IFeatureProvisioningCallback; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 140 | import android.telephony.ims.aidl.IImsCapabilityCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 141 | import android.telephony.ims.aidl.IImsConfig; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 142 | import android.telephony.ims.aidl.IImsConfigCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 143 | import android.telephony.ims.aidl.IImsRegistration; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 144 | import android.telephony.ims.aidl.IImsRegistrationCallback; |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 145 | import android.telephony.ims.aidl.IRcsConfigCallback; |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 146 | import android.telephony.ims.feature.ImsFeature; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 147 | import android.telephony.ims.stub.ImsConfigImplBase; |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 148 | import android.telephony.ims.stub.ImsRegistrationImplBase; |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 149 | import android.telephony.satellite.ISatelliteDatagramCallback; |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 150 | import android.telephony.satellite.ISatelliteProvisionStateCallback; |
| 151 | import android.telephony.satellite.ISatelliteStateCallback; |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 152 | import android.telephony.satellite.ISatelliteTransmissionUpdateCallback; |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 153 | import android.telephony.satellite.SatelliteCapabilities; |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 154 | import android.telephony.satellite.SatelliteDatagram; |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 155 | import android.telephony.satellite.SatelliteDatagramCallback; |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 156 | import android.telephony.satellite.SatelliteManager; |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 157 | import android.telephony.satellite.SatelliteProvisionStateCallback; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 158 | import android.text.TextUtils; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 159 | import android.util.ArraySet; |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 160 | import android.util.EventLog; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 161 | import android.util.Log; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 162 | import android.util.Pair; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 163 | |
Andrew Lee | 312e817 | 2014-10-23 17:01:36 -0700 | [diff] [blame] | 164 | import com.android.ims.ImsManager; |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 165 | import com.android.ims.internal.IImsServiceFeatureCallback; |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 166 | import com.android.ims.rcs.uce.eab.EabUtil; |
SongFerngWang | fd89b10 | 2021-05-27 22:44:54 +0800 | [diff] [blame] | 167 | import com.android.internal.annotations.VisibleForTesting; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 168 | import com.android.internal.telephony.CallForwardInfo; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 169 | import com.android.internal.telephony.CallManager; |
Tyler Gunn | 52dcf77 | 2017-04-26 11:30:31 -0700 | [diff] [blame] | 170 | import com.android.internal.telephony.CallStateException; |
Tyler Gunn | d433926 | 2021-05-03 14:46:49 -0700 | [diff] [blame] | 171 | import com.android.internal.telephony.CallTracker; |
Rambo Wang | 9c9ffdd | 2022-01-13 21:51:44 -0800 | [diff] [blame] | 172 | import com.android.internal.telephony.CarrierPrivilegesTracker; |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 173 | import com.android.internal.telephony.CarrierResolver; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 174 | import com.android.internal.telephony.CellNetworkScanResult; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 175 | import com.android.internal.telephony.CommandException; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 176 | import com.android.internal.telephony.CommandsInterface; |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 177 | import com.android.internal.telephony.GbaManager; |
Shuo Qian | ccbaf74 | 2021-02-22 18:32:21 -0800 | [diff] [blame] | 178 | import com.android.internal.telephony.GsmCdmaPhone; |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 179 | import com.android.internal.telephony.HalVersion; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 180 | import com.android.internal.telephony.IBooleanConsumer; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 181 | import com.android.internal.telephony.ICallForwardingInfoCallback; |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 182 | import com.android.internal.telephony.IImsStateCallback; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 183 | import com.android.internal.telephony.IIntegerConsumer; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 184 | import com.android.internal.telephony.INumberVerificationCallback; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 185 | import com.android.internal.telephony.ITelephony; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 186 | import com.android.internal.telephony.IccCard; |
Jack Yu | f5badd9 | 2022-12-08 00:50:53 -0800 | [diff] [blame] | 187 | import com.android.internal.telephony.IccCardConstants; |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 188 | import com.android.internal.telephony.IccLogicalChannelRequest; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 189 | import com.android.internal.telephony.LocaleTracker; |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 190 | import com.android.internal.telephony.NetworkScanRequestTracker; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 191 | import com.android.internal.telephony.OperatorInfo; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 192 | import com.android.internal.telephony.Phone; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 193 | import com.android.internal.telephony.PhoneConfigurationManager; |
Nathan Harold | a667c15 | 2016-12-14 11:27:20 -0800 | [diff] [blame] | 194 | import com.android.internal.telephony.PhoneConstantConversions; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 195 | import com.android.internal.telephony.PhoneConstants; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 196 | import com.android.internal.telephony.PhoneFactory; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 197 | import com.android.internal.telephony.ProxyController; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 198 | import com.android.internal.telephony.RIL; |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 199 | import com.android.internal.telephony.RILConstants; |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 200 | import com.android.internal.telephony.RadioInterfaceCapabilityController; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 201 | import com.android.internal.telephony.ServiceStateTracker; |
Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame] | 202 | import com.android.internal.telephony.SmsApplication; |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 203 | import com.android.internal.telephony.SmsController; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 204 | import com.android.internal.telephony.SmsPermissions; |
Peter Wang | 59571be | 2020-01-27 12:35:15 +0800 | [diff] [blame] | 205 | import com.android.internal.telephony.TelephonyIntents; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 206 | import com.android.internal.telephony.TelephonyPermissions; |
Jack Yu | 27422a5 | 2022-03-21 10:38:05 -0700 | [diff] [blame] | 207 | import com.android.internal.telephony.data.DataUtils; |
Hunsuk Choi | 42cc62a | 2022-10-16 06:03:40 +0000 | [diff] [blame] | 208 | import com.android.internal.telephony.domainselection.DomainSelectionResolver; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 209 | import com.android.internal.telephony.emergency.EmergencyNumberTracker; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 210 | import com.android.internal.telephony.euicc.EuiccConnector; |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 211 | import com.android.internal.telephony.ims.ImsResolver; |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 212 | import com.android.internal.telephony.imsphone.ImsPhone; |
| 213 | import com.android.internal.telephony.imsphone.ImsPhoneCallTracker; |
joonhunshin | 3e15424 | 2021-09-17 06:33:39 +0000 | [diff] [blame] | 214 | import com.android.internal.telephony.metrics.RcsStats; |
Pengquan Meng | 6c2dc9f | 2019-02-06 11:12:53 -0800 | [diff] [blame] | 215 | import com.android.internal.telephony.metrics.TelephonyMetrics; |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 216 | import com.android.internal.telephony.satellite.SatelliteController; |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 217 | import com.android.internal.telephony.subscription.SubscriptionInfoInternal; |
| 218 | import com.android.internal.telephony.subscription.SubscriptionManagerService; |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 219 | import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 220 | import com.android.internal.telephony.uicc.IccIoResult; |
| 221 | import com.android.internal.telephony.uicc.IccUtils; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 222 | import com.android.internal.telephony.uicc.SIMRecords; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 223 | import com.android.internal.telephony.uicc.UiccCard; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 224 | import com.android.internal.telephony.uicc.UiccCardApplication; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 225 | import com.android.internal.telephony.uicc.UiccController; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 226 | import com.android.internal.telephony.uicc.UiccPort; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 227 | import com.android.internal.telephony.uicc.UiccProfile; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 228 | import com.android.internal.telephony.uicc.UiccSlot; |
zoey chen | c730df8 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 229 | import com.android.internal.telephony.util.LocaleUtils; |
Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame] | 230 | import com.android.internal.telephony.util.TelephonyUtils; |
fionaxu | 7ed723d | 2017-05-30 18:58:54 -0700 | [diff] [blame] | 231 | import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 232 | import com.android.internal.util.FunctionalUtils; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 233 | import com.android.internal.util.HexDump; |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 234 | import com.android.phone.callcomposer.CallComposerPictureManager; |
| 235 | import com.android.phone.callcomposer.CallComposerPictureTransfer; |
| 236 | import com.android.phone.callcomposer.ImageData; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 237 | import com.android.phone.settings.PickSmsSubscriptionActivity; |
Sarah Chin | 46355ba | 2022-11-01 23:51:16 -0700 | [diff] [blame] | 238 | import com.android.phone.slice.SlicePurchaseController; |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 239 | import com.android.phone.utils.CarrierAllowListInfo; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 240 | import com.android.phone.vvm.PhoneAccountHandleConverter; |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 241 | import com.android.phone.vvm.RemoteVvmTaskManager; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 242 | import com.android.phone.vvm.VisualVoicemailSettingsUtil; |
Ta-wei Yen | c890531 | 2017-03-28 11:14:45 -0700 | [diff] [blame] | 243 | import com.android.phone.vvm.VisualVoicemailSmsFilterConfig; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 244 | import com.android.services.telephony.TelecomAccountRegistry; |
| 245 | import com.android.services.telephony.TelephonyConnectionService; |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 246 | import com.android.telephony.Rlog; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 247 | |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 248 | import java.io.ByteArrayOutputStream; |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 249 | import java.io.FileDescriptor; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 250 | import java.io.IOException; |
| 251 | import java.io.InputStream; |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 252 | import java.io.PrintWriter; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 253 | import java.util.ArrayList; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 254 | import java.util.Arrays; |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 255 | import java.util.Collection; |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 256 | import java.util.Collections; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 257 | import java.util.HashMap; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 258 | import java.util.HashSet; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 259 | import java.util.List; |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 260 | import java.util.Locale; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 261 | import java.util.Map; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 262 | import java.util.NoSuchElementException; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 263 | import java.util.Objects; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 264 | import java.util.Set; |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 265 | import java.util.UUID; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 266 | import java.util.concurrent.Executors; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 267 | import java.util.concurrent.atomic.AtomicBoolean; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 268 | import java.util.function.Consumer; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 269 | |
| 270 | /** |
| 271 | * Implementation of the ITelephony interface. |
| 272 | */ |
Santos Cordon | 117fee7 | 2014-05-16 17:56:12 -0700 | [diff] [blame] | 273 | public class PhoneInterfaceManager extends ITelephony.Stub { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 274 | private static final String LOG_TAG = "PhoneInterfaceManager"; |
| 275 | private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2); |
| 276 | private static final boolean DBG_LOC = false; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 277 | private static final boolean DBG_MERGE = false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 278 | |
| 279 | // Message codes used with mMainThreadHandler |
| 280 | private static final int CMD_HANDLE_PIN_MMI = 1; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 281 | private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7; |
| 282 | private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 283 | private static final int CMD_OPEN_CHANNEL = 9; |
| 284 | private static final int EVENT_OPEN_CHANNEL_DONE = 10; |
| 285 | private static final int CMD_CLOSE_CHANNEL = 11; |
| 286 | private static final int EVENT_CLOSE_CHANNEL_DONE = 12; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 287 | private static final int CMD_NV_READ_ITEM = 13; |
| 288 | private static final int EVENT_NV_READ_ITEM_DONE = 14; |
| 289 | private static final int CMD_NV_WRITE_ITEM = 15; |
| 290 | private static final int EVENT_NV_WRITE_ITEM_DONE = 16; |
| 291 | private static final int CMD_NV_WRITE_CDMA_PRL = 17; |
| 292 | private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 293 | private static final int CMD_RESET_MODEM_CONFIG = 19; |
| 294 | private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 295 | private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21; |
| 296 | private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22; |
Sailesh Nepal | 35b5945 | 2014-03-06 09:26:56 -0800 | [diff] [blame] | 297 | private static final int CMD_SEND_ENVELOPE = 25; |
| 298 | private static final int EVENT_SEND_ENVELOPE_DONE = 26; |
Derek Tan | 6b088ee | 2014-09-05 14:15:18 -0700 | [diff] [blame] | 299 | private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29; |
| 300 | private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30; |
| 301 | private static final int CMD_EXCHANGE_SIM_IO = 31; |
| 302 | private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 303 | private static final int CMD_SET_VOICEMAIL_NUMBER = 33; |
| 304 | private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 305 | private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35; |
| 306 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 307 | private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37; |
| 308 | private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 309 | private static final int CMD_PERFORM_NETWORK_SCAN = 39; |
| 310 | private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40; |
| 311 | private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41; |
| 312 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 313 | private static final int CMD_SET_ALLOWED_CARRIERS = 43; |
| 314 | private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44; |
| 315 | private static final int CMD_GET_ALLOWED_CARRIERS = 45; |
| 316 | private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 317 | private static final int CMD_HANDLE_USSD_REQUEST = 47; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 318 | private static final int CMD_GET_FORBIDDEN_PLMNS = 48; |
| 319 | private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 320 | private static final int CMD_SWITCH_SLOTS = 50; |
| 321 | private static final int EVENT_SWITCH_SLOTS_DONE = 51; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 322 | private static final int CMD_GET_NETWORK_SELECTION_MODE = 52; |
| 323 | private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53; |
| 324 | private static final int CMD_GET_CDMA_ROAMING_MODE = 54; |
| 325 | private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55; |
| 326 | private static final int CMD_SET_CDMA_ROAMING_MODE = 56; |
| 327 | private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57; |
| 328 | private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58; |
| 329 | private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 330 | private static final int CMD_GET_ALL_CELL_INFO = 60; |
| 331 | private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61; |
| 332 | private static final int CMD_GET_CELL_LOCATION = 62; |
| 333 | private static final int EVENT_GET_CELL_LOCATION_DONE = 63; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 334 | private static final int CMD_MODEM_REBOOT = 64; |
| 335 | private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 336 | private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66; |
| 337 | private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 338 | private static final int CMD_REQUEST_ENABLE_MODEM = 68; |
| 339 | private static final int EVENT_ENABLE_MODEM_DONE = 69; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 340 | private static final int CMD_GET_MODEM_STATUS = 70; |
| 341 | private static final int EVENT_GET_MODEM_STATUS_DONE = 71; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 342 | private static final int CMD_SET_FORBIDDEN_PLMNS = 72; |
| 343 | private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 344 | private static final int CMD_ERASE_MODEM_CONFIG = 74; |
| 345 | private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75; |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 346 | private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76; |
| 347 | private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77; |
| 348 | private static final int CMD_SET_ICC_LOCK_ENABLED = 78; |
| 349 | private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 350 | private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80; |
| 351 | private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 352 | private static final int MSG_NOTIFY_USER_ACTIVITY = 82; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 353 | private static final int CMD_GET_CALL_FORWARDING = 83; |
| 354 | private static final int EVENT_GET_CALL_FORWARDING_DONE = 84; |
| 355 | private static final int CMD_SET_CALL_FORWARDING = 85; |
| 356 | private static final int EVENT_SET_CALL_FORWARDING_DONE = 86; |
| 357 | private static final int CMD_GET_CALL_WAITING = 87; |
| 358 | private static final int EVENT_GET_CALL_WAITING_DONE = 88; |
| 359 | private static final int CMD_SET_CALL_WAITING = 89; |
| 360 | private static final int EVENT_SET_CALL_WAITING_DONE = 90; |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 361 | private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91; |
| 362 | private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92; |
| 363 | private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93; |
| 364 | private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 365 | private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95; |
| 366 | private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 367 | private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97; |
| 368 | private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 369 | private static final int CMD_SET_DATA_THROTTLING = 99; |
| 370 | private static final int EVENT_SET_DATA_THROTTLING_DONE = 100; |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 371 | private static final int CMD_SET_SIM_POWER = 101; |
| 372 | private static final int EVENT_SET_SIM_POWER_DONE = 102; |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 373 | private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103; |
| 374 | private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104; |
| 375 | private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105; |
| 376 | private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 377 | private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107; |
| 378 | 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] | 379 | private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 380 | private static final int CMD_GET_SLICING_CONFIG = 110; |
| 381 | private static final int EVENT_GET_SLICING_CONFIG_DONE = 111; |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 382 | private static final int CMD_ERASE_DATA_SHARED_PREFERENCES = 112; |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 383 | private static final int CMD_ENABLE_VONR = 113; |
| 384 | private static final int EVENT_ENABLE_VONR_DONE = 114; |
| 385 | private static final int CMD_IS_VONR_ENABLED = 115; |
| 386 | private static final int EVENT_IS_VONR_ENABLED_DONE = 116; |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 387 | private static final int CMD_PURCHASE_PREMIUM_CAPABILITY = 117; |
| 388 | private static final int EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE = 118; |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 389 | |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 390 | // Parameters of select command. |
| 391 | private static final int SELECT_COMMAND = 0xA4; |
| 392 | private static final int SELECT_P1 = 0x04; |
| 393 | private static final int SELECT_P2 = 0; |
| 394 | private static final int SELECT_P3 = 0x10; |
| 395 | |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 396 | // Toggling null cipher and integrity support was added in IRadioNetwork 2.1 |
| 397 | private static final int MIN_NULL_CIPHER_AND_INTEGRITY_VERSION = 201; |
| 398 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 399 | /** The singleton instance. */ |
| 400 | private static PhoneInterfaceManager sInstance; |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 401 | private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 402 | |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 403 | private final PhoneGlobals mApp; |
| 404 | private final CallManager mCM; |
| 405 | private final ImsResolver mImsResolver; |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 406 | |
| 407 | private final SatelliteController mSatelliteController; |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 408 | private final UserManager mUserManager; |
| 409 | private final AppOpsManager mAppOps; |
| 410 | private final MainThreadHandler mMainThreadHandler; |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 411 | private final SharedPreferences mTelephonySharedPreferences; |
| 412 | private final PhoneConfigurationManager mPhoneConfigurationManager; |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 413 | private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 414 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 415 | /** User Activity */ |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 416 | private final AtomicBoolean mNotifyUserActivity; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 417 | private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200; |
| 418 | |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 419 | private final Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>(); |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 420 | |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 421 | private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_"; |
| 422 | private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_"; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 423 | private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_"; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 424 | private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_"; |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 425 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 426 | // String to store multi SIM allowed |
| 427 | private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted"; |
| 428 | |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 429 | // The AID of ISD-R. |
| 430 | private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100"; |
| 431 | |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 432 | private NetworkScanRequestTracker mNetworkScanRequestTracker; |
| 433 | |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 434 | private static final int TYPE_ALLOCATION_CODE_LENGTH = 8; |
| 435 | private static final int MANUFACTURER_CODE_LENGTH = 8; |
| 436 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 437 | private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1; |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 438 | 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] | 439 | |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 440 | private static final String PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID = |
| 441 | "24bf97a6-e8a6-44d8-a6a4-255d7548733c"; |
| 442 | |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 443 | /** |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 444 | * Experiment flag to enable erase modem config on reset network, default value is false |
| 445 | */ |
| 446 | public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED = |
| 447 | "reset_network_erase_modem_config_enabled"; |
| 448 | |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 449 | 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] | 450 | |
Gary Jian | 76280a4 | 2022-12-07 16:18:33 +0800 | [diff] [blame] | 451 | private static final int MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS = 50; |
| 452 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 453 | /** |
| 454 | * With support for MEP(multiple enabled profile) in Android T, a SIM card can have more than |
| 455 | * one ICCID active at the same time. |
| 456 | * Apps should use below API signatures if targeting SDK is T and beyond. |
| 457 | * |
| 458 | * @hide |
| 459 | */ |
| 460 | @ChangeId |
| 461 | @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU) |
| 462 | public static final long GET_API_SIGNATURES_FROM_UICC_PORT_INFO = 202110963L; |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 463 | |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 464 | /** |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 465 | * Apps targeting on Android T and beyond will get exception whenever icc close channel |
| 466 | * operation fails. |
| 467 | */ |
| 468 | @ChangeId |
| 469 | @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU) |
| 470 | public static final long ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE = 208739934L; |
| 471 | |
| 472 | /** |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 473 | * A request object to use for transmitting data to an ICC. |
| 474 | */ |
| 475 | private static final class IccAPDUArgument { |
| 476 | public int channel, cla, command, p1, p2, p3; |
| 477 | public String data; |
| 478 | |
| 479 | public IccAPDUArgument(int channel, int cla, int command, |
| 480 | int p1, int p2, int p3, String data) { |
| 481 | this.channel = channel; |
| 482 | this.cla = cla; |
| 483 | this.command = command; |
| 484 | this.p1 = p1; |
| 485 | this.p2 = p2; |
| 486 | this.p3 = p3; |
| 487 | this.data = data; |
| 488 | } |
| 489 | } |
| 490 | |
| 491 | /** |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 492 | * A request object to use for transmitting data to an ICC. |
| 493 | */ |
| 494 | private static final class ManualNetworkSelectionArgument { |
| 495 | public OperatorInfo operatorInfo; |
| 496 | public boolean persistSelection; |
| 497 | |
| 498 | public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) { |
| 499 | this.operatorInfo = operatorInfo; |
| 500 | this.persistSelection = persistSelection; |
| 501 | } |
| 502 | } |
| 503 | |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 504 | private static final class PurchasePremiumCapabilityArgument { |
| 505 | public @TelephonyManager.PremiumCapability int capability; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 506 | public @NonNull IIntegerConsumer callback; |
| 507 | |
| 508 | PurchasePremiumCapabilityArgument(@TelephonyManager.PremiumCapability int capability, |
Sarah Chin | b8218c2 | 2023-01-04 13:35:29 -0800 | [diff] [blame] | 509 | @NonNull IIntegerConsumer callback) { |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 510 | this.capability = capability; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 511 | this.callback = callback; |
| 512 | } |
| 513 | } |
| 514 | |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 515 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 516 | * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the |
| 517 | * request after sending. The main thread will notify the request when it is complete. |
| 518 | */ |
| 519 | private static final class MainThreadRequest { |
| 520 | /** The argument to use for the request */ |
| 521 | public Object argument; |
| 522 | /** The result of the request that is run on the main thread */ |
| 523 | public Object result; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 524 | // The subscriber id that this request applies to. Defaults to |
| 525 | // SubscriptionManager.INVALID_SUBSCRIPTION_ID |
| 526 | public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 527 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 528 | // In cases where subId is unavailable, the caller needs to specify the phone. |
| 529 | public Phone phone; |
| 530 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 531 | public WorkSource workSource; |
| 532 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 533 | public MainThreadRequest(Object argument) { |
| 534 | this.argument = argument; |
| 535 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 536 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 537 | MainThreadRequest(Object argument, Phone phone, WorkSource workSource) { |
| 538 | this.argument = argument; |
| 539 | if (phone != null) { |
| 540 | this.phone = phone; |
| 541 | } |
| 542 | this.workSource = workSource; |
| 543 | } |
| 544 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 545 | MainThreadRequest(Object argument, Integer subId, WorkSource workSource) { |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 546 | this.argument = argument; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 547 | if (subId != null) { |
| 548 | this.subId = subId; |
| 549 | } |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 550 | this.workSource = workSource; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 551 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 552 | } |
| 553 | |
Sailesh Nepal | cc0375f | 2013-11-13 09:15:18 -0800 | [diff] [blame] | 554 | private static final class IncomingThirdPartyCallArgs { |
| 555 | public final ComponentName component; |
| 556 | public final String callId; |
| 557 | public final String callerDisplayName; |
| 558 | |
| 559 | public IncomingThirdPartyCallArgs(ComponentName component, String callId, |
| 560 | String callerDisplayName) { |
| 561 | this.component = component; |
| 562 | this.callId = callId; |
| 563 | this.callerDisplayName = callerDisplayName; |
| 564 | } |
| 565 | } |
| 566 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 567 | /** |
| 568 | * A handler that processes messages on the main thread in the phone process. Since many |
| 569 | * of the Phone calls are not thread safe this is needed to shuttle the requests from the |
| 570 | * inbound binder threads to the main thread in the phone process. The Binder thread |
| 571 | * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting |
| 572 | * on, which will be notified when the operation completes and will contain the result of the |
| 573 | * request. |
| 574 | * |
| 575 | * <p>If a MainThreadRequest object is provided in the msg.obj field, |
| 576 | * note that request.result must be set to something non-null for the calling thread to |
| 577 | * unblock. |
| 578 | */ |
| 579 | private final class MainThreadHandler extends Handler { |
| 580 | @Override |
| 581 | public void handleMessage(Message msg) { |
| 582 | MainThreadRequest request; |
| 583 | Message onCompleted; |
| 584 | AsyncResult ar; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 585 | UiccPort uiccPort; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 586 | IccAPDUArgument iccArgument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 587 | final Phone defaultPhone = getDefaultPhone(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 588 | |
| 589 | switch (msg.what) { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 590 | case CMD_HANDLE_USSD_REQUEST: { |
| 591 | request = (MainThreadRequest) msg.obj; |
| 592 | final Phone phone = getPhoneFromRequest(request); |
| 593 | Pair<String, ResultReceiver> ussdObject = (Pair) request.argument; |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 594 | String ussdRequest = ussdObject.first; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 595 | ResultReceiver wrappedCallback = ussdObject.second; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 596 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 597 | if (!isUssdApiAllowed(request.subId)) { |
| 598 | // Carrier does not support use of this API, return failure. |
| 599 | Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis."); |
| 600 | UssdResponse response = new UssdResponse(ussdRequest, null); |
| 601 | Bundle returnData = new Bundle(); |
| 602 | returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response); |
| 603 | wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 604 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 605 | request.result = true; |
| 606 | notifyRequester(request); |
| 607 | return; |
| 608 | } |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 609 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 610 | try { |
| 611 | request.result = phone != null |
| 612 | ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false; |
| 613 | } catch (CallStateException cse) { |
| 614 | request.result = false; |
| 615 | } |
| 616 | // Wake up the requesting thread |
| 617 | notifyRequester(request); |
| 618 | break; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 619 | } |
| 620 | |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 621 | case CMD_HANDLE_PIN_MMI: { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 622 | request = (MainThreadRequest) msg.obj; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 623 | final Phone phone = getPhoneFromRequest(request); |
| 624 | request.result = phone != null ? |
| 625 | getPhoneFromRequest(request).handlePinMmi((String) request.argument) |
| 626 | : false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 627 | // Wake up the requesting thread |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 628 | notifyRequester(request); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 629 | break; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 630 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 631 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 632 | case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 633 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 634 | iccArgument = (IccAPDUArgument) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 635 | uiccPort = getUiccPortFromRequest(request); |
| 636 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 637 | loge("iccTransmitApduLogicalChannel: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 638 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 639 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 640 | } else { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 641 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE, |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 642 | request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 643 | uiccPort.iccTransmitApduLogicalChannel( |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 644 | iccArgument.channel, iccArgument.cla, iccArgument.command, |
| 645 | iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data, |
| 646 | onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 647 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 648 | break; |
| 649 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 650 | case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 651 | ar = (AsyncResult) msg.obj; |
| 652 | request = (MainThreadRequest) ar.userObj; |
| 653 | if (ar.exception == null && ar.result != null) { |
| 654 | request.result = ar.result; |
| 655 | } else { |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 656 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 657 | if (ar.result == null) { |
| 658 | loge("iccTransmitApduLogicalChannel: Empty response"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 659 | } else if (ar.exception instanceof CommandException) { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 660 | loge("iccTransmitApduLogicalChannel: CommandException: " + |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 661 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 662 | } else { |
| 663 | loge("iccTransmitApduLogicalChannel: Unknown exception"); |
| 664 | } |
| 665 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 666 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 667 | break; |
| 668 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 669 | case CMD_TRANSMIT_APDU_BASIC_CHANNEL: |
| 670 | request = (MainThreadRequest) msg.obj; |
| 671 | iccArgument = (IccAPDUArgument) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 672 | uiccPort = getUiccPortFromRequest(request); |
| 673 | if (uiccPort == null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 674 | loge("iccTransmitApduBasicChannel: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 675 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 676 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 677 | } else { |
| 678 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE, |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 679 | request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 680 | uiccPort.iccTransmitApduBasicChannel( |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 681 | iccArgument.cla, iccArgument.command, iccArgument.p1, |
| 682 | iccArgument.p2, |
| 683 | iccArgument.p3, iccArgument.data, onCompleted); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 684 | } |
| 685 | break; |
| 686 | |
| 687 | case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE: |
| 688 | ar = (AsyncResult) msg.obj; |
| 689 | request = (MainThreadRequest) ar.userObj; |
| 690 | if (ar.exception == null && ar.result != null) { |
| 691 | request.result = ar.result; |
| 692 | } else { |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 693 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 694 | if (ar.result == null) { |
| 695 | loge("iccTransmitApduBasicChannel: Empty response"); |
| 696 | } else if (ar.exception instanceof CommandException) { |
| 697 | loge("iccTransmitApduBasicChannel: CommandException: " + |
| 698 | ar.exception); |
| 699 | } else { |
| 700 | loge("iccTransmitApduBasicChannel: Unknown exception"); |
| 701 | } |
| 702 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 703 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 704 | break; |
| 705 | |
| 706 | case CMD_EXCHANGE_SIM_IO: |
| 707 | request = (MainThreadRequest) msg.obj; |
| 708 | iccArgument = (IccAPDUArgument) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 709 | uiccPort = getUiccPortFromRequest(request); |
| 710 | if (uiccPort == null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 711 | loge("iccExchangeSimIO: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 712 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 713 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 714 | } else { |
| 715 | onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE, |
| 716 | request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 717 | uiccPort.iccExchangeSimIO(iccArgument.cla, /* fileID */ |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 718 | iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3, |
| 719 | iccArgument.data, onCompleted); |
| 720 | } |
| 721 | break; |
| 722 | |
| 723 | case EVENT_EXCHANGE_SIM_IO_DONE: |
| 724 | ar = (AsyncResult) msg.obj; |
| 725 | request = (MainThreadRequest) ar.userObj; |
| 726 | if (ar.exception == null && ar.result != null) { |
| 727 | request.result = ar.result; |
| 728 | } else { |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 729 | request.result = new IccIoResult(0x6f, 0, (byte[]) null); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 730 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 731 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 732 | break; |
| 733 | |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 734 | case CMD_SEND_ENVELOPE: |
| 735 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 736 | uiccPort = getUiccPortFromRequest(request); |
| 737 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 738 | loge("sendEnvelopeWithStatus: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 739 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 740 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 741 | } else { |
| 742 | onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 743 | uiccPort.sendEnvelopeWithStatus((String) request.argument, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 744 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 745 | break; |
| 746 | |
| 747 | case EVENT_SEND_ENVELOPE_DONE: |
| 748 | ar = (AsyncResult) msg.obj; |
| 749 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 750 | if (ar.exception == null && ar.result != null) { |
| 751 | request.result = ar.result; |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 752 | } else { |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 753 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 754 | if (ar.result == null) { |
| 755 | loge("sendEnvelopeWithStatus: Empty response"); |
| 756 | } else if (ar.exception instanceof CommandException) { |
| 757 | loge("sendEnvelopeWithStatus: CommandException: " + |
| 758 | ar.exception); |
| 759 | } else { |
| 760 | loge("sendEnvelopeWithStatus: exception:" + ar.exception); |
| 761 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 762 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 763 | notifyRequester(request); |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 764 | break; |
| 765 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 766 | case CMD_OPEN_CHANNEL: |
| 767 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 768 | uiccPort = getUiccPortFromRequest(request); |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 769 | IccLogicalChannelRequest openChannelRequest = |
| 770 | (IccLogicalChannelRequest) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 771 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 772 | loge("iccOpenLogicalChannel: No UICC"); |
Shishir Agrawal | fc0492a | 2016-02-17 11:15:33 -0800 | [diff] [blame] | 773 | request.result = new IccOpenLogicalChannelResponse(-1, |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 774 | IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 775 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 776 | } else { |
| 777 | onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request); |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 778 | uiccPort.iccOpenLogicalChannel(openChannelRequest.aid, |
| 779 | openChannelRequest.p2, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 780 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 781 | break; |
| 782 | |
| 783 | case EVENT_OPEN_CHANNEL_DONE: |
| 784 | ar = (AsyncResult) msg.obj; |
| 785 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 786 | IccOpenLogicalChannelResponse openChannelResp; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 787 | if (ar.exception == null && ar.result != null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 788 | int[] result = (int[]) ar.result; |
| 789 | int channelId = result[0]; |
| 790 | byte[] selectResponse = null; |
| 791 | if (result.length > 1) { |
| 792 | selectResponse = new byte[result.length - 1]; |
| 793 | for (int i = 1; i < result.length; ++i) { |
| 794 | selectResponse[i - 1] = (byte) result[i]; |
| 795 | } |
| 796 | } |
| 797 | openChannelResp = new IccOpenLogicalChannelResponse(channelId, |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 798 | IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse); |
Rambo Wang | 3b77c4c | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 799 | |
| 800 | uiccPort = getUiccPortFromRequest(request); |
Rambo Wang | e53e07d | 2022-05-10 13:01:13 -0700 | [diff] [blame] | 801 | if (uiccPort == null) { |
| 802 | loge("EVENT_OPEN_CHANNEL_DONE: UiccPort is null"); |
| 803 | } else { |
| 804 | IccLogicalChannelRequest channelRequest = |
| 805 | (IccLogicalChannelRequest) request.argument; |
| 806 | channelRequest.channel = channelId; |
| 807 | uiccPort.onLogicalChannelOpened(channelRequest); |
| 808 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 809 | } else { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 810 | if (ar.result == null) { |
| 811 | loge("iccOpenLogicalChannel: Empty response"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 812 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 813 | if (ar.exception != null) { |
| 814 | loge("iccOpenLogicalChannel: Exception: " + ar.exception); |
| 815 | } |
| 816 | |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 817 | int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 818 | if (ar.exception instanceof CommandException) { |
| 819 | CommandException.Error error = |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 820 | ((CommandException) (ar.exception)).getCommandError(); |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 821 | if (error == CommandException.Error.MISSING_RESOURCE) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 822 | errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 823 | } else if (error == CommandException.Error.NO_SUCH_ELEMENT) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 824 | errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 825 | } |
| 826 | } |
| 827 | openChannelResp = new IccOpenLogicalChannelResponse( |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 828 | IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 829 | } |
Shishir Agrawal | 82c8a46 | 2014-07-31 18:13:17 -0700 | [diff] [blame] | 830 | request.result = openChannelResp; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 831 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 832 | break; |
| 833 | |
| 834 | case CMD_CLOSE_CHANNEL: |
| 835 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 836 | uiccPort = getUiccPortFromRequest(request); |
| 837 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 838 | loge("iccCloseLogicalChannel: No UICC"); |
Chen Xu | a8f0dff | 2022-02-12 00:34:15 -0800 | [diff] [blame] | 839 | request.result = new IllegalArgumentException( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 840 | "iccCloseLogicalChannel: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 841 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 842 | } else { |
| 843 | onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 844 | uiccPort.iccCloseLogicalChannel((Integer) request.argument, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 845 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 846 | break; |
| 847 | |
| 848 | case EVENT_CLOSE_CHANNEL_DONE: |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 849 | ar = (AsyncResult) msg.obj; |
| 850 | request = (MainThreadRequest) ar.userObj; |
| 851 | if (ar.exception == null) { |
| 852 | request.result = true; |
Rambo Wang | 3b77c4c | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 853 | uiccPort = getUiccPortFromRequest(request); |
Rambo Wang | e53e07d | 2022-05-10 13:01:13 -0700 | [diff] [blame] | 854 | if (uiccPort == null) { |
| 855 | loge("EVENT_CLOSE_CHANNEL_DONE: UiccPort is null"); |
| 856 | } else { |
| 857 | final int channelId = (Integer) request.argument; |
| 858 | uiccPort.onLogicalChannelClosed(channelId); |
| 859 | } |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 860 | } else { |
| 861 | request.result = false; |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 862 | Exception exception = null; |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 863 | if (ar.exception instanceof CommandException) { |
| 864 | loge("iccCloseLogicalChannel: CommandException: " + ar.exception); |
| 865 | CommandException.Error error = |
| 866 | ((CommandException) (ar.exception)).getCommandError(); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 867 | if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 868 | // should only throw exceptions from the binder threads. |
| 869 | exception = new IllegalArgumentException( |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 870 | "iccCloseLogicalChannel: invalid argument "); |
| 871 | } |
| 872 | } else { |
| 873 | loge("iccCloseLogicalChannel: Unknown exception"); |
| 874 | } |
Chen Xu | a8f0dff | 2022-02-12 00:34:15 -0800 | [diff] [blame] | 875 | request.result = (exception != null) ? exception : |
| 876 | new IllegalStateException( |
| 877 | "exception from modem to close iccLogical Channel"); |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 878 | } |
| 879 | notifyRequester(request); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 880 | break; |
| 881 | |
| 882 | case CMD_NV_READ_ITEM: |
| 883 | request = (MainThreadRequest) msg.obj; |
| 884 | onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 885 | defaultPhone.nvReadItem((Integer) request.argument, onCompleted, |
| 886 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 887 | break; |
| 888 | |
| 889 | case EVENT_NV_READ_ITEM_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 890 | ar = (AsyncResult) msg.obj; |
| 891 | request = (MainThreadRequest) ar.userObj; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 892 | if (ar.exception == null && ar.result != null) { |
| 893 | request.result = ar.result; // String |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 894 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 895 | request.result = ""; |
| 896 | if (ar.result == null) { |
| 897 | loge("nvReadItem: Empty response"); |
| 898 | } else if (ar.exception instanceof CommandException) { |
| 899 | loge("nvReadItem: CommandException: " + |
| 900 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 901 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 902 | loge("nvReadItem: Unknown exception"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 903 | } |
| 904 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 905 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 906 | break; |
| 907 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 908 | case CMD_NV_WRITE_ITEM: |
| 909 | request = (MainThreadRequest) msg.obj; |
| 910 | onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request); |
| 911 | Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 912 | defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 913 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 914 | break; |
| 915 | |
| 916 | case EVENT_NV_WRITE_ITEM_DONE: |
| 917 | handleNullReturnEvent(msg, "nvWriteItem"); |
| 918 | break; |
| 919 | |
| 920 | case CMD_NV_WRITE_CDMA_PRL: |
| 921 | request = (MainThreadRequest) msg.obj; |
| 922 | onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 923 | defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 924 | break; |
| 925 | |
| 926 | case EVENT_NV_WRITE_CDMA_PRL_DONE: |
| 927 | handleNullReturnEvent(msg, "nvWriteCdmaPrl"); |
| 928 | break; |
| 929 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 930 | case CMD_RESET_MODEM_CONFIG: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 931 | request = (MainThreadRequest) msg.obj; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 932 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 933 | defaultPhone.resetModemConfig(onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 934 | break; |
| 935 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 936 | case EVENT_RESET_MODEM_CONFIG_DONE: |
| 937 | handleNullReturnEvent(msg, "resetModemConfig"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 938 | break; |
| 939 | |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 940 | case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: { |
| 941 | request = (MainThreadRequest) msg.obj; |
| 942 | onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE, |
| 943 | request); |
| 944 | Phone phone = getPhoneFromRequest(request); |
| 945 | if (phone != null) { |
| 946 | phone.isNrDualConnectivityEnabled(onCompleted, request.workSource); |
| 947 | } else { |
| 948 | loge("isNRDualConnectivityEnabled: No phone object"); |
| 949 | request.result = false; |
| 950 | notifyRequester(request); |
| 951 | } |
| 952 | break; |
| 953 | } |
| 954 | |
| 955 | case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE: |
| 956 | ar = (AsyncResult) msg.obj; |
| 957 | request = (MainThreadRequest) ar.userObj; |
| 958 | if (ar.exception == null && ar.result != null) { |
| 959 | request.result = ar.result; |
| 960 | } else { |
| 961 | // request.result must be set to something non-null |
| 962 | // for the calling thread to unblock |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 963 | if (ar.result != null) { |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 964 | request.result = ar.result; |
| 965 | } else { |
| 966 | request.result = false; |
| 967 | } |
| 968 | if (ar.result == null) { |
| 969 | loge("isNRDualConnectivityEnabled: Empty response"); |
| 970 | } else if (ar.exception instanceof CommandException) { |
| 971 | loge("isNRDualConnectivityEnabled: CommandException: " |
| 972 | + ar.exception); |
| 973 | } else { |
| 974 | loge("isNRDualConnectivityEnabled: Unknown exception"); |
| 975 | } |
| 976 | } |
| 977 | notifyRequester(request); |
| 978 | break; |
| 979 | |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 980 | case CMD_IS_VONR_ENABLED: { |
| 981 | request = (MainThreadRequest) msg.obj; |
| 982 | onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE, |
| 983 | request); |
| 984 | Phone phone = getPhoneFromRequest(request); |
| 985 | if (phone != null) { |
| 986 | phone.isVoNrEnabled(onCompleted, request.workSource); |
| 987 | } else { |
| 988 | loge("isVoNrEnabled: No phone object"); |
| 989 | request.result = false; |
| 990 | notifyRequester(request); |
| 991 | } |
| 992 | break; |
| 993 | } |
| 994 | |
| 995 | case EVENT_IS_VONR_ENABLED_DONE: |
| 996 | ar = (AsyncResult) msg.obj; |
| 997 | request = (MainThreadRequest) ar.userObj; |
| 998 | if (ar.exception == null && ar.result != null) { |
| 999 | request.result = ar.result; |
| 1000 | } else { |
| 1001 | // request.result must be set to something non-null |
| 1002 | // for the calling thread to unblock |
| 1003 | if (ar.result != null) { |
| 1004 | request.result = ar.result; |
| 1005 | } else { |
| 1006 | request.result = false; |
| 1007 | } |
| 1008 | if (ar.result == null) { |
| 1009 | loge("isVoNrEnabled: Empty response"); |
| 1010 | } else if (ar.exception instanceof CommandException) { |
| 1011 | loge("isVoNrEnabled: CommandException: " |
| 1012 | + ar.exception); |
| 1013 | } else { |
| 1014 | loge("isVoNrEnabled: Unknown exception"); |
| 1015 | } |
| 1016 | } |
| 1017 | notifyRequester(request); |
| 1018 | break; |
| 1019 | |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 1020 | case CMD_ENABLE_NR_DUAL_CONNECTIVITY: { |
| 1021 | request = (MainThreadRequest) msg.obj; |
| 1022 | onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request); |
| 1023 | Phone phone = getPhoneFromRequest(request); |
| 1024 | if (phone != null) { |
| 1025 | phone.setNrDualConnectivityState((int) request.argument, onCompleted, |
| 1026 | request.workSource); |
| 1027 | } else { |
| 1028 | loge("enableNrDualConnectivity: No phone object"); |
| 1029 | request.result = |
| 1030 | TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE; |
| 1031 | notifyRequester(request); |
| 1032 | } |
| 1033 | break; |
| 1034 | } |
| 1035 | |
| 1036 | case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: { |
| 1037 | ar = (AsyncResult) msg.obj; |
| 1038 | request = (MainThreadRequest) ar.userObj; |
| 1039 | if (ar.exception == null) { |
| 1040 | request.result = |
| 1041 | TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS; |
| 1042 | } else { |
| 1043 | request.result = |
| 1044 | TelephonyManager |
| 1045 | .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR; |
| 1046 | if (ar.exception instanceof CommandException) { |
| 1047 | CommandException.Error error = |
| 1048 | ((CommandException) (ar.exception)).getCommandError(); |
| 1049 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1050 | request.result = |
| 1051 | TelephonyManager |
| 1052 | .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE; |
Sooraj Sasindran | 2965416 | 2021-03-03 23:00:01 +0000 | [diff] [blame] | 1053 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1054 | request.result = |
| 1055 | TelephonyManager |
| 1056 | .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED; |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 1057 | } |
| 1058 | loge("enableNrDualConnectivity" + ": CommandException: " |
| 1059 | + ar.exception); |
| 1060 | } else { |
| 1061 | loge("enableNrDualConnectivity" + ": Unknown exception"); |
| 1062 | } |
| 1063 | } |
| 1064 | notifyRequester(request); |
| 1065 | break; |
| 1066 | } |
| 1067 | |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 1068 | case CMD_ENABLE_VONR: { |
| 1069 | request = (MainThreadRequest) msg.obj; |
| 1070 | onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request); |
| 1071 | Phone phone = getPhoneFromRequest(request); |
| 1072 | if (phone != null) { |
| 1073 | phone.setVoNrEnabled((boolean) request.argument, onCompleted, |
| 1074 | request.workSource); |
| 1075 | } else { |
| 1076 | loge("setVoNrEnabled: No phone object"); |
| 1077 | request.result = |
| 1078 | TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE; |
| 1079 | notifyRequester(request); |
| 1080 | } |
| 1081 | break; |
| 1082 | } |
| 1083 | |
| 1084 | case EVENT_ENABLE_VONR_DONE: { |
| 1085 | ar = (AsyncResult) msg.obj; |
| 1086 | request = (MainThreadRequest) ar.userObj; |
| 1087 | if (ar.exception == null) { |
| 1088 | request.result = TelephonyManager.ENABLE_VONR_SUCCESS; |
| 1089 | } else { |
| 1090 | request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR; |
| 1091 | if (ar.exception instanceof CommandException) { |
| 1092 | CommandException.Error error = |
| 1093 | ((CommandException) (ar.exception)).getCommandError(); |
| 1094 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1095 | request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE; |
| 1096 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1097 | request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED; |
| 1098 | } else { |
| 1099 | request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR; |
| 1100 | } |
| 1101 | loge("setVoNrEnabled" + ": CommandException: " |
| 1102 | + ar.exception); |
| 1103 | } else { |
| 1104 | loge("setVoNrEnabled" + ": Unknown exception"); |
| 1105 | } |
| 1106 | } |
| 1107 | notifyRequester(request); |
| 1108 | break; |
| 1109 | } |
| 1110 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1111 | case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1112 | request = (MainThreadRequest) msg.obj; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1113 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE, |
| 1114 | request); |
| 1115 | getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1116 | break; |
| 1117 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1118 | case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1119 | ar = (AsyncResult) msg.obj; |
| 1120 | request = (MainThreadRequest) ar.userObj; |
| 1121 | if (ar.exception == null && ar.result != null) { |
| 1122 | request.result = ar.result; // Integer |
| 1123 | } else { |
Nazish Tabassum | e8ba43a | 2020-07-28 14:49:25 +0530 | [diff] [blame] | 1124 | // request.result must be set to something non-null |
| 1125 | // for the calling thread to unblock |
| 1126 | request.result = new int[]{-1}; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1127 | if (ar.result == null) { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1128 | loge("getAllowedNetworkTypesBitmask: Empty response"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1129 | } else if (ar.exception instanceof CommandException) { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1130 | loge("getAllowedNetworkTypesBitmask: CommandException: " |
| 1131 | + ar.exception); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1132 | } else { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1133 | loge("getAllowedNetworkTypesBitmask: Unknown exception"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1134 | } |
| 1135 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1136 | notifyRequester(request); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1137 | break; |
| 1138 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1139 | case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1140 | request = (MainThreadRequest) msg.obj; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1141 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE, |
| 1142 | request); |
| 1143 | Pair<Integer, Long> reasonWithNetworkTypes = |
| 1144 | (Pair<Integer, Long>) request.argument; |
| 1145 | getPhoneFromRequest(request).setAllowedNetworkTypes( |
| 1146 | reasonWithNetworkTypes.first, |
| 1147 | reasonWithNetworkTypes.second, |
| 1148 | onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1149 | break; |
| 1150 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1151 | case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE: |
| 1152 | handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1153 | break; |
| 1154 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1155 | case CMD_SET_VOICEMAIL_NUMBER: |
| 1156 | request = (MainThreadRequest) msg.obj; |
| 1157 | onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request); |
| 1158 | Pair<String, String> tagNum = (Pair<String, String>) request.argument; |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1159 | getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second, |
| 1160 | onCompleted); |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1161 | break; |
| 1162 | |
| 1163 | case EVENT_SET_VOICEMAIL_NUMBER_DONE: |
| 1164 | handleNullReturnEvent(msg, "setVoicemailNumber"); |
| 1165 | break; |
| 1166 | |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 1167 | case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC: |
| 1168 | request = (MainThreadRequest) msg.obj; |
| 1169 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE, |
| 1170 | request); |
| 1171 | getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted); |
| 1172 | break; |
| 1173 | |
| 1174 | case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE: |
| 1175 | handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic"); |
| 1176 | break; |
| 1177 | |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1178 | case CMD_PERFORM_NETWORK_SCAN: |
| 1179 | request = (MainThreadRequest) msg.obj; |
| 1180 | onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request); |
| 1181 | getPhoneFromRequest(request).getAvailableNetworks(onCompleted); |
| 1182 | break; |
| 1183 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1184 | case CMD_GET_CALL_FORWARDING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1185 | request = (MainThreadRequest) msg.obj; |
| 1186 | onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1187 | Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args = |
| 1188 | (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>) |
| 1189 | request.argument; |
| 1190 | int callForwardingReason = args.first; |
| 1191 | request.phone.getCallForwardingOption(callForwardingReason, onCompleted); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1192 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1193 | } |
| 1194 | case EVENT_GET_CALL_FORWARDING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1195 | ar = (AsyncResult) msg.obj; |
| 1196 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1197 | TelephonyManager.CallForwardingInfoCallback callback = |
| 1198 | ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>) |
| 1199 | request.argument).second; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1200 | if (ar.exception == null && ar.result != null) { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1201 | CallForwardingInfo callForwardingInfo = null; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1202 | CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result; |
| 1203 | for (CallForwardInfo callForwardInfo : callForwardInfos) { |
| 1204 | // Service Class is a bit mask per 3gpp 27.007. Search for |
| 1205 | // any service for voice call. |
| 1206 | if ((callForwardInfo.serviceClass |
| 1207 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0) { |
Yuchen Dong | 69cc141 | 2021-09-27 20:27:01 +0800 | [diff] [blame] | 1208 | callForwardingInfo = new CallForwardingInfo( |
| 1209 | callForwardInfo.status |
| 1210 | == CommandsInterface.CF_ACTION_ENABLE, |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1211 | callForwardInfo.reason, |
| 1212 | callForwardInfo.number, |
| 1213 | callForwardInfo.timeSeconds); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1214 | break; |
| 1215 | } |
| 1216 | } |
| 1217 | // Didn't find a call forward info for voice call. |
| 1218 | if (callForwardingInfo == null) { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1219 | callForwardingInfo = new CallForwardingInfo(false /* enabled */, |
| 1220 | 0 /* reason */, null /* number */, 0 /* timeout */); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1221 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1222 | callback.onCallForwardingInfoAvailable(callForwardingInfo); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1223 | } else { |
| 1224 | if (ar.result == null) { |
| 1225 | loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response"); |
| 1226 | } |
| 1227 | if (ar.exception != null) { |
| 1228 | loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception); |
| 1229 | } |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1230 | int errorCode = TelephonyManager |
| 1231 | .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1232 | if (ar.exception instanceof CommandException) { |
| 1233 | CommandException.Error error = |
| 1234 | ((CommandException) (ar.exception)).getCommandError(); |
| 1235 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1236 | errorCode = TelephonyManager |
| 1237 | .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1238 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1239 | errorCode = TelephonyManager |
| 1240 | .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1241 | } |
| 1242 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1243 | callback.onError(errorCode); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1244 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1245 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1246 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1247 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1248 | case CMD_SET_CALL_FORWARDING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1249 | request = (MainThreadRequest) msg.obj; |
| 1250 | onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1251 | request = (MainThreadRequest) msg.obj; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1252 | CallForwardingInfo callForwardingInfoToSet = |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1253 | ((Pair<CallForwardingInfo, Consumer<Integer>>) |
| 1254 | request.argument).first; |
| 1255 | request.phone.setCallForwardingOption( |
| 1256 | callForwardingInfoToSet.isEnabled() |
Calvin Pan | 258f1f7 | 2021-07-28 21:46:56 +0800 | [diff] [blame] | 1257 | ? CommandsInterface.CF_ACTION_REGISTRATION |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1258 | : CommandsInterface.CF_ACTION_DISABLE, |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1259 | callForwardingInfoToSet.getReason(), |
| 1260 | callForwardingInfoToSet.getNumber(), |
| 1261 | callForwardingInfoToSet.getTimeoutSeconds(), onCompleted); |
| 1262 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1263 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1264 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1265 | case EVENT_SET_CALL_FORWARDING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1266 | ar = (AsyncResult) msg.obj; |
| 1267 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1268 | Consumer<Integer> callback = |
| 1269 | ((Pair<CallForwardingInfo, Consumer<Integer>>) |
| 1270 | request.argument).second; |
| 1271 | if (ar.exception != null) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1272 | loge("setCallForwarding exception: " + ar.exception); |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1273 | int errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1274 | .RESULT_ERROR_UNKNOWN; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1275 | if (ar.exception instanceof CommandException) { |
| 1276 | CommandException.Error error = |
| 1277 | ((CommandException) (ar.exception)).getCommandError(); |
| 1278 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1279 | errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1280 | .RESULT_ERROR_FDN_CHECK_FAILURE; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1281 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1282 | errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1283 | .RESULT_ERROR_NOT_SUPPORTED; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1284 | } |
| 1285 | } |
| 1286 | callback.accept(errorCode); |
| 1287 | } else { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1288 | callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1289 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1290 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1291 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1292 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1293 | case CMD_GET_CALL_WAITING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1294 | request = (MainThreadRequest) msg.obj; |
| 1295 | onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request); |
| 1296 | getPhoneFromRequest(request).getCallWaiting(onCompleted); |
| 1297 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1298 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1299 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1300 | case EVENT_GET_CALL_WAITING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1301 | ar = (AsyncResult) msg.obj; |
| 1302 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1303 | Consumer<Integer> callback = (Consumer<Integer>) request.argument; |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1304 | int callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1305 | if (ar.exception == null && ar.result != null) { |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1306 | int[] callForwardResults = (int[]) ar.result; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1307 | // Service Class is a bit mask per 3gpp 27.007. |
| 1308 | // Search for any service for voice call. |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1309 | if (callForwardResults.length > 1 |
| 1310 | && ((callForwardResults[1] |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1311 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) { |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1312 | callWaitingStatus = callForwardResults[0] == 0 |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1313 | ? TelephonyManager.CALL_WAITING_STATUS_DISABLED |
| 1314 | : TelephonyManager.CALL_WAITING_STATUS_ENABLED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1315 | } else { |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1316 | callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1317 | } |
| 1318 | } else { |
| 1319 | if (ar.result == null) { |
| 1320 | loge("EVENT_GET_CALL_WAITING_DONE: Empty response"); |
| 1321 | } |
| 1322 | if (ar.exception != null) { |
| 1323 | loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception); |
| 1324 | } |
| 1325 | if (ar.exception instanceof CommandException) { |
| 1326 | CommandException.Error error = |
| 1327 | ((CommandException) (ar.exception)).getCommandError(); |
| 1328 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1329 | callWaitingStatus = |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1330 | TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED; |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1331 | } else if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
| 1332 | callWaitingStatus = |
| 1333 | TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1334 | } |
| 1335 | } |
| 1336 | } |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1337 | callback.accept(callWaitingStatus); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1338 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1339 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1340 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1341 | case CMD_SET_CALL_WAITING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1342 | request = (MainThreadRequest) msg.obj; |
| 1343 | onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1344 | boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first; |
| 1345 | getPhoneFromRequest(request).setCallWaiting(enable, onCompleted); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1346 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1347 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1348 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1349 | case EVENT_SET_CALL_WAITING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1350 | ar = (AsyncResult) msg.obj; |
| 1351 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1352 | boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first; |
| 1353 | Consumer<Integer> callback = |
| 1354 | ((Pair<Boolean, Consumer<Integer>>) request.argument).second; |
| 1355 | if (ar.exception != null) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1356 | loge("setCallWaiting exception: " + ar.exception); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1357 | if (ar.exception instanceof CommandException) { |
| 1358 | CommandException.Error error = |
| 1359 | ((CommandException) (ar.exception)).getCommandError(); |
| 1360 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1361 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED); |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1362 | } else if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
| 1363 | callback.accept( |
| 1364 | TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1365 | } else { |
| 1366 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 1367 | } |
| 1368 | } else { |
| 1369 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 1370 | } |
| 1371 | } else { |
| 1372 | callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED |
| 1373 | : TelephonyManager.CALL_WAITING_STATUS_DISABLED); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1374 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1375 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1376 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1377 | case EVENT_PERFORM_NETWORK_SCAN_DONE: |
| 1378 | ar = (AsyncResult) msg.obj; |
| 1379 | request = (MainThreadRequest) ar.userObj; |
| 1380 | CellNetworkScanResult cellScanResult; |
| 1381 | if (ar.exception == null && ar.result != null) { |
| 1382 | cellScanResult = new CellNetworkScanResult( |
| 1383 | CellNetworkScanResult.STATUS_SUCCESS, |
| 1384 | (List<OperatorInfo>) ar.result); |
| 1385 | } else { |
| 1386 | if (ar.result == null) { |
| 1387 | loge("getCellNetworkScanResults: Empty response"); |
| 1388 | } |
| 1389 | if (ar.exception != null) { |
| 1390 | loge("getCellNetworkScanResults: Exception: " + ar.exception); |
| 1391 | } |
| 1392 | int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR; |
| 1393 | if (ar.exception instanceof CommandException) { |
| 1394 | CommandException.Error error = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 1395 | ((CommandException) (ar.exception)).getCommandError(); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1396 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1397 | errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE; |
| 1398 | } else if (error == CommandException.Error.GENERIC_FAILURE) { |
| 1399 | errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE; |
| 1400 | } |
| 1401 | } |
| 1402 | cellScanResult = new CellNetworkScanResult(errorCode, null); |
| 1403 | } |
| 1404 | request.result = cellScanResult; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1405 | notifyRequester(request); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1406 | break; |
| 1407 | |
| 1408 | case CMD_SET_NETWORK_SELECTION_MODE_MANUAL: |
| 1409 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1410 | ManualNetworkSelectionArgument selArg = |
| 1411 | (ManualNetworkSelectionArgument) request.argument; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1412 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE, |
| 1413 | request); |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1414 | getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo, |
| 1415 | selArg.persistSelection, onCompleted); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1416 | break; |
| 1417 | |
| 1418 | case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE: |
Pengquan Meng | e3d01e2 | 2018-09-20 15:25:35 -0700 | [diff] [blame] | 1419 | ar = (AsyncResult) msg.obj; |
| 1420 | request = (MainThreadRequest) ar.userObj; |
| 1421 | if (ar.exception == null) { |
| 1422 | request.result = true; |
| 1423 | } else { |
| 1424 | request.result = false; |
| 1425 | loge("setNetworkSelectionModeManual " + ar.exception); |
| 1426 | } |
| 1427 | notifyRequester(request); |
| 1428 | mApp.onNetworkSelectionChanged(request.subId); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1429 | break; |
| 1430 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1431 | case CMD_GET_MODEM_ACTIVITY_INFO: |
| 1432 | request = (MainThreadRequest) msg.obj; |
| 1433 | onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1434 | if (defaultPhone != null) { |
| 1435 | defaultPhone.getModemActivityInfo(onCompleted, request.workSource); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1436 | } else { |
| 1437 | ResultReceiver result = (ResultReceiver) request.argument; |
| 1438 | Bundle bundle = new Bundle(); |
| 1439 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 1440 | new ModemActivityInfo(0, 0, 0, |
| 1441 | new int[ModemActivityInfo.getNumTxPowerLevels()], 0)); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1442 | result.send(0, bundle); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1443 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1444 | break; |
| 1445 | |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1446 | case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: { |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1447 | ar = (AsyncResult) msg.obj; |
| 1448 | request = (MainThreadRequest) ar.userObj; |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1449 | ResultReceiver result = (ResultReceiver) request.argument; |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1450 | int error = 0; |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 1451 | ModemActivityInfo ret = null; |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1452 | if (mLastModemActivityInfo == null) { |
| 1453 | mLastModemActivitySpecificInfo = new ActivityStatsTechSpecificInfo[1]; |
| 1454 | mLastModemActivitySpecificInfo[0] = |
| 1455 | new ActivityStatsTechSpecificInfo( |
| 1456 | 0, |
| 1457 | 0, |
| 1458 | new int[ModemActivityInfo.getNumTxPowerLevels()], |
| 1459 | 0); |
| 1460 | mLastModemActivityInfo = |
| 1461 | new ModemActivityInfo(0, 0, 0, mLastModemActivitySpecificInfo); |
| 1462 | } |
| 1463 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1464 | if (ar.exception == null && ar.result != null) { |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1465 | // Update the last modem activity info and the result of the request. |
| 1466 | ModemActivityInfo info = (ModemActivityInfo) ar.result; |
| 1467 | if (isModemActivityInfoValid(info)) { |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1468 | mergeModemActivityInfo(info); |
Gary Jian | 76280a4 | 2022-12-07 16:18:33 +0800 | [diff] [blame] | 1469 | } else { |
| 1470 | loge("queryModemActivityInfo: invalid response"); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1471 | } |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 1472 | // This is needed to decouple ret from mLastModemActivityInfo |
| 1473 | // We don't want to return mLastModemActivityInfo which is updated |
| 1474 | // inside mergeModemActivityInfo() |
| 1475 | ret = new ModemActivityInfo( |
| 1476 | mLastModemActivityInfo.getTimestampMillis(), |
| 1477 | mLastModemActivityInfo.getSleepTimeMillis(), |
| 1478 | mLastModemActivityInfo.getIdleTimeMillis(), |
| 1479 | deepCopyModemActivitySpecificInfo(mLastModemActivitySpecificInfo)); |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1480 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1481 | } else { |
| 1482 | if (ar.result == null) { |
| 1483 | loge("queryModemActivityInfo: Empty response"); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1484 | error = TelephonyManager.ModemActivityInfoException |
| 1485 | .ERROR_INVALID_INFO_RECEIVED; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1486 | } else if (ar.exception instanceof CommandException) { |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1487 | loge("queryModemActivityInfo: CommandException: " + ar.exception); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1488 | error = TelephonyManager.ModemActivityInfoException |
| 1489 | .ERROR_MODEM_RESPONSE_ERROR; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1490 | } else { |
| 1491 | loge("queryModemActivityInfo: Unknown exception"); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1492 | error = TelephonyManager.ModemActivityInfoException |
| 1493 | .ERROR_UNKNOWN; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1494 | } |
| 1495 | } |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1496 | Bundle bundle = new Bundle(); |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 1497 | if (ret != null) { |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1498 | bundle.putParcelable( |
| 1499 | TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 1500 | ret); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1501 | } else { |
| 1502 | bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error); |
| 1503 | } |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1504 | result.send(0, bundle); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1505 | notifyRequester(request); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1506 | break; |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1507 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1508 | |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 1509 | case CMD_SET_ALLOWED_CARRIERS: { |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1510 | request = (MainThreadRequest) msg.obj; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1511 | CarrierRestrictionRules argument = |
| 1512 | (CarrierRestrictionRules) request.argument; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1513 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request); |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1514 | defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1515 | break; |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 1516 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1517 | |
| 1518 | case EVENT_SET_ALLOWED_CARRIERS_DONE: |
| 1519 | ar = (AsyncResult) msg.obj; |
| 1520 | request = (MainThreadRequest) ar.userObj; |
| 1521 | if (ar.exception == null && ar.result != null) { |
| 1522 | request.result = ar.result; |
| 1523 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1524 | request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR; |
| 1525 | if (ar.exception instanceof CommandException) { |
| 1526 | loge("setAllowedCarriers: CommandException: " + ar.exception); |
| 1527 | CommandException.Error error = |
| 1528 | ((CommandException) (ar.exception)).getCommandError(); |
| 1529 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1530 | request.result = |
| 1531 | TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED; |
| 1532 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1533 | } else { |
| 1534 | loge("setAllowedCarriers: Unknown exception"); |
| 1535 | } |
| 1536 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1537 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1538 | break; |
| 1539 | |
| 1540 | case CMD_GET_ALLOWED_CARRIERS: |
| 1541 | request = (MainThreadRequest) msg.obj; |
| 1542 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1543 | defaultPhone.getAllowedCarriers(onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1544 | break; |
| 1545 | |
| 1546 | case EVENT_GET_ALLOWED_CARRIERS_DONE: |
| 1547 | ar = (AsyncResult) msg.obj; |
| 1548 | request = (MainThreadRequest) ar.userObj; |
| 1549 | if (ar.exception == null && ar.result != null) { |
| 1550 | request.result = ar.result; |
| 1551 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1552 | request.result = new IllegalStateException( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 1553 | "Failed to get carrier restrictions"); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1554 | if (ar.result == null) { |
| 1555 | loge("getAllowedCarriers: Empty response"); |
| 1556 | } else if (ar.exception instanceof CommandException) { |
| 1557 | loge("getAllowedCarriers: CommandException: " + |
| 1558 | ar.exception); |
| 1559 | } else { |
| 1560 | loge("getAllowedCarriers: Unknown exception"); |
| 1561 | } |
| 1562 | } |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 1563 | if (request.argument != null) { |
| 1564 | // This is for the implementation of carrierRestrictionStatus. |
| 1565 | CallerCallbackInfo callbackInfo = (CallerCallbackInfo) request.argument; |
| 1566 | Consumer<Integer> callback = callbackInfo.getConsumer(); |
| 1567 | int callerCarrierId = callbackInfo.getCarrierId(); |
| 1568 | int lockStatus = TelephonyManager.CARRIER_RESTRICTION_STATUS_UNKNOWN; |
| 1569 | if (ar.exception == null && ar.result instanceof CarrierRestrictionRules) { |
| 1570 | CarrierRestrictionRules carrierRestrictionRules = |
| 1571 | (CarrierRestrictionRules) ar.result; |
| 1572 | int carrierId = -1; |
| 1573 | try { |
| 1574 | CarrierIdentifier carrierIdentifier = |
| 1575 | carrierRestrictionRules.getAllowedCarriers().get(0); |
| 1576 | carrierId = CarrierResolver.getCarrierIdFromIdentifier(mApp, |
| 1577 | carrierIdentifier); |
| 1578 | } catch (NullPointerException | IndexOutOfBoundsException ex) { |
| 1579 | Rlog.e(LOG_TAG, "CarrierIdentifier exception = " + ex); |
| 1580 | } |
| 1581 | lockStatus = carrierRestrictionRules.getCarrierRestrictionStatus(); |
| 1582 | if (carrierId != -1 && callerCarrierId == carrierId && lockStatus |
| 1583 | == TelephonyManager.CARRIER_RESTRICTION_STATUS_RESTRICTED) { |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 1584 | lockStatus = TelephonyManager |
| 1585 | .CARRIER_RESTRICTION_STATUS_RESTRICTED_TO_CALLER; |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 1586 | } |
| 1587 | } else { |
| 1588 | Rlog.e(LOG_TAG, |
| 1589 | "getCarrierRestrictionStatus: exception ex = " + ar.exception); |
| 1590 | } |
| 1591 | callback.accept(lockStatus); |
| 1592 | } else { |
| 1593 | // This is for the implementation of getAllowedCarriers. |
| 1594 | notifyRequester(request); |
| 1595 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1596 | break; |
| 1597 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1598 | case EVENT_GET_FORBIDDEN_PLMNS_DONE: |
| 1599 | ar = (AsyncResult) msg.obj; |
| 1600 | request = (MainThreadRequest) ar.userObj; |
| 1601 | if (ar.exception == null && ar.result != null) { |
| 1602 | request.result = ar.result; |
| 1603 | } else { |
| 1604 | request.result = new IllegalArgumentException( |
| 1605 | "Failed to retrieve Forbidden Plmns"); |
| 1606 | if (ar.result == null) { |
| 1607 | loge("getForbiddenPlmns: Empty response"); |
| 1608 | } else { |
| 1609 | loge("getForbiddenPlmns: Unknown exception"); |
| 1610 | } |
| 1611 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1612 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1613 | break; |
| 1614 | |
| 1615 | case CMD_GET_FORBIDDEN_PLMNS: |
| 1616 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1617 | uiccPort = getUiccPortFromRequest(request); |
| 1618 | if (uiccPort == null) { |
| 1619 | loge("getForbiddenPlmns() UiccPort is null"); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1620 | request.result = new IllegalArgumentException( |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1621 | "getForbiddenPlmns() UiccPort is null"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1622 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1623 | break; |
| 1624 | } |
| 1625 | Integer appType = (Integer) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1626 | UiccCardApplication uiccApp = uiccPort.getApplicationByType(appType); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1627 | if (uiccApp == null) { |
| 1628 | loge("getForbiddenPlmns() no app with specified type -- " |
| 1629 | + appType); |
| 1630 | request.result = new IllegalArgumentException("Failed to get UICC App"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1631 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1632 | break; |
| 1633 | } else { |
| 1634 | if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid() |
| 1635 | + " specified type -- " + appType); |
| 1636 | } |
| 1637 | onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request); |
| 1638 | ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 1639 | onCompleted); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1640 | break; |
| 1641 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1642 | case CMD_SWITCH_SLOTS: |
| 1643 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 1644 | List<UiccSlotMapping> slotMapping = (List<UiccSlotMapping>) request.argument; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1645 | onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 1646 | UiccController.getInstance().switchSlots(slotMapping, onCompleted); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1647 | break; |
| 1648 | |
| 1649 | case EVENT_SWITCH_SLOTS_DONE: |
| 1650 | ar = (AsyncResult) msg.obj; |
| 1651 | request = (MainThreadRequest) ar.userObj; |
| 1652 | request.result = (ar.exception == null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1653 | notifyRequester(request); |
| 1654 | break; |
| 1655 | case CMD_GET_NETWORK_SELECTION_MODE: |
| 1656 | request = (MainThreadRequest) msg.obj; |
| 1657 | onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request); |
| 1658 | getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted); |
| 1659 | break; |
| 1660 | |
| 1661 | case EVENT_GET_NETWORK_SELECTION_MODE_DONE: |
| 1662 | ar = (AsyncResult) msg.obj; |
| 1663 | request = (MainThreadRequest) ar.userObj; |
| 1664 | if (ar.exception != null) { |
| 1665 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 1666 | } else { |
| 1667 | int mode = ((int[]) ar.result)[0]; |
| 1668 | if (mode == 0) { |
| 1669 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO; |
| 1670 | } else { |
| 1671 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL; |
| 1672 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1673 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1674 | notifyRequester(request); |
| 1675 | break; |
| 1676 | case CMD_GET_CDMA_ROAMING_MODE: |
| 1677 | request = (MainThreadRequest) msg.obj; |
| 1678 | onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request); |
| 1679 | getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted); |
| 1680 | break; |
| 1681 | case EVENT_GET_CDMA_ROAMING_MODE_DONE: |
| 1682 | ar = (AsyncResult) msg.obj; |
| 1683 | request = (MainThreadRequest) ar.userObj; |
| 1684 | if (ar.exception != null) { |
| 1685 | request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT; |
| 1686 | } else { |
| 1687 | request.result = ((int[]) ar.result)[0]; |
| 1688 | } |
| 1689 | notifyRequester(request); |
| 1690 | break; |
| 1691 | case CMD_SET_CDMA_ROAMING_MODE: |
| 1692 | request = (MainThreadRequest) msg.obj; |
| 1693 | onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request); |
| 1694 | int mode = (int) request.argument; |
| 1695 | getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted); |
| 1696 | break; |
| 1697 | case EVENT_SET_CDMA_ROAMING_MODE_DONE: |
| 1698 | ar = (AsyncResult) msg.obj; |
| 1699 | request = (MainThreadRequest) ar.userObj; |
| 1700 | request.result = ar.exception == null; |
| 1701 | notifyRequester(request); |
| 1702 | break; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 1703 | case CMD_GET_CDMA_SUBSCRIPTION_MODE: |
| 1704 | request = (MainThreadRequest) msg.obj; |
| 1705 | onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1706 | getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted); |
| 1707 | break; |
| 1708 | case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1709 | ar = (AsyncResult) msg.obj; |
| 1710 | request = (MainThreadRequest) ar.userObj; |
| 1711 | if (ar.exception != null) { |
| 1712 | request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM; |
| 1713 | } else { |
| 1714 | request.result = ((int[]) ar.result)[0]; |
| 1715 | } |
| 1716 | notifyRequester(request); |
| 1717 | break; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1718 | case CMD_SET_CDMA_SUBSCRIPTION_MODE: |
| 1719 | request = (MainThreadRequest) msg.obj; |
| 1720 | onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1721 | int subscriptionMode = (int) request.argument; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 1722 | getPhoneFromRequest(request).setCdmaSubscriptionMode( |
| 1723 | subscriptionMode, onCompleted); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1724 | break; |
| 1725 | case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1726 | ar = (AsyncResult) msg.obj; |
| 1727 | request = (MainThreadRequest) ar.userObj; |
| 1728 | request.result = ar.exception == null; |
| 1729 | notifyRequester(request); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1730 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1731 | case CMD_GET_ALL_CELL_INFO: |
| 1732 | request = (MainThreadRequest) msg.obj; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1733 | onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1734 | request.phone.requestCellInfoUpdate(request.workSource, onCompleted); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1735 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1736 | case EVENT_GET_ALL_CELL_INFO_DONE: |
| 1737 | ar = (AsyncResult) msg.obj; |
| 1738 | request = (MainThreadRequest) ar.userObj; |
Nathan Harold | 8d0f174 | 2018-10-02 12:14:47 -0700 | [diff] [blame] | 1739 | // If a timeout occurs, the response will be null |
| 1740 | request.result = (ar.exception == null && ar.result != null) |
| 1741 | ? ar.result : new ArrayList<CellInfo>(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1742 | synchronized (request) { |
| 1743 | request.notifyAll(); |
| 1744 | } |
| 1745 | break; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1746 | case CMD_REQUEST_CELL_INFO_UPDATE: |
| 1747 | request = (MainThreadRequest) msg.obj; |
| 1748 | request.phone.requestCellInfoUpdate(request.workSource, |
| 1749 | obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request)); |
| 1750 | break; |
| 1751 | case EVENT_REQUEST_CELL_INFO_UPDATE_DONE: |
| 1752 | ar = (AsyncResult) msg.obj; |
| 1753 | request = (MainThreadRequest) ar.userObj; |
| 1754 | ICellInfoCallback cb = (ICellInfoCallback) request.argument; |
| 1755 | try { |
| 1756 | if (ar.exception != null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1757 | Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception); |
Meng Wang | d8921f4 | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1758 | cb.onError( |
| 1759 | TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR, |
| 1760 | ar.exception.getClass().getName(), |
| 1761 | ar.exception.toString()); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1762 | } else if (ar.result == null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1763 | Log.w(LOG_TAG, "Timeout Waiting for CellInfo!"); |
Meng Wang | d8921f4 | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1764 | cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1765 | } else { |
| 1766 | // use the result as returned |
| 1767 | cb.onCellInfo((List<CellInfo>) ar.result); |
| 1768 | } |
| 1769 | } catch (RemoteException re) { |
| 1770 | Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException"); |
| 1771 | } |
| 1772 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1773 | case CMD_GET_CELL_LOCATION: { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1774 | request = (MainThreadRequest) msg.obj; |
| 1775 | WorkSource ws = (WorkSource) request.argument; |
| 1776 | Phone phone = getPhoneFromRequest(request); |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1777 | phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request)); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1778 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1779 | } |
| 1780 | case EVENT_GET_CELL_LOCATION_DONE: { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1781 | ar = (AsyncResult) msg.obj; |
| 1782 | request = (MainThreadRequest) ar.userObj; |
| 1783 | if (ar.exception == null) { |
| 1784 | request.result = ar.result; |
| 1785 | } else { |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1786 | Phone phone = getPhoneFromRequest(request); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1787 | request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1788 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1789 | } |
| 1790 | |
| 1791 | synchronized (request) { |
| 1792 | request.notifyAll(); |
| 1793 | } |
| 1794 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1795 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1796 | case CMD_MODEM_REBOOT: |
| 1797 | request = (MainThreadRequest) msg.obj; |
| 1798 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1799 | defaultPhone.rebootModem(onCompleted); |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1800 | break; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1801 | case EVENT_CMD_MODEM_REBOOT_DONE: |
| 1802 | handleNullReturnEvent(msg, "rebootModem"); |
| 1803 | break; |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 1804 | case CMD_REQUEST_ENABLE_MODEM: { |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1805 | request = (MainThreadRequest) msg.obj; |
| 1806 | boolean enable = (boolean) request.argument; |
| 1807 | onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1808 | onCompleted.arg1 = enable ? 1 : 0; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1809 | PhoneConfigurationManager.getInstance() |
| 1810 | .enablePhone(request.phone, enable, onCompleted); |
| 1811 | break; |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 1812 | } |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1813 | case EVENT_ENABLE_MODEM_DONE: { |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1814 | ar = (AsyncResult) msg.obj; |
| 1815 | request = (MainThreadRequest) ar.userObj; |
| 1816 | request.result = (ar.exception == null); |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1817 | int phoneId = request.phone.getPhoneId(); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1818 | //update the cache as modem status has changed |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1819 | if ((boolean) request.result) { |
| 1820 | mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1); |
| 1821 | updateModemStateMetrics(); |
| 1822 | } else { |
| 1823 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1824 | + ar.exception); |
| 1825 | } |
| 1826 | notifyRequester(request); |
| 1827 | break; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1828 | } |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1829 | case CMD_GET_MODEM_STATUS: |
| 1830 | request = (MainThreadRequest) msg.obj; |
| 1831 | onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request); |
| 1832 | PhoneConfigurationManager.getInstance() |
| 1833 | .getPhoneStatusFromModem(request.phone, onCompleted); |
| 1834 | break; |
| 1835 | case EVENT_GET_MODEM_STATUS_DONE: |
| 1836 | ar = (AsyncResult) msg.obj; |
| 1837 | request = (MainThreadRequest) ar.userObj; |
| 1838 | int id = request.phone.getPhoneId(); |
| 1839 | if (ar.exception == null && ar.result != null) { |
| 1840 | request.result = ar.result; |
| 1841 | //update the cache as modem status has changed |
| 1842 | mPhoneConfigurationManager.addToPhoneStatusCache(id, |
| 1843 | (boolean) request.result); |
| 1844 | } else { |
| 1845 | // Return true if modem status cannot be retrieved. For most cases, |
| 1846 | // modem status is on. And for older version modems, GET_MODEM_STATUS |
| 1847 | // and disable modem are not supported. Modem is always on. |
| 1848 | // TODO: this should be fixed in R to support a third |
| 1849 | // status UNKNOWN b/131631629 |
| 1850 | request.result = true; |
| 1851 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1852 | + ar.exception); |
| 1853 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1854 | notifyRequester(request); |
| 1855 | break; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 1856 | case CMD_SET_SYSTEM_SELECTION_CHANNELS: { |
| 1857 | request = (MainThreadRequest) msg.obj; |
| 1858 | onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request); |
| 1859 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 1860 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 1861 | request.phone.setSystemSelectionChannels(args.first, onCompleted); |
| 1862 | break; |
| 1863 | } |
| 1864 | case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: { |
| 1865 | ar = (AsyncResult) msg.obj; |
| 1866 | request = (MainThreadRequest) ar.userObj; |
| 1867 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 1868 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 1869 | args.second.accept(ar.exception == null); |
| 1870 | notifyRequester(request); |
| 1871 | break; |
| 1872 | } |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1873 | case CMD_GET_SYSTEM_SELECTION_CHANNELS: { |
| 1874 | request = (MainThreadRequest) msg.obj; |
| 1875 | onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request); |
| 1876 | Phone phone = getPhoneFromRequest(request); |
| 1877 | if (phone != null) { |
| 1878 | phone.getSystemSelectionChannels(onCompleted); |
| 1879 | } else { |
| 1880 | loge("getSystemSelectionChannels: No phone object"); |
| 1881 | request.result = new ArrayList<RadioAccessSpecifier>(); |
| 1882 | notifyRequester(request); |
| 1883 | } |
| 1884 | break; |
| 1885 | } |
| 1886 | case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE: |
| 1887 | ar = (AsyncResult) msg.obj; |
| 1888 | request = (MainThreadRequest) ar.userObj; |
| 1889 | if (ar.exception == null && ar.result != null) { |
| 1890 | request.result = ar.result; |
| 1891 | } else { |
Sarah Chin | 428d1d6 | 2021-03-13 03:17:40 -0800 | [diff] [blame] | 1892 | request.result = new IllegalStateException( |
| 1893 | "Failed to retrieve system selecton channels"); |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1894 | if (ar.result == null) { |
| 1895 | loge("getSystemSelectionChannels: Empty response"); |
| 1896 | } else { |
| 1897 | loge("getSystemSelectionChannels: Unknown exception"); |
| 1898 | } |
| 1899 | } |
| 1900 | notifyRequester(request); |
| 1901 | break; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1902 | case EVENT_SET_FORBIDDEN_PLMNS_DONE: |
| 1903 | ar = (AsyncResult) msg.obj; |
| 1904 | request = (MainThreadRequest) ar.userObj; |
| 1905 | if (ar.exception == null && ar.result != null) { |
| 1906 | request.result = ar.result; |
| 1907 | } else { |
| 1908 | request.result = -1; |
| 1909 | loge("Failed to set Forbidden Plmns"); |
| 1910 | if (ar.result == null) { |
| 1911 | loge("setForbidenPlmns: Empty response"); |
| 1912 | } else if (ar.exception != null) { |
| 1913 | loge("setForbiddenPlmns: Exception: " + ar.exception); |
| 1914 | request.result = -1; |
| 1915 | } else { |
| 1916 | loge("setForbiddenPlmns: Unknown exception"); |
| 1917 | } |
| 1918 | } |
| 1919 | notifyRequester(request); |
| 1920 | break; |
| 1921 | case CMD_SET_FORBIDDEN_PLMNS: |
| 1922 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1923 | uiccPort = getUiccPortFromRequest(request); |
| 1924 | if (uiccPort == null) { |
| 1925 | loge("setForbiddenPlmns: UiccPort is null"); |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1926 | request.result = -1; |
| 1927 | notifyRequester(request); |
| 1928 | break; |
| 1929 | } |
| 1930 | Pair<Integer, List<String>> setFplmnsArgs = |
| 1931 | (Pair<Integer, List<String>>) request.argument; |
| 1932 | appType = setFplmnsArgs.first; |
| 1933 | List<String> fplmns = setFplmnsArgs.second; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1934 | uiccApp = uiccPort.getApplicationByType(appType); |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1935 | if (uiccApp == null) { |
| 1936 | loge("setForbiddenPlmns: no app with specified type -- " + appType); |
| 1937 | request.result = -1; |
| 1938 | loge("Failed to get UICC App"); |
| 1939 | notifyRequester(request); |
| 1940 | } else { |
| 1941 | onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request); |
| 1942 | ((SIMRecords) uiccApp.getIccRecords()) |
| 1943 | .setForbiddenPlmns(onCompleted, fplmns); |
| 1944 | } |
yinchengzhao | 4d163c0 | 2019-12-12 15:21:47 -0800 | [diff] [blame] | 1945 | break; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 1946 | case CMD_ERASE_MODEM_CONFIG: |
| 1947 | request = (MainThreadRequest) msg.obj; |
| 1948 | onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request); |
| 1949 | defaultPhone.eraseModemConfig(onCompleted); |
| 1950 | break; |
| 1951 | case EVENT_ERASE_MODEM_CONFIG_DONE: |
| 1952 | handleNullReturnEvent(msg, "eraseModemConfig"); |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1953 | break; |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1954 | |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 1955 | case CMD_ERASE_DATA_SHARED_PREFERENCES: |
| 1956 | request = (MainThreadRequest) msg.obj; |
| 1957 | request.result = defaultPhone.eraseDataInSharedPreferences(); |
| 1958 | notifyRequester(request); |
| 1959 | break; |
| 1960 | |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1961 | case CMD_CHANGE_ICC_LOCK_PASSWORD: |
| 1962 | request = (MainThreadRequest) msg.obj; |
| 1963 | onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request); |
| 1964 | Pair<String, String> changed = (Pair<String, String>) request.argument; |
| 1965 | getPhoneFromRequest(request).getIccCard().changeIccLockPassword( |
| 1966 | changed.first, changed.second, onCompleted); |
| 1967 | break; |
| 1968 | case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE: |
| 1969 | ar = (AsyncResult) msg.obj; |
| 1970 | request = (MainThreadRequest) ar.userObj; |
| 1971 | if (ar.exception == null) { |
| 1972 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1973 | // If the operation is successful, update the PIN storage |
| 1974 | Pair<String, String> passwords = (Pair<String, String>) request.argument; |
| 1975 | int phoneId = getPhoneFromRequest(request).getPhoneId(); |
Jon Spivack | 9c3bc76 | 2021-10-06 20:53:09 +0000 | [diff] [blame] | 1976 | UiccController.getInstance().getPinStorage() |
| 1977 | .storePin(passwords.second, phoneId); |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1978 | } else { |
| 1979 | request.result = msg.arg1; |
| 1980 | } |
| 1981 | notifyRequester(request); |
| 1982 | break; |
| 1983 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1984 | case CMD_SET_ICC_LOCK_ENABLED: { |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1985 | request = (MainThreadRequest) msg.obj; |
| 1986 | onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request); |
| 1987 | Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument; |
| 1988 | getPhoneFromRequest(request).getIccCard().setIccLockEnabled( |
| 1989 | enabled.first, enabled.second, onCompleted); |
| 1990 | break; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1991 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1992 | case EVENT_SET_ICC_LOCK_ENABLED_DONE: |
| 1993 | ar = (AsyncResult) msg.obj; |
| 1994 | request = (MainThreadRequest) ar.userObj; |
| 1995 | if (ar.exception == null) { |
| 1996 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1997 | // If the operation is successful, update the PIN storage |
| 1998 | Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument; |
| 1999 | int phoneId = getPhoneFromRequest(request).getPhoneId(); |
| 2000 | if (enabled.first) { |
Jon Spivack | 9c3bc76 | 2021-10-06 20:53:09 +0000 | [diff] [blame] | 2001 | UiccController.getInstance().getPinStorage() |
| 2002 | .storePin(enabled.second, phoneId); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2003 | } else { |
| 2004 | UiccController.getInstance().getPinStorage().clearPin(phoneId); |
| 2005 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 2006 | } else { |
| 2007 | request.result = msg.arg1; |
| 2008 | } |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2009 | |
| 2010 | |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 2011 | notifyRequester(request); |
| 2012 | break; |
| 2013 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 2014 | case MSG_NOTIFY_USER_ACTIVITY: |
| 2015 | removeMessages(MSG_NOTIFY_USER_ACTIVITY); |
Peter Wang | 59571be | 2020-01-27 12:35:15 +0800 | [diff] [blame] | 2016 | Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION); |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 2017 | intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY); |
| 2018 | getDefaultPhone().getContext().sendBroadcastAsUser( |
| 2019 | intent, UserHandle.ALL, permission.USER_ACTIVITY); |
| 2020 | break; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 2021 | |
| 2022 | case CMD_SET_DATA_THROTTLING: { |
| 2023 | request = (MainThreadRequest) msg.obj; |
| 2024 | onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request); |
| 2025 | DataThrottlingRequest dataThrottlingRequest = |
| 2026 | (DataThrottlingRequest) request.argument; |
| 2027 | Phone phone = getPhoneFromRequest(request); |
| 2028 | if (phone != null) { |
| 2029 | phone.setDataThrottling(onCompleted, |
| 2030 | request.workSource, dataThrottlingRequest.getDataThrottlingAction(), |
| 2031 | dataThrottlingRequest.getCompletionDurationMillis()); |
| 2032 | } else { |
| 2033 | loge("setDataThrottling: No phone object"); |
| 2034 | request.result = |
| 2035 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 2036 | notifyRequester(request); |
| 2037 | } |
| 2038 | |
| 2039 | break; |
| 2040 | } |
| 2041 | case EVENT_SET_DATA_THROTTLING_DONE: |
| 2042 | ar = (AsyncResult) msg.obj; |
| 2043 | request = (MainThreadRequest) ar.userObj; |
| 2044 | |
| 2045 | if (ar.exception == null) { |
| 2046 | request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 2047 | } else if (ar.exception instanceof CommandException) { |
| 2048 | loge("setDataThrottling: CommandException: " + ar.exception); |
| 2049 | CommandException.Error error = |
| 2050 | ((CommandException) (ar.exception)).getCommandError(); |
| 2051 | |
| 2052 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 2053 | request.result = TelephonyManager |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2054 | .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 2055 | } else if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 2056 | request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS; |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 2057 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 2058 | request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 2059 | } else { |
| 2060 | request.result = |
| 2061 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 2062 | } |
| 2063 | } else { |
| 2064 | request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 2065 | } |
| 2066 | Log.w(LOG_TAG, "DataThrottlingResult = " + request.result); |
| 2067 | notifyRequester(request); |
| 2068 | break; |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 2069 | |
| 2070 | case CMD_SET_SIM_POWER: { |
| 2071 | request = (MainThreadRequest) msg.obj; |
| 2072 | onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request); |
| 2073 | request = (MainThreadRequest) msg.obj; |
| 2074 | int stateToSet = |
| 2075 | ((Pair<Integer, IIntegerConsumer>) |
| 2076 | request.argument).first; |
| 2077 | request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource); |
| 2078 | break; |
| 2079 | } |
| 2080 | case EVENT_SET_SIM_POWER_DONE: { |
| 2081 | ar = (AsyncResult) msg.obj; |
| 2082 | request = (MainThreadRequest) ar.userObj; |
| 2083 | IIntegerConsumer callback = |
| 2084 | ((Pair<Integer, IIntegerConsumer>) request.argument).second; |
| 2085 | if (ar.exception != null) { |
| 2086 | loge("setSimPower exception: " + ar.exception); |
| 2087 | int errorCode = TelephonyManager.CallForwardingInfoCallback |
| 2088 | .RESULT_ERROR_UNKNOWN; |
| 2089 | if (ar.exception instanceof CommandException) { |
| 2090 | CommandException.Error error = |
| 2091 | ((CommandException) (ar.exception)).getCommandError(); |
| 2092 | if (error == CommandException.Error.SIM_ERR) { |
| 2093 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR; |
| 2094 | } else if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 2095 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE; |
| 2096 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 2097 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED; |
| 2098 | } else { |
| 2099 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR; |
| 2100 | } |
| 2101 | } |
| 2102 | try { |
| 2103 | callback.accept(errorCode); |
| 2104 | } catch (RemoteException e) { |
| 2105 | // Ignore if the remote process is no longer available to call back. |
| 2106 | Log.w(LOG_TAG, "setSimPower: callback not available."); |
| 2107 | } |
| 2108 | } else { |
| 2109 | try { |
| 2110 | callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS); |
| 2111 | } catch (RemoteException e) { |
| 2112 | // Ignore if the remote process is no longer available to call back. |
| 2113 | Log.w(LOG_TAG, "setSimPower: callback not available."); |
| 2114 | } |
| 2115 | } |
| 2116 | break; |
| 2117 | } |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 2118 | case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: { |
| 2119 | request = (MainThreadRequest) msg.obj; |
| 2120 | |
| 2121 | final Phone phone = getPhoneFromRequest(request); |
| 2122 | if (phone == null || phone.getServiceStateTracker() == null) { |
| 2123 | request.result = new IllegalStateException("Phone or SST is null"); |
| 2124 | notifyRequester(request); |
| 2125 | break; |
| 2126 | } |
| 2127 | |
| 2128 | Pair<Integer, SignalStrengthUpdateRequest> pair = |
| 2129 | (Pair<Integer, SignalStrengthUpdateRequest>) request.argument; |
| 2130 | onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE, |
| 2131 | request); |
Rambo Wang | 6568f17 | 2021-02-03 16:56:47 -0800 | [diff] [blame] | 2132 | phone.getSignalStrengthController().setSignalStrengthUpdateRequest( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2133 | request.subId, pair.first /*callingUid*/, |
| 2134 | pair.second /*request*/, onCompleted); |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 2135 | break; |
| 2136 | } |
| 2137 | case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: { |
| 2138 | ar = (AsyncResult) msg.obj; |
| 2139 | request = (MainThreadRequest) ar.userObj; |
| 2140 | // request.result will be the exception of ar if present, true otherwise. |
| 2141 | // Be cautious not to leave result null which will wait() forever |
| 2142 | request.result = ar.exception != null ? ar.exception : true; |
| 2143 | notifyRequester(request); |
| 2144 | break; |
| 2145 | } |
| 2146 | case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: { |
| 2147 | request = (MainThreadRequest) msg.obj; |
| 2148 | |
| 2149 | Phone phone = getPhoneFromRequest(request); |
| 2150 | if (phone == null || phone.getServiceStateTracker() == null) { |
| 2151 | request.result = new IllegalStateException("Phone or SST is null"); |
| 2152 | notifyRequester(request); |
| 2153 | break; |
| 2154 | } |
| 2155 | |
| 2156 | Pair<Integer, SignalStrengthUpdateRequest> pair = |
| 2157 | (Pair<Integer, SignalStrengthUpdateRequest>) request.argument; |
| 2158 | onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE, |
| 2159 | request); |
Rambo Wang | 6568f17 | 2021-02-03 16:56:47 -0800 | [diff] [blame] | 2160 | phone.getSignalStrengthController().clearSignalStrengthUpdateRequest( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2161 | request.subId, pair.first /*callingUid*/, |
| 2162 | pair.second /*request*/, onCompleted); |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 2163 | break; |
| 2164 | } |
| 2165 | case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: { |
| 2166 | ar = (AsyncResult) msg.obj; |
| 2167 | request = (MainThreadRequest) ar.userObj; |
| 2168 | request.result = ar.exception != null ? ar.exception : true; |
| 2169 | notifyRequester(request); |
| 2170 | break; |
| 2171 | } |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 2172 | |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2173 | case CMD_GET_SLICING_CONFIG: { |
| 2174 | request = (MainThreadRequest) msg.obj; |
| 2175 | onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request); |
| 2176 | request.phone.getSlicingConfig(onCompleted); |
| 2177 | break; |
| 2178 | } |
| 2179 | case EVENT_GET_SLICING_CONFIG_DONE: { |
| 2180 | ar = (AsyncResult) msg.obj; |
| 2181 | request = (MainThreadRequest) ar.userObj; |
| 2182 | ResultReceiver result = (ResultReceiver) request.argument; |
| 2183 | |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2184 | NetworkSlicingConfig slicingConfig = null; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2185 | Bundle bundle = new Bundle(); |
| 2186 | int resultCode = 0; |
| 2187 | if (ar.exception != null) { |
| 2188 | Log.e(LOG_TAG, "Exception retrieving slicing configuration=" |
| 2189 | + ar.exception); |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2190 | resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2191 | } else if (ar.result == null) { |
| 2192 | Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!"); |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2193 | resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2194 | } else { |
| 2195 | // use the result as returned |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2196 | resultCode = TelephonyManager.NetworkSlicingException.SUCCESS; |
| 2197 | slicingConfig = (NetworkSlicingConfig) ar.result; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2198 | } |
| 2199 | |
| 2200 | if (slicingConfig == null) { |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2201 | slicingConfig = new NetworkSlicingConfig(); |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2202 | } |
| 2203 | bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig); |
| 2204 | result.send(resultCode, bundle); |
| 2205 | notifyRequester(request); |
| 2206 | break; |
| 2207 | } |
| 2208 | |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2209 | case CMD_PURCHASE_PREMIUM_CAPABILITY: { |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2210 | request = (MainThreadRequest) msg.obj; |
| 2211 | onCompleted = obtainMessage(EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE, request); |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2212 | PurchasePremiumCapabilityArgument arg = |
| 2213 | (PurchasePremiumCapabilityArgument) request.argument; |
Sarah Chin | 46355ba | 2022-11-01 23:51:16 -0700 | [diff] [blame] | 2214 | SlicePurchaseController.getInstance(request.phone).purchasePremiumCapability( |
Sarah Chin | b8218c2 | 2023-01-04 13:35:29 -0800 | [diff] [blame] | 2215 | arg.capability, onCompleted); |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2216 | break; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2217 | } |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2218 | |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2219 | case EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE: { |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2220 | ar = (AsyncResult) msg.obj; |
| 2221 | request = (MainThreadRequest) ar.userObj; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2222 | PurchasePremiumCapabilityArgument arg = |
| 2223 | (PurchasePremiumCapabilityArgument) request.argument; |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2224 | try { |
| 2225 | int result = (int) ar.result; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2226 | arg.callback.accept(result); |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2227 | log("purchasePremiumCapability: capability=" |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2228 | + TelephonyManager.convertPremiumCapabilityToString(arg.capability) |
Sarah Chin | ff8b180 | 2023-04-11 14:22:14 -0700 | [diff] [blame] | 2229 | + ", result=" |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2230 | + TelephonyManager.convertPurchaseResultToString(result)); |
| 2231 | } catch (RemoteException e) { |
| 2232 | String logStr = "Purchase premium capability " |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2233 | + TelephonyManager.convertPremiumCapabilityToString(arg.capability) |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2234 | + " failed: " + e; |
| 2235 | if (DBG) log(logStr); |
| 2236 | AnomalyReporter.reportAnomaly( |
| 2237 | UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr); |
| 2238 | } |
| 2239 | break; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2240 | } |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2241 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2242 | case CMD_PREPARE_UNATTENDED_REBOOT: |
| 2243 | request = (MainThreadRequest) msg.obj; |
| 2244 | request.result = |
Rafael Higuera Silva | d963064 | 2021-09-20 15:32:01 +0000 | [diff] [blame] | 2245 | UiccController.getInstance().getPinStorage() |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2246 | .prepareUnattendedReboot(request.workSource); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2247 | notifyRequester(request); |
| 2248 | break; |
| 2249 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2250 | default: |
| 2251 | Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what); |
| 2252 | break; |
| 2253 | } |
| 2254 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2255 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 2256 | private void notifyRequester(MainThreadRequest request) { |
| 2257 | synchronized (request) { |
| 2258 | request.notifyAll(); |
| 2259 | } |
| 2260 | } |
| 2261 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2262 | private void handleNullReturnEvent(Message msg, String command) { |
| 2263 | AsyncResult ar = (AsyncResult) msg.obj; |
| 2264 | MainThreadRequest request = (MainThreadRequest) ar.userObj; |
| 2265 | if (ar.exception == null) { |
| 2266 | request.result = true; |
| 2267 | } else { |
| 2268 | request.result = false; |
| 2269 | if (ar.exception instanceof CommandException) { |
| 2270 | loge(command + ": CommandException: " + ar.exception); |
| 2271 | } else { |
| 2272 | loge(command + ": Unknown exception"); |
| 2273 | } |
| 2274 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 2275 | notifyRequester(request); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2276 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2277 | } |
| 2278 | |
| 2279 | /** |
| 2280 | * Posts the specified command to be executed on the main thread, |
| 2281 | * waits for the request to complete, and returns the result. |
| 2282 | * @see #sendRequestAsync |
| 2283 | */ |
| 2284 | private Object sendRequest(int command, Object argument) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2285 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, |
| 2286 | null, -1 /*timeoutInMs*/); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 2287 | } |
| 2288 | |
| 2289 | /** |
| 2290 | * Posts the specified command to be executed on the main thread, |
| 2291 | * waits for the request to complete, and returns the result. |
| 2292 | * @see #sendRequestAsync |
| 2293 | */ |
| 2294 | private Object sendRequest(int command, Object argument, WorkSource workSource) { |
| 2295 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2296 | null, workSource, -1 /*timeoutInMs*/); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2297 | } |
| 2298 | |
| 2299 | /** |
| 2300 | * Posts the specified command to be executed on the main thread, |
| 2301 | * waits for the request to complete, and returns the result. |
| 2302 | * @see #sendRequestAsync |
| 2303 | */ |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2304 | private Object sendRequest(int command, Object argument, Integer subId) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2305 | return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/); |
| 2306 | } |
| 2307 | |
| 2308 | /** |
| 2309 | * Posts the specified command to be executed on the main thread, |
| 2310 | * waits for the request to complete for at most {@code timeoutInMs}, and returns the result |
| 2311 | * if not timeout or null otherwise. |
| 2312 | * @see #sendRequestAsync |
| 2313 | */ |
| 2314 | private @Nullable Object sendRequest(int command, Object argument, Integer subId, |
| 2315 | long timeoutInMs) { |
| 2316 | return sendRequest(command, argument, subId, null, null, timeoutInMs); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 2317 | } |
| 2318 | |
| 2319 | /** |
| 2320 | * Posts the specified command to be executed on the main thread, |
| 2321 | * waits for the request to complete, and returns the result. |
| 2322 | * @see #sendRequestAsync |
| 2323 | */ |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2324 | private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2325 | return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2326 | } |
| 2327 | |
| 2328 | /** |
| 2329 | * Posts the specified command to be executed on the main thread, |
| 2330 | * waits for the request to complete, and returns the result. |
| 2331 | * @see #sendRequestAsync |
| 2332 | */ |
| 2333 | private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2334 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, |
| 2335 | workSource, -1 /*timeoutInMs*/); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2336 | } |
| 2337 | |
| 2338 | /** |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2339 | * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is |
| 2340 | * negative, waits for the request to complete, and returns the result. Otherwise, wait for |
| 2341 | * maximum of {@code timeoutInMs} milliseconds, interrupt and return null. |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2342 | * @see #sendRequestAsync |
| 2343 | */ |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2344 | private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone, |
| 2345 | WorkSource workSource, long timeoutInMs) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2346 | if (Looper.myLooper() == mMainThreadHandler.getLooper()) { |
| 2347 | throw new RuntimeException("This method will deadlock if called from the main thread."); |
| 2348 | } |
| 2349 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2350 | MainThreadRequest request = null; |
| 2351 | if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) { |
| 2352 | throw new IllegalArgumentException("subId and phone cannot both be specified!"); |
| 2353 | } else if (phone != null) { |
| 2354 | request = new MainThreadRequest(argument, phone, workSource); |
| 2355 | } else { |
| 2356 | request = new MainThreadRequest(argument, subId, workSource); |
| 2357 | } |
| 2358 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2359 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 2360 | msg.sendToTarget(); |
| 2361 | |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2362 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2363 | synchronized (request) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2364 | if (timeoutInMs >= 0) { |
| 2365 | // Wait for at least timeoutInMs before returning null request result |
| 2366 | long now = SystemClock.elapsedRealtime(); |
| 2367 | long deadline = now + timeoutInMs; |
Grace Jia | 8a0a1e8 | 2021-05-23 22:59:52 -0700 | [diff] [blame] | 2368 | while (request.result == null && now < deadline) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2369 | try { |
| 2370 | request.wait(deadline - now); |
| 2371 | } catch (InterruptedException e) { |
| 2372 | // Do nothing, go back and check if request is completed or timeout |
| 2373 | } finally { |
| 2374 | now = SystemClock.elapsedRealtime(); |
| 2375 | } |
| 2376 | } |
| 2377 | } else { |
| 2378 | // Wait for the request to complete |
| 2379 | while (request.result == null) { |
| 2380 | try { |
| 2381 | request.wait(); |
| 2382 | } catch (InterruptedException e) { |
| 2383 | // Do nothing, go back and wait until the request is complete |
| 2384 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2385 | } |
| 2386 | } |
| 2387 | } |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2388 | if (request.result == null) { |
| 2389 | Log.wtf(LOG_TAG, |
| 2390 | "sendRequest: Blocking command timed out. Something has gone terribly wrong."); |
| 2391 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2392 | return request.result; |
| 2393 | } |
| 2394 | |
| 2395 | /** |
| 2396 | * Asynchronous ("fire and forget") version of sendRequest(): |
| 2397 | * Posts the specified command to be executed on the main thread, and |
| 2398 | * returns immediately. |
| 2399 | * @see #sendRequest |
| 2400 | */ |
| 2401 | private void sendRequestAsync(int command) { |
| 2402 | mMainThreadHandler.sendEmptyMessage(command); |
| 2403 | } |
| 2404 | |
| 2405 | /** |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2406 | * Same as {@link #sendRequestAsync(int)} except it takes an argument. |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2407 | * @see {@link #sendRequest(int)} |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2408 | */ |
| 2409 | private void sendRequestAsync(int command, Object argument) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2410 | sendRequestAsync(command, argument, null, null); |
| 2411 | } |
| 2412 | |
| 2413 | /** |
| 2414 | * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource. |
| 2415 | * @see {@link #sendRequest(int,Object)} |
| 2416 | */ |
| 2417 | private void sendRequestAsync( |
| 2418 | int command, Object argument, Phone phone, WorkSource workSource) { |
| 2419 | MainThreadRequest request = new MainThreadRequest(argument, phone, workSource); |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2420 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 2421 | msg.sendToTarget(); |
| 2422 | } |
| 2423 | |
| 2424 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2425 | * Initialize the singleton PhoneInterfaceManager instance. |
| 2426 | * This is only done once, at startup, from PhoneApp.onCreate(). |
| 2427 | */ |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2428 | /* package */ static PhoneInterfaceManager init(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2429 | synchronized (PhoneInterfaceManager.class) { |
| 2430 | if (sInstance == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2431 | sInstance = new PhoneInterfaceManager(app); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2432 | } else { |
| 2433 | Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance); |
| 2434 | } |
| 2435 | return sInstance; |
| 2436 | } |
| 2437 | } |
| 2438 | |
| 2439 | /** Private constructor; @see init() */ |
Jordan Liu | 1979a04 | 2020-03-20 21:39:35 +0000 | [diff] [blame] | 2440 | private PhoneInterfaceManager(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2441 | mApp = app; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2442 | mCM = PhoneGlobals.getInstance().mCM; |
Brad Ebinger | d1947d8 | 2021-05-17 20:54:49 +0000 | [diff] [blame] | 2443 | mImsResolver = ImsResolver.getInstance(); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 2444 | mSatelliteController = SatelliteController.getInstance(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 2445 | mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2446 | mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE); |
| 2447 | mMainThreadHandler = new MainThreadHandler(); |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 2448 | mTelephonySharedPreferences = PreferenceManager.getDefaultSharedPreferences(mApp); |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 2449 | mNetworkScanRequestTracker = new NetworkScanRequestTracker(); |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 2450 | mPhoneConfigurationManager = PhoneConfigurationManager.getInstance(); |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 2451 | mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance(); |
Peter Wang | a3cf4ac | 2020-01-27 09:39:46 +0800 | [diff] [blame] | 2452 | mNotifyUserActivity = new AtomicBoolean(false); |
Tyler Gunn | 64144d9 | 2022-03-17 14:16:41 -0700 | [diff] [blame] | 2453 | PropertyInvalidatedCache.invalidateCache(TelephonyManager.CACHE_KEY_PHONE_ACCOUNT_TO_SUBID); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2454 | publish(); |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 2455 | CarrierAllowListInfo.loadInstance(mApp); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2456 | } |
| 2457 | |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 2458 | @VisibleForTesting |
| 2459 | public SharedPreferences getSharedPreferences() { |
| 2460 | return mTelephonySharedPreferences; |
| 2461 | } |
| 2462 | |
Gil Cukierman | 92cc7db | 2023-01-06 19:25:53 +0000 | [diff] [blame] | 2463 | /** |
| 2464 | * Get the default phone for this device. |
| 2465 | */ |
| 2466 | @VisibleForTesting |
| 2467 | public Phone getDefaultPhone() { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2468 | Phone thePhone = getPhone(getDefaultSubscription()); |
| 2469 | return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone(); |
| 2470 | } |
| 2471 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2472 | private void publish() { |
| 2473 | if (DBG) log("publish: " + this); |
| 2474 | |
Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 2475 | TelephonyFrameworkInitializer |
| 2476 | .getTelephonyServiceManager() |
| 2477 | .getTelephonyServiceRegisterer() |
| 2478 | .register(this); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2479 | } |
| 2480 | |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 2481 | private Phone getPhoneFromRequest(MainThreadRequest request) { |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 2482 | if (request.phone != null) { |
| 2483 | return request.phone; |
| 2484 | } else { |
| 2485 | return getPhoneFromSubId(request.subId); |
| 2486 | } |
| 2487 | } |
| 2488 | |
| 2489 | private Phone getPhoneFromSubId(int subId) { |
| 2490 | return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) |
| 2491 | ? getDefaultPhone() : getPhone(subId); |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 2492 | } |
| 2493 | |
Aishwarya Mallampati | 5e581e1 | 2023-01-17 21:57:06 +0000 | [diff] [blame] | 2494 | /** |
| 2495 | * Get phone object associated with a subscription. |
| 2496 | * Return default phone if phone object associated with subscription is null |
| 2497 | * @param subId - subscriptionId |
| 2498 | * @return phone object associated with a subscription or default phone if null. |
| 2499 | */ |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 2500 | private @NonNull Phone getPhoneFromSubIdOrDefault(int subId) { |
Aishwarya Mallampati | 5e581e1 | 2023-01-17 21:57:06 +0000 | [diff] [blame] | 2501 | Phone phone = getPhoneFromSubId(subId); |
| 2502 | if (phone == null) { |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 2503 | loge("Called with invalid subId: " + subId + ". Retrying with default phone."); |
Aishwarya Mallampati | 5e581e1 | 2023-01-17 21:57:06 +0000 | [diff] [blame] | 2504 | phone = getDefaultPhone(); |
| 2505 | } |
| 2506 | return phone; |
| 2507 | } |
| 2508 | |
Rambo Wang | e53e07d | 2022-05-10 13:01:13 -0700 | [diff] [blame] | 2509 | @Nullable |
| 2510 | private UiccPort getUiccPortFromRequest(@NonNull MainThreadRequest request) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2511 | Phone phone = getPhoneFromRequest(request); |
| 2512 | return phone == null ? null : |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 2513 | UiccController.getInstance().getUiccPort(phone.getPhoneId()); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2514 | } |
| 2515 | |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 2516 | /** |
| 2517 | * @param subId The sub Id that associates the phone. If the device has no active SIM, passing |
| 2518 | * in {@link SubscriptionManager#DEFAULT_SUBSCRIPTION_ID} or any sub <= |
| 2519 | * {@link SubscriptionManager#INVALID_SUBSCRIPTION_ID} will return {@code null}. |
| 2520 | * @return The Phone associated the sub Id |
| 2521 | */ |
| 2522 | private @Nullable Phone getPhone(int subId) { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 2523 | return PhoneFactory.getPhone(SubscriptionManager.getPhoneId(subId)); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2524 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2525 | |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 2526 | private void sendEraseModemConfig(@NonNull Phone phone) { |
| 2527 | Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null); |
| 2528 | if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 2529 | } |
| 2530 | |
| 2531 | private void sendEraseDataInSharedPreferences(@NonNull Phone phone) { |
| 2532 | Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null); |
| 2533 | if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail")); |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 2534 | } |
| 2535 | |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 2536 | private boolean isImsAvailableOnDevice() { |
| 2537 | PackageManager pm = getDefaultPhone().getContext().getPackageManager(); |
| 2538 | if (pm == null) { |
| 2539 | // For some reason package manger is not available.. This will fail internally anyway, |
| 2540 | // so do not throw error and allow. |
| 2541 | return true; |
| 2542 | } |
| 2543 | return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0); |
| 2544 | } |
| 2545 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2546 | public void dial(String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2547 | dialForSubscriber(getPreferredVoiceSubscription(), number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2548 | } |
| 2549 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2550 | public void dialForSubscriber(int subId, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2551 | if (DBG) log("dial: " + number); |
| 2552 | // No permission check needed here: This is just a wrapper around the |
| 2553 | // ACTION_DIAL intent, which is available to any app since it puts up |
| 2554 | // the UI before it does anything. |
| 2555 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2556 | final long identity = Binder.clearCallingIdentity(); |
| 2557 | try { |
| 2558 | String url = createTelUrl(number); |
| 2559 | if (url == null) { |
| 2560 | return; |
| 2561 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2562 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2563 | // PENDING: should we just silently fail if phone is offhook or ringing? |
| 2564 | PhoneConstants.State state = mCM.getState(subId); |
| 2565 | if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) { |
| 2566 | Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url)); |
| 2567 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2568 | mApp.startActivity(intent); |
| 2569 | } |
| 2570 | } finally { |
| 2571 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2572 | } |
| 2573 | } |
| 2574 | |
| 2575 | public void call(String callingPackage, String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2576 | callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2577 | } |
| 2578 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2579 | public void callForSubscriber(int subId, String callingPackage, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2580 | if (DBG) log("call: " + number); |
| 2581 | |
| 2582 | // This is just a wrapper around the ACTION_CALL intent, but we still |
| 2583 | // need to do a permission check since we're calling startActivity() |
| 2584 | // from the context of the phone app. |
| 2585 | enforceCallPermission(); |
| 2586 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 2587 | if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage) |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2588 | != AppOpsManager.MODE_ALLOWED) { |
| 2589 | return; |
| 2590 | } |
| 2591 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2592 | final long identity = Binder.clearCallingIdentity(); |
| 2593 | try { |
| 2594 | String url = createTelUrl(number); |
| 2595 | if (url == null) { |
| 2596 | return; |
| 2597 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2598 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2599 | boolean isValid = false; |
| 2600 | final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged(); |
| 2601 | if (slist != null) { |
| 2602 | for (SubscriptionInfo subInfoRecord : slist) { |
| 2603 | if (subInfoRecord.getSubscriptionId() == subId) { |
| 2604 | isValid = true; |
| 2605 | break; |
| 2606 | } |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 2607 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 2608 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2609 | if (!isValid) { |
| 2610 | return; |
| 2611 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 2612 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2613 | Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url)); |
| 2614 | intent.putExtra(SUBSCRIPTION_KEY, subId); |
| 2615 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2616 | mApp.startActivity(intent); |
| 2617 | } finally { |
| 2618 | Binder.restoreCallingIdentity(identity); |
| 2619 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2620 | } |
| 2621 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2622 | public boolean supplyPinForSubscriber(int subId, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2623 | int [] resultArray = supplyPinReportResultForSubscriber(subId, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2624 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 2625 | } |
| 2626 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2627 | public boolean supplyPukForSubscriber(int subId, String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2628 | int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2629 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 2630 | } |
| 2631 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2632 | public int[] supplyPinReportResultForSubscriber(int subId, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2633 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2634 | |
| 2635 | final long identity = Binder.clearCallingIdentity(); |
| 2636 | try { |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2637 | Phone phone = getPhone(subId); |
| 2638 | final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2639 | checkSimPin.start(); |
| 2640 | return checkSimPin.unlockSim(null, pin); |
| 2641 | } finally { |
| 2642 | Binder.restoreCallingIdentity(identity); |
| 2643 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2644 | } |
| 2645 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2646 | public int[] supplyPukReportResultForSubscriber(int subId, String puk, 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 checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2653 | checkSimPuk.start(); |
| 2654 | return checkSimPuk.unlockSim(puk, pin); |
| 2655 | } finally { |
| 2656 | Binder.restoreCallingIdentity(identity); |
| 2657 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2658 | } |
| 2659 | |
| 2660 | /** |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2661 | * Helper thread to turn async call to SimCard#supplyPin into |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2662 | * a synchronous one. |
| 2663 | */ |
| 2664 | private static class UnlockSim extends Thread { |
| 2665 | |
| 2666 | private final IccCard mSimCard; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2667 | private final int mPhoneId; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2668 | |
| 2669 | private boolean mDone = false; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2670 | private int mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 2671 | private int mRetryCount = -1; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2672 | |
| 2673 | // For replies from SimCard interface |
| 2674 | private Handler mHandler; |
| 2675 | |
| 2676 | // For async handler to identify request type |
| 2677 | private static final int SUPPLY_PIN_COMPLETE = 100; |
| 2678 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2679 | UnlockSim(int phoneId, IccCard simCard) { |
| 2680 | mPhoneId = phoneId; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2681 | mSimCard = simCard; |
| 2682 | } |
| 2683 | |
| 2684 | @Override |
| 2685 | public void run() { |
| 2686 | Looper.prepare(); |
| 2687 | synchronized (UnlockSim.this) { |
| 2688 | mHandler = new Handler() { |
| 2689 | @Override |
| 2690 | public void handleMessage(Message msg) { |
| 2691 | AsyncResult ar = (AsyncResult) msg.obj; |
| 2692 | switch (msg.what) { |
| 2693 | case SUPPLY_PIN_COMPLETE: |
| 2694 | Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE"); |
| 2695 | synchronized (UnlockSim.this) { |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2696 | mRetryCount = msg.arg1; |
| 2697 | if (ar.exception != null) { |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2698 | CommandException.Error error = null; |
| 2699 | if (ar.exception instanceof CommandException) { |
| 2700 | error = ((CommandException) (ar.exception)) |
| 2701 | .getCommandError(); |
| 2702 | } |
| 2703 | if (error == CommandException.Error.PASSWORD_INCORRECT) { |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2704 | mResult = PhoneConstants.PIN_PASSWORD_INCORRECT; |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2705 | } else if (error == CommandException.Error.ABORTED) { |
| 2706 | /* When UiccCardApp dispose, handle message and return |
| 2707 | exception */ |
vivi.li | b5e9ada | 2019-09-12 16:04:24 +0800 | [diff] [blame] | 2708 | mResult = PhoneConstants.PIN_OPERATION_ABORTED; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2709 | } else { |
| 2710 | mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 2711 | } |
| 2712 | } else { |
| 2713 | mResult = PhoneConstants.PIN_RESULT_SUCCESS; |
| 2714 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2715 | mDone = true; |
| 2716 | UnlockSim.this.notifyAll(); |
| 2717 | } |
| 2718 | break; |
| 2719 | } |
| 2720 | } |
| 2721 | }; |
| 2722 | UnlockSim.this.notifyAll(); |
| 2723 | } |
| 2724 | Looper.loop(); |
| 2725 | } |
| 2726 | |
| 2727 | /* |
| 2728 | * Use PIN or PUK to unlock SIM card |
| 2729 | * |
| 2730 | * If PUK is null, unlock SIM card with PIN |
| 2731 | * |
| 2732 | * If PUK is not null, unlock SIM card with PUK and set PIN code |
Mengjun Leng | 7ddbbfc | 2023-08-17 11:53:32 +0530 | [diff] [blame] | 2733 | * |
| 2734 | * Besides, since it is reused in class level, the thread's looper will be stopped to avoid |
| 2735 | * its thread leak. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2736 | */ |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2737 | synchronized int[] unlockSim(String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2738 | |
| 2739 | while (mHandler == null) { |
| 2740 | try { |
| 2741 | wait(); |
| 2742 | } catch (InterruptedException e) { |
| 2743 | Thread.currentThread().interrupt(); |
| 2744 | } |
| 2745 | } |
| 2746 | Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE); |
| 2747 | |
| 2748 | if (puk == null) { |
| 2749 | mSimCard.supplyPin(pin, callback); |
| 2750 | } else { |
| 2751 | mSimCard.supplyPuk(puk, pin, callback); |
| 2752 | } |
| 2753 | |
| 2754 | while (!mDone) { |
| 2755 | try { |
| 2756 | Log.d(LOG_TAG, "wait for done"); |
| 2757 | wait(); |
| 2758 | } catch (InterruptedException e) { |
| 2759 | // Restore the interrupted status |
| 2760 | Thread.currentThread().interrupt(); |
| 2761 | } |
| 2762 | } |
| 2763 | Log.d(LOG_TAG, "done"); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2764 | int[] resultArray = new int[2]; |
| 2765 | resultArray[0] = mResult; |
| 2766 | resultArray[1] = mRetryCount; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2767 | |
| 2768 | if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) { |
Jon Spivack | 9c3bc76 | 2021-10-06 20:53:09 +0000 | [diff] [blame] | 2769 | UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2770 | } |
Mengjun Leng | 7ddbbfc | 2023-08-17 11:53:32 +0530 | [diff] [blame] | 2771 | // This instance is no longer reused, so quit its thread's looper. |
| 2772 | mHandler.getLooper().quitSafely(); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2773 | |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2774 | return resultArray; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2775 | } |
| 2776 | } |
| 2777 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2778 | /** |
| 2779 | * This method has been removed due to privacy and stability concerns. |
| 2780 | */ |
| 2781 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2782 | public void updateServiceLocation() { |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2783 | Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()"); |
| 2784 | return; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2785 | } |
| 2786 | |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2787 | @Override |
| 2788 | public void updateServiceLocationWithPackageName(String callingPackage) { |
| 2789 | mApp.getSystemService(AppOpsManager.class) |
| 2790 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 2791 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 2792 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2793 | if (targetSdk > android.os.Build.VERSION_CODES.R) { |
| 2794 | // Callers targeting S have no business invoking this method. |
| 2795 | return; |
| 2796 | } |
| 2797 | |
| 2798 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2799 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2800 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2801 | .setCallingPackage(callingPackage) |
| 2802 | .setCallingFeatureId(null) |
| 2803 | .setCallingPid(Binder.getCallingPid()) |
| 2804 | .setCallingUid(Binder.getCallingUid()) |
| 2805 | .setMethod("updateServiceLocation") |
| 2806 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
| 2807 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2808 | .build()); |
| 2809 | // Apps that lack location permission have no business calling this method; |
| 2810 | // however, because no permission was declared in the public API, denials must |
| 2811 | // all be "soft". |
| 2812 | switch (locationResult) { |
| 2813 | case DENIED_HARD: /* fall through */ |
| 2814 | case DENIED_SOFT: |
| 2815 | return; |
| 2816 | } |
| 2817 | |
| 2818 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2819 | final long identity = Binder.clearCallingIdentity(); |
| 2820 | try { |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 2821 | getPhoneFromSubIdOrDefault(getDefaultSubscription()).updateServiceLocation(workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2822 | } finally { |
| 2823 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2824 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2825 | } |
| 2826 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2827 | @Deprecated |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2828 | @Override |
| 2829 | public boolean isRadioOn(String callingPackage) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2830 | return isRadioOnWithFeature(callingPackage, null); |
| 2831 | } |
| 2832 | |
| 2833 | |
| 2834 | @Override |
| 2835 | public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) { |
| 2836 | return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage, |
| 2837 | callingFeatureId); |
| 2838 | } |
| 2839 | |
| 2840 | @Deprecated |
| 2841 | @Override |
| 2842 | public boolean isRadioOnForSubscriber(int subId, String callingPackage) { |
| 2843 | return isRadioOnForSubscriberWithFeature(subId, callingPackage, null); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2844 | } |
| 2845 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2846 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2847 | public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage, |
| 2848 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2849 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2850 | mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2851 | return false; |
| 2852 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2853 | |
| 2854 | final long identity = Binder.clearCallingIdentity(); |
| 2855 | try { |
| 2856 | return isRadioOnForSubscriber(subId); |
| 2857 | } finally { |
| 2858 | Binder.restoreCallingIdentity(identity); |
| 2859 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2860 | } |
| 2861 | |
| 2862 | private boolean isRadioOnForSubscriber(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2863 | final long identity = Binder.clearCallingIdentity(); |
| 2864 | try { |
| 2865 | final Phone phone = getPhone(subId); |
| 2866 | if (phone != null) { |
| 2867 | return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF; |
| 2868 | } else { |
| 2869 | return false; |
| 2870 | } |
| 2871 | } finally { |
| 2872 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2873 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2874 | } |
| 2875 | |
| 2876 | public void toggleRadioOnOff() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2877 | toggleRadioOnOffForSubscriber(getDefaultSubscription()); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2878 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2879 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2880 | public void toggleRadioOnOffForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2881 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2882 | |
| 2883 | final long identity = Binder.clearCallingIdentity(); |
| 2884 | try { |
| 2885 | final Phone phone = getPhone(subId); |
| 2886 | if (phone != null) { |
| 2887 | phone.setRadioPower(!isRadioOnForSubscriber(subId)); |
| 2888 | } |
| 2889 | } finally { |
| 2890 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2891 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2892 | } |
| 2893 | |
| 2894 | public boolean setRadio(boolean turnOn) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2895 | return setRadioForSubscriber(getDefaultSubscription(), turnOn); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2896 | } |
| 2897 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2898 | public boolean setRadioForSubscriber(int subId, boolean turnOn) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2899 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2900 | |
| 2901 | final long identity = Binder.clearCallingIdentity(); |
| 2902 | try { |
| 2903 | final Phone phone = getPhone(subId); |
| 2904 | if (phone == null) { |
| 2905 | return false; |
| 2906 | } |
| 2907 | if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) { |
| 2908 | toggleRadioOnOffForSubscriber(subId); |
| 2909 | } |
| 2910 | return true; |
| 2911 | } finally { |
| 2912 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2913 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2914 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2915 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2916 | public boolean needMobileRadioShutdown() { |
Shuo Qian | fa7b6b3 | 2019-12-10 10:40:38 -0800 | [diff] [blame] | 2917 | enforceReadPrivilegedPermission("needMobileRadioShutdown"); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2918 | /* |
| 2919 | * If any of the Radios are available, it will need to be |
| 2920 | * shutdown. So return true if any Radio is available. |
| 2921 | */ |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2922 | final long identity = Binder.clearCallingIdentity(); |
| 2923 | try { |
| 2924 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 2925 | Phone phone = PhoneFactory.getPhone(i); |
| 2926 | if (phone != null && phone.isRadioAvailable()) return true; |
| 2927 | } |
| 2928 | logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown."); |
| 2929 | return false; |
| 2930 | } finally { |
| 2931 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2932 | } |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2933 | } |
| 2934 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2935 | @Override |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2936 | public void shutdownMobileRadios() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2937 | enforceModifyPermission(); |
| 2938 | |
| 2939 | final long identity = Binder.clearCallingIdentity(); |
| 2940 | try { |
| 2941 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 2942 | logv("Shutting down Phone " + i); |
| 2943 | shutdownRadioUsingPhoneId(i); |
| 2944 | } |
| 2945 | } finally { |
| 2946 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2947 | } |
| 2948 | } |
| 2949 | |
| 2950 | private void shutdownRadioUsingPhoneId(int phoneId) { |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2951 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 2952 | if (phone != null && phone.isRadioAvailable()) { |
| 2953 | phone.shutdownRadio(); |
| 2954 | } |
| 2955 | } |
| 2956 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2957 | public boolean setRadioPower(boolean turnOn) { |
Jack Yu | b4e1616 | 2017-05-15 12:48:40 -0700 | [diff] [blame] | 2958 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2959 | |
Ling Ma | 83dc5ea | 2023-01-12 15:06:04 -0800 | [diff] [blame] | 2960 | if (!turnOn) { |
| 2961 | log("setRadioPower off: callingPackage=" + getCurrentPackageName()); |
| 2962 | } |
| 2963 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2964 | final long identity = Binder.clearCallingIdentity(); |
| 2965 | try { |
| 2966 | final Phone defaultPhone = PhoneFactory.getDefaultPhone(); |
| 2967 | if (defaultPhone != null) { |
| 2968 | defaultPhone.setRadioPower(turnOn); |
| 2969 | return true; |
| 2970 | } else { |
| 2971 | loge("There's no default phone."); |
| 2972 | return false; |
| 2973 | } |
| 2974 | } finally { |
| 2975 | Binder.restoreCallingIdentity(identity); |
Wei Liu | 9ae2a06 | 2016-08-08 11:09:34 -0700 | [diff] [blame] | 2976 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2977 | } |
| 2978 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2979 | public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2980 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2981 | |
Ling Ma | 83dc5ea | 2023-01-12 15:06:04 -0800 | [diff] [blame] | 2982 | if (!turnOn) { |
| 2983 | log("setRadioPowerForSubscriber off: subId=" + subId |
| 2984 | + ",callingPackage=" + getCurrentPackageName()); |
| 2985 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2986 | final long identity = Binder.clearCallingIdentity(); |
| 2987 | try { |
| 2988 | final Phone phone = getPhone(subId); |
| 2989 | if (phone != null) { |
| 2990 | phone.setRadioPower(turnOn); |
| 2991 | return true; |
| 2992 | } else { |
| 2993 | return false; |
| 2994 | } |
| 2995 | } finally { |
| 2996 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2997 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2998 | } |
| 2999 | |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3000 | /** |
| 3001 | * Vote on powering off the radio for a reason. The radio will be turned on only when there is |
| 3002 | * no reason to power it off. When any of the voters want to power it off, it will be turned |
| 3003 | * off. In case of emergency, the radio will be turned on even if there are some reasons for |
| 3004 | * powering it off, and these radio off votes will be cleared. |
| 3005 | * Multiple apps can vote for the same reason and the last vote will take effect. Each app is |
| 3006 | * responsible for its vote. A powering-off vote of a reason will be maintained until it is |
| 3007 | * cleared by calling {@link clearRadioPowerOffForReason} for that reason, or an emergency call |
| 3008 | * is made, or the device is rebooted. When an app comes backup from a crash, it needs to make |
| 3009 | * sure if its vote is as expected. An app can use the API {@link getRadioPowerOffReasons} to |
| 3010 | * check its vote. |
| 3011 | * |
| 3012 | * @param subId The subscription ID. |
| 3013 | * @param reason The reason for powering off radio. |
| 3014 | * @return true on success and false on failure. |
| 3015 | */ |
| 3016 | public boolean requestRadioPowerOffForReason(int subId, |
| 3017 | @TelephonyManager.RadioPowerReason int reason) { |
| 3018 | enforceModifyPermission(); |
| 3019 | |
Ling Ma | 83dc5ea | 2023-01-12 15:06:04 -0800 | [diff] [blame] | 3020 | log("requestRadioPowerOffForReason: subId=" + subId |
| 3021 | + ",reason=" + reason + ",callingPackage=" + getCurrentPackageName()); |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3022 | final long identity = Binder.clearCallingIdentity(); |
| 3023 | try { |
Thomas Nguyen | b47fc3c | 2023-04-06 13:30:32 -0700 | [diff] [blame] | 3024 | final Phone phone = getPhoneFromSubIdOrDefault(subId); |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3025 | if (phone != null) { |
| 3026 | phone.setRadioPowerForReason(false, reason); |
| 3027 | return true; |
| 3028 | } else { |
Thomas Nguyen | b47fc3c | 2023-04-06 13:30:32 -0700 | [diff] [blame] | 3029 | loge("requestRadioPowerOffForReason: phone is null"); |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3030 | return false; |
| 3031 | } |
| 3032 | } finally { |
| 3033 | Binder.restoreCallingIdentity(identity); |
| 3034 | } |
| 3035 | } |
| 3036 | |
| 3037 | /** |
| 3038 | * Remove the vote on powering off the radio for a reason, as requested by |
| 3039 | * {@link requestRadioPowerOffForReason}. |
| 3040 | * |
| 3041 | * @param subId The subscription ID. |
| 3042 | * @param reason The reason for powering off radio. |
| 3043 | * @return true on success and false on failure. |
| 3044 | */ |
| 3045 | public boolean clearRadioPowerOffForReason(int subId, |
| 3046 | @TelephonyManager.RadioPowerReason int reason) { |
| 3047 | enforceModifyPermission(); |
| 3048 | |
| 3049 | final long identity = Binder.clearCallingIdentity(); |
| 3050 | try { |
Thomas Nguyen | b47fc3c | 2023-04-06 13:30:32 -0700 | [diff] [blame] | 3051 | final Phone phone = getPhoneFromSubIdOrDefault(subId); |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3052 | if (phone != null) { |
| 3053 | phone.setRadioPowerForReason(true, reason); |
| 3054 | return true; |
| 3055 | } else { |
Thomas Nguyen | b47fc3c | 2023-04-06 13:30:32 -0700 | [diff] [blame] | 3056 | loge("clearRadioPowerOffForReason: phone is null"); |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3057 | return false; |
| 3058 | } |
| 3059 | } finally { |
| 3060 | Binder.restoreCallingIdentity(identity); |
| 3061 | } |
| 3062 | } |
| 3063 | |
| 3064 | /** |
| 3065 | * Get reasons for powering off radio, as requested by {@link requestRadioPowerOffForReason}. |
| 3066 | * |
| 3067 | * @param subId The subscription ID. |
| 3068 | * @param callingPackage The package making the call. |
| 3069 | * @param callingFeatureId The feature in the package. |
| 3070 | * @return List of reasons for powering off radio. |
| 3071 | */ |
| 3072 | public List getRadioPowerOffReasons(int subId, String callingPackage, String callingFeatureId) { |
| 3073 | enforceReadPrivilegedPermission("getRadioPowerOffReasons"); |
| 3074 | |
| 3075 | final long identity = Binder.clearCallingIdentity(); |
| 3076 | List result = new ArrayList(); |
| 3077 | try { |
| 3078 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, |
| 3079 | callingPackage, callingFeatureId, "getRadioPowerOffReasons")) { |
| 3080 | return result; |
| 3081 | } |
| 3082 | |
Thomas Nguyen | b47fc3c | 2023-04-06 13:30:32 -0700 | [diff] [blame] | 3083 | final Phone phone = getPhoneFromSubIdOrDefault(subId); |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3084 | if (phone != null) { |
| 3085 | result.addAll(phone.getRadioPowerOffReasons()); |
Thomas Nguyen | b47fc3c | 2023-04-06 13:30:32 -0700 | [diff] [blame] | 3086 | } else { |
| 3087 | loge("getRadioPowerOffReasons: phone is null"); |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3088 | } |
| 3089 | } finally { |
| 3090 | Binder.restoreCallingIdentity(identity); |
| 3091 | } |
| 3092 | return result; |
| 3093 | } |
| 3094 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3095 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3096 | @Override |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 3097 | public boolean enableDataConnectivity(String callingPackage) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3098 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3099 | |
| 3100 | final long identity = Binder.clearCallingIdentity(); |
| 3101 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3102 | int subId = SubscriptionManager.getDefaultDataSubscriptionId(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3103 | final Phone phone = getPhone(subId); |
| 3104 | if (phone != null) { |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 3105 | phone.getDataSettingsManager().setDataEnabled( |
| 3106 | TelephonyManager.DATA_ENABLED_REASON_USER, true, callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3107 | return true; |
| 3108 | } else { |
| 3109 | return false; |
| 3110 | } |
| 3111 | } finally { |
| 3112 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3113 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3114 | } |
| 3115 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3116 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3117 | @Override |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 3118 | public boolean disableDataConnectivity(String callingPackage) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3119 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3120 | |
| 3121 | final long identity = Binder.clearCallingIdentity(); |
| 3122 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3123 | int subId = SubscriptionManager.getDefaultDataSubscriptionId(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3124 | final Phone phone = getPhone(subId); |
| 3125 | if (phone != null) { |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 3126 | phone.getDataSettingsManager().setDataEnabled( |
| 3127 | TelephonyManager.DATA_ENABLED_REASON_USER, false, callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3128 | return true; |
| 3129 | } else { |
| 3130 | return false; |
| 3131 | } |
| 3132 | } finally { |
| 3133 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3134 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3135 | } |
| 3136 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3137 | @Override |
Jack Yu | acf8a13 | 2017-05-01 17:00:48 -0700 | [diff] [blame] | 3138 | public boolean isDataConnectivityPossible(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3139 | final long identity = Binder.clearCallingIdentity(); |
| 3140 | try { |
| 3141 | final Phone phone = getPhone(subId); |
| 3142 | if (phone != null) { |
Jack Yu | 59824e1 | 2022-03-23 01:42:44 -0700 | [diff] [blame] | 3143 | return phone.isDataAllowed(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3144 | } else { |
| 3145 | return false; |
| 3146 | } |
| 3147 | } finally { |
| 3148 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3149 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3150 | } |
| 3151 | |
| 3152 | public boolean handlePinMmi(String dialString) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 3153 | return handlePinMmiForSubscriber(getDefaultSubscription(), dialString); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3154 | } |
| 3155 | |
pkanwar | ae03a6b | 2016-11-06 20:37:09 -0800 | [diff] [blame] | 3156 | public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3157 | enforceCallPermission(); |
| 3158 | |
| 3159 | final long identity = Binder.clearCallingIdentity(); |
| 3160 | try { |
| 3161 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3162 | return; |
| 3163 | } |
| 3164 | Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback); |
| 3165 | sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId); |
| 3166 | } finally { |
| 3167 | Binder.restoreCallingIdentity(identity); |
| 3168 | } |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 3169 | }; |
| 3170 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3171 | public boolean handlePinMmiForSubscriber(int subId, String dialString) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3172 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3173 | |
| 3174 | final long identity = Binder.clearCallingIdentity(); |
| 3175 | try { |
| 3176 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3177 | return false; |
| 3178 | } |
| 3179 | return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId); |
| 3180 | } finally { |
| 3181 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3182 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3183 | } |
| 3184 | |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 3185 | /** |
| 3186 | * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage |
| 3187 | * tag on getCallState Binder call. |
| 3188 | */ |
| 3189 | @Deprecated |
| 3190 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3191 | public int getCallState() { |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 3192 | if (CompatChanges.isChangeEnabled( |
| 3193 | TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION, |
| 3194 | Binder.getCallingUid())) { |
| 3195 | // Do not allow this API to be called on API version 31+, it should only be |
| 3196 | // called on old apps using this Binder call directly. |
| 3197 | throw new SecurityException("This method can only be used for applications " |
| 3198 | + "targeting API version 30 or less."); |
| 3199 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3200 | final long identity = Binder.clearCallingIdentity(); |
| 3201 | try { |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 3202 | Phone phone = getPhoneFromSubIdOrDefault(getDefaultSubscription()); |
| 3203 | return PhoneConstantConversions.convertCallState(phone.getState()); |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 3204 | } finally { |
| 3205 | Binder.restoreCallingIdentity(identity); |
| 3206 | } |
| 3207 | } |
| 3208 | |
| 3209 | @Override |
| 3210 | public int getCallStateForSubscription(int subId, String callingPackage, String featureId) { |
| 3211 | if (CompatChanges.isChangeEnabled( |
| 3212 | TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION, |
| 3213 | Binder.getCallingUid())) { |
| 3214 | // Check READ_PHONE_STATE for API version 31+ |
| 3215 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage, |
| 3216 | featureId, "getCallStateForSubscription")) { |
| 3217 | throw new SecurityException("getCallState requires READ_PHONE_STATE for apps " |
| 3218 | + "targeting API level 31+."); |
| 3219 | } |
| 3220 | } |
| 3221 | final long identity = Binder.clearCallingIdentity(); |
| 3222 | try { |
| 3223 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3224 | return phone == null ? TelephonyManager.CALL_STATE_IDLE : |
| 3225 | PhoneConstantConversions.convertCallState(phone.getState()); |
| 3226 | } finally { |
| 3227 | Binder.restoreCallingIdentity(identity); |
| 3228 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3229 | } |
| 3230 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3231 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 3232 | public int getDataState() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3233 | return getDataStateForSubId(SubscriptionManager.getDefaultDataSubscriptionId()); |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 3234 | } |
| 3235 | |
| 3236 | @Override |
| 3237 | public int getDataStateForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3238 | final long identity = Binder.clearCallingIdentity(); |
| 3239 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 3240 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3241 | if (phone != null) { |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 3242 | return phone.getDataNetworkController().getInternetDataNetworkState(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3243 | } else { |
| 3244 | return PhoneConstantConversions.convertDataState( |
| 3245 | PhoneConstants.DataState.DISCONNECTED); |
| 3246 | } |
| 3247 | } finally { |
| 3248 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3249 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3250 | } |
| 3251 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3252 | @Override |
Jack Yu | 0eda684 | 2022-04-18 00:34:46 -0700 | [diff] [blame] | 3253 | public @DataActivityType int getDataActivity() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3254 | return getDataActivityForSubId(SubscriptionManager.getDefaultDataSubscriptionId()); |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 3255 | } |
| 3256 | |
| 3257 | @Override |
Jack Yu | 0eda684 | 2022-04-18 00:34:46 -0700 | [diff] [blame] | 3258 | public @DataActivityType int getDataActivityForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3259 | final long identity = Binder.clearCallingIdentity(); |
| 3260 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 3261 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3262 | if (phone != null) { |
Jack Yu | 0eda684 | 2022-04-18 00:34:46 -0700 | [diff] [blame] | 3263 | return phone.getDataActivityState(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3264 | } else { |
| 3265 | return TelephonyManager.DATA_ACTIVITY_NONE; |
| 3266 | } |
| 3267 | } finally { |
| 3268 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3269 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3270 | } |
| 3271 | |
| 3272 | @Override |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 3273 | public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3274 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 3275 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3276 | |
| 3277 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 3278 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 3279 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 3280 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3281 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3282 | .setCallingPid(Binder.getCallingPid()) |
| 3283 | .setCallingUid(Binder.getCallingUid()) |
| 3284 | .setMethod("getCellLocation") |
Hall Liu | 773ba02 | 2020-01-24 18:07:12 -0800 | [diff] [blame] | 3285 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3286 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 3287 | .build()); |
| 3288 | switch (locationResult) { |
| 3289 | case DENIED_HARD: |
| 3290 | throw new SecurityException("Not allowed to access cell location"); |
| 3291 | case DENIED_SOFT: |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 3292 | return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
| 3293 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3294 | } |
| 3295 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 3296 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3297 | final long identity = Binder.clearCallingIdentity(); |
| 3298 | try { |
| 3299 | if (DBG_LOC) log("getCellLocation: is active user"); |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3300 | int subId = SubscriptionManager.getDefaultDataSubscriptionId(); |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 3301 | return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3302 | } finally { |
| 3303 | Binder.restoreCallingIdentity(identity); |
| 3304 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 3305 | } |
| 3306 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3307 | @Override |
Jack Yu | eb1e7fe | 2020-02-22 19:38:58 -0800 | [diff] [blame] | 3308 | public String getNetworkCountryIsoForPhone(int phoneId) { |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3309 | // Reporting the correct network country is ambiguous when IWLAN could conflict with |
| 3310 | // registered cell info, so return a NULL country instead. |
| 3311 | final long identity = Binder.clearCallingIdentity(); |
| 3312 | try { |
Malcolm Chen | 3732c2b | 2018-07-18 20:15:24 -0700 | [diff] [blame] | 3313 | if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) { |
| 3314 | // Get default phone in this case. |
| 3315 | phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX; |
| 3316 | } |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3317 | final int subId = SubscriptionManager.getSubscriptionId(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3318 | Phone phone = PhoneFactory.getPhone(phoneId); |
Nathan Harold | 532f51c | 2020-04-21 19:31:10 -0700 | [diff] [blame] | 3319 | if (phone == null) return ""; |
| 3320 | ServiceStateTracker sst = phone.getServiceStateTracker(); |
| 3321 | if (sst == null) return ""; |
| 3322 | LocaleTracker lt = sst.getLocaleTracker(); |
| 3323 | if (lt == null) return ""; |
Shuo Qian | 9418a92 | 2021-03-09 11:21:16 -0800 | [diff] [blame] | 3324 | return lt.getCurrentCountry(); |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3325 | } finally { |
| 3326 | Binder.restoreCallingIdentity(identity); |
| 3327 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3328 | } |
| 3329 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 3330 | /** |
| 3331 | * This method was removed due to potential issues caused by performing partial |
| 3332 | * updates of service state, and lack of a credible use case. |
| 3333 | * |
| 3334 | * This has the ability to break the telephony implementation by disabling notification of |
| 3335 | * changes in device connectivity. DO NOT USE THIS! |
| 3336 | */ |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3337 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3338 | public void enableLocationUpdates() { |
| 3339 | mApp.enforceCallingOrSelfPermission( |
| 3340 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3341 | } |
| 3342 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 3343 | /** |
| 3344 | * This method was removed due to potential issues caused by performing partial |
| 3345 | * updates of service state, and lack of a credible use case. |
| 3346 | * |
| 3347 | * This has the ability to break the telephony implementation by disabling notification of |
| 3348 | * changes in device connectivity. DO NOT USE THIS! |
| 3349 | */ |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3350 | @Override |
| 3351 | public void disableLocationUpdates() { |
| 3352 | mApp.enforceCallingOrSelfPermission( |
| 3353 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3354 | } |
| 3355 | |
| 3356 | @Override |
| 3357 | @SuppressWarnings("unchecked") |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3358 | public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage, |
| 3359 | String callingFeatureId) { |
Nathan Harold | b55f63b | 2021-07-27 11:27:38 -0700 | [diff] [blame] | 3360 | try { |
| 3361 | mApp.getSystemService(AppOpsManager.class) |
| 3362 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 3363 | } catch (SecurityException e) { |
| 3364 | EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid()); |
| 3365 | throw e; |
| 3366 | } |
| 3367 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3368 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | dbea45a | 2018-08-30 14:35:07 -0700 | [diff] [blame] | 3369 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 3370 | throw new SecurityException( |
| 3371 | "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels."); |
| 3372 | } |
Nathan Harold | b4d5561 | 2018-07-20 13:13:08 -0700 | [diff] [blame] | 3373 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 3374 | if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(), |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3375 | callingPackage) != AppOpsManager.MODE_ALLOWED) { |
| 3376 | return null; |
| 3377 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 3378 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 3379 | if (DBG_LOC) log("getNeighboringCellInfo: is active user"); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3380 | |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3381 | List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId); |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 3382 | if (info == null) return null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3383 | |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 3384 | List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>(); |
| 3385 | for (CellInfo ci : info) { |
| 3386 | if (ci instanceof CellInfoGsm) { |
| 3387 | neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci)); |
| 3388 | } else if (ci instanceof CellInfoWcdma) { |
| 3389 | neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci)); |
| 3390 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3391 | } |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 3392 | return (neighbors.size()) > 0 ? neighbors : null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3393 | } |
| 3394 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3395 | private List<CellInfo> getCachedCellInfo() { |
| 3396 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 3397 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3398 | List<CellInfo> info = phone.getAllCellInfo(); |
| 3399 | if (info != null) cellInfos.addAll(info); |
| 3400 | } |
| 3401 | return cellInfos; |
| 3402 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3403 | |
| 3404 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3405 | public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3406 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 3407 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3408 | |
| 3409 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 3410 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 3411 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 3412 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3413 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3414 | .setCallingPid(Binder.getCallingPid()) |
| 3415 | .setCallingUid(Binder.getCallingUid()) |
| 3416 | .setMethod("getAllCellInfo") |
Nathan Harold | 5ae50b5 | 2019-02-20 15:46:36 -0800 | [diff] [blame] | 3417 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3418 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 3419 | .build()); |
| 3420 | switch (locationResult) { |
| 3421 | case DENIED_HARD: |
| 3422 | throw new SecurityException("Not allowed to access cell info"); |
| 3423 | case DENIED_SOFT: |
| 3424 | return new ArrayList<>(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3425 | } |
| 3426 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3427 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3428 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 3429 | return getCachedCellInfo(); |
| 3430 | } |
| 3431 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 3432 | if (DBG_LOC) log("getAllCellInfo: is active user"); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 3433 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3434 | final long identity = Binder.clearCallingIdentity(); |
| 3435 | try { |
| 3436 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 3437 | for (Phone phone : PhoneFactory.getPhones()) { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 3438 | final List<CellInfo> info = (List<CellInfo>) sendRequest( |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 3439 | CMD_GET_ALL_CELL_INFO, null, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3440 | if (info != null) cellInfos.addAll(info); |
| 3441 | } |
| 3442 | return cellInfos; |
| 3443 | } finally { |
| 3444 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3445 | } |
| 3446 | } |
| 3447 | |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 3448 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3449 | public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage, |
| 3450 | String callingFeatureId) { |
| 3451 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, |
| 3452 | getWorkSource(Binder.getCallingUid())); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3453 | } |
| 3454 | |
| 3455 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3456 | public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb, |
| 3457 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3458 | enforceModifyPermission(); |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3459 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3460 | } |
| 3461 | |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3462 | private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb, |
| 3463 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3464 | mApp.getSystemService(AppOpsManager.class) |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3465 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3466 | |
| 3467 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 3468 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 3469 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 3470 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3471 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3472 | .setCallingPid(Binder.getCallingPid()) |
| 3473 | .setCallingUid(Binder.getCallingUid()) |
| 3474 | .setMethod("requestCellInfoUpdate") |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 3475 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
| 3476 | .setMinSdkVersionForFine(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3477 | .build()); |
| 3478 | switch (locationResult) { |
| 3479 | case DENIED_HARD: |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3480 | if (TelephonyPermissions |
| 3481 | .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) { |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 3482 | // Safetynet logging for b/154934934 |
| 3483 | EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid()); |
| 3484 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3485 | throw new SecurityException("Not allowed to access cell info"); |
| 3486 | case DENIED_SOFT: |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3487 | if (TelephonyPermissions |
| 3488 | .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) { |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 3489 | // Safetynet logging for b/154934934 |
| 3490 | EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid()); |
| 3491 | } |
Nathan Harold | 5320c42 | 2019-05-09 10:26:08 -0700 | [diff] [blame] | 3492 | try { |
| 3493 | cb.onCellInfo(new ArrayList<CellInfo>()); |
| 3494 | } catch (RemoteException re) { |
| 3495 | // Drop without consequences |
| 3496 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3497 | return; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3498 | } |
| 3499 | |
Nathan Harold | a939a96 | 2019-05-09 10:13:47 -0700 | [diff] [blame] | 3500 | |
| 3501 | final Phone phone = getPhoneFromSubId(subId); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3502 | if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
| 3503 | |
| 3504 | sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource); |
| 3505 | } |
| 3506 | |
| 3507 | @Override |
Aishwarya Mallampati | 0603fb1 | 2022-08-24 21:16:56 +0000 | [diff] [blame] | 3508 | public void setCellInfoListRate(int rateInMillis, int subId) { |
Jack Yu | a8d8cb8 | 2017-01-16 10:15:34 -0800 | [diff] [blame] | 3509 | enforceModifyPermission(); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 3510 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3511 | |
| 3512 | final long identity = Binder.clearCallingIdentity(); |
| 3513 | try { |
Aishwarya Mallampati | 0603fb1 | 2022-08-24 21:16:56 +0000 | [diff] [blame] | 3514 | Phone phone = getPhone(subId); |
| 3515 | if (phone == null) { |
| 3516 | getDefaultPhone().setCellInfoListRate(rateInMillis, workSource); |
| 3517 | } else { |
| 3518 | phone.setCellInfoListRate(rateInMillis, workSource); |
| 3519 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3520 | } finally { |
| 3521 | Binder.restoreCallingIdentity(identity); |
| 3522 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3523 | } |
| 3524 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3525 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3526 | public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3527 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3528 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3529 | return null; |
| 3530 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3531 | int subId = phone.getSubId(); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3532 | enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot"); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 3533 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3534 | callingPackage, callingFeatureId, "getImeiForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3535 | return null; |
| 3536 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3537 | |
| 3538 | final long identity = Binder.clearCallingIdentity(); |
| 3539 | try { |
| 3540 | return phone.getImei(); |
| 3541 | } finally { |
| 3542 | Binder.restoreCallingIdentity(identity); |
| 3543 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3544 | } |
| 3545 | |
| 3546 | @Override |
arunvoddu | d5c6ce0 | 2022-12-11 06:03:12 +0000 | [diff] [blame] | 3547 | public String getPrimaryImei(String callingPackage, String callingFeatureId) { |
| 3548 | enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getPrimaryImei"); |
| 3549 | if (!checkCallingOrSelfReadDeviceIdentifiersForAnySub(mApp, callingPackage, |
| 3550 | callingFeatureId, "getPrimaryImei")) { |
| 3551 | throw new SecurityException("Caller does not have permission"); |
| 3552 | } |
| 3553 | final long identity = Binder.clearCallingIdentity(); |
| 3554 | try { |
| 3555 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3556 | if (phone.getImeiType() == Phone.IMEI_TYPE_PRIMARY) { |
| 3557 | return phone.getImei(); |
| 3558 | } |
| 3559 | } |
| 3560 | throw new UnsupportedOperationException("Operation not supported"); |
| 3561 | } finally { |
| 3562 | Binder.restoreCallingIdentity(identity); |
| 3563 | } |
| 3564 | } |
| 3565 | |
| 3566 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3567 | public String getTypeAllocationCodeForSlot(int slotIndex) { |
| 3568 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3569 | String tac = null; |
| 3570 | if (phone != null) { |
| 3571 | String imei = phone.getImei(); |
Vala Zadeh | ab00555 | 2021-09-21 15:54:29 -0700 | [diff] [blame] | 3572 | try { |
| 3573 | tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH); |
| 3574 | } catch (IndexOutOfBoundsException e) { |
| 3575 | Log.e(LOG_TAG, "IMEI length shorter than upper index."); |
| 3576 | return null; |
| 3577 | } |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3578 | } |
| 3579 | return tac; |
| 3580 | } |
| 3581 | |
| 3582 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3583 | public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Shuo Qian | 13d8915 | 2021-05-10 23:58:11 -0700 | [diff] [blame] | 3584 | try { |
| 3585 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 3586 | } catch (SecurityException se) { |
| 3587 | EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid()); |
| 3588 | throw new SecurityException("Package " + callingPackage + " does not belong to " |
| 3589 | + Binder.getCallingUid()); |
| 3590 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3591 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3592 | if (phone == null) { |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 3593 | return null; |
| 3594 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3595 | |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3596 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 3597 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3598 | callingPackage, callingFeatureId, "getMeidForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3599 | return null; |
| 3600 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3601 | |
| 3602 | final long identity = Binder.clearCallingIdentity(); |
| 3603 | try { |
| 3604 | return phone.getMeid(); |
| 3605 | } finally { |
| 3606 | Binder.restoreCallingIdentity(identity); |
| 3607 | } |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 3608 | } |
| 3609 | |
| 3610 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3611 | public String getManufacturerCodeForSlot(int slotIndex) { |
| 3612 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3613 | String manufacturerCode = null; |
| 3614 | if (phone != null) { |
| 3615 | String meid = phone.getMeid(); |
Vala Zadeh | ab00555 | 2021-09-21 15:54:29 -0700 | [diff] [blame] | 3616 | try { |
| 3617 | manufacturerCode = |
| 3618 | meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH); |
| 3619 | } catch (IndexOutOfBoundsException e) { |
| 3620 | Log.e(LOG_TAG, "MEID length shorter than upper index."); |
| 3621 | return null; |
| 3622 | } |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3623 | } |
| 3624 | return manufacturerCode; |
| 3625 | } |
| 3626 | |
| 3627 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3628 | public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage, |
| 3629 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3630 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3631 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3632 | return null; |
| 3633 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3634 | int subId = phone.getSubId(); |
| 3635 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3636 | mApp, subId, callingPackage, callingFeatureId, |
| 3637 | "getDeviceSoftwareVersionForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3638 | return null; |
| 3639 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3640 | |
| 3641 | final long identity = Binder.clearCallingIdentity(); |
| 3642 | try { |
| 3643 | return phone.getDeviceSvn(); |
| 3644 | } finally { |
| 3645 | Binder.restoreCallingIdentity(identity); |
| 3646 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3647 | } |
| 3648 | |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3649 | @Override |
| 3650 | public int getSubscriptionCarrierId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3651 | final long identity = Binder.clearCallingIdentity(); |
| 3652 | try { |
| 3653 | final Phone phone = getPhone(subId); |
| 3654 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId(); |
| 3655 | } finally { |
| 3656 | Binder.restoreCallingIdentity(identity); |
| 3657 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3658 | } |
| 3659 | |
| 3660 | @Override |
| 3661 | public String getSubscriptionCarrierName(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3662 | final long identity = Binder.clearCallingIdentity(); |
| 3663 | try { |
| 3664 | final Phone phone = getPhone(subId); |
| 3665 | return phone == null ? null : phone.getCarrierName(); |
| 3666 | } finally { |
| 3667 | Binder.restoreCallingIdentity(identity); |
| 3668 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3669 | } |
| 3670 | |
calvinpan | ffe225e | 2018-11-01 19:43:06 +0800 | [diff] [blame] | 3671 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3672 | public int getSubscriptionSpecificCarrierId(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3673 | final long identity = Binder.clearCallingIdentity(); |
| 3674 | try { |
| 3675 | final Phone phone = getPhone(subId); |
| 3676 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3677 | : phone.getSpecificCarrierId(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3678 | } finally { |
| 3679 | Binder.restoreCallingIdentity(identity); |
| 3680 | } |
| 3681 | } |
| 3682 | |
| 3683 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3684 | public String getSubscriptionSpecificCarrierName(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3685 | final long identity = Binder.clearCallingIdentity(); |
| 3686 | try { |
| 3687 | final Phone phone = getPhone(subId); |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3688 | return phone == null ? null : phone.getSpecificCarrierName(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3689 | } finally { |
| 3690 | Binder.restoreCallingIdentity(identity); |
| 3691 | } |
| 3692 | } |
| 3693 | |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 3694 | @Override |
chen xu | 864e11c | 2018-12-06 22:10:03 -0800 | [diff] [blame] | 3695 | public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) { |
| 3696 | if (!isSubscriptionMccMnc) { |
| 3697 | enforceReadPrivilegedPermission("getCarrierIdFromMccMnc"); |
| 3698 | } |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 3699 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3700 | if (phone == null) { |
| 3701 | return TelephonyManager.UNKNOWN_CARRIER_ID; |
| 3702 | } |
| 3703 | final long identity = Binder.clearCallingIdentity(); |
| 3704 | try { |
| 3705 | return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc); |
| 3706 | } finally { |
| 3707 | Binder.restoreCallingIdentity(identity); |
| 3708 | } |
| 3709 | } |
| 3710 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3711 | // |
| 3712 | // Internal helper methods. |
| 3713 | // |
| 3714 | |
Sanket Padawe | ee13a9b | 2016-03-08 17:30:28 -0800 | [diff] [blame] | 3715 | /** |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3716 | * Make sure the caller is the calling package itself |
| 3717 | * |
| 3718 | * @throws SecurityException if the caller is not the calling package |
| 3719 | */ |
| 3720 | private void enforceCallingPackage(String callingPackage, int callingUid, String message) { |
| 3721 | int packageUid = -1; |
Grace Jia | dbefca0 | 2021-04-26 15:13:31 -0700 | [diff] [blame] | 3722 | PackageManager pm = mApp.getBaseContext().createContextAsUser( |
| 3723 | UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager(); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3724 | try { |
Grace Jia | dbefca0 | 2021-04-26 15:13:31 -0700 | [diff] [blame] | 3725 | packageUid = pm.getPackageUid(callingPackage, 0); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3726 | } catch (PackageManager.NameNotFoundException e) { |
| 3727 | // packageUid is -1 |
| 3728 | } |
| 3729 | if (packageUid != callingUid) { |
| 3730 | throw new SecurityException(message + ": Package " + callingPackage |
| 3731 | + " does not belong to " + callingUid); |
| 3732 | } |
| 3733 | } |
| 3734 | |
| 3735 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3736 | * Make sure the caller has the MODIFY_PHONE_STATE permission. |
| 3737 | * |
| 3738 | * @throws SecurityException if the caller does not have the required permission |
| 3739 | */ |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 3740 | @VisibleForTesting |
| 3741 | public void enforceModifyPermission() { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3742 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null); |
| 3743 | } |
| 3744 | |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 3745 | /** |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 3746 | * Make sure the caller has the READ_PHONE_STATE permission. |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 3747 | * |
| 3748 | * @throws SecurityException if the caller does not have the required permission |
| 3749 | */ |
| 3750 | @VisibleForTesting |
| 3751 | public void enforceReadPermission() { |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 3752 | enforceReadPermission(null); |
| 3753 | } |
| 3754 | |
| 3755 | /** |
| 3756 | * Make sure the caller has the READ_PHONE_STATE permissions. |
| 3757 | * |
| 3758 | * @throws SecurityException if the caller does not have the READ_PHONE_STATE permission. |
| 3759 | */ |
| 3760 | @VisibleForTesting |
| 3761 | public void enforceReadPermission(String msg) { |
| 3762 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, msg); |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 3763 | } |
| 3764 | |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 3765 | private void enforceActiveEmergencySessionPermission() { |
| 3766 | mApp.enforceCallingOrSelfPermission( |
| 3767 | android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null); |
| 3768 | } |
| 3769 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3770 | /** |
| 3771 | * Make sure the caller has the CALL_PHONE permission. |
| 3772 | * |
| 3773 | * @throws SecurityException if the caller does not have the required permission |
| 3774 | */ |
| 3775 | private void enforceCallPermission() { |
| 3776 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null); |
| 3777 | } |
| 3778 | |
paulhu | 5a77360 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 3779 | private void enforceSettingsPermission() { |
| 3780 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 3781 | } |
| 3782 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 3783 | private void enforceRebootPermission() { |
| 3784 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null); |
| 3785 | } |
| 3786 | |
Aishwarya Mallampati | 60fe113 | 2023-01-24 19:07:21 +0000 | [diff] [blame] | 3787 | /** |
| 3788 | * Make sure the caller has SATELLITE_COMMUNICATION permission. |
| 3789 | * @param message - log message to print. |
| 3790 | * @throws SecurityException if the caller does not have the required permission |
| 3791 | */ |
| 3792 | private void enforceSatelliteCommunicationPermission(String message) { |
| 3793 | mApp.enforceCallingOrSelfPermission(permission.SATELLITE_COMMUNICATION, message); |
| 3794 | } |
| 3795 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3796 | private String createTelUrl(String number) { |
| 3797 | if (TextUtils.isEmpty(number)) { |
| 3798 | return null; |
| 3799 | } |
| 3800 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3801 | return "tel:" + number; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3802 | } |
| 3803 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3804 | private static void log(String msg) { |
Ling Ma | 83dc5ea | 2023-01-12 15:06:04 -0800 | [diff] [blame] | 3805 | Log.d(LOG_TAG, msg); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3806 | } |
| 3807 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3808 | private static void logv(String msg) { |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 3809 | Log.v(LOG_TAG, msg); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3810 | } |
| 3811 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3812 | private static void loge(String msg) { |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 3813 | Log.e(LOG_TAG, msg); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3814 | } |
| 3815 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3816 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3817 | public int getActivePhoneType() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3818 | return getActivePhoneTypeForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3819 | } |
| 3820 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3821 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3822 | public int getActivePhoneTypeForSlot(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3823 | final long identity = Binder.clearCallingIdentity(); |
| 3824 | try { |
| 3825 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3826 | if (phone == null) { |
| 3827 | return PhoneConstants.PHONE_TYPE_NONE; |
| 3828 | } else { |
| 3829 | return phone.getPhoneType(); |
| 3830 | } |
| 3831 | } finally { |
| 3832 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3833 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3834 | } |
| 3835 | |
| 3836 | /** |
| 3837 | * Returns the CDMA ERI icon index to display |
| 3838 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3839 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3840 | public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) { |
| 3841 | return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage, |
| 3842 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3843 | } |
| 3844 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3845 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3846 | public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage, |
| 3847 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3848 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3849 | mApp, subId, callingPackage, callingFeatureId, |
| 3850 | "getCdmaEriIconIndexForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3851 | return -1; |
| 3852 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3853 | |
| 3854 | final long identity = Binder.clearCallingIdentity(); |
| 3855 | try { |
| 3856 | final Phone phone = getPhone(subId); |
| 3857 | if (phone != null) { |
| 3858 | return phone.getCdmaEriIconIndex(); |
| 3859 | } else { |
| 3860 | return -1; |
| 3861 | } |
| 3862 | } finally { |
| 3863 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3864 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3865 | } |
| 3866 | |
| 3867 | /** |
| 3868 | * Returns the CDMA ERI icon mode, |
| 3869 | * 0 - ON |
| 3870 | * 1 - FLASHING |
| 3871 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3872 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3873 | public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) { |
| 3874 | return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 3875 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3876 | } |
| 3877 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3878 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3879 | public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage, |
| 3880 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3881 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3882 | mApp, subId, callingPackage, callingFeatureId, |
| 3883 | "getCdmaEriIconModeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3884 | return -1; |
| 3885 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3886 | |
| 3887 | final long identity = Binder.clearCallingIdentity(); |
| 3888 | try { |
| 3889 | final Phone phone = getPhone(subId); |
| 3890 | if (phone != null) { |
| 3891 | return phone.getCdmaEriIconMode(); |
| 3892 | } else { |
| 3893 | return -1; |
| 3894 | } |
| 3895 | } finally { |
| 3896 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3897 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3898 | } |
| 3899 | |
| 3900 | /** |
| 3901 | * Returns the CDMA ERI text, |
| 3902 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3903 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3904 | public String getCdmaEriText(String callingPackage, String callingFeatureId) { |
| 3905 | return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage, |
| 3906 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3907 | } |
| 3908 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3909 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3910 | public String getCdmaEriTextForSubscriber(int subId, String callingPackage, |
| 3911 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3912 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3913 | mApp, subId, callingPackage, callingFeatureId, |
| 3914 | "getCdmaEriIconTextForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3915 | return null; |
| 3916 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3917 | |
| 3918 | final long identity = Binder.clearCallingIdentity(); |
| 3919 | try { |
| 3920 | final Phone phone = getPhone(subId); |
| 3921 | if (phone != null) { |
| 3922 | return phone.getCdmaEriText(); |
| 3923 | } else { |
| 3924 | return null; |
| 3925 | } |
| 3926 | } finally { |
| 3927 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3928 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3929 | } |
| 3930 | |
| 3931 | /** |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3932 | * Returns the CDMA MDN. |
| 3933 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3934 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3935 | public String getCdmaMdn(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3936 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3937 | mApp, subId, "getCdmaMdn"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3938 | |
| 3939 | final long identity = Binder.clearCallingIdentity(); |
| 3940 | try { |
| 3941 | final Phone phone = getPhone(subId); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3942 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3943 | return phone.getLine1Number(); |
| 3944 | } else { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3945 | loge("getCdmaMdn: no phone found. Invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3946 | return null; |
| 3947 | } |
| 3948 | } finally { |
| 3949 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3950 | } |
| 3951 | } |
| 3952 | |
| 3953 | /** |
| 3954 | * Returns the CDMA MIN. |
| 3955 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3956 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3957 | public String getCdmaMin(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3958 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3959 | mApp, subId, "getCdmaMin"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3960 | |
| 3961 | final long identity = Binder.clearCallingIdentity(); |
| 3962 | try { |
| 3963 | final Phone phone = getPhone(subId); |
| 3964 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
| 3965 | return phone.getCdmaMin(); |
| 3966 | } else { |
| 3967 | return null; |
| 3968 | } |
| 3969 | } finally { |
| 3970 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3971 | } |
| 3972 | } |
| 3973 | |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3974 | @Override |
| 3975 | public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis, |
| 3976 | INumberVerificationCallback callback, String callingPackage) { |
| 3977 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 3978 | != PERMISSION_GRANTED) { |
| 3979 | throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission"); |
| 3980 | } |
| 3981 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 3982 | |
| 3983 | String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp); |
| 3984 | if (!TextUtils.equals(callingPackage, authorizedPackage)) { |
Hall Liu | b9d8feb | 2021-01-13 10:28:04 -0800 | [diff] [blame] | 3985 | throw new SecurityException("Calling package must be configured in the device config: " |
| 3986 | + "calling package: " + callingPackage |
| 3987 | + ", configured package: " + authorizedPackage); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3988 | } |
| 3989 | |
| 3990 | if (range == null) { |
| 3991 | throw new NullPointerException("Range must be non-null"); |
| 3992 | } |
| 3993 | |
| 3994 | timeoutMillis = Math.min(timeoutMillis, |
Hall Liu | bd069e3 | 2019-02-28 18:56:30 -0800 | [diff] [blame] | 3995 | TelephonyManager.getMaxNumberVerificationTimeoutMillis()); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3996 | |
| 3997 | NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis); |
| 3998 | } |
| 3999 | |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 4000 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4001 | * Returns true if CDMA provisioning needs to run. |
| 4002 | */ |
| 4003 | public boolean needsOtaServiceProvisioning() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4004 | final long identity = Binder.clearCallingIdentity(); |
| 4005 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4006 | return getDefaultPhone().needsOtaServiceProvisioning(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4007 | } finally { |
| 4008 | Binder.restoreCallingIdentity(identity); |
| 4009 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4010 | } |
| 4011 | |
| 4012 | /** |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 4013 | * Sets the voice mail number of a given subId. |
| 4014 | */ |
| 4015 | @Override |
| 4016 | public boolean setVoiceMailNumber(int subId, String alphaTag, String number) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 4017 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 4018 | mApp, subId, "setVoiceMailNumber"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4019 | |
| 4020 | final long identity = Binder.clearCallingIdentity(); |
| 4021 | try { |
| 4022 | Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER, |
| 4023 | new Pair<String, String>(alphaTag, number), new Integer(subId)); |
| 4024 | return success; |
| 4025 | } finally { |
| 4026 | Binder.restoreCallingIdentity(identity); |
| 4027 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 4028 | } |
| 4029 | |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 4030 | @Override |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 4031 | public Bundle getVisualVoicemailSettings(String callingPackage, int subId) { |
| 4032 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 4033 | TelecomManager tm = mApp.getSystemService(TelecomManager.class); |
| 4034 | String systemDialer = tm.getSystemDialerPackage(); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 4035 | if (!TextUtils.equals(callingPackage, systemDialer)) { |
| 4036 | throw new SecurityException("caller must be system dialer"); |
| 4037 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4038 | |
| 4039 | final long identity = Binder.clearCallingIdentity(); |
| 4040 | try { |
| 4041 | PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId); |
| 4042 | if (phoneAccountHandle == null) { |
| 4043 | return null; |
| 4044 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4045 | return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4046 | } finally { |
| 4047 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 4048 | } |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 4049 | } |
| 4050 | |
| 4051 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4052 | public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId, |
| 4053 | int subId) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 4054 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4055 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4056 | mApp, subId, callingPackage, callingFeatureId, |
| 4057 | "getVisualVoicemailPackageName")) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 4058 | return null; |
| 4059 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4060 | |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 4061 | final long identity = Binder.clearCallingIdentity(); |
| 4062 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4063 | return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName(); |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 4064 | } finally { |
| 4065 | Binder.restoreCallingIdentity(identity); |
| 4066 | } |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 4067 | } |
| 4068 | |
| 4069 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 4070 | public void enableVisualVoicemailSmsFilter(String callingPackage, int subId, |
| 4071 | VisualVoicemailSmsFilterSettings settings) { |
| 4072 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4073 | |
| 4074 | final long identity = Binder.clearCallingIdentity(); |
| 4075 | try { |
| 4076 | VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4077 | mApp, callingPackage, subId, settings); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4078 | } finally { |
| 4079 | Binder.restoreCallingIdentity(identity); |
| 4080 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 4081 | } |
| 4082 | |
| 4083 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 4084 | public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) { |
| 4085 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4086 | |
| 4087 | final long identity = Binder.clearCallingIdentity(); |
| 4088 | try { |
| 4089 | VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4090 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4091 | } finally { |
| 4092 | Binder.restoreCallingIdentity(identity); |
| 4093 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 4094 | } |
| 4095 | |
| 4096 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 4097 | public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings( |
| 4098 | String callingPackage, int subId) { |
| 4099 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4100 | |
| 4101 | final long identity = Binder.clearCallingIdentity(); |
| 4102 | try { |
| 4103 | return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4104 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4105 | } finally { |
| 4106 | Binder.restoreCallingIdentity(identity); |
| 4107 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 4108 | } |
| 4109 | |
| 4110 | @Override |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 4111 | public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4112 | enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4113 | |
| 4114 | final long identity = Binder.clearCallingIdentity(); |
| 4115 | try { |
| 4116 | return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4117 | mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4118 | } finally { |
| 4119 | Binder.restoreCallingIdentity(identity); |
| 4120 | } |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 4121 | } |
| 4122 | |
| 4123 | @Override |
Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 4124 | public void sendVisualVoicemailSmsForSubscriber(String callingPackage, |
| 4125 | String callingAttributionTag, int subId, String number, int port, String text, |
| 4126 | PendingIntent sentIntent) { |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 4127 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 4128 | enforceVisualVoicemailPackage(callingPackage, subId); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 4129 | enforceSendSmsPermission(); |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 4130 | SmsController smsController = PhoneFactory.getSmsController(); |
Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 4131 | smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag, |
| 4132 | subId, number, port, text, sentIntent); |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 4133 | } |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 4134 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 4135 | /** |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4136 | * Sets the voice activation state of a given subId. |
| 4137 | */ |
| 4138 | @Override |
| 4139 | public void setVoiceActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4140 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4141 | mApp, subId, "setVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4142 | |
| 4143 | final long identity = Binder.clearCallingIdentity(); |
| 4144 | try { |
| 4145 | final Phone phone = getPhone(subId); |
| 4146 | if (phone != null) { |
| 4147 | phone.setVoiceActivationState(activationState); |
| 4148 | } else { |
| 4149 | loge("setVoiceActivationState fails with invalid subId: " + subId); |
| 4150 | } |
| 4151 | } finally { |
| 4152 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4153 | } |
| 4154 | } |
| 4155 | |
| 4156 | /** |
| 4157 | * Sets the data activation state of a given subId. |
| 4158 | */ |
| 4159 | @Override |
| 4160 | public void setDataActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4161 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4162 | mApp, subId, "setDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4163 | |
| 4164 | final long identity = Binder.clearCallingIdentity(); |
| 4165 | try { |
| 4166 | final Phone phone = getPhone(subId); |
| 4167 | if (phone != null) { |
| 4168 | phone.setDataActivationState(activationState); |
| 4169 | } else { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 4170 | loge("setDataActivationState fails with invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4171 | } |
| 4172 | } finally { |
| 4173 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4174 | } |
| 4175 | } |
| 4176 | |
| 4177 | /** |
| 4178 | * Returns the voice activation state of a given subId. |
| 4179 | */ |
| 4180 | @Override |
| 4181 | public int getVoiceActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4182 | enforceReadPrivilegedPermission("getVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4183 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4184 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4185 | final long identity = Binder.clearCallingIdentity(); |
| 4186 | try { |
| 4187 | if (phone != null) { |
| 4188 | return phone.getVoiceActivationState(); |
| 4189 | } else { |
| 4190 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 4191 | } |
| 4192 | } finally { |
| 4193 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4194 | } |
| 4195 | } |
| 4196 | |
| 4197 | /** |
| 4198 | * Returns the data activation state of a given subId. |
| 4199 | */ |
| 4200 | @Override |
| 4201 | public int getDataActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4202 | enforceReadPrivilegedPermission("getDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4203 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4204 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4205 | final long identity = Binder.clearCallingIdentity(); |
| 4206 | try { |
| 4207 | if (phone != null) { |
| 4208 | return phone.getDataActivationState(); |
| 4209 | } else { |
| 4210 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 4211 | } |
| 4212 | } finally { |
| 4213 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4214 | } |
| 4215 | } |
| 4216 | |
| 4217 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4218 | * Returns the unread count of voicemails for a subId |
| 4219 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4220 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4221 | public int getVoiceMessageCountForSubscriber(int subId, String callingPackage, |
| 4222 | String callingFeatureId) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 4223 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4224 | mApp, subId, callingPackage, callingFeatureId, |
| 4225 | "getVoiceMessageCountForSubscriber")) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 4226 | return 0; |
| 4227 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4228 | final long identity = Binder.clearCallingIdentity(); |
| 4229 | try { |
| 4230 | final Phone phone = getPhone(subId); |
| 4231 | if (phone != null) { |
| 4232 | return phone.getVoiceMessageCount(); |
| 4233 | } else { |
| 4234 | return 0; |
| 4235 | } |
| 4236 | } finally { |
| 4237 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4238 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4239 | } |
| 4240 | |
| 4241 | /** |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 4242 | * returns true, if the device is in a state where both voice and data |
| 4243 | * are supported simultaneously. This can change based on location or network condition. |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 4244 | */ |
| 4245 | @Override |
| 4246 | public boolean isConcurrentVoiceAndDataAllowed(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4247 | final long identity = Binder.clearCallingIdentity(); |
| 4248 | try { |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 4249 | return getPhoneFromSubIdOrDefault(subId).isConcurrentVoiceAndDataAllowed(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4250 | } finally { |
| 4251 | Binder.restoreCallingIdentity(identity); |
| 4252 | } |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 4253 | } |
| 4254 | |
| 4255 | /** |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4256 | * Send the dialer code if called from the current default dialer or the caller has |
| 4257 | * carrier privilege. |
| 4258 | * @param inputCode The dialer code to send |
| 4259 | */ |
| 4260 | @Override |
| 4261 | public void sendDialerSpecialCode(String callingPackage, String inputCode) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4262 | final Phone defaultPhone = getDefaultPhone(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4263 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 4264 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 4265 | String defaultDialer = tm.getDefaultDialerPackage(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4266 | if (!TextUtils.equals(callingPackage, defaultDialer)) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 4267 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4268 | getDefaultSubscription(), "sendDialerSpecialCode"); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4269 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4270 | |
| 4271 | final long identity = Binder.clearCallingIdentity(); |
| 4272 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4273 | defaultPhone.sendDialerSpecialCode(inputCode); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4274 | } finally { |
| 4275 | Binder.restoreCallingIdentity(identity); |
| 4276 | } |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4277 | } |
| 4278 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 4279 | @Override |
| 4280 | public int getNetworkSelectionMode(int subId) { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 4281 | TelephonyPermissions |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 4282 | .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4283 | mApp, subId, "getNetworkSelectionMode"); |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 4284 | final long identity = Binder.clearCallingIdentity(); |
| 4285 | try { |
| 4286 | if (!isActiveSubscription(subId)) { |
| 4287 | return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 4288 | } |
| 4289 | return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId); |
| 4290 | } finally { |
| 4291 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 4292 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 4293 | } |
| 4294 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4295 | @Override |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 4296 | public boolean isInEmergencySmsMode() { |
| 4297 | enforceReadPrivilegedPermission("isInEmergencySmsMode"); |
| 4298 | final long identity = Binder.clearCallingIdentity(); |
| 4299 | try { |
| 4300 | for (Phone phone : PhoneFactory.getPhones()) { |
| 4301 | if (phone.isInEmergencySmsMode()) { |
| 4302 | return true; |
| 4303 | } |
| 4304 | } |
| 4305 | } finally { |
| 4306 | Binder.restoreCallingIdentity(identity); |
| 4307 | } |
| 4308 | return false; |
| 4309 | } |
| 4310 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4311 | /** |
| 4312 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4313 | * @param subId The subscription to use to check the configuration. |
| 4314 | * @param c The callback that will be used to send the result. |
| 4315 | */ |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 4316 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4317 | public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c) |
| 4318 | throws RemoteException { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4319 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4320 | mApp, subId, "registerImsRegistrationCallback"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4321 | |
| 4322 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4323 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4324 | "IMS not available on device."); |
| 4325 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4326 | final long token = Binder.clearCallingIdentity(); |
| 4327 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4328 | int slotId = getSlotIndexOrException(subId); |
| 4329 | verifyImsMmTelConfiguredOrThrow(slotId); |
joonhunshin | 49f0aed | 2022-08-05 08:33:05 +0000 | [diff] [blame] | 4330 | |
| 4331 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4332 | if (controller != null) { |
| 4333 | ImsManager imsManager = controller.getImsManager(subId); |
| 4334 | if (imsManager != null) { |
| 4335 | imsManager.addRegistrationCallbackForSubscription(c, subId); |
| 4336 | } else { |
| 4337 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE); |
| 4338 | } |
| 4339 | } else { |
| 4340 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION); |
| 4341 | } |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4342 | } catch (ImsException e) { |
| 4343 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4344 | } finally { |
| 4345 | Binder.restoreCallingIdentity(token); |
| 4346 | } |
| 4347 | } |
| 4348 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4349 | /** |
| 4350 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4351 | * @param subId The subscription to use to check the configuration. |
| 4352 | * @param c The callback that will be used to send the result. |
| 4353 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4354 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4355 | public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4356 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4357 | mApp, subId, "unregisterImsRegistrationCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4358 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4359 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4360 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4361 | final long token = Binder.clearCallingIdentity(); |
joonhunshin | 49f0aed | 2022-08-05 08:33:05 +0000 | [diff] [blame] | 4362 | |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4363 | try { |
joonhunshin | 49f0aed | 2022-08-05 08:33:05 +0000 | [diff] [blame] | 4364 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4365 | if (controller != null) { |
| 4366 | ImsManager imsManager = controller.getImsManager(subId); |
| 4367 | if (imsManager != null) { |
| 4368 | imsManager.removeRegistrationCallbackForSubscription(c, subId); |
| 4369 | } else { |
| 4370 | Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId |
| 4371 | + "is inactive, ignoring unregister."); |
| 4372 | // If the ImsManager is not valid, just return, since the callback |
| 4373 | // will already have been removed internally. |
| 4374 | } |
| 4375 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4376 | } finally { |
| 4377 | Binder.restoreCallingIdentity(token); |
| 4378 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4379 | } |
| 4380 | |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 4381 | /** |
| 4382 | * Get the IMS service registration state for the MmTelFeature associated with this sub id. |
| 4383 | */ |
| 4384 | @Override |
| 4385 | public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) { |
| 4386 | enforceReadPrivilegedPermission("getImsMmTelRegistrationState"); |
| 4387 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4388 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4389 | "IMS not available on device."); |
| 4390 | } |
| 4391 | final long token = Binder.clearCallingIdentity(); |
| 4392 | try { |
| 4393 | Phone phone = getPhone(subId); |
| 4394 | if (phone == null) { |
| 4395 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 4396 | + subId + "'"); |
| 4397 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 4398 | } |
| 4399 | phone.getImsRegistrationState(regState -> { |
| 4400 | try { |
| 4401 | consumer.accept((regState == null) |
| 4402 | ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState); |
| 4403 | } catch (RemoteException e) { |
| 4404 | // Ignore if the remote process is no longer available to call back. |
| 4405 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 4406 | } |
| 4407 | }); |
| 4408 | } finally { |
| 4409 | Binder.restoreCallingIdentity(token); |
| 4410 | } |
| 4411 | } |
| 4412 | |
| 4413 | /** |
| 4414 | * Get the transport type for the IMS service registration state. |
| 4415 | */ |
| 4416 | @Override |
| 4417 | public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4418 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4419 | mApp, subId, "getImsMmTelRegistrationTransportType"); |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 4420 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4421 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4422 | "IMS not available on device."); |
| 4423 | } |
| 4424 | final long token = Binder.clearCallingIdentity(); |
| 4425 | try { |
| 4426 | Phone phone = getPhone(subId); |
| 4427 | if (phone == null) { |
| 4428 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 4429 | + subId + "'"); |
| 4430 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 4431 | } |
| 4432 | phone.getImsRegistrationTech(regTech -> { |
| 4433 | // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager |
| 4434 | int regTechConverted = (regTech == null) |
| 4435 | ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech; |
| 4436 | regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get( |
| 4437 | regTechConverted); |
| 4438 | try { |
| 4439 | consumer.accept(regTechConverted); |
| 4440 | } catch (RemoteException e) { |
| 4441 | // Ignore if the remote process is no longer available to call back. |
| 4442 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 4443 | } |
| 4444 | }); |
| 4445 | } finally { |
| 4446 | Binder.restoreCallingIdentity(token); |
| 4447 | } |
| 4448 | } |
| 4449 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4450 | /** |
| 4451 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4452 | * @param subId The subscription to use to check the configuration. |
| 4453 | * @param c The callback that will be used to send the result. |
| 4454 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4455 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4456 | public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) |
| 4457 | throws RemoteException { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4458 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4459 | mApp, subId, "registerMmTelCapabilityCallback"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4460 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4461 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4462 | "IMS not available on device."); |
| 4463 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4464 | final long token = Binder.clearCallingIdentity(); |
| 4465 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4466 | int slotId = getSlotIndexOrException(subId); |
| 4467 | verifyImsMmTelConfiguredOrThrow(slotId); |
Hwangoo Park | 8646b0d | 2023-01-13 02:42:34 +0000 | [diff] [blame] | 4468 | |
| 4469 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4470 | if (controller != null) { |
| 4471 | ImsManager imsManager = controller.getImsManager(subId); |
| 4472 | if (imsManager != null) { |
| 4473 | imsManager.addCapabilitiesCallbackForSubscription(c, subId); |
| 4474 | } else { |
| 4475 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE); |
| 4476 | } |
| 4477 | } else { |
| 4478 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION); |
| 4479 | } |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4480 | } catch (ImsException e) { |
| 4481 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4482 | } finally { |
| 4483 | Binder.restoreCallingIdentity(token); |
| 4484 | } |
| 4485 | } |
| 4486 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4487 | /** |
| 4488 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4489 | * @param subId The subscription to use to check the configuration. |
| 4490 | * @param c The callback that will be used to send the result. |
| 4491 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4492 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4493 | public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4494 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4495 | mApp, subId, "unregisterMmTelCapabilityCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4496 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4497 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4498 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4499 | |
| 4500 | final long token = Binder.clearCallingIdentity(); |
| 4501 | try { |
Hwangoo Park | 8646b0d | 2023-01-13 02:42:34 +0000 | [diff] [blame] | 4502 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4503 | if (controller != null) { |
| 4504 | ImsManager imsManager = controller.getImsManager(subId); |
| 4505 | if (imsManager != null) { |
| 4506 | imsManager.removeCapabilitiesCallbackForSubscription(c, subId); |
| 4507 | } else { |
| 4508 | Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId |
| 4509 | + " is inactive, ignoring unregister."); |
| 4510 | // If the ImsManager is not valid, just return, since the callback |
| 4511 | // will already have been removed internally. |
| 4512 | } |
| 4513 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4514 | } finally { |
| 4515 | Binder.restoreCallingIdentity(token); |
| 4516 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4517 | } |
| 4518 | |
| 4519 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4520 | public boolean isCapable(int subId, int capability, int regTech) { |
| 4521 | enforceReadPrivilegedPermission("isCapable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4522 | final long token = Binder.clearCallingIdentity(); |
| 4523 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4524 | int slotId = getSlotIndexOrException(subId); |
| 4525 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 4526 | return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech); |
| 4527 | } catch (com.android.ims.ImsException e) { |
| 4528 | Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage()); |
| 4529 | return false; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4530 | } catch (ImsException e) { |
Brad Ebinger | 6b5ac22 | 2019-02-04 14:36:52 -0800 | [diff] [blame] | 4531 | Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false."); |
| 4532 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4533 | } finally { |
| 4534 | Binder.restoreCallingIdentity(token); |
| 4535 | } |
| 4536 | } |
| 4537 | |
| 4538 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4539 | public boolean isAvailable(int subId, int capability, int regTech) { |
| 4540 | enforceReadPrivilegedPermission("isAvailable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4541 | final long token = Binder.clearCallingIdentity(); |
| 4542 | try { |
| 4543 | Phone phone = getPhone(subId); |
| 4544 | if (phone == null) return false; |
| 4545 | return phone.isImsCapabilityAvailable(capability, regTech); |
Daniel Bright | 5e40e4e | 2020-03-11 16:35:39 -0700 | [diff] [blame] | 4546 | } catch (com.android.ims.ImsException e) { |
| 4547 | Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage()); |
| 4548 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4549 | } finally { |
| 4550 | Binder.restoreCallingIdentity(token); |
| 4551 | } |
| 4552 | } |
| 4553 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4554 | /** |
| 4555 | * Determines if the MmTel feature capability is supported by the carrier configuration for this |
| 4556 | * subscription. |
| 4557 | * @param subId The subscription to use to check the configuration. |
| 4558 | * @param callback The callback that will be used to send the result. |
| 4559 | * @param capability The MmTelFeature capability that will be used to send the result. |
| 4560 | * @param transportType The transport type of the MmTelFeature capability. |
| 4561 | */ |
| 4562 | @Override |
| 4563 | public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability, |
| 4564 | int transportType) { |
| 4565 | enforceReadPrivilegedPermission("isMmTelCapabilitySupported"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4566 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4567 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4568 | "IMS not available on device."); |
| 4569 | } |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4570 | final long token = Binder.clearCallingIdentity(); |
| 4571 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4572 | int slotId = getSlotIndex(subId); |
| 4573 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4574 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '" |
| 4575 | + subId + "'"); |
| 4576 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 4577 | } |
| 4578 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 4579 | ImsManager.getInstance(mApp, slotId).isSupported(capability, |
| 4580 | transportType, aBoolean -> { |
| 4581 | try { |
| 4582 | callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0)); |
| 4583 | } catch (RemoteException e) { |
| 4584 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not " |
| 4585 | + "running. Ignore"); |
| 4586 | } |
| 4587 | }); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4588 | } catch (ImsException e) { |
| 4589 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4590 | } finally { |
| 4591 | Binder.restoreCallingIdentity(token); |
| 4592 | } |
| 4593 | } |
| 4594 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4595 | /** |
| 4596 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4597 | * @param subId The subscription to use to check the configuration. |
| 4598 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4599 | @Override |
| 4600 | public boolean isAdvancedCallingSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4601 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4602 | mApp, subId, "isAdvancedCallingSettingEnabled"); |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4603 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4604 | final long token = Binder.clearCallingIdentity(); |
| 4605 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4606 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4607 | // 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] | 4608 | return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4609 | } catch (ImsException e) { |
| 4610 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4611 | } finally { |
| 4612 | Binder.restoreCallingIdentity(token); |
| 4613 | } |
| 4614 | } |
| 4615 | |
| 4616 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4617 | public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4618 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4619 | "setAdvancedCallingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4620 | final long identity = Binder.clearCallingIdentity(); |
| 4621 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4622 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4623 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4624 | // 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] | 4625 | ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4626 | } catch (ImsException e) { |
| 4627 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4628 | } finally { |
| 4629 | Binder.restoreCallingIdentity(identity); |
| 4630 | } |
| 4631 | } |
| 4632 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4633 | /** |
| 4634 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4635 | * @param subId The subscription to use to check the configuration. |
| 4636 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4637 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4638 | public boolean isVtSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4639 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4640 | mApp, subId, "isVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4641 | final long identity = Binder.clearCallingIdentity(); |
| 4642 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4643 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4644 | // 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] | 4645 | return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4646 | } catch (ImsException e) { |
| 4647 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4648 | } finally { |
| 4649 | Binder.restoreCallingIdentity(identity); |
| 4650 | } |
| 4651 | } |
| 4652 | |
| 4653 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4654 | public void setVtSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4655 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4656 | "setVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4657 | final long identity = Binder.clearCallingIdentity(); |
| 4658 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4659 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4660 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4661 | // 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] | 4662 | ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4663 | } catch (ImsException e) { |
| 4664 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4665 | } finally { |
| 4666 | Binder.restoreCallingIdentity(identity); |
| 4667 | } |
| 4668 | } |
| 4669 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4670 | /** |
| 4671 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4672 | * @param subId The subscription to use to check the configuration. |
| 4673 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4674 | @Override |
| 4675 | public boolean isVoWiFiSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4676 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4677 | mApp, subId, "isVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4678 | final long identity = Binder.clearCallingIdentity(); |
| 4679 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4680 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4681 | // 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] | 4682 | return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4683 | } catch (ImsException e) { |
| 4684 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4685 | } finally { |
| 4686 | Binder.restoreCallingIdentity(identity); |
| 4687 | } |
| 4688 | } |
| 4689 | |
| 4690 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4691 | public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4692 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4693 | "setVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4694 | final long identity = Binder.clearCallingIdentity(); |
| 4695 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4696 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4697 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4698 | // 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] | 4699 | ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4700 | } catch (ImsException e) { |
| 4701 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4702 | } finally { |
| 4703 | Binder.restoreCallingIdentity(identity); |
| 4704 | } |
| 4705 | } |
| 4706 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4707 | /** |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 4708 | * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not |
| 4709 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4710 | * @param subId The subscription to use to check the configuration. |
| 4711 | */ |
| 4712 | @Override |
| 4713 | public boolean isCrossSimCallingEnabledByUser(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4714 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 4715 | mApp, subId, "isCrossSimCallingEnabledByUser"); |
| 4716 | final long identity = Binder.clearCallingIdentity(); |
| 4717 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4718 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4719 | // 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] | 4720 | return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser(); |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 4721 | } catch (ImsException e) { |
| 4722 | throw new ServiceSpecificException(e.getCode()); |
| 4723 | } finally { |
| 4724 | Binder.restoreCallingIdentity(identity); |
| 4725 | } |
| 4726 | } |
| 4727 | |
| 4728 | /** |
| 4729 | * Sets the user's setting for whether or not Voice over Cross SIM is enabled. |
| 4730 | * Requires MODIFY_PHONE_STATE permission. |
| 4731 | * @param subId The subscription to use to check the configuration. |
| 4732 | * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled, |
| 4733 | * false otherwise |
| 4734 | */ |
| 4735 | @Override |
| 4736 | public void setCrossSimCallingEnabled(int subId, boolean isEnabled) { |
| 4737 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4738 | "setCrossSimCallingEnabled"); |
| 4739 | final long identity = Binder.clearCallingIdentity(); |
| 4740 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4741 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4742 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4743 | // 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] | 4744 | ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled); |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 4745 | } catch (ImsException e) { |
| 4746 | throw new ServiceSpecificException(e.getCode()); |
| 4747 | } finally { |
| 4748 | Binder.restoreCallingIdentity(identity); |
| 4749 | } |
| 4750 | } |
| 4751 | |
| 4752 | /** |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4753 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4754 | * @param subId The subscription to use to check the configuration. |
| 4755 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4756 | @Override |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4757 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4758 | public boolean isVoWiFiRoamingSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4759 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4760 | mApp, subId, "isVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4761 | final long identity = Binder.clearCallingIdentity(); |
| 4762 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4763 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4764 | // 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] | 4765 | return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4766 | } catch (ImsException e) { |
| 4767 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4768 | } finally { |
| 4769 | Binder.restoreCallingIdentity(identity); |
| 4770 | } |
| 4771 | } |
| 4772 | |
| 4773 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4774 | public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4775 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4776 | "setVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4777 | final long identity = Binder.clearCallingIdentity(); |
| 4778 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4779 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4780 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4781 | // 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] | 4782 | ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4783 | } catch (ImsException e) { |
| 4784 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4785 | } finally { |
| 4786 | Binder.restoreCallingIdentity(identity); |
| 4787 | } |
| 4788 | } |
| 4789 | |
| 4790 | @Override |
| 4791 | public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) { |
| 4792 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4793 | "setVoWiFiNonPersistent"); |
| 4794 | final long identity = Binder.clearCallingIdentity(); |
| 4795 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4796 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4797 | // This setting will be ignored if the ImsService isn't up. |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4798 | ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4799 | } catch (ImsException e) { |
| 4800 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4801 | } finally { |
| 4802 | Binder.restoreCallingIdentity(identity); |
| 4803 | } |
| 4804 | } |
| 4805 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4806 | /** |
| 4807 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4808 | * @param subId The subscription to use to check the configuration. |
| 4809 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4810 | @Override |
| 4811 | public int getVoWiFiModeSetting(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4812 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4813 | mApp, subId, "getVoWiFiModeSetting"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4814 | final long identity = Binder.clearCallingIdentity(); |
| 4815 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4816 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4817 | // 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] | 4818 | return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4819 | } catch (ImsException e) { |
| 4820 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4821 | } finally { |
| 4822 | Binder.restoreCallingIdentity(identity); |
| 4823 | } |
| 4824 | } |
| 4825 | |
| 4826 | @Override |
| 4827 | public void setVoWiFiModeSetting(int subId, int mode) { |
| 4828 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4829 | "setVoWiFiModeSetting"); |
| 4830 | final long identity = Binder.clearCallingIdentity(); |
| 4831 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4832 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4833 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4834 | // 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] | 4835 | ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4836 | } catch (ImsException e) { |
| 4837 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4838 | } finally { |
| 4839 | Binder.restoreCallingIdentity(identity); |
| 4840 | } |
| 4841 | } |
| 4842 | |
| 4843 | @Override |
| 4844 | public int getVoWiFiRoamingModeSetting(int subId) { |
| 4845 | enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting"); |
| 4846 | final long identity = Binder.clearCallingIdentity(); |
| 4847 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4848 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4849 | // 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] | 4850 | return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4851 | } catch (ImsException e) { |
| 4852 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4853 | } finally { |
| 4854 | Binder.restoreCallingIdentity(identity); |
| 4855 | } |
| 4856 | } |
| 4857 | |
| 4858 | @Override |
| 4859 | public void setVoWiFiRoamingModeSetting(int subId, int mode) { |
| 4860 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4861 | "setVoWiFiRoamingModeSetting"); |
| 4862 | final long identity = Binder.clearCallingIdentity(); |
| 4863 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4864 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4865 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4866 | // 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] | 4867 | ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4868 | } catch (ImsException e) { |
| 4869 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4870 | } finally { |
| 4871 | Binder.restoreCallingIdentity(identity); |
| 4872 | } |
| 4873 | } |
| 4874 | |
| 4875 | @Override |
| 4876 | public void setRttCapabilitySetting(int subId, boolean isEnabled) { |
| 4877 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4878 | "setRttCapabilityEnabled"); |
| 4879 | final long identity = Binder.clearCallingIdentity(); |
| 4880 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4881 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4882 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4883 | // 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] | 4884 | ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4885 | } catch (ImsException e) { |
| 4886 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4887 | } finally { |
| 4888 | Binder.restoreCallingIdentity(identity); |
| 4889 | } |
| 4890 | } |
| 4891 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4892 | /** |
| 4893 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4894 | * @param subId The subscription to use to check the configuration. |
| 4895 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4896 | @Override |
| 4897 | public boolean isTtyOverVolteEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4898 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4899 | mApp, subId, "isTtyOverVolteEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4900 | final long identity = Binder.clearCallingIdentity(); |
| 4901 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4902 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4903 | // 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] | 4904 | return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4905 | } catch (ImsException e) { |
| 4906 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4907 | } finally { |
| 4908 | Binder.restoreCallingIdentity(identity); |
| 4909 | } |
| 4910 | } |
| 4911 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4912 | @Override |
| 4913 | public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 4914 | enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4915 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4916 | final long identity = Binder.clearCallingIdentity(); |
| 4917 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4918 | if (!isImsAvailableOnDevice()) { |
| 4919 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4920 | "IMS not available on device."); |
| 4921 | } |
| 4922 | int slotId = getSlotIndexOrException(subId); |
| 4923 | verifyImsMmTelConfiguredOrThrow(slotId); |
Hwangoo Park | 8646b0d | 2023-01-13 02:42:34 +0000 | [diff] [blame] | 4924 | |
| 4925 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4926 | if (controller != null) { |
| 4927 | ImsManager imsManager = controller.getImsManager(subId); |
| 4928 | if (imsManager != null) { |
| 4929 | imsManager.addProvisioningCallbackForSubscription(callback, subId); |
| 4930 | } else { |
| 4931 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE); |
| 4932 | } |
| 4933 | } else { |
| 4934 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION); |
| 4935 | } |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4936 | } catch (ImsException e) { |
| 4937 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4938 | } finally { |
| 4939 | Binder.restoreCallingIdentity(identity); |
| 4940 | } |
| 4941 | } |
| 4942 | |
| 4943 | @Override |
| 4944 | public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 4945 | enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4946 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4947 | final long identity = Binder.clearCallingIdentity(); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4948 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4949 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4950 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4951 | try { |
Hwangoo Park | 8646b0d | 2023-01-13 02:42:34 +0000 | [diff] [blame] | 4952 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4953 | if (controller != null) { |
| 4954 | ImsManager imsManager = controller.getImsManager(subId); |
| 4955 | if (imsManager != null) { |
| 4956 | imsManager.removeProvisioningCallbackForSubscription(callback, subId); |
| 4957 | } else { |
| 4958 | Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId |
| 4959 | + " is inactive, ignoring unregister."); |
| 4960 | // If the ImsManager is not valid, just return, since the callback will already |
| 4961 | // have been removed internally. |
| 4962 | } |
| 4963 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4964 | } finally { |
| 4965 | Binder.restoreCallingIdentity(identity); |
| 4966 | } |
| 4967 | } |
| 4968 | |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4969 | @Override |
| 4970 | public void registerFeatureProvisioningChangedCallback(int subId, |
| 4971 | IFeatureProvisioningCallback callback) { |
| 4972 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4973 | mApp, subId, "registerFeatureProvisioningChangedCallback"); |
| 4974 | |
| 4975 | final long identity = Binder.clearCallingIdentity(); |
| 4976 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4977 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4978 | } |
| 4979 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 4980 | try { |
| 4981 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 4982 | if (controller == null) { |
| 4983 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4984 | "Device does not support IMS"); |
| 4985 | } |
| 4986 | controller.addFeatureProvisioningChangedCallback(subId, callback); |
| 4987 | } finally { |
| 4988 | Binder.restoreCallingIdentity(identity); |
| 4989 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4990 | } |
| 4991 | |
| 4992 | @Override |
| 4993 | public void unregisterFeatureProvisioningChangedCallback(int subId, |
| 4994 | IFeatureProvisioningCallback callback) { |
| 4995 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4996 | mApp, subId, "unregisterFeatureProvisioningChangedCallback"); |
| 4997 | |
| 4998 | final long identity = Binder.clearCallingIdentity(); |
| 4999 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5000 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 5001 | } |
| 5002 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5003 | try { |
| 5004 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5005 | if (controller == null) { |
| 5006 | loge("unregisterFeatureProvisioningChangedCallback: Device does not support IMS"); |
| 5007 | return; |
| 5008 | } |
| 5009 | controller.removeFeatureProvisioningChangedCallback(subId, callback); |
| 5010 | } finally { |
| 5011 | Binder.restoreCallingIdentity(identity); |
| 5012 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5013 | } |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5014 | |
| 5015 | private void checkModifyPhoneStatePermission(int subId, String message) { |
| 5016 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5017 | message); |
| 5018 | } |
| 5019 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5020 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5021 | public void setRcsProvisioningStatusForCapability(int subId, int capability, int tech, |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5022 | boolean isProvisioned) { |
| 5023 | checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability"); |
| 5024 | |
| 5025 | final long identity = Binder.clearCallingIdentity(); |
| 5026 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5027 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5028 | if (controller == null) { |
| 5029 | loge("setRcsProvisioningStatusForCapability: Device does not support IMS"); |
| 5030 | return; |
| 5031 | } |
| 5032 | controller.setRcsProvisioningStatusForCapability( |
| 5033 | subId, capability, tech, isProvisioned); |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5034 | } finally { |
| 5035 | Binder.restoreCallingIdentity(identity); |
| 5036 | } |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5037 | } |
| 5038 | |
| 5039 | |
| 5040 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5041 | public boolean getRcsProvisioningStatusForCapability(int subId, int capability, int tech) { |
| 5042 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5043 | mApp, subId, "getRcsProvisioningStatusForCapability"); |
| 5044 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5045 | final long identity = Binder.clearCallingIdentity(); |
| 5046 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5047 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5048 | if (controller == null) { |
| 5049 | loge("getRcsProvisioningStatusForCapability: Device does not support IMS"); |
| 5050 | |
| 5051 | // device does not support IMS, this method will return true always. |
| 5052 | return true; |
| 5053 | } |
| 5054 | return controller.getRcsProvisioningStatusForCapability(subId, capability, tech); |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5055 | } finally { |
| 5056 | Binder.restoreCallingIdentity(identity); |
| 5057 | } |
| 5058 | } |
| 5059 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5060 | @Override |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5061 | public void setImsProvisioningStatusForCapability(int subId, int capability, int tech, |
| 5062 | boolean isProvisioned) { |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5063 | checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5064 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5065 | final long identity = Binder.clearCallingIdentity(); |
| 5066 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5067 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5068 | if (controller == null) { |
| 5069 | loge("setImsProvisioningStatusForCapability: Device does not support IMS"); |
| 5070 | return; |
| 5071 | } |
| 5072 | controller.setImsProvisioningStatusForCapability( |
| 5073 | subId, capability, tech, isProvisioned); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5074 | } finally { |
| 5075 | Binder.restoreCallingIdentity(identity); |
| 5076 | } |
| 5077 | } |
| 5078 | |
| 5079 | @Override |
| 5080 | public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) { |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5081 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5082 | mApp, subId, "getProvisioningStatusForCapability"); |
| 5083 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5084 | final long identity = Binder.clearCallingIdentity(); |
| 5085 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5086 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5087 | if (controller == null) { |
| 5088 | loge("getImsProvisioningStatusForCapability: Device does not support IMS"); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5089 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5090 | // device does not support IMS, this method will return true always. |
| 5091 | return true; |
| 5092 | } |
| 5093 | return controller.getImsProvisioningStatusForCapability(subId, capability, tech); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5094 | } finally { |
| 5095 | Binder.restoreCallingIdentity(identity); |
| 5096 | } |
| 5097 | } |
| 5098 | |
| 5099 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5100 | public boolean isProvisioningRequiredForCapability(int subId, int capability, int tech) { |
| 5101 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5102 | mApp, subId, "isProvisioningRequiredForCapability"); |
| 5103 | |
| 5104 | final long identity = Binder.clearCallingIdentity(); |
| 5105 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5106 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5107 | if (controller == null) { |
| 5108 | loge("isProvisioningRequiredForCapability: Device does not support IMS"); |
| 5109 | |
| 5110 | // device does not support IMS, this method will return false |
| 5111 | return false; |
| 5112 | } |
| 5113 | return controller.isImsProvisioningRequiredForCapability(subId, capability, tech); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5114 | } finally { |
| 5115 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5116 | } |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5117 | } |
| 5118 | |
| 5119 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5120 | public boolean isRcsProvisioningRequiredForCapability(int subId, int capability, int tech) { |
| 5121 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5122 | mApp, subId, "isProvisioningRequiredForCapability"); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5123 | |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5124 | final long identity = Binder.clearCallingIdentity(); |
| 5125 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5126 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5127 | if (controller == null) { |
| 5128 | loge("isRcsProvisioningRequiredForCapability: Device does not support IMS"); |
| 5129 | |
| 5130 | // device does not support IMS, this method will return false |
| 5131 | return false; |
| 5132 | } |
| 5133 | return controller.isRcsProvisioningRequiredForCapability(subId, capability, tech); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5134 | } finally { |
| 5135 | Binder.restoreCallingIdentity(identity); |
| 5136 | } |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5137 | } |
| 5138 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5139 | @Override |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5140 | public int getImsProvisioningInt(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5141 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5142 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 5143 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5144 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5145 | mApp, subId, "getImsProvisioningInt"); |
| 5146 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5147 | final long identity = Binder.clearCallingIdentity(); |
| 5148 | try { |
| 5149 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5150 | int slotId = getSlotIndex(subId); |
| 5151 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5152 | Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '" |
| 5153 | + subId + "' for key:" + key); |
| 5154 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
| 5155 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5156 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5157 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5158 | if (controller == null) { |
| 5159 | loge("getImsProvisioningInt: Device does not support IMS"); |
| 5160 | |
| 5161 | // device does not support IMS, this method will return CONFIG_RESULT_UNKNOWN. |
| 5162 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
| 5163 | } |
| 5164 | int retVal = controller.getProvisioningValue(subId, key); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5165 | if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) { |
| 5166 | return retVal; |
| 5167 | } |
| 5168 | |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5169 | return ImsManager.getInstance(mApp, slotId).getConfigInt(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5170 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5171 | Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '" |
| 5172 | + subId + "' for key:" + key); |
| 5173 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5174 | } finally { |
| 5175 | Binder.restoreCallingIdentity(identity); |
| 5176 | } |
| 5177 | } |
| 5178 | |
| 5179 | @Override |
| 5180 | public String getImsProvisioningString(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5181 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5182 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 5183 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5184 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5185 | mApp, subId, "getImsProvisioningString"); |
| 5186 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5187 | final long identity = Binder.clearCallingIdentity(); |
| 5188 | try { |
| 5189 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5190 | int slotId = getSlotIndex(subId); |
| 5191 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5192 | Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '" |
| 5193 | + subId + "' for key:" + key); |
| 5194 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC; |
| 5195 | } |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5196 | return ImsManager.getInstance(mApp, slotId).getConfigString(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5197 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5198 | Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '" |
| 5199 | + subId + "' for key:" + key); |
| 5200 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5201 | } finally { |
| 5202 | Binder.restoreCallingIdentity(identity); |
| 5203 | } |
| 5204 | } |
| 5205 | |
| 5206 | @Override |
| 5207 | public int setImsProvisioningInt(int subId, int key, int value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5208 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5209 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 5210 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 5211 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5212 | "setImsProvisioningInt"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5213 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5214 | final long identity = Binder.clearCallingIdentity(); |
| 5215 | try { |
| 5216 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5217 | int slotId = getSlotIndex(subId); |
| 5218 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5219 | Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '" |
| 5220 | + subId + "' for key:" + key); |
| 5221 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 5222 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5223 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5224 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5225 | if (controller == null) { |
| 5226 | loge("setImsProvisioningInt: Device does not support IMS"); |
| 5227 | |
| 5228 | // device does not support IMS, this method will return CONFIG_RESULT_FAILED. |
| 5229 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 5230 | } |
| 5231 | int retVal = controller.setProvisioningValue(subId, key, value); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5232 | if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) { |
| 5233 | return retVal; |
| 5234 | } |
| 5235 | |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5236 | return ImsManager.getInstance(mApp, slotId).setConfig(key, value); |
| 5237 | } catch (com.android.ims.ImsException | RemoteException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5238 | Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5239 | + "' for key:" + key, e); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5240 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5241 | } finally { |
| 5242 | Binder.restoreCallingIdentity(identity); |
| 5243 | } |
| 5244 | } |
| 5245 | |
| 5246 | @Override |
| 5247 | public int setImsProvisioningString(int subId, int key, String value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5248 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5249 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 5250 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 5251 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5252 | "setImsProvisioningString"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5253 | final long identity = Binder.clearCallingIdentity(); |
| 5254 | try { |
| 5255 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5256 | int slotId = getSlotIndex(subId); |
| 5257 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5258 | Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '" |
| 5259 | + subId + "' for key:" + key); |
| 5260 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 5261 | } |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5262 | return ImsManager.getInstance(mApp, slotId).setConfig(key, value); |
| 5263 | } catch (com.android.ims.ImsException | RemoteException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5264 | Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5265 | + "' for key:" + key, e); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5266 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5267 | } finally { |
| 5268 | Binder.restoreCallingIdentity(identity); |
| 5269 | } |
| 5270 | } |
| 5271 | |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5272 | /** |
| 5273 | * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL |
| 5274 | * for the given slot ID or no ImsResolver instance has been created. |
| 5275 | * @param slotId The slot ID that the IMS service is created for. |
| 5276 | * @throws ImsException If there is no ImsService configured for this slot. |
| 5277 | */ |
| 5278 | private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException { |
| 5279 | if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId, |
| 5280 | ImsFeature.FEATURE_MMTEL)) { |
| 5281 | throw new ImsException("This subscription does not support MMTEL over IMS", |
| 5282 | ImsException.CODE_ERROR_UNSUPPORTED_OPERATION); |
| 5283 | } |
| 5284 | } |
| 5285 | |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5286 | private int getSlotIndexOrException(int subId) throws ImsException { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5287 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 5288 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5289 | throw new ImsException("Invalid Subscription Id, subId=" + subId, |
| 5290 | ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5291 | } |
| 5292 | return slotId; |
| 5293 | } |
| 5294 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5295 | private int getSlotIndex(int subId) { |
| 5296 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 5297 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
| 5298 | return SubscriptionManager.INVALID_SIM_SLOT_INDEX; |
| 5299 | } |
| 5300 | return slotId; |
| 5301 | } |
| 5302 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5303 | /** |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 5304 | * Returns the data network type for a subId; does not throw SecurityException. |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5305 | */ |
| 5306 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5307 | public int getNetworkTypeForSubscriber(int subId, String callingPackage, |
| 5308 | String callingFeatureId) { |
Shuo Qian | 13d8915 | 2021-05-10 23:58:11 -0700 | [diff] [blame] | 5309 | try { |
| 5310 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 5311 | } catch (SecurityException se) { |
| 5312 | EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid()); |
| 5313 | throw new SecurityException("Package " + callingPackage + " does not belong to " |
| 5314 | + Binder.getCallingUid()); |
| 5315 | } |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 5316 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 5317 | if (targetSdk > android.os.Build.VERSION_CODES.Q) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5318 | return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 5319 | } else if (targetSdk == android.os.Build.VERSION_CODES.Q |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 5320 | && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 5321 | mApp, subId, callingPackage, callingFeatureId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5322 | "getNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5323 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5324 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 5325 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5326 | final long identity = Binder.clearCallingIdentity(); |
| 5327 | try { |
| 5328 | final Phone phone = getPhone(subId); |
| 5329 | if (phone != null) { |
| 5330 | return phone.getServiceState().getDataNetworkType(); |
| 5331 | } else { |
| 5332 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5333 | } |
| 5334 | } finally { |
| 5335 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5336 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5337 | } |
| 5338 | |
| 5339 | /** |
| 5340 | * Returns the data network type |
| 5341 | */ |
| 5342 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5343 | public int getDataNetworkType(String callingPackage, String callingFeatureId) { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5344 | return getDataNetworkTypeForSubscriber(SubscriptionManager.getDefaultDataSubscriptionId(), |
Zoey Chen | fd61f7f | 2021-04-21 13:42:10 +0800 | [diff] [blame] | 5345 | callingPackage, callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5346 | } |
| 5347 | |
| 5348 | /** |
| 5349 | * Returns the data network type for a subId |
| 5350 | */ |
| 5351 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5352 | public int getDataNetworkTypeForSubscriber(int subId, String callingPackage, |
| 5353 | String callingFeatureId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 5354 | String functionName = "getDataNetworkTypeForSubscriber"; |
| 5355 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 5356 | mApp, functionName)) { |
| 5357 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 5358 | mApp, subId, callingPackage, callingFeatureId, functionName)) { |
| 5359 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5360 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5361 | } |
| 5362 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5363 | final long identity = Binder.clearCallingIdentity(); |
| 5364 | try { |
| 5365 | final Phone phone = getPhone(subId); |
| 5366 | if (phone != null) { |
| 5367 | return phone.getServiceState().getDataNetworkType(); |
| 5368 | } else { |
| 5369 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5370 | } |
| 5371 | } finally { |
| 5372 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5373 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5374 | } |
| 5375 | |
| 5376 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5377 | * Returns the Voice network type for a subId |
| 5378 | */ |
| 5379 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5380 | public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage, |
| 5381 | String callingFeatureId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 5382 | String functionName = "getVoiceNetworkTypeForSubscriber"; |
| 5383 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 5384 | mApp, functionName)) { |
| 5385 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 5386 | mApp, subId, callingPackage, callingFeatureId, functionName)) { |
| 5387 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5388 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 5389 | } |
| 5390 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5391 | final long identity = Binder.clearCallingIdentity(); |
| 5392 | try { |
| 5393 | final Phone phone = getPhone(subId); |
| 5394 | if (phone != null) { |
| 5395 | return phone.getServiceState().getVoiceNetworkType(); |
| 5396 | } else { |
| 5397 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5398 | } |
| 5399 | } finally { |
| 5400 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5401 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5402 | } |
| 5403 | |
| 5404 | /** |
| 5405 | * @return true if a ICC card is present |
| 5406 | */ |
| 5407 | public boolean hasIccCard() { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5408 | // FIXME Make changes to pass defaultSimId of type int |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5409 | return hasIccCardUsingSlotIndex(SubscriptionManager.getSlotIndex( |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5410 | getDefaultSubscription())); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5411 | } |
| 5412 | |
| 5413 | /** |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5414 | * @return true if a ICC card is present for a slotIndex |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5415 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5416 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5417 | public boolean hasIccCardUsingSlotIndex(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5418 | final long identity = Binder.clearCallingIdentity(); |
| 5419 | try { |
| 5420 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5421 | if (phone != null) { |
| 5422 | return phone.getIccCard().hasIccCard(); |
| 5423 | } else { |
| 5424 | return false; |
| 5425 | } |
| 5426 | } finally { |
| 5427 | Binder.restoreCallingIdentity(identity); |
Amit Mahajan | a6fc2a8 | 2015-01-06 11:53:51 -0800 | [diff] [blame] | 5428 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5429 | } |
| 5430 | |
| 5431 | /** |
| 5432 | * Return if the current radio is LTE on CDMA. This |
| 5433 | * is a tri-state return value as for a period of time |
| 5434 | * the mode may be unknown. |
| 5435 | * |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5436 | * @param callingPackage the name of the package making the call. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5437 | * @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] | 5438 | * or {@link Phone#LTE_ON_CDMA_TRUE} |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5439 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5440 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5441 | public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) { |
| 5442 | return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 5443 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5444 | } |
| 5445 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5446 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5447 | public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage, |
| 5448 | String callingFeatureId) { |
Sarah Chin | 790d292 | 2020-01-16 12:17:23 -0800 | [diff] [blame] | 5449 | try { |
| 5450 | enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber"); |
| 5451 | } catch (SecurityException e) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5452 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 5453 | } |
| 5454 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5455 | final long identity = Binder.clearCallingIdentity(); |
| 5456 | try { |
| 5457 | final Phone phone = getPhone(subId); |
| 5458 | if (phone == null) { |
| 5459 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 5460 | } else { |
Nathan Harold | 05ad633 | 2020-07-10 11:54:36 -0700 | [diff] [blame] | 5461 | return TelephonyProperties.lte_on_cdma_device() |
| 5462 | .orElse(PhoneConstants.LTE_ON_CDMA_FALSE); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5463 | } |
| 5464 | } finally { |
| 5465 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5466 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5467 | } |
| 5468 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5469 | /** |
| 5470 | * {@hide} |
| 5471 | * Returns Default subId, 0 in the case of single standby. |
| 5472 | */ |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 5473 | private int getDefaultSubscription() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5474 | return SubscriptionManager.getDefaultSubscriptionId(); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5475 | } |
| 5476 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 5477 | private int getSlotForDefaultSubscription() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5478 | return SubscriptionManager.getPhoneId(getDefaultSubscription()); |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 5479 | } |
| 5480 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 5481 | private int getPreferredVoiceSubscription() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5482 | return SubscriptionManager.getDefaultVoiceSubscriptionId(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5483 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5484 | |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 5485 | private boolean isActiveSubscription(int subId) { |
Jack Yu | 3beaf9d | 2023-04-14 09:17:27 -0700 | [diff] [blame] | 5486 | return getSubscriptionManagerService().isActiveSubId(subId, |
| 5487 | mApp.getOpPackageName(), mApp.getFeatureId()); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 5488 | } |
| 5489 | |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5490 | /** |
| 5491 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 5492 | */ |
| 5493 | public int getWhenToMakeWifiCalls() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5494 | final long identity = Binder.clearCallingIdentity(); |
| 5495 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5496 | return Settings.System.getInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5497 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, |
| 5498 | getWhenToMakeWifiCallsDefaultPreference()); |
| 5499 | } finally { |
| 5500 | Binder.restoreCallingIdentity(identity); |
| 5501 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5502 | } |
| 5503 | |
| 5504 | /** |
| 5505 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 5506 | */ |
| 5507 | public void setWhenToMakeWifiCalls(int preference) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5508 | final long identity = Binder.clearCallingIdentity(); |
| 5509 | try { |
| 5510 | if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5511 | Settings.System.putInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5512 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference); |
| 5513 | } finally { |
| 5514 | Binder.restoreCallingIdentity(identity); |
| 5515 | } |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 5516 | } |
| 5517 | |
Sailesh Nepal | d1e6815 | 2013-12-12 19:08:02 -0800 | [diff] [blame] | 5518 | private static int getWhenToMakeWifiCallsDefaultPreference() { |
Santos Cordon | da120f4 | 2014-08-06 04:44:34 -0700 | [diff] [blame] | 5519 | // TODO: Use a build property to choose this value. |
Evan Charlton | 9829e88 | 2013-12-19 15:30:38 -0800 | [diff] [blame] | 5520 | return TelephonyManager.WifiCallingChoices.ALWAYS_USE; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5521 | } |
Shishir Agrawal | 69f6812 | 2013-12-16 17:25:49 -0800 | [diff] [blame] | 5522 | |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5523 | private Phone getPhoneFromSlotPortIndexOrThrowException(int slotIndex, int portIndex) { |
| 5524 | int phoneId = UiccController.getInstance().getPhoneIdFromSlotPortIndex(slotIndex, |
| 5525 | portIndex); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5526 | if (phoneId == -1) { |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5527 | throw new IllegalArgumentException("Given slot index: " + slotIndex + " port index: " |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 5528 | + portIndex + " does not correspond to an active phone"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5529 | } |
| 5530 | return PhoneFactory.getPhone(phoneId); |
| 5531 | } |
| 5532 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5533 | @Override |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 5534 | public IccOpenLogicalChannelResponse iccOpenLogicalChannel( |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5535 | @NonNull IccLogicalChannelRequest request) { |
| 5536 | Phone phone = getPhoneFromValidIccLogicalChannelRequest(request, |
| 5537 | /*message=*/ "iccOpenLogicalChannel"); |
| 5538 | |
| 5539 | if (DBG) log("iccOpenLogicalChannel: request=" + request); |
| 5540 | // Verify that the callingPackage in the request belongs to the calling UID |
| 5541 | mAppOps.checkPackage(Binder.getCallingUid(), request.callingPackage); |
| 5542 | |
| 5543 | return iccOpenLogicalChannelWithPermission(phone, request); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5544 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5545 | |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5546 | private Phone getPhoneFromValidIccLogicalChannelRequest( |
| 5547 | @NonNull IccLogicalChannelRequest request, String message) { |
| 5548 | Phone phone; |
| 5549 | if (request.subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) { |
| 5550 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5551 | mApp, request.subId, message); |
| 5552 | phone = getPhoneFromSubId(request.subId); |
| 5553 | } else if (request.slotIndex != SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5554 | enforceModifyPermission(); |
| 5555 | phone = getPhoneFromSlotPortIndexOrThrowException(request.slotIndex, request.portIndex); |
| 5556 | } else { |
| 5557 | throw new IllegalArgumentException("Both subId and slotIndex in request are invalid."); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5558 | } |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5559 | return phone; |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5560 | } |
| 5561 | |
| 5562 | private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone, |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5563 | IccLogicalChannelRequest channelRequest) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5564 | final long identity = Binder.clearCallingIdentity(); |
| 5565 | try { |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5566 | if (TextUtils.equals(ISDR_AID, channelRequest.aid)) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5567 | // Only allows LPA to open logical channel to ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5568 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 5569 | .getContext().getPackageManager()); |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5570 | if (bestComponent == null || !TextUtils.equals(channelRequest.callingPackage, |
| 5571 | bestComponent.packageName)) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5572 | loge("The calling package is not allowed to access ISD-R."); |
| 5573 | throw new SecurityException( |
| 5574 | "The calling package is not allowed to access ISD-R."); |
| 5575 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 5576 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 5577 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5578 | IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest( |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5579 | CMD_OPEN_CHANNEL, channelRequest, phone, null /* workSource */); |
| 5580 | if (DBG) log("iccOpenLogicalChannelWithPermission: response=" + response); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5581 | return response; |
| 5582 | } finally { |
| 5583 | Binder.restoreCallingIdentity(identity); |
| 5584 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5585 | } |
| 5586 | |
| 5587 | @Override |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5588 | public boolean iccCloseLogicalChannel(@NonNull IccLogicalChannelRequest request) { |
| 5589 | Phone phone = getPhoneFromValidIccLogicalChannelRequest(request, |
| 5590 | /*message=*/"iccCloseLogicalChannel"); |
| 5591 | |
| 5592 | if (DBG) log("iccCloseLogicalChannel: request=" + request); |
| 5593 | |
| 5594 | return iccCloseLogicalChannelWithPermission(phone, request); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5595 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5596 | |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5597 | private boolean iccCloseLogicalChannelWithPermission(Phone phone, |
| 5598 | IccLogicalChannelRequest request) { |
Chen Xu | a8f0dff | 2022-02-12 00:34:15 -0800 | [diff] [blame] | 5599 | // before this feature is enabled, this API should only return false if |
| 5600 | // the operation fails instead of throwing runtime exception for |
| 5601 | // backward-compatibility. |
| 5602 | final boolean shouldThrowExceptionOnFailure = CompatChanges.isChangeEnabled( |
| 5603 | ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE, Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5604 | final long identity = Binder.clearCallingIdentity(); |
| 5605 | try { |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5606 | if (request.channel < 0) { |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 5607 | throw new IllegalArgumentException("request.channel is less than 0"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5608 | } |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 5609 | Object result = sendRequest(CMD_CLOSE_CHANNEL, request.channel, phone, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5610 | null /* workSource */); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 5611 | Boolean success = false; |
| 5612 | if (result instanceof RuntimeException) { |
| 5613 | // if there is an exception returned, throw from the binder thread here. |
Chen Xu | a8f0dff | 2022-02-12 00:34:15 -0800 | [diff] [blame] | 5614 | if (shouldThrowExceptionOnFailure) { |
| 5615 | throw (RuntimeException) result; |
| 5616 | } else { |
| 5617 | return false; |
| 5618 | } |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 5619 | } else if (result instanceof Boolean) { |
| 5620 | success = (Boolean) result; |
| 5621 | } else { |
| 5622 | loge("iccCloseLogicalChannelWithPermission: supported return type " + result); |
| 5623 | } |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5624 | if (DBG) log("iccCloseLogicalChannelWithPermission: success=" + success); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5625 | return success; |
| 5626 | } finally { |
| 5627 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5628 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5629 | } |
| 5630 | |
| 5631 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5632 | public String iccTransmitApduLogicalChannel(int subId, int channel, int cla, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5633 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5634 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5635 | mApp, subId, "iccTransmitApduLogicalChannel"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5636 | if (DBG) { |
| 5637 | log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel |
| 5638 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 5639 | + p3 + " data=" + data); |
| 5640 | } |
| 5641 | return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla, |
| 5642 | command, p1, p2, p3, data); |
| 5643 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5644 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5645 | @Override |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5646 | public String iccTransmitApduLogicalChannelByPort(int slotIndex, int portIndex, int channel, |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 5647 | int cla, int command, int p1, int p2, int p3, String data) { |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5648 | enforceModifyPermission(); |
| 5649 | if (DBG) { |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5650 | log("iccTransmitApduLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex=" |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 5651 | + portIndex + " chnl=" + channel + " cla=" + cla + " cmd=" + command + " p1=" |
| 5652 | + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5653 | } |
| 5654 | return iccTransmitApduLogicalChannelWithPermission( |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5655 | getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel, cla, |
| 5656 | command, p1, p2, p3, data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5657 | } |
| 5658 | |
| 5659 | private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla, |
| 5660 | int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5661 | final long identity = Binder.clearCallingIdentity(); |
| 5662 | try { |
Hall Liu | 4fd771b | 2019-05-02 09:16:29 -0700 | [diff] [blame] | 5663 | if (channel <= 0) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5664 | return ""; |
| 5665 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5666 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5667 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5668 | new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone, |
| 5669 | null /* workSource */); |
| 5670 | if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5671 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5672 | // Append the returned status code to the end of the response payload. |
| 5673 | String s = Integer.toHexString( |
| 5674 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 5675 | if (response.payload != null) { |
| 5676 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 5677 | } |
| 5678 | return s; |
| 5679 | } finally { |
| 5680 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 5681 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5682 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5683 | |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5684 | @Override |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 5685 | public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla, |
| 5686 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5687 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5688 | mApp, subId, "iccTransmitApduBasicChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5689 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5690 | if (DBG) { |
| 5691 | log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" |
| 5692 | + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
| 5693 | } |
| 5694 | return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage, |
| 5695 | cla, command, p1, p2, p3, data); |
| 5696 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5697 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5698 | @Override |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5699 | public String iccTransmitApduBasicChannelByPort(int slotIndex, int portIndex, |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 5700 | 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] | 5701 | enforceModifyPermission(); |
| 5702 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 5703 | if (DBG) { |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5704 | log("iccTransmitApduBasicChannelByPort: slotIndex=" + slotIndex + " portIndex=" |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 5705 | + portIndex + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" |
| 5706 | + p2 + " p3=" + p3 + " data=" + data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5707 | } |
| 5708 | |
| 5709 | return iccTransmitApduBasicChannelWithPermission( |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5710 | getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), callingPackage, |
| 5711 | cla, command, p1, p2, p3, data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5712 | } |
| 5713 | |
| 5714 | // open APDU basic channel assuming the caller has sufficient permissions |
| 5715 | private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage, |
| 5716 | int cla, int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5717 | final long identity = Binder.clearCallingIdentity(); |
| 5718 | try { |
| 5719 | if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3 |
| 5720 | && TextUtils.equals(ISDR_AID, data)) { |
| 5721 | // Only allows LPA to select ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5722 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 5723 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5724 | if (bestComponent == null |
| 5725 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 5726 | loge("The calling package is not allowed to select ISD-R."); |
| 5727 | throw new SecurityException( |
| 5728 | "The calling package is not allowed to select ISD-R."); |
| 5729 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 5730 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 5731 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5732 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5733 | new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone, |
| 5734 | null /* workSource */); |
| 5735 | if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5736 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5737 | // Append the returned status code to the end of the response payload. |
| 5738 | String s = Integer.toHexString( |
| 5739 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 5740 | if (response.payload != null) { |
| 5741 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 5742 | } |
| 5743 | return s; |
| 5744 | } finally { |
| 5745 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 5746 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5747 | } |
| 5748 | |
| 5749 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5750 | 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] | 5751 | String filePath) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5752 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5753 | mApp, subId, "iccExchangeSimIO"); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5754 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5755 | final long identity = Binder.clearCallingIdentity(); |
| 5756 | try { |
| 5757 | if (DBG) { |
| 5758 | log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " |
| 5759 | + p1 + " " + p2 + " " + p3 + ":" + filePath); |
| 5760 | } |
| 5761 | |
| 5762 | IccIoResult response = |
| 5763 | (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO, |
| 5764 | new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath), |
| 5765 | subId); |
| 5766 | |
| 5767 | if (DBG) { |
| 5768 | log("Exchange SIM_IO [R]" + response); |
| 5769 | } |
| 5770 | |
| 5771 | byte[] result = null; |
| 5772 | int length = 2; |
| 5773 | if (response.payload != null) { |
| 5774 | length = 2 + response.payload.length; |
| 5775 | result = new byte[length]; |
| 5776 | System.arraycopy(response.payload, 0, result, 0, response.payload.length); |
| 5777 | } else { |
| 5778 | result = new byte[length]; |
| 5779 | } |
| 5780 | |
| 5781 | result[length - 1] = (byte) response.sw2; |
| 5782 | result[length - 2] = (byte) response.sw1; |
| 5783 | return result; |
| 5784 | } finally { |
| 5785 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5786 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5787 | } |
| 5788 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5789 | /** |
| 5790 | * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM) |
| 5791 | * on a particular subscription |
| 5792 | */ |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5793 | public String[] getForbiddenPlmns(int subId, int appType, String callingPackage, |
| 5794 | String callingFeatureId) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 5795 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5796 | mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 5797 | return null; |
| 5798 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5799 | |
| 5800 | final long identity = Binder.clearCallingIdentity(); |
| 5801 | try { |
| 5802 | if (appType != TelephonyManager.APPTYPE_USIM |
| 5803 | && appType != TelephonyManager.APPTYPE_SIM) { |
| 5804 | loge("getForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 5805 | return null; |
| 5806 | } |
| 5807 | Object response = sendRequest( |
| 5808 | CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId); |
| 5809 | if (response instanceof String[]) { |
| 5810 | return (String[]) response; |
| 5811 | } |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5812 | // Response is an Exception of some kind |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5813 | // which is signalled to the user as a NULL retval |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5814 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5815 | } finally { |
| 5816 | Binder.restoreCallingIdentity(identity); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5817 | } |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5818 | } |
| 5819 | |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5820 | /** |
| 5821 | * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular |
| 5822 | * subscription. |
| 5823 | * |
| 5824 | * @param subId the id of the subscription. |
| 5825 | * @param appType the uicc app type, must be USIM or SIM. |
| 5826 | * @param fplmns the Forbiden plmns list that needed to be written to the SIM. |
| 5827 | * @param callingPackage the op Package name. |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5828 | * @param callingFeatureId the feature in the package. |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5829 | * @return number of fplmns that is successfully written to the SIM. |
| 5830 | */ |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5831 | public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage, |
| 5832 | String callingFeatureId) { |
Jayachandran C | 5b0d75a | 2021-10-21 22:15:27 -0700 | [diff] [blame] | 5833 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5834 | mApp, subId, "setForbiddenPlmns"); |
| 5835 | |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5836 | if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) { |
| 5837 | loge("setForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 5838 | throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM"); |
| 5839 | } |
| 5840 | if (fplmns == null) { |
| 5841 | throw new IllegalArgumentException("Fplmn List provided is null"); |
| 5842 | } |
| 5843 | for (String fplmn : fplmns) { |
| 5844 | if (!CellIdentity.isValidPlmn(fplmn)) { |
| 5845 | throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn); |
| 5846 | } |
| 5847 | } |
| 5848 | final long identity = Binder.clearCallingIdentity(); |
| 5849 | try { |
| 5850 | Object response = sendRequest( |
| 5851 | CMD_SET_FORBIDDEN_PLMNS, |
| 5852 | new Pair<Integer, List<String>>(new Integer(appType), fplmns), |
| 5853 | subId); |
| 5854 | return (int) response; |
| 5855 | } finally { |
| 5856 | Binder.restoreCallingIdentity(identity); |
| 5857 | } |
| 5858 | } |
| 5859 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5860 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5861 | public String sendEnvelopeWithStatus(int subId, String content) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5862 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5863 | mApp, subId, "sendEnvelopeWithStatus"); |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5864 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5865 | final long identity = Binder.clearCallingIdentity(); |
| 5866 | try { |
| 5867 | IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId); |
| 5868 | if (response.payload == null) { |
| 5869 | return ""; |
| 5870 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5871 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5872 | // Append the returned status code to the end of the response payload. |
| 5873 | String s = Integer.toHexString( |
| 5874 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 5875 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 5876 | return s; |
| 5877 | } finally { |
| 5878 | Binder.restoreCallingIdentity(identity); |
| 5879 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5880 | } |
| 5881 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5882 | /** |
| 5883 | * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 5884 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 5885 | * |
| 5886 | * @param itemID the ID of the item to read |
| 5887 | * @return the NV item as a String, or null on error. |
| 5888 | */ |
| 5889 | @Override |
| 5890 | public String nvReadItem(int itemID) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5891 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5892 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5893 | mApp, getDefaultSubscription(), "nvReadItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5894 | |
| 5895 | final long identity = Binder.clearCallingIdentity(); |
| 5896 | try { |
| 5897 | if (DBG) log("nvReadItem: item " + itemID); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5898 | String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5899 | if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"'); |
| 5900 | return value; |
| 5901 | } finally { |
| 5902 | Binder.restoreCallingIdentity(identity); |
| 5903 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5904 | } |
| 5905 | |
| 5906 | /** |
| 5907 | * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 5908 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 5909 | * |
| 5910 | * @param itemID the ID of the item to read |
| 5911 | * @param itemValue the value to write, as a String |
| 5912 | * @return true on success; false on any failure |
| 5913 | */ |
| 5914 | @Override |
| 5915 | public boolean nvWriteItem(int itemID, String itemValue) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5916 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5917 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5918 | mApp, getDefaultSubscription(), "nvWriteItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5919 | |
| 5920 | final long identity = Binder.clearCallingIdentity(); |
| 5921 | try { |
| 5922 | if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"'); |
| 5923 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5924 | new Pair<Integer, String>(itemID, itemValue), workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5925 | if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail")); |
| 5926 | return success; |
| 5927 | } finally { |
| 5928 | Binder.restoreCallingIdentity(identity); |
| 5929 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5930 | } |
| 5931 | |
| 5932 | /** |
| 5933 | * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage. |
| 5934 | * Used for device configuration by some CDMA operators. |
| 5935 | * |
| 5936 | * @param preferredRoamingList byte array containing the new PRL |
| 5937 | * @return true on success; false on any failure |
| 5938 | */ |
| 5939 | @Override |
| 5940 | public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5941 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5942 | mApp, getDefaultSubscription(), "nvWriteCdmaPrl"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5943 | |
| 5944 | final long identity = Binder.clearCallingIdentity(); |
| 5945 | try { |
| 5946 | if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList)); |
| 5947 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList); |
| 5948 | if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail")); |
| 5949 | return success; |
| 5950 | } finally { |
| 5951 | Binder.restoreCallingIdentity(identity); |
| 5952 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5953 | } |
| 5954 | |
| 5955 | /** |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5956 | * 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] | 5957 | * Used for device configuration by some CDMA operators. |
| 5958 | * |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5959 | * @param slotIndex - device slot. |
| 5960 | * |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5961 | * @return true on success; false on any failure |
| 5962 | */ |
| 5963 | @Override |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5964 | public boolean resetModemConfig(int slotIndex) { |
| 5965 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5966 | if (phone != null) { |
| 5967 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5968 | mApp, phone.getSubId(), "resetModemConfig"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5969 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5970 | final long identity = Binder.clearCallingIdentity(); |
| 5971 | try { |
| 5972 | Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null); |
| 5973 | if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 5974 | return success; |
| 5975 | } finally { |
| 5976 | Binder.restoreCallingIdentity(identity); |
| 5977 | } |
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 | return false; |
| 5980 | } |
| 5981 | |
| 5982 | /** |
| 5983 | * Generate a radio modem reset. Used for device configuration by some CDMA operators. |
| 5984 | * |
| 5985 | * @param slotIndex - device slot. |
| 5986 | * |
| 5987 | * @return true on success; false on any failure |
| 5988 | */ |
| 5989 | @Override |
| 5990 | public boolean rebootModem(int slotIndex) { |
| 5991 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5992 | if (phone != null) { |
| 5993 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5994 | mApp, phone.getSubId(), "rebootModem"); |
| 5995 | |
| 5996 | final long identity = Binder.clearCallingIdentity(); |
| 5997 | try { |
| 5998 | Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null); |
| 5999 | if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail")); |
| 6000 | return success; |
| 6001 | } finally { |
| 6002 | Binder.restoreCallingIdentity(identity); |
| 6003 | } |
| 6004 | } |
| 6005 | return false; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 6006 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 6007 | |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 6008 | /** |
Grace Jia | aa2eb6b | 2020-01-09 16:26:08 -0800 | [diff] [blame] | 6009 | * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and |
| 6010 | * {@link #disableIms(int)}. |
| 6011 | * @param slotIndex device slot. |
| 6012 | */ |
| 6013 | public void resetIms(int slotIndex) { |
| 6014 | enforceModifyPermission(); |
| 6015 | |
| 6016 | final long identity = Binder.clearCallingIdentity(); |
| 6017 | try { |
| 6018 | if (mImsResolver == null) { |
| 6019 | // may happen if the does not support IMS. |
| 6020 | return; |
| 6021 | } |
Hyunho | a17ac7c | 2022-08-30 12:03:04 +0000 | [diff] [blame] | 6022 | mImsResolver.resetIms(slotIndex); |
Grace Jia | aa2eb6b | 2020-01-09 16:26:08 -0800 | [diff] [blame] | 6023 | } finally { |
| 6024 | Binder.restoreCallingIdentity(identity); |
| 6025 | } |
| 6026 | } |
| 6027 | |
| 6028 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6029 | * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability |
| 6030 | * status updates, if not already enabled. |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 6031 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6032 | public void enableIms(int slotId) { |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 6033 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6034 | |
| 6035 | final long identity = Binder.clearCallingIdentity(); |
| 6036 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6037 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6038 | // may happen if the device does not support IMS. |
| 6039 | return; |
| 6040 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6041 | mImsResolver.enableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6042 | } finally { |
| 6043 | Binder.restoreCallingIdentity(identity); |
| 6044 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 6045 | } |
| 6046 | |
| 6047 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6048 | * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature |
| 6049 | * status updates to disabled. |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 6050 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6051 | public void disableIms(int slotId) { |
| 6052 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6053 | |
| 6054 | final long identity = Binder.clearCallingIdentity(); |
| 6055 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6056 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6057 | // may happen if the device does not support IMS. |
| 6058 | return; |
| 6059 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6060 | mImsResolver.disableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6061 | } finally { |
| 6062 | Binder.restoreCallingIdentity(identity); |
| 6063 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6064 | } |
| 6065 | |
| 6066 | /** |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 6067 | * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback |
| 6068 | * callback. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6069 | */ |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 6070 | @Override |
Brad Ebinger | f6aca00 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 6071 | public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) { |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 6072 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6073 | |
| 6074 | final long identity = Binder.clearCallingIdentity(); |
| 6075 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6076 | if (mImsResolver == null) { |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 6077 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 6078 | "Device does not support IMS"); |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6079 | } |
Brad Ebinger | f6aca00 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 6080 | mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6081 | } finally { |
| 6082 | Binder.restoreCallingIdentity(identity); |
| 6083 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 6084 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 6085 | /** |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 6086 | * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature. |
| 6087 | */ |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 6088 | @Override |
| 6089 | public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) { |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 6090 | enforceModifyPermission(); |
| 6091 | |
| 6092 | final long identity = Binder.clearCallingIdentity(); |
| 6093 | try { |
| 6094 | if (mImsResolver == null) return; |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 6095 | mImsResolver.unregisterImsFeatureCallback(callback); |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 6096 | } finally { |
| 6097 | Binder.restoreCallingIdentity(identity); |
| 6098 | } |
| 6099 | } |
| 6100 | |
| 6101 | /** |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 6102 | * Returns the {@link IImsRegistration} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6103 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 6104 | */ |
| 6105 | public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException { |
| 6106 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6107 | |
| 6108 | final long identity = Binder.clearCallingIdentity(); |
| 6109 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6110 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6111 | // may happen if the device does not support IMS. |
| 6112 | return null; |
| 6113 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6114 | return mImsResolver.getImsRegistration(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6115 | } finally { |
| 6116 | Binder.restoreCallingIdentity(identity); |
| 6117 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 6118 | } |
| 6119 | |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6120 | /** |
| 6121 | * Returns the {@link IImsConfig} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6122 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6123 | */ |
| 6124 | public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException { |
| 6125 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6126 | |
| 6127 | final long identity = Binder.clearCallingIdentity(); |
| 6128 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6129 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6130 | // may happen if the device does not support IMS. |
| 6131 | return null; |
| 6132 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6133 | return mImsResolver.getImsConfig(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6134 | } finally { |
| 6135 | Binder.restoreCallingIdentity(identity); |
| 6136 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6137 | } |
| 6138 | |
Brad Ebinger | 884c07b | 2018-02-15 16:17:40 -0800 | [diff] [blame] | 6139 | /** |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6140 | * Sets the ImsService Package Name that Telephony will bind to. |
| 6141 | * |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6142 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 6143 | * @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] | 6144 | * ImsService is the device default ImsService. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6145 | * @param featureTypes An integer array of feature types associated with a packageName. |
| 6146 | * @param packageName The name of the package that the current configuration will be replaced |
| 6147 | * with. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6148 | * @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] | 6149 | */ |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6150 | public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService, |
| 6151 | int[] featureTypes, String packageName) { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6152 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 6153 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
Jack Yu | 00ece8c | 2022-11-19 22:29:12 -0800 | [diff] [blame] | 6154 | SubscriptionManager.getSubscriptionId(slotIndex), "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 6155 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6156 | final long identity = Binder.clearCallingIdentity(); |
| 6157 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6158 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6159 | // may happen if the device does not support IMS. |
| 6160 | return false; |
| 6161 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6162 | Map<Integer, String> featureConfig = new HashMap<>(); |
| 6163 | for (int featureType : featureTypes) { |
| 6164 | featureConfig.put(featureType, packageName); |
| 6165 | } |
| 6166 | return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService, |
| 6167 | featureConfig); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6168 | } finally { |
| 6169 | Binder.restoreCallingIdentity(identity); |
| 6170 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6171 | } |
| 6172 | |
| 6173 | /** |
Brad Ebinger | 999d330 | 2020-11-25 14:31:39 -0800 | [diff] [blame] | 6174 | * Clears any carrier ImsService overrides for the slot index specified that were previously |
| 6175 | * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}. |
| 6176 | * |
| 6177 | * This should only be used for testing. |
| 6178 | * |
| 6179 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 6180 | * @return true if clearing the carrier ImsService override succeeded or false if it did not. |
| 6181 | */ |
| 6182 | @Override |
| 6183 | public boolean clearCarrierImsServiceOverride(int slotIndex) { |
Brad Ebinger | 999d330 | 2020-11-25 14:31:39 -0800 | [diff] [blame] | 6184 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 6185 | "clearCarrierImsServiceOverride"); |
| 6186 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
Jack Yu | 00ece8c | 2022-11-19 22:29:12 -0800 | [diff] [blame] | 6187 | SubscriptionManager.getSubscriptionId(slotIndex), "clearCarrierImsServiceOverride"); |
Brad Ebinger | 999d330 | 2020-11-25 14:31:39 -0800 | [diff] [blame] | 6188 | |
| 6189 | final long identity = Binder.clearCallingIdentity(); |
| 6190 | try { |
| 6191 | if (mImsResolver == null) { |
| 6192 | // may happen if the device does not support IMS. |
| 6193 | return false; |
| 6194 | } |
| 6195 | return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex); |
| 6196 | } finally { |
| 6197 | Binder.restoreCallingIdentity(identity); |
| 6198 | } |
| 6199 | } |
| 6200 | |
| 6201 | /** |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6202 | * Return the package name of the currently bound ImsService. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6203 | * |
| 6204 | * @param slotId The slot that the ImsService is associated with. |
| 6205 | * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is |
| 6206 | * the device default. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6207 | * @param featureType The feature associated with the queried configuration. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6208 | * @return the package name of the ImsService configuration. |
| 6209 | */ |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6210 | public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService, |
| 6211 | @ImsFeature.FeatureType int featureType) { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6212 | TelephonyPermissions |
Jack Yu | 00ece8c | 2022-11-19 22:29:12 -0800 | [diff] [blame] | 6213 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(mApp, |
| 6214 | SubscriptionManager.getSubscriptionId(slotId), "getBoundImsServicePackage"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 6215 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6216 | final long identity = Binder.clearCallingIdentity(); |
| 6217 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6218 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6219 | // may happen if the device does not support IMS. |
| 6220 | return ""; |
| 6221 | } |
Brad Ebinger | a80c331 | 2019-12-02 10:59:39 -0800 | [diff] [blame] | 6222 | // TODO: change API to query RCS separately. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6223 | return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService, |
| 6224 | featureType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6225 | } finally { |
| 6226 | Binder.restoreCallingIdentity(identity); |
| 6227 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6228 | } |
| 6229 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6230 | /** |
| 6231 | * Get the MmTelFeature state associated with the requested subscription id. |
| 6232 | * @param subId The subscription that the MmTelFeature is associated with. |
| 6233 | * @param callback A callback with an integer containing the |
| 6234 | * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature. |
| 6235 | */ |
| 6236 | @Override |
| 6237 | public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) { |
| 6238 | enforceReadPrivilegedPermission("getImsMmTelFeatureState"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 6239 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 6240 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 6241 | "IMS not available on device."); |
| 6242 | } |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6243 | final long token = Binder.clearCallingIdentity(); |
| 6244 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 6245 | int slotId = getSlotIndex(subId); |
| 6246 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 6247 | Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '" |
| 6248 | + subId + "'"); |
| 6249 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 6250 | } |
| 6251 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 6252 | ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> { |
| 6253 | try { |
| 6254 | callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger); |
| 6255 | } catch (RemoteException e) { |
| 6256 | Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. " |
| 6257 | + "Ignore"); |
| 6258 | } |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6259 | }); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 6260 | } catch (ImsException e) { |
| 6261 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6262 | } finally { |
| 6263 | Binder.restoreCallingIdentity(token); |
| 6264 | } |
| 6265 | } |
| 6266 | |
Daniel Bright | bb5840b | 2021-01-12 15:48:18 -0800 | [diff] [blame] | 6267 | /** |
| 6268 | * Sets the ims registration state on all valid {@link Phone}s. |
| 6269 | */ |
| 6270 | public void setImsRegistrationState(final boolean registered) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 6271 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6272 | |
| 6273 | final long identity = Binder.clearCallingIdentity(); |
| 6274 | try { |
Daniel Bright | bb5840b | 2021-01-12 15:48:18 -0800 | [diff] [blame] | 6275 | // NOTE: Before S, this method only set the default phone. |
| 6276 | for (final Phone phone : PhoneFactory.getPhones()) { |
| 6277 | if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) { |
| 6278 | phone.setImsRegistrationState(registered); |
| 6279 | } |
| 6280 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6281 | } finally { |
| 6282 | Binder.restoreCallingIdentity(identity); |
| 6283 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 6284 | } |
| 6285 | |
| 6286 | /** |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 6287 | * Set the network selection mode to automatic. |
| 6288 | * |
| 6289 | */ |
| 6290 | @Override |
| 6291 | public void setNetworkSelectionModeAutomatic(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6292 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6293 | mApp, subId, "setNetworkSelectionModeAutomatic"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6294 | |
| 6295 | final long identity = Binder.clearCallingIdentity(); |
| 6296 | try { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 6297 | if (!isActiveSubscription(subId)) { |
| 6298 | return; |
| 6299 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6300 | if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId); |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 6301 | sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId, |
| 6302 | SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6303 | } finally { |
| 6304 | Binder.restoreCallingIdentity(identity); |
| 6305 | } |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 6306 | } |
| 6307 | |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 6308 | /** |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6309 | * Ask the radio to connect to the input network and change selection mode to manual. |
| 6310 | * |
| 6311 | * @param subId the id of the subscription. |
| 6312 | * @param operatorInfo the operator information, included the PLMN, long name and short name of |
| 6313 | * the operator to attach to. |
| 6314 | * @param persistSelection whether the selection will persist until reboot. If true, only allows |
| 6315 | * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume |
| 6316 | * normal network selection next time. |
| 6317 | * @return {@code true} on success; {@code true} on any failure. |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6318 | */ |
| 6319 | @Override |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6320 | public boolean setNetworkSelectionModeManual( |
| 6321 | int subId, OperatorInfo operatorInfo, boolean persistSelection) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6322 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6323 | mApp, subId, "setNetworkSelectionModeManual"); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 6324 | |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 6325 | final long identity = Binder.clearCallingIdentity(); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 6326 | if (!isActiveSubscription(subId)) { |
| 6327 | return false; |
| 6328 | } |
| 6329 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6330 | try { |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6331 | ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6332 | persistSelection); |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6333 | if (DBG) { |
| 6334 | log("setNetworkSelectionModeManual: subId: " + subId |
| 6335 | + " operator: " + operatorInfo); |
| 6336 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6337 | return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId); |
| 6338 | } finally { |
| 6339 | Binder.restoreCallingIdentity(identity); |
| 6340 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6341 | } |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6342 | /** |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6343 | * Get the manual network selection |
| 6344 | * |
| 6345 | * @param subId the id of the subscription. |
| 6346 | * |
| 6347 | * @return the previously saved user selected PLMN |
| 6348 | */ |
| 6349 | @Override |
| 6350 | public String getManualNetworkSelectionPlmn(int subId) { |
| 6351 | TelephonyPermissions |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6352 | .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 6353 | mApp, subId, "getManualNetworkSelectionPlmn"); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6354 | |
| 6355 | final long identity = Binder.clearCallingIdentity(); |
| 6356 | try { |
| 6357 | if (!isActiveSubscription(subId)) { |
shilu | fa1c259 | 2020-03-10 10:59:43 -0700 | [diff] [blame] | 6358 | throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6359 | } |
| 6360 | |
| 6361 | final Phone phone = getPhone(subId); |
| 6362 | if (phone == null) { |
shilu | fa1c259 | 2020-03-10 10:59:43 -0700 | [diff] [blame] | 6363 | throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6364 | } |
| 6365 | OperatorInfo networkSelection = phone.getSavedNetworkSelection(); |
| 6366 | return TextUtils.isEmpty(networkSelection.getOperatorNumeric()) |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6367 | ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric(); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6368 | } finally { |
| 6369 | Binder.restoreCallingIdentity(identity); |
| 6370 | } |
| 6371 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6372 | |
| 6373 | /** |
| 6374 | * Scans for available networks. |
| 6375 | */ |
| 6376 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6377 | public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage, |
| 6378 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6379 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6380 | mApp, subId, "getCellNetworkScanResults"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6381 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 6382 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 6383 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 6384 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6385 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6386 | .setCallingPid(Binder.getCallingPid()) |
| 6387 | .setCallingUid(Binder.getCallingUid()) |
| 6388 | .setMethod("getCellNetworkScanResults") |
| 6389 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
Hall Liu | c4a3e42 | 2020-05-26 17:18:03 -0700 | [diff] [blame] | 6390 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 6391 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6392 | .build()); |
| 6393 | switch (locationResult) { |
| 6394 | case DENIED_HARD: |
| 6395 | throw new SecurityException("Not allowed to access scan results -- location"); |
| 6396 | case DENIED_SOFT: |
| 6397 | return null; |
| 6398 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6399 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6400 | long identity = Binder.clearCallingIdentity(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6401 | try { |
| 6402 | if (DBG) log("getCellNetworkScanResults: subId " + subId); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6403 | return (CellNetworkScanResult) sendRequest( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6404 | CMD_PERFORM_NETWORK_SCAN, null, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6405 | } finally { |
| 6406 | Binder.restoreCallingIdentity(identity); |
| 6407 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6408 | } |
| 6409 | |
| 6410 | /** |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6411 | * Get the call forwarding info, given the call forwarding reason. |
| 6412 | */ |
| 6413 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6414 | public void getCallForwarding(int subId, int callForwardingReason, |
| 6415 | ICallForwardingInfoCallback callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6416 | enforceReadPrivilegedPermission("getCallForwarding"); |
| 6417 | long identity = Binder.clearCallingIdentity(); |
| 6418 | try { |
| 6419 | if (DBG) { |
| 6420 | log("getCallForwarding: subId " + subId |
| 6421 | + " callForwardingReason" + callForwardingReason); |
| 6422 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6423 | |
| 6424 | Phone phone = getPhone(subId); |
| 6425 | if (phone == null) { |
| 6426 | try { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 6427 | callback.onError( |
| 6428 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6429 | } catch (RemoteException e) { |
| 6430 | // ignore |
| 6431 | } |
| 6432 | return; |
| 6433 | } |
| 6434 | |
| 6435 | Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create( |
| 6436 | callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() { |
| 6437 | @Override |
| 6438 | public void onCallForwardingInfoAvailable(CallForwardingInfo info) { |
| 6439 | try { |
| 6440 | callback.onCallForwardingInfoAvailable(info); |
| 6441 | } catch (RemoteException e) { |
| 6442 | // ignore |
| 6443 | } |
| 6444 | } |
| 6445 | |
| 6446 | @Override |
| 6447 | public void onError(int error) { |
| 6448 | try { |
| 6449 | callback.onError(error); |
| 6450 | } catch (RemoteException e) { |
| 6451 | // ignore |
| 6452 | } |
| 6453 | } |
| 6454 | }); |
| 6455 | sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6456 | } finally { |
| 6457 | Binder.restoreCallingIdentity(identity); |
| 6458 | } |
| 6459 | } |
| 6460 | |
| 6461 | /** |
| 6462 | * Sets the voice call forwarding info including status (enable/disable), call forwarding |
| 6463 | * reason, the number to forward, and the timeout before the forwarding is attempted. |
| 6464 | */ |
| 6465 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6466 | public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo, |
| 6467 | IIntegerConsumer callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6468 | enforceModifyPermission(); |
| 6469 | long identity = Binder.clearCallingIdentity(); |
| 6470 | try { |
| 6471 | if (DBG) { |
| 6472 | log("setCallForwarding: subId " + subId |
| 6473 | + " callForwardingInfo" + callForwardingInfo); |
| 6474 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6475 | |
| 6476 | Phone phone = getPhone(subId); |
| 6477 | if (phone == null) { |
| 6478 | try { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 6479 | callback.accept( |
| 6480 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6481 | } catch (RemoteException e) { |
| 6482 | // ignore |
| 6483 | } |
| 6484 | return; |
| 6485 | } |
| 6486 | |
| 6487 | Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo, |
| 6488 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 6489 | |
| 6490 | sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6491 | } finally { |
| 6492 | Binder.restoreCallingIdentity(identity); |
| 6493 | } |
| 6494 | } |
| 6495 | |
| 6496 | /** |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6497 | * Get the call waiting status for a subId. |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6498 | */ |
| 6499 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6500 | public void getCallWaitingStatus(int subId, IIntegerConsumer callback) { |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6501 | enforceReadPrivilegedPermission("getCallWaitingStatus"); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6502 | long identity = Binder.clearCallingIdentity(); |
| 6503 | try { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6504 | Phone phone = getPhone(subId); |
| 6505 | if (phone == null) { |
| 6506 | try { |
| 6507 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 6508 | } catch (RemoteException e) { |
| 6509 | // ignore |
| 6510 | } |
| 6511 | return; |
| 6512 | } |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6513 | CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext()); |
| 6514 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 6515 | boolean requireUssd = c.getBoolean( |
| 6516 | CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6517 | |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6518 | if (DBG) log("getCallWaitingStatus: subId " + subId); |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6519 | if (requireUssd) { |
| 6520 | CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(), |
| 6521 | getSubscriptionCarrierId(subId)); |
| 6522 | String newUssdCommand = ""; |
| 6523 | try { |
| 6524 | newUssdCommand = carrierXmlParser.getFeature( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6525 | CarrierXmlParser.FEATURE_CALL_WAITING) |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6526 | .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null); |
| 6527 | } catch (NullPointerException e) { |
| 6528 | loge("Failed to generate USSD number" + e); |
| 6529 | } |
| 6530 | ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver( |
| 6531 | mMainThreadHandler, callback, carrierXmlParser, |
| 6532 | CarrierXmlParser.SsEntry.SSAction.QUERY); |
| 6533 | final String ussdCommand = newUssdCommand; |
| 6534 | Executors.newSingleThreadExecutor().execute(() -> { |
| 6535 | handleUssdRequest(subId, ussdCommand, wrappedCallback); |
| 6536 | }); |
| 6537 | } else { |
| 6538 | Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException( |
| 6539 | callback::accept); |
| 6540 | sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null); |
| 6541 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6542 | } finally { |
| 6543 | Binder.restoreCallingIdentity(identity); |
| 6544 | } |
| 6545 | } |
| 6546 | |
| 6547 | /** |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6548 | * Sets whether call waiting is enabled for a given subId. |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6549 | */ |
| 6550 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6551 | public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6552 | enforceModifyPermission(); |
| 6553 | long identity = Binder.clearCallingIdentity(); |
| 6554 | try { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6555 | if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable); |
| 6556 | |
| 6557 | Phone phone = getPhone(subId); |
| 6558 | if (phone == null) { |
| 6559 | try { |
| 6560 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 6561 | } catch (RemoteException e) { |
| 6562 | // ignore |
| 6563 | } |
| 6564 | return; |
| 6565 | } |
| 6566 | |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6567 | CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext()); |
| 6568 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 6569 | boolean requireUssd = c.getBoolean( |
| 6570 | CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6571 | |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6572 | if (DBG) log("getCallWaitingStatus: subId " + subId); |
| 6573 | if (requireUssd) { |
| 6574 | CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(), |
| 6575 | getSubscriptionCarrierId(subId)); |
| 6576 | CarrierXmlParser.SsEntry.SSAction ssAction = |
| 6577 | enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE |
| 6578 | : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE; |
| 6579 | String newUssdCommand = ""; |
| 6580 | try { |
| 6581 | newUssdCommand = carrierXmlParser.getFeature( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6582 | CarrierXmlParser.FEATURE_CALL_WAITING) |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6583 | .makeCommand(ssAction, null); |
| 6584 | } catch (NullPointerException e) { |
| 6585 | loge("Failed to generate USSD number" + e); |
| 6586 | } |
| 6587 | ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver( |
| 6588 | mMainThreadHandler, callback, carrierXmlParser, ssAction); |
| 6589 | final String ussdCommand = newUssdCommand; |
| 6590 | Executors.newSingleThreadExecutor().execute(() -> { |
| 6591 | handleUssdRequest(subId, ussdCommand, wrappedCallback); |
| 6592 | }); |
| 6593 | } else { |
| 6594 | Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable, |
| 6595 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 6596 | |
| 6597 | sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null); |
| 6598 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6599 | } finally { |
| 6600 | Binder.restoreCallingIdentity(identity); |
| 6601 | } |
| 6602 | } |
| 6603 | |
| 6604 | /** |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 6605 | * Starts a new network scan and returns the id of this scan. |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6606 | * |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 6607 | * @param subId id of the subscription |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 6608 | * @param renounceFineLocationAccess Set this to true if the caller would not like to receive |
| 6609 | * location related information which will be sent if the caller already possess |
| 6610 | * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 6611 | * @param request contains the radio access networks with bands/channels to scan |
| 6612 | * @param messenger callback messenger for scan results or errors |
| 6613 | * @param binder for the purpose of auto clean when the user thread crashes |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6614 | * @return the id of the requested scan which can be used to stop the scan. |
| 6615 | */ |
| 6616 | @Override |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 6617 | public int requestNetworkScan(int subId, boolean renounceFineLocationAccess, |
| 6618 | NetworkScanRequest request, Messenger messenger, |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6619 | IBinder binder, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6620 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6621 | mApp, subId, "requestNetworkScan"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6622 | LocationAccessPolicy.LocationPermissionResult locationResult = |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 6623 | LocationAccessPolicy.LocationPermissionResult.DENIED_HARD; |
| 6624 | if (!renounceFineLocationAccess) { |
| 6625 | locationResult = LocationAccessPolicy.checkLocationPermission(mApp, |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6626 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 6627 | .setCallingPackage(callingPackage) |
| 6628 | .setCallingFeatureId(callingFeatureId) |
| 6629 | .setCallingPid(Binder.getCallingPid()) |
| 6630 | .setCallingUid(Binder.getCallingUid()) |
| 6631 | .setMethod("requestNetworkScan") |
| 6632 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 6633 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 6634 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 6635 | .build()); |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 6636 | } |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6637 | if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) { |
Nathan Harold | 1c11dba | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 6638 | SecurityException e = checkNetworkRequestForSanitizedLocationAccess( |
| 6639 | request, subId, callingPackage); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6640 | if (e != null) { |
| 6641 | if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) { |
| 6642 | throw e; |
| 6643 | } else { |
Hall Liu | 0e5abaf | 2019-04-04 01:25:30 -0700 | [diff] [blame] | 6644 | loge(e.getMessage()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6645 | return TelephonyScanManager.INVALID_SCAN_ID; |
| 6646 | } |
| 6647 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6648 | } |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6649 | int callingUid = Binder.getCallingUid(); |
| 6650 | int callingPid = Binder.getCallingPid(); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 6651 | final long identity = Binder.clearCallingIdentity(); |
| 6652 | try { |
| 6653 | return mNetworkScanRequestTracker.startNetworkScan( |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 6654 | renounceFineLocationAccess, request, messenger, binder, |
| 6655 | getPhoneFromSubIdOrDefault(subId), |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6656 | callingUid, callingPid, callingPackage); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 6657 | } finally { |
| 6658 | Binder.restoreCallingIdentity(identity); |
| 6659 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6660 | } |
| 6661 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6662 | private SecurityException checkNetworkRequestForSanitizedLocationAccess( |
Nathan Harold | 1c11dba | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 6663 | NetworkScanRequest request, int subId, String callingPackage) { |
Rambo Wang | 3dee30a | 2022-10-20 16:52:29 +0000 | [diff] [blame] | 6664 | boolean hasCarrierPriv; |
| 6665 | final long identity = Binder.clearCallingIdentity(); |
| 6666 | try { |
| 6667 | hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage) |
| 6668 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 6669 | } finally { |
| 6670 | Binder.restoreCallingIdentity(identity); |
| 6671 | } |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 6672 | boolean hasNetworkScanPermission = |
| 6673 | mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN) |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6674 | == PERMISSION_GRANTED; |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 6675 | |
| 6676 | if (!hasCarrierPriv && !hasNetworkScanPermission) { |
| 6677 | return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed" |
| 6678 | + " for network scans without location access."); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6679 | } |
| 6680 | |
| 6681 | if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) { |
| 6682 | for (RadioAccessSpecifier ras : request.getSpecifiers()) { |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6683 | if (ras.getChannels() != null && ras.getChannels().length > 0) { |
| 6684 | return new SecurityException("Specific channels must not be" |
| 6685 | + " scanned without location access."); |
| 6686 | } |
| 6687 | } |
| 6688 | } |
| 6689 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6690 | return null; |
| 6691 | } |
| 6692 | |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6693 | /** |
| 6694 | * Stops an existing network scan with the given scanId. |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 6695 | * |
| 6696 | * @param subId id of the subscription |
| 6697 | * @param scanId id of the scan that needs to be stopped |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6698 | */ |
| 6699 | @Override |
| 6700 | public void stopNetworkScan(int subId, int scanId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6701 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6702 | mApp, subId, "stopNetworkScan"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6703 | |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6704 | int callingUid = Binder.getCallingUid(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6705 | final long identity = Binder.clearCallingIdentity(); |
| 6706 | try { |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6707 | mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6708 | } finally { |
| 6709 | Binder.restoreCallingIdentity(identity); |
| 6710 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6711 | } |
| 6712 | |
| 6713 | /** |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6714 | * Get the allowed network types bitmask. |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 6715 | * |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6716 | * @return the allowed network types bitmask, defined in RILConstants.java. |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 6717 | */ |
| 6718 | @Override |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6719 | public int getAllowedNetworkTypesBitmask(int subId) { |
Pengquan Meng | a4009cb | 2018-12-20 11:00:24 -0800 | [diff] [blame] | 6720 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 6721 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6722 | mApp, subId, "getAllowedNetworkTypesBitmask"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6723 | |
| 6724 | final long identity = Binder.clearCallingIdentity(); |
| 6725 | try { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6726 | if (DBG) log("getAllowedNetworkTypesBitmask"); |
| 6727 | int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId); |
| 6728 | int networkTypesBitmask = (result != null ? result[0] : -1); |
| 6729 | if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask); |
| 6730 | return networkTypesBitmask; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6731 | } finally { |
| 6732 | Binder.restoreCallingIdentity(identity); |
| 6733 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 6734 | } |
| 6735 | |
| 6736 | /** |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6737 | * Get the allowed network types for certain reason. |
| 6738 | * |
| 6739 | * @param subId the id of the subscription. |
| 6740 | * @param reason the reason the allowed network type change is taking place |
| 6741 | * @return the allowed network types. |
| 6742 | */ |
| 6743 | @Override |
| 6744 | public long getAllowedNetworkTypesForReason(int subId, |
| 6745 | @TelephonyManager.AllowedNetworkTypesReason int reason) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 6746 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 6747 | mApp, subId, "getAllowedNetworkTypesForReason"); |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6748 | final long identity = Binder.clearCallingIdentity(); |
| 6749 | try { |
Jack Yu | 7247ac8 | 2023-03-02 23:52:10 -0800 | [diff] [blame] | 6750 | return getPhoneFromSubIdOrDefault(subId).getAllowedNetworkTypes(reason); |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6751 | } finally { |
| 6752 | Binder.restoreCallingIdentity(identity); |
| 6753 | } |
| 6754 | } |
| 6755 | |
| 6756 | /** |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6757 | * Enable/Disable E-UTRA-NR Dual Connectivity |
| 6758 | * @param subId subscription id of the sim card |
| 6759 | * @param nrDualConnectivityState expected NR dual connectivity state |
| 6760 | * This can be passed following states |
| 6761 | * <ol> |
| 6762 | * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE} |
| 6763 | * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE} |
| 6764 | * <li>Disable NR dual connectivity and force secondary cell to be released |
| 6765 | * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE} |
| 6766 | * </ol> |
| 6767 | * @return operation result. |
| 6768 | */ |
| 6769 | @Override |
| 6770 | public int setNrDualConnectivityState(int subId, |
| 6771 | @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) { |
| 6772 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6773 | mApp, subId, "enableNRDualConnectivity"); |
Sooraj Sasindran | 0e4e00a | 2021-03-16 18:02:32 -0700 | [diff] [blame] | 6774 | if (!isRadioInterfaceCapabilitySupported( |
Sooraj Sasindran | dfd595b | 2021-03-11 17:38:13 -0800 | [diff] [blame] | 6775 | TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) { |
| 6776 | return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED; |
| 6777 | } |
| 6778 | |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6779 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 6780 | final long identity = Binder.clearCallingIdentity(); |
| 6781 | try { |
| 6782 | int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY, |
| 6783 | nrDualConnectivityState, subId, |
| 6784 | workSource); |
| 6785 | if (DBG) log("enableNRDualConnectivity result: " + result); |
| 6786 | return result; |
| 6787 | } finally { |
| 6788 | Binder.restoreCallingIdentity(identity); |
| 6789 | } |
| 6790 | } |
| 6791 | |
| 6792 | /** |
| 6793 | * Is E-UTRA-NR Dual Connectivity enabled |
| 6794 | * @return true if dual connectivity is enabled else false |
| 6795 | */ |
| 6796 | @Override |
| 6797 | public boolean isNrDualConnectivityEnabled(int subId) { |
| 6798 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 6799 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6800 | mApp, subId, "isNRDualConnectivityEnabled"); |
Sooraj Sasindran | 0e4e00a | 2021-03-16 18:02:32 -0700 | [diff] [blame] | 6801 | if (!isRadioInterfaceCapabilitySupported( |
Sooraj Sasindran | dfd595b | 2021-03-11 17:38:13 -0800 | [diff] [blame] | 6802 | TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) { |
| 6803 | return false; |
| 6804 | } |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6805 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 6806 | final long identity = Binder.clearCallingIdentity(); |
| 6807 | try { |
| 6808 | boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED, |
| 6809 | null, subId, workSource); |
| 6810 | if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled); |
| 6811 | return isEnabled; |
| 6812 | } finally { |
| 6813 | Binder.restoreCallingIdentity(identity); |
| 6814 | } |
| 6815 | } |
| 6816 | |
| 6817 | /** |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6818 | * Set the allowed network types of the device and |
| 6819 | * provide the reason triggering the allowed network change. |
| 6820 | * |
| 6821 | * @param subId the id of the subscription. |
| 6822 | * @param reason the reason the allowed network type change is taking place |
| 6823 | * @param allowedNetworkTypes the allowed network types. |
| 6824 | * @return true on success; false on any failure. |
| 6825 | */ |
| 6826 | @Override |
| 6827 | public boolean setAllowedNetworkTypesForReason(int subId, |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6828 | @TelephonyManager.AllowedNetworkTypesReason int reason, |
| 6829 | @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) { |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6830 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6831 | mApp, subId, "setAllowedNetworkTypesForReason"); |
Gil Cukierman | 1d3d375 | 2022-10-03 21:31:33 +0000 | [diff] [blame] | 6832 | // If the caller only has carrier privileges, then they should not be able to override |
| 6833 | // any network types which were set for security reasons. |
| 6834 | if (mApp.checkCallingOrSelfPermission(Manifest.permission.MODIFY_PHONE_STATE) |
| 6835 | != PERMISSION_GRANTED |
Gil Cukierman | 2a8f48b | 2023-01-26 20:26:20 +0000 | [diff] [blame] | 6836 | && reason == TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_ENABLE_2G) { |
Gil Cukierman | 1d3d375 | 2022-10-03 21:31:33 +0000 | [diff] [blame] | 6837 | throw new SecurityException( |
| 6838 | "setAllowedNetworkTypesForReason cannot be called with carrier privileges for" |
Gil Cukierman | 2a8f48b | 2023-01-26 20:26:20 +0000 | [diff] [blame] | 6839 | + " reason " + reason); |
Gil Cukierman | 1d3d375 | 2022-10-03 21:31:33 +0000 | [diff] [blame] | 6840 | } |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6841 | if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) { |
Jack Yu | 5b49433 | 2023-01-23 18:18:04 +0000 | [diff] [blame] | 6842 | loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason); |
SongFerngWang | 7ffc273 | 2021-04-15 19:46:33 +0800 | [diff] [blame] | 6843 | return false; |
| 6844 | } |
| 6845 | if (!SubscriptionManager.isUsableSubscriptionId(subId)) { |
| 6846 | loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId); |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6847 | return false; |
| 6848 | } |
| 6849 | |
Jack Yu | 5b49433 | 2023-01-23 18:18:04 +0000 | [diff] [blame] | 6850 | log("setAllowedNetworkTypesForReason: subId=" + subId + ", reason=" + reason + " value: " |
| 6851 | + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes)); |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 6852 | |
Jack Yu | e37dd26 | 2022-12-16 11:53:37 -0800 | [diff] [blame] | 6853 | Phone phone = getPhone(subId); |
| 6854 | if (phone == null) { |
| 6855 | return false; |
| 6856 | } |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 6857 | |
Jack Yu | e37dd26 | 2022-12-16 11:53:37 -0800 | [diff] [blame] | 6858 | if (allowedNetworkTypes == phone.getAllowedNetworkTypes(reason)) { |
Jack Yu | 5b49433 | 2023-01-23 18:18:04 +0000 | [diff] [blame] | 6859 | log("setAllowedNetworkTypesForReason: " + reason + "does not change value"); |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 6860 | return true; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6861 | } |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 6862 | |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6863 | final long identity = Binder.clearCallingIdentity(); |
| 6864 | try { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6865 | Boolean success = (Boolean) sendRequest( |
| 6866 | CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON, |
| 6867 | new Pair<Integer, Long>(reason, allowedNetworkTypes), subId); |
| 6868 | |
| 6869 | if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail")); |
| 6870 | return success; |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6871 | } finally { |
| 6872 | Binder.restoreCallingIdentity(identity); |
| 6873 | } |
| 6874 | } |
| 6875 | |
| 6876 | /** |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6877 | * Check whether DUN APN is required for tethering with subId. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6878 | * |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6879 | * @param subId the id of the subscription to require tethering. |
Amit Mahajan | fe58cdf | 2017-07-11 12:01:53 -0700 | [diff] [blame] | 6880 | * @return {@code true} if DUN APN is required for tethering. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6881 | * @hide |
| 6882 | */ |
| 6883 | @Override |
SongFerngWang | f08d812 | 2019-11-15 14:58:44 +0800 | [diff] [blame] | 6884 | public boolean isTetheringApnRequiredForSubscriber(int subId) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6885 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6886 | final long identity = Binder.clearCallingIdentity(); |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6887 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6888 | try { |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6889 | if (phone != null) { |
| 6890 | return phone.hasMatchedTetherApnSetting(); |
| 6891 | } else { |
| 6892 | return false; |
| 6893 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6894 | } finally { |
| 6895 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6896 | } |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6897 | } |
| 6898 | |
| 6899 | /** |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6900 | * Get the user enabled state of Mobile Data. |
| 6901 | * |
| 6902 | * TODO: remove and use isUserDataEnabled. |
| 6903 | * This can't be removed now because some vendor codes |
| 6904 | * calls through ITelephony directly while they should |
| 6905 | * use TelephonyManager. |
| 6906 | * |
| 6907 | * @return true on enabled |
| 6908 | */ |
| 6909 | @Override |
| 6910 | public boolean getDataEnabled(int subId) { |
| 6911 | return isUserDataEnabled(subId); |
| 6912 | } |
| 6913 | |
| 6914 | /** |
| 6915 | * Get whether mobile data is enabled per user setting. |
| 6916 | * |
| 6917 | * There are other factors deciding whether mobile data is actually enabled, but they are |
| 6918 | * not considered here. See {@link #isDataEnabled(int)} for more details. |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6919 | * |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6920 | * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE |
| 6921 | * or carrier privileges. |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 6922 | * |
| 6923 | * @return {@code true} if data is enabled else {@code false} |
| 6924 | */ |
| 6925 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6926 | public boolean isUserDataEnabled(int subId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6927 | String functionName = "isUserDataEnabled"; |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6928 | try { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6929 | try { |
| 6930 | mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE, |
| 6931 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 6932 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6933 | mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName); |
| 6934 | } |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 6935 | } catch (SecurityException e) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6936 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6937 | mApp, subId, functionName); |
| 6938 | |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6939 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6940 | |
| 6941 | final long identity = Binder.clearCallingIdentity(); |
| 6942 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 6943 | int phoneId = SubscriptionManager.getPhoneId(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6944 | if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 6945 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6946 | if (phone != null) { |
| 6947 | boolean retVal = phone.isUserDataEnabled(); |
| 6948 | if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 6949 | return retVal; |
| 6950 | } else { |
| 6951 | if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 6952 | return false; |
| 6953 | } |
| 6954 | } finally { |
| 6955 | Binder.restoreCallingIdentity(identity); |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6956 | } |
| 6957 | } |
| 6958 | |
| 6959 | /** |
Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 6960 | * Checks if the device is capable of mobile data by considering whether whether the |
| 6961 | * user has enabled mobile data, whether the carrier has enabled mobile data, and |
| 6962 | * whether the network policy allows data connections. |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6963 | * |
Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 6964 | * @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] | 6965 | */ |
| 6966 | @Override |
| 6967 | public boolean isDataEnabled(int subId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6968 | String functionName = "isDataEnabled"; |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6969 | try { |
| 6970 | try { |
| 6971 | mApp.enforceCallingOrSelfPermission( |
| 6972 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6973 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 6974 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6975 | try { |
| 6976 | mApp.enforceCallingOrSelfPermission( |
| 6977 | android.Manifest.permission.READ_PHONE_STATE, |
| 6978 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 6979 | } catch (SecurityException e2) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6980 | mApp.enforceCallingOrSelfPermission( |
| 6981 | permission.READ_BASIC_PHONE_STATE, functionName); |
| 6982 | } |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6983 | } |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 6984 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6985 | enforceReadPrivilegedPermission(functionName); |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6986 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6987 | |
| 6988 | final long identity = Binder.clearCallingIdentity(); |
| 6989 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 6990 | int phoneId = SubscriptionManager.getPhoneId(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6991 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6992 | if (phone != null) { |
Sarah Chin | e04784a | 2022-10-31 20:32:34 -0700 | [diff] [blame] | 6993 | boolean retVal = phone.getDataSettingsManager().isDataEnabled(); |
Jack Yu | 4ad64e5 | 2021-12-03 14:23:53 -0800 | [diff] [blame] | 6994 | if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6995 | return retVal; |
| 6996 | } else { |
| 6997 | if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 6998 | return false; |
| 6999 | } |
| 7000 | } finally { |
| 7001 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 7002 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 7003 | } |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 7004 | |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7005 | /** |
| 7006 | * Check if data is enabled for a specific reason |
| 7007 | * @param subId Subscription index |
| 7008 | * @param reason the reason the data enable change is taking place |
| 7009 | * @return {@code true} if the overall data is enabled; {@code false} if not. |
| 7010 | */ |
| 7011 | @Override |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7012 | public boolean isDataEnabledForReason(int subId, |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7013 | @TelephonyManager.DataEnabledReason int reason) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7014 | String functionName = "isDataEnabledForReason"; |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7015 | try { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7016 | try { |
| 7017 | mApp.enforceCallingOrSelfPermission( |
| 7018 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 7019 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7020 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7021 | mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE, |
| 7022 | functionName); |
| 7023 | } |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7024 | } catch (SecurityException e) { |
Sooraj Sasindran | 0d909a0 | 2021-11-08 12:01:16 -0800 | [diff] [blame] | 7025 | try { |
| 7026 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7027 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7028 | } catch (SecurityException e2) { |
Sooraj Sasindran | 0d909a0 | 2021-11-08 12:01:16 -0800 | [diff] [blame] | 7029 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7030 | mApp, subId, functionName); |
Sooraj Sasindran | 0d909a0 | 2021-11-08 12:01:16 -0800 | [diff] [blame] | 7031 | } |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7032 | } |
| 7033 | |
| 7034 | |
| 7035 | final long identity = Binder.clearCallingIdentity(); |
| 7036 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 7037 | int phoneId = SubscriptionManager.getPhoneId(subId); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7038 | if (DBG) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7039 | log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7040 | + " reason=" + reason); |
| 7041 | } |
| 7042 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 7043 | if (phone != null) { |
| 7044 | boolean retVal; |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 7045 | retVal = phone.getDataSettingsManager().isDataEnabledForReason(reason); |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7046 | if (DBG) log("isDataEnabledForReason: retVal=" + retVal); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7047 | return retVal; |
| 7048 | } else { |
| 7049 | if (DBG) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7050 | loge("isDataEnabledForReason: no phone subId=" |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7051 | + subId + " retVal=false"); |
| 7052 | } |
| 7053 | return false; |
| 7054 | } |
| 7055 | } finally { |
| 7056 | Binder.restoreCallingIdentity(identity); |
| 7057 | } |
| 7058 | } |
| 7059 | |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 7060 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7061 | public int getCarrierPrivilegeStatus(int subId) { |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7062 | // No permission needed; this only lets the caller inspect their own status. |
| 7063 | return getCarrierPrivilegeStatusForUidWithPermission(subId, Binder.getCallingUid()); |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 7064 | } |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 7065 | |
| 7066 | @Override |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7067 | public int getCarrierPrivilegeStatusForUid(int subId, int uid) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 7068 | enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid"); |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7069 | return getCarrierPrivilegeStatusForUidWithPermission(subId, uid); |
| 7070 | } |
| 7071 | |
| 7072 | private int getCarrierPrivilegeStatusForUidWithPermission(int subId, int uid) { |
| 7073 | Phone phone = getPhone(subId); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7074 | if (phone == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 7075 | loge("getCarrierPrivilegeStatusForUid: Invalid subId"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7076 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 7077 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7078 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7079 | if (cpt == null) { |
| 7080 | loge("getCarrierPrivilegeStatusForUid: No CarrierPrivilegesTracker"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7081 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 7082 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7083 | return cpt.getCarrierPrivilegeStatusForUid(uid); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7084 | } |
| 7085 | |
| 7086 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7087 | public int checkCarrierPrivilegesForPackage(int subId, String pkgName) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 7088 | enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage"); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7089 | if (TextUtils.isEmpty(pkgName)) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 7090 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7091 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7092 | Phone phone = getPhone(subId); |
| 7093 | if (phone == null) { |
| 7094 | loge("checkCarrierPrivilegesForPackage: Invalid subId"); |
| 7095 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 7096 | } |
| 7097 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7098 | if (cpt == null) { |
| 7099 | loge("checkCarrierPrivilegesForPackage: No CarrierPrivilegesTracker"); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 7100 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 7101 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7102 | return cpt.getCarrierPrivilegeStatusForPackage(pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 7103 | } |
| 7104 | |
| 7105 | @Override |
| 7106 | public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) { |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7107 | enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackageAnyPhone"); |
Rambo Wang | e7209ce | 2022-02-23 13:41:02 -0800 | [diff] [blame] | 7108 | return checkCarrierPrivilegesForPackageAnyPhoneWithPermission(pkgName); |
| 7109 | } |
| 7110 | |
| 7111 | private int checkCarrierPrivilegesForPackageAnyPhoneWithPermission(String pkgName) { |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7112 | if (TextUtils.isEmpty(pkgName)) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 7113 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7114 | } |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 7115 | int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7116 | for (int phoneId = 0; phoneId < TelephonyManager.getDefault().getPhoneCount(); phoneId++) { |
| 7117 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 7118 | if (phone == null) { |
| 7119 | continue; |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 7120 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7121 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7122 | if (cpt == null) { |
| 7123 | continue; |
| 7124 | } |
| 7125 | result = cpt.getCarrierPrivilegeStatusForPackage(pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 7126 | if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 7127 | break; |
| 7128 | } |
| 7129 | } |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 7130 | return result; |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 7131 | } |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 7132 | |
| 7133 | @Override |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 7134 | public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 7135 | enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone"); |
Rambo Wang | 8a247eb | 2022-02-08 21:11:18 +0000 | [diff] [blame] | 7136 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 7137 | if (phone == null) { |
| 7138 | return Collections.emptyList(); |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 7139 | } |
Rambo Wang | 8a247eb | 2022-02-08 21:11:18 +0000 | [diff] [blame] | 7140 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7141 | if (cpt == null) { |
| 7142 | return Collections.emptyList(); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 7143 | } |
Rambo Wang | 8a247eb | 2022-02-08 21:11:18 +0000 | [diff] [blame] | 7144 | return cpt.getCarrierPackageNamesForIntent(intent); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 7145 | } |
| 7146 | |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 7147 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7148 | public List<String> getPackagesWithCarrierPrivileges(int phoneId) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 7149 | enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges"); |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7150 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 7151 | if (phone == null) { |
| 7152 | return Collections.emptyList(); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 7153 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7154 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7155 | if (cpt == null) { |
| 7156 | return Collections.emptyList(); |
| 7157 | } |
| 7158 | return new ArrayList<>(cpt.getPackagesWithCarrierPrivileges()); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 7159 | } |
| 7160 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7161 | @Override |
| 7162 | public List<String> getPackagesWithCarrierPrivilegesForAllPhones() { |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 7163 | enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones"); |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7164 | Set<String> privilegedPackages = new ArraySet<>(); |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 7165 | final long identity = Binder.clearCallingIdentity(); |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 7166 | try { |
| 7167 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 7168 | privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i)); |
| 7169 | } |
| 7170 | } finally { |
| 7171 | Binder.restoreCallingIdentity(identity); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7172 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7173 | return new ArrayList<>(privilegedPackages); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7174 | } |
| 7175 | |
Rambo Wang | 6812ffb | 2022-03-15 16:54:17 -0700 | [diff] [blame] | 7176 | @Override |
| 7177 | public @Nullable String getCarrierServicePackageNameForLogicalSlot(int logicalSlotIndex) { |
| 7178 | enforceReadPrivilegedPermission("getCarrierServicePackageNameForLogicalSlot"); |
| 7179 | |
| 7180 | final Phone phone = PhoneFactory.getPhone(logicalSlotIndex); |
| 7181 | if (phone == null) { |
| 7182 | return null; |
| 7183 | } |
| 7184 | final CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7185 | if (cpt == null) { |
| 7186 | return null; |
| 7187 | } |
| 7188 | return cpt.getCarrierServicePackageName(); |
| 7189 | } |
| 7190 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 7191 | private String getIccId(int subId) { |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 7192 | final Phone phone = getPhone(subId); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 7193 | UiccPort port = phone == null ? null : phone.getUiccPort(); |
| 7194 | if (port == null) { |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7195 | return null; |
| 7196 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 7197 | String iccId = port.getIccId(); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7198 | if (TextUtils.isEmpty(iccId)) { |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7199 | return null; |
| 7200 | } |
| 7201 | return iccId; |
| 7202 | } |
| 7203 | |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 7204 | @Override |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 7205 | public void setCallComposerStatus(int subId, int status) { |
| 7206 | enforceModifyPermission(); |
| 7207 | |
| 7208 | final long identity = Binder.clearCallingIdentity(); |
| 7209 | try { |
| 7210 | Phone phone = getPhone(subId); |
| 7211 | if (phone != null) { |
| 7212 | Phone defaultPhone = phone.getImsPhone(); |
| 7213 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 7214 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 7215 | imsPhone.setCallComposerStatus(status); |
Shuo Qian | 284ae75 | 2020-12-22 19:10:14 -0800 | [diff] [blame] | 7216 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| 7217 | .updateImsServiceConfig(); |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 7218 | } |
| 7219 | } |
Shuo Qian | 284ae75 | 2020-12-22 19:10:14 -0800 | [diff] [blame] | 7220 | } catch (ImsException e) { |
| 7221 | throw new ServiceSpecificException(e.getCode()); |
| 7222 | } finally { |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 7223 | Binder.restoreCallingIdentity(identity); |
| 7224 | } |
| 7225 | } |
| 7226 | |
| 7227 | @Override |
| 7228 | public int getCallComposerStatus(int subId) { |
| 7229 | enforceReadPrivilegedPermission("getCallComposerStatus"); |
| 7230 | |
| 7231 | final long identity = Binder.clearCallingIdentity(); |
| 7232 | try { |
| 7233 | Phone phone = getPhone(subId); |
| 7234 | if (phone != null) { |
| 7235 | Phone defaultPhone = phone.getImsPhone(); |
| 7236 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 7237 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 7238 | return imsPhone.getCallComposerStatus(); |
| 7239 | } |
| 7240 | } |
| 7241 | } finally { |
| 7242 | Binder.restoreCallingIdentity(identity); |
| 7243 | } |
| 7244 | return TelephonyManager.CALL_COMPOSER_STATUS_OFF; |
| 7245 | } |
| 7246 | |
| 7247 | @Override |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7248 | public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag, |
| 7249 | String number) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 7250 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7251 | subId, "setLine1NumberForDisplayForSubscriber"); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7252 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7253 | final long identity = Binder.clearCallingIdentity(); |
| 7254 | try { |
| 7255 | final String iccId = getIccId(subId); |
| 7256 | final Phone phone = getPhone(subId); |
| 7257 | if (phone == null) { |
| 7258 | return false; |
| 7259 | } |
| 7260 | final String subscriberId = phone.getSubscriberId(); |
| 7261 | |
| 7262 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 7263 | Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId=" |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7264 | + subscriberId + " to " + number); |
| 7265 | } |
| 7266 | |
| 7267 | if (TextUtils.isEmpty(iccId)) { |
| 7268 | return false; |
| 7269 | } |
| 7270 | |
| 7271 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 7272 | |
| 7273 | final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 7274 | if (alphaTag == null) { |
| 7275 | editor.remove(alphaTagPrefKey); |
| 7276 | } else { |
| 7277 | editor.putString(alphaTagPrefKey, alphaTag); |
| 7278 | } |
| 7279 | |
| 7280 | // Record both the line number and IMSI for this ICCID, since we need to |
| 7281 | // track all merged IMSIs based on line number |
| 7282 | final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 7283 | final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 7284 | if (number == null) { |
| 7285 | editor.remove(numberPrefKey); |
| 7286 | editor.remove(subscriberPrefKey); |
| 7287 | } else { |
| 7288 | editor.putString(numberPrefKey, number); |
| 7289 | editor.putString(subscriberPrefKey, subscriberId); |
| 7290 | } |
| 7291 | |
| 7292 | editor.commit(); |
| 7293 | return true; |
| 7294 | } finally { |
| 7295 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 7296 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7297 | } |
| 7298 | |
| 7299 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7300 | public String getLine1NumberForDisplay(int subId, String callingPackage, |
| 7301 | String callingFeatureId) { |
Makoto Onuki | fee6934 | 2015-06-29 14:44:50 -0700 | [diff] [blame] | 7302 | // This is open to apps with WRITE_SMS. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7303 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7304 | mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) { |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 7305 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission"); |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 7306 | return null; |
| 7307 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7308 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7309 | final long identity = Binder.clearCallingIdentity(); |
| 7310 | try { |
| 7311 | String iccId = getIccId(subId); |
| 7312 | if (iccId != null) { |
| 7313 | String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 7314 | if (DBG_MERGE) { |
| 7315 | log("getLine1NumberForDisplay returning " |
| 7316 | + mTelephonySharedPreferences.getString(numberPrefKey, null)); |
| 7317 | } |
| 7318 | return mTelephonySharedPreferences.getString(numberPrefKey, null); |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 7319 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7320 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null"); |
| 7321 | return null; |
| 7322 | } finally { |
| 7323 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7324 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7325 | } |
| 7326 | |
| 7327 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7328 | public String getLine1AlphaTagForDisplay(int subId, String callingPackage, |
| 7329 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7330 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7331 | mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 7332 | return null; |
| 7333 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7334 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7335 | final long identity = Binder.clearCallingIdentity(); |
| 7336 | try { |
| 7337 | String iccId = getIccId(subId); |
| 7338 | if (iccId != null) { |
| 7339 | String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 7340 | return mTelephonySharedPreferences.getString(alphaTagPrefKey, null); |
| 7341 | } |
| 7342 | return null; |
| 7343 | } finally { |
| 7344 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7345 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7346 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 7347 | |
| 7348 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7349 | public String[] getMergedSubscriberIds(int subId, String callingPackage, |
| 7350 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7351 | // This API isn't public, so no need to provide a valid subscription ID - we're not worried |
| 7352 | // about carrier-privileged callers not having access. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7353 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7354 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7355 | callingFeatureId, "getMergedSubscriberIds")) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7356 | return null; |
| 7357 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7358 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 7359 | // Clear calling identity, when calling TelephonyManager, because callerUid must be |
| 7360 | // the process, where TelephonyManager was instantiated. |
| 7361 | // Otherwise AppOps check will fail. |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7362 | final long identity = Binder.clearCallingIdentity(); |
| 7363 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7364 | final Context context = mApp; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7365 | final TelephonyManager tele = TelephonyManager.from(context); |
| 7366 | final SubscriptionManager sub = SubscriptionManager.from(context); |
| 7367 | |
| 7368 | // Figure out what subscribers are currently active |
| 7369 | final ArraySet<String> activeSubscriberIds = new ArraySet<>(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7370 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 7371 | // Only consider subs which match the current subId |
| 7372 | // This logic can be simplified. See b/131189269 for progress. |
| 7373 | if (isActiveSubscription(subId)) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7374 | activeSubscriberIds.add(tele.getSubscriberId(subId)); |
| 7375 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7376 | |
| 7377 | // First pass, find a number override for an active subscriber |
| 7378 | String mergeNumber = null; |
| 7379 | final Map<String, ?> prefs = mTelephonySharedPreferences.getAll(); |
| 7380 | for (String key : prefs.keySet()) { |
| 7381 | if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) { |
| 7382 | final String subscriberId = (String) prefs.get(key); |
| 7383 | if (activeSubscriberIds.contains(subscriberId)) { |
| 7384 | final String iccId = key.substring( |
| 7385 | PREF_CARRIERS_SUBSCRIBER_PREFIX.length()); |
| 7386 | final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 7387 | mergeNumber = (String) prefs.get(numberKey); |
| 7388 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 7389 | Rlog.d(LOG_TAG, "Found line number " + mergeNumber |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7390 | + " for active subscriber " + subscriberId); |
| 7391 | } |
| 7392 | if (!TextUtils.isEmpty(mergeNumber)) { |
| 7393 | break; |
| 7394 | } |
| 7395 | } |
| 7396 | } |
| 7397 | } |
| 7398 | |
| 7399 | // Shortcut when no active merged subscribers |
| 7400 | if (TextUtils.isEmpty(mergeNumber)) { |
| 7401 | return null; |
| 7402 | } |
| 7403 | |
| 7404 | // Second pass, find all subscribers under that line override |
| 7405 | final ArraySet<String> result = new ArraySet<>(); |
| 7406 | for (String key : prefs.keySet()) { |
| 7407 | if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) { |
| 7408 | final String number = (String) prefs.get(key); |
| 7409 | if (mergeNumber.equals(number)) { |
| 7410 | final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length()); |
| 7411 | final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 7412 | final String subscriberId = (String) prefs.get(subscriberKey); |
| 7413 | if (!TextUtils.isEmpty(subscriberId)) { |
| 7414 | result.add(subscriberId); |
| 7415 | } |
| 7416 | } |
| 7417 | } |
| 7418 | } |
| 7419 | |
| 7420 | final String[] resultArray = result.toArray(new String[result.size()]); |
| 7421 | Arrays.sort(resultArray); |
| 7422 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 7423 | Rlog.d(LOG_TAG, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7424 | "Found subscribers " + Arrays.toString(resultArray) + " after merge"); |
| 7425 | } |
| 7426 | return resultArray; |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7427 | } finally { |
| 7428 | Binder.restoreCallingIdentity(identity); |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7429 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7430 | } |
| 7431 | |
| 7432 | @Override |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 7433 | public String[] getMergedImsisFromGroup(int subId, String callingPackage) { |
| 7434 | enforceReadPrivilegedPermission("getMergedImsisFromGroup"); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7435 | |
| 7436 | final long identity = Binder.clearCallingIdentity(); |
| 7437 | try { |
| 7438 | final TelephonyManager telephonyManager = mApp.getSystemService( |
| 7439 | TelephonyManager.class); |
| 7440 | String subscriberId = telephonyManager.getSubscriberId(subId); |
| 7441 | if (subscriberId == null) { |
| 7442 | if (DBG) { |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 7443 | log("getMergedImsisFromGroup can't find subscriberId for subId " |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7444 | + subId); |
| 7445 | } |
| 7446 | return null; |
| 7447 | } |
| 7448 | |
Jack Yu | 3beaf9d | 2023-04-14 09:17:27 -0700 | [diff] [blame] | 7449 | final SubscriptionInfo info = getSubscriptionManagerService() |
| 7450 | .getSubscriptionInfo(subId); |
| 7451 | ParcelUuid groupUuid = info.getGroupUuid(); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7452 | // If it doesn't belong to any group, return just subscriberId of itself. |
| 7453 | if (groupUuid == null) { |
| 7454 | return new String[]{subscriberId}; |
| 7455 | } |
| 7456 | |
| 7457 | // Get all subscriberIds from the group. |
| 7458 | final List<String> mergedSubscriberIds = new ArrayList<>(); |
Jack Yu | 3beaf9d | 2023-04-14 09:17:27 -0700 | [diff] [blame] | 7459 | List<SubscriptionInfo> groupInfos = getSubscriptionManagerService() |
| 7460 | .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(), |
| 7461 | mApp.getAttributionTag()); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7462 | for (SubscriptionInfo subInfo : groupInfos) { |
| 7463 | subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId()); |
| 7464 | if (subscriberId != null) { |
| 7465 | mergedSubscriberIds.add(subscriberId); |
| 7466 | } |
| 7467 | } |
| 7468 | |
| 7469 | return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]); |
| 7470 | } finally { |
| 7471 | Binder.restoreCallingIdentity(identity); |
| 7472 | |
| 7473 | } |
| 7474 | } |
| 7475 | |
| 7476 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7477 | public boolean setOperatorBrandOverride(int subId, String brand) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 7478 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7479 | subId, "setOperatorBrandOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7480 | |
| 7481 | final long identity = Binder.clearCallingIdentity(); |
| 7482 | try { |
| 7483 | final Phone phone = getPhone(subId); |
| 7484 | return phone == null ? false : phone.setOperatorBrandOverride(brand); |
| 7485 | } finally { |
| 7486 | Binder.restoreCallingIdentity(identity); |
| 7487 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 7488 | } |
Steven Liu | 4bf01bc | 2014-07-17 11:05:29 -0500 | [diff] [blame] | 7489 | |
| 7490 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7491 | public boolean setRoamingOverride(int subId, List<String> gsmRoamingList, |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 7492 | List<String> gsmNonRoamingList, List<String> cdmaRoamingList, |
| 7493 | List<String> cdmaNonRoamingList) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 7494 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 7495 | mApp, subId, "setRoamingOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7496 | |
| 7497 | final long identity = Binder.clearCallingIdentity(); |
| 7498 | try { |
| 7499 | final Phone phone = getPhone(subId); |
| 7500 | if (phone == null) { |
| 7501 | return false; |
| 7502 | } |
| 7503 | return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList, |
| 7504 | cdmaNonRoamingList); |
| 7505 | } finally { |
| 7506 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7507 | } |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 7508 | } |
| 7509 | |
| 7510 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 7511 | public int getRadioAccessFamily(int phoneId, String callingPackage) { |
Aishwarya Mallampati | 11e8287 | 2023-03-13 21:04:00 +0000 | [diff] [blame] | 7512 | int raf = RadioAccessFamily.RAF_UNKNOWN; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7513 | Phone phone = PhoneFactory.getPhone(phoneId); |
Aishwarya Mallampati | 11e8287 | 2023-03-13 21:04:00 +0000 | [diff] [blame] | 7514 | if (phone == null) { |
| 7515 | return raf; |
| 7516 | } |
| 7517 | |
Shuo Qian | dee5340 | 2020-05-29 14:08:15 -0700 | [diff] [blame] | 7518 | try { |
| 7519 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 7520 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Shuo Qian | dee5340 | 2020-05-29 14:08:15 -0700 | [diff] [blame] | 7521 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 7522 | } catch (SecurityException e) { |
| 7523 | EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission"); |
| 7524 | throw e; |
| 7525 | } |
Aishwarya Mallampati | 11e8287 | 2023-03-13 21:04:00 +0000 | [diff] [blame] | 7526 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7527 | final long identity = Binder.clearCallingIdentity(); |
| 7528 | try { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7529 | raf = ProxyController.getInstance().getRadioAccessFamily(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7530 | } finally { |
| 7531 | Binder.restoreCallingIdentity(identity); |
| 7532 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7533 | return raf; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 7534 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7535 | |
| 7536 | @Override |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7537 | public void uploadCallComposerPicture(int subscriptionId, String callingPackage, |
Hall Liu | e31bac6 | 2020-12-23 19:16:10 -0800 | [diff] [blame] | 7538 | String contentType, ParcelFileDescriptor fd, ResultReceiver callback) { |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7539 | try { |
| 7540 | if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0), |
| 7541 | Binder.getCallingUid())) { |
Tyler Gunn | b87925a | 2021-06-10 14:54:27 -0700 | [diff] [blame] | 7542 | throw new SecurityException("Invalid package:" + callingPackage); |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7543 | } |
| 7544 | } catch (PackageManager.NameNotFoundException e) { |
Tyler Gunn | b87925a | 2021-06-10 14:54:27 -0700 | [diff] [blame] | 7545 | throw new SecurityException("Invalid package:" + callingPackage); |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7546 | } |
| 7547 | RoleManager rm = mApp.getSystemService(RoleManager.class); |
| 7548 | List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER); |
| 7549 | if (!dialerRoleHolders.contains(callingPackage)) { |
| 7550 | throw new SecurityException("App must be the dialer role holder to" |
| 7551 | + " upload a call composer pic"); |
| 7552 | } |
| 7553 | |
| 7554 | Executors.newSingleThreadExecutor().execute(() -> { |
| 7555 | ByteArrayOutputStream output = new ByteArrayOutputStream( |
| 7556 | (int) TelephonyManager.getMaximumCallComposerPictureSize()); |
| 7557 | InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd); |
| 7558 | boolean readUntilEnd = false; |
| 7559 | int totalBytesRead = 0; |
| 7560 | byte[] buffer = new byte[16 * 1024]; |
| 7561 | while (true) { |
| 7562 | int numRead; |
| 7563 | try { |
| 7564 | numRead = input.read(buffer); |
| 7565 | } catch (IOException e) { |
| 7566 | try { |
| 7567 | fd.checkError(); |
| 7568 | callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED, |
| 7569 | null); |
| 7570 | } catch (IOException e1) { |
| 7571 | // This means that the other side closed explicitly with an error. If this |
| 7572 | // happens, log and ignore. |
| 7573 | loge("Remote end of call composer picture pipe closed: " + e1); |
| 7574 | } |
| 7575 | break; |
| 7576 | } |
| 7577 | if (numRead == -1) { |
| 7578 | readUntilEnd = true; |
| 7579 | break; |
| 7580 | } |
| 7581 | totalBytesRead += numRead; |
| 7582 | if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) { |
| 7583 | loge("Too many bytes read for call composer picture: " + totalBytesRead); |
| 7584 | try { |
| 7585 | input.close(); |
| 7586 | } catch (IOException e) { |
| 7587 | // ignore |
| 7588 | } |
| 7589 | break; |
| 7590 | } |
| 7591 | output.write(buffer, 0, numRead); |
| 7592 | } |
| 7593 | // Generally, the remote end will close the file descriptors. The only case where we |
| 7594 | // close is above, where the picture size is too big. |
| 7595 | |
| 7596 | try { |
| 7597 | fd.checkError(); |
| 7598 | } catch (IOException e) { |
| 7599 | loge("Remote end for call composer closed with an error: " + e); |
| 7600 | return; |
| 7601 | } |
| 7602 | |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 7603 | if (!readUntilEnd) { |
| 7604 | loge("Did not finish reading entire image; aborting"); |
| 7605 | return; |
| 7606 | } |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7607 | |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 7608 | ImageData imageData = new ImageData(output.toByteArray(), contentType, null); |
| 7609 | CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer( |
| 7610 | new CallComposerPictureTransfer.Factory() {}, |
| 7611 | imageData, |
| 7612 | (result) -> { |
| 7613 | if (result.first != null) { |
| 7614 | ParcelUuid parcelUuid = new ParcelUuid(result.first); |
| 7615 | Bundle outputResult = new Bundle(); |
| 7616 | outputResult.putParcelable( |
| 7617 | TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid); |
| 7618 | callback.send(TelephonyManager.CallComposerException.SUCCESS, |
| 7619 | outputResult); |
| 7620 | } else { |
| 7621 | callback.send(result.second, null); |
| 7622 | } |
| 7623 | } |
| 7624 | ); |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7625 | }); |
| 7626 | } |
| 7627 | |
| 7628 | @Override |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7629 | public void enableVideoCalling(boolean enable) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7630 | final Phone defaultPhone = getDefaultPhone(); |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7631 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7632 | |
| 7633 | final long identity = Binder.clearCallingIdentity(); |
| 7634 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7635 | ImsManager.getInstance(defaultPhone.getContext(), |
| 7636 | defaultPhone.getPhoneId()).setVtSetting(enable); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7637 | } finally { |
| 7638 | Binder.restoreCallingIdentity(identity); |
| 7639 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7640 | } |
| 7641 | |
| 7642 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7643 | public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7644 | final Phone defaultPhone = getDefaultPhone(); |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7645 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 7646 | callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 7647 | return false; |
| 7648 | } |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 7649 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7650 | final long identity = Binder.clearCallingIdentity(); |
| 7651 | try { |
| 7652 | // Check the user preference and the system-level IMS setting. Even if the user has |
| 7653 | // enabled video calling, if IMS is disabled we aren't able to support video calling. |
| 7654 | // In the long run, we may instead need to check if there exists a connection service |
| 7655 | // which can support video calling. |
| 7656 | ImsManager imsManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7657 | ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7658 | return imsManager.isVtEnabledByPlatform() |
| 7659 | && imsManager.isEnhanced4gLteModeSettingEnabledByUser() |
| 7660 | && imsManager.isVtEnabledByUser(); |
| 7661 | } finally { |
| 7662 | Binder.restoreCallingIdentity(identity); |
| 7663 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7664 | } |
Libin.Tang@motorola.com | afe8264 | 2014-12-18 13:27:53 -0600 | [diff] [blame] | 7665 | |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7666 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7667 | public boolean canChangeDtmfToneLength(int subId, String callingPackage, |
| 7668 | String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7669 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7670 | mApp, subId, callingPackage, callingFeatureId, |
| 7671 | "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7672 | return false; |
| 7673 | } |
| 7674 | |
| 7675 | final long identity = Binder.clearCallingIdentity(); |
| 7676 | try { |
| 7677 | CarrierConfigManager configManager = |
| 7678 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7679 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7680 | .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL); |
| 7681 | } finally { |
| 7682 | Binder.restoreCallingIdentity(identity); |
| 7683 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7684 | } |
| 7685 | |
| 7686 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7687 | public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7688 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7689 | mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7690 | return false; |
| 7691 | } |
| 7692 | |
| 7693 | final long identity = Binder.clearCallingIdentity(); |
| 7694 | try { |
| 7695 | CarrierConfigManager configManager = |
| 7696 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7697 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7698 | .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL); |
| 7699 | } finally { |
| 7700 | Binder.restoreCallingIdentity(identity); |
| 7701 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7702 | } |
| 7703 | |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7704 | @Override |
| 7705 | public boolean isTtyModeSupported() { |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 7706 | TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class); |
Wooki Wu | 1f82f7a | 2016-02-15 15:59:58 +0800 | [diff] [blame] | 7707 | return telecomManager.isTtySupported(); |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7708 | } |
| 7709 | |
| 7710 | @Override |
| 7711 | public boolean isHearingAidCompatibilitySupported() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7712 | final long identity = Binder.clearCallingIdentity(); |
| 7713 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7714 | return mApp.getResources().getBoolean(R.bool.hac_enabled); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7715 | } finally { |
| 7716 | Binder.restoreCallingIdentity(identity); |
| 7717 | } |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7718 | } |
| 7719 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 7720 | /** |
| 7721 | * Determines whether the device currently supports RTT (Real-time text). Based both on carrier |
| 7722 | * support for the feature and device firmware support. |
| 7723 | * |
| 7724 | * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise. |
| 7725 | */ |
| 7726 | @Override |
| 7727 | public boolean isRttSupported(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7728 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7729 | final Phone phone = getPhone(subscriptionId); |
| 7730 | if (phone == null) { |
| 7731 | loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId); |
| 7732 | return false; |
| 7733 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7734 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7735 | boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7736 | CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL); |
| 7737 | boolean isDeviceSupported = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7738 | phone.getContext().getResources().getBoolean(R.bool.config_support_rtt); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7739 | return isCarrierSupported && isDeviceSupported; |
| 7740 | } finally { |
| 7741 | Binder.restoreCallingIdentity(identity); |
| 7742 | } |
Hall Liu | 9818758 | 2018-01-22 19:15:32 -0800 | [diff] [blame] | 7743 | } |
| 7744 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 7745 | /** |
Hall Liu | f2daa02 | 2019-07-23 18:39:00 -0700 | [diff] [blame] | 7746 | * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set |
| 7747 | * RTT setting, will return true if the device and carrier both support RTT. |
| 7748 | * 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] | 7749 | */ |
| 7750 | public boolean isRttEnabled(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7751 | final long identity = Binder.clearCallingIdentity(); |
| 7752 | try { |
Hall Liu | 5bab75c | 2019-12-11 23:58:20 +0000 | [diff] [blame] | 7753 | boolean isRttSupported = isRttSupported(subscriptionId); |
| 7754 | boolean isUserRttSettingOn = Settings.Secure.getInt( |
| 7755 | mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0; |
| 7756 | boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId) |
| 7757 | .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL); |
| 7758 | return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7759 | } finally { |
| 7760 | Binder.restoreCallingIdentity(identity); |
| 7761 | } |
Hall Liu | 3ad5f01 | 2018-04-06 16:23:39 -0700 | [diff] [blame] | 7762 | } |
| 7763 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7764 | @Deprecated |
| 7765 | @Override |
| 7766 | public String getDeviceId(String callingPackage) { |
| 7767 | return getDeviceIdWithFeature(callingPackage, null); |
| 7768 | } |
| 7769 | |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7770 | /** |
| 7771 | * Returns the unique device ID of phone, for example, the IMEI for |
| 7772 | * GSM and the MEID for CDMA phones. Return null if device ID is not available. |
| 7773 | * |
| 7774 | * <p>Requires Permission: |
| 7775 | * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} |
| 7776 | */ |
| 7777 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7778 | public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) { |
Shuo Qian | 13d8915 | 2021-05-10 23:58:11 -0700 | [diff] [blame] | 7779 | try { |
| 7780 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 7781 | } catch (SecurityException se) { |
| 7782 | EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid()); |
| 7783 | throw new SecurityException("Package " + callingPackage + " does not belong to " |
| 7784 | + Binder.getCallingUid()); |
| 7785 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7786 | final Phone phone = PhoneFactory.getPhone(0); |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7787 | if (phone == null) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7788 | return null; |
| 7789 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7790 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 7791 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7792 | callingPackage, callingFeatureId, "getDeviceId")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7793 | return null; |
| 7794 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7795 | |
| 7796 | final long identity = Binder.clearCallingIdentity(); |
| 7797 | try { |
| 7798 | return phone.getDeviceId(); |
| 7799 | } finally { |
| 7800 | Binder.restoreCallingIdentity(identity); |
| 7801 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7802 | } |
| 7803 | |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 7804 | /** |
| 7805 | * {@hide} |
| 7806 | * Returns the IMS Registration Status on a particular subid |
| 7807 | * |
| 7808 | * @param subId |
| 7809 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7810 | public boolean isImsRegistered(int subId) { |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 7811 | Phone phone = getPhone(subId); |
| 7812 | if (phone != null) { |
| 7813 | return phone.isImsRegistered(); |
| 7814 | } else { |
| 7815 | return false; |
| 7816 | } |
| 7817 | } |
| 7818 | |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 7819 | @Override |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7820 | public int getSubIdForPhoneAccountHandle( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7821 | PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) { |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7822 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(), |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7823 | callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) { |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7824 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 7825 | } |
| 7826 | final long identity = Binder.clearCallingIdentity(); |
| 7827 | try { |
| 7828 | return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle); |
| 7829 | } finally { |
| 7830 | Binder.restoreCallingIdentity(identity); |
| 7831 | } |
| 7832 | } |
| 7833 | |
| 7834 | @Override |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 7835 | public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) { |
Alireza Forouzan | 4ac4f98 | 2021-03-16 22:18:52 -0700 | [diff] [blame] | 7836 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 7837 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 7838 | mApp, |
| 7839 | subscriptionId, |
| 7840 | "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: " |
| 7841 | + subscriptionId); |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 7842 | final long identity = Binder.clearCallingIdentity(); |
| 7843 | try { |
| 7844 | Phone phone = getPhone(subscriptionId); |
| 7845 | if (phone == null) { |
| 7846 | return null; |
| 7847 | } |
| 7848 | return PhoneUtils.makePstnPhoneAccountHandle(phone); |
| 7849 | } finally { |
| 7850 | Binder.restoreCallingIdentity(identity); |
| 7851 | } |
| 7852 | } |
| 7853 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7854 | /** |
| 7855 | * @return the VoWiFi calling availability. |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 7856 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7857 | public boolean isWifiCallingAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7858 | final long identity = Binder.clearCallingIdentity(); |
| 7859 | try { |
| 7860 | Phone phone = getPhone(subId); |
| 7861 | if (phone != null) { |
| 7862 | return phone.isWifiCallingEnabled(); |
| 7863 | } else { |
| 7864 | return false; |
| 7865 | } |
| 7866 | } finally { |
| 7867 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7868 | } |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 7869 | } |
| 7870 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7871 | /** |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7872 | * @return the VT calling availability. |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 7873 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7874 | public boolean isVideoTelephonyAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7875 | final long identity = Binder.clearCallingIdentity(); |
| 7876 | try { |
| 7877 | Phone phone = getPhone(subId); |
| 7878 | if (phone != null) { |
| 7879 | return phone.isVideoEnabled(); |
| 7880 | } else { |
| 7881 | return false; |
| 7882 | } |
| 7883 | } finally { |
| 7884 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7885 | } |
| 7886 | } |
| 7887 | |
| 7888 | /** |
| 7889 | * @return the IMS registration technology for the MMTEL feature. Valid return values are |
| 7890 | * defined in {@link ImsRegistrationImplBase}. |
| 7891 | */ |
| 7892 | public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7893 | final long identity = Binder.clearCallingIdentity(); |
| 7894 | try { |
| 7895 | Phone phone = getPhone(subId); |
| 7896 | if (phone != null) { |
| 7897 | return phone.getImsRegistrationTech(); |
| 7898 | } else { |
| 7899 | return ImsRegistrationImplBase.REGISTRATION_TECH_NONE; |
| 7900 | } |
| 7901 | } finally { |
| 7902 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7903 | } |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 7904 | } |
| 7905 | |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 7906 | @Override |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 7907 | public void factoryReset(int subId, String callingPackage) { |
paulhu | 5a77360 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 7908 | enforceSettingsPermission(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 7909 | if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) { |
| 7910 | return; |
| 7911 | } |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 7912 | Phone defaultPhone = getDefaultPhone(); |
| 7913 | if (defaultPhone != null) { |
| 7914 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7915 | mApp, getDefaultPhone().getSubId(), "factoryReset"); |
| 7916 | } |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7917 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7918 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7919 | try { |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 7920 | if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction( |
| 7921 | UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7922 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 7923 | getDefaultDataEnabled(), callingPackage); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7924 | setNetworkSelectionModeAutomatic(subId); |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 7925 | Phone phone = getPhone(subId); |
SongFerngWang | fd89b10 | 2021-05-27 22:44:54 +0800 | [diff] [blame] | 7926 | cleanUpAllowedNetworkTypes(phone, subId); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7927 | setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId)); |
Jordan Liu | 857e73a | 2021-03-05 16:24:04 -0800 | [diff] [blame] | 7928 | getPhone(subId).resetCarrierKeysForImsiEncryption(); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7929 | } |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 7930 | // There has been issues when Sms raw table somehow stores orphan |
| 7931 | // fragments. They lead to garbled message when new fragments come |
| 7932 | // in and combined with those stale ones. In case this happens again, |
| 7933 | // user can reset all network settings which will clean up this table. |
| 7934 | cleanUpSmsRawTable(getDefaultPhone().getContext()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 7935 | // Clean up IMS settings as well here. |
| 7936 | int slotId = getSlotIndex(subId); |
| 7937 | if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 7938 | ImsManager.getInstance(mApp, slotId).factoryReset(); |
| 7939 | } |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 7940 | |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 7941 | if (defaultPhone == null) { |
| 7942 | return; |
| 7943 | } |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 7944 | // Erase modem config if erase modem on network setting is enabled. |
| 7945 | String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY, |
| 7946 | RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED); |
| 7947 | if (configValue != null && Boolean.parseBoolean(configValue)) { |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 7948 | sendEraseModemConfig(defaultPhone); |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 7949 | } |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 7950 | |
| 7951 | sendEraseDataInSharedPreferences(defaultPhone); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7952 | } finally { |
| 7953 | Binder.restoreCallingIdentity(identity); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 7954 | } |
| 7955 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7956 | |
SongFerngWang | fd89b10 | 2021-05-27 22:44:54 +0800 | [diff] [blame] | 7957 | @VisibleForTesting |
| 7958 | void cleanUpAllowedNetworkTypes(Phone phone, int subId) { |
| 7959 | if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) { |
| 7960 | return; |
| 7961 | } |
| 7962 | long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType( |
| 7963 | RILConstants.PREFERRED_NETWORK_MODE); |
| 7964 | SubscriptionManager.setSubscriptionProperty(subId, |
| 7965 | SubscriptionManager.ALLOWED_NETWORK_TYPES, |
| 7966 | "user=" + defaultNetworkType); |
| 7967 | phone.loadAllowedNetworksFromSubscriptionDatabase(); |
| 7968 | phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER, |
| 7969 | defaultNetworkType, null); |
| 7970 | } |
| 7971 | |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 7972 | private void cleanUpSmsRawTable(Context context) { |
| 7973 | ContentResolver resolver = context.getContentResolver(); |
| 7974 | Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete"); |
| 7975 | resolver.delete(uri, null, null); |
| 7976 | } |
| 7977 | |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7978 | @Override |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7979 | public String getSimLocaleForSubscriber(int subId) { |
| 7980 | enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId); |
| 7981 | final Phone phone = getPhone(subId); |
| 7982 | if (phone == null) { |
| 7983 | log("getSimLocaleForSubscriber, invalid subId"); |
chen xu | 2bb91e4 | 2019-01-24 14:35:54 -0800 | [diff] [blame] | 7984 | return null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7985 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7986 | final long identity = Binder.clearCallingIdentity(); |
| 7987 | try { |
Jack Yu | 3beaf9d | 2023-04-14 09:17:27 -0700 | [diff] [blame] | 7988 | SubscriptionInfo info = getSubscriptionManagerService().getActiveSubscriptionInfo(subId, |
| 7989 | phone.getContext().getOpPackageName(), |
| 7990 | phone.getContext().getAttributionTag()); |
| 7991 | if (info == null) { |
| 7992 | log("getSimLocaleForSubscriber, inactive subId: " + subId); |
| 7993 | return null; |
chen xu | 6291c47 | 2019-02-04 12:55:53 -0800 | [diff] [blame] | 7994 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7995 | // Try and fetch the locale from the carrier properties or from the SIM language |
| 7996 | // preferences (EF-PL and EF-LI)... |
| 7997 | final int mcc = info.getMcc(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7998 | String simLanguage = null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7999 | final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs(); |
| 8000 | if (localeFromDefaultSim != null) { |
| 8001 | if (!localeFromDefaultSim.getCountry().isEmpty()) { |
| 8002 | if (DBG) log("Using locale from subId: " + subId + " locale: " |
| 8003 | + localeFromDefaultSim); |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 8004 | return matchLocaleFromSupportedLocaleList(phone, localeFromDefaultSim); |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 8005 | } else { |
| 8006 | simLanguage = localeFromDefaultSim.getLanguage(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8007 | } |
| 8008 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 8009 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8010 | // The SIM language preferences only store a language (e.g. fr = French), not an |
| 8011 | // exact locale (e.g. fr_FR = French/France). So, if the locale returned from |
| 8012 | // the SIM and carrier preferences does not include a country we add the country |
| 8013 | // determined from the SIM MCC to provide an exact locale. |
zoey chen | c730df8 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 8014 | final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8015 | if (mccLocale != null) { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 8016 | if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale); |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 8017 | return matchLocaleFromSupportedLocaleList(phone, mccLocale); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8018 | } |
| 8019 | |
| 8020 | if (DBG) log("No locale found - returning null"); |
| 8021 | return null; |
| 8022 | } finally { |
| 8023 | Binder.restoreCallingIdentity(identity); |
| 8024 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 8025 | } |
| 8026 | |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 8027 | @VisibleForTesting |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 8028 | String matchLocaleFromSupportedLocaleList(Phone phone, @NonNull Locale inputLocale) { |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 8029 | String[] supportedLocale = com.android.internal.app.LocalePicker.getSupportedLocales( |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 8030 | phone.getContext()); |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 8031 | for (String localeTag : supportedLocale) { |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 8032 | if (LocaleList.matchesLanguageAndScript(inputLocale, Locale.forLanguageTag(localeTag)) |
| 8033 | && TextUtils.equals(inputLocale.getCountry(), |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 8034 | Locale.forLanguageTag(localeTag).getCountry())) { |
| 8035 | return localeTag; |
| 8036 | } |
| 8037 | } |
| 8038 | return inputLocale.toLanguageTag(); |
| 8039 | } |
| 8040 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8041 | /** |
| 8042 | * NOTE: this method assumes permission checks are done and caller identity has been cleared. |
| 8043 | */ |
| 8044 | private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() { |
Jack Yu | 3beaf9d | 2023-04-14 09:17:27 -0700 | [diff] [blame] | 8045 | return getSubscriptionManagerService().getActiveSubscriptionInfoList( |
| 8046 | mApp.getOpPackageName(), mApp.getAttributionTag()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 8047 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 8048 | |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8049 | private ActivityStatsTechSpecificInfo[] mLastModemActivitySpecificInfo = null; |
| 8050 | private ModemActivityInfo mLastModemActivityInfo = null; |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 8051 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 8052 | /** |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 8053 | * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object |
| 8054 | * representing the state of the modem. |
| 8055 | * |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 8056 | * NOTE: The underlying implementation clears the modem state, so there should only ever be one |
| 8057 | * caller to it. Everyone should call this class to get cumulative data. |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 8058 | * @hide |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 8059 | */ |
| 8060 | @Override |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 8061 | public void requestModemActivityInfo(ResultReceiver result) { |
| 8062 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8063 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8064 | |
| 8065 | final long identity = Binder.clearCallingIdentity(); |
| 8066 | try { |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 8067 | sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8068 | } finally { |
| 8069 | Binder.restoreCallingIdentity(identity); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 8070 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 8071 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8072 | |
Gary Jian | 76280a4 | 2022-12-07 16:18:33 +0800 | [diff] [blame] | 8073 | // Checks that ModemActivityInfo is valid. Sleep time and Idle time should be |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 8074 | // less than total activity duration. |
| 8075 | private boolean isModemActivityInfoValid(ModemActivityInfo info) { |
| 8076 | if (info == null) { |
| 8077 | return false; |
| 8078 | } |
| 8079 | int activityDurationMs = |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 8080 | (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis()); |
Gary Jian | 76280a4 | 2022-12-07 16:18:33 +0800 | [diff] [blame] | 8081 | activityDurationMs += MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS; |
| 8082 | |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 8083 | int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum(); |
| 8084 | |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 8085 | return (info.isValid() |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 8086 | && (info.getSleepTimeMillis() <= activityDurationMs) |
| 8087 | && (info.getIdleTimeMillis() <= activityDurationMs)); |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 8088 | } |
| 8089 | |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8090 | private void updateLastModemActivityInfo(ModemActivityInfo info, int rat, int freq) { |
| 8091 | int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()]; |
| 8092 | int[] txTimeMs = info.getTransmitTimeMillis(rat, freq); |
| 8093 | int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat, freq); |
| 8094 | |
| 8095 | for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) { |
| 8096 | mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl]; |
| 8097 | } |
| 8098 | |
| 8099 | mLastModemActivityInfo.setTransmitTimeMillis(rat, freq, mergedTxTimeMs); |
| 8100 | mLastModemActivityInfo.setReceiveTimeMillis( |
| 8101 | rat, |
| 8102 | freq, |
| 8103 | info.getReceiveTimeMillis(rat, freq) |
| 8104 | + mLastModemActivityInfo.getReceiveTimeMillis(rat, freq)); |
| 8105 | } |
| 8106 | |
| 8107 | private void updateLastModemActivityInfo(ModemActivityInfo info, int rat) { |
| 8108 | int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()]; |
| 8109 | int[] txTimeMs = info.getTransmitTimeMillis(rat); |
| 8110 | int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat); |
| 8111 | |
| 8112 | for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) { |
| 8113 | mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl]; |
| 8114 | } |
| 8115 | mLastModemActivityInfo.setTransmitTimeMillis(rat, mergedTxTimeMs); |
| 8116 | mLastModemActivityInfo.setReceiveTimeMillis( |
| 8117 | rat, |
| 8118 | info.getReceiveTimeMillis(rat) + mLastModemActivityInfo.getReceiveTimeMillis(rat)); |
| 8119 | } |
| 8120 | |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 8121 | /** |
| 8122 | * Merge this ModemActivityInfo with mLastModemActivitySpecificInfo |
| 8123 | * @param info recent ModemActivityInfo |
| 8124 | */ |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8125 | private void mergeModemActivityInfo(ModemActivityInfo info) { |
| 8126 | List<ActivityStatsTechSpecificInfo> merged = new ArrayList<>(); |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 8127 | ActivityStatsTechSpecificInfo deltaSpecificInfo; |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8128 | boolean matched; |
| 8129 | for (int i = 0; i < info.getSpecificInfoLength(); i++) { |
| 8130 | matched = false; |
| 8131 | int rat = info.getSpecificInfoRat(i); |
| 8132 | int freq = info.getSpecificInfoFrequencyRange(i); |
| 8133 | //Check each ActivityStatsTechSpecificInfo in this ModemActivityInfo for new rat returns |
| 8134 | //Add a new ActivityStatsTechSpecificInfo if is a new rat, and merge with the original |
| 8135 | //if it already exists |
| 8136 | for (int j = 0; j < mLastModemActivitySpecificInfo.length; j++) { |
| 8137 | if (rat == mLastModemActivityInfo.getSpecificInfoRat(j) && !matched) { |
| 8138 | //Merged based on frequency range (MMWAVE vs SUB6) for 5G |
| 8139 | if (rat == AccessNetworkConstants.AccessNetworkType.NGRAN) { |
| 8140 | if (freq == mLastModemActivityInfo.getSpecificInfoFrequencyRange(j)) { |
| 8141 | updateLastModemActivityInfo(info, rat, freq); |
| 8142 | matched = true; |
| 8143 | } |
| 8144 | } else { |
| 8145 | updateLastModemActivityInfo(info, rat); |
| 8146 | matched = true; |
| 8147 | } |
| 8148 | } |
| 8149 | } |
| 8150 | |
| 8151 | if (!matched) { |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 8152 | deltaSpecificInfo = |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8153 | new ActivityStatsTechSpecificInfo( |
| 8154 | rat, |
| 8155 | freq, |
| 8156 | info.getTransmitTimeMillis(rat, freq), |
| 8157 | (int) info.getReceiveTimeMillis(rat, freq)); |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 8158 | merged.addAll(Arrays.asList(deltaSpecificInfo)); |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8159 | } |
| 8160 | } |
| 8161 | merged.addAll(Arrays.asList(mLastModemActivitySpecificInfo)); |
| 8162 | mLastModemActivitySpecificInfo = |
| 8163 | new ActivityStatsTechSpecificInfo[merged.size()]; |
| 8164 | merged.toArray(mLastModemActivitySpecificInfo); |
| 8165 | |
| 8166 | mLastModemActivityInfo.setTimestamp(info.getTimestampMillis()); |
| 8167 | mLastModemActivityInfo.setSleepTimeMillis( |
| 8168 | info.getSleepTimeMillis() |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 8169 | + mLastModemActivityInfo.getSleepTimeMillis()); |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8170 | mLastModemActivityInfo.setIdleTimeMillis( |
| 8171 | info.getIdleTimeMillis() |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 8172 | + mLastModemActivityInfo.getIdleTimeMillis()); |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 8173 | |
| 8174 | mLastModemActivityInfo = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 8175 | new ModemActivityInfo( |
| 8176 | mLastModemActivityInfo.getTimestampMillis(), |
| 8177 | mLastModemActivityInfo.getSleepTimeMillis(), |
| 8178 | mLastModemActivityInfo.getIdleTimeMillis(), |
| 8179 | mLastModemActivitySpecificInfo); |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 8180 | } |
| 8181 | |
| 8182 | private ActivityStatsTechSpecificInfo[] deepCopyModemActivitySpecificInfo( |
| 8183 | ActivityStatsTechSpecificInfo[] info) { |
| 8184 | int infoSize = info.length; |
| 8185 | ActivityStatsTechSpecificInfo[] ret = new ActivityStatsTechSpecificInfo[infoSize]; |
| 8186 | for (int i = 0; i < infoSize; i++) { |
| 8187 | ret[i] = new ActivityStatsTechSpecificInfo( |
| 8188 | info[i].getRat(), info[i].getFrequencyRange(), |
| 8189 | info[i].getTransmitTimeMillis(), |
| 8190 | (int) info[i].getReceiveTimeMillis()); |
| 8191 | } |
| 8192 | return ret; |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8193 | } |
| 8194 | |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8195 | /** |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8196 | * Returns the service state information on specified subscription. |
| 8197 | */ |
| 8198 | @Override |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 8199 | public ServiceState getServiceStateForSubscriber(int subId, |
| 8200 | boolean renounceFineLocationAccess, boolean renounceCoarseLocationAccess, |
| 8201 | String callingPackage, String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8202 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8203 | mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) { |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8204 | return null; |
| 8205 | } |
| 8206 | |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 8207 | boolean hasFinePermission = false; |
| 8208 | boolean hasCoarsePermission = false; |
| 8209 | if (!renounceFineLocationAccess) { |
| 8210 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 8211 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 8212 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 8213 | .setCallingPackage(callingPackage) |
| 8214 | .setCallingFeatureId(callingFeatureId) |
| 8215 | .setCallingPid(Binder.getCallingPid()) |
| 8216 | .setCallingUid(Binder.getCallingUid()) |
| 8217 | .setMethod("getServiceStateForSubscriber") |
| 8218 | .setLogAsInfo(true) |
| 8219 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 8220 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 8221 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 8222 | .build()); |
| 8223 | hasFinePermission = |
| 8224 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 8225 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 8226 | |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 8227 | if (!renounceCoarseLocationAccess) { |
| 8228 | LocationAccessPolicy.LocationPermissionResult coarseLocationResult = |
| 8229 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 8230 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 8231 | .setCallingPackage(callingPackage) |
| 8232 | .setCallingFeatureId(callingFeatureId) |
| 8233 | .setCallingPid(Binder.getCallingPid()) |
| 8234 | .setCallingUid(Binder.getCallingUid()) |
| 8235 | .setMethod("getServiceStateForSubscriber") |
| 8236 | .setLogAsInfo(true) |
| 8237 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 8238 | .setMinSdkVersionForFine(Integer.MAX_VALUE) |
| 8239 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 8240 | .build()); |
| 8241 | hasCoarsePermission = |
| 8242 | coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 8243 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 8244 | |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 8245 | final Phone phone = getPhone(subId); |
| 8246 | if (phone == null) { |
| 8247 | return null; |
| 8248 | } |
| 8249 | |
Jordan Liu | 0f2bc44 | 2020-11-18 16:47:37 -0800 | [diff] [blame] | 8250 | final long identity = Binder.clearCallingIdentity(); |
| 8251 | |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 8252 | boolean isCallingPackageDataService = phone.getDataServicePackages() |
| 8253 | .contains(callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8254 | try { |
Jordan Liu | c437b19 | 2020-08-17 10:59:12 -0700 | [diff] [blame] | 8255 | // isActiveSubId requires READ_PHONE_STATE, which we already check for above |
Jack Yu | 3beaf9d | 2023-04-14 09:17:27 -0700 | [diff] [blame] | 8256 | SubscriptionInfoInternal subInfo = getSubscriptionManagerService() |
| 8257 | .getSubscriptionInfoInternal(subId); |
| 8258 | if (subInfo == null || !subInfo.isActive()) { |
| 8259 | Rlog.d(LOG_TAG, "getServiceStateForSubscriber returning null for inactive " |
| 8260 | + "subId=" + subId); |
| 8261 | return null; |
Jordan Liu | c437b19 | 2020-08-17 10:59:12 -0700 | [diff] [blame] | 8262 | } |
| 8263 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 8264 | ServiceState ss = phone.getServiceState(); |
| 8265 | |
| 8266 | // Scrub out the location info in ServiceState depending on what level of access |
| 8267 | // the caller has. |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 8268 | if (hasFinePermission || isCallingPackageDataService) return ss; |
Malcolm Chen | 5052de6 | 2019-12-30 13:56:38 -0800 | [diff] [blame] | 8269 | if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false); |
| 8270 | return ss.createLocationInfoSanitizedCopy(true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8271 | } finally { |
| 8272 | Binder.restoreCallingIdentity(identity); |
| 8273 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8274 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8275 | |
| 8276 | /** |
| 8277 | * Returns the URI for the per-account voicemail ringtone set in Phone settings. |
| 8278 | * |
| 8279 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 8280 | * voicemail ringtone. |
| 8281 | * @return The URI for the ringtone to play when receiving a voicemail from a specific |
| 8282 | * PhoneAccount. |
| 8283 | */ |
| 8284 | @Override |
| 8285 | public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8286 | final long identity = Binder.clearCallingIdentity(); |
| 8287 | try { |
| 8288 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 8289 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8290 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8291 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8292 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8293 | return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext()); |
| 8294 | } finally { |
| 8295 | Binder.restoreCallingIdentity(identity); |
| 8296 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8297 | } |
| 8298 | |
| 8299 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8300 | * Sets the per-account voicemail ringtone. |
| 8301 | * |
| 8302 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 8303 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 8304 | * |
| 8305 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 8306 | * voicemail ringtone. |
| 8307 | * @param uri The URI for the ringtone to play when receiving a voicemail from a specific |
| 8308 | * PhoneAccount. |
| 8309 | */ |
| 8310 | @Override |
| 8311 | public void setVoicemailRingtoneUri(String callingPackage, |
| 8312 | PhoneAccountHandle phoneAccountHandle, Uri uri) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8313 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8314 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 8315 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 8316 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8317 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8318 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 8319 | "setVoicemailRingtoneUri"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8320 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8321 | |
| 8322 | final long identity = Binder.clearCallingIdentity(); |
| 8323 | try { |
| 8324 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 8325 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8326 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8327 | } |
| 8328 | VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri); |
| 8329 | } finally { |
| 8330 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8331 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8332 | } |
| 8333 | |
| 8334 | /** |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8335 | * Returns whether vibration is set for voicemail notification in Phone settings. |
| 8336 | * |
| 8337 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 8338 | * voicemail vibration setting. |
| 8339 | * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise. |
| 8340 | */ |
| 8341 | @Override |
| 8342 | public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8343 | final long identity = Binder.clearCallingIdentity(); |
| 8344 | try { |
| 8345 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 8346 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8347 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8348 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8349 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8350 | return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext()); |
| 8351 | } finally { |
| 8352 | Binder.restoreCallingIdentity(identity); |
| 8353 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8354 | } |
| 8355 | |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8356 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8357 | * Sets the per-account voicemail vibration. |
| 8358 | * |
| 8359 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 8360 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 8361 | * |
| 8362 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 8363 | * voicemail vibration setting. |
| 8364 | * @param enabled Whether to enable or disable vibration for voicemail notifications from a |
| 8365 | * specific PhoneAccount. |
| 8366 | */ |
| 8367 | @Override |
| 8368 | public void setVoicemailVibrationEnabled(String callingPackage, |
| 8369 | PhoneAccountHandle phoneAccountHandle, boolean enabled) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8370 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8371 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 8372 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 8373 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8374 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8375 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 8376 | "setVoicemailVibrationEnabled"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8377 | } |
| 8378 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8379 | final long identity = Binder.clearCallingIdentity(); |
| 8380 | try { |
| 8381 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 8382 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8383 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8384 | } |
| 8385 | VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled); |
| 8386 | } finally { |
| 8387 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8388 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8389 | } |
| 8390 | |
| 8391 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8392 | * Make sure either called from same process as self (phone) or IPC caller has read privilege. |
| 8393 | * |
| 8394 | * @throws SecurityException if the caller does not have the required permission |
| 8395 | */ |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 8396 | @VisibleForTesting |
| 8397 | public void enforceReadPrivilegedPermission(String message) { |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8398 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8399 | message); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8400 | } |
| 8401 | |
| 8402 | /** |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 8403 | * Make sure either called from same process as self (phone) or IPC caller has send SMS |
| 8404 | * permission. |
| 8405 | * |
| 8406 | * @throws SecurityException if the caller does not have the required permission |
| 8407 | */ |
| 8408 | private void enforceSendSmsPermission() { |
| 8409 | mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null); |
| 8410 | } |
| 8411 | |
| 8412 | /** |
Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame] | 8413 | * Make sure either called from same process as self (phone) or IPC caller has interact across |
| 8414 | * users permission. |
| 8415 | * |
| 8416 | * @throws SecurityException if the caller does not have the required permission |
| 8417 | */ |
| 8418 | private void enforceInteractAcrossUsersPermission(String message) { |
| 8419 | mApp.enforceCallingOrSelfPermission(permission.INTERACT_ACROSS_USERS, message); |
| 8420 | } |
| 8421 | |
| 8422 | /** |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 8423 | * Make sure called from the package in charge of visual voicemail. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 8424 | * |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 8425 | * @throws SecurityException if the caller is not the visual voicemail package. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 8426 | */ |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 8427 | private void enforceVisualVoicemailPackage(String callingPackage, int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8428 | final long identity = Binder.clearCallingIdentity(); |
| 8429 | try { |
| 8430 | ComponentName componentName = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8431 | RemoteVvmTaskManager.getRemotePackage(mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8432 | if (componentName == null) { |
| 8433 | throw new SecurityException( |
| 8434 | "Caller not current active visual voicemail package[null]"); |
| 8435 | } |
| 8436 | String vvmPackage = componentName.getPackageName(); |
| 8437 | if (!callingPackage.equals(vvmPackage)) { |
Hui Wang | 7f65755 | 2022-08-16 16:58:25 +0000 | [diff] [blame] | 8438 | throw new SecurityException("Caller not current active visual voicemail package"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8439 | } |
| 8440 | } finally { |
| 8441 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 8442 | } |
| 8443 | } |
| 8444 | |
| 8445 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8446 | * Return the application ID for the app type. |
| 8447 | * |
| 8448 | * @param subId the subscription ID that this request applies to. |
| 8449 | * @param appType the uicc app type. |
| 8450 | * @return Application ID for specificied app type, or null if no uicc. |
| 8451 | */ |
| 8452 | @Override |
| 8453 | public String getAidForAppType(int subId, int appType) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8454 | enforceReadPrivilegedPermission("getAidForAppType"); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8455 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8456 | |
| 8457 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8458 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8459 | if (phone == null) { |
| 8460 | return null; |
| 8461 | } |
| 8462 | String aid = null; |
| 8463 | try { |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 8464 | aid = UiccController.getInstance().getUiccPort(phone.getPhoneId()) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8465 | .getApplicationByType(appType).getAid(); |
| 8466 | } catch (Exception e) { |
| 8467 | Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e); |
| 8468 | } |
| 8469 | return aid; |
| 8470 | } finally { |
| 8471 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8472 | } |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8473 | } |
| 8474 | |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8475 | /** |
| 8476 | * Return the Electronic Serial Number. |
| 8477 | * |
| 8478 | * @param subId the subscription ID that this request applies to. |
| 8479 | * @return ESN or null if error. |
| 8480 | */ |
| 8481 | @Override |
| 8482 | public String getEsn(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8483 | enforceReadPrivilegedPermission("getEsn"); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8484 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8485 | |
| 8486 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8487 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8488 | if (phone == null) { |
| 8489 | return null; |
| 8490 | } |
| 8491 | String esn = null; |
| 8492 | try { |
| 8493 | esn = phone.getEsn(); |
| 8494 | } catch (Exception e) { |
| 8495 | Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e); |
| 8496 | } |
| 8497 | return esn; |
| 8498 | } finally { |
| 8499 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8500 | } |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8501 | } |
| 8502 | |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 8503 | /** |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8504 | * Return the Preferred Roaming List Version. |
| 8505 | * |
| 8506 | * @param subId the subscription ID that this request applies to. |
| 8507 | * @return PRLVersion or null if error. |
| 8508 | */ |
| 8509 | @Override |
| 8510 | public String getCdmaPrlVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8511 | enforceReadPrivilegedPermission("getCdmaPrlVersion"); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8512 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8513 | |
| 8514 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8515 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8516 | if (phone == null) { |
| 8517 | return null; |
| 8518 | } |
| 8519 | String cdmaPrlVersion = null; |
| 8520 | try { |
| 8521 | cdmaPrlVersion = phone.getCdmaPrlVersion(); |
| 8522 | } catch (Exception e) { |
| 8523 | Log.e(LOG_TAG, "Not getting PRLVersion", e); |
| 8524 | } |
| 8525 | return cdmaPrlVersion; |
| 8526 | } finally { |
| 8527 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8528 | } |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8529 | } |
| 8530 | |
| 8531 | /** |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 8532 | * Get snapshot of Telephony histograms |
| 8533 | * @return List of Telephony histograms |
| 8534 | * @hide |
| 8535 | */ |
| 8536 | @Override |
| 8537 | public List<TelephonyHistogram> getTelephonyHistograms() { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8538 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8539 | mApp, getDefaultSubscription(), "getTelephonyHistograms"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8540 | |
| 8541 | final long identity = Binder.clearCallingIdentity(); |
| 8542 | try { |
| 8543 | return RIL.getTelephonyRILTimingHistograms(); |
| 8544 | } finally { |
| 8545 | Binder.restoreCallingIdentity(identity); |
| 8546 | } |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 8547 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8548 | |
| 8549 | /** |
| 8550 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8551 | * Set the allowed carrier list and the excluded carrier list, indicating the priority between |
| 8552 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8553 | * Require system privileges. In the future we may add this to carrier APIs. |
| 8554 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8555 | * @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] | 8556 | */ |
| 8557 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8558 | @TelephonyManager.SetCarrierRestrictionResult |
| 8559 | public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) { |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8560 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8561 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8562 | |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8563 | if (carrierRestrictionRules == null) { |
| 8564 | throw new NullPointerException("carrier restriction cannot be null"); |
Meng Wang | 9b7c4e9 | 2017-02-17 11:41:27 -0800 | [diff] [blame] | 8565 | } |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8566 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8567 | final long identity = Binder.clearCallingIdentity(); |
| 8568 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8569 | return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8570 | workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8571 | } finally { |
| 8572 | Binder.restoreCallingIdentity(identity); |
| 8573 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8574 | } |
| 8575 | |
| 8576 | /** |
| 8577 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8578 | * Get the allowed carrier list and the excluded carrier list, including the priority between |
| 8579 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8580 | * Require system privileges. In the future we may add this to carrier APIs. |
| 8581 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8582 | * @return {@link android.telephony.CarrierRestrictionRules} |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8583 | */ |
| 8584 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8585 | public CarrierRestrictionRules getAllowedCarriers() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8586 | enforceReadPrivilegedPermission("getAllowedCarriers"); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8587 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8588 | |
| 8589 | final long identity = Binder.clearCallingIdentity(); |
| 8590 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8591 | Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource); |
| 8592 | if (response instanceof CarrierRestrictionRules) { |
| 8593 | return (CarrierRestrictionRules) response; |
| 8594 | } |
| 8595 | // Response is an Exception of some kind, |
| 8596 | // which is signalled to the user as a NULL retval |
| 8597 | return null; |
| 8598 | } catch (Exception e) { |
| 8599 | Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e); |
| 8600 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8601 | } finally { |
| 8602 | Binder.restoreCallingIdentity(identity); |
| 8603 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8604 | } |
| 8605 | |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 8606 | /** |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 8607 | * Fetches the carrier restriction status of the device and sends the status to the caller |
| 8608 | * through the callback. |
| 8609 | * |
| 8610 | * @param callback The callback that will be used to send the result. |
| 8611 | * @throws SecurityException if the caller does not have the required permission/privileges or |
| 8612 | * the caller is not allowlisted. |
| 8613 | */ |
| 8614 | @Override |
| 8615 | public void getCarrierRestrictionStatus(IIntegerConsumer callback, String packageName) { |
| 8616 | enforceReadPermission("getCarrierRestrictionStatus"); |
| 8617 | int carrierId = validateCallerAndGetCarrierId(packageName); |
| 8618 | if (carrierId == CarrierAllowListInfo.INVALID_CARRIER_ID) { |
| 8619 | Rlog.e(LOG_TAG, "getCarrierRestrictionStatus: caller is not registered"); |
| 8620 | throw new SecurityException("Not an authorized caller"); |
| 8621 | } |
| 8622 | final long identity = Binder.clearCallingIdentity(); |
| 8623 | try { |
| 8624 | Consumer<Integer> consumer = FunctionalUtils.ignoreRemoteException(callback::accept); |
| 8625 | CallerCallbackInfo callbackInfo = new CallerCallbackInfo(consumer, carrierId); |
| 8626 | sendRequestAsync(CMD_GET_ALLOWED_CARRIERS, callbackInfo); |
| 8627 | } finally { |
| 8628 | Binder.restoreCallingIdentity(identity); |
| 8629 | } |
| 8630 | } |
| 8631 | |
arunvoddu | 567f2b4 | 2023-04-25 17:22:00 +0000 | [diff] [blame] | 8632 | @Override |
| 8633 | public List<String> getShaIdFromAllowList(String pkgName, int carrierId) { |
| 8634 | enforceReadPrivilegedPermission("checkCarrierRestrictionFileForNoChange"); |
| 8635 | CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp); |
| 8636 | return allowListInfo.getShaIdList(pkgName, carrierId); |
| 8637 | } |
| 8638 | |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 8639 | @VisibleForTesting |
| 8640 | public int validateCallerAndGetCarrierId(String packageName) { |
| 8641 | CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp); |
| 8642 | return allowListInfo.validateCallerAndGetCarrierId(packageName); |
| 8643 | } |
| 8644 | |
| 8645 | /** |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 8646 | * Action set from carrier signalling broadcast receivers to enable/disable radio |
| 8647 | * @param subId the subscription ID that this action applies to. |
| 8648 | * @param enabled control enable or disable radio. |
| 8649 | * {@hide} |
| 8650 | */ |
| 8651 | @Override |
| 8652 | public void carrierActionSetRadioEnabled(int subId, boolean enabled) { |
| 8653 | enforceModifyPermission(); |
| 8654 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8655 | |
| 8656 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 8657 | if (phone == null) { |
| 8658 | loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId); |
| 8659 | return; |
| 8660 | } |
| 8661 | try { |
| 8662 | phone.carrierActionSetRadioEnabled(enabled); |
| 8663 | } catch (Exception e) { |
| 8664 | Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8665 | } finally { |
| 8666 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 8667 | } |
| 8668 | } |
| 8669 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 8670 | /** |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 8671 | * Enable or disable Voice over NR (VoNR) |
| 8672 | * @param subId the subscription ID that this action applies to. |
| 8673 | * @param enabled enable or disable VoNR. |
| 8674 | * @return operation result. |
| 8675 | */ |
| 8676 | @Override |
| 8677 | public int setVoNrEnabled(int subId, boolean enabled) { |
| 8678 | enforceModifyPermission(); |
| 8679 | final Phone phone = getPhone(subId); |
| 8680 | |
| 8681 | final long identity = Binder.clearCallingIdentity(); |
| 8682 | if (phone == null) { |
| 8683 | loge("setVoNrEnabled fails with no phone object for subId: " + subId); |
| 8684 | return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE; |
| 8685 | } |
| 8686 | |
| 8687 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8688 | try { |
| 8689 | int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId, |
| 8690 | workSource); |
| 8691 | if (DBG) log("setVoNrEnabled result: " + result); |
Gary Jian | 8dd305f | 2021-10-14 16:31:35 +0800 | [diff] [blame] | 8692 | |
| 8693 | if (result == TelephonyManager.ENABLE_VONR_SUCCESS) { |
| 8694 | if (DBG) { |
| 8695 | log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled); |
| 8696 | } |
| 8697 | SubscriptionManager.setSubscriptionProperty( |
| 8698 | subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED, |
| 8699 | (enabled ? "1" : "0")); |
| 8700 | } |
| 8701 | |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 8702 | return result; |
| 8703 | } finally { |
| 8704 | Binder.restoreCallingIdentity(identity); |
| 8705 | } |
| 8706 | } |
| 8707 | |
| 8708 | /** |
| 8709 | * Is voice over NR enabled |
| 8710 | * @return true if VoNR is enabled else false |
| 8711 | */ |
| 8712 | @Override |
| 8713 | public boolean isVoNrEnabled(int subId) { |
| 8714 | enforceReadPrivilegedPermission("isVoNrEnabled"); |
| 8715 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8716 | final long identity = Binder.clearCallingIdentity(); |
| 8717 | try { |
| 8718 | boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED, |
| 8719 | null, subId, workSource); |
| 8720 | if (DBG) log("isVoNrEnabled: " + isEnabled); |
| 8721 | return isEnabled; |
| 8722 | } finally { |
| 8723 | Binder.restoreCallingIdentity(identity); |
| 8724 | } |
| 8725 | } |
| 8726 | |
| 8727 | /** |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 8728 | * Action set from carrier signalling broadcast receivers to start/stop reporting the default |
| 8729 | * network status based on which carrier apps could apply actions accordingly, |
| 8730 | * enable/disable default url handler for example. |
| 8731 | * |
| 8732 | * @param subId the subscription ID that this action applies to. |
| 8733 | * @param report control start/stop reporting the default network status. |
| 8734 | * {@hide} |
| 8735 | */ |
| 8736 | @Override |
| 8737 | public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) { |
| 8738 | enforceModifyPermission(); |
| 8739 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8740 | |
| 8741 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 8742 | if (phone == null) { |
| 8743 | loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId); |
| 8744 | return; |
| 8745 | } |
| 8746 | try { |
| 8747 | phone.carrierActionReportDefaultNetworkStatus(report); |
| 8748 | } catch (Exception e) { |
| 8749 | Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8750 | } finally { |
| 8751 | Binder.restoreCallingIdentity(identity); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 8752 | } |
| 8753 | } |
| 8754 | |
| 8755 | /** |
fionaxu | d962228 | 2017-07-17 17:51:30 -0700 | [diff] [blame] | 8756 | * Action set from carrier signalling broadcast receivers to reset all carrier actions |
| 8757 | * @param subId the subscription ID that this action applies to. |
| 8758 | * {@hide} |
| 8759 | */ |
| 8760 | @Override |
| 8761 | public void carrierActionResetAll(int subId) { |
| 8762 | enforceModifyPermission(); |
| 8763 | final Phone phone = getPhone(subId); |
| 8764 | if (phone == null) { |
| 8765 | loge("carrierAction: ResetAll fails with invalid sibId: " + subId); |
| 8766 | return; |
| 8767 | } |
| 8768 | try { |
| 8769 | phone.carrierActionResetAll(); |
| 8770 | } catch (Exception e) { |
| 8771 | Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e); |
| 8772 | } |
| 8773 | } |
| 8774 | |
| 8775 | /** |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 8776 | * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a |
| 8777 | * bug report is being generated. |
| 8778 | */ |
| 8779 | @Override |
Ta-wei Yen | 99282e0 | 2016-06-21 18:19:35 -0700 | [diff] [blame] | 8780 | protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8781 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 8782 | != PackageManager.PERMISSION_GRANTED) { |
dcashman | 22b950d | 2016-06-27 11:39:02 -0700 | [diff] [blame] | 8783 | writer.println("Permission Denial: can't dump Phone from pid=" |
| 8784 | + Binder.getCallingPid() |
| 8785 | + ", uid=" + Binder.getCallingUid() |
| 8786 | + "without permission " |
| 8787 | + android.Manifest.permission.DUMP); |
| 8788 | return; |
| 8789 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8790 | DumpsysHandler.dump(mApp, fd, writer, args); |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 8791 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 8792 | |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 8793 | @Override |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 8794 | public int handleShellCommand(@NonNull ParcelFileDescriptor in, |
| 8795 | @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err, |
| 8796 | @NonNull String[] args) { |
| 8797 | return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec( |
| 8798 | this, in.getFileDescriptor(), out.getFileDescriptor(), |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 8799 | err.getFileDescriptor(), args); |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 8800 | } |
| 8801 | |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 8802 | /** |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8803 | * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason} |
Greg Kaiser | 17f4175 | 2020-05-05 16:47:47 +0000 | [diff] [blame] | 8804 | * @param subId Subscription index |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 8805 | * @param reason The reason the data enable change is taking place. |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8806 | * @param enabled True if enabling the data, otherwise disabling. |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 8807 | * @param callingPackage The package that changed the data enabled state. |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8808 | * @hide |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 8809 | */ |
| 8810 | @Override |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 8811 | public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 8812 | boolean enabled, String callingPackage) { |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8813 | if (reason == TelephonyManager.DATA_ENABLED_REASON_USER |
| 8814 | || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 8815 | try { |
| 8816 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 8817 | mApp, subId, "setDataEnabledForReason"); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8818 | } catch (SecurityException se) { |
| 8819 | enforceModifyPermission(); |
| 8820 | } |
| 8821 | } else { |
| 8822 | enforceModifyPermission(); |
| 8823 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8824 | |
| 8825 | final long identity = Binder.clearCallingIdentity(); |
| 8826 | try { |
| 8827 | Phone phone = getPhone(subId); |
| 8828 | if (phone != null) { |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8829 | if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 8830 | phone.carrierActionSetMeteredApnsEnabled(enabled); |
| 8831 | } else { |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 8832 | phone.getDataSettingsManager().setDataEnabled( |
| 8833 | reason, enabled, callingPackage); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8834 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8835 | } |
| 8836 | } finally { |
| 8837 | Binder.restoreCallingIdentity(identity); |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 8838 | } |
| 8839 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8840 | |
| 8841 | /** |
| 8842 | * Get Client request stats |
| 8843 | * @return List of Client Request Stats |
| 8844 | * @hide |
| 8845 | */ |
| 8846 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8847 | public List<ClientRequestStats> getClientRequestStats(String callingPackage, |
| 8848 | String callingFeatureId, int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8849 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8850 | mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) { |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8851 | return null; |
| 8852 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8853 | Phone phone = getPhone(subId); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8854 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8855 | final long identity = Binder.clearCallingIdentity(); |
| 8856 | try { |
| 8857 | if (phone != null) { |
| 8858 | return phone.getClientRequestStats(); |
| 8859 | } |
| 8860 | |
| 8861 | return null; |
| 8862 | } finally { |
| 8863 | Binder.restoreCallingIdentity(identity); |
| 8864 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8865 | } |
| 8866 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 8867 | private WorkSource getWorkSource(int uid) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8868 | String packageName = mApp.getPackageManager().getNameForUid(uid); |
Hunter Knepshield | d03383b | 2022-03-29 22:47:54 +0000 | [diff] [blame] | 8869 | if (uid == Process.ROOT_UID && packageName == null) { |
| 8870 | // Downstream WorkSource attribution inside the RIL requires both a UID and package name |
| 8871 | // to be set for wakelock tracking, otherwise RIL requests fail with a runtime |
| 8872 | // exception. ROOT_UID seems not to have a valid package name returned by |
| 8873 | // PackageManager, so just fake it here to avoid issues when running telephony shell |
| 8874 | // commands that plumb through the RIL as root, like so: |
| 8875 | // $ adb root |
| 8876 | // $ adb shell cmd phone ... |
| 8877 | packageName = "root"; |
| 8878 | } |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 8879 | return new WorkSource(uid, packageName); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8880 | } |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8881 | |
| 8882 | /** |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 8883 | * Set SIM card power state. |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8884 | * |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8885 | * @param slotIndex SIM slot id. |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 8886 | * @param state State of SIM (power down, power up, pass through) |
| 8887 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 8888 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 8889 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8890 | * |
| 8891 | **/ |
| 8892 | @Override |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 8893 | public void setSimPowerStateForSlot(int slotIndex, int state) { |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8894 | enforceModifyPermission(); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8895 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8896 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8897 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8898 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8899 | final long identity = Binder.clearCallingIdentity(); |
| 8900 | try { |
| 8901 | if (phone != null) { |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 8902 | phone.setSimPowerState(state, null, workSource); |
| 8903 | } |
| 8904 | } finally { |
| 8905 | Binder.restoreCallingIdentity(identity); |
| 8906 | } |
| 8907 | } |
| 8908 | |
| 8909 | /** |
| 8910 | * Set SIM card power state. |
| 8911 | * |
| 8912 | * @param slotIndex SIM slot id. |
| 8913 | * @param state State of SIM (power down, power up, pass through) |
| 8914 | * @param callback callback to trigger after success or failure |
| 8915 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 8916 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 8917 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
| 8918 | * |
| 8919 | **/ |
| 8920 | @Override |
| 8921 | public void setSimPowerStateForSlotWithCallback(int slotIndex, int state, |
| 8922 | IIntegerConsumer callback) { |
| 8923 | enforceModifyPermission(); |
| 8924 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8925 | |
| 8926 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8927 | |
| 8928 | final long identity = Binder.clearCallingIdentity(); |
| 8929 | try { |
| 8930 | if (phone != null) { |
| 8931 | Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback); |
| 8932 | sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8933 | } |
| 8934 | } finally { |
| 8935 | Binder.restoreCallingIdentity(identity); |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8936 | } |
| 8937 | } |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8938 | |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 8939 | private boolean isUssdApiAllowed(int subId) { |
| 8940 | CarrierConfigManager configManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8941 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 8942 | if (configManager == null) { |
| 8943 | return false; |
| 8944 | } |
| 8945 | PersistableBundle pb = configManager.getConfigForSubId(subId); |
| 8946 | if (pb == null) { |
| 8947 | return false; |
| 8948 | } |
| 8949 | return pb.getBoolean( |
| 8950 | CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL); |
| 8951 | } |
| 8952 | |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8953 | /** |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 8954 | * Check if phone is in emergency callback mode. |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8955 | * @return true if phone is in emergency callback mode |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 8956 | * @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] | 8957 | */ |
goneil | 9c5f487 | 2017-12-05 14:07:56 -0800 | [diff] [blame] | 8958 | @Override |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8959 | public boolean getEmergencyCallbackMode(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8960 | enforceReadPrivilegedPermission("getEmergencyCallbackMode"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8961 | final long identity = Binder.clearCallingIdentity(); |
| 8962 | try { |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 8963 | return getPhoneFromSubIdOrDefault(subId).isInEcm(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8964 | } finally { |
| 8965 | Binder.restoreCallingIdentity(identity); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8966 | } |
| 8967 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 8968 | |
| 8969 | /** |
| 8970 | * Get the current signal strength information for the given subscription. |
| 8971 | * Because this information is not updated when the device is in a low power state |
| 8972 | * it should not be relied-upon to be current. |
| 8973 | * @param subId Subscription index |
| 8974 | * @return the most recent cached signal strength info from the modem |
| 8975 | */ |
| 8976 | @Override |
| 8977 | public SignalStrength getSignalStrength(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8978 | final long identity = Binder.clearCallingIdentity(); |
| 8979 | try { |
| 8980 | Phone p = getPhone(subId); |
| 8981 | if (p == null) { |
| 8982 | return null; |
| 8983 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 8984 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8985 | return p.getSignalStrength(); |
| 8986 | } finally { |
| 8987 | Binder.restoreCallingIdentity(identity); |
| 8988 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 8989 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8990 | |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8991 | /** |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8992 | * Get the current modem radio state for the given slot. |
| 8993 | * @param slotIndex slot index. |
| 8994 | * @param callingPackage the name of the package making the call. |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8995 | * @param callingFeatureId The feature in the package. |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8996 | * @return the current radio power state from the modem |
| 8997 | */ |
| 8998 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8999 | public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 9000 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 9001 | if (phone != null) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9002 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(), |
| 9003 | callingPackage, callingFeatureId, "getRadioPowerState")) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 9004 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 9005 | } |
| 9006 | |
| 9007 | final long identity = Binder.clearCallingIdentity(); |
| 9008 | try { |
| 9009 | return phone.getRadioPowerState(); |
| 9010 | } finally { |
| 9011 | Binder.restoreCallingIdentity(identity); |
| 9012 | } |
| 9013 | } |
| 9014 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 9015 | } |
| 9016 | |
| 9017 | /** |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9018 | * Checks if data roaming is enabled on the subscription with id {@code subId}. |
| 9019 | * |
| 9020 | * <p>Requires one of the following permissions: |
| 9021 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}, |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 9022 | * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE}, |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9023 | * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier |
| 9024 | * privileges. |
| 9025 | * |
| 9026 | * @param subId subscription id |
| 9027 | * @return {@code true} if data roaming is enabled on this subscription, otherwise return |
| 9028 | * {@code false}. |
| 9029 | */ |
| 9030 | @Override |
| 9031 | public boolean isDataRoamingEnabled(int subId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 9032 | String functionName = "isDataRoamingEnabled"; |
Shuo Qian | 093013d | 2020-08-13 15:42:55 -0700 | [diff] [blame] | 9033 | try { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 9034 | try { |
| 9035 | mApp.enforceCallingOrSelfPermission( |
| 9036 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 9037 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 9038 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 9039 | mApp.enforceCallingOrSelfPermission( |
| 9040 | permission.READ_BASIC_PHONE_STATE, functionName); |
| 9041 | } |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 9042 | } catch (SecurityException e) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9043 | TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 9044 | mApp, subId, functionName); |
Shuo Qian | 093013d | 2020-08-13 15:42:55 -0700 | [diff] [blame] | 9045 | } |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 9046 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9047 | boolean isEnabled = false; |
| 9048 | final long identity = Binder.clearCallingIdentity(); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9049 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9050 | Phone phone = getPhone(subId); |
| 9051 | isEnabled = phone != null ? phone.getDataRoamingEnabled() : false; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9052 | } finally { |
| 9053 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9054 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9055 | return isEnabled; |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9056 | } |
| 9057 | |
| 9058 | |
| 9059 | /** |
| 9060 | * Enables/Disables the data roaming on the subscription with id {@code subId}. |
| 9061 | * |
| 9062 | * <p> Requires permission: |
| 9063 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier |
| 9064 | * privileges. |
| 9065 | * |
| 9066 | * @param subId subscription id |
| 9067 | * @param isEnabled {@code true} means enable, {@code false} means disable. |
| 9068 | */ |
| 9069 | @Override |
| 9070 | public void setDataRoamingEnabled(int subId, boolean isEnabled) { |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 9071 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9072 | mApp, subId, "setDataRoamingEnabled"); |
| 9073 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9074 | final long identity = Binder.clearCallingIdentity(); |
| 9075 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9076 | Phone phone = getPhone(subId); |
| 9077 | if (phone != null) { |
| 9078 | phone.setDataRoamingEnabled(isEnabled); |
| 9079 | } |
| 9080 | } finally { |
| 9081 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9082 | } |
| 9083 | } |
| 9084 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9085 | @Override |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 9086 | public boolean isManualNetworkSelectionAllowed(int subId) { |
tom hsu | c91afc7 | 2020-01-06 23:46:07 +0800 | [diff] [blame] | 9087 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9088 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 9089 | mApp, subId, "isManualNetworkSelectionAllowed"); |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 9090 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 9091 | boolean isAllowed = true; |
| 9092 | final long identity = Binder.clearCallingIdentity(); |
| 9093 | try { |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 9094 | Phone phone = getPhone(subId); |
| 9095 | if (phone != null) { |
| 9096 | isAllowed = phone.isCspPlmnEnabled(); |
| 9097 | } |
| 9098 | } finally { |
| 9099 | Binder.restoreCallingIdentity(identity); |
| 9100 | } |
| 9101 | return isAllowed; |
| 9102 | } |
| 9103 | |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9104 | private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) { |
| 9105 | UiccProfile profile = port.getUiccProfile(); |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 9106 | if (profile == null) { |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9107 | return false; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9108 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 9109 | Phone phone = PhoneFactory.getPhone(profile.getPhoneId()); |
| 9110 | if (phone == null) { |
| 9111 | return false; |
| 9112 | } |
| 9113 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 9114 | return cpt != null && cpt.getCarrierPrivilegeStatusForPackage(callingPackage) |
| 9115 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9116 | } |
| 9117 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 9118 | @Override |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 9119 | public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) { |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9120 | // Verify that the callingPackage belongs to the calling UID |
Jordan Liu | 4cda455 | 2020-03-23 11:55:07 -0700 | [diff] [blame] | 9121 | mApp.getSystemService(AppOpsManager.class) |
| 9122 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 9123 | |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9124 | boolean hasReadPermission = false; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9125 | boolean isIccIdAccessRestricted = false; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 9126 | try { |
| 9127 | enforceReadPrivilegedPermission("getUiccCardsInfo"); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9128 | hasReadPermission = true; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 9129 | } catch (SecurityException e) { |
| 9130 | // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller |
| 9131 | // has carrier privileges on an active UICC |
Rambo Wang | e7209ce | 2022-02-23 13:41:02 -0800 | [diff] [blame] | 9132 | if (checkCarrierPrivilegesForPackageAnyPhoneWithPermission(callingPackage) |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 9133 | != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9134 | throw new SecurityException("Caller does not have permission."); |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 9135 | } |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 9136 | } |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9137 | // checking compatibility, if calling app's target SDK is T and beyond. |
| 9138 | if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO, |
| 9139 | Binder.getCallingUid())) { |
| 9140 | isIccIdAccessRestricted = true; |
| 9141 | } |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 9142 | final long identity = Binder.clearCallingIdentity(); |
| 9143 | try { |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 9144 | UiccController uiccController = UiccController.getInstance(); |
| 9145 | ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos(); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9146 | if (hasReadPermission) { |
| 9147 | return cardInfos; |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 9148 | } |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9149 | |
| 9150 | // Remove private info if the caller doesn't have access |
| 9151 | ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>(); |
| 9152 | for (UiccCardInfo cardInfo : cardInfos) { |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9153 | //setting the value after compatibility check |
| 9154 | cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9155 | // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo |
| 9156 | // is available |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9157 | UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex()); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9158 | if (card == null) { |
| 9159 | // assume no access if the card is unavailable |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9160 | filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo)); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9161 | continue; |
| 9162 | } |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9163 | Collection<UiccPortInfo> portInfos = cardInfo.getPorts(); |
| 9164 | if (portInfos.isEmpty()) { |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9165 | filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo)); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9166 | continue; |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9167 | } |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9168 | List<UiccPortInfo> uiccPortInfos = new ArrayList<>(); |
| 9169 | for (UiccPortInfo portInfo : portInfos) { |
| 9170 | UiccPort port = uiccController.getUiccPortForSlot( |
| 9171 | cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex()); |
| 9172 | if (port == null) { |
| 9173 | // assume no access if port is null |
| 9174 | uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo)); |
| 9175 | continue; |
| 9176 | } |
| 9177 | if (haveCarrierPrivilegeAccess(port, callingPackage)) { |
| 9178 | uiccPortInfos.add(portInfo); |
| 9179 | } else { |
| 9180 | uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo)); |
| 9181 | } |
| 9182 | } |
| 9183 | filteredInfos.add(new UiccCardInfo( |
| 9184 | cardInfo.isEuicc(), |
| 9185 | cardInfo.getCardId(), |
| 9186 | null, |
| 9187 | cardInfo.getPhysicalSlotIndex(), |
| 9188 | cardInfo.isRemovable(), |
| 9189 | cardInfo.isMultipleEnabledProfilesSupported(), |
| 9190 | uiccPortInfos)); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9191 | } |
| 9192 | return filteredInfos; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 9193 | } finally { |
| 9194 | Binder.restoreCallingIdentity(identity); |
| 9195 | } |
| 9196 | } |
| 9197 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9198 | /** |
| 9199 | * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are |
| 9200 | * generally private and require carrier privileges to view. |
| 9201 | * |
| 9202 | * @hide |
| 9203 | */ |
| 9204 | @NonNull |
| 9205 | public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) { |
| 9206 | List<UiccPortInfo> portinfo = new ArrayList<>(); |
| 9207 | for (UiccPortInfo portinfos : cardInfo.getPorts()) { |
| 9208 | portinfo.add(getUiccPortInfoUnPrivileged(portinfos)); |
| 9209 | } |
| 9210 | return new UiccCardInfo( |
| 9211 | cardInfo.isEuicc(), |
| 9212 | cardInfo.getCardId(), |
| 9213 | null, |
| 9214 | cardInfo.getPhysicalSlotIndex(), |
| 9215 | cardInfo.isRemovable(), |
| 9216 | cardInfo.isMultipleEnabledProfilesSupported(), |
| 9217 | portinfo |
| 9218 | ); |
| 9219 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9220 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9221 | /** |
| 9222 | * @hide |
| 9223 | * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}. |
| 9224 | * These values are generally private and require carrier privileges to view. |
| 9225 | */ |
| 9226 | @NonNull |
| 9227 | public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) { |
| 9228 | return new UiccPortInfo( |
| 9229 | UiccPortInfo.ICCID_REDACTED, |
| 9230 | portInfo.getPortIndex(), |
| 9231 | portInfo.getLogicalSlotIndex(), |
| 9232 | portInfo.isActive() |
| 9233 | ); |
| 9234 | } |
| 9235 | @Override |
| 9236 | public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) { |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9237 | // Verify that the callingPackage belongs to the calling UID |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9238 | mApp.getSystemService(AppOpsManager.class) |
| 9239 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 9240 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9241 | boolean isLogicalSlotAccessRestricted = false; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9242 | |
Aman Gupta | f3c90b3 | 2022-03-17 04:54:16 +0000 | [diff] [blame] | 9243 | // This will make sure caller has the READ_PRIVILEGED_PHONE_STATE. Do not remove this as |
| 9244 | // we are reading iccId which is PII data. |
| 9245 | enforceReadPrivilegedPermission("getUiccSlotsInfo"); |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9246 | |
| 9247 | // checking compatibility, if calling app's target SDK is T and beyond. |
| 9248 | if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO, |
| 9249 | Binder.getCallingUid())) { |
| 9250 | isLogicalSlotAccessRestricted = true; |
| 9251 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9252 | final long identity = Binder.clearCallingIdentity(); |
| 9253 | try { |
| 9254 | UiccSlot[] slots = UiccController.getInstance().getUiccSlots(); |
Muralidhar Reddy | d196bbf | 2022-01-17 17:56:30 +0000 | [diff] [blame] | 9255 | if (slots == null || slots.length == 0) { |
| 9256 | Rlog.i(LOG_TAG, "slots is null or empty."); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9257 | return null; |
| 9258 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9259 | UiccSlotInfo[] infos = new UiccSlotInfo[slots.length]; |
| 9260 | for (int i = 0; i < slots.length; i++) { |
| 9261 | UiccSlot slot = slots[i]; |
| 9262 | if (slot == null) { |
| 9263 | continue; |
| 9264 | } |
| 9265 | |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 9266 | String cardId; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9267 | UiccCard card = slot.getUiccCard(); |
| 9268 | if (card != null) { |
| 9269 | cardId = card.getCardId(); |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 9270 | } else { |
Jordan Liu | 01bd00d | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 9271 | cardId = slot.getEid(); |
| 9272 | if (TextUtils.isEmpty(cardId)) { |
Aman Gupta | f3c90b3 | 2022-03-17 04:54:16 +0000 | [diff] [blame] | 9273 | // If cardId is null, use iccId of default port as cardId. |
| 9274 | cardId = slot.getIccId(TelephonyManager.DEFAULT_PORT_INDEX); |
Jordan Liu | 01bd00d | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 9275 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9276 | } |
| 9277 | |
Jordan Liu | 857451f | 2019-05-09 16:35:35 -0700 | [diff] [blame] | 9278 | if (cardId != null) { |
| 9279 | // if cardId is an ICCID, strip off trailing Fs before exposing to user |
| 9280 | // if cardId is an EID, it's all digits so this is fine |
| 9281 | cardId = IccUtils.stripTrailingFs(cardId); |
| 9282 | } |
| 9283 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9284 | int cardState = 0; |
| 9285 | switch (slot.getCardState()) { |
| 9286 | case CARDSTATE_ABSENT: |
| 9287 | cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT; |
| 9288 | break; |
| 9289 | case CARDSTATE_PRESENT: |
| 9290 | cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT; |
| 9291 | break; |
| 9292 | case CARDSTATE_ERROR: |
| 9293 | cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR; |
| 9294 | break; |
| 9295 | case CARDSTATE_RESTRICTED: |
| 9296 | cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED; |
| 9297 | break; |
| 9298 | default: |
| 9299 | break; |
| 9300 | |
| 9301 | } |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9302 | List<UiccPortInfo> portInfos = new ArrayList<>(); |
| 9303 | int[] portIndexes = slot.getPortList(); |
| 9304 | for (int portIdx : portIndexes) { |
| 9305 | String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx, |
Aman Gupta | f3c90b3 | 2022-03-17 04:54:16 +0000 | [diff] [blame] | 9306 | callingPackage, /* hasReadPermission= */ true)); |
Muralidhar Reddy | fbcff0c | 2022-01-19 13:07:57 +0000 | [diff] [blame] | 9307 | portInfos.add(new UiccPortInfo(iccId, portIdx, |
| 9308 | slot.getPhoneIdFromPortIndex(portIdx), slot.isPortActive(portIdx))); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9309 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9310 | infos[i] = new UiccSlotInfo( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9311 | slot.isEuicc(), |
| 9312 | cardId, |
| 9313 | cardState, |
Jordan Liu | a261958 | 2019-02-14 12:56:40 -0800 | [diff] [blame] | 9314 | slot.isExtendedApduSupported(), |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9315 | slot.isRemovable(), portInfos); |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9316 | //setting the value after compatibility check |
| 9317 | infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9318 | } |
| 9319 | return infos; |
| 9320 | } finally { |
| 9321 | Binder.restoreCallingIdentity(identity); |
Holly Jiuyu Sun | 1d957c5 | 2018-04-04 13:52:42 -0700 | [diff] [blame] | 9322 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9323 | } |
| 9324 | |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9325 | /* Returns null if doesn't have read permission or carrier privilege access. */ |
| 9326 | private String getIccId(UiccSlot slot, int portIndex, String callingPackage, |
| 9327 | boolean hasReadPermission) { |
| 9328 | String iccId = slot.getIccId(portIndex); |
| 9329 | if (hasReadPermission) { // if has read permission |
| 9330 | return iccId; |
| 9331 | } else { |
| 9332 | if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) { |
| 9333 | UiccPort port = slot.getUiccCard().getUiccPort(portIndex); |
| 9334 | // if no read permission, checking carrier privilege access |
| 9335 | if (haveCarrierPrivilegeAccess(port, callingPackage)) { |
| 9336 | return iccId; |
| 9337 | } |
| 9338 | } |
| 9339 | } |
| 9340 | // No read permission or carrier privilege access. |
| 9341 | return UiccPortInfo.ICCID_REDACTED; |
| 9342 | } |
| 9343 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9344 | @Override |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9345 | @Deprecated |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9346 | public boolean switchSlots(int[] physicalSlots) { |
| 9347 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9348 | |
| 9349 | final long identity = Binder.clearCallingIdentity(); |
| 9350 | try { |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9351 | List<UiccSlotMapping> slotMappings = new ArrayList<>(); |
| 9352 | for (int i = 0; i < physicalSlots.length; i++) { |
| 9353 | // Deprecated API, hence MEP is not supported. Adding default portIndex 0. |
| 9354 | slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX, |
| 9355 | physicalSlots[i], i)); |
| 9356 | } |
| 9357 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9358 | } finally { |
| 9359 | Binder.restoreCallingIdentity(identity); |
| 9360 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9361 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 9362 | |
| 9363 | @Override |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9364 | @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 9365 | public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) { |
| 9366 | enforceModifyPermission(); |
| 9367 | |
| 9368 | final long identity = Binder.clearCallingIdentity(); |
| 9369 | try { |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9370 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping); |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9371 | } finally { |
| 9372 | Binder.restoreCallingIdentity(identity); |
| 9373 | } |
| 9374 | } |
| 9375 | |
| 9376 | @Override |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 9377 | public int getCardIdForDefaultEuicc(int subId, String callingPackage) { |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 9378 | final long identity = Binder.clearCallingIdentity(); |
| 9379 | try { |
| 9380 | return UiccController.getInstance().getCardIdForDefaultEuicc(); |
| 9381 | } finally { |
| 9382 | Binder.restoreCallingIdentity(identity); |
| 9383 | } |
| 9384 | } |
| 9385 | |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9386 | /** |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 9387 | * A test API to reload the UICC profile. |
| 9388 | * |
| 9389 | * <p>Requires that the calling app has permission |
| 9390 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 9391 | * @hide |
| 9392 | */ |
| 9393 | @Override |
| 9394 | public void refreshUiccProfile(int subId) { |
| 9395 | enforceModifyPermission(); |
| 9396 | |
| 9397 | final long identity = Binder.clearCallingIdentity(); |
| 9398 | try { |
| 9399 | Phone phone = getPhone(subId); |
| 9400 | if (phone == null) { |
| 9401 | return; |
| 9402 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9403 | UiccPort uiccPort = phone.getUiccPort(); |
| 9404 | if (uiccPort == null) { |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 9405 | return; |
| 9406 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9407 | UiccProfile uiccProfile = uiccPort.getUiccProfile(); |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 9408 | if (uiccProfile == null) { |
| 9409 | return; |
| 9410 | } |
| 9411 | uiccProfile.refresh(); |
| 9412 | } finally { |
| 9413 | Binder.restoreCallingIdentity(identity); |
| 9414 | } |
| 9415 | } |
| 9416 | |
| 9417 | /** |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9418 | * Returns false if the mobile data is disabled by default, otherwise return true. |
| 9419 | */ |
| 9420 | private boolean getDefaultDataEnabled() { |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 9421 | return TelephonyProperties.mobile_data().orElse(true); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9422 | } |
| 9423 | |
| 9424 | /** |
| 9425 | * Returns true if the data roaming is enabled by default, i.e the system property |
| 9426 | * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of |
| 9427 | * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true. |
| 9428 | */ |
| 9429 | private boolean getDefaultDataRoamingEnabled(int subId) { |
| 9430 | final CarrierConfigManager configMgr = (CarrierConfigManager) |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9431 | mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Shuo Qian | 1d84a0e | 2020-07-15 12:36:44 -0700 | [diff] [blame] | 9432 | boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9433 | isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean( |
| 9434 | CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL); |
| 9435 | return isDataRoamingEnabled; |
| 9436 | } |
| 9437 | |
| 9438 | /** |
| 9439 | * Returns the default network type for the given {@code subId}, if the default network type is |
| 9440 | * not set, return {@link Phone#PREFERRED_NT_MODE}. |
| 9441 | */ |
| 9442 | private int getDefaultNetworkType(int subId) { |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 9443 | List<Integer> list = TelephonyProperties.default_network(); |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 9444 | int phoneId = SubscriptionManager.getPhoneId(subId); |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 9445 | if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) { |
| 9446 | return list.get(phoneId); |
| 9447 | } |
| 9448 | return Phone.PREFERRED_NT_MODE; |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9449 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9450 | |
| 9451 | @Override |
| 9452 | public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 9453 | gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) { |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9454 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9455 | |
| 9456 | final long identity = Binder.clearCallingIdentity(); |
| 9457 | try { |
| 9458 | final Phone phone = getPhone(subId); |
| 9459 | if (phone == null) { |
| 9460 | loge("setCarrierTestOverride fails with invalid subId: " + subId); |
| 9461 | return; |
| 9462 | } |
Rambo Wang | 9c9ffdd | 2022-01-13 21:51:44 -0800 | [diff] [blame] | 9463 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 9464 | if (cpt != null) { |
| 9465 | cpt.setTestOverrideCarrierPrivilegeRules(carrierPrivilegeRules); |
| 9466 | } |
| 9467 | // 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] | 9468 | phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn, |
| 9469 | carrierPrivilegeRules, apn); |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 9470 | if (carrierPrivilegeRules == null) { |
| 9471 | mCarrierPrivilegeTestOverrideSubIds.remove(subId); |
| 9472 | } else { |
| 9473 | mCarrierPrivilegeTestOverrideSubIds.add(subId); |
| 9474 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9475 | } finally { |
| 9476 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9477 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9478 | } |
| 9479 | |
| 9480 | @Override |
Benedict Wong | 6647762 | 2023-02-03 23:30:57 +0000 | [diff] [blame] | 9481 | public void setCarrierServicePackageOverride( |
| 9482 | int subId, String carrierServicePackage, String callingPackage) { |
| 9483 | TelephonyPermissions.enforceShellOnly( |
| 9484 | Binder.getCallingUid(), "setCarrierServicePackageOverride"); |
| 9485 | |
| 9486 | // Verify that the callingPackage belongs to the calling UID |
| 9487 | mApp.getSystemService(AppOpsManager.class) |
| 9488 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 9489 | |
| 9490 | final long identity = Binder.clearCallingIdentity(); |
| 9491 | try { |
| 9492 | final Phone phone = getPhone(subId); |
| 9493 | if (phone == null || phone.getSubId() != subId) { |
| 9494 | loge("setCarrierServicePackageOverride fails with invalid subId: " + subId); |
| 9495 | throw new IllegalArgumentException("No phone for subid"); |
| 9496 | } |
| 9497 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 9498 | if (cpt == null) { |
| 9499 | loge("setCarrierServicePackageOverride failed with no CPT for phone"); |
| 9500 | throw new IllegalStateException("No CPT for phone"); |
| 9501 | } |
| 9502 | cpt.setTestOverrideCarrierServicePackage(carrierServicePackage); |
| 9503 | } finally { |
| 9504 | Binder.restoreCallingIdentity(identity); |
| 9505 | } |
| 9506 | } |
| 9507 | |
| 9508 | @Override |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9509 | public int getCarrierIdListVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 9510 | enforceReadPrivilegedPermission("getCarrierIdListVersion"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9511 | |
| 9512 | final long identity = Binder.clearCallingIdentity(); |
| 9513 | try { |
| 9514 | final Phone phone = getPhone(subId); |
| 9515 | if (phone == null) { |
| 9516 | loge("getCarrierIdListVersion fails with invalid subId: " + subId); |
| 9517 | return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION; |
| 9518 | } |
| 9519 | return phone.getCarrierIdListVersion(); |
| 9520 | } finally { |
| 9521 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9522 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9523 | } |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 9524 | |
| 9525 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9526 | public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage, |
| 9527 | String callingFeatureId) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 9528 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9529 | mApp, subId, callingPackage, callingFeatureId, |
| 9530 | "getNumberOfModemsWithSimultaneousDataConnections")) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 9531 | return -1; |
| 9532 | } |
| 9533 | |
| 9534 | final long identity = Binder.clearCallingIdentity(); |
| 9535 | try { |
| 9536 | return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections(); |
| 9537 | } finally { |
| 9538 | Binder.restoreCallingIdentity(identity); |
| 9539 | } |
| 9540 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9541 | |
| 9542 | @Override |
| 9543 | public int getCdmaRoamingMode(int subId) { |
zoey chen | 7e6d4e5 | 2019-12-17 18:18:59 +0800 | [diff] [blame] | 9544 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9545 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 9546 | mApp, subId, "getCdmaRoamingMode"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9547 | |
| 9548 | final long identity = Binder.clearCallingIdentity(); |
| 9549 | try { |
| 9550 | return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId); |
| 9551 | } finally { |
| 9552 | Binder.restoreCallingIdentity(identity); |
| 9553 | } |
| 9554 | } |
| 9555 | |
| 9556 | @Override |
| 9557 | public boolean setCdmaRoamingMode(int subId, int mode) { |
| 9558 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9559 | mApp, subId, "setCdmaRoamingMode"); |
| 9560 | |
| 9561 | final long identity = Binder.clearCallingIdentity(); |
| 9562 | try { |
| 9563 | return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId); |
| 9564 | } finally { |
| 9565 | Binder.restoreCallingIdentity(identity); |
| 9566 | } |
| 9567 | } |
| 9568 | |
| 9569 | @Override |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 9570 | public int getCdmaSubscriptionMode(int subId) { |
| 9571 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9572 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 9573 | mApp, subId, "getCdmaSubscriptionMode"); |
| 9574 | |
| 9575 | final long identity = Binder.clearCallingIdentity(); |
| 9576 | try { |
| 9577 | return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId); |
| 9578 | } finally { |
| 9579 | Binder.restoreCallingIdentity(identity); |
| 9580 | } |
| 9581 | } |
| 9582 | |
| 9583 | @Override |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9584 | public boolean setCdmaSubscriptionMode(int subId, int mode) { |
| 9585 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9586 | mApp, subId, "setCdmaSubscriptionMode"); |
| 9587 | |
| 9588 | final long identity = Binder.clearCallingIdentity(); |
| 9589 | try { |
| 9590 | return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId); |
| 9591 | } finally { |
| 9592 | Binder.restoreCallingIdentity(identity); |
| 9593 | } |
| 9594 | } |
Makoto Onuki | da3bf79 | 2018-09-18 16:06:29 -0700 | [diff] [blame] | 9595 | |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 9596 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 9597 | public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9598 | String callingPackage, String callingFeatureId) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9599 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9600 | mApp, getDefaultSubscription(), callingPackage, callingFeatureId, |
| 9601 | "getEmergencyNumberList")) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9602 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 9603 | } |
| 9604 | final long identity = Binder.clearCallingIdentity(); |
| 9605 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 9606 | Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>(); |
| 9607 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9608 | if (phone.getEmergencyNumberTracker() != null |
| 9609 | && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) { |
| 9610 | emergencyNumberListInternal.put( |
| 9611 | phone.getSubId(), |
| 9612 | phone.getEmergencyNumberTracker().getEmergencyNumberList()); |
| 9613 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9614 | } |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 9615 | return emergencyNumberListInternal; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9616 | } finally { |
| 9617 | Binder.restoreCallingIdentity(identity); |
| 9618 | } |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 9619 | } |
| 9620 | |
| 9621 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 9622 | public boolean isEmergencyNumber(String number, boolean exactMatch) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9623 | final Phone defaultPhone = getDefaultPhone(); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9624 | if (!exactMatch) { |
| 9625 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9626 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 9627 | mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)"); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9628 | } |
| 9629 | final long identity = Binder.clearCallingIdentity(); |
| 9630 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 9631 | for (Phone phone: PhoneFactory.getPhones()) { |
Chinmay Dhodapkar | d521bb1 | 2022-08-16 15:49:54 -0700 | [diff] [blame] | 9632 | //Note: we ignore passed in param exactMatch. We can remove it once |
| 9633 | // TelephonyManager#isPotentialEmergencyNumber is removed completely |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 9634 | if (phone.getEmergencyNumberTracker() != null |
Taesu Lee | e050c00 | 2020-10-13 17:19:35 +0900 | [diff] [blame] | 9635 | && phone.getEmergencyNumberTracker() |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 9636 | .isEmergencyNumber(number)) { |
Taesu Lee | e050c00 | 2020-10-13 17:19:35 +0900 | [diff] [blame] | 9637 | return true; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9638 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9639 | } |
| 9640 | return false; |
| 9641 | } finally { |
| 9642 | Binder.restoreCallingIdentity(identity); |
| 9643 | } |
| 9644 | } |
| 9645 | |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 9646 | /** |
Shuo Qian | ccbaf74 | 2021-02-22 18:32:21 -0800 | [diff] [blame] | 9647 | * Start emergency callback mode for GsmCdmaPhone for testing. |
| 9648 | */ |
| 9649 | @Override |
| 9650 | public void startEmergencyCallbackMode() { |
| 9651 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9652 | "startEmergencyCallbackMode"); |
| 9653 | enforceModifyPermission(); |
| 9654 | final long identity = Binder.clearCallingIdentity(); |
| 9655 | try { |
| 9656 | for (Phone phone : PhoneFactory.getPhones()) { |
| 9657 | Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType()); |
| 9658 | if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM) |
| 9659 | || (phone.getPhoneType() == PHONE_TYPE_CDMA))) { |
| 9660 | GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone; |
| 9661 | gsmCdmaPhone.obtainMessage( |
| 9662 | GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget(); |
| 9663 | Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered"); |
| 9664 | } |
| 9665 | } |
| 9666 | } finally { |
| 9667 | Binder.restoreCallingIdentity(identity); |
| 9668 | } |
| 9669 | } |
| 9670 | |
| 9671 | /** |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 9672 | * Update emergency number list for test mode. |
| 9673 | */ |
| 9674 | @Override |
| 9675 | public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) { |
| 9676 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9677 | "updateEmergencyNumberListTestMode"); |
| 9678 | |
| 9679 | final long identity = Binder.clearCallingIdentity(); |
| 9680 | try { |
| 9681 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9682 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9683 | if (tracker != null) { |
| 9684 | tracker.executeEmergencyNumberTestModeCommand(action, num); |
| 9685 | } |
| 9686 | } |
| 9687 | } finally { |
| 9688 | Binder.restoreCallingIdentity(identity); |
| 9689 | } |
| 9690 | } |
| 9691 | |
| 9692 | /** |
| 9693 | * Get the full emergency number list for test mode. |
| 9694 | */ |
| 9695 | @Override |
| 9696 | public List<String> getEmergencyNumberListTestMode() { |
| 9697 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9698 | "getEmergencyNumberListTestMode"); |
| 9699 | |
| 9700 | final long identity = Binder.clearCallingIdentity(); |
| 9701 | try { |
| 9702 | Set<String> emergencyNumbers = new HashSet<>(); |
| 9703 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9704 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9705 | if (tracker != null) { |
| 9706 | for (EmergencyNumber num : tracker.getEmergencyNumberList()) { |
| 9707 | emergencyNumbers.add(num.getNumber()); |
| 9708 | } |
| 9709 | } |
| 9710 | } |
| 9711 | return new ArrayList<>(emergencyNumbers); |
| 9712 | } finally { |
| 9713 | Binder.restoreCallingIdentity(identity); |
| 9714 | } |
| 9715 | } |
| 9716 | |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 9717 | @Override |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 9718 | public int getEmergencyNumberDbVersion(int subId) { |
| 9719 | enforceReadPrivilegedPermission("getEmergencyNumberDbVersion"); |
| 9720 | |
| 9721 | final long identity = Binder.clearCallingIdentity(); |
| 9722 | try { |
| 9723 | final Phone phone = getPhone(subId); |
| 9724 | if (phone == null) { |
| 9725 | loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId); |
| 9726 | return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION; |
| 9727 | } |
| 9728 | return phone.getEmergencyNumberDbVersion(); |
| 9729 | } finally { |
| 9730 | Binder.restoreCallingIdentity(identity); |
| 9731 | } |
| 9732 | } |
| 9733 | |
| 9734 | @Override |
| 9735 | public void notifyOtaEmergencyNumberDbInstalled() { |
| 9736 | enforceModifyPermission(); |
| 9737 | |
| 9738 | final long identity = Binder.clearCallingIdentity(); |
| 9739 | try { |
| 9740 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9741 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9742 | if (tracker != null) { |
| 9743 | tracker.updateOtaEmergencyNumberDatabase(); |
| 9744 | } |
| 9745 | } |
| 9746 | } finally { |
| 9747 | Binder.restoreCallingIdentity(identity); |
| 9748 | } |
| 9749 | } |
| 9750 | |
| 9751 | @Override |
Shuo Qian | c373f11 | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 9752 | public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) { |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 9753 | enforceActiveEmergencySessionPermission(); |
| 9754 | |
| 9755 | final long identity = Binder.clearCallingIdentity(); |
| 9756 | try { |
| 9757 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9758 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9759 | if (tracker != null) { |
Shuo Qian | c373f11 | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 9760 | tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor); |
| 9761 | } |
| 9762 | } |
| 9763 | } finally { |
| 9764 | Binder.restoreCallingIdentity(identity); |
| 9765 | } |
| 9766 | } |
| 9767 | |
| 9768 | @Override |
| 9769 | public void resetOtaEmergencyNumberDbFilePath() { |
| 9770 | enforceActiveEmergencySessionPermission(); |
| 9771 | |
| 9772 | final long identity = Binder.clearCallingIdentity(); |
| 9773 | try { |
| 9774 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9775 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9776 | if (tracker != null) { |
| 9777 | tracker.resetOtaEmergencyNumberDbFilePath(); |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 9778 | } |
| 9779 | } |
| 9780 | } finally { |
| 9781 | Binder.restoreCallingIdentity(identity); |
| 9782 | } |
| 9783 | } |
| 9784 | |
| 9785 | @Override |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 9786 | public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) { |
| 9787 | enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules"); |
| 9788 | Phone phone = getPhone(subId); |
| 9789 | if (phone == null) { |
| 9790 | return null; |
| 9791 | } |
| 9792 | final long identity = Binder.clearCallingIdentity(); |
| 9793 | try { |
| 9794 | UiccProfile profile = UiccController.getInstance() |
| 9795 | .getUiccProfileForPhone(phone.getPhoneId()); |
| 9796 | if (profile != null) { |
| 9797 | return profile.getCertsFromCarrierPrivilegeAccessRules(); |
| 9798 | } |
| 9799 | } finally { |
| 9800 | Binder.restoreCallingIdentity(identity); |
| 9801 | } |
| 9802 | return null; |
| 9803 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 9804 | |
| 9805 | /** |
| 9806 | * Enable or disable a modem stack. |
| 9807 | */ |
| 9808 | @Override |
| 9809 | public boolean enableModemForSlot(int slotIndex, boolean enable) { |
| 9810 | enforceModifyPermission(); |
| 9811 | |
| 9812 | final long identity = Binder.clearCallingIdentity(); |
| 9813 | try { |
| 9814 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 9815 | if (phone == null) { |
| 9816 | return false; |
| 9817 | } else { |
| 9818 | return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null); |
| 9819 | } |
| 9820 | } finally { |
| 9821 | Binder.restoreCallingIdentity(identity); |
| 9822 | } |
| 9823 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9824 | |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 9825 | /** |
| 9826 | * Whether a modem stack is enabled or not. |
| 9827 | */ |
| 9828 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9829 | public boolean isModemEnabledForSlot(int slotIndex, String callingPackage, |
| 9830 | String callingFeatureId) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 9831 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 9832 | if (phone == null) return false; |
| 9833 | |
| 9834 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9835 | mApp, phone.getSubId(), callingPackage, callingFeatureId, |
| 9836 | "isModemEnabledForSlot")) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 9837 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 9838 | } |
| 9839 | |
| 9840 | final long identity = Binder.clearCallingIdentity(); |
| 9841 | try { |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 9842 | try { |
| 9843 | return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId()); |
| 9844 | } catch (NoSuchElementException ex) { |
| 9845 | return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null); |
| 9846 | } |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 9847 | } finally { |
| 9848 | Binder.restoreCallingIdentity(identity); |
| 9849 | } |
| 9850 | } |
| 9851 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9852 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9853 | public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) { |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9854 | enforceModifyPermission(); |
| 9855 | |
| 9856 | final long identity = Binder.clearCallingIdentity(); |
| 9857 | try { |
| 9858 | mTelephonySharedPreferences.edit() |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9859 | .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted) |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9860 | .commit(); |
| 9861 | } finally { |
| 9862 | Binder.restoreCallingIdentity(identity); |
| 9863 | } |
| 9864 | } |
| 9865 | |
| 9866 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9867 | @TelephonyManager.IsMultiSimSupportedResult |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9868 | public int isMultiSimSupported(String callingPackage, String callingFeatureId) { |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 9869 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9870 | getDefaultPhone().getSubId(), callingPackage, callingFeatureId, |
| 9871 | "isMultiSimSupported")) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9872 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 9873 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9874 | |
| 9875 | final long identity = Binder.clearCallingIdentity(); |
| 9876 | try { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9877 | return isMultiSimSupportedInternal(); |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9878 | } finally { |
| 9879 | Binder.restoreCallingIdentity(identity); |
| 9880 | } |
| 9881 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9882 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9883 | @TelephonyManager.IsMultiSimSupportedResult |
| 9884 | private int isMultiSimSupportedInternal() { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9885 | // If the device has less than 2 SIM cards, indicate that multisim is restricted. |
| 9886 | int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length; |
| 9887 | if (numPhysicalSlots < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9888 | loge("isMultiSimSupportedInternal: requires at least 2 cards"); |
| 9889 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9890 | } |
| 9891 | // Check if the hardware supports multisim functionality. If usage of multisim is not |
| 9892 | // supported by the modem, indicate that it is restricted. |
| 9893 | PhoneCapability staticCapability = |
| 9894 | mPhoneConfigurationManager.getStaticPhoneCapability(); |
| 9895 | if (staticCapability == null) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9896 | loge("isMultiSimSupportedInternal: no static configuration available"); |
| 9897 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9898 | } |
SongFerngWang | 8236caa | 2021-01-17 21:51:44 +0800 | [diff] [blame] | 9899 | if (staticCapability.getLogicalModemList().size() < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9900 | loge("isMultiSimSupportedInternal: maximum number of modem is < 2"); |
| 9901 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9902 | } |
| 9903 | // Check if support of multiple SIMs is restricted by carrier |
| 9904 | if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9905 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9906 | } |
| 9907 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9908 | return TelephonyManager.MULTISIM_ALLOWED; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9909 | } |
| 9910 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9911 | /** |
| 9912 | * Switch configs to enable multi-sim or switch back to single-sim |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 9913 | * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE |
| 9914 | * permission, but the other way around is possible with either MODIFY_PHONE_STATE |
| 9915 | * or carrier privileges |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9916 | * @param numOfSims number of active sims we want to switch to |
| 9917 | */ |
| 9918 | @Override |
| 9919 | public void switchMultiSimConfig(int numOfSims) { |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 9920 | if (numOfSims == 1) { |
| 9921 | enforceModifyPermission(); |
| 9922 | } else { |
| 9923 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9924 | mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig"); |
| 9925 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9926 | final long identity = Binder.clearCallingIdentity(); |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9927 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9928 | try { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9929 | //only proceed if multi-sim is not restricted |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9930 | if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9931 | loge("switchMultiSimConfig not possible. It is restricted or not supported."); |
| 9932 | return; |
| 9933 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9934 | mPhoneConfigurationManager.switchMultiSimConfig(numOfSims); |
| 9935 | } finally { |
| 9936 | Binder.restoreCallingIdentity(identity); |
| 9937 | } |
| 9938 | } |
| 9939 | |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 9940 | @Override |
| 9941 | public boolean isApplicationOnUicc(int subId, int appType) { |
| 9942 | enforceReadPrivilegedPermission("isApplicationOnUicc"); |
| 9943 | Phone phone = getPhone(subId); |
| 9944 | if (phone == null) { |
| 9945 | return false; |
| 9946 | } |
| 9947 | final long identity = Binder.clearCallingIdentity(); |
| 9948 | try { |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9949 | UiccPort uiccPort = phone.getUiccPort(); |
| 9950 | if (uiccPort == null) { |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 9951 | return false; |
| 9952 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9953 | UiccProfile uiccProfile = uiccPort.getUiccProfile(); |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 9954 | if (uiccProfile == null) { |
| 9955 | return false; |
| 9956 | } |
| 9957 | if (TelephonyManager.APPTYPE_SIM <= appType |
| 9958 | && appType <= TelephonyManager.APPTYPE_ISIM) { |
| 9959 | return uiccProfile.isApplicationOnIcc(AppType.values()[appType]); |
| 9960 | } |
| 9961 | return false; |
| 9962 | } finally { |
| 9963 | Binder.restoreCallingIdentity(identity); |
| 9964 | } |
| 9965 | } |
| 9966 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9967 | /** |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 9968 | * Get whether making changes to modem configurations will trigger reboot. |
| 9969 | * Return value defaults to true. |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 9970 | */ |
| 9971 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9972 | public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage, |
| 9973 | String callingFeatureId) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 9974 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9975 | mApp, subId, callingPackage, callingFeatureId, |
| 9976 | "doesSwitchMultiSimConfigTriggerReboot")) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 9977 | return false; |
| 9978 | } |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 9979 | final long identity = Binder.clearCallingIdentity(); |
| 9980 | try { |
| 9981 | return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange(); |
| 9982 | } finally { |
| 9983 | Binder.restoreCallingIdentity(identity); |
| 9984 | } |
| 9985 | } |
| 9986 | |
Nathan Harold | 29f5f05 | 2019-02-15 13:41:57 -0800 | [diff] [blame] | 9987 | private void updateModemStateMetrics() { |
| 9988 | TelephonyMetrics metrics = TelephonyMetrics.getInstance(); |
| 9989 | // TODO: check the state for each modem if the api is ready. |
| 9990 | metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1); |
| 9991 | } |
| 9992 | |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 9993 | @Override |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9994 | public List<UiccSlotMapping> getSlotsMapping(String callingPackage) { |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 9995 | enforceReadPrivilegedPermission("getSlotsMapping"); |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9996 | // Verify that the callingPackage belongs to the calling UID |
| 9997 | mApp.getSystemService(AppOpsManager.class) |
| 9998 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 9999 | final long identity = Binder.clearCallingIdentity(); |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 10000 | List<UiccSlotMapping> slotMap = new ArrayList<>(); |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10001 | try { |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 10002 | UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName()); |
| 10003 | if (slotInfos != null) { |
| 10004 | for (int i = 0; i < slotInfos.length; i++) { |
| 10005 | for (UiccPortInfo portInfo : slotInfos[i].getPorts()) { |
| 10006 | if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) { |
| 10007 | slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i, |
| 10008 | portInfo.getLogicalSlotIndex())); |
| 10009 | } |
| 10010 | } |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10011 | } |
| 10012 | } |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 10013 | return slotMap; |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10014 | } finally { |
| 10015 | Binder.restoreCallingIdentity(identity); |
| 10016 | } |
| 10017 | } |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 10018 | |
| 10019 | /** |
| 10020 | * Get the IRadio HAL Version |
jimsun | f9ec162 | 2022-09-13 21:18:43 +0800 | [diff] [blame] | 10021 | * @deprecated use getHalVersion instead |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 10022 | */ |
jimsun | f9ec162 | 2022-09-13 21:18:43 +0800 | [diff] [blame] | 10023 | @Deprecated |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 10024 | @Override |
| 10025 | public int getRadioHalVersion() { |
jimsun | f9ec162 | 2022-09-13 21:18:43 +0800 | [diff] [blame] | 10026 | return getHalVersion(HAL_SERVICE_RADIO); |
| 10027 | } |
| 10028 | |
| 10029 | /** |
| 10030 | * Get the HAL Version of a specific service |
| 10031 | */ |
| 10032 | @Override |
| 10033 | public int getHalVersion(int service) { |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 10034 | Phone phone = getDefaultPhone(); |
| 10035 | if (phone == null) return -1; |
jimsun | f9ec162 | 2022-09-13 21:18:43 +0800 | [diff] [blame] | 10036 | HalVersion hv = phone.getHalVersion(service); |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 10037 | if (hv.equals(HalVersion.UNKNOWN)) return -1; |
| 10038 | return hv.major * 100 + hv.minor; |
| 10039 | } |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 10040 | |
| 10041 | /** |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 10042 | * Get the current calling package name. |
| 10043 | * @return the current calling package name |
| 10044 | */ |
| 10045 | @Override |
| 10046 | public String getCurrentPackageName() { |
| 10047 | return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0]; |
| 10048 | } |
| 10049 | |
| 10050 | /** |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10051 | * Return whether data is enabled for certain APN type. This will tell if framework will accept |
| 10052 | * corresponding network requests on a subId. |
| 10053 | * |
| 10054 | * Data is enabled if: |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 10055 | * 1) user data is turned on, or |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10056 | * 2) APN is un-metered for this subscription, or |
| 10057 | * 3) APN type is whitelisted. E.g. MMS is whitelisted if |
Hall Liu | 746e03c | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 10058 | * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled. |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10059 | * |
| 10060 | * @return whether data is allowed for a apn type. |
| 10061 | * |
| 10062 | * @hide |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 10063 | */ |
| 10064 | @Override |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10065 | public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) { |
Amit Mahajan | 5d4e192 | 2019-10-07 16:20:43 -0700 | [diff] [blame] | 10066 | enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for " |
| 10067 | + "isDataEnabledForApn"); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 10068 | |
| 10069 | // Now that all security checks passes, perform the operation as ourselves. |
| 10070 | final long identity = Binder.clearCallingIdentity(); |
| 10071 | try { |
| 10072 | Phone phone = getPhone(subId); |
| 10073 | if (phone == null) return false; |
| 10074 | |
Jack Yu | 27422a5 | 2022-03-21 10:38:05 -0700 | [diff] [blame] | 10075 | boolean isMetered; |
Jack Yu | 99e8733 | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 10076 | boolean isDataEnabled; |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 10077 | isMetered = phone.getDataNetworkController().getDataConfigManager() |
| 10078 | .isMeteredCapability(DataUtils.apnTypeToNetworkCapability(apnType), |
| 10079 | phone.getServiceState().getDataRoaming()); |
| 10080 | isDataEnabled = phone.getDataSettingsManager().isDataEnabled(apnType); |
Jack Yu | 99e8733 | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 10081 | return !isMetered || isDataEnabled; |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10082 | } finally { |
| 10083 | Binder.restoreCallingIdentity(identity); |
| 10084 | } |
| 10085 | } |
| 10086 | |
| 10087 | @Override |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 10088 | public boolean isApnMetered(@ApnType int apnType, int subId) { |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10089 | enforceReadPrivilegedPermission("isApnMetered"); |
| 10090 | |
| 10091 | // Now that all security checks passes, perform the operation as ourselves. |
| 10092 | final long identity = Binder.clearCallingIdentity(); |
| 10093 | try { |
| 10094 | Phone phone = getPhone(subId); |
| 10095 | if (phone == null) return true; // By default return true. |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 10096 | return phone.getDataNetworkController().getDataConfigManager().isMeteredCapability( |
| 10097 | DataUtils.apnTypeToNetworkCapability(apnType), |
| 10098 | phone.getServiceState().getDataRoaming()); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 10099 | } finally { |
| 10100 | Binder.restoreCallingIdentity(identity); |
| 10101 | } |
| 10102 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 10103 | |
| 10104 | @Override |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 10105 | public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers, |
| 10106 | int subscriptionId, IBooleanConsumer resultCallback) { |
| 10107 | enforceModifyPermission(); |
| 10108 | long token = Binder.clearCallingIdentity(); |
| 10109 | try { |
| 10110 | Phone phone = getPhone(subscriptionId); |
| 10111 | if (phone == null) { |
| 10112 | try { |
| 10113 | if (resultCallback != null) { |
| 10114 | resultCallback.accept(false); |
| 10115 | } |
| 10116 | } catch (RemoteException e) { |
| 10117 | // ignore |
| 10118 | } |
| 10119 | return; |
| 10120 | } |
| 10121 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument = |
| 10122 | Pair.create(specifiers, (x) -> { |
| 10123 | try { |
| 10124 | if (resultCallback != null) { |
| 10125 | resultCallback.accept(x); |
| 10126 | } |
| 10127 | } catch (RemoteException e) { |
| 10128 | // ignore |
| 10129 | } |
| 10130 | }); |
| 10131 | sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null); |
| 10132 | } finally { |
| 10133 | Binder.restoreCallingIdentity(token); |
| 10134 | } |
| 10135 | } |
| 10136 | |
| 10137 | @Override |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 10138 | public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) { |
| 10139 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 10140 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 10141 | mApp, subId, "getSystemSelectionChannels"); |
| 10142 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 10143 | final long identity = Binder.clearCallingIdentity(); |
| 10144 | try { |
Sarah Chin | 428d1d6 | 2021-03-13 03:17:40 -0800 | [diff] [blame] | 10145 | Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource); |
| 10146 | if (result instanceof IllegalStateException) { |
| 10147 | throw (IllegalStateException) result; |
| 10148 | } |
| 10149 | List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 10150 | if (DBG) log("getSystemSelectionChannels: " + specifiers); |
| 10151 | return specifiers; |
| 10152 | } finally { |
| 10153 | Binder.restoreCallingIdentity(identity); |
| 10154 | } |
| 10155 | } |
| 10156 | |
| 10157 | @Override |
Jack Yu | 8b766fc | 2022-03-21 09:42:33 -0700 | [diff] [blame] | 10158 | public boolean isMvnoMatched(int slotIndex, int mvnoType, @NonNull String mvnoMatchData) { |
changbetty | ca3d40d | 2020-03-03 16:27:31 +0800 | [diff] [blame] | 10159 | enforceReadPrivilegedPermission("isMvnoMatched"); |
Jack Yu | 8b766fc | 2022-03-21 09:42:33 -0700 | [diff] [blame] | 10160 | return UiccController.getInstance().mvnoMatches(slotIndex, mvnoType, mvnoMatchData); |
changbetty | 7157e9e | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 10161 | } |
| 10162 | |
| 10163 | @Override |
Philip P. Moltmann | d02b737 | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 10164 | public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag, |
| 10165 | IIntegerConsumer pendingSubIdResult) { |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 10166 | if (callingPackage == null) { |
| 10167 | callingPackage = getCurrentPackageName(); |
| 10168 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 10169 | SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp, |
| 10170 | (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE)); |
Philip P. Moltmann | d02b737 | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 10171 | if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag, |
| 10172 | "Sending message")) { |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 10173 | throw new SecurityException("Requires SEND_SMS permission to perform this operation"); |
| 10174 | } |
| 10175 | PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult); |
| 10176 | Intent intent = new Intent(); |
| 10177 | intent.setClass(mApp, PickSmsSubscriptionActivity.class); |
| 10178 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 10179 | // Bring up choose default SMS subscription dialog right now |
| 10180 | intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY, |
| 10181 | PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE); |
| 10182 | mApp.startActivity(intent); |
| 10183 | } |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 10184 | |
| 10185 | @Override |
Ayush Sharma | 787854b | 2022-12-12 14:55:02 +0000 | [diff] [blame] | 10186 | public void showSwitchToManagedProfileDialog() { |
| 10187 | enforceModifyPermission(); |
Anthony Alridge | 70ba557 | 2023-05-02 12:14:14 +0000 | [diff] [blame] | 10188 | try { |
| 10189 | // Note: This intent is constructed to ensure that the IntentForwarderActivity is |
| 10190 | // shown in accordance with the intent filters in DefaultCrossProfileIntentFilterUtils |
| 10191 | // for work telephony. |
| 10192 | Intent intent = new Intent(Intent.ACTION_SENDTO); |
| 10193 | intent.setData(Uri.parse("smsto:")); |
| 10194 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 10195 | mApp.startActivity(intent); |
| 10196 | } catch (ActivityNotFoundException e) { |
| 10197 | Log.w(LOG_TAG, "Unable to show intent forwarder, try showing error dialog instead"); |
| 10198 | Intent intent = new Intent(); |
| 10199 | intent.setClass(mApp, ErrorDialogActivity.class); |
| 10200 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 10201 | mApp.startActivity(intent); |
| 10202 | } |
Ayush Sharma | 787854b | 2022-12-12 14:55:02 +0000 | [diff] [blame] | 10203 | } |
| 10204 | |
| 10205 | @Override |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 10206 | public String getMmsUAProfUrl(int subId) { |
| 10207 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 10208 | final long identity = Binder.clearCallingIdentity(); |
| 10209 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 10210 | String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString( |
| 10211 | CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING); |
| 10212 | if (!TextUtils.isEmpty(carrierUAProfUrl)) { |
| 10213 | return carrierUAProfUrl; |
| 10214 | } |
Daniel Bright | ebb4eb7 | 2020-02-18 15:16:33 -0800 | [diff] [blame] | 10215 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 10216 | .getString(com.android.internal.R.string.config_mms_user_agent_profile_url); |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 10217 | } finally { |
| 10218 | Binder.restoreCallingIdentity(identity); |
| 10219 | } |
| 10220 | } |
| 10221 | |
| 10222 | @Override |
| 10223 | public String getMmsUserAgent(int subId) { |
| 10224 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 10225 | final long identity = Binder.clearCallingIdentity(); |
| 10226 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 10227 | String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString( |
| 10228 | CarrierConfigManager.KEY_MMS_USER_AGENT_STRING); |
| 10229 | if (!TextUtils.isEmpty(carrierUserAgent)) { |
| 10230 | return carrierUserAgent; |
| 10231 | } |
Daniel Bright | ebb4eb7 | 2020-02-18 15:16:33 -0800 | [diff] [blame] | 10232 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 10233 | .getString(com.android.internal.R.string.config_mms_user_agent); |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 10234 | } finally { |
| 10235 | Binder.restoreCallingIdentity(identity); |
| 10236 | } |
| 10237 | } |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 10238 | |
| 10239 | @Override |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 10240 | public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) { |
| 10241 | enforceReadPrivilegedPermission("isMobileDataPolicyEnabled"); |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 10242 | |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 10243 | final long identity = Binder.clearCallingIdentity(); |
| 10244 | try { |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 10245 | Phone phone = getPhone(subscriptionId); |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 10246 | if (phone == null) return false; |
| 10247 | |
Ling Ma | f188d50 | 2022-09-16 15:22:36 -0700 | [diff] [blame] | 10248 | return phone.getDataSettingsManager().isMobileDataPolicyEnabled(policy); |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 10249 | } finally { |
| 10250 | Binder.restoreCallingIdentity(identity); |
| 10251 | } |
| 10252 | } |
| 10253 | |
| 10254 | @Override |
Hall Liu | c66bb11 | 2021-02-02 12:09:32 -0800 | [diff] [blame] | 10255 | public void setMobileDataPolicyEnabled(int subscriptionId, int policy, |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 10256 | boolean enabled) { |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 10257 | enforceModifyPermission(); |
| 10258 | |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 10259 | final long identity = Binder.clearCallingIdentity(); |
| 10260 | try { |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 10261 | Phone phone = getPhone(subscriptionId); |
| 10262 | if (phone == null) return; |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 10263 | |
Ling Ma | f188d50 | 2022-09-16 15:22:36 -0700 | [diff] [blame] | 10264 | phone.getDataSettingsManager().setMobileDataPolicy(policy, enabled); |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 10265 | } finally { |
| 10266 | Binder.restoreCallingIdentity(identity); |
| 10267 | } |
| 10268 | } |
| 10269 | |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 10270 | /** |
Hall Liu | 746e03c | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 10271 | * Updates whether conference event package handling is enabled. |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 10272 | * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false} |
| 10273 | * otherwise. |
| 10274 | */ |
| 10275 | @Override |
| 10276 | public void setCepEnabled(boolean isCepEnabled) { |
| 10277 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled"); |
| 10278 | |
| 10279 | final long identity = Binder.clearCallingIdentity(); |
| 10280 | try { |
| 10281 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled); |
| 10282 | for (Phone phone : PhoneFactory.getPhones()) { |
| 10283 | Phone defaultPhone = phone.getImsPhone(); |
| 10284 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 10285 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 10286 | ImsPhoneCallTracker imsPhoneCallTracker = |
| 10287 | (ImsPhoneCallTracker) imsPhone.getCallTracker(); |
| 10288 | imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled); |
| 10289 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone " |
| 10290 | + imsPhone.getMsisdn()); |
| 10291 | } |
| 10292 | } |
| 10293 | } finally { |
| 10294 | Binder.restoreCallingIdentity(identity); |
| 10295 | } |
| 10296 | } |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 10297 | |
| 10298 | /** |
| 10299 | * Notify that an RCS autoconfiguration XML file has been received for provisioning. |
| 10300 | * |
| 10301 | * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed. |
| 10302 | * @param isCompressed The XML file is compressed in gzip format and must be decompressed |
| 10303 | * before being read. |
| 10304 | */ |
| 10305 | @Override |
| 10306 | public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean |
| 10307 | isCompressed) { |
| 10308 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 10309 | mApp, subId, "notifyRcsAutoConfigurationReceived"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10310 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10311 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10312 | } |
| 10313 | if (!isImsAvailableOnDevice()) { |
joonhunshin | 46b49a3 | 2022-12-21 05:33:23 +0000 | [diff] [blame] | 10314 | // ProvisioningManager can not handle ServiceSpecificException. |
| 10315 | // Throw the IllegalStateException and annotate ProvisioningManager. |
| 10316 | throw new IllegalStateException("IMS not available on device."); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10317 | } |
| 10318 | |
| 10319 | final long identity = Binder.clearCallingIdentity(); |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 10320 | try { |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10321 | RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed); |
| 10322 | } finally { |
| 10323 | Binder.restoreCallingIdentity(identity); |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 10324 | } |
| 10325 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 10326 | |
| 10327 | @Override |
| 10328 | public boolean isIccLockEnabled(int subId) { |
| 10329 | enforceReadPrivilegedPermission("isIccLockEnabled"); |
| 10330 | |
| 10331 | // Now that all security checks passes, perform the operation as ourselves. |
| 10332 | final long identity = Binder.clearCallingIdentity(); |
| 10333 | try { |
| 10334 | Phone phone = getPhone(subId); |
| 10335 | if (phone != null && phone.getIccCard() != null) { |
| 10336 | return phone.getIccCard().getIccLockEnabled(); |
| 10337 | } else { |
| 10338 | return false; |
| 10339 | } |
| 10340 | } finally { |
| 10341 | Binder.restoreCallingIdentity(identity); |
| 10342 | } |
| 10343 | } |
| 10344 | |
| 10345 | /** |
| 10346 | * Set the ICC pin lock enabled or disabled. |
| 10347 | * |
| 10348 | * @return an integer representing the status of IccLock enabled or disabled in the following |
| 10349 | * three cases: |
| 10350 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock |
| 10351 | * successfully. |
| 10352 | * - Positive number and zero for remaining password attempts. |
| 10353 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
| 10354 | * |
| 10355 | */ |
| 10356 | @Override |
| 10357 | public int setIccLockEnabled(int subId, boolean enabled, String password) { |
| 10358 | enforceModifyPermission(); |
| 10359 | |
| 10360 | Phone phone = getPhone(subId); |
| 10361 | if (phone == null) { |
| 10362 | return 0; |
| 10363 | } |
| 10364 | // Now that all security checks passes, perform the operation as ourselves. |
| 10365 | final long identity = Binder.clearCallingIdentity(); |
| 10366 | try { |
| 10367 | int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED, |
| 10368 | new Pair<Boolean, String>(enabled, password), phone, null); |
| 10369 | return attemptsRemaining; |
| 10370 | |
| 10371 | } catch (Exception e) { |
| 10372 | Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e); |
| 10373 | } finally { |
| 10374 | Binder.restoreCallingIdentity(identity); |
| 10375 | } |
| 10376 | return 0; |
| 10377 | } |
| 10378 | |
| 10379 | /** |
| 10380 | * Change the ICC password used in ICC pin lock. |
| 10381 | * |
| 10382 | * @return an integer representing the status of IccLock changed in the following three cases: |
| 10383 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock 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 changeIccLockPassword(int subId, String oldPassword, String newPassword) { |
| 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_CHANGE_ICC_LOCK_PASSWORD, |
| 10400 | new Pair<String, String>(oldPassword, newPassword), phone, null); |
| 10401 | return attemptsRemaining; |
| 10402 | |
| 10403 | } catch (Exception e) { |
| 10404 | Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e); |
| 10405 | } finally { |
| 10406 | Binder.restoreCallingIdentity(identity); |
| 10407 | } |
| 10408 | return 0; |
| 10409 | } |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 10410 | |
| 10411 | /** |
| 10412 | * Request for receiving user activity notification |
| 10413 | */ |
| 10414 | @Override |
| 10415 | public void requestUserActivityNotification() { |
| 10416 | if (!mNotifyUserActivity.get() |
| 10417 | && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) { |
| 10418 | mNotifyUserActivity.set(true); |
| 10419 | } |
| 10420 | } |
| 10421 | |
| 10422 | /** |
| 10423 | * Called when userActivity is signalled in the power manager. |
| 10424 | * This is safe to call from any thread, with any window manager locks held or not. |
| 10425 | */ |
| 10426 | @Override |
| 10427 | public void userActivity() { |
| 10428 | // *************************************** |
| 10429 | // * Inherited from PhoneWindowManager * |
| 10430 | // *************************************** |
| 10431 | // THIS IS CALLED FROM DEEP IN THE POWER MANAGER |
| 10432 | // WITH ITS LOCKS HELD. |
| 10433 | // |
| 10434 | // This code must be VERY careful about the locks |
| 10435 | // it acquires. |
| 10436 | // In fact, the current code acquires way too many, |
| 10437 | // and probably has lurking deadlocks. |
| 10438 | |
| 10439 | if (Binder.getCallingUid() != Process.SYSTEM_UID) { |
| 10440 | throw new SecurityException("Only the OS may call notifyUserActivity()"); |
| 10441 | } |
| 10442 | |
| 10443 | if (mNotifyUserActivity.getAndSet(false)) { |
| 10444 | mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY, |
| 10445 | USER_ACTIVITY_NOTIFICATION_DELAY); |
| 10446 | } |
| 10447 | } |
Malcolm Chen | 4639c56 | 2020-04-13 11:59:40 -0700 | [diff] [blame] | 10448 | |
| 10449 | @Override |
| 10450 | public boolean canConnectTo5GInDsdsMode() { |
| 10451 | return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode); |
| 10452 | } |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 10453 | |
| 10454 | @Override |
| 10455 | public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage, |
| 10456 | String callingFeatureId) { |
| 10457 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 10458 | mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) { |
| 10459 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 10460 | } |
| 10461 | |
| 10462 | Phone phone = getPhone(subId); |
| 10463 | if (phone == null) { |
| 10464 | throw new RuntimeException("phone is not available"); |
| 10465 | } |
| 10466 | // Now that all security checks passes, perform the operation as ourselves. |
| 10467 | final long identity = Binder.clearCallingIdentity(); |
| 10468 | try { |
| 10469 | return phone.getEquivalentHomePlmns(); |
| 10470 | } finally { |
| 10471 | Binder.restoreCallingIdentity(identity); |
| 10472 | } |
| 10473 | } |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 10474 | |
| 10475 | @Override |
| 10476 | public boolean isRadioInterfaceCapabilitySupported( |
Daniel Bright | 95a4c1f | 2021-02-11 09:57:16 -0800 | [diff] [blame] | 10477 | final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) { |
| 10478 | Set<String> radioInterfaceCapabilities = |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 10479 | mRadioInterfaceCapabilities.getCapabilities(); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 10480 | if (radioInterfaceCapabilities == null) { |
| 10481 | throw new RuntimeException("radio interface capabilities are not available"); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 10482 | } |
Daniel Bright | 95a4c1f | 2021-02-11 09:57:16 -0800 | [diff] [blame] | 10483 | return radioInterfaceCapabilities.contains(capability); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 10484 | } |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10485 | |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 10486 | @Override |
| 10487 | public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl, |
| 10488 | UaSecurityProtocolIdentifier securityProtocol, |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10489 | boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) { |
| 10490 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 10491 | Binder.getCallingUid(), "bootstrapAuthenticationRequest", |
| 10492 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 10493 | Manifest.permission.MODIFY_PHONE_STATE); |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 10494 | if (DBG) { |
| 10495 | log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:" |
| 10496 | + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol |
| 10497 | + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback); |
| 10498 | } |
| 10499 | |
| 10500 | if (!SubscriptionManager.isValidSubscriptionId(subId) |
| 10501 | || appType < TelephonyManager.APPTYPE_UNKNOWN |
| 10502 | || appType > TelephonyManager.APPTYPE_ISIM |
| 10503 | || nafUrl == null || securityProtocol == null || callback == null) { |
| 10504 | Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters"); |
| 10505 | if (callback != null) { |
| 10506 | try { |
| 10507 | callback.onAuthenticationFailure( |
| 10508 | 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED); |
| 10509 | } catch (RemoteException exception) { |
| 10510 | log("Fail to notify onAuthenticationFailure due to " + exception); |
| 10511 | } |
| 10512 | return; |
| 10513 | } |
| 10514 | } |
| 10515 | |
| 10516 | final long token = Binder.clearCallingIdentity(); |
| 10517 | try { |
| 10518 | getGbaManager(subId).bootstrapAuthenticationRequest( |
| 10519 | new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(), |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 10520 | forceBootStrapping, callback)); |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 10521 | } finally { |
| 10522 | Binder.restoreCallingIdentity(token); |
| 10523 | } |
| 10524 | } |
| 10525 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10526 | /** |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10527 | * Attempts to set the radio power state for all phones for thermal reason. |
| 10528 | * This does not guarantee that the |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10529 | * requested radio power state will actually be set. See {@link |
| 10530 | * PhoneInternalInterface#setRadioPowerForReason} for more details. |
| 10531 | * |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10532 | * @param enable {@code true} if trying to turn radio on. |
| 10533 | * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code |
| 10534 | * false}. |
| 10535 | */ |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10536 | private boolean setRadioPowerForThermal(boolean enable) { |
| 10537 | boolean isPhoneAvailable = false; |
| 10538 | for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) { |
| 10539 | Phone phone = PhoneFactory.getPhone(i); |
| 10540 | if (phone != null) { |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 10541 | phone.setRadioPowerForReason(enable, TelephonyManager.RADIO_POWER_REASON_THERMAL); |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10542 | isPhoneAvailable = true; |
| 10543 | } |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10544 | } |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10545 | |
| 10546 | // return true if successfully informed the phone object about the thermal radio power |
| 10547 | // request. |
| 10548 | return isPhoneAvailable; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10549 | } |
| 10550 | |
| 10551 | private int handleDataThrottlingRequest(int subId, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 10552 | DataThrottlingRequest dataThrottlingRequest, String callingPackage) { |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10553 | boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported( |
| 10554 | TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING); |
| 10555 | if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction() |
| 10556 | != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) { |
| 10557 | throw new IllegalArgumentException("modem does not support data throttling"); |
| 10558 | } |
| 10559 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10560 | // Ensure that radio is on. If not able to power on due to phone being unavailable, return |
| 10561 | // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10562 | if (!setRadioPowerForThermal(true)) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10563 | return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 10564 | } |
| 10565 | |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 10566 | setDataEnabledForReason( |
| 10567 | subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true, callingPackage); |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10568 | |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10569 | if (isDataThrottlingSupported) { |
| 10570 | int thermalMitigationResult = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 10571 | (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId); |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10572 | if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) { |
| 10573 | throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS"); |
| 10574 | } else if (thermalMitigationResult |
| 10575 | == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) { |
Jack Nudelman | 760d096 | 2021-05-20 13:57:30 -0700 | [diff] [blame] | 10576 | log("Modem likely does not support data throttling on secondary carrier. Data " + |
| 10577 | "throttling action = " + dataThrottlingRequest.getDataThrottlingAction()); |
| 10578 | return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10579 | } |
| 10580 | return thermalMitigationResult; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10581 | } |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10582 | |
| 10583 | return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10584 | } |
| 10585 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10586 | private static List<String> getThermalMitigationAllowlist(Context context) { |
| 10587 | if (sThermalMitigationAllowlistedPackages.isEmpty()) { |
| 10588 | for (String pckg : context.getResources() |
| 10589 | .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) { |
| 10590 | sThermalMitigationAllowlistedPackages.add(pckg); |
| 10591 | } |
| 10592 | } |
| 10593 | |
| 10594 | return sThermalMitigationAllowlistedPackages; |
| 10595 | } |
| 10596 | |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 10597 | private boolean isAnyPhoneInEmergencyState() { |
| 10598 | TelecomManager tm = mApp.getSystemService(TelecomManager.class); |
| 10599 | if (tm.isInEmergencyCall()) { |
| 10600 | Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call"); |
| 10601 | return true; |
| 10602 | } |
| 10603 | for (Phone phone : PhoneFactory.getPhones()) { |
| 10604 | if (phone.isInEmergencySmsMode() || phone.isInEcm()) { |
| 10605 | Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = " |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 10606 | + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = " |
| 10607 | + phone.isInEcm()); |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 10608 | return true; |
| 10609 | } |
| 10610 | } |
| 10611 | |
| 10612 | return false; |
| 10613 | } |
| 10614 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10615 | /** |
| 10616 | * Used by shell commands to add an authorized package name for thermal mitigation. |
| 10617 | * @param packageName name of package to be allowlisted |
| 10618 | * @param context |
| 10619 | */ |
| 10620 | static void addPackageToThermalMitigationAllowlist(String packageName, Context context) { |
| 10621 | sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context); |
| 10622 | sThermalMitigationAllowlistedPackages.add(packageName); |
| 10623 | } |
| 10624 | |
| 10625 | /** |
| 10626 | * Used by shell commands to remove an authorized package name for thermal mitigation. |
| 10627 | * @param packageName name of package to remove from allowlist |
| 10628 | * @param context |
| 10629 | */ |
| 10630 | static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) { |
| 10631 | sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context); |
| 10632 | sThermalMitigationAllowlistedPackages.remove(packageName); |
| 10633 | } |
| 10634 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10635 | /** |
| 10636 | * Thermal mitigation request to control functionalities at modem. |
| 10637 | * |
| 10638 | * @param subId the id of the subscription. |
| 10639 | * @param thermalMitigationRequest holds all necessary information to be passed down to modem. |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10640 | * @param callingPackage the package name of the calling package. |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10641 | * |
| 10642 | * @return thermalMitigationResult enum as defined in android.telephony.Annotation. |
| 10643 | */ |
| 10644 | @Override |
| 10645 | @ThermalMitigationResult |
| 10646 | public int sendThermalMitigationRequest( |
| 10647 | int subId, |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10648 | ThermalMitigationRequest thermalMitigationRequest, |
| 10649 | String callingPackage) throws IllegalArgumentException { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10650 | enforceModifyPermission(); |
| 10651 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10652 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 10653 | if (!getThermalMitigationAllowlist(getDefaultPhone().getContext()) |
| 10654 | .contains(callingPackage)) { |
| 10655 | throw new SecurityException("Calling package must be configured in the device config. " |
| 10656 | + "calling package: " + callingPackage); |
| 10657 | } |
| 10658 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10659 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 10660 | final long identity = Binder.clearCallingIdentity(); |
| 10661 | |
| 10662 | int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR; |
| 10663 | try { |
| 10664 | int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction(); |
| 10665 | switch (thermalMitigationAction) { |
| 10666 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING: |
| 10667 | thermalMitigationResult = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 10668 | handleDataThrottlingRequest(subId, |
| 10669 | thermalMitigationRequest.getDataThrottlingRequest(), |
| 10670 | callingPackage); |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10671 | break; |
| 10672 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY: |
| 10673 | if (thermalMitigationRequest.getDataThrottlingRequest() != null) { |
| 10674 | throw new IllegalArgumentException("dataThrottlingRequest must be null for " |
| 10675 | + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY"); |
| 10676 | } |
| 10677 | |
| 10678 | // Ensure that radio is on. If not able to power on due to phone being |
| 10679 | // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10680 | if (!setRadioPowerForThermal(true)) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10681 | thermalMitigationResult = |
| 10682 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 10683 | break; |
| 10684 | } |
| 10685 | |
| 10686 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 10687 | false, callingPackage); |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10688 | thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 10689 | break; |
| 10690 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF: |
| 10691 | if (thermalMitigationRequest.getDataThrottlingRequest() != null) { |
| 10692 | throw new IllegalArgumentException("dataThrottlingRequest must be null for" |
| 10693 | + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF"); |
| 10694 | } |
| 10695 | |
| 10696 | TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null); |
| 10697 | if (registry != null) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10698 | Phone phone = getPhone(subId); |
| 10699 | if (phone == null) { |
| 10700 | thermalMitigationResult = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 10701 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10702 | break; |
| 10703 | } |
| 10704 | |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 10705 | TelephonyConnectionService service = |
| 10706 | registry.getTelephonyConnectionService(); |
Jack Nudelman | b30ac30 | 2021-06-17 15:39:58 -0700 | [diff] [blame] | 10707 | if (service != null && service.isEmergencyCallPending()) { |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 10708 | Log.e(LOG_TAG, "An emergency call is pending"); |
| 10709 | thermalMitigationResult = |
| 10710 | TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE; |
| 10711 | break; |
| 10712 | } else if (isAnyPhoneInEmergencyState()) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10713 | thermalMitigationResult = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 10714 | TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10715 | break; |
| 10716 | } |
| 10717 | } else { |
| 10718 | thermalMitigationResult = |
| 10719 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 10720 | break; |
| 10721 | } |
| 10722 | |
| 10723 | // Turn radio off. If not able to power off due to phone being unavailable, |
| 10724 | // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10725 | if (!setRadioPowerForThermal(false)) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10726 | thermalMitigationResult = |
| 10727 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 10728 | break; |
| 10729 | } |
| 10730 | thermalMitigationResult = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 10731 | TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10732 | break; |
| 10733 | default: |
| 10734 | throw new IllegalArgumentException("the requested thermalMitigationAction does " |
| 10735 | + "not exist. Requested action: " + thermalMitigationAction); |
| 10736 | } |
| 10737 | } catch (IllegalArgumentException e) { |
| 10738 | throw e; |
| 10739 | } catch (Exception e) { |
| 10740 | Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e); |
| 10741 | thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 10742 | } finally { |
| 10743 | Binder.restoreCallingIdentity(identity); |
| 10744 | } |
| 10745 | |
| 10746 | if (DBG) { |
| 10747 | log("thermalMitigationRequest returning with thermalMitigationResult: " |
| 10748 | + thermalMitigationResult); |
| 10749 | } |
| 10750 | |
| 10751 | return thermalMitigationResult; |
| 10752 | } |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 10753 | |
| 10754 | /** |
| 10755 | * Set the GbaService Package Name that Telephony will bind to. |
| 10756 | * |
| 10757 | * @param subId The sim that the GbaService is associated with. |
| 10758 | * @param packageName The name of the package to be replaced with. |
| 10759 | * @return true if setting the GbaService to bind to succeeded, false if it did not. |
| 10760 | */ |
| 10761 | @Override |
| 10762 | public boolean setBoundGbaServiceOverride(int subId, String packageName) { |
| 10763 | enforceModifyPermission(); |
| 10764 | |
| 10765 | final long identity = Binder.clearCallingIdentity(); |
| 10766 | try { |
| 10767 | return getGbaManager(subId).overrideServicePackage(packageName); |
| 10768 | } finally { |
| 10769 | Binder.restoreCallingIdentity(identity); |
| 10770 | } |
| 10771 | } |
| 10772 | |
| 10773 | /** |
| 10774 | * Return the package name of the currently bound GbaService. |
| 10775 | * |
| 10776 | * @param subId The sim that the GbaService is associated with. |
| 10777 | * @return the package name of the GbaService configuration, null if GBA is not supported. |
| 10778 | */ |
| 10779 | @Override |
| 10780 | public String getBoundGbaService(int subId) { |
| 10781 | enforceReadPrivilegedPermission("getBoundGbaServicePackage"); |
| 10782 | |
| 10783 | final long identity = Binder.clearCallingIdentity(); |
| 10784 | try { |
| 10785 | return getGbaManager(subId).getServicePackage(); |
| 10786 | } finally { |
| 10787 | Binder.restoreCallingIdentity(identity); |
| 10788 | } |
| 10789 | } |
| 10790 | |
| 10791 | /** |
| 10792 | * Set the release time for telephony to unbind GbaService. |
| 10793 | * |
| 10794 | * @param subId The sim that the GbaService is associated with. |
| 10795 | * @param interval The release time to unbind GbaService by millisecond. |
| 10796 | * @return true if setting the GbaService to bind to succeeded, false if it did not. |
| 10797 | */ |
| 10798 | @Override |
| 10799 | public boolean setGbaReleaseTimeOverride(int subId, int interval) { |
| 10800 | enforceModifyPermission(); |
| 10801 | |
| 10802 | final long identity = Binder.clearCallingIdentity(); |
| 10803 | try { |
| 10804 | return getGbaManager(subId).overrideReleaseTime(interval); |
| 10805 | } finally { |
| 10806 | Binder.restoreCallingIdentity(identity); |
| 10807 | } |
| 10808 | } |
| 10809 | |
| 10810 | /** |
| 10811 | * Return the release time for telephony to unbind GbaService. |
| 10812 | * |
| 10813 | * @param subId The sim that the GbaService is associated with. |
| 10814 | * @return The release time to unbind GbaService by millisecond. |
| 10815 | */ |
| 10816 | @Override |
| 10817 | public int getGbaReleaseTime(int subId) { |
| 10818 | enforceReadPrivilegedPermission("getGbaReleaseTime"); |
| 10819 | |
| 10820 | final long identity = Binder.clearCallingIdentity(); |
| 10821 | try { |
| 10822 | return getGbaManager(subId).getReleaseTime(); |
| 10823 | } finally { |
| 10824 | Binder.restoreCallingIdentity(identity); |
| 10825 | } |
| 10826 | } |
| 10827 | |
| 10828 | private GbaManager getGbaManager(int subId) { |
| 10829 | GbaManager instance = GbaManager.getInstance(subId); |
| 10830 | if (instance == null) { |
| 10831 | String packageName = mApp.getResources().getString(R.string.config_gba_package); |
| 10832 | int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time); |
| 10833 | instance = GbaManager.make(mApp, subId, packageName, releaseTime); |
| 10834 | } |
| 10835 | return instance; |
| 10836 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10837 | |
| 10838 | /** |
| 10839 | * indicate whether the device and the carrier can support |
| 10840 | * RCS VoLTE single registration. |
| 10841 | */ |
| 10842 | @Override |
| 10843 | public boolean isRcsVolteSingleRegistrationCapable(int subId) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10844 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 10845 | Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable", |
| 10846 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 10847 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10848 | |
| 10849 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10850 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10851 | } |
| 10852 | |
| 10853 | final long identity = Binder.clearCallingIdentity(); |
| 10854 | try { |
| 10855 | RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance(); |
| 10856 | if (rpm != null) { |
Hui Wang | 67af90e | 2021-06-04 16:57:15 -0700 | [diff] [blame] | 10857 | Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId); |
| 10858 | if (isCapable != null) { |
| 10859 | return isCapable; |
| 10860 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10861 | } |
Hui Wang | 67af90e | 2021-06-04 16:57:15 -0700 | [diff] [blame] | 10862 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE, |
| 10863 | "service is temporarily unavailable."); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10864 | } finally { |
| 10865 | Binder.restoreCallingIdentity(identity); |
| 10866 | } |
| 10867 | } |
| 10868 | |
| 10869 | /** |
| 10870 | * Register RCS provisioning callback. |
| 10871 | */ |
| 10872 | @Override |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10873 | public void registerRcsProvisioningCallback(int subId, |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10874 | IRcsConfigCallback callback) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10875 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10876 | Binder.getCallingUid(), "registerRcsProvisioningCallback", |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10877 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 10878 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10879 | |
| 10880 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10881 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10882 | } |
| 10883 | if (!isImsAvailableOnDevice()) { |
| 10884 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 10885 | "IMS not available on device."); |
| 10886 | } |
| 10887 | |
| 10888 | final long identity = Binder.clearCallingIdentity(); |
| 10889 | try { |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 10890 | if (!RcsProvisioningMonitor.getInstance() |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10891 | .registerRcsProvisioningCallback(subId, callback)) { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 10892 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION, |
| 10893 | "Active subscription not found."); |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 10894 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10895 | } finally { |
| 10896 | Binder.restoreCallingIdentity(identity); |
| 10897 | } |
| 10898 | } |
| 10899 | |
| 10900 | /** |
| 10901 | * Unregister RCS provisioning callback. |
| 10902 | */ |
| 10903 | @Override |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10904 | public void unregisterRcsProvisioningCallback(int subId, |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10905 | IRcsConfigCallback callback) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10906 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10907 | Binder.getCallingUid(), "unregisterRcsProvisioningCallback", |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10908 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 10909 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10910 | |
| 10911 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10912 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10913 | } |
| 10914 | if (!isImsAvailableOnDevice()) { |
joonhunshin | 46b49a3 | 2022-12-21 05:33:23 +0000 | [diff] [blame] | 10915 | // operation failed silently |
| 10916 | Rlog.w(LOG_TAG, "IMS not available on device."); |
| 10917 | return; |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10918 | } |
| 10919 | |
| 10920 | final long identity = Binder.clearCallingIdentity(); |
| 10921 | try { |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 10922 | RcsProvisioningMonitor.getInstance() |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10923 | .unregisterRcsProvisioningCallback(subId, callback); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10924 | } finally { |
| 10925 | Binder.restoreCallingIdentity(identity); |
| 10926 | } |
| 10927 | } |
| 10928 | |
| 10929 | /** |
| 10930 | * trigger RCS reconfiguration. |
| 10931 | */ |
| 10932 | public void triggerRcsReconfiguration(int subId) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10933 | TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(), |
| 10934 | "triggerRcsReconfiguration", |
| 10935 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10936 | |
| 10937 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10938 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10939 | } |
| 10940 | if (!isImsAvailableOnDevice()) { |
joonhunshin | 46b49a3 | 2022-12-21 05:33:23 +0000 | [diff] [blame] | 10941 | // ProvisioningManager can not handle ServiceSpecificException. |
| 10942 | // Throw the IllegalStateException and annotate ProvisioningManager. |
| 10943 | throw new IllegalStateException("IMS not available on device."); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10944 | } |
| 10945 | |
| 10946 | final long identity = Binder.clearCallingIdentity(); |
| 10947 | try { |
| 10948 | RcsProvisioningMonitor.getInstance().requestReconfig(subId); |
| 10949 | } finally { |
| 10950 | Binder.restoreCallingIdentity(identity); |
| 10951 | } |
| 10952 | } |
| 10953 | |
| 10954 | /** |
| 10955 | * Provide the client configuration parameters of the RCS application. |
| 10956 | */ |
| 10957 | public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10958 | TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(), |
| 10959 | "setRcsClientConfiguration", |
| 10960 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10961 | |
| 10962 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10963 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10964 | } |
| 10965 | if (!isImsAvailableOnDevice()) { |
| 10966 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 10967 | "IMS not available on device."); |
| 10968 | } |
| 10969 | |
| 10970 | final long identity = Binder.clearCallingIdentity(); |
| 10971 | |
| 10972 | try { |
| 10973 | IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS); |
| 10974 | if (configBinder == null) { |
| 10975 | Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration"); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 10976 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION, |
| 10977 | "could not find the requested subscription"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10978 | } else { |
| 10979 | configBinder.setRcsClientConfiguration(rcc); |
| 10980 | } |
joonhunshin | 3e15424 | 2021-09-17 06:33:39 +0000 | [diff] [blame] | 10981 | |
| 10982 | RcsStats.getInstance().onRcsClientProvisioningStats(subId, |
| 10983 | RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10984 | } catch (RemoteException e) { |
| 10985 | Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage()); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 10986 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE, |
| 10987 | "service is temporarily unavailable."); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10988 | } finally { |
| 10989 | Binder.restoreCallingIdentity(identity); |
| 10990 | } |
| 10991 | } |
| 10992 | |
| 10993 | /** |
Hui Wang | baaee6a | 2021-02-19 20:45:36 -0800 | [diff] [blame] | 10994 | * Enables or disables the test mode for RCS VoLTE single registration. |
| 10995 | */ |
| 10996 | @Override |
| 10997 | public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) { |
| 10998 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10999 | "setRcsSingleRegistrationTestModeEnabled"); |
| 11000 | |
| 11001 | RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled); |
| 11002 | } |
| 11003 | |
| 11004 | /** |
| 11005 | * Gets the test mode for RCS VoLTE single registration. |
| 11006 | */ |
| 11007 | @Override |
| 11008 | public boolean getRcsSingleRegistrationTestModeEnabled() { |
| 11009 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11010 | "getRcsSingleRegistrationTestModeEnabled"); |
| 11011 | |
| 11012 | return RcsProvisioningMonitor.getInstance().getTestModeEnabled(); |
| 11013 | } |
| 11014 | |
| 11015 | /** |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11016 | * Overrides the config of RCS VoLTE single registration enabled for the device. |
| 11017 | */ |
| 11018 | @Override |
| 11019 | public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) { |
| 11020 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11021 | "setDeviceSingleRegistrationEnabledOverride"); |
| 11022 | enforceModifyPermission(); |
| 11023 | |
| 11024 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 11025 | : Boolean.parseBoolean(enabledStr); |
| 11026 | RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled); |
Brad Ebinger | 49a72b4 | 2021-01-29 00:55:24 +0000 | [diff] [blame] | 11027 | mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11028 | } |
| 11029 | |
| 11030 | /** |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 11031 | * Sends a device to device communication message. Only usable via shell. |
| 11032 | * @param message message to send. |
| 11033 | * @param value message value. |
| 11034 | */ |
| 11035 | @Override |
| 11036 | public void sendDeviceToDeviceMessage(int message, int value) { |
| 11037 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
Tyler Gunn | babbda0 | 2021-02-10 11:05:02 -0800 | [diff] [blame] | 11038 | "sendDeviceToDeviceMessage"); |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 11039 | enforceModifyPermission(); |
| 11040 | |
| 11041 | final long identity = Binder.clearCallingIdentity(); |
| 11042 | try { |
| 11043 | TelephonyConnectionService service = |
| 11044 | TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService(); |
| 11045 | if (service == null) { |
| 11046 | Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call."); |
| 11047 | return; |
| 11048 | } |
| 11049 | service.sendTestDeviceToDeviceMessage(message, value); |
| 11050 | } finally { |
| 11051 | Binder.restoreCallingIdentity(identity); |
| 11052 | } |
| 11053 | } |
| 11054 | |
Tyler Gunn | babbda0 | 2021-02-10 11:05:02 -0800 | [diff] [blame] | 11055 | /** |
| 11056 | * Sets the specified device to device transport active. |
| 11057 | * @param transport The transport to set active. |
| 11058 | */ |
| 11059 | @Override |
| 11060 | public void setActiveDeviceToDeviceTransport(@NonNull String transport) { |
| 11061 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11062 | "setActiveDeviceToDeviceTransport"); |
| 11063 | enforceModifyPermission(); |
| 11064 | |
| 11065 | final long identity = Binder.clearCallingIdentity(); |
| 11066 | try { |
| 11067 | TelephonyConnectionService service = |
| 11068 | TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService(); |
| 11069 | if (service == null) { |
| 11070 | Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call."); |
| 11071 | return; |
| 11072 | } |
| 11073 | service.setActiveDeviceToDeviceTransport(transport); |
| 11074 | } finally { |
| 11075 | Binder.restoreCallingIdentity(identity); |
| 11076 | } |
| 11077 | } |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 11078 | |
Tyler Gunn | d433926 | 2021-05-03 14:46:49 -0700 | [diff] [blame] | 11079 | @Override |
| 11080 | public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) { |
| 11081 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11082 | "setDeviceToDeviceForceEnabled"); |
| 11083 | |
| 11084 | final long identity = Binder.clearCallingIdentity(); |
| 11085 | try { |
| 11086 | Arrays.stream(PhoneFactory.getPhones()).forEach( |
| 11087 | p -> { |
| 11088 | Phone thePhone = p.getImsPhone(); |
| 11089 | if (thePhone != null && thePhone instanceof ImsPhone) { |
| 11090 | ImsPhone imsPhone = (ImsPhone) thePhone; |
| 11091 | CallTracker tracker = imsPhone.getCallTracker(); |
| 11092 | if (tracker != null && tracker instanceof ImsPhoneCallTracker) { |
| 11093 | ImsPhoneCallTracker imsPhoneCallTracker = |
| 11094 | (ImsPhoneCallTracker) tracker; |
| 11095 | imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled); |
| 11096 | } |
| 11097 | } |
| 11098 | } |
| 11099 | ); |
| 11100 | } finally { |
| 11101 | Binder.restoreCallingIdentity(identity); |
| 11102 | } |
| 11103 | } |
| 11104 | |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 11105 | /** |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11106 | * Gets the config of RCS VoLTE single registration enabled for the device. |
| 11107 | */ |
| 11108 | @Override |
| 11109 | public boolean getDeviceSingleRegistrationEnabled() { |
| 11110 | enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled"); |
| 11111 | return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled(); |
| 11112 | } |
| 11113 | |
| 11114 | /** |
| 11115 | * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription. |
| 11116 | */ |
| 11117 | @Override |
| 11118 | public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) { |
| 11119 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11120 | "setCarrierSingleRegistrationEnabledOverride"); |
| 11121 | enforceModifyPermission(); |
| 11122 | |
| 11123 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 11124 | : Boolean.parseBoolean(enabledStr); |
| 11125 | return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled( |
| 11126 | subId, enabled); |
| 11127 | } |
| 11128 | |
| 11129 | /** |
| 11130 | * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription. |
| 11131 | */ |
| 11132 | @Override |
| 11133 | public boolean getCarrierSingleRegistrationEnabled(int subId) { |
| 11134 | enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled"); |
| 11135 | return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId); |
| 11136 | } |
Chiachang Wang | d6d3477 | 2020-12-22 11:38:27 +0800 | [diff] [blame] | 11137 | |
| 11138 | /** |
Hui Wang | b647abe | 2021-02-26 09:33:38 -0800 | [diff] [blame] | 11139 | * Overrides the ims feature validation result |
| 11140 | */ |
| 11141 | @Override |
| 11142 | public boolean setImsFeatureValidationOverride(int subId, String enabledStr) { |
| 11143 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11144 | "setImsFeatureValidationOverride"); |
| 11145 | |
| 11146 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 11147 | : Boolean.parseBoolean(enabledStr); |
| 11148 | return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation( |
| 11149 | subId, enabled); |
| 11150 | } |
| 11151 | |
| 11152 | /** |
| 11153 | * Gets the ims feature validation override value |
| 11154 | */ |
| 11155 | @Override |
| 11156 | public boolean getImsFeatureValidationOverride(int subId) { |
| 11157 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11158 | "getImsFeatureValidationOverride"); |
| 11159 | return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId); |
| 11160 | } |
| 11161 | |
| 11162 | /** |
Chiachang Wang | d6d3477 | 2020-12-22 11:38:27 +0800 | [diff] [blame] | 11163 | * Get the mobile provisioning url that is used to launch a browser to allow users to manage |
| 11164 | * their mobile plan. |
| 11165 | */ |
| 11166 | @Override |
| 11167 | public String getMobileProvisioningUrl() { |
| 11168 | enforceReadPrivilegedPermission("getMobileProvisioningUrl"); |
| 11169 | final long identity = Binder.clearCallingIdentity(); |
| 11170 | try { |
| 11171 | return getDefaultPhone().getMobileProvisioningUrl(); |
| 11172 | } finally { |
| 11173 | Binder.restoreCallingIdentity(identity); |
| 11174 | } |
| 11175 | } |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11176 | |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 11177 | /** |
calvinpan | e4a8a1d | 2021-01-25 13:51:18 +0800 | [diff] [blame] | 11178 | * Get the EAB contact from the EAB database. |
| 11179 | */ |
| 11180 | @Override |
| 11181 | public String getContactFromEab(String contact) { |
| 11182 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab"); |
| 11183 | enforceModifyPermission(); |
| 11184 | final long identity = Binder.clearCallingIdentity(); |
| 11185 | try { |
| 11186 | return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact); |
| 11187 | } finally { |
| 11188 | Binder.restoreCallingIdentity(identity); |
| 11189 | } |
| 11190 | } |
| 11191 | |
| 11192 | /** |
Calvin Pan | a143432 | 2021-07-01 19:27:01 +0800 | [diff] [blame] | 11193 | * Get the EAB capability from the EAB database. |
| 11194 | */ |
| 11195 | @Override |
| 11196 | public String getCapabilityFromEab(String contact) { |
| 11197 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab"); |
| 11198 | enforceModifyPermission(); |
| 11199 | final long identity = Binder.clearCallingIdentity(); |
| 11200 | try { |
| 11201 | return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact); |
| 11202 | } finally { |
| 11203 | Binder.restoreCallingIdentity(identity); |
| 11204 | } |
| 11205 | } |
| 11206 | |
| 11207 | /** |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 11208 | * Remove the EAB contacts from the EAB database. |
| 11209 | */ |
| 11210 | @Override |
| 11211 | public int removeContactFromEab(int subId, String contacts) { |
| 11212 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab"); |
| 11213 | enforceModifyPermission(); |
| 11214 | final long identity = Binder.clearCallingIdentity(); |
| 11215 | try { |
| 11216 | return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext()); |
| 11217 | } finally { |
| 11218 | Binder.restoreCallingIdentity(identity); |
| 11219 | } |
| 11220 | } |
| 11221 | |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11222 | @Override |
James.cf Lin | 4b784aa | 2021-01-31 03:25:15 +0800 | [diff] [blame] | 11223 | public boolean getDeviceUceEnabled() { |
| 11224 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled"); |
| 11225 | final long identity = Binder.clearCallingIdentity(); |
| 11226 | try { |
| 11227 | return mApp.getDeviceUceEnabled(); |
| 11228 | } finally { |
| 11229 | Binder.restoreCallingIdentity(identity); |
| 11230 | } |
| 11231 | } |
| 11232 | |
| 11233 | @Override |
| 11234 | public void setDeviceUceEnabled(boolean isEnabled) { |
| 11235 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled"); |
| 11236 | final long identity = Binder.clearCallingIdentity(); |
| 11237 | try { |
| 11238 | mApp.setDeviceUceEnabled(isEnabled); |
| 11239 | } finally { |
| 11240 | Binder.restoreCallingIdentity(identity); |
| 11241 | } |
| 11242 | } |
| 11243 | |
Brad Ebinger | 14d467f | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 11244 | /** |
| 11245 | * Add new feature tags to the Set used to calculate the capabilities in PUBLISH. |
| 11246 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 11247 | */ |
| 11248 | // Used for SHELL command only right now. |
| 11249 | @Override |
| 11250 | public RcsContactUceCapability addUceRegistrationOverrideShell(int subId, |
| 11251 | List<String> featureTags) { |
| 11252 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11253 | "addUceRegistrationOverrideShell"); |
| 11254 | final long identity = Binder.clearCallingIdentity(); |
| 11255 | try { |
| 11256 | return mApp.imsRcsController.addUceRegistrationOverrideShell(subId, |
| 11257 | new ArraySet<>(featureTags)); |
| 11258 | } catch (ImsException e) { |
| 11259 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 11260 | } finally { |
| 11261 | Binder.restoreCallingIdentity(identity); |
| 11262 | } |
| 11263 | } |
| 11264 | |
| 11265 | /** |
| 11266 | * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH. |
| 11267 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 11268 | */ |
| 11269 | // Used for SHELL command only right now. |
| 11270 | @Override |
| 11271 | public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId, |
| 11272 | List<String> featureTags) { |
| 11273 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11274 | "removeUceRegistrationOverrideShell"); |
| 11275 | final long identity = Binder.clearCallingIdentity(); |
| 11276 | try { |
| 11277 | return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId, |
| 11278 | new ArraySet<>(featureTags)); |
| 11279 | } catch (ImsException e) { |
| 11280 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 11281 | } finally { |
| 11282 | Binder.restoreCallingIdentity(identity); |
| 11283 | } |
| 11284 | } |
| 11285 | |
| 11286 | /** |
| 11287 | * Clear all overrides in the Set used to calculate the capabilities in PUBLISH. |
| 11288 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 11289 | */ |
| 11290 | // Used for SHELL command only right now. |
| 11291 | @Override |
| 11292 | public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) { |
| 11293 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11294 | "clearUceRegistrationOverrideShell"); |
| 11295 | final long identity = Binder.clearCallingIdentity(); |
| 11296 | try { |
| 11297 | return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId); |
| 11298 | } catch (ImsException e) { |
| 11299 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 11300 | } finally { |
| 11301 | Binder.restoreCallingIdentity(identity); |
| 11302 | } |
| 11303 | } |
| 11304 | |
| 11305 | /** |
| 11306 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 11307 | */ |
| 11308 | // Used for SHELL command only right now. |
| 11309 | @Override |
| 11310 | public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) { |
| 11311 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11312 | "getLatestRcsContactUceCapabilityShell"); |
| 11313 | final long identity = Binder.clearCallingIdentity(); |
| 11314 | try { |
| 11315 | return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId); |
| 11316 | } catch (ImsException e) { |
| 11317 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 11318 | } finally { |
| 11319 | Binder.restoreCallingIdentity(identity); |
| 11320 | } |
| 11321 | } |
| 11322 | |
| 11323 | /** |
| 11324 | * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the |
| 11325 | * device does not have an active PUBLISH. |
| 11326 | */ |
| 11327 | // Used for SHELL command only right now. |
| 11328 | @Override |
| 11329 | public String getLastUcePidfXmlShell(int subId) { |
| 11330 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml"); |
| 11331 | final long identity = Binder.clearCallingIdentity(); |
| 11332 | try { |
| 11333 | return mApp.imsRcsController.getLastUcePidfXmlShell(subId); |
| 11334 | } catch (ImsException e) { |
| 11335 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 11336 | } finally { |
| 11337 | Binder.restoreCallingIdentity(identity); |
| 11338 | } |
| 11339 | } |
| 11340 | |
James.cf Lin | e8713a4 | 2021-04-29 16:04:26 +0800 | [diff] [blame] | 11341 | /** |
| 11342 | * Remove UCE requests cannot be sent to the network status. |
| 11343 | */ |
| 11344 | // Used for SHELL command only right now. |
| 11345 | @Override |
| 11346 | public boolean removeUceRequestDisallowedStatus(int subId) { |
| 11347 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus"); |
| 11348 | final long identity = Binder.clearCallingIdentity(); |
| 11349 | try { |
| 11350 | return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId); |
| 11351 | } catch (ImsException e) { |
| 11352 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 11353 | } finally { |
| 11354 | Binder.restoreCallingIdentity(identity); |
| 11355 | } |
| 11356 | } |
| 11357 | |
James.cf Lin | 18bb900 | 2021-05-25 01:37:38 +0800 | [diff] [blame] | 11358 | /** |
| 11359 | * Remove UCE requests cannot be sent to the network status. |
| 11360 | */ |
| 11361 | // Used for SHELL command only. |
| 11362 | @Override |
| 11363 | public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) { |
| 11364 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout"); |
| 11365 | final long identity = Binder.clearCallingIdentity(); |
| 11366 | try { |
| 11367 | return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs); |
| 11368 | } catch (ImsException e) { |
| 11369 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 11370 | } finally { |
| 11371 | Binder.restoreCallingIdentity(identity); |
| 11372 | } |
| 11373 | } |
Brad Ebinger | 14d467f | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 11374 | |
James.cf Lin | 4b784aa | 2021-01-31 03:25:15 +0800 | [diff] [blame] | 11375 | @Override |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11376 | public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request, |
| 11377 | String callingPackage) { |
| 11378 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 11379 | mApp, subId, "setSignalStrengthUpdateRequest"); |
| 11380 | |
| 11381 | final int callingUid = Binder.getCallingUid(); |
| 11382 | // Verify that tha callingPackage belongs to the calling UID |
| 11383 | mApp.getSystemService(AppOpsManager.class) |
| 11384 | .checkPackage(callingUid, callingPackage); |
| 11385 | |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 11386 | validateSignalStrengthUpdateRequest(mApp, request, callingUid); |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11387 | |
| 11388 | final long identity = Binder.clearCallingIdentity(); |
| 11389 | try { |
| 11390 | Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST, |
| 11391 | new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId); |
| 11392 | |
| 11393 | if (result instanceof IllegalStateException) { |
| 11394 | throw (IllegalStateException) result; |
| 11395 | } |
| 11396 | } finally { |
| 11397 | Binder.restoreCallingIdentity(identity); |
| 11398 | } |
| 11399 | } |
| 11400 | |
| 11401 | @Override |
| 11402 | public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request, |
| 11403 | String callingPackage) { |
| 11404 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 11405 | mApp, subId, "clearSignalStrengthUpdateRequest"); |
| 11406 | |
| 11407 | final int callingUid = Binder.getCallingUid(); |
| 11408 | // Verify that tha callingPackage belongs to the calling UID |
| 11409 | mApp.getSystemService(AppOpsManager.class) |
| 11410 | .checkPackage(callingUid, callingPackage); |
| 11411 | |
| 11412 | final long identity = Binder.clearCallingIdentity(); |
| 11413 | try { |
| 11414 | Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST, |
| 11415 | new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId); |
| 11416 | |
| 11417 | if (result instanceof IllegalStateException) { |
| 11418 | throw (IllegalStateException) result; |
| 11419 | } |
| 11420 | } finally { |
| 11421 | Binder.restoreCallingIdentity(identity); |
| 11422 | } |
| 11423 | } |
| 11424 | |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 11425 | private static void validateSignalStrengthUpdateRequest(Context context, |
| 11426 | SignalStrengthUpdateRequest request, int callingUid) { |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11427 | if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) { |
| 11428 | // phone/system process do not have further restriction on request |
| 11429 | return; |
| 11430 | } |
| 11431 | |
| 11432 | // Applications has restrictions on how to use the request: |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 11433 | // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11434 | if (request.isSystemThresholdReportingRequestedWhileIdle()) { |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 11435 | context.enforceCallingOrSelfPermission( |
| 11436 | android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH, |
| 11437 | "validateSignalStrengthUpdateRequest"); |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11438 | } |
| 11439 | |
| 11440 | for (SignalThresholdInfo info : request.getSignalThresholdInfos()) { |
Nagendra Prasad Nagarle Basavaraju | fee544c | 2022-12-07 16:34:52 +0000 | [diff] [blame] | 11441 | // Only system caller can set mHysteresisMs/mIsEnabled. |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11442 | if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11443 | || info.isEnabled()) { |
| 11444 | throw new IllegalArgumentException( |
| 11445 | "Only system can set hide fields in SignalThresholdInfo"); |
| 11446 | } |
| 11447 | |
| 11448 | // Thresholds length for each RAN need in range. This has been validated in |
| 11449 | // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method |
| 11450 | // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds |
| 11451 | final int[] thresholds = info.getThresholds(); |
| 11452 | Objects.requireNonNull(thresholds); |
| 11453 | if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed() |
| 11454 | || thresholds.length |
| 11455 | > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) { |
| 11456 | throw new IllegalArgumentException( |
| 11457 | "thresholds length is out of range: " + thresholds.length); |
| 11458 | } |
| 11459 | } |
| 11460 | } |
SongFerngWang | 8236caa | 2021-01-17 21:51:44 +0800 | [diff] [blame] | 11461 | |
| 11462 | /** |
| 11463 | * Gets the current phone capability. |
| 11464 | * |
| 11465 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 11466 | * @return the PhoneCapability which describes the data connection capability of modem. |
| 11467 | * It's used to evaluate possible phone config change, for example from single |
| 11468 | * SIM device to multi-SIM device. |
| 11469 | */ |
| 11470 | @Override |
| 11471 | public PhoneCapability getPhoneCapability() { |
| 11472 | enforceReadPrivilegedPermission("getPhoneCapability"); |
| 11473 | final long identity = Binder.clearCallingIdentity(); |
| 11474 | try { |
| 11475 | return mPhoneConfigurationManager.getCurrentPhoneCapability(); |
| 11476 | } finally { |
| 11477 | Binder.restoreCallingIdentity(identity); |
| 11478 | } |
| 11479 | } |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 11480 | |
| 11481 | /** |
| 11482 | * Prepare TelephonyManager for an unattended reboot. The reboot is |
| 11483 | * required to be done shortly after the API is invoked. |
| 11484 | */ |
| 11485 | @Override |
| 11486 | @TelephonyManager.PrepareUnattendedRebootResult |
| 11487 | public int prepareForUnattendedReboot() { |
Rafael Higuera Silva | d963064 | 2021-09-20 15:32:01 +0000 | [diff] [blame] | 11488 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 11489 | enforceRebootPermission(); |
| 11490 | |
| 11491 | final long identity = Binder.clearCallingIdentity(); |
| 11492 | try { |
Rafael Higuera Silva | d963064 | 2021-09-20 15:32:01 +0000 | [diff] [blame] | 11493 | return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 11494 | } finally { |
| 11495 | Binder.restoreCallingIdentity(identity); |
| 11496 | } |
| 11497 | } |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 11498 | |
| 11499 | /** |
| 11500 | * Request to get the current slicing configuration including URSP rules and |
| 11501 | * NSSAIs (configured, allowed and rejected). |
| 11502 | * |
| 11503 | * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission. |
| 11504 | */ |
| 11505 | @Override |
| 11506 | public void getSlicingConfig(ResultReceiver callback) { |
Hongbo Zeng | 1b2063d | 2022-02-21 01:33:03 +0000 | [diff] [blame] | 11507 | TelephonyPermissions |
| 11508 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 11509 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, "getSlicingConfig"); |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 11510 | |
| 11511 | final long identity = Binder.clearCallingIdentity(); |
| 11512 | try { |
| 11513 | Phone phone = getDefaultPhone(); |
| 11514 | sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null); |
| 11515 | } finally { |
| 11516 | Binder.restoreCallingIdentity(identity); |
| 11517 | } |
| 11518 | } |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 11519 | |
| 11520 | /** |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 11521 | * Check whether the given premium capability is available for purchase from the carrier. |
| 11522 | * |
| 11523 | * @param capability The premium capability to check. |
| 11524 | * @param subId The subId to check the premium capability for. |
| 11525 | * |
| 11526 | * @return Whether the given premium capability is available to purchase. |
| 11527 | */ |
| 11528 | @Override |
| 11529 | public boolean isPremiumCapabilityAvailableForPurchase(int capability, int subId) { |
| 11530 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 11531 | mApp, "isPremiumCapabilityAvailableForPurchase")) { |
| 11532 | log("Premium capability " |
| 11533 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 11534 | + " is not available for purchase due to missing permissions."); |
| 11535 | throw new SecurityException("isPremiumCapabilityAvailableForPurchase requires " |
| 11536 | + "permission READ_BASIC_PHONE_STATE."); |
| 11537 | } |
| 11538 | |
| 11539 | Phone phone = getPhone(subId); |
Thomas Nguyen | 7216ed6 | 2022-11-29 16:45:31 -0800 | [diff] [blame] | 11540 | if (phone == null) { |
| 11541 | loge("isPremiumCapabilityAvailableForPurchase: phone is null, subId=" + subId); |
| 11542 | return false; |
| 11543 | } |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 11544 | final long identity = Binder.clearCallingIdentity(); |
| 11545 | try { |
Sarah Chin | 46355ba | 2022-11-01 23:51:16 -0700 | [diff] [blame] | 11546 | return SlicePurchaseController.getInstance(phone) |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 11547 | .isPremiumCapabilityAvailableForPurchase(capability); |
| 11548 | } finally { |
| 11549 | Binder.restoreCallingIdentity(identity); |
| 11550 | } |
| 11551 | } |
| 11552 | |
| 11553 | /** |
| 11554 | * Purchase the given premium capability from the carrier. |
| 11555 | * |
| 11556 | * @param capability The premium capability to purchase. |
| 11557 | * @param callback The result of the purchase request. |
| 11558 | * @param subId The subId to purchase the premium capability for. |
| 11559 | */ |
| 11560 | @Override |
| 11561 | public void purchasePremiumCapability(int capability, IIntegerConsumer callback, int subId) { |
| 11562 | log("purchasePremiumCapability: capability=" |
| 11563 | + TelephonyManager.convertPremiumCapabilityToString(capability) + ", caller=" |
| 11564 | + getCurrentPackageName()); |
| 11565 | |
| 11566 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 11567 | mApp, "purchasePremiumCapability")) { |
| 11568 | log("purchasePremiumCapability " |
| 11569 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 11570 | + " failed due to missing permissions."); |
| 11571 | throw new SecurityException("purchasePremiumCapability requires permission " |
| 11572 | + "READ_BASIC_PHONE_STATE."); |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 11573 | } else if (!TelephonyPermissions.checkInternetPermissionNoThrow( |
| 11574 | mApp, "purchasePremiumCapability")) { |
| 11575 | log("purchasePremiumCapability " |
| 11576 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 11577 | + " failed due to missing permissions."); |
| 11578 | throw new SecurityException("purchasePremiumCapability requires permission INTERNET."); |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 11579 | } |
| 11580 | |
| 11581 | Phone phone = getPhone(subId); |
Sarah Chin | 1969411 | 2022-12-06 15:41:37 -0800 | [diff] [blame] | 11582 | if (phone == null) { |
| 11583 | try { |
| 11584 | int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_REQUEST_FAILED; |
| 11585 | callback.accept(result); |
| 11586 | loge("purchasePremiumCapability: phone is null, subId=" + subId); |
| 11587 | } catch (RemoteException e) { |
| 11588 | String logStr = "Purchase premium capability " |
| 11589 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 11590 | + " failed due to RemoteException handling null phone: " + e; |
| 11591 | if (DBG) log(logStr); |
| 11592 | AnomalyReporter.reportAnomaly( |
| 11593 | UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr); |
| 11594 | } |
| 11595 | return; |
| 11596 | } |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 11597 | |
| 11598 | String callingProcess; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 11599 | try { |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 11600 | callingProcess = mApp.getPackageManager().getApplicationInfo( |
| 11601 | getCurrentPackageName(), 0).processName; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 11602 | } catch (PackageManager.NameNotFoundException e) { |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 11603 | callingProcess = getCurrentPackageName(); |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 11604 | } |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 11605 | |
| 11606 | boolean isVisible = false; |
| 11607 | ActivityManager am = mApp.getSystemService(ActivityManager.class); |
| 11608 | if (am != null) { |
| 11609 | List<ActivityManager.RunningAppProcessInfo> processes = am.getRunningAppProcesses(); |
| 11610 | if (processes != null) { |
| 11611 | for (ActivityManager.RunningAppProcessInfo process : processes) { |
| 11612 | log("purchasePremiumCapability: process " + process.processName |
Sarah Chin | ff8b180 | 2023-04-11 14:22:14 -0700 | [diff] [blame] | 11613 | + " has importance " + process.importance); |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 11614 | if (process.processName.equals(callingProcess) && process.importance |
| 11615 | <= ActivityManager.RunningAppProcessInfo.IMPORTANCE_VISIBLE) { |
| 11616 | isVisible = true; |
| 11617 | break; |
| 11618 | } |
| 11619 | } |
| 11620 | } |
| 11621 | } |
| 11622 | |
| 11623 | if (!isVisible) { |
| 11624 | try { |
| 11625 | int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_NOT_FOREGROUND; |
| 11626 | callback.accept(result); |
| 11627 | loge("purchasePremiumCapability: " + callingProcess + " is not in the foreground."); |
| 11628 | } catch (RemoteException e) { |
| 11629 | String logStr = "Purchase premium capability " |
| 11630 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 11631 | + " failed due to RemoteException handling background application: " + e; |
| 11632 | if (DBG) log(logStr); |
| 11633 | AnomalyReporter.reportAnomaly( |
| 11634 | UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr); |
| 11635 | } |
| 11636 | return; |
| 11637 | } |
| 11638 | |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 11639 | sendRequestAsync(CMD_PURCHASE_PREMIUM_CAPABILITY, |
Sarah Chin | b8218c2 | 2023-01-04 13:35:29 -0800 | [diff] [blame] | 11640 | new PurchasePremiumCapabilityArgument(capability, callback), phone, null); |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 11641 | } |
| 11642 | |
| 11643 | /** |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 11644 | * Register an IMS connection state callback |
| 11645 | */ |
| 11646 | @Override |
Hunsuk Choi | 89bd22c | 2021-11-01 13:04:54 +0000 | [diff] [blame] | 11647 | public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb, |
| 11648 | String callingPackage) { |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 11649 | if (feature == ImsFeature.FEATURE_MMTEL) { |
| 11650 | // ImsMmTelManager |
| 11651 | // The following also checks READ_PRIVILEGED_PHONE_STATE. |
| 11652 | TelephonyPermissions |
| 11653 | .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 11654 | mApp, subId, "registerImsStateCallback"); |
| 11655 | } else if (feature == ImsFeature.FEATURE_RCS) { |
| 11656 | // ImsRcsManager or SipDelegateManager |
| 11657 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 11658 | Binder.getCallingUid(), "registerImsStateCallback", |
| 11659 | Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
| 11660 | Manifest.permission.READ_PRECISE_PHONE_STATE, |
| 11661 | Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE, |
| 11662 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
| 11663 | } |
| 11664 | |
| 11665 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 11666 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 11667 | "IMS not available on device."); |
| 11668 | } |
| 11669 | |
| 11670 | if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) { |
| 11671 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 11672 | } |
| 11673 | |
| 11674 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 11675 | if (controller == null) { |
| 11676 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 11677 | "IMS not available on device."); |
| 11678 | } |
| 11679 | |
Hunsuk Choi | 89bd22c | 2021-11-01 13:04:54 +0000 | [diff] [blame] | 11680 | if (callingPackage == null) { |
| 11681 | callingPackage = getCurrentPackageName(); |
| 11682 | } |
| 11683 | |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 11684 | final long token = Binder.clearCallingIdentity(); |
| 11685 | try { |
| 11686 | int slotId = getSlotIndexOrException(subId); |
Hunsuk Choi | 89bd22c | 2021-11-01 13:04:54 +0000 | [diff] [blame] | 11687 | controller.registerImsStateCallback(subId, feature, cb, callingPackage); |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 11688 | } catch (ImsException e) { |
| 11689 | throw new ServiceSpecificException(e.getCode()); |
| 11690 | } finally { |
| 11691 | Binder.restoreCallingIdentity(token); |
| 11692 | } |
| 11693 | } |
| 11694 | |
| 11695 | /** |
| 11696 | * Unregister an IMS connection state callback |
| 11697 | */ |
| 11698 | @Override |
| 11699 | public void unregisterImsStateCallback(IImsStateCallback cb) { |
| 11700 | final long token = Binder.clearCallingIdentity(); |
| 11701 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 11702 | if (controller == null) { |
| 11703 | return; |
| 11704 | } |
| 11705 | try { |
| 11706 | controller.unregisterImsStateCallback(cb); |
| 11707 | } finally { |
| 11708 | Binder.restoreCallingIdentity(token); |
| 11709 | } |
| 11710 | } |
Sooraj Sasindran | fae41b3 | 2021-10-26 02:10:05 -0700 | [diff] [blame] | 11711 | |
| 11712 | /** |
| 11713 | * @return {@CellIdentity} last known cell identity {@CellIdentity}. |
| 11714 | * |
| 11715 | * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and |
| 11716 | * com.android.phone.permission.ACCESS_LAST_KNOWN_CELL_ID, otherwise throws |
| 11717 | * SecurityException. |
| 11718 | * If there is current registered network this value will be same as the registered cell |
| 11719 | * identity. If the device goes out of service the previous cell identity is cached and |
| 11720 | * will be returned. If the cache age of the Cell identity is more than 24 hours |
| 11721 | * it will be cleared and null will be returned. |
| 11722 | * |
| 11723 | */ |
| 11724 | @Override |
| 11725 | public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage, |
| 11726 | String callingFeatureId) { |
| 11727 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 11728 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 11729 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 11730 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 11731 | .setCallingPackage(callingPackage) |
| 11732 | .setCallingFeatureId(callingFeatureId) |
| 11733 | .setCallingPid(Binder.getCallingPid()) |
| 11734 | .setCallingUid(Binder.getCallingUid()) |
| 11735 | .setMethod("getLastKnownCellIdentity") |
| 11736 | .setLogAsInfo(true) |
| 11737 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 11738 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 11739 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 11740 | .build()); |
| 11741 | |
| 11742 | boolean hasFinePermission = |
| 11743 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 11744 | if (!hasFinePermission |
| 11745 | || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) { |
| 11746 | throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION " |
Rambo Wang | 918993a | 2022-04-27 09:08:36 -0700 | [diff] [blame] | 11747 | + "and ACCESS_LAST_KNOWN_CELL_ID permission."); |
Sooraj Sasindran | fae41b3 | 2021-10-26 02:10:05 -0700 | [diff] [blame] | 11748 | } |
| 11749 | |
| 11750 | final long identity = Binder.clearCallingIdentity(); |
| 11751 | try { |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 11752 | ServiceStateTracker sst = getPhoneFromSubIdOrDefault(subId).getServiceStateTracker(); |
Sooraj Sasindran | fae41b3 | 2021-10-26 02:10:05 -0700 | [diff] [blame] | 11753 | if (sst == null) return null; |
| 11754 | return sst.getLastKnownCellIdentity(); |
| 11755 | } finally { |
| 11756 | Binder.restoreCallingIdentity(identity); |
| 11757 | } |
| 11758 | } |
Jack Yu | 4c0a550 | 2021-12-03 23:58:26 -0800 | [diff] [blame] | 11759 | |
jimsun | 3b9ccac | 2021-10-26 15:01:23 +0800 | [diff] [blame] | 11760 | /** |
| 11761 | * Sets the modem service class Name that Telephony will bind to. |
| 11762 | * |
| 11763 | * @param serviceName The class name of the modem service. |
| 11764 | * @return true if the operation is succeed, otherwise false. |
| 11765 | */ |
| 11766 | public boolean setModemService(String serviceName) { |
| 11767 | Log.d(LOG_TAG, "setModemService - " + serviceName); |
| 11768 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService"); |
| 11769 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 11770 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 11771 | "setModemService"); |
jimsun | 3b9ccac | 2021-10-26 15:01:23 +0800 | [diff] [blame] | 11772 | return mPhoneConfigurationManager.setModemService(serviceName); |
| 11773 | } |
| 11774 | |
| 11775 | /** |
| 11776 | * Return the class name of the currently bounded modem service. |
| 11777 | * |
| 11778 | * @return the class name of the modem service. |
| 11779 | */ |
| 11780 | public String getModemService() { |
| 11781 | String result; |
| 11782 | Log.d(LOG_TAG, "getModemService"); |
| 11783 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService"); |
| 11784 | TelephonyPermissions |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 11785 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
jimsun | 3b9ccac | 2021-10-26 15:01:23 +0800 | [diff] [blame] | 11786 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 11787 | "getModemService"); |
| 11788 | result = mPhoneConfigurationManager.getModemService(); |
| 11789 | Log.d(LOG_TAG, "result = " + result); |
| 11790 | return result; |
| 11791 | } |
Hunter Knepshield | 2b076fa | 2022-01-19 02:26:22 -0800 | [diff] [blame] | 11792 | |
| 11793 | @Override |
| 11794 | public void setVoiceServiceStateOverride(int subId, boolean hasService, String callingPackage) { |
| 11795 | // Only telecom (and shell, for CTS purposes) is allowed to call this method. |
| 11796 | mApp.enforceCallingOrSelfPermission( |
| 11797 | permission.BIND_TELECOM_CONNECTION_SERVICE, "setVoiceServiceStateOverride"); |
| 11798 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 11799 | |
| 11800 | final long identity = Binder.clearCallingIdentity(); |
| 11801 | try { |
| 11802 | Phone phone = getPhone(subId); |
| 11803 | if (phone == null) return; |
Grant Menke | 63ade12 | 2023-01-20 14:31:54 -0800 | [diff] [blame] | 11804 | Log.i(LOG_TAG, "setVoiceServiceStateOverride: subId=" + subId + ", phone=" + phone |
| 11805 | + ", hasService=" + hasService + ", callingPackage=" + callingPackage); |
Hunter Knepshield | 2b076fa | 2022-01-19 02:26:22 -0800 | [diff] [blame] | 11806 | phone.setVoiceServiceStateOverride(hasService); |
| 11807 | } finally { |
| 11808 | Binder.restoreCallingIdentity(identity); |
| 11809 | } |
| 11810 | } |
Muralidhar Reddy | 4e5a801 | 2022-05-11 14:49:00 +0000 | [diff] [blame] | 11811 | |
| 11812 | /** |
| 11813 | * set removable eSIM as default eUICC. |
| 11814 | * |
| 11815 | * @hide |
| 11816 | */ |
| 11817 | @Override |
| 11818 | public void setRemovableEsimAsDefaultEuicc(boolean isDefault, String callingPackage) { |
| 11819 | enforceModifyPermission(); |
| 11820 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 11821 | |
| 11822 | final long identity = Binder.clearCallingIdentity(); |
| 11823 | try { |
| 11824 | UiccController.getInstance().setRemovableEsimAsDefaultEuicc(isDefault); |
| 11825 | } finally { |
| 11826 | Binder.restoreCallingIdentity(identity); |
| 11827 | } |
| 11828 | } |
| 11829 | |
| 11830 | /** |
| 11831 | * Returns whether the removable eSIM is default eUICC or not. |
| 11832 | * |
| 11833 | * @hide |
| 11834 | */ |
| 11835 | @Override |
| 11836 | public boolean isRemovableEsimDefaultEuicc(String callingPackage) { |
| 11837 | enforceReadPrivilegedPermission("isRemovableEsimDefaultEuicc"); |
| 11838 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 11839 | |
| 11840 | final long identity = Binder.clearCallingIdentity(); |
| 11841 | try { |
| 11842 | return UiccController.getInstance().isRemovableEsimDefaultEuicc(); |
| 11843 | } finally { |
| 11844 | Binder.restoreCallingIdentity(identity); |
| 11845 | } |
| 11846 | } |
| 11847 | |
Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame] | 11848 | /** |
| 11849 | * Get the component name of the default app to direct respond-via-message intent for the |
| 11850 | * user associated with this subscription, update the cache if there is no respond-via-message |
| 11851 | * application currently configured for this user. |
| 11852 | * @return component name of the app and class to direct Respond Via Message intent to, or |
| 11853 | * {@code null} if the functionality is not supported. |
| 11854 | * @hide |
| 11855 | */ |
| 11856 | @Override |
| 11857 | public @Nullable ComponentName getDefaultRespondViaMessageApplication(int subId, |
| 11858 | boolean updateIfNeeded) { |
| 11859 | enforceInteractAcrossUsersPermission("getDefaultRespondViaMessageApplication"); |
Muralidhar Reddy | 4e5a801 | 2022-05-11 14:49:00 +0000 | [diff] [blame] | 11860 | |
Aishwarya Mallampati | 5e581e1 | 2023-01-17 21:57:06 +0000 | [diff] [blame] | 11861 | Context context = getPhoneFromSubIdOrDefault(subId).getContext(); |
| 11862 | |
Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame] | 11863 | UserHandle userHandle = null; |
| 11864 | final long identity = Binder.clearCallingIdentity(); |
| 11865 | try { |
| 11866 | userHandle = TelephonyUtils.getSubscriptionUserHandle(context, subId); |
| 11867 | } finally { |
| 11868 | Binder.restoreCallingIdentity(identity); |
| 11869 | } |
| 11870 | return SmsApplication.getDefaultRespondViaMessageApplicationAsUser(context, |
| 11871 | updateIfNeeded, userHandle); |
| 11872 | } |
Jack Yu | f5badd9 | 2022-12-08 00:50:53 -0800 | [diff] [blame] | 11873 | |
| 11874 | /** |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 11875 | * Set whether the device is able to connect with null ciphering or integrity |
| 11876 | * algorithms. This is a global setting and will apply to all active subscriptions |
| 11877 | * and all new subscriptions after this. |
| 11878 | * |
| 11879 | * @param enabled when true, null cipher and integrity algorithms are allowed. |
| 11880 | * @hide |
| 11881 | */ |
| 11882 | @Override |
| 11883 | @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 11884 | public void setNullCipherAndIntegrityEnabled(boolean enabled) { |
| 11885 | enforceModifyPermission(); |
| 11886 | checkForNullCipherAndIntegritySupport(); |
| 11887 | |
| 11888 | // Persist the state of our preference. Each GsmCdmaPhone instance is responsible |
| 11889 | // for listening to these preference changes and applying them immediately. |
| 11890 | SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 11891 | editor.putBoolean(Phone.PREF_NULL_CIPHER_AND_INTEGRITY_ENABLED, enabled); |
| 11892 | editor.apply(); |
| 11893 | |
| 11894 | for (Phone phone: PhoneFactory.getPhones()) { |
| 11895 | phone.handleNullCipherEnabledChange(); |
| 11896 | } |
| 11897 | } |
| 11898 | |
| 11899 | |
| 11900 | /** |
| 11901 | * Get whether the device is able to connect with null ciphering or integrity |
| 11902 | * algorithms. Note that this retrieves the phone-global preference and not |
| 11903 | * the state of the radio. |
| 11904 | * |
| 11905 | * @throws SecurityException if {@link permission#MODIFY_PHONE_STATE} is not satisfied |
| 11906 | * @throws UnsupportedOperationException if the device does not support the minimum HAL |
| 11907 | * version for this feature. |
| 11908 | * @hide |
| 11909 | */ |
| 11910 | @Override |
| 11911 | @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) |
| 11912 | public boolean isNullCipherAndIntegrityPreferenceEnabled() { |
| 11913 | enforceReadPermission(); |
| 11914 | checkForNullCipherAndIntegritySupport(); |
| 11915 | return getDefaultPhone().getNullCipherAndIntegrityEnabledPreference(); |
| 11916 | } |
| 11917 | |
| 11918 | private void checkForNullCipherAndIntegritySupport() { |
| 11919 | if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_NULL_CIPHER_AND_INTEGRITY_VERSION) { |
| 11920 | throw new UnsupportedOperationException( |
| 11921 | "Null cipher and integrity operations require HAL 2.1 or above"); |
| 11922 | } |
Gil Cukierman | 92cc7db | 2023-01-06 19:25:53 +0000 | [diff] [blame] | 11923 | if (!getDefaultPhone().isNullCipherAndIntegritySupported()) { |
| 11924 | throw new UnsupportedOperationException( |
| 11925 | "Null cipher and integrity operations unsupported by modem"); |
| 11926 | } |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 11927 | } |
| 11928 | |
| 11929 | /** |
Jack Yu | f5badd9 | 2022-12-08 00:50:53 -0800 | [diff] [blame] | 11930 | * Get the SIM state for the slot index. |
| 11931 | * For Remote-SIMs, this method returns {@link IccCardConstants.State#UNKNOWN} |
| 11932 | * |
| 11933 | * @return SIM state as the ordinal of {@link IccCardConstants.State} |
| 11934 | */ |
| 11935 | @Override |
| 11936 | @SimState |
| 11937 | public int getSimStateForSlotIndex(int slotIndex) { |
| 11938 | IccCardConstants.State simState; |
| 11939 | if (slotIndex < 0) { |
| 11940 | simState = IccCardConstants.State.UNKNOWN; |
| 11941 | } else { |
| 11942 | Phone phone = null; |
| 11943 | try { |
| 11944 | phone = PhoneFactory.getPhone(slotIndex); |
| 11945 | } catch (IllegalStateException e) { |
| 11946 | // ignore |
| 11947 | } |
| 11948 | if (phone == null) { |
| 11949 | simState = IccCardConstants.State.UNKNOWN; |
| 11950 | } else { |
| 11951 | IccCard icc = phone.getIccCard(); |
| 11952 | if (icc == null) { |
| 11953 | simState = IccCardConstants.State.UNKNOWN; |
| 11954 | } else { |
| 11955 | simState = icc.getState(); |
| 11956 | } |
| 11957 | } |
| 11958 | } |
| 11959 | return simState.ordinal(); |
| 11960 | } |
Hui Wang | 9b5793a | 2022-12-05 14:38:06 -0600 | [diff] [blame] | 11961 | |
Chinmay Dhodapkar | 3e11ced | 2023-03-03 19:44:00 -0800 | [diff] [blame] | 11962 | private void persistEmergencyCallDiagnosticDataInternal(@NonNull String dropboxTag, |
| 11963 | boolean enableLogcat, |
| 11964 | long logcatStartTimestampMillis, boolean enableTelecomDump, |
| 11965 | boolean enableTelephonyDump) { |
Chinmay Dhodapkar | 66262c4 | 2023-03-10 15:47:41 -0800 | [diff] [blame] | 11966 | DropBoxManager db = mApp.getSystemService(DropBoxManager.class); |
| 11967 | TelephonyManager.EmergencyCallDiagnosticParams edp = |
| 11968 | new TelephonyManager.EmergencyCallDiagnosticParams(); |
| 11969 | edp.setLogcatCollection(enableLogcat, logcatStartTimestampMillis); |
| 11970 | edp.setTelephonyDumpSysCollection(enableTelephonyDump); |
| 11971 | edp.setTelecomDumpSysCollection(enableTelecomDump); |
| 11972 | Log.d(LOG_TAG, "persisting with Params " + edp.toString()); |
| 11973 | DiagnosticDataCollector ddc = new DiagnosticDataCollector(Runtime.getRuntime(), |
| 11974 | Executors.newCachedThreadPool(), db, |
| 11975 | mApp.getSystemService(ActivityManager.class).isLowRamDevice()); |
| 11976 | ddc.persistEmergencyDianosticData(new DataCollectorConfig.Adapter(), edp, dropboxTag); |
Chinmay Dhodapkar | 3e11ced | 2023-03-03 19:44:00 -0800 | [diff] [blame] | 11977 | } |
| 11978 | |
| 11979 | /** |
| 11980 | * Request telephony to persist state for debugging emergency call failures. |
| 11981 | * |
| 11982 | * @param dropBoxTag Tag to use when persisting data to dropbox service. |
| 11983 | * @param enableLogcat whether to collect logcat output |
| 11984 | * @param logcatStartTimestampMillis timestamp from when logcat buffers would be persisted |
| 11985 | * @param enableTelecomDump whether to collect telecom dumpsys |
| 11986 | * @param enableTelephonyDump whether to collect telephony dumpsys |
| 11987 | */ |
| 11988 | @Override |
| 11989 | @RequiresPermission(android.Manifest.permission.DUMP) |
| 11990 | public void persistEmergencyCallDiagnosticData(@NonNull String dropboxTag, boolean enableLogcat, |
| 11991 | long logcatStartTimestampMillis, boolean enableTelecomDump, |
| 11992 | boolean enableTelephonyDump) { |
| 11993 | mApp.enforceCallingPermission(android.Manifest.permission.DUMP, |
| 11994 | "persistEmergencyCallDiagnosticData"); |
| 11995 | final long identity = Binder.clearCallingIdentity(); |
| 11996 | try { |
| 11997 | persistEmergencyCallDiagnosticDataInternal(dropboxTag, enableLogcat, |
| 11998 | logcatStartTimestampMillis, enableTelecomDump, enableTelephonyDump); |
| 11999 | |
| 12000 | } finally { |
| 12001 | Binder.restoreCallingIdentity(identity); |
| 12002 | } |
| 12003 | } |
| 12004 | |
Hui Wang | 9b5793a | 2022-12-05 14:38:06 -0600 | [diff] [blame] | 12005 | /** |
| 12006 | * Get current cell broadcast ranges. |
| 12007 | */ |
| 12008 | @Override |
| 12009 | @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS) |
| 12010 | public List<CellBroadcastIdRange> getCellBroadcastIdRanges(int subId) { |
| 12011 | mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS, |
| 12012 | "getCellBroadcastIdRanges"); |
| 12013 | final long identity = Binder.clearCallingIdentity(); |
| 12014 | try { |
| 12015 | return getPhone(subId).getCellBroadcastIdRanges(); |
| 12016 | } finally { |
| 12017 | Binder.restoreCallingIdentity(identity); |
| 12018 | } |
| 12019 | } |
| 12020 | |
| 12021 | /** |
| 12022 | * Set reception of cell broadcast messages with the list of the given ranges |
| 12023 | * |
| 12024 | * @param ranges the list of {@link CellBroadcastIdRange} to be enabled |
| 12025 | */ |
| 12026 | @Override |
| 12027 | @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS) |
| 12028 | public void setCellBroadcastIdRanges(int subId, @NonNull List<CellBroadcastIdRange> ranges, |
| 12029 | @Nullable IIntegerConsumer callback) { |
| 12030 | mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS, |
| 12031 | "setCellBroadcastIdRanges"); |
| 12032 | final long identity = Binder.clearCallingIdentity(); |
| 12033 | try { |
| 12034 | Phone phone = getPhoneFromSubId(subId); |
| 12035 | if (DBG) { |
| 12036 | log("setCellBroadcastIdRanges for subId :" + subId + ", phone:" + phone); |
| 12037 | } |
| 12038 | phone.setCellBroadcastIdRanges(ranges, result -> { |
| 12039 | if (callback != null) { |
| 12040 | try { |
| 12041 | callback.accept(result); |
| 12042 | } catch (RemoteException e) { |
| 12043 | Log.w(LOG_TAG, "setCellBroadcastIdRanges: callback not available."); |
| 12044 | } |
| 12045 | } |
| 12046 | }); |
| 12047 | } finally { |
| 12048 | Binder.restoreCallingIdentity(identity); |
| 12049 | } |
| 12050 | } |
Hunsuk Choi | 42cc62a | 2022-10-16 06:03:40 +0000 | [diff] [blame] | 12051 | |
| 12052 | /** |
| 12053 | * Returns whether the device supports the domain selection service. |
| 12054 | * |
| 12055 | * @return {@code true} if the device supports the domain selection service. |
| 12056 | */ |
| 12057 | @Override |
| 12058 | public boolean isDomainSelectionSupported() { |
| 12059 | mApp.enforceCallingOrSelfPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
| 12060 | "isDomainSelectionSupported"); |
| 12061 | |
| 12062 | final long identity = Binder.clearCallingIdentity(); |
| 12063 | try { |
| 12064 | return DomainSelectionResolver.getInstance().isDomainSelectionSupported(); |
| 12065 | } finally { |
| 12066 | Binder.restoreCallingIdentity(identity); |
| 12067 | } |
| 12068 | } |
arunvoddu | d5c6ce0 | 2022-12-11 06:03:12 +0000 | [diff] [blame] | 12069 | |
| 12070 | /** |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 12071 | * Request to enable or disable the satellite modem and demo mode. If the satellite modem is |
| 12072 | * enabled, this may also disable the cellular modem, and if the satellite modem is disabled, |
| 12073 | * this may also re-enable the cellular modem. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12074 | * |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12075 | * @param subId The subId of the subscription to set satellite enabled for. |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 12076 | * @param enableSatellite {@code true} to enable the satellite modem and |
| 12077 | * {@code false} to disable. |
| 12078 | * @param enableDemoMode {@code true} to enable demo mode and {@code false} to disable. |
| 12079 | * @param callback The callback to get the result of the request. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12080 | * |
| 12081 | * @throws SecurityException if the caller doesn't have the required permission. |
| 12082 | */ |
| 12083 | @Override |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 12084 | public void requestSatelliteEnabled(int subId, boolean enableSatellite, boolean enableDemoMode, |
| 12085 | @NonNull IIntegerConsumer callback) { |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 12086 | enforceSatelliteCommunicationPermission("requestSatelliteEnabled"); |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 12087 | mSatelliteController.requestSatelliteEnabled(subId, enableSatellite, enableDemoMode, |
| 12088 | callback); |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12089 | } |
| 12090 | |
| 12091 | /** |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12092 | * Request to get whether the satellite modem is enabled. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12093 | * |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12094 | * @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] | 12095 | * @param result The result receiver that returns whether the satellite modem is enabled |
| 12096 | * 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] | 12097 | * |
| 12098 | * @throws SecurityException if the caller doesn't have the required permission. |
| 12099 | */ |
| 12100 | @Override |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12101 | public void requestIsSatelliteEnabled(int subId, @NonNull ResultReceiver result) { |
| 12102 | enforceSatelliteCommunicationPermission("requestIsSatelliteEnabled"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 12103 | mSatelliteController.requestIsSatelliteEnabled(subId, result); |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12104 | } |
| 12105 | |
| 12106 | /** |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 12107 | * Request to get whether the satellite service demo mode is enabled. |
| 12108 | * |
| 12109 | * @param subId The subId of the subscription to check whether the satellite demo mode |
| 12110 | * is enabled for. |
| 12111 | * @param result The result receiver that returns whether the satellite demo mode is enabled |
| 12112 | * if the request is successful or an error code if the request failed. |
| 12113 | * |
| 12114 | * @throws SecurityException if the caller doesn't have the required permission. |
| 12115 | */ |
| 12116 | @Override |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 12117 | public void requestIsDemoModeEnabled(int subId, @NonNull ResultReceiver result) { |
| 12118 | enforceSatelliteCommunicationPermission("requestIsDemoModeEnabled"); |
| 12119 | mSatelliteController.requestIsDemoModeEnabled(subId, result); |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 12120 | } |
| 12121 | |
| 12122 | /** |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12123 | * Request to get whether the satellite service is supported on the device. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12124 | * |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12125 | * @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] | 12126 | * @param result The result receiver that returns whether the satellite service is supported on |
| 12127 | * 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] | 12128 | */ |
| 12129 | @Override |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12130 | public void requestIsSatelliteSupported(int subId, @NonNull ResultReceiver result) { |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 12131 | mSatelliteController.requestIsSatelliteSupported(subId, result); |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12132 | } |
| 12133 | |
| 12134 | /** |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12135 | * Request to get the {@link SatelliteCapabilities} of the satellite service. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12136 | * |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12137 | * @param subId The subId of the subscription to get the satellite capabilities for. |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12138 | * @param result The result receiver that returns the {@link SatelliteCapabilities} |
| 12139 | * if the request is successful or an error code if the request failed. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12140 | * |
| 12141 | * @throws SecurityException if the caller doesn't have required permission. |
| 12142 | */ |
| 12143 | @Override |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12144 | public void requestSatelliteCapabilities(int subId, @NonNull ResultReceiver result) { |
| 12145 | enforceSatelliteCommunicationPermission("requestSatelliteCapabilities"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 12146 | mSatelliteController.requestSatelliteCapabilities(subId, result); |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12147 | } |
| 12148 | |
| 12149 | /** |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 12150 | * Start receiving satellite transmission updates. |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 12151 | * This can be called by the pointing UI when the user starts pointing to the satellite. |
| 12152 | * Modem should continue to report the pointing input as the device or satellite moves. |
| 12153 | * |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 12154 | * @param subId The subId of the subscription to start satellite transmission updates for. |
| 12155 | * @param resultCallback The callback to get the result of the request. |
| 12156 | * @param callback The callback to notify of satellite transmission updates. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12157 | * |
| 12158 | * @throws SecurityException if the caller doesn't have the required permission. |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 12159 | */ |
| 12160 | @Override |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 12161 | public void startSatelliteTransmissionUpdates(int subId, |
| 12162 | @NonNull IIntegerConsumer resultCallback, |
| 12163 | @NonNull ISatelliteTransmissionUpdateCallback callback) { |
| 12164 | enforceSatelliteCommunicationPermission("startSatelliteTransmissionUpdates"); |
| 12165 | mSatelliteController.startSatelliteTransmissionUpdates(subId, resultCallback, callback); |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 12166 | } |
| 12167 | |
| 12168 | /** |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 12169 | * Stop receiving satellite transmission updates. |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 12170 | * This can be called by the pointing UI when the user stops pointing to the satellite. |
| 12171 | * |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 12172 | * @param subId The subId of the subscription to stop satellite transmission updates for. |
| 12173 | * @param resultCallback The callback to get the result of the request. |
| 12174 | * @param callback The callback that was passed to {@link #startSatelliteTransmissionUpdates( |
| 12175 | * int, IIntegerConsumer, ISatelliteTransmissionUpdateCallback)}. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12176 | * |
| 12177 | * @throws SecurityException if the caller doesn't have the required permission. |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 12178 | */ |
| 12179 | @Override |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 12180 | public void stopSatelliteTransmissionUpdates(int subId, |
| 12181 | @NonNull IIntegerConsumer resultCallback, |
| 12182 | @NonNull ISatelliteTransmissionUpdateCallback callback) { |
| 12183 | enforceSatelliteCommunicationPermission("stopSatelliteTransmissionUpdates"); |
| 12184 | mSatelliteController.stopSatelliteTransmissionUpdates(subId, resultCallback, callback); |
Aishwarya Mallampati | 60fe113 | 2023-01-24 19:07:21 +0000 | [diff] [blame] | 12185 | } |
| 12186 | |
| 12187 | /** |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12188 | * Register the subscription with a satellite provider. |
| 12189 | * This is needed to register the subscription if the provider allows dynamic registration. |
| 12190 | * |
| 12191 | * @param subId The subId of the subscription to be provisioned. |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame] | 12192 | * @param token The token to be used as a unique identifier for provisioning with satellite |
| 12193 | * gateway. |
Aishwarya Mallampati | 8b2310c | 2023-03-28 22:01:43 +0000 | [diff] [blame] | 12194 | * @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] | 12195 | * @param callback The callback to get the result of the request. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12196 | * |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12197 | * @return The signal transport used by the caller to cancel the provision request, |
| 12198 | * or {@code null} if the request failed. |
| 12199 | * |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12200 | * @throws SecurityException if the caller doesn't have the required permission. |
| 12201 | */ |
| 12202 | @Override |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12203 | @Nullable public ICancellationSignal provisionSatelliteService(int subId, |
Aishwarya Mallampati | 8b2310c | 2023-03-28 22:01:43 +0000 | [diff] [blame] | 12204 | @NonNull String token, @NonNull byte[] provisionData, |
| 12205 | @NonNull IIntegerConsumer callback) { |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12206 | enforceSatelliteCommunicationPermission("provisionSatelliteService"); |
Aishwarya Mallampati | 8b2310c | 2023-03-28 22:01:43 +0000 | [diff] [blame] | 12207 | return mSatelliteController.provisionSatelliteService(subId, token, provisionData, |
| 12208 | callback); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12209 | } |
| 12210 | |
| 12211 | /** |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame] | 12212 | * Unregister the device/subscription with the satellite provider. |
| 12213 | * This is needed if the provider allows dynamic registration. Once deprovisioned, |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 12214 | * {@link SatelliteProvisionStateCallback#onSatelliteProvisionStateChanged(boolean)} |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame] | 12215 | * should report as deprovisioned. |
| 12216 | * |
| 12217 | * @param subId The subId of the subscription to be deprovisioned. |
| 12218 | * @param token The token of the device/subscription to be deprovisioned. |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 12219 | * @param callback The callback to get the result of the request. |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame] | 12220 | * |
| 12221 | * @throws SecurityException if the caller doesn't have the required permission. |
| 12222 | */ |
| 12223 | @Override |
| 12224 | public void deprovisionSatelliteService(int subId, |
| 12225 | @NonNull String token, @NonNull IIntegerConsumer callback) { |
| 12226 | enforceSatelliteCommunicationPermission("deprovisionSatelliteService"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 12227 | mSatelliteController.deprovisionSatelliteService(subId, token, callback); |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame] | 12228 | } |
| 12229 | |
| 12230 | /** |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 12231 | * Registers for the satellite provision state changed. |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12232 | * |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 12233 | * @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] | 12234 | * @param callback The callback to handle the satellite provision state changed event. |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12235 | * |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12236 | * @return The {@link SatelliteManager.SatelliteError} result of the operation. |
| 12237 | * |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12238 | * @throws SecurityException if the caller doesn't have the required permission. |
| 12239 | */ |
| 12240 | @Override |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12241 | @SatelliteManager.SatelliteError public int registerForSatelliteProvisionStateChanged(int subId, |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 12242 | @NonNull ISatelliteProvisionStateCallback callback) { |
Thomas Nguyen | e77de6d | 2023-02-10 17:42:43 -0800 | [diff] [blame] | 12243 | enforceSatelliteCommunicationPermission("registerForSatelliteProvisionStateChanged"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 12244 | return mSatelliteController.registerForSatelliteProvisionStateChanged(subId, callback); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12245 | } |
| 12246 | |
| 12247 | /** |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 12248 | * Unregisters for the satellite provision state changed. |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 12249 | * If callback was not registered before, the request will be ignored. |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12250 | * |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 12251 | * @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] | 12252 | * @param callback The callback that was passed to |
| 12253 | * {@link #registerForSatelliteProvisionStateChanged(int, ISatelliteProvisionStateCallback)}. |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12254 | * |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12255 | * @throws SecurityException if the caller doesn't have the required permission. |
| 12256 | */ |
| 12257 | @Override |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 12258 | public void unregisterForSatelliteProvisionStateChanged( |
| 12259 | int subId, @NonNull ISatelliteProvisionStateCallback callback) { |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12260 | enforceSatelliteCommunicationPermission("unregisterForSatelliteProvisionStateChanged"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 12261 | mSatelliteController.unregisterForSatelliteProvisionStateChanged(subId, callback); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12262 | } |
| 12263 | |
| 12264 | /** |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12265 | * Request to get whether the device is provisioned with a satellite provider. |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12266 | * |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12267 | * @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] | 12268 | * @param result The result receiver that returns whether the device is provisioned with a |
| 12269 | * satellite provider if the request is successful or an error code if the |
| 12270 | * request failed. |
| 12271 | * |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12272 | * @throws SecurityException if the caller doesn't have the required permission. |
| 12273 | */ |
| 12274 | @Override |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12275 | public void requestIsSatelliteProvisioned(int subId, @NonNull ResultReceiver result) { |
| 12276 | enforceSatelliteCommunicationPermission("requestIsSatelliteProvisioned"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 12277 | mSatelliteController.requestIsSatelliteProvisioned(subId, result); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12278 | } |
| 12279 | |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 12280 | /** |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 12281 | * Registers for modem state changed from satellite modem. |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 12282 | * |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 12283 | * @param subId The subId of the subscription to register for satellite modem state changed. |
| 12284 | * @param callback The callback to handle the satellite modem state changed event. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12285 | * |
| 12286 | * @return The {@link SatelliteManager.SatelliteError} result of the operation. |
| 12287 | * |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 12288 | * @throws SecurityException if the caller doesn't have the required permission. |
| 12289 | */ |
| 12290 | @Override |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 12291 | @SatelliteManager.SatelliteError public int registerForSatelliteModemStateChanged(int subId, |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 12292 | @NonNull ISatelliteStateCallback callback) { |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 12293 | enforceSatelliteCommunicationPermission("registerForSatelliteModemStateChanged"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 12294 | return mSatelliteController.registerForSatelliteModemStateChanged(subId, callback); |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 12295 | } |
| 12296 | |
| 12297 | /** |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 12298 | * Unregisters for modem state changed from satellite modem. |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 12299 | * If callback was not registered before, the request will be ignored. |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 12300 | * |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 12301 | * @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] | 12302 | * @param callback The callback that was passed to |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 12303 | * {@link #registerForSatelliteModemStateChanged(int, ISatelliteStateCallback)}. |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 12304 | * |
| 12305 | * @throws SecurityException if the caller doesn't have the required permission. |
| 12306 | */ |
| 12307 | @Override |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 12308 | public void unregisterForSatelliteModemStateChanged(int subId, |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 12309 | @NonNull ISatelliteStateCallback callback) { |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 12310 | enforceSatelliteCommunicationPermission("unregisterForSatelliteModemStateChanged"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 12311 | mSatelliteController.unregisterForSatelliteModemStateChanged(subId, callback); |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 12312 | } |
| 12313 | |
| 12314 | /** |
| 12315 | * Register to receive incoming datagrams over satellite. |
| 12316 | * |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12317 | * @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] | 12318 | * @param callback The callback to handle incoming datagrams over satellite. |
| 12319 | * |
| 12320 | * @return The {@link SatelliteManager.SatelliteError} result of the operation. |
| 12321 | * |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 12322 | * @throws SecurityException if the caller doesn't have the required permission. |
| 12323 | */ |
| 12324 | @Override |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12325 | @SatelliteManager.SatelliteError public int registerForSatelliteDatagram(int subId, |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 12326 | @NonNull ISatelliteDatagramCallback callback) { |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 12327 | enforceSatelliteCommunicationPermission("registerForSatelliteDatagram"); |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 12328 | return mSatelliteController.registerForSatelliteDatagram(subId, callback); |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 12329 | } |
| 12330 | |
| 12331 | /** |
| 12332 | * Unregister to stop receiving incoming datagrams over satellite. |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 12333 | * If callback was not registered before, the request will be ignored. |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 12334 | * |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12335 | * @param subId The subId of the subscription to unregister for incoming satellite datagrams. |
| 12336 | * @param callback The callback that was passed to |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 12337 | * {@link #registerForSatelliteDatagram(int, ISatelliteDatagramCallback)}. |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 12338 | * |
| 12339 | * @throws SecurityException if the caller doesn't have the required permission. |
| 12340 | */ |
| 12341 | @Override |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 12342 | public void unregisterForSatelliteDatagram(int subId, |
| 12343 | @NonNull ISatelliteDatagramCallback callback) { |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 12344 | enforceSatelliteCommunicationPermission("unregisterForSatelliteDatagram"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 12345 | mSatelliteController.unregisterForSatelliteDatagram(subId, callback); |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 12346 | } |
| 12347 | |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 12348 | /** |
| 12349 | * Poll pending satellite datagrams over satellite. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12350 | * |
Aishwarya Mallampati | 224317a | 2023-02-13 22:09:30 +0000 | [diff] [blame] | 12351 | * This method requests modem to check if there are any pending datagrams to be received over |
| 12352 | * satellite. If there are any incoming datagrams, they will be received via |
Aishwarya Mallampati | 0a78dfb | 2023-03-28 20:29:26 +0000 | [diff] [blame] | 12353 | * {@link SatelliteDatagramCallback#onSatelliteDatagramReceived(long, SatelliteDatagram, int, Consumer)})} |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12354 | * |
Aishwarya Mallampati | 224317a | 2023-02-13 22:09:30 +0000 | [diff] [blame] | 12355 | * @param subId The subId of the subscription used for receiving datagrams. |
| 12356 | * @param callback The callback to get {@link SatelliteManager.SatelliteError} of the request. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12357 | * |
Aishwarya Mallampati | 224317a | 2023-02-13 22:09:30 +0000 | [diff] [blame] | 12358 | * @throws SecurityException if the caller doesn't have required permission. |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 12359 | */ |
Aishwarya Mallampati | 224317a | 2023-02-13 22:09:30 +0000 | [diff] [blame] | 12360 | @Override |
| 12361 | public void pollPendingSatelliteDatagrams(int subId, IIntegerConsumer callback) { |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 12362 | enforceSatelliteCommunicationPermission("pollPendingSatelliteDatagrams"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 12363 | mSatelliteController.pollPendingSatelliteDatagrams(subId, callback); |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 12364 | } |
| 12365 | |
Aishwarya Mallampati | e8ac686 | 2023-02-09 22:13:02 +0000 | [diff] [blame] | 12366 | /** |
| 12367 | * Send datagram over satellite. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12368 | * |
Aishwarya Mallampati | 4d9a094 | 2023-02-16 18:01:53 +0000 | [diff] [blame] | 12369 | * Gateway encodes SOS message or location sharing message into a datagram and passes it as |
| 12370 | * input to this method. Datagram received here will be passed down to modem without any |
| 12371 | * encoding or encryption. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12372 | * |
Aishwarya Mallampati | 224317a | 2023-02-13 22:09:30 +0000 | [diff] [blame] | 12373 | * @param subId The subId of the subscription to send satellite datagrams for. |
| 12374 | * @param datagramType datagram type indicating whether the datagram is of type |
| 12375 | * SOS_SMS or LOCATION_SHARING. |
| 12376 | * @param datagram encoded gateway datagram which is encrypted by the caller. |
| 12377 | * Datagram will be passed down to modem without any encoding or encryption. |
Aishwarya Mallampati | a46437b | 2023-02-21 18:52:58 +0000 | [diff] [blame] | 12378 | * @param needFullScreenPointingUI this is used to indicate pointingUI app to open in |
| 12379 | * full screen mode. |
Aishwarya Mallampati | 14e0de0 | 2023-03-03 00:34:32 +0000 | [diff] [blame] | 12380 | * @param callback The callback to get {@link SatelliteManager.SatelliteError} of the request. |
Aishwarya Mallampati | 224317a | 2023-02-13 22:09:30 +0000 | [diff] [blame] | 12381 | * |
| 12382 | * @throws SecurityException if the caller doesn't have required permission. |
Aishwarya Mallampati | e8ac686 | 2023-02-09 22:13:02 +0000 | [diff] [blame] | 12383 | */ |
| 12384 | @Override |
Aishwarya Mallampati | 14e0de0 | 2023-03-03 00:34:32 +0000 | [diff] [blame] | 12385 | public void sendSatelliteDatagram(int subId, @SatelliteManager.DatagramType int datagramType, |
| 12386 | @NonNull SatelliteDatagram datagram, boolean needFullScreenPointingUI, |
| 12387 | @NonNull IIntegerConsumer callback) { |
Aishwarya Mallampati | e8ac686 | 2023-02-09 22:13:02 +0000 | [diff] [blame] | 12388 | enforceSatelliteCommunicationPermission("sendSatelliteDatagram"); |
Aishwarya Mallampati | 14e0de0 | 2023-03-03 00:34:32 +0000 | [diff] [blame] | 12389 | mSatelliteController.sendSatelliteDatagram(subId, datagramType, datagram, |
| 12390 | needFullScreenPointingUI, callback); |
Aishwarya Mallampati | e8ac686 | 2023-02-09 22:13:02 +0000 | [diff] [blame] | 12391 | } |
| 12392 | |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12393 | /** |
| 12394 | * Request to get whether satellite communication is allowed for the current location. |
| 12395 | * |
| 12396 | * @param subId The subId of the subscription to check whether satellite communication is |
| 12397 | * allowed for the current location for. |
| 12398 | * @param result The result receiver that returns whether satellite communication is allowed |
| 12399 | * for the current location if the request is successful or an error code |
| 12400 | * if the request failed. |
| 12401 | * |
| 12402 | * @throws SecurityException if the caller doesn't have the required permission. |
| 12403 | */ |
| 12404 | @Override |
| 12405 | public void requestIsSatelliteCommunicationAllowedForCurrentLocation(int subId, |
| 12406 | @NonNull ResultReceiver result) { |
| 12407 | enforceSatelliteCommunicationPermission( |
| 12408 | "requestIsSatelliteCommunicationAllowedForCurrentLocation"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 12409 | mSatelliteController.requestIsSatelliteCommunicationAllowedForCurrentLocation(subId, |
| 12410 | result); |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12411 | } |
| 12412 | |
| 12413 | /** |
Hakjun Choi | ae36597 | 2023-04-25 11:00:31 +0000 | [diff] [blame] | 12414 | * Request to get the time after which the satellite will be visible. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12415 | * |
Sarah Chin | 5f57c58 | 2023-02-14 04:16:10 -0800 | [diff] [blame] | 12416 | * @param subId The subId to get the time after which the satellite will be visible for. |
| 12417 | * @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] | 12418 | * be visible if the request is successful or an error code if the request failed. |
| 12419 | * |
| 12420 | * @throws SecurityException if the caller doesn't have the required permission. |
| 12421 | */ |
| 12422 | @Override |
| 12423 | public void requestTimeForNextSatelliteVisibility(int subId, @NonNull ResultReceiver result) { |
| 12424 | enforceSatelliteCommunicationPermission("requestTimeForNextSatelliteVisibility"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 12425 | mSatelliteController.requestTimeForNextSatelliteVisibility(subId, result); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12426 | } |
| 12427 | |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12428 | /** |
Hakjun Choi | ae36597 | 2023-04-25 11:00:31 +0000 | [diff] [blame] | 12429 | * Inform that Device is aligned to satellite for demo mode. |
| 12430 | * |
| 12431 | * @param subId The subId to get the time after which the satellite will be visible for. |
| 12432 | * @param isAligned {@code true} Device is aligned with the satellite for demo mode |
| 12433 | * {@code false} Device fails to align with the satellite for demo mode. |
| 12434 | * |
| 12435 | * @throws SecurityException if the caller doesn't have required permission. |
| 12436 | */ |
| 12437 | @RequiresPermission(Manifest.permission.SATELLITE_COMMUNICATION) |
| 12438 | |
Aishwarya Mallamapti | 697af85 | 2023-08-11 00:21:10 +0000 | [diff] [blame] | 12439 | public void setDeviceAlignedWithSatellite(int subId, @NonNull boolean isAligned) { |
Hakjun Choi | ae36597 | 2023-04-25 11:00:31 +0000 | [diff] [blame] | 12440 | enforceSatelliteCommunicationPermission("informDeviceAlignedToSatellite"); |
Aishwarya Mallamapti | 697af85 | 2023-08-11 00:21:10 +0000 | [diff] [blame] | 12441 | mSatelliteController.setDeviceAlignedWithSatellite(subId, isAligned); |
Hakjun Choi | ae36597 | 2023-04-25 11:00:31 +0000 | [diff] [blame] | 12442 | } |
| 12443 | |
| 12444 | /** |
Thomas Nguyen | d34a5fc | 2023-03-23 21:07:03 -0700 | [diff] [blame] | 12445 | * This API can be used by only CTS to update satellite vendor service package name. |
| 12446 | * |
| 12447 | * @param servicePackageName The package name of the satellite vendor service. |
| 12448 | * @return {@code true} if the satellite vendor service is set successfully, |
| 12449 | * {@code false} otherwise. |
| 12450 | */ |
| 12451 | public boolean setSatelliteServicePackageName(String servicePackageName) { |
| 12452 | Log.d(LOG_TAG, "setSatelliteServicePackageName - " + servicePackageName); |
| 12453 | TelephonyPermissions.enforceShellOnly( |
| 12454 | Binder.getCallingUid(), "setSatelliteServicePackageName"); |
| 12455 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 12456 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 12457 | "setSatelliteServicePackageName"); |
| 12458 | return mSatelliteController.setSatelliteServicePackageName(servicePackageName); |
| 12459 | } |
| 12460 | |
| 12461 | /** |
Thomas Nguyen | 1854a5a | 2023-04-04 09:31:47 -0700 | [diff] [blame] | 12462 | * This API can be used by only CTS to update satellite gateway service package name. |
| 12463 | * |
| 12464 | * @param servicePackageName The package name of the satellite gateway service. |
| 12465 | * @return {@code true} if the satellite gateway service is set successfully, |
| 12466 | * {@code false} otherwise. |
| 12467 | */ |
| 12468 | public boolean setSatelliteGatewayServicePackageName(@Nullable String servicePackageName) { |
| 12469 | Log.d(LOG_TAG, "setSatelliteGatewayServicePackageName - " + servicePackageName); |
| 12470 | TelephonyPermissions.enforceShellOnly( |
| 12471 | Binder.getCallingUid(), "setSatelliteGatewayServicePackageName"); |
| 12472 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 12473 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 12474 | "setSatelliteGatewayServicePackageName"); |
| 12475 | return mSatelliteController.setSatelliteGatewayServicePackageName(servicePackageName); |
| 12476 | } |
| 12477 | |
| 12478 | /** |
Thomas Nguyen | 87dce73 | 2023-04-20 18:27:16 -0700 | [diff] [blame] | 12479 | * This API can be used by only CTS to update satellite pointing UI app package and class names. |
| 12480 | * |
| 12481 | * @param packageName The package name of the satellite pointing UI app. |
| 12482 | * @param className The class name of the satellite pointing UI app. |
| 12483 | * @return {@code true} if the satellite pointing UI app package and class is set successfully, |
| 12484 | * {@code false} otherwise. |
| 12485 | */ |
| 12486 | public boolean setSatellitePointingUiClassName( |
| 12487 | @Nullable String packageName, @Nullable String className) { |
| 12488 | Log.d(LOG_TAG, "setSatellitePointingUiClassName: packageName=" + packageName |
| 12489 | + ", className=" + className); |
| 12490 | TelephonyPermissions.enforceShellOnly( |
| 12491 | Binder.getCallingUid(), "setSatellitePointingUiClassName"); |
| 12492 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 12493 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 12494 | "setSatelliteGatewayServicePackageName"); |
| 12495 | return mSatelliteController.setSatellitePointingUiClassName(packageName, className); |
| 12496 | } |
| 12497 | |
| 12498 | /** |
Thomas Nguyen | f9a533c | 2023-04-06 20:48:41 -0700 | [diff] [blame] | 12499 | * This API can be used by only CTS to update the timeout duration in milliseconds that |
| 12500 | * satellite should stay at listening mode to wait for the next incoming page before disabling |
| 12501 | * listening mode. |
| 12502 | * |
| 12503 | * @param timeoutMillis The timeout duration in millisecond. |
| 12504 | * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise. |
| 12505 | */ |
| 12506 | public boolean setSatelliteListeningTimeoutDuration(long timeoutMillis) { |
| 12507 | Log.d(LOG_TAG, "setSatelliteListeningTimeoutDuration - " + timeoutMillis); |
| 12508 | TelephonyPermissions.enforceShellOnly( |
| 12509 | Binder.getCallingUid(), "setSatelliteListeningTimeoutDuration"); |
| 12510 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 12511 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 12512 | "setSatelliteListeningTimeoutDuration"); |
| 12513 | return mSatelliteController.setSatelliteListeningTimeoutDuration(timeoutMillis); |
| 12514 | } |
| 12515 | |
| 12516 | /** |
Hakjun Choi | ae36597 | 2023-04-25 11:00:31 +0000 | [diff] [blame] | 12517 | * This API can be used by only CTS to update the timeout duration in milliseconds whether |
| 12518 | * the device is aligned with the satellite for demo mode |
| 12519 | * |
| 12520 | * @param timeoutMillis The timeout duration in millisecond. |
| 12521 | * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise. |
| 12522 | */ |
| 12523 | public boolean setSatelliteDeviceAlignedTimeoutDuration(long timeoutMillis) { |
| 12524 | Log.d(LOG_TAG, "setDeviceAlignedTimeoutDuration - " + timeoutMillis); |
| 12525 | TelephonyPermissions.enforceShellOnly( |
| 12526 | Binder.getCallingUid(), "setDeviceAlignedTimeoutDuration"); |
| 12527 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 12528 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 12529 | "setDeviceAlignedTimeoutDuration"); |
| 12530 | return mSatelliteController.setSatelliteDeviceAlignedTimeoutDuration(timeoutMillis); |
| 12531 | } |
| 12532 | |
| 12533 | /** |
arunvoddu | d5c6ce0 | 2022-12-11 06:03:12 +0000 | [diff] [blame] | 12534 | * Check whether the caller (or self, if not processing an IPC) can read device identifiers. |
| 12535 | * |
| 12536 | * <p>This method behaves in one of the following ways: |
| 12537 | * <ul> |
| 12538 | * <li>return true : if the calling package has the appop permission {@link |
| 12539 | * Manifest.permission#USE_ICC_AUTH_WITH_DEVICE_IDENTIFIER} in the manifest </> |
| 12540 | * <li>return true : if any one subscription has the READ_PRIVILEGED_PHONE_STATE |
| 12541 | * permission, the calling package passes a DevicePolicyManager Device Owner / Profile |
| 12542 | * Owner device identifier access check, or the calling package has carrier privileges</> |
| 12543 | * <li>throw SecurityException: if the caller does not meet any of the requirements. |
| 12544 | * </ul> |
| 12545 | */ |
| 12546 | private static boolean checkCallingOrSelfReadDeviceIdentifiersForAnySub(Context context, |
| 12547 | String callingPackage, @Nullable String callingFeatureId, String message) { |
| 12548 | for (Phone phone : PhoneFactory.getPhones()) { |
| 12549 | if (TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(context, |
| 12550 | phone.getSubId(), callingPackage, callingFeatureId, message)) { |
| 12551 | return true; |
| 12552 | } |
| 12553 | } |
| 12554 | return false; |
| 12555 | } |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 12556 | |
| 12557 | /** |
Jack Yu | fa8ed01 | 2023-02-11 15:42:28 -0800 | [diff] [blame] | 12558 | * @return The subscription manager service instance. |
| 12559 | */ |
| 12560 | public SubscriptionManagerService getSubscriptionManagerService() { |
| 12561 | return SubscriptionManagerService.getInstance(); |
| 12562 | } |
| 12563 | |
| 12564 | /** |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 12565 | * Class binds the consumer[callback] and carrierId. |
| 12566 | */ |
| 12567 | private static class CallerCallbackInfo { |
| 12568 | private final Consumer<Integer> mConsumer; |
| 12569 | private final int mCarrierId; |
| 12570 | |
| 12571 | public CallerCallbackInfo(Consumer<Integer> consumer, int carrierId) { |
| 12572 | mConsumer = consumer; |
| 12573 | mCarrierId = carrierId; |
| 12574 | } |
| 12575 | |
| 12576 | public Consumer<Integer> getConsumer() { |
| 12577 | return mConsumer; |
| 12578 | } |
| 12579 | |
| 12580 | public int getCarrierId() { |
| 12581 | return mCarrierId; |
| 12582 | } |
| 12583 | } |
Jack Yu | fa8ed01 | 2023-02-11 15:42:28 -0800 | [diff] [blame] | 12584 | } |