Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2006 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.phone; |
| 18 | |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 19 | import static android.content.pm.PackageManager.PERMISSION_GRANTED; |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 20 | import static android.telephony.TelephonyManager.HAL_SERVICE_NETWORK; |
jimsun | f9ec162 | 2022-09-13 21:18:43 +0800 | [diff] [blame] | 21 | import static android.telephony.TelephonyManager.HAL_SERVICE_RADIO; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 22 | |
Shuo Qian | ccbaf74 | 2021-02-22 18:32:21 -0800 | [diff] [blame] | 23 | import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_CDMA; |
| 24 | import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_GSM; |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 25 | import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_IMS; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 26 | import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY; |
joonhunshin | 3e15424 | 2021-09-17 06:33:39 +0000 | [diff] [blame] | 27 | import static com.android.internal.telephony.TelephonyStatsLog.RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 28 | |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 29 | import android.Manifest; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 30 | import android.Manifest.permission; |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 31 | import android.annotation.NonNull; |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 32 | import android.annotation.Nullable; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 33 | import android.annotation.RequiresPermission; |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 34 | import android.app.ActivityManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 35 | import android.app.AppOpsManager; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 36 | import android.app.PendingIntent; |
Tyler Gunn | 64144d9 | 2022-03-17 14:16:41 -0700 | [diff] [blame] | 37 | import android.app.PropertyInvalidatedCache; |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 38 | import android.app.compat.CompatChanges; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 39 | import android.app.role.RoleManager; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 40 | import android.compat.annotation.ChangeId; |
| 41 | import android.compat.annotation.EnabledSince; |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 42 | import android.content.ComponentName; |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 43 | import android.content.ContentResolver; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 44 | import android.content.Context; |
| 45 | import android.content.Intent; |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 46 | import android.content.SharedPreferences; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 47 | import android.content.pm.ComponentInfo; |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 48 | import android.content.pm.PackageManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 49 | import android.net.Uri; |
| 50 | import android.os.AsyncResult; |
| 51 | import android.os.Binder; |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 52 | import android.os.Build; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 53 | import android.os.Bundle; |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 54 | import android.os.CancellationSignal; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 55 | import android.os.Handler; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 56 | import android.os.IBinder; |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 57 | import android.os.ICancellationSignal; |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 58 | import android.os.LocaleList; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 59 | import android.os.Looper; |
| 60 | import android.os.Message; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 61 | import android.os.Messenger; |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 62 | import android.os.ParcelFileDescriptor; |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 63 | import android.os.ParcelUuid; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 64 | import android.os.PersistableBundle; |
Shuo Qian | cd19c46 | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 65 | import android.os.Process; |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 66 | import android.os.RemoteException; |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 67 | import android.os.ResultReceiver; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 68 | import android.os.ServiceSpecificException; |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 69 | import android.os.SystemClock; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 70 | import android.os.UserHandle; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 71 | import android.os.UserManager; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 72 | import android.os.WorkSource; |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 73 | import android.preference.PreferenceManager; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 74 | import android.provider.DeviceConfig; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 75 | import android.provider.Settings; |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 76 | import android.provider.Telephony; |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 77 | import android.service.carrier.CarrierIdentifier; |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 78 | import android.sysprop.TelephonyProperties; |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 79 | import android.telecom.PhoneAccount; |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 80 | import android.telecom.PhoneAccountHandle; |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 81 | import android.telecom.TelecomManager; |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 82 | import android.telephony.AccessNetworkConstants; |
| 83 | import android.telephony.ActivityStatsTechSpecificInfo; |
Chen Xu | 227e06f | 2019-09-26 22:48:11 -0700 | [diff] [blame] | 84 | import android.telephony.Annotation.ApnType; |
Jack Yu | 0eda684 | 2022-04-18 00:34:46 -0700 | [diff] [blame] | 85 | import android.telephony.Annotation.DataActivityType; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 86 | import android.telephony.Annotation.ThermalMitigationResult; |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 87 | import android.telephony.AnomalyReporter; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 88 | import android.telephony.CallForwardingInfo; |
Junda Liu | 12f7d80 | 2015-05-01 12:06:44 -0700 | [diff] [blame] | 89 | import android.telephony.CarrierConfigManager; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 90 | import android.telephony.CarrierRestrictionRules; |
Hui Wang | 9b5793a | 2022-12-05 14:38:06 -0600 | [diff] [blame] | 91 | import android.telephony.CellBroadcastIdRange; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 92 | import android.telephony.CellIdentity; |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 93 | import android.telephony.CellIdentityCdma; |
| 94 | import android.telephony.CellIdentityGsm; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 95 | import android.telephony.CellInfo; |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 96 | import android.telephony.CellInfoGsm; |
| 97 | import android.telephony.CellInfoWcdma; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 98 | import android.telephony.ClientRequestStats; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 99 | import android.telephony.DataThrottlingRequest; |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 100 | import android.telephony.IBootstrapAuthenticationCallback; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 101 | import android.telephony.ICellInfoCallback; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 102 | import android.telephony.IccOpenLogicalChannelResponse; |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 103 | import android.telephony.LocationAccessPolicy; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 104 | import android.telephony.ModemActivityInfo; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 105 | import android.telephony.NeighboringCellInfo; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 106 | import android.telephony.NetworkScanRequest; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 107 | import android.telephony.PhoneCapability; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 108 | import android.telephony.PhoneNumberRange; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 109 | import android.telephony.RadioAccessFamily; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 110 | import android.telephony.RadioAccessSpecifier; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 111 | import android.telephony.ServiceState; |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 112 | import android.telephony.SignalStrength; |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 113 | import android.telephony.SignalStrengthUpdateRequest; |
| 114 | import android.telephony.SignalThresholdInfo; |
Wink Saville | 0f3b5fc | 2014-11-11 08:40:49 -0800 | [diff] [blame] | 115 | import android.telephony.SubscriptionInfo; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 116 | import android.telephony.SubscriptionManager; |
Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 117 | import android.telephony.TelephonyFrameworkInitializer; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 118 | import android.telephony.TelephonyHistogram; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 119 | import android.telephony.TelephonyManager; |
Jack Yu | f5badd9 | 2022-12-08 00:50:53 -0800 | [diff] [blame] | 120 | import android.telephony.TelephonyManager.SimState; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 121 | import android.telephony.TelephonyScanManager; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 122 | import android.telephony.ThermalMitigationRequest; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 123 | import android.telephony.UiccCardInfo; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 124 | import android.telephony.UiccPortInfo; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 125 | import android.telephony.UiccSlotInfo; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 126 | import android.telephony.UiccSlotMapping; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 127 | import android.telephony.UssdResponse; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 128 | import android.telephony.VisualVoicemailSmsFilterSettings; |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 129 | import android.telephony.data.NetworkSlicingConfig; |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 130 | import android.telephony.emergency.EmergencyNumber; |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 131 | import android.telephony.gba.GbaAuthRequest; |
| 132 | import android.telephony.gba.UaSecurityProtocolIdentifier; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 133 | import android.telephony.ims.ImsException; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 134 | import android.telephony.ims.ProvisioningManager; |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 135 | import android.telephony.ims.RcsClientConfiguration; |
Brad Ebinger | 14d467f | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 136 | import android.telephony.ims.RcsContactUceCapability; |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 137 | import android.telephony.ims.RegistrationManager; |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 138 | import android.telephony.ims.aidl.IFeatureProvisioningCallback; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 139 | import android.telephony.ims.aidl.IImsCapabilityCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 140 | import android.telephony.ims.aidl.IImsConfig; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 141 | import android.telephony.ims.aidl.IImsConfigCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 142 | import android.telephony.ims.aidl.IImsRegistration; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 143 | import android.telephony.ims.aidl.IImsRegistrationCallback; |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 144 | import android.telephony.ims.aidl.IRcsConfigCallback; |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 145 | import android.telephony.ims.feature.ImsFeature; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 146 | import android.telephony.ims.stub.ImsConfigImplBase; |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 147 | import android.telephony.ims.stub.ImsRegistrationImplBase; |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 148 | import android.telephony.satellite.ISatelliteStateListener; |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 149 | import android.telephony.satellite.PointingInfo; |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 150 | import android.telephony.satellite.SatelliteCapabilities; |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 151 | import android.telephony.satellite.SatelliteManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 152 | import android.text.TextUtils; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 153 | import android.util.ArraySet; |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 154 | import android.util.EventLog; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 155 | import android.util.Log; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 156 | import android.util.Pair; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 157 | |
Andrew Lee | 312e817 | 2014-10-23 17:01:36 -0700 | [diff] [blame] | 158 | import com.android.ims.ImsManager; |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 159 | import com.android.ims.internal.IImsServiceFeatureCallback; |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 160 | import com.android.ims.rcs.uce.eab.EabUtil; |
SongFerngWang | fd89b10 | 2021-05-27 22:44:54 +0800 | [diff] [blame] | 161 | import com.android.internal.annotations.VisibleForTesting; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 162 | import com.android.internal.telephony.CallForwardInfo; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 163 | import com.android.internal.telephony.CallManager; |
Tyler Gunn | 52dcf77 | 2017-04-26 11:30:31 -0700 | [diff] [blame] | 164 | import com.android.internal.telephony.CallStateException; |
Tyler Gunn | d433926 | 2021-05-03 14:46:49 -0700 | [diff] [blame] | 165 | import com.android.internal.telephony.CallTracker; |
Rambo Wang | 9c9ffdd | 2022-01-13 21:51:44 -0800 | [diff] [blame] | 166 | import com.android.internal.telephony.CarrierPrivilegesTracker; |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 167 | import com.android.internal.telephony.CarrierResolver; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 168 | import com.android.internal.telephony.CellNetworkScanResult; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 169 | import com.android.internal.telephony.CommandException; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 170 | import com.android.internal.telephony.CommandsInterface; |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 171 | import com.android.internal.telephony.GbaManager; |
Shuo Qian | ccbaf74 | 2021-02-22 18:32:21 -0800 | [diff] [blame] | 172 | import com.android.internal.telephony.GsmCdmaPhone; |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 173 | import com.android.internal.telephony.HalVersion; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 174 | import com.android.internal.telephony.IBooleanConsumer; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 175 | import com.android.internal.telephony.ICallForwardingInfoCallback; |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 176 | import com.android.internal.telephony.IImsStateCallback; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 177 | import com.android.internal.telephony.IIntegerConsumer; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 178 | import com.android.internal.telephony.INumberVerificationCallback; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 179 | import com.android.internal.telephony.ITelephony; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 180 | import com.android.internal.telephony.IccCard; |
Jack Yu | f5badd9 | 2022-12-08 00:50:53 -0800 | [diff] [blame] | 181 | import com.android.internal.telephony.IccCardConstants; |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 182 | import com.android.internal.telephony.IccLogicalChannelRequest; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 183 | import com.android.internal.telephony.LocaleTracker; |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 184 | import com.android.internal.telephony.NetworkScanRequestTracker; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 185 | import com.android.internal.telephony.OperatorInfo; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 186 | import com.android.internal.telephony.Phone; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 187 | import com.android.internal.telephony.PhoneConfigurationManager; |
Nathan Harold | a667c15 | 2016-12-14 11:27:20 -0800 | [diff] [blame] | 188 | import com.android.internal.telephony.PhoneConstantConversions; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 189 | import com.android.internal.telephony.PhoneConstants; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 190 | import com.android.internal.telephony.PhoneFactory; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 191 | import com.android.internal.telephony.ProxyController; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 192 | import com.android.internal.telephony.RIL; |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 193 | import com.android.internal.telephony.RILConstants; |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 194 | import com.android.internal.telephony.RILUtils; |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 195 | import com.android.internal.telephony.RadioInterfaceCapabilityController; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 196 | import com.android.internal.telephony.ServiceStateTracker; |
Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame] | 197 | import com.android.internal.telephony.SmsApplication; |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 198 | import com.android.internal.telephony.SmsController; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 199 | import com.android.internal.telephony.SmsPermissions; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 200 | import com.android.internal.telephony.SubscriptionController; |
Peter Wang | 59571be | 2020-01-27 12:35:15 +0800 | [diff] [blame] | 201 | import com.android.internal.telephony.TelephonyIntents; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 202 | import com.android.internal.telephony.TelephonyPermissions; |
Jack Yu | 27422a5 | 2022-03-21 10:38:05 -0700 | [diff] [blame] | 203 | import com.android.internal.telephony.data.DataUtils; |
Hunsuk Choi | 42cc62a | 2022-10-16 06:03:40 +0000 | [diff] [blame] | 204 | import com.android.internal.telephony.domainselection.DomainSelectionResolver; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 205 | import com.android.internal.telephony.emergency.EmergencyNumberTracker; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 206 | import com.android.internal.telephony.euicc.EuiccConnector; |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 207 | import com.android.internal.telephony.ims.ImsResolver; |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 208 | import com.android.internal.telephony.imsphone.ImsPhone; |
| 209 | import com.android.internal.telephony.imsphone.ImsPhoneCallTracker; |
joonhunshin | 3e15424 | 2021-09-17 06:33:39 +0000 | [diff] [blame] | 210 | import com.android.internal.telephony.metrics.RcsStats; |
Pengquan Meng | 6c2dc9f | 2019-02-06 11:12:53 -0800 | [diff] [blame] | 211 | import com.android.internal.telephony.metrics.TelephonyMetrics; |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 212 | import com.android.internal.telephony.subscription.SubscriptionInfoInternal; |
| 213 | import com.android.internal.telephony.subscription.SubscriptionManagerService; |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 214 | import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 215 | import com.android.internal.telephony.uicc.IccIoResult; |
| 216 | import com.android.internal.telephony.uicc.IccUtils; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 217 | import com.android.internal.telephony.uicc.SIMRecords; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 218 | import com.android.internal.telephony.uicc.UiccCard; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 219 | import com.android.internal.telephony.uicc.UiccCardApplication; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 220 | import com.android.internal.telephony.uicc.UiccController; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 221 | import com.android.internal.telephony.uicc.UiccPort; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 222 | import com.android.internal.telephony.uicc.UiccProfile; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 223 | import com.android.internal.telephony.uicc.UiccSlot; |
zoey chen | c730df8 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 224 | import com.android.internal.telephony.util.LocaleUtils; |
Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame] | 225 | import com.android.internal.telephony.util.TelephonyUtils; |
fionaxu | 7ed723d | 2017-05-30 18:58:54 -0700 | [diff] [blame] | 226 | import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 227 | import com.android.internal.util.FunctionalUtils; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 228 | import com.android.internal.util.HexDump; |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 229 | import com.android.phone.callcomposer.CallComposerPictureManager; |
| 230 | import com.android.phone.callcomposer.CallComposerPictureTransfer; |
| 231 | import com.android.phone.callcomposer.ImageData; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 232 | import com.android.phone.settings.PickSmsSubscriptionActivity; |
Sarah Chin | 46355ba | 2022-11-01 23:51:16 -0700 | [diff] [blame] | 233 | import com.android.phone.slice.SlicePurchaseController; |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 234 | import com.android.phone.utils.CarrierAllowListInfo; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 235 | import com.android.phone.vvm.PhoneAccountHandleConverter; |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 236 | import com.android.phone.vvm.RemoteVvmTaskManager; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 237 | import com.android.phone.vvm.VisualVoicemailSettingsUtil; |
Ta-wei Yen | c890531 | 2017-03-28 11:14:45 -0700 | [diff] [blame] | 238 | import com.android.phone.vvm.VisualVoicemailSmsFilterConfig; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 239 | import com.android.services.telephony.TelecomAccountRegistry; |
| 240 | import com.android.services.telephony.TelephonyConnectionService; |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 241 | import com.android.telephony.Rlog; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 242 | |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 243 | import java.io.ByteArrayOutputStream; |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 244 | import java.io.FileDescriptor; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 245 | import java.io.IOException; |
| 246 | import java.io.InputStream; |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 247 | import java.io.PrintWriter; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 248 | import java.util.ArrayList; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 249 | import java.util.Arrays; |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 250 | import java.util.Collection; |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 251 | import java.util.Collections; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 252 | import java.util.HashMap; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 253 | import java.util.HashSet; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 254 | import java.util.List; |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 255 | import java.util.Locale; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 256 | import java.util.Map; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 257 | import java.util.NoSuchElementException; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 258 | import java.util.Objects; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 259 | import java.util.Set; |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 260 | import java.util.UUID; |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 261 | import java.util.concurrent.ConcurrentHashMap; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 262 | import java.util.concurrent.Executors; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 263 | import java.util.concurrent.atomic.AtomicBoolean; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 264 | import java.util.function.Consumer; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 265 | |
| 266 | /** |
| 267 | * Implementation of the ITelephony interface. |
| 268 | */ |
Santos Cordon | 117fee7 | 2014-05-16 17:56:12 -0700 | [diff] [blame] | 269 | public class PhoneInterfaceManager extends ITelephony.Stub { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 270 | private static final String LOG_TAG = "PhoneInterfaceManager"; |
| 271 | private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2); |
| 272 | private static final boolean DBG_LOC = false; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 273 | private static final boolean DBG_MERGE = false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 274 | |
| 275 | // Message codes used with mMainThreadHandler |
| 276 | private static final int CMD_HANDLE_PIN_MMI = 1; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 277 | private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7; |
| 278 | private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 279 | private static final int CMD_OPEN_CHANNEL = 9; |
| 280 | private static final int EVENT_OPEN_CHANNEL_DONE = 10; |
| 281 | private static final int CMD_CLOSE_CHANNEL = 11; |
| 282 | private static final int EVENT_CLOSE_CHANNEL_DONE = 12; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 283 | private static final int CMD_NV_READ_ITEM = 13; |
| 284 | private static final int EVENT_NV_READ_ITEM_DONE = 14; |
| 285 | private static final int CMD_NV_WRITE_ITEM = 15; |
| 286 | private static final int EVENT_NV_WRITE_ITEM_DONE = 16; |
| 287 | private static final int CMD_NV_WRITE_CDMA_PRL = 17; |
| 288 | private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 289 | private static final int CMD_RESET_MODEM_CONFIG = 19; |
| 290 | private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 291 | private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21; |
| 292 | private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22; |
Sailesh Nepal | 35b5945 | 2014-03-06 09:26:56 -0800 | [diff] [blame] | 293 | private static final int CMD_SEND_ENVELOPE = 25; |
| 294 | private static final int EVENT_SEND_ENVELOPE_DONE = 26; |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 295 | private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27; |
| 296 | private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28; |
Derek Tan | 6b088ee | 2014-09-05 14:15:18 -0700 | [diff] [blame] | 297 | private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29; |
| 298 | private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30; |
| 299 | private static final int CMD_EXCHANGE_SIM_IO = 31; |
| 300 | private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 301 | private static final int CMD_SET_VOICEMAIL_NUMBER = 33; |
| 302 | private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 303 | private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35; |
| 304 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 305 | private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37; |
| 306 | private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 307 | private static final int CMD_PERFORM_NETWORK_SCAN = 39; |
| 308 | private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40; |
| 309 | private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41; |
| 310 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 311 | private static final int CMD_SET_ALLOWED_CARRIERS = 43; |
| 312 | private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44; |
| 313 | private static final int CMD_GET_ALLOWED_CARRIERS = 45; |
| 314 | private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 315 | private static final int CMD_HANDLE_USSD_REQUEST = 47; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 316 | private static final int CMD_GET_FORBIDDEN_PLMNS = 48; |
| 317 | private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 318 | private static final int CMD_SWITCH_SLOTS = 50; |
| 319 | private static final int EVENT_SWITCH_SLOTS_DONE = 51; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 320 | private static final int CMD_GET_NETWORK_SELECTION_MODE = 52; |
| 321 | private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53; |
| 322 | private static final int CMD_GET_CDMA_ROAMING_MODE = 54; |
| 323 | private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55; |
| 324 | private static final int CMD_SET_CDMA_ROAMING_MODE = 56; |
| 325 | private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57; |
| 326 | private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58; |
| 327 | private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 328 | private static final int CMD_GET_ALL_CELL_INFO = 60; |
| 329 | private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61; |
| 330 | private static final int CMD_GET_CELL_LOCATION = 62; |
| 331 | private static final int EVENT_GET_CELL_LOCATION_DONE = 63; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 332 | private static final int CMD_MODEM_REBOOT = 64; |
| 333 | private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 334 | private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66; |
| 335 | private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 336 | private static final int CMD_REQUEST_ENABLE_MODEM = 68; |
| 337 | private static final int EVENT_ENABLE_MODEM_DONE = 69; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 338 | private static final int CMD_GET_MODEM_STATUS = 70; |
| 339 | private static final int EVENT_GET_MODEM_STATUS_DONE = 71; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 340 | private static final int CMD_SET_FORBIDDEN_PLMNS = 72; |
| 341 | private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 342 | private static final int CMD_ERASE_MODEM_CONFIG = 74; |
| 343 | private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75; |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 344 | private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76; |
| 345 | private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77; |
| 346 | private static final int CMD_SET_ICC_LOCK_ENABLED = 78; |
| 347 | private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 348 | private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80; |
| 349 | private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 350 | private static final int MSG_NOTIFY_USER_ACTIVITY = 82; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 351 | private static final int CMD_GET_CALL_FORWARDING = 83; |
| 352 | private static final int EVENT_GET_CALL_FORWARDING_DONE = 84; |
| 353 | private static final int CMD_SET_CALL_FORWARDING = 85; |
| 354 | private static final int EVENT_SET_CALL_FORWARDING_DONE = 86; |
| 355 | private static final int CMD_GET_CALL_WAITING = 87; |
| 356 | private static final int EVENT_GET_CALL_WAITING_DONE = 88; |
| 357 | private static final int CMD_SET_CALL_WAITING = 89; |
| 358 | private static final int EVENT_SET_CALL_WAITING_DONE = 90; |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 359 | private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91; |
| 360 | private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92; |
| 361 | private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93; |
| 362 | private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 363 | private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95; |
| 364 | private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 365 | private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97; |
| 366 | private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 367 | private static final int CMD_SET_DATA_THROTTLING = 99; |
| 368 | private static final int EVENT_SET_DATA_THROTTLING_DONE = 100; |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 369 | private static final int CMD_SET_SIM_POWER = 101; |
| 370 | private static final int EVENT_SET_SIM_POWER_DONE = 102; |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 371 | private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103; |
| 372 | private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104; |
| 373 | private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105; |
| 374 | private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 375 | private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107; |
| 376 | 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] | 377 | private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 378 | private static final int CMD_GET_SLICING_CONFIG = 110; |
| 379 | private static final int EVENT_GET_SLICING_CONFIG_DONE = 111; |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 380 | private static final int CMD_ERASE_DATA_SHARED_PREFERENCES = 112; |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 381 | private static final int CMD_ENABLE_VONR = 113; |
| 382 | private static final int EVENT_ENABLE_VONR_DONE = 114; |
| 383 | private static final int CMD_IS_VONR_ENABLED = 115; |
| 384 | private static final int EVENT_IS_VONR_ENABLED_DONE = 116; |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 385 | private static final int CMD_PURCHASE_PREMIUM_CAPABILITY = 117; |
| 386 | private static final int EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE = 118; |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 387 | private static final int CMD_START_SATELLITE_POSITION_UPDATES = 119; |
| 388 | private static final int EVENT_START_SATELLITE_POSITION_UPDATES_DONE = 120; |
| 389 | private static final int CMD_STOP_SATELLITE_POSITION_UPDATES = 121; |
| 390 | private static final int EVENT_STOP_SATELLITE_POSITION_UPDATES_DONE = 122; |
Aishwarya Mallampati | 60fe113 | 2023-01-24 19:07:21 +0000 | [diff] [blame] | 391 | private static final int CMD_GET_MAX_CHAR_PER_SATELLITE_TEXT_MSG = 123; |
| 392 | private static final int EVENT_GET_MAX_CHAR_PER_SATELLITE_TEXT_MSG_DONE = 124; |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 393 | private static final int CMD_PROVISION_SATELLITE_SERVICE = 125; |
| 394 | private static final int EVENT_PROVISION_SATELLITE_SERVICE_DONE = 126; |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame^] | 395 | private static final int CMD_DEPROVISION_SATELLITE_SERVICE = 127; |
| 396 | private static final int EVENT_DEPROVISION_SATELLITE_SERVICE_DONE = 128; |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 397 | private static final int CMD_SET_SATELLITE_ENABLED = 129; |
| 398 | private static final int EVENT_SET_SATELLITE_ENABLED_DONE = 130; |
| 399 | private static final int CMD_IS_SATELLITE_ENABLED = 131; |
| 400 | private static final int EVENT_IS_SATELLITE_ENABLED_DONE = 132; |
| 401 | private static final int CMD_IS_SATELLITE_SUPPORTED = 133; |
| 402 | private static final int EVENT_IS_SATELLITE_SUPPORTED_DONE = 134; |
| 403 | private static final int CMD_GET_SATELLITE_CAPABILITIES = 135; |
| 404 | private static final int EVENT_GET_SATELLITE_CAPABILITIES_DONE = 136; |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 405 | // Parameters of select command. |
| 406 | private static final int SELECT_COMMAND = 0xA4; |
| 407 | private static final int SELECT_P1 = 0x04; |
| 408 | private static final int SELECT_P2 = 0; |
| 409 | private static final int SELECT_P3 = 0x10; |
| 410 | |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 411 | // Toggling null cipher and integrity support was added in IRadioNetwork 2.1 |
| 412 | private static final int MIN_NULL_CIPHER_AND_INTEGRITY_VERSION = 201; |
| 413 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 414 | /** The singleton instance. */ |
| 415 | private static PhoneInterfaceManager sInstance; |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 416 | private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 417 | |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 418 | private PhoneGlobals mApp; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 419 | private CallManager mCM; |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 420 | private ImsResolver mImsResolver; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 421 | private UserManager mUserManager; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 422 | private AppOpsManager mAppOps; |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 423 | private PackageManager mPm; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 424 | private MainThreadHandler mMainThreadHandler; |
Jack Yu | e37dd26 | 2022-12-16 11:53:37 -0800 | [diff] [blame] | 425 | private final SubscriptionController mSubscriptionController; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 426 | private SharedPreferences mTelephonySharedPreferences; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 427 | private PhoneConfigurationManager mPhoneConfigurationManager; |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 428 | private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 429 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 430 | /** User Activity */ |
| 431 | private AtomicBoolean mNotifyUserActivity; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 432 | private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200; |
| 433 | |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 434 | private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>(); |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 435 | |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 436 | /** |
| 437 | * Map key: subId, value: callback to get error code of the provision request. |
| 438 | */ |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 439 | private final ConcurrentHashMap<Integer, Consumer<Integer>> mSatelliteProvisionCallbacks = |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 440 | new ConcurrentHashMap<>(); |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 441 | /** |
| 442 | * Map key: subId, value: SatellitePositionUpdateHandler to notify registrants. |
| 443 | */ |
| 444 | private final ConcurrentHashMap<IBinder, SatellitePositionUpdateHandler> |
| 445 | mSatellitePositionUpdateHandlers = new ConcurrentHashMap<>(); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 446 | /** |
| 447 | * Map key: subId, value: SatelliteProvisionStateChangedHandler to notify registrants. |
| 448 | */ |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 449 | private final ConcurrentHashMap<Integer, SatelliteProvisionStateChangedHandler> |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 450 | mSatelliteProvisionStateChangedHandlers = new ConcurrentHashMap<>(); |
| 451 | |
Thomas Nguyen | e77de6d | 2023-02-10 17:42:43 -0800 | [diff] [blame] | 452 | private Boolean mIsSatelliteSupported = null; |
| 453 | private final Object mIsSatelliteSupportedLock = new Object(); |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 454 | private final ResultReceiver mSatelliteSupportedReceiver; |
Thomas Nguyen | e77de6d | 2023-02-10 17:42:43 -0800 | [diff] [blame] | 455 | |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 456 | private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_"; |
| 457 | private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_"; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 458 | private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_"; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 459 | private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_"; |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 460 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 461 | // String to store multi SIM allowed |
| 462 | private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted"; |
| 463 | |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 464 | // The AID of ISD-R. |
| 465 | private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100"; |
| 466 | |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 467 | private NetworkScanRequestTracker mNetworkScanRequestTracker; |
| 468 | |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 469 | private static final int TYPE_ALLOCATION_CODE_LENGTH = 8; |
| 470 | private static final int MANUFACTURER_CODE_LENGTH = 8; |
| 471 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 472 | private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1; |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 473 | 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] | 474 | |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 475 | private static final String PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID = |
| 476 | "24bf97a6-e8a6-44d8-a6a4-255d7548733c"; |
| 477 | |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 478 | /** |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 479 | * Experiment flag to enable erase modem config on reset network, default value is false |
| 480 | */ |
| 481 | public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED = |
| 482 | "reset_network_erase_modem_config_enabled"; |
| 483 | |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 484 | 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] | 485 | |
Gary Jian | 76280a4 | 2022-12-07 16:18:33 +0800 | [diff] [blame] | 486 | private static final int MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS = 50; |
| 487 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 488 | /** |
| 489 | * With support for MEP(multiple enabled profile) in Android T, a SIM card can have more than |
| 490 | * one ICCID active at the same time. |
| 491 | * Apps should use below API signatures if targeting SDK is T and beyond. |
| 492 | * |
| 493 | * @hide |
| 494 | */ |
| 495 | @ChangeId |
| 496 | @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU) |
| 497 | public static final long GET_API_SIGNATURES_FROM_UICC_PORT_INFO = 202110963L; |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 498 | |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 499 | /** |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 500 | * Apps targeting on Android T and beyond will get exception whenever icc close channel |
| 501 | * operation fails. |
| 502 | */ |
| 503 | @ChangeId |
| 504 | @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU) |
| 505 | public static final long ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE = 208739934L; |
| 506 | |
| 507 | /** |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 508 | * A request object to use for transmitting data to an ICC. |
| 509 | */ |
| 510 | private static final class IccAPDUArgument { |
| 511 | public int channel, cla, command, p1, p2, p3; |
| 512 | public String data; |
| 513 | |
| 514 | public IccAPDUArgument(int channel, int cla, int command, |
| 515 | int p1, int p2, int p3, String data) { |
| 516 | this.channel = channel; |
| 517 | this.cla = cla; |
| 518 | this.command = command; |
| 519 | this.p1 = p1; |
| 520 | this.p2 = p2; |
| 521 | this.p3 = p3; |
| 522 | this.data = data; |
| 523 | } |
| 524 | } |
| 525 | |
| 526 | /** |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 527 | * A request object to use for transmitting data to an ICC. |
| 528 | */ |
| 529 | private static final class ManualNetworkSelectionArgument { |
| 530 | public OperatorInfo operatorInfo; |
| 531 | public boolean persistSelection; |
| 532 | |
| 533 | public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) { |
| 534 | this.operatorInfo = operatorInfo; |
| 535 | this.persistSelection = persistSelection; |
| 536 | } |
| 537 | } |
| 538 | |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 539 | private static final class PurchasePremiumCapabilityArgument { |
| 540 | public @TelephonyManager.PremiumCapability int capability; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 541 | public @NonNull IIntegerConsumer callback; |
| 542 | |
| 543 | PurchasePremiumCapabilityArgument(@TelephonyManager.PremiumCapability int capability, |
Sarah Chin | b8218c2 | 2023-01-04 13:35:29 -0800 | [diff] [blame] | 544 | @NonNull IIntegerConsumer callback) { |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 545 | this.capability = capability; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 546 | this.callback = callback; |
| 547 | } |
| 548 | } |
| 549 | |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 550 | private static final class ProvisionSatelliteServiceArgument { |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 551 | public @NonNull String token; |
| 552 | public @NonNull Consumer<Integer> callback; |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 553 | public int subId; |
| 554 | |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 555 | ProvisionSatelliteServiceArgument(String token, Consumer<Integer> callback, int subId) { |
| 556 | this.token = token; |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 557 | this.callback = callback; |
| 558 | this.subId = subId; |
| 559 | } |
| 560 | } |
| 561 | |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 562 | private static final class SatellitePositionUpdateHandler extends Handler { |
| 563 | public static final int EVENT_POSITION_UPDATE = 1; |
| 564 | public static final int EVENT_MESSAGE_TRANSFER_STATE_UPDATE = 2; |
| 565 | |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 566 | private final ISatelliteStateListener mCallback; |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 567 | |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 568 | SatellitePositionUpdateHandler(ISatelliteStateListener callback, Looper looper) { |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 569 | super(looper); |
| 570 | mCallback = callback; |
| 571 | } |
| 572 | |
| 573 | @Override |
| 574 | public void handleMessage(@NonNull Message msg) { |
| 575 | switch (msg.what) { |
| 576 | case EVENT_POSITION_UPDATE: { |
| 577 | AsyncResult ar = (AsyncResult) msg.obj; |
| 578 | PointingInfo pointingInfo = (PointingInfo) ar.result; |
| 579 | try { |
| 580 | mCallback.onSatellitePositionUpdate(pointingInfo); |
| 581 | } catch (RemoteException e) { |
| 582 | loge("EVENT_POSITION_UPDATE RemoteException: " + e); |
| 583 | } |
| 584 | break; |
| 585 | } |
| 586 | case EVENT_MESSAGE_TRANSFER_STATE_UPDATE: { |
| 587 | AsyncResult ar = (AsyncResult) msg.obj; |
| 588 | int state = (int) ar.result; |
| 589 | try { |
| 590 | mCallback.onMessageTransferStateUpdate(state); |
| 591 | } catch (RemoteException e) { |
| 592 | loge("EVENT_MESSAGE_TRANSFER_STATE_UPDATE RemoteException: " + e); |
| 593 | } |
| 594 | break; |
| 595 | } |
| 596 | default: |
| 597 | loge("SatellitePositionUpdateHandler unknown event: " + msg.what); |
| 598 | } |
| 599 | } |
| 600 | } |
| 601 | |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 602 | private static final class SatelliteProvisionStateChangedHandler extends Handler { |
| 603 | public static final int EVENT_PROVISION_STATE_CHANGED = 1; |
| 604 | |
| 605 | private ConcurrentHashMap<IBinder, ISatelliteStateListener> mListeners; |
| 606 | private final int mSubId; |
| 607 | |
| 608 | SatelliteProvisionStateChangedHandler(Looper looper, int subId) { |
| 609 | super(looper); |
| 610 | mListeners = new ConcurrentHashMap<>(); |
| 611 | mSubId = subId; |
| 612 | } |
| 613 | |
| 614 | public void addListener(ISatelliteStateListener listener) { |
| 615 | mListeners.put(listener.asBinder(), listener); |
| 616 | } |
| 617 | |
| 618 | public boolean removeListener(ISatelliteStateListener listener) { |
| 619 | return (mListeners.remove(listener.asBinder()) != null); |
| 620 | } |
| 621 | |
| 622 | @Override |
| 623 | public void handleMessage(@NonNull Message msg) { |
| 624 | switch (msg.what) { |
| 625 | case EVENT_PROVISION_STATE_CHANGED: { |
| 626 | AsyncResult ar = (AsyncResult) msg.obj; |
| 627 | boolean provisioned = (boolean) ar.userObj; |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 628 | log("Received EVENT_PROVISION_STATE_CHANGED for subId=" + mSubId |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 629 | + ", provisioned=" + provisioned); |
| 630 | mListeners.values().forEach(listener -> { |
| 631 | try { |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame^] | 632 | listener.onSatelliteProvisionStateChanged(provisioned); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 633 | } catch (RemoteException e) { |
| 634 | log("EVENT_PROVISION_STATE_CHANGED RemoteException: " + e); |
| 635 | } |
| 636 | }); |
| 637 | |
Thomas Nguyen | e77de6d | 2023-02-10 17:42:43 -0800 | [diff] [blame] | 638 | setSatelliteProvisioned(provisioned); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 639 | /** |
| 640 | * TODO: Take bugreport if provisioned is true and user did not initiate the |
| 641 | * provision procedure for the corresponding subscription. |
| 642 | */ |
| 643 | break; |
| 644 | } |
| 645 | default: |
| 646 | loge("SatelliteProvisionStateChangedHandler unknown event: " + msg.what); |
| 647 | } |
| 648 | } |
| 649 | |
Thomas Nguyen | e77de6d | 2023-02-10 17:42:43 -0800 | [diff] [blame] | 650 | private void setSatelliteProvisioned(boolean isProvisioned) { |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 651 | if (mSubId != SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) { |
| 652 | SubscriptionManager.setSubscriptionProperty( |
Thomas Nguyen | e77de6d | 2023-02-10 17:42:43 -0800 | [diff] [blame] | 653 | mSubId, SubscriptionManager.SATELLITE_ENABLED, isProvisioned ? "1" : "0"); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 654 | } else { |
Thomas Nguyen | e77de6d | 2023-02-10 17:42:43 -0800 | [diff] [blame] | 655 | //TODO (b/267826133): set via SatelliteController. |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 656 | } |
| 657 | } |
| 658 | } |
| 659 | |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 660 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 661 | * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the |
| 662 | * request after sending. The main thread will notify the request when it is complete. |
| 663 | */ |
| 664 | private static final class MainThreadRequest { |
| 665 | /** The argument to use for the request */ |
| 666 | public Object argument; |
| 667 | /** The result of the request that is run on the main thread */ |
| 668 | public Object result; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 669 | // The subscriber id that this request applies to. Defaults to |
| 670 | // SubscriptionManager.INVALID_SUBSCRIPTION_ID |
| 671 | public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 672 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 673 | // In cases where subId is unavailable, the caller needs to specify the phone. |
| 674 | public Phone phone; |
| 675 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 676 | public WorkSource workSource; |
| 677 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 678 | public MainThreadRequest(Object argument) { |
| 679 | this.argument = argument; |
| 680 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 681 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 682 | MainThreadRequest(Object argument, Phone phone, WorkSource workSource) { |
| 683 | this.argument = argument; |
| 684 | if (phone != null) { |
| 685 | this.phone = phone; |
| 686 | } |
| 687 | this.workSource = workSource; |
| 688 | } |
| 689 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 690 | MainThreadRequest(Object argument, Integer subId, WorkSource workSource) { |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 691 | this.argument = argument; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 692 | if (subId != null) { |
| 693 | this.subId = subId; |
| 694 | } |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 695 | this.workSource = workSource; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 696 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 697 | } |
| 698 | |
Sailesh Nepal | cc0375f | 2013-11-13 09:15:18 -0800 | [diff] [blame] | 699 | private static final class IncomingThirdPartyCallArgs { |
| 700 | public final ComponentName component; |
| 701 | public final String callId; |
| 702 | public final String callerDisplayName; |
| 703 | |
| 704 | public IncomingThirdPartyCallArgs(ComponentName component, String callId, |
| 705 | String callerDisplayName) { |
| 706 | this.component = component; |
| 707 | this.callId = callId; |
| 708 | this.callerDisplayName = callerDisplayName; |
| 709 | } |
| 710 | } |
| 711 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 712 | /** |
| 713 | * A handler that processes messages on the main thread in the phone process. Since many |
| 714 | * of the Phone calls are not thread safe this is needed to shuttle the requests from the |
| 715 | * inbound binder threads to the main thread in the phone process. The Binder thread |
| 716 | * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting |
| 717 | * on, which will be notified when the operation completes and will contain the result of the |
| 718 | * request. |
| 719 | * |
| 720 | * <p>If a MainThreadRequest object is provided in the msg.obj field, |
| 721 | * note that request.result must be set to something non-null for the calling thread to |
| 722 | * unblock. |
| 723 | */ |
| 724 | private final class MainThreadHandler extends Handler { |
| 725 | @Override |
| 726 | public void handleMessage(Message msg) { |
| 727 | MainThreadRequest request; |
| 728 | Message onCompleted; |
| 729 | AsyncResult ar; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 730 | UiccPort uiccPort; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 731 | IccAPDUArgument iccArgument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 732 | final Phone defaultPhone = getDefaultPhone(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 733 | |
| 734 | switch (msg.what) { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 735 | case CMD_HANDLE_USSD_REQUEST: { |
| 736 | request = (MainThreadRequest) msg.obj; |
| 737 | final Phone phone = getPhoneFromRequest(request); |
| 738 | Pair<String, ResultReceiver> ussdObject = (Pair) request.argument; |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 739 | String ussdRequest = ussdObject.first; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 740 | ResultReceiver wrappedCallback = ussdObject.second; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 741 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 742 | if (!isUssdApiAllowed(request.subId)) { |
| 743 | // Carrier does not support use of this API, return failure. |
| 744 | Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis."); |
| 745 | UssdResponse response = new UssdResponse(ussdRequest, null); |
| 746 | Bundle returnData = new Bundle(); |
| 747 | returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response); |
| 748 | wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 749 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 750 | request.result = true; |
| 751 | notifyRequester(request); |
| 752 | return; |
| 753 | } |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 754 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 755 | try { |
| 756 | request.result = phone != null |
| 757 | ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false; |
| 758 | } catch (CallStateException cse) { |
| 759 | request.result = false; |
| 760 | } |
| 761 | // Wake up the requesting thread |
| 762 | notifyRequester(request); |
| 763 | break; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 764 | } |
| 765 | |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 766 | case CMD_HANDLE_PIN_MMI: { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 767 | request = (MainThreadRequest) msg.obj; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 768 | final Phone phone = getPhoneFromRequest(request); |
| 769 | request.result = phone != null ? |
| 770 | getPhoneFromRequest(request).handlePinMmi((String) request.argument) |
| 771 | : false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 772 | // Wake up the requesting thread |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 773 | notifyRequester(request); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 774 | break; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 775 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 776 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 777 | case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 778 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 779 | iccArgument = (IccAPDUArgument) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 780 | uiccPort = getUiccPortFromRequest(request); |
| 781 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 782 | loge("iccTransmitApduLogicalChannel: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 783 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 784 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 785 | } else { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 786 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE, |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 787 | request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 788 | uiccPort.iccTransmitApduLogicalChannel( |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 789 | iccArgument.channel, iccArgument.cla, iccArgument.command, |
| 790 | iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data, |
| 791 | onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 792 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 793 | break; |
| 794 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 795 | case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 796 | ar = (AsyncResult) msg.obj; |
| 797 | request = (MainThreadRequest) ar.userObj; |
| 798 | if (ar.exception == null && ar.result != null) { |
| 799 | request.result = ar.result; |
| 800 | } else { |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 801 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 802 | if (ar.result == null) { |
| 803 | loge("iccTransmitApduLogicalChannel: Empty response"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 804 | } else if (ar.exception instanceof CommandException) { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 805 | loge("iccTransmitApduLogicalChannel: CommandException: " + |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 806 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 807 | } else { |
| 808 | loge("iccTransmitApduLogicalChannel: Unknown exception"); |
| 809 | } |
| 810 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 811 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 812 | break; |
| 813 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 814 | case CMD_TRANSMIT_APDU_BASIC_CHANNEL: |
| 815 | request = (MainThreadRequest) msg.obj; |
| 816 | iccArgument = (IccAPDUArgument) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 817 | uiccPort = getUiccPortFromRequest(request); |
| 818 | if (uiccPort == null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 819 | loge("iccTransmitApduBasicChannel: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 820 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 821 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 822 | } else { |
| 823 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE, |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 824 | request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 825 | uiccPort.iccTransmitApduBasicChannel( |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 826 | iccArgument.cla, iccArgument.command, iccArgument.p1, |
| 827 | iccArgument.p2, |
| 828 | iccArgument.p3, iccArgument.data, onCompleted); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 829 | } |
| 830 | break; |
| 831 | |
| 832 | case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE: |
| 833 | ar = (AsyncResult) msg.obj; |
| 834 | request = (MainThreadRequest) ar.userObj; |
| 835 | if (ar.exception == null && ar.result != null) { |
| 836 | request.result = ar.result; |
| 837 | } else { |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 838 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 839 | if (ar.result == null) { |
| 840 | loge("iccTransmitApduBasicChannel: Empty response"); |
| 841 | } else if (ar.exception instanceof CommandException) { |
| 842 | loge("iccTransmitApduBasicChannel: CommandException: " + |
| 843 | ar.exception); |
| 844 | } else { |
| 845 | loge("iccTransmitApduBasicChannel: Unknown exception"); |
| 846 | } |
| 847 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 848 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 849 | break; |
| 850 | |
| 851 | case CMD_EXCHANGE_SIM_IO: |
| 852 | request = (MainThreadRequest) msg.obj; |
| 853 | iccArgument = (IccAPDUArgument) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 854 | uiccPort = getUiccPortFromRequest(request); |
| 855 | if (uiccPort == null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 856 | loge("iccExchangeSimIO: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 857 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 858 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 859 | } else { |
| 860 | onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE, |
| 861 | request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 862 | uiccPort.iccExchangeSimIO(iccArgument.cla, /* fileID */ |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 863 | iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3, |
| 864 | iccArgument.data, onCompleted); |
| 865 | } |
| 866 | break; |
| 867 | |
| 868 | case EVENT_EXCHANGE_SIM_IO_DONE: |
| 869 | ar = (AsyncResult) msg.obj; |
| 870 | request = (MainThreadRequest) ar.userObj; |
| 871 | if (ar.exception == null && ar.result != null) { |
| 872 | request.result = ar.result; |
| 873 | } else { |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 874 | request.result = new IccIoResult(0x6f, 0, (byte[]) null); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 875 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 876 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 877 | break; |
| 878 | |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 879 | case CMD_SEND_ENVELOPE: |
| 880 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 881 | uiccPort = getUiccPortFromRequest(request); |
| 882 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 883 | loge("sendEnvelopeWithStatus: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 884 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 885 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 886 | } else { |
| 887 | onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 888 | uiccPort.sendEnvelopeWithStatus((String) request.argument, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 889 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 890 | break; |
| 891 | |
| 892 | case EVENT_SEND_ENVELOPE_DONE: |
| 893 | ar = (AsyncResult) msg.obj; |
| 894 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 895 | if (ar.exception == null && ar.result != null) { |
| 896 | request.result = ar.result; |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 897 | } else { |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 898 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 899 | if (ar.result == null) { |
| 900 | loge("sendEnvelopeWithStatus: Empty response"); |
| 901 | } else if (ar.exception instanceof CommandException) { |
| 902 | loge("sendEnvelopeWithStatus: CommandException: " + |
| 903 | ar.exception); |
| 904 | } else { |
| 905 | loge("sendEnvelopeWithStatus: exception:" + ar.exception); |
| 906 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 907 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 908 | notifyRequester(request); |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 909 | break; |
| 910 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 911 | case CMD_OPEN_CHANNEL: |
| 912 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 913 | uiccPort = getUiccPortFromRequest(request); |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 914 | IccLogicalChannelRequest openChannelRequest = |
| 915 | (IccLogicalChannelRequest) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 916 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 917 | loge("iccOpenLogicalChannel: No UICC"); |
Shishir Agrawal | fc0492a | 2016-02-17 11:15:33 -0800 | [diff] [blame] | 918 | request.result = new IccOpenLogicalChannelResponse(-1, |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 919 | IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 920 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 921 | } else { |
| 922 | onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request); |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 923 | uiccPort.iccOpenLogicalChannel(openChannelRequest.aid, |
| 924 | openChannelRequest.p2, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 925 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 926 | break; |
| 927 | |
| 928 | case EVENT_OPEN_CHANNEL_DONE: |
| 929 | ar = (AsyncResult) msg.obj; |
| 930 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 931 | IccOpenLogicalChannelResponse openChannelResp; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 932 | if (ar.exception == null && ar.result != null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 933 | int[] result = (int[]) ar.result; |
| 934 | int channelId = result[0]; |
| 935 | byte[] selectResponse = null; |
| 936 | if (result.length > 1) { |
| 937 | selectResponse = new byte[result.length - 1]; |
| 938 | for (int i = 1; i < result.length; ++i) { |
| 939 | selectResponse[i - 1] = (byte) result[i]; |
| 940 | } |
| 941 | } |
| 942 | openChannelResp = new IccOpenLogicalChannelResponse(channelId, |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 943 | IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse); |
Rambo Wang | 3b77c4c | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 944 | |
| 945 | uiccPort = getUiccPortFromRequest(request); |
Rambo Wang | e53e07d | 2022-05-10 13:01:13 -0700 | [diff] [blame] | 946 | if (uiccPort == null) { |
| 947 | loge("EVENT_OPEN_CHANNEL_DONE: UiccPort is null"); |
| 948 | } else { |
| 949 | IccLogicalChannelRequest channelRequest = |
| 950 | (IccLogicalChannelRequest) request.argument; |
| 951 | channelRequest.channel = channelId; |
| 952 | uiccPort.onLogicalChannelOpened(channelRequest); |
| 953 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 954 | } else { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 955 | if (ar.result == null) { |
| 956 | loge("iccOpenLogicalChannel: Empty response"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 957 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 958 | if (ar.exception != null) { |
| 959 | loge("iccOpenLogicalChannel: Exception: " + ar.exception); |
| 960 | } |
| 961 | |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 962 | int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 963 | if (ar.exception instanceof CommandException) { |
| 964 | CommandException.Error error = |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 965 | ((CommandException) (ar.exception)).getCommandError(); |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 966 | if (error == CommandException.Error.MISSING_RESOURCE) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 967 | errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 968 | } else if (error == CommandException.Error.NO_SUCH_ELEMENT) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 969 | errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 970 | } |
| 971 | } |
| 972 | openChannelResp = new IccOpenLogicalChannelResponse( |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 973 | IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 974 | } |
Shishir Agrawal | 82c8a46 | 2014-07-31 18:13:17 -0700 | [diff] [blame] | 975 | request.result = openChannelResp; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 976 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 977 | break; |
| 978 | |
| 979 | case CMD_CLOSE_CHANNEL: |
| 980 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 981 | uiccPort = getUiccPortFromRequest(request); |
| 982 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 983 | loge("iccCloseLogicalChannel: No UICC"); |
Chen Xu | a8f0dff | 2022-02-12 00:34:15 -0800 | [diff] [blame] | 984 | request.result = new IllegalArgumentException( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 985 | "iccCloseLogicalChannel: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 986 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 987 | } else { |
| 988 | onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 989 | uiccPort.iccCloseLogicalChannel((Integer) request.argument, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 990 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 991 | break; |
| 992 | |
| 993 | case EVENT_CLOSE_CHANNEL_DONE: |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 994 | ar = (AsyncResult) msg.obj; |
| 995 | request = (MainThreadRequest) ar.userObj; |
| 996 | if (ar.exception == null) { |
| 997 | request.result = true; |
Rambo Wang | 3b77c4c | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 998 | uiccPort = getUiccPortFromRequest(request); |
Rambo Wang | e53e07d | 2022-05-10 13:01:13 -0700 | [diff] [blame] | 999 | if (uiccPort == null) { |
| 1000 | loge("EVENT_CLOSE_CHANNEL_DONE: UiccPort is null"); |
| 1001 | } else { |
| 1002 | final int channelId = (Integer) request.argument; |
| 1003 | uiccPort.onLogicalChannelClosed(channelId); |
| 1004 | } |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 1005 | } else { |
| 1006 | request.result = false; |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 1007 | Exception exception = null; |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 1008 | if (ar.exception instanceof CommandException) { |
| 1009 | loge("iccCloseLogicalChannel: CommandException: " + ar.exception); |
| 1010 | CommandException.Error error = |
| 1011 | ((CommandException) (ar.exception)).getCommandError(); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 1012 | if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 1013 | // should only throw exceptions from the binder threads. |
| 1014 | exception = new IllegalArgumentException( |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 1015 | "iccCloseLogicalChannel: invalid argument "); |
| 1016 | } |
| 1017 | } else { |
| 1018 | loge("iccCloseLogicalChannel: Unknown exception"); |
| 1019 | } |
Chen Xu | a8f0dff | 2022-02-12 00:34:15 -0800 | [diff] [blame] | 1020 | request.result = (exception != null) ? exception : |
| 1021 | new IllegalStateException( |
| 1022 | "exception from modem to close iccLogical Channel"); |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 1023 | } |
| 1024 | notifyRequester(request); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1025 | break; |
| 1026 | |
| 1027 | case CMD_NV_READ_ITEM: |
| 1028 | request = (MainThreadRequest) msg.obj; |
| 1029 | onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1030 | defaultPhone.nvReadItem((Integer) request.argument, onCompleted, |
| 1031 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1032 | break; |
| 1033 | |
| 1034 | case EVENT_NV_READ_ITEM_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 1035 | ar = (AsyncResult) msg.obj; |
| 1036 | request = (MainThreadRequest) ar.userObj; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1037 | if (ar.exception == null && ar.result != null) { |
| 1038 | request.result = ar.result; // String |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 1039 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1040 | request.result = ""; |
| 1041 | if (ar.result == null) { |
| 1042 | loge("nvReadItem: Empty response"); |
| 1043 | } else if (ar.exception instanceof CommandException) { |
| 1044 | loge("nvReadItem: CommandException: " + |
| 1045 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 1046 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1047 | loge("nvReadItem: Unknown exception"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 1048 | } |
| 1049 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1050 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 1051 | break; |
| 1052 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1053 | case CMD_NV_WRITE_ITEM: |
| 1054 | request = (MainThreadRequest) msg.obj; |
| 1055 | onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request); |
| 1056 | Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1057 | defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 1058 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1059 | break; |
| 1060 | |
| 1061 | case EVENT_NV_WRITE_ITEM_DONE: |
| 1062 | handleNullReturnEvent(msg, "nvWriteItem"); |
| 1063 | break; |
| 1064 | |
| 1065 | case CMD_NV_WRITE_CDMA_PRL: |
| 1066 | request = (MainThreadRequest) msg.obj; |
| 1067 | onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1068 | defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1069 | break; |
| 1070 | |
| 1071 | case EVENT_NV_WRITE_CDMA_PRL_DONE: |
| 1072 | handleNullReturnEvent(msg, "nvWriteCdmaPrl"); |
| 1073 | break; |
| 1074 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1075 | case CMD_RESET_MODEM_CONFIG: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1076 | request = (MainThreadRequest) msg.obj; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1077 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1078 | defaultPhone.resetModemConfig(onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1079 | break; |
| 1080 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1081 | case EVENT_RESET_MODEM_CONFIG_DONE: |
| 1082 | handleNullReturnEvent(msg, "resetModemConfig"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1083 | break; |
| 1084 | |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 1085 | case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: { |
| 1086 | request = (MainThreadRequest) msg.obj; |
| 1087 | onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE, |
| 1088 | request); |
| 1089 | Phone phone = getPhoneFromRequest(request); |
| 1090 | if (phone != null) { |
| 1091 | phone.isNrDualConnectivityEnabled(onCompleted, request.workSource); |
| 1092 | } else { |
| 1093 | loge("isNRDualConnectivityEnabled: No phone object"); |
| 1094 | request.result = false; |
| 1095 | notifyRequester(request); |
| 1096 | } |
| 1097 | break; |
| 1098 | } |
| 1099 | |
| 1100 | case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE: |
| 1101 | ar = (AsyncResult) msg.obj; |
| 1102 | request = (MainThreadRequest) ar.userObj; |
| 1103 | if (ar.exception == null && ar.result != null) { |
| 1104 | request.result = ar.result; |
| 1105 | } else { |
| 1106 | // request.result must be set to something non-null |
| 1107 | // for the calling thread to unblock |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 1108 | if (ar.result != null) { |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 1109 | request.result = ar.result; |
| 1110 | } else { |
| 1111 | request.result = false; |
| 1112 | } |
| 1113 | if (ar.result == null) { |
| 1114 | loge("isNRDualConnectivityEnabled: Empty response"); |
| 1115 | } else if (ar.exception instanceof CommandException) { |
| 1116 | loge("isNRDualConnectivityEnabled: CommandException: " |
| 1117 | + ar.exception); |
| 1118 | } else { |
| 1119 | loge("isNRDualConnectivityEnabled: Unknown exception"); |
| 1120 | } |
| 1121 | } |
| 1122 | notifyRequester(request); |
| 1123 | break; |
| 1124 | |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 1125 | case CMD_IS_VONR_ENABLED: { |
| 1126 | request = (MainThreadRequest) msg.obj; |
| 1127 | onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE, |
| 1128 | request); |
| 1129 | Phone phone = getPhoneFromRequest(request); |
| 1130 | if (phone != null) { |
| 1131 | phone.isVoNrEnabled(onCompleted, request.workSource); |
| 1132 | } else { |
| 1133 | loge("isVoNrEnabled: No phone object"); |
| 1134 | request.result = false; |
| 1135 | notifyRequester(request); |
| 1136 | } |
| 1137 | break; |
| 1138 | } |
| 1139 | |
| 1140 | case EVENT_IS_VONR_ENABLED_DONE: |
| 1141 | ar = (AsyncResult) msg.obj; |
| 1142 | request = (MainThreadRequest) ar.userObj; |
| 1143 | if (ar.exception == null && ar.result != null) { |
| 1144 | request.result = ar.result; |
| 1145 | } else { |
| 1146 | // request.result must be set to something non-null |
| 1147 | // for the calling thread to unblock |
| 1148 | if (ar.result != null) { |
| 1149 | request.result = ar.result; |
| 1150 | } else { |
| 1151 | request.result = false; |
| 1152 | } |
| 1153 | if (ar.result == null) { |
| 1154 | loge("isVoNrEnabled: Empty response"); |
| 1155 | } else if (ar.exception instanceof CommandException) { |
| 1156 | loge("isVoNrEnabled: CommandException: " |
| 1157 | + ar.exception); |
| 1158 | } else { |
| 1159 | loge("isVoNrEnabled: Unknown exception"); |
| 1160 | } |
| 1161 | } |
| 1162 | notifyRequester(request); |
| 1163 | break; |
| 1164 | |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 1165 | case CMD_ENABLE_NR_DUAL_CONNECTIVITY: { |
| 1166 | request = (MainThreadRequest) msg.obj; |
| 1167 | onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request); |
| 1168 | Phone phone = getPhoneFromRequest(request); |
| 1169 | if (phone != null) { |
| 1170 | phone.setNrDualConnectivityState((int) request.argument, onCompleted, |
| 1171 | request.workSource); |
| 1172 | } else { |
| 1173 | loge("enableNrDualConnectivity: No phone object"); |
| 1174 | request.result = |
| 1175 | TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE; |
| 1176 | notifyRequester(request); |
| 1177 | } |
| 1178 | break; |
| 1179 | } |
| 1180 | |
| 1181 | case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: { |
| 1182 | ar = (AsyncResult) msg.obj; |
| 1183 | request = (MainThreadRequest) ar.userObj; |
| 1184 | if (ar.exception == null) { |
| 1185 | request.result = |
| 1186 | TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS; |
| 1187 | } else { |
| 1188 | request.result = |
| 1189 | TelephonyManager |
| 1190 | .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR; |
| 1191 | if (ar.exception instanceof CommandException) { |
| 1192 | CommandException.Error error = |
| 1193 | ((CommandException) (ar.exception)).getCommandError(); |
| 1194 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1195 | request.result = |
| 1196 | TelephonyManager |
| 1197 | .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE; |
Sooraj Sasindran | 2965416 | 2021-03-03 23:00:01 +0000 | [diff] [blame] | 1198 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1199 | request.result = |
| 1200 | TelephonyManager |
| 1201 | .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED; |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 1202 | } |
| 1203 | loge("enableNrDualConnectivity" + ": CommandException: " |
| 1204 | + ar.exception); |
| 1205 | } else { |
| 1206 | loge("enableNrDualConnectivity" + ": Unknown exception"); |
| 1207 | } |
| 1208 | } |
| 1209 | notifyRequester(request); |
| 1210 | break; |
| 1211 | } |
| 1212 | |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 1213 | case CMD_ENABLE_VONR: { |
| 1214 | request = (MainThreadRequest) msg.obj; |
| 1215 | onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request); |
| 1216 | Phone phone = getPhoneFromRequest(request); |
| 1217 | if (phone != null) { |
| 1218 | phone.setVoNrEnabled((boolean) request.argument, onCompleted, |
| 1219 | request.workSource); |
| 1220 | } else { |
| 1221 | loge("setVoNrEnabled: No phone object"); |
| 1222 | request.result = |
| 1223 | TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE; |
| 1224 | notifyRequester(request); |
| 1225 | } |
| 1226 | break; |
| 1227 | } |
| 1228 | |
| 1229 | case EVENT_ENABLE_VONR_DONE: { |
| 1230 | ar = (AsyncResult) msg.obj; |
| 1231 | request = (MainThreadRequest) ar.userObj; |
| 1232 | if (ar.exception == null) { |
| 1233 | request.result = TelephonyManager.ENABLE_VONR_SUCCESS; |
| 1234 | } else { |
| 1235 | request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR; |
| 1236 | if (ar.exception instanceof CommandException) { |
| 1237 | CommandException.Error error = |
| 1238 | ((CommandException) (ar.exception)).getCommandError(); |
| 1239 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1240 | request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE; |
| 1241 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1242 | request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED; |
| 1243 | } else { |
| 1244 | request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR; |
| 1245 | } |
| 1246 | loge("setVoNrEnabled" + ": CommandException: " |
| 1247 | + ar.exception); |
| 1248 | } else { |
| 1249 | loge("setVoNrEnabled" + ": Unknown exception"); |
| 1250 | } |
| 1251 | } |
| 1252 | notifyRequester(request); |
| 1253 | break; |
| 1254 | } |
| 1255 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1256 | case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1257 | request = (MainThreadRequest) msg.obj; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1258 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE, |
| 1259 | request); |
| 1260 | getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1261 | break; |
| 1262 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1263 | case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1264 | ar = (AsyncResult) msg.obj; |
| 1265 | request = (MainThreadRequest) ar.userObj; |
| 1266 | if (ar.exception == null && ar.result != null) { |
| 1267 | request.result = ar.result; // Integer |
| 1268 | } else { |
Nazish Tabassum | e8ba43a | 2020-07-28 14:49:25 +0530 | [diff] [blame] | 1269 | // request.result must be set to something non-null |
| 1270 | // for the calling thread to unblock |
| 1271 | request.result = new int[]{-1}; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1272 | if (ar.result == null) { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1273 | loge("getAllowedNetworkTypesBitmask: Empty response"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1274 | } else if (ar.exception instanceof CommandException) { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1275 | loge("getAllowedNetworkTypesBitmask: CommandException: " |
| 1276 | + ar.exception); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1277 | } else { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1278 | loge("getAllowedNetworkTypesBitmask: Unknown exception"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1279 | } |
| 1280 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1281 | notifyRequester(request); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1282 | break; |
| 1283 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1284 | case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1285 | request = (MainThreadRequest) msg.obj; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1286 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE, |
| 1287 | request); |
| 1288 | Pair<Integer, Long> reasonWithNetworkTypes = |
| 1289 | (Pair<Integer, Long>) request.argument; |
| 1290 | getPhoneFromRequest(request).setAllowedNetworkTypes( |
| 1291 | reasonWithNetworkTypes.first, |
| 1292 | reasonWithNetworkTypes.second, |
| 1293 | onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1294 | break; |
| 1295 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1296 | case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE: |
| 1297 | handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1298 | break; |
| 1299 | |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 1300 | case CMD_INVOKE_OEM_RIL_REQUEST_RAW: |
| 1301 | request = (MainThreadRequest)msg.obj; |
| 1302 | onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1303 | defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 1304 | break; |
| 1305 | |
| 1306 | case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE: |
| 1307 | ar = (AsyncResult)msg.obj; |
| 1308 | request = (MainThreadRequest)ar.userObj; |
| 1309 | request.result = ar; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1310 | notifyRequester(request); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 1311 | break; |
| 1312 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1313 | case CMD_SET_VOICEMAIL_NUMBER: |
| 1314 | request = (MainThreadRequest) msg.obj; |
| 1315 | onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request); |
| 1316 | Pair<String, String> tagNum = (Pair<String, String>) request.argument; |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1317 | getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second, |
| 1318 | onCompleted); |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1319 | break; |
| 1320 | |
| 1321 | case EVENT_SET_VOICEMAIL_NUMBER_DONE: |
| 1322 | handleNullReturnEvent(msg, "setVoicemailNumber"); |
| 1323 | break; |
| 1324 | |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 1325 | case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC: |
| 1326 | request = (MainThreadRequest) msg.obj; |
| 1327 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE, |
| 1328 | request); |
| 1329 | getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted); |
| 1330 | break; |
| 1331 | |
| 1332 | case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE: |
| 1333 | handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic"); |
| 1334 | break; |
| 1335 | |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1336 | case CMD_PERFORM_NETWORK_SCAN: |
| 1337 | request = (MainThreadRequest) msg.obj; |
| 1338 | onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request); |
| 1339 | getPhoneFromRequest(request).getAvailableNetworks(onCompleted); |
| 1340 | break; |
| 1341 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1342 | case CMD_GET_CALL_FORWARDING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1343 | request = (MainThreadRequest) msg.obj; |
| 1344 | onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1345 | Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args = |
| 1346 | (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>) |
| 1347 | request.argument; |
| 1348 | int callForwardingReason = args.first; |
| 1349 | request.phone.getCallForwardingOption(callForwardingReason, onCompleted); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1350 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1351 | } |
| 1352 | case EVENT_GET_CALL_FORWARDING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1353 | ar = (AsyncResult) msg.obj; |
| 1354 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1355 | TelephonyManager.CallForwardingInfoCallback callback = |
| 1356 | ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>) |
| 1357 | request.argument).second; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1358 | if (ar.exception == null && ar.result != null) { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1359 | CallForwardingInfo callForwardingInfo = null; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1360 | CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result; |
| 1361 | for (CallForwardInfo callForwardInfo : callForwardInfos) { |
| 1362 | // Service Class is a bit mask per 3gpp 27.007. Search for |
| 1363 | // any service for voice call. |
| 1364 | if ((callForwardInfo.serviceClass |
| 1365 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0) { |
Yuchen Dong | 69cc141 | 2021-09-27 20:27:01 +0800 | [diff] [blame] | 1366 | callForwardingInfo = new CallForwardingInfo( |
| 1367 | callForwardInfo.status |
| 1368 | == CommandsInterface.CF_ACTION_ENABLE, |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1369 | callForwardInfo.reason, |
| 1370 | callForwardInfo.number, |
| 1371 | callForwardInfo.timeSeconds); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1372 | break; |
| 1373 | } |
| 1374 | } |
| 1375 | // Didn't find a call forward info for voice call. |
| 1376 | if (callForwardingInfo == null) { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1377 | callForwardingInfo = new CallForwardingInfo(false /* enabled */, |
| 1378 | 0 /* reason */, null /* number */, 0 /* timeout */); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1379 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1380 | callback.onCallForwardingInfoAvailable(callForwardingInfo); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1381 | } else { |
| 1382 | if (ar.result == null) { |
| 1383 | loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response"); |
| 1384 | } |
| 1385 | if (ar.exception != null) { |
| 1386 | loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception); |
| 1387 | } |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1388 | int errorCode = TelephonyManager |
| 1389 | .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1390 | if (ar.exception instanceof CommandException) { |
| 1391 | CommandException.Error error = |
| 1392 | ((CommandException) (ar.exception)).getCommandError(); |
| 1393 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1394 | errorCode = TelephonyManager |
| 1395 | .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1396 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1397 | errorCode = TelephonyManager |
| 1398 | .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1399 | } |
| 1400 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1401 | callback.onError(errorCode); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1402 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1403 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1404 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1405 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1406 | case CMD_SET_CALL_FORWARDING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1407 | request = (MainThreadRequest) msg.obj; |
| 1408 | onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1409 | request = (MainThreadRequest) msg.obj; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1410 | CallForwardingInfo callForwardingInfoToSet = |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1411 | ((Pair<CallForwardingInfo, Consumer<Integer>>) |
| 1412 | request.argument).first; |
| 1413 | request.phone.setCallForwardingOption( |
| 1414 | callForwardingInfoToSet.isEnabled() |
Calvin Pan | 258f1f7 | 2021-07-28 21:46:56 +0800 | [diff] [blame] | 1415 | ? CommandsInterface.CF_ACTION_REGISTRATION |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1416 | : CommandsInterface.CF_ACTION_DISABLE, |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1417 | callForwardingInfoToSet.getReason(), |
| 1418 | callForwardingInfoToSet.getNumber(), |
| 1419 | callForwardingInfoToSet.getTimeoutSeconds(), onCompleted); |
| 1420 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1421 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1422 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1423 | case EVENT_SET_CALL_FORWARDING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1424 | ar = (AsyncResult) msg.obj; |
| 1425 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1426 | Consumer<Integer> callback = |
| 1427 | ((Pair<CallForwardingInfo, Consumer<Integer>>) |
| 1428 | request.argument).second; |
| 1429 | if (ar.exception != null) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1430 | loge("setCallForwarding exception: " + ar.exception); |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1431 | int errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1432 | .RESULT_ERROR_UNKNOWN; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1433 | if (ar.exception instanceof CommandException) { |
| 1434 | CommandException.Error error = |
| 1435 | ((CommandException) (ar.exception)).getCommandError(); |
| 1436 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1437 | errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1438 | .RESULT_ERROR_FDN_CHECK_FAILURE; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1439 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1440 | errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1441 | .RESULT_ERROR_NOT_SUPPORTED; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1442 | } |
| 1443 | } |
| 1444 | callback.accept(errorCode); |
| 1445 | } else { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1446 | callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1447 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1448 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1449 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1450 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1451 | case CMD_GET_CALL_WAITING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1452 | request = (MainThreadRequest) msg.obj; |
| 1453 | onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request); |
| 1454 | getPhoneFromRequest(request).getCallWaiting(onCompleted); |
| 1455 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1456 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1457 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1458 | case EVENT_GET_CALL_WAITING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1459 | ar = (AsyncResult) msg.obj; |
| 1460 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1461 | Consumer<Integer> callback = (Consumer<Integer>) request.argument; |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1462 | int callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1463 | if (ar.exception == null && ar.result != null) { |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1464 | int[] callForwardResults = (int[]) ar.result; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1465 | // Service Class is a bit mask per 3gpp 27.007. |
| 1466 | // Search for any service for voice call. |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1467 | if (callForwardResults.length > 1 |
| 1468 | && ((callForwardResults[1] |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1469 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) { |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1470 | callWaitingStatus = callForwardResults[0] == 0 |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1471 | ? TelephonyManager.CALL_WAITING_STATUS_DISABLED |
| 1472 | : TelephonyManager.CALL_WAITING_STATUS_ENABLED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1473 | } else { |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1474 | callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1475 | } |
| 1476 | } else { |
| 1477 | if (ar.result == null) { |
| 1478 | loge("EVENT_GET_CALL_WAITING_DONE: Empty response"); |
| 1479 | } |
| 1480 | if (ar.exception != null) { |
| 1481 | loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception); |
| 1482 | } |
| 1483 | if (ar.exception instanceof CommandException) { |
| 1484 | CommandException.Error error = |
| 1485 | ((CommandException) (ar.exception)).getCommandError(); |
| 1486 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1487 | callWaitingStatus = |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1488 | TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED; |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1489 | } else if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
| 1490 | callWaitingStatus = |
| 1491 | TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1492 | } |
| 1493 | } |
| 1494 | } |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1495 | callback.accept(callWaitingStatus); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1496 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1497 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1498 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1499 | case CMD_SET_CALL_WAITING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1500 | request = (MainThreadRequest) msg.obj; |
| 1501 | onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1502 | boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first; |
| 1503 | getPhoneFromRequest(request).setCallWaiting(enable, onCompleted); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1504 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1505 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1506 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1507 | case EVENT_SET_CALL_WAITING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1508 | ar = (AsyncResult) msg.obj; |
| 1509 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1510 | boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first; |
| 1511 | Consumer<Integer> callback = |
| 1512 | ((Pair<Boolean, Consumer<Integer>>) request.argument).second; |
| 1513 | if (ar.exception != null) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1514 | loge("setCallWaiting exception: " + ar.exception); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1515 | if (ar.exception instanceof CommandException) { |
| 1516 | CommandException.Error error = |
| 1517 | ((CommandException) (ar.exception)).getCommandError(); |
| 1518 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1519 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED); |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1520 | } else if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
| 1521 | callback.accept( |
| 1522 | TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1523 | } else { |
| 1524 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 1525 | } |
| 1526 | } else { |
| 1527 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 1528 | } |
| 1529 | } else { |
| 1530 | callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED |
| 1531 | : TelephonyManager.CALL_WAITING_STATUS_DISABLED); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1532 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1533 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1534 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1535 | case EVENT_PERFORM_NETWORK_SCAN_DONE: |
| 1536 | ar = (AsyncResult) msg.obj; |
| 1537 | request = (MainThreadRequest) ar.userObj; |
| 1538 | CellNetworkScanResult cellScanResult; |
| 1539 | if (ar.exception == null && ar.result != null) { |
| 1540 | cellScanResult = new CellNetworkScanResult( |
| 1541 | CellNetworkScanResult.STATUS_SUCCESS, |
| 1542 | (List<OperatorInfo>) ar.result); |
| 1543 | } else { |
| 1544 | if (ar.result == null) { |
| 1545 | loge("getCellNetworkScanResults: Empty response"); |
| 1546 | } |
| 1547 | if (ar.exception != null) { |
| 1548 | loge("getCellNetworkScanResults: Exception: " + ar.exception); |
| 1549 | } |
| 1550 | int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR; |
| 1551 | if (ar.exception instanceof CommandException) { |
| 1552 | CommandException.Error error = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 1553 | ((CommandException) (ar.exception)).getCommandError(); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1554 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1555 | errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE; |
| 1556 | } else if (error == CommandException.Error.GENERIC_FAILURE) { |
| 1557 | errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE; |
| 1558 | } |
| 1559 | } |
| 1560 | cellScanResult = new CellNetworkScanResult(errorCode, null); |
| 1561 | } |
| 1562 | request.result = cellScanResult; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1563 | notifyRequester(request); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1564 | break; |
| 1565 | |
| 1566 | case CMD_SET_NETWORK_SELECTION_MODE_MANUAL: |
| 1567 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1568 | ManualNetworkSelectionArgument selArg = |
| 1569 | (ManualNetworkSelectionArgument) request.argument; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1570 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE, |
| 1571 | request); |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1572 | getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo, |
| 1573 | selArg.persistSelection, onCompleted); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1574 | break; |
| 1575 | |
| 1576 | case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE: |
Pengquan Meng | e3d01e2 | 2018-09-20 15:25:35 -0700 | [diff] [blame] | 1577 | ar = (AsyncResult) msg.obj; |
| 1578 | request = (MainThreadRequest) ar.userObj; |
| 1579 | if (ar.exception == null) { |
| 1580 | request.result = true; |
| 1581 | } else { |
| 1582 | request.result = false; |
| 1583 | loge("setNetworkSelectionModeManual " + ar.exception); |
| 1584 | } |
| 1585 | notifyRequester(request); |
| 1586 | mApp.onNetworkSelectionChanged(request.subId); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1587 | break; |
| 1588 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1589 | case CMD_GET_MODEM_ACTIVITY_INFO: |
| 1590 | request = (MainThreadRequest) msg.obj; |
| 1591 | onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1592 | if (defaultPhone != null) { |
| 1593 | defaultPhone.getModemActivityInfo(onCompleted, request.workSource); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1594 | } else { |
| 1595 | ResultReceiver result = (ResultReceiver) request.argument; |
| 1596 | Bundle bundle = new Bundle(); |
| 1597 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 1598 | new ModemActivityInfo(0, 0, 0, |
| 1599 | new int[ModemActivityInfo.getNumTxPowerLevels()], 0)); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1600 | result.send(0, bundle); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1601 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1602 | break; |
| 1603 | |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1604 | case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: { |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1605 | ar = (AsyncResult) msg.obj; |
| 1606 | request = (MainThreadRequest) ar.userObj; |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1607 | ResultReceiver result = (ResultReceiver) request.argument; |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1608 | int error = 0; |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 1609 | ModemActivityInfo ret = null; |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1610 | if (mLastModemActivityInfo == null) { |
| 1611 | mLastModemActivitySpecificInfo = new ActivityStatsTechSpecificInfo[1]; |
| 1612 | mLastModemActivitySpecificInfo[0] = |
| 1613 | new ActivityStatsTechSpecificInfo( |
| 1614 | 0, |
| 1615 | 0, |
| 1616 | new int[ModemActivityInfo.getNumTxPowerLevels()], |
| 1617 | 0); |
| 1618 | mLastModemActivityInfo = |
| 1619 | new ModemActivityInfo(0, 0, 0, mLastModemActivitySpecificInfo); |
| 1620 | } |
| 1621 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1622 | if (ar.exception == null && ar.result != null) { |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1623 | // Update the last modem activity info and the result of the request. |
| 1624 | ModemActivityInfo info = (ModemActivityInfo) ar.result; |
| 1625 | if (isModemActivityInfoValid(info)) { |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1626 | mergeModemActivityInfo(info); |
Gary Jian | 76280a4 | 2022-12-07 16:18:33 +0800 | [diff] [blame] | 1627 | } else { |
| 1628 | loge("queryModemActivityInfo: invalid response"); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1629 | } |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 1630 | // This is needed to decouple ret from mLastModemActivityInfo |
| 1631 | // We don't want to return mLastModemActivityInfo which is updated |
| 1632 | // inside mergeModemActivityInfo() |
| 1633 | ret = new ModemActivityInfo( |
| 1634 | mLastModemActivityInfo.getTimestampMillis(), |
| 1635 | mLastModemActivityInfo.getSleepTimeMillis(), |
| 1636 | mLastModemActivityInfo.getIdleTimeMillis(), |
| 1637 | deepCopyModemActivitySpecificInfo(mLastModemActivitySpecificInfo)); |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1638 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1639 | } else { |
| 1640 | if (ar.result == null) { |
| 1641 | loge("queryModemActivityInfo: Empty response"); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1642 | error = TelephonyManager.ModemActivityInfoException |
| 1643 | .ERROR_INVALID_INFO_RECEIVED; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1644 | } else if (ar.exception instanceof CommandException) { |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1645 | loge("queryModemActivityInfo: CommandException: " + ar.exception); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1646 | error = TelephonyManager.ModemActivityInfoException |
| 1647 | .ERROR_MODEM_RESPONSE_ERROR; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1648 | } else { |
| 1649 | loge("queryModemActivityInfo: Unknown exception"); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1650 | error = TelephonyManager.ModemActivityInfoException |
| 1651 | .ERROR_UNKNOWN; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1652 | } |
| 1653 | } |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1654 | Bundle bundle = new Bundle(); |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 1655 | if (ret != null) { |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1656 | bundle.putParcelable( |
| 1657 | TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 1658 | ret); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1659 | } else { |
| 1660 | bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error); |
| 1661 | } |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1662 | result.send(0, bundle); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1663 | notifyRequester(request); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1664 | break; |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1665 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1666 | |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 1667 | case CMD_SET_ALLOWED_CARRIERS: { |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1668 | request = (MainThreadRequest) msg.obj; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1669 | CarrierRestrictionRules argument = |
| 1670 | (CarrierRestrictionRules) request.argument; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1671 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request); |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1672 | defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1673 | break; |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 1674 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1675 | |
| 1676 | case EVENT_SET_ALLOWED_CARRIERS_DONE: |
| 1677 | ar = (AsyncResult) msg.obj; |
| 1678 | request = (MainThreadRequest) ar.userObj; |
| 1679 | if (ar.exception == null && ar.result != null) { |
| 1680 | request.result = ar.result; |
| 1681 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1682 | request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR; |
| 1683 | if (ar.exception instanceof CommandException) { |
| 1684 | loge("setAllowedCarriers: CommandException: " + ar.exception); |
| 1685 | CommandException.Error error = |
| 1686 | ((CommandException) (ar.exception)).getCommandError(); |
| 1687 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1688 | request.result = |
| 1689 | TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED; |
| 1690 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1691 | } else { |
| 1692 | loge("setAllowedCarriers: Unknown exception"); |
| 1693 | } |
| 1694 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1695 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1696 | break; |
| 1697 | |
| 1698 | case CMD_GET_ALLOWED_CARRIERS: |
| 1699 | request = (MainThreadRequest) msg.obj; |
| 1700 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1701 | defaultPhone.getAllowedCarriers(onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1702 | break; |
| 1703 | |
| 1704 | case EVENT_GET_ALLOWED_CARRIERS_DONE: |
| 1705 | ar = (AsyncResult) msg.obj; |
| 1706 | request = (MainThreadRequest) ar.userObj; |
| 1707 | if (ar.exception == null && ar.result != null) { |
| 1708 | request.result = ar.result; |
| 1709 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1710 | request.result = new IllegalStateException( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 1711 | "Failed to get carrier restrictions"); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1712 | if (ar.result == null) { |
| 1713 | loge("getAllowedCarriers: Empty response"); |
| 1714 | } else if (ar.exception instanceof CommandException) { |
| 1715 | loge("getAllowedCarriers: CommandException: " + |
| 1716 | ar.exception); |
| 1717 | } else { |
| 1718 | loge("getAllowedCarriers: Unknown exception"); |
| 1719 | } |
| 1720 | } |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 1721 | if (request.argument != null) { |
| 1722 | // This is for the implementation of carrierRestrictionStatus. |
| 1723 | CallerCallbackInfo callbackInfo = (CallerCallbackInfo) request.argument; |
| 1724 | Consumer<Integer> callback = callbackInfo.getConsumer(); |
| 1725 | int callerCarrierId = callbackInfo.getCarrierId(); |
| 1726 | int lockStatus = TelephonyManager.CARRIER_RESTRICTION_STATUS_UNKNOWN; |
| 1727 | if (ar.exception == null && ar.result instanceof CarrierRestrictionRules) { |
| 1728 | CarrierRestrictionRules carrierRestrictionRules = |
| 1729 | (CarrierRestrictionRules) ar.result; |
| 1730 | int carrierId = -1; |
| 1731 | try { |
| 1732 | CarrierIdentifier carrierIdentifier = |
| 1733 | carrierRestrictionRules.getAllowedCarriers().get(0); |
| 1734 | carrierId = CarrierResolver.getCarrierIdFromIdentifier(mApp, |
| 1735 | carrierIdentifier); |
| 1736 | } catch (NullPointerException | IndexOutOfBoundsException ex) { |
| 1737 | Rlog.e(LOG_TAG, "CarrierIdentifier exception = " + ex); |
| 1738 | } |
| 1739 | lockStatus = carrierRestrictionRules.getCarrierRestrictionStatus(); |
| 1740 | if (carrierId != -1 && callerCarrierId == carrierId && lockStatus |
| 1741 | == TelephonyManager.CARRIER_RESTRICTION_STATUS_RESTRICTED) { |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 1742 | lockStatus = TelephonyManager |
| 1743 | .CARRIER_RESTRICTION_STATUS_RESTRICTED_TO_CALLER; |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 1744 | } |
| 1745 | } else { |
| 1746 | Rlog.e(LOG_TAG, |
| 1747 | "getCarrierRestrictionStatus: exception ex = " + ar.exception); |
| 1748 | } |
| 1749 | callback.accept(lockStatus); |
| 1750 | } else { |
| 1751 | // This is for the implementation of getAllowedCarriers. |
| 1752 | notifyRequester(request); |
| 1753 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1754 | break; |
| 1755 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1756 | case EVENT_GET_FORBIDDEN_PLMNS_DONE: |
| 1757 | ar = (AsyncResult) msg.obj; |
| 1758 | request = (MainThreadRequest) ar.userObj; |
| 1759 | if (ar.exception == null && ar.result != null) { |
| 1760 | request.result = ar.result; |
| 1761 | } else { |
| 1762 | request.result = new IllegalArgumentException( |
| 1763 | "Failed to retrieve Forbidden Plmns"); |
| 1764 | if (ar.result == null) { |
| 1765 | loge("getForbiddenPlmns: Empty response"); |
| 1766 | } else { |
| 1767 | loge("getForbiddenPlmns: Unknown exception"); |
| 1768 | } |
| 1769 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1770 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1771 | break; |
| 1772 | |
| 1773 | case CMD_GET_FORBIDDEN_PLMNS: |
| 1774 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1775 | uiccPort = getUiccPortFromRequest(request); |
| 1776 | if (uiccPort == null) { |
| 1777 | loge("getForbiddenPlmns() UiccPort is null"); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1778 | request.result = new IllegalArgumentException( |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1779 | "getForbiddenPlmns() UiccPort is null"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1780 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1781 | break; |
| 1782 | } |
| 1783 | Integer appType = (Integer) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1784 | UiccCardApplication uiccApp = uiccPort.getApplicationByType(appType); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1785 | if (uiccApp == null) { |
| 1786 | loge("getForbiddenPlmns() no app with specified type -- " |
| 1787 | + appType); |
| 1788 | request.result = new IllegalArgumentException("Failed to get UICC App"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1789 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1790 | break; |
| 1791 | } else { |
| 1792 | if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid() |
| 1793 | + " specified type -- " + appType); |
| 1794 | } |
| 1795 | onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request); |
| 1796 | ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 1797 | onCompleted); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1798 | break; |
| 1799 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1800 | case CMD_SWITCH_SLOTS: |
| 1801 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 1802 | List<UiccSlotMapping> slotMapping = (List<UiccSlotMapping>) request.argument; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1803 | onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 1804 | UiccController.getInstance().switchSlots(slotMapping, onCompleted); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1805 | break; |
| 1806 | |
| 1807 | case EVENT_SWITCH_SLOTS_DONE: |
| 1808 | ar = (AsyncResult) msg.obj; |
| 1809 | request = (MainThreadRequest) ar.userObj; |
| 1810 | request.result = (ar.exception == null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1811 | notifyRequester(request); |
| 1812 | break; |
| 1813 | case CMD_GET_NETWORK_SELECTION_MODE: |
| 1814 | request = (MainThreadRequest) msg.obj; |
| 1815 | onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request); |
| 1816 | getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted); |
| 1817 | break; |
| 1818 | |
| 1819 | case EVENT_GET_NETWORK_SELECTION_MODE_DONE: |
| 1820 | ar = (AsyncResult) msg.obj; |
| 1821 | request = (MainThreadRequest) ar.userObj; |
| 1822 | if (ar.exception != null) { |
| 1823 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 1824 | } else { |
| 1825 | int mode = ((int[]) ar.result)[0]; |
| 1826 | if (mode == 0) { |
| 1827 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO; |
| 1828 | } else { |
| 1829 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL; |
| 1830 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1831 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1832 | notifyRequester(request); |
| 1833 | break; |
| 1834 | case CMD_GET_CDMA_ROAMING_MODE: |
| 1835 | request = (MainThreadRequest) msg.obj; |
| 1836 | onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request); |
| 1837 | getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted); |
| 1838 | break; |
| 1839 | case EVENT_GET_CDMA_ROAMING_MODE_DONE: |
| 1840 | ar = (AsyncResult) msg.obj; |
| 1841 | request = (MainThreadRequest) ar.userObj; |
| 1842 | if (ar.exception != null) { |
| 1843 | request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT; |
| 1844 | } else { |
| 1845 | request.result = ((int[]) ar.result)[0]; |
| 1846 | } |
| 1847 | notifyRequester(request); |
| 1848 | break; |
| 1849 | case CMD_SET_CDMA_ROAMING_MODE: |
| 1850 | request = (MainThreadRequest) msg.obj; |
| 1851 | onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request); |
| 1852 | int mode = (int) request.argument; |
| 1853 | getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted); |
| 1854 | break; |
| 1855 | case EVENT_SET_CDMA_ROAMING_MODE_DONE: |
| 1856 | ar = (AsyncResult) msg.obj; |
| 1857 | request = (MainThreadRequest) ar.userObj; |
| 1858 | request.result = ar.exception == null; |
| 1859 | notifyRequester(request); |
| 1860 | break; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 1861 | case CMD_GET_CDMA_SUBSCRIPTION_MODE: |
| 1862 | request = (MainThreadRequest) msg.obj; |
| 1863 | onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1864 | getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted); |
| 1865 | break; |
| 1866 | case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1867 | ar = (AsyncResult) msg.obj; |
| 1868 | request = (MainThreadRequest) ar.userObj; |
| 1869 | if (ar.exception != null) { |
| 1870 | request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM; |
| 1871 | } else { |
| 1872 | request.result = ((int[]) ar.result)[0]; |
| 1873 | } |
| 1874 | notifyRequester(request); |
| 1875 | break; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1876 | case CMD_SET_CDMA_SUBSCRIPTION_MODE: |
| 1877 | request = (MainThreadRequest) msg.obj; |
| 1878 | onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1879 | int subscriptionMode = (int) request.argument; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 1880 | getPhoneFromRequest(request).setCdmaSubscriptionMode( |
| 1881 | subscriptionMode, onCompleted); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1882 | break; |
| 1883 | case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1884 | ar = (AsyncResult) msg.obj; |
| 1885 | request = (MainThreadRequest) ar.userObj; |
| 1886 | request.result = ar.exception == null; |
| 1887 | notifyRequester(request); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1888 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1889 | case CMD_GET_ALL_CELL_INFO: |
| 1890 | request = (MainThreadRequest) msg.obj; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1891 | onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1892 | request.phone.requestCellInfoUpdate(request.workSource, onCompleted); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1893 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1894 | case EVENT_GET_ALL_CELL_INFO_DONE: |
| 1895 | ar = (AsyncResult) msg.obj; |
| 1896 | request = (MainThreadRequest) ar.userObj; |
Nathan Harold | 8d0f174 | 2018-10-02 12:14:47 -0700 | [diff] [blame] | 1897 | // If a timeout occurs, the response will be null |
| 1898 | request.result = (ar.exception == null && ar.result != null) |
| 1899 | ? ar.result : new ArrayList<CellInfo>(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1900 | synchronized (request) { |
| 1901 | request.notifyAll(); |
| 1902 | } |
| 1903 | break; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1904 | case CMD_REQUEST_CELL_INFO_UPDATE: |
| 1905 | request = (MainThreadRequest) msg.obj; |
| 1906 | request.phone.requestCellInfoUpdate(request.workSource, |
| 1907 | obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request)); |
| 1908 | break; |
| 1909 | case EVENT_REQUEST_CELL_INFO_UPDATE_DONE: |
| 1910 | ar = (AsyncResult) msg.obj; |
| 1911 | request = (MainThreadRequest) ar.userObj; |
| 1912 | ICellInfoCallback cb = (ICellInfoCallback) request.argument; |
| 1913 | try { |
| 1914 | if (ar.exception != null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1915 | Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception); |
Meng Wang | d8921f4 | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1916 | cb.onError( |
| 1917 | TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR, |
| 1918 | ar.exception.getClass().getName(), |
| 1919 | ar.exception.toString()); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1920 | } else if (ar.result == null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1921 | Log.w(LOG_TAG, "Timeout Waiting for CellInfo!"); |
Meng Wang | d8921f4 | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1922 | cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1923 | } else { |
| 1924 | // use the result as returned |
| 1925 | cb.onCellInfo((List<CellInfo>) ar.result); |
| 1926 | } |
| 1927 | } catch (RemoteException re) { |
| 1928 | Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException"); |
| 1929 | } |
| 1930 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1931 | case CMD_GET_CELL_LOCATION: { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1932 | request = (MainThreadRequest) msg.obj; |
| 1933 | WorkSource ws = (WorkSource) request.argument; |
| 1934 | Phone phone = getPhoneFromRequest(request); |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1935 | phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request)); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1936 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1937 | } |
| 1938 | case EVENT_GET_CELL_LOCATION_DONE: { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1939 | ar = (AsyncResult) msg.obj; |
| 1940 | request = (MainThreadRequest) ar.userObj; |
| 1941 | if (ar.exception == null) { |
| 1942 | request.result = ar.result; |
| 1943 | } else { |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1944 | Phone phone = getPhoneFromRequest(request); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1945 | request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1946 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1947 | } |
| 1948 | |
| 1949 | synchronized (request) { |
| 1950 | request.notifyAll(); |
| 1951 | } |
| 1952 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1953 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1954 | case CMD_MODEM_REBOOT: |
| 1955 | request = (MainThreadRequest) msg.obj; |
| 1956 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1957 | defaultPhone.rebootModem(onCompleted); |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1958 | break; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1959 | case EVENT_CMD_MODEM_REBOOT_DONE: |
| 1960 | handleNullReturnEvent(msg, "rebootModem"); |
| 1961 | break; |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 1962 | case CMD_REQUEST_ENABLE_MODEM: { |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1963 | request = (MainThreadRequest) msg.obj; |
| 1964 | boolean enable = (boolean) request.argument; |
| 1965 | onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1966 | onCompleted.arg1 = enable ? 1 : 0; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1967 | PhoneConfigurationManager.getInstance() |
| 1968 | .enablePhone(request.phone, enable, onCompleted); |
| 1969 | break; |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 1970 | } |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1971 | case EVENT_ENABLE_MODEM_DONE: { |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1972 | ar = (AsyncResult) msg.obj; |
| 1973 | request = (MainThreadRequest) ar.userObj; |
| 1974 | request.result = (ar.exception == null); |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1975 | int phoneId = request.phone.getPhoneId(); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1976 | //update the cache as modem status has changed |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1977 | if ((boolean) request.result) { |
| 1978 | mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1); |
| 1979 | updateModemStateMetrics(); |
| 1980 | } else { |
| 1981 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1982 | + ar.exception); |
| 1983 | } |
| 1984 | notifyRequester(request); |
| 1985 | break; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1986 | } |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1987 | case CMD_GET_MODEM_STATUS: |
| 1988 | request = (MainThreadRequest) msg.obj; |
| 1989 | onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request); |
| 1990 | PhoneConfigurationManager.getInstance() |
| 1991 | .getPhoneStatusFromModem(request.phone, onCompleted); |
| 1992 | break; |
| 1993 | case EVENT_GET_MODEM_STATUS_DONE: |
| 1994 | ar = (AsyncResult) msg.obj; |
| 1995 | request = (MainThreadRequest) ar.userObj; |
| 1996 | int id = request.phone.getPhoneId(); |
| 1997 | if (ar.exception == null && ar.result != null) { |
| 1998 | request.result = ar.result; |
| 1999 | //update the cache as modem status has changed |
| 2000 | mPhoneConfigurationManager.addToPhoneStatusCache(id, |
| 2001 | (boolean) request.result); |
| 2002 | } else { |
| 2003 | // Return true if modem status cannot be retrieved. For most cases, |
| 2004 | // modem status is on. And for older version modems, GET_MODEM_STATUS |
| 2005 | // and disable modem are not supported. Modem is always on. |
| 2006 | // TODO: this should be fixed in R to support a third |
| 2007 | // status UNKNOWN b/131631629 |
| 2008 | request.result = true; |
| 2009 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 2010 | + ar.exception); |
| 2011 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 2012 | notifyRequester(request); |
| 2013 | break; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 2014 | case CMD_SET_SYSTEM_SELECTION_CHANNELS: { |
| 2015 | request = (MainThreadRequest) msg.obj; |
| 2016 | onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request); |
| 2017 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 2018 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 2019 | request.phone.setSystemSelectionChannels(args.first, onCompleted); |
| 2020 | break; |
| 2021 | } |
| 2022 | case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: { |
| 2023 | ar = (AsyncResult) msg.obj; |
| 2024 | request = (MainThreadRequest) ar.userObj; |
| 2025 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 2026 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 2027 | args.second.accept(ar.exception == null); |
| 2028 | notifyRequester(request); |
| 2029 | break; |
| 2030 | } |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 2031 | case CMD_GET_SYSTEM_SELECTION_CHANNELS: { |
| 2032 | request = (MainThreadRequest) msg.obj; |
| 2033 | onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request); |
| 2034 | Phone phone = getPhoneFromRequest(request); |
| 2035 | if (phone != null) { |
| 2036 | phone.getSystemSelectionChannels(onCompleted); |
| 2037 | } else { |
| 2038 | loge("getSystemSelectionChannels: No phone object"); |
| 2039 | request.result = new ArrayList<RadioAccessSpecifier>(); |
| 2040 | notifyRequester(request); |
| 2041 | } |
| 2042 | break; |
| 2043 | } |
| 2044 | case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE: |
| 2045 | ar = (AsyncResult) msg.obj; |
| 2046 | request = (MainThreadRequest) ar.userObj; |
| 2047 | if (ar.exception == null && ar.result != null) { |
| 2048 | request.result = ar.result; |
| 2049 | } else { |
Sarah Chin | 428d1d6 | 2021-03-13 03:17:40 -0800 | [diff] [blame] | 2050 | request.result = new IllegalStateException( |
| 2051 | "Failed to retrieve system selecton channels"); |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 2052 | if (ar.result == null) { |
| 2053 | loge("getSystemSelectionChannels: Empty response"); |
| 2054 | } else { |
| 2055 | loge("getSystemSelectionChannels: Unknown exception"); |
| 2056 | } |
| 2057 | } |
| 2058 | notifyRequester(request); |
| 2059 | break; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 2060 | case EVENT_SET_FORBIDDEN_PLMNS_DONE: |
| 2061 | ar = (AsyncResult) msg.obj; |
| 2062 | request = (MainThreadRequest) ar.userObj; |
| 2063 | if (ar.exception == null && ar.result != null) { |
| 2064 | request.result = ar.result; |
| 2065 | } else { |
| 2066 | request.result = -1; |
| 2067 | loge("Failed to set Forbidden Plmns"); |
| 2068 | if (ar.result == null) { |
| 2069 | loge("setForbidenPlmns: Empty response"); |
| 2070 | } else if (ar.exception != null) { |
| 2071 | loge("setForbiddenPlmns: Exception: " + ar.exception); |
| 2072 | request.result = -1; |
| 2073 | } else { |
| 2074 | loge("setForbiddenPlmns: Unknown exception"); |
| 2075 | } |
| 2076 | } |
| 2077 | notifyRequester(request); |
| 2078 | break; |
| 2079 | case CMD_SET_FORBIDDEN_PLMNS: |
| 2080 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 2081 | uiccPort = getUiccPortFromRequest(request); |
| 2082 | if (uiccPort == null) { |
| 2083 | loge("setForbiddenPlmns: UiccPort is null"); |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 2084 | request.result = -1; |
| 2085 | notifyRequester(request); |
| 2086 | break; |
| 2087 | } |
| 2088 | Pair<Integer, List<String>> setFplmnsArgs = |
| 2089 | (Pair<Integer, List<String>>) request.argument; |
| 2090 | appType = setFplmnsArgs.first; |
| 2091 | List<String> fplmns = setFplmnsArgs.second; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 2092 | uiccApp = uiccPort.getApplicationByType(appType); |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 2093 | if (uiccApp == null) { |
| 2094 | loge("setForbiddenPlmns: no app with specified type -- " + appType); |
| 2095 | request.result = -1; |
| 2096 | loge("Failed to get UICC App"); |
| 2097 | notifyRequester(request); |
| 2098 | } else { |
| 2099 | onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request); |
| 2100 | ((SIMRecords) uiccApp.getIccRecords()) |
| 2101 | .setForbiddenPlmns(onCompleted, fplmns); |
| 2102 | } |
yinchengzhao | 4d163c0 | 2019-12-12 15:21:47 -0800 | [diff] [blame] | 2103 | break; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 2104 | case CMD_ERASE_MODEM_CONFIG: |
| 2105 | request = (MainThreadRequest) msg.obj; |
| 2106 | onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request); |
| 2107 | defaultPhone.eraseModemConfig(onCompleted); |
| 2108 | break; |
| 2109 | case EVENT_ERASE_MODEM_CONFIG_DONE: |
| 2110 | handleNullReturnEvent(msg, "eraseModemConfig"); |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 2111 | break; |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 2112 | |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 2113 | case CMD_ERASE_DATA_SHARED_PREFERENCES: |
| 2114 | request = (MainThreadRequest) msg.obj; |
| 2115 | request.result = defaultPhone.eraseDataInSharedPreferences(); |
| 2116 | notifyRequester(request); |
| 2117 | break; |
| 2118 | |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 2119 | case CMD_CHANGE_ICC_LOCK_PASSWORD: |
| 2120 | request = (MainThreadRequest) msg.obj; |
| 2121 | onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request); |
| 2122 | Pair<String, String> changed = (Pair<String, String>) request.argument; |
| 2123 | getPhoneFromRequest(request).getIccCard().changeIccLockPassword( |
| 2124 | changed.first, changed.second, onCompleted); |
| 2125 | break; |
| 2126 | case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE: |
| 2127 | ar = (AsyncResult) msg.obj; |
| 2128 | request = (MainThreadRequest) ar.userObj; |
| 2129 | if (ar.exception == null) { |
| 2130 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2131 | // If the operation is successful, update the PIN storage |
| 2132 | Pair<String, String> passwords = (Pair<String, String>) request.argument; |
| 2133 | int phoneId = getPhoneFromRequest(request).getPhoneId(); |
Jon Spivack | 9c3bc76 | 2021-10-06 20:53:09 +0000 | [diff] [blame] | 2134 | UiccController.getInstance().getPinStorage() |
| 2135 | .storePin(passwords.second, phoneId); |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 2136 | } else { |
| 2137 | request.result = msg.arg1; |
| 2138 | } |
| 2139 | notifyRequester(request); |
| 2140 | break; |
| 2141 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2142 | case CMD_SET_ICC_LOCK_ENABLED: { |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 2143 | request = (MainThreadRequest) msg.obj; |
| 2144 | onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request); |
| 2145 | Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument; |
| 2146 | getPhoneFromRequest(request).getIccCard().setIccLockEnabled( |
| 2147 | enabled.first, enabled.second, onCompleted); |
| 2148 | break; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2149 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 2150 | case EVENT_SET_ICC_LOCK_ENABLED_DONE: |
| 2151 | ar = (AsyncResult) msg.obj; |
| 2152 | request = (MainThreadRequest) ar.userObj; |
| 2153 | if (ar.exception == null) { |
| 2154 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2155 | // If the operation is successful, update the PIN storage |
| 2156 | Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument; |
| 2157 | int phoneId = getPhoneFromRequest(request).getPhoneId(); |
| 2158 | if (enabled.first) { |
Jon Spivack | 9c3bc76 | 2021-10-06 20:53:09 +0000 | [diff] [blame] | 2159 | UiccController.getInstance().getPinStorage() |
| 2160 | .storePin(enabled.second, phoneId); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2161 | } else { |
| 2162 | UiccController.getInstance().getPinStorage().clearPin(phoneId); |
| 2163 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 2164 | } else { |
| 2165 | request.result = msg.arg1; |
| 2166 | } |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2167 | |
| 2168 | |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 2169 | notifyRequester(request); |
| 2170 | break; |
| 2171 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 2172 | case MSG_NOTIFY_USER_ACTIVITY: |
| 2173 | removeMessages(MSG_NOTIFY_USER_ACTIVITY); |
Peter Wang | 59571be | 2020-01-27 12:35:15 +0800 | [diff] [blame] | 2174 | Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION); |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 2175 | intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY); |
| 2176 | getDefaultPhone().getContext().sendBroadcastAsUser( |
| 2177 | intent, UserHandle.ALL, permission.USER_ACTIVITY); |
| 2178 | break; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 2179 | |
| 2180 | case CMD_SET_DATA_THROTTLING: { |
| 2181 | request = (MainThreadRequest) msg.obj; |
| 2182 | onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request); |
| 2183 | DataThrottlingRequest dataThrottlingRequest = |
| 2184 | (DataThrottlingRequest) request.argument; |
| 2185 | Phone phone = getPhoneFromRequest(request); |
| 2186 | if (phone != null) { |
| 2187 | phone.setDataThrottling(onCompleted, |
| 2188 | request.workSource, dataThrottlingRequest.getDataThrottlingAction(), |
| 2189 | dataThrottlingRequest.getCompletionDurationMillis()); |
| 2190 | } else { |
| 2191 | loge("setDataThrottling: No phone object"); |
| 2192 | request.result = |
| 2193 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 2194 | notifyRequester(request); |
| 2195 | } |
| 2196 | |
| 2197 | break; |
| 2198 | } |
| 2199 | case EVENT_SET_DATA_THROTTLING_DONE: |
| 2200 | ar = (AsyncResult) msg.obj; |
| 2201 | request = (MainThreadRequest) ar.userObj; |
| 2202 | |
| 2203 | if (ar.exception == null) { |
| 2204 | request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 2205 | } else if (ar.exception instanceof CommandException) { |
| 2206 | loge("setDataThrottling: CommandException: " + ar.exception); |
| 2207 | CommandException.Error error = |
| 2208 | ((CommandException) (ar.exception)).getCommandError(); |
| 2209 | |
| 2210 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 2211 | request.result = TelephonyManager |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2212 | .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 2213 | } else if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 2214 | request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS; |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 2215 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 2216 | request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 2217 | } else { |
| 2218 | request.result = |
| 2219 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 2220 | } |
| 2221 | } else { |
| 2222 | request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 2223 | } |
| 2224 | Log.w(LOG_TAG, "DataThrottlingResult = " + request.result); |
| 2225 | notifyRequester(request); |
| 2226 | break; |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 2227 | |
| 2228 | case CMD_SET_SIM_POWER: { |
| 2229 | request = (MainThreadRequest) msg.obj; |
| 2230 | onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request); |
| 2231 | request = (MainThreadRequest) msg.obj; |
| 2232 | int stateToSet = |
| 2233 | ((Pair<Integer, IIntegerConsumer>) |
| 2234 | request.argument).first; |
| 2235 | request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource); |
| 2236 | break; |
| 2237 | } |
| 2238 | case EVENT_SET_SIM_POWER_DONE: { |
| 2239 | ar = (AsyncResult) msg.obj; |
| 2240 | request = (MainThreadRequest) ar.userObj; |
| 2241 | IIntegerConsumer callback = |
| 2242 | ((Pair<Integer, IIntegerConsumer>) request.argument).second; |
| 2243 | if (ar.exception != null) { |
| 2244 | loge("setSimPower exception: " + ar.exception); |
| 2245 | int errorCode = TelephonyManager.CallForwardingInfoCallback |
| 2246 | .RESULT_ERROR_UNKNOWN; |
| 2247 | if (ar.exception instanceof CommandException) { |
| 2248 | CommandException.Error error = |
| 2249 | ((CommandException) (ar.exception)).getCommandError(); |
| 2250 | if (error == CommandException.Error.SIM_ERR) { |
| 2251 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR; |
| 2252 | } else if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 2253 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE; |
| 2254 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 2255 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED; |
| 2256 | } else { |
| 2257 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR; |
| 2258 | } |
| 2259 | } |
| 2260 | try { |
| 2261 | callback.accept(errorCode); |
| 2262 | } catch (RemoteException e) { |
| 2263 | // Ignore if the remote process is no longer available to call back. |
| 2264 | Log.w(LOG_TAG, "setSimPower: callback not available."); |
| 2265 | } |
| 2266 | } else { |
| 2267 | try { |
| 2268 | callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS); |
| 2269 | } catch (RemoteException e) { |
| 2270 | // Ignore if the remote process is no longer available to call back. |
| 2271 | Log.w(LOG_TAG, "setSimPower: callback not available."); |
| 2272 | } |
| 2273 | } |
| 2274 | break; |
| 2275 | } |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 2276 | case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: { |
| 2277 | request = (MainThreadRequest) msg.obj; |
| 2278 | |
| 2279 | final Phone phone = getPhoneFromRequest(request); |
| 2280 | if (phone == null || phone.getServiceStateTracker() == null) { |
| 2281 | request.result = new IllegalStateException("Phone or SST is null"); |
| 2282 | notifyRequester(request); |
| 2283 | break; |
| 2284 | } |
| 2285 | |
| 2286 | Pair<Integer, SignalStrengthUpdateRequest> pair = |
| 2287 | (Pair<Integer, SignalStrengthUpdateRequest>) request.argument; |
| 2288 | onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE, |
| 2289 | request); |
Rambo Wang | 6568f17 | 2021-02-03 16:56:47 -0800 | [diff] [blame] | 2290 | phone.getSignalStrengthController().setSignalStrengthUpdateRequest( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2291 | request.subId, pair.first /*callingUid*/, |
| 2292 | pair.second /*request*/, onCompleted); |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 2293 | break; |
| 2294 | } |
| 2295 | case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: { |
| 2296 | ar = (AsyncResult) msg.obj; |
| 2297 | request = (MainThreadRequest) ar.userObj; |
| 2298 | // request.result will be the exception of ar if present, true otherwise. |
| 2299 | // Be cautious not to leave result null which will wait() forever |
| 2300 | request.result = ar.exception != null ? ar.exception : true; |
| 2301 | notifyRequester(request); |
| 2302 | break; |
| 2303 | } |
| 2304 | case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: { |
| 2305 | request = (MainThreadRequest) msg.obj; |
| 2306 | |
| 2307 | Phone phone = getPhoneFromRequest(request); |
| 2308 | if (phone == null || phone.getServiceStateTracker() == null) { |
| 2309 | request.result = new IllegalStateException("Phone or SST is null"); |
| 2310 | notifyRequester(request); |
| 2311 | break; |
| 2312 | } |
| 2313 | |
| 2314 | Pair<Integer, SignalStrengthUpdateRequest> pair = |
| 2315 | (Pair<Integer, SignalStrengthUpdateRequest>) request.argument; |
| 2316 | onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE, |
| 2317 | request); |
Rambo Wang | 6568f17 | 2021-02-03 16:56:47 -0800 | [diff] [blame] | 2318 | phone.getSignalStrengthController().clearSignalStrengthUpdateRequest( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2319 | request.subId, pair.first /*callingUid*/, |
| 2320 | pair.second /*request*/, onCompleted); |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 2321 | break; |
| 2322 | } |
| 2323 | case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: { |
| 2324 | ar = (AsyncResult) msg.obj; |
| 2325 | request = (MainThreadRequest) ar.userObj; |
| 2326 | request.result = ar.exception != null ? ar.exception : true; |
| 2327 | notifyRequester(request); |
| 2328 | break; |
| 2329 | } |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 2330 | |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2331 | case CMD_GET_SLICING_CONFIG: { |
| 2332 | request = (MainThreadRequest) msg.obj; |
| 2333 | onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request); |
| 2334 | request.phone.getSlicingConfig(onCompleted); |
| 2335 | break; |
| 2336 | } |
| 2337 | case EVENT_GET_SLICING_CONFIG_DONE: { |
| 2338 | ar = (AsyncResult) msg.obj; |
| 2339 | request = (MainThreadRequest) ar.userObj; |
| 2340 | ResultReceiver result = (ResultReceiver) request.argument; |
| 2341 | |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2342 | NetworkSlicingConfig slicingConfig = null; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2343 | Bundle bundle = new Bundle(); |
| 2344 | int resultCode = 0; |
| 2345 | if (ar.exception != null) { |
| 2346 | Log.e(LOG_TAG, "Exception retrieving slicing configuration=" |
| 2347 | + ar.exception); |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2348 | resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2349 | } else if (ar.result == null) { |
| 2350 | Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!"); |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2351 | resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2352 | } else { |
| 2353 | // use the result as returned |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2354 | resultCode = TelephonyManager.NetworkSlicingException.SUCCESS; |
| 2355 | slicingConfig = (NetworkSlicingConfig) ar.result; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2356 | } |
| 2357 | |
| 2358 | if (slicingConfig == null) { |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2359 | slicingConfig = new NetworkSlicingConfig(); |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2360 | } |
| 2361 | bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig); |
| 2362 | result.send(resultCode, bundle); |
| 2363 | notifyRequester(request); |
| 2364 | break; |
| 2365 | } |
| 2366 | |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2367 | case CMD_PURCHASE_PREMIUM_CAPABILITY: { |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2368 | request = (MainThreadRequest) msg.obj; |
| 2369 | onCompleted = obtainMessage(EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE, request); |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2370 | PurchasePremiumCapabilityArgument arg = |
| 2371 | (PurchasePremiumCapabilityArgument) request.argument; |
Sarah Chin | 46355ba | 2022-11-01 23:51:16 -0700 | [diff] [blame] | 2372 | SlicePurchaseController.getInstance(request.phone).purchasePremiumCapability( |
Sarah Chin | b8218c2 | 2023-01-04 13:35:29 -0800 | [diff] [blame] | 2373 | arg.capability, onCompleted); |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2374 | break; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2375 | } |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2376 | |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2377 | case EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE: { |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2378 | ar = (AsyncResult) msg.obj; |
| 2379 | request = (MainThreadRequest) ar.userObj; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2380 | PurchasePremiumCapabilityArgument arg = |
| 2381 | (PurchasePremiumCapabilityArgument) request.argument; |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2382 | try { |
| 2383 | int result = (int) ar.result; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2384 | arg.callback.accept(result); |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2385 | log("purchasePremiumCapability: capability=" |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2386 | + TelephonyManager.convertPremiumCapabilityToString(arg.capability) |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2387 | + ", result= " |
| 2388 | + TelephonyManager.convertPurchaseResultToString(result)); |
| 2389 | } catch (RemoteException e) { |
| 2390 | String logStr = "Purchase premium capability " |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2391 | + TelephonyManager.convertPremiumCapabilityToString(arg.capability) |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2392 | + " failed: " + e; |
| 2393 | if (DBG) log(logStr); |
| 2394 | AnomalyReporter.reportAnomaly( |
| 2395 | UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr); |
| 2396 | } |
| 2397 | break; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2398 | } |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2399 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2400 | case CMD_PREPARE_UNATTENDED_REBOOT: |
| 2401 | request = (MainThreadRequest) msg.obj; |
| 2402 | request.result = |
Rafael Higuera Silva | d963064 | 2021-09-20 15:32:01 +0000 | [diff] [blame] | 2403 | UiccController.getInstance().getPinStorage() |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2404 | .prepareUnattendedReboot(request.workSource); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2405 | notifyRequester(request); |
| 2406 | break; |
| 2407 | |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 2408 | case CMD_START_SATELLITE_POSITION_UPDATES: { |
| 2409 | request = (MainThreadRequest) msg.obj; |
| 2410 | onCompleted = |
| 2411 | obtainMessage(EVENT_START_SATELLITE_POSITION_UPDATES_DONE, request); |
| 2412 | Phone phone = getPhoneFromRequest(request); |
| 2413 | if (phone != null) { |
| 2414 | phone.startSatellitePositionUpdates(onCompleted); |
| 2415 | } else { |
| 2416 | loge("startSatellitePositionUpdates: No phone object"); |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 2417 | ((Consumer<Integer>) request.argument).accept( |
| 2418 | SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE); |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 2419 | } |
| 2420 | break; |
| 2421 | } |
| 2422 | |
| 2423 | case EVENT_START_SATELLITE_POSITION_UPDATES_DONE: { |
| 2424 | ar = (AsyncResult) msg.obj; |
| 2425 | request = (MainThreadRequest) ar.userObj; |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 2426 | int error = getSatelliteError(ar, "startSatellitePositionUpdates", false); |
| 2427 | ((Consumer<Integer>) request.argument).accept(error); |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 2428 | break; |
| 2429 | } |
| 2430 | |
| 2431 | case CMD_STOP_SATELLITE_POSITION_UPDATES: { |
| 2432 | request = (MainThreadRequest) msg.obj; |
| 2433 | onCompleted = |
| 2434 | obtainMessage(EVENT_STOP_SATELLITE_POSITION_UPDATES_DONE, request); |
| 2435 | Phone phone = getPhoneFromRequest(request); |
| 2436 | if (phone != null) { |
| 2437 | phone.stopSatellitePositionUpdates(onCompleted); |
| 2438 | } else { |
| 2439 | loge("stopSatellitePositionUpdates: No phone object"); |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 2440 | ((Consumer<Integer>) request.argument).accept( |
| 2441 | SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE); |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 2442 | } |
| 2443 | break; |
| 2444 | } |
| 2445 | |
| 2446 | case EVENT_STOP_SATELLITE_POSITION_UPDATES_DONE: { |
| 2447 | ar = (AsyncResult) msg.obj; |
| 2448 | request = (MainThreadRequest) ar.userObj; |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 2449 | int error = getSatelliteError(ar, "stopSatellitePositionUpdates", false); |
| 2450 | ((Consumer<Integer>) request.argument).accept(error); |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 2451 | break; |
| 2452 | } |
| 2453 | |
Aishwarya Mallampati | 60fe113 | 2023-01-24 19:07:21 +0000 | [diff] [blame] | 2454 | case CMD_GET_MAX_CHAR_PER_SATELLITE_TEXT_MSG: { |
| 2455 | request = (MainThreadRequest) msg.obj; |
| 2456 | onCompleted = obtainMessage(EVENT_GET_MAX_CHAR_PER_SATELLITE_TEXT_MSG_DONE, |
| 2457 | request); |
| 2458 | Phone phone = getPhoneFromRequest(request); |
| 2459 | if (phone != null) { |
| 2460 | phone.getMaxCharactersPerSatelliteTextMessage(onCompleted); |
| 2461 | } else { |
| 2462 | loge("getMaxCharactersPerSatelliteTextMessage: No phone object"); |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 2463 | ((ResultReceiver) request.argument).send( |
| 2464 | SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE, null); |
Aishwarya Mallampati | 60fe113 | 2023-01-24 19:07:21 +0000 | [diff] [blame] | 2465 | } |
| 2466 | break; |
| 2467 | } |
| 2468 | |
| 2469 | case EVENT_GET_MAX_CHAR_PER_SATELLITE_TEXT_MSG_DONE: { |
| 2470 | ar = (AsyncResult) msg.obj; |
| 2471 | request = (MainThreadRequest) ar.userObj; |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 2472 | int error = |
| 2473 | getSatelliteError(ar, "getMaxCharactersPerSatelliteTextMessage", true); |
| 2474 | Bundle bundle = new Bundle(); |
| 2475 | if (error == SatelliteManager.SATELLITE_ERROR_NONE) { |
Aishwarya Mallampati | 60fe113 | 2023-01-24 19:07:21 +0000 | [diff] [blame] | 2476 | int maxCharLimit = ((int[]) ar.result)[0]; |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 2477 | if (DBG) log("getMaxCharactersPerSatelliteTextMessage: " + maxCharLimit); |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 2478 | bundle.putInt(SatelliteManager.KEY_MAX_CHARACTERS_PER_SATELLITE_TEXT, |
| 2479 | maxCharLimit); |
Aishwarya Mallampati | 60fe113 | 2023-01-24 19:07:21 +0000 | [diff] [blame] | 2480 | } |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 2481 | ((ResultReceiver) request.argument).send(error, bundle); |
Aishwarya Mallampati | 60fe113 | 2023-01-24 19:07:21 +0000 | [diff] [blame] | 2482 | break; |
| 2483 | } |
| 2484 | |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2485 | case CMD_PROVISION_SATELLITE_SERVICE: { |
| 2486 | request = (MainThreadRequest) msg.obj; |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 2487 | onCompleted = obtainMessage(EVENT_PROVISION_SATELLITE_SERVICE_DONE, request); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2488 | Phone phone = getPhoneFromRequest(request); |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 2489 | ProvisionSatelliteServiceArgument argument = |
| 2490 | (ProvisionSatelliteServiceArgument) request.argument; |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2491 | if (phone != null) { |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 2492 | handleCmdProvisionSatelliteService(argument, phone, onCompleted); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2493 | } else { |
| 2494 | loge("provisionSatelliteService: No phone object"); |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 2495 | argument.callback.accept( |
| 2496 | SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2497 | notifyRequester(request); |
| 2498 | } |
| 2499 | break; |
| 2500 | } |
| 2501 | |
| 2502 | case EVENT_PROVISION_SATELLITE_SERVICE_DONE: { |
| 2503 | ar = (AsyncResult) msg.obj; |
| 2504 | request = (MainThreadRequest) ar.userObj; |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 2505 | int errorCode = getSatelliteError(ar, "provisionSatelliteService", false); |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame^] | 2506 | handleEventProvisionSatelliteServiceDone( |
| 2507 | (ProvisionSatelliteServiceArgument) request.argument, errorCode); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2508 | notifyRequester(request); |
| 2509 | break; |
| 2510 | } |
| 2511 | |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame^] | 2512 | case CMD_DEPROVISION_SATELLITE_SERVICE: { |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2513 | request = (MainThreadRequest) msg.obj; |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame^] | 2514 | onCompleted = obtainMessage(EVENT_DEPROVISION_SATELLITE_SERVICE_DONE, request); |
| 2515 | Phone phone = getPhoneFromRequest(request); |
| 2516 | ProvisionSatelliteServiceArgument argument = |
| 2517 | (ProvisionSatelliteServiceArgument) request.argument; |
| 2518 | if (phone != null) { |
| 2519 | handleCmdDeprovisionSatelliteService(argument, phone, onCompleted); |
| 2520 | } else { |
| 2521 | loge("deprovisionSatelliteService: No phone object"); |
| 2522 | if (argument.callback != null) { |
| 2523 | argument.callback.accept( |
| 2524 | SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE); |
| 2525 | } |
| 2526 | notifyRequester(request); |
| 2527 | } |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2528 | break; |
| 2529 | } |
| 2530 | |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame^] | 2531 | case EVENT_DEPROVISION_SATELLITE_SERVICE_DONE: { |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2532 | ar = (AsyncResult) msg.obj; |
| 2533 | request = (MainThreadRequest) ar.userObj; |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame^] | 2534 | int errorCode = getSatelliteError(ar, "deprovisionSatelliteService", false); |
| 2535 | handleEventDeprovisionSatelliteServiceDone( |
| 2536 | (ProvisionSatelliteServiceArgument) request.argument, errorCode); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2537 | notifyRequester(request); |
| 2538 | break; |
| 2539 | } |
| 2540 | |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 2541 | case CMD_SET_SATELLITE_ENABLED: { |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2542 | request = (MainThreadRequest) msg.obj; |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 2543 | onCompleted = obtainMessage(EVENT_SET_SATELLITE_ENABLED_DONE, request); |
| 2544 | Pair<Boolean, Consumer<Integer>> argument = |
| 2545 | (Pair<Boolean, Consumer<Integer>>) request.argument; |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2546 | Phone phone = getPhoneFromRequest(request); |
| 2547 | if (phone != null) { |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 2548 | boolean enable = argument.first.booleanValue(); |
| 2549 | phone.setSatellitePower(onCompleted, enable); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2550 | } else { |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 2551 | loge("setSatelliteEnabled: No phone object"); |
| 2552 | argument.second.accept(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2553 | notifyRequester(request); |
| 2554 | } |
| 2555 | break; |
| 2556 | } |
| 2557 | |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 2558 | case EVENT_SET_SATELLITE_ENABLED_DONE: { |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2559 | ar = (AsyncResult) msg.obj; |
| 2560 | request = (MainThreadRequest) ar.userObj; |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 2561 | Pair<Boolean, Consumer<Integer>> argument = |
| 2562 | (Pair<Boolean, Consumer<Integer>>) request.argument; |
| 2563 | int error = getSatelliteError(ar, "setSatelliteEnabled", false); |
| 2564 | argument.second.accept(error); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2565 | break; |
| 2566 | } |
| 2567 | |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 2568 | case CMD_IS_SATELLITE_ENABLED: { |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 2569 | request = (MainThreadRequest) msg.obj; |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 2570 | onCompleted = obtainMessage(EVENT_IS_SATELLITE_ENABLED_DONE, request); |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 2571 | Phone phone = getPhoneFromRequest(request); |
| 2572 | if (phone != null) { |
| 2573 | phone.isSatellitePowerOn(onCompleted); |
| 2574 | } else { |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 2575 | loge("isSatelliteEnabled: No phone object"); |
| 2576 | ((ResultReceiver) request.argument).send( |
| 2577 | SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE, null); |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 2578 | } |
| 2579 | break; |
| 2580 | } |
| 2581 | |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 2582 | case EVENT_IS_SATELLITE_ENABLED_DONE: { |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 2583 | ar = (AsyncResult) msg.obj; |
| 2584 | request = (MainThreadRequest) ar.userObj; |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 2585 | int error = getSatelliteError(ar, "isSatelliteEnabled", true); |
| 2586 | Bundle bundle = new Bundle(); |
| 2587 | if (error == SatelliteManager.SATELLITE_ERROR_NONE) { |
| 2588 | boolean enabled = ((int[]) ar.result)[0] == 1; |
| 2589 | if (DBG) log("isSatelliteEnabled: " + enabled); |
| 2590 | bundle.putBoolean(SatelliteManager.KEY_SATELLITE_ENABLED, enabled); |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 2591 | } |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 2592 | ((ResultReceiver) request.argument).send(error, bundle); |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 2593 | break; |
| 2594 | } |
| 2595 | |
| 2596 | case CMD_IS_SATELLITE_SUPPORTED: { |
| 2597 | request = (MainThreadRequest) msg.obj; |
| 2598 | onCompleted = obtainMessage(EVENT_IS_SATELLITE_SUPPORTED_DONE, request); |
| 2599 | Phone phone = getPhoneFromRequest(request); |
| 2600 | if (phone != null) { |
| 2601 | phone.isSatelliteSupported(onCompleted); |
| 2602 | } else { |
| 2603 | loge("isSatelliteSupported: No phone object"); |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 2604 | ((ResultReceiver) request.argument).send( |
| 2605 | SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE, null); |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 2606 | } |
| 2607 | break; |
| 2608 | } |
| 2609 | |
| 2610 | case EVENT_IS_SATELLITE_SUPPORTED_DONE: { |
| 2611 | ar = (AsyncResult) msg.obj; |
| 2612 | request = (MainThreadRequest) ar.userObj; |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 2613 | int error = getSatelliteError(ar, "isSatelliteSupported", true); |
| 2614 | Bundle bundle = new Bundle(); |
| 2615 | if (error == SatelliteManager.SATELLITE_ERROR_NONE) { |
| 2616 | boolean supported = ((int[]) ar.result)[0] == 1; |
| 2617 | if (DBG) log("isSatelliteSupported: " + supported); |
| 2618 | bundle.putBoolean(SatelliteManager.KEY_SATELLITE_SUPPORTED, supported); |
Thomas Nguyen | e77de6d | 2023-02-10 17:42:43 -0800 | [diff] [blame] | 2619 | synchronized (mIsSatelliteSupportedLock) { |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 2620 | mIsSatelliteSupported = supported; |
| 2621 | } |
| 2622 | } else { |
| 2623 | synchronized (mIsSatelliteSupportedLock) { |
| 2624 | mIsSatelliteSupported = null; |
Thomas Nguyen | e77de6d | 2023-02-10 17:42:43 -0800 | [diff] [blame] | 2625 | } |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 2626 | } |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 2627 | ((ResultReceiver) request.argument).send(error, bundle); |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 2628 | break; |
| 2629 | } |
| 2630 | |
| 2631 | case CMD_GET_SATELLITE_CAPABILITIES: { |
| 2632 | request = (MainThreadRequest) msg.obj; |
| 2633 | onCompleted = obtainMessage(EVENT_GET_SATELLITE_CAPABILITIES_DONE, request); |
| 2634 | Phone phone = getPhoneFromRequest(request); |
| 2635 | if (phone != null) { |
| 2636 | phone.getSatelliteCapabilities(onCompleted); |
| 2637 | } else { |
| 2638 | loge("getSatelliteCapabilities: No phone object"); |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 2639 | ((ResultReceiver) request.argument).send( |
| 2640 | SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE, null); |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 2641 | } |
| 2642 | break; |
| 2643 | } |
| 2644 | |
| 2645 | case EVENT_GET_SATELLITE_CAPABILITIES_DONE: { |
| 2646 | ar = (AsyncResult) msg.obj; |
| 2647 | request = (MainThreadRequest) ar.userObj; |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 2648 | int error = getSatelliteError(ar, "getSatelliteCapabilities", true); |
| 2649 | Bundle bundle = new Bundle(); |
| 2650 | if (error == SatelliteManager.SATELLITE_ERROR_NONE) { |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 2651 | SatelliteCapabilities capabilities = (SatelliteCapabilities) ar.result; |
| 2652 | if (DBG) log("getSatelliteCapabilities: " + capabilities); |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 2653 | bundle.putParcelable(SatelliteManager.KEY_SATELLITE_CAPABILITIES, |
| 2654 | capabilities); |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 2655 | } |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 2656 | ((ResultReceiver) request.argument).send(error, bundle); |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 2657 | break; |
| 2658 | } |
| 2659 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2660 | default: |
| 2661 | Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what); |
| 2662 | break; |
| 2663 | } |
| 2664 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2665 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 2666 | private void notifyRequester(MainThreadRequest request) { |
| 2667 | synchronized (request) { |
| 2668 | request.notifyAll(); |
| 2669 | } |
| 2670 | } |
| 2671 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2672 | private void handleNullReturnEvent(Message msg, String command) { |
| 2673 | AsyncResult ar = (AsyncResult) msg.obj; |
| 2674 | MainThreadRequest request = (MainThreadRequest) ar.userObj; |
| 2675 | if (ar.exception == null) { |
| 2676 | request.result = true; |
| 2677 | } else { |
| 2678 | request.result = false; |
| 2679 | if (ar.exception instanceof CommandException) { |
| 2680 | loge(command + ": CommandException: " + ar.exception); |
| 2681 | } else { |
| 2682 | loge(command + ": Unknown exception"); |
| 2683 | } |
| 2684 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 2685 | notifyRequester(request); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2686 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2687 | } |
| 2688 | |
| 2689 | /** |
| 2690 | * Posts the specified command to be executed on the main thread, |
| 2691 | * waits for the request to complete, and returns the result. |
| 2692 | * @see #sendRequestAsync |
| 2693 | */ |
| 2694 | private Object sendRequest(int command, Object argument) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2695 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, |
| 2696 | null, -1 /*timeoutInMs*/); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 2697 | } |
| 2698 | |
| 2699 | /** |
| 2700 | * Posts the specified command to be executed on the main thread, |
| 2701 | * waits for the request to complete, and returns the result. |
| 2702 | * @see #sendRequestAsync |
| 2703 | */ |
| 2704 | private Object sendRequest(int command, Object argument, WorkSource workSource) { |
| 2705 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2706 | null, workSource, -1 /*timeoutInMs*/); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2707 | } |
| 2708 | |
| 2709 | /** |
| 2710 | * Posts the specified command to be executed on the main thread, |
| 2711 | * waits for the request to complete, and returns the result. |
| 2712 | * @see #sendRequestAsync |
| 2713 | */ |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2714 | private Object sendRequest(int command, Object argument, Integer subId) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2715 | return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/); |
| 2716 | } |
| 2717 | |
| 2718 | /** |
| 2719 | * Posts the specified command to be executed on the main thread, |
| 2720 | * waits for the request to complete for at most {@code timeoutInMs}, and returns the result |
| 2721 | * if not timeout or null otherwise. |
| 2722 | * @see #sendRequestAsync |
| 2723 | */ |
| 2724 | private @Nullable Object sendRequest(int command, Object argument, Integer subId, |
| 2725 | long timeoutInMs) { |
| 2726 | return sendRequest(command, argument, subId, null, null, timeoutInMs); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 2727 | } |
| 2728 | |
| 2729 | /** |
| 2730 | * Posts the specified command to be executed on the main thread, |
| 2731 | * waits for the request to complete, and returns the result. |
| 2732 | * @see #sendRequestAsync |
| 2733 | */ |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2734 | private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2735 | return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2736 | } |
| 2737 | |
| 2738 | /** |
| 2739 | * Posts the specified command to be executed on the main thread, |
| 2740 | * waits for the request to complete, and returns the result. |
| 2741 | * @see #sendRequestAsync |
| 2742 | */ |
| 2743 | private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2744 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, |
| 2745 | workSource, -1 /*timeoutInMs*/); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2746 | } |
| 2747 | |
| 2748 | /** |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2749 | * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is |
| 2750 | * negative, waits for the request to complete, and returns the result. Otherwise, wait for |
| 2751 | * maximum of {@code timeoutInMs} milliseconds, interrupt and return null. |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2752 | * @see #sendRequestAsync |
| 2753 | */ |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2754 | private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone, |
| 2755 | WorkSource workSource, long timeoutInMs) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2756 | if (Looper.myLooper() == mMainThreadHandler.getLooper()) { |
| 2757 | throw new RuntimeException("This method will deadlock if called from the main thread."); |
| 2758 | } |
| 2759 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2760 | MainThreadRequest request = null; |
| 2761 | if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) { |
| 2762 | throw new IllegalArgumentException("subId and phone cannot both be specified!"); |
| 2763 | } else if (phone != null) { |
| 2764 | request = new MainThreadRequest(argument, phone, workSource); |
| 2765 | } else { |
| 2766 | request = new MainThreadRequest(argument, subId, workSource); |
| 2767 | } |
| 2768 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2769 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 2770 | msg.sendToTarget(); |
| 2771 | |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2772 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2773 | synchronized (request) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2774 | if (timeoutInMs >= 0) { |
| 2775 | // Wait for at least timeoutInMs before returning null request result |
| 2776 | long now = SystemClock.elapsedRealtime(); |
| 2777 | long deadline = now + timeoutInMs; |
Grace Jia | 8a0a1e8 | 2021-05-23 22:59:52 -0700 | [diff] [blame] | 2778 | while (request.result == null && now < deadline) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2779 | try { |
| 2780 | request.wait(deadline - now); |
| 2781 | } catch (InterruptedException e) { |
| 2782 | // Do nothing, go back and check if request is completed or timeout |
| 2783 | } finally { |
| 2784 | now = SystemClock.elapsedRealtime(); |
| 2785 | } |
| 2786 | } |
| 2787 | } else { |
| 2788 | // Wait for the request to complete |
| 2789 | while (request.result == null) { |
| 2790 | try { |
| 2791 | request.wait(); |
| 2792 | } catch (InterruptedException e) { |
| 2793 | // Do nothing, go back and wait until the request is complete |
| 2794 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2795 | } |
| 2796 | } |
| 2797 | } |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2798 | if (request.result == null) { |
| 2799 | Log.wtf(LOG_TAG, |
| 2800 | "sendRequest: Blocking command timed out. Something has gone terribly wrong."); |
| 2801 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2802 | return request.result; |
| 2803 | } |
| 2804 | |
| 2805 | /** |
| 2806 | * Asynchronous ("fire and forget") version of sendRequest(): |
| 2807 | * Posts the specified command to be executed on the main thread, and |
| 2808 | * returns immediately. |
| 2809 | * @see #sendRequest |
| 2810 | */ |
| 2811 | private void sendRequestAsync(int command) { |
| 2812 | mMainThreadHandler.sendEmptyMessage(command); |
| 2813 | } |
| 2814 | |
| 2815 | /** |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2816 | * Same as {@link #sendRequestAsync(int)} except it takes an argument. |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2817 | * @see {@link #sendRequest(int)} |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2818 | */ |
| 2819 | private void sendRequestAsync(int command, Object argument) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2820 | sendRequestAsync(command, argument, null, null); |
| 2821 | } |
| 2822 | |
| 2823 | /** |
| 2824 | * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource. |
| 2825 | * @see {@link #sendRequest(int,Object)} |
| 2826 | */ |
| 2827 | private void sendRequestAsync( |
| 2828 | int command, Object argument, Phone phone, WorkSource workSource) { |
| 2829 | MainThreadRequest request = new MainThreadRequest(argument, phone, workSource); |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2830 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 2831 | msg.sendToTarget(); |
| 2832 | } |
| 2833 | |
| 2834 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2835 | * Initialize the singleton PhoneInterfaceManager instance. |
| 2836 | * This is only done once, at startup, from PhoneApp.onCreate(). |
| 2837 | */ |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2838 | /* package */ static PhoneInterfaceManager init(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2839 | synchronized (PhoneInterfaceManager.class) { |
| 2840 | if (sInstance == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2841 | sInstance = new PhoneInterfaceManager(app); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2842 | } else { |
| 2843 | Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance); |
| 2844 | } |
| 2845 | return sInstance; |
| 2846 | } |
| 2847 | } |
| 2848 | |
| 2849 | /** Private constructor; @see init() */ |
Jordan Liu | 1979a04 | 2020-03-20 21:39:35 +0000 | [diff] [blame] | 2850 | private PhoneInterfaceManager(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2851 | mApp = app; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2852 | mCM = PhoneGlobals.getInstance().mCM; |
Brad Ebinger | d1947d8 | 2021-05-17 20:54:49 +0000 | [diff] [blame] | 2853 | mImsResolver = ImsResolver.getInstance(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 2854 | mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2855 | mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 2856 | mPm = app.getSystemService(PackageManager.class); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2857 | mMainThreadHandler = new MainThreadHandler(); |
Jack Yu | e37dd26 | 2022-12-16 11:53:37 -0800 | [diff] [blame] | 2858 | if (!PhoneFactory.isSubscriptionManagerServiceEnabled()) { |
| 2859 | mSubscriptionController = SubscriptionController.getInstance(); |
| 2860 | } else { |
| 2861 | mSubscriptionController = null; |
| 2862 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2863 | mTelephonySharedPreferences = |
| 2864 | PreferenceManager.getDefaultSharedPreferences(mApp); |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 2865 | mNetworkScanRequestTracker = new NetworkScanRequestTracker(); |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 2866 | mPhoneConfigurationManager = PhoneConfigurationManager.getInstance(); |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 2867 | mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance(); |
Peter Wang | a3cf4ac | 2020-01-27 09:39:46 +0800 | [diff] [blame] | 2868 | mNotifyUserActivity = new AtomicBoolean(false); |
Tyler Gunn | 64144d9 | 2022-03-17 14:16:41 -0700 | [diff] [blame] | 2869 | PropertyInvalidatedCache.invalidateCache(TelephonyManager.CACHE_KEY_PHONE_ACCOUNT_TO_SUBID); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2870 | publish(); |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 2871 | CarrierAllowListInfo.loadInstance(mApp); |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 2872 | mSatelliteSupportedReceiver = new ResultReceiver(mMainThreadHandler) { |
| 2873 | @Override |
| 2874 | protected void onReceiveResult(int resultCode, Bundle resultData) { |
| 2875 | if (resultCode == SatelliteManager.SATELLITE_ERROR_NONE |
| 2876 | && resultData.containsKey(SatelliteManager.KEY_SATELLITE_SUPPORTED)) { |
| 2877 | synchronized (mIsSatelliteSupportedLock) { |
| 2878 | mIsSatelliteSupported = resultData.getBoolean( |
| 2879 | SatelliteManager.KEY_SATELLITE_SUPPORTED); |
| 2880 | } |
| 2881 | } else { |
| 2882 | synchronized (mIsSatelliteSupportedLock) { |
| 2883 | mIsSatelliteSupported = null; |
| 2884 | } |
| 2885 | } |
| 2886 | } |
| 2887 | }; |
| 2888 | requestIsSatelliteSupported(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, |
| 2889 | mSatelliteSupportedReceiver); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2890 | } |
| 2891 | |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 2892 | @VisibleForTesting |
| 2893 | public SharedPreferences getSharedPreferences() { |
| 2894 | return mTelephonySharedPreferences; |
| 2895 | } |
| 2896 | |
Gil Cukierman | 92cc7db | 2023-01-06 19:25:53 +0000 | [diff] [blame] | 2897 | /** |
| 2898 | * Get the default phone for this device. |
| 2899 | */ |
| 2900 | @VisibleForTesting |
| 2901 | public Phone getDefaultPhone() { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2902 | Phone thePhone = getPhone(getDefaultSubscription()); |
| 2903 | return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone(); |
| 2904 | } |
| 2905 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2906 | private void publish() { |
| 2907 | if (DBG) log("publish: " + this); |
| 2908 | |
Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 2909 | TelephonyFrameworkInitializer |
| 2910 | .getTelephonyServiceManager() |
| 2911 | .getTelephonyServiceRegisterer() |
| 2912 | .register(this); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2913 | } |
| 2914 | |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 2915 | private Phone getPhoneFromRequest(MainThreadRequest request) { |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 2916 | if (request.phone != null) { |
| 2917 | return request.phone; |
| 2918 | } else { |
| 2919 | return getPhoneFromSubId(request.subId); |
| 2920 | } |
| 2921 | } |
| 2922 | |
| 2923 | private Phone getPhoneFromSubId(int subId) { |
| 2924 | return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) |
| 2925 | ? getDefaultPhone() : getPhone(subId); |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 2926 | } |
| 2927 | |
Aishwarya Mallampati | 5e581e1 | 2023-01-17 21:57:06 +0000 | [diff] [blame] | 2928 | /** |
| 2929 | * Get phone object associated with a subscription. |
| 2930 | * Return default phone if phone object associated with subscription is null |
| 2931 | * @param subId - subscriptionId |
| 2932 | * @return phone object associated with a subscription or default phone if null. |
| 2933 | */ |
| 2934 | private Phone getPhoneFromSubIdOrDefault(int subId) { |
| 2935 | Phone phone = getPhoneFromSubId(subId); |
| 2936 | if (phone == null) { |
| 2937 | phone = getDefaultPhone(); |
| 2938 | } |
| 2939 | return phone; |
| 2940 | } |
| 2941 | |
Rambo Wang | e53e07d | 2022-05-10 13:01:13 -0700 | [diff] [blame] | 2942 | @Nullable |
| 2943 | private UiccPort getUiccPortFromRequest(@NonNull MainThreadRequest request) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2944 | Phone phone = getPhoneFromRequest(request); |
| 2945 | return phone == null ? null : |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 2946 | UiccController.getInstance().getUiccPort(phone.getPhoneId()); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2947 | } |
| 2948 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2949 | // returns phone associated with the subId. |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2950 | private Phone getPhone(int subId) { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 2951 | return PhoneFactory.getPhone(SubscriptionManager.getPhoneId(subId)); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2952 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2953 | |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 2954 | private void sendEraseModemConfig(@NonNull Phone phone) { |
| 2955 | Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null); |
| 2956 | if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 2957 | } |
| 2958 | |
| 2959 | private void sendEraseDataInSharedPreferences(@NonNull Phone phone) { |
| 2960 | Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null); |
| 2961 | if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail")); |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 2962 | } |
| 2963 | |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 2964 | private boolean isImsAvailableOnDevice() { |
| 2965 | PackageManager pm = getDefaultPhone().getContext().getPackageManager(); |
| 2966 | if (pm == null) { |
| 2967 | // For some reason package manger is not available.. This will fail internally anyway, |
| 2968 | // so do not throw error and allow. |
| 2969 | return true; |
| 2970 | } |
| 2971 | return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0); |
| 2972 | } |
| 2973 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2974 | public void dial(String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2975 | dialForSubscriber(getPreferredVoiceSubscription(), number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2976 | } |
| 2977 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2978 | public void dialForSubscriber(int subId, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2979 | if (DBG) log("dial: " + number); |
| 2980 | // No permission check needed here: This is just a wrapper around the |
| 2981 | // ACTION_DIAL intent, which is available to any app since it puts up |
| 2982 | // the UI before it does anything. |
| 2983 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2984 | final long identity = Binder.clearCallingIdentity(); |
| 2985 | try { |
| 2986 | String url = createTelUrl(number); |
| 2987 | if (url == null) { |
| 2988 | return; |
| 2989 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2990 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2991 | // PENDING: should we just silently fail if phone is offhook or ringing? |
| 2992 | PhoneConstants.State state = mCM.getState(subId); |
| 2993 | if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) { |
| 2994 | Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url)); |
| 2995 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2996 | mApp.startActivity(intent); |
| 2997 | } |
| 2998 | } finally { |
| 2999 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3000 | } |
| 3001 | } |
| 3002 | |
| 3003 | public void call(String callingPackage, String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 3004 | callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3005 | } |
| 3006 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3007 | public void callForSubscriber(int subId, String callingPackage, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3008 | if (DBG) log("call: " + number); |
| 3009 | |
| 3010 | // This is just a wrapper around the ACTION_CALL intent, but we still |
| 3011 | // need to do a permission check since we're calling startActivity() |
| 3012 | // from the context of the phone app. |
| 3013 | enforceCallPermission(); |
| 3014 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 3015 | if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage) |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3016 | != AppOpsManager.MODE_ALLOWED) { |
| 3017 | return; |
| 3018 | } |
| 3019 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3020 | final long identity = Binder.clearCallingIdentity(); |
| 3021 | try { |
| 3022 | String url = createTelUrl(number); |
| 3023 | if (url == null) { |
| 3024 | return; |
| 3025 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3026 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3027 | boolean isValid = false; |
| 3028 | final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged(); |
| 3029 | if (slist != null) { |
| 3030 | for (SubscriptionInfo subInfoRecord : slist) { |
| 3031 | if (subInfoRecord.getSubscriptionId() == subId) { |
| 3032 | isValid = true; |
| 3033 | break; |
| 3034 | } |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 3035 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 3036 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3037 | if (!isValid) { |
| 3038 | return; |
| 3039 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 3040 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3041 | Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url)); |
| 3042 | intent.putExtra(SUBSCRIPTION_KEY, subId); |
| 3043 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 3044 | mApp.startActivity(intent); |
| 3045 | } finally { |
| 3046 | Binder.restoreCallingIdentity(identity); |
| 3047 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3048 | } |
| 3049 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3050 | public boolean supplyPinForSubscriber(int subId, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 3051 | int [] resultArray = supplyPinReportResultForSubscriber(subId, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 3052 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 3053 | } |
| 3054 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3055 | public boolean supplyPukForSubscriber(int subId, String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 3056 | int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 3057 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 3058 | } |
| 3059 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3060 | public int[] supplyPinReportResultForSubscriber(int subId, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3061 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3062 | |
| 3063 | final long identity = Binder.clearCallingIdentity(); |
| 3064 | try { |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 3065 | Phone phone = getPhone(subId); |
| 3066 | final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3067 | checkSimPin.start(); |
| 3068 | return checkSimPin.unlockSim(null, pin); |
| 3069 | } finally { |
| 3070 | Binder.restoreCallingIdentity(identity); |
| 3071 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3072 | } |
| 3073 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3074 | public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3075 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3076 | |
| 3077 | final long identity = Binder.clearCallingIdentity(); |
| 3078 | try { |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 3079 | Phone phone = getPhone(subId); |
| 3080 | final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3081 | checkSimPuk.start(); |
| 3082 | return checkSimPuk.unlockSim(puk, pin); |
| 3083 | } finally { |
| 3084 | Binder.restoreCallingIdentity(identity); |
| 3085 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3086 | } |
| 3087 | |
| 3088 | /** |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 3089 | * Helper thread to turn async call to SimCard#supplyPin into |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3090 | * a synchronous one. |
| 3091 | */ |
| 3092 | private static class UnlockSim extends Thread { |
| 3093 | |
| 3094 | private final IccCard mSimCard; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 3095 | private final int mPhoneId; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3096 | |
| 3097 | private boolean mDone = false; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 3098 | private int mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 3099 | private int mRetryCount = -1; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3100 | |
| 3101 | // For replies from SimCard interface |
| 3102 | private Handler mHandler; |
| 3103 | |
| 3104 | // For async handler to identify request type |
| 3105 | private static final int SUPPLY_PIN_COMPLETE = 100; |
| 3106 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 3107 | UnlockSim(int phoneId, IccCard simCard) { |
| 3108 | mPhoneId = phoneId; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3109 | mSimCard = simCard; |
| 3110 | } |
| 3111 | |
| 3112 | @Override |
| 3113 | public void run() { |
| 3114 | Looper.prepare(); |
| 3115 | synchronized (UnlockSim.this) { |
| 3116 | mHandler = new Handler() { |
| 3117 | @Override |
| 3118 | public void handleMessage(Message msg) { |
| 3119 | AsyncResult ar = (AsyncResult) msg.obj; |
| 3120 | switch (msg.what) { |
| 3121 | case SUPPLY_PIN_COMPLETE: |
| 3122 | Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE"); |
| 3123 | synchronized (UnlockSim.this) { |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 3124 | mRetryCount = msg.arg1; |
| 3125 | if (ar.exception != null) { |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 3126 | CommandException.Error error = null; |
| 3127 | if (ar.exception instanceof CommandException) { |
| 3128 | error = ((CommandException) (ar.exception)) |
| 3129 | .getCommandError(); |
| 3130 | } |
| 3131 | if (error == CommandException.Error.PASSWORD_INCORRECT) { |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 3132 | mResult = PhoneConstants.PIN_PASSWORD_INCORRECT; |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 3133 | } else if (error == CommandException.Error.ABORTED) { |
| 3134 | /* When UiccCardApp dispose, handle message and return |
| 3135 | exception */ |
vivi.li | b5e9ada | 2019-09-12 16:04:24 +0800 | [diff] [blame] | 3136 | mResult = PhoneConstants.PIN_OPERATION_ABORTED; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 3137 | } else { |
| 3138 | mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 3139 | } |
| 3140 | } else { |
| 3141 | mResult = PhoneConstants.PIN_RESULT_SUCCESS; |
| 3142 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3143 | mDone = true; |
| 3144 | UnlockSim.this.notifyAll(); |
| 3145 | } |
| 3146 | break; |
| 3147 | } |
| 3148 | } |
| 3149 | }; |
| 3150 | UnlockSim.this.notifyAll(); |
| 3151 | } |
| 3152 | Looper.loop(); |
| 3153 | } |
| 3154 | |
| 3155 | /* |
| 3156 | * Use PIN or PUK to unlock SIM card |
| 3157 | * |
| 3158 | * If PUK is null, unlock SIM card with PIN |
| 3159 | * |
| 3160 | * If PUK is not null, unlock SIM card with PUK and set PIN code |
| 3161 | */ |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 3162 | synchronized int[] unlockSim(String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3163 | |
| 3164 | while (mHandler == null) { |
| 3165 | try { |
| 3166 | wait(); |
| 3167 | } catch (InterruptedException e) { |
| 3168 | Thread.currentThread().interrupt(); |
| 3169 | } |
| 3170 | } |
| 3171 | Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE); |
| 3172 | |
| 3173 | if (puk == null) { |
| 3174 | mSimCard.supplyPin(pin, callback); |
| 3175 | } else { |
| 3176 | mSimCard.supplyPuk(puk, pin, callback); |
| 3177 | } |
| 3178 | |
| 3179 | while (!mDone) { |
| 3180 | try { |
| 3181 | Log.d(LOG_TAG, "wait for done"); |
| 3182 | wait(); |
| 3183 | } catch (InterruptedException e) { |
| 3184 | // Restore the interrupted status |
| 3185 | Thread.currentThread().interrupt(); |
| 3186 | } |
| 3187 | } |
| 3188 | Log.d(LOG_TAG, "done"); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 3189 | int[] resultArray = new int[2]; |
| 3190 | resultArray[0] = mResult; |
| 3191 | resultArray[1] = mRetryCount; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 3192 | |
| 3193 | if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) { |
Jon Spivack | 9c3bc76 | 2021-10-06 20:53:09 +0000 | [diff] [blame] | 3194 | UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 3195 | } |
| 3196 | |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 3197 | return resultArray; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3198 | } |
| 3199 | } |
| 3200 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 3201 | /** |
| 3202 | * This method has been removed due to privacy and stability concerns. |
| 3203 | */ |
| 3204 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3205 | public void updateServiceLocation() { |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 3206 | Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()"); |
| 3207 | return; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3208 | } |
| 3209 | |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 3210 | @Override |
| 3211 | public void updateServiceLocationWithPackageName(String callingPackage) { |
| 3212 | mApp.getSystemService(AppOpsManager.class) |
| 3213 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 3214 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3215 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 3216 | if (targetSdk > android.os.Build.VERSION_CODES.R) { |
| 3217 | // Callers targeting S have no business invoking this method. |
| 3218 | return; |
| 3219 | } |
| 3220 | |
| 3221 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 3222 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 3223 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 3224 | .setCallingPackage(callingPackage) |
| 3225 | .setCallingFeatureId(null) |
| 3226 | .setCallingPid(Binder.getCallingPid()) |
| 3227 | .setCallingUid(Binder.getCallingUid()) |
| 3228 | .setMethod("updateServiceLocation") |
| 3229 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
| 3230 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 3231 | .build()); |
| 3232 | // Apps that lack location permission have no business calling this method; |
| 3233 | // however, because no permission was declared in the public API, denials must |
| 3234 | // all be "soft". |
| 3235 | switch (locationResult) { |
| 3236 | case DENIED_HARD: /* fall through */ |
| 3237 | case DENIED_SOFT: |
| 3238 | return; |
| 3239 | } |
| 3240 | |
| 3241 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3242 | final long identity = Binder.clearCallingIdentity(); |
| 3243 | try { |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 3244 | final Phone phone = getPhone(getDefaultSubscription()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3245 | if (phone != null) { |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 3246 | phone.updateServiceLocation(workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3247 | } |
| 3248 | } finally { |
| 3249 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3250 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3251 | } |
| 3252 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3253 | @Deprecated |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3254 | @Override |
| 3255 | public boolean isRadioOn(String callingPackage) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3256 | return isRadioOnWithFeature(callingPackage, null); |
| 3257 | } |
| 3258 | |
| 3259 | |
| 3260 | @Override |
| 3261 | public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) { |
| 3262 | return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage, |
| 3263 | callingFeatureId); |
| 3264 | } |
| 3265 | |
| 3266 | @Deprecated |
| 3267 | @Override |
| 3268 | public boolean isRadioOnForSubscriber(int subId, String callingPackage) { |
| 3269 | return isRadioOnForSubscriberWithFeature(subId, callingPackage, null); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3270 | } |
| 3271 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3272 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3273 | public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage, |
| 3274 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3275 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3276 | mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3277 | return false; |
| 3278 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3279 | |
| 3280 | final long identity = Binder.clearCallingIdentity(); |
| 3281 | try { |
| 3282 | return isRadioOnForSubscriber(subId); |
| 3283 | } finally { |
| 3284 | Binder.restoreCallingIdentity(identity); |
| 3285 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3286 | } |
| 3287 | |
| 3288 | private boolean isRadioOnForSubscriber(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3289 | final long identity = Binder.clearCallingIdentity(); |
| 3290 | try { |
| 3291 | final Phone phone = getPhone(subId); |
| 3292 | if (phone != null) { |
| 3293 | return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF; |
| 3294 | } else { |
| 3295 | return false; |
| 3296 | } |
| 3297 | } finally { |
| 3298 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3299 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3300 | } |
| 3301 | |
| 3302 | public void toggleRadioOnOff() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 3303 | toggleRadioOnOffForSubscriber(getDefaultSubscription()); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3304 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3305 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3306 | public void toggleRadioOnOffForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3307 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3308 | |
| 3309 | final long identity = Binder.clearCallingIdentity(); |
| 3310 | try { |
| 3311 | final Phone phone = getPhone(subId); |
| 3312 | if (phone != null) { |
| 3313 | phone.setRadioPower(!isRadioOnForSubscriber(subId)); |
| 3314 | } |
| 3315 | } finally { |
| 3316 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3317 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3318 | } |
| 3319 | |
| 3320 | public boolean setRadio(boolean turnOn) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 3321 | return setRadioForSubscriber(getDefaultSubscription(), turnOn); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3322 | } |
| 3323 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3324 | public boolean setRadioForSubscriber(int subId, boolean turnOn) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3325 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3326 | |
| 3327 | final long identity = Binder.clearCallingIdentity(); |
| 3328 | try { |
| 3329 | final Phone phone = getPhone(subId); |
| 3330 | if (phone == null) { |
| 3331 | return false; |
| 3332 | } |
| 3333 | if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) { |
| 3334 | toggleRadioOnOffForSubscriber(subId); |
| 3335 | } |
| 3336 | return true; |
| 3337 | } finally { |
| 3338 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3339 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3340 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3341 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3342 | public boolean needMobileRadioShutdown() { |
Shuo Qian | fa7b6b3 | 2019-12-10 10:40:38 -0800 | [diff] [blame] | 3343 | enforceReadPrivilegedPermission("needMobileRadioShutdown"); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3344 | /* |
| 3345 | * If any of the Radios are available, it will need to be |
| 3346 | * shutdown. So return true if any Radio is available. |
| 3347 | */ |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3348 | final long identity = Binder.clearCallingIdentity(); |
| 3349 | try { |
| 3350 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 3351 | Phone phone = PhoneFactory.getPhone(i); |
| 3352 | if (phone != null && phone.isRadioAvailable()) return true; |
| 3353 | } |
| 3354 | logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown."); |
| 3355 | return false; |
| 3356 | } finally { |
| 3357 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3358 | } |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3359 | } |
| 3360 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3361 | @Override |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3362 | public void shutdownMobileRadios() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3363 | enforceModifyPermission(); |
| 3364 | |
| 3365 | final long identity = Binder.clearCallingIdentity(); |
| 3366 | try { |
| 3367 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 3368 | logv("Shutting down Phone " + i); |
| 3369 | shutdownRadioUsingPhoneId(i); |
| 3370 | } |
| 3371 | } finally { |
| 3372 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3373 | } |
| 3374 | } |
| 3375 | |
| 3376 | private void shutdownRadioUsingPhoneId(int phoneId) { |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3377 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 3378 | if (phone != null && phone.isRadioAvailable()) { |
| 3379 | phone.shutdownRadio(); |
| 3380 | } |
| 3381 | } |
| 3382 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3383 | public boolean setRadioPower(boolean turnOn) { |
Jack Yu | b4e1616 | 2017-05-15 12:48:40 -0700 | [diff] [blame] | 3384 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3385 | |
Ling Ma | 83dc5ea | 2023-01-12 15:06:04 -0800 | [diff] [blame] | 3386 | if (!turnOn) { |
| 3387 | log("setRadioPower off: callingPackage=" + getCurrentPackageName()); |
| 3388 | } |
| 3389 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3390 | final long identity = Binder.clearCallingIdentity(); |
| 3391 | try { |
| 3392 | final Phone defaultPhone = PhoneFactory.getDefaultPhone(); |
| 3393 | if (defaultPhone != null) { |
| 3394 | defaultPhone.setRadioPower(turnOn); |
| 3395 | return true; |
| 3396 | } else { |
| 3397 | loge("There's no default phone."); |
| 3398 | return false; |
| 3399 | } |
| 3400 | } finally { |
| 3401 | Binder.restoreCallingIdentity(identity); |
Wei Liu | 9ae2a06 | 2016-08-08 11:09:34 -0700 | [diff] [blame] | 3402 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3403 | } |
| 3404 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3405 | public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3406 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3407 | |
Ling Ma | 83dc5ea | 2023-01-12 15:06:04 -0800 | [diff] [blame] | 3408 | if (!turnOn) { |
| 3409 | log("setRadioPowerForSubscriber off: subId=" + subId |
| 3410 | + ",callingPackage=" + getCurrentPackageName()); |
| 3411 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3412 | final long identity = Binder.clearCallingIdentity(); |
| 3413 | try { |
| 3414 | final Phone phone = getPhone(subId); |
| 3415 | if (phone != null) { |
| 3416 | phone.setRadioPower(turnOn); |
| 3417 | return true; |
| 3418 | } else { |
| 3419 | return false; |
| 3420 | } |
| 3421 | } finally { |
| 3422 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3423 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3424 | } |
| 3425 | |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3426 | /** |
| 3427 | * Vote on powering off the radio for a reason. The radio will be turned on only when there is |
| 3428 | * no reason to power it off. When any of the voters want to power it off, it will be turned |
| 3429 | * off. In case of emergency, the radio will be turned on even if there are some reasons for |
| 3430 | * powering it off, and these radio off votes will be cleared. |
| 3431 | * Multiple apps can vote for the same reason and the last vote will take effect. Each app is |
| 3432 | * responsible for its vote. A powering-off vote of a reason will be maintained until it is |
| 3433 | * cleared by calling {@link clearRadioPowerOffForReason} for that reason, or an emergency call |
| 3434 | * is made, or the device is rebooted. When an app comes backup from a crash, it needs to make |
| 3435 | * sure if its vote is as expected. An app can use the API {@link getRadioPowerOffReasons} to |
| 3436 | * check its vote. |
| 3437 | * |
| 3438 | * @param subId The subscription ID. |
| 3439 | * @param reason The reason for powering off radio. |
| 3440 | * @return true on success and false on failure. |
| 3441 | */ |
| 3442 | public boolean requestRadioPowerOffForReason(int subId, |
| 3443 | @TelephonyManager.RadioPowerReason int reason) { |
| 3444 | enforceModifyPermission(); |
| 3445 | |
Ling Ma | 83dc5ea | 2023-01-12 15:06:04 -0800 | [diff] [blame] | 3446 | log("requestRadioPowerOffForReason: subId=" + subId |
| 3447 | + ",reason=" + reason + ",callingPackage=" + getCurrentPackageName()); |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3448 | final long identity = Binder.clearCallingIdentity(); |
| 3449 | try { |
| 3450 | final Phone phone = getPhone(subId); |
| 3451 | if (phone != null) { |
| 3452 | phone.setRadioPowerForReason(false, reason); |
| 3453 | return true; |
| 3454 | } else { |
| 3455 | return false; |
| 3456 | } |
| 3457 | } finally { |
| 3458 | Binder.restoreCallingIdentity(identity); |
| 3459 | } |
| 3460 | } |
| 3461 | |
| 3462 | /** |
| 3463 | * Remove the vote on powering off the radio for a reason, as requested by |
| 3464 | * {@link requestRadioPowerOffForReason}. |
| 3465 | * |
| 3466 | * @param subId The subscription ID. |
| 3467 | * @param reason The reason for powering off radio. |
| 3468 | * @return true on success and false on failure. |
| 3469 | */ |
| 3470 | public boolean clearRadioPowerOffForReason(int subId, |
| 3471 | @TelephonyManager.RadioPowerReason int reason) { |
| 3472 | enforceModifyPermission(); |
| 3473 | |
| 3474 | final long identity = Binder.clearCallingIdentity(); |
| 3475 | try { |
| 3476 | final Phone phone = getPhone(subId); |
| 3477 | if (phone != null) { |
| 3478 | phone.setRadioPowerForReason(true, reason); |
| 3479 | return true; |
| 3480 | } else { |
| 3481 | return false; |
| 3482 | } |
| 3483 | } finally { |
| 3484 | Binder.restoreCallingIdentity(identity); |
| 3485 | } |
| 3486 | } |
| 3487 | |
| 3488 | /** |
| 3489 | * Get reasons for powering off radio, as requested by {@link requestRadioPowerOffForReason}. |
| 3490 | * |
| 3491 | * @param subId The subscription ID. |
| 3492 | * @param callingPackage The package making the call. |
| 3493 | * @param callingFeatureId The feature in the package. |
| 3494 | * @return List of reasons for powering off radio. |
| 3495 | */ |
| 3496 | public List getRadioPowerOffReasons(int subId, String callingPackage, String callingFeatureId) { |
| 3497 | enforceReadPrivilegedPermission("getRadioPowerOffReasons"); |
| 3498 | |
| 3499 | final long identity = Binder.clearCallingIdentity(); |
| 3500 | List result = new ArrayList(); |
| 3501 | try { |
| 3502 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, |
| 3503 | callingPackage, callingFeatureId, "getRadioPowerOffReasons")) { |
| 3504 | return result; |
| 3505 | } |
| 3506 | |
| 3507 | final Phone phone = getPhone(subId); |
| 3508 | if (phone != null) { |
| 3509 | result.addAll(phone.getRadioPowerOffReasons()); |
| 3510 | } |
| 3511 | } finally { |
| 3512 | Binder.restoreCallingIdentity(identity); |
| 3513 | } |
| 3514 | return result; |
| 3515 | } |
| 3516 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3517 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3518 | @Override |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 3519 | public boolean enableDataConnectivity(String callingPackage) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3520 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3521 | |
| 3522 | final long identity = Binder.clearCallingIdentity(); |
| 3523 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3524 | int subId = SubscriptionManager.getDefaultDataSubscriptionId(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3525 | final Phone phone = getPhone(subId); |
| 3526 | if (phone != null) { |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 3527 | phone.getDataSettingsManager().setDataEnabled( |
| 3528 | TelephonyManager.DATA_ENABLED_REASON_USER, true, callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3529 | return true; |
| 3530 | } else { |
| 3531 | return false; |
| 3532 | } |
| 3533 | } finally { |
| 3534 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3535 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3536 | } |
| 3537 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3538 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3539 | @Override |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 3540 | public boolean disableDataConnectivity(String callingPackage) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3541 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3542 | |
| 3543 | final long identity = Binder.clearCallingIdentity(); |
| 3544 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3545 | int subId = SubscriptionManager.getDefaultDataSubscriptionId(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3546 | final Phone phone = getPhone(subId); |
| 3547 | if (phone != null) { |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 3548 | phone.getDataSettingsManager().setDataEnabled( |
| 3549 | TelephonyManager.DATA_ENABLED_REASON_USER, false, callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3550 | return true; |
| 3551 | } else { |
| 3552 | return false; |
| 3553 | } |
| 3554 | } finally { |
| 3555 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3556 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3557 | } |
| 3558 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3559 | @Override |
Jack Yu | acf8a13 | 2017-05-01 17:00:48 -0700 | [diff] [blame] | 3560 | public boolean isDataConnectivityPossible(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3561 | final long identity = Binder.clearCallingIdentity(); |
| 3562 | try { |
| 3563 | final Phone phone = getPhone(subId); |
| 3564 | if (phone != null) { |
Jack Yu | 59824e1 | 2022-03-23 01:42:44 -0700 | [diff] [blame] | 3565 | return phone.isDataAllowed(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3566 | } else { |
| 3567 | return false; |
| 3568 | } |
| 3569 | } finally { |
| 3570 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3571 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3572 | } |
| 3573 | |
| 3574 | public boolean handlePinMmi(String dialString) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 3575 | return handlePinMmiForSubscriber(getDefaultSubscription(), dialString); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3576 | } |
| 3577 | |
pkanwar | ae03a6b | 2016-11-06 20:37:09 -0800 | [diff] [blame] | 3578 | public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3579 | enforceCallPermission(); |
| 3580 | |
| 3581 | final long identity = Binder.clearCallingIdentity(); |
| 3582 | try { |
| 3583 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3584 | return; |
| 3585 | } |
| 3586 | Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback); |
| 3587 | sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId); |
| 3588 | } finally { |
| 3589 | Binder.restoreCallingIdentity(identity); |
| 3590 | } |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 3591 | }; |
| 3592 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3593 | public boolean handlePinMmiForSubscriber(int subId, String dialString) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3594 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3595 | |
| 3596 | final long identity = Binder.clearCallingIdentity(); |
| 3597 | try { |
| 3598 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3599 | return false; |
| 3600 | } |
| 3601 | return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId); |
| 3602 | } finally { |
| 3603 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3604 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3605 | } |
| 3606 | |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 3607 | /** |
| 3608 | * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage |
| 3609 | * tag on getCallState Binder call. |
| 3610 | */ |
| 3611 | @Deprecated |
| 3612 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3613 | public int getCallState() { |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 3614 | if (CompatChanges.isChangeEnabled( |
| 3615 | TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION, |
| 3616 | Binder.getCallingUid())) { |
| 3617 | // Do not allow this API to be called on API version 31+, it should only be |
| 3618 | // called on old apps using this Binder call directly. |
| 3619 | throw new SecurityException("This method can only be used for applications " |
| 3620 | + "targeting API version 30 or less."); |
| 3621 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3622 | final long identity = Binder.clearCallingIdentity(); |
| 3623 | try { |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 3624 | Phone phone = getPhone(getDefaultSubscription()); |
| 3625 | return phone == null ? TelephonyManager.CALL_STATE_IDLE : |
| 3626 | PhoneConstantConversions.convertCallState(phone.getState()); |
| 3627 | } finally { |
| 3628 | Binder.restoreCallingIdentity(identity); |
| 3629 | } |
| 3630 | } |
| 3631 | |
| 3632 | @Override |
| 3633 | public int getCallStateForSubscription(int subId, String callingPackage, String featureId) { |
| 3634 | if (CompatChanges.isChangeEnabled( |
| 3635 | TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION, |
| 3636 | Binder.getCallingUid())) { |
| 3637 | // Check READ_PHONE_STATE for API version 31+ |
| 3638 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage, |
| 3639 | featureId, "getCallStateForSubscription")) { |
| 3640 | throw new SecurityException("getCallState requires READ_PHONE_STATE for apps " |
| 3641 | + "targeting API level 31+."); |
| 3642 | } |
| 3643 | } |
| 3644 | final long identity = Binder.clearCallingIdentity(); |
| 3645 | try { |
| 3646 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3647 | return phone == null ? TelephonyManager.CALL_STATE_IDLE : |
| 3648 | PhoneConstantConversions.convertCallState(phone.getState()); |
| 3649 | } finally { |
| 3650 | Binder.restoreCallingIdentity(identity); |
| 3651 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3652 | } |
| 3653 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3654 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 3655 | public int getDataState() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3656 | return getDataStateForSubId(SubscriptionManager.getDefaultDataSubscriptionId()); |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 3657 | } |
| 3658 | |
| 3659 | @Override |
| 3660 | public int getDataStateForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3661 | final long identity = Binder.clearCallingIdentity(); |
| 3662 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 3663 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3664 | if (phone != null) { |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 3665 | return phone.getDataNetworkController().getInternetDataNetworkState(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3666 | } else { |
| 3667 | return PhoneConstantConversions.convertDataState( |
| 3668 | PhoneConstants.DataState.DISCONNECTED); |
| 3669 | } |
| 3670 | } finally { |
| 3671 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3672 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3673 | } |
| 3674 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3675 | @Override |
Jack Yu | 0eda684 | 2022-04-18 00:34:46 -0700 | [diff] [blame] | 3676 | public @DataActivityType int getDataActivity() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3677 | return getDataActivityForSubId(SubscriptionManager.getDefaultDataSubscriptionId()); |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 3678 | } |
| 3679 | |
| 3680 | @Override |
Jack Yu | 0eda684 | 2022-04-18 00:34:46 -0700 | [diff] [blame] | 3681 | public @DataActivityType int getDataActivityForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3682 | final long identity = Binder.clearCallingIdentity(); |
| 3683 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 3684 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3685 | if (phone != null) { |
Jack Yu | 0eda684 | 2022-04-18 00:34:46 -0700 | [diff] [blame] | 3686 | return phone.getDataActivityState(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3687 | } else { |
| 3688 | return TelephonyManager.DATA_ACTIVITY_NONE; |
| 3689 | } |
| 3690 | } finally { |
| 3691 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3692 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3693 | } |
| 3694 | |
| 3695 | @Override |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 3696 | public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3697 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 3698 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3699 | |
| 3700 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 3701 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 3702 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 3703 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3704 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3705 | .setCallingPid(Binder.getCallingPid()) |
| 3706 | .setCallingUid(Binder.getCallingUid()) |
| 3707 | .setMethod("getCellLocation") |
Hall Liu | 773ba02 | 2020-01-24 18:07:12 -0800 | [diff] [blame] | 3708 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3709 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 3710 | .build()); |
| 3711 | switch (locationResult) { |
| 3712 | case DENIED_HARD: |
| 3713 | throw new SecurityException("Not allowed to access cell location"); |
| 3714 | case DENIED_SOFT: |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 3715 | return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
| 3716 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3717 | } |
| 3718 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 3719 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3720 | final long identity = Binder.clearCallingIdentity(); |
| 3721 | try { |
| 3722 | if (DBG_LOC) log("getCellLocation: is active user"); |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3723 | int subId = SubscriptionManager.getDefaultDataSubscriptionId(); |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 3724 | return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3725 | } finally { |
| 3726 | Binder.restoreCallingIdentity(identity); |
| 3727 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 3728 | } |
| 3729 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3730 | @Override |
Jack Yu | eb1e7fe | 2020-02-22 19:38:58 -0800 | [diff] [blame] | 3731 | public String getNetworkCountryIsoForPhone(int phoneId) { |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3732 | // Reporting the correct network country is ambiguous when IWLAN could conflict with |
| 3733 | // registered cell info, so return a NULL country instead. |
| 3734 | final long identity = Binder.clearCallingIdentity(); |
| 3735 | try { |
Malcolm Chen | 3732c2b | 2018-07-18 20:15:24 -0700 | [diff] [blame] | 3736 | if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) { |
| 3737 | // Get default phone in this case. |
| 3738 | phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX; |
| 3739 | } |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3740 | final int subId = SubscriptionManager.getSubscriptionId(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3741 | Phone phone = PhoneFactory.getPhone(phoneId); |
Nathan Harold | 532f51c | 2020-04-21 19:31:10 -0700 | [diff] [blame] | 3742 | if (phone == null) return ""; |
| 3743 | ServiceStateTracker sst = phone.getServiceStateTracker(); |
| 3744 | if (sst == null) return ""; |
| 3745 | LocaleTracker lt = sst.getLocaleTracker(); |
| 3746 | if (lt == null) return ""; |
Shuo Qian | 9418a92 | 2021-03-09 11:21:16 -0800 | [diff] [blame] | 3747 | return lt.getCurrentCountry(); |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3748 | } finally { |
| 3749 | Binder.restoreCallingIdentity(identity); |
| 3750 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3751 | } |
| 3752 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 3753 | /** |
| 3754 | * This method was removed due to potential issues caused by performing partial |
| 3755 | * updates of service state, and lack of a credible use case. |
| 3756 | * |
| 3757 | * This has the ability to break the telephony implementation by disabling notification of |
| 3758 | * changes in device connectivity. DO NOT USE THIS! |
| 3759 | */ |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3760 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3761 | public void enableLocationUpdates() { |
| 3762 | mApp.enforceCallingOrSelfPermission( |
| 3763 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3764 | } |
| 3765 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 3766 | /** |
| 3767 | * This method was removed due to potential issues caused by performing partial |
| 3768 | * updates of service state, and lack of a credible use case. |
| 3769 | * |
| 3770 | * This has the ability to break the telephony implementation by disabling notification of |
| 3771 | * changes in device connectivity. DO NOT USE THIS! |
| 3772 | */ |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3773 | @Override |
| 3774 | public void disableLocationUpdates() { |
| 3775 | mApp.enforceCallingOrSelfPermission( |
| 3776 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3777 | } |
| 3778 | |
| 3779 | @Override |
| 3780 | @SuppressWarnings("unchecked") |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3781 | public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage, |
| 3782 | String callingFeatureId) { |
Nathan Harold | b55f63b | 2021-07-27 11:27:38 -0700 | [diff] [blame] | 3783 | try { |
| 3784 | mApp.getSystemService(AppOpsManager.class) |
| 3785 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 3786 | } catch (SecurityException e) { |
| 3787 | EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid()); |
| 3788 | throw e; |
| 3789 | } |
| 3790 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3791 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | dbea45a | 2018-08-30 14:35:07 -0700 | [diff] [blame] | 3792 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 3793 | throw new SecurityException( |
| 3794 | "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels."); |
| 3795 | } |
Nathan Harold | b4d5561 | 2018-07-20 13:13:08 -0700 | [diff] [blame] | 3796 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 3797 | if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(), |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3798 | callingPackage) != AppOpsManager.MODE_ALLOWED) { |
| 3799 | return null; |
| 3800 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 3801 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 3802 | if (DBG_LOC) log("getNeighboringCellInfo: is active user"); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3803 | |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3804 | List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId); |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 3805 | if (info == null) return null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3806 | |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 3807 | List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>(); |
| 3808 | for (CellInfo ci : info) { |
| 3809 | if (ci instanceof CellInfoGsm) { |
| 3810 | neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci)); |
| 3811 | } else if (ci instanceof CellInfoWcdma) { |
| 3812 | neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci)); |
| 3813 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3814 | } |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 3815 | return (neighbors.size()) > 0 ? neighbors : null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3816 | } |
| 3817 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3818 | private List<CellInfo> getCachedCellInfo() { |
| 3819 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 3820 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3821 | List<CellInfo> info = phone.getAllCellInfo(); |
| 3822 | if (info != null) cellInfos.addAll(info); |
| 3823 | } |
| 3824 | return cellInfos; |
| 3825 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3826 | |
| 3827 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3828 | public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3829 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 3830 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3831 | |
| 3832 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 3833 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 3834 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 3835 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3836 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3837 | .setCallingPid(Binder.getCallingPid()) |
| 3838 | .setCallingUid(Binder.getCallingUid()) |
| 3839 | .setMethod("getAllCellInfo") |
Nathan Harold | 5ae50b5 | 2019-02-20 15:46:36 -0800 | [diff] [blame] | 3840 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3841 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 3842 | .build()); |
| 3843 | switch (locationResult) { |
| 3844 | case DENIED_HARD: |
| 3845 | throw new SecurityException("Not allowed to access cell info"); |
| 3846 | case DENIED_SOFT: |
| 3847 | return new ArrayList<>(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3848 | } |
| 3849 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3850 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3851 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 3852 | return getCachedCellInfo(); |
| 3853 | } |
| 3854 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 3855 | if (DBG_LOC) log("getAllCellInfo: is active user"); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 3856 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3857 | final long identity = Binder.clearCallingIdentity(); |
| 3858 | try { |
| 3859 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 3860 | for (Phone phone : PhoneFactory.getPhones()) { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 3861 | final List<CellInfo> info = (List<CellInfo>) sendRequest( |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 3862 | CMD_GET_ALL_CELL_INFO, null, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3863 | if (info != null) cellInfos.addAll(info); |
| 3864 | } |
| 3865 | return cellInfos; |
| 3866 | } finally { |
| 3867 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3868 | } |
| 3869 | } |
| 3870 | |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 3871 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3872 | public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage, |
| 3873 | String callingFeatureId) { |
| 3874 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, |
| 3875 | getWorkSource(Binder.getCallingUid())); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3876 | } |
| 3877 | |
| 3878 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3879 | public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb, |
| 3880 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3881 | enforceModifyPermission(); |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3882 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3883 | } |
| 3884 | |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3885 | private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb, |
| 3886 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3887 | mApp.getSystemService(AppOpsManager.class) |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3888 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3889 | |
| 3890 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 3891 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 3892 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 3893 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3894 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3895 | .setCallingPid(Binder.getCallingPid()) |
| 3896 | .setCallingUid(Binder.getCallingUid()) |
| 3897 | .setMethod("requestCellInfoUpdate") |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 3898 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
| 3899 | .setMinSdkVersionForFine(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3900 | .build()); |
| 3901 | switch (locationResult) { |
| 3902 | case DENIED_HARD: |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3903 | if (TelephonyPermissions |
| 3904 | .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) { |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 3905 | // Safetynet logging for b/154934934 |
| 3906 | EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid()); |
| 3907 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3908 | throw new SecurityException("Not allowed to access cell info"); |
| 3909 | case DENIED_SOFT: |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3910 | if (TelephonyPermissions |
| 3911 | .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) { |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 3912 | // Safetynet logging for b/154934934 |
| 3913 | EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid()); |
| 3914 | } |
Nathan Harold | 5320c42 | 2019-05-09 10:26:08 -0700 | [diff] [blame] | 3915 | try { |
| 3916 | cb.onCellInfo(new ArrayList<CellInfo>()); |
| 3917 | } catch (RemoteException re) { |
| 3918 | // Drop without consequences |
| 3919 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3920 | return; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3921 | } |
| 3922 | |
Nathan Harold | a939a96 | 2019-05-09 10:13:47 -0700 | [diff] [blame] | 3923 | |
| 3924 | final Phone phone = getPhoneFromSubId(subId); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3925 | if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
| 3926 | |
| 3927 | sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource); |
| 3928 | } |
| 3929 | |
| 3930 | @Override |
Aishwarya Mallampati | 0603fb1 | 2022-08-24 21:16:56 +0000 | [diff] [blame] | 3931 | public void setCellInfoListRate(int rateInMillis, int subId) { |
Jack Yu | a8d8cb8 | 2017-01-16 10:15:34 -0800 | [diff] [blame] | 3932 | enforceModifyPermission(); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 3933 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3934 | |
| 3935 | final long identity = Binder.clearCallingIdentity(); |
| 3936 | try { |
Aishwarya Mallampati | 0603fb1 | 2022-08-24 21:16:56 +0000 | [diff] [blame] | 3937 | Phone phone = getPhone(subId); |
| 3938 | if (phone == null) { |
| 3939 | getDefaultPhone().setCellInfoListRate(rateInMillis, workSource); |
| 3940 | } else { |
| 3941 | phone.setCellInfoListRate(rateInMillis, workSource); |
| 3942 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3943 | } finally { |
| 3944 | Binder.restoreCallingIdentity(identity); |
| 3945 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3946 | } |
| 3947 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3948 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3949 | public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3950 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3951 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3952 | return null; |
| 3953 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3954 | int subId = phone.getSubId(); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3955 | enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot"); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 3956 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3957 | callingPackage, callingFeatureId, "getImeiForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3958 | return null; |
| 3959 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3960 | |
| 3961 | final long identity = Binder.clearCallingIdentity(); |
| 3962 | try { |
| 3963 | return phone.getImei(); |
| 3964 | } finally { |
| 3965 | Binder.restoreCallingIdentity(identity); |
| 3966 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3967 | } |
| 3968 | |
| 3969 | @Override |
arunvoddu | d5c6ce0 | 2022-12-11 06:03:12 +0000 | [diff] [blame] | 3970 | public String getPrimaryImei(String callingPackage, String callingFeatureId) { |
| 3971 | enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getPrimaryImei"); |
| 3972 | if (!checkCallingOrSelfReadDeviceIdentifiersForAnySub(mApp, callingPackage, |
| 3973 | callingFeatureId, "getPrimaryImei")) { |
| 3974 | throw new SecurityException("Caller does not have permission"); |
| 3975 | } |
| 3976 | final long identity = Binder.clearCallingIdentity(); |
| 3977 | try { |
| 3978 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3979 | if (phone.getImeiType() == Phone.IMEI_TYPE_PRIMARY) { |
| 3980 | return phone.getImei(); |
| 3981 | } |
| 3982 | } |
| 3983 | throw new UnsupportedOperationException("Operation not supported"); |
| 3984 | } finally { |
| 3985 | Binder.restoreCallingIdentity(identity); |
| 3986 | } |
| 3987 | } |
| 3988 | |
| 3989 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3990 | public String getTypeAllocationCodeForSlot(int slotIndex) { |
| 3991 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3992 | String tac = null; |
| 3993 | if (phone != null) { |
| 3994 | String imei = phone.getImei(); |
Vala Zadeh | ab00555 | 2021-09-21 15:54:29 -0700 | [diff] [blame] | 3995 | try { |
| 3996 | tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH); |
| 3997 | } catch (IndexOutOfBoundsException e) { |
| 3998 | Log.e(LOG_TAG, "IMEI length shorter than upper index."); |
| 3999 | return null; |
| 4000 | } |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 4001 | } |
| 4002 | return tac; |
| 4003 | } |
| 4004 | |
| 4005 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4006 | public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Shuo Qian | 13d8915 | 2021-05-10 23:58:11 -0700 | [diff] [blame] | 4007 | try { |
| 4008 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 4009 | } catch (SecurityException se) { |
| 4010 | EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid()); |
| 4011 | throw new SecurityException("Package " + callingPackage + " does not belong to " |
| 4012 | + Binder.getCallingUid()); |
| 4013 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 4014 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 4015 | if (phone == null) { |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 4016 | return null; |
| 4017 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4018 | |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 4019 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 4020 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4021 | callingPackage, callingFeatureId, "getMeidForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 4022 | return null; |
| 4023 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4024 | |
| 4025 | final long identity = Binder.clearCallingIdentity(); |
| 4026 | try { |
| 4027 | return phone.getMeid(); |
| 4028 | } finally { |
| 4029 | Binder.restoreCallingIdentity(identity); |
| 4030 | } |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 4031 | } |
| 4032 | |
| 4033 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 4034 | public String getManufacturerCodeForSlot(int slotIndex) { |
| 4035 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 4036 | String manufacturerCode = null; |
| 4037 | if (phone != null) { |
| 4038 | String meid = phone.getMeid(); |
Vala Zadeh | ab00555 | 2021-09-21 15:54:29 -0700 | [diff] [blame] | 4039 | try { |
| 4040 | manufacturerCode = |
| 4041 | meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH); |
| 4042 | } catch (IndexOutOfBoundsException e) { |
| 4043 | Log.e(LOG_TAG, "MEID length shorter than upper index."); |
| 4044 | return null; |
| 4045 | } |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 4046 | } |
| 4047 | return manufacturerCode; |
| 4048 | } |
| 4049 | |
| 4050 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4051 | public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage, |
| 4052 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 4053 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 4054 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4055 | return null; |
| 4056 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 4057 | int subId = phone.getSubId(); |
| 4058 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4059 | mApp, subId, callingPackage, callingFeatureId, |
| 4060 | "getDeviceSoftwareVersionForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 4061 | return null; |
| 4062 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4063 | |
| 4064 | final long identity = Binder.clearCallingIdentity(); |
| 4065 | try { |
| 4066 | return phone.getDeviceSvn(); |
| 4067 | } finally { |
| 4068 | Binder.restoreCallingIdentity(identity); |
| 4069 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 4070 | } |
| 4071 | |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 4072 | @Override |
| 4073 | public int getSubscriptionCarrierId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4074 | final long identity = Binder.clearCallingIdentity(); |
| 4075 | try { |
| 4076 | final Phone phone = getPhone(subId); |
| 4077 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId(); |
| 4078 | } finally { |
| 4079 | Binder.restoreCallingIdentity(identity); |
| 4080 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 4081 | } |
| 4082 | |
| 4083 | @Override |
| 4084 | public String getSubscriptionCarrierName(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4085 | final long identity = Binder.clearCallingIdentity(); |
| 4086 | try { |
| 4087 | final Phone phone = getPhone(subId); |
| 4088 | return phone == null ? null : phone.getCarrierName(); |
| 4089 | } finally { |
| 4090 | Binder.restoreCallingIdentity(identity); |
| 4091 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 4092 | } |
| 4093 | |
calvinpan | ffe225e | 2018-11-01 19:43:06 +0800 | [diff] [blame] | 4094 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 4095 | public int getSubscriptionSpecificCarrierId(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 4096 | final long identity = Binder.clearCallingIdentity(); |
| 4097 | try { |
| 4098 | final Phone phone = getPhone(subId); |
| 4099 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 4100 | : phone.getSpecificCarrierId(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 4101 | } finally { |
| 4102 | Binder.restoreCallingIdentity(identity); |
| 4103 | } |
| 4104 | } |
| 4105 | |
| 4106 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 4107 | public String getSubscriptionSpecificCarrierName(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 4108 | final long identity = Binder.clearCallingIdentity(); |
| 4109 | try { |
| 4110 | final Phone phone = getPhone(subId); |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 4111 | return phone == null ? null : phone.getSpecificCarrierName(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 4112 | } finally { |
| 4113 | Binder.restoreCallingIdentity(identity); |
| 4114 | } |
| 4115 | } |
| 4116 | |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 4117 | @Override |
chen xu | 864e11c | 2018-12-06 22:10:03 -0800 | [diff] [blame] | 4118 | public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) { |
| 4119 | if (!isSubscriptionMccMnc) { |
| 4120 | enforceReadPrivilegedPermission("getCarrierIdFromMccMnc"); |
| 4121 | } |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 4122 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 4123 | if (phone == null) { |
| 4124 | return TelephonyManager.UNKNOWN_CARRIER_ID; |
| 4125 | } |
| 4126 | final long identity = Binder.clearCallingIdentity(); |
| 4127 | try { |
| 4128 | return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc); |
| 4129 | } finally { |
| 4130 | Binder.restoreCallingIdentity(identity); |
| 4131 | } |
| 4132 | } |
| 4133 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4134 | // |
| 4135 | // Internal helper methods. |
| 4136 | // |
| 4137 | |
Sanket Padawe | ee13a9b | 2016-03-08 17:30:28 -0800 | [diff] [blame] | 4138 | /** |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 4139 | * Make sure the caller is the calling package itself |
| 4140 | * |
| 4141 | * @throws SecurityException if the caller is not the calling package |
| 4142 | */ |
| 4143 | private void enforceCallingPackage(String callingPackage, int callingUid, String message) { |
| 4144 | int packageUid = -1; |
Grace Jia | dbefca0 | 2021-04-26 15:13:31 -0700 | [diff] [blame] | 4145 | PackageManager pm = mApp.getBaseContext().createContextAsUser( |
| 4146 | UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager(); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 4147 | try { |
Grace Jia | dbefca0 | 2021-04-26 15:13:31 -0700 | [diff] [blame] | 4148 | packageUid = pm.getPackageUid(callingPackage, 0); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 4149 | } catch (PackageManager.NameNotFoundException e) { |
| 4150 | // packageUid is -1 |
| 4151 | } |
| 4152 | if (packageUid != callingUid) { |
| 4153 | throw new SecurityException(message + ": Package " + callingPackage |
| 4154 | + " does not belong to " + callingUid); |
| 4155 | } |
| 4156 | } |
| 4157 | |
| 4158 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4159 | * Make sure the caller has the MODIFY_PHONE_STATE permission. |
| 4160 | * |
| 4161 | * @throws SecurityException if the caller does not have the required permission |
| 4162 | */ |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 4163 | @VisibleForTesting |
| 4164 | public void enforceModifyPermission() { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4165 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null); |
| 4166 | } |
| 4167 | |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 4168 | /** |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 4169 | * Make sure the caller has the READ_PHONE_STATE permission. |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 4170 | * |
| 4171 | * @throws SecurityException if the caller does not have the required permission |
| 4172 | */ |
| 4173 | @VisibleForTesting |
| 4174 | public void enforceReadPermission() { |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 4175 | enforceReadPermission(null); |
| 4176 | } |
| 4177 | |
| 4178 | /** |
| 4179 | * Make sure the caller has the READ_PHONE_STATE permissions. |
| 4180 | * |
| 4181 | * @throws SecurityException if the caller does not have the READ_PHONE_STATE permission. |
| 4182 | */ |
| 4183 | @VisibleForTesting |
| 4184 | public void enforceReadPermission(String msg) { |
| 4185 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, msg); |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 4186 | } |
| 4187 | |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 4188 | private void enforceActiveEmergencySessionPermission() { |
| 4189 | mApp.enforceCallingOrSelfPermission( |
| 4190 | android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null); |
| 4191 | } |
| 4192 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4193 | /** |
| 4194 | * Make sure the caller has the CALL_PHONE permission. |
| 4195 | * |
| 4196 | * @throws SecurityException if the caller does not have the required permission |
| 4197 | */ |
| 4198 | private void enforceCallPermission() { |
| 4199 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null); |
| 4200 | } |
| 4201 | |
paulhu | 5a77360 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 4202 | private void enforceSettingsPermission() { |
| 4203 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 4204 | } |
| 4205 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 4206 | private void enforceRebootPermission() { |
| 4207 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null); |
| 4208 | } |
| 4209 | |
Aishwarya Mallampati | 60fe113 | 2023-01-24 19:07:21 +0000 | [diff] [blame] | 4210 | /** |
| 4211 | * Make sure the caller has SATELLITE_COMMUNICATION permission. |
| 4212 | * @param message - log message to print. |
| 4213 | * @throws SecurityException if the caller does not have the required permission |
| 4214 | */ |
| 4215 | private void enforceSatelliteCommunicationPermission(String message) { |
| 4216 | mApp.enforceCallingOrSelfPermission(permission.SATELLITE_COMMUNICATION, message); |
| 4217 | } |
| 4218 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4219 | private String createTelUrl(String number) { |
| 4220 | if (TextUtils.isEmpty(number)) { |
| 4221 | return null; |
| 4222 | } |
| 4223 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4224 | return "tel:" + number; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4225 | } |
| 4226 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 4227 | private static void log(String msg) { |
Ling Ma | 83dc5ea | 2023-01-12 15:06:04 -0800 | [diff] [blame] | 4228 | Log.d(LOG_TAG, msg); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4229 | } |
| 4230 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 4231 | private static void logv(String msg) { |
| 4232 | Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 4233 | } |
| 4234 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 4235 | private static void loge(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4236 | Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 4237 | } |
| 4238 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4239 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4240 | public int getActivePhoneType() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 4241 | return getActivePhoneTypeForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4242 | } |
| 4243 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4244 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 4245 | public int getActivePhoneTypeForSlot(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4246 | final long identity = Binder.clearCallingIdentity(); |
| 4247 | try { |
| 4248 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 4249 | if (phone == null) { |
| 4250 | return PhoneConstants.PHONE_TYPE_NONE; |
| 4251 | } else { |
| 4252 | return phone.getPhoneType(); |
| 4253 | } |
| 4254 | } finally { |
| 4255 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4256 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4257 | } |
| 4258 | |
| 4259 | /** |
| 4260 | * Returns the CDMA ERI icon index to display |
| 4261 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4262 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4263 | public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) { |
| 4264 | return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage, |
| 4265 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4266 | } |
| 4267 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4268 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4269 | public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage, |
| 4270 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4271 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4272 | mApp, subId, callingPackage, callingFeatureId, |
| 4273 | "getCdmaEriIconIndexForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4274 | return -1; |
| 4275 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4276 | |
| 4277 | final long identity = Binder.clearCallingIdentity(); |
| 4278 | try { |
| 4279 | final Phone phone = getPhone(subId); |
| 4280 | if (phone != null) { |
| 4281 | return phone.getCdmaEriIconIndex(); |
| 4282 | } else { |
| 4283 | return -1; |
| 4284 | } |
| 4285 | } finally { |
| 4286 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4287 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4288 | } |
| 4289 | |
| 4290 | /** |
| 4291 | * Returns the CDMA ERI icon mode, |
| 4292 | * 0 - ON |
| 4293 | * 1 - FLASHING |
| 4294 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4295 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4296 | public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) { |
| 4297 | return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 4298 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4299 | } |
| 4300 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4301 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4302 | public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage, |
| 4303 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4304 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4305 | mApp, subId, callingPackage, callingFeatureId, |
| 4306 | "getCdmaEriIconModeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4307 | return -1; |
| 4308 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4309 | |
| 4310 | final long identity = Binder.clearCallingIdentity(); |
| 4311 | try { |
| 4312 | final Phone phone = getPhone(subId); |
| 4313 | if (phone != null) { |
| 4314 | return phone.getCdmaEriIconMode(); |
| 4315 | } else { |
| 4316 | return -1; |
| 4317 | } |
| 4318 | } finally { |
| 4319 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4320 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4321 | } |
| 4322 | |
| 4323 | /** |
| 4324 | * Returns the CDMA ERI text, |
| 4325 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4326 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4327 | public String getCdmaEriText(String callingPackage, String callingFeatureId) { |
| 4328 | return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage, |
| 4329 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4330 | } |
| 4331 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4332 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4333 | public String getCdmaEriTextForSubscriber(int subId, String callingPackage, |
| 4334 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4335 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4336 | mApp, subId, callingPackage, callingFeatureId, |
| 4337 | "getCdmaEriIconTextForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4338 | return null; |
| 4339 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4340 | |
| 4341 | final long identity = Binder.clearCallingIdentity(); |
| 4342 | try { |
| 4343 | final Phone phone = getPhone(subId); |
| 4344 | if (phone != null) { |
| 4345 | return phone.getCdmaEriText(); |
| 4346 | } else { |
| 4347 | return null; |
| 4348 | } |
| 4349 | } finally { |
| 4350 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4351 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4352 | } |
| 4353 | |
| 4354 | /** |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 4355 | * Returns the CDMA MDN. |
| 4356 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4357 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 4358 | public String getCdmaMdn(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4359 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4360 | mApp, subId, "getCdmaMdn"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4361 | |
| 4362 | final long identity = Binder.clearCallingIdentity(); |
| 4363 | try { |
| 4364 | final Phone phone = getPhone(subId); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4365 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4366 | return phone.getLine1Number(); |
| 4367 | } else { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4368 | loge("getCdmaMdn: no phone found. Invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4369 | return null; |
| 4370 | } |
| 4371 | } finally { |
| 4372 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 4373 | } |
| 4374 | } |
| 4375 | |
| 4376 | /** |
| 4377 | * Returns the CDMA MIN. |
| 4378 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4379 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 4380 | public String getCdmaMin(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4381 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4382 | mApp, subId, "getCdmaMin"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4383 | |
| 4384 | final long identity = Binder.clearCallingIdentity(); |
| 4385 | try { |
| 4386 | final Phone phone = getPhone(subId); |
| 4387 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
| 4388 | return phone.getCdmaMin(); |
| 4389 | } else { |
| 4390 | return null; |
| 4391 | } |
| 4392 | } finally { |
| 4393 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 4394 | } |
| 4395 | } |
| 4396 | |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 4397 | @Override |
| 4398 | public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis, |
| 4399 | INumberVerificationCallback callback, String callingPackage) { |
| 4400 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 4401 | != PERMISSION_GRANTED) { |
| 4402 | throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission"); |
| 4403 | } |
| 4404 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 4405 | |
| 4406 | String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp); |
| 4407 | if (!TextUtils.equals(callingPackage, authorizedPackage)) { |
Hall Liu | b9d8feb | 2021-01-13 10:28:04 -0800 | [diff] [blame] | 4408 | throw new SecurityException("Calling package must be configured in the device config: " |
| 4409 | + "calling package: " + callingPackage |
| 4410 | + ", configured package: " + authorizedPackage); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 4411 | } |
| 4412 | |
| 4413 | if (range == null) { |
| 4414 | throw new NullPointerException("Range must be non-null"); |
| 4415 | } |
| 4416 | |
| 4417 | timeoutMillis = Math.min(timeoutMillis, |
Hall Liu | bd069e3 | 2019-02-28 18:56:30 -0800 | [diff] [blame] | 4418 | TelephonyManager.getMaxNumberVerificationTimeoutMillis()); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 4419 | |
| 4420 | NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis); |
| 4421 | } |
| 4422 | |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 4423 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4424 | * Returns true if CDMA provisioning needs to run. |
| 4425 | */ |
| 4426 | public boolean needsOtaServiceProvisioning() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4427 | final long identity = Binder.clearCallingIdentity(); |
| 4428 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4429 | return getDefaultPhone().needsOtaServiceProvisioning(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4430 | } finally { |
| 4431 | Binder.restoreCallingIdentity(identity); |
| 4432 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4433 | } |
| 4434 | |
| 4435 | /** |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 4436 | * Sets the voice mail number of a given subId. |
| 4437 | */ |
| 4438 | @Override |
| 4439 | public boolean setVoiceMailNumber(int subId, String alphaTag, String number) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 4440 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 4441 | mApp, subId, "setVoiceMailNumber"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4442 | |
| 4443 | final long identity = Binder.clearCallingIdentity(); |
| 4444 | try { |
| 4445 | Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER, |
| 4446 | new Pair<String, String>(alphaTag, number), new Integer(subId)); |
| 4447 | return success; |
| 4448 | } finally { |
| 4449 | Binder.restoreCallingIdentity(identity); |
| 4450 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 4451 | } |
| 4452 | |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 4453 | @Override |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 4454 | public Bundle getVisualVoicemailSettings(String callingPackage, int subId) { |
| 4455 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 4456 | TelecomManager tm = mApp.getSystemService(TelecomManager.class); |
| 4457 | String systemDialer = tm.getSystemDialerPackage(); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 4458 | if (!TextUtils.equals(callingPackage, systemDialer)) { |
| 4459 | throw new SecurityException("caller must be system dialer"); |
| 4460 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4461 | |
| 4462 | final long identity = Binder.clearCallingIdentity(); |
| 4463 | try { |
| 4464 | PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId); |
| 4465 | if (phoneAccountHandle == null) { |
| 4466 | return null; |
| 4467 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4468 | return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4469 | } finally { |
| 4470 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 4471 | } |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 4472 | } |
| 4473 | |
| 4474 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4475 | public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId, |
| 4476 | int subId) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 4477 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4478 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4479 | mApp, subId, callingPackage, callingFeatureId, |
| 4480 | "getVisualVoicemailPackageName")) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 4481 | return null; |
| 4482 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4483 | |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 4484 | final long identity = Binder.clearCallingIdentity(); |
| 4485 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4486 | return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName(); |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 4487 | } finally { |
| 4488 | Binder.restoreCallingIdentity(identity); |
| 4489 | } |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 4490 | } |
| 4491 | |
| 4492 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 4493 | public void enableVisualVoicemailSmsFilter(String callingPackage, int subId, |
| 4494 | VisualVoicemailSmsFilterSettings settings) { |
| 4495 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4496 | |
| 4497 | final long identity = Binder.clearCallingIdentity(); |
| 4498 | try { |
| 4499 | VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4500 | mApp, callingPackage, subId, settings); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4501 | } finally { |
| 4502 | Binder.restoreCallingIdentity(identity); |
| 4503 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 4504 | } |
| 4505 | |
| 4506 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 4507 | public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) { |
| 4508 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4509 | |
| 4510 | final long identity = Binder.clearCallingIdentity(); |
| 4511 | try { |
| 4512 | VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4513 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4514 | } finally { |
| 4515 | Binder.restoreCallingIdentity(identity); |
| 4516 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 4517 | } |
| 4518 | |
| 4519 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 4520 | public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings( |
| 4521 | String callingPackage, int subId) { |
| 4522 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4523 | |
| 4524 | final long identity = Binder.clearCallingIdentity(); |
| 4525 | try { |
| 4526 | return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4527 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4528 | } finally { |
| 4529 | Binder.restoreCallingIdentity(identity); |
| 4530 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 4531 | } |
| 4532 | |
| 4533 | @Override |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 4534 | public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4535 | enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4536 | |
| 4537 | final long identity = Binder.clearCallingIdentity(); |
| 4538 | try { |
| 4539 | return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4540 | mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4541 | } finally { |
| 4542 | Binder.restoreCallingIdentity(identity); |
| 4543 | } |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 4544 | } |
| 4545 | |
| 4546 | @Override |
Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 4547 | public void sendVisualVoicemailSmsForSubscriber(String callingPackage, |
| 4548 | String callingAttributionTag, int subId, String number, int port, String text, |
| 4549 | PendingIntent sentIntent) { |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 4550 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 4551 | enforceVisualVoicemailPackage(callingPackage, subId); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 4552 | enforceSendSmsPermission(); |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 4553 | SmsController smsController = PhoneFactory.getSmsController(); |
Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 4554 | smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag, |
| 4555 | subId, number, port, text, sentIntent); |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 4556 | } |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 4557 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 4558 | /** |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4559 | * Sets the voice activation state of a given subId. |
| 4560 | */ |
| 4561 | @Override |
| 4562 | public void setVoiceActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4563 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4564 | mApp, subId, "setVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4565 | |
| 4566 | final long identity = Binder.clearCallingIdentity(); |
| 4567 | try { |
| 4568 | final Phone phone = getPhone(subId); |
| 4569 | if (phone != null) { |
| 4570 | phone.setVoiceActivationState(activationState); |
| 4571 | } else { |
| 4572 | loge("setVoiceActivationState fails with invalid subId: " + subId); |
| 4573 | } |
| 4574 | } finally { |
| 4575 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4576 | } |
| 4577 | } |
| 4578 | |
| 4579 | /** |
| 4580 | * Sets the data activation state of a given subId. |
| 4581 | */ |
| 4582 | @Override |
| 4583 | public void setDataActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4584 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4585 | mApp, subId, "setDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4586 | |
| 4587 | final long identity = Binder.clearCallingIdentity(); |
| 4588 | try { |
| 4589 | final Phone phone = getPhone(subId); |
| 4590 | if (phone != null) { |
| 4591 | phone.setDataActivationState(activationState); |
| 4592 | } else { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 4593 | loge("setDataActivationState fails with invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4594 | } |
| 4595 | } finally { |
| 4596 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4597 | } |
| 4598 | } |
| 4599 | |
| 4600 | /** |
| 4601 | * Returns the voice activation state of a given subId. |
| 4602 | */ |
| 4603 | @Override |
| 4604 | public int getVoiceActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4605 | enforceReadPrivilegedPermission("getVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4606 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4607 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4608 | final long identity = Binder.clearCallingIdentity(); |
| 4609 | try { |
| 4610 | if (phone != null) { |
| 4611 | return phone.getVoiceActivationState(); |
| 4612 | } else { |
| 4613 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 4614 | } |
| 4615 | } finally { |
| 4616 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4617 | } |
| 4618 | } |
| 4619 | |
| 4620 | /** |
| 4621 | * Returns the data activation state of a given subId. |
| 4622 | */ |
| 4623 | @Override |
| 4624 | public int getDataActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4625 | enforceReadPrivilegedPermission("getDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4626 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4627 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4628 | final long identity = Binder.clearCallingIdentity(); |
| 4629 | try { |
| 4630 | if (phone != null) { |
| 4631 | return phone.getDataActivationState(); |
| 4632 | } else { |
| 4633 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 4634 | } |
| 4635 | } finally { |
| 4636 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4637 | } |
| 4638 | } |
| 4639 | |
| 4640 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4641 | * Returns the unread count of voicemails for a subId |
| 4642 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4643 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4644 | public int getVoiceMessageCountForSubscriber(int subId, String callingPackage, |
| 4645 | String callingFeatureId) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 4646 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4647 | mApp, subId, callingPackage, callingFeatureId, |
| 4648 | "getVoiceMessageCountForSubscriber")) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 4649 | return 0; |
| 4650 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4651 | final long identity = Binder.clearCallingIdentity(); |
| 4652 | try { |
| 4653 | final Phone phone = getPhone(subId); |
| 4654 | if (phone != null) { |
| 4655 | return phone.getVoiceMessageCount(); |
| 4656 | } else { |
| 4657 | return 0; |
| 4658 | } |
| 4659 | } finally { |
| 4660 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4661 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4662 | } |
| 4663 | |
| 4664 | /** |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 4665 | * returns true, if the device is in a state where both voice and data |
| 4666 | * are supported simultaneously. This can change based on location or network condition. |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 4667 | */ |
| 4668 | @Override |
| 4669 | public boolean isConcurrentVoiceAndDataAllowed(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4670 | final long identity = Binder.clearCallingIdentity(); |
| 4671 | try { |
| 4672 | final Phone phone = getPhone(subId); |
| 4673 | return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed()); |
| 4674 | } finally { |
| 4675 | Binder.restoreCallingIdentity(identity); |
| 4676 | } |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 4677 | } |
| 4678 | |
| 4679 | /** |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4680 | * Send the dialer code if called from the current default dialer or the caller has |
| 4681 | * carrier privilege. |
| 4682 | * @param inputCode The dialer code to send |
| 4683 | */ |
| 4684 | @Override |
| 4685 | public void sendDialerSpecialCode(String callingPackage, String inputCode) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4686 | final Phone defaultPhone = getDefaultPhone(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4687 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 4688 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 4689 | String defaultDialer = tm.getDefaultDialerPackage(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4690 | if (!TextUtils.equals(callingPackage, defaultDialer)) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 4691 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4692 | getDefaultSubscription(), "sendDialerSpecialCode"); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4693 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4694 | |
| 4695 | final long identity = Binder.clearCallingIdentity(); |
| 4696 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4697 | defaultPhone.sendDialerSpecialCode(inputCode); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4698 | } finally { |
| 4699 | Binder.restoreCallingIdentity(identity); |
| 4700 | } |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4701 | } |
| 4702 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 4703 | @Override |
| 4704 | public int getNetworkSelectionMode(int subId) { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 4705 | TelephonyPermissions |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 4706 | .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4707 | mApp, subId, "getNetworkSelectionMode"); |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 4708 | final long identity = Binder.clearCallingIdentity(); |
| 4709 | try { |
| 4710 | if (!isActiveSubscription(subId)) { |
| 4711 | return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 4712 | } |
| 4713 | return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId); |
| 4714 | } finally { |
| 4715 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 4716 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 4717 | } |
| 4718 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4719 | @Override |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 4720 | public boolean isInEmergencySmsMode() { |
| 4721 | enforceReadPrivilegedPermission("isInEmergencySmsMode"); |
| 4722 | final long identity = Binder.clearCallingIdentity(); |
| 4723 | try { |
| 4724 | for (Phone phone : PhoneFactory.getPhones()) { |
| 4725 | if (phone.isInEmergencySmsMode()) { |
| 4726 | return true; |
| 4727 | } |
| 4728 | } |
| 4729 | } finally { |
| 4730 | Binder.restoreCallingIdentity(identity); |
| 4731 | } |
| 4732 | return false; |
| 4733 | } |
| 4734 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4735 | /** |
| 4736 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4737 | * @param subId The subscription to use to check the configuration. |
| 4738 | * @param c The callback that will be used to send the result. |
| 4739 | */ |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 4740 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4741 | public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c) |
| 4742 | throws RemoteException { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4743 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4744 | mApp, subId, "registerImsRegistrationCallback"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4745 | |
| 4746 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4747 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4748 | "IMS not available on device."); |
| 4749 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4750 | final long token = Binder.clearCallingIdentity(); |
| 4751 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4752 | int slotId = getSlotIndexOrException(subId); |
| 4753 | verifyImsMmTelConfiguredOrThrow(slotId); |
joonhunshin | 49f0aed | 2022-08-05 08:33:05 +0000 | [diff] [blame] | 4754 | |
| 4755 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4756 | if (controller != null) { |
| 4757 | ImsManager imsManager = controller.getImsManager(subId); |
| 4758 | if (imsManager != null) { |
| 4759 | imsManager.addRegistrationCallbackForSubscription(c, subId); |
| 4760 | } else { |
| 4761 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE); |
| 4762 | } |
| 4763 | } else { |
| 4764 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION); |
| 4765 | } |
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(token); |
| 4770 | } |
| 4771 | } |
| 4772 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4773 | /** |
| 4774 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4775 | * @param subId The subscription to use to check the configuration. |
| 4776 | * @param c The callback that will be used to send the result. |
| 4777 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4778 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4779 | public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4780 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4781 | mApp, subId, "unregisterImsRegistrationCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4782 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4783 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4784 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4785 | final long token = Binder.clearCallingIdentity(); |
joonhunshin | 49f0aed | 2022-08-05 08:33:05 +0000 | [diff] [blame] | 4786 | |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4787 | try { |
joonhunshin | 49f0aed | 2022-08-05 08:33:05 +0000 | [diff] [blame] | 4788 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4789 | if (controller != null) { |
| 4790 | ImsManager imsManager = controller.getImsManager(subId); |
| 4791 | if (imsManager != null) { |
| 4792 | imsManager.removeRegistrationCallbackForSubscription(c, subId); |
| 4793 | } else { |
| 4794 | Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId |
| 4795 | + "is inactive, ignoring unregister."); |
| 4796 | // If the ImsManager is not valid, just return, since the callback |
| 4797 | // will already have been removed internally. |
| 4798 | } |
| 4799 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4800 | } finally { |
| 4801 | Binder.restoreCallingIdentity(token); |
| 4802 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4803 | } |
| 4804 | |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 4805 | /** |
| 4806 | * Get the IMS service registration state for the MmTelFeature associated with this sub id. |
| 4807 | */ |
| 4808 | @Override |
| 4809 | public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) { |
| 4810 | enforceReadPrivilegedPermission("getImsMmTelRegistrationState"); |
| 4811 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4812 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4813 | "IMS not available on device."); |
| 4814 | } |
| 4815 | final long token = Binder.clearCallingIdentity(); |
| 4816 | try { |
| 4817 | Phone phone = getPhone(subId); |
| 4818 | if (phone == null) { |
| 4819 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 4820 | + subId + "'"); |
| 4821 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 4822 | } |
| 4823 | phone.getImsRegistrationState(regState -> { |
| 4824 | try { |
| 4825 | consumer.accept((regState == null) |
| 4826 | ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState); |
| 4827 | } catch (RemoteException e) { |
| 4828 | // Ignore if the remote process is no longer available to call back. |
| 4829 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 4830 | } |
| 4831 | }); |
| 4832 | } finally { |
| 4833 | Binder.restoreCallingIdentity(token); |
| 4834 | } |
| 4835 | } |
| 4836 | |
| 4837 | /** |
| 4838 | * Get the transport type for the IMS service registration state. |
| 4839 | */ |
| 4840 | @Override |
| 4841 | public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4842 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4843 | mApp, subId, "getImsMmTelRegistrationTransportType"); |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 4844 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4845 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4846 | "IMS not available on device."); |
| 4847 | } |
| 4848 | final long token = Binder.clearCallingIdentity(); |
| 4849 | try { |
| 4850 | Phone phone = getPhone(subId); |
| 4851 | if (phone == null) { |
| 4852 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 4853 | + subId + "'"); |
| 4854 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 4855 | } |
| 4856 | phone.getImsRegistrationTech(regTech -> { |
| 4857 | // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager |
| 4858 | int regTechConverted = (regTech == null) |
| 4859 | ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech; |
| 4860 | regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get( |
| 4861 | regTechConverted); |
| 4862 | try { |
| 4863 | consumer.accept(regTechConverted); |
| 4864 | } catch (RemoteException e) { |
| 4865 | // Ignore if the remote process is no longer available to call back. |
| 4866 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 4867 | } |
| 4868 | }); |
| 4869 | } finally { |
| 4870 | Binder.restoreCallingIdentity(token); |
| 4871 | } |
| 4872 | } |
| 4873 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4874 | /** |
| 4875 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4876 | * @param subId The subscription to use to check the configuration. |
| 4877 | * @param c The callback that will be used to send the result. |
| 4878 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4879 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4880 | public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) |
| 4881 | throws RemoteException { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4882 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4883 | mApp, subId, "registerMmTelCapabilityCallback"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4884 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4885 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4886 | "IMS not available on device."); |
| 4887 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4888 | final long token = Binder.clearCallingIdentity(); |
| 4889 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4890 | int slotId = getSlotIndexOrException(subId); |
| 4891 | verifyImsMmTelConfiguredOrThrow(slotId); |
Hwangoo Park | 8646b0d | 2023-01-13 02:42:34 +0000 | [diff] [blame] | 4892 | |
| 4893 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4894 | if (controller != null) { |
| 4895 | ImsManager imsManager = controller.getImsManager(subId); |
| 4896 | if (imsManager != null) { |
| 4897 | imsManager.addCapabilitiesCallbackForSubscription(c, subId); |
| 4898 | } else { |
| 4899 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE); |
| 4900 | } |
| 4901 | } else { |
| 4902 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION); |
| 4903 | } |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4904 | } catch (ImsException e) { |
| 4905 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4906 | } finally { |
| 4907 | Binder.restoreCallingIdentity(token); |
| 4908 | } |
| 4909 | } |
| 4910 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4911 | /** |
| 4912 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4913 | * @param subId The subscription to use to check the configuration. |
| 4914 | * @param c The callback that will be used to send the result. |
| 4915 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4916 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4917 | public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4918 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4919 | mApp, subId, "unregisterMmTelCapabilityCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4920 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4921 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4922 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4923 | |
| 4924 | final long token = Binder.clearCallingIdentity(); |
| 4925 | try { |
Hwangoo Park | 8646b0d | 2023-01-13 02:42:34 +0000 | [diff] [blame] | 4926 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4927 | if (controller != null) { |
| 4928 | ImsManager imsManager = controller.getImsManager(subId); |
| 4929 | if (imsManager != null) { |
| 4930 | imsManager.removeCapabilitiesCallbackForSubscription(c, subId); |
| 4931 | } else { |
| 4932 | Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId |
| 4933 | + " is inactive, ignoring unregister."); |
| 4934 | // If the ImsManager is not valid, just return, since the callback |
| 4935 | // will already have been removed internally. |
| 4936 | } |
| 4937 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4938 | } finally { |
| 4939 | Binder.restoreCallingIdentity(token); |
| 4940 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4941 | } |
| 4942 | |
| 4943 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4944 | public boolean isCapable(int subId, int capability, int regTech) { |
| 4945 | enforceReadPrivilegedPermission("isCapable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4946 | final long token = Binder.clearCallingIdentity(); |
| 4947 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4948 | int slotId = getSlotIndexOrException(subId); |
| 4949 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 4950 | return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech); |
| 4951 | } catch (com.android.ims.ImsException e) { |
| 4952 | Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage()); |
| 4953 | return false; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4954 | } catch (ImsException e) { |
Brad Ebinger | 6b5ac22 | 2019-02-04 14:36:52 -0800 | [diff] [blame] | 4955 | Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false."); |
| 4956 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4957 | } finally { |
| 4958 | Binder.restoreCallingIdentity(token); |
| 4959 | } |
| 4960 | } |
| 4961 | |
| 4962 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4963 | public boolean isAvailable(int subId, int capability, int regTech) { |
| 4964 | enforceReadPrivilegedPermission("isAvailable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4965 | final long token = Binder.clearCallingIdentity(); |
| 4966 | try { |
| 4967 | Phone phone = getPhone(subId); |
| 4968 | if (phone == null) return false; |
| 4969 | return phone.isImsCapabilityAvailable(capability, regTech); |
Daniel Bright | 5e40e4e | 2020-03-11 16:35:39 -0700 | [diff] [blame] | 4970 | } catch (com.android.ims.ImsException e) { |
| 4971 | Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage()); |
| 4972 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4973 | } finally { |
| 4974 | Binder.restoreCallingIdentity(token); |
| 4975 | } |
| 4976 | } |
| 4977 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4978 | /** |
| 4979 | * Determines if the MmTel feature capability is supported by the carrier configuration for this |
| 4980 | * subscription. |
| 4981 | * @param subId The subscription to use to check the configuration. |
| 4982 | * @param callback The callback that will be used to send the result. |
| 4983 | * @param capability The MmTelFeature capability that will be used to send the result. |
| 4984 | * @param transportType The transport type of the MmTelFeature capability. |
| 4985 | */ |
| 4986 | @Override |
| 4987 | public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability, |
| 4988 | int transportType) { |
| 4989 | enforceReadPrivilegedPermission("isMmTelCapabilitySupported"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4990 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4991 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4992 | "IMS not available on device."); |
| 4993 | } |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4994 | final long token = Binder.clearCallingIdentity(); |
| 4995 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4996 | int slotId = getSlotIndex(subId); |
| 4997 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4998 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '" |
| 4999 | + subId + "'"); |
| 5000 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 5001 | } |
| 5002 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 5003 | ImsManager.getInstance(mApp, slotId).isSupported(capability, |
| 5004 | transportType, aBoolean -> { |
| 5005 | try { |
| 5006 | callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0)); |
| 5007 | } catch (RemoteException e) { |
| 5008 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not " |
| 5009 | + "running. Ignore"); |
| 5010 | } |
| 5011 | }); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5012 | } catch (ImsException e) { |
| 5013 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 5014 | } finally { |
| 5015 | Binder.restoreCallingIdentity(token); |
| 5016 | } |
| 5017 | } |
| 5018 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 5019 | /** |
| 5020 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 5021 | * @param subId The subscription to use to check the configuration. |
| 5022 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5023 | @Override |
| 5024 | public boolean isAdvancedCallingSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 5025 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 5026 | mApp, subId, "isAdvancedCallingSettingEnabled"); |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 5027 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5028 | final long token = Binder.clearCallingIdentity(); |
| 5029 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5030 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5031 | // 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] | 5032 | return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5033 | } catch (ImsException e) { |
| 5034 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5035 | } finally { |
| 5036 | Binder.restoreCallingIdentity(token); |
| 5037 | } |
| 5038 | } |
| 5039 | |
| 5040 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 5041 | public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5042 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 5043 | "setAdvancedCallingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5044 | final long identity = Binder.clearCallingIdentity(); |
| 5045 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5046 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5047 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 5048 | // 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] | 5049 | ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5050 | } catch (ImsException e) { |
| 5051 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5052 | } finally { |
| 5053 | Binder.restoreCallingIdentity(identity); |
| 5054 | } |
| 5055 | } |
| 5056 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 5057 | /** |
| 5058 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 5059 | * @param subId The subscription to use to check the configuration. |
| 5060 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5061 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 5062 | public boolean isVtSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 5063 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 5064 | mApp, subId, "isVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5065 | final long identity = Binder.clearCallingIdentity(); |
| 5066 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5067 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5068 | // 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] | 5069 | return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5070 | } catch (ImsException e) { |
| 5071 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5072 | } finally { |
| 5073 | Binder.restoreCallingIdentity(identity); |
| 5074 | } |
| 5075 | } |
| 5076 | |
| 5077 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 5078 | public void setVtSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5079 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 5080 | "setVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5081 | final long identity = Binder.clearCallingIdentity(); |
| 5082 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5083 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5084 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 5085 | // 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] | 5086 | ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5087 | } catch (ImsException e) { |
| 5088 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5089 | } finally { |
| 5090 | Binder.restoreCallingIdentity(identity); |
| 5091 | } |
| 5092 | } |
| 5093 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 5094 | /** |
| 5095 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 5096 | * @param subId The subscription to use to check the configuration. |
| 5097 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5098 | @Override |
| 5099 | public boolean isVoWiFiSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 5100 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 5101 | mApp, subId, "isVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5102 | final long identity = Binder.clearCallingIdentity(); |
| 5103 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5104 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5105 | // 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] | 5106 | return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5107 | } catch (ImsException e) { |
| 5108 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5109 | } finally { |
| 5110 | Binder.restoreCallingIdentity(identity); |
| 5111 | } |
| 5112 | } |
| 5113 | |
| 5114 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 5115 | public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5116 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 5117 | "setVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5118 | final long identity = Binder.clearCallingIdentity(); |
| 5119 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5120 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5121 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 5122 | // 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] | 5123 | ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5124 | } catch (ImsException e) { |
| 5125 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5126 | } finally { |
| 5127 | Binder.restoreCallingIdentity(identity); |
| 5128 | } |
| 5129 | } |
| 5130 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 5131 | /** |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 5132 | * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not |
| 5133 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 5134 | * @param subId The subscription to use to check the configuration. |
| 5135 | */ |
| 5136 | @Override |
| 5137 | public boolean isCrossSimCallingEnabledByUser(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 5138 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 5139 | mApp, subId, "isCrossSimCallingEnabledByUser"); |
| 5140 | final long identity = Binder.clearCallingIdentity(); |
| 5141 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5142 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5143 | // 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] | 5144 | return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser(); |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 5145 | } catch (ImsException e) { |
| 5146 | throw new ServiceSpecificException(e.getCode()); |
| 5147 | } finally { |
| 5148 | Binder.restoreCallingIdentity(identity); |
| 5149 | } |
| 5150 | } |
| 5151 | |
| 5152 | /** |
| 5153 | * Sets the user's setting for whether or not Voice over Cross SIM is enabled. |
| 5154 | * Requires MODIFY_PHONE_STATE permission. |
| 5155 | * @param subId The subscription to use to check the configuration. |
| 5156 | * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled, |
| 5157 | * false otherwise |
| 5158 | */ |
| 5159 | @Override |
| 5160 | public void setCrossSimCallingEnabled(int subId, boolean isEnabled) { |
| 5161 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5162 | "setCrossSimCallingEnabled"); |
| 5163 | final long identity = Binder.clearCallingIdentity(); |
| 5164 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5165 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5166 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 5167 | // 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] | 5168 | ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled); |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 5169 | } catch (ImsException e) { |
| 5170 | throw new ServiceSpecificException(e.getCode()); |
| 5171 | } finally { |
| 5172 | Binder.restoreCallingIdentity(identity); |
| 5173 | } |
| 5174 | } |
| 5175 | |
| 5176 | /** |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 5177 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 5178 | * @param subId The subscription to use to check the configuration. |
| 5179 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5180 | @Override |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 5181 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5182 | public boolean isVoWiFiRoamingSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 5183 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 5184 | mApp, subId, "isVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5185 | final long identity = Binder.clearCallingIdentity(); |
| 5186 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5187 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5188 | // 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] | 5189 | return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5190 | } catch (ImsException e) { |
| 5191 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5192 | } finally { |
| 5193 | Binder.restoreCallingIdentity(identity); |
| 5194 | } |
| 5195 | } |
| 5196 | |
| 5197 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 5198 | public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5199 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 5200 | "setVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5201 | final long identity = Binder.clearCallingIdentity(); |
| 5202 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5203 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5204 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 5205 | // 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] | 5206 | ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5207 | } catch (ImsException e) { |
| 5208 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5209 | } finally { |
| 5210 | Binder.restoreCallingIdentity(identity); |
| 5211 | } |
| 5212 | } |
| 5213 | |
| 5214 | @Override |
| 5215 | public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) { |
| 5216 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5217 | "setVoWiFiNonPersistent"); |
| 5218 | final long identity = Binder.clearCallingIdentity(); |
| 5219 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5220 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5221 | // This setting will be ignored if the ImsService isn't up. |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5222 | ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5223 | } catch (ImsException e) { |
| 5224 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5225 | } finally { |
| 5226 | Binder.restoreCallingIdentity(identity); |
| 5227 | } |
| 5228 | } |
| 5229 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 5230 | /** |
| 5231 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 5232 | * @param subId The subscription to use to check the configuration. |
| 5233 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5234 | @Override |
| 5235 | public int getVoWiFiModeSetting(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 5236 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 5237 | mApp, subId, "getVoWiFiModeSetting"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5238 | final long identity = Binder.clearCallingIdentity(); |
| 5239 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5240 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5241 | // 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] | 5242 | return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5243 | } catch (ImsException e) { |
| 5244 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5245 | } finally { |
| 5246 | Binder.restoreCallingIdentity(identity); |
| 5247 | } |
| 5248 | } |
| 5249 | |
| 5250 | @Override |
| 5251 | public void setVoWiFiModeSetting(int subId, int mode) { |
| 5252 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5253 | "setVoWiFiModeSetting"); |
| 5254 | final long identity = Binder.clearCallingIdentity(); |
| 5255 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5256 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5257 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 5258 | // 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] | 5259 | ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5260 | } catch (ImsException e) { |
| 5261 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5262 | } finally { |
| 5263 | Binder.restoreCallingIdentity(identity); |
| 5264 | } |
| 5265 | } |
| 5266 | |
| 5267 | @Override |
| 5268 | public int getVoWiFiRoamingModeSetting(int subId) { |
| 5269 | enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting"); |
| 5270 | final long identity = Binder.clearCallingIdentity(); |
| 5271 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5272 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5273 | // 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] | 5274 | return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5275 | } catch (ImsException e) { |
| 5276 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5277 | } finally { |
| 5278 | Binder.restoreCallingIdentity(identity); |
| 5279 | } |
| 5280 | } |
| 5281 | |
| 5282 | @Override |
| 5283 | public void setVoWiFiRoamingModeSetting(int subId, int mode) { |
| 5284 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5285 | "setVoWiFiRoamingModeSetting"); |
| 5286 | final long identity = Binder.clearCallingIdentity(); |
| 5287 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5288 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5289 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 5290 | // 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] | 5291 | ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5292 | } catch (ImsException e) { |
| 5293 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5294 | } finally { |
| 5295 | Binder.restoreCallingIdentity(identity); |
| 5296 | } |
| 5297 | } |
| 5298 | |
| 5299 | @Override |
| 5300 | public void setRttCapabilitySetting(int subId, boolean isEnabled) { |
| 5301 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5302 | "setRttCapabilityEnabled"); |
| 5303 | final long identity = Binder.clearCallingIdentity(); |
| 5304 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5305 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5306 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 5307 | // 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] | 5308 | ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5309 | } catch (ImsException e) { |
| 5310 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5311 | } finally { |
| 5312 | Binder.restoreCallingIdentity(identity); |
| 5313 | } |
| 5314 | } |
| 5315 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 5316 | /** |
| 5317 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 5318 | * @param subId The subscription to use to check the configuration. |
| 5319 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5320 | @Override |
| 5321 | public boolean isTtyOverVolteEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 5322 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 5323 | mApp, subId, "isTtyOverVolteEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5324 | final long identity = Binder.clearCallingIdentity(); |
| 5325 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5326 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5327 | // 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] | 5328 | return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5329 | } catch (ImsException e) { |
| 5330 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5331 | } finally { |
| 5332 | Binder.restoreCallingIdentity(identity); |
| 5333 | } |
| 5334 | } |
| 5335 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5336 | @Override |
| 5337 | public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 5338 | enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5339 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5340 | final long identity = Binder.clearCallingIdentity(); |
| 5341 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 5342 | if (!isImsAvailableOnDevice()) { |
| 5343 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 5344 | "IMS not available on device."); |
| 5345 | } |
| 5346 | int slotId = getSlotIndexOrException(subId); |
| 5347 | verifyImsMmTelConfiguredOrThrow(slotId); |
Hwangoo Park | 8646b0d | 2023-01-13 02:42:34 +0000 | [diff] [blame] | 5348 | |
| 5349 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 5350 | if (controller != null) { |
| 5351 | ImsManager imsManager = controller.getImsManager(subId); |
| 5352 | if (imsManager != null) { |
| 5353 | imsManager.addProvisioningCallbackForSubscription(callback, subId); |
| 5354 | } else { |
| 5355 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE); |
| 5356 | } |
| 5357 | } else { |
| 5358 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION); |
| 5359 | } |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5360 | } catch (ImsException e) { |
| 5361 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5362 | } finally { |
| 5363 | Binder.restoreCallingIdentity(identity); |
| 5364 | } |
| 5365 | } |
| 5366 | |
| 5367 | @Override |
| 5368 | public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 5369 | enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5370 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5371 | final long identity = Binder.clearCallingIdentity(); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 5372 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5373 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 5374 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5375 | try { |
Hwangoo Park | 8646b0d | 2023-01-13 02:42:34 +0000 | [diff] [blame] | 5376 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 5377 | if (controller != null) { |
| 5378 | ImsManager imsManager = controller.getImsManager(subId); |
| 5379 | if (imsManager != null) { |
| 5380 | imsManager.removeProvisioningCallbackForSubscription(callback, subId); |
| 5381 | } else { |
| 5382 | Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId |
| 5383 | + " is inactive, ignoring unregister."); |
| 5384 | // If the ImsManager is not valid, just return, since the callback will already |
| 5385 | // have been removed internally. |
| 5386 | } |
| 5387 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5388 | } finally { |
| 5389 | Binder.restoreCallingIdentity(identity); |
| 5390 | } |
| 5391 | } |
| 5392 | |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5393 | @Override |
| 5394 | public void registerFeatureProvisioningChangedCallback(int subId, |
| 5395 | IFeatureProvisioningCallback callback) { |
| 5396 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5397 | mApp, subId, "registerFeatureProvisioningChangedCallback"); |
| 5398 | |
| 5399 | final long identity = Binder.clearCallingIdentity(); |
| 5400 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5401 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 5402 | } |
| 5403 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5404 | try { |
| 5405 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5406 | if (controller == null) { |
| 5407 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 5408 | "Device does not support IMS"); |
| 5409 | } |
| 5410 | controller.addFeatureProvisioningChangedCallback(subId, callback); |
| 5411 | } finally { |
| 5412 | Binder.restoreCallingIdentity(identity); |
| 5413 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5414 | } |
| 5415 | |
| 5416 | @Override |
| 5417 | public void unregisterFeatureProvisioningChangedCallback(int subId, |
| 5418 | IFeatureProvisioningCallback callback) { |
| 5419 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5420 | mApp, subId, "unregisterFeatureProvisioningChangedCallback"); |
| 5421 | |
| 5422 | final long identity = Binder.clearCallingIdentity(); |
| 5423 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5424 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 5425 | } |
| 5426 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5427 | try { |
| 5428 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5429 | if (controller == null) { |
| 5430 | loge("unregisterFeatureProvisioningChangedCallback: Device does not support IMS"); |
| 5431 | return; |
| 5432 | } |
| 5433 | controller.removeFeatureProvisioningChangedCallback(subId, callback); |
| 5434 | } finally { |
| 5435 | Binder.restoreCallingIdentity(identity); |
| 5436 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5437 | } |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5438 | |
| 5439 | private void checkModifyPhoneStatePermission(int subId, String message) { |
| 5440 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5441 | message); |
| 5442 | } |
| 5443 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5444 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5445 | public void setRcsProvisioningStatusForCapability(int subId, int capability, int tech, |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5446 | boolean isProvisioned) { |
| 5447 | checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability"); |
| 5448 | |
| 5449 | final long identity = Binder.clearCallingIdentity(); |
| 5450 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5451 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5452 | if (controller == null) { |
| 5453 | loge("setRcsProvisioningStatusForCapability: Device does not support IMS"); |
| 5454 | return; |
| 5455 | } |
| 5456 | controller.setRcsProvisioningStatusForCapability( |
| 5457 | subId, capability, tech, isProvisioned); |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5458 | } finally { |
| 5459 | Binder.restoreCallingIdentity(identity); |
| 5460 | } |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5461 | } |
| 5462 | |
| 5463 | |
| 5464 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5465 | public boolean getRcsProvisioningStatusForCapability(int subId, int capability, int tech) { |
| 5466 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5467 | mApp, subId, "getRcsProvisioningStatusForCapability"); |
| 5468 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5469 | final long identity = Binder.clearCallingIdentity(); |
| 5470 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5471 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5472 | if (controller == null) { |
| 5473 | loge("getRcsProvisioningStatusForCapability: Device does not support IMS"); |
| 5474 | |
| 5475 | // device does not support IMS, this method will return true always. |
| 5476 | return true; |
| 5477 | } |
| 5478 | return controller.getRcsProvisioningStatusForCapability(subId, capability, tech); |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5479 | } finally { |
| 5480 | Binder.restoreCallingIdentity(identity); |
| 5481 | } |
| 5482 | } |
| 5483 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5484 | @Override |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5485 | public void setImsProvisioningStatusForCapability(int subId, int capability, int tech, |
| 5486 | boolean isProvisioned) { |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5487 | checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5488 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5489 | final long identity = Binder.clearCallingIdentity(); |
| 5490 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5491 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5492 | if (controller == null) { |
| 5493 | loge("setImsProvisioningStatusForCapability: Device does not support IMS"); |
| 5494 | return; |
| 5495 | } |
| 5496 | controller.setImsProvisioningStatusForCapability( |
| 5497 | subId, capability, tech, isProvisioned); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5498 | } finally { |
| 5499 | Binder.restoreCallingIdentity(identity); |
| 5500 | } |
| 5501 | } |
| 5502 | |
| 5503 | @Override |
| 5504 | public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) { |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5505 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5506 | mApp, subId, "getProvisioningStatusForCapability"); |
| 5507 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5508 | final long identity = Binder.clearCallingIdentity(); |
| 5509 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5510 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5511 | if (controller == null) { |
| 5512 | loge("getImsProvisioningStatusForCapability: Device does not support IMS"); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5513 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5514 | // device does not support IMS, this method will return true always. |
| 5515 | return true; |
| 5516 | } |
| 5517 | return controller.getImsProvisioningStatusForCapability(subId, capability, tech); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5518 | } finally { |
| 5519 | Binder.restoreCallingIdentity(identity); |
| 5520 | } |
| 5521 | } |
| 5522 | |
| 5523 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5524 | public boolean isProvisioningRequiredForCapability(int subId, int capability, int tech) { |
| 5525 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5526 | mApp, subId, "isProvisioningRequiredForCapability"); |
| 5527 | |
| 5528 | final long identity = Binder.clearCallingIdentity(); |
| 5529 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5530 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5531 | if (controller == null) { |
| 5532 | loge("isProvisioningRequiredForCapability: Device does not support IMS"); |
| 5533 | |
| 5534 | // device does not support IMS, this method will return false |
| 5535 | return false; |
| 5536 | } |
| 5537 | return controller.isImsProvisioningRequiredForCapability(subId, capability, tech); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5538 | } finally { |
| 5539 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5540 | } |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5541 | } |
| 5542 | |
| 5543 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5544 | public boolean isRcsProvisioningRequiredForCapability(int subId, int capability, int tech) { |
| 5545 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5546 | mApp, subId, "isProvisioningRequiredForCapability"); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5547 | |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5548 | final long identity = Binder.clearCallingIdentity(); |
| 5549 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5550 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5551 | if (controller == null) { |
| 5552 | loge("isRcsProvisioningRequiredForCapability: Device does not support IMS"); |
| 5553 | |
| 5554 | // device does not support IMS, this method will return false |
| 5555 | return false; |
| 5556 | } |
| 5557 | return controller.isRcsProvisioningRequiredForCapability(subId, capability, tech); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5558 | } finally { |
| 5559 | Binder.restoreCallingIdentity(identity); |
| 5560 | } |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5561 | } |
| 5562 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5563 | @Override |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5564 | public int getImsProvisioningInt(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5565 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5566 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 5567 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5568 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5569 | mApp, subId, "getImsProvisioningInt"); |
| 5570 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5571 | final long identity = Binder.clearCallingIdentity(); |
| 5572 | try { |
| 5573 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5574 | int slotId = getSlotIndex(subId); |
| 5575 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5576 | Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '" |
| 5577 | + subId + "' for key:" + key); |
| 5578 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
| 5579 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5580 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5581 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5582 | if (controller == null) { |
| 5583 | loge("getImsProvisioningInt: Device does not support IMS"); |
| 5584 | |
| 5585 | // device does not support IMS, this method will return CONFIG_RESULT_UNKNOWN. |
| 5586 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
| 5587 | } |
| 5588 | int retVal = controller.getProvisioningValue(subId, key); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5589 | if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) { |
| 5590 | return retVal; |
| 5591 | } |
| 5592 | |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5593 | return ImsManager.getInstance(mApp, slotId).getConfigInt(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5594 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5595 | Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '" |
| 5596 | + subId + "' for key:" + key); |
| 5597 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5598 | } finally { |
| 5599 | Binder.restoreCallingIdentity(identity); |
| 5600 | } |
| 5601 | } |
| 5602 | |
| 5603 | @Override |
| 5604 | public String getImsProvisioningString(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5605 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5606 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 5607 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5608 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5609 | mApp, subId, "getImsProvisioningString"); |
| 5610 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5611 | final long identity = Binder.clearCallingIdentity(); |
| 5612 | try { |
| 5613 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5614 | int slotId = getSlotIndex(subId); |
| 5615 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5616 | Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '" |
| 5617 | + subId + "' for key:" + key); |
| 5618 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC; |
| 5619 | } |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5620 | return ImsManager.getInstance(mApp, slotId).getConfigString(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5621 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5622 | Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '" |
| 5623 | + subId + "' for key:" + key); |
| 5624 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5625 | } finally { |
| 5626 | Binder.restoreCallingIdentity(identity); |
| 5627 | } |
| 5628 | } |
| 5629 | |
| 5630 | @Override |
| 5631 | public int setImsProvisioningInt(int subId, int key, int value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5632 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5633 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 5634 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 5635 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5636 | "setImsProvisioningInt"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5637 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5638 | final long identity = Binder.clearCallingIdentity(); |
| 5639 | try { |
| 5640 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5641 | int slotId = getSlotIndex(subId); |
| 5642 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5643 | Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '" |
| 5644 | + subId + "' for key:" + key); |
| 5645 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 5646 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5647 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5648 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5649 | if (controller == null) { |
| 5650 | loge("setImsProvisioningInt: Device does not support IMS"); |
| 5651 | |
| 5652 | // device does not support IMS, this method will return CONFIG_RESULT_FAILED. |
| 5653 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 5654 | } |
| 5655 | int retVal = controller.setProvisioningValue(subId, key, value); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5656 | if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) { |
| 5657 | return retVal; |
| 5658 | } |
| 5659 | |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5660 | return ImsManager.getInstance(mApp, slotId).setConfig(key, value); |
| 5661 | } catch (com.android.ims.ImsException | RemoteException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5662 | Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5663 | + "' for key:" + key, e); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5664 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5665 | } finally { |
| 5666 | Binder.restoreCallingIdentity(identity); |
| 5667 | } |
| 5668 | } |
| 5669 | |
| 5670 | @Override |
| 5671 | public int setImsProvisioningString(int subId, int key, String value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5672 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5673 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 5674 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 5675 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5676 | "setImsProvisioningString"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5677 | final long identity = Binder.clearCallingIdentity(); |
| 5678 | try { |
| 5679 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5680 | int slotId = getSlotIndex(subId); |
| 5681 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5682 | Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '" |
| 5683 | + subId + "' for key:" + key); |
| 5684 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 5685 | } |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5686 | return ImsManager.getInstance(mApp, slotId).setConfig(key, value); |
| 5687 | } catch (com.android.ims.ImsException | RemoteException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5688 | Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5689 | + "' for key:" + key, e); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5690 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5691 | } finally { |
| 5692 | Binder.restoreCallingIdentity(identity); |
| 5693 | } |
| 5694 | } |
| 5695 | |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5696 | /** |
| 5697 | * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL |
| 5698 | * for the given slot ID or no ImsResolver instance has been created. |
| 5699 | * @param slotId The slot ID that the IMS service is created for. |
| 5700 | * @throws ImsException If there is no ImsService configured for this slot. |
| 5701 | */ |
| 5702 | private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException { |
| 5703 | if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId, |
| 5704 | ImsFeature.FEATURE_MMTEL)) { |
| 5705 | throw new ImsException("This subscription does not support MMTEL over IMS", |
| 5706 | ImsException.CODE_ERROR_UNSUPPORTED_OPERATION); |
| 5707 | } |
| 5708 | } |
| 5709 | |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5710 | private int getSlotIndexOrException(int subId) throws ImsException { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5711 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 5712 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5713 | throw new ImsException("Invalid Subscription Id, subId=" + subId, |
| 5714 | ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5715 | } |
| 5716 | return slotId; |
| 5717 | } |
| 5718 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5719 | private int getSlotIndex(int subId) { |
| 5720 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 5721 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
| 5722 | return SubscriptionManager.INVALID_SIM_SLOT_INDEX; |
| 5723 | } |
| 5724 | return slotId; |
| 5725 | } |
| 5726 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5727 | /** |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 5728 | * Returns the data network type for a subId; does not throw SecurityException. |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5729 | */ |
| 5730 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5731 | public int getNetworkTypeForSubscriber(int subId, String callingPackage, |
| 5732 | String callingFeatureId) { |
Shuo Qian | 13d8915 | 2021-05-10 23:58:11 -0700 | [diff] [blame] | 5733 | try { |
| 5734 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 5735 | } catch (SecurityException se) { |
| 5736 | EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid()); |
| 5737 | throw new SecurityException("Package " + callingPackage + " does not belong to " |
| 5738 | + Binder.getCallingUid()); |
| 5739 | } |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 5740 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 5741 | if (targetSdk > android.os.Build.VERSION_CODES.Q) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5742 | return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 5743 | } else if (targetSdk == android.os.Build.VERSION_CODES.Q |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 5744 | && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 5745 | mApp, subId, callingPackage, callingFeatureId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5746 | "getNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5747 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5748 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 5749 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5750 | final long identity = Binder.clearCallingIdentity(); |
| 5751 | try { |
| 5752 | final Phone phone = getPhone(subId); |
| 5753 | if (phone != null) { |
| 5754 | return phone.getServiceState().getDataNetworkType(); |
| 5755 | } else { |
| 5756 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5757 | } |
| 5758 | } finally { |
| 5759 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5760 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5761 | } |
| 5762 | |
| 5763 | /** |
| 5764 | * Returns the data network type |
| 5765 | */ |
| 5766 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5767 | public int getDataNetworkType(String callingPackage, String callingFeatureId) { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5768 | return getDataNetworkTypeForSubscriber(SubscriptionManager.getDefaultDataSubscriptionId(), |
Zoey Chen | fd61f7f | 2021-04-21 13:42:10 +0800 | [diff] [blame] | 5769 | callingPackage, callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5770 | } |
| 5771 | |
| 5772 | /** |
| 5773 | * Returns the data network type for a subId |
| 5774 | */ |
| 5775 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5776 | public int getDataNetworkTypeForSubscriber(int subId, String callingPackage, |
| 5777 | String callingFeatureId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 5778 | String functionName = "getDataNetworkTypeForSubscriber"; |
| 5779 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 5780 | mApp, functionName)) { |
| 5781 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 5782 | mApp, subId, callingPackage, callingFeatureId, functionName)) { |
| 5783 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5784 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5785 | } |
| 5786 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5787 | final long identity = Binder.clearCallingIdentity(); |
| 5788 | try { |
| 5789 | final Phone phone = getPhone(subId); |
| 5790 | if (phone != null) { |
| 5791 | return phone.getServiceState().getDataNetworkType(); |
| 5792 | } else { |
| 5793 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5794 | } |
| 5795 | } finally { |
| 5796 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5797 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5798 | } |
| 5799 | |
| 5800 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5801 | * Returns the Voice network type for a subId |
| 5802 | */ |
| 5803 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5804 | public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage, |
| 5805 | String callingFeatureId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 5806 | String functionName = "getVoiceNetworkTypeForSubscriber"; |
| 5807 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 5808 | mApp, functionName)) { |
| 5809 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 5810 | mApp, subId, callingPackage, callingFeatureId, functionName)) { |
| 5811 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5812 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 5813 | } |
| 5814 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5815 | final long identity = Binder.clearCallingIdentity(); |
| 5816 | try { |
| 5817 | final Phone phone = getPhone(subId); |
| 5818 | if (phone != null) { |
| 5819 | return phone.getServiceState().getVoiceNetworkType(); |
| 5820 | } else { |
| 5821 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5822 | } |
| 5823 | } finally { |
| 5824 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5825 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5826 | } |
| 5827 | |
| 5828 | /** |
| 5829 | * @return true if a ICC card is present |
| 5830 | */ |
| 5831 | public boolean hasIccCard() { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5832 | // FIXME Make changes to pass defaultSimId of type int |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5833 | return hasIccCardUsingSlotIndex(SubscriptionManager.getSlotIndex( |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5834 | getDefaultSubscription())); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5835 | } |
| 5836 | |
| 5837 | /** |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5838 | * @return true if a ICC card is present for a slotIndex |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5839 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5840 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5841 | public boolean hasIccCardUsingSlotIndex(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5842 | final long identity = Binder.clearCallingIdentity(); |
| 5843 | try { |
| 5844 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5845 | if (phone != null) { |
| 5846 | return phone.getIccCard().hasIccCard(); |
| 5847 | } else { |
| 5848 | return false; |
| 5849 | } |
| 5850 | } finally { |
| 5851 | Binder.restoreCallingIdentity(identity); |
Amit Mahajan | a6fc2a8 | 2015-01-06 11:53:51 -0800 | [diff] [blame] | 5852 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5853 | } |
| 5854 | |
| 5855 | /** |
| 5856 | * Return if the current radio is LTE on CDMA. This |
| 5857 | * is a tri-state return value as for a period of time |
| 5858 | * the mode may be unknown. |
| 5859 | * |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5860 | * @param callingPackage the name of the package making the call. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5861 | * @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] | 5862 | * or {@link Phone#LTE_ON_CDMA_TRUE} |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5863 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5864 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5865 | public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) { |
| 5866 | return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 5867 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5868 | } |
| 5869 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5870 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5871 | public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage, |
| 5872 | String callingFeatureId) { |
Sarah Chin | 790d292 | 2020-01-16 12:17:23 -0800 | [diff] [blame] | 5873 | try { |
| 5874 | enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber"); |
| 5875 | } catch (SecurityException e) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5876 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 5877 | } |
| 5878 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5879 | final long identity = Binder.clearCallingIdentity(); |
| 5880 | try { |
| 5881 | final Phone phone = getPhone(subId); |
| 5882 | if (phone == null) { |
| 5883 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 5884 | } else { |
Nathan Harold | 05ad633 | 2020-07-10 11:54:36 -0700 | [diff] [blame] | 5885 | return TelephonyProperties.lte_on_cdma_device() |
| 5886 | .orElse(PhoneConstants.LTE_ON_CDMA_FALSE); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5887 | } |
| 5888 | } finally { |
| 5889 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5890 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5891 | } |
| 5892 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5893 | /** |
| 5894 | * {@hide} |
| 5895 | * Returns Default subId, 0 in the case of single standby. |
| 5896 | */ |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 5897 | private int getDefaultSubscription() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5898 | return SubscriptionManager.getDefaultSubscriptionId(); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5899 | } |
| 5900 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 5901 | private int getSlotForDefaultSubscription() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5902 | return SubscriptionManager.getPhoneId(getDefaultSubscription()); |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 5903 | } |
| 5904 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 5905 | private int getPreferredVoiceSubscription() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5906 | return SubscriptionManager.getDefaultVoiceSubscriptionId(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5907 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5908 | |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 5909 | private boolean isActiveSubscription(int subId) { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5910 | if (PhoneFactory.isSubscriptionManagerServiceEnabled()) { |
Jack Yu | fa8ed01 | 2023-02-11 15:42:28 -0800 | [diff] [blame] | 5911 | return getSubscriptionManagerService().isActiveSubId(subId, |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5912 | mApp.getOpPackageName(), mApp.getFeatureId()); |
| 5913 | } |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 5914 | return mSubscriptionController.isActiveSubId(subId); |
| 5915 | } |
| 5916 | |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5917 | /** |
| 5918 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 5919 | */ |
| 5920 | public int getWhenToMakeWifiCalls() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5921 | final long identity = Binder.clearCallingIdentity(); |
| 5922 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5923 | return Settings.System.getInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5924 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, |
| 5925 | getWhenToMakeWifiCallsDefaultPreference()); |
| 5926 | } finally { |
| 5927 | Binder.restoreCallingIdentity(identity); |
| 5928 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5929 | } |
| 5930 | |
| 5931 | /** |
| 5932 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 5933 | */ |
| 5934 | public void setWhenToMakeWifiCalls(int preference) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5935 | final long identity = Binder.clearCallingIdentity(); |
| 5936 | try { |
| 5937 | if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5938 | Settings.System.putInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5939 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference); |
| 5940 | } finally { |
| 5941 | Binder.restoreCallingIdentity(identity); |
| 5942 | } |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 5943 | } |
| 5944 | |
Sailesh Nepal | d1e6815 | 2013-12-12 19:08:02 -0800 | [diff] [blame] | 5945 | private static int getWhenToMakeWifiCallsDefaultPreference() { |
Santos Cordon | da120f4 | 2014-08-06 04:44:34 -0700 | [diff] [blame] | 5946 | // TODO: Use a build property to choose this value. |
Evan Charlton | 9829e88 | 2013-12-19 15:30:38 -0800 | [diff] [blame] | 5947 | return TelephonyManager.WifiCallingChoices.ALWAYS_USE; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5948 | } |
Shishir Agrawal | 69f6812 | 2013-12-16 17:25:49 -0800 | [diff] [blame] | 5949 | |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5950 | private Phone getPhoneFromSlotPortIndexOrThrowException(int slotIndex, int portIndex) { |
| 5951 | int phoneId = UiccController.getInstance().getPhoneIdFromSlotPortIndex(slotIndex, |
| 5952 | portIndex); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5953 | if (phoneId == -1) { |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5954 | throw new IllegalArgumentException("Given slot index: " + slotIndex + " port index: " |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 5955 | + portIndex + " does not correspond to an active phone"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5956 | } |
| 5957 | return PhoneFactory.getPhone(phoneId); |
| 5958 | } |
| 5959 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5960 | @Override |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 5961 | public IccOpenLogicalChannelResponse iccOpenLogicalChannel( |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5962 | @NonNull IccLogicalChannelRequest request) { |
| 5963 | Phone phone = getPhoneFromValidIccLogicalChannelRequest(request, |
| 5964 | /*message=*/ "iccOpenLogicalChannel"); |
| 5965 | |
| 5966 | if (DBG) log("iccOpenLogicalChannel: request=" + request); |
| 5967 | // Verify that the callingPackage in the request belongs to the calling UID |
| 5968 | mAppOps.checkPackage(Binder.getCallingUid(), request.callingPackage); |
| 5969 | |
| 5970 | return iccOpenLogicalChannelWithPermission(phone, request); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5971 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5972 | |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5973 | private Phone getPhoneFromValidIccLogicalChannelRequest( |
| 5974 | @NonNull IccLogicalChannelRequest request, String message) { |
| 5975 | Phone phone; |
| 5976 | if (request.subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) { |
| 5977 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5978 | mApp, request.subId, message); |
| 5979 | phone = getPhoneFromSubId(request.subId); |
| 5980 | } else if (request.slotIndex != SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5981 | enforceModifyPermission(); |
| 5982 | phone = getPhoneFromSlotPortIndexOrThrowException(request.slotIndex, request.portIndex); |
| 5983 | } else { |
| 5984 | throw new IllegalArgumentException("Both subId and slotIndex in request are invalid."); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5985 | } |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5986 | return phone; |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5987 | } |
| 5988 | |
| 5989 | private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone, |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5990 | IccLogicalChannelRequest channelRequest) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5991 | final long identity = Binder.clearCallingIdentity(); |
| 5992 | try { |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5993 | if (TextUtils.equals(ISDR_AID, channelRequest.aid)) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5994 | // Only allows LPA to open logical channel to ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5995 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 5996 | .getContext().getPackageManager()); |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5997 | if (bestComponent == null || !TextUtils.equals(channelRequest.callingPackage, |
| 5998 | bestComponent.packageName)) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5999 | loge("The calling package is not allowed to access ISD-R."); |
| 6000 | throw new SecurityException( |
| 6001 | "The calling package is not allowed to access ISD-R."); |
| 6002 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 6003 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 6004 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6005 | IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest( |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 6006 | CMD_OPEN_CHANNEL, channelRequest, phone, null /* workSource */); |
| 6007 | if (DBG) log("iccOpenLogicalChannelWithPermission: response=" + response); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6008 | return response; |
| 6009 | } finally { |
| 6010 | Binder.restoreCallingIdentity(identity); |
| 6011 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 6012 | } |
| 6013 | |
| 6014 | @Override |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 6015 | public boolean iccCloseLogicalChannel(@NonNull IccLogicalChannelRequest request) { |
| 6016 | Phone phone = getPhoneFromValidIccLogicalChannelRequest(request, |
| 6017 | /*message=*/"iccCloseLogicalChannel"); |
| 6018 | |
| 6019 | if (DBG) log("iccCloseLogicalChannel: request=" + request); |
| 6020 | |
| 6021 | return iccCloseLogicalChannelWithPermission(phone, request); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6022 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 6023 | |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 6024 | private boolean iccCloseLogicalChannelWithPermission(Phone phone, |
| 6025 | IccLogicalChannelRequest request) { |
Chen Xu | a8f0dff | 2022-02-12 00:34:15 -0800 | [diff] [blame] | 6026 | // before this feature is enabled, this API should only return false if |
| 6027 | // the operation fails instead of throwing runtime exception for |
| 6028 | // backward-compatibility. |
| 6029 | final boolean shouldThrowExceptionOnFailure = CompatChanges.isChangeEnabled( |
| 6030 | ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE, Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6031 | final long identity = Binder.clearCallingIdentity(); |
| 6032 | try { |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 6033 | if (request.channel < 0) { |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 6034 | throw new IllegalArgumentException("request.channel is less than 0"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6035 | } |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 6036 | Object result = sendRequest(CMD_CLOSE_CHANNEL, request.channel, phone, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6037 | null /* workSource */); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 6038 | Boolean success = false; |
| 6039 | if (result instanceof RuntimeException) { |
| 6040 | // if there is an exception returned, throw from the binder thread here. |
Chen Xu | a8f0dff | 2022-02-12 00:34:15 -0800 | [diff] [blame] | 6041 | if (shouldThrowExceptionOnFailure) { |
| 6042 | throw (RuntimeException) result; |
| 6043 | } else { |
| 6044 | return false; |
| 6045 | } |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 6046 | } else if (result instanceof Boolean) { |
| 6047 | success = (Boolean) result; |
| 6048 | } else { |
| 6049 | loge("iccCloseLogicalChannelWithPermission: supported return type " + result); |
| 6050 | } |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 6051 | if (DBG) log("iccCloseLogicalChannelWithPermission: success=" + success); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6052 | return success; |
| 6053 | } finally { |
| 6054 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 6055 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 6056 | } |
| 6057 | |
| 6058 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6059 | public String iccTransmitApduLogicalChannel(int subId, int channel, int cla, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 6060 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6061 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6062 | mApp, subId, "iccTransmitApduLogicalChannel"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6063 | if (DBG) { |
| 6064 | log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel |
| 6065 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 6066 | + p3 + " data=" + data); |
| 6067 | } |
| 6068 | return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla, |
| 6069 | command, p1, p2, p3, data); |
| 6070 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 6071 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6072 | @Override |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 6073 | public String iccTransmitApduLogicalChannelByPort(int slotIndex, int portIndex, int channel, |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6074 | int cla, int command, int p1, int p2, int p3, String data) { |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6075 | enforceModifyPermission(); |
| 6076 | if (DBG) { |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 6077 | log("iccTransmitApduLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex=" |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6078 | + portIndex + " chnl=" + channel + " cla=" + cla + " cmd=" + command + " p1=" |
| 6079 | + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6080 | } |
| 6081 | return iccTransmitApduLogicalChannelWithPermission( |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 6082 | getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel, cla, |
| 6083 | command, p1, p2, p3, data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6084 | } |
| 6085 | |
| 6086 | private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla, |
| 6087 | int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6088 | final long identity = Binder.clearCallingIdentity(); |
| 6089 | try { |
Hall Liu | 4fd771b | 2019-05-02 09:16:29 -0700 | [diff] [blame] | 6090 | if (channel <= 0) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6091 | return ""; |
| 6092 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 6093 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6094 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6095 | new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone, |
| 6096 | null /* workSource */); |
| 6097 | if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 6098 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6099 | // Append the returned status code to the end of the response payload. |
| 6100 | String s = Integer.toHexString( |
| 6101 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 6102 | if (response.payload != null) { |
| 6103 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 6104 | } |
| 6105 | return s; |
| 6106 | } finally { |
| 6107 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 6108 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 6109 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 6110 | |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 6111 | @Override |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 6112 | public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla, |
| 6113 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6114 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6115 | mApp, subId, "iccTransmitApduBasicChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6116 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6117 | if (DBG) { |
| 6118 | log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" |
| 6119 | + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
| 6120 | } |
| 6121 | return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage, |
| 6122 | cla, command, p1, p2, p3, data); |
| 6123 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 6124 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6125 | @Override |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 6126 | public String iccTransmitApduBasicChannelByPort(int slotIndex, int portIndex, |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6127 | 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] | 6128 | enforceModifyPermission(); |
| 6129 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 6130 | if (DBG) { |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 6131 | log("iccTransmitApduBasicChannelByPort: slotIndex=" + slotIndex + " portIndex=" |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6132 | + portIndex + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" |
| 6133 | + p2 + " p3=" + p3 + " data=" + data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6134 | } |
| 6135 | |
| 6136 | return iccTransmitApduBasicChannelWithPermission( |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 6137 | getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), callingPackage, |
| 6138 | cla, command, p1, p2, p3, data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6139 | } |
| 6140 | |
| 6141 | // open APDU basic channel assuming the caller has sufficient permissions |
| 6142 | private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage, |
| 6143 | int cla, int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6144 | final long identity = Binder.clearCallingIdentity(); |
| 6145 | try { |
| 6146 | if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3 |
| 6147 | && TextUtils.equals(ISDR_AID, data)) { |
| 6148 | // Only allows LPA to select ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6149 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 6150 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6151 | if (bestComponent == null |
| 6152 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 6153 | loge("The calling package is not allowed to select ISD-R."); |
| 6154 | throw new SecurityException( |
| 6155 | "The calling package is not allowed to select ISD-R."); |
| 6156 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 6157 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 6158 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6159 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6160 | new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone, |
| 6161 | null /* workSource */); |
| 6162 | if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 6163 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6164 | // Append the returned status code to the end of the response payload. |
| 6165 | String s = Integer.toHexString( |
| 6166 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 6167 | if (response.payload != null) { |
| 6168 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 6169 | } |
| 6170 | return s; |
| 6171 | } finally { |
| 6172 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 6173 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 6174 | } |
| 6175 | |
| 6176 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6177 | 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] | 6178 | String filePath) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6179 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6180 | mApp, subId, "iccExchangeSimIO"); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 6181 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6182 | final long identity = Binder.clearCallingIdentity(); |
| 6183 | try { |
| 6184 | if (DBG) { |
| 6185 | log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " |
| 6186 | + p1 + " " + p2 + " " + p3 + ":" + filePath); |
| 6187 | } |
| 6188 | |
| 6189 | IccIoResult response = |
| 6190 | (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO, |
| 6191 | new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath), |
| 6192 | subId); |
| 6193 | |
| 6194 | if (DBG) { |
| 6195 | log("Exchange SIM_IO [R]" + response); |
| 6196 | } |
| 6197 | |
| 6198 | byte[] result = null; |
| 6199 | int length = 2; |
| 6200 | if (response.payload != null) { |
| 6201 | length = 2 + response.payload.length; |
| 6202 | result = new byte[length]; |
| 6203 | System.arraycopy(response.payload, 0, result, 0, response.payload.length); |
| 6204 | } else { |
| 6205 | result = new byte[length]; |
| 6206 | } |
| 6207 | |
| 6208 | result[length - 1] = (byte) response.sw2; |
| 6209 | result[length - 2] = (byte) response.sw1; |
| 6210 | return result; |
| 6211 | } finally { |
| 6212 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 6213 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 6214 | } |
| 6215 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 6216 | /** |
| 6217 | * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM) |
| 6218 | * on a particular subscription |
| 6219 | */ |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6220 | public String[] getForbiddenPlmns(int subId, int appType, String callingPackage, |
| 6221 | String callingFeatureId) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 6222 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6223 | mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 6224 | return null; |
| 6225 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6226 | |
| 6227 | final long identity = Binder.clearCallingIdentity(); |
| 6228 | try { |
| 6229 | if (appType != TelephonyManager.APPTYPE_USIM |
| 6230 | && appType != TelephonyManager.APPTYPE_SIM) { |
| 6231 | loge("getForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 6232 | return null; |
| 6233 | } |
| 6234 | Object response = sendRequest( |
| 6235 | CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId); |
| 6236 | if (response instanceof String[]) { |
| 6237 | return (String[]) response; |
| 6238 | } |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 6239 | // Response is an Exception of some kind |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6240 | // which is signalled to the user as a NULL retval |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 6241 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6242 | } finally { |
| 6243 | Binder.restoreCallingIdentity(identity); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 6244 | } |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 6245 | } |
| 6246 | |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 6247 | /** |
| 6248 | * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular |
| 6249 | * subscription. |
| 6250 | * |
| 6251 | * @param subId the id of the subscription. |
| 6252 | * @param appType the uicc app type, must be USIM or SIM. |
| 6253 | * @param fplmns the Forbiden plmns list that needed to be written to the SIM. |
| 6254 | * @param callingPackage the op Package name. |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6255 | * @param callingFeatureId the feature in the package. |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 6256 | * @return number of fplmns that is successfully written to the SIM. |
| 6257 | */ |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6258 | public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage, |
| 6259 | String callingFeatureId) { |
Jayachandran C | 5b0d75a | 2021-10-21 22:15:27 -0700 | [diff] [blame] | 6260 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6261 | mApp, subId, "setForbiddenPlmns"); |
| 6262 | |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 6263 | if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) { |
| 6264 | loge("setForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 6265 | throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM"); |
| 6266 | } |
| 6267 | if (fplmns == null) { |
| 6268 | throw new IllegalArgumentException("Fplmn List provided is null"); |
| 6269 | } |
| 6270 | for (String fplmn : fplmns) { |
| 6271 | if (!CellIdentity.isValidPlmn(fplmn)) { |
| 6272 | throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn); |
| 6273 | } |
| 6274 | } |
| 6275 | final long identity = Binder.clearCallingIdentity(); |
| 6276 | try { |
| 6277 | Object response = sendRequest( |
| 6278 | CMD_SET_FORBIDDEN_PLMNS, |
| 6279 | new Pair<Integer, List<String>>(new Integer(appType), fplmns), |
| 6280 | subId); |
| 6281 | return (int) response; |
| 6282 | } finally { |
| 6283 | Binder.restoreCallingIdentity(identity); |
| 6284 | } |
| 6285 | } |
| 6286 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 6287 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6288 | public String sendEnvelopeWithStatus(int subId, String content) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6289 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6290 | mApp, subId, "sendEnvelopeWithStatus"); |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 6291 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6292 | final long identity = Binder.clearCallingIdentity(); |
| 6293 | try { |
| 6294 | IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId); |
| 6295 | if (response.payload == null) { |
| 6296 | return ""; |
| 6297 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 6298 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6299 | // Append the returned status code to the end of the response payload. |
| 6300 | String s = Integer.toHexString( |
| 6301 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 6302 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 6303 | return s; |
| 6304 | } finally { |
| 6305 | Binder.restoreCallingIdentity(identity); |
| 6306 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 6307 | } |
| 6308 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 6309 | /** |
| 6310 | * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 6311 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 6312 | * |
| 6313 | * @param itemID the ID of the item to read |
| 6314 | * @return the NV item as a String, or null on error. |
| 6315 | */ |
| 6316 | @Override |
| 6317 | public String nvReadItem(int itemID) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6318 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6319 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6320 | mApp, getDefaultSubscription(), "nvReadItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6321 | |
| 6322 | final long identity = Binder.clearCallingIdentity(); |
| 6323 | try { |
| 6324 | if (DBG) log("nvReadItem: item " + itemID); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6325 | String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6326 | if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"'); |
| 6327 | return value; |
| 6328 | } finally { |
| 6329 | Binder.restoreCallingIdentity(identity); |
| 6330 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 6331 | } |
| 6332 | |
| 6333 | /** |
| 6334 | * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 6335 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 6336 | * |
| 6337 | * @param itemID the ID of the item to read |
| 6338 | * @param itemValue the value to write, as a String |
| 6339 | * @return true on success; false on any failure |
| 6340 | */ |
| 6341 | @Override |
| 6342 | public boolean nvWriteItem(int itemID, String itemValue) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6343 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6344 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6345 | mApp, getDefaultSubscription(), "nvWriteItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6346 | |
| 6347 | final long identity = Binder.clearCallingIdentity(); |
| 6348 | try { |
| 6349 | if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"'); |
| 6350 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6351 | new Pair<Integer, String>(itemID, itemValue), workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6352 | if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail")); |
| 6353 | return success; |
| 6354 | } finally { |
| 6355 | Binder.restoreCallingIdentity(identity); |
| 6356 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 6357 | } |
| 6358 | |
| 6359 | /** |
| 6360 | * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage. |
| 6361 | * Used for device configuration by some CDMA operators. |
| 6362 | * |
| 6363 | * @param preferredRoamingList byte array containing the new PRL |
| 6364 | * @return true on success; false on any failure |
| 6365 | */ |
| 6366 | @Override |
| 6367 | public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6368 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6369 | mApp, getDefaultSubscription(), "nvWriteCdmaPrl"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6370 | |
| 6371 | final long identity = Binder.clearCallingIdentity(); |
| 6372 | try { |
| 6373 | if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList)); |
| 6374 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList); |
| 6375 | if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail")); |
| 6376 | return success; |
| 6377 | } finally { |
| 6378 | Binder.restoreCallingIdentity(identity); |
| 6379 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 6380 | } |
| 6381 | |
| 6382 | /** |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 6383 | * 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] | 6384 | * Used for device configuration by some CDMA operators. |
| 6385 | * |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 6386 | * @param slotIndex - device slot. |
| 6387 | * |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 6388 | * @return true on success; false on any failure |
| 6389 | */ |
| 6390 | @Override |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 6391 | public boolean resetModemConfig(int slotIndex) { |
| 6392 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 6393 | if (phone != null) { |
| 6394 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6395 | mApp, phone.getSubId(), "resetModemConfig"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6396 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 6397 | final long identity = Binder.clearCallingIdentity(); |
| 6398 | try { |
| 6399 | Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null); |
| 6400 | if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 6401 | return success; |
| 6402 | } finally { |
| 6403 | Binder.restoreCallingIdentity(identity); |
| 6404 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6405 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 6406 | return false; |
| 6407 | } |
| 6408 | |
| 6409 | /** |
| 6410 | * Generate a radio modem reset. Used for device configuration by some CDMA operators. |
| 6411 | * |
| 6412 | * @param slotIndex - device slot. |
| 6413 | * |
| 6414 | * @return true on success; false on any failure |
| 6415 | */ |
| 6416 | @Override |
| 6417 | public boolean rebootModem(int slotIndex) { |
| 6418 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 6419 | if (phone != null) { |
| 6420 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6421 | mApp, phone.getSubId(), "rebootModem"); |
| 6422 | |
| 6423 | final long identity = Binder.clearCallingIdentity(); |
| 6424 | try { |
| 6425 | Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null); |
| 6426 | if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail")); |
| 6427 | return success; |
| 6428 | } finally { |
| 6429 | Binder.restoreCallingIdentity(identity); |
| 6430 | } |
| 6431 | } |
| 6432 | return false; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 6433 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 6434 | |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 6435 | /** |
Grace Jia | aa2eb6b | 2020-01-09 16:26:08 -0800 | [diff] [blame] | 6436 | * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and |
| 6437 | * {@link #disableIms(int)}. |
| 6438 | * @param slotIndex device slot. |
| 6439 | */ |
| 6440 | public void resetIms(int slotIndex) { |
| 6441 | enforceModifyPermission(); |
| 6442 | |
| 6443 | final long identity = Binder.clearCallingIdentity(); |
| 6444 | try { |
| 6445 | if (mImsResolver == null) { |
| 6446 | // may happen if the does not support IMS. |
| 6447 | return; |
| 6448 | } |
Hyunho | a17ac7c | 2022-08-30 12:03:04 +0000 | [diff] [blame] | 6449 | mImsResolver.resetIms(slotIndex); |
Grace Jia | aa2eb6b | 2020-01-09 16:26:08 -0800 | [diff] [blame] | 6450 | } finally { |
| 6451 | Binder.restoreCallingIdentity(identity); |
| 6452 | } |
| 6453 | } |
| 6454 | |
| 6455 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6456 | * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability |
| 6457 | * status updates, if not already enabled. |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 6458 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6459 | public void enableIms(int slotId) { |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 6460 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6461 | |
| 6462 | final long identity = Binder.clearCallingIdentity(); |
| 6463 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6464 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6465 | // may happen if the device does not support IMS. |
| 6466 | return; |
| 6467 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6468 | mImsResolver.enableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6469 | } finally { |
| 6470 | Binder.restoreCallingIdentity(identity); |
| 6471 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 6472 | } |
| 6473 | |
| 6474 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6475 | * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature |
| 6476 | * status updates to disabled. |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 6477 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6478 | public void disableIms(int slotId) { |
| 6479 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6480 | |
| 6481 | final long identity = Binder.clearCallingIdentity(); |
| 6482 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6483 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6484 | // may happen if the device does not support IMS. |
| 6485 | return; |
| 6486 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6487 | mImsResolver.disableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6488 | } finally { |
| 6489 | Binder.restoreCallingIdentity(identity); |
| 6490 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6491 | } |
| 6492 | |
| 6493 | /** |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 6494 | * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback |
| 6495 | * callback. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6496 | */ |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 6497 | @Override |
Brad Ebinger | f6aca00 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 6498 | public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) { |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 6499 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6500 | |
| 6501 | final long identity = Binder.clearCallingIdentity(); |
| 6502 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6503 | if (mImsResolver == null) { |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 6504 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 6505 | "Device does not support IMS"); |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6506 | } |
Brad Ebinger | f6aca00 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 6507 | mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6508 | } finally { |
| 6509 | Binder.restoreCallingIdentity(identity); |
| 6510 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 6511 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 6512 | /** |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 6513 | * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature. |
| 6514 | */ |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 6515 | @Override |
| 6516 | public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) { |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 6517 | enforceModifyPermission(); |
| 6518 | |
| 6519 | final long identity = Binder.clearCallingIdentity(); |
| 6520 | try { |
| 6521 | if (mImsResolver == null) return; |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 6522 | mImsResolver.unregisterImsFeatureCallback(callback); |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 6523 | } finally { |
| 6524 | Binder.restoreCallingIdentity(identity); |
| 6525 | } |
| 6526 | } |
| 6527 | |
| 6528 | /** |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 6529 | * Returns the {@link IImsRegistration} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6530 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 6531 | */ |
| 6532 | public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException { |
| 6533 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6534 | |
| 6535 | final long identity = Binder.clearCallingIdentity(); |
| 6536 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6537 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6538 | // may happen if the device does not support IMS. |
| 6539 | return null; |
| 6540 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6541 | return mImsResolver.getImsRegistration(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6542 | } finally { |
| 6543 | Binder.restoreCallingIdentity(identity); |
| 6544 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 6545 | } |
| 6546 | |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6547 | /** |
| 6548 | * Returns the {@link IImsConfig} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6549 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6550 | */ |
| 6551 | public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException { |
| 6552 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6553 | |
| 6554 | final long identity = Binder.clearCallingIdentity(); |
| 6555 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6556 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6557 | // may happen if the device does not support IMS. |
| 6558 | return null; |
| 6559 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6560 | return mImsResolver.getImsConfig(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6561 | } finally { |
| 6562 | Binder.restoreCallingIdentity(identity); |
| 6563 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6564 | } |
| 6565 | |
Brad Ebinger | 884c07b | 2018-02-15 16:17:40 -0800 | [diff] [blame] | 6566 | /** |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6567 | * Sets the ImsService Package Name that Telephony will bind to. |
| 6568 | * |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6569 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 6570 | * @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] | 6571 | * ImsService is the device default ImsService. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6572 | * @param featureTypes An integer array of feature types associated with a packageName. |
| 6573 | * @param packageName The name of the package that the current configuration will be replaced |
| 6574 | * with. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6575 | * @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] | 6576 | */ |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6577 | public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService, |
| 6578 | int[] featureTypes, String packageName) { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6579 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 6580 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
Jack Yu | 00ece8c | 2022-11-19 22:29:12 -0800 | [diff] [blame] | 6581 | SubscriptionManager.getSubscriptionId(slotIndex), "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 6582 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6583 | final long identity = Binder.clearCallingIdentity(); |
| 6584 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6585 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6586 | // may happen if the device does not support IMS. |
| 6587 | return false; |
| 6588 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6589 | Map<Integer, String> featureConfig = new HashMap<>(); |
| 6590 | for (int featureType : featureTypes) { |
| 6591 | featureConfig.put(featureType, packageName); |
| 6592 | } |
| 6593 | return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService, |
| 6594 | featureConfig); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6595 | } finally { |
| 6596 | Binder.restoreCallingIdentity(identity); |
| 6597 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6598 | } |
| 6599 | |
| 6600 | /** |
Brad Ebinger | 999d330 | 2020-11-25 14:31:39 -0800 | [diff] [blame] | 6601 | * Clears any carrier ImsService overrides for the slot index specified that were previously |
| 6602 | * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}. |
| 6603 | * |
| 6604 | * This should only be used for testing. |
| 6605 | * |
| 6606 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 6607 | * @return true if clearing the carrier ImsService override succeeded or false if it did not. |
| 6608 | */ |
| 6609 | @Override |
| 6610 | public boolean clearCarrierImsServiceOverride(int slotIndex) { |
Brad Ebinger | 999d330 | 2020-11-25 14:31:39 -0800 | [diff] [blame] | 6611 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 6612 | "clearCarrierImsServiceOverride"); |
| 6613 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
Jack Yu | 00ece8c | 2022-11-19 22:29:12 -0800 | [diff] [blame] | 6614 | SubscriptionManager.getSubscriptionId(slotIndex), "clearCarrierImsServiceOverride"); |
Brad Ebinger | 999d330 | 2020-11-25 14:31:39 -0800 | [diff] [blame] | 6615 | |
| 6616 | final long identity = Binder.clearCallingIdentity(); |
| 6617 | try { |
| 6618 | if (mImsResolver == null) { |
| 6619 | // may happen if the device does not support IMS. |
| 6620 | return false; |
| 6621 | } |
| 6622 | return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex); |
| 6623 | } finally { |
| 6624 | Binder.restoreCallingIdentity(identity); |
| 6625 | } |
| 6626 | } |
| 6627 | |
| 6628 | /** |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6629 | * Return the package name of the currently bound ImsService. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6630 | * |
| 6631 | * @param slotId The slot that the ImsService is associated with. |
| 6632 | * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is |
| 6633 | * the device default. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6634 | * @param featureType The feature associated with the queried configuration. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6635 | * @return the package name of the ImsService configuration. |
| 6636 | */ |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6637 | public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService, |
| 6638 | @ImsFeature.FeatureType int featureType) { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6639 | TelephonyPermissions |
Jack Yu | 00ece8c | 2022-11-19 22:29:12 -0800 | [diff] [blame] | 6640 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(mApp, |
| 6641 | SubscriptionManager.getSubscriptionId(slotId), "getBoundImsServicePackage"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 6642 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6643 | final long identity = Binder.clearCallingIdentity(); |
| 6644 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6645 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6646 | // may happen if the device does not support IMS. |
| 6647 | return ""; |
| 6648 | } |
Brad Ebinger | a80c331 | 2019-12-02 10:59:39 -0800 | [diff] [blame] | 6649 | // TODO: change API to query RCS separately. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6650 | return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService, |
| 6651 | featureType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6652 | } finally { |
| 6653 | Binder.restoreCallingIdentity(identity); |
| 6654 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6655 | } |
| 6656 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6657 | /** |
| 6658 | * Get the MmTelFeature state associated with the requested subscription id. |
| 6659 | * @param subId The subscription that the MmTelFeature is associated with. |
| 6660 | * @param callback A callback with an integer containing the |
| 6661 | * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature. |
| 6662 | */ |
| 6663 | @Override |
| 6664 | public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) { |
| 6665 | enforceReadPrivilegedPermission("getImsMmTelFeatureState"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 6666 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 6667 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 6668 | "IMS not available on device."); |
| 6669 | } |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6670 | final long token = Binder.clearCallingIdentity(); |
| 6671 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 6672 | int slotId = getSlotIndex(subId); |
| 6673 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 6674 | Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '" |
| 6675 | + subId + "'"); |
| 6676 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 6677 | } |
| 6678 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 6679 | ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> { |
| 6680 | try { |
| 6681 | callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger); |
| 6682 | } catch (RemoteException e) { |
| 6683 | Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. " |
| 6684 | + "Ignore"); |
| 6685 | } |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6686 | }); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 6687 | } catch (ImsException e) { |
| 6688 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6689 | } finally { |
| 6690 | Binder.restoreCallingIdentity(token); |
| 6691 | } |
| 6692 | } |
| 6693 | |
Daniel Bright | bb5840b | 2021-01-12 15:48:18 -0800 | [diff] [blame] | 6694 | /** |
| 6695 | * Sets the ims registration state on all valid {@link Phone}s. |
| 6696 | */ |
| 6697 | public void setImsRegistrationState(final boolean registered) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 6698 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6699 | |
| 6700 | final long identity = Binder.clearCallingIdentity(); |
| 6701 | try { |
Daniel Bright | bb5840b | 2021-01-12 15:48:18 -0800 | [diff] [blame] | 6702 | // NOTE: Before S, this method only set the default phone. |
| 6703 | for (final Phone phone : PhoneFactory.getPhones()) { |
| 6704 | if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) { |
| 6705 | phone.setImsRegistrationState(registered); |
| 6706 | } |
| 6707 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6708 | } finally { |
| 6709 | Binder.restoreCallingIdentity(identity); |
| 6710 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 6711 | } |
| 6712 | |
| 6713 | /** |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 6714 | * Set the network selection mode to automatic. |
| 6715 | * |
| 6716 | */ |
| 6717 | @Override |
| 6718 | public void setNetworkSelectionModeAutomatic(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6719 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6720 | mApp, subId, "setNetworkSelectionModeAutomatic"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6721 | |
| 6722 | final long identity = Binder.clearCallingIdentity(); |
| 6723 | try { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 6724 | if (!isActiveSubscription(subId)) { |
| 6725 | return; |
| 6726 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6727 | if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId); |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 6728 | sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId, |
| 6729 | SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6730 | } finally { |
| 6731 | Binder.restoreCallingIdentity(identity); |
| 6732 | } |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 6733 | } |
| 6734 | |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 6735 | /** |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6736 | * Ask the radio to connect to the input network and change selection mode to manual. |
| 6737 | * |
| 6738 | * @param subId the id of the subscription. |
| 6739 | * @param operatorInfo the operator information, included the PLMN, long name and short name of |
| 6740 | * the operator to attach to. |
| 6741 | * @param persistSelection whether the selection will persist until reboot. If true, only allows |
| 6742 | * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume |
| 6743 | * normal network selection next time. |
| 6744 | * @return {@code true} on success; {@code true} on any failure. |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6745 | */ |
| 6746 | @Override |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6747 | public boolean setNetworkSelectionModeManual( |
| 6748 | int subId, OperatorInfo operatorInfo, boolean persistSelection) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6749 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6750 | mApp, subId, "setNetworkSelectionModeManual"); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 6751 | |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 6752 | final long identity = Binder.clearCallingIdentity(); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 6753 | if (!isActiveSubscription(subId)) { |
| 6754 | return false; |
| 6755 | } |
| 6756 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6757 | try { |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6758 | ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6759 | persistSelection); |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6760 | if (DBG) { |
| 6761 | log("setNetworkSelectionModeManual: subId: " + subId |
| 6762 | + " operator: " + operatorInfo); |
| 6763 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6764 | return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId); |
| 6765 | } finally { |
| 6766 | Binder.restoreCallingIdentity(identity); |
| 6767 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6768 | } |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6769 | /** |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6770 | * Get the manual network selection |
| 6771 | * |
| 6772 | * @param subId the id of the subscription. |
| 6773 | * |
| 6774 | * @return the previously saved user selected PLMN |
| 6775 | */ |
| 6776 | @Override |
| 6777 | public String getManualNetworkSelectionPlmn(int subId) { |
| 6778 | TelephonyPermissions |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6779 | .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 6780 | mApp, subId, "getManualNetworkSelectionPlmn"); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6781 | |
| 6782 | final long identity = Binder.clearCallingIdentity(); |
| 6783 | try { |
| 6784 | if (!isActiveSubscription(subId)) { |
shilu | fa1c259 | 2020-03-10 10:59:43 -0700 | [diff] [blame] | 6785 | throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6786 | } |
| 6787 | |
| 6788 | final Phone phone = getPhone(subId); |
| 6789 | if (phone == null) { |
shilu | fa1c259 | 2020-03-10 10:59:43 -0700 | [diff] [blame] | 6790 | throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6791 | } |
| 6792 | OperatorInfo networkSelection = phone.getSavedNetworkSelection(); |
| 6793 | return TextUtils.isEmpty(networkSelection.getOperatorNumeric()) |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6794 | ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric(); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6795 | } finally { |
| 6796 | Binder.restoreCallingIdentity(identity); |
| 6797 | } |
| 6798 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6799 | |
| 6800 | /** |
| 6801 | * Scans for available networks. |
| 6802 | */ |
| 6803 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6804 | public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage, |
| 6805 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6806 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6807 | mApp, subId, "getCellNetworkScanResults"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6808 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 6809 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 6810 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 6811 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6812 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6813 | .setCallingPid(Binder.getCallingPid()) |
| 6814 | .setCallingUid(Binder.getCallingUid()) |
| 6815 | .setMethod("getCellNetworkScanResults") |
| 6816 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
Hall Liu | c4a3e42 | 2020-05-26 17:18:03 -0700 | [diff] [blame] | 6817 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 6818 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6819 | .build()); |
| 6820 | switch (locationResult) { |
| 6821 | case DENIED_HARD: |
| 6822 | throw new SecurityException("Not allowed to access scan results -- location"); |
| 6823 | case DENIED_SOFT: |
| 6824 | return null; |
| 6825 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6826 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6827 | long identity = Binder.clearCallingIdentity(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6828 | try { |
| 6829 | if (DBG) log("getCellNetworkScanResults: subId " + subId); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6830 | return (CellNetworkScanResult) sendRequest( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6831 | CMD_PERFORM_NETWORK_SCAN, null, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6832 | } finally { |
| 6833 | Binder.restoreCallingIdentity(identity); |
| 6834 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6835 | } |
| 6836 | |
| 6837 | /** |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6838 | * Get the call forwarding info, given the call forwarding reason. |
| 6839 | */ |
| 6840 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6841 | public void getCallForwarding(int subId, int callForwardingReason, |
| 6842 | ICallForwardingInfoCallback callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6843 | enforceReadPrivilegedPermission("getCallForwarding"); |
| 6844 | long identity = Binder.clearCallingIdentity(); |
| 6845 | try { |
| 6846 | if (DBG) { |
| 6847 | log("getCallForwarding: subId " + subId |
| 6848 | + " callForwardingReason" + callForwardingReason); |
| 6849 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6850 | |
| 6851 | Phone phone = getPhone(subId); |
| 6852 | if (phone == null) { |
| 6853 | try { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 6854 | callback.onError( |
| 6855 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6856 | } catch (RemoteException e) { |
| 6857 | // ignore |
| 6858 | } |
| 6859 | return; |
| 6860 | } |
| 6861 | |
| 6862 | Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create( |
| 6863 | callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() { |
| 6864 | @Override |
| 6865 | public void onCallForwardingInfoAvailable(CallForwardingInfo info) { |
| 6866 | try { |
| 6867 | callback.onCallForwardingInfoAvailable(info); |
| 6868 | } catch (RemoteException e) { |
| 6869 | // ignore |
| 6870 | } |
| 6871 | } |
| 6872 | |
| 6873 | @Override |
| 6874 | public void onError(int error) { |
| 6875 | try { |
| 6876 | callback.onError(error); |
| 6877 | } catch (RemoteException e) { |
| 6878 | // ignore |
| 6879 | } |
| 6880 | } |
| 6881 | }); |
| 6882 | sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6883 | } finally { |
| 6884 | Binder.restoreCallingIdentity(identity); |
| 6885 | } |
| 6886 | } |
| 6887 | |
| 6888 | /** |
| 6889 | * Sets the voice call forwarding info including status (enable/disable), call forwarding |
| 6890 | * reason, the number to forward, and the timeout before the forwarding is attempted. |
| 6891 | */ |
| 6892 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6893 | public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo, |
| 6894 | IIntegerConsumer callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6895 | enforceModifyPermission(); |
| 6896 | long identity = Binder.clearCallingIdentity(); |
| 6897 | try { |
| 6898 | if (DBG) { |
| 6899 | log("setCallForwarding: subId " + subId |
| 6900 | + " callForwardingInfo" + callForwardingInfo); |
| 6901 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6902 | |
| 6903 | Phone phone = getPhone(subId); |
| 6904 | if (phone == null) { |
| 6905 | try { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 6906 | callback.accept( |
| 6907 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6908 | } catch (RemoteException e) { |
| 6909 | // ignore |
| 6910 | } |
| 6911 | return; |
| 6912 | } |
| 6913 | |
| 6914 | Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo, |
| 6915 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 6916 | |
| 6917 | sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6918 | } finally { |
| 6919 | Binder.restoreCallingIdentity(identity); |
| 6920 | } |
| 6921 | } |
| 6922 | |
| 6923 | /** |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6924 | * Get the call waiting status for a subId. |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6925 | */ |
| 6926 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6927 | public void getCallWaitingStatus(int subId, IIntegerConsumer callback) { |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6928 | enforceReadPrivilegedPermission("getCallWaitingStatus"); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6929 | long identity = Binder.clearCallingIdentity(); |
| 6930 | try { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6931 | Phone phone = getPhone(subId); |
| 6932 | if (phone == null) { |
| 6933 | try { |
| 6934 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 6935 | } catch (RemoteException e) { |
| 6936 | // ignore |
| 6937 | } |
| 6938 | return; |
| 6939 | } |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6940 | CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext()); |
| 6941 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 6942 | boolean requireUssd = c.getBoolean( |
| 6943 | CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6944 | |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6945 | if (DBG) log("getCallWaitingStatus: subId " + subId); |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6946 | if (requireUssd) { |
| 6947 | CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(), |
| 6948 | getSubscriptionCarrierId(subId)); |
| 6949 | String newUssdCommand = ""; |
| 6950 | try { |
| 6951 | newUssdCommand = carrierXmlParser.getFeature( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6952 | CarrierXmlParser.FEATURE_CALL_WAITING) |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6953 | .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null); |
| 6954 | } catch (NullPointerException e) { |
| 6955 | loge("Failed to generate USSD number" + e); |
| 6956 | } |
| 6957 | ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver( |
| 6958 | mMainThreadHandler, callback, carrierXmlParser, |
| 6959 | CarrierXmlParser.SsEntry.SSAction.QUERY); |
| 6960 | final String ussdCommand = newUssdCommand; |
| 6961 | Executors.newSingleThreadExecutor().execute(() -> { |
| 6962 | handleUssdRequest(subId, ussdCommand, wrappedCallback); |
| 6963 | }); |
| 6964 | } else { |
| 6965 | Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException( |
| 6966 | callback::accept); |
| 6967 | sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null); |
| 6968 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6969 | } finally { |
| 6970 | Binder.restoreCallingIdentity(identity); |
| 6971 | } |
| 6972 | } |
| 6973 | |
| 6974 | /** |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6975 | * Sets whether call waiting is enabled for a given subId. |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6976 | */ |
| 6977 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6978 | public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6979 | enforceModifyPermission(); |
| 6980 | long identity = Binder.clearCallingIdentity(); |
| 6981 | try { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6982 | if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable); |
| 6983 | |
| 6984 | Phone phone = getPhone(subId); |
| 6985 | if (phone == null) { |
| 6986 | try { |
| 6987 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 6988 | } catch (RemoteException e) { |
| 6989 | // ignore |
| 6990 | } |
| 6991 | return; |
| 6992 | } |
| 6993 | |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6994 | CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext()); |
| 6995 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 6996 | boolean requireUssd = c.getBoolean( |
| 6997 | CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6998 | |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6999 | if (DBG) log("getCallWaitingStatus: subId " + subId); |
| 7000 | if (requireUssd) { |
| 7001 | CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(), |
| 7002 | getSubscriptionCarrierId(subId)); |
| 7003 | CarrierXmlParser.SsEntry.SSAction ssAction = |
| 7004 | enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE |
| 7005 | : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE; |
| 7006 | String newUssdCommand = ""; |
| 7007 | try { |
| 7008 | newUssdCommand = carrierXmlParser.getFeature( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 7009 | CarrierXmlParser.FEATURE_CALL_WAITING) |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 7010 | .makeCommand(ssAction, null); |
| 7011 | } catch (NullPointerException e) { |
| 7012 | loge("Failed to generate USSD number" + e); |
| 7013 | } |
| 7014 | ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver( |
| 7015 | mMainThreadHandler, callback, carrierXmlParser, ssAction); |
| 7016 | final String ussdCommand = newUssdCommand; |
| 7017 | Executors.newSingleThreadExecutor().execute(() -> { |
| 7018 | handleUssdRequest(subId, ussdCommand, wrappedCallback); |
| 7019 | }); |
| 7020 | } else { |
| 7021 | Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable, |
| 7022 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 7023 | |
| 7024 | sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null); |
| 7025 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 7026 | } finally { |
| 7027 | Binder.restoreCallingIdentity(identity); |
| 7028 | } |
| 7029 | } |
| 7030 | |
| 7031 | /** |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 7032 | * Starts a new network scan and returns the id of this scan. |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 7033 | * |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 7034 | * @param subId id of the subscription |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 7035 | * @param renounceFineLocationAccess Set this to true if the caller would not like to receive |
| 7036 | * location related information which will be sent if the caller already possess |
| 7037 | * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 7038 | * @param request contains the radio access networks with bands/channels to scan |
| 7039 | * @param messenger callback messenger for scan results or errors |
| 7040 | * @param binder for the purpose of auto clean when the user thread crashes |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 7041 | * @return the id of the requested scan which can be used to stop the scan. |
| 7042 | */ |
| 7043 | @Override |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 7044 | public int requestNetworkScan(int subId, boolean renounceFineLocationAccess, |
| 7045 | NetworkScanRequest request, Messenger messenger, |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 7046 | IBinder binder, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7047 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7048 | mApp, subId, "requestNetworkScan"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7049 | LocationAccessPolicy.LocationPermissionResult locationResult = |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 7050 | LocationAccessPolicy.LocationPermissionResult.DENIED_HARD; |
| 7051 | if (!renounceFineLocationAccess) { |
| 7052 | locationResult = LocationAccessPolicy.checkLocationPermission(mApp, |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 7053 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 7054 | .setCallingPackage(callingPackage) |
| 7055 | .setCallingFeatureId(callingFeatureId) |
| 7056 | .setCallingPid(Binder.getCallingPid()) |
| 7057 | .setCallingUid(Binder.getCallingUid()) |
| 7058 | .setMethod("requestNetworkScan") |
| 7059 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 7060 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 7061 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 7062 | .build()); |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 7063 | } |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 7064 | if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) { |
Nathan Harold | 1c11dba | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 7065 | SecurityException e = checkNetworkRequestForSanitizedLocationAccess( |
| 7066 | request, subId, callingPackage); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 7067 | if (e != null) { |
| 7068 | if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) { |
| 7069 | throw e; |
| 7070 | } else { |
Hall Liu | 0e5abaf | 2019-04-04 01:25:30 -0700 | [diff] [blame] | 7071 | loge(e.getMessage()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 7072 | return TelephonyScanManager.INVALID_SCAN_ID; |
| 7073 | } |
| 7074 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7075 | } |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 7076 | int callingUid = Binder.getCallingUid(); |
| 7077 | int callingPid = Binder.getCallingPid(); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 7078 | final long identity = Binder.clearCallingIdentity(); |
| 7079 | try { |
| 7080 | return mNetworkScanRequestTracker.startNetworkScan( |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 7081 | renounceFineLocationAccess, request, messenger, binder, getPhone(subId), |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 7082 | callingUid, callingPid, callingPackage); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 7083 | } finally { |
| 7084 | Binder.restoreCallingIdentity(identity); |
| 7085 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 7086 | } |
| 7087 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 7088 | private SecurityException checkNetworkRequestForSanitizedLocationAccess( |
Nathan Harold | 1c11dba | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 7089 | NetworkScanRequest request, int subId, String callingPackage) { |
Rambo Wang | 3dee30a | 2022-10-20 16:52:29 +0000 | [diff] [blame] | 7090 | boolean hasCarrierPriv; |
| 7091 | final long identity = Binder.clearCallingIdentity(); |
| 7092 | try { |
| 7093 | hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage) |
| 7094 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 7095 | } finally { |
| 7096 | Binder.restoreCallingIdentity(identity); |
| 7097 | } |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 7098 | boolean hasNetworkScanPermission = |
| 7099 | mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN) |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 7100 | == PERMISSION_GRANTED; |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 7101 | |
| 7102 | if (!hasCarrierPriv && !hasNetworkScanPermission) { |
| 7103 | return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed" |
| 7104 | + " for network scans without location access."); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 7105 | } |
| 7106 | |
| 7107 | if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) { |
| 7108 | for (RadioAccessSpecifier ras : request.getSpecifiers()) { |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 7109 | if (ras.getChannels() != null && ras.getChannels().length > 0) { |
| 7110 | return new SecurityException("Specific channels must not be" |
| 7111 | + " scanned without location access."); |
| 7112 | } |
| 7113 | } |
| 7114 | } |
| 7115 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 7116 | return null; |
| 7117 | } |
| 7118 | |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 7119 | /** |
| 7120 | * Stops an existing network scan with the given scanId. |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 7121 | * |
| 7122 | * @param subId id of the subscription |
| 7123 | * @param scanId id of the scan that needs to be stopped |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 7124 | */ |
| 7125 | @Override |
| 7126 | public void stopNetworkScan(int subId, int scanId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7127 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7128 | mApp, subId, "stopNetworkScan"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7129 | |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 7130 | int callingUid = Binder.getCallingUid(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7131 | final long identity = Binder.clearCallingIdentity(); |
| 7132 | try { |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 7133 | mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7134 | } finally { |
| 7135 | Binder.restoreCallingIdentity(identity); |
| 7136 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 7137 | } |
| 7138 | |
| 7139 | /** |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7140 | * Get the allowed network types bitmask. |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 7141 | * |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7142 | * @return the allowed network types bitmask, defined in RILConstants.java. |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 7143 | */ |
| 7144 | @Override |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7145 | public int getAllowedNetworkTypesBitmask(int subId) { |
Pengquan Meng | a4009cb | 2018-12-20 11:00:24 -0800 | [diff] [blame] | 7146 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 7147 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7148 | mApp, subId, "getAllowedNetworkTypesBitmask"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7149 | |
| 7150 | final long identity = Binder.clearCallingIdentity(); |
| 7151 | try { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7152 | if (DBG) log("getAllowedNetworkTypesBitmask"); |
| 7153 | int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId); |
| 7154 | int networkTypesBitmask = (result != null ? result[0] : -1); |
| 7155 | if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask); |
| 7156 | return networkTypesBitmask; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7157 | } finally { |
| 7158 | Binder.restoreCallingIdentity(identity); |
| 7159 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 7160 | } |
| 7161 | |
| 7162 | /** |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 7163 | * Get the allowed network types for certain reason. |
| 7164 | * |
| 7165 | * @param subId the id of the subscription. |
| 7166 | * @param reason the reason the allowed network type change is taking place |
| 7167 | * @return the allowed network types. |
| 7168 | */ |
| 7169 | @Override |
| 7170 | public long getAllowedNetworkTypesForReason(int subId, |
| 7171 | @TelephonyManager.AllowedNetworkTypesReason int reason) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 7172 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 7173 | mApp, subId, "getAllowedNetworkTypesForReason"); |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 7174 | final long identity = Binder.clearCallingIdentity(); |
| 7175 | try { |
| 7176 | return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason); |
| 7177 | } finally { |
| 7178 | Binder.restoreCallingIdentity(identity); |
| 7179 | } |
| 7180 | } |
| 7181 | |
| 7182 | /** |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 7183 | * Enable/Disable E-UTRA-NR Dual Connectivity |
| 7184 | * @param subId subscription id of the sim card |
| 7185 | * @param nrDualConnectivityState expected NR dual connectivity state |
| 7186 | * This can be passed following states |
| 7187 | * <ol> |
| 7188 | * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE} |
| 7189 | * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE} |
| 7190 | * <li>Disable NR dual connectivity and force secondary cell to be released |
| 7191 | * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE} |
| 7192 | * </ol> |
| 7193 | * @return operation result. |
| 7194 | */ |
| 7195 | @Override |
| 7196 | public int setNrDualConnectivityState(int subId, |
| 7197 | @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) { |
| 7198 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7199 | mApp, subId, "enableNRDualConnectivity"); |
Sooraj Sasindran | 0e4e00a | 2021-03-16 18:02:32 -0700 | [diff] [blame] | 7200 | if (!isRadioInterfaceCapabilitySupported( |
Sooraj Sasindran | dfd595b | 2021-03-11 17:38:13 -0800 | [diff] [blame] | 7201 | TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) { |
| 7202 | return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED; |
| 7203 | } |
| 7204 | |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 7205 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 7206 | final long identity = Binder.clearCallingIdentity(); |
| 7207 | try { |
| 7208 | int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY, |
| 7209 | nrDualConnectivityState, subId, |
| 7210 | workSource); |
| 7211 | if (DBG) log("enableNRDualConnectivity result: " + result); |
| 7212 | return result; |
| 7213 | } finally { |
| 7214 | Binder.restoreCallingIdentity(identity); |
| 7215 | } |
| 7216 | } |
| 7217 | |
| 7218 | /** |
| 7219 | * Is E-UTRA-NR Dual Connectivity enabled |
| 7220 | * @return true if dual connectivity is enabled else false |
| 7221 | */ |
| 7222 | @Override |
| 7223 | public boolean isNrDualConnectivityEnabled(int subId) { |
| 7224 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 7225 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 7226 | mApp, subId, "isNRDualConnectivityEnabled"); |
Sooraj Sasindran | 0e4e00a | 2021-03-16 18:02:32 -0700 | [diff] [blame] | 7227 | if (!isRadioInterfaceCapabilitySupported( |
Sooraj Sasindran | dfd595b | 2021-03-11 17:38:13 -0800 | [diff] [blame] | 7228 | TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) { |
| 7229 | return false; |
| 7230 | } |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 7231 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 7232 | final long identity = Binder.clearCallingIdentity(); |
| 7233 | try { |
| 7234 | boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED, |
| 7235 | null, subId, workSource); |
| 7236 | if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled); |
| 7237 | return isEnabled; |
| 7238 | } finally { |
| 7239 | Binder.restoreCallingIdentity(identity); |
| 7240 | } |
| 7241 | } |
| 7242 | |
| 7243 | /** |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 7244 | * Set the allowed network types of the device and |
| 7245 | * provide the reason triggering the allowed network change. |
| 7246 | * |
| 7247 | * @param subId the id of the subscription. |
| 7248 | * @param reason the reason the allowed network type change is taking place |
| 7249 | * @param allowedNetworkTypes the allowed network types. |
| 7250 | * @return true on success; false on any failure. |
| 7251 | */ |
| 7252 | @Override |
| 7253 | public boolean setAllowedNetworkTypesForReason(int subId, |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7254 | @TelephonyManager.AllowedNetworkTypesReason int reason, |
| 7255 | @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) { |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 7256 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7257 | mApp, subId, "setAllowedNetworkTypesForReason"); |
Gil Cukierman | 1d3d375 | 2022-10-03 21:31:33 +0000 | [diff] [blame] | 7258 | // If the caller only has carrier privileges, then they should not be able to override |
| 7259 | // any network types which were set for security reasons. |
| 7260 | if (mApp.checkCallingOrSelfPermission(Manifest.permission.MODIFY_PHONE_STATE) |
| 7261 | != PERMISSION_GRANTED |
Gil Cukierman | 2a8f48b | 2023-01-26 20:26:20 +0000 | [diff] [blame] | 7262 | && reason == TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_ENABLE_2G) { |
Gil Cukierman | 1d3d375 | 2022-10-03 21:31:33 +0000 | [diff] [blame] | 7263 | throw new SecurityException( |
| 7264 | "setAllowedNetworkTypesForReason cannot be called with carrier privileges for" |
Gil Cukierman | 2a8f48b | 2023-01-26 20:26:20 +0000 | [diff] [blame] | 7265 | + " reason " + reason); |
Gil Cukierman | 1d3d375 | 2022-10-03 21:31:33 +0000 | [diff] [blame] | 7266 | } |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7267 | if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) { |
Jack Yu | 5b49433 | 2023-01-23 18:18:04 +0000 | [diff] [blame] | 7268 | loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason); |
SongFerngWang | 7ffc273 | 2021-04-15 19:46:33 +0800 | [diff] [blame] | 7269 | return false; |
| 7270 | } |
| 7271 | if (!SubscriptionManager.isUsableSubscriptionId(subId)) { |
| 7272 | loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId); |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7273 | return false; |
| 7274 | } |
| 7275 | |
Jack Yu | 5b49433 | 2023-01-23 18:18:04 +0000 | [diff] [blame] | 7276 | log("setAllowedNetworkTypesForReason: subId=" + subId + ", reason=" + reason + " value: " |
| 7277 | + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes)); |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 7278 | |
Jack Yu | e37dd26 | 2022-12-16 11:53:37 -0800 | [diff] [blame] | 7279 | Phone phone = getPhone(subId); |
| 7280 | if (phone == null) { |
| 7281 | return false; |
| 7282 | } |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 7283 | |
Jack Yu | e37dd26 | 2022-12-16 11:53:37 -0800 | [diff] [blame] | 7284 | if (allowedNetworkTypes == phone.getAllowedNetworkTypes(reason)) { |
Jack Yu | 5b49433 | 2023-01-23 18:18:04 +0000 | [diff] [blame] | 7285 | log("setAllowedNetworkTypesForReason: " + reason + "does not change value"); |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 7286 | return true; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7287 | } |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 7288 | |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 7289 | final long identity = Binder.clearCallingIdentity(); |
| 7290 | try { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7291 | Boolean success = (Boolean) sendRequest( |
| 7292 | CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON, |
| 7293 | new Pair<Integer, Long>(reason, allowedNetworkTypes), subId); |
| 7294 | |
| 7295 | if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail")); |
| 7296 | return success; |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 7297 | } finally { |
| 7298 | Binder.restoreCallingIdentity(identity); |
| 7299 | } |
| 7300 | } |
| 7301 | |
| 7302 | /** |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 7303 | * Check whether DUN APN is required for tethering with subId. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 7304 | * |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 7305 | * @param subId the id of the subscription to require tethering. |
Amit Mahajan | fe58cdf | 2017-07-11 12:01:53 -0700 | [diff] [blame] | 7306 | * @return {@code true} if DUN APN is required for tethering. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 7307 | * @hide |
| 7308 | */ |
| 7309 | @Override |
SongFerngWang | f08d812 | 2019-11-15 14:58:44 +0800 | [diff] [blame] | 7310 | public boolean isTetheringApnRequiredForSubscriber(int subId) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7311 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7312 | final long identity = Binder.clearCallingIdentity(); |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 7313 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7314 | try { |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 7315 | if (phone != null) { |
| 7316 | return phone.hasMatchedTetherApnSetting(); |
| 7317 | } else { |
| 7318 | return false; |
| 7319 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7320 | } finally { |
| 7321 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 7322 | } |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 7323 | } |
| 7324 | |
| 7325 | /** |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 7326 | * Get the user enabled state of Mobile Data. |
| 7327 | * |
| 7328 | * TODO: remove and use isUserDataEnabled. |
| 7329 | * This can't be removed now because some vendor codes |
| 7330 | * calls through ITelephony directly while they should |
| 7331 | * use TelephonyManager. |
| 7332 | * |
| 7333 | * @return true on enabled |
| 7334 | */ |
| 7335 | @Override |
| 7336 | public boolean getDataEnabled(int subId) { |
| 7337 | return isUserDataEnabled(subId); |
| 7338 | } |
| 7339 | |
| 7340 | /** |
| 7341 | * Get whether mobile data is enabled per user setting. |
| 7342 | * |
| 7343 | * There are other factors deciding whether mobile data is actually enabled, but they are |
| 7344 | * not considered here. See {@link #isDataEnabled(int)} for more details. |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 7345 | * |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7346 | * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE |
| 7347 | * or carrier privileges. |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 7348 | * |
| 7349 | * @return {@code true} if data is enabled else {@code false} |
| 7350 | */ |
| 7351 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 7352 | public boolean isUserDataEnabled(int subId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7353 | String functionName = "isUserDataEnabled"; |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 7354 | try { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7355 | try { |
| 7356 | mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE, |
| 7357 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7358 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7359 | mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName); |
| 7360 | } |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7361 | } catch (SecurityException e) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7362 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7363 | mApp, subId, functionName); |
| 7364 | |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 7365 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7366 | |
| 7367 | final long identity = Binder.clearCallingIdentity(); |
| 7368 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 7369 | int phoneId = SubscriptionManager.getPhoneId(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7370 | if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 7371 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 7372 | if (phone != null) { |
| 7373 | boolean retVal = phone.isUserDataEnabled(); |
| 7374 | if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 7375 | return retVal; |
| 7376 | } else { |
| 7377 | if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 7378 | return false; |
| 7379 | } |
| 7380 | } finally { |
| 7381 | Binder.restoreCallingIdentity(identity); |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 7382 | } |
| 7383 | } |
| 7384 | |
| 7385 | /** |
Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 7386 | * Checks if the device is capable of mobile data by considering whether whether the |
| 7387 | * user has enabled mobile data, whether the carrier has enabled mobile data, and |
| 7388 | * whether the network policy allows data connections. |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 7389 | * |
Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 7390 | * @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] | 7391 | */ |
| 7392 | @Override |
| 7393 | public boolean isDataEnabled(int subId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7394 | String functionName = "isDataEnabled"; |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7395 | try { |
| 7396 | try { |
| 7397 | mApp.enforceCallingOrSelfPermission( |
| 7398 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7399 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7400 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7401 | try { |
| 7402 | mApp.enforceCallingOrSelfPermission( |
| 7403 | android.Manifest.permission.READ_PHONE_STATE, |
| 7404 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7405 | } catch (SecurityException e2) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7406 | mApp.enforceCallingOrSelfPermission( |
| 7407 | permission.READ_BASIC_PHONE_STATE, functionName); |
| 7408 | } |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7409 | } |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7410 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7411 | enforceReadPrivilegedPermission(functionName); |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7412 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7413 | |
| 7414 | final long identity = Binder.clearCallingIdentity(); |
| 7415 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 7416 | int phoneId = SubscriptionManager.getPhoneId(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7417 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 7418 | if (phone != null) { |
Sarah Chin | e04784a | 2022-10-31 20:32:34 -0700 | [diff] [blame] | 7419 | boolean retVal = phone.getDataSettingsManager().isDataEnabled(); |
Jack Yu | 4ad64e5 | 2021-12-03 14:23:53 -0800 | [diff] [blame] | 7420 | if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7421 | return retVal; |
| 7422 | } else { |
| 7423 | if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 7424 | return false; |
| 7425 | } |
| 7426 | } finally { |
| 7427 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 7428 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 7429 | } |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 7430 | |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7431 | /** |
| 7432 | * Check if data is enabled for a specific reason |
| 7433 | * @param subId Subscription index |
| 7434 | * @param reason the reason the data enable change is taking place |
| 7435 | * @return {@code true} if the overall data is enabled; {@code false} if not. |
| 7436 | */ |
| 7437 | @Override |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7438 | public boolean isDataEnabledForReason(int subId, |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7439 | @TelephonyManager.DataEnabledReason int reason) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7440 | String functionName = "isDataEnabledForReason"; |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7441 | try { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7442 | try { |
| 7443 | mApp.enforceCallingOrSelfPermission( |
| 7444 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 7445 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7446 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7447 | mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE, |
| 7448 | functionName); |
| 7449 | } |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7450 | } catch (SecurityException e) { |
Sooraj Sasindran | 0d909a0 | 2021-11-08 12:01:16 -0800 | [diff] [blame] | 7451 | try { |
| 7452 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7453 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7454 | } catch (SecurityException e2) { |
Sooraj Sasindran | 0d909a0 | 2021-11-08 12:01:16 -0800 | [diff] [blame] | 7455 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7456 | mApp, subId, functionName); |
Sooraj Sasindran | 0d909a0 | 2021-11-08 12:01:16 -0800 | [diff] [blame] | 7457 | } |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7458 | } |
| 7459 | |
| 7460 | |
| 7461 | final long identity = Binder.clearCallingIdentity(); |
| 7462 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 7463 | int phoneId = SubscriptionManager.getPhoneId(subId); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7464 | if (DBG) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7465 | log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7466 | + " reason=" + reason); |
| 7467 | } |
| 7468 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 7469 | if (phone != null) { |
| 7470 | boolean retVal; |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 7471 | retVal = phone.getDataSettingsManager().isDataEnabledForReason(reason); |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7472 | if (DBG) log("isDataEnabledForReason: retVal=" + retVal); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7473 | return retVal; |
| 7474 | } else { |
| 7475 | if (DBG) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7476 | loge("isDataEnabledForReason: no phone subId=" |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7477 | + subId + " retVal=false"); |
| 7478 | } |
| 7479 | return false; |
| 7480 | } |
| 7481 | } finally { |
| 7482 | Binder.restoreCallingIdentity(identity); |
| 7483 | } |
| 7484 | } |
| 7485 | |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 7486 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7487 | public int getCarrierPrivilegeStatus(int subId) { |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7488 | // No permission needed; this only lets the caller inspect their own status. |
| 7489 | return getCarrierPrivilegeStatusForUidWithPermission(subId, Binder.getCallingUid()); |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 7490 | } |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 7491 | |
| 7492 | @Override |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7493 | public int getCarrierPrivilegeStatusForUid(int subId, int uid) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 7494 | enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid"); |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7495 | return getCarrierPrivilegeStatusForUidWithPermission(subId, uid); |
| 7496 | } |
| 7497 | |
| 7498 | private int getCarrierPrivilegeStatusForUidWithPermission(int subId, int uid) { |
| 7499 | Phone phone = getPhone(subId); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7500 | if (phone == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 7501 | loge("getCarrierPrivilegeStatusForUid: Invalid subId"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7502 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 7503 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7504 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7505 | if (cpt == null) { |
| 7506 | loge("getCarrierPrivilegeStatusForUid: No CarrierPrivilegesTracker"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7507 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 7508 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7509 | return cpt.getCarrierPrivilegeStatusForUid(uid); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7510 | } |
| 7511 | |
| 7512 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7513 | public int checkCarrierPrivilegesForPackage(int subId, String pkgName) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 7514 | enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage"); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7515 | if (TextUtils.isEmpty(pkgName)) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 7516 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7517 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7518 | Phone phone = getPhone(subId); |
| 7519 | if (phone == null) { |
| 7520 | loge("checkCarrierPrivilegesForPackage: Invalid subId"); |
| 7521 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 7522 | } |
| 7523 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7524 | if (cpt == null) { |
| 7525 | loge("checkCarrierPrivilegesForPackage: No CarrierPrivilegesTracker"); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 7526 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 7527 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7528 | return cpt.getCarrierPrivilegeStatusForPackage(pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 7529 | } |
| 7530 | |
| 7531 | @Override |
| 7532 | public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) { |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7533 | enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackageAnyPhone"); |
Rambo Wang | e7209ce | 2022-02-23 13:41:02 -0800 | [diff] [blame] | 7534 | return checkCarrierPrivilegesForPackageAnyPhoneWithPermission(pkgName); |
| 7535 | } |
| 7536 | |
| 7537 | private int checkCarrierPrivilegesForPackageAnyPhoneWithPermission(String pkgName) { |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7538 | if (TextUtils.isEmpty(pkgName)) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 7539 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7540 | } |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 7541 | int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7542 | for (int phoneId = 0; phoneId < TelephonyManager.getDefault().getPhoneCount(); phoneId++) { |
| 7543 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 7544 | if (phone == null) { |
| 7545 | continue; |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 7546 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7547 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7548 | if (cpt == null) { |
| 7549 | continue; |
| 7550 | } |
| 7551 | result = cpt.getCarrierPrivilegeStatusForPackage(pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 7552 | if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 7553 | break; |
| 7554 | } |
| 7555 | } |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 7556 | return result; |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 7557 | } |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 7558 | |
| 7559 | @Override |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 7560 | public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 7561 | enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone"); |
Rambo Wang | 8a247eb | 2022-02-08 21:11:18 +0000 | [diff] [blame] | 7562 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 7563 | if (phone == null) { |
| 7564 | return Collections.emptyList(); |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 7565 | } |
Rambo Wang | 8a247eb | 2022-02-08 21:11:18 +0000 | [diff] [blame] | 7566 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7567 | if (cpt == null) { |
| 7568 | return Collections.emptyList(); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 7569 | } |
Rambo Wang | 8a247eb | 2022-02-08 21:11:18 +0000 | [diff] [blame] | 7570 | return cpt.getCarrierPackageNamesForIntent(intent); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 7571 | } |
| 7572 | |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 7573 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7574 | public List<String> getPackagesWithCarrierPrivileges(int phoneId) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 7575 | enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges"); |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7576 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 7577 | if (phone == null) { |
| 7578 | return Collections.emptyList(); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 7579 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7580 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7581 | if (cpt == null) { |
| 7582 | return Collections.emptyList(); |
| 7583 | } |
| 7584 | return new ArrayList<>(cpt.getPackagesWithCarrierPrivileges()); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 7585 | } |
| 7586 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7587 | @Override |
| 7588 | public List<String> getPackagesWithCarrierPrivilegesForAllPhones() { |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 7589 | enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones"); |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7590 | Set<String> privilegedPackages = new ArraySet<>(); |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 7591 | final long identity = Binder.clearCallingIdentity(); |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 7592 | try { |
| 7593 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 7594 | privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i)); |
| 7595 | } |
| 7596 | } finally { |
| 7597 | Binder.restoreCallingIdentity(identity); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7598 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7599 | return new ArrayList<>(privilegedPackages); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7600 | } |
| 7601 | |
Rambo Wang | 6812ffb | 2022-03-15 16:54:17 -0700 | [diff] [blame] | 7602 | @Override |
| 7603 | public @Nullable String getCarrierServicePackageNameForLogicalSlot(int logicalSlotIndex) { |
| 7604 | enforceReadPrivilegedPermission("getCarrierServicePackageNameForLogicalSlot"); |
| 7605 | |
| 7606 | final Phone phone = PhoneFactory.getPhone(logicalSlotIndex); |
| 7607 | if (phone == null) { |
| 7608 | return null; |
| 7609 | } |
| 7610 | final CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7611 | if (cpt == null) { |
| 7612 | return null; |
| 7613 | } |
| 7614 | return cpt.getCarrierServicePackageName(); |
| 7615 | } |
| 7616 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 7617 | private String getIccId(int subId) { |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 7618 | final Phone phone = getPhone(subId); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 7619 | UiccPort port = phone == null ? null : phone.getUiccPort(); |
| 7620 | if (port == null) { |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7621 | return null; |
| 7622 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 7623 | String iccId = port.getIccId(); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7624 | if (TextUtils.isEmpty(iccId)) { |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7625 | return null; |
| 7626 | } |
| 7627 | return iccId; |
| 7628 | } |
| 7629 | |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 7630 | @Override |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 7631 | public void setCallComposerStatus(int subId, int status) { |
| 7632 | enforceModifyPermission(); |
| 7633 | |
| 7634 | final long identity = Binder.clearCallingIdentity(); |
| 7635 | try { |
| 7636 | Phone phone = getPhone(subId); |
| 7637 | if (phone != null) { |
| 7638 | Phone defaultPhone = phone.getImsPhone(); |
| 7639 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 7640 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 7641 | imsPhone.setCallComposerStatus(status); |
Shuo Qian | 284ae75 | 2020-12-22 19:10:14 -0800 | [diff] [blame] | 7642 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| 7643 | .updateImsServiceConfig(); |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 7644 | } |
| 7645 | } |
Shuo Qian | 284ae75 | 2020-12-22 19:10:14 -0800 | [diff] [blame] | 7646 | } catch (ImsException e) { |
| 7647 | throw new ServiceSpecificException(e.getCode()); |
| 7648 | } finally { |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 7649 | Binder.restoreCallingIdentity(identity); |
| 7650 | } |
| 7651 | } |
| 7652 | |
| 7653 | @Override |
| 7654 | public int getCallComposerStatus(int subId) { |
| 7655 | enforceReadPrivilegedPermission("getCallComposerStatus"); |
| 7656 | |
| 7657 | final long identity = Binder.clearCallingIdentity(); |
| 7658 | try { |
| 7659 | Phone phone = getPhone(subId); |
| 7660 | if (phone != null) { |
| 7661 | Phone defaultPhone = phone.getImsPhone(); |
| 7662 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 7663 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 7664 | return imsPhone.getCallComposerStatus(); |
| 7665 | } |
| 7666 | } |
| 7667 | } finally { |
| 7668 | Binder.restoreCallingIdentity(identity); |
| 7669 | } |
| 7670 | return TelephonyManager.CALL_COMPOSER_STATUS_OFF; |
| 7671 | } |
| 7672 | |
| 7673 | @Override |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7674 | public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag, |
| 7675 | String number) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 7676 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7677 | subId, "setLine1NumberForDisplayForSubscriber"); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7678 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7679 | final long identity = Binder.clearCallingIdentity(); |
| 7680 | try { |
| 7681 | final String iccId = getIccId(subId); |
| 7682 | final Phone phone = getPhone(subId); |
| 7683 | if (phone == null) { |
| 7684 | return false; |
| 7685 | } |
| 7686 | final String subscriberId = phone.getSubscriberId(); |
| 7687 | |
| 7688 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 7689 | Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId=" |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7690 | + subscriberId + " to " + number); |
| 7691 | } |
| 7692 | |
| 7693 | if (TextUtils.isEmpty(iccId)) { |
| 7694 | return false; |
| 7695 | } |
| 7696 | |
| 7697 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 7698 | |
| 7699 | final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 7700 | if (alphaTag == null) { |
| 7701 | editor.remove(alphaTagPrefKey); |
| 7702 | } else { |
| 7703 | editor.putString(alphaTagPrefKey, alphaTag); |
| 7704 | } |
| 7705 | |
| 7706 | // Record both the line number and IMSI for this ICCID, since we need to |
| 7707 | // track all merged IMSIs based on line number |
| 7708 | final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 7709 | final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 7710 | if (number == null) { |
| 7711 | editor.remove(numberPrefKey); |
| 7712 | editor.remove(subscriberPrefKey); |
| 7713 | } else { |
| 7714 | editor.putString(numberPrefKey, number); |
| 7715 | editor.putString(subscriberPrefKey, subscriberId); |
| 7716 | } |
| 7717 | |
| 7718 | editor.commit(); |
| 7719 | return true; |
| 7720 | } finally { |
| 7721 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 7722 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7723 | } |
| 7724 | |
| 7725 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7726 | public String getLine1NumberForDisplay(int subId, String callingPackage, |
| 7727 | String callingFeatureId) { |
Makoto Onuki | fee6934 | 2015-06-29 14:44:50 -0700 | [diff] [blame] | 7728 | // This is open to apps with WRITE_SMS. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7729 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7730 | mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) { |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 7731 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission"); |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 7732 | return null; |
| 7733 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7734 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7735 | final long identity = Binder.clearCallingIdentity(); |
| 7736 | try { |
| 7737 | String iccId = getIccId(subId); |
| 7738 | if (iccId != null) { |
| 7739 | String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 7740 | if (DBG_MERGE) { |
| 7741 | log("getLine1NumberForDisplay returning " |
| 7742 | + mTelephonySharedPreferences.getString(numberPrefKey, null)); |
| 7743 | } |
| 7744 | return mTelephonySharedPreferences.getString(numberPrefKey, null); |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 7745 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7746 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null"); |
| 7747 | return null; |
| 7748 | } finally { |
| 7749 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7750 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7751 | } |
| 7752 | |
| 7753 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7754 | public String getLine1AlphaTagForDisplay(int subId, String callingPackage, |
| 7755 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7756 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7757 | mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 7758 | return null; |
| 7759 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7760 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7761 | final long identity = Binder.clearCallingIdentity(); |
| 7762 | try { |
| 7763 | String iccId = getIccId(subId); |
| 7764 | if (iccId != null) { |
| 7765 | String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 7766 | return mTelephonySharedPreferences.getString(alphaTagPrefKey, null); |
| 7767 | } |
| 7768 | return null; |
| 7769 | } finally { |
| 7770 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7771 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7772 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 7773 | |
| 7774 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7775 | public String[] getMergedSubscriberIds(int subId, String callingPackage, |
| 7776 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7777 | // This API isn't public, so no need to provide a valid subscription ID - we're not worried |
| 7778 | // about carrier-privileged callers not having access. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7779 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7780 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7781 | callingFeatureId, "getMergedSubscriberIds")) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7782 | return null; |
| 7783 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7784 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 7785 | // Clear calling identity, when calling TelephonyManager, because callerUid must be |
| 7786 | // the process, where TelephonyManager was instantiated. |
| 7787 | // Otherwise AppOps check will fail. |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7788 | final long identity = Binder.clearCallingIdentity(); |
| 7789 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7790 | final Context context = mApp; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7791 | final TelephonyManager tele = TelephonyManager.from(context); |
| 7792 | final SubscriptionManager sub = SubscriptionManager.from(context); |
| 7793 | |
| 7794 | // Figure out what subscribers are currently active |
| 7795 | final ArraySet<String> activeSubscriberIds = new ArraySet<>(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7796 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 7797 | // Only consider subs which match the current subId |
| 7798 | // This logic can be simplified. See b/131189269 for progress. |
| 7799 | if (isActiveSubscription(subId)) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7800 | activeSubscriberIds.add(tele.getSubscriberId(subId)); |
| 7801 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7802 | |
| 7803 | // First pass, find a number override for an active subscriber |
| 7804 | String mergeNumber = null; |
| 7805 | final Map<String, ?> prefs = mTelephonySharedPreferences.getAll(); |
| 7806 | for (String key : prefs.keySet()) { |
| 7807 | if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) { |
| 7808 | final String subscriberId = (String) prefs.get(key); |
| 7809 | if (activeSubscriberIds.contains(subscriberId)) { |
| 7810 | final String iccId = key.substring( |
| 7811 | PREF_CARRIERS_SUBSCRIBER_PREFIX.length()); |
| 7812 | final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 7813 | mergeNumber = (String) prefs.get(numberKey); |
| 7814 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 7815 | Rlog.d(LOG_TAG, "Found line number " + mergeNumber |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7816 | + " for active subscriber " + subscriberId); |
| 7817 | } |
| 7818 | if (!TextUtils.isEmpty(mergeNumber)) { |
| 7819 | break; |
| 7820 | } |
| 7821 | } |
| 7822 | } |
| 7823 | } |
| 7824 | |
| 7825 | // Shortcut when no active merged subscribers |
| 7826 | if (TextUtils.isEmpty(mergeNumber)) { |
| 7827 | return null; |
| 7828 | } |
| 7829 | |
| 7830 | // Second pass, find all subscribers under that line override |
| 7831 | final ArraySet<String> result = new ArraySet<>(); |
| 7832 | for (String key : prefs.keySet()) { |
| 7833 | if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) { |
| 7834 | final String number = (String) prefs.get(key); |
| 7835 | if (mergeNumber.equals(number)) { |
| 7836 | final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length()); |
| 7837 | final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 7838 | final String subscriberId = (String) prefs.get(subscriberKey); |
| 7839 | if (!TextUtils.isEmpty(subscriberId)) { |
| 7840 | result.add(subscriberId); |
| 7841 | } |
| 7842 | } |
| 7843 | } |
| 7844 | } |
| 7845 | |
| 7846 | final String[] resultArray = result.toArray(new String[result.size()]); |
| 7847 | Arrays.sort(resultArray); |
| 7848 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 7849 | Rlog.d(LOG_TAG, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7850 | "Found subscribers " + Arrays.toString(resultArray) + " after merge"); |
| 7851 | } |
| 7852 | return resultArray; |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7853 | } finally { |
| 7854 | Binder.restoreCallingIdentity(identity); |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7855 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7856 | } |
| 7857 | |
| 7858 | @Override |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 7859 | public String[] getMergedImsisFromGroup(int subId, String callingPackage) { |
| 7860 | enforceReadPrivilegedPermission("getMergedImsisFromGroup"); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7861 | |
| 7862 | final long identity = Binder.clearCallingIdentity(); |
| 7863 | try { |
| 7864 | final TelephonyManager telephonyManager = mApp.getSystemService( |
| 7865 | TelephonyManager.class); |
| 7866 | String subscriberId = telephonyManager.getSubscriberId(subId); |
| 7867 | if (subscriberId == null) { |
| 7868 | if (DBG) { |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 7869 | log("getMergedImsisFromGroup can't find subscriberId for subId " |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7870 | + subId); |
| 7871 | } |
| 7872 | return null; |
| 7873 | } |
| 7874 | |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 7875 | ParcelUuid groupUuid; |
| 7876 | if (PhoneFactory.isSubscriptionManagerServiceEnabled()) { |
Jack Yu | fa8ed01 | 2023-02-11 15:42:28 -0800 | [diff] [blame] | 7877 | final SubscriptionInfo info = getSubscriptionManagerService() |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 7878 | .getSubscriptionInfo(subId); |
| 7879 | groupUuid = info.getGroupUuid(); |
| 7880 | } else { |
| 7881 | final SubscriptionInfo info = mSubscriptionController |
| 7882 | .getSubscriptionInfo(subId); |
| 7883 | groupUuid = info.getGroupUuid(); |
| 7884 | } |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7885 | // If it doesn't belong to any group, return just subscriberId of itself. |
| 7886 | if (groupUuid == null) { |
| 7887 | return new String[]{subscriberId}; |
| 7888 | } |
| 7889 | |
| 7890 | // Get all subscriberIds from the group. |
| 7891 | final List<String> mergedSubscriberIds = new ArrayList<>(); |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 7892 | List<SubscriptionInfo> groupInfos; |
| 7893 | if (PhoneFactory.isSubscriptionManagerServiceEnabled()) { |
Jack Yu | fa8ed01 | 2023-02-11 15:42:28 -0800 | [diff] [blame] | 7894 | groupInfos = getSubscriptionManagerService() |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 7895 | .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(), |
| 7896 | mApp.getAttributionTag()); |
| 7897 | } else { |
| 7898 | groupInfos = mSubscriptionController |
| 7899 | .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(), |
| 7900 | mApp.getAttributionTag()); |
| 7901 | } |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7902 | for (SubscriptionInfo subInfo : groupInfos) { |
| 7903 | subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId()); |
| 7904 | if (subscriberId != null) { |
| 7905 | mergedSubscriberIds.add(subscriberId); |
| 7906 | } |
| 7907 | } |
| 7908 | |
| 7909 | return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]); |
| 7910 | } finally { |
| 7911 | Binder.restoreCallingIdentity(identity); |
| 7912 | |
| 7913 | } |
| 7914 | } |
| 7915 | |
| 7916 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7917 | public boolean setOperatorBrandOverride(int subId, String brand) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 7918 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7919 | subId, "setOperatorBrandOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7920 | |
| 7921 | final long identity = Binder.clearCallingIdentity(); |
| 7922 | try { |
| 7923 | final Phone phone = getPhone(subId); |
| 7924 | return phone == null ? false : phone.setOperatorBrandOverride(brand); |
| 7925 | } finally { |
| 7926 | Binder.restoreCallingIdentity(identity); |
| 7927 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 7928 | } |
Steven Liu | 4bf01bc | 2014-07-17 11:05:29 -0500 | [diff] [blame] | 7929 | |
| 7930 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7931 | public boolean setRoamingOverride(int subId, List<String> gsmRoamingList, |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 7932 | List<String> gsmNonRoamingList, List<String> cdmaRoamingList, |
| 7933 | List<String> cdmaNonRoamingList) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 7934 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 7935 | mApp, subId, "setRoamingOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7936 | |
| 7937 | final long identity = Binder.clearCallingIdentity(); |
| 7938 | try { |
| 7939 | final Phone phone = getPhone(subId); |
| 7940 | if (phone == null) { |
| 7941 | return false; |
| 7942 | } |
| 7943 | return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList, |
| 7944 | cdmaNonRoamingList); |
| 7945 | } finally { |
| 7946 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7947 | } |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 7948 | } |
| 7949 | |
| 7950 | @Override |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 7951 | @Deprecated |
| 7952 | public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) { |
| 7953 | enforceModifyPermission(); |
| 7954 | |
| 7955 | int returnValue = 0; |
| 7956 | try { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7957 | AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 7958 | if(result.exception == null) { |
| 7959 | if (result.result != null) { |
| 7960 | byte[] responseData = (byte[])(result.result); |
| 7961 | if(responseData.length > oemResp.length) { |
| 7962 | Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " + |
| 7963 | responseData.length + "bytes. Buffer Size is " + |
| 7964 | oemResp.length + "bytes."); |
| 7965 | } |
| 7966 | System.arraycopy(responseData, 0, oemResp, 0, responseData.length); |
| 7967 | returnValue = responseData.length; |
| 7968 | } |
| 7969 | } else { |
| 7970 | CommandException ex = (CommandException) result.exception; |
| 7971 | returnValue = ex.getCommandError().ordinal(); |
| 7972 | if(returnValue > 0) returnValue *= -1; |
| 7973 | } |
| 7974 | } catch (RuntimeException e) { |
| 7975 | Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception"); |
| 7976 | returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal()); |
| 7977 | if(returnValue > 0) returnValue *= -1; |
| 7978 | } |
| 7979 | |
| 7980 | return returnValue; |
| 7981 | } |
| 7982 | |
| 7983 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 7984 | public int getRadioAccessFamily(int phoneId, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7985 | Phone phone = PhoneFactory.getPhone(phoneId); |
Shuo Qian | dee5340 | 2020-05-29 14:08:15 -0700 | [diff] [blame] | 7986 | try { |
| 7987 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 7988 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Shuo Qian | dee5340 | 2020-05-29 14:08:15 -0700 | [diff] [blame] | 7989 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 7990 | } catch (SecurityException e) { |
| 7991 | EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission"); |
| 7992 | throw e; |
| 7993 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7994 | int raf = RadioAccessFamily.RAF_UNKNOWN; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7995 | if (phone == null) { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7996 | return raf; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7997 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7998 | final long identity = Binder.clearCallingIdentity(); |
| 7999 | try { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 8000 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 8001 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 8002 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 8003 | raf = ProxyController.getInstance().getRadioAccessFamily(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8004 | } finally { |
| 8005 | Binder.restoreCallingIdentity(identity); |
| 8006 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 8007 | return raf; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 8008 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 8009 | |
| 8010 | @Override |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 8011 | public void uploadCallComposerPicture(int subscriptionId, String callingPackage, |
Hall Liu | e31bac6 | 2020-12-23 19:16:10 -0800 | [diff] [blame] | 8012 | String contentType, ParcelFileDescriptor fd, ResultReceiver callback) { |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 8013 | try { |
| 8014 | if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0), |
| 8015 | Binder.getCallingUid())) { |
Tyler Gunn | b87925a | 2021-06-10 14:54:27 -0700 | [diff] [blame] | 8016 | throw new SecurityException("Invalid package:" + callingPackage); |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 8017 | } |
| 8018 | } catch (PackageManager.NameNotFoundException e) { |
Tyler Gunn | b87925a | 2021-06-10 14:54:27 -0700 | [diff] [blame] | 8019 | throw new SecurityException("Invalid package:" + callingPackage); |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 8020 | } |
| 8021 | RoleManager rm = mApp.getSystemService(RoleManager.class); |
| 8022 | List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER); |
| 8023 | if (!dialerRoleHolders.contains(callingPackage)) { |
| 8024 | throw new SecurityException("App must be the dialer role holder to" |
| 8025 | + " upload a call composer pic"); |
| 8026 | } |
| 8027 | |
| 8028 | Executors.newSingleThreadExecutor().execute(() -> { |
| 8029 | ByteArrayOutputStream output = new ByteArrayOutputStream( |
| 8030 | (int) TelephonyManager.getMaximumCallComposerPictureSize()); |
| 8031 | InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd); |
| 8032 | boolean readUntilEnd = false; |
| 8033 | int totalBytesRead = 0; |
| 8034 | byte[] buffer = new byte[16 * 1024]; |
| 8035 | while (true) { |
| 8036 | int numRead; |
| 8037 | try { |
| 8038 | numRead = input.read(buffer); |
| 8039 | } catch (IOException e) { |
| 8040 | try { |
| 8041 | fd.checkError(); |
| 8042 | callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED, |
| 8043 | null); |
| 8044 | } catch (IOException e1) { |
| 8045 | // This means that the other side closed explicitly with an error. If this |
| 8046 | // happens, log and ignore. |
| 8047 | loge("Remote end of call composer picture pipe closed: " + e1); |
| 8048 | } |
| 8049 | break; |
| 8050 | } |
| 8051 | if (numRead == -1) { |
| 8052 | readUntilEnd = true; |
| 8053 | break; |
| 8054 | } |
| 8055 | totalBytesRead += numRead; |
| 8056 | if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) { |
| 8057 | loge("Too many bytes read for call composer picture: " + totalBytesRead); |
| 8058 | try { |
| 8059 | input.close(); |
| 8060 | } catch (IOException e) { |
| 8061 | // ignore |
| 8062 | } |
| 8063 | break; |
| 8064 | } |
| 8065 | output.write(buffer, 0, numRead); |
| 8066 | } |
| 8067 | // Generally, the remote end will close the file descriptors. The only case where we |
| 8068 | // close is above, where the picture size is too big. |
| 8069 | |
| 8070 | try { |
| 8071 | fd.checkError(); |
| 8072 | } catch (IOException e) { |
| 8073 | loge("Remote end for call composer closed with an error: " + e); |
| 8074 | return; |
| 8075 | } |
| 8076 | |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 8077 | if (!readUntilEnd) { |
| 8078 | loge("Did not finish reading entire image; aborting"); |
| 8079 | return; |
| 8080 | } |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 8081 | |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 8082 | ImageData imageData = new ImageData(output.toByteArray(), contentType, null); |
| 8083 | CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer( |
| 8084 | new CallComposerPictureTransfer.Factory() {}, |
| 8085 | imageData, |
| 8086 | (result) -> { |
| 8087 | if (result.first != null) { |
| 8088 | ParcelUuid parcelUuid = new ParcelUuid(result.first); |
| 8089 | Bundle outputResult = new Bundle(); |
| 8090 | outputResult.putParcelable( |
| 8091 | TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid); |
| 8092 | callback.send(TelephonyManager.CallComposerException.SUCCESS, |
| 8093 | outputResult); |
| 8094 | } else { |
| 8095 | callback.send(result.second, null); |
| 8096 | } |
| 8097 | } |
| 8098 | ); |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 8099 | }); |
| 8100 | } |
| 8101 | |
| 8102 | @Override |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 8103 | public void enableVideoCalling(boolean enable) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8104 | final Phone defaultPhone = getDefaultPhone(); |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 8105 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8106 | |
| 8107 | final long identity = Binder.clearCallingIdentity(); |
| 8108 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8109 | ImsManager.getInstance(defaultPhone.getContext(), |
| 8110 | defaultPhone.getPhoneId()).setVtSetting(enable); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8111 | } finally { |
| 8112 | Binder.restoreCallingIdentity(identity); |
| 8113 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 8114 | } |
| 8115 | |
| 8116 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8117 | public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8118 | final Phone defaultPhone = getDefaultPhone(); |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8119 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 8120 | callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 8121 | return false; |
| 8122 | } |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 8123 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8124 | final long identity = Binder.clearCallingIdentity(); |
| 8125 | try { |
| 8126 | // Check the user preference and the system-level IMS setting. Even if the user has |
| 8127 | // enabled video calling, if IMS is disabled we aren't able to support video calling. |
| 8128 | // In the long run, we may instead need to check if there exists a connection service |
| 8129 | // which can support video calling. |
| 8130 | ImsManager imsManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8131 | ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8132 | return imsManager.isVtEnabledByPlatform() |
| 8133 | && imsManager.isEnhanced4gLteModeSettingEnabledByUser() |
| 8134 | && imsManager.isVtEnabledByUser(); |
| 8135 | } finally { |
| 8136 | Binder.restoreCallingIdentity(identity); |
| 8137 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 8138 | } |
Libin.Tang@motorola.com | afe8264 | 2014-12-18 13:27:53 -0600 | [diff] [blame] | 8139 | |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 8140 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8141 | public boolean canChangeDtmfToneLength(int subId, String callingPackage, |
| 8142 | String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8143 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8144 | mApp, subId, callingPackage, callingFeatureId, |
| 8145 | "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8146 | return false; |
| 8147 | } |
| 8148 | |
| 8149 | final long identity = Binder.clearCallingIdentity(); |
| 8150 | try { |
| 8151 | CarrierConfigManager configManager = |
| 8152 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8153 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8154 | .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL); |
| 8155 | } finally { |
| 8156 | Binder.restoreCallingIdentity(identity); |
| 8157 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 8158 | } |
| 8159 | |
| 8160 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8161 | public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8162 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8163 | mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8164 | return false; |
| 8165 | } |
| 8166 | |
| 8167 | final long identity = Binder.clearCallingIdentity(); |
| 8168 | try { |
| 8169 | CarrierConfigManager configManager = |
| 8170 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8171 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8172 | .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL); |
| 8173 | } finally { |
| 8174 | Binder.restoreCallingIdentity(identity); |
| 8175 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 8176 | } |
| 8177 | |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 8178 | @Override |
| 8179 | public boolean isTtyModeSupported() { |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 8180 | TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class); |
Wooki Wu | 1f82f7a | 2016-02-15 15:59:58 +0800 | [diff] [blame] | 8181 | return telecomManager.isTtySupported(); |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 8182 | } |
| 8183 | |
| 8184 | @Override |
| 8185 | public boolean isHearingAidCompatibilitySupported() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8186 | final long identity = Binder.clearCallingIdentity(); |
| 8187 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8188 | return mApp.getResources().getBoolean(R.bool.hac_enabled); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8189 | } finally { |
| 8190 | Binder.restoreCallingIdentity(identity); |
| 8191 | } |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 8192 | } |
| 8193 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 8194 | /** |
| 8195 | * Determines whether the device currently supports RTT (Real-time text). Based both on carrier |
| 8196 | * support for the feature and device firmware support. |
| 8197 | * |
| 8198 | * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise. |
| 8199 | */ |
| 8200 | @Override |
| 8201 | public boolean isRttSupported(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8202 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8203 | final Phone phone = getPhone(subscriptionId); |
| 8204 | if (phone == null) { |
| 8205 | loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId); |
| 8206 | return false; |
| 8207 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8208 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8209 | boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8210 | CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL); |
| 8211 | boolean isDeviceSupported = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8212 | phone.getContext().getResources().getBoolean(R.bool.config_support_rtt); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8213 | return isCarrierSupported && isDeviceSupported; |
| 8214 | } finally { |
| 8215 | Binder.restoreCallingIdentity(identity); |
| 8216 | } |
Hall Liu | 9818758 | 2018-01-22 19:15:32 -0800 | [diff] [blame] | 8217 | } |
| 8218 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 8219 | /** |
Hall Liu | f2daa02 | 2019-07-23 18:39:00 -0700 | [diff] [blame] | 8220 | * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set |
| 8221 | * RTT setting, will return true if the device and carrier both support RTT. |
| 8222 | * 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] | 8223 | */ |
| 8224 | public boolean isRttEnabled(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8225 | final long identity = Binder.clearCallingIdentity(); |
| 8226 | try { |
Hall Liu | 5bab75c | 2019-12-11 23:58:20 +0000 | [diff] [blame] | 8227 | boolean isRttSupported = isRttSupported(subscriptionId); |
| 8228 | boolean isUserRttSettingOn = Settings.Secure.getInt( |
| 8229 | mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0; |
| 8230 | boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId) |
| 8231 | .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL); |
| 8232 | return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8233 | } finally { |
| 8234 | Binder.restoreCallingIdentity(identity); |
| 8235 | } |
Hall Liu | 3ad5f01 | 2018-04-06 16:23:39 -0700 | [diff] [blame] | 8236 | } |
| 8237 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8238 | @Deprecated |
| 8239 | @Override |
| 8240 | public String getDeviceId(String callingPackage) { |
| 8241 | return getDeviceIdWithFeature(callingPackage, null); |
| 8242 | } |
| 8243 | |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 8244 | /** |
| 8245 | * Returns the unique device ID of phone, for example, the IMEI for |
| 8246 | * GSM and the MEID for CDMA phones. Return null if device ID is not available. |
| 8247 | * |
| 8248 | * <p>Requires Permission: |
| 8249 | * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} |
| 8250 | */ |
| 8251 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8252 | public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) { |
Shuo Qian | 13d8915 | 2021-05-10 23:58:11 -0700 | [diff] [blame] | 8253 | try { |
| 8254 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 8255 | } catch (SecurityException se) { |
| 8256 | EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid()); |
| 8257 | throw new SecurityException("Package " + callingPackage + " does not belong to " |
| 8258 | + Binder.getCallingUid()); |
| 8259 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 8260 | final Phone phone = PhoneFactory.getPhone(0); |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 8261 | if (phone == null) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 8262 | return null; |
| 8263 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 8264 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 8265 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8266 | callingPackage, callingFeatureId, "getDeviceId")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 8267 | return null; |
| 8268 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8269 | |
| 8270 | final long identity = Binder.clearCallingIdentity(); |
| 8271 | try { |
| 8272 | return phone.getDeviceId(); |
| 8273 | } finally { |
| 8274 | Binder.restoreCallingIdentity(identity); |
| 8275 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 8276 | } |
| 8277 | |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 8278 | /** |
| 8279 | * {@hide} |
| 8280 | * Returns the IMS Registration Status on a particular subid |
| 8281 | * |
| 8282 | * @param subId |
| 8283 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8284 | public boolean isImsRegistered(int subId) { |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 8285 | Phone phone = getPhone(subId); |
| 8286 | if (phone != null) { |
| 8287 | return phone.isImsRegistered(); |
| 8288 | } else { |
| 8289 | return false; |
| 8290 | } |
| 8291 | } |
| 8292 | |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 8293 | @Override |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 8294 | public int getSubIdForPhoneAccountHandle( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8295 | PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) { |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 8296 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(), |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8297 | callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) { |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 8298 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 8299 | } |
| 8300 | final long identity = Binder.clearCallingIdentity(); |
| 8301 | try { |
| 8302 | return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle); |
| 8303 | } finally { |
| 8304 | Binder.restoreCallingIdentity(identity); |
| 8305 | } |
| 8306 | } |
| 8307 | |
| 8308 | @Override |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 8309 | public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) { |
Alireza Forouzan | 4ac4f98 | 2021-03-16 22:18:52 -0700 | [diff] [blame] | 8310 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 8311 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 8312 | mApp, |
| 8313 | subscriptionId, |
| 8314 | "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: " |
| 8315 | + subscriptionId); |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 8316 | final long identity = Binder.clearCallingIdentity(); |
| 8317 | try { |
| 8318 | Phone phone = getPhone(subscriptionId); |
| 8319 | if (phone == null) { |
| 8320 | return null; |
| 8321 | } |
| 8322 | return PhoneUtils.makePstnPhoneAccountHandle(phone); |
| 8323 | } finally { |
| 8324 | Binder.restoreCallingIdentity(identity); |
| 8325 | } |
| 8326 | } |
| 8327 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8328 | /** |
| 8329 | * @return the VoWiFi calling availability. |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 8330 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8331 | public boolean isWifiCallingAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8332 | final long identity = Binder.clearCallingIdentity(); |
| 8333 | try { |
| 8334 | Phone phone = getPhone(subId); |
| 8335 | if (phone != null) { |
| 8336 | return phone.isWifiCallingEnabled(); |
| 8337 | } else { |
| 8338 | return false; |
| 8339 | } |
| 8340 | } finally { |
| 8341 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8342 | } |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 8343 | } |
| 8344 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8345 | /** |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8346 | * @return the VT calling availability. |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 8347 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8348 | public boolean isVideoTelephonyAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8349 | final long identity = Binder.clearCallingIdentity(); |
| 8350 | try { |
| 8351 | Phone phone = getPhone(subId); |
| 8352 | if (phone != null) { |
| 8353 | return phone.isVideoEnabled(); |
| 8354 | } else { |
| 8355 | return false; |
| 8356 | } |
| 8357 | } finally { |
| 8358 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8359 | } |
| 8360 | } |
| 8361 | |
| 8362 | /** |
| 8363 | * @return the IMS registration technology for the MMTEL feature. Valid return values are |
| 8364 | * defined in {@link ImsRegistrationImplBase}. |
| 8365 | */ |
| 8366 | public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8367 | final long identity = Binder.clearCallingIdentity(); |
| 8368 | try { |
| 8369 | Phone phone = getPhone(subId); |
| 8370 | if (phone != null) { |
| 8371 | return phone.getImsRegistrationTech(); |
| 8372 | } else { |
| 8373 | return ImsRegistrationImplBase.REGISTRATION_TECH_NONE; |
| 8374 | } |
| 8375 | } finally { |
| 8376 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8377 | } |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 8378 | } |
| 8379 | |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 8380 | @Override |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 8381 | public void factoryReset(int subId, String callingPackage) { |
paulhu | 5a77360 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 8382 | enforceSettingsPermission(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 8383 | if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) { |
| 8384 | return; |
| 8385 | } |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 8386 | Phone defaultPhone = getDefaultPhone(); |
| 8387 | if (defaultPhone != null) { |
| 8388 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8389 | mApp, getDefaultPhone().getSubId(), "factoryReset"); |
| 8390 | } |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 8391 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8392 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 8393 | try { |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 8394 | if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction( |
| 8395 | UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 8396 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 8397 | getDefaultDataEnabled(), callingPackage); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 8398 | setNetworkSelectionModeAutomatic(subId); |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 8399 | Phone phone = getPhone(subId); |
SongFerngWang | fd89b10 | 2021-05-27 22:44:54 +0800 | [diff] [blame] | 8400 | cleanUpAllowedNetworkTypes(phone, subId); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8401 | setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId)); |
Jordan Liu | 857e73a | 2021-03-05 16:24:04 -0800 | [diff] [blame] | 8402 | getPhone(subId).resetCarrierKeysForImsiEncryption(); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 8403 | } |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 8404 | // There has been issues when Sms raw table somehow stores orphan |
| 8405 | // fragments. They lead to garbled message when new fragments come |
| 8406 | // in and combined with those stale ones. In case this happens again, |
| 8407 | // user can reset all network settings which will clean up this table. |
| 8408 | cleanUpSmsRawTable(getDefaultPhone().getContext()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 8409 | // Clean up IMS settings as well here. |
| 8410 | int slotId = getSlotIndex(subId); |
| 8411 | if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 8412 | ImsManager.getInstance(mApp, slotId).factoryReset(); |
| 8413 | } |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 8414 | |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 8415 | if (defaultPhone == null) { |
| 8416 | return; |
| 8417 | } |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 8418 | // Erase modem config if erase modem on network setting is enabled. |
| 8419 | String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY, |
| 8420 | RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED); |
| 8421 | if (configValue != null && Boolean.parseBoolean(configValue)) { |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 8422 | sendEraseModemConfig(defaultPhone); |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 8423 | } |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 8424 | |
| 8425 | sendEraseDataInSharedPreferences(defaultPhone); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 8426 | } finally { |
| 8427 | Binder.restoreCallingIdentity(identity); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 8428 | } |
| 8429 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 8430 | |
SongFerngWang | fd89b10 | 2021-05-27 22:44:54 +0800 | [diff] [blame] | 8431 | @VisibleForTesting |
| 8432 | void cleanUpAllowedNetworkTypes(Phone phone, int subId) { |
| 8433 | if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) { |
| 8434 | return; |
| 8435 | } |
| 8436 | long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType( |
| 8437 | RILConstants.PREFERRED_NETWORK_MODE); |
| 8438 | SubscriptionManager.setSubscriptionProperty(subId, |
| 8439 | SubscriptionManager.ALLOWED_NETWORK_TYPES, |
| 8440 | "user=" + defaultNetworkType); |
| 8441 | phone.loadAllowedNetworksFromSubscriptionDatabase(); |
| 8442 | phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER, |
| 8443 | defaultNetworkType, null); |
| 8444 | } |
| 8445 | |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 8446 | private void cleanUpSmsRawTable(Context context) { |
| 8447 | ContentResolver resolver = context.getContentResolver(); |
| 8448 | Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete"); |
| 8449 | resolver.delete(uri, null, null); |
| 8450 | } |
| 8451 | |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 8452 | @Override |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 8453 | public String getSimLocaleForSubscriber(int subId) { |
| 8454 | enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId); |
| 8455 | final Phone phone = getPhone(subId); |
| 8456 | if (phone == null) { |
| 8457 | log("getSimLocaleForSubscriber, invalid subId"); |
chen xu | 2bb91e4 | 2019-01-24 14:35:54 -0800 | [diff] [blame] | 8458 | return null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 8459 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8460 | final long identity = Binder.clearCallingIdentity(); |
| 8461 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 8462 | SubscriptionInfo info; |
| 8463 | if (PhoneFactory.isSubscriptionManagerServiceEnabled()) { |
Jack Yu | fa8ed01 | 2023-02-11 15:42:28 -0800 | [diff] [blame] | 8464 | info = getSubscriptionManagerService().getActiveSubscriptionInfo(subId, |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 8465 | phone.getContext().getOpPackageName(), |
| 8466 | phone.getContext().getAttributionTag()); |
| 8467 | if (info == null) { |
| 8468 | log("getSimLocaleForSubscriber, inactive subId: " + subId); |
| 8469 | return null; |
| 8470 | } |
| 8471 | } else { |
| 8472 | info = mSubscriptionController.getActiveSubscriptionInfo(subId, |
| 8473 | phone.getContext().getOpPackageName(), |
| 8474 | phone.getContext().getAttributionTag()); |
| 8475 | if (info == null) { |
| 8476 | log("getSimLocaleForSubscriber, inactive subId: " + subId); |
| 8477 | return null; |
| 8478 | } |
chen xu | 6291c47 | 2019-02-04 12:55:53 -0800 | [diff] [blame] | 8479 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8480 | // Try and fetch the locale from the carrier properties or from the SIM language |
| 8481 | // preferences (EF-PL and EF-LI)... |
| 8482 | final int mcc = info.getMcc(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8483 | String simLanguage = null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 8484 | final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs(); |
| 8485 | if (localeFromDefaultSim != null) { |
| 8486 | if (!localeFromDefaultSim.getCountry().isEmpty()) { |
| 8487 | if (DBG) log("Using locale from subId: " + subId + " locale: " |
| 8488 | + localeFromDefaultSim); |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 8489 | return matchLocaleFromSupportedLocaleList(phone, localeFromDefaultSim); |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 8490 | } else { |
| 8491 | simLanguage = localeFromDefaultSim.getLanguage(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8492 | } |
| 8493 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 8494 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8495 | // The SIM language preferences only store a language (e.g. fr = French), not an |
| 8496 | // exact locale (e.g. fr_FR = French/France). So, if the locale returned from |
| 8497 | // the SIM and carrier preferences does not include a country we add the country |
| 8498 | // determined from the SIM MCC to provide an exact locale. |
zoey chen | c730df8 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 8499 | final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8500 | if (mccLocale != null) { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 8501 | if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale); |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 8502 | return matchLocaleFromSupportedLocaleList(phone, mccLocale); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8503 | } |
| 8504 | |
| 8505 | if (DBG) log("No locale found - returning null"); |
| 8506 | return null; |
| 8507 | } finally { |
| 8508 | Binder.restoreCallingIdentity(identity); |
| 8509 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 8510 | } |
| 8511 | |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 8512 | @VisibleForTesting |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 8513 | String matchLocaleFromSupportedLocaleList(Phone phone, @NonNull Locale inputLocale) { |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 8514 | String[] supportedLocale = com.android.internal.app.LocalePicker.getSupportedLocales( |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 8515 | phone.getContext()); |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 8516 | for (String localeTag : supportedLocale) { |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 8517 | if (LocaleList.matchesLanguageAndScript(inputLocale, Locale.forLanguageTag(localeTag)) |
| 8518 | && TextUtils.equals(inputLocale.getCountry(), |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 8519 | Locale.forLanguageTag(localeTag).getCountry())) { |
| 8520 | return localeTag; |
| 8521 | } |
| 8522 | } |
| 8523 | return inputLocale.toLanguageTag(); |
| 8524 | } |
| 8525 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8526 | /** |
| 8527 | * NOTE: this method assumes permission checks are done and caller identity has been cleared. |
| 8528 | */ |
| 8529 | private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 8530 | if (PhoneFactory.isSubscriptionManagerServiceEnabled()) { |
Jack Yu | fa8ed01 | 2023-02-11 15:42:28 -0800 | [diff] [blame] | 8531 | return getSubscriptionManagerService().getActiveSubscriptionInfoList( |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 8532 | mApp.getOpPackageName(), mApp.getAttributionTag()); |
| 8533 | } |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8534 | return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(), |
Philip P. Moltmann | 8d34f0c | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 8535 | mApp.getAttributionTag()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 8536 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 8537 | |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8538 | private ActivityStatsTechSpecificInfo[] mLastModemActivitySpecificInfo = null; |
| 8539 | private ModemActivityInfo mLastModemActivityInfo = null; |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 8540 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 8541 | /** |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 8542 | * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object |
| 8543 | * representing the state of the modem. |
| 8544 | * |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 8545 | * NOTE: The underlying implementation clears the modem state, so there should only ever be one |
| 8546 | * caller to it. Everyone should call this class to get cumulative data. |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 8547 | * @hide |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 8548 | */ |
| 8549 | @Override |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 8550 | public void requestModemActivityInfo(ResultReceiver result) { |
| 8551 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8552 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8553 | |
| 8554 | final long identity = Binder.clearCallingIdentity(); |
| 8555 | try { |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 8556 | sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8557 | } finally { |
| 8558 | Binder.restoreCallingIdentity(identity); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 8559 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 8560 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8561 | |
Gary Jian | 76280a4 | 2022-12-07 16:18:33 +0800 | [diff] [blame] | 8562 | // Checks that ModemActivityInfo is valid. Sleep time and Idle time should be |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 8563 | // less than total activity duration. |
| 8564 | private boolean isModemActivityInfoValid(ModemActivityInfo info) { |
| 8565 | if (info == null) { |
| 8566 | return false; |
| 8567 | } |
| 8568 | int activityDurationMs = |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 8569 | (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis()); |
Gary Jian | 76280a4 | 2022-12-07 16:18:33 +0800 | [diff] [blame] | 8570 | activityDurationMs += MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS; |
| 8571 | |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 8572 | int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum(); |
| 8573 | |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 8574 | return (info.isValid() |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 8575 | && (info.getSleepTimeMillis() <= activityDurationMs) |
| 8576 | && (info.getIdleTimeMillis() <= activityDurationMs)); |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 8577 | } |
| 8578 | |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8579 | private void updateLastModemActivityInfo(ModemActivityInfo info, int rat, int freq) { |
| 8580 | int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()]; |
| 8581 | int[] txTimeMs = info.getTransmitTimeMillis(rat, freq); |
| 8582 | int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat, freq); |
| 8583 | |
| 8584 | for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) { |
| 8585 | mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl]; |
| 8586 | } |
| 8587 | |
| 8588 | mLastModemActivityInfo.setTransmitTimeMillis(rat, freq, mergedTxTimeMs); |
| 8589 | mLastModemActivityInfo.setReceiveTimeMillis( |
| 8590 | rat, |
| 8591 | freq, |
| 8592 | info.getReceiveTimeMillis(rat, freq) |
| 8593 | + mLastModemActivityInfo.getReceiveTimeMillis(rat, freq)); |
| 8594 | } |
| 8595 | |
| 8596 | private void updateLastModemActivityInfo(ModemActivityInfo info, int rat) { |
| 8597 | int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()]; |
| 8598 | int[] txTimeMs = info.getTransmitTimeMillis(rat); |
| 8599 | int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat); |
| 8600 | |
| 8601 | for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) { |
| 8602 | mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl]; |
| 8603 | } |
| 8604 | mLastModemActivityInfo.setTransmitTimeMillis(rat, mergedTxTimeMs); |
| 8605 | mLastModemActivityInfo.setReceiveTimeMillis( |
| 8606 | rat, |
| 8607 | info.getReceiveTimeMillis(rat) + mLastModemActivityInfo.getReceiveTimeMillis(rat)); |
| 8608 | } |
| 8609 | |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 8610 | /** |
| 8611 | * Merge this ModemActivityInfo with mLastModemActivitySpecificInfo |
| 8612 | * @param info recent ModemActivityInfo |
| 8613 | */ |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8614 | private void mergeModemActivityInfo(ModemActivityInfo info) { |
| 8615 | List<ActivityStatsTechSpecificInfo> merged = new ArrayList<>(); |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 8616 | ActivityStatsTechSpecificInfo deltaSpecificInfo; |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8617 | boolean matched; |
| 8618 | for (int i = 0; i < info.getSpecificInfoLength(); i++) { |
| 8619 | matched = false; |
| 8620 | int rat = info.getSpecificInfoRat(i); |
| 8621 | int freq = info.getSpecificInfoFrequencyRange(i); |
| 8622 | //Check each ActivityStatsTechSpecificInfo in this ModemActivityInfo for new rat returns |
| 8623 | //Add a new ActivityStatsTechSpecificInfo if is a new rat, and merge with the original |
| 8624 | //if it already exists |
| 8625 | for (int j = 0; j < mLastModemActivitySpecificInfo.length; j++) { |
| 8626 | if (rat == mLastModemActivityInfo.getSpecificInfoRat(j) && !matched) { |
| 8627 | //Merged based on frequency range (MMWAVE vs SUB6) for 5G |
| 8628 | if (rat == AccessNetworkConstants.AccessNetworkType.NGRAN) { |
| 8629 | if (freq == mLastModemActivityInfo.getSpecificInfoFrequencyRange(j)) { |
| 8630 | updateLastModemActivityInfo(info, rat, freq); |
| 8631 | matched = true; |
| 8632 | } |
| 8633 | } else { |
| 8634 | updateLastModemActivityInfo(info, rat); |
| 8635 | matched = true; |
| 8636 | } |
| 8637 | } |
| 8638 | } |
| 8639 | |
| 8640 | if (!matched) { |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 8641 | deltaSpecificInfo = |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8642 | new ActivityStatsTechSpecificInfo( |
| 8643 | rat, |
| 8644 | freq, |
| 8645 | info.getTransmitTimeMillis(rat, freq), |
| 8646 | (int) info.getReceiveTimeMillis(rat, freq)); |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 8647 | merged.addAll(Arrays.asList(deltaSpecificInfo)); |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8648 | } |
| 8649 | } |
| 8650 | merged.addAll(Arrays.asList(mLastModemActivitySpecificInfo)); |
| 8651 | mLastModemActivitySpecificInfo = |
| 8652 | new ActivityStatsTechSpecificInfo[merged.size()]; |
| 8653 | merged.toArray(mLastModemActivitySpecificInfo); |
| 8654 | |
| 8655 | mLastModemActivityInfo.setTimestamp(info.getTimestampMillis()); |
| 8656 | mLastModemActivityInfo.setSleepTimeMillis( |
| 8657 | info.getSleepTimeMillis() |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 8658 | + mLastModemActivityInfo.getSleepTimeMillis()); |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8659 | mLastModemActivityInfo.setIdleTimeMillis( |
| 8660 | info.getIdleTimeMillis() |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 8661 | + mLastModemActivityInfo.getIdleTimeMillis()); |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 8662 | |
| 8663 | mLastModemActivityInfo = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 8664 | new ModemActivityInfo( |
| 8665 | mLastModemActivityInfo.getTimestampMillis(), |
| 8666 | mLastModemActivityInfo.getSleepTimeMillis(), |
| 8667 | mLastModemActivityInfo.getIdleTimeMillis(), |
| 8668 | mLastModemActivitySpecificInfo); |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 8669 | } |
| 8670 | |
| 8671 | private ActivityStatsTechSpecificInfo[] deepCopyModemActivitySpecificInfo( |
| 8672 | ActivityStatsTechSpecificInfo[] info) { |
| 8673 | int infoSize = info.length; |
| 8674 | ActivityStatsTechSpecificInfo[] ret = new ActivityStatsTechSpecificInfo[infoSize]; |
| 8675 | for (int i = 0; i < infoSize; i++) { |
| 8676 | ret[i] = new ActivityStatsTechSpecificInfo( |
| 8677 | info[i].getRat(), info[i].getFrequencyRange(), |
| 8678 | info[i].getTransmitTimeMillis(), |
| 8679 | (int) info[i].getReceiveTimeMillis()); |
| 8680 | } |
| 8681 | return ret; |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8682 | } |
| 8683 | |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8684 | /** |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8685 | * Returns the service state information on specified subscription. |
| 8686 | */ |
| 8687 | @Override |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 8688 | public ServiceState getServiceStateForSubscriber(int subId, |
| 8689 | boolean renounceFineLocationAccess, boolean renounceCoarseLocationAccess, |
| 8690 | String callingPackage, String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8691 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8692 | mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) { |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8693 | return null; |
| 8694 | } |
| 8695 | |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 8696 | boolean hasFinePermission = false; |
| 8697 | boolean hasCoarsePermission = false; |
| 8698 | if (!renounceFineLocationAccess) { |
| 8699 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 8700 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 8701 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 8702 | .setCallingPackage(callingPackage) |
| 8703 | .setCallingFeatureId(callingFeatureId) |
| 8704 | .setCallingPid(Binder.getCallingPid()) |
| 8705 | .setCallingUid(Binder.getCallingUid()) |
| 8706 | .setMethod("getServiceStateForSubscriber") |
| 8707 | .setLogAsInfo(true) |
| 8708 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 8709 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 8710 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 8711 | .build()); |
| 8712 | hasFinePermission = |
| 8713 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 8714 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 8715 | |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 8716 | if (!renounceCoarseLocationAccess) { |
| 8717 | LocationAccessPolicy.LocationPermissionResult coarseLocationResult = |
| 8718 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 8719 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 8720 | .setCallingPackage(callingPackage) |
| 8721 | .setCallingFeatureId(callingFeatureId) |
| 8722 | .setCallingPid(Binder.getCallingPid()) |
| 8723 | .setCallingUid(Binder.getCallingUid()) |
| 8724 | .setMethod("getServiceStateForSubscriber") |
| 8725 | .setLogAsInfo(true) |
| 8726 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 8727 | .setMinSdkVersionForFine(Integer.MAX_VALUE) |
| 8728 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 8729 | .build()); |
| 8730 | hasCoarsePermission = |
| 8731 | coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 8732 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 8733 | |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 8734 | final Phone phone = getPhone(subId); |
| 8735 | if (phone == null) { |
| 8736 | return null; |
| 8737 | } |
| 8738 | |
Jordan Liu | 0f2bc44 | 2020-11-18 16:47:37 -0800 | [diff] [blame] | 8739 | final long identity = Binder.clearCallingIdentity(); |
| 8740 | |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 8741 | boolean isCallingPackageDataService = phone.getDataServicePackages() |
| 8742 | .contains(callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8743 | try { |
Jordan Liu | c437b19 | 2020-08-17 10:59:12 -0700 | [diff] [blame] | 8744 | // isActiveSubId requires READ_PHONE_STATE, which we already check for above |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 8745 | if (PhoneFactory.isSubscriptionManagerServiceEnabled()) { |
Jack Yu | fa8ed01 | 2023-02-11 15:42:28 -0800 | [diff] [blame] | 8746 | SubscriptionInfoInternal subInfo = getSubscriptionManagerService() |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 8747 | .getSubscriptionInfoInternal(subId); |
| 8748 | if (subInfo == null || !subInfo.isActive()) { |
| 8749 | Rlog.d(LOG_TAG, "getServiceStateForSubscriber returning null for inactive " |
| 8750 | + "subId=" + subId); |
| 8751 | return null; |
| 8752 | } |
| 8753 | } else { |
| 8754 | if (!mSubscriptionController.isActiveSubId(subId, callingPackage, |
| 8755 | callingFeatureId)) { |
| 8756 | Rlog.d(LOG_TAG, "getServiceStateForSubscriber returning null for inactive " |
| 8757 | + "subId=" + subId); |
| 8758 | return null; |
| 8759 | } |
Jordan Liu | c437b19 | 2020-08-17 10:59:12 -0700 | [diff] [blame] | 8760 | } |
| 8761 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 8762 | ServiceState ss = phone.getServiceState(); |
| 8763 | |
| 8764 | // Scrub out the location info in ServiceState depending on what level of access |
| 8765 | // the caller has. |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 8766 | if (hasFinePermission || isCallingPackageDataService) return ss; |
Malcolm Chen | 5052de6 | 2019-12-30 13:56:38 -0800 | [diff] [blame] | 8767 | if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false); |
| 8768 | return ss.createLocationInfoSanitizedCopy(true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8769 | } finally { |
| 8770 | Binder.restoreCallingIdentity(identity); |
| 8771 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8772 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8773 | |
| 8774 | /** |
| 8775 | * Returns the URI for the per-account voicemail ringtone set in Phone settings. |
| 8776 | * |
| 8777 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 8778 | * voicemail ringtone. |
| 8779 | * @return The URI for the ringtone to play when receiving a voicemail from a specific |
| 8780 | * PhoneAccount. |
| 8781 | */ |
| 8782 | @Override |
| 8783 | public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8784 | final long identity = Binder.clearCallingIdentity(); |
| 8785 | try { |
| 8786 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 8787 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8788 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8789 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8790 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8791 | return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext()); |
| 8792 | } finally { |
| 8793 | Binder.restoreCallingIdentity(identity); |
| 8794 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8795 | } |
| 8796 | |
| 8797 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8798 | * Sets the per-account voicemail ringtone. |
| 8799 | * |
| 8800 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 8801 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 8802 | * |
| 8803 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 8804 | * voicemail ringtone. |
| 8805 | * @param uri The URI for the ringtone to play when receiving a voicemail from a specific |
| 8806 | * PhoneAccount. |
| 8807 | */ |
| 8808 | @Override |
| 8809 | public void setVoicemailRingtoneUri(String callingPackage, |
| 8810 | PhoneAccountHandle phoneAccountHandle, Uri uri) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8811 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8812 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 8813 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 8814 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8815 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8816 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 8817 | "setVoicemailRingtoneUri"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8818 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8819 | |
| 8820 | final long identity = Binder.clearCallingIdentity(); |
| 8821 | try { |
| 8822 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 8823 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8824 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8825 | } |
| 8826 | VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri); |
| 8827 | } finally { |
| 8828 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8829 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8830 | } |
| 8831 | |
| 8832 | /** |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8833 | * Returns whether vibration is set for voicemail notification in Phone settings. |
| 8834 | * |
| 8835 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 8836 | * voicemail vibration setting. |
| 8837 | * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise. |
| 8838 | */ |
| 8839 | @Override |
| 8840 | public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8841 | final long identity = Binder.clearCallingIdentity(); |
| 8842 | try { |
| 8843 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 8844 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8845 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8846 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8847 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8848 | return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext()); |
| 8849 | } finally { |
| 8850 | Binder.restoreCallingIdentity(identity); |
| 8851 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8852 | } |
| 8853 | |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8854 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8855 | * Sets the per-account voicemail vibration. |
| 8856 | * |
| 8857 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 8858 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 8859 | * |
| 8860 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 8861 | * voicemail vibration setting. |
| 8862 | * @param enabled Whether to enable or disable vibration for voicemail notifications from a |
| 8863 | * specific PhoneAccount. |
| 8864 | */ |
| 8865 | @Override |
| 8866 | public void setVoicemailVibrationEnabled(String callingPackage, |
| 8867 | PhoneAccountHandle phoneAccountHandle, boolean enabled) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8868 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8869 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 8870 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 8871 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8872 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8873 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 8874 | "setVoicemailVibrationEnabled"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8875 | } |
| 8876 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8877 | final long identity = Binder.clearCallingIdentity(); |
| 8878 | try { |
| 8879 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 8880 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8881 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8882 | } |
| 8883 | VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled); |
| 8884 | } finally { |
| 8885 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8886 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8887 | } |
| 8888 | |
| 8889 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8890 | * Make sure either called from same process as self (phone) or IPC caller has read privilege. |
| 8891 | * |
| 8892 | * @throws SecurityException if the caller does not have the required permission |
| 8893 | */ |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 8894 | @VisibleForTesting |
| 8895 | public void enforceReadPrivilegedPermission(String message) { |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8896 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8897 | message); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8898 | } |
| 8899 | |
| 8900 | /** |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 8901 | * Make sure either called from same process as self (phone) or IPC caller has send SMS |
| 8902 | * permission. |
| 8903 | * |
| 8904 | * @throws SecurityException if the caller does not have the required permission |
| 8905 | */ |
| 8906 | private void enforceSendSmsPermission() { |
| 8907 | mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null); |
| 8908 | } |
| 8909 | |
| 8910 | /** |
Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame] | 8911 | * Make sure either called from same process as self (phone) or IPC caller has interact across |
| 8912 | * users permission. |
| 8913 | * |
| 8914 | * @throws SecurityException if the caller does not have the required permission |
| 8915 | */ |
| 8916 | private void enforceInteractAcrossUsersPermission(String message) { |
| 8917 | mApp.enforceCallingOrSelfPermission(permission.INTERACT_ACROSS_USERS, message); |
| 8918 | } |
| 8919 | |
| 8920 | /** |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 8921 | * Make sure called from the package in charge of visual voicemail. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 8922 | * |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 8923 | * @throws SecurityException if the caller is not the visual voicemail package. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 8924 | */ |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 8925 | private void enforceVisualVoicemailPackage(String callingPackage, int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8926 | final long identity = Binder.clearCallingIdentity(); |
| 8927 | try { |
| 8928 | ComponentName componentName = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8929 | RemoteVvmTaskManager.getRemotePackage(mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8930 | if (componentName == null) { |
| 8931 | throw new SecurityException( |
| 8932 | "Caller not current active visual voicemail package[null]"); |
| 8933 | } |
| 8934 | String vvmPackage = componentName.getPackageName(); |
| 8935 | if (!callingPackage.equals(vvmPackage)) { |
Hui Wang | 7f65755 | 2022-08-16 16:58:25 +0000 | [diff] [blame] | 8936 | throw new SecurityException("Caller not current active visual voicemail package"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8937 | } |
| 8938 | } finally { |
| 8939 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 8940 | } |
| 8941 | } |
| 8942 | |
| 8943 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8944 | * Return the application ID for the app type. |
| 8945 | * |
| 8946 | * @param subId the subscription ID that this request applies to. |
| 8947 | * @param appType the uicc app type. |
| 8948 | * @return Application ID for specificied app type, or null if no uicc. |
| 8949 | */ |
| 8950 | @Override |
| 8951 | public String getAidForAppType(int subId, int appType) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8952 | enforceReadPrivilegedPermission("getAidForAppType"); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8953 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8954 | |
| 8955 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8956 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8957 | if (phone == null) { |
| 8958 | return null; |
| 8959 | } |
| 8960 | String aid = null; |
| 8961 | try { |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 8962 | aid = UiccController.getInstance().getUiccPort(phone.getPhoneId()) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8963 | .getApplicationByType(appType).getAid(); |
| 8964 | } catch (Exception e) { |
| 8965 | Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e); |
| 8966 | } |
| 8967 | return aid; |
| 8968 | } finally { |
| 8969 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8970 | } |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8971 | } |
| 8972 | |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8973 | /** |
| 8974 | * Return the Electronic Serial Number. |
| 8975 | * |
| 8976 | * @param subId the subscription ID that this request applies to. |
| 8977 | * @return ESN or null if error. |
| 8978 | */ |
| 8979 | @Override |
| 8980 | public String getEsn(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8981 | enforceReadPrivilegedPermission("getEsn"); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8982 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8983 | |
| 8984 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8985 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8986 | if (phone == null) { |
| 8987 | return null; |
| 8988 | } |
| 8989 | String esn = null; |
| 8990 | try { |
| 8991 | esn = phone.getEsn(); |
| 8992 | } catch (Exception e) { |
| 8993 | Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e); |
| 8994 | } |
| 8995 | return esn; |
| 8996 | } finally { |
| 8997 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8998 | } |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8999 | } |
| 9000 | |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 9001 | /** |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 9002 | * Return the Preferred Roaming List Version. |
| 9003 | * |
| 9004 | * @param subId the subscription ID that this request applies to. |
| 9005 | * @return PRLVersion or null if error. |
| 9006 | */ |
| 9007 | @Override |
| 9008 | public String getCdmaPrlVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 9009 | enforceReadPrivilegedPermission("getCdmaPrlVersion"); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 9010 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9011 | |
| 9012 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 9013 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9014 | if (phone == null) { |
| 9015 | return null; |
| 9016 | } |
| 9017 | String cdmaPrlVersion = null; |
| 9018 | try { |
| 9019 | cdmaPrlVersion = phone.getCdmaPrlVersion(); |
| 9020 | } catch (Exception e) { |
| 9021 | Log.e(LOG_TAG, "Not getting PRLVersion", e); |
| 9022 | } |
| 9023 | return cdmaPrlVersion; |
| 9024 | } finally { |
| 9025 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 9026 | } |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 9027 | } |
| 9028 | |
| 9029 | /** |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 9030 | * Get snapshot of Telephony histograms |
| 9031 | * @return List of Telephony histograms |
| 9032 | * @hide |
| 9033 | */ |
| 9034 | @Override |
| 9035 | public List<TelephonyHistogram> getTelephonyHistograms() { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 9036 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9037 | mApp, getDefaultSubscription(), "getTelephonyHistograms"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9038 | |
| 9039 | final long identity = Binder.clearCallingIdentity(); |
| 9040 | try { |
| 9041 | return RIL.getTelephonyRILTimingHistograms(); |
| 9042 | } finally { |
| 9043 | Binder.restoreCallingIdentity(identity); |
| 9044 | } |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 9045 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 9046 | |
| 9047 | /** |
| 9048 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 9049 | * Set the allowed carrier list and the excluded carrier list, indicating the priority between |
| 9050 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 9051 | * Require system privileges. In the future we may add this to carrier APIs. |
| 9052 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 9053 | * @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] | 9054 | */ |
| 9055 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 9056 | @TelephonyManager.SetCarrierRestrictionResult |
| 9057 | public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) { |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 9058 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 9059 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 9060 | |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 9061 | if (carrierRestrictionRules == null) { |
| 9062 | throw new NullPointerException("carrier restriction cannot be null"); |
Meng Wang | 9b7c4e9 | 2017-02-17 11:41:27 -0800 | [diff] [blame] | 9063 | } |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 9064 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9065 | final long identity = Binder.clearCallingIdentity(); |
| 9066 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 9067 | return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 9068 | workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9069 | } finally { |
| 9070 | Binder.restoreCallingIdentity(identity); |
| 9071 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 9072 | } |
| 9073 | |
| 9074 | /** |
| 9075 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 9076 | * Get the allowed carrier list and the excluded carrier list, including the priority between |
| 9077 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 9078 | * Require system privileges. In the future we may add this to carrier APIs. |
| 9079 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 9080 | * @return {@link android.telephony.CarrierRestrictionRules} |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 9081 | */ |
| 9082 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 9083 | public CarrierRestrictionRules getAllowedCarriers() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 9084 | enforceReadPrivilegedPermission("getAllowedCarriers"); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 9085 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9086 | |
| 9087 | final long identity = Binder.clearCallingIdentity(); |
| 9088 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 9089 | Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource); |
| 9090 | if (response instanceof CarrierRestrictionRules) { |
| 9091 | return (CarrierRestrictionRules) response; |
| 9092 | } |
| 9093 | // Response is an Exception of some kind, |
| 9094 | // which is signalled to the user as a NULL retval |
| 9095 | return null; |
| 9096 | } catch (Exception e) { |
| 9097 | Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e); |
| 9098 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9099 | } finally { |
| 9100 | Binder.restoreCallingIdentity(identity); |
| 9101 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 9102 | } |
| 9103 | |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 9104 | /** |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 9105 | * Fetches the carrier restriction status of the device and sends the status to the caller |
| 9106 | * through the callback. |
| 9107 | * |
| 9108 | * @param callback The callback that will be used to send the result. |
| 9109 | * @throws SecurityException if the caller does not have the required permission/privileges or |
| 9110 | * the caller is not allowlisted. |
| 9111 | */ |
| 9112 | @Override |
| 9113 | public void getCarrierRestrictionStatus(IIntegerConsumer callback, String packageName) { |
| 9114 | enforceReadPermission("getCarrierRestrictionStatus"); |
| 9115 | int carrierId = validateCallerAndGetCarrierId(packageName); |
| 9116 | if (carrierId == CarrierAllowListInfo.INVALID_CARRIER_ID) { |
| 9117 | Rlog.e(LOG_TAG, "getCarrierRestrictionStatus: caller is not registered"); |
| 9118 | throw new SecurityException("Not an authorized caller"); |
| 9119 | } |
| 9120 | final long identity = Binder.clearCallingIdentity(); |
| 9121 | try { |
| 9122 | Consumer<Integer> consumer = FunctionalUtils.ignoreRemoteException(callback::accept); |
| 9123 | CallerCallbackInfo callbackInfo = new CallerCallbackInfo(consumer, carrierId); |
| 9124 | sendRequestAsync(CMD_GET_ALLOWED_CARRIERS, callbackInfo); |
| 9125 | } finally { |
| 9126 | Binder.restoreCallingIdentity(identity); |
| 9127 | } |
| 9128 | } |
| 9129 | |
| 9130 | @VisibleForTesting |
| 9131 | public int validateCallerAndGetCarrierId(String packageName) { |
| 9132 | CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp); |
| 9133 | return allowListInfo.validateCallerAndGetCarrierId(packageName); |
| 9134 | } |
| 9135 | |
| 9136 | /** |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 9137 | * Action set from carrier signalling broadcast receivers to enable/disable radio |
| 9138 | * @param subId the subscription ID that this action applies to. |
| 9139 | * @param enabled control enable or disable radio. |
| 9140 | * {@hide} |
| 9141 | */ |
| 9142 | @Override |
| 9143 | public void carrierActionSetRadioEnabled(int subId, boolean enabled) { |
| 9144 | enforceModifyPermission(); |
| 9145 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9146 | |
| 9147 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 9148 | if (phone == null) { |
| 9149 | loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId); |
| 9150 | return; |
| 9151 | } |
| 9152 | try { |
| 9153 | phone.carrierActionSetRadioEnabled(enabled); |
| 9154 | } catch (Exception e) { |
| 9155 | Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9156 | } finally { |
| 9157 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 9158 | } |
| 9159 | } |
| 9160 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 9161 | /** |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 9162 | * Enable or disable Voice over NR (VoNR) |
| 9163 | * @param subId the subscription ID that this action applies to. |
| 9164 | * @param enabled enable or disable VoNR. |
| 9165 | * @return operation result. |
| 9166 | */ |
| 9167 | @Override |
| 9168 | public int setVoNrEnabled(int subId, boolean enabled) { |
| 9169 | enforceModifyPermission(); |
| 9170 | final Phone phone = getPhone(subId); |
| 9171 | |
| 9172 | final long identity = Binder.clearCallingIdentity(); |
| 9173 | if (phone == null) { |
| 9174 | loge("setVoNrEnabled fails with no phone object for subId: " + subId); |
| 9175 | return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE; |
| 9176 | } |
| 9177 | |
| 9178 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 9179 | try { |
| 9180 | int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId, |
| 9181 | workSource); |
| 9182 | if (DBG) log("setVoNrEnabled result: " + result); |
Gary Jian | 8dd305f | 2021-10-14 16:31:35 +0800 | [diff] [blame] | 9183 | |
| 9184 | if (result == TelephonyManager.ENABLE_VONR_SUCCESS) { |
| 9185 | if (DBG) { |
| 9186 | log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled); |
| 9187 | } |
| 9188 | SubscriptionManager.setSubscriptionProperty( |
| 9189 | subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED, |
| 9190 | (enabled ? "1" : "0")); |
| 9191 | } |
| 9192 | |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 9193 | return result; |
| 9194 | } finally { |
| 9195 | Binder.restoreCallingIdentity(identity); |
| 9196 | } |
| 9197 | } |
| 9198 | |
| 9199 | /** |
| 9200 | * Is voice over NR enabled |
| 9201 | * @return true if VoNR is enabled else false |
| 9202 | */ |
| 9203 | @Override |
| 9204 | public boolean isVoNrEnabled(int subId) { |
| 9205 | enforceReadPrivilegedPermission("isVoNrEnabled"); |
| 9206 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 9207 | final long identity = Binder.clearCallingIdentity(); |
| 9208 | try { |
| 9209 | boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED, |
| 9210 | null, subId, workSource); |
| 9211 | if (DBG) log("isVoNrEnabled: " + isEnabled); |
| 9212 | return isEnabled; |
| 9213 | } finally { |
| 9214 | Binder.restoreCallingIdentity(identity); |
| 9215 | } |
| 9216 | } |
| 9217 | |
| 9218 | /** |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 9219 | * Action set from carrier signalling broadcast receivers to start/stop reporting the default |
| 9220 | * network status based on which carrier apps could apply actions accordingly, |
| 9221 | * enable/disable default url handler for example. |
| 9222 | * |
| 9223 | * @param subId the subscription ID that this action applies to. |
| 9224 | * @param report control start/stop reporting the default network status. |
| 9225 | * {@hide} |
| 9226 | */ |
| 9227 | @Override |
| 9228 | public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) { |
| 9229 | enforceModifyPermission(); |
| 9230 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9231 | |
| 9232 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 9233 | if (phone == null) { |
| 9234 | loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId); |
| 9235 | return; |
| 9236 | } |
| 9237 | try { |
| 9238 | phone.carrierActionReportDefaultNetworkStatus(report); |
| 9239 | } catch (Exception e) { |
| 9240 | Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9241 | } finally { |
| 9242 | Binder.restoreCallingIdentity(identity); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 9243 | } |
| 9244 | } |
| 9245 | |
| 9246 | /** |
fionaxu | d962228 | 2017-07-17 17:51:30 -0700 | [diff] [blame] | 9247 | * Action set from carrier signalling broadcast receivers to reset all carrier actions |
| 9248 | * @param subId the subscription ID that this action applies to. |
| 9249 | * {@hide} |
| 9250 | */ |
| 9251 | @Override |
| 9252 | public void carrierActionResetAll(int subId) { |
| 9253 | enforceModifyPermission(); |
| 9254 | final Phone phone = getPhone(subId); |
| 9255 | if (phone == null) { |
| 9256 | loge("carrierAction: ResetAll fails with invalid sibId: " + subId); |
| 9257 | return; |
| 9258 | } |
| 9259 | try { |
| 9260 | phone.carrierActionResetAll(); |
| 9261 | } catch (Exception e) { |
| 9262 | Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e); |
| 9263 | } |
| 9264 | } |
| 9265 | |
| 9266 | /** |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 9267 | * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a |
| 9268 | * bug report is being generated. |
| 9269 | */ |
| 9270 | @Override |
Ta-wei Yen | 99282e0 | 2016-06-21 18:19:35 -0700 | [diff] [blame] | 9271 | protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9272 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 9273 | != PackageManager.PERMISSION_GRANTED) { |
dcashman | 22b950d | 2016-06-27 11:39:02 -0700 | [diff] [blame] | 9274 | writer.println("Permission Denial: can't dump Phone from pid=" |
| 9275 | + Binder.getCallingPid() |
| 9276 | + ", uid=" + Binder.getCallingUid() |
| 9277 | + "without permission " |
| 9278 | + android.Manifest.permission.DUMP); |
| 9279 | return; |
| 9280 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9281 | DumpsysHandler.dump(mApp, fd, writer, args); |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 9282 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 9283 | |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 9284 | @Override |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 9285 | public int handleShellCommand(@NonNull ParcelFileDescriptor in, |
| 9286 | @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err, |
| 9287 | @NonNull String[] args) { |
| 9288 | return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec( |
| 9289 | this, in.getFileDescriptor(), out.getFileDescriptor(), |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 9290 | err.getFileDescriptor(), args); |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 9291 | } |
| 9292 | |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 9293 | /** |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 9294 | * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason} |
Greg Kaiser | 17f4175 | 2020-05-05 16:47:47 +0000 | [diff] [blame] | 9295 | * @param subId Subscription index |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 9296 | * @param reason The reason the data enable change is taking place. |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 9297 | * @param enabled True if enabling the data, otherwise disabling. |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 9298 | * @param callingPackage The package that changed the data enabled state. |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 9299 | * @hide |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 9300 | */ |
| 9301 | @Override |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 9302 | public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 9303 | boolean enabled, String callingPackage) { |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 9304 | if (reason == TelephonyManager.DATA_ENABLED_REASON_USER |
| 9305 | || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 9306 | try { |
| 9307 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 9308 | mApp, subId, "setDataEnabledForReason"); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 9309 | } catch (SecurityException se) { |
| 9310 | enforceModifyPermission(); |
| 9311 | } |
| 9312 | } else { |
| 9313 | enforceModifyPermission(); |
| 9314 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9315 | |
| 9316 | final long identity = Binder.clearCallingIdentity(); |
| 9317 | try { |
| 9318 | Phone phone = getPhone(subId); |
| 9319 | if (phone != null) { |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 9320 | if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 9321 | phone.carrierActionSetMeteredApnsEnabled(enabled); |
| 9322 | } else { |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 9323 | phone.getDataSettingsManager().setDataEnabled( |
| 9324 | reason, enabled, callingPackage); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 9325 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9326 | } |
| 9327 | } finally { |
| 9328 | Binder.restoreCallingIdentity(identity); |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 9329 | } |
| 9330 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 9331 | |
| 9332 | /** |
| 9333 | * Get Client request stats |
| 9334 | * @return List of Client Request Stats |
| 9335 | * @hide |
| 9336 | */ |
| 9337 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9338 | public List<ClientRequestStats> getClientRequestStats(String callingPackage, |
| 9339 | String callingFeatureId, int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 9340 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9341 | mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) { |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 9342 | return null; |
| 9343 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 9344 | Phone phone = getPhone(subId); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 9345 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9346 | final long identity = Binder.clearCallingIdentity(); |
| 9347 | try { |
| 9348 | if (phone != null) { |
| 9349 | return phone.getClientRequestStats(); |
| 9350 | } |
| 9351 | |
| 9352 | return null; |
| 9353 | } finally { |
| 9354 | Binder.restoreCallingIdentity(identity); |
| 9355 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 9356 | } |
| 9357 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 9358 | private WorkSource getWorkSource(int uid) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9359 | String packageName = mApp.getPackageManager().getNameForUid(uid); |
Hunter Knepshield | d03383b | 2022-03-29 22:47:54 +0000 | [diff] [blame] | 9360 | if (uid == Process.ROOT_UID && packageName == null) { |
| 9361 | // Downstream WorkSource attribution inside the RIL requires both a UID and package name |
| 9362 | // to be set for wakelock tracking, otherwise RIL requests fail with a runtime |
| 9363 | // exception. ROOT_UID seems not to have a valid package name returned by |
| 9364 | // PackageManager, so just fake it here to avoid issues when running telephony shell |
| 9365 | // commands that plumb through the RIL as root, like so: |
| 9366 | // $ adb root |
| 9367 | // $ adb shell cmd phone ... |
| 9368 | packageName = "root"; |
| 9369 | } |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 9370 | return new WorkSource(uid, packageName); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 9371 | } |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 9372 | |
| 9373 | /** |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 9374 | * Set SIM card power state. |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 9375 | * |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 9376 | * @param slotIndex SIM slot id. |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 9377 | * @param state State of SIM (power down, power up, pass through) |
| 9378 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 9379 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 9380 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 9381 | * |
| 9382 | **/ |
| 9383 | @Override |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 9384 | public void setSimPowerStateForSlot(int slotIndex, int state) { |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 9385 | enforceModifyPermission(); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 9386 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 9387 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 9388 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 9389 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9390 | final long identity = Binder.clearCallingIdentity(); |
| 9391 | try { |
| 9392 | if (phone != null) { |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 9393 | phone.setSimPowerState(state, null, workSource); |
| 9394 | } |
| 9395 | } finally { |
| 9396 | Binder.restoreCallingIdentity(identity); |
| 9397 | } |
| 9398 | } |
| 9399 | |
| 9400 | /** |
| 9401 | * Set SIM card power state. |
| 9402 | * |
| 9403 | * @param slotIndex SIM slot id. |
| 9404 | * @param state State of SIM (power down, power up, pass through) |
| 9405 | * @param callback callback to trigger after success or failure |
| 9406 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 9407 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 9408 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
| 9409 | * |
| 9410 | **/ |
| 9411 | @Override |
| 9412 | public void setSimPowerStateForSlotWithCallback(int slotIndex, int state, |
| 9413 | IIntegerConsumer callback) { |
| 9414 | enforceModifyPermission(); |
| 9415 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 9416 | |
| 9417 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 9418 | |
| 9419 | final long identity = Binder.clearCallingIdentity(); |
| 9420 | try { |
| 9421 | if (phone != null) { |
| 9422 | Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback); |
| 9423 | sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9424 | } |
| 9425 | } finally { |
| 9426 | Binder.restoreCallingIdentity(identity); |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 9427 | } |
| 9428 | } |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 9429 | |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 9430 | private boolean isUssdApiAllowed(int subId) { |
| 9431 | CarrierConfigManager configManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9432 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 9433 | if (configManager == null) { |
| 9434 | return false; |
| 9435 | } |
| 9436 | PersistableBundle pb = configManager.getConfigForSubId(subId); |
| 9437 | if (pb == null) { |
| 9438 | return false; |
| 9439 | } |
| 9440 | return pb.getBoolean( |
| 9441 | CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL); |
| 9442 | } |
| 9443 | |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 9444 | /** |
| 9445 | * Check if phone is in emergency callback mode |
| 9446 | * @return true if phone is in emergency callback mode |
| 9447 | * @param subId sub id |
| 9448 | */ |
goneil | 9c5f487 | 2017-12-05 14:07:56 -0800 | [diff] [blame] | 9449 | @Override |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 9450 | public boolean getEmergencyCallbackMode(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 9451 | enforceReadPrivilegedPermission("getEmergencyCallbackMode"); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 9452 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9453 | |
| 9454 | final long identity = Binder.clearCallingIdentity(); |
| 9455 | try { |
| 9456 | if (phone != null) { |
| 9457 | return phone.isInEcm(); |
| 9458 | } else { |
| 9459 | return false; |
| 9460 | } |
| 9461 | } finally { |
| 9462 | Binder.restoreCallingIdentity(identity); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 9463 | } |
| 9464 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 9465 | |
| 9466 | /** |
| 9467 | * Get the current signal strength information for the given subscription. |
| 9468 | * Because this information is not updated when the device is in a low power state |
| 9469 | * it should not be relied-upon to be current. |
| 9470 | * @param subId Subscription index |
| 9471 | * @return the most recent cached signal strength info from the modem |
| 9472 | */ |
| 9473 | @Override |
| 9474 | public SignalStrength getSignalStrength(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9475 | final long identity = Binder.clearCallingIdentity(); |
| 9476 | try { |
| 9477 | Phone p = getPhone(subId); |
| 9478 | if (p == null) { |
| 9479 | return null; |
| 9480 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 9481 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9482 | return p.getSignalStrength(); |
| 9483 | } finally { |
| 9484 | Binder.restoreCallingIdentity(identity); |
| 9485 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 9486 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9487 | |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9488 | /** |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 9489 | * Get the current modem radio state for the given slot. |
| 9490 | * @param slotIndex slot index. |
| 9491 | * @param callingPackage the name of the package making the call. |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9492 | * @param callingFeatureId The feature in the package. |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 9493 | * @return the current radio power state from the modem |
| 9494 | */ |
| 9495 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9496 | public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 9497 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 9498 | if (phone != null) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9499 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(), |
| 9500 | callingPackage, callingFeatureId, "getRadioPowerState")) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 9501 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 9502 | } |
| 9503 | |
| 9504 | final long identity = Binder.clearCallingIdentity(); |
| 9505 | try { |
| 9506 | return phone.getRadioPowerState(); |
| 9507 | } finally { |
| 9508 | Binder.restoreCallingIdentity(identity); |
| 9509 | } |
| 9510 | } |
| 9511 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 9512 | } |
| 9513 | |
| 9514 | /** |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9515 | * Checks if data roaming is enabled on the subscription with id {@code subId}. |
| 9516 | * |
| 9517 | * <p>Requires one of the following permissions: |
| 9518 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}, |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 9519 | * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE}, |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9520 | * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier |
| 9521 | * privileges. |
| 9522 | * |
| 9523 | * @param subId subscription id |
| 9524 | * @return {@code true} if data roaming is enabled on this subscription, otherwise return |
| 9525 | * {@code false}. |
| 9526 | */ |
| 9527 | @Override |
| 9528 | public boolean isDataRoamingEnabled(int subId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 9529 | String functionName = "isDataRoamingEnabled"; |
Shuo Qian | 093013d | 2020-08-13 15:42:55 -0700 | [diff] [blame] | 9530 | try { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 9531 | try { |
| 9532 | mApp.enforceCallingOrSelfPermission( |
| 9533 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 9534 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 9535 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 9536 | mApp.enforceCallingOrSelfPermission( |
| 9537 | permission.READ_BASIC_PHONE_STATE, functionName); |
| 9538 | } |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 9539 | } catch (SecurityException e) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9540 | TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 9541 | mApp, subId, functionName); |
Shuo Qian | 093013d | 2020-08-13 15:42:55 -0700 | [diff] [blame] | 9542 | } |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 9543 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9544 | boolean isEnabled = false; |
| 9545 | final long identity = Binder.clearCallingIdentity(); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9546 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9547 | Phone phone = getPhone(subId); |
| 9548 | isEnabled = phone != null ? phone.getDataRoamingEnabled() : false; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9549 | } finally { |
| 9550 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9551 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9552 | return isEnabled; |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9553 | } |
| 9554 | |
| 9555 | |
| 9556 | /** |
| 9557 | * Enables/Disables the data roaming on the subscription with id {@code subId}. |
| 9558 | * |
| 9559 | * <p> Requires permission: |
| 9560 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier |
| 9561 | * privileges. |
| 9562 | * |
| 9563 | * @param subId subscription id |
| 9564 | * @param isEnabled {@code true} means enable, {@code false} means disable. |
| 9565 | */ |
| 9566 | @Override |
| 9567 | public void setDataRoamingEnabled(int subId, boolean isEnabled) { |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 9568 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9569 | mApp, subId, "setDataRoamingEnabled"); |
| 9570 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9571 | final long identity = Binder.clearCallingIdentity(); |
| 9572 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9573 | Phone phone = getPhone(subId); |
| 9574 | if (phone != null) { |
| 9575 | phone.setDataRoamingEnabled(isEnabled); |
| 9576 | } |
| 9577 | } finally { |
| 9578 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9579 | } |
| 9580 | } |
| 9581 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9582 | @Override |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 9583 | public boolean isManualNetworkSelectionAllowed(int subId) { |
tom hsu | c91afc7 | 2020-01-06 23:46:07 +0800 | [diff] [blame] | 9584 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9585 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 9586 | mApp, subId, "isManualNetworkSelectionAllowed"); |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 9587 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 9588 | boolean isAllowed = true; |
| 9589 | final long identity = Binder.clearCallingIdentity(); |
| 9590 | try { |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 9591 | Phone phone = getPhone(subId); |
| 9592 | if (phone != null) { |
| 9593 | isAllowed = phone.isCspPlmnEnabled(); |
| 9594 | } |
| 9595 | } finally { |
| 9596 | Binder.restoreCallingIdentity(identity); |
| 9597 | } |
| 9598 | return isAllowed; |
| 9599 | } |
| 9600 | |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9601 | private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) { |
| 9602 | UiccProfile profile = port.getUiccProfile(); |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 9603 | if (profile == null) { |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9604 | return false; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9605 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 9606 | Phone phone = PhoneFactory.getPhone(profile.getPhoneId()); |
| 9607 | if (phone == null) { |
| 9608 | return false; |
| 9609 | } |
| 9610 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 9611 | return cpt != null && cpt.getCarrierPrivilegeStatusForPackage(callingPackage) |
| 9612 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9613 | } |
| 9614 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 9615 | @Override |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 9616 | public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) { |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9617 | // Verify that the callingPackage belongs to the calling UID |
Jordan Liu | 4cda455 | 2020-03-23 11:55:07 -0700 | [diff] [blame] | 9618 | mApp.getSystemService(AppOpsManager.class) |
| 9619 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 9620 | |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9621 | boolean hasReadPermission = false; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9622 | boolean isIccIdAccessRestricted = false; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 9623 | try { |
| 9624 | enforceReadPrivilegedPermission("getUiccCardsInfo"); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9625 | hasReadPermission = true; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 9626 | } catch (SecurityException e) { |
| 9627 | // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller |
| 9628 | // has carrier privileges on an active UICC |
Rambo Wang | e7209ce | 2022-02-23 13:41:02 -0800 | [diff] [blame] | 9629 | if (checkCarrierPrivilegesForPackageAnyPhoneWithPermission(callingPackage) |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 9630 | != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9631 | throw new SecurityException("Caller does not have permission."); |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 9632 | } |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 9633 | } |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9634 | // checking compatibility, if calling app's target SDK is T and beyond. |
| 9635 | if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO, |
| 9636 | Binder.getCallingUid())) { |
| 9637 | isIccIdAccessRestricted = true; |
| 9638 | } |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 9639 | final long identity = Binder.clearCallingIdentity(); |
| 9640 | try { |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 9641 | UiccController uiccController = UiccController.getInstance(); |
| 9642 | ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos(); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9643 | if (hasReadPermission) { |
| 9644 | return cardInfos; |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 9645 | } |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9646 | |
| 9647 | // Remove private info if the caller doesn't have access |
| 9648 | ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>(); |
| 9649 | for (UiccCardInfo cardInfo : cardInfos) { |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9650 | //setting the value after compatibility check |
| 9651 | cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9652 | // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo |
| 9653 | // is available |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9654 | UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex()); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9655 | if (card == null) { |
| 9656 | // assume no access if the card is unavailable |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9657 | filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo)); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9658 | continue; |
| 9659 | } |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9660 | Collection<UiccPortInfo> portInfos = cardInfo.getPorts(); |
| 9661 | if (portInfos.isEmpty()) { |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9662 | filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo)); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9663 | continue; |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9664 | } |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9665 | List<UiccPortInfo> uiccPortInfos = new ArrayList<>(); |
| 9666 | for (UiccPortInfo portInfo : portInfos) { |
| 9667 | UiccPort port = uiccController.getUiccPortForSlot( |
| 9668 | cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex()); |
| 9669 | if (port == null) { |
| 9670 | // assume no access if port is null |
| 9671 | uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo)); |
| 9672 | continue; |
| 9673 | } |
| 9674 | if (haveCarrierPrivilegeAccess(port, callingPackage)) { |
| 9675 | uiccPortInfos.add(portInfo); |
| 9676 | } else { |
| 9677 | uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo)); |
| 9678 | } |
| 9679 | } |
| 9680 | filteredInfos.add(new UiccCardInfo( |
| 9681 | cardInfo.isEuicc(), |
| 9682 | cardInfo.getCardId(), |
| 9683 | null, |
| 9684 | cardInfo.getPhysicalSlotIndex(), |
| 9685 | cardInfo.isRemovable(), |
| 9686 | cardInfo.isMultipleEnabledProfilesSupported(), |
| 9687 | uiccPortInfos)); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9688 | } |
| 9689 | return filteredInfos; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 9690 | } finally { |
| 9691 | Binder.restoreCallingIdentity(identity); |
| 9692 | } |
| 9693 | } |
| 9694 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9695 | /** |
| 9696 | * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are |
| 9697 | * generally private and require carrier privileges to view. |
| 9698 | * |
| 9699 | * @hide |
| 9700 | */ |
| 9701 | @NonNull |
| 9702 | public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) { |
| 9703 | List<UiccPortInfo> portinfo = new ArrayList<>(); |
| 9704 | for (UiccPortInfo portinfos : cardInfo.getPorts()) { |
| 9705 | portinfo.add(getUiccPortInfoUnPrivileged(portinfos)); |
| 9706 | } |
| 9707 | return new UiccCardInfo( |
| 9708 | cardInfo.isEuicc(), |
| 9709 | cardInfo.getCardId(), |
| 9710 | null, |
| 9711 | cardInfo.getPhysicalSlotIndex(), |
| 9712 | cardInfo.isRemovable(), |
| 9713 | cardInfo.isMultipleEnabledProfilesSupported(), |
| 9714 | portinfo |
| 9715 | ); |
| 9716 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9717 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9718 | /** |
| 9719 | * @hide |
| 9720 | * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}. |
| 9721 | * These values are generally private and require carrier privileges to view. |
| 9722 | */ |
| 9723 | @NonNull |
| 9724 | public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) { |
| 9725 | return new UiccPortInfo( |
| 9726 | UiccPortInfo.ICCID_REDACTED, |
| 9727 | portInfo.getPortIndex(), |
| 9728 | portInfo.getLogicalSlotIndex(), |
| 9729 | portInfo.isActive() |
| 9730 | ); |
| 9731 | } |
| 9732 | @Override |
| 9733 | public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) { |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9734 | // Verify that the callingPackage belongs to the calling UID |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9735 | mApp.getSystemService(AppOpsManager.class) |
| 9736 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 9737 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9738 | boolean isLogicalSlotAccessRestricted = false; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9739 | |
Aman Gupta | f3c90b3 | 2022-03-17 04:54:16 +0000 | [diff] [blame] | 9740 | // This will make sure caller has the READ_PRIVILEGED_PHONE_STATE. Do not remove this as |
| 9741 | // we are reading iccId which is PII data. |
| 9742 | enforceReadPrivilegedPermission("getUiccSlotsInfo"); |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9743 | |
| 9744 | // checking compatibility, if calling app's target SDK is T and beyond. |
| 9745 | if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO, |
| 9746 | Binder.getCallingUid())) { |
| 9747 | isLogicalSlotAccessRestricted = true; |
| 9748 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9749 | final long identity = Binder.clearCallingIdentity(); |
| 9750 | try { |
| 9751 | UiccSlot[] slots = UiccController.getInstance().getUiccSlots(); |
Muralidhar Reddy | d196bbf | 2022-01-17 17:56:30 +0000 | [diff] [blame] | 9752 | if (slots == null || slots.length == 0) { |
| 9753 | Rlog.i(LOG_TAG, "slots is null or empty."); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9754 | return null; |
| 9755 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9756 | UiccSlotInfo[] infos = new UiccSlotInfo[slots.length]; |
| 9757 | for (int i = 0; i < slots.length; i++) { |
| 9758 | UiccSlot slot = slots[i]; |
| 9759 | if (slot == null) { |
| 9760 | continue; |
| 9761 | } |
| 9762 | |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 9763 | String cardId; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9764 | UiccCard card = slot.getUiccCard(); |
| 9765 | if (card != null) { |
| 9766 | cardId = card.getCardId(); |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 9767 | } else { |
Jordan Liu | 01bd00d | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 9768 | cardId = slot.getEid(); |
| 9769 | if (TextUtils.isEmpty(cardId)) { |
Aman Gupta | f3c90b3 | 2022-03-17 04:54:16 +0000 | [diff] [blame] | 9770 | // If cardId is null, use iccId of default port as cardId. |
| 9771 | cardId = slot.getIccId(TelephonyManager.DEFAULT_PORT_INDEX); |
Jordan Liu | 01bd00d | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 9772 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9773 | } |
| 9774 | |
Jordan Liu | 857451f | 2019-05-09 16:35:35 -0700 | [diff] [blame] | 9775 | if (cardId != null) { |
| 9776 | // if cardId is an ICCID, strip off trailing Fs before exposing to user |
| 9777 | // if cardId is an EID, it's all digits so this is fine |
| 9778 | cardId = IccUtils.stripTrailingFs(cardId); |
| 9779 | } |
| 9780 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9781 | int cardState = 0; |
| 9782 | switch (slot.getCardState()) { |
| 9783 | case CARDSTATE_ABSENT: |
| 9784 | cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT; |
| 9785 | break; |
| 9786 | case CARDSTATE_PRESENT: |
| 9787 | cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT; |
| 9788 | break; |
| 9789 | case CARDSTATE_ERROR: |
| 9790 | cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR; |
| 9791 | break; |
| 9792 | case CARDSTATE_RESTRICTED: |
| 9793 | cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED; |
| 9794 | break; |
| 9795 | default: |
| 9796 | break; |
| 9797 | |
| 9798 | } |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9799 | List<UiccPortInfo> portInfos = new ArrayList<>(); |
| 9800 | int[] portIndexes = slot.getPortList(); |
| 9801 | for (int portIdx : portIndexes) { |
| 9802 | String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx, |
Aman Gupta | f3c90b3 | 2022-03-17 04:54:16 +0000 | [diff] [blame] | 9803 | callingPackage, /* hasReadPermission= */ true)); |
Muralidhar Reddy | fbcff0c | 2022-01-19 13:07:57 +0000 | [diff] [blame] | 9804 | portInfos.add(new UiccPortInfo(iccId, portIdx, |
| 9805 | slot.getPhoneIdFromPortIndex(portIdx), slot.isPortActive(portIdx))); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9806 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9807 | infos[i] = new UiccSlotInfo( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9808 | slot.isEuicc(), |
| 9809 | cardId, |
| 9810 | cardState, |
Jordan Liu | a261958 | 2019-02-14 12:56:40 -0800 | [diff] [blame] | 9811 | slot.isExtendedApduSupported(), |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9812 | slot.isRemovable(), portInfos); |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9813 | //setting the value after compatibility check |
| 9814 | infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9815 | } |
| 9816 | return infos; |
| 9817 | } finally { |
| 9818 | Binder.restoreCallingIdentity(identity); |
Holly Jiuyu Sun | 1d957c5 | 2018-04-04 13:52:42 -0700 | [diff] [blame] | 9819 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9820 | } |
| 9821 | |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9822 | /* Returns null if doesn't have read permission or carrier privilege access. */ |
| 9823 | private String getIccId(UiccSlot slot, int portIndex, String callingPackage, |
| 9824 | boolean hasReadPermission) { |
| 9825 | String iccId = slot.getIccId(portIndex); |
| 9826 | if (hasReadPermission) { // if has read permission |
| 9827 | return iccId; |
| 9828 | } else { |
| 9829 | if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) { |
| 9830 | UiccPort port = slot.getUiccCard().getUiccPort(portIndex); |
| 9831 | // if no read permission, checking carrier privilege access |
| 9832 | if (haveCarrierPrivilegeAccess(port, callingPackage)) { |
| 9833 | return iccId; |
| 9834 | } |
| 9835 | } |
| 9836 | } |
| 9837 | // No read permission or carrier privilege access. |
| 9838 | return UiccPortInfo.ICCID_REDACTED; |
| 9839 | } |
| 9840 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9841 | @Override |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9842 | @Deprecated |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9843 | public boolean switchSlots(int[] physicalSlots) { |
| 9844 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9845 | |
| 9846 | final long identity = Binder.clearCallingIdentity(); |
| 9847 | try { |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9848 | List<UiccSlotMapping> slotMappings = new ArrayList<>(); |
| 9849 | for (int i = 0; i < physicalSlots.length; i++) { |
| 9850 | // Deprecated API, hence MEP is not supported. Adding default portIndex 0. |
| 9851 | slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX, |
| 9852 | physicalSlots[i], i)); |
| 9853 | } |
| 9854 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9855 | } finally { |
| 9856 | Binder.restoreCallingIdentity(identity); |
| 9857 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9858 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 9859 | |
| 9860 | @Override |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9861 | @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 9862 | public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) { |
| 9863 | enforceModifyPermission(); |
| 9864 | |
| 9865 | final long identity = Binder.clearCallingIdentity(); |
| 9866 | try { |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9867 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping); |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9868 | } finally { |
| 9869 | Binder.restoreCallingIdentity(identity); |
| 9870 | } |
| 9871 | } |
| 9872 | |
| 9873 | @Override |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 9874 | public int getCardIdForDefaultEuicc(int subId, String callingPackage) { |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 9875 | final long identity = Binder.clearCallingIdentity(); |
| 9876 | try { |
| 9877 | return UiccController.getInstance().getCardIdForDefaultEuicc(); |
| 9878 | } finally { |
| 9879 | Binder.restoreCallingIdentity(identity); |
| 9880 | } |
| 9881 | } |
| 9882 | |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9883 | /** |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 9884 | * A test API to reload the UICC profile. |
| 9885 | * |
| 9886 | * <p>Requires that the calling app has permission |
| 9887 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 9888 | * @hide |
| 9889 | */ |
| 9890 | @Override |
| 9891 | public void refreshUiccProfile(int subId) { |
| 9892 | enforceModifyPermission(); |
| 9893 | |
| 9894 | final long identity = Binder.clearCallingIdentity(); |
| 9895 | try { |
| 9896 | Phone phone = getPhone(subId); |
| 9897 | if (phone == null) { |
| 9898 | return; |
| 9899 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9900 | UiccPort uiccPort = phone.getUiccPort(); |
| 9901 | if (uiccPort == null) { |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 9902 | return; |
| 9903 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9904 | UiccProfile uiccProfile = uiccPort.getUiccProfile(); |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 9905 | if (uiccProfile == null) { |
| 9906 | return; |
| 9907 | } |
| 9908 | uiccProfile.refresh(); |
| 9909 | } finally { |
| 9910 | Binder.restoreCallingIdentity(identity); |
| 9911 | } |
| 9912 | } |
| 9913 | |
| 9914 | /** |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9915 | * Returns false if the mobile data is disabled by default, otherwise return true. |
| 9916 | */ |
| 9917 | private boolean getDefaultDataEnabled() { |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 9918 | return TelephonyProperties.mobile_data().orElse(true); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9919 | } |
| 9920 | |
| 9921 | /** |
| 9922 | * Returns true if the data roaming is enabled by default, i.e the system property |
| 9923 | * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of |
| 9924 | * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true. |
| 9925 | */ |
| 9926 | private boolean getDefaultDataRoamingEnabled(int subId) { |
| 9927 | final CarrierConfigManager configMgr = (CarrierConfigManager) |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9928 | mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Shuo Qian | 1d84a0e | 2020-07-15 12:36:44 -0700 | [diff] [blame] | 9929 | boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9930 | isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean( |
| 9931 | CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL); |
| 9932 | return isDataRoamingEnabled; |
| 9933 | } |
| 9934 | |
| 9935 | /** |
| 9936 | * Returns the default network type for the given {@code subId}, if the default network type is |
| 9937 | * not set, return {@link Phone#PREFERRED_NT_MODE}. |
| 9938 | */ |
| 9939 | private int getDefaultNetworkType(int subId) { |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 9940 | List<Integer> list = TelephonyProperties.default_network(); |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 9941 | int phoneId = SubscriptionManager.getPhoneId(subId); |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 9942 | if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) { |
| 9943 | return list.get(phoneId); |
| 9944 | } |
| 9945 | return Phone.PREFERRED_NT_MODE; |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9946 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9947 | |
| 9948 | @Override |
| 9949 | public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 9950 | gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) { |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9951 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9952 | |
| 9953 | final long identity = Binder.clearCallingIdentity(); |
| 9954 | try { |
| 9955 | final Phone phone = getPhone(subId); |
| 9956 | if (phone == null) { |
| 9957 | loge("setCarrierTestOverride fails with invalid subId: " + subId); |
| 9958 | return; |
| 9959 | } |
Rambo Wang | 9c9ffdd | 2022-01-13 21:51:44 -0800 | [diff] [blame] | 9960 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 9961 | if (cpt != null) { |
| 9962 | cpt.setTestOverrideCarrierPrivilegeRules(carrierPrivilegeRules); |
| 9963 | } |
| 9964 | // 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] | 9965 | phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn, |
| 9966 | carrierPrivilegeRules, apn); |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 9967 | if (carrierPrivilegeRules == null) { |
| 9968 | mCarrierPrivilegeTestOverrideSubIds.remove(subId); |
| 9969 | } else { |
| 9970 | mCarrierPrivilegeTestOverrideSubIds.add(subId); |
| 9971 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9972 | } finally { |
| 9973 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9974 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9975 | } |
| 9976 | |
| 9977 | @Override |
| 9978 | public int getCarrierIdListVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 9979 | enforceReadPrivilegedPermission("getCarrierIdListVersion"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9980 | |
| 9981 | final long identity = Binder.clearCallingIdentity(); |
| 9982 | try { |
| 9983 | final Phone phone = getPhone(subId); |
| 9984 | if (phone == null) { |
| 9985 | loge("getCarrierIdListVersion fails with invalid subId: " + subId); |
| 9986 | return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION; |
| 9987 | } |
| 9988 | return phone.getCarrierIdListVersion(); |
| 9989 | } finally { |
| 9990 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9991 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9992 | } |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 9993 | |
| 9994 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9995 | public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage, |
| 9996 | String callingFeatureId) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 9997 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9998 | mApp, subId, callingPackage, callingFeatureId, |
| 9999 | "getNumberOfModemsWithSimultaneousDataConnections")) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 10000 | return -1; |
| 10001 | } |
| 10002 | |
| 10003 | final long identity = Binder.clearCallingIdentity(); |
| 10004 | try { |
| 10005 | return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections(); |
| 10006 | } finally { |
| 10007 | Binder.restoreCallingIdentity(identity); |
| 10008 | } |
| 10009 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 10010 | |
| 10011 | @Override |
| 10012 | public int getCdmaRoamingMode(int subId) { |
zoey chen | 7e6d4e5 | 2019-12-17 18:18:59 +0800 | [diff] [blame] | 10013 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 10014 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 10015 | mApp, subId, "getCdmaRoamingMode"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 10016 | |
| 10017 | final long identity = Binder.clearCallingIdentity(); |
| 10018 | try { |
| 10019 | return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId); |
| 10020 | } finally { |
| 10021 | Binder.restoreCallingIdentity(identity); |
| 10022 | } |
| 10023 | } |
| 10024 | |
| 10025 | @Override |
| 10026 | public boolean setCdmaRoamingMode(int subId, int mode) { |
| 10027 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 10028 | mApp, subId, "setCdmaRoamingMode"); |
| 10029 | |
| 10030 | final long identity = Binder.clearCallingIdentity(); |
| 10031 | try { |
| 10032 | return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId); |
| 10033 | } finally { |
| 10034 | Binder.restoreCallingIdentity(identity); |
| 10035 | } |
| 10036 | } |
| 10037 | |
| 10038 | @Override |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 10039 | public int getCdmaSubscriptionMode(int subId) { |
| 10040 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 10041 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 10042 | mApp, subId, "getCdmaSubscriptionMode"); |
| 10043 | |
| 10044 | final long identity = Binder.clearCallingIdentity(); |
| 10045 | try { |
| 10046 | return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId); |
| 10047 | } finally { |
| 10048 | Binder.restoreCallingIdentity(identity); |
| 10049 | } |
| 10050 | } |
| 10051 | |
| 10052 | @Override |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 10053 | public boolean setCdmaSubscriptionMode(int subId, int mode) { |
| 10054 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 10055 | mApp, subId, "setCdmaSubscriptionMode"); |
| 10056 | |
| 10057 | final long identity = Binder.clearCallingIdentity(); |
| 10058 | try { |
| 10059 | return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId); |
| 10060 | } finally { |
| 10061 | Binder.restoreCallingIdentity(identity); |
| 10062 | } |
| 10063 | } |
Makoto Onuki | da3bf79 | 2018-09-18 16:06:29 -0700 | [diff] [blame] | 10064 | |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 10065 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 10066 | public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10067 | String callingPackage, String callingFeatureId) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10068 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10069 | mApp, getDefaultSubscription(), callingPackage, callingFeatureId, |
| 10070 | "getEmergencyNumberList")) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10071 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 10072 | } |
| 10073 | final long identity = Binder.clearCallingIdentity(); |
| 10074 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 10075 | Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>(); |
| 10076 | for (Phone phone: PhoneFactory.getPhones()) { |
| 10077 | if (phone.getEmergencyNumberTracker() != null |
| 10078 | && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) { |
| 10079 | emergencyNumberListInternal.put( |
| 10080 | phone.getSubId(), |
| 10081 | phone.getEmergencyNumberTracker().getEmergencyNumberList()); |
| 10082 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10083 | } |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 10084 | return emergencyNumberListInternal; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10085 | } finally { |
| 10086 | Binder.restoreCallingIdentity(identity); |
| 10087 | } |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 10088 | } |
| 10089 | |
| 10090 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 10091 | public boolean isEmergencyNumber(String number, boolean exactMatch) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 10092 | final Phone defaultPhone = getDefaultPhone(); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10093 | if (!exactMatch) { |
| 10094 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 10095 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 10096 | mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)"); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10097 | } |
| 10098 | final long identity = Binder.clearCallingIdentity(); |
| 10099 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 10100 | for (Phone phone: PhoneFactory.getPhones()) { |
Chinmay Dhodapkar | d521bb1 | 2022-08-16 15:49:54 -0700 | [diff] [blame] | 10101 | //Note: we ignore passed in param exactMatch. We can remove it once |
| 10102 | // TelephonyManager#isPotentialEmergencyNumber is removed completely |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 10103 | if (phone.getEmergencyNumberTracker() != null |
Taesu Lee | e050c00 | 2020-10-13 17:19:35 +0900 | [diff] [blame] | 10104 | && phone.getEmergencyNumberTracker() |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 10105 | .isEmergencyNumber(number)) { |
Taesu Lee | e050c00 | 2020-10-13 17:19:35 +0900 | [diff] [blame] | 10106 | return true; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10107 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10108 | } |
| 10109 | return false; |
| 10110 | } finally { |
| 10111 | Binder.restoreCallingIdentity(identity); |
| 10112 | } |
| 10113 | } |
| 10114 | |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 10115 | /** |
Shuo Qian | ccbaf74 | 2021-02-22 18:32:21 -0800 | [diff] [blame] | 10116 | * Start emergency callback mode for GsmCdmaPhone for testing. |
| 10117 | */ |
| 10118 | @Override |
| 10119 | public void startEmergencyCallbackMode() { |
| 10120 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10121 | "startEmergencyCallbackMode"); |
| 10122 | enforceModifyPermission(); |
| 10123 | final long identity = Binder.clearCallingIdentity(); |
| 10124 | try { |
| 10125 | for (Phone phone : PhoneFactory.getPhones()) { |
| 10126 | Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType()); |
| 10127 | if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM) |
| 10128 | || (phone.getPhoneType() == PHONE_TYPE_CDMA))) { |
| 10129 | GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone; |
| 10130 | gsmCdmaPhone.obtainMessage( |
| 10131 | GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget(); |
| 10132 | Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered"); |
| 10133 | } |
| 10134 | } |
| 10135 | } finally { |
| 10136 | Binder.restoreCallingIdentity(identity); |
| 10137 | } |
| 10138 | } |
| 10139 | |
| 10140 | /** |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 10141 | * Update emergency number list for test mode. |
| 10142 | */ |
| 10143 | @Override |
| 10144 | public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) { |
| 10145 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10146 | "updateEmergencyNumberListTestMode"); |
| 10147 | |
| 10148 | final long identity = Binder.clearCallingIdentity(); |
| 10149 | try { |
| 10150 | for (Phone phone: PhoneFactory.getPhones()) { |
| 10151 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 10152 | if (tracker != null) { |
| 10153 | tracker.executeEmergencyNumberTestModeCommand(action, num); |
| 10154 | } |
| 10155 | } |
| 10156 | } finally { |
| 10157 | Binder.restoreCallingIdentity(identity); |
| 10158 | } |
| 10159 | } |
| 10160 | |
| 10161 | /** |
| 10162 | * Get the full emergency number list for test mode. |
| 10163 | */ |
| 10164 | @Override |
| 10165 | public List<String> getEmergencyNumberListTestMode() { |
| 10166 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10167 | "getEmergencyNumberListTestMode"); |
| 10168 | |
| 10169 | final long identity = Binder.clearCallingIdentity(); |
| 10170 | try { |
| 10171 | Set<String> emergencyNumbers = new HashSet<>(); |
| 10172 | for (Phone phone: PhoneFactory.getPhones()) { |
| 10173 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 10174 | if (tracker != null) { |
| 10175 | for (EmergencyNumber num : tracker.getEmergencyNumberList()) { |
| 10176 | emergencyNumbers.add(num.getNumber()); |
| 10177 | } |
| 10178 | } |
| 10179 | } |
| 10180 | return new ArrayList<>(emergencyNumbers); |
| 10181 | } finally { |
| 10182 | Binder.restoreCallingIdentity(identity); |
| 10183 | } |
| 10184 | } |
| 10185 | |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 10186 | @Override |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 10187 | public int getEmergencyNumberDbVersion(int subId) { |
| 10188 | enforceReadPrivilegedPermission("getEmergencyNumberDbVersion"); |
| 10189 | |
| 10190 | final long identity = Binder.clearCallingIdentity(); |
| 10191 | try { |
| 10192 | final Phone phone = getPhone(subId); |
| 10193 | if (phone == null) { |
| 10194 | loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId); |
| 10195 | return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION; |
| 10196 | } |
| 10197 | return phone.getEmergencyNumberDbVersion(); |
| 10198 | } finally { |
| 10199 | Binder.restoreCallingIdentity(identity); |
| 10200 | } |
| 10201 | } |
| 10202 | |
| 10203 | @Override |
| 10204 | public void notifyOtaEmergencyNumberDbInstalled() { |
| 10205 | enforceModifyPermission(); |
| 10206 | |
| 10207 | final long identity = Binder.clearCallingIdentity(); |
| 10208 | try { |
| 10209 | for (Phone phone: PhoneFactory.getPhones()) { |
| 10210 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 10211 | if (tracker != null) { |
| 10212 | tracker.updateOtaEmergencyNumberDatabase(); |
| 10213 | } |
| 10214 | } |
| 10215 | } finally { |
| 10216 | Binder.restoreCallingIdentity(identity); |
| 10217 | } |
| 10218 | } |
| 10219 | |
| 10220 | @Override |
Shuo Qian | c373f11 | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 10221 | public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) { |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 10222 | enforceActiveEmergencySessionPermission(); |
| 10223 | |
| 10224 | final long identity = Binder.clearCallingIdentity(); |
| 10225 | try { |
| 10226 | for (Phone phone: PhoneFactory.getPhones()) { |
| 10227 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 10228 | if (tracker != null) { |
Shuo Qian | c373f11 | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 10229 | tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor); |
| 10230 | } |
| 10231 | } |
| 10232 | } finally { |
| 10233 | Binder.restoreCallingIdentity(identity); |
| 10234 | } |
| 10235 | } |
| 10236 | |
| 10237 | @Override |
| 10238 | public void resetOtaEmergencyNumberDbFilePath() { |
| 10239 | enforceActiveEmergencySessionPermission(); |
| 10240 | |
| 10241 | final long identity = Binder.clearCallingIdentity(); |
| 10242 | try { |
| 10243 | for (Phone phone: PhoneFactory.getPhones()) { |
| 10244 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 10245 | if (tracker != null) { |
| 10246 | tracker.resetOtaEmergencyNumberDbFilePath(); |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 10247 | } |
| 10248 | } |
| 10249 | } finally { |
| 10250 | Binder.restoreCallingIdentity(identity); |
| 10251 | } |
| 10252 | } |
| 10253 | |
| 10254 | @Override |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 10255 | public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) { |
| 10256 | enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules"); |
| 10257 | Phone phone = getPhone(subId); |
| 10258 | if (phone == null) { |
| 10259 | return null; |
| 10260 | } |
| 10261 | final long identity = Binder.clearCallingIdentity(); |
| 10262 | try { |
| 10263 | UiccProfile profile = UiccController.getInstance() |
| 10264 | .getUiccProfileForPhone(phone.getPhoneId()); |
| 10265 | if (profile != null) { |
| 10266 | return profile.getCertsFromCarrierPrivilegeAccessRules(); |
| 10267 | } |
| 10268 | } finally { |
| 10269 | Binder.restoreCallingIdentity(identity); |
| 10270 | } |
| 10271 | return null; |
| 10272 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 10273 | |
| 10274 | /** |
| 10275 | * Enable or disable a modem stack. |
| 10276 | */ |
| 10277 | @Override |
| 10278 | public boolean enableModemForSlot(int slotIndex, boolean enable) { |
| 10279 | enforceModifyPermission(); |
| 10280 | |
| 10281 | final long identity = Binder.clearCallingIdentity(); |
| 10282 | try { |
| 10283 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 10284 | if (phone == null) { |
| 10285 | return false; |
| 10286 | } else { |
| 10287 | return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null); |
| 10288 | } |
| 10289 | } finally { |
| 10290 | Binder.restoreCallingIdentity(identity); |
| 10291 | } |
| 10292 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 10293 | |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 10294 | /** |
| 10295 | * Whether a modem stack is enabled or not. |
| 10296 | */ |
| 10297 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10298 | public boolean isModemEnabledForSlot(int slotIndex, String callingPackage, |
| 10299 | String callingFeatureId) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 10300 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 10301 | if (phone == null) return false; |
| 10302 | |
| 10303 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10304 | mApp, phone.getSubId(), callingPackage, callingFeatureId, |
| 10305 | "isModemEnabledForSlot")) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 10306 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 10307 | } |
| 10308 | |
| 10309 | final long identity = Binder.clearCallingIdentity(); |
| 10310 | try { |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 10311 | try { |
| 10312 | return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId()); |
| 10313 | } catch (NoSuchElementException ex) { |
| 10314 | return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null); |
| 10315 | } |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 10316 | } finally { |
| 10317 | Binder.restoreCallingIdentity(identity); |
| 10318 | } |
| 10319 | } |
| 10320 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 10321 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10322 | public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) { |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 10323 | enforceModifyPermission(); |
| 10324 | |
| 10325 | final long identity = Binder.clearCallingIdentity(); |
| 10326 | try { |
| 10327 | mTelephonySharedPreferences.edit() |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10328 | .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted) |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 10329 | .commit(); |
| 10330 | } finally { |
| 10331 | Binder.restoreCallingIdentity(identity); |
| 10332 | } |
| 10333 | } |
| 10334 | |
| 10335 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10336 | @TelephonyManager.IsMultiSimSupportedResult |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10337 | public int isMultiSimSupported(String callingPackage, String callingFeatureId) { |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 10338 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10339 | getDefaultPhone().getSubId(), callingPackage, callingFeatureId, |
| 10340 | "isMultiSimSupported")) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10341 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 10342 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 10343 | |
| 10344 | final long identity = Binder.clearCallingIdentity(); |
| 10345 | try { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10346 | return isMultiSimSupportedInternal(); |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 10347 | } finally { |
| 10348 | Binder.restoreCallingIdentity(identity); |
| 10349 | } |
| 10350 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 10351 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10352 | @TelephonyManager.IsMultiSimSupportedResult |
| 10353 | private int isMultiSimSupportedInternal() { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10354 | // If the device has less than 2 SIM cards, indicate that multisim is restricted. |
| 10355 | int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length; |
| 10356 | if (numPhysicalSlots < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10357 | loge("isMultiSimSupportedInternal: requires at least 2 cards"); |
| 10358 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10359 | } |
| 10360 | // Check if the hardware supports multisim functionality. If usage of multisim is not |
| 10361 | // supported by the modem, indicate that it is restricted. |
| 10362 | PhoneCapability staticCapability = |
| 10363 | mPhoneConfigurationManager.getStaticPhoneCapability(); |
| 10364 | if (staticCapability == null) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10365 | loge("isMultiSimSupportedInternal: no static configuration available"); |
| 10366 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10367 | } |
SongFerngWang | 8236caa | 2021-01-17 21:51:44 +0800 | [diff] [blame] | 10368 | if (staticCapability.getLogicalModemList().size() < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10369 | loge("isMultiSimSupportedInternal: maximum number of modem is < 2"); |
| 10370 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10371 | } |
| 10372 | // Check if support of multiple SIMs is restricted by carrier |
| 10373 | if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10374 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10375 | } |
| 10376 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10377 | return TelephonyManager.MULTISIM_ALLOWED; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10378 | } |
| 10379 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 10380 | /** |
| 10381 | * Switch configs to enable multi-sim or switch back to single-sim |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 10382 | * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE |
| 10383 | * permission, but the other way around is possible with either MODIFY_PHONE_STATE |
| 10384 | * or carrier privileges |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 10385 | * @param numOfSims number of active sims we want to switch to |
| 10386 | */ |
| 10387 | @Override |
| 10388 | public void switchMultiSimConfig(int numOfSims) { |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 10389 | if (numOfSims == 1) { |
| 10390 | enforceModifyPermission(); |
| 10391 | } else { |
| 10392 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 10393 | mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig"); |
| 10394 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 10395 | final long identity = Binder.clearCallingIdentity(); |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10396 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 10397 | try { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10398 | //only proceed if multi-sim is not restricted |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10399 | if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10400 | loge("switchMultiSimConfig not possible. It is restricted or not supported."); |
| 10401 | return; |
| 10402 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 10403 | mPhoneConfigurationManager.switchMultiSimConfig(numOfSims); |
| 10404 | } finally { |
| 10405 | Binder.restoreCallingIdentity(identity); |
| 10406 | } |
| 10407 | } |
| 10408 | |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 10409 | @Override |
| 10410 | public boolean isApplicationOnUicc(int subId, int appType) { |
| 10411 | enforceReadPrivilegedPermission("isApplicationOnUicc"); |
| 10412 | Phone phone = getPhone(subId); |
| 10413 | if (phone == null) { |
| 10414 | return false; |
| 10415 | } |
| 10416 | final long identity = Binder.clearCallingIdentity(); |
| 10417 | try { |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 10418 | UiccPort uiccPort = phone.getUiccPort(); |
| 10419 | if (uiccPort == null) { |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 10420 | return false; |
| 10421 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 10422 | UiccProfile uiccProfile = uiccPort.getUiccProfile(); |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 10423 | if (uiccProfile == null) { |
| 10424 | return false; |
| 10425 | } |
| 10426 | if (TelephonyManager.APPTYPE_SIM <= appType |
| 10427 | && appType <= TelephonyManager.APPTYPE_ISIM) { |
| 10428 | return uiccProfile.isApplicationOnIcc(AppType.values()[appType]); |
| 10429 | } |
| 10430 | return false; |
| 10431 | } finally { |
| 10432 | Binder.restoreCallingIdentity(identity); |
| 10433 | } |
| 10434 | } |
| 10435 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 10436 | /** |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 10437 | * Get whether making changes to modem configurations will trigger reboot. |
| 10438 | * Return value defaults to true. |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 10439 | */ |
| 10440 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10441 | public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage, |
| 10442 | String callingFeatureId) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 10443 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10444 | mApp, subId, callingPackage, callingFeatureId, |
| 10445 | "doesSwitchMultiSimConfigTriggerReboot")) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 10446 | return false; |
| 10447 | } |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 10448 | final long identity = Binder.clearCallingIdentity(); |
| 10449 | try { |
| 10450 | return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange(); |
| 10451 | } finally { |
| 10452 | Binder.restoreCallingIdentity(identity); |
| 10453 | } |
| 10454 | } |
| 10455 | |
Nathan Harold | 29f5f05 | 2019-02-15 13:41:57 -0800 | [diff] [blame] | 10456 | private void updateModemStateMetrics() { |
| 10457 | TelephonyMetrics metrics = TelephonyMetrics.getInstance(); |
| 10458 | // TODO: check the state for each modem if the api is ready. |
| 10459 | metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1); |
| 10460 | } |
| 10461 | |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10462 | @Override |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 10463 | public List<UiccSlotMapping> getSlotsMapping(String callingPackage) { |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10464 | enforceReadPrivilegedPermission("getSlotsMapping"); |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 10465 | // Verify that the callingPackage belongs to the calling UID |
| 10466 | mApp.getSystemService(AppOpsManager.class) |
| 10467 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10468 | final long identity = Binder.clearCallingIdentity(); |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 10469 | List<UiccSlotMapping> slotMap = new ArrayList<>(); |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10470 | try { |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 10471 | UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName()); |
| 10472 | if (slotInfos != null) { |
| 10473 | for (int i = 0; i < slotInfos.length; i++) { |
| 10474 | for (UiccPortInfo portInfo : slotInfos[i].getPorts()) { |
| 10475 | if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) { |
| 10476 | slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i, |
| 10477 | portInfo.getLogicalSlotIndex())); |
| 10478 | } |
| 10479 | } |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10480 | } |
| 10481 | } |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 10482 | return slotMap; |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10483 | } finally { |
| 10484 | Binder.restoreCallingIdentity(identity); |
| 10485 | } |
| 10486 | } |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 10487 | |
| 10488 | /** |
| 10489 | * Get the IRadio HAL Version |
jimsun | f9ec162 | 2022-09-13 21:18:43 +0800 | [diff] [blame] | 10490 | * @deprecated use getHalVersion instead |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 10491 | */ |
jimsun | f9ec162 | 2022-09-13 21:18:43 +0800 | [diff] [blame] | 10492 | @Deprecated |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 10493 | @Override |
| 10494 | public int getRadioHalVersion() { |
jimsun | f9ec162 | 2022-09-13 21:18:43 +0800 | [diff] [blame] | 10495 | return getHalVersion(HAL_SERVICE_RADIO); |
| 10496 | } |
| 10497 | |
| 10498 | /** |
| 10499 | * Get the HAL Version of a specific service |
| 10500 | */ |
| 10501 | @Override |
| 10502 | public int getHalVersion(int service) { |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 10503 | Phone phone = getDefaultPhone(); |
| 10504 | if (phone == null) return -1; |
jimsun | f9ec162 | 2022-09-13 21:18:43 +0800 | [diff] [blame] | 10505 | HalVersion hv = phone.getHalVersion(service); |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 10506 | if (hv.equals(HalVersion.UNKNOWN)) return -1; |
| 10507 | return hv.major * 100 + hv.minor; |
| 10508 | } |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 10509 | |
| 10510 | /** |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 10511 | * Get the current calling package name. |
| 10512 | * @return the current calling package name |
| 10513 | */ |
| 10514 | @Override |
| 10515 | public String getCurrentPackageName() { |
| 10516 | return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0]; |
| 10517 | } |
| 10518 | |
| 10519 | /** |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10520 | * Return whether data is enabled for certain APN type. This will tell if framework will accept |
| 10521 | * corresponding network requests on a subId. |
| 10522 | * |
| 10523 | * Data is enabled if: |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 10524 | * 1) user data is turned on, or |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10525 | * 2) APN is un-metered for this subscription, or |
| 10526 | * 3) APN type is whitelisted. E.g. MMS is whitelisted if |
Hall Liu | 746e03c | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 10527 | * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled. |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10528 | * |
| 10529 | * @return whether data is allowed for a apn type. |
| 10530 | * |
| 10531 | * @hide |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 10532 | */ |
| 10533 | @Override |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10534 | public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) { |
Amit Mahajan | 5d4e192 | 2019-10-07 16:20:43 -0700 | [diff] [blame] | 10535 | enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for " |
| 10536 | + "isDataEnabledForApn"); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 10537 | |
| 10538 | // Now that all security checks passes, perform the operation as ourselves. |
| 10539 | final long identity = Binder.clearCallingIdentity(); |
| 10540 | try { |
| 10541 | Phone phone = getPhone(subId); |
| 10542 | if (phone == null) return false; |
| 10543 | |
Jack Yu | 27422a5 | 2022-03-21 10:38:05 -0700 | [diff] [blame] | 10544 | boolean isMetered; |
Jack Yu | 99e8733 | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 10545 | boolean isDataEnabled; |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 10546 | isMetered = phone.getDataNetworkController().getDataConfigManager() |
| 10547 | .isMeteredCapability(DataUtils.apnTypeToNetworkCapability(apnType), |
| 10548 | phone.getServiceState().getDataRoaming()); |
| 10549 | isDataEnabled = phone.getDataSettingsManager().isDataEnabled(apnType); |
Jack Yu | 99e8733 | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 10550 | return !isMetered || isDataEnabled; |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10551 | } finally { |
| 10552 | Binder.restoreCallingIdentity(identity); |
| 10553 | } |
| 10554 | } |
| 10555 | |
| 10556 | @Override |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 10557 | public boolean isApnMetered(@ApnType int apnType, int subId) { |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10558 | enforceReadPrivilegedPermission("isApnMetered"); |
| 10559 | |
| 10560 | // Now that all security checks passes, perform the operation as ourselves. |
| 10561 | final long identity = Binder.clearCallingIdentity(); |
| 10562 | try { |
| 10563 | Phone phone = getPhone(subId); |
| 10564 | if (phone == null) return true; // By default return true. |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 10565 | return phone.getDataNetworkController().getDataConfigManager().isMeteredCapability( |
| 10566 | DataUtils.apnTypeToNetworkCapability(apnType), |
| 10567 | phone.getServiceState().getDataRoaming()); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 10568 | } finally { |
| 10569 | Binder.restoreCallingIdentity(identity); |
| 10570 | } |
| 10571 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 10572 | |
| 10573 | @Override |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 10574 | public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers, |
| 10575 | int subscriptionId, IBooleanConsumer resultCallback) { |
| 10576 | enforceModifyPermission(); |
| 10577 | long token = Binder.clearCallingIdentity(); |
| 10578 | try { |
| 10579 | Phone phone = getPhone(subscriptionId); |
| 10580 | if (phone == null) { |
| 10581 | try { |
| 10582 | if (resultCallback != null) { |
| 10583 | resultCallback.accept(false); |
| 10584 | } |
| 10585 | } catch (RemoteException e) { |
| 10586 | // ignore |
| 10587 | } |
| 10588 | return; |
| 10589 | } |
| 10590 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument = |
| 10591 | Pair.create(specifiers, (x) -> { |
| 10592 | try { |
| 10593 | if (resultCallback != null) { |
| 10594 | resultCallback.accept(x); |
| 10595 | } |
| 10596 | } catch (RemoteException e) { |
| 10597 | // ignore |
| 10598 | } |
| 10599 | }); |
| 10600 | sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null); |
| 10601 | } finally { |
| 10602 | Binder.restoreCallingIdentity(token); |
| 10603 | } |
| 10604 | } |
| 10605 | |
| 10606 | @Override |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 10607 | public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) { |
| 10608 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 10609 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 10610 | mApp, subId, "getSystemSelectionChannels"); |
| 10611 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 10612 | final long identity = Binder.clearCallingIdentity(); |
| 10613 | try { |
Sarah Chin | 428d1d6 | 2021-03-13 03:17:40 -0800 | [diff] [blame] | 10614 | Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource); |
| 10615 | if (result instanceof IllegalStateException) { |
| 10616 | throw (IllegalStateException) result; |
| 10617 | } |
| 10618 | List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 10619 | if (DBG) log("getSystemSelectionChannels: " + specifiers); |
| 10620 | return specifiers; |
| 10621 | } finally { |
| 10622 | Binder.restoreCallingIdentity(identity); |
| 10623 | } |
| 10624 | } |
| 10625 | |
| 10626 | @Override |
Jack Yu | 8b766fc | 2022-03-21 09:42:33 -0700 | [diff] [blame] | 10627 | public boolean isMvnoMatched(int slotIndex, int mvnoType, @NonNull String mvnoMatchData) { |
changbetty | ca3d40d | 2020-03-03 16:27:31 +0800 | [diff] [blame] | 10628 | enforceReadPrivilegedPermission("isMvnoMatched"); |
Jack Yu | 8b766fc | 2022-03-21 09:42:33 -0700 | [diff] [blame] | 10629 | return UiccController.getInstance().mvnoMatches(slotIndex, mvnoType, mvnoMatchData); |
changbetty | 7157e9e | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 10630 | } |
| 10631 | |
| 10632 | @Override |
Philip P. Moltmann | d02b737 | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 10633 | public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag, |
| 10634 | IIntegerConsumer pendingSubIdResult) { |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 10635 | if (callingPackage == null) { |
| 10636 | callingPackage = getCurrentPackageName(); |
| 10637 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 10638 | SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp, |
| 10639 | (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE)); |
Philip P. Moltmann | d02b737 | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 10640 | if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag, |
| 10641 | "Sending message")) { |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 10642 | throw new SecurityException("Requires SEND_SMS permission to perform this operation"); |
| 10643 | } |
| 10644 | PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult); |
| 10645 | Intent intent = new Intent(); |
| 10646 | intent.setClass(mApp, PickSmsSubscriptionActivity.class); |
| 10647 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 10648 | // Bring up choose default SMS subscription dialog right now |
| 10649 | intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY, |
| 10650 | PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE); |
| 10651 | mApp.startActivity(intent); |
| 10652 | } |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 10653 | |
| 10654 | @Override |
Ayush Sharma | 787854b | 2022-12-12 14:55:02 +0000 | [diff] [blame] | 10655 | public void showSwitchToManagedProfileDialog() { |
| 10656 | enforceModifyPermission(); |
| 10657 | |
| 10658 | Intent intent = new Intent(); |
| 10659 | intent.setClass(mApp, ErrorDialogActivity.class); |
| 10660 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 10661 | mApp.startActivity(intent); |
| 10662 | } |
| 10663 | |
| 10664 | @Override |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 10665 | public String getMmsUAProfUrl(int subId) { |
| 10666 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 10667 | final long identity = Binder.clearCallingIdentity(); |
| 10668 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 10669 | String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString( |
| 10670 | CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING); |
| 10671 | if (!TextUtils.isEmpty(carrierUAProfUrl)) { |
| 10672 | return carrierUAProfUrl; |
| 10673 | } |
Daniel Bright | ebb4eb7 | 2020-02-18 15:16:33 -0800 | [diff] [blame] | 10674 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 10675 | .getString(com.android.internal.R.string.config_mms_user_agent_profile_url); |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 10676 | } finally { |
| 10677 | Binder.restoreCallingIdentity(identity); |
| 10678 | } |
| 10679 | } |
| 10680 | |
| 10681 | @Override |
| 10682 | public String getMmsUserAgent(int subId) { |
| 10683 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 10684 | final long identity = Binder.clearCallingIdentity(); |
| 10685 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 10686 | String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString( |
| 10687 | CarrierConfigManager.KEY_MMS_USER_AGENT_STRING); |
| 10688 | if (!TextUtils.isEmpty(carrierUserAgent)) { |
| 10689 | return carrierUserAgent; |
| 10690 | } |
Daniel Bright | ebb4eb7 | 2020-02-18 15:16:33 -0800 | [diff] [blame] | 10691 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 10692 | .getString(com.android.internal.R.string.config_mms_user_agent); |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 10693 | } finally { |
| 10694 | Binder.restoreCallingIdentity(identity); |
| 10695 | } |
| 10696 | } |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 10697 | |
| 10698 | @Override |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 10699 | public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) { |
| 10700 | enforceReadPrivilegedPermission("isMobileDataPolicyEnabled"); |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 10701 | |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 10702 | final long identity = Binder.clearCallingIdentity(); |
| 10703 | try { |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 10704 | Phone phone = getPhone(subscriptionId); |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 10705 | if (phone == null) return false; |
| 10706 | |
Ling Ma | f188d50 | 2022-09-16 15:22:36 -0700 | [diff] [blame] | 10707 | return phone.getDataSettingsManager().isMobileDataPolicyEnabled(policy); |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 10708 | } finally { |
| 10709 | Binder.restoreCallingIdentity(identity); |
| 10710 | } |
| 10711 | } |
| 10712 | |
| 10713 | @Override |
Hall Liu | c66bb11 | 2021-02-02 12:09:32 -0800 | [diff] [blame] | 10714 | public void setMobileDataPolicyEnabled(int subscriptionId, int policy, |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 10715 | boolean enabled) { |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 10716 | enforceModifyPermission(); |
| 10717 | |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 10718 | final long identity = Binder.clearCallingIdentity(); |
| 10719 | try { |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 10720 | Phone phone = getPhone(subscriptionId); |
| 10721 | if (phone == null) return; |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 10722 | |
Ling Ma | f188d50 | 2022-09-16 15:22:36 -0700 | [diff] [blame] | 10723 | phone.getDataSettingsManager().setMobileDataPolicy(policy, enabled); |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 10724 | } finally { |
| 10725 | Binder.restoreCallingIdentity(identity); |
| 10726 | } |
| 10727 | } |
| 10728 | |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 10729 | /** |
Hall Liu | 746e03c | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 10730 | * Updates whether conference event package handling is enabled. |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 10731 | * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false} |
| 10732 | * otherwise. |
| 10733 | */ |
| 10734 | @Override |
| 10735 | public void setCepEnabled(boolean isCepEnabled) { |
| 10736 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled"); |
| 10737 | |
| 10738 | final long identity = Binder.clearCallingIdentity(); |
| 10739 | try { |
| 10740 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled); |
| 10741 | for (Phone phone : PhoneFactory.getPhones()) { |
| 10742 | Phone defaultPhone = phone.getImsPhone(); |
| 10743 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 10744 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 10745 | ImsPhoneCallTracker imsPhoneCallTracker = |
| 10746 | (ImsPhoneCallTracker) imsPhone.getCallTracker(); |
| 10747 | imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled); |
| 10748 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone " |
| 10749 | + imsPhone.getMsisdn()); |
| 10750 | } |
| 10751 | } |
| 10752 | } finally { |
| 10753 | Binder.restoreCallingIdentity(identity); |
| 10754 | } |
| 10755 | } |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 10756 | |
| 10757 | /** |
| 10758 | * Notify that an RCS autoconfiguration XML file has been received for provisioning. |
| 10759 | * |
| 10760 | * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed. |
| 10761 | * @param isCompressed The XML file is compressed in gzip format and must be decompressed |
| 10762 | * before being read. |
| 10763 | */ |
| 10764 | @Override |
| 10765 | public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean |
| 10766 | isCompressed) { |
| 10767 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 10768 | mApp, subId, "notifyRcsAutoConfigurationReceived"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10769 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10770 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10771 | } |
| 10772 | if (!isImsAvailableOnDevice()) { |
joonhunshin | 46b49a3 | 2022-12-21 05:33:23 +0000 | [diff] [blame] | 10773 | // ProvisioningManager can not handle ServiceSpecificException. |
| 10774 | // Throw the IllegalStateException and annotate ProvisioningManager. |
| 10775 | throw new IllegalStateException("IMS not available on device."); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10776 | } |
| 10777 | |
| 10778 | final long identity = Binder.clearCallingIdentity(); |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 10779 | try { |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10780 | RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed); |
| 10781 | } finally { |
| 10782 | Binder.restoreCallingIdentity(identity); |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 10783 | } |
| 10784 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 10785 | |
| 10786 | @Override |
| 10787 | public boolean isIccLockEnabled(int subId) { |
| 10788 | enforceReadPrivilegedPermission("isIccLockEnabled"); |
| 10789 | |
| 10790 | // Now that all security checks passes, perform the operation as ourselves. |
| 10791 | final long identity = Binder.clearCallingIdentity(); |
| 10792 | try { |
| 10793 | Phone phone = getPhone(subId); |
| 10794 | if (phone != null && phone.getIccCard() != null) { |
| 10795 | return phone.getIccCard().getIccLockEnabled(); |
| 10796 | } else { |
| 10797 | return false; |
| 10798 | } |
| 10799 | } finally { |
| 10800 | Binder.restoreCallingIdentity(identity); |
| 10801 | } |
| 10802 | } |
| 10803 | |
| 10804 | /** |
| 10805 | * Set the ICC pin lock enabled or disabled. |
| 10806 | * |
| 10807 | * @return an integer representing the status of IccLock enabled or disabled in the following |
| 10808 | * three cases: |
| 10809 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock |
| 10810 | * successfully. |
| 10811 | * - Positive number and zero for remaining password attempts. |
| 10812 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
| 10813 | * |
| 10814 | */ |
| 10815 | @Override |
| 10816 | public int setIccLockEnabled(int subId, boolean enabled, String password) { |
| 10817 | enforceModifyPermission(); |
| 10818 | |
| 10819 | Phone phone = getPhone(subId); |
| 10820 | if (phone == null) { |
| 10821 | return 0; |
| 10822 | } |
| 10823 | // Now that all security checks passes, perform the operation as ourselves. |
| 10824 | final long identity = Binder.clearCallingIdentity(); |
| 10825 | try { |
| 10826 | int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED, |
| 10827 | new Pair<Boolean, String>(enabled, password), phone, null); |
| 10828 | return attemptsRemaining; |
| 10829 | |
| 10830 | } catch (Exception e) { |
| 10831 | Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e); |
| 10832 | } finally { |
| 10833 | Binder.restoreCallingIdentity(identity); |
| 10834 | } |
| 10835 | return 0; |
| 10836 | } |
| 10837 | |
| 10838 | /** |
| 10839 | * Change the ICC password used in ICC pin lock. |
| 10840 | * |
| 10841 | * @return an integer representing the status of IccLock changed in the following three cases: |
| 10842 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully. |
| 10843 | * - Positive number and zero for remaining password attempts. |
| 10844 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
| 10845 | * |
| 10846 | */ |
| 10847 | @Override |
| 10848 | public int changeIccLockPassword(int subId, String oldPassword, String newPassword) { |
| 10849 | enforceModifyPermission(); |
| 10850 | |
| 10851 | Phone phone = getPhone(subId); |
| 10852 | if (phone == null) { |
| 10853 | return 0; |
| 10854 | } |
| 10855 | // Now that all security checks passes, perform the operation as ourselves. |
| 10856 | final long identity = Binder.clearCallingIdentity(); |
| 10857 | try { |
| 10858 | int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD, |
| 10859 | new Pair<String, String>(oldPassword, newPassword), phone, null); |
| 10860 | return attemptsRemaining; |
| 10861 | |
| 10862 | } catch (Exception e) { |
| 10863 | Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e); |
| 10864 | } finally { |
| 10865 | Binder.restoreCallingIdentity(identity); |
| 10866 | } |
| 10867 | return 0; |
| 10868 | } |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 10869 | |
| 10870 | /** |
| 10871 | * Request for receiving user activity notification |
| 10872 | */ |
| 10873 | @Override |
| 10874 | public void requestUserActivityNotification() { |
| 10875 | if (!mNotifyUserActivity.get() |
| 10876 | && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) { |
| 10877 | mNotifyUserActivity.set(true); |
| 10878 | } |
| 10879 | } |
| 10880 | |
| 10881 | /** |
| 10882 | * Called when userActivity is signalled in the power manager. |
| 10883 | * This is safe to call from any thread, with any window manager locks held or not. |
| 10884 | */ |
| 10885 | @Override |
| 10886 | public void userActivity() { |
| 10887 | // *************************************** |
| 10888 | // * Inherited from PhoneWindowManager * |
| 10889 | // *************************************** |
| 10890 | // THIS IS CALLED FROM DEEP IN THE POWER MANAGER |
| 10891 | // WITH ITS LOCKS HELD. |
| 10892 | // |
| 10893 | // This code must be VERY careful about the locks |
| 10894 | // it acquires. |
| 10895 | // In fact, the current code acquires way too many, |
| 10896 | // and probably has lurking deadlocks. |
| 10897 | |
| 10898 | if (Binder.getCallingUid() != Process.SYSTEM_UID) { |
| 10899 | throw new SecurityException("Only the OS may call notifyUserActivity()"); |
| 10900 | } |
| 10901 | |
| 10902 | if (mNotifyUserActivity.getAndSet(false)) { |
| 10903 | mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY, |
| 10904 | USER_ACTIVITY_NOTIFICATION_DELAY); |
| 10905 | } |
| 10906 | } |
Malcolm Chen | 4639c56 | 2020-04-13 11:59:40 -0700 | [diff] [blame] | 10907 | |
| 10908 | @Override |
| 10909 | public boolean canConnectTo5GInDsdsMode() { |
| 10910 | return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode); |
| 10911 | } |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 10912 | |
| 10913 | @Override |
| 10914 | public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage, |
| 10915 | String callingFeatureId) { |
| 10916 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 10917 | mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) { |
| 10918 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 10919 | } |
| 10920 | |
| 10921 | Phone phone = getPhone(subId); |
| 10922 | if (phone == null) { |
| 10923 | throw new RuntimeException("phone is not available"); |
| 10924 | } |
| 10925 | // Now that all security checks passes, perform the operation as ourselves. |
| 10926 | final long identity = Binder.clearCallingIdentity(); |
| 10927 | try { |
| 10928 | return phone.getEquivalentHomePlmns(); |
| 10929 | } finally { |
| 10930 | Binder.restoreCallingIdentity(identity); |
| 10931 | } |
| 10932 | } |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 10933 | |
| 10934 | @Override |
| 10935 | public boolean isRadioInterfaceCapabilitySupported( |
Daniel Bright | 95a4c1f | 2021-02-11 09:57:16 -0800 | [diff] [blame] | 10936 | final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) { |
| 10937 | Set<String> radioInterfaceCapabilities = |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 10938 | mRadioInterfaceCapabilities.getCapabilities(); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 10939 | if (radioInterfaceCapabilities == null) { |
| 10940 | throw new RuntimeException("radio interface capabilities are not available"); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 10941 | } |
Daniel Bright | 95a4c1f | 2021-02-11 09:57:16 -0800 | [diff] [blame] | 10942 | return radioInterfaceCapabilities.contains(capability); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 10943 | } |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10944 | |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 10945 | @Override |
| 10946 | public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl, |
| 10947 | UaSecurityProtocolIdentifier securityProtocol, |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10948 | boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) { |
| 10949 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 10950 | Binder.getCallingUid(), "bootstrapAuthenticationRequest", |
| 10951 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 10952 | Manifest.permission.MODIFY_PHONE_STATE); |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 10953 | if (DBG) { |
| 10954 | log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:" |
| 10955 | + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol |
| 10956 | + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback); |
| 10957 | } |
| 10958 | |
| 10959 | if (!SubscriptionManager.isValidSubscriptionId(subId) |
| 10960 | || appType < TelephonyManager.APPTYPE_UNKNOWN |
| 10961 | || appType > TelephonyManager.APPTYPE_ISIM |
| 10962 | || nafUrl == null || securityProtocol == null || callback == null) { |
| 10963 | Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters"); |
| 10964 | if (callback != null) { |
| 10965 | try { |
| 10966 | callback.onAuthenticationFailure( |
| 10967 | 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED); |
| 10968 | } catch (RemoteException exception) { |
| 10969 | log("Fail to notify onAuthenticationFailure due to " + exception); |
| 10970 | } |
| 10971 | return; |
| 10972 | } |
| 10973 | } |
| 10974 | |
| 10975 | final long token = Binder.clearCallingIdentity(); |
| 10976 | try { |
| 10977 | getGbaManager(subId).bootstrapAuthenticationRequest( |
| 10978 | new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(), |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 10979 | forceBootStrapping, callback)); |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 10980 | } finally { |
| 10981 | Binder.restoreCallingIdentity(token); |
| 10982 | } |
| 10983 | } |
| 10984 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10985 | /** |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10986 | * Attempts to set the radio power state for all phones for thermal reason. |
| 10987 | * This does not guarantee that the |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10988 | * requested radio power state will actually be set. See {@link |
| 10989 | * PhoneInternalInterface#setRadioPowerForReason} for more details. |
| 10990 | * |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10991 | * @param enable {@code true} if trying to turn radio on. |
| 10992 | * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code |
| 10993 | * false}. |
| 10994 | */ |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10995 | private boolean setRadioPowerForThermal(boolean enable) { |
| 10996 | boolean isPhoneAvailable = false; |
| 10997 | for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) { |
| 10998 | Phone phone = PhoneFactory.getPhone(i); |
| 10999 | if (phone != null) { |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 11000 | phone.setRadioPowerForReason(enable, TelephonyManager.RADIO_POWER_REASON_THERMAL); |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 11001 | isPhoneAvailable = true; |
| 11002 | } |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11003 | } |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 11004 | |
| 11005 | // return true if successfully informed the phone object about the thermal radio power |
| 11006 | // request. |
| 11007 | return isPhoneAvailable; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11008 | } |
| 11009 | |
| 11010 | private int handleDataThrottlingRequest(int subId, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 11011 | DataThrottlingRequest dataThrottlingRequest, String callingPackage) { |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 11012 | boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported( |
| 11013 | TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING); |
| 11014 | if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction() |
| 11015 | != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) { |
| 11016 | throw new IllegalArgumentException("modem does not support data throttling"); |
| 11017 | } |
| 11018 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11019 | // Ensure that radio is on. If not able to power on due to phone being unavailable, return |
| 11020 | // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 11021 | if (!setRadioPowerForThermal(true)) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11022 | return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 11023 | } |
| 11024 | |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 11025 | setDataEnabledForReason( |
| 11026 | subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true, callingPackage); |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11027 | |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 11028 | if (isDataThrottlingSupported) { |
| 11029 | int thermalMitigationResult = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 11030 | (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId); |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 11031 | if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) { |
| 11032 | throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS"); |
| 11033 | } else if (thermalMitigationResult |
| 11034 | == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) { |
Jack Nudelman | 760d096 | 2021-05-20 13:57:30 -0700 | [diff] [blame] | 11035 | log("Modem likely does not support data throttling on secondary carrier. Data " + |
| 11036 | "throttling action = " + dataThrottlingRequest.getDataThrottlingAction()); |
| 11037 | return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 11038 | } |
| 11039 | return thermalMitigationResult; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11040 | } |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 11041 | |
| 11042 | return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11043 | } |
| 11044 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 11045 | private static List<String> getThermalMitigationAllowlist(Context context) { |
| 11046 | if (sThermalMitigationAllowlistedPackages.isEmpty()) { |
| 11047 | for (String pckg : context.getResources() |
| 11048 | .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) { |
| 11049 | sThermalMitigationAllowlistedPackages.add(pckg); |
| 11050 | } |
| 11051 | } |
| 11052 | |
| 11053 | return sThermalMitigationAllowlistedPackages; |
| 11054 | } |
| 11055 | |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 11056 | private boolean isAnyPhoneInEmergencyState() { |
| 11057 | TelecomManager tm = mApp.getSystemService(TelecomManager.class); |
| 11058 | if (tm.isInEmergencyCall()) { |
| 11059 | Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call"); |
| 11060 | return true; |
| 11061 | } |
| 11062 | for (Phone phone : PhoneFactory.getPhones()) { |
| 11063 | if (phone.isInEmergencySmsMode() || phone.isInEcm()) { |
| 11064 | Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = " |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 11065 | + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = " |
| 11066 | + phone.isInEcm()); |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 11067 | return true; |
| 11068 | } |
| 11069 | } |
| 11070 | |
| 11071 | return false; |
| 11072 | } |
| 11073 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 11074 | /** |
| 11075 | * Used by shell commands to add an authorized package name for thermal mitigation. |
| 11076 | * @param packageName name of package to be allowlisted |
| 11077 | * @param context |
| 11078 | */ |
| 11079 | static void addPackageToThermalMitigationAllowlist(String packageName, Context context) { |
| 11080 | sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context); |
| 11081 | sThermalMitigationAllowlistedPackages.add(packageName); |
| 11082 | } |
| 11083 | |
| 11084 | /** |
| 11085 | * Used by shell commands to remove an authorized package name for thermal mitigation. |
| 11086 | * @param packageName name of package to remove from allowlist |
| 11087 | * @param context |
| 11088 | */ |
| 11089 | static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) { |
| 11090 | sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context); |
| 11091 | sThermalMitigationAllowlistedPackages.remove(packageName); |
| 11092 | } |
| 11093 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11094 | /** |
| 11095 | * Thermal mitigation request to control functionalities at modem. |
| 11096 | * |
| 11097 | * @param subId the id of the subscription. |
| 11098 | * @param thermalMitigationRequest holds all necessary information to be passed down to modem. |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 11099 | * @param callingPackage the package name of the calling package. |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11100 | * |
| 11101 | * @return thermalMitigationResult enum as defined in android.telephony.Annotation. |
| 11102 | */ |
| 11103 | @Override |
| 11104 | @ThermalMitigationResult |
| 11105 | public int sendThermalMitigationRequest( |
| 11106 | int subId, |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 11107 | ThermalMitigationRequest thermalMitigationRequest, |
| 11108 | String callingPackage) throws IllegalArgumentException { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11109 | enforceModifyPermission(); |
| 11110 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 11111 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 11112 | if (!getThermalMitigationAllowlist(getDefaultPhone().getContext()) |
| 11113 | .contains(callingPackage)) { |
| 11114 | throw new SecurityException("Calling package must be configured in the device config. " |
| 11115 | + "calling package: " + callingPackage); |
| 11116 | } |
| 11117 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11118 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 11119 | final long identity = Binder.clearCallingIdentity(); |
| 11120 | |
| 11121 | int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR; |
| 11122 | try { |
| 11123 | int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction(); |
| 11124 | switch (thermalMitigationAction) { |
| 11125 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING: |
| 11126 | thermalMitigationResult = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 11127 | handleDataThrottlingRequest(subId, |
| 11128 | thermalMitigationRequest.getDataThrottlingRequest(), |
| 11129 | callingPackage); |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11130 | break; |
| 11131 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY: |
| 11132 | if (thermalMitigationRequest.getDataThrottlingRequest() != null) { |
| 11133 | throw new IllegalArgumentException("dataThrottlingRequest must be null for " |
| 11134 | + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY"); |
| 11135 | } |
| 11136 | |
| 11137 | // Ensure that radio is on. If not able to power on due to phone being |
| 11138 | // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 11139 | if (!setRadioPowerForThermal(true)) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11140 | thermalMitigationResult = |
| 11141 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 11142 | break; |
| 11143 | } |
| 11144 | |
| 11145 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 11146 | false, callingPackage); |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11147 | thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 11148 | break; |
| 11149 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF: |
| 11150 | if (thermalMitigationRequest.getDataThrottlingRequest() != null) { |
| 11151 | throw new IllegalArgumentException("dataThrottlingRequest must be null for" |
| 11152 | + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF"); |
| 11153 | } |
| 11154 | |
| 11155 | TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null); |
| 11156 | if (registry != null) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11157 | Phone phone = getPhone(subId); |
| 11158 | if (phone == null) { |
| 11159 | thermalMitigationResult = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 11160 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11161 | break; |
| 11162 | } |
| 11163 | |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 11164 | TelephonyConnectionService service = |
| 11165 | registry.getTelephonyConnectionService(); |
Jack Nudelman | b30ac30 | 2021-06-17 15:39:58 -0700 | [diff] [blame] | 11166 | if (service != null && service.isEmergencyCallPending()) { |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 11167 | Log.e(LOG_TAG, "An emergency call is pending"); |
| 11168 | thermalMitigationResult = |
| 11169 | TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE; |
| 11170 | break; |
| 11171 | } else if (isAnyPhoneInEmergencyState()) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11172 | thermalMitigationResult = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 11173 | TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11174 | break; |
| 11175 | } |
| 11176 | } else { |
| 11177 | thermalMitigationResult = |
| 11178 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 11179 | break; |
| 11180 | } |
| 11181 | |
| 11182 | // Turn radio off. If not able to power off due to phone being unavailable, |
| 11183 | // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 11184 | if (!setRadioPowerForThermal(false)) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11185 | thermalMitigationResult = |
| 11186 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 11187 | break; |
| 11188 | } |
| 11189 | thermalMitigationResult = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 11190 | TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11191 | break; |
| 11192 | default: |
| 11193 | throw new IllegalArgumentException("the requested thermalMitigationAction does " |
| 11194 | + "not exist. Requested action: " + thermalMitigationAction); |
| 11195 | } |
| 11196 | } catch (IllegalArgumentException e) { |
| 11197 | throw e; |
| 11198 | } catch (Exception e) { |
| 11199 | Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e); |
| 11200 | thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 11201 | } finally { |
| 11202 | Binder.restoreCallingIdentity(identity); |
| 11203 | } |
| 11204 | |
| 11205 | if (DBG) { |
| 11206 | log("thermalMitigationRequest returning with thermalMitigationResult: " |
| 11207 | + thermalMitigationResult); |
| 11208 | } |
| 11209 | |
| 11210 | return thermalMitigationResult; |
| 11211 | } |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 11212 | |
| 11213 | /** |
| 11214 | * Set the GbaService Package Name that Telephony will bind to. |
| 11215 | * |
| 11216 | * @param subId The sim that the GbaService is associated with. |
| 11217 | * @param packageName The name of the package to be replaced with. |
| 11218 | * @return true if setting the GbaService to bind to succeeded, false if it did not. |
| 11219 | */ |
| 11220 | @Override |
| 11221 | public boolean setBoundGbaServiceOverride(int subId, String packageName) { |
| 11222 | enforceModifyPermission(); |
| 11223 | |
| 11224 | final long identity = Binder.clearCallingIdentity(); |
| 11225 | try { |
| 11226 | return getGbaManager(subId).overrideServicePackage(packageName); |
| 11227 | } finally { |
| 11228 | Binder.restoreCallingIdentity(identity); |
| 11229 | } |
| 11230 | } |
| 11231 | |
| 11232 | /** |
| 11233 | * Return the package name of the currently bound GbaService. |
| 11234 | * |
| 11235 | * @param subId The sim that the GbaService is associated with. |
| 11236 | * @return the package name of the GbaService configuration, null if GBA is not supported. |
| 11237 | */ |
| 11238 | @Override |
| 11239 | public String getBoundGbaService(int subId) { |
| 11240 | enforceReadPrivilegedPermission("getBoundGbaServicePackage"); |
| 11241 | |
| 11242 | final long identity = Binder.clearCallingIdentity(); |
| 11243 | try { |
| 11244 | return getGbaManager(subId).getServicePackage(); |
| 11245 | } finally { |
| 11246 | Binder.restoreCallingIdentity(identity); |
| 11247 | } |
| 11248 | } |
| 11249 | |
| 11250 | /** |
| 11251 | * Set the release time for telephony to unbind GbaService. |
| 11252 | * |
| 11253 | * @param subId The sim that the GbaService is associated with. |
| 11254 | * @param interval The release time to unbind GbaService by millisecond. |
| 11255 | * @return true if setting the GbaService to bind to succeeded, false if it did not. |
| 11256 | */ |
| 11257 | @Override |
| 11258 | public boolean setGbaReleaseTimeOverride(int subId, int interval) { |
| 11259 | enforceModifyPermission(); |
| 11260 | |
| 11261 | final long identity = Binder.clearCallingIdentity(); |
| 11262 | try { |
| 11263 | return getGbaManager(subId).overrideReleaseTime(interval); |
| 11264 | } finally { |
| 11265 | Binder.restoreCallingIdentity(identity); |
| 11266 | } |
| 11267 | } |
| 11268 | |
| 11269 | /** |
| 11270 | * Return the release time for telephony to unbind GbaService. |
| 11271 | * |
| 11272 | * @param subId The sim that the GbaService is associated with. |
| 11273 | * @return The release time to unbind GbaService by millisecond. |
| 11274 | */ |
| 11275 | @Override |
| 11276 | public int getGbaReleaseTime(int subId) { |
| 11277 | enforceReadPrivilegedPermission("getGbaReleaseTime"); |
| 11278 | |
| 11279 | final long identity = Binder.clearCallingIdentity(); |
| 11280 | try { |
| 11281 | return getGbaManager(subId).getReleaseTime(); |
| 11282 | } finally { |
| 11283 | Binder.restoreCallingIdentity(identity); |
| 11284 | } |
| 11285 | } |
| 11286 | |
| 11287 | private GbaManager getGbaManager(int subId) { |
| 11288 | GbaManager instance = GbaManager.getInstance(subId); |
| 11289 | if (instance == null) { |
| 11290 | String packageName = mApp.getResources().getString(R.string.config_gba_package); |
| 11291 | int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time); |
| 11292 | instance = GbaManager.make(mApp, subId, packageName, releaseTime); |
| 11293 | } |
| 11294 | return instance; |
| 11295 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11296 | |
| 11297 | /** |
| 11298 | * indicate whether the device and the carrier can support |
| 11299 | * RCS VoLTE single registration. |
| 11300 | */ |
| 11301 | @Override |
| 11302 | public boolean isRcsVolteSingleRegistrationCapable(int subId) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 11303 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 11304 | Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable", |
| 11305 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 11306 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11307 | |
| 11308 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 11309 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 11310 | } |
| 11311 | |
| 11312 | final long identity = Binder.clearCallingIdentity(); |
| 11313 | try { |
| 11314 | RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance(); |
| 11315 | if (rpm != null) { |
Hui Wang | 67af90e | 2021-06-04 16:57:15 -0700 | [diff] [blame] | 11316 | Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId); |
| 11317 | if (isCapable != null) { |
| 11318 | return isCapable; |
| 11319 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11320 | } |
Hui Wang | 67af90e | 2021-06-04 16:57:15 -0700 | [diff] [blame] | 11321 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE, |
| 11322 | "service is temporarily unavailable."); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11323 | } finally { |
| 11324 | Binder.restoreCallingIdentity(identity); |
| 11325 | } |
| 11326 | } |
| 11327 | |
| 11328 | /** |
| 11329 | * Register RCS provisioning callback. |
| 11330 | */ |
| 11331 | @Override |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 11332 | public void registerRcsProvisioningCallback(int subId, |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11333 | IRcsConfigCallback callback) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 11334 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 11335 | Binder.getCallingUid(), "registerRcsProvisioningCallback", |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 11336 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 11337 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11338 | |
| 11339 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 11340 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 11341 | } |
| 11342 | if (!isImsAvailableOnDevice()) { |
| 11343 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 11344 | "IMS not available on device."); |
| 11345 | } |
| 11346 | |
| 11347 | final long identity = Binder.clearCallingIdentity(); |
| 11348 | try { |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 11349 | if (!RcsProvisioningMonitor.getInstance() |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 11350 | .registerRcsProvisioningCallback(subId, callback)) { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 11351 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION, |
| 11352 | "Active subscription not found."); |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 11353 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11354 | } finally { |
| 11355 | Binder.restoreCallingIdentity(identity); |
| 11356 | } |
| 11357 | } |
| 11358 | |
| 11359 | /** |
| 11360 | * Unregister RCS provisioning callback. |
| 11361 | */ |
| 11362 | @Override |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 11363 | public void unregisterRcsProvisioningCallback(int subId, |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11364 | IRcsConfigCallback callback) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 11365 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 11366 | Binder.getCallingUid(), "unregisterRcsProvisioningCallback", |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 11367 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 11368 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11369 | |
| 11370 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 11371 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 11372 | } |
| 11373 | if (!isImsAvailableOnDevice()) { |
joonhunshin | 46b49a3 | 2022-12-21 05:33:23 +0000 | [diff] [blame] | 11374 | // operation failed silently |
| 11375 | Rlog.w(LOG_TAG, "IMS not available on device."); |
| 11376 | return; |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11377 | } |
| 11378 | |
| 11379 | final long identity = Binder.clearCallingIdentity(); |
| 11380 | try { |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 11381 | RcsProvisioningMonitor.getInstance() |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 11382 | .unregisterRcsProvisioningCallback(subId, callback); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11383 | } finally { |
| 11384 | Binder.restoreCallingIdentity(identity); |
| 11385 | } |
| 11386 | } |
| 11387 | |
| 11388 | /** |
| 11389 | * trigger RCS reconfiguration. |
| 11390 | */ |
| 11391 | public void triggerRcsReconfiguration(int subId) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 11392 | TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(), |
| 11393 | "triggerRcsReconfiguration", |
| 11394 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11395 | |
| 11396 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 11397 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 11398 | } |
| 11399 | if (!isImsAvailableOnDevice()) { |
joonhunshin | 46b49a3 | 2022-12-21 05:33:23 +0000 | [diff] [blame] | 11400 | // ProvisioningManager can not handle ServiceSpecificException. |
| 11401 | // Throw the IllegalStateException and annotate ProvisioningManager. |
| 11402 | throw new IllegalStateException("IMS not available on device."); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11403 | } |
| 11404 | |
| 11405 | final long identity = Binder.clearCallingIdentity(); |
| 11406 | try { |
| 11407 | RcsProvisioningMonitor.getInstance().requestReconfig(subId); |
| 11408 | } finally { |
| 11409 | Binder.restoreCallingIdentity(identity); |
| 11410 | } |
| 11411 | } |
| 11412 | |
| 11413 | /** |
| 11414 | * Provide the client configuration parameters of the RCS application. |
| 11415 | */ |
| 11416 | public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 11417 | TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(), |
| 11418 | "setRcsClientConfiguration", |
| 11419 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11420 | |
| 11421 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 11422 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 11423 | } |
| 11424 | if (!isImsAvailableOnDevice()) { |
| 11425 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 11426 | "IMS not available on device."); |
| 11427 | } |
| 11428 | |
| 11429 | final long identity = Binder.clearCallingIdentity(); |
| 11430 | |
| 11431 | try { |
| 11432 | IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS); |
| 11433 | if (configBinder == null) { |
| 11434 | Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration"); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 11435 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION, |
| 11436 | "could not find the requested subscription"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11437 | } else { |
| 11438 | configBinder.setRcsClientConfiguration(rcc); |
| 11439 | } |
joonhunshin | 3e15424 | 2021-09-17 06:33:39 +0000 | [diff] [blame] | 11440 | |
| 11441 | RcsStats.getInstance().onRcsClientProvisioningStats(subId, |
| 11442 | RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11443 | } catch (RemoteException e) { |
| 11444 | Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage()); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 11445 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE, |
| 11446 | "service is temporarily unavailable."); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11447 | } finally { |
| 11448 | Binder.restoreCallingIdentity(identity); |
| 11449 | } |
| 11450 | } |
| 11451 | |
| 11452 | /** |
Hui Wang | baaee6a | 2021-02-19 20:45:36 -0800 | [diff] [blame] | 11453 | * Enables or disables the test mode for RCS VoLTE single registration. |
| 11454 | */ |
| 11455 | @Override |
| 11456 | public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) { |
| 11457 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11458 | "setRcsSingleRegistrationTestModeEnabled"); |
| 11459 | |
| 11460 | RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled); |
| 11461 | } |
| 11462 | |
| 11463 | /** |
| 11464 | * Gets the test mode for RCS VoLTE single registration. |
| 11465 | */ |
| 11466 | @Override |
| 11467 | public boolean getRcsSingleRegistrationTestModeEnabled() { |
| 11468 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11469 | "getRcsSingleRegistrationTestModeEnabled"); |
| 11470 | |
| 11471 | return RcsProvisioningMonitor.getInstance().getTestModeEnabled(); |
| 11472 | } |
| 11473 | |
| 11474 | /** |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11475 | * Overrides the config of RCS VoLTE single registration enabled for the device. |
| 11476 | */ |
| 11477 | @Override |
| 11478 | public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) { |
| 11479 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11480 | "setDeviceSingleRegistrationEnabledOverride"); |
| 11481 | enforceModifyPermission(); |
| 11482 | |
| 11483 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 11484 | : Boolean.parseBoolean(enabledStr); |
| 11485 | RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled); |
Brad Ebinger | 49a72b4 | 2021-01-29 00:55:24 +0000 | [diff] [blame] | 11486 | mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11487 | } |
| 11488 | |
| 11489 | /** |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 11490 | * Sends a device to device communication message. Only usable via shell. |
| 11491 | * @param message message to send. |
| 11492 | * @param value message value. |
| 11493 | */ |
| 11494 | @Override |
| 11495 | public void sendDeviceToDeviceMessage(int message, int value) { |
| 11496 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
Tyler Gunn | babbda0 | 2021-02-10 11:05:02 -0800 | [diff] [blame] | 11497 | "sendDeviceToDeviceMessage"); |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 11498 | enforceModifyPermission(); |
| 11499 | |
| 11500 | final long identity = Binder.clearCallingIdentity(); |
| 11501 | try { |
| 11502 | TelephonyConnectionService service = |
| 11503 | TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService(); |
| 11504 | if (service == null) { |
| 11505 | Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call."); |
| 11506 | return; |
| 11507 | } |
| 11508 | service.sendTestDeviceToDeviceMessage(message, value); |
| 11509 | } finally { |
| 11510 | Binder.restoreCallingIdentity(identity); |
| 11511 | } |
| 11512 | } |
| 11513 | |
Tyler Gunn | babbda0 | 2021-02-10 11:05:02 -0800 | [diff] [blame] | 11514 | /** |
| 11515 | * Sets the specified device to device transport active. |
| 11516 | * @param transport The transport to set active. |
| 11517 | */ |
| 11518 | @Override |
| 11519 | public void setActiveDeviceToDeviceTransport(@NonNull String transport) { |
| 11520 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11521 | "setActiveDeviceToDeviceTransport"); |
| 11522 | enforceModifyPermission(); |
| 11523 | |
| 11524 | final long identity = Binder.clearCallingIdentity(); |
| 11525 | try { |
| 11526 | TelephonyConnectionService service = |
| 11527 | TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService(); |
| 11528 | if (service == null) { |
| 11529 | Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call."); |
| 11530 | return; |
| 11531 | } |
| 11532 | service.setActiveDeviceToDeviceTransport(transport); |
| 11533 | } finally { |
| 11534 | Binder.restoreCallingIdentity(identity); |
| 11535 | } |
| 11536 | } |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 11537 | |
Tyler Gunn | d433926 | 2021-05-03 14:46:49 -0700 | [diff] [blame] | 11538 | @Override |
| 11539 | public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) { |
| 11540 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11541 | "setDeviceToDeviceForceEnabled"); |
| 11542 | |
| 11543 | final long identity = Binder.clearCallingIdentity(); |
| 11544 | try { |
| 11545 | Arrays.stream(PhoneFactory.getPhones()).forEach( |
| 11546 | p -> { |
| 11547 | Phone thePhone = p.getImsPhone(); |
| 11548 | if (thePhone != null && thePhone instanceof ImsPhone) { |
| 11549 | ImsPhone imsPhone = (ImsPhone) thePhone; |
| 11550 | CallTracker tracker = imsPhone.getCallTracker(); |
| 11551 | if (tracker != null && tracker instanceof ImsPhoneCallTracker) { |
| 11552 | ImsPhoneCallTracker imsPhoneCallTracker = |
| 11553 | (ImsPhoneCallTracker) tracker; |
| 11554 | imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled); |
| 11555 | } |
| 11556 | } |
| 11557 | } |
| 11558 | ); |
| 11559 | } finally { |
| 11560 | Binder.restoreCallingIdentity(identity); |
| 11561 | } |
| 11562 | } |
| 11563 | |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 11564 | /** |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11565 | * Gets the config of RCS VoLTE single registration enabled for the device. |
| 11566 | */ |
| 11567 | @Override |
| 11568 | public boolean getDeviceSingleRegistrationEnabled() { |
| 11569 | enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled"); |
| 11570 | return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled(); |
| 11571 | } |
| 11572 | |
| 11573 | /** |
| 11574 | * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription. |
| 11575 | */ |
| 11576 | @Override |
| 11577 | public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) { |
| 11578 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11579 | "setCarrierSingleRegistrationEnabledOverride"); |
| 11580 | enforceModifyPermission(); |
| 11581 | |
| 11582 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 11583 | : Boolean.parseBoolean(enabledStr); |
| 11584 | return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled( |
| 11585 | subId, enabled); |
| 11586 | } |
| 11587 | |
| 11588 | /** |
| 11589 | * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription. |
| 11590 | */ |
| 11591 | @Override |
| 11592 | public boolean getCarrierSingleRegistrationEnabled(int subId) { |
| 11593 | enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled"); |
| 11594 | return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId); |
| 11595 | } |
Chiachang Wang | d6d3477 | 2020-12-22 11:38:27 +0800 | [diff] [blame] | 11596 | |
| 11597 | /** |
Hui Wang | b647abe | 2021-02-26 09:33:38 -0800 | [diff] [blame] | 11598 | * Overrides the ims feature validation result |
| 11599 | */ |
| 11600 | @Override |
| 11601 | public boolean setImsFeatureValidationOverride(int subId, String enabledStr) { |
| 11602 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11603 | "setImsFeatureValidationOverride"); |
| 11604 | |
| 11605 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 11606 | : Boolean.parseBoolean(enabledStr); |
| 11607 | return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation( |
| 11608 | subId, enabled); |
| 11609 | } |
| 11610 | |
| 11611 | /** |
| 11612 | * Gets the ims feature validation override value |
| 11613 | */ |
| 11614 | @Override |
| 11615 | public boolean getImsFeatureValidationOverride(int subId) { |
| 11616 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11617 | "getImsFeatureValidationOverride"); |
| 11618 | return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId); |
| 11619 | } |
| 11620 | |
| 11621 | /** |
Chiachang Wang | d6d3477 | 2020-12-22 11:38:27 +0800 | [diff] [blame] | 11622 | * Get the mobile provisioning url that is used to launch a browser to allow users to manage |
| 11623 | * their mobile plan. |
| 11624 | */ |
| 11625 | @Override |
| 11626 | public String getMobileProvisioningUrl() { |
| 11627 | enforceReadPrivilegedPermission("getMobileProvisioningUrl"); |
| 11628 | final long identity = Binder.clearCallingIdentity(); |
| 11629 | try { |
| 11630 | return getDefaultPhone().getMobileProvisioningUrl(); |
| 11631 | } finally { |
| 11632 | Binder.restoreCallingIdentity(identity); |
| 11633 | } |
| 11634 | } |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11635 | |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 11636 | /** |
calvinpan | e4a8a1d | 2021-01-25 13:51:18 +0800 | [diff] [blame] | 11637 | * Get the EAB contact from the EAB database. |
| 11638 | */ |
| 11639 | @Override |
| 11640 | public String getContactFromEab(String contact) { |
| 11641 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab"); |
| 11642 | enforceModifyPermission(); |
| 11643 | final long identity = Binder.clearCallingIdentity(); |
| 11644 | try { |
| 11645 | return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact); |
| 11646 | } finally { |
| 11647 | Binder.restoreCallingIdentity(identity); |
| 11648 | } |
| 11649 | } |
| 11650 | |
| 11651 | /** |
Calvin Pan | a143432 | 2021-07-01 19:27:01 +0800 | [diff] [blame] | 11652 | * Get the EAB capability from the EAB database. |
| 11653 | */ |
| 11654 | @Override |
| 11655 | public String getCapabilityFromEab(String contact) { |
| 11656 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab"); |
| 11657 | enforceModifyPermission(); |
| 11658 | final long identity = Binder.clearCallingIdentity(); |
| 11659 | try { |
| 11660 | return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact); |
| 11661 | } finally { |
| 11662 | Binder.restoreCallingIdentity(identity); |
| 11663 | } |
| 11664 | } |
| 11665 | |
| 11666 | /** |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 11667 | * Remove the EAB contacts from the EAB database. |
| 11668 | */ |
| 11669 | @Override |
| 11670 | public int removeContactFromEab(int subId, String contacts) { |
| 11671 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab"); |
| 11672 | enforceModifyPermission(); |
| 11673 | final long identity = Binder.clearCallingIdentity(); |
| 11674 | try { |
| 11675 | return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext()); |
| 11676 | } finally { |
| 11677 | Binder.restoreCallingIdentity(identity); |
| 11678 | } |
| 11679 | } |
| 11680 | |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11681 | @Override |
James.cf Lin | 4b784aa | 2021-01-31 03:25:15 +0800 | [diff] [blame] | 11682 | public boolean getDeviceUceEnabled() { |
| 11683 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled"); |
| 11684 | final long identity = Binder.clearCallingIdentity(); |
| 11685 | try { |
| 11686 | return mApp.getDeviceUceEnabled(); |
| 11687 | } finally { |
| 11688 | Binder.restoreCallingIdentity(identity); |
| 11689 | } |
| 11690 | } |
| 11691 | |
| 11692 | @Override |
| 11693 | public void setDeviceUceEnabled(boolean isEnabled) { |
| 11694 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled"); |
| 11695 | final long identity = Binder.clearCallingIdentity(); |
| 11696 | try { |
| 11697 | mApp.setDeviceUceEnabled(isEnabled); |
| 11698 | } finally { |
| 11699 | Binder.restoreCallingIdentity(identity); |
| 11700 | } |
| 11701 | } |
| 11702 | |
Brad Ebinger | 14d467f | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 11703 | /** |
| 11704 | * Add new feature tags to the Set used to calculate the capabilities in PUBLISH. |
| 11705 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 11706 | */ |
| 11707 | // Used for SHELL command only right now. |
| 11708 | @Override |
| 11709 | public RcsContactUceCapability addUceRegistrationOverrideShell(int subId, |
| 11710 | List<String> featureTags) { |
| 11711 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11712 | "addUceRegistrationOverrideShell"); |
| 11713 | final long identity = Binder.clearCallingIdentity(); |
| 11714 | try { |
| 11715 | return mApp.imsRcsController.addUceRegistrationOverrideShell(subId, |
| 11716 | new ArraySet<>(featureTags)); |
| 11717 | } catch (ImsException e) { |
| 11718 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 11719 | } finally { |
| 11720 | Binder.restoreCallingIdentity(identity); |
| 11721 | } |
| 11722 | } |
| 11723 | |
| 11724 | /** |
| 11725 | * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH. |
| 11726 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 11727 | */ |
| 11728 | // Used for SHELL command only right now. |
| 11729 | @Override |
| 11730 | public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId, |
| 11731 | List<String> featureTags) { |
| 11732 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11733 | "removeUceRegistrationOverrideShell"); |
| 11734 | final long identity = Binder.clearCallingIdentity(); |
| 11735 | try { |
| 11736 | return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId, |
| 11737 | new ArraySet<>(featureTags)); |
| 11738 | } catch (ImsException e) { |
| 11739 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 11740 | } finally { |
| 11741 | Binder.restoreCallingIdentity(identity); |
| 11742 | } |
| 11743 | } |
| 11744 | |
| 11745 | /** |
| 11746 | * Clear all overrides in the Set used to calculate the capabilities in PUBLISH. |
| 11747 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 11748 | */ |
| 11749 | // Used for SHELL command only right now. |
| 11750 | @Override |
| 11751 | public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) { |
| 11752 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11753 | "clearUceRegistrationOverrideShell"); |
| 11754 | final long identity = Binder.clearCallingIdentity(); |
| 11755 | try { |
| 11756 | return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId); |
| 11757 | } catch (ImsException e) { |
| 11758 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 11759 | } finally { |
| 11760 | Binder.restoreCallingIdentity(identity); |
| 11761 | } |
| 11762 | } |
| 11763 | |
| 11764 | /** |
| 11765 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 11766 | */ |
| 11767 | // Used for SHELL command only right now. |
| 11768 | @Override |
| 11769 | public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) { |
| 11770 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11771 | "getLatestRcsContactUceCapabilityShell"); |
| 11772 | final long identity = Binder.clearCallingIdentity(); |
| 11773 | try { |
| 11774 | return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId); |
| 11775 | } catch (ImsException e) { |
| 11776 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 11777 | } finally { |
| 11778 | Binder.restoreCallingIdentity(identity); |
| 11779 | } |
| 11780 | } |
| 11781 | |
| 11782 | /** |
| 11783 | * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the |
| 11784 | * device does not have an active PUBLISH. |
| 11785 | */ |
| 11786 | // Used for SHELL command only right now. |
| 11787 | @Override |
| 11788 | public String getLastUcePidfXmlShell(int subId) { |
| 11789 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml"); |
| 11790 | final long identity = Binder.clearCallingIdentity(); |
| 11791 | try { |
| 11792 | return mApp.imsRcsController.getLastUcePidfXmlShell(subId); |
| 11793 | } catch (ImsException e) { |
| 11794 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 11795 | } finally { |
| 11796 | Binder.restoreCallingIdentity(identity); |
| 11797 | } |
| 11798 | } |
| 11799 | |
James.cf Lin | e8713a4 | 2021-04-29 16:04:26 +0800 | [diff] [blame] | 11800 | /** |
| 11801 | * Remove UCE requests cannot be sent to the network status. |
| 11802 | */ |
| 11803 | // Used for SHELL command only right now. |
| 11804 | @Override |
| 11805 | public boolean removeUceRequestDisallowedStatus(int subId) { |
| 11806 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus"); |
| 11807 | final long identity = Binder.clearCallingIdentity(); |
| 11808 | try { |
| 11809 | return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId); |
| 11810 | } catch (ImsException e) { |
| 11811 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 11812 | } finally { |
| 11813 | Binder.restoreCallingIdentity(identity); |
| 11814 | } |
| 11815 | } |
| 11816 | |
James.cf Lin | 18bb900 | 2021-05-25 01:37:38 +0800 | [diff] [blame] | 11817 | /** |
| 11818 | * Remove UCE requests cannot be sent to the network status. |
| 11819 | */ |
| 11820 | // Used for SHELL command only. |
| 11821 | @Override |
| 11822 | public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) { |
| 11823 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout"); |
| 11824 | final long identity = Binder.clearCallingIdentity(); |
| 11825 | try { |
| 11826 | return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs); |
| 11827 | } catch (ImsException e) { |
| 11828 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 11829 | } finally { |
| 11830 | Binder.restoreCallingIdentity(identity); |
| 11831 | } |
| 11832 | } |
Brad Ebinger | 14d467f | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 11833 | |
James.cf Lin | 4b784aa | 2021-01-31 03:25:15 +0800 | [diff] [blame] | 11834 | @Override |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11835 | public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request, |
| 11836 | String callingPackage) { |
| 11837 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 11838 | mApp, subId, "setSignalStrengthUpdateRequest"); |
| 11839 | |
| 11840 | final int callingUid = Binder.getCallingUid(); |
| 11841 | // Verify that tha callingPackage belongs to the calling UID |
| 11842 | mApp.getSystemService(AppOpsManager.class) |
| 11843 | .checkPackage(callingUid, callingPackage); |
| 11844 | |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 11845 | validateSignalStrengthUpdateRequest(mApp, request, callingUid); |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11846 | |
| 11847 | final long identity = Binder.clearCallingIdentity(); |
| 11848 | try { |
| 11849 | Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST, |
| 11850 | new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId); |
| 11851 | |
| 11852 | if (result instanceof IllegalStateException) { |
| 11853 | throw (IllegalStateException) result; |
| 11854 | } |
| 11855 | } finally { |
| 11856 | Binder.restoreCallingIdentity(identity); |
| 11857 | } |
| 11858 | } |
| 11859 | |
| 11860 | @Override |
| 11861 | public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request, |
| 11862 | String callingPackage) { |
| 11863 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 11864 | mApp, subId, "clearSignalStrengthUpdateRequest"); |
| 11865 | |
| 11866 | final int callingUid = Binder.getCallingUid(); |
| 11867 | // Verify that tha callingPackage belongs to the calling UID |
| 11868 | mApp.getSystemService(AppOpsManager.class) |
| 11869 | .checkPackage(callingUid, callingPackage); |
| 11870 | |
| 11871 | final long identity = Binder.clearCallingIdentity(); |
| 11872 | try { |
| 11873 | Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST, |
| 11874 | new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId); |
| 11875 | |
| 11876 | if (result instanceof IllegalStateException) { |
| 11877 | throw (IllegalStateException) result; |
| 11878 | } |
| 11879 | } finally { |
| 11880 | Binder.restoreCallingIdentity(identity); |
| 11881 | } |
| 11882 | } |
| 11883 | |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 11884 | private static void validateSignalStrengthUpdateRequest(Context context, |
| 11885 | SignalStrengthUpdateRequest request, int callingUid) { |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11886 | if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) { |
| 11887 | // phone/system process do not have further restriction on request |
| 11888 | return; |
| 11889 | } |
| 11890 | |
| 11891 | // Applications has restrictions on how to use the request: |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 11892 | // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11893 | if (request.isSystemThresholdReportingRequestedWhileIdle()) { |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 11894 | context.enforceCallingOrSelfPermission( |
| 11895 | android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH, |
| 11896 | "validateSignalStrengthUpdateRequest"); |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11897 | } |
| 11898 | |
| 11899 | for (SignalThresholdInfo info : request.getSignalThresholdInfos()) { |
Nagendra Prasad Nagarle Basavaraju | fee544c | 2022-12-07 16:34:52 +0000 | [diff] [blame] | 11900 | // Only system caller can set mHysteresisMs/mIsEnabled. |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11901 | if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11902 | || info.isEnabled()) { |
| 11903 | throw new IllegalArgumentException( |
| 11904 | "Only system can set hide fields in SignalThresholdInfo"); |
| 11905 | } |
| 11906 | |
| 11907 | // Thresholds length for each RAN need in range. This has been validated in |
| 11908 | // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method |
| 11909 | // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds |
| 11910 | final int[] thresholds = info.getThresholds(); |
| 11911 | Objects.requireNonNull(thresholds); |
| 11912 | if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed() |
| 11913 | || thresholds.length |
| 11914 | > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) { |
| 11915 | throw new IllegalArgumentException( |
| 11916 | "thresholds length is out of range: " + thresholds.length); |
| 11917 | } |
| 11918 | } |
| 11919 | } |
SongFerngWang | 8236caa | 2021-01-17 21:51:44 +0800 | [diff] [blame] | 11920 | |
| 11921 | /** |
| 11922 | * Gets the current phone capability. |
| 11923 | * |
| 11924 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 11925 | * @return the PhoneCapability which describes the data connection capability of modem. |
| 11926 | * It's used to evaluate possible phone config change, for example from single |
| 11927 | * SIM device to multi-SIM device. |
| 11928 | */ |
| 11929 | @Override |
| 11930 | public PhoneCapability getPhoneCapability() { |
| 11931 | enforceReadPrivilegedPermission("getPhoneCapability"); |
| 11932 | final long identity = Binder.clearCallingIdentity(); |
| 11933 | try { |
| 11934 | return mPhoneConfigurationManager.getCurrentPhoneCapability(); |
| 11935 | } finally { |
| 11936 | Binder.restoreCallingIdentity(identity); |
| 11937 | } |
| 11938 | } |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 11939 | |
| 11940 | /** |
| 11941 | * Prepare TelephonyManager for an unattended reboot. The reboot is |
| 11942 | * required to be done shortly after the API is invoked. |
| 11943 | */ |
| 11944 | @Override |
| 11945 | @TelephonyManager.PrepareUnattendedRebootResult |
| 11946 | public int prepareForUnattendedReboot() { |
Rafael Higuera Silva | d963064 | 2021-09-20 15:32:01 +0000 | [diff] [blame] | 11947 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 11948 | enforceRebootPermission(); |
| 11949 | |
| 11950 | final long identity = Binder.clearCallingIdentity(); |
| 11951 | try { |
Rafael Higuera Silva | d963064 | 2021-09-20 15:32:01 +0000 | [diff] [blame] | 11952 | return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 11953 | } finally { |
| 11954 | Binder.restoreCallingIdentity(identity); |
| 11955 | } |
| 11956 | } |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 11957 | |
| 11958 | /** |
| 11959 | * Request to get the current slicing configuration including URSP rules and |
| 11960 | * NSSAIs (configured, allowed and rejected). |
| 11961 | * |
| 11962 | * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission. |
| 11963 | */ |
| 11964 | @Override |
| 11965 | public void getSlicingConfig(ResultReceiver callback) { |
Hongbo Zeng | 1b2063d | 2022-02-21 01:33:03 +0000 | [diff] [blame] | 11966 | TelephonyPermissions |
| 11967 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 11968 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, "getSlicingConfig"); |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 11969 | |
| 11970 | final long identity = Binder.clearCallingIdentity(); |
| 11971 | try { |
| 11972 | Phone phone = getDefaultPhone(); |
| 11973 | sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null); |
| 11974 | } finally { |
| 11975 | Binder.restoreCallingIdentity(identity); |
| 11976 | } |
| 11977 | } |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 11978 | |
| 11979 | /** |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 11980 | * Check whether the given premium capability is available for purchase from the carrier. |
| 11981 | * |
| 11982 | * @param capability The premium capability to check. |
| 11983 | * @param subId The subId to check the premium capability for. |
| 11984 | * |
| 11985 | * @return Whether the given premium capability is available to purchase. |
| 11986 | */ |
| 11987 | @Override |
| 11988 | public boolean isPremiumCapabilityAvailableForPurchase(int capability, int subId) { |
| 11989 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 11990 | mApp, "isPremiumCapabilityAvailableForPurchase")) { |
| 11991 | log("Premium capability " |
| 11992 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 11993 | + " is not available for purchase due to missing permissions."); |
| 11994 | throw new SecurityException("isPremiumCapabilityAvailableForPurchase requires " |
| 11995 | + "permission READ_BASIC_PHONE_STATE."); |
| 11996 | } |
| 11997 | |
| 11998 | Phone phone = getPhone(subId); |
Thomas Nguyen | 7216ed6 | 2022-11-29 16:45:31 -0800 | [diff] [blame] | 11999 | if (phone == null) { |
| 12000 | loge("isPremiumCapabilityAvailableForPurchase: phone is null, subId=" + subId); |
| 12001 | return false; |
| 12002 | } |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 12003 | final long identity = Binder.clearCallingIdentity(); |
| 12004 | try { |
Sarah Chin | 46355ba | 2022-11-01 23:51:16 -0700 | [diff] [blame] | 12005 | return SlicePurchaseController.getInstance(phone) |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 12006 | .isPremiumCapabilityAvailableForPurchase(capability); |
| 12007 | } finally { |
| 12008 | Binder.restoreCallingIdentity(identity); |
| 12009 | } |
| 12010 | } |
| 12011 | |
| 12012 | /** |
| 12013 | * Purchase the given premium capability from the carrier. |
| 12014 | * |
| 12015 | * @param capability The premium capability to purchase. |
| 12016 | * @param callback The result of the purchase request. |
| 12017 | * @param subId The subId to purchase the premium capability for. |
| 12018 | */ |
| 12019 | @Override |
| 12020 | public void purchasePremiumCapability(int capability, IIntegerConsumer callback, int subId) { |
| 12021 | log("purchasePremiumCapability: capability=" |
| 12022 | + TelephonyManager.convertPremiumCapabilityToString(capability) + ", caller=" |
| 12023 | + getCurrentPackageName()); |
| 12024 | |
| 12025 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 12026 | mApp, "purchasePremiumCapability")) { |
| 12027 | log("purchasePremiumCapability " |
| 12028 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 12029 | + " failed due to missing permissions."); |
| 12030 | throw new SecurityException("purchasePremiumCapability requires permission " |
| 12031 | + "READ_BASIC_PHONE_STATE."); |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 12032 | } else if (!TelephonyPermissions.checkInternetPermissionNoThrow( |
| 12033 | mApp, "purchasePremiumCapability")) { |
| 12034 | log("purchasePremiumCapability " |
| 12035 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 12036 | + " failed due to missing permissions."); |
| 12037 | throw new SecurityException("purchasePremiumCapability requires permission INTERNET."); |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 12038 | } |
| 12039 | |
| 12040 | Phone phone = getPhone(subId); |
Sarah Chin | 1969411 | 2022-12-06 15:41:37 -0800 | [diff] [blame] | 12041 | if (phone == null) { |
| 12042 | try { |
| 12043 | int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_REQUEST_FAILED; |
| 12044 | callback.accept(result); |
| 12045 | loge("purchasePremiumCapability: phone is null, subId=" + subId); |
| 12046 | } catch (RemoteException e) { |
| 12047 | String logStr = "Purchase premium capability " |
| 12048 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 12049 | + " failed due to RemoteException handling null phone: " + e; |
| 12050 | if (DBG) log(logStr); |
| 12051 | AnomalyReporter.reportAnomaly( |
| 12052 | UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr); |
| 12053 | } |
| 12054 | return; |
| 12055 | } |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 12056 | |
| 12057 | String callingProcess; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 12058 | try { |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 12059 | callingProcess = mApp.getPackageManager().getApplicationInfo( |
| 12060 | getCurrentPackageName(), 0).processName; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 12061 | } catch (PackageManager.NameNotFoundException e) { |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 12062 | callingProcess = getCurrentPackageName(); |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 12063 | } |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 12064 | |
| 12065 | boolean isVisible = false; |
| 12066 | ActivityManager am = mApp.getSystemService(ActivityManager.class); |
| 12067 | if (am != null) { |
| 12068 | List<ActivityManager.RunningAppProcessInfo> processes = am.getRunningAppProcesses(); |
| 12069 | if (processes != null) { |
| 12070 | for (ActivityManager.RunningAppProcessInfo process : processes) { |
| 12071 | log("purchasePremiumCapability: process " + process.processName |
| 12072 | + "has importance " + process.importance); |
| 12073 | if (process.processName.equals(callingProcess) && process.importance |
| 12074 | <= ActivityManager.RunningAppProcessInfo.IMPORTANCE_VISIBLE) { |
| 12075 | isVisible = true; |
| 12076 | break; |
| 12077 | } |
| 12078 | } |
| 12079 | } |
| 12080 | } |
| 12081 | |
| 12082 | if (!isVisible) { |
| 12083 | try { |
| 12084 | int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_NOT_FOREGROUND; |
| 12085 | callback.accept(result); |
| 12086 | loge("purchasePremiumCapability: " + callingProcess + " is not in the foreground."); |
| 12087 | } catch (RemoteException e) { |
| 12088 | String logStr = "Purchase premium capability " |
| 12089 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 12090 | + " failed due to RemoteException handling background application: " + e; |
| 12091 | if (DBG) log(logStr); |
| 12092 | AnomalyReporter.reportAnomaly( |
| 12093 | UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr); |
| 12094 | } |
| 12095 | return; |
| 12096 | } |
| 12097 | |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 12098 | sendRequestAsync(CMD_PURCHASE_PREMIUM_CAPABILITY, |
Sarah Chin | b8218c2 | 2023-01-04 13:35:29 -0800 | [diff] [blame] | 12099 | new PurchasePremiumCapabilityArgument(capability, callback), phone, null); |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 12100 | } |
| 12101 | |
| 12102 | /** |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 12103 | * Register an IMS connection state callback |
| 12104 | */ |
| 12105 | @Override |
Hunsuk Choi | 89bd22c | 2021-11-01 13:04:54 +0000 | [diff] [blame] | 12106 | public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb, |
| 12107 | String callingPackage) { |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 12108 | if (feature == ImsFeature.FEATURE_MMTEL) { |
| 12109 | // ImsMmTelManager |
| 12110 | // The following also checks READ_PRIVILEGED_PHONE_STATE. |
| 12111 | TelephonyPermissions |
| 12112 | .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 12113 | mApp, subId, "registerImsStateCallback"); |
| 12114 | } else if (feature == ImsFeature.FEATURE_RCS) { |
| 12115 | // ImsRcsManager or SipDelegateManager |
| 12116 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 12117 | Binder.getCallingUid(), "registerImsStateCallback", |
| 12118 | Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
| 12119 | Manifest.permission.READ_PRECISE_PHONE_STATE, |
| 12120 | Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE, |
| 12121 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
| 12122 | } |
| 12123 | |
| 12124 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 12125 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 12126 | "IMS not available on device."); |
| 12127 | } |
| 12128 | |
| 12129 | if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) { |
| 12130 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 12131 | } |
| 12132 | |
| 12133 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 12134 | if (controller == null) { |
| 12135 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 12136 | "IMS not available on device."); |
| 12137 | } |
| 12138 | |
Hunsuk Choi | 89bd22c | 2021-11-01 13:04:54 +0000 | [diff] [blame] | 12139 | if (callingPackage == null) { |
| 12140 | callingPackage = getCurrentPackageName(); |
| 12141 | } |
| 12142 | |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 12143 | final long token = Binder.clearCallingIdentity(); |
| 12144 | try { |
| 12145 | int slotId = getSlotIndexOrException(subId); |
Hunsuk Choi | 89bd22c | 2021-11-01 13:04:54 +0000 | [diff] [blame] | 12146 | controller.registerImsStateCallback(subId, feature, cb, callingPackage); |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 12147 | } catch (ImsException e) { |
| 12148 | throw new ServiceSpecificException(e.getCode()); |
| 12149 | } finally { |
| 12150 | Binder.restoreCallingIdentity(token); |
| 12151 | } |
| 12152 | } |
| 12153 | |
| 12154 | /** |
| 12155 | * Unregister an IMS connection state callback |
| 12156 | */ |
| 12157 | @Override |
| 12158 | public void unregisterImsStateCallback(IImsStateCallback cb) { |
| 12159 | final long token = Binder.clearCallingIdentity(); |
| 12160 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 12161 | if (controller == null) { |
| 12162 | return; |
| 12163 | } |
| 12164 | try { |
| 12165 | controller.unregisterImsStateCallback(cb); |
| 12166 | } finally { |
| 12167 | Binder.restoreCallingIdentity(token); |
| 12168 | } |
| 12169 | } |
Sooraj Sasindran | fae41b3 | 2021-10-26 02:10:05 -0700 | [diff] [blame] | 12170 | |
| 12171 | /** |
| 12172 | * @return {@CellIdentity} last known cell identity {@CellIdentity}. |
| 12173 | * |
| 12174 | * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and |
| 12175 | * com.android.phone.permission.ACCESS_LAST_KNOWN_CELL_ID, otherwise throws |
| 12176 | * SecurityException. |
| 12177 | * If there is current registered network this value will be same as the registered cell |
| 12178 | * identity. If the device goes out of service the previous cell identity is cached and |
| 12179 | * will be returned. If the cache age of the Cell identity is more than 24 hours |
| 12180 | * it will be cleared and null will be returned. |
| 12181 | * |
| 12182 | */ |
| 12183 | @Override |
| 12184 | public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage, |
| 12185 | String callingFeatureId) { |
| 12186 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 12187 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 12188 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 12189 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 12190 | .setCallingPackage(callingPackage) |
| 12191 | .setCallingFeatureId(callingFeatureId) |
| 12192 | .setCallingPid(Binder.getCallingPid()) |
| 12193 | .setCallingUid(Binder.getCallingUid()) |
| 12194 | .setMethod("getLastKnownCellIdentity") |
| 12195 | .setLogAsInfo(true) |
| 12196 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 12197 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 12198 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 12199 | .build()); |
| 12200 | |
| 12201 | boolean hasFinePermission = |
| 12202 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 12203 | if (!hasFinePermission |
| 12204 | || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) { |
| 12205 | throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION " |
Rambo Wang | 918993a | 2022-04-27 09:08:36 -0700 | [diff] [blame] | 12206 | + "and ACCESS_LAST_KNOWN_CELL_ID permission."); |
Sooraj Sasindran | fae41b3 | 2021-10-26 02:10:05 -0700 | [diff] [blame] | 12207 | } |
| 12208 | |
| 12209 | final long identity = Binder.clearCallingIdentity(); |
| 12210 | try { |
| 12211 | Phone phone = getPhone(subId); |
| 12212 | if (phone == null) return null; |
| 12213 | ServiceStateTracker sst = phone.getServiceStateTracker(); |
| 12214 | if (sst == null) return null; |
| 12215 | return sst.getLastKnownCellIdentity(); |
| 12216 | } finally { |
| 12217 | Binder.restoreCallingIdentity(identity); |
| 12218 | } |
| 12219 | } |
Jack Yu | 4c0a550 | 2021-12-03 23:58:26 -0800 | [diff] [blame] | 12220 | |
jimsun | 3b9ccac | 2021-10-26 15:01:23 +0800 | [diff] [blame] | 12221 | /** |
| 12222 | * Sets the modem service class Name that Telephony will bind to. |
| 12223 | * |
| 12224 | * @param serviceName The class name of the modem service. |
| 12225 | * @return true if the operation is succeed, otherwise false. |
| 12226 | */ |
| 12227 | public boolean setModemService(String serviceName) { |
| 12228 | Log.d(LOG_TAG, "setModemService - " + serviceName); |
| 12229 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService"); |
| 12230 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12231 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 12232 | "setModemService"); |
jimsun | 3b9ccac | 2021-10-26 15:01:23 +0800 | [diff] [blame] | 12233 | return mPhoneConfigurationManager.setModemService(serviceName); |
| 12234 | } |
| 12235 | |
| 12236 | /** |
| 12237 | * Return the class name of the currently bounded modem service. |
| 12238 | * |
| 12239 | * @return the class name of the modem service. |
| 12240 | */ |
| 12241 | public String getModemService() { |
| 12242 | String result; |
| 12243 | Log.d(LOG_TAG, "getModemService"); |
| 12244 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService"); |
| 12245 | TelephonyPermissions |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12246 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
jimsun | 3b9ccac | 2021-10-26 15:01:23 +0800 | [diff] [blame] | 12247 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 12248 | "getModemService"); |
| 12249 | result = mPhoneConfigurationManager.getModemService(); |
| 12250 | Log.d(LOG_TAG, "result = " + result); |
| 12251 | return result; |
| 12252 | } |
Hunter Knepshield | 2b076fa | 2022-01-19 02:26:22 -0800 | [diff] [blame] | 12253 | |
| 12254 | @Override |
| 12255 | public void setVoiceServiceStateOverride(int subId, boolean hasService, String callingPackage) { |
| 12256 | // Only telecom (and shell, for CTS purposes) is allowed to call this method. |
| 12257 | mApp.enforceCallingOrSelfPermission( |
| 12258 | permission.BIND_TELECOM_CONNECTION_SERVICE, "setVoiceServiceStateOverride"); |
| 12259 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 12260 | |
| 12261 | final long identity = Binder.clearCallingIdentity(); |
| 12262 | try { |
| 12263 | Phone phone = getPhone(subId); |
| 12264 | if (phone == null) return; |
Grant Menke | 63ade12 | 2023-01-20 14:31:54 -0800 | [diff] [blame] | 12265 | Log.i(LOG_TAG, "setVoiceServiceStateOverride: subId=" + subId + ", phone=" + phone |
| 12266 | + ", hasService=" + hasService + ", callingPackage=" + callingPackage); |
Hunter Knepshield | 2b076fa | 2022-01-19 02:26:22 -0800 | [diff] [blame] | 12267 | phone.setVoiceServiceStateOverride(hasService); |
| 12268 | } finally { |
| 12269 | Binder.restoreCallingIdentity(identity); |
| 12270 | } |
| 12271 | } |
Muralidhar Reddy | 4e5a801 | 2022-05-11 14:49:00 +0000 | [diff] [blame] | 12272 | |
| 12273 | /** |
| 12274 | * set removable eSIM as default eUICC. |
| 12275 | * |
| 12276 | * @hide |
| 12277 | */ |
| 12278 | @Override |
| 12279 | public void setRemovableEsimAsDefaultEuicc(boolean isDefault, String callingPackage) { |
| 12280 | enforceModifyPermission(); |
| 12281 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 12282 | |
| 12283 | final long identity = Binder.clearCallingIdentity(); |
| 12284 | try { |
| 12285 | UiccController.getInstance().setRemovableEsimAsDefaultEuicc(isDefault); |
| 12286 | } finally { |
| 12287 | Binder.restoreCallingIdentity(identity); |
| 12288 | } |
| 12289 | } |
| 12290 | |
| 12291 | /** |
| 12292 | * Returns whether the removable eSIM is default eUICC or not. |
| 12293 | * |
| 12294 | * @hide |
| 12295 | */ |
| 12296 | @Override |
| 12297 | public boolean isRemovableEsimDefaultEuicc(String callingPackage) { |
| 12298 | enforceReadPrivilegedPermission("isRemovableEsimDefaultEuicc"); |
| 12299 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 12300 | |
| 12301 | final long identity = Binder.clearCallingIdentity(); |
| 12302 | try { |
| 12303 | return UiccController.getInstance().isRemovableEsimDefaultEuicc(); |
| 12304 | } finally { |
| 12305 | Binder.restoreCallingIdentity(identity); |
| 12306 | } |
| 12307 | } |
| 12308 | |
Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame] | 12309 | /** |
| 12310 | * Get the component name of the default app to direct respond-via-message intent for the |
| 12311 | * user associated with this subscription, update the cache if there is no respond-via-message |
| 12312 | * application currently configured for this user. |
| 12313 | * @return component name of the app and class to direct Respond Via Message intent to, or |
| 12314 | * {@code null} if the functionality is not supported. |
| 12315 | * @hide |
| 12316 | */ |
| 12317 | @Override |
| 12318 | public @Nullable ComponentName getDefaultRespondViaMessageApplication(int subId, |
| 12319 | boolean updateIfNeeded) { |
| 12320 | enforceInteractAcrossUsersPermission("getDefaultRespondViaMessageApplication"); |
Muralidhar Reddy | 4e5a801 | 2022-05-11 14:49:00 +0000 | [diff] [blame] | 12321 | |
Aishwarya Mallampati | 5e581e1 | 2023-01-17 21:57:06 +0000 | [diff] [blame] | 12322 | Context context = getPhoneFromSubIdOrDefault(subId).getContext(); |
| 12323 | |
Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame] | 12324 | UserHandle userHandle = null; |
| 12325 | final long identity = Binder.clearCallingIdentity(); |
| 12326 | try { |
| 12327 | userHandle = TelephonyUtils.getSubscriptionUserHandle(context, subId); |
| 12328 | } finally { |
| 12329 | Binder.restoreCallingIdentity(identity); |
| 12330 | } |
| 12331 | return SmsApplication.getDefaultRespondViaMessageApplicationAsUser(context, |
| 12332 | updateIfNeeded, userHandle); |
| 12333 | } |
Jack Yu | f5badd9 | 2022-12-08 00:50:53 -0800 | [diff] [blame] | 12334 | |
| 12335 | /** |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 12336 | * Set whether the device is able to connect with null ciphering or integrity |
| 12337 | * algorithms. This is a global setting and will apply to all active subscriptions |
| 12338 | * and all new subscriptions after this. |
| 12339 | * |
| 12340 | * @param enabled when true, null cipher and integrity algorithms are allowed. |
| 12341 | * @hide |
| 12342 | */ |
| 12343 | @Override |
| 12344 | @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 12345 | public void setNullCipherAndIntegrityEnabled(boolean enabled) { |
| 12346 | enforceModifyPermission(); |
| 12347 | checkForNullCipherAndIntegritySupport(); |
| 12348 | |
| 12349 | // Persist the state of our preference. Each GsmCdmaPhone instance is responsible |
| 12350 | // for listening to these preference changes and applying them immediately. |
| 12351 | SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 12352 | editor.putBoolean(Phone.PREF_NULL_CIPHER_AND_INTEGRITY_ENABLED, enabled); |
| 12353 | editor.apply(); |
| 12354 | |
| 12355 | for (Phone phone: PhoneFactory.getPhones()) { |
| 12356 | phone.handleNullCipherEnabledChange(); |
| 12357 | } |
| 12358 | } |
| 12359 | |
| 12360 | |
| 12361 | /** |
| 12362 | * Get whether the device is able to connect with null ciphering or integrity |
| 12363 | * algorithms. Note that this retrieves the phone-global preference and not |
| 12364 | * the state of the radio. |
| 12365 | * |
| 12366 | * @throws SecurityException if {@link permission#MODIFY_PHONE_STATE} is not satisfied |
| 12367 | * @throws UnsupportedOperationException if the device does not support the minimum HAL |
| 12368 | * version for this feature. |
| 12369 | * @hide |
| 12370 | */ |
| 12371 | @Override |
| 12372 | @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) |
| 12373 | public boolean isNullCipherAndIntegrityPreferenceEnabled() { |
| 12374 | enforceReadPermission(); |
| 12375 | checkForNullCipherAndIntegritySupport(); |
| 12376 | return getDefaultPhone().getNullCipherAndIntegrityEnabledPreference(); |
| 12377 | } |
| 12378 | |
| 12379 | private void checkForNullCipherAndIntegritySupport() { |
| 12380 | if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_NULL_CIPHER_AND_INTEGRITY_VERSION) { |
| 12381 | throw new UnsupportedOperationException( |
| 12382 | "Null cipher and integrity operations require HAL 2.1 or above"); |
| 12383 | } |
Gil Cukierman | 92cc7db | 2023-01-06 19:25:53 +0000 | [diff] [blame] | 12384 | if (!getDefaultPhone().isNullCipherAndIntegritySupported()) { |
| 12385 | throw new UnsupportedOperationException( |
| 12386 | "Null cipher and integrity operations unsupported by modem"); |
| 12387 | } |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 12388 | } |
| 12389 | |
| 12390 | /** |
Jack Yu | f5badd9 | 2022-12-08 00:50:53 -0800 | [diff] [blame] | 12391 | * Get the SIM state for the slot index. |
| 12392 | * For Remote-SIMs, this method returns {@link IccCardConstants.State#UNKNOWN} |
| 12393 | * |
| 12394 | * @return SIM state as the ordinal of {@link IccCardConstants.State} |
| 12395 | */ |
| 12396 | @Override |
| 12397 | @SimState |
| 12398 | public int getSimStateForSlotIndex(int slotIndex) { |
| 12399 | IccCardConstants.State simState; |
| 12400 | if (slotIndex < 0) { |
| 12401 | simState = IccCardConstants.State.UNKNOWN; |
| 12402 | } else { |
| 12403 | Phone phone = null; |
| 12404 | try { |
| 12405 | phone = PhoneFactory.getPhone(slotIndex); |
| 12406 | } catch (IllegalStateException e) { |
| 12407 | // ignore |
| 12408 | } |
| 12409 | if (phone == null) { |
| 12410 | simState = IccCardConstants.State.UNKNOWN; |
| 12411 | } else { |
| 12412 | IccCard icc = phone.getIccCard(); |
| 12413 | if (icc == null) { |
| 12414 | simState = IccCardConstants.State.UNKNOWN; |
| 12415 | } else { |
| 12416 | simState = icc.getState(); |
| 12417 | } |
| 12418 | } |
| 12419 | } |
| 12420 | return simState.ordinal(); |
| 12421 | } |
Hui Wang | 9b5793a | 2022-12-05 14:38:06 -0600 | [diff] [blame] | 12422 | |
| 12423 | /** |
| 12424 | * Get current cell broadcast ranges. |
| 12425 | */ |
| 12426 | @Override |
| 12427 | @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS) |
| 12428 | public List<CellBroadcastIdRange> getCellBroadcastIdRanges(int subId) { |
| 12429 | mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS, |
| 12430 | "getCellBroadcastIdRanges"); |
| 12431 | final long identity = Binder.clearCallingIdentity(); |
| 12432 | try { |
| 12433 | return getPhone(subId).getCellBroadcastIdRanges(); |
| 12434 | } finally { |
| 12435 | Binder.restoreCallingIdentity(identity); |
| 12436 | } |
| 12437 | } |
| 12438 | |
| 12439 | /** |
| 12440 | * Set reception of cell broadcast messages with the list of the given ranges |
| 12441 | * |
| 12442 | * @param ranges the list of {@link CellBroadcastIdRange} to be enabled |
| 12443 | */ |
| 12444 | @Override |
| 12445 | @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS) |
| 12446 | public void setCellBroadcastIdRanges(int subId, @NonNull List<CellBroadcastIdRange> ranges, |
| 12447 | @Nullable IIntegerConsumer callback) { |
| 12448 | mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS, |
| 12449 | "setCellBroadcastIdRanges"); |
| 12450 | final long identity = Binder.clearCallingIdentity(); |
| 12451 | try { |
| 12452 | Phone phone = getPhoneFromSubId(subId); |
| 12453 | if (DBG) { |
| 12454 | log("setCellBroadcastIdRanges for subId :" + subId + ", phone:" + phone); |
| 12455 | } |
| 12456 | phone.setCellBroadcastIdRanges(ranges, result -> { |
| 12457 | if (callback != null) { |
| 12458 | try { |
| 12459 | callback.accept(result); |
| 12460 | } catch (RemoteException e) { |
| 12461 | Log.w(LOG_TAG, "setCellBroadcastIdRanges: callback not available."); |
| 12462 | } |
| 12463 | } |
| 12464 | }); |
| 12465 | } finally { |
| 12466 | Binder.restoreCallingIdentity(identity); |
| 12467 | } |
| 12468 | } |
Hunsuk Choi | 42cc62a | 2022-10-16 06:03:40 +0000 | [diff] [blame] | 12469 | |
| 12470 | /** |
| 12471 | * Returns whether the device supports the domain selection service. |
| 12472 | * |
| 12473 | * @return {@code true} if the device supports the domain selection service. |
| 12474 | */ |
| 12475 | @Override |
| 12476 | public boolean isDomainSelectionSupported() { |
| 12477 | mApp.enforceCallingOrSelfPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
| 12478 | "isDomainSelectionSupported"); |
| 12479 | |
| 12480 | final long identity = Binder.clearCallingIdentity(); |
| 12481 | try { |
| 12482 | return DomainSelectionResolver.getInstance().isDomainSelectionSupported(); |
| 12483 | } finally { |
| 12484 | Binder.restoreCallingIdentity(identity); |
| 12485 | } |
| 12486 | } |
arunvoddu | d5c6ce0 | 2022-12-11 06:03:12 +0000 | [diff] [blame] | 12487 | |
| 12488 | /** |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12489 | * Enable or disable the satellite modem. If the satellite modem is enabled, this will also |
| 12490 | * disable the cellular modem, and if the satellite modem is disabled, this will also re-enable |
| 12491 | * the cellular modem. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12492 | * |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12493 | * @param subId The subId to set satellite enabled for. |
| 12494 | * @param enable {@code true} to enable the satellite modem and {@code false} to disable. |
| 12495 | * @param callback The callback to get the error code of the request. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12496 | * |
| 12497 | * @throws SecurityException if the caller doesn't have the required permission. |
| 12498 | */ |
| 12499 | @Override |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12500 | public void setSatelliteEnabled(int subId, boolean enable, @NonNull IIntegerConsumer callback) { |
| 12501 | enforceSatelliteCommunicationPermission("setSatelliteEnabled"); |
| 12502 | Consumer<Integer> result = FunctionalUtils.ignoreRemoteException(callback::accept); |
Thomas Nguyen | e77de6d | 2023-02-10 17:42:43 -0800 | [diff] [blame] | 12503 | if (!isSatelliteSupported()) { |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12504 | result.accept(SatelliteManager.SATELLITE_NOT_SUPPORTED); |
| 12505 | return; |
Thomas Nguyen | e77de6d | 2023-02-10 17:42:43 -0800 | [diff] [blame] | 12506 | } |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12507 | |
| 12508 | final int validSubId = getValidSatelliteSubId(subId); |
Thomas Nguyen | e77de6d | 2023-02-10 17:42:43 -0800 | [diff] [blame] | 12509 | if (!isSatelliteProvisioned(validSubId)) { |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12510 | result.accept(SatelliteManager.SATELLITE_SERVICE_NOT_PROVISIONED); |
| 12511 | return; |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12512 | } |
| 12513 | |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12514 | Phone phone = getPhoneOrDefault(validSubId, "setSatelliteEnabled"); |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12515 | if (phone == null) { |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12516 | result.accept(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE); |
| 12517 | return; |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12518 | } |
| 12519 | |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12520 | Pair<Boolean, Consumer<Integer>> arg = new Pair<>(enable, result); |
| 12521 | sendRequestAsync(CMD_SET_SATELLITE_ENABLED, arg, phone, null); |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12522 | } |
| 12523 | |
| 12524 | /** |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12525 | * Request to get whether the satellite modem is enabled. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12526 | * |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12527 | * @param subId The subId to check whether satellite is enabled for. |
| 12528 | * @param result The result receiver that returns whether the satellite modem is enabled |
| 12529 | * 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] | 12530 | * |
| 12531 | * @throws SecurityException if the caller doesn't have the required permission. |
| 12532 | */ |
| 12533 | @Override |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12534 | public void requestIsSatelliteEnabled(int subId, @NonNull ResultReceiver result) { |
| 12535 | enforceSatelliteCommunicationPermission("requestIsSatelliteEnabled"); |
Thomas Nguyen | e77de6d | 2023-02-10 17:42:43 -0800 | [diff] [blame] | 12536 | if (!isSatelliteSupported()) { |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12537 | result.send(SatelliteManager.SATELLITE_NOT_SUPPORTED, null); |
| 12538 | return; |
Thomas Nguyen | e77de6d | 2023-02-10 17:42:43 -0800 | [diff] [blame] | 12539 | } |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12540 | |
| 12541 | final int validSubId = getValidSatelliteSubId(subId); |
Thomas Nguyen | e77de6d | 2023-02-10 17:42:43 -0800 | [diff] [blame] | 12542 | if (!isSatelliteProvisioned(validSubId)) { |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12543 | result.send(SatelliteManager.SATELLITE_SERVICE_NOT_PROVISIONED, null); |
| 12544 | return; |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12545 | } |
| 12546 | |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12547 | Phone phone = getPhoneOrDefault(validSubId, "requestIsSatelliteEnabled"); |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12548 | if (phone == null) { |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12549 | result.send(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE, null); |
| 12550 | return; |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12551 | } |
| 12552 | |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12553 | sendRequest(CMD_IS_SATELLITE_ENABLED, result, subId); |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12554 | } |
| 12555 | |
| 12556 | /** |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12557 | * Request to get whether the satellite service is supported on the device. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12558 | * |
| 12559 | * @param subId The subId to check satellite service support for. |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12560 | * @param result The result receiver that returns whether the satellite service is supported on |
| 12561 | * 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] | 12562 | */ |
| 12563 | @Override |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12564 | public void requestIsSatelliteSupported(int subId, @NonNull ResultReceiver result) { |
Thomas Nguyen | e77de6d | 2023-02-10 17:42:43 -0800 | [diff] [blame] | 12565 | synchronized (mIsSatelliteSupportedLock) { |
| 12566 | if (mIsSatelliteSupported != null) { |
| 12567 | /* We have already successfully queried the satellite modem. */ |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12568 | Bundle bundle = new Bundle(); |
| 12569 | bundle.putBoolean(SatelliteManager.KEY_SATELLITE_SUPPORTED, mIsSatelliteSupported); |
| 12570 | result.send(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE, bundle); |
| 12571 | return; |
Thomas Nguyen | e77de6d | 2023-02-10 17:42:43 -0800 | [diff] [blame] | 12572 | } |
| 12573 | } |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12574 | |
| 12575 | final int validSubId = getValidSatelliteSubId(subId); |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12576 | Phone phone = getPhoneOrDefault(validSubId, "requestIsSatelliteSupported"); |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12577 | if (phone == null) { |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12578 | result.send(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE, null); |
| 12579 | return; |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12580 | } |
| 12581 | |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12582 | sendRequestAsync(CMD_IS_SATELLITE_SUPPORTED, result, phone, null); |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12583 | } |
| 12584 | |
| 12585 | /** |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12586 | * Request to get the {@link SatelliteCapabilities} of the satellite service. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12587 | * |
| 12588 | * @param subId The subId to get the satellite capabilities for. |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12589 | * @param result The result receiver that returns the {@link SatelliteCapabilities} |
| 12590 | * 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] | 12591 | * |
| 12592 | * @throws SecurityException if the caller doesn't have required permission. |
| 12593 | */ |
| 12594 | @Override |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12595 | public void requestSatelliteCapabilities(int subId, @NonNull ResultReceiver result) { |
| 12596 | enforceSatelliteCommunicationPermission("requestSatelliteCapabilities"); |
Thomas Nguyen | e77de6d | 2023-02-10 17:42:43 -0800 | [diff] [blame] | 12597 | if (!isSatelliteSupported()) { |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12598 | result.send(SatelliteManager.SATELLITE_NOT_SUPPORTED, null); |
| 12599 | return; |
Thomas Nguyen | e77de6d | 2023-02-10 17:42:43 -0800 | [diff] [blame] | 12600 | } |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12601 | |
| 12602 | final int validSubId = getValidSatelliteSubId(subId); |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12603 | Phone phone = getPhoneOrDefault(validSubId, "requestSatelliteCapabilities"); |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12604 | if (phone == null) { |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12605 | result.send(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE, null); |
| 12606 | return; |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12607 | } |
| 12608 | |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12609 | sendRequestAsync(CMD_GET_SATELLITE_CAPABILITIES, result, phone, null); |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12610 | } |
| 12611 | |
| 12612 | /** |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 12613 | * Start receiving satellite position updates. |
| 12614 | * This can be called by the pointing UI when the user starts pointing to the satellite. |
| 12615 | * Modem should continue to report the pointing input as the device or satellite moves. |
| 12616 | * |
| 12617 | * @param subId The subId to start satellite position updates for. |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12618 | * @param errorCallback The callback to get the error code of the request. |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 12619 | * @param callback The callback to notify of changes in satellite position. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12620 | * |
| 12621 | * @throws SecurityException if the caller doesn't have the required permission. |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 12622 | */ |
| 12623 | @Override |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12624 | public void startSatellitePositionUpdates(int subId, @NonNull IIntegerConsumer errorCallback, |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12625 | @NonNull ISatelliteStateListener callback) { |
Sarah Chin | f75afa7 | 2023-02-01 01:32:19 -0800 | [diff] [blame] | 12626 | enforceSatelliteCommunicationPermission("startSatellitePositionUpdates"); |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12627 | Consumer<Integer> result = FunctionalUtils.ignoreRemoteException(errorCallback::accept); |
Thomas Nguyen | e77de6d | 2023-02-10 17:42:43 -0800 | [diff] [blame] | 12628 | if (!isSatelliteSupported()) { |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12629 | result.accept(SatelliteManager.SATELLITE_NOT_SUPPORTED); |
| 12630 | return; |
Thomas Nguyen | e77de6d | 2023-02-10 17:42:43 -0800 | [diff] [blame] | 12631 | } |
Sarah Chin | f75afa7 | 2023-02-01 01:32:19 -0800 | [diff] [blame] | 12632 | |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12633 | final int validSubId = getValidSatelliteSubId(subId); |
Thomas Nguyen | e77de6d | 2023-02-10 17:42:43 -0800 | [diff] [blame] | 12634 | if (!isSatelliteProvisioned(validSubId)) { |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12635 | result.accept(SatelliteManager.SATELLITE_SERVICE_NOT_PROVISIONED); |
| 12636 | return; |
Sarah Chin | f75afa7 | 2023-02-01 01:32:19 -0800 | [diff] [blame] | 12637 | } |
| 12638 | |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12639 | Phone phone = getPhoneOrDefault(validSubId, "startSatellitePositionUpdates"); |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 12640 | if (phone == null) { |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12641 | result.accept(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE); |
| 12642 | return; |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 12643 | } |
| 12644 | |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12645 | if (mSatellitePositionUpdateHandlers.containsKey(callback.asBinder())) { |
Thomas Nguyen | e77de6d | 2023-02-10 17:42:43 -0800 | [diff] [blame] | 12646 | if (DBG) { |
| 12647 | log("startSatellitePositionUpdates: callback already registered: " |
| 12648 | + callback.asBinder()); |
| 12649 | } |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12650 | result.accept(SatelliteManager.SATELLITE_ERROR_NONE); |
| 12651 | return; |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 12652 | } |
| 12653 | |
| 12654 | SatellitePositionUpdateHandler handler = |
| 12655 | new SatellitePositionUpdateHandler(callback, Looper.getMainLooper()); |
| 12656 | phone.registerForSatellitePointingInfoChanged(handler, |
| 12657 | SatellitePositionUpdateHandler.EVENT_POSITION_UPDATE, null); |
| 12658 | phone.registerForSatelliteMessagesTransferComplete(handler, |
| 12659 | SatellitePositionUpdateHandler.EVENT_MESSAGE_TRANSFER_STATE_UPDATE, null); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12660 | mSatellitePositionUpdateHandlers.put(callback.asBinder(), handler); |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 12661 | |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12662 | sendRequestAsync(CMD_START_SATELLITE_POSITION_UPDATES, result, phone, null); |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 12663 | } |
| 12664 | |
| 12665 | /** |
| 12666 | * Stop receiving satellite position updates. |
| 12667 | * This can be called by the pointing UI when the user stops pointing to the satellite. |
| 12668 | * |
| 12669 | * @param subId The subId to stop satellite position updates for. |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12670 | * @param errorCallback The callback to get the error code of the request. |
| 12671 | * @param callback The callback that was passed to {@link |
| 12672 | * #startSatellitePositionUpdates(int, IIntegerConsumer, ISatelliteStateListener)} |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12673 | * |
| 12674 | * @throws SecurityException if the caller doesn't have the required permission. |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 12675 | */ |
| 12676 | @Override |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12677 | public void stopSatellitePositionUpdates(int subId, @NonNull IIntegerConsumer errorCallback, |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12678 | @NonNull ISatelliteStateListener callback) { |
Sarah Chin | f75afa7 | 2023-02-01 01:32:19 -0800 | [diff] [blame] | 12679 | enforceSatelliteCommunicationPermission("stopSatellitePositionUpdates"); |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12680 | Consumer<Integer> result = FunctionalUtils.ignoreRemoteException(errorCallback::accept); |
Thomas Nguyen | e77de6d | 2023-02-10 17:42:43 -0800 | [diff] [blame] | 12681 | if (!isSatelliteSupported()) { |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12682 | result.accept(SatelliteManager.SATELLITE_NOT_SUPPORTED); |
| 12683 | return; |
Thomas Nguyen | e77de6d | 2023-02-10 17:42:43 -0800 | [diff] [blame] | 12684 | } |
Sarah Chin | f75afa7 | 2023-02-01 01:32:19 -0800 | [diff] [blame] | 12685 | |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12686 | final int validSubId = getValidSatelliteSubId(subId); |
Thomas Nguyen | e77de6d | 2023-02-10 17:42:43 -0800 | [diff] [blame] | 12687 | if (!isSatelliteProvisioned(validSubId)) { |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12688 | result.accept(SatelliteManager.SATELLITE_SERVICE_NOT_PROVISIONED); |
| 12689 | return; |
Sarah Chin | f75afa7 | 2023-02-01 01:32:19 -0800 | [diff] [blame] | 12690 | } |
| 12691 | |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12692 | Phone phone = getPhoneOrDefault(validSubId, "stopSatellitePositionUpdates"); |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 12693 | if (phone == null) { |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12694 | result.accept(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE); |
| 12695 | return; |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 12696 | } |
| 12697 | |
| 12698 | SatellitePositionUpdateHandler handler = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12699 | mSatellitePositionUpdateHandlers.remove(callback.asBinder()); |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 12700 | if (handler == null) { |
| 12701 | loge("stopSatellitePositionUpdates: No SatellitePositionArgument"); |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12702 | result.accept(SatelliteManager.SATELLITE_INVALID_ARGUMENTS); |
| 12703 | return; |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 12704 | } else { |
| 12705 | phone.unregisterForSatellitePointingInfoChanged(handler); |
| 12706 | phone.unregisterForSatelliteMessagesTransferComplete(handler); |
| 12707 | } |
| 12708 | |
| 12709 | if (!mSatellitePositionUpdateHandlers.isEmpty()) { |
| 12710 | log("stopSatellitePositionUpdates: other listeners still exist."); |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12711 | result.accept(SatelliteManager.SATELLITE_ERROR_NONE); |
| 12712 | return; |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 12713 | } |
| 12714 | |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12715 | sendRequestAsync(CMD_STOP_SATELLITE_POSITION_UPDATES, result, phone, null); |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 12716 | } |
| 12717 | |
| 12718 | /** |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12719 | * Request to get the maximum number of characters per text message on satellite. |
| 12720 | * |
| 12721 | * @param subId The subId of the subscription. |
| 12722 | * @param result The result receiver that returns the maximum number of characters per text |
| 12723 | * message on satellite if the request is successful or an error code |
| 12724 | * if the request failed. |
Aishwarya Mallampati | 60fe113 | 2023-01-24 19:07:21 +0000 | [diff] [blame] | 12725 | * |
| 12726 | * @throws SecurityException if the caller doesn't have the required permission. |
| 12727 | */ |
| 12728 | @Override |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12729 | public void requestMaxCharactersPerSatelliteTextMessage(int subId, |
| 12730 | @NonNull ResultReceiver result) { |
| 12731 | enforceSatelliteCommunicationPermission("requestMaxCharactersPerSatelliteTextMessage"); |
Thomas Nguyen | e77de6d | 2023-02-10 17:42:43 -0800 | [diff] [blame] | 12732 | if (!isSatelliteSupported()) { |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12733 | result.send(SatelliteManager.SATELLITE_NOT_SUPPORTED, null); |
| 12734 | return; |
Thomas Nguyen | e77de6d | 2023-02-10 17:42:43 -0800 | [diff] [blame] | 12735 | } |
Aishwarya Mallampati | 60fe113 | 2023-01-24 19:07:21 +0000 | [diff] [blame] | 12736 | |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12737 | final int validSubId = getValidSatelliteSubId(subId); |
Thomas Nguyen | e77de6d | 2023-02-10 17:42:43 -0800 | [diff] [blame] | 12738 | if (!isSatelliteProvisioned(validSubId)) { |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12739 | result.send(SatelliteManager.SATELLITE_SERVICE_NOT_PROVISIONED, null); |
| 12740 | return; |
Aishwarya Mallampati | 60fe113 | 2023-01-24 19:07:21 +0000 | [diff] [blame] | 12741 | } |
| 12742 | |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12743 | Phone phone = getPhoneOrDefault(validSubId, "requestMaxCharactersPerSatelliteTextMessage"); |
Aishwarya Mallampati | 60fe113 | 2023-01-24 19:07:21 +0000 | [diff] [blame] | 12744 | if (phone == null) { |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12745 | result.send(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE, null); |
| 12746 | return; |
Aishwarya Mallampati | 60fe113 | 2023-01-24 19:07:21 +0000 | [diff] [blame] | 12747 | } |
| 12748 | |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12749 | sendRequestAsync(CMD_GET_MAX_CHAR_PER_SATELLITE_TEXT_MSG, result, phone, null); |
Aishwarya Mallampati | 60fe113 | 2023-01-24 19:07:21 +0000 | [diff] [blame] | 12750 | } |
| 12751 | |
| 12752 | /** |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12753 | * Register the subscription with a satellite provider. |
| 12754 | * This is needed to register the subscription if the provider allows dynamic registration. |
| 12755 | * |
| 12756 | * @param subId The subId of the subscription to be provisioned. |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame^] | 12757 | * @param token The token to be used as a unique identifier for provisioning with satellite |
| 12758 | * gateway. |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12759 | * @param callback The callback to get the error code of the request. |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12760 | * @return The signal transport used by the caller to cancel the provision request, |
| 12761 | * or {@code null} if the request failed. |
| 12762 | * |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12763 | * @throws SecurityException if the caller doesn't have the required permission. |
| 12764 | */ |
| 12765 | @Override |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12766 | @Nullable public ICancellationSignal provisionSatelliteService(int subId, |
| 12767 | @NonNull String token, @NonNull IIntegerConsumer callback) { |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12768 | enforceSatelliteCommunicationPermission("provisionSatelliteService"); |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12769 | Consumer<Integer> result = FunctionalUtils.ignoreRemoteException(callback::accept); |
Thomas Nguyen | e77de6d | 2023-02-10 17:42:43 -0800 | [diff] [blame] | 12770 | if (!isSatelliteSupported()) { |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12771 | result.accept(SatelliteManager.SATELLITE_NOT_SUPPORTED); |
Thomas Nguyen | e77de6d | 2023-02-10 17:42:43 -0800 | [diff] [blame] | 12772 | return null; |
| 12773 | } |
| 12774 | |
| 12775 | final int validSubId = getValidSatelliteSubId(subId); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12776 | Phone phone = getPhoneOrDefault(validSubId, "provisionSatelliteService"); |
| 12777 | if (phone == null) { |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12778 | result.accept(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12779 | return null; |
| 12780 | } |
| 12781 | |
| 12782 | if (mSatelliteProvisionCallbacks.containsKey(validSubId)) { |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12783 | result.accept(SatelliteManager.SATELLITE_SERVICE_PROVISION_IN_PROGRESS); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12784 | return null; |
| 12785 | } |
| 12786 | |
Thomas Nguyen | e77de6d | 2023-02-10 17:42:43 -0800 | [diff] [blame] | 12787 | if (isSatelliteProvisioned(validSubId)) { |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12788 | result.accept(SatelliteManager.SATELLITE_ERROR_NONE); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12789 | return null; |
| 12790 | } |
| 12791 | |
| 12792 | sendRequestAsync(CMD_PROVISION_SATELLITE_SERVICE, |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12793 | new ProvisionSatelliteServiceArgument(token, result, validSubId), phone, null); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12794 | |
| 12795 | ICancellationSignal cancelTransport = CancellationSignal.createTransport(); |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame^] | 12796 | CancellationSignal.fromTransport(cancelTransport).setOnCancelListener(() -> { |
| 12797 | sendRequestAsync(CMD_DEPROVISION_SATELLITE_SERVICE, |
| 12798 | new ProvisionSatelliteServiceArgument(token, null, validSubId), |
| 12799 | phone, null); |
| 12800 | }); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12801 | return cancelTransport; |
| 12802 | } |
| 12803 | |
| 12804 | /** |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame^] | 12805 | * Unregister the device/subscription with the satellite provider. |
| 12806 | * This is needed if the provider allows dynamic registration. Once deprovisioned, |
| 12807 | * {@link SatelliteCallback.SatelliteProvisionStateListener#onSatelliteProvisionStateChanged} |
| 12808 | * should report as deprovisioned. |
| 12809 | * |
| 12810 | * @param subId The subId of the subscription to be deprovisioned. |
| 12811 | * @param token The token of the device/subscription to be deprovisioned. |
| 12812 | * @param callback The callback to get the error code of the request. |
| 12813 | * |
| 12814 | * @throws SecurityException if the caller doesn't have the required permission. |
| 12815 | */ |
| 12816 | @Override |
| 12817 | public void deprovisionSatelliteService(int subId, |
| 12818 | @NonNull String token, @NonNull IIntegerConsumer callback) { |
| 12819 | enforceSatelliteCommunicationPermission("deprovisionSatelliteService"); |
| 12820 | Consumer<Integer> result = FunctionalUtils.ignoreRemoteException(callback::accept); |
| 12821 | if (!isSatelliteSupported()) { |
| 12822 | result.accept(SatelliteManager.SATELLITE_NOT_SUPPORTED); |
| 12823 | return; |
| 12824 | } |
| 12825 | |
| 12826 | final int validSubId = getValidSatelliteSubId(subId); |
| 12827 | if (!isSatelliteProvisioned(validSubId)) { |
| 12828 | result.accept(SatelliteManager.SATELLITE_ERROR_NONE); |
| 12829 | return; |
| 12830 | } |
| 12831 | |
| 12832 | Phone phone = getPhoneOrDefault(validSubId, "deprovisionSatelliteService"); |
| 12833 | if (phone == null) { |
| 12834 | result.accept(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE); |
| 12835 | return; |
| 12836 | } |
| 12837 | |
| 12838 | sendRequestAsync(CMD_DEPROVISION_SATELLITE_SERVICE, |
| 12839 | new ProvisionSatelliteServiceArgument(token, result, validSubId), phone, null); |
| 12840 | } |
| 12841 | |
| 12842 | /** |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12843 | * Register for the satellite provision state change. |
| 12844 | * |
| 12845 | * @param subId The subId of the subscription associated with the satellite service. |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12846 | * @param errorCallback The callback to get the error code of the request. |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12847 | * @param callback The callback to handle the satellite provision state changed event. |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12848 | * |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12849 | * @throws SecurityException if the caller doesn't have the required permission. |
| 12850 | */ |
| 12851 | @Override |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12852 | public void registerForSatelliteProvisionStateChanged(int subId, |
| 12853 | @NonNull IIntegerConsumer errorCallback, @NonNull ISatelliteStateListener callback) { |
Thomas Nguyen | e77de6d | 2023-02-10 17:42:43 -0800 | [diff] [blame] | 12854 | enforceSatelliteCommunicationPermission("registerForSatelliteProvisionStateChanged"); |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame^] | 12855 | registerForSatelliteProvisionStateChangedInternal(subId, errorCallback, callback); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12856 | } |
| 12857 | |
| 12858 | /** |
| 12859 | * Unregister for the satellite provision state change. |
| 12860 | * |
| 12861 | * @param subId The subId of the subscription associated with the satellite service. |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12862 | * @param errorCallback The callback to get the error code of the request. |
| 12863 | * @param callback The callback that was passed to {@link |
| 12864 | * #registerForSatelliteProvisionStateChanged(int, IIntegerConsumer, ISatelliteStateListener)}. |
| 12865 | * |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12866 | * @throws SecurityException if the caller doesn't have the required permission. |
| 12867 | */ |
| 12868 | @Override |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12869 | public void unregisterForSatelliteProvisionStateChanged(int subId, |
| 12870 | @NonNull IIntegerConsumer errorCallback, @NonNull ISatelliteStateListener callback) { |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12871 | enforceSatelliteCommunicationPermission("unregisterForSatelliteProvisionStateChanged"); |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12872 | Consumer<Integer> result = FunctionalUtils.ignoreRemoteException(errorCallback::accept); |
Thomas Nguyen | e77de6d | 2023-02-10 17:42:43 -0800 | [diff] [blame] | 12873 | if (!isSatelliteSupported()) { |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12874 | result.accept(SatelliteManager.SATELLITE_NOT_SUPPORTED); |
| 12875 | return; |
Thomas Nguyen | e77de6d | 2023-02-10 17:42:43 -0800 | [diff] [blame] | 12876 | } |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12877 | |
| 12878 | final int validSubId = getValidSatelliteSubId(subId); |
| 12879 | SatelliteProvisionStateChangedHandler satelliteProvisionStateChangedHandler = |
| 12880 | mSatelliteProvisionStateChangedHandlers.get(validSubId); |
| 12881 | if (satelliteProvisionStateChangedHandler != null) { |
| 12882 | if (satelliteProvisionStateChangedHandler.removeListener(callback)) { |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12883 | result.accept(SatelliteManager.SATELLITE_ERROR_NONE); |
| 12884 | return; |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12885 | } |
| 12886 | } |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12887 | result.accept(SatelliteManager.SATELLITE_INVALID_ARGUMENTS); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12888 | } |
| 12889 | |
| 12890 | /** |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12891 | * Request to get whether the device is provisioned with a satellite provider. |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12892 | * |
| 12893 | * @param subId The subId of the subscription associated with the satellite service. |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12894 | * @param result The result receiver that returns whether the device is provisioned with a |
| 12895 | * satellite provider if the request is successful or an error code if the |
| 12896 | * request failed. |
| 12897 | * |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12898 | * @throws SecurityException if the caller doesn't have the required permission. |
| 12899 | */ |
| 12900 | @Override |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12901 | public void requestIsSatelliteProvisioned(int subId, @NonNull ResultReceiver result) { |
| 12902 | enforceSatelliteCommunicationPermission("requestIsSatelliteProvisioned"); |
Thomas Nguyen | e77de6d | 2023-02-10 17:42:43 -0800 | [diff] [blame] | 12903 | if (!isSatelliteSupported()) { |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12904 | result.send(SatelliteManager.SATELLITE_NOT_SUPPORTED, null); |
| 12905 | return; |
Thomas Nguyen | e77de6d | 2023-02-10 17:42:43 -0800 | [diff] [blame] | 12906 | } |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12907 | |
| 12908 | final int validSubId = getValidSatelliteSubId(subId); |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12909 | Bundle bundle = new Bundle(); |
| 12910 | bundle.putBoolean(SatelliteManager.KEY_SATELLITE_PROVISIONED, |
| 12911 | isSatelliteProvisioned(validSubId)); |
| 12912 | result.send(SatelliteManager.SATELLITE_ERROR_NONE, bundle); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12913 | } |
| 12914 | |
| 12915 | private void handleCmdProvisionSatelliteService(@NonNull ProvisionSatelliteServiceArgument arg, |
| 12916 | @NonNull Phone phone, Message onCompleted) { |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12917 | if (!mSatelliteProvisionCallbacks.containsKey(arg.subId)) { |
| 12918 | mSatelliteProvisionCallbacks.put(arg.subId, arg.callback); |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame^] | 12919 | phone.provisionSatelliteService(onCompleted, arg.token); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12920 | } else { |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12921 | arg.callback.accept(SatelliteManager.SATELLITE_SERVICE_PROVISION_IN_PROGRESS); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12922 | } |
| 12923 | } |
| 12924 | |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame^] | 12925 | private void handleEventProvisionSatelliteServiceDone( |
| 12926 | @NonNull ProvisionSatelliteServiceArgument arg, |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12927 | @SatelliteManager.SatelliteError int result) { |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame^] | 12928 | log("handleEventProvisionSatelliteServiceDone: result=" |
| 12929 | + result + ", subId=" + arg.subId); |
| 12930 | |
| 12931 | Consumer<Integer> callback = mSatelliteProvisionCallbacks.remove(arg.subId); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12932 | if (callback == null) { |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame^] | 12933 | loge("handleEventProvisionSatelliteServiceDone: callback is null for subId=" |
| 12934 | + arg.subId); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12935 | return; |
| 12936 | } |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12937 | callback.accept(result); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12938 | |
Thomas Nguyen | e77de6d | 2023-02-10 17:42:43 -0800 | [diff] [blame] | 12939 | if (result == SatelliteManager.SATELLITE_ERROR_NONE) { |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame^] | 12940 | setSatelliteProvisioned(arg.subId, true); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12941 | } |
| 12942 | |
| 12943 | /** |
| 12944 | * We need to update satellite provision status in SubscriptionController |
| 12945 | * or SatelliteController. |
| 12946 | * TODO (b/267826133) we need to do this for all subscriptions on the device. |
| 12947 | */ |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame^] | 12948 | registerForSatelliteProvisionStateChangedInternal(arg.subId, null, null); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12949 | } |
| 12950 | |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame^] | 12951 | private void handleCmdDeprovisionSatelliteService( |
| 12952 | @NonNull ProvisionSatelliteServiceArgument arg, |
| 12953 | @NonNull Phone phone, Message onCompleted) { |
| 12954 | if (arg == null) { |
| 12955 | loge("handleCmdDeprovisionSatelliteService: arg is null"); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12956 | return; |
| 12957 | } |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame^] | 12958 | if (phone == null) { |
| 12959 | loge("handleCmdDeprovisionSatelliteService: phone is null"); |
| 12960 | if (arg.callback != null) { |
| 12961 | arg.callback.accept(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE); |
| 12962 | } |
| 12963 | return; |
| 12964 | } |
| 12965 | phone.deprovisionSatelliteService(onCompleted, arg.token); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12966 | } |
| 12967 | |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame^] | 12968 | private void handleEventDeprovisionSatelliteServiceDone( |
| 12969 | @NonNull ProvisionSatelliteServiceArgument arg, |
| 12970 | @SatelliteManager.SatelliteError int result) { |
| 12971 | if (arg == null) { |
| 12972 | loge("handleEventDeprovisionSatelliteServiceDone: arg is null"); |
| 12973 | return; |
| 12974 | } |
| 12975 | log("handleEventDeprovisionSatelliteServiceDone: result=" |
| 12976 | + result + ", subId=" + arg.subId); |
| 12977 | |
| 12978 | if (arg.callback != null) { |
| 12979 | arg.callback.accept(result); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12980 | } |
| 12981 | |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame^] | 12982 | if (result == SatelliteManager.SATELLITE_ERROR_NONE) { |
| 12983 | setSatelliteProvisioned(arg.subId, false); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12984 | } |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12985 | } |
| 12986 | |
| 12987 | private Phone getPhoneOrDefault(int subId, String caller) { |
| 12988 | Phone phone = getPhone(subId); |
| 12989 | if (phone == null) { |
| 12990 | loge(caller + " called with invalid subId: " + subId |
| 12991 | + ". Retrying with default phone."); |
| 12992 | phone = getDefaultPhone(); |
| 12993 | if (phone == null) { |
| 12994 | loge(caller + " failed with no phone object."); |
| 12995 | } |
| 12996 | } |
| 12997 | return phone; |
| 12998 | } |
| 12999 | |
| 13000 | /** |
Thomas Nguyen | e77de6d | 2023-02-10 17:42:43 -0800 | [diff] [blame] | 13001 | * Check if satellite is provisioned for a subscription or the device. |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13002 | * |
| 13003 | * Note: this is the version without permission check for telephony internal use only. The |
| 13004 | * caller need to take care of the permission check. |
| 13005 | */ |
Thomas Nguyen | e77de6d | 2023-02-10 17:42:43 -0800 | [diff] [blame] | 13006 | private boolean isSatelliteProvisioned(int subId) { |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13007 | if (subId != SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) { |
| 13008 | if (mSubscriptionController == null) { |
Thomas Nguyen | e77de6d | 2023-02-10 17:42:43 -0800 | [diff] [blame] | 13009 | loge("isSatelliteProvisioned mSubscriptionController is null"); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13010 | return false; |
| 13011 | } |
| 13012 | |
| 13013 | String strResult = mSubscriptionController.getSubscriptionProperty( |
| 13014 | subId, SubscriptionManager.SATELLITE_ENABLED); |
| 13015 | if (strResult != null) { |
| 13016 | int intResult = Integer.parseInt(strResult); |
| 13017 | return (intResult == 1) ? true : false; |
| 13018 | } |
| 13019 | } else { |
| 13020 | //TODO (b/267826133): check via SatelliteController |
| 13021 | } |
| 13022 | return false; |
| 13023 | } |
| 13024 | |
| 13025 | /** |
Thomas Nguyen | e77de6d | 2023-02-10 17:42:43 -0800 | [diff] [blame] | 13026 | * Set satellite provisioned for a subscription or the device. |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13027 | * |
| 13028 | * The permission {@link android.Manifest.permission#MODIFY_PHONE_STATE} will be enforced by |
| 13029 | * {@link SubscriptionController} when setting satellite enabled for an active subscription. |
| 13030 | * Otherwise, {@link android.Manifest.permission#SATELLITE_COMMUNICATION} will be enforced. |
| 13031 | */ |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame^] | 13032 | private synchronized void setSatelliteProvisioned(int subId, boolean isEnabled) { |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13033 | if (subId != SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) { |
| 13034 | if (mSubscriptionController == null) { |
Thomas Nguyen | e77de6d | 2023-02-10 17:42:43 -0800 | [diff] [blame] | 13035 | loge("setSatelliteProvisioned mSubscriptionController is null"); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13036 | return; |
| 13037 | } |
| 13038 | mSubscriptionController.setSubscriptionProperty( |
| 13039 | subId, SubscriptionManager.SATELLITE_ENABLED, isEnabled ? "1" : "0"); |
| 13040 | } else { |
Thomas Nguyen | e77de6d | 2023-02-10 17:42:43 -0800 | [diff] [blame] | 13041 | //TODO (b/267826133): set via SatelliteController |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13042 | } |
| 13043 | } |
| 13044 | |
| 13045 | private int getValidSatelliteSubId(int subId) { |
| 13046 | if (mSubscriptionController == null) { |
| 13047 | loge("getValidSatelliteSubId mSubscriptionController is null. " |
| 13048 | + "Use DEFAULT_SUBSCRIPTION_ID for subId=" + subId); |
| 13049 | return SubscriptionManager.DEFAULT_SUBSCRIPTION_ID; |
| 13050 | } |
| 13051 | final long identity = Binder.clearCallingIdentity(); |
| 13052 | try { |
| 13053 | Context context = getDefaultPhone().getContext(); |
| 13054 | if (mSubscriptionController.isActiveSubId( |
| 13055 | subId, context.getOpPackageName(), context.getAttributionTag())) { |
| 13056 | return subId; |
| 13057 | } |
| 13058 | } finally { |
| 13059 | Binder.restoreCallingIdentity(identity); |
| 13060 | } |
| 13061 | if (DBG) log("getValidSatelliteSubId: use DEFAULT_SUBSCRIPTION_ID for subId=" + subId); |
| 13062 | return SubscriptionManager.DEFAULT_SUBSCRIPTION_ID; |
| 13063 | } |
| 13064 | |
| 13065 | /** |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13066 | * If we have not successfully queried the satellite modem for its satellite service support, |
| 13067 | * we will retry the query one more time. Otherwise, we will return the queried result. |
Thomas Nguyen | e77de6d | 2023-02-10 17:42:43 -0800 | [diff] [blame] | 13068 | */ |
| 13069 | private boolean isSatelliteSupported() { |
| 13070 | synchronized (mIsSatelliteSupportedLock) { |
| 13071 | if (mIsSatelliteSupported != null) { |
| 13072 | /* We have already successfully queried the satellite modem. */ |
| 13073 | return mIsSatelliteSupported; |
| 13074 | } |
| 13075 | } |
| 13076 | /** |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13077 | * We have not successfully checked whether the modem supports satellite service. |
| 13078 | * Thus, we need to retry it now. |
Thomas Nguyen | e77de6d | 2023-02-10 17:42:43 -0800 | [diff] [blame] | 13079 | */ |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13080 | requestIsSatelliteSupported(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, |
| 13081 | mSatelliteSupportedReceiver); |
| 13082 | return false; |
| 13083 | } |
| 13084 | |
| 13085 | /** |
| 13086 | * Get the {@link SatelliteManager.SatelliteError} from the provided result. |
| 13087 | * @param ar AsyncResult used to determine the error code. |
| 13088 | * @param caller The satellite request. |
| 13089 | * @param checkResult Whether to check if the result exists. |
| 13090 | * @return The {@link SatelliteManager.SatelliteError} error code from the request. |
| 13091 | */ |
| 13092 | @SatelliteManager.SatelliteError private int getSatelliteError(@NonNull AsyncResult ar, |
| 13093 | @NonNull String caller, boolean checkResult) { |
| 13094 | int errorCode; |
| 13095 | if (ar.exception == null) { |
| 13096 | errorCode = SatelliteManager.SATELLITE_ERROR_NONE; |
| 13097 | if (checkResult && ar.result == null) { |
| 13098 | loge(caller + ": result is null"); |
| 13099 | errorCode = SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE; |
| 13100 | } |
| 13101 | } else { |
| 13102 | errorCode = SatelliteManager.SATELLITE_ERROR; |
| 13103 | if (ar.exception instanceof CommandException) { |
| 13104 | CommandException.Error error = |
| 13105 | ((CommandException) (ar.exception)).getCommandError(); |
| 13106 | errorCode = RILUtils.convertToSatelliteError(error); |
| 13107 | loge(caller + " CommandException: " + ar.exception); |
| 13108 | } else { |
| 13109 | loge(caller + " unknown exception: " + ar.exception); |
Thomas Nguyen | e77de6d | 2023-02-10 17:42:43 -0800 | [diff] [blame] | 13110 | } |
| 13111 | } |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13112 | log(caller + " error: " + errorCode); |
| 13113 | return errorCode; |
Thomas Nguyen | e77de6d | 2023-02-10 17:42:43 -0800 | [diff] [blame] | 13114 | } |
| 13115 | |
| 13116 | /** |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame^] | 13117 | * Register for the satellite provision state change. |
| 13118 | * |
| 13119 | * @param subId The subId of the subscription associated with the satellite service. |
| 13120 | * @param errorCallback The callback to get the error code of the request. |
| 13121 | * @param callback The callback to handle the satellite provision state changed event. |
| 13122 | */ |
| 13123 | private void registerForSatelliteProvisionStateChangedInternal(int subId, |
| 13124 | @Nullable IIntegerConsumer errorCallback, @Nullable ISatelliteStateListener callback) { |
| 13125 | Consumer<Integer> result = null; |
| 13126 | if (errorCallback != null) { |
| 13127 | result = FunctionalUtils.ignoreRemoteException(errorCallback::accept); |
| 13128 | } |
| 13129 | if (!isSatelliteSupported()) { |
| 13130 | if (result != null) { |
| 13131 | result.accept(SatelliteManager.SATELLITE_NOT_SUPPORTED); |
| 13132 | } |
| 13133 | return; |
| 13134 | } |
| 13135 | |
| 13136 | final int validSubId = getValidSatelliteSubId(subId); |
| 13137 | Phone phone = getPhoneOrDefault(validSubId, "registerForSatelliteProvisionStateChanged"); |
| 13138 | if (phone == null) { |
| 13139 | if (result != null) { |
| 13140 | result.accept(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE); |
| 13141 | } |
| 13142 | return; |
| 13143 | } |
| 13144 | |
| 13145 | SatelliteProvisionStateChangedHandler satelliteProvisionStateChangedHandler = |
| 13146 | mSatelliteProvisionStateChangedHandlers.get(validSubId); |
| 13147 | if (satelliteProvisionStateChangedHandler == null) { |
| 13148 | satelliteProvisionStateChangedHandler = new SatelliteProvisionStateChangedHandler( |
| 13149 | Looper.getMainLooper(), validSubId); |
| 13150 | phone.registerForSatelliteProvisionStateChanged(satelliteProvisionStateChangedHandler, |
| 13151 | SatelliteProvisionStateChangedHandler.EVENT_PROVISION_STATE_CHANGED, null); |
| 13152 | } |
| 13153 | |
| 13154 | if (callback != null) { |
| 13155 | satelliteProvisionStateChangedHandler.addListener(callback); |
| 13156 | } |
| 13157 | mSatelliteProvisionStateChangedHandlers.put( |
| 13158 | validSubId, satelliteProvisionStateChangedHandler); |
| 13159 | if (result != null) { |
| 13160 | result.accept(SatelliteManager.SATELLITE_ERROR_NONE); |
| 13161 | } |
| 13162 | } |
| 13163 | |
| 13164 | /** |
arunvoddu | d5c6ce0 | 2022-12-11 06:03:12 +0000 | [diff] [blame] | 13165 | * Check whether the caller (or self, if not processing an IPC) can read device identifiers. |
| 13166 | * |
| 13167 | * <p>This method behaves in one of the following ways: |
| 13168 | * <ul> |
| 13169 | * <li>return true : if the calling package has the appop permission {@link |
| 13170 | * Manifest.permission#USE_ICC_AUTH_WITH_DEVICE_IDENTIFIER} in the manifest </> |
| 13171 | * <li>return true : if any one subscription has the READ_PRIVILEGED_PHONE_STATE |
| 13172 | * permission, the calling package passes a DevicePolicyManager Device Owner / Profile |
| 13173 | * Owner device identifier access check, or the calling package has carrier privileges</> |
| 13174 | * <li>throw SecurityException: if the caller does not meet any of the requirements. |
| 13175 | * </ul> |
| 13176 | */ |
| 13177 | private static boolean checkCallingOrSelfReadDeviceIdentifiersForAnySub(Context context, |
| 13178 | String callingPackage, @Nullable String callingFeatureId, String message) { |
| 13179 | for (Phone phone : PhoneFactory.getPhones()) { |
| 13180 | if (TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(context, |
| 13181 | phone.getSubId(), callingPackage, callingFeatureId, message)) { |
| 13182 | return true; |
| 13183 | } |
| 13184 | } |
| 13185 | return false; |
| 13186 | } |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 13187 | |
| 13188 | /** |
Jack Yu | fa8ed01 | 2023-02-11 15:42:28 -0800 | [diff] [blame] | 13189 | * @return The subscription manager service instance. |
| 13190 | */ |
| 13191 | public SubscriptionManagerService getSubscriptionManagerService() { |
| 13192 | return SubscriptionManagerService.getInstance(); |
| 13193 | } |
| 13194 | |
| 13195 | /** |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 13196 | * Class binds the consumer[callback] and carrierId. |
| 13197 | */ |
| 13198 | private static class CallerCallbackInfo { |
| 13199 | private final Consumer<Integer> mConsumer; |
| 13200 | private final int mCarrierId; |
| 13201 | |
| 13202 | public CallerCallbackInfo(Consumer<Integer> consumer, int carrierId) { |
| 13203 | mConsumer = consumer; |
| 13204 | mCarrierId = carrierId; |
| 13205 | } |
| 13206 | |
| 13207 | public Consumer<Integer> getConsumer() { |
| 13208 | return mConsumer; |
| 13209 | } |
| 13210 | |
| 13211 | public int getCarrierId() { |
| 13212 | return mCarrierId; |
| 13213 | } |
| 13214 | } |
Jack Yu | fa8ed01 | 2023-02-11 15:42:28 -0800 | [diff] [blame] | 13215 | } |