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; |
| 395 | private static final int CMD_CANCEL_PROVISION_SATELLITE_SERVICE = 127; |
| 396 | private static final int EVENT_CANCEL_PROVISION_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; |
| 628 | int[] features = (int[]) ar.result; |
| 629 | log("Received EVENT_PROVISION_STATE_CHANGED for subId=" + mSubId |
| 630 | + ", features=" + Arrays.toString(features) |
| 631 | + ", provisioned=" + provisioned); |
| 632 | mListeners.values().forEach(listener -> { |
| 633 | try { |
| 634 | listener.onSatelliteProvisionStateChanged(features, provisioned); |
| 635 | } catch (RemoteException e) { |
| 636 | log("EVENT_PROVISION_STATE_CHANGED RemoteException: " + e); |
| 637 | } |
| 638 | }); |
| 639 | |
Thomas Nguyen | e77de6d | 2023-02-10 17:42:43 -0800 | [diff] [blame] | 640 | setSatelliteProvisioned(provisioned); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 641 | /** |
| 642 | * TODO: Take bugreport if provisioned is true and user did not initiate the |
| 643 | * provision procedure for the corresponding subscription. |
| 644 | */ |
| 645 | break; |
| 646 | } |
| 647 | default: |
| 648 | loge("SatelliteProvisionStateChangedHandler unknown event: " + msg.what); |
| 649 | } |
| 650 | } |
| 651 | |
Thomas Nguyen | e77de6d | 2023-02-10 17:42:43 -0800 | [diff] [blame] | 652 | private void setSatelliteProvisioned(boolean isProvisioned) { |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 653 | if (mSubId != SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) { |
| 654 | SubscriptionManager.setSubscriptionProperty( |
Thomas Nguyen | e77de6d | 2023-02-10 17:42:43 -0800 | [diff] [blame] | 655 | mSubId, SubscriptionManager.SATELLITE_ENABLED, isProvisioned ? "1" : "0"); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 656 | } else { |
Thomas Nguyen | e77de6d | 2023-02-10 17:42:43 -0800 | [diff] [blame] | 657 | //TODO (b/267826133): set via SatelliteController. |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 658 | } |
| 659 | } |
| 660 | } |
| 661 | |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 662 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 663 | * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the |
| 664 | * request after sending. The main thread will notify the request when it is complete. |
| 665 | */ |
| 666 | private static final class MainThreadRequest { |
| 667 | /** The argument to use for the request */ |
| 668 | public Object argument; |
| 669 | /** The result of the request that is run on the main thread */ |
| 670 | public Object result; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 671 | // The subscriber id that this request applies to. Defaults to |
| 672 | // SubscriptionManager.INVALID_SUBSCRIPTION_ID |
| 673 | public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 674 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 675 | // In cases where subId is unavailable, the caller needs to specify the phone. |
| 676 | public Phone phone; |
| 677 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 678 | public WorkSource workSource; |
| 679 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 680 | public MainThreadRequest(Object argument) { |
| 681 | this.argument = argument; |
| 682 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 683 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 684 | MainThreadRequest(Object argument, Phone phone, WorkSource workSource) { |
| 685 | this.argument = argument; |
| 686 | if (phone != null) { |
| 687 | this.phone = phone; |
| 688 | } |
| 689 | this.workSource = workSource; |
| 690 | } |
| 691 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 692 | MainThreadRequest(Object argument, Integer subId, WorkSource workSource) { |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 693 | this.argument = argument; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 694 | if (subId != null) { |
| 695 | this.subId = subId; |
| 696 | } |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 697 | this.workSource = workSource; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 698 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 699 | } |
| 700 | |
Sailesh Nepal | cc0375f | 2013-11-13 09:15:18 -0800 | [diff] [blame] | 701 | private static final class IncomingThirdPartyCallArgs { |
| 702 | public final ComponentName component; |
| 703 | public final String callId; |
| 704 | public final String callerDisplayName; |
| 705 | |
| 706 | public IncomingThirdPartyCallArgs(ComponentName component, String callId, |
| 707 | String callerDisplayName) { |
| 708 | this.component = component; |
| 709 | this.callId = callId; |
| 710 | this.callerDisplayName = callerDisplayName; |
| 711 | } |
| 712 | } |
| 713 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 714 | /** |
| 715 | * A handler that processes messages on the main thread in the phone process. Since many |
| 716 | * of the Phone calls are not thread safe this is needed to shuttle the requests from the |
| 717 | * inbound binder threads to the main thread in the phone process. The Binder thread |
| 718 | * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting |
| 719 | * on, which will be notified when the operation completes and will contain the result of the |
| 720 | * request. |
| 721 | * |
| 722 | * <p>If a MainThreadRequest object is provided in the msg.obj field, |
| 723 | * note that request.result must be set to something non-null for the calling thread to |
| 724 | * unblock. |
| 725 | */ |
| 726 | private final class MainThreadHandler extends Handler { |
| 727 | @Override |
| 728 | public void handleMessage(Message msg) { |
| 729 | MainThreadRequest request; |
| 730 | Message onCompleted; |
| 731 | AsyncResult ar; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 732 | UiccPort uiccPort; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 733 | IccAPDUArgument iccArgument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 734 | final Phone defaultPhone = getDefaultPhone(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 735 | |
| 736 | switch (msg.what) { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 737 | case CMD_HANDLE_USSD_REQUEST: { |
| 738 | request = (MainThreadRequest) msg.obj; |
| 739 | final Phone phone = getPhoneFromRequest(request); |
| 740 | Pair<String, ResultReceiver> ussdObject = (Pair) request.argument; |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 741 | String ussdRequest = ussdObject.first; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 742 | ResultReceiver wrappedCallback = ussdObject.second; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 743 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 744 | if (!isUssdApiAllowed(request.subId)) { |
| 745 | // Carrier does not support use of this API, return failure. |
| 746 | Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis."); |
| 747 | UssdResponse response = new UssdResponse(ussdRequest, null); |
| 748 | Bundle returnData = new Bundle(); |
| 749 | returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response); |
| 750 | wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 751 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 752 | request.result = true; |
| 753 | notifyRequester(request); |
| 754 | return; |
| 755 | } |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 756 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 757 | try { |
| 758 | request.result = phone != null |
| 759 | ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false; |
| 760 | } catch (CallStateException cse) { |
| 761 | request.result = false; |
| 762 | } |
| 763 | // Wake up the requesting thread |
| 764 | notifyRequester(request); |
| 765 | break; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 766 | } |
| 767 | |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 768 | case CMD_HANDLE_PIN_MMI: { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 769 | request = (MainThreadRequest) msg.obj; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 770 | final Phone phone = getPhoneFromRequest(request); |
| 771 | request.result = phone != null ? |
| 772 | getPhoneFromRequest(request).handlePinMmi((String) request.argument) |
| 773 | : false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 774 | // Wake up the requesting thread |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 775 | notifyRequester(request); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 776 | break; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 777 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 778 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 779 | case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 780 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 781 | iccArgument = (IccAPDUArgument) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 782 | uiccPort = getUiccPortFromRequest(request); |
| 783 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 784 | loge("iccTransmitApduLogicalChannel: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 785 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 786 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 787 | } else { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 788 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE, |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 789 | request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 790 | uiccPort.iccTransmitApduLogicalChannel( |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 791 | iccArgument.channel, iccArgument.cla, iccArgument.command, |
| 792 | iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data, |
| 793 | onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 794 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 795 | break; |
| 796 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 797 | case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 798 | ar = (AsyncResult) msg.obj; |
| 799 | request = (MainThreadRequest) ar.userObj; |
| 800 | if (ar.exception == null && ar.result != null) { |
| 801 | request.result = ar.result; |
| 802 | } else { |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 803 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 804 | if (ar.result == null) { |
| 805 | loge("iccTransmitApduLogicalChannel: Empty response"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 806 | } else if (ar.exception instanceof CommandException) { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 807 | loge("iccTransmitApduLogicalChannel: CommandException: " + |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 808 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 809 | } else { |
| 810 | loge("iccTransmitApduLogicalChannel: Unknown exception"); |
| 811 | } |
| 812 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 813 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 814 | break; |
| 815 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 816 | case CMD_TRANSMIT_APDU_BASIC_CHANNEL: |
| 817 | request = (MainThreadRequest) msg.obj; |
| 818 | iccArgument = (IccAPDUArgument) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 819 | uiccPort = getUiccPortFromRequest(request); |
| 820 | if (uiccPort == null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 821 | loge("iccTransmitApduBasicChannel: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 822 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 823 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 824 | } else { |
| 825 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE, |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 826 | request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 827 | uiccPort.iccTransmitApduBasicChannel( |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 828 | iccArgument.cla, iccArgument.command, iccArgument.p1, |
| 829 | iccArgument.p2, |
| 830 | iccArgument.p3, iccArgument.data, onCompleted); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 831 | } |
| 832 | break; |
| 833 | |
| 834 | case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE: |
| 835 | ar = (AsyncResult) msg.obj; |
| 836 | request = (MainThreadRequest) ar.userObj; |
| 837 | if (ar.exception == null && ar.result != null) { |
| 838 | request.result = ar.result; |
| 839 | } else { |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 840 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 841 | if (ar.result == null) { |
| 842 | loge("iccTransmitApduBasicChannel: Empty response"); |
| 843 | } else if (ar.exception instanceof CommandException) { |
| 844 | loge("iccTransmitApduBasicChannel: CommandException: " + |
| 845 | ar.exception); |
| 846 | } else { |
| 847 | loge("iccTransmitApduBasicChannel: Unknown exception"); |
| 848 | } |
| 849 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 850 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 851 | break; |
| 852 | |
| 853 | case CMD_EXCHANGE_SIM_IO: |
| 854 | request = (MainThreadRequest) msg.obj; |
| 855 | iccArgument = (IccAPDUArgument) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 856 | uiccPort = getUiccPortFromRequest(request); |
| 857 | if (uiccPort == null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 858 | loge("iccExchangeSimIO: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 859 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 860 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 861 | } else { |
| 862 | onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE, |
| 863 | request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 864 | uiccPort.iccExchangeSimIO(iccArgument.cla, /* fileID */ |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 865 | iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3, |
| 866 | iccArgument.data, onCompleted); |
| 867 | } |
| 868 | break; |
| 869 | |
| 870 | case EVENT_EXCHANGE_SIM_IO_DONE: |
| 871 | ar = (AsyncResult) msg.obj; |
| 872 | request = (MainThreadRequest) ar.userObj; |
| 873 | if (ar.exception == null && ar.result != null) { |
| 874 | request.result = ar.result; |
| 875 | } else { |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 876 | request.result = new IccIoResult(0x6f, 0, (byte[]) null); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 877 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 878 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 879 | break; |
| 880 | |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 881 | case CMD_SEND_ENVELOPE: |
| 882 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 883 | uiccPort = getUiccPortFromRequest(request); |
| 884 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 885 | loge("sendEnvelopeWithStatus: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 886 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 887 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 888 | } else { |
| 889 | onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 890 | uiccPort.sendEnvelopeWithStatus((String) request.argument, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 891 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 892 | break; |
| 893 | |
| 894 | case EVENT_SEND_ENVELOPE_DONE: |
| 895 | ar = (AsyncResult) msg.obj; |
| 896 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 897 | if (ar.exception == null && ar.result != null) { |
| 898 | request.result = ar.result; |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 899 | } else { |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 900 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 901 | if (ar.result == null) { |
| 902 | loge("sendEnvelopeWithStatus: Empty response"); |
| 903 | } else if (ar.exception instanceof CommandException) { |
| 904 | loge("sendEnvelopeWithStatus: CommandException: " + |
| 905 | ar.exception); |
| 906 | } else { |
| 907 | loge("sendEnvelopeWithStatus: exception:" + ar.exception); |
| 908 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 909 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 910 | notifyRequester(request); |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 911 | break; |
| 912 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 913 | case CMD_OPEN_CHANNEL: |
| 914 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 915 | uiccPort = getUiccPortFromRequest(request); |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 916 | IccLogicalChannelRequest openChannelRequest = |
| 917 | (IccLogicalChannelRequest) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 918 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 919 | loge("iccOpenLogicalChannel: No UICC"); |
Shishir Agrawal | fc0492a | 2016-02-17 11:15:33 -0800 | [diff] [blame] | 920 | request.result = new IccOpenLogicalChannelResponse(-1, |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 921 | IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 922 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 923 | } else { |
| 924 | onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request); |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 925 | uiccPort.iccOpenLogicalChannel(openChannelRequest.aid, |
| 926 | openChannelRequest.p2, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 927 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 928 | break; |
| 929 | |
| 930 | case EVENT_OPEN_CHANNEL_DONE: |
| 931 | ar = (AsyncResult) msg.obj; |
| 932 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 933 | IccOpenLogicalChannelResponse openChannelResp; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 934 | if (ar.exception == null && ar.result != null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 935 | int[] result = (int[]) ar.result; |
| 936 | int channelId = result[0]; |
| 937 | byte[] selectResponse = null; |
| 938 | if (result.length > 1) { |
| 939 | selectResponse = new byte[result.length - 1]; |
| 940 | for (int i = 1; i < result.length; ++i) { |
| 941 | selectResponse[i - 1] = (byte) result[i]; |
| 942 | } |
| 943 | } |
| 944 | openChannelResp = new IccOpenLogicalChannelResponse(channelId, |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 945 | IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse); |
Rambo Wang | 3b77c4c | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 946 | |
| 947 | uiccPort = getUiccPortFromRequest(request); |
Rambo Wang | e53e07d | 2022-05-10 13:01:13 -0700 | [diff] [blame] | 948 | if (uiccPort == null) { |
| 949 | loge("EVENT_OPEN_CHANNEL_DONE: UiccPort is null"); |
| 950 | } else { |
| 951 | IccLogicalChannelRequest channelRequest = |
| 952 | (IccLogicalChannelRequest) request.argument; |
| 953 | channelRequest.channel = channelId; |
| 954 | uiccPort.onLogicalChannelOpened(channelRequest); |
| 955 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 956 | } else { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 957 | if (ar.result == null) { |
| 958 | loge("iccOpenLogicalChannel: Empty response"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 959 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 960 | if (ar.exception != null) { |
| 961 | loge("iccOpenLogicalChannel: Exception: " + ar.exception); |
| 962 | } |
| 963 | |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 964 | int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 965 | if (ar.exception instanceof CommandException) { |
| 966 | CommandException.Error error = |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 967 | ((CommandException) (ar.exception)).getCommandError(); |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 968 | if (error == CommandException.Error.MISSING_RESOURCE) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 969 | errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 970 | } else if (error == CommandException.Error.NO_SUCH_ELEMENT) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 971 | errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 972 | } |
| 973 | } |
| 974 | openChannelResp = new IccOpenLogicalChannelResponse( |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 975 | IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 976 | } |
Shishir Agrawal | 82c8a46 | 2014-07-31 18:13:17 -0700 | [diff] [blame] | 977 | request.result = openChannelResp; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 978 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 979 | break; |
| 980 | |
| 981 | case CMD_CLOSE_CHANNEL: |
| 982 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 983 | uiccPort = getUiccPortFromRequest(request); |
| 984 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 985 | loge("iccCloseLogicalChannel: No UICC"); |
Chen Xu | a8f0dff | 2022-02-12 00:34:15 -0800 | [diff] [blame] | 986 | request.result = new IllegalArgumentException( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 987 | "iccCloseLogicalChannel: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 988 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 989 | } else { |
| 990 | onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 991 | uiccPort.iccCloseLogicalChannel((Integer) request.argument, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 992 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 993 | break; |
| 994 | |
| 995 | case EVENT_CLOSE_CHANNEL_DONE: |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 996 | ar = (AsyncResult) msg.obj; |
| 997 | request = (MainThreadRequest) ar.userObj; |
| 998 | if (ar.exception == null) { |
| 999 | request.result = true; |
Rambo Wang | 3b77c4c | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 1000 | uiccPort = getUiccPortFromRequest(request); |
Rambo Wang | e53e07d | 2022-05-10 13:01:13 -0700 | [diff] [blame] | 1001 | if (uiccPort == null) { |
| 1002 | loge("EVENT_CLOSE_CHANNEL_DONE: UiccPort is null"); |
| 1003 | } else { |
| 1004 | final int channelId = (Integer) request.argument; |
| 1005 | uiccPort.onLogicalChannelClosed(channelId); |
| 1006 | } |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 1007 | } else { |
| 1008 | request.result = false; |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 1009 | Exception exception = null; |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 1010 | if (ar.exception instanceof CommandException) { |
| 1011 | loge("iccCloseLogicalChannel: CommandException: " + ar.exception); |
| 1012 | CommandException.Error error = |
| 1013 | ((CommandException) (ar.exception)).getCommandError(); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 1014 | if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 1015 | // should only throw exceptions from the binder threads. |
| 1016 | exception = new IllegalArgumentException( |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 1017 | "iccCloseLogicalChannel: invalid argument "); |
| 1018 | } |
| 1019 | } else { |
| 1020 | loge("iccCloseLogicalChannel: Unknown exception"); |
| 1021 | } |
Chen Xu | a8f0dff | 2022-02-12 00:34:15 -0800 | [diff] [blame] | 1022 | request.result = (exception != null) ? exception : |
| 1023 | new IllegalStateException( |
| 1024 | "exception from modem to close iccLogical Channel"); |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 1025 | } |
| 1026 | notifyRequester(request); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1027 | break; |
| 1028 | |
| 1029 | case CMD_NV_READ_ITEM: |
| 1030 | request = (MainThreadRequest) msg.obj; |
| 1031 | onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1032 | defaultPhone.nvReadItem((Integer) request.argument, onCompleted, |
| 1033 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1034 | break; |
| 1035 | |
| 1036 | case EVENT_NV_READ_ITEM_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 1037 | ar = (AsyncResult) msg.obj; |
| 1038 | request = (MainThreadRequest) ar.userObj; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1039 | if (ar.exception == null && ar.result != null) { |
| 1040 | request.result = ar.result; // String |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 1041 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1042 | request.result = ""; |
| 1043 | if (ar.result == null) { |
| 1044 | loge("nvReadItem: Empty response"); |
| 1045 | } else if (ar.exception instanceof CommandException) { |
| 1046 | loge("nvReadItem: CommandException: " + |
| 1047 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 1048 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1049 | loge("nvReadItem: Unknown exception"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 1050 | } |
| 1051 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1052 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 1053 | break; |
| 1054 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1055 | case CMD_NV_WRITE_ITEM: |
| 1056 | request = (MainThreadRequest) msg.obj; |
| 1057 | onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request); |
| 1058 | Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1059 | defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 1060 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1061 | break; |
| 1062 | |
| 1063 | case EVENT_NV_WRITE_ITEM_DONE: |
| 1064 | handleNullReturnEvent(msg, "nvWriteItem"); |
| 1065 | break; |
| 1066 | |
| 1067 | case CMD_NV_WRITE_CDMA_PRL: |
| 1068 | request = (MainThreadRequest) msg.obj; |
| 1069 | onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1070 | defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1071 | break; |
| 1072 | |
| 1073 | case EVENT_NV_WRITE_CDMA_PRL_DONE: |
| 1074 | handleNullReturnEvent(msg, "nvWriteCdmaPrl"); |
| 1075 | break; |
| 1076 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1077 | case CMD_RESET_MODEM_CONFIG: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1078 | request = (MainThreadRequest) msg.obj; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1079 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1080 | defaultPhone.resetModemConfig(onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1081 | break; |
| 1082 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1083 | case EVENT_RESET_MODEM_CONFIG_DONE: |
| 1084 | handleNullReturnEvent(msg, "resetModemConfig"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1085 | break; |
| 1086 | |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 1087 | case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: { |
| 1088 | request = (MainThreadRequest) msg.obj; |
| 1089 | onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE, |
| 1090 | request); |
| 1091 | Phone phone = getPhoneFromRequest(request); |
| 1092 | if (phone != null) { |
| 1093 | phone.isNrDualConnectivityEnabled(onCompleted, request.workSource); |
| 1094 | } else { |
| 1095 | loge("isNRDualConnectivityEnabled: No phone object"); |
| 1096 | request.result = false; |
| 1097 | notifyRequester(request); |
| 1098 | } |
| 1099 | break; |
| 1100 | } |
| 1101 | |
| 1102 | case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE: |
| 1103 | ar = (AsyncResult) msg.obj; |
| 1104 | request = (MainThreadRequest) ar.userObj; |
| 1105 | if (ar.exception == null && ar.result != null) { |
| 1106 | request.result = ar.result; |
| 1107 | } else { |
| 1108 | // request.result must be set to something non-null |
| 1109 | // for the calling thread to unblock |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 1110 | if (ar.result != null) { |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 1111 | request.result = ar.result; |
| 1112 | } else { |
| 1113 | request.result = false; |
| 1114 | } |
| 1115 | if (ar.result == null) { |
| 1116 | loge("isNRDualConnectivityEnabled: Empty response"); |
| 1117 | } else if (ar.exception instanceof CommandException) { |
| 1118 | loge("isNRDualConnectivityEnabled: CommandException: " |
| 1119 | + ar.exception); |
| 1120 | } else { |
| 1121 | loge("isNRDualConnectivityEnabled: Unknown exception"); |
| 1122 | } |
| 1123 | } |
| 1124 | notifyRequester(request); |
| 1125 | break; |
| 1126 | |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 1127 | case CMD_IS_VONR_ENABLED: { |
| 1128 | request = (MainThreadRequest) msg.obj; |
| 1129 | onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE, |
| 1130 | request); |
| 1131 | Phone phone = getPhoneFromRequest(request); |
| 1132 | if (phone != null) { |
| 1133 | phone.isVoNrEnabled(onCompleted, request.workSource); |
| 1134 | } else { |
| 1135 | loge("isVoNrEnabled: No phone object"); |
| 1136 | request.result = false; |
| 1137 | notifyRequester(request); |
| 1138 | } |
| 1139 | break; |
| 1140 | } |
| 1141 | |
| 1142 | case EVENT_IS_VONR_ENABLED_DONE: |
| 1143 | ar = (AsyncResult) msg.obj; |
| 1144 | request = (MainThreadRequest) ar.userObj; |
| 1145 | if (ar.exception == null && ar.result != null) { |
| 1146 | request.result = ar.result; |
| 1147 | } else { |
| 1148 | // request.result must be set to something non-null |
| 1149 | // for the calling thread to unblock |
| 1150 | if (ar.result != null) { |
| 1151 | request.result = ar.result; |
| 1152 | } else { |
| 1153 | request.result = false; |
| 1154 | } |
| 1155 | if (ar.result == null) { |
| 1156 | loge("isVoNrEnabled: Empty response"); |
| 1157 | } else if (ar.exception instanceof CommandException) { |
| 1158 | loge("isVoNrEnabled: CommandException: " |
| 1159 | + ar.exception); |
| 1160 | } else { |
| 1161 | loge("isVoNrEnabled: Unknown exception"); |
| 1162 | } |
| 1163 | } |
| 1164 | notifyRequester(request); |
| 1165 | break; |
| 1166 | |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 1167 | case CMD_ENABLE_NR_DUAL_CONNECTIVITY: { |
| 1168 | request = (MainThreadRequest) msg.obj; |
| 1169 | onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request); |
| 1170 | Phone phone = getPhoneFromRequest(request); |
| 1171 | if (phone != null) { |
| 1172 | phone.setNrDualConnectivityState((int) request.argument, onCompleted, |
| 1173 | request.workSource); |
| 1174 | } else { |
| 1175 | loge("enableNrDualConnectivity: No phone object"); |
| 1176 | request.result = |
| 1177 | TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE; |
| 1178 | notifyRequester(request); |
| 1179 | } |
| 1180 | break; |
| 1181 | } |
| 1182 | |
| 1183 | case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: { |
| 1184 | ar = (AsyncResult) msg.obj; |
| 1185 | request = (MainThreadRequest) ar.userObj; |
| 1186 | if (ar.exception == null) { |
| 1187 | request.result = |
| 1188 | TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS; |
| 1189 | } else { |
| 1190 | request.result = |
| 1191 | TelephonyManager |
| 1192 | .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR; |
| 1193 | if (ar.exception instanceof CommandException) { |
| 1194 | CommandException.Error error = |
| 1195 | ((CommandException) (ar.exception)).getCommandError(); |
| 1196 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1197 | request.result = |
| 1198 | TelephonyManager |
| 1199 | .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE; |
Sooraj Sasindran | 2965416 | 2021-03-03 23:00:01 +0000 | [diff] [blame] | 1200 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1201 | request.result = |
| 1202 | TelephonyManager |
| 1203 | .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED; |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 1204 | } |
| 1205 | loge("enableNrDualConnectivity" + ": CommandException: " |
| 1206 | + ar.exception); |
| 1207 | } else { |
| 1208 | loge("enableNrDualConnectivity" + ": Unknown exception"); |
| 1209 | } |
| 1210 | } |
| 1211 | notifyRequester(request); |
| 1212 | break; |
| 1213 | } |
| 1214 | |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 1215 | case CMD_ENABLE_VONR: { |
| 1216 | request = (MainThreadRequest) msg.obj; |
| 1217 | onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request); |
| 1218 | Phone phone = getPhoneFromRequest(request); |
| 1219 | if (phone != null) { |
| 1220 | phone.setVoNrEnabled((boolean) request.argument, onCompleted, |
| 1221 | request.workSource); |
| 1222 | } else { |
| 1223 | loge("setVoNrEnabled: No phone object"); |
| 1224 | request.result = |
| 1225 | TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE; |
| 1226 | notifyRequester(request); |
| 1227 | } |
| 1228 | break; |
| 1229 | } |
| 1230 | |
| 1231 | case EVENT_ENABLE_VONR_DONE: { |
| 1232 | ar = (AsyncResult) msg.obj; |
| 1233 | request = (MainThreadRequest) ar.userObj; |
| 1234 | if (ar.exception == null) { |
| 1235 | request.result = TelephonyManager.ENABLE_VONR_SUCCESS; |
| 1236 | } else { |
| 1237 | request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR; |
| 1238 | if (ar.exception instanceof CommandException) { |
| 1239 | CommandException.Error error = |
| 1240 | ((CommandException) (ar.exception)).getCommandError(); |
| 1241 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1242 | request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE; |
| 1243 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1244 | request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED; |
| 1245 | } else { |
| 1246 | request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR; |
| 1247 | } |
| 1248 | loge("setVoNrEnabled" + ": CommandException: " |
| 1249 | + ar.exception); |
| 1250 | } else { |
| 1251 | loge("setVoNrEnabled" + ": Unknown exception"); |
| 1252 | } |
| 1253 | } |
| 1254 | notifyRequester(request); |
| 1255 | break; |
| 1256 | } |
| 1257 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1258 | case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1259 | request = (MainThreadRequest) msg.obj; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1260 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE, |
| 1261 | request); |
| 1262 | getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1263 | break; |
| 1264 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1265 | case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1266 | ar = (AsyncResult) msg.obj; |
| 1267 | request = (MainThreadRequest) ar.userObj; |
| 1268 | if (ar.exception == null && ar.result != null) { |
| 1269 | request.result = ar.result; // Integer |
| 1270 | } else { |
Nazish Tabassum | e8ba43a | 2020-07-28 14:49:25 +0530 | [diff] [blame] | 1271 | // request.result must be set to something non-null |
| 1272 | // for the calling thread to unblock |
| 1273 | request.result = new int[]{-1}; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1274 | if (ar.result == null) { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1275 | loge("getAllowedNetworkTypesBitmask: Empty response"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1276 | } else if (ar.exception instanceof CommandException) { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1277 | loge("getAllowedNetworkTypesBitmask: CommandException: " |
| 1278 | + ar.exception); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1279 | } else { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1280 | loge("getAllowedNetworkTypesBitmask: Unknown exception"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1281 | } |
| 1282 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1283 | notifyRequester(request); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1284 | break; |
| 1285 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1286 | case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1287 | request = (MainThreadRequest) msg.obj; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1288 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE, |
| 1289 | request); |
| 1290 | Pair<Integer, Long> reasonWithNetworkTypes = |
| 1291 | (Pair<Integer, Long>) request.argument; |
| 1292 | getPhoneFromRequest(request).setAllowedNetworkTypes( |
| 1293 | reasonWithNetworkTypes.first, |
| 1294 | reasonWithNetworkTypes.second, |
| 1295 | onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1296 | break; |
| 1297 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1298 | case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE: |
| 1299 | handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1300 | break; |
| 1301 | |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 1302 | case CMD_INVOKE_OEM_RIL_REQUEST_RAW: |
| 1303 | request = (MainThreadRequest)msg.obj; |
| 1304 | onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1305 | defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 1306 | break; |
| 1307 | |
| 1308 | case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE: |
| 1309 | ar = (AsyncResult)msg.obj; |
| 1310 | request = (MainThreadRequest)ar.userObj; |
| 1311 | request.result = ar; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1312 | notifyRequester(request); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 1313 | break; |
| 1314 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1315 | case CMD_SET_VOICEMAIL_NUMBER: |
| 1316 | request = (MainThreadRequest) msg.obj; |
| 1317 | onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request); |
| 1318 | Pair<String, String> tagNum = (Pair<String, String>) request.argument; |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1319 | getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second, |
| 1320 | onCompleted); |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1321 | break; |
| 1322 | |
| 1323 | case EVENT_SET_VOICEMAIL_NUMBER_DONE: |
| 1324 | handleNullReturnEvent(msg, "setVoicemailNumber"); |
| 1325 | break; |
| 1326 | |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 1327 | case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC: |
| 1328 | request = (MainThreadRequest) msg.obj; |
| 1329 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE, |
| 1330 | request); |
| 1331 | getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted); |
| 1332 | break; |
| 1333 | |
| 1334 | case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE: |
| 1335 | handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic"); |
| 1336 | break; |
| 1337 | |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1338 | case CMD_PERFORM_NETWORK_SCAN: |
| 1339 | request = (MainThreadRequest) msg.obj; |
| 1340 | onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request); |
| 1341 | getPhoneFromRequest(request).getAvailableNetworks(onCompleted); |
| 1342 | break; |
| 1343 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1344 | case CMD_GET_CALL_FORWARDING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1345 | request = (MainThreadRequest) msg.obj; |
| 1346 | onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1347 | Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args = |
| 1348 | (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>) |
| 1349 | request.argument; |
| 1350 | int callForwardingReason = args.first; |
| 1351 | request.phone.getCallForwardingOption(callForwardingReason, onCompleted); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1352 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1353 | } |
| 1354 | case EVENT_GET_CALL_FORWARDING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1355 | ar = (AsyncResult) msg.obj; |
| 1356 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1357 | TelephonyManager.CallForwardingInfoCallback callback = |
| 1358 | ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>) |
| 1359 | request.argument).second; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1360 | if (ar.exception == null && ar.result != null) { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1361 | CallForwardingInfo callForwardingInfo = null; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1362 | CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result; |
| 1363 | for (CallForwardInfo callForwardInfo : callForwardInfos) { |
| 1364 | // Service Class is a bit mask per 3gpp 27.007. Search for |
| 1365 | // any service for voice call. |
| 1366 | if ((callForwardInfo.serviceClass |
| 1367 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0) { |
Yuchen Dong | 69cc141 | 2021-09-27 20:27:01 +0800 | [diff] [blame] | 1368 | callForwardingInfo = new CallForwardingInfo( |
| 1369 | callForwardInfo.status |
| 1370 | == CommandsInterface.CF_ACTION_ENABLE, |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1371 | callForwardInfo.reason, |
| 1372 | callForwardInfo.number, |
| 1373 | callForwardInfo.timeSeconds); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1374 | break; |
| 1375 | } |
| 1376 | } |
| 1377 | // Didn't find a call forward info for voice call. |
| 1378 | if (callForwardingInfo == null) { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1379 | callForwardingInfo = new CallForwardingInfo(false /* enabled */, |
| 1380 | 0 /* reason */, null /* number */, 0 /* timeout */); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1381 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1382 | callback.onCallForwardingInfoAvailable(callForwardingInfo); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1383 | } else { |
| 1384 | if (ar.result == null) { |
| 1385 | loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response"); |
| 1386 | } |
| 1387 | if (ar.exception != null) { |
| 1388 | loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception); |
| 1389 | } |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1390 | int errorCode = TelephonyManager |
| 1391 | .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1392 | if (ar.exception instanceof CommandException) { |
| 1393 | CommandException.Error error = |
| 1394 | ((CommandException) (ar.exception)).getCommandError(); |
| 1395 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1396 | errorCode = TelephonyManager |
| 1397 | .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1398 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1399 | errorCode = TelephonyManager |
| 1400 | .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1401 | } |
| 1402 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1403 | callback.onError(errorCode); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1404 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1405 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1406 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1407 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1408 | case CMD_SET_CALL_FORWARDING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1409 | request = (MainThreadRequest) msg.obj; |
| 1410 | onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1411 | request = (MainThreadRequest) msg.obj; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1412 | CallForwardingInfo callForwardingInfoToSet = |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1413 | ((Pair<CallForwardingInfo, Consumer<Integer>>) |
| 1414 | request.argument).first; |
| 1415 | request.phone.setCallForwardingOption( |
| 1416 | callForwardingInfoToSet.isEnabled() |
Calvin Pan | 258f1f7 | 2021-07-28 21:46:56 +0800 | [diff] [blame] | 1417 | ? CommandsInterface.CF_ACTION_REGISTRATION |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1418 | : CommandsInterface.CF_ACTION_DISABLE, |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1419 | callForwardingInfoToSet.getReason(), |
| 1420 | callForwardingInfoToSet.getNumber(), |
| 1421 | callForwardingInfoToSet.getTimeoutSeconds(), onCompleted); |
| 1422 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1423 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1424 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1425 | case EVENT_SET_CALL_FORWARDING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1426 | ar = (AsyncResult) msg.obj; |
| 1427 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1428 | Consumer<Integer> callback = |
| 1429 | ((Pair<CallForwardingInfo, Consumer<Integer>>) |
| 1430 | request.argument).second; |
| 1431 | if (ar.exception != null) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1432 | loge("setCallForwarding exception: " + ar.exception); |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1433 | int errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1434 | .RESULT_ERROR_UNKNOWN; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1435 | if (ar.exception instanceof CommandException) { |
| 1436 | CommandException.Error error = |
| 1437 | ((CommandException) (ar.exception)).getCommandError(); |
| 1438 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1439 | errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1440 | .RESULT_ERROR_FDN_CHECK_FAILURE; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1441 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1442 | errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1443 | .RESULT_ERROR_NOT_SUPPORTED; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1444 | } |
| 1445 | } |
| 1446 | callback.accept(errorCode); |
| 1447 | } else { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1448 | callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1449 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1450 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1451 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1452 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1453 | case CMD_GET_CALL_WAITING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1454 | request = (MainThreadRequest) msg.obj; |
| 1455 | onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request); |
| 1456 | getPhoneFromRequest(request).getCallWaiting(onCompleted); |
| 1457 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1458 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1459 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1460 | case EVENT_GET_CALL_WAITING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1461 | ar = (AsyncResult) msg.obj; |
| 1462 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1463 | Consumer<Integer> callback = (Consumer<Integer>) request.argument; |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1464 | int callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1465 | if (ar.exception == null && ar.result != null) { |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1466 | int[] callForwardResults = (int[]) ar.result; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1467 | // Service Class is a bit mask per 3gpp 27.007. |
| 1468 | // Search for any service for voice call. |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1469 | if (callForwardResults.length > 1 |
| 1470 | && ((callForwardResults[1] |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1471 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) { |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1472 | callWaitingStatus = callForwardResults[0] == 0 |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1473 | ? TelephonyManager.CALL_WAITING_STATUS_DISABLED |
| 1474 | : TelephonyManager.CALL_WAITING_STATUS_ENABLED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1475 | } else { |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1476 | callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1477 | } |
| 1478 | } else { |
| 1479 | if (ar.result == null) { |
| 1480 | loge("EVENT_GET_CALL_WAITING_DONE: Empty response"); |
| 1481 | } |
| 1482 | if (ar.exception != null) { |
| 1483 | loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception); |
| 1484 | } |
| 1485 | if (ar.exception instanceof CommandException) { |
| 1486 | CommandException.Error error = |
| 1487 | ((CommandException) (ar.exception)).getCommandError(); |
| 1488 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1489 | callWaitingStatus = |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1490 | TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED; |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1491 | } else if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
| 1492 | callWaitingStatus = |
| 1493 | TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1494 | } |
| 1495 | } |
| 1496 | } |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1497 | callback.accept(callWaitingStatus); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1498 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1499 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1500 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1501 | case CMD_SET_CALL_WAITING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1502 | request = (MainThreadRequest) msg.obj; |
| 1503 | onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1504 | boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first; |
| 1505 | getPhoneFromRequest(request).setCallWaiting(enable, onCompleted); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1506 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1507 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1508 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1509 | case EVENT_SET_CALL_WAITING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1510 | ar = (AsyncResult) msg.obj; |
| 1511 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1512 | boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first; |
| 1513 | Consumer<Integer> callback = |
| 1514 | ((Pair<Boolean, Consumer<Integer>>) request.argument).second; |
| 1515 | if (ar.exception != null) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1516 | loge("setCallWaiting exception: " + ar.exception); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1517 | if (ar.exception instanceof CommandException) { |
| 1518 | CommandException.Error error = |
| 1519 | ((CommandException) (ar.exception)).getCommandError(); |
| 1520 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1521 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED); |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1522 | } else if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
| 1523 | callback.accept( |
| 1524 | TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1525 | } else { |
| 1526 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 1527 | } |
| 1528 | } else { |
| 1529 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 1530 | } |
| 1531 | } else { |
| 1532 | callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED |
| 1533 | : TelephonyManager.CALL_WAITING_STATUS_DISABLED); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1534 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1535 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1536 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1537 | case EVENT_PERFORM_NETWORK_SCAN_DONE: |
| 1538 | ar = (AsyncResult) msg.obj; |
| 1539 | request = (MainThreadRequest) ar.userObj; |
| 1540 | CellNetworkScanResult cellScanResult; |
| 1541 | if (ar.exception == null && ar.result != null) { |
| 1542 | cellScanResult = new CellNetworkScanResult( |
| 1543 | CellNetworkScanResult.STATUS_SUCCESS, |
| 1544 | (List<OperatorInfo>) ar.result); |
| 1545 | } else { |
| 1546 | if (ar.result == null) { |
| 1547 | loge("getCellNetworkScanResults: Empty response"); |
| 1548 | } |
| 1549 | if (ar.exception != null) { |
| 1550 | loge("getCellNetworkScanResults: Exception: " + ar.exception); |
| 1551 | } |
| 1552 | int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR; |
| 1553 | if (ar.exception instanceof CommandException) { |
| 1554 | CommandException.Error error = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 1555 | ((CommandException) (ar.exception)).getCommandError(); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1556 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1557 | errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE; |
| 1558 | } else if (error == CommandException.Error.GENERIC_FAILURE) { |
| 1559 | errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE; |
| 1560 | } |
| 1561 | } |
| 1562 | cellScanResult = new CellNetworkScanResult(errorCode, null); |
| 1563 | } |
| 1564 | request.result = cellScanResult; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1565 | notifyRequester(request); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1566 | break; |
| 1567 | |
| 1568 | case CMD_SET_NETWORK_SELECTION_MODE_MANUAL: |
| 1569 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1570 | ManualNetworkSelectionArgument selArg = |
| 1571 | (ManualNetworkSelectionArgument) request.argument; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1572 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE, |
| 1573 | request); |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1574 | getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo, |
| 1575 | selArg.persistSelection, onCompleted); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1576 | break; |
| 1577 | |
| 1578 | case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE: |
Pengquan Meng | e3d01e2 | 2018-09-20 15:25:35 -0700 | [diff] [blame] | 1579 | ar = (AsyncResult) msg.obj; |
| 1580 | request = (MainThreadRequest) ar.userObj; |
| 1581 | if (ar.exception == null) { |
| 1582 | request.result = true; |
| 1583 | } else { |
| 1584 | request.result = false; |
| 1585 | loge("setNetworkSelectionModeManual " + ar.exception); |
| 1586 | } |
| 1587 | notifyRequester(request); |
| 1588 | mApp.onNetworkSelectionChanged(request.subId); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1589 | break; |
| 1590 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1591 | case CMD_GET_MODEM_ACTIVITY_INFO: |
| 1592 | request = (MainThreadRequest) msg.obj; |
| 1593 | onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1594 | if (defaultPhone != null) { |
| 1595 | defaultPhone.getModemActivityInfo(onCompleted, request.workSource); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1596 | } else { |
| 1597 | ResultReceiver result = (ResultReceiver) request.argument; |
| 1598 | Bundle bundle = new Bundle(); |
| 1599 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 1600 | new ModemActivityInfo(0, 0, 0, |
| 1601 | new int[ModemActivityInfo.getNumTxPowerLevels()], 0)); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1602 | result.send(0, bundle); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1603 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1604 | break; |
| 1605 | |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1606 | case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: { |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1607 | ar = (AsyncResult) msg.obj; |
| 1608 | request = (MainThreadRequest) ar.userObj; |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1609 | ResultReceiver result = (ResultReceiver) request.argument; |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1610 | int error = 0; |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 1611 | ModemActivityInfo ret = null; |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1612 | if (mLastModemActivityInfo == null) { |
| 1613 | mLastModemActivitySpecificInfo = new ActivityStatsTechSpecificInfo[1]; |
| 1614 | mLastModemActivitySpecificInfo[0] = |
| 1615 | new ActivityStatsTechSpecificInfo( |
| 1616 | 0, |
| 1617 | 0, |
| 1618 | new int[ModemActivityInfo.getNumTxPowerLevels()], |
| 1619 | 0); |
| 1620 | mLastModemActivityInfo = |
| 1621 | new ModemActivityInfo(0, 0, 0, mLastModemActivitySpecificInfo); |
| 1622 | } |
| 1623 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1624 | if (ar.exception == null && ar.result != null) { |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1625 | // Update the last modem activity info and the result of the request. |
| 1626 | ModemActivityInfo info = (ModemActivityInfo) ar.result; |
| 1627 | if (isModemActivityInfoValid(info)) { |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1628 | mergeModemActivityInfo(info); |
Gary Jian | 76280a4 | 2022-12-07 16:18:33 +0800 | [diff] [blame] | 1629 | } else { |
| 1630 | loge("queryModemActivityInfo: invalid response"); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1631 | } |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 1632 | // This is needed to decouple ret from mLastModemActivityInfo |
| 1633 | // We don't want to return mLastModemActivityInfo which is updated |
| 1634 | // inside mergeModemActivityInfo() |
| 1635 | ret = new ModemActivityInfo( |
| 1636 | mLastModemActivityInfo.getTimestampMillis(), |
| 1637 | mLastModemActivityInfo.getSleepTimeMillis(), |
| 1638 | mLastModemActivityInfo.getIdleTimeMillis(), |
| 1639 | deepCopyModemActivitySpecificInfo(mLastModemActivitySpecificInfo)); |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1640 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1641 | } else { |
| 1642 | if (ar.result == null) { |
| 1643 | loge("queryModemActivityInfo: Empty response"); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1644 | error = TelephonyManager.ModemActivityInfoException |
| 1645 | .ERROR_INVALID_INFO_RECEIVED; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1646 | } else if (ar.exception instanceof CommandException) { |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1647 | loge("queryModemActivityInfo: CommandException: " + ar.exception); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1648 | error = TelephonyManager.ModemActivityInfoException |
| 1649 | .ERROR_MODEM_RESPONSE_ERROR; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1650 | } else { |
| 1651 | loge("queryModemActivityInfo: Unknown exception"); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1652 | error = TelephonyManager.ModemActivityInfoException |
| 1653 | .ERROR_UNKNOWN; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1654 | } |
| 1655 | } |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1656 | Bundle bundle = new Bundle(); |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 1657 | if (ret != null) { |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1658 | bundle.putParcelable( |
| 1659 | TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 1660 | ret); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1661 | } else { |
| 1662 | bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error); |
| 1663 | } |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1664 | result.send(0, bundle); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1665 | notifyRequester(request); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1666 | break; |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1667 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1668 | |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame^] | 1669 | case CMD_SET_ALLOWED_CARRIERS: { |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1670 | request = (MainThreadRequest) msg.obj; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1671 | CarrierRestrictionRules argument = |
| 1672 | (CarrierRestrictionRules) request.argument; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1673 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request); |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1674 | defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1675 | break; |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame^] | 1676 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1677 | |
| 1678 | case EVENT_SET_ALLOWED_CARRIERS_DONE: |
| 1679 | ar = (AsyncResult) msg.obj; |
| 1680 | request = (MainThreadRequest) ar.userObj; |
| 1681 | if (ar.exception == null && ar.result != null) { |
| 1682 | request.result = ar.result; |
| 1683 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1684 | request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR; |
| 1685 | if (ar.exception instanceof CommandException) { |
| 1686 | loge("setAllowedCarriers: CommandException: " + ar.exception); |
| 1687 | CommandException.Error error = |
| 1688 | ((CommandException) (ar.exception)).getCommandError(); |
| 1689 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1690 | request.result = |
| 1691 | TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED; |
| 1692 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1693 | } else { |
| 1694 | loge("setAllowedCarriers: Unknown exception"); |
| 1695 | } |
| 1696 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1697 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1698 | break; |
| 1699 | |
| 1700 | case CMD_GET_ALLOWED_CARRIERS: |
| 1701 | request = (MainThreadRequest) msg.obj; |
| 1702 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1703 | defaultPhone.getAllowedCarriers(onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1704 | break; |
| 1705 | |
| 1706 | case EVENT_GET_ALLOWED_CARRIERS_DONE: |
| 1707 | ar = (AsyncResult) msg.obj; |
| 1708 | request = (MainThreadRequest) ar.userObj; |
| 1709 | if (ar.exception == null && ar.result != null) { |
| 1710 | request.result = ar.result; |
| 1711 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1712 | request.result = new IllegalStateException( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 1713 | "Failed to get carrier restrictions"); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1714 | if (ar.result == null) { |
| 1715 | loge("getAllowedCarriers: Empty response"); |
| 1716 | } else if (ar.exception instanceof CommandException) { |
| 1717 | loge("getAllowedCarriers: CommandException: " + |
| 1718 | ar.exception); |
| 1719 | } else { |
| 1720 | loge("getAllowedCarriers: Unknown exception"); |
| 1721 | } |
| 1722 | } |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 1723 | if (request.argument != null) { |
| 1724 | // This is for the implementation of carrierRestrictionStatus. |
| 1725 | CallerCallbackInfo callbackInfo = (CallerCallbackInfo) request.argument; |
| 1726 | Consumer<Integer> callback = callbackInfo.getConsumer(); |
| 1727 | int callerCarrierId = callbackInfo.getCarrierId(); |
| 1728 | int lockStatus = TelephonyManager.CARRIER_RESTRICTION_STATUS_UNKNOWN; |
| 1729 | if (ar.exception == null && ar.result instanceof CarrierRestrictionRules) { |
| 1730 | CarrierRestrictionRules carrierRestrictionRules = |
| 1731 | (CarrierRestrictionRules) ar.result; |
| 1732 | int carrierId = -1; |
| 1733 | try { |
| 1734 | CarrierIdentifier carrierIdentifier = |
| 1735 | carrierRestrictionRules.getAllowedCarriers().get(0); |
| 1736 | carrierId = CarrierResolver.getCarrierIdFromIdentifier(mApp, |
| 1737 | carrierIdentifier); |
| 1738 | } catch (NullPointerException | IndexOutOfBoundsException ex) { |
| 1739 | Rlog.e(LOG_TAG, "CarrierIdentifier exception = " + ex); |
| 1740 | } |
| 1741 | lockStatus = carrierRestrictionRules.getCarrierRestrictionStatus(); |
| 1742 | if (carrierId != -1 && callerCarrierId == carrierId && lockStatus |
| 1743 | == TelephonyManager.CARRIER_RESTRICTION_STATUS_RESTRICTED) { |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 1744 | lockStatus = TelephonyManager |
| 1745 | .CARRIER_RESTRICTION_STATUS_RESTRICTED_TO_CALLER; |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 1746 | } |
| 1747 | } else { |
| 1748 | Rlog.e(LOG_TAG, |
| 1749 | "getCarrierRestrictionStatus: exception ex = " + ar.exception); |
| 1750 | } |
| 1751 | callback.accept(lockStatus); |
| 1752 | } else { |
| 1753 | // This is for the implementation of getAllowedCarriers. |
| 1754 | notifyRequester(request); |
| 1755 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1756 | break; |
| 1757 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1758 | case EVENT_GET_FORBIDDEN_PLMNS_DONE: |
| 1759 | ar = (AsyncResult) msg.obj; |
| 1760 | request = (MainThreadRequest) ar.userObj; |
| 1761 | if (ar.exception == null && ar.result != null) { |
| 1762 | request.result = ar.result; |
| 1763 | } else { |
| 1764 | request.result = new IllegalArgumentException( |
| 1765 | "Failed to retrieve Forbidden Plmns"); |
| 1766 | if (ar.result == null) { |
| 1767 | loge("getForbiddenPlmns: Empty response"); |
| 1768 | } else { |
| 1769 | loge("getForbiddenPlmns: Unknown exception"); |
| 1770 | } |
| 1771 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1772 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1773 | break; |
| 1774 | |
| 1775 | case CMD_GET_FORBIDDEN_PLMNS: |
| 1776 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1777 | uiccPort = getUiccPortFromRequest(request); |
| 1778 | if (uiccPort == null) { |
| 1779 | loge("getForbiddenPlmns() UiccPort is null"); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1780 | request.result = new IllegalArgumentException( |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1781 | "getForbiddenPlmns() UiccPort is null"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1782 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1783 | break; |
| 1784 | } |
| 1785 | Integer appType = (Integer) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1786 | UiccCardApplication uiccApp = uiccPort.getApplicationByType(appType); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1787 | if (uiccApp == null) { |
| 1788 | loge("getForbiddenPlmns() no app with specified type -- " |
| 1789 | + appType); |
| 1790 | request.result = new IllegalArgumentException("Failed to get UICC App"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1791 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1792 | break; |
| 1793 | } else { |
| 1794 | if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid() |
| 1795 | + " specified type -- " + appType); |
| 1796 | } |
| 1797 | onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request); |
| 1798 | ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 1799 | onCompleted); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1800 | break; |
| 1801 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1802 | case CMD_SWITCH_SLOTS: |
| 1803 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 1804 | List<UiccSlotMapping> slotMapping = (List<UiccSlotMapping>) request.argument; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1805 | onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 1806 | UiccController.getInstance().switchSlots(slotMapping, onCompleted); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1807 | break; |
| 1808 | |
| 1809 | case EVENT_SWITCH_SLOTS_DONE: |
| 1810 | ar = (AsyncResult) msg.obj; |
| 1811 | request = (MainThreadRequest) ar.userObj; |
| 1812 | request.result = (ar.exception == null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1813 | notifyRequester(request); |
| 1814 | break; |
| 1815 | case CMD_GET_NETWORK_SELECTION_MODE: |
| 1816 | request = (MainThreadRequest) msg.obj; |
| 1817 | onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request); |
| 1818 | getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted); |
| 1819 | break; |
| 1820 | |
| 1821 | case EVENT_GET_NETWORK_SELECTION_MODE_DONE: |
| 1822 | ar = (AsyncResult) msg.obj; |
| 1823 | request = (MainThreadRequest) ar.userObj; |
| 1824 | if (ar.exception != null) { |
| 1825 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 1826 | } else { |
| 1827 | int mode = ((int[]) ar.result)[0]; |
| 1828 | if (mode == 0) { |
| 1829 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO; |
| 1830 | } else { |
| 1831 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL; |
| 1832 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1833 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1834 | notifyRequester(request); |
| 1835 | break; |
| 1836 | case CMD_GET_CDMA_ROAMING_MODE: |
| 1837 | request = (MainThreadRequest) msg.obj; |
| 1838 | onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request); |
| 1839 | getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted); |
| 1840 | break; |
| 1841 | case EVENT_GET_CDMA_ROAMING_MODE_DONE: |
| 1842 | ar = (AsyncResult) msg.obj; |
| 1843 | request = (MainThreadRequest) ar.userObj; |
| 1844 | if (ar.exception != null) { |
| 1845 | request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT; |
| 1846 | } else { |
| 1847 | request.result = ((int[]) ar.result)[0]; |
| 1848 | } |
| 1849 | notifyRequester(request); |
| 1850 | break; |
| 1851 | case CMD_SET_CDMA_ROAMING_MODE: |
| 1852 | request = (MainThreadRequest) msg.obj; |
| 1853 | onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request); |
| 1854 | int mode = (int) request.argument; |
| 1855 | getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted); |
| 1856 | break; |
| 1857 | case EVENT_SET_CDMA_ROAMING_MODE_DONE: |
| 1858 | ar = (AsyncResult) msg.obj; |
| 1859 | request = (MainThreadRequest) ar.userObj; |
| 1860 | request.result = ar.exception == null; |
| 1861 | notifyRequester(request); |
| 1862 | break; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 1863 | case CMD_GET_CDMA_SUBSCRIPTION_MODE: |
| 1864 | request = (MainThreadRequest) msg.obj; |
| 1865 | onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1866 | getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted); |
| 1867 | break; |
| 1868 | case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1869 | ar = (AsyncResult) msg.obj; |
| 1870 | request = (MainThreadRequest) ar.userObj; |
| 1871 | if (ar.exception != null) { |
| 1872 | request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM; |
| 1873 | } else { |
| 1874 | request.result = ((int[]) ar.result)[0]; |
| 1875 | } |
| 1876 | notifyRequester(request); |
| 1877 | break; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1878 | case CMD_SET_CDMA_SUBSCRIPTION_MODE: |
| 1879 | request = (MainThreadRequest) msg.obj; |
| 1880 | onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1881 | int subscriptionMode = (int) request.argument; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 1882 | getPhoneFromRequest(request).setCdmaSubscriptionMode( |
| 1883 | subscriptionMode, onCompleted); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1884 | break; |
| 1885 | case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1886 | ar = (AsyncResult) msg.obj; |
| 1887 | request = (MainThreadRequest) ar.userObj; |
| 1888 | request.result = ar.exception == null; |
| 1889 | notifyRequester(request); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1890 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1891 | case CMD_GET_ALL_CELL_INFO: |
| 1892 | request = (MainThreadRequest) msg.obj; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1893 | onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1894 | request.phone.requestCellInfoUpdate(request.workSource, onCompleted); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1895 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1896 | case EVENT_GET_ALL_CELL_INFO_DONE: |
| 1897 | ar = (AsyncResult) msg.obj; |
| 1898 | request = (MainThreadRequest) ar.userObj; |
Nathan Harold | 8d0f174 | 2018-10-02 12:14:47 -0700 | [diff] [blame] | 1899 | // If a timeout occurs, the response will be null |
| 1900 | request.result = (ar.exception == null && ar.result != null) |
| 1901 | ? ar.result : new ArrayList<CellInfo>(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1902 | synchronized (request) { |
| 1903 | request.notifyAll(); |
| 1904 | } |
| 1905 | break; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1906 | case CMD_REQUEST_CELL_INFO_UPDATE: |
| 1907 | request = (MainThreadRequest) msg.obj; |
| 1908 | request.phone.requestCellInfoUpdate(request.workSource, |
| 1909 | obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request)); |
| 1910 | break; |
| 1911 | case EVENT_REQUEST_CELL_INFO_UPDATE_DONE: |
| 1912 | ar = (AsyncResult) msg.obj; |
| 1913 | request = (MainThreadRequest) ar.userObj; |
| 1914 | ICellInfoCallback cb = (ICellInfoCallback) request.argument; |
| 1915 | try { |
| 1916 | if (ar.exception != null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1917 | Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception); |
Meng Wang | d8921f4 | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1918 | cb.onError( |
| 1919 | TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR, |
| 1920 | ar.exception.getClass().getName(), |
| 1921 | ar.exception.toString()); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1922 | } else if (ar.result == null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1923 | Log.w(LOG_TAG, "Timeout Waiting for CellInfo!"); |
Meng Wang | d8921f4 | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1924 | cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1925 | } else { |
| 1926 | // use the result as returned |
| 1927 | cb.onCellInfo((List<CellInfo>) ar.result); |
| 1928 | } |
| 1929 | } catch (RemoteException re) { |
| 1930 | Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException"); |
| 1931 | } |
| 1932 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1933 | case CMD_GET_CELL_LOCATION: { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1934 | request = (MainThreadRequest) msg.obj; |
| 1935 | WorkSource ws = (WorkSource) request.argument; |
| 1936 | Phone phone = getPhoneFromRequest(request); |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1937 | phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request)); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1938 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1939 | } |
| 1940 | case EVENT_GET_CELL_LOCATION_DONE: { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1941 | ar = (AsyncResult) msg.obj; |
| 1942 | request = (MainThreadRequest) ar.userObj; |
| 1943 | if (ar.exception == null) { |
| 1944 | request.result = ar.result; |
| 1945 | } else { |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1946 | Phone phone = getPhoneFromRequest(request); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1947 | request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1948 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1949 | } |
| 1950 | |
| 1951 | synchronized (request) { |
| 1952 | request.notifyAll(); |
| 1953 | } |
| 1954 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1955 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1956 | case CMD_MODEM_REBOOT: |
| 1957 | request = (MainThreadRequest) msg.obj; |
| 1958 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1959 | defaultPhone.rebootModem(onCompleted); |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1960 | break; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1961 | case EVENT_CMD_MODEM_REBOOT_DONE: |
| 1962 | handleNullReturnEvent(msg, "rebootModem"); |
| 1963 | break; |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame^] | 1964 | case CMD_REQUEST_ENABLE_MODEM: { |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1965 | request = (MainThreadRequest) msg.obj; |
| 1966 | boolean enable = (boolean) request.argument; |
| 1967 | onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1968 | onCompleted.arg1 = enable ? 1 : 0; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1969 | PhoneConfigurationManager.getInstance() |
| 1970 | .enablePhone(request.phone, enable, onCompleted); |
| 1971 | break; |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame^] | 1972 | } |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1973 | case EVENT_ENABLE_MODEM_DONE: { |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1974 | ar = (AsyncResult) msg.obj; |
| 1975 | request = (MainThreadRequest) ar.userObj; |
| 1976 | request.result = (ar.exception == null); |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1977 | int phoneId = request.phone.getPhoneId(); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1978 | //update the cache as modem status has changed |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1979 | if ((boolean) request.result) { |
| 1980 | mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1); |
| 1981 | updateModemStateMetrics(); |
| 1982 | } else { |
| 1983 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1984 | + ar.exception); |
| 1985 | } |
| 1986 | notifyRequester(request); |
| 1987 | break; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1988 | } |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1989 | case CMD_GET_MODEM_STATUS: |
| 1990 | request = (MainThreadRequest) msg.obj; |
| 1991 | onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request); |
| 1992 | PhoneConfigurationManager.getInstance() |
| 1993 | .getPhoneStatusFromModem(request.phone, onCompleted); |
| 1994 | break; |
| 1995 | case EVENT_GET_MODEM_STATUS_DONE: |
| 1996 | ar = (AsyncResult) msg.obj; |
| 1997 | request = (MainThreadRequest) ar.userObj; |
| 1998 | int id = request.phone.getPhoneId(); |
| 1999 | if (ar.exception == null && ar.result != null) { |
| 2000 | request.result = ar.result; |
| 2001 | //update the cache as modem status has changed |
| 2002 | mPhoneConfigurationManager.addToPhoneStatusCache(id, |
| 2003 | (boolean) request.result); |
| 2004 | } else { |
| 2005 | // Return true if modem status cannot be retrieved. For most cases, |
| 2006 | // modem status is on. And for older version modems, GET_MODEM_STATUS |
| 2007 | // and disable modem are not supported. Modem is always on. |
| 2008 | // TODO: this should be fixed in R to support a third |
| 2009 | // status UNKNOWN b/131631629 |
| 2010 | request.result = true; |
| 2011 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 2012 | + ar.exception); |
| 2013 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 2014 | notifyRequester(request); |
| 2015 | break; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 2016 | case CMD_SET_SYSTEM_SELECTION_CHANNELS: { |
| 2017 | request = (MainThreadRequest) msg.obj; |
| 2018 | onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request); |
| 2019 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 2020 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 2021 | request.phone.setSystemSelectionChannels(args.first, onCompleted); |
| 2022 | break; |
| 2023 | } |
| 2024 | case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: { |
| 2025 | ar = (AsyncResult) msg.obj; |
| 2026 | request = (MainThreadRequest) ar.userObj; |
| 2027 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 2028 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 2029 | args.second.accept(ar.exception == null); |
| 2030 | notifyRequester(request); |
| 2031 | break; |
| 2032 | } |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 2033 | case CMD_GET_SYSTEM_SELECTION_CHANNELS: { |
| 2034 | request = (MainThreadRequest) msg.obj; |
| 2035 | onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request); |
| 2036 | Phone phone = getPhoneFromRequest(request); |
| 2037 | if (phone != null) { |
| 2038 | phone.getSystemSelectionChannels(onCompleted); |
| 2039 | } else { |
| 2040 | loge("getSystemSelectionChannels: No phone object"); |
| 2041 | request.result = new ArrayList<RadioAccessSpecifier>(); |
| 2042 | notifyRequester(request); |
| 2043 | } |
| 2044 | break; |
| 2045 | } |
| 2046 | case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE: |
| 2047 | ar = (AsyncResult) msg.obj; |
| 2048 | request = (MainThreadRequest) ar.userObj; |
| 2049 | if (ar.exception == null && ar.result != null) { |
| 2050 | request.result = ar.result; |
| 2051 | } else { |
Sarah Chin | 428d1d6 | 2021-03-13 03:17:40 -0800 | [diff] [blame] | 2052 | request.result = new IllegalStateException( |
| 2053 | "Failed to retrieve system selecton channels"); |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 2054 | if (ar.result == null) { |
| 2055 | loge("getSystemSelectionChannels: Empty response"); |
| 2056 | } else { |
| 2057 | loge("getSystemSelectionChannels: Unknown exception"); |
| 2058 | } |
| 2059 | } |
| 2060 | notifyRequester(request); |
| 2061 | break; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 2062 | case EVENT_SET_FORBIDDEN_PLMNS_DONE: |
| 2063 | ar = (AsyncResult) msg.obj; |
| 2064 | request = (MainThreadRequest) ar.userObj; |
| 2065 | if (ar.exception == null && ar.result != null) { |
| 2066 | request.result = ar.result; |
| 2067 | } else { |
| 2068 | request.result = -1; |
| 2069 | loge("Failed to set Forbidden Plmns"); |
| 2070 | if (ar.result == null) { |
| 2071 | loge("setForbidenPlmns: Empty response"); |
| 2072 | } else if (ar.exception != null) { |
| 2073 | loge("setForbiddenPlmns: Exception: " + ar.exception); |
| 2074 | request.result = -1; |
| 2075 | } else { |
| 2076 | loge("setForbiddenPlmns: Unknown exception"); |
| 2077 | } |
| 2078 | } |
| 2079 | notifyRequester(request); |
| 2080 | break; |
| 2081 | case CMD_SET_FORBIDDEN_PLMNS: |
| 2082 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 2083 | uiccPort = getUiccPortFromRequest(request); |
| 2084 | if (uiccPort == null) { |
| 2085 | loge("setForbiddenPlmns: UiccPort is null"); |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 2086 | request.result = -1; |
| 2087 | notifyRequester(request); |
| 2088 | break; |
| 2089 | } |
| 2090 | Pair<Integer, List<String>> setFplmnsArgs = |
| 2091 | (Pair<Integer, List<String>>) request.argument; |
| 2092 | appType = setFplmnsArgs.first; |
| 2093 | List<String> fplmns = setFplmnsArgs.second; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 2094 | uiccApp = uiccPort.getApplicationByType(appType); |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 2095 | if (uiccApp == null) { |
| 2096 | loge("setForbiddenPlmns: no app with specified type -- " + appType); |
| 2097 | request.result = -1; |
| 2098 | loge("Failed to get UICC App"); |
| 2099 | notifyRequester(request); |
| 2100 | } else { |
| 2101 | onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request); |
| 2102 | ((SIMRecords) uiccApp.getIccRecords()) |
| 2103 | .setForbiddenPlmns(onCompleted, fplmns); |
| 2104 | } |
yinchengzhao | 4d163c0 | 2019-12-12 15:21:47 -0800 | [diff] [blame] | 2105 | break; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 2106 | case CMD_ERASE_MODEM_CONFIG: |
| 2107 | request = (MainThreadRequest) msg.obj; |
| 2108 | onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request); |
| 2109 | defaultPhone.eraseModemConfig(onCompleted); |
| 2110 | break; |
| 2111 | case EVENT_ERASE_MODEM_CONFIG_DONE: |
| 2112 | handleNullReturnEvent(msg, "eraseModemConfig"); |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 2113 | break; |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 2114 | |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 2115 | case CMD_ERASE_DATA_SHARED_PREFERENCES: |
| 2116 | request = (MainThreadRequest) msg.obj; |
| 2117 | request.result = defaultPhone.eraseDataInSharedPreferences(); |
| 2118 | notifyRequester(request); |
| 2119 | break; |
| 2120 | |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 2121 | case CMD_CHANGE_ICC_LOCK_PASSWORD: |
| 2122 | request = (MainThreadRequest) msg.obj; |
| 2123 | onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request); |
| 2124 | Pair<String, String> changed = (Pair<String, String>) request.argument; |
| 2125 | getPhoneFromRequest(request).getIccCard().changeIccLockPassword( |
| 2126 | changed.first, changed.second, onCompleted); |
| 2127 | break; |
| 2128 | case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE: |
| 2129 | ar = (AsyncResult) msg.obj; |
| 2130 | request = (MainThreadRequest) ar.userObj; |
| 2131 | if (ar.exception == null) { |
| 2132 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2133 | // If the operation is successful, update the PIN storage |
| 2134 | Pair<String, String> passwords = (Pair<String, String>) request.argument; |
| 2135 | int phoneId = getPhoneFromRequest(request).getPhoneId(); |
Jon Spivack | 9c3bc76 | 2021-10-06 20:53:09 +0000 | [diff] [blame] | 2136 | UiccController.getInstance().getPinStorage() |
| 2137 | .storePin(passwords.second, phoneId); |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 2138 | } else { |
| 2139 | request.result = msg.arg1; |
| 2140 | } |
| 2141 | notifyRequester(request); |
| 2142 | break; |
| 2143 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2144 | case CMD_SET_ICC_LOCK_ENABLED: { |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 2145 | request = (MainThreadRequest) msg.obj; |
| 2146 | onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request); |
| 2147 | Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument; |
| 2148 | getPhoneFromRequest(request).getIccCard().setIccLockEnabled( |
| 2149 | enabled.first, enabled.second, onCompleted); |
| 2150 | break; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2151 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 2152 | case EVENT_SET_ICC_LOCK_ENABLED_DONE: |
| 2153 | ar = (AsyncResult) msg.obj; |
| 2154 | request = (MainThreadRequest) ar.userObj; |
| 2155 | if (ar.exception == null) { |
| 2156 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2157 | // If the operation is successful, update the PIN storage |
| 2158 | Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument; |
| 2159 | int phoneId = getPhoneFromRequest(request).getPhoneId(); |
| 2160 | if (enabled.first) { |
Jon Spivack | 9c3bc76 | 2021-10-06 20:53:09 +0000 | [diff] [blame] | 2161 | UiccController.getInstance().getPinStorage() |
| 2162 | .storePin(enabled.second, phoneId); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2163 | } else { |
| 2164 | UiccController.getInstance().getPinStorage().clearPin(phoneId); |
| 2165 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 2166 | } else { |
| 2167 | request.result = msg.arg1; |
| 2168 | } |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2169 | |
| 2170 | |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 2171 | notifyRequester(request); |
| 2172 | break; |
| 2173 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 2174 | case MSG_NOTIFY_USER_ACTIVITY: |
| 2175 | removeMessages(MSG_NOTIFY_USER_ACTIVITY); |
Peter Wang | 59571be | 2020-01-27 12:35:15 +0800 | [diff] [blame] | 2176 | Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION); |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 2177 | intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY); |
| 2178 | getDefaultPhone().getContext().sendBroadcastAsUser( |
| 2179 | intent, UserHandle.ALL, permission.USER_ACTIVITY); |
| 2180 | break; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 2181 | |
| 2182 | case CMD_SET_DATA_THROTTLING: { |
| 2183 | request = (MainThreadRequest) msg.obj; |
| 2184 | onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request); |
| 2185 | DataThrottlingRequest dataThrottlingRequest = |
| 2186 | (DataThrottlingRequest) request.argument; |
| 2187 | Phone phone = getPhoneFromRequest(request); |
| 2188 | if (phone != null) { |
| 2189 | phone.setDataThrottling(onCompleted, |
| 2190 | request.workSource, dataThrottlingRequest.getDataThrottlingAction(), |
| 2191 | dataThrottlingRequest.getCompletionDurationMillis()); |
| 2192 | } else { |
| 2193 | loge("setDataThrottling: No phone object"); |
| 2194 | request.result = |
| 2195 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 2196 | notifyRequester(request); |
| 2197 | } |
| 2198 | |
| 2199 | break; |
| 2200 | } |
| 2201 | case EVENT_SET_DATA_THROTTLING_DONE: |
| 2202 | ar = (AsyncResult) msg.obj; |
| 2203 | request = (MainThreadRequest) ar.userObj; |
| 2204 | |
| 2205 | if (ar.exception == null) { |
| 2206 | request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 2207 | } else if (ar.exception instanceof CommandException) { |
| 2208 | loge("setDataThrottling: CommandException: " + ar.exception); |
| 2209 | CommandException.Error error = |
| 2210 | ((CommandException) (ar.exception)).getCommandError(); |
| 2211 | |
| 2212 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 2213 | request.result = TelephonyManager |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2214 | .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 2215 | } else if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 2216 | request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS; |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 2217 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 2218 | request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 2219 | } else { |
| 2220 | request.result = |
| 2221 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 2222 | } |
| 2223 | } else { |
| 2224 | request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 2225 | } |
| 2226 | Log.w(LOG_TAG, "DataThrottlingResult = " + request.result); |
| 2227 | notifyRequester(request); |
| 2228 | break; |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 2229 | |
| 2230 | case CMD_SET_SIM_POWER: { |
| 2231 | request = (MainThreadRequest) msg.obj; |
| 2232 | onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request); |
| 2233 | request = (MainThreadRequest) msg.obj; |
| 2234 | int stateToSet = |
| 2235 | ((Pair<Integer, IIntegerConsumer>) |
| 2236 | request.argument).first; |
| 2237 | request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource); |
| 2238 | break; |
| 2239 | } |
| 2240 | case EVENT_SET_SIM_POWER_DONE: { |
| 2241 | ar = (AsyncResult) msg.obj; |
| 2242 | request = (MainThreadRequest) ar.userObj; |
| 2243 | IIntegerConsumer callback = |
| 2244 | ((Pair<Integer, IIntegerConsumer>) request.argument).second; |
| 2245 | if (ar.exception != null) { |
| 2246 | loge("setSimPower exception: " + ar.exception); |
| 2247 | int errorCode = TelephonyManager.CallForwardingInfoCallback |
| 2248 | .RESULT_ERROR_UNKNOWN; |
| 2249 | if (ar.exception instanceof CommandException) { |
| 2250 | CommandException.Error error = |
| 2251 | ((CommandException) (ar.exception)).getCommandError(); |
| 2252 | if (error == CommandException.Error.SIM_ERR) { |
| 2253 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR; |
| 2254 | } else if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 2255 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE; |
| 2256 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 2257 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED; |
| 2258 | } else { |
| 2259 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR; |
| 2260 | } |
| 2261 | } |
| 2262 | try { |
| 2263 | callback.accept(errorCode); |
| 2264 | } catch (RemoteException e) { |
| 2265 | // Ignore if the remote process is no longer available to call back. |
| 2266 | Log.w(LOG_TAG, "setSimPower: callback not available."); |
| 2267 | } |
| 2268 | } else { |
| 2269 | try { |
| 2270 | callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS); |
| 2271 | } catch (RemoteException e) { |
| 2272 | // Ignore if the remote process is no longer available to call back. |
| 2273 | Log.w(LOG_TAG, "setSimPower: callback not available."); |
| 2274 | } |
| 2275 | } |
| 2276 | break; |
| 2277 | } |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 2278 | case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: { |
| 2279 | request = (MainThreadRequest) msg.obj; |
| 2280 | |
| 2281 | final Phone phone = getPhoneFromRequest(request); |
| 2282 | if (phone == null || phone.getServiceStateTracker() == null) { |
| 2283 | request.result = new IllegalStateException("Phone or SST is null"); |
| 2284 | notifyRequester(request); |
| 2285 | break; |
| 2286 | } |
| 2287 | |
| 2288 | Pair<Integer, SignalStrengthUpdateRequest> pair = |
| 2289 | (Pair<Integer, SignalStrengthUpdateRequest>) request.argument; |
| 2290 | onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE, |
| 2291 | request); |
Rambo Wang | 6568f17 | 2021-02-03 16:56:47 -0800 | [diff] [blame] | 2292 | phone.getSignalStrengthController().setSignalStrengthUpdateRequest( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2293 | request.subId, pair.first /*callingUid*/, |
| 2294 | pair.second /*request*/, onCompleted); |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 2295 | break; |
| 2296 | } |
| 2297 | case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: { |
| 2298 | ar = (AsyncResult) msg.obj; |
| 2299 | request = (MainThreadRequest) ar.userObj; |
| 2300 | // request.result will be the exception of ar if present, true otherwise. |
| 2301 | // Be cautious not to leave result null which will wait() forever |
| 2302 | request.result = ar.exception != null ? ar.exception : true; |
| 2303 | notifyRequester(request); |
| 2304 | break; |
| 2305 | } |
| 2306 | case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: { |
| 2307 | request = (MainThreadRequest) msg.obj; |
| 2308 | |
| 2309 | Phone phone = getPhoneFromRequest(request); |
| 2310 | if (phone == null || phone.getServiceStateTracker() == null) { |
| 2311 | request.result = new IllegalStateException("Phone or SST is null"); |
| 2312 | notifyRequester(request); |
| 2313 | break; |
| 2314 | } |
| 2315 | |
| 2316 | Pair<Integer, SignalStrengthUpdateRequest> pair = |
| 2317 | (Pair<Integer, SignalStrengthUpdateRequest>) request.argument; |
| 2318 | onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE, |
| 2319 | request); |
Rambo Wang | 6568f17 | 2021-02-03 16:56:47 -0800 | [diff] [blame] | 2320 | phone.getSignalStrengthController().clearSignalStrengthUpdateRequest( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2321 | request.subId, pair.first /*callingUid*/, |
| 2322 | pair.second /*request*/, onCompleted); |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 2323 | break; |
| 2324 | } |
| 2325 | case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: { |
| 2326 | ar = (AsyncResult) msg.obj; |
| 2327 | request = (MainThreadRequest) ar.userObj; |
| 2328 | request.result = ar.exception != null ? ar.exception : true; |
| 2329 | notifyRequester(request); |
| 2330 | break; |
| 2331 | } |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 2332 | |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2333 | case CMD_GET_SLICING_CONFIG: { |
| 2334 | request = (MainThreadRequest) msg.obj; |
| 2335 | onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request); |
| 2336 | request.phone.getSlicingConfig(onCompleted); |
| 2337 | break; |
| 2338 | } |
| 2339 | case EVENT_GET_SLICING_CONFIG_DONE: { |
| 2340 | ar = (AsyncResult) msg.obj; |
| 2341 | request = (MainThreadRequest) ar.userObj; |
| 2342 | ResultReceiver result = (ResultReceiver) request.argument; |
| 2343 | |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2344 | NetworkSlicingConfig slicingConfig = null; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2345 | Bundle bundle = new Bundle(); |
| 2346 | int resultCode = 0; |
| 2347 | if (ar.exception != null) { |
| 2348 | Log.e(LOG_TAG, "Exception retrieving slicing configuration=" |
| 2349 | + ar.exception); |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2350 | resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2351 | } else if (ar.result == null) { |
| 2352 | Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!"); |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2353 | resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2354 | } else { |
| 2355 | // use the result as returned |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2356 | resultCode = TelephonyManager.NetworkSlicingException.SUCCESS; |
| 2357 | slicingConfig = (NetworkSlicingConfig) ar.result; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2358 | } |
| 2359 | |
| 2360 | if (slicingConfig == null) { |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2361 | slicingConfig = new NetworkSlicingConfig(); |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2362 | } |
| 2363 | bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig); |
| 2364 | result.send(resultCode, bundle); |
| 2365 | notifyRequester(request); |
| 2366 | break; |
| 2367 | } |
| 2368 | |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2369 | case CMD_PURCHASE_PREMIUM_CAPABILITY: { |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2370 | request = (MainThreadRequest) msg.obj; |
| 2371 | onCompleted = obtainMessage(EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE, request); |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2372 | PurchasePremiumCapabilityArgument arg = |
| 2373 | (PurchasePremiumCapabilityArgument) request.argument; |
Sarah Chin | 46355ba | 2022-11-01 23:51:16 -0700 | [diff] [blame] | 2374 | SlicePurchaseController.getInstance(request.phone).purchasePremiumCapability( |
Sarah Chin | b8218c2 | 2023-01-04 13:35:29 -0800 | [diff] [blame] | 2375 | arg.capability, onCompleted); |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2376 | break; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2377 | } |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2378 | |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2379 | case EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE: { |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2380 | ar = (AsyncResult) msg.obj; |
| 2381 | request = (MainThreadRequest) ar.userObj; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2382 | PurchasePremiumCapabilityArgument arg = |
| 2383 | (PurchasePremiumCapabilityArgument) request.argument; |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2384 | try { |
| 2385 | int result = (int) ar.result; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2386 | arg.callback.accept(result); |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2387 | log("purchasePremiumCapability: capability=" |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2388 | + TelephonyManager.convertPremiumCapabilityToString(arg.capability) |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2389 | + ", result= " |
| 2390 | + TelephonyManager.convertPurchaseResultToString(result)); |
| 2391 | } catch (RemoteException e) { |
| 2392 | String logStr = "Purchase premium capability " |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2393 | + TelephonyManager.convertPremiumCapabilityToString(arg.capability) |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2394 | + " failed: " + e; |
| 2395 | if (DBG) log(logStr); |
| 2396 | AnomalyReporter.reportAnomaly( |
| 2397 | UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr); |
| 2398 | } |
| 2399 | break; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2400 | } |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2401 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2402 | case CMD_PREPARE_UNATTENDED_REBOOT: |
| 2403 | request = (MainThreadRequest) msg.obj; |
| 2404 | request.result = |
Rafael Higuera Silva | d963064 | 2021-09-20 15:32:01 +0000 | [diff] [blame] | 2405 | UiccController.getInstance().getPinStorage() |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2406 | .prepareUnattendedReboot(request.workSource); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2407 | notifyRequester(request); |
| 2408 | break; |
| 2409 | |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 2410 | case CMD_START_SATELLITE_POSITION_UPDATES: { |
| 2411 | request = (MainThreadRequest) msg.obj; |
| 2412 | onCompleted = |
| 2413 | obtainMessage(EVENT_START_SATELLITE_POSITION_UPDATES_DONE, request); |
| 2414 | Phone phone = getPhoneFromRequest(request); |
| 2415 | if (phone != null) { |
| 2416 | phone.startSatellitePositionUpdates(onCompleted); |
| 2417 | } else { |
| 2418 | loge("startSatellitePositionUpdates: No phone object"); |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame^] | 2419 | ((Consumer<Integer>) request.argument).accept( |
| 2420 | SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE); |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 2421 | } |
| 2422 | break; |
| 2423 | } |
| 2424 | |
| 2425 | case EVENT_START_SATELLITE_POSITION_UPDATES_DONE: { |
| 2426 | ar = (AsyncResult) msg.obj; |
| 2427 | request = (MainThreadRequest) ar.userObj; |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame^] | 2428 | int error = getSatelliteError(ar, "startSatellitePositionUpdates", false); |
| 2429 | ((Consumer<Integer>) request.argument).accept(error); |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 2430 | break; |
| 2431 | } |
| 2432 | |
| 2433 | case CMD_STOP_SATELLITE_POSITION_UPDATES: { |
| 2434 | request = (MainThreadRequest) msg.obj; |
| 2435 | onCompleted = |
| 2436 | obtainMessage(EVENT_STOP_SATELLITE_POSITION_UPDATES_DONE, request); |
| 2437 | Phone phone = getPhoneFromRequest(request); |
| 2438 | if (phone != null) { |
| 2439 | phone.stopSatellitePositionUpdates(onCompleted); |
| 2440 | } else { |
| 2441 | loge("stopSatellitePositionUpdates: No phone object"); |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame^] | 2442 | ((Consumer<Integer>) request.argument).accept( |
| 2443 | SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE); |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 2444 | } |
| 2445 | break; |
| 2446 | } |
| 2447 | |
| 2448 | case EVENT_STOP_SATELLITE_POSITION_UPDATES_DONE: { |
| 2449 | ar = (AsyncResult) msg.obj; |
| 2450 | request = (MainThreadRequest) ar.userObj; |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame^] | 2451 | int error = getSatelliteError(ar, "stopSatellitePositionUpdates", false); |
| 2452 | ((Consumer<Integer>) request.argument).accept(error); |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 2453 | break; |
| 2454 | } |
| 2455 | |
Aishwarya Mallampati | 60fe113 | 2023-01-24 19:07:21 +0000 | [diff] [blame] | 2456 | case CMD_GET_MAX_CHAR_PER_SATELLITE_TEXT_MSG: { |
| 2457 | request = (MainThreadRequest) msg.obj; |
| 2458 | onCompleted = obtainMessage(EVENT_GET_MAX_CHAR_PER_SATELLITE_TEXT_MSG_DONE, |
| 2459 | request); |
| 2460 | Phone phone = getPhoneFromRequest(request); |
| 2461 | if (phone != null) { |
| 2462 | phone.getMaxCharactersPerSatelliteTextMessage(onCompleted); |
| 2463 | } else { |
| 2464 | loge("getMaxCharactersPerSatelliteTextMessage: No phone object"); |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame^] | 2465 | ((ResultReceiver) request.argument).send( |
| 2466 | SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE, null); |
Aishwarya Mallampati | 60fe113 | 2023-01-24 19:07:21 +0000 | [diff] [blame] | 2467 | } |
| 2468 | break; |
| 2469 | } |
| 2470 | |
| 2471 | case EVENT_GET_MAX_CHAR_PER_SATELLITE_TEXT_MSG_DONE: { |
| 2472 | ar = (AsyncResult) msg.obj; |
| 2473 | request = (MainThreadRequest) ar.userObj; |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame^] | 2474 | int error = |
| 2475 | getSatelliteError(ar, "getMaxCharactersPerSatelliteTextMessage", true); |
| 2476 | Bundle bundle = new Bundle(); |
| 2477 | if (error == SatelliteManager.SATELLITE_ERROR_NONE) { |
Aishwarya Mallampati | 60fe113 | 2023-01-24 19:07:21 +0000 | [diff] [blame] | 2478 | int maxCharLimit = ((int[]) ar.result)[0]; |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 2479 | if (DBG) log("getMaxCharactersPerSatelliteTextMessage: " + maxCharLimit); |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame^] | 2480 | bundle.putInt(SatelliteManager.KEY_MAX_CHARACTERS_PER_SATELLITE_TEXT, |
| 2481 | maxCharLimit); |
Aishwarya Mallampati | 60fe113 | 2023-01-24 19:07:21 +0000 | [diff] [blame] | 2482 | } |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame^] | 2483 | ((ResultReceiver) request.argument).send(error, bundle); |
Aishwarya Mallampati | 60fe113 | 2023-01-24 19:07:21 +0000 | [diff] [blame] | 2484 | break; |
| 2485 | } |
| 2486 | |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2487 | case CMD_PROVISION_SATELLITE_SERVICE: { |
| 2488 | request = (MainThreadRequest) msg.obj; |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame^] | 2489 | onCompleted = obtainMessage(EVENT_PROVISION_SATELLITE_SERVICE_DONE, request); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2490 | Phone phone = getPhoneFromRequest(request); |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame^] | 2491 | ProvisionSatelliteServiceArgument argument = |
| 2492 | (ProvisionSatelliteServiceArgument) request.argument; |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2493 | if (phone != null) { |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame^] | 2494 | handleCmdProvisionSatelliteService(argument, phone, onCompleted); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2495 | } else { |
| 2496 | loge("provisionSatelliteService: No phone object"); |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame^] | 2497 | argument.callback.accept( |
| 2498 | SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2499 | notifyRequester(request); |
| 2500 | } |
| 2501 | break; |
| 2502 | } |
| 2503 | |
| 2504 | case EVENT_PROVISION_SATELLITE_SERVICE_DONE: { |
| 2505 | ar = (AsyncResult) msg.obj; |
| 2506 | request = (MainThreadRequest) ar.userObj; |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame^] | 2507 | int errorCode = getSatelliteError(ar, "provisionSatelliteService", false); |
| 2508 | ProvisionSatelliteServiceArgument argument = |
| 2509 | (ProvisionSatelliteServiceArgument) request.argument; |
| 2510 | handleEventProvisionSatelliteServiceDone(argument.subId, errorCode); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2511 | notifyRequester(request); |
| 2512 | break; |
| 2513 | } |
| 2514 | |
| 2515 | case CMD_CANCEL_PROVISION_SATELLITE_SERVICE: { |
| 2516 | request = (MainThreadRequest) msg.obj; |
| 2517 | onCompleted = |
| 2518 | obtainMessage(EVENT_CANCEL_PROVISION_SATELLITE_SERVICE_DONE, request); |
| 2519 | handleCmdCancelProvisionSatelliteService((int) request.argument, onCompleted); |
| 2520 | break; |
| 2521 | } |
| 2522 | |
| 2523 | case EVENT_CANCEL_PROVISION_SATELLITE_SERVICE_DONE: { |
| 2524 | ar = (AsyncResult) msg.obj; |
| 2525 | request = (MainThreadRequest) ar.userObj; |
| 2526 | |
| 2527 | if (ar.exception == null) { |
Thomas Nguyen | e77de6d | 2023-02-10 17:42:43 -0800 | [diff] [blame] | 2528 | request.result = SatelliteManager.SATELLITE_ERROR_NONE; |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2529 | log("cancelProvisionSatelliteService succeeded for subId=" |
| 2530 | + (int) request.argument); |
| 2531 | } else { |
Thomas Nguyen | e77de6d | 2023-02-10 17:42:43 -0800 | [diff] [blame] | 2532 | request.result = SatelliteManager.SATELLITE_ERROR; |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2533 | if (ar.exception instanceof CommandException) { |
| 2534 | CommandException.Error error = |
| 2535 | ((CommandException) (ar.exception)).getCommandError(); |
| 2536 | request.result = RILUtils.convertToSatelliteError(error); |
| 2537 | loge("cancelProvisionSatelliteService CommandException: " |
| 2538 | + ar.exception + ", error code:" + request.result); |
| 2539 | } else { |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame^] | 2540 | loge("cancelProvisionSatelliteService unknown exception: " |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2541 | + ar.exception); |
| 2542 | } |
| 2543 | } |
| 2544 | notifyRequester(request); |
| 2545 | break; |
| 2546 | } |
| 2547 | |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame^] | 2548 | case CMD_SET_SATELLITE_ENABLED: { |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2549 | request = (MainThreadRequest) msg.obj; |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame^] | 2550 | onCompleted = obtainMessage(EVENT_SET_SATELLITE_ENABLED_DONE, request); |
| 2551 | Pair<Boolean, Consumer<Integer>> argument = |
| 2552 | (Pair<Boolean, Consumer<Integer>>) request.argument; |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2553 | Phone phone = getPhoneFromRequest(request); |
| 2554 | if (phone != null) { |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame^] | 2555 | boolean enable = argument.first.booleanValue(); |
| 2556 | phone.setSatellitePower(onCompleted, enable); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2557 | } else { |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame^] | 2558 | loge("setSatelliteEnabled: No phone object"); |
| 2559 | argument.second.accept(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2560 | notifyRequester(request); |
| 2561 | } |
| 2562 | break; |
| 2563 | } |
| 2564 | |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame^] | 2565 | case EVENT_SET_SATELLITE_ENABLED_DONE: { |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2566 | ar = (AsyncResult) msg.obj; |
| 2567 | request = (MainThreadRequest) ar.userObj; |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame^] | 2568 | Pair<Boolean, Consumer<Integer>> argument = |
| 2569 | (Pair<Boolean, Consumer<Integer>>) request.argument; |
| 2570 | int error = getSatelliteError(ar, "setSatelliteEnabled", false); |
| 2571 | argument.second.accept(error); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2572 | break; |
| 2573 | } |
| 2574 | |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame^] | 2575 | case CMD_IS_SATELLITE_ENABLED: { |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 2576 | request = (MainThreadRequest) msg.obj; |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame^] | 2577 | onCompleted = obtainMessage(EVENT_IS_SATELLITE_ENABLED_DONE, request); |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 2578 | Phone phone = getPhoneFromRequest(request); |
| 2579 | if (phone != null) { |
| 2580 | phone.isSatellitePowerOn(onCompleted); |
| 2581 | } else { |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame^] | 2582 | loge("isSatelliteEnabled: No phone object"); |
| 2583 | ((ResultReceiver) request.argument).send( |
| 2584 | SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE, null); |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 2585 | } |
| 2586 | break; |
| 2587 | } |
| 2588 | |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame^] | 2589 | case EVENT_IS_SATELLITE_ENABLED_DONE: { |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 2590 | ar = (AsyncResult) msg.obj; |
| 2591 | request = (MainThreadRequest) ar.userObj; |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame^] | 2592 | int error = getSatelliteError(ar, "isSatelliteEnabled", true); |
| 2593 | Bundle bundle = new Bundle(); |
| 2594 | if (error == SatelliteManager.SATELLITE_ERROR_NONE) { |
| 2595 | boolean enabled = ((int[]) ar.result)[0] == 1; |
| 2596 | if (DBG) log("isSatelliteEnabled: " + enabled); |
| 2597 | bundle.putBoolean(SatelliteManager.KEY_SATELLITE_ENABLED, enabled); |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 2598 | } |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame^] | 2599 | ((ResultReceiver) request.argument).send(error, bundle); |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 2600 | break; |
| 2601 | } |
| 2602 | |
| 2603 | case CMD_IS_SATELLITE_SUPPORTED: { |
| 2604 | request = (MainThreadRequest) msg.obj; |
| 2605 | onCompleted = obtainMessage(EVENT_IS_SATELLITE_SUPPORTED_DONE, request); |
| 2606 | Phone phone = getPhoneFromRequest(request); |
| 2607 | if (phone != null) { |
| 2608 | phone.isSatelliteSupported(onCompleted); |
| 2609 | } else { |
| 2610 | loge("isSatelliteSupported: No phone object"); |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame^] | 2611 | ((ResultReceiver) request.argument).send( |
| 2612 | SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE, null); |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 2613 | } |
| 2614 | break; |
| 2615 | } |
| 2616 | |
| 2617 | case EVENT_IS_SATELLITE_SUPPORTED_DONE: { |
| 2618 | ar = (AsyncResult) msg.obj; |
| 2619 | request = (MainThreadRequest) ar.userObj; |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame^] | 2620 | int error = getSatelliteError(ar, "isSatelliteSupported", true); |
| 2621 | Bundle bundle = new Bundle(); |
| 2622 | if (error == SatelliteManager.SATELLITE_ERROR_NONE) { |
| 2623 | boolean supported = ((int[]) ar.result)[0] == 1; |
| 2624 | if (DBG) log("isSatelliteSupported: " + supported); |
| 2625 | bundle.putBoolean(SatelliteManager.KEY_SATELLITE_SUPPORTED, supported); |
Thomas Nguyen | e77de6d | 2023-02-10 17:42:43 -0800 | [diff] [blame] | 2626 | synchronized (mIsSatelliteSupportedLock) { |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame^] | 2627 | mIsSatelliteSupported = supported; |
| 2628 | } |
| 2629 | } else { |
| 2630 | synchronized (mIsSatelliteSupportedLock) { |
| 2631 | mIsSatelliteSupported = null; |
Thomas Nguyen | e77de6d | 2023-02-10 17:42:43 -0800 | [diff] [blame] | 2632 | } |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 2633 | } |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame^] | 2634 | ((ResultReceiver) request.argument).send(error, bundle); |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 2635 | break; |
| 2636 | } |
| 2637 | |
| 2638 | case CMD_GET_SATELLITE_CAPABILITIES: { |
| 2639 | request = (MainThreadRequest) msg.obj; |
| 2640 | onCompleted = obtainMessage(EVENT_GET_SATELLITE_CAPABILITIES_DONE, request); |
| 2641 | Phone phone = getPhoneFromRequest(request); |
| 2642 | if (phone != null) { |
| 2643 | phone.getSatelliteCapabilities(onCompleted); |
| 2644 | } else { |
| 2645 | loge("getSatelliteCapabilities: No phone object"); |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame^] | 2646 | ((ResultReceiver) request.argument).send( |
| 2647 | SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE, null); |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 2648 | } |
| 2649 | break; |
| 2650 | } |
| 2651 | |
| 2652 | case EVENT_GET_SATELLITE_CAPABILITIES_DONE: { |
| 2653 | ar = (AsyncResult) msg.obj; |
| 2654 | request = (MainThreadRequest) ar.userObj; |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame^] | 2655 | int error = getSatelliteError(ar, "getSatelliteCapabilities", true); |
| 2656 | Bundle bundle = new Bundle(); |
| 2657 | if (error == SatelliteManager.SATELLITE_ERROR_NONE) { |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 2658 | SatelliteCapabilities capabilities = (SatelliteCapabilities) ar.result; |
| 2659 | if (DBG) log("getSatelliteCapabilities: " + capabilities); |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame^] | 2660 | bundle.putParcelable(SatelliteManager.KEY_SATELLITE_CAPABILITIES, |
| 2661 | capabilities); |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 2662 | } |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame^] | 2663 | ((ResultReceiver) request.argument).send(error, bundle); |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 2664 | break; |
| 2665 | } |
| 2666 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2667 | default: |
| 2668 | Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what); |
| 2669 | break; |
| 2670 | } |
| 2671 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2672 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 2673 | private void notifyRequester(MainThreadRequest request) { |
| 2674 | synchronized (request) { |
| 2675 | request.notifyAll(); |
| 2676 | } |
| 2677 | } |
| 2678 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2679 | private void handleNullReturnEvent(Message msg, String command) { |
| 2680 | AsyncResult ar = (AsyncResult) msg.obj; |
| 2681 | MainThreadRequest request = (MainThreadRequest) ar.userObj; |
| 2682 | if (ar.exception == null) { |
| 2683 | request.result = true; |
| 2684 | } else { |
| 2685 | request.result = false; |
| 2686 | if (ar.exception instanceof CommandException) { |
| 2687 | loge(command + ": CommandException: " + ar.exception); |
| 2688 | } else { |
| 2689 | loge(command + ": Unknown exception"); |
| 2690 | } |
| 2691 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 2692 | notifyRequester(request); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2693 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2694 | } |
| 2695 | |
| 2696 | /** |
| 2697 | * Posts the specified command to be executed on the main thread, |
| 2698 | * waits for the request to complete, and returns the result. |
| 2699 | * @see #sendRequestAsync |
| 2700 | */ |
| 2701 | private Object sendRequest(int command, Object argument) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2702 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, |
| 2703 | null, -1 /*timeoutInMs*/); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 2704 | } |
| 2705 | |
| 2706 | /** |
| 2707 | * Posts the specified command to be executed on the main thread, |
| 2708 | * waits for the request to complete, and returns the result. |
| 2709 | * @see #sendRequestAsync |
| 2710 | */ |
| 2711 | private Object sendRequest(int command, Object argument, WorkSource workSource) { |
| 2712 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2713 | null, workSource, -1 /*timeoutInMs*/); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2714 | } |
| 2715 | |
| 2716 | /** |
| 2717 | * Posts the specified command to be executed on the main thread, |
| 2718 | * waits for the request to complete, and returns the result. |
| 2719 | * @see #sendRequestAsync |
| 2720 | */ |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2721 | private Object sendRequest(int command, Object argument, Integer subId) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2722 | return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/); |
| 2723 | } |
| 2724 | |
| 2725 | /** |
| 2726 | * Posts the specified command to be executed on the main thread, |
| 2727 | * waits for the request to complete for at most {@code timeoutInMs}, and returns the result |
| 2728 | * if not timeout or null otherwise. |
| 2729 | * @see #sendRequestAsync |
| 2730 | */ |
| 2731 | private @Nullable Object sendRequest(int command, Object argument, Integer subId, |
| 2732 | long timeoutInMs) { |
| 2733 | return sendRequest(command, argument, subId, null, null, timeoutInMs); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 2734 | } |
| 2735 | |
| 2736 | /** |
| 2737 | * Posts the specified command to be executed on the main thread, |
| 2738 | * waits for the request to complete, and returns the result. |
| 2739 | * @see #sendRequestAsync |
| 2740 | */ |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2741 | private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2742 | return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2743 | } |
| 2744 | |
| 2745 | /** |
| 2746 | * Posts the specified command to be executed on the main thread, |
| 2747 | * waits for the request to complete, and returns the result. |
| 2748 | * @see #sendRequestAsync |
| 2749 | */ |
| 2750 | private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2751 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, |
| 2752 | workSource, -1 /*timeoutInMs*/); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2753 | } |
| 2754 | |
| 2755 | /** |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2756 | * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is |
| 2757 | * negative, waits for the request to complete, and returns the result. Otherwise, wait for |
| 2758 | * maximum of {@code timeoutInMs} milliseconds, interrupt and return null. |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2759 | * @see #sendRequestAsync |
| 2760 | */ |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2761 | private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone, |
| 2762 | WorkSource workSource, long timeoutInMs) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2763 | if (Looper.myLooper() == mMainThreadHandler.getLooper()) { |
| 2764 | throw new RuntimeException("This method will deadlock if called from the main thread."); |
| 2765 | } |
| 2766 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2767 | MainThreadRequest request = null; |
| 2768 | if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) { |
| 2769 | throw new IllegalArgumentException("subId and phone cannot both be specified!"); |
| 2770 | } else if (phone != null) { |
| 2771 | request = new MainThreadRequest(argument, phone, workSource); |
| 2772 | } else { |
| 2773 | request = new MainThreadRequest(argument, subId, workSource); |
| 2774 | } |
| 2775 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2776 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 2777 | msg.sendToTarget(); |
| 2778 | |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2779 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2780 | synchronized (request) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2781 | if (timeoutInMs >= 0) { |
| 2782 | // Wait for at least timeoutInMs before returning null request result |
| 2783 | long now = SystemClock.elapsedRealtime(); |
| 2784 | long deadline = now + timeoutInMs; |
Grace Jia | 8a0a1e8 | 2021-05-23 22:59:52 -0700 | [diff] [blame] | 2785 | while (request.result == null && now < deadline) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2786 | try { |
| 2787 | request.wait(deadline - now); |
| 2788 | } catch (InterruptedException e) { |
| 2789 | // Do nothing, go back and check if request is completed or timeout |
| 2790 | } finally { |
| 2791 | now = SystemClock.elapsedRealtime(); |
| 2792 | } |
| 2793 | } |
| 2794 | } else { |
| 2795 | // Wait for the request to complete |
| 2796 | while (request.result == null) { |
| 2797 | try { |
| 2798 | request.wait(); |
| 2799 | } catch (InterruptedException e) { |
| 2800 | // Do nothing, go back and wait until the request is complete |
| 2801 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2802 | } |
| 2803 | } |
| 2804 | } |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2805 | if (request.result == null) { |
| 2806 | Log.wtf(LOG_TAG, |
| 2807 | "sendRequest: Blocking command timed out. Something has gone terribly wrong."); |
| 2808 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2809 | return request.result; |
| 2810 | } |
| 2811 | |
| 2812 | /** |
| 2813 | * Asynchronous ("fire and forget") version of sendRequest(): |
| 2814 | * Posts the specified command to be executed on the main thread, and |
| 2815 | * returns immediately. |
| 2816 | * @see #sendRequest |
| 2817 | */ |
| 2818 | private void sendRequestAsync(int command) { |
| 2819 | mMainThreadHandler.sendEmptyMessage(command); |
| 2820 | } |
| 2821 | |
| 2822 | /** |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2823 | * Same as {@link #sendRequestAsync(int)} except it takes an argument. |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2824 | * @see {@link #sendRequest(int)} |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2825 | */ |
| 2826 | private void sendRequestAsync(int command, Object argument) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2827 | sendRequestAsync(command, argument, null, null); |
| 2828 | } |
| 2829 | |
| 2830 | /** |
| 2831 | * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource. |
| 2832 | * @see {@link #sendRequest(int,Object)} |
| 2833 | */ |
| 2834 | private void sendRequestAsync( |
| 2835 | int command, Object argument, Phone phone, WorkSource workSource) { |
| 2836 | MainThreadRequest request = new MainThreadRequest(argument, phone, workSource); |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2837 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 2838 | msg.sendToTarget(); |
| 2839 | } |
| 2840 | |
| 2841 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2842 | * Initialize the singleton PhoneInterfaceManager instance. |
| 2843 | * This is only done once, at startup, from PhoneApp.onCreate(). |
| 2844 | */ |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2845 | /* package */ static PhoneInterfaceManager init(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2846 | synchronized (PhoneInterfaceManager.class) { |
| 2847 | if (sInstance == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2848 | sInstance = new PhoneInterfaceManager(app); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2849 | } else { |
| 2850 | Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance); |
| 2851 | } |
| 2852 | return sInstance; |
| 2853 | } |
| 2854 | } |
| 2855 | |
| 2856 | /** Private constructor; @see init() */ |
Jordan Liu | 1979a04 | 2020-03-20 21:39:35 +0000 | [diff] [blame] | 2857 | private PhoneInterfaceManager(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2858 | mApp = app; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2859 | mCM = PhoneGlobals.getInstance().mCM; |
Brad Ebinger | d1947d8 | 2021-05-17 20:54:49 +0000 | [diff] [blame] | 2860 | mImsResolver = ImsResolver.getInstance(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 2861 | mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2862 | mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 2863 | mPm = app.getSystemService(PackageManager.class); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2864 | mMainThreadHandler = new MainThreadHandler(); |
Jack Yu | e37dd26 | 2022-12-16 11:53:37 -0800 | [diff] [blame] | 2865 | if (!PhoneFactory.isSubscriptionManagerServiceEnabled()) { |
| 2866 | mSubscriptionController = SubscriptionController.getInstance(); |
| 2867 | } else { |
| 2868 | mSubscriptionController = null; |
| 2869 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2870 | mTelephonySharedPreferences = |
| 2871 | PreferenceManager.getDefaultSharedPreferences(mApp); |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 2872 | mNetworkScanRequestTracker = new NetworkScanRequestTracker(); |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 2873 | mPhoneConfigurationManager = PhoneConfigurationManager.getInstance(); |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 2874 | mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance(); |
Peter Wang | a3cf4ac | 2020-01-27 09:39:46 +0800 | [diff] [blame] | 2875 | mNotifyUserActivity = new AtomicBoolean(false); |
Tyler Gunn | 64144d9 | 2022-03-17 14:16:41 -0700 | [diff] [blame] | 2876 | PropertyInvalidatedCache.invalidateCache(TelephonyManager.CACHE_KEY_PHONE_ACCOUNT_TO_SUBID); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2877 | publish(); |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 2878 | CarrierAllowListInfo.loadInstance(mApp); |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame^] | 2879 | mSatelliteSupportedReceiver = new ResultReceiver(mMainThreadHandler) { |
| 2880 | @Override |
| 2881 | protected void onReceiveResult(int resultCode, Bundle resultData) { |
| 2882 | if (resultCode == SatelliteManager.SATELLITE_ERROR_NONE |
| 2883 | && resultData.containsKey(SatelliteManager.KEY_SATELLITE_SUPPORTED)) { |
| 2884 | synchronized (mIsSatelliteSupportedLock) { |
| 2885 | mIsSatelliteSupported = resultData.getBoolean( |
| 2886 | SatelliteManager.KEY_SATELLITE_SUPPORTED); |
| 2887 | } |
| 2888 | } else { |
| 2889 | synchronized (mIsSatelliteSupportedLock) { |
| 2890 | mIsSatelliteSupported = null; |
| 2891 | } |
| 2892 | } |
| 2893 | } |
| 2894 | }; |
| 2895 | requestIsSatelliteSupported(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, |
| 2896 | mSatelliteSupportedReceiver); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2897 | } |
| 2898 | |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 2899 | @VisibleForTesting |
| 2900 | public SharedPreferences getSharedPreferences() { |
| 2901 | return mTelephonySharedPreferences; |
| 2902 | } |
| 2903 | |
Gil Cukierman | 92cc7db | 2023-01-06 19:25:53 +0000 | [diff] [blame] | 2904 | /** |
| 2905 | * Get the default phone for this device. |
| 2906 | */ |
| 2907 | @VisibleForTesting |
| 2908 | public Phone getDefaultPhone() { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2909 | Phone thePhone = getPhone(getDefaultSubscription()); |
| 2910 | return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone(); |
| 2911 | } |
| 2912 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2913 | private void publish() { |
| 2914 | if (DBG) log("publish: " + this); |
| 2915 | |
Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 2916 | TelephonyFrameworkInitializer |
| 2917 | .getTelephonyServiceManager() |
| 2918 | .getTelephonyServiceRegisterer() |
| 2919 | .register(this); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2920 | } |
| 2921 | |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 2922 | private Phone getPhoneFromRequest(MainThreadRequest request) { |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 2923 | if (request.phone != null) { |
| 2924 | return request.phone; |
| 2925 | } else { |
| 2926 | return getPhoneFromSubId(request.subId); |
| 2927 | } |
| 2928 | } |
| 2929 | |
| 2930 | private Phone getPhoneFromSubId(int subId) { |
| 2931 | return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) |
| 2932 | ? getDefaultPhone() : getPhone(subId); |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 2933 | } |
| 2934 | |
Aishwarya Mallampati | 5e581e1 | 2023-01-17 21:57:06 +0000 | [diff] [blame] | 2935 | /** |
| 2936 | * Get phone object associated with a subscription. |
| 2937 | * Return default phone if phone object associated with subscription is null |
| 2938 | * @param subId - subscriptionId |
| 2939 | * @return phone object associated with a subscription or default phone if null. |
| 2940 | */ |
| 2941 | private Phone getPhoneFromSubIdOrDefault(int subId) { |
| 2942 | Phone phone = getPhoneFromSubId(subId); |
| 2943 | if (phone == null) { |
| 2944 | phone = getDefaultPhone(); |
| 2945 | } |
| 2946 | return phone; |
| 2947 | } |
| 2948 | |
Rambo Wang | e53e07d | 2022-05-10 13:01:13 -0700 | [diff] [blame] | 2949 | @Nullable |
| 2950 | private UiccPort getUiccPortFromRequest(@NonNull MainThreadRequest request) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2951 | Phone phone = getPhoneFromRequest(request); |
| 2952 | return phone == null ? null : |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 2953 | UiccController.getInstance().getUiccPort(phone.getPhoneId()); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2954 | } |
| 2955 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2956 | // returns phone associated with the subId. |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2957 | private Phone getPhone(int subId) { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 2958 | return PhoneFactory.getPhone(SubscriptionManager.getPhoneId(subId)); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2959 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2960 | |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 2961 | private void sendEraseModemConfig(@NonNull Phone phone) { |
| 2962 | Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null); |
| 2963 | if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 2964 | } |
| 2965 | |
| 2966 | private void sendEraseDataInSharedPreferences(@NonNull Phone phone) { |
| 2967 | Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null); |
| 2968 | if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail")); |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 2969 | } |
| 2970 | |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 2971 | private boolean isImsAvailableOnDevice() { |
| 2972 | PackageManager pm = getDefaultPhone().getContext().getPackageManager(); |
| 2973 | if (pm == null) { |
| 2974 | // For some reason package manger is not available.. This will fail internally anyway, |
| 2975 | // so do not throw error and allow. |
| 2976 | return true; |
| 2977 | } |
| 2978 | return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0); |
| 2979 | } |
| 2980 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2981 | public void dial(String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2982 | dialForSubscriber(getPreferredVoiceSubscription(), number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2983 | } |
| 2984 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2985 | public void dialForSubscriber(int subId, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2986 | if (DBG) log("dial: " + number); |
| 2987 | // No permission check needed here: This is just a wrapper around the |
| 2988 | // ACTION_DIAL intent, which is available to any app since it puts up |
| 2989 | // the UI before it does anything. |
| 2990 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2991 | final long identity = Binder.clearCallingIdentity(); |
| 2992 | try { |
| 2993 | String url = createTelUrl(number); |
| 2994 | if (url == null) { |
| 2995 | return; |
| 2996 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2997 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2998 | // PENDING: should we just silently fail if phone is offhook or ringing? |
| 2999 | PhoneConstants.State state = mCM.getState(subId); |
| 3000 | if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) { |
| 3001 | Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url)); |
| 3002 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 3003 | mApp.startActivity(intent); |
| 3004 | } |
| 3005 | } finally { |
| 3006 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3007 | } |
| 3008 | } |
| 3009 | |
| 3010 | public void call(String callingPackage, String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 3011 | callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3012 | } |
| 3013 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3014 | public void callForSubscriber(int subId, String callingPackage, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3015 | if (DBG) log("call: " + number); |
| 3016 | |
| 3017 | // This is just a wrapper around the ACTION_CALL intent, but we still |
| 3018 | // need to do a permission check since we're calling startActivity() |
| 3019 | // from the context of the phone app. |
| 3020 | enforceCallPermission(); |
| 3021 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 3022 | if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage) |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3023 | != AppOpsManager.MODE_ALLOWED) { |
| 3024 | return; |
| 3025 | } |
| 3026 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3027 | final long identity = Binder.clearCallingIdentity(); |
| 3028 | try { |
| 3029 | String url = createTelUrl(number); |
| 3030 | if (url == null) { |
| 3031 | return; |
| 3032 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3033 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3034 | boolean isValid = false; |
| 3035 | final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged(); |
| 3036 | if (slist != null) { |
| 3037 | for (SubscriptionInfo subInfoRecord : slist) { |
| 3038 | if (subInfoRecord.getSubscriptionId() == subId) { |
| 3039 | isValid = true; |
| 3040 | break; |
| 3041 | } |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 3042 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 3043 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3044 | if (!isValid) { |
| 3045 | return; |
| 3046 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 3047 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3048 | Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url)); |
| 3049 | intent.putExtra(SUBSCRIPTION_KEY, subId); |
| 3050 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 3051 | mApp.startActivity(intent); |
| 3052 | } finally { |
| 3053 | Binder.restoreCallingIdentity(identity); |
| 3054 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3055 | } |
| 3056 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3057 | public boolean supplyPinForSubscriber(int subId, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 3058 | int [] resultArray = supplyPinReportResultForSubscriber(subId, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 3059 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 3060 | } |
| 3061 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3062 | public boolean supplyPukForSubscriber(int subId, String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 3063 | int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 3064 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 3065 | } |
| 3066 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3067 | public int[] supplyPinReportResultForSubscriber(int subId, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3068 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3069 | |
| 3070 | final long identity = Binder.clearCallingIdentity(); |
| 3071 | try { |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 3072 | Phone phone = getPhone(subId); |
| 3073 | final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3074 | checkSimPin.start(); |
| 3075 | return checkSimPin.unlockSim(null, pin); |
| 3076 | } finally { |
| 3077 | Binder.restoreCallingIdentity(identity); |
| 3078 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3079 | } |
| 3080 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3081 | public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3082 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3083 | |
| 3084 | final long identity = Binder.clearCallingIdentity(); |
| 3085 | try { |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 3086 | Phone phone = getPhone(subId); |
| 3087 | final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3088 | checkSimPuk.start(); |
| 3089 | return checkSimPuk.unlockSim(puk, pin); |
| 3090 | } finally { |
| 3091 | Binder.restoreCallingIdentity(identity); |
| 3092 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3093 | } |
| 3094 | |
| 3095 | /** |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 3096 | * Helper thread to turn async call to SimCard#supplyPin into |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3097 | * a synchronous one. |
| 3098 | */ |
| 3099 | private static class UnlockSim extends Thread { |
| 3100 | |
| 3101 | private final IccCard mSimCard; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 3102 | private final int mPhoneId; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3103 | |
| 3104 | private boolean mDone = false; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 3105 | private int mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 3106 | private int mRetryCount = -1; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3107 | |
| 3108 | // For replies from SimCard interface |
| 3109 | private Handler mHandler; |
| 3110 | |
| 3111 | // For async handler to identify request type |
| 3112 | private static final int SUPPLY_PIN_COMPLETE = 100; |
| 3113 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 3114 | UnlockSim(int phoneId, IccCard simCard) { |
| 3115 | mPhoneId = phoneId; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3116 | mSimCard = simCard; |
| 3117 | } |
| 3118 | |
| 3119 | @Override |
| 3120 | public void run() { |
| 3121 | Looper.prepare(); |
| 3122 | synchronized (UnlockSim.this) { |
| 3123 | mHandler = new Handler() { |
| 3124 | @Override |
| 3125 | public void handleMessage(Message msg) { |
| 3126 | AsyncResult ar = (AsyncResult) msg.obj; |
| 3127 | switch (msg.what) { |
| 3128 | case SUPPLY_PIN_COMPLETE: |
| 3129 | Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE"); |
| 3130 | synchronized (UnlockSim.this) { |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 3131 | mRetryCount = msg.arg1; |
| 3132 | if (ar.exception != null) { |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 3133 | CommandException.Error error = null; |
| 3134 | if (ar.exception instanceof CommandException) { |
| 3135 | error = ((CommandException) (ar.exception)) |
| 3136 | .getCommandError(); |
| 3137 | } |
| 3138 | if (error == CommandException.Error.PASSWORD_INCORRECT) { |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 3139 | mResult = PhoneConstants.PIN_PASSWORD_INCORRECT; |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 3140 | } else if (error == CommandException.Error.ABORTED) { |
| 3141 | /* When UiccCardApp dispose, handle message and return |
| 3142 | exception */ |
vivi.li | b5e9ada | 2019-09-12 16:04:24 +0800 | [diff] [blame] | 3143 | mResult = PhoneConstants.PIN_OPERATION_ABORTED; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 3144 | } else { |
| 3145 | mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 3146 | } |
| 3147 | } else { |
| 3148 | mResult = PhoneConstants.PIN_RESULT_SUCCESS; |
| 3149 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3150 | mDone = true; |
| 3151 | UnlockSim.this.notifyAll(); |
| 3152 | } |
| 3153 | break; |
| 3154 | } |
| 3155 | } |
| 3156 | }; |
| 3157 | UnlockSim.this.notifyAll(); |
| 3158 | } |
| 3159 | Looper.loop(); |
| 3160 | } |
| 3161 | |
| 3162 | /* |
| 3163 | * Use PIN or PUK to unlock SIM card |
| 3164 | * |
| 3165 | * If PUK is null, unlock SIM card with PIN |
| 3166 | * |
| 3167 | * If PUK is not null, unlock SIM card with PUK and set PIN code |
| 3168 | */ |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 3169 | synchronized int[] unlockSim(String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3170 | |
| 3171 | while (mHandler == null) { |
| 3172 | try { |
| 3173 | wait(); |
| 3174 | } catch (InterruptedException e) { |
| 3175 | Thread.currentThread().interrupt(); |
| 3176 | } |
| 3177 | } |
| 3178 | Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE); |
| 3179 | |
| 3180 | if (puk == null) { |
| 3181 | mSimCard.supplyPin(pin, callback); |
| 3182 | } else { |
| 3183 | mSimCard.supplyPuk(puk, pin, callback); |
| 3184 | } |
| 3185 | |
| 3186 | while (!mDone) { |
| 3187 | try { |
| 3188 | Log.d(LOG_TAG, "wait for done"); |
| 3189 | wait(); |
| 3190 | } catch (InterruptedException e) { |
| 3191 | // Restore the interrupted status |
| 3192 | Thread.currentThread().interrupt(); |
| 3193 | } |
| 3194 | } |
| 3195 | Log.d(LOG_TAG, "done"); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 3196 | int[] resultArray = new int[2]; |
| 3197 | resultArray[0] = mResult; |
| 3198 | resultArray[1] = mRetryCount; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 3199 | |
| 3200 | if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) { |
Jon Spivack | 9c3bc76 | 2021-10-06 20:53:09 +0000 | [diff] [blame] | 3201 | UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 3202 | } |
| 3203 | |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 3204 | return resultArray; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3205 | } |
| 3206 | } |
| 3207 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 3208 | /** |
| 3209 | * This method has been removed due to privacy and stability concerns. |
| 3210 | */ |
| 3211 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3212 | public void updateServiceLocation() { |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 3213 | Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()"); |
| 3214 | return; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3215 | } |
| 3216 | |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 3217 | @Override |
| 3218 | public void updateServiceLocationWithPackageName(String callingPackage) { |
| 3219 | mApp.getSystemService(AppOpsManager.class) |
| 3220 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 3221 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3222 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 3223 | if (targetSdk > android.os.Build.VERSION_CODES.R) { |
| 3224 | // Callers targeting S have no business invoking this method. |
| 3225 | return; |
| 3226 | } |
| 3227 | |
| 3228 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 3229 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 3230 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 3231 | .setCallingPackage(callingPackage) |
| 3232 | .setCallingFeatureId(null) |
| 3233 | .setCallingPid(Binder.getCallingPid()) |
| 3234 | .setCallingUid(Binder.getCallingUid()) |
| 3235 | .setMethod("updateServiceLocation") |
| 3236 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
| 3237 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 3238 | .build()); |
| 3239 | // Apps that lack location permission have no business calling this method; |
| 3240 | // however, because no permission was declared in the public API, denials must |
| 3241 | // all be "soft". |
| 3242 | switch (locationResult) { |
| 3243 | case DENIED_HARD: /* fall through */ |
| 3244 | case DENIED_SOFT: |
| 3245 | return; |
| 3246 | } |
| 3247 | |
| 3248 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3249 | final long identity = Binder.clearCallingIdentity(); |
| 3250 | try { |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 3251 | final Phone phone = getPhone(getDefaultSubscription()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3252 | if (phone != null) { |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 3253 | phone.updateServiceLocation(workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3254 | } |
| 3255 | } finally { |
| 3256 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3257 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3258 | } |
| 3259 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3260 | @Deprecated |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3261 | @Override |
| 3262 | public boolean isRadioOn(String callingPackage) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3263 | return isRadioOnWithFeature(callingPackage, null); |
| 3264 | } |
| 3265 | |
| 3266 | |
| 3267 | @Override |
| 3268 | public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) { |
| 3269 | return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage, |
| 3270 | callingFeatureId); |
| 3271 | } |
| 3272 | |
| 3273 | @Deprecated |
| 3274 | @Override |
| 3275 | public boolean isRadioOnForSubscriber(int subId, String callingPackage) { |
| 3276 | return isRadioOnForSubscriberWithFeature(subId, callingPackage, null); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3277 | } |
| 3278 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3279 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3280 | public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage, |
| 3281 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3282 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3283 | mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3284 | return false; |
| 3285 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3286 | |
| 3287 | final long identity = Binder.clearCallingIdentity(); |
| 3288 | try { |
| 3289 | return isRadioOnForSubscriber(subId); |
| 3290 | } finally { |
| 3291 | Binder.restoreCallingIdentity(identity); |
| 3292 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3293 | } |
| 3294 | |
| 3295 | private boolean isRadioOnForSubscriber(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3296 | final long identity = Binder.clearCallingIdentity(); |
| 3297 | try { |
| 3298 | final Phone phone = getPhone(subId); |
| 3299 | if (phone != null) { |
| 3300 | return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF; |
| 3301 | } else { |
| 3302 | return false; |
| 3303 | } |
| 3304 | } finally { |
| 3305 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3306 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3307 | } |
| 3308 | |
| 3309 | public void toggleRadioOnOff() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 3310 | toggleRadioOnOffForSubscriber(getDefaultSubscription()); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3311 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3312 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3313 | public void toggleRadioOnOffForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3314 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3315 | |
| 3316 | final long identity = Binder.clearCallingIdentity(); |
| 3317 | try { |
| 3318 | final Phone phone = getPhone(subId); |
| 3319 | if (phone != null) { |
| 3320 | phone.setRadioPower(!isRadioOnForSubscriber(subId)); |
| 3321 | } |
| 3322 | } finally { |
| 3323 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3324 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3325 | } |
| 3326 | |
| 3327 | public boolean setRadio(boolean turnOn) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 3328 | return setRadioForSubscriber(getDefaultSubscription(), turnOn); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3329 | } |
| 3330 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3331 | public boolean setRadioForSubscriber(int subId, boolean turnOn) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3332 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3333 | |
| 3334 | final long identity = Binder.clearCallingIdentity(); |
| 3335 | try { |
| 3336 | final Phone phone = getPhone(subId); |
| 3337 | if (phone == null) { |
| 3338 | return false; |
| 3339 | } |
| 3340 | if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) { |
| 3341 | toggleRadioOnOffForSubscriber(subId); |
| 3342 | } |
| 3343 | return true; |
| 3344 | } finally { |
| 3345 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3346 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3347 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3348 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3349 | public boolean needMobileRadioShutdown() { |
Shuo Qian | fa7b6b3 | 2019-12-10 10:40:38 -0800 | [diff] [blame] | 3350 | enforceReadPrivilegedPermission("needMobileRadioShutdown"); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3351 | /* |
| 3352 | * If any of the Radios are available, it will need to be |
| 3353 | * shutdown. So return true if any Radio is available. |
| 3354 | */ |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3355 | final long identity = Binder.clearCallingIdentity(); |
| 3356 | try { |
| 3357 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 3358 | Phone phone = PhoneFactory.getPhone(i); |
| 3359 | if (phone != null && phone.isRadioAvailable()) return true; |
| 3360 | } |
| 3361 | logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown."); |
| 3362 | return false; |
| 3363 | } finally { |
| 3364 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3365 | } |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3366 | } |
| 3367 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3368 | @Override |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3369 | public void shutdownMobileRadios() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3370 | enforceModifyPermission(); |
| 3371 | |
| 3372 | final long identity = Binder.clearCallingIdentity(); |
| 3373 | try { |
| 3374 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 3375 | logv("Shutting down Phone " + i); |
| 3376 | shutdownRadioUsingPhoneId(i); |
| 3377 | } |
| 3378 | } finally { |
| 3379 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3380 | } |
| 3381 | } |
| 3382 | |
| 3383 | private void shutdownRadioUsingPhoneId(int phoneId) { |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3384 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 3385 | if (phone != null && phone.isRadioAvailable()) { |
| 3386 | phone.shutdownRadio(); |
| 3387 | } |
| 3388 | } |
| 3389 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3390 | public boolean setRadioPower(boolean turnOn) { |
Jack Yu | b4e1616 | 2017-05-15 12:48:40 -0700 | [diff] [blame] | 3391 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3392 | |
Ling Ma | 83dc5ea | 2023-01-12 15:06:04 -0800 | [diff] [blame] | 3393 | if (!turnOn) { |
| 3394 | log("setRadioPower off: callingPackage=" + getCurrentPackageName()); |
| 3395 | } |
| 3396 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3397 | final long identity = Binder.clearCallingIdentity(); |
| 3398 | try { |
| 3399 | final Phone defaultPhone = PhoneFactory.getDefaultPhone(); |
| 3400 | if (defaultPhone != null) { |
| 3401 | defaultPhone.setRadioPower(turnOn); |
| 3402 | return true; |
| 3403 | } else { |
| 3404 | loge("There's no default phone."); |
| 3405 | return false; |
| 3406 | } |
| 3407 | } finally { |
| 3408 | Binder.restoreCallingIdentity(identity); |
Wei Liu | 9ae2a06 | 2016-08-08 11:09:34 -0700 | [diff] [blame] | 3409 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3410 | } |
| 3411 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3412 | public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3413 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3414 | |
Ling Ma | 83dc5ea | 2023-01-12 15:06:04 -0800 | [diff] [blame] | 3415 | if (!turnOn) { |
| 3416 | log("setRadioPowerForSubscriber off: subId=" + subId |
| 3417 | + ",callingPackage=" + getCurrentPackageName()); |
| 3418 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3419 | final long identity = Binder.clearCallingIdentity(); |
| 3420 | try { |
| 3421 | final Phone phone = getPhone(subId); |
| 3422 | if (phone != null) { |
| 3423 | phone.setRadioPower(turnOn); |
| 3424 | return true; |
| 3425 | } else { |
| 3426 | return false; |
| 3427 | } |
| 3428 | } finally { |
| 3429 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3430 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3431 | } |
| 3432 | |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3433 | /** |
| 3434 | * Vote on powering off the radio for a reason. The radio will be turned on only when there is |
| 3435 | * no reason to power it off. When any of the voters want to power it off, it will be turned |
| 3436 | * off. In case of emergency, the radio will be turned on even if there are some reasons for |
| 3437 | * powering it off, and these radio off votes will be cleared. |
| 3438 | * Multiple apps can vote for the same reason and the last vote will take effect. Each app is |
| 3439 | * responsible for its vote. A powering-off vote of a reason will be maintained until it is |
| 3440 | * cleared by calling {@link clearRadioPowerOffForReason} for that reason, or an emergency call |
| 3441 | * is made, or the device is rebooted. When an app comes backup from a crash, it needs to make |
| 3442 | * sure if its vote is as expected. An app can use the API {@link getRadioPowerOffReasons} to |
| 3443 | * check its vote. |
| 3444 | * |
| 3445 | * @param subId The subscription ID. |
| 3446 | * @param reason The reason for powering off radio. |
| 3447 | * @return true on success and false on failure. |
| 3448 | */ |
| 3449 | public boolean requestRadioPowerOffForReason(int subId, |
| 3450 | @TelephonyManager.RadioPowerReason int reason) { |
| 3451 | enforceModifyPermission(); |
| 3452 | |
Ling Ma | 83dc5ea | 2023-01-12 15:06:04 -0800 | [diff] [blame] | 3453 | log("requestRadioPowerOffForReason: subId=" + subId |
| 3454 | + ",reason=" + reason + ",callingPackage=" + getCurrentPackageName()); |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3455 | final long identity = Binder.clearCallingIdentity(); |
| 3456 | try { |
| 3457 | final Phone phone = getPhone(subId); |
| 3458 | if (phone != null) { |
| 3459 | phone.setRadioPowerForReason(false, reason); |
| 3460 | return true; |
| 3461 | } else { |
| 3462 | return false; |
| 3463 | } |
| 3464 | } finally { |
| 3465 | Binder.restoreCallingIdentity(identity); |
| 3466 | } |
| 3467 | } |
| 3468 | |
| 3469 | /** |
| 3470 | * Remove the vote on powering off the radio for a reason, as requested by |
| 3471 | * {@link requestRadioPowerOffForReason}. |
| 3472 | * |
| 3473 | * @param subId The subscription ID. |
| 3474 | * @param reason The reason for powering off radio. |
| 3475 | * @return true on success and false on failure. |
| 3476 | */ |
| 3477 | public boolean clearRadioPowerOffForReason(int subId, |
| 3478 | @TelephonyManager.RadioPowerReason int reason) { |
| 3479 | enforceModifyPermission(); |
| 3480 | |
| 3481 | final long identity = Binder.clearCallingIdentity(); |
| 3482 | try { |
| 3483 | final Phone phone = getPhone(subId); |
| 3484 | if (phone != null) { |
| 3485 | phone.setRadioPowerForReason(true, reason); |
| 3486 | return true; |
| 3487 | } else { |
| 3488 | return false; |
| 3489 | } |
| 3490 | } finally { |
| 3491 | Binder.restoreCallingIdentity(identity); |
| 3492 | } |
| 3493 | } |
| 3494 | |
| 3495 | /** |
| 3496 | * Get reasons for powering off radio, as requested by {@link requestRadioPowerOffForReason}. |
| 3497 | * |
| 3498 | * @param subId The subscription ID. |
| 3499 | * @param callingPackage The package making the call. |
| 3500 | * @param callingFeatureId The feature in the package. |
| 3501 | * @return List of reasons for powering off radio. |
| 3502 | */ |
| 3503 | public List getRadioPowerOffReasons(int subId, String callingPackage, String callingFeatureId) { |
| 3504 | enforceReadPrivilegedPermission("getRadioPowerOffReasons"); |
| 3505 | |
| 3506 | final long identity = Binder.clearCallingIdentity(); |
| 3507 | List result = new ArrayList(); |
| 3508 | try { |
| 3509 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, |
| 3510 | callingPackage, callingFeatureId, "getRadioPowerOffReasons")) { |
| 3511 | return result; |
| 3512 | } |
| 3513 | |
| 3514 | final Phone phone = getPhone(subId); |
| 3515 | if (phone != null) { |
| 3516 | result.addAll(phone.getRadioPowerOffReasons()); |
| 3517 | } |
| 3518 | } finally { |
| 3519 | Binder.restoreCallingIdentity(identity); |
| 3520 | } |
| 3521 | return result; |
| 3522 | } |
| 3523 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3524 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3525 | @Override |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 3526 | public boolean enableDataConnectivity(String callingPackage) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3527 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3528 | |
| 3529 | final long identity = Binder.clearCallingIdentity(); |
| 3530 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3531 | int subId = SubscriptionManager.getDefaultDataSubscriptionId(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3532 | final Phone phone = getPhone(subId); |
| 3533 | if (phone != null) { |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 3534 | phone.getDataSettingsManager().setDataEnabled( |
| 3535 | TelephonyManager.DATA_ENABLED_REASON_USER, true, callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3536 | return true; |
| 3537 | } else { |
| 3538 | return false; |
| 3539 | } |
| 3540 | } finally { |
| 3541 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3542 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3543 | } |
| 3544 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3545 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3546 | @Override |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 3547 | public boolean disableDataConnectivity(String callingPackage) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3548 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3549 | |
| 3550 | final long identity = Binder.clearCallingIdentity(); |
| 3551 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3552 | int subId = SubscriptionManager.getDefaultDataSubscriptionId(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3553 | final Phone phone = getPhone(subId); |
| 3554 | if (phone != null) { |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 3555 | phone.getDataSettingsManager().setDataEnabled( |
| 3556 | TelephonyManager.DATA_ENABLED_REASON_USER, false, callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3557 | return true; |
| 3558 | } else { |
| 3559 | return false; |
| 3560 | } |
| 3561 | } finally { |
| 3562 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3563 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3564 | } |
| 3565 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3566 | @Override |
Jack Yu | acf8a13 | 2017-05-01 17:00:48 -0700 | [diff] [blame] | 3567 | public boolean isDataConnectivityPossible(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3568 | final long identity = Binder.clearCallingIdentity(); |
| 3569 | try { |
| 3570 | final Phone phone = getPhone(subId); |
| 3571 | if (phone != null) { |
Jack Yu | 59824e1 | 2022-03-23 01:42:44 -0700 | [diff] [blame] | 3572 | return phone.isDataAllowed(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3573 | } else { |
| 3574 | return false; |
| 3575 | } |
| 3576 | } finally { |
| 3577 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3578 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3579 | } |
| 3580 | |
| 3581 | public boolean handlePinMmi(String dialString) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 3582 | return handlePinMmiForSubscriber(getDefaultSubscription(), dialString); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3583 | } |
| 3584 | |
pkanwar | ae03a6b | 2016-11-06 20:37:09 -0800 | [diff] [blame] | 3585 | public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3586 | enforceCallPermission(); |
| 3587 | |
| 3588 | final long identity = Binder.clearCallingIdentity(); |
| 3589 | try { |
| 3590 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3591 | return; |
| 3592 | } |
| 3593 | Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback); |
| 3594 | sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId); |
| 3595 | } finally { |
| 3596 | Binder.restoreCallingIdentity(identity); |
| 3597 | } |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 3598 | }; |
| 3599 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3600 | public boolean handlePinMmiForSubscriber(int subId, String dialString) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3601 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3602 | |
| 3603 | final long identity = Binder.clearCallingIdentity(); |
| 3604 | try { |
| 3605 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3606 | return false; |
| 3607 | } |
| 3608 | return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId); |
| 3609 | } finally { |
| 3610 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3611 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3612 | } |
| 3613 | |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 3614 | /** |
| 3615 | * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage |
| 3616 | * tag on getCallState Binder call. |
| 3617 | */ |
| 3618 | @Deprecated |
| 3619 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3620 | public int getCallState() { |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 3621 | if (CompatChanges.isChangeEnabled( |
| 3622 | TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION, |
| 3623 | Binder.getCallingUid())) { |
| 3624 | // Do not allow this API to be called on API version 31+, it should only be |
| 3625 | // called on old apps using this Binder call directly. |
| 3626 | throw new SecurityException("This method can only be used for applications " |
| 3627 | + "targeting API version 30 or less."); |
| 3628 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3629 | final long identity = Binder.clearCallingIdentity(); |
| 3630 | try { |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 3631 | Phone phone = getPhone(getDefaultSubscription()); |
| 3632 | return phone == null ? TelephonyManager.CALL_STATE_IDLE : |
| 3633 | PhoneConstantConversions.convertCallState(phone.getState()); |
| 3634 | } finally { |
| 3635 | Binder.restoreCallingIdentity(identity); |
| 3636 | } |
| 3637 | } |
| 3638 | |
| 3639 | @Override |
| 3640 | public int getCallStateForSubscription(int subId, String callingPackage, String featureId) { |
| 3641 | if (CompatChanges.isChangeEnabled( |
| 3642 | TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION, |
| 3643 | Binder.getCallingUid())) { |
| 3644 | // Check READ_PHONE_STATE for API version 31+ |
| 3645 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage, |
| 3646 | featureId, "getCallStateForSubscription")) { |
| 3647 | throw new SecurityException("getCallState requires READ_PHONE_STATE for apps " |
| 3648 | + "targeting API level 31+."); |
| 3649 | } |
| 3650 | } |
| 3651 | final long identity = Binder.clearCallingIdentity(); |
| 3652 | try { |
| 3653 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3654 | return phone == null ? TelephonyManager.CALL_STATE_IDLE : |
| 3655 | PhoneConstantConversions.convertCallState(phone.getState()); |
| 3656 | } finally { |
| 3657 | Binder.restoreCallingIdentity(identity); |
| 3658 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3659 | } |
| 3660 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3661 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 3662 | public int getDataState() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3663 | return getDataStateForSubId(SubscriptionManager.getDefaultDataSubscriptionId()); |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 3664 | } |
| 3665 | |
| 3666 | @Override |
| 3667 | public int getDataStateForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3668 | final long identity = Binder.clearCallingIdentity(); |
| 3669 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 3670 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3671 | if (phone != null) { |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 3672 | return phone.getDataNetworkController().getInternetDataNetworkState(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3673 | } else { |
| 3674 | return PhoneConstantConversions.convertDataState( |
| 3675 | PhoneConstants.DataState.DISCONNECTED); |
| 3676 | } |
| 3677 | } finally { |
| 3678 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3679 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3680 | } |
| 3681 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3682 | @Override |
Jack Yu | 0eda684 | 2022-04-18 00:34:46 -0700 | [diff] [blame] | 3683 | public @DataActivityType int getDataActivity() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3684 | return getDataActivityForSubId(SubscriptionManager.getDefaultDataSubscriptionId()); |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 3685 | } |
| 3686 | |
| 3687 | @Override |
Jack Yu | 0eda684 | 2022-04-18 00:34:46 -0700 | [diff] [blame] | 3688 | public @DataActivityType int getDataActivityForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3689 | final long identity = Binder.clearCallingIdentity(); |
| 3690 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 3691 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3692 | if (phone != null) { |
Jack Yu | 0eda684 | 2022-04-18 00:34:46 -0700 | [diff] [blame] | 3693 | return phone.getDataActivityState(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3694 | } else { |
| 3695 | return TelephonyManager.DATA_ACTIVITY_NONE; |
| 3696 | } |
| 3697 | } finally { |
| 3698 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3699 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3700 | } |
| 3701 | |
| 3702 | @Override |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 3703 | public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3704 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 3705 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3706 | |
| 3707 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 3708 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 3709 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 3710 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3711 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3712 | .setCallingPid(Binder.getCallingPid()) |
| 3713 | .setCallingUid(Binder.getCallingUid()) |
| 3714 | .setMethod("getCellLocation") |
Hall Liu | 773ba02 | 2020-01-24 18:07:12 -0800 | [diff] [blame] | 3715 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3716 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 3717 | .build()); |
| 3718 | switch (locationResult) { |
| 3719 | case DENIED_HARD: |
| 3720 | throw new SecurityException("Not allowed to access cell location"); |
| 3721 | case DENIED_SOFT: |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 3722 | return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
| 3723 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3724 | } |
| 3725 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 3726 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3727 | final long identity = Binder.clearCallingIdentity(); |
| 3728 | try { |
| 3729 | if (DBG_LOC) log("getCellLocation: is active user"); |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3730 | int subId = SubscriptionManager.getDefaultDataSubscriptionId(); |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 3731 | return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3732 | } finally { |
| 3733 | Binder.restoreCallingIdentity(identity); |
| 3734 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 3735 | } |
| 3736 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3737 | @Override |
Jack Yu | eb1e7fe | 2020-02-22 19:38:58 -0800 | [diff] [blame] | 3738 | public String getNetworkCountryIsoForPhone(int phoneId) { |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3739 | // Reporting the correct network country is ambiguous when IWLAN could conflict with |
| 3740 | // registered cell info, so return a NULL country instead. |
| 3741 | final long identity = Binder.clearCallingIdentity(); |
| 3742 | try { |
Malcolm Chen | 3732c2b | 2018-07-18 20:15:24 -0700 | [diff] [blame] | 3743 | if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) { |
| 3744 | // Get default phone in this case. |
| 3745 | phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX; |
| 3746 | } |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3747 | final int subId = SubscriptionManager.getSubscriptionId(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3748 | Phone phone = PhoneFactory.getPhone(phoneId); |
Nathan Harold | 532f51c | 2020-04-21 19:31:10 -0700 | [diff] [blame] | 3749 | if (phone == null) return ""; |
| 3750 | ServiceStateTracker sst = phone.getServiceStateTracker(); |
| 3751 | if (sst == null) return ""; |
| 3752 | LocaleTracker lt = sst.getLocaleTracker(); |
| 3753 | if (lt == null) return ""; |
Shuo Qian | 9418a92 | 2021-03-09 11:21:16 -0800 | [diff] [blame] | 3754 | return lt.getCurrentCountry(); |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3755 | } finally { |
| 3756 | Binder.restoreCallingIdentity(identity); |
| 3757 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3758 | } |
| 3759 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 3760 | /** |
| 3761 | * This method was removed due to potential issues caused by performing partial |
| 3762 | * updates of service state, and lack of a credible use case. |
| 3763 | * |
| 3764 | * This has the ability to break the telephony implementation by disabling notification of |
| 3765 | * changes in device connectivity. DO NOT USE THIS! |
| 3766 | */ |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3767 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3768 | public void enableLocationUpdates() { |
| 3769 | mApp.enforceCallingOrSelfPermission( |
| 3770 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3771 | } |
| 3772 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 3773 | /** |
| 3774 | * This method was removed due to potential issues caused by performing partial |
| 3775 | * updates of service state, and lack of a credible use case. |
| 3776 | * |
| 3777 | * This has the ability to break the telephony implementation by disabling notification of |
| 3778 | * changes in device connectivity. DO NOT USE THIS! |
| 3779 | */ |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3780 | @Override |
| 3781 | public void disableLocationUpdates() { |
| 3782 | mApp.enforceCallingOrSelfPermission( |
| 3783 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3784 | } |
| 3785 | |
| 3786 | @Override |
| 3787 | @SuppressWarnings("unchecked") |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3788 | public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage, |
| 3789 | String callingFeatureId) { |
Nathan Harold | b55f63b | 2021-07-27 11:27:38 -0700 | [diff] [blame] | 3790 | try { |
| 3791 | mApp.getSystemService(AppOpsManager.class) |
| 3792 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 3793 | } catch (SecurityException e) { |
| 3794 | EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid()); |
| 3795 | throw e; |
| 3796 | } |
| 3797 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3798 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | dbea45a | 2018-08-30 14:35:07 -0700 | [diff] [blame] | 3799 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 3800 | throw new SecurityException( |
| 3801 | "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels."); |
| 3802 | } |
Nathan Harold | b4d5561 | 2018-07-20 13:13:08 -0700 | [diff] [blame] | 3803 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 3804 | if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(), |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3805 | callingPackage) != AppOpsManager.MODE_ALLOWED) { |
| 3806 | return null; |
| 3807 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 3808 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 3809 | if (DBG_LOC) log("getNeighboringCellInfo: is active user"); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3810 | |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3811 | List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId); |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 3812 | if (info == null) return null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3813 | |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 3814 | List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>(); |
| 3815 | for (CellInfo ci : info) { |
| 3816 | if (ci instanceof CellInfoGsm) { |
| 3817 | neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci)); |
| 3818 | } else if (ci instanceof CellInfoWcdma) { |
| 3819 | neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci)); |
| 3820 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3821 | } |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 3822 | return (neighbors.size()) > 0 ? neighbors : null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3823 | } |
| 3824 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3825 | private List<CellInfo> getCachedCellInfo() { |
| 3826 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 3827 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3828 | List<CellInfo> info = phone.getAllCellInfo(); |
| 3829 | if (info != null) cellInfos.addAll(info); |
| 3830 | } |
| 3831 | return cellInfos; |
| 3832 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3833 | |
| 3834 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3835 | public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3836 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 3837 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3838 | |
| 3839 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 3840 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 3841 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 3842 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3843 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3844 | .setCallingPid(Binder.getCallingPid()) |
| 3845 | .setCallingUid(Binder.getCallingUid()) |
| 3846 | .setMethod("getAllCellInfo") |
Nathan Harold | 5ae50b5 | 2019-02-20 15:46:36 -0800 | [diff] [blame] | 3847 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3848 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 3849 | .build()); |
| 3850 | switch (locationResult) { |
| 3851 | case DENIED_HARD: |
| 3852 | throw new SecurityException("Not allowed to access cell info"); |
| 3853 | case DENIED_SOFT: |
| 3854 | return new ArrayList<>(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3855 | } |
| 3856 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3857 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3858 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 3859 | return getCachedCellInfo(); |
| 3860 | } |
| 3861 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 3862 | if (DBG_LOC) log("getAllCellInfo: is active user"); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 3863 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3864 | final long identity = Binder.clearCallingIdentity(); |
| 3865 | try { |
| 3866 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 3867 | for (Phone phone : PhoneFactory.getPhones()) { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 3868 | final List<CellInfo> info = (List<CellInfo>) sendRequest( |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 3869 | CMD_GET_ALL_CELL_INFO, null, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3870 | if (info != null) cellInfos.addAll(info); |
| 3871 | } |
| 3872 | return cellInfos; |
| 3873 | } finally { |
| 3874 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3875 | } |
| 3876 | } |
| 3877 | |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 3878 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3879 | public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage, |
| 3880 | String callingFeatureId) { |
| 3881 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, |
| 3882 | getWorkSource(Binder.getCallingUid())); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3883 | } |
| 3884 | |
| 3885 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3886 | public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb, |
| 3887 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3888 | enforceModifyPermission(); |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3889 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3890 | } |
| 3891 | |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3892 | private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb, |
| 3893 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3894 | mApp.getSystemService(AppOpsManager.class) |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3895 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3896 | |
| 3897 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 3898 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 3899 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 3900 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3901 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3902 | .setCallingPid(Binder.getCallingPid()) |
| 3903 | .setCallingUid(Binder.getCallingUid()) |
| 3904 | .setMethod("requestCellInfoUpdate") |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 3905 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
| 3906 | .setMinSdkVersionForFine(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3907 | .build()); |
| 3908 | switch (locationResult) { |
| 3909 | case DENIED_HARD: |
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 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3915 | throw new SecurityException("Not allowed to access cell info"); |
| 3916 | case DENIED_SOFT: |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3917 | if (TelephonyPermissions |
| 3918 | .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) { |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 3919 | // Safetynet logging for b/154934934 |
| 3920 | EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid()); |
| 3921 | } |
Nathan Harold | 5320c42 | 2019-05-09 10:26:08 -0700 | [diff] [blame] | 3922 | try { |
| 3923 | cb.onCellInfo(new ArrayList<CellInfo>()); |
| 3924 | } catch (RemoteException re) { |
| 3925 | // Drop without consequences |
| 3926 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3927 | return; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3928 | } |
| 3929 | |
Nathan Harold | a939a96 | 2019-05-09 10:13:47 -0700 | [diff] [blame] | 3930 | |
| 3931 | final Phone phone = getPhoneFromSubId(subId); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3932 | if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
| 3933 | |
| 3934 | sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource); |
| 3935 | } |
| 3936 | |
| 3937 | @Override |
Aishwarya Mallampati | 0603fb1 | 2022-08-24 21:16:56 +0000 | [diff] [blame] | 3938 | public void setCellInfoListRate(int rateInMillis, int subId) { |
Jack Yu | a8d8cb8 | 2017-01-16 10:15:34 -0800 | [diff] [blame] | 3939 | enforceModifyPermission(); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 3940 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3941 | |
| 3942 | final long identity = Binder.clearCallingIdentity(); |
| 3943 | try { |
Aishwarya Mallampati | 0603fb1 | 2022-08-24 21:16:56 +0000 | [diff] [blame] | 3944 | Phone phone = getPhone(subId); |
| 3945 | if (phone == null) { |
| 3946 | getDefaultPhone().setCellInfoListRate(rateInMillis, workSource); |
| 3947 | } else { |
| 3948 | phone.setCellInfoListRate(rateInMillis, workSource); |
| 3949 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3950 | } finally { |
| 3951 | Binder.restoreCallingIdentity(identity); |
| 3952 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3953 | } |
| 3954 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3955 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3956 | public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3957 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3958 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3959 | return null; |
| 3960 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3961 | int subId = phone.getSubId(); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3962 | enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot"); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 3963 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3964 | callingPackage, callingFeatureId, "getImeiForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3965 | return null; |
| 3966 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3967 | |
| 3968 | final long identity = Binder.clearCallingIdentity(); |
| 3969 | try { |
| 3970 | return phone.getImei(); |
| 3971 | } finally { |
| 3972 | Binder.restoreCallingIdentity(identity); |
| 3973 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3974 | } |
| 3975 | |
| 3976 | @Override |
arunvoddu | d5c6ce0 | 2022-12-11 06:03:12 +0000 | [diff] [blame] | 3977 | public String getPrimaryImei(String callingPackage, String callingFeatureId) { |
| 3978 | enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getPrimaryImei"); |
| 3979 | if (!checkCallingOrSelfReadDeviceIdentifiersForAnySub(mApp, callingPackage, |
| 3980 | callingFeatureId, "getPrimaryImei")) { |
| 3981 | throw new SecurityException("Caller does not have permission"); |
| 3982 | } |
| 3983 | final long identity = Binder.clearCallingIdentity(); |
| 3984 | try { |
| 3985 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3986 | if (phone.getImeiType() == Phone.IMEI_TYPE_PRIMARY) { |
| 3987 | return phone.getImei(); |
| 3988 | } |
| 3989 | } |
| 3990 | throw new UnsupportedOperationException("Operation not supported"); |
| 3991 | } finally { |
| 3992 | Binder.restoreCallingIdentity(identity); |
| 3993 | } |
| 3994 | } |
| 3995 | |
| 3996 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3997 | public String getTypeAllocationCodeForSlot(int slotIndex) { |
| 3998 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3999 | String tac = null; |
| 4000 | if (phone != null) { |
| 4001 | String imei = phone.getImei(); |
Vala Zadeh | ab00555 | 2021-09-21 15:54:29 -0700 | [diff] [blame] | 4002 | try { |
| 4003 | tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH); |
| 4004 | } catch (IndexOutOfBoundsException e) { |
| 4005 | Log.e(LOG_TAG, "IMEI length shorter than upper index."); |
| 4006 | return null; |
| 4007 | } |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 4008 | } |
| 4009 | return tac; |
| 4010 | } |
| 4011 | |
| 4012 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4013 | public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Shuo Qian | 13d8915 | 2021-05-10 23:58:11 -0700 | [diff] [blame] | 4014 | try { |
| 4015 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 4016 | } catch (SecurityException se) { |
| 4017 | EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid()); |
| 4018 | throw new SecurityException("Package " + callingPackage + " does not belong to " |
| 4019 | + Binder.getCallingUid()); |
| 4020 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 4021 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 4022 | if (phone == null) { |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 4023 | return null; |
| 4024 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4025 | |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 4026 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 4027 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4028 | callingPackage, callingFeatureId, "getMeidForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 4029 | return null; |
| 4030 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4031 | |
| 4032 | final long identity = Binder.clearCallingIdentity(); |
| 4033 | try { |
| 4034 | return phone.getMeid(); |
| 4035 | } finally { |
| 4036 | Binder.restoreCallingIdentity(identity); |
| 4037 | } |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 4038 | } |
| 4039 | |
| 4040 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 4041 | public String getManufacturerCodeForSlot(int slotIndex) { |
| 4042 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 4043 | String manufacturerCode = null; |
| 4044 | if (phone != null) { |
| 4045 | String meid = phone.getMeid(); |
Vala Zadeh | ab00555 | 2021-09-21 15:54:29 -0700 | [diff] [blame] | 4046 | try { |
| 4047 | manufacturerCode = |
| 4048 | meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH); |
| 4049 | } catch (IndexOutOfBoundsException e) { |
| 4050 | Log.e(LOG_TAG, "MEID length shorter than upper index."); |
| 4051 | return null; |
| 4052 | } |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 4053 | } |
| 4054 | return manufacturerCode; |
| 4055 | } |
| 4056 | |
| 4057 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4058 | public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage, |
| 4059 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 4060 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 4061 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4062 | return null; |
| 4063 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 4064 | int subId = phone.getSubId(); |
| 4065 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4066 | mApp, subId, callingPackage, callingFeatureId, |
| 4067 | "getDeviceSoftwareVersionForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 4068 | return null; |
| 4069 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4070 | |
| 4071 | final long identity = Binder.clearCallingIdentity(); |
| 4072 | try { |
| 4073 | return phone.getDeviceSvn(); |
| 4074 | } finally { |
| 4075 | Binder.restoreCallingIdentity(identity); |
| 4076 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 4077 | } |
| 4078 | |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 4079 | @Override |
| 4080 | public int getSubscriptionCarrierId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4081 | final long identity = Binder.clearCallingIdentity(); |
| 4082 | try { |
| 4083 | final Phone phone = getPhone(subId); |
| 4084 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId(); |
| 4085 | } finally { |
| 4086 | Binder.restoreCallingIdentity(identity); |
| 4087 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 4088 | } |
| 4089 | |
| 4090 | @Override |
| 4091 | public String getSubscriptionCarrierName(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4092 | final long identity = Binder.clearCallingIdentity(); |
| 4093 | try { |
| 4094 | final Phone phone = getPhone(subId); |
| 4095 | return phone == null ? null : phone.getCarrierName(); |
| 4096 | } finally { |
| 4097 | Binder.restoreCallingIdentity(identity); |
| 4098 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 4099 | } |
| 4100 | |
calvinpan | ffe225e | 2018-11-01 19:43:06 +0800 | [diff] [blame] | 4101 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 4102 | public int getSubscriptionSpecificCarrierId(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 4103 | final long identity = Binder.clearCallingIdentity(); |
| 4104 | try { |
| 4105 | final Phone phone = getPhone(subId); |
| 4106 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 4107 | : phone.getSpecificCarrierId(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 4108 | } finally { |
| 4109 | Binder.restoreCallingIdentity(identity); |
| 4110 | } |
| 4111 | } |
| 4112 | |
| 4113 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 4114 | public String getSubscriptionSpecificCarrierName(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 4115 | final long identity = Binder.clearCallingIdentity(); |
| 4116 | try { |
| 4117 | final Phone phone = getPhone(subId); |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 4118 | return phone == null ? null : phone.getSpecificCarrierName(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 4119 | } finally { |
| 4120 | Binder.restoreCallingIdentity(identity); |
| 4121 | } |
| 4122 | } |
| 4123 | |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 4124 | @Override |
chen xu | 864e11c | 2018-12-06 22:10:03 -0800 | [diff] [blame] | 4125 | public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) { |
| 4126 | if (!isSubscriptionMccMnc) { |
| 4127 | enforceReadPrivilegedPermission("getCarrierIdFromMccMnc"); |
| 4128 | } |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 4129 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 4130 | if (phone == null) { |
| 4131 | return TelephonyManager.UNKNOWN_CARRIER_ID; |
| 4132 | } |
| 4133 | final long identity = Binder.clearCallingIdentity(); |
| 4134 | try { |
| 4135 | return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc); |
| 4136 | } finally { |
| 4137 | Binder.restoreCallingIdentity(identity); |
| 4138 | } |
| 4139 | } |
| 4140 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4141 | // |
| 4142 | // Internal helper methods. |
| 4143 | // |
| 4144 | |
Sanket Padawe | ee13a9b | 2016-03-08 17:30:28 -0800 | [diff] [blame] | 4145 | /** |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 4146 | * Make sure the caller is the calling package itself |
| 4147 | * |
| 4148 | * @throws SecurityException if the caller is not the calling package |
| 4149 | */ |
| 4150 | private void enforceCallingPackage(String callingPackage, int callingUid, String message) { |
| 4151 | int packageUid = -1; |
Grace Jia | dbefca0 | 2021-04-26 15:13:31 -0700 | [diff] [blame] | 4152 | PackageManager pm = mApp.getBaseContext().createContextAsUser( |
| 4153 | UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager(); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 4154 | try { |
Grace Jia | dbefca0 | 2021-04-26 15:13:31 -0700 | [diff] [blame] | 4155 | packageUid = pm.getPackageUid(callingPackage, 0); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 4156 | } catch (PackageManager.NameNotFoundException e) { |
| 4157 | // packageUid is -1 |
| 4158 | } |
| 4159 | if (packageUid != callingUid) { |
| 4160 | throw new SecurityException(message + ": Package " + callingPackage |
| 4161 | + " does not belong to " + callingUid); |
| 4162 | } |
| 4163 | } |
| 4164 | |
| 4165 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4166 | * Make sure the caller has the MODIFY_PHONE_STATE permission. |
| 4167 | * |
| 4168 | * @throws SecurityException if the caller does not have the required permission |
| 4169 | */ |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 4170 | @VisibleForTesting |
| 4171 | public void enforceModifyPermission() { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4172 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null); |
| 4173 | } |
| 4174 | |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 4175 | /** |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 4176 | * Make sure the caller has the READ_PHONE_STATE permission. |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 4177 | * |
| 4178 | * @throws SecurityException if the caller does not have the required permission |
| 4179 | */ |
| 4180 | @VisibleForTesting |
| 4181 | public void enforceReadPermission() { |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 4182 | enforceReadPermission(null); |
| 4183 | } |
| 4184 | |
| 4185 | /** |
| 4186 | * Make sure the caller has the READ_PHONE_STATE permissions. |
| 4187 | * |
| 4188 | * @throws SecurityException if the caller does not have the READ_PHONE_STATE permission. |
| 4189 | */ |
| 4190 | @VisibleForTesting |
| 4191 | public void enforceReadPermission(String msg) { |
| 4192 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, msg); |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 4193 | } |
| 4194 | |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 4195 | private void enforceActiveEmergencySessionPermission() { |
| 4196 | mApp.enforceCallingOrSelfPermission( |
| 4197 | android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null); |
| 4198 | } |
| 4199 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4200 | /** |
| 4201 | * Make sure the caller has the CALL_PHONE permission. |
| 4202 | * |
| 4203 | * @throws SecurityException if the caller does not have the required permission |
| 4204 | */ |
| 4205 | private void enforceCallPermission() { |
| 4206 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null); |
| 4207 | } |
| 4208 | |
paulhu | 5a77360 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 4209 | private void enforceSettingsPermission() { |
| 4210 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 4211 | } |
| 4212 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 4213 | private void enforceRebootPermission() { |
| 4214 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null); |
| 4215 | } |
| 4216 | |
Aishwarya Mallampati | 60fe113 | 2023-01-24 19:07:21 +0000 | [diff] [blame] | 4217 | /** |
| 4218 | * Make sure the caller has SATELLITE_COMMUNICATION permission. |
| 4219 | * @param message - log message to print. |
| 4220 | * @throws SecurityException if the caller does not have the required permission |
| 4221 | */ |
| 4222 | private void enforceSatelliteCommunicationPermission(String message) { |
| 4223 | mApp.enforceCallingOrSelfPermission(permission.SATELLITE_COMMUNICATION, message); |
| 4224 | } |
| 4225 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4226 | private String createTelUrl(String number) { |
| 4227 | if (TextUtils.isEmpty(number)) { |
| 4228 | return null; |
| 4229 | } |
| 4230 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4231 | return "tel:" + number; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4232 | } |
| 4233 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 4234 | private static void log(String msg) { |
Ling Ma | 83dc5ea | 2023-01-12 15:06:04 -0800 | [diff] [blame] | 4235 | Log.d(LOG_TAG, msg); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4236 | } |
| 4237 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 4238 | private static void logv(String msg) { |
| 4239 | Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 4240 | } |
| 4241 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 4242 | private static void loge(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4243 | Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 4244 | } |
| 4245 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4246 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4247 | public int getActivePhoneType() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 4248 | return getActivePhoneTypeForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4249 | } |
| 4250 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4251 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 4252 | public int getActivePhoneTypeForSlot(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4253 | final long identity = Binder.clearCallingIdentity(); |
| 4254 | try { |
| 4255 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 4256 | if (phone == null) { |
| 4257 | return PhoneConstants.PHONE_TYPE_NONE; |
| 4258 | } else { |
| 4259 | return phone.getPhoneType(); |
| 4260 | } |
| 4261 | } finally { |
| 4262 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4263 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4264 | } |
| 4265 | |
| 4266 | /** |
| 4267 | * Returns the CDMA ERI icon index to display |
| 4268 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4269 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4270 | public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) { |
| 4271 | return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage, |
| 4272 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4273 | } |
| 4274 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4275 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4276 | public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage, |
| 4277 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4278 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4279 | mApp, subId, callingPackage, callingFeatureId, |
| 4280 | "getCdmaEriIconIndexForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4281 | return -1; |
| 4282 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4283 | |
| 4284 | final long identity = Binder.clearCallingIdentity(); |
| 4285 | try { |
| 4286 | final Phone phone = getPhone(subId); |
| 4287 | if (phone != null) { |
| 4288 | return phone.getCdmaEriIconIndex(); |
| 4289 | } else { |
| 4290 | return -1; |
| 4291 | } |
| 4292 | } finally { |
| 4293 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4294 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4295 | } |
| 4296 | |
| 4297 | /** |
| 4298 | * Returns the CDMA ERI icon mode, |
| 4299 | * 0 - ON |
| 4300 | * 1 - FLASHING |
| 4301 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4302 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4303 | public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) { |
| 4304 | return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 4305 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4306 | } |
| 4307 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4308 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4309 | public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage, |
| 4310 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4311 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4312 | mApp, subId, callingPackage, callingFeatureId, |
| 4313 | "getCdmaEriIconModeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4314 | return -1; |
| 4315 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4316 | |
| 4317 | final long identity = Binder.clearCallingIdentity(); |
| 4318 | try { |
| 4319 | final Phone phone = getPhone(subId); |
| 4320 | if (phone != null) { |
| 4321 | return phone.getCdmaEriIconMode(); |
| 4322 | } else { |
| 4323 | return -1; |
| 4324 | } |
| 4325 | } finally { |
| 4326 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4327 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4328 | } |
| 4329 | |
| 4330 | /** |
| 4331 | * Returns the CDMA ERI text, |
| 4332 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4333 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4334 | public String getCdmaEriText(String callingPackage, String callingFeatureId) { |
| 4335 | return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage, |
| 4336 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4337 | } |
| 4338 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4339 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4340 | public String getCdmaEriTextForSubscriber(int subId, String callingPackage, |
| 4341 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4342 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4343 | mApp, subId, callingPackage, callingFeatureId, |
| 4344 | "getCdmaEriIconTextForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4345 | return null; |
| 4346 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4347 | |
| 4348 | final long identity = Binder.clearCallingIdentity(); |
| 4349 | try { |
| 4350 | final Phone phone = getPhone(subId); |
| 4351 | if (phone != null) { |
| 4352 | return phone.getCdmaEriText(); |
| 4353 | } else { |
| 4354 | return null; |
| 4355 | } |
| 4356 | } finally { |
| 4357 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4358 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4359 | } |
| 4360 | |
| 4361 | /** |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 4362 | * Returns the CDMA MDN. |
| 4363 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4364 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 4365 | public String getCdmaMdn(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4366 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4367 | mApp, subId, "getCdmaMdn"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4368 | |
| 4369 | final long identity = Binder.clearCallingIdentity(); |
| 4370 | try { |
| 4371 | final Phone phone = getPhone(subId); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4372 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4373 | return phone.getLine1Number(); |
| 4374 | } else { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4375 | loge("getCdmaMdn: no phone found. Invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4376 | return null; |
| 4377 | } |
| 4378 | } finally { |
| 4379 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 4380 | } |
| 4381 | } |
| 4382 | |
| 4383 | /** |
| 4384 | * Returns the CDMA MIN. |
| 4385 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4386 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 4387 | public String getCdmaMin(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4388 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4389 | mApp, subId, "getCdmaMin"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4390 | |
| 4391 | final long identity = Binder.clearCallingIdentity(); |
| 4392 | try { |
| 4393 | final Phone phone = getPhone(subId); |
| 4394 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
| 4395 | return phone.getCdmaMin(); |
| 4396 | } else { |
| 4397 | return null; |
| 4398 | } |
| 4399 | } finally { |
| 4400 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 4401 | } |
| 4402 | } |
| 4403 | |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 4404 | @Override |
| 4405 | public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis, |
| 4406 | INumberVerificationCallback callback, String callingPackage) { |
| 4407 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 4408 | != PERMISSION_GRANTED) { |
| 4409 | throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission"); |
| 4410 | } |
| 4411 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 4412 | |
| 4413 | String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp); |
| 4414 | if (!TextUtils.equals(callingPackage, authorizedPackage)) { |
Hall Liu | b9d8feb | 2021-01-13 10:28:04 -0800 | [diff] [blame] | 4415 | throw new SecurityException("Calling package must be configured in the device config: " |
| 4416 | + "calling package: " + callingPackage |
| 4417 | + ", configured package: " + authorizedPackage); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 4418 | } |
| 4419 | |
| 4420 | if (range == null) { |
| 4421 | throw new NullPointerException("Range must be non-null"); |
| 4422 | } |
| 4423 | |
| 4424 | timeoutMillis = Math.min(timeoutMillis, |
Hall Liu | bd069e3 | 2019-02-28 18:56:30 -0800 | [diff] [blame] | 4425 | TelephonyManager.getMaxNumberVerificationTimeoutMillis()); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 4426 | |
| 4427 | NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis); |
| 4428 | } |
| 4429 | |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 4430 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4431 | * Returns true if CDMA provisioning needs to run. |
| 4432 | */ |
| 4433 | public boolean needsOtaServiceProvisioning() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4434 | final long identity = Binder.clearCallingIdentity(); |
| 4435 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4436 | return getDefaultPhone().needsOtaServiceProvisioning(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4437 | } finally { |
| 4438 | Binder.restoreCallingIdentity(identity); |
| 4439 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4440 | } |
| 4441 | |
| 4442 | /** |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 4443 | * Sets the voice mail number of a given subId. |
| 4444 | */ |
| 4445 | @Override |
| 4446 | public boolean setVoiceMailNumber(int subId, String alphaTag, String number) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 4447 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 4448 | mApp, subId, "setVoiceMailNumber"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4449 | |
| 4450 | final long identity = Binder.clearCallingIdentity(); |
| 4451 | try { |
| 4452 | Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER, |
| 4453 | new Pair<String, String>(alphaTag, number), new Integer(subId)); |
| 4454 | return success; |
| 4455 | } finally { |
| 4456 | Binder.restoreCallingIdentity(identity); |
| 4457 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 4458 | } |
| 4459 | |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 4460 | @Override |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 4461 | public Bundle getVisualVoicemailSettings(String callingPackage, int subId) { |
| 4462 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 4463 | TelecomManager tm = mApp.getSystemService(TelecomManager.class); |
| 4464 | String systemDialer = tm.getSystemDialerPackage(); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 4465 | if (!TextUtils.equals(callingPackage, systemDialer)) { |
| 4466 | throw new SecurityException("caller must be system dialer"); |
| 4467 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4468 | |
| 4469 | final long identity = Binder.clearCallingIdentity(); |
| 4470 | try { |
| 4471 | PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId); |
| 4472 | if (phoneAccountHandle == null) { |
| 4473 | return null; |
| 4474 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4475 | return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4476 | } finally { |
| 4477 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 4478 | } |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 4479 | } |
| 4480 | |
| 4481 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4482 | public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId, |
| 4483 | int subId) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 4484 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4485 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4486 | mApp, subId, callingPackage, callingFeatureId, |
| 4487 | "getVisualVoicemailPackageName")) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 4488 | return null; |
| 4489 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4490 | |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 4491 | final long identity = Binder.clearCallingIdentity(); |
| 4492 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4493 | return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName(); |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 4494 | } finally { |
| 4495 | Binder.restoreCallingIdentity(identity); |
| 4496 | } |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 4497 | } |
| 4498 | |
| 4499 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 4500 | public void enableVisualVoicemailSmsFilter(String callingPackage, int subId, |
| 4501 | VisualVoicemailSmsFilterSettings settings) { |
| 4502 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4503 | |
| 4504 | final long identity = Binder.clearCallingIdentity(); |
| 4505 | try { |
| 4506 | VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4507 | mApp, callingPackage, subId, settings); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4508 | } finally { |
| 4509 | Binder.restoreCallingIdentity(identity); |
| 4510 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 4511 | } |
| 4512 | |
| 4513 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 4514 | public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) { |
| 4515 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4516 | |
| 4517 | final long identity = Binder.clearCallingIdentity(); |
| 4518 | try { |
| 4519 | VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4520 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4521 | } finally { |
| 4522 | Binder.restoreCallingIdentity(identity); |
| 4523 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 4524 | } |
| 4525 | |
| 4526 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 4527 | public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings( |
| 4528 | String callingPackage, int subId) { |
| 4529 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4530 | |
| 4531 | final long identity = Binder.clearCallingIdentity(); |
| 4532 | try { |
| 4533 | return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4534 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4535 | } finally { |
| 4536 | Binder.restoreCallingIdentity(identity); |
| 4537 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 4538 | } |
| 4539 | |
| 4540 | @Override |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 4541 | public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4542 | enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4543 | |
| 4544 | final long identity = Binder.clearCallingIdentity(); |
| 4545 | try { |
| 4546 | return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4547 | mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4548 | } finally { |
| 4549 | Binder.restoreCallingIdentity(identity); |
| 4550 | } |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 4551 | } |
| 4552 | |
| 4553 | @Override |
Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 4554 | public void sendVisualVoicemailSmsForSubscriber(String callingPackage, |
| 4555 | String callingAttributionTag, int subId, String number, int port, String text, |
| 4556 | PendingIntent sentIntent) { |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 4557 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 4558 | enforceVisualVoicemailPackage(callingPackage, subId); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 4559 | enforceSendSmsPermission(); |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 4560 | SmsController smsController = PhoneFactory.getSmsController(); |
Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 4561 | smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag, |
| 4562 | subId, number, port, text, sentIntent); |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 4563 | } |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 4564 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 4565 | /** |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4566 | * Sets the voice activation state of a given subId. |
| 4567 | */ |
| 4568 | @Override |
| 4569 | public void setVoiceActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4570 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4571 | mApp, subId, "setVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4572 | |
| 4573 | final long identity = Binder.clearCallingIdentity(); |
| 4574 | try { |
| 4575 | final Phone phone = getPhone(subId); |
| 4576 | if (phone != null) { |
| 4577 | phone.setVoiceActivationState(activationState); |
| 4578 | } else { |
| 4579 | loge("setVoiceActivationState fails with invalid subId: " + subId); |
| 4580 | } |
| 4581 | } finally { |
| 4582 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4583 | } |
| 4584 | } |
| 4585 | |
| 4586 | /** |
| 4587 | * Sets the data activation state of a given subId. |
| 4588 | */ |
| 4589 | @Override |
| 4590 | public void setDataActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4591 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4592 | mApp, subId, "setDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4593 | |
| 4594 | final long identity = Binder.clearCallingIdentity(); |
| 4595 | try { |
| 4596 | final Phone phone = getPhone(subId); |
| 4597 | if (phone != null) { |
| 4598 | phone.setDataActivationState(activationState); |
| 4599 | } else { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 4600 | loge("setDataActivationState fails with invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4601 | } |
| 4602 | } finally { |
| 4603 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4604 | } |
| 4605 | } |
| 4606 | |
| 4607 | /** |
| 4608 | * Returns the voice activation state of a given subId. |
| 4609 | */ |
| 4610 | @Override |
| 4611 | public int getVoiceActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4612 | enforceReadPrivilegedPermission("getVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4613 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4614 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4615 | final long identity = Binder.clearCallingIdentity(); |
| 4616 | try { |
| 4617 | if (phone != null) { |
| 4618 | return phone.getVoiceActivationState(); |
| 4619 | } else { |
| 4620 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 4621 | } |
| 4622 | } finally { |
| 4623 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4624 | } |
| 4625 | } |
| 4626 | |
| 4627 | /** |
| 4628 | * Returns the data activation state of a given subId. |
| 4629 | */ |
| 4630 | @Override |
| 4631 | public int getDataActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4632 | enforceReadPrivilegedPermission("getDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4633 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4634 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4635 | final long identity = Binder.clearCallingIdentity(); |
| 4636 | try { |
| 4637 | if (phone != null) { |
| 4638 | return phone.getDataActivationState(); |
| 4639 | } else { |
| 4640 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 4641 | } |
| 4642 | } finally { |
| 4643 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4644 | } |
| 4645 | } |
| 4646 | |
| 4647 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4648 | * Returns the unread count of voicemails for a subId |
| 4649 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4650 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4651 | public int getVoiceMessageCountForSubscriber(int subId, String callingPackage, |
| 4652 | String callingFeatureId) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 4653 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4654 | mApp, subId, callingPackage, callingFeatureId, |
| 4655 | "getVoiceMessageCountForSubscriber")) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 4656 | return 0; |
| 4657 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4658 | final long identity = Binder.clearCallingIdentity(); |
| 4659 | try { |
| 4660 | final Phone phone = getPhone(subId); |
| 4661 | if (phone != null) { |
| 4662 | return phone.getVoiceMessageCount(); |
| 4663 | } else { |
| 4664 | return 0; |
| 4665 | } |
| 4666 | } finally { |
| 4667 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4668 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4669 | } |
| 4670 | |
| 4671 | /** |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 4672 | * returns true, if the device is in a state where both voice and data |
| 4673 | * are supported simultaneously. This can change based on location or network condition. |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 4674 | */ |
| 4675 | @Override |
| 4676 | public boolean isConcurrentVoiceAndDataAllowed(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4677 | final long identity = Binder.clearCallingIdentity(); |
| 4678 | try { |
| 4679 | final Phone phone = getPhone(subId); |
| 4680 | return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed()); |
| 4681 | } finally { |
| 4682 | Binder.restoreCallingIdentity(identity); |
| 4683 | } |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 4684 | } |
| 4685 | |
| 4686 | /** |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4687 | * Send the dialer code if called from the current default dialer or the caller has |
| 4688 | * carrier privilege. |
| 4689 | * @param inputCode The dialer code to send |
| 4690 | */ |
| 4691 | @Override |
| 4692 | public void sendDialerSpecialCode(String callingPackage, String inputCode) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4693 | final Phone defaultPhone = getDefaultPhone(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4694 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 4695 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 4696 | String defaultDialer = tm.getDefaultDialerPackage(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4697 | if (!TextUtils.equals(callingPackage, defaultDialer)) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 4698 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4699 | getDefaultSubscription(), "sendDialerSpecialCode"); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4700 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4701 | |
| 4702 | final long identity = Binder.clearCallingIdentity(); |
| 4703 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4704 | defaultPhone.sendDialerSpecialCode(inputCode); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4705 | } finally { |
| 4706 | Binder.restoreCallingIdentity(identity); |
| 4707 | } |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4708 | } |
| 4709 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 4710 | @Override |
| 4711 | public int getNetworkSelectionMode(int subId) { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 4712 | TelephonyPermissions |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 4713 | .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4714 | mApp, subId, "getNetworkSelectionMode"); |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 4715 | final long identity = Binder.clearCallingIdentity(); |
| 4716 | try { |
| 4717 | if (!isActiveSubscription(subId)) { |
| 4718 | return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 4719 | } |
| 4720 | return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId); |
| 4721 | } finally { |
| 4722 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 4723 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 4724 | } |
| 4725 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4726 | @Override |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 4727 | public boolean isInEmergencySmsMode() { |
| 4728 | enforceReadPrivilegedPermission("isInEmergencySmsMode"); |
| 4729 | final long identity = Binder.clearCallingIdentity(); |
| 4730 | try { |
| 4731 | for (Phone phone : PhoneFactory.getPhones()) { |
| 4732 | if (phone.isInEmergencySmsMode()) { |
| 4733 | return true; |
| 4734 | } |
| 4735 | } |
| 4736 | } finally { |
| 4737 | Binder.restoreCallingIdentity(identity); |
| 4738 | } |
| 4739 | return false; |
| 4740 | } |
| 4741 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4742 | /** |
| 4743 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4744 | * @param subId The subscription to use to check the configuration. |
| 4745 | * @param c The callback that will be used to send the result. |
| 4746 | */ |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 4747 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4748 | public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c) |
| 4749 | throws RemoteException { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4750 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4751 | mApp, subId, "registerImsRegistrationCallback"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4752 | |
| 4753 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4754 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4755 | "IMS not available on device."); |
| 4756 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4757 | final long token = Binder.clearCallingIdentity(); |
| 4758 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4759 | int slotId = getSlotIndexOrException(subId); |
| 4760 | verifyImsMmTelConfiguredOrThrow(slotId); |
joonhunshin | 49f0aed | 2022-08-05 08:33:05 +0000 | [diff] [blame] | 4761 | |
| 4762 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4763 | if (controller != null) { |
| 4764 | ImsManager imsManager = controller.getImsManager(subId); |
| 4765 | if (imsManager != null) { |
| 4766 | imsManager.addRegistrationCallbackForSubscription(c, subId); |
| 4767 | } else { |
| 4768 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE); |
| 4769 | } |
| 4770 | } else { |
| 4771 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION); |
| 4772 | } |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4773 | } catch (ImsException e) { |
| 4774 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4775 | } finally { |
| 4776 | Binder.restoreCallingIdentity(token); |
| 4777 | } |
| 4778 | } |
| 4779 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4780 | /** |
| 4781 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4782 | * @param subId The subscription to use to check the configuration. |
| 4783 | * @param c The callback that will be used to send the result. |
| 4784 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4785 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4786 | public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4787 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4788 | mApp, subId, "unregisterImsRegistrationCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4789 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4790 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4791 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4792 | final long token = Binder.clearCallingIdentity(); |
joonhunshin | 49f0aed | 2022-08-05 08:33:05 +0000 | [diff] [blame] | 4793 | |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4794 | try { |
joonhunshin | 49f0aed | 2022-08-05 08:33:05 +0000 | [diff] [blame] | 4795 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4796 | if (controller != null) { |
| 4797 | ImsManager imsManager = controller.getImsManager(subId); |
| 4798 | if (imsManager != null) { |
| 4799 | imsManager.removeRegistrationCallbackForSubscription(c, subId); |
| 4800 | } else { |
| 4801 | Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId |
| 4802 | + "is inactive, ignoring unregister."); |
| 4803 | // If the ImsManager is not valid, just return, since the callback |
| 4804 | // will already have been removed internally. |
| 4805 | } |
| 4806 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4807 | } finally { |
| 4808 | Binder.restoreCallingIdentity(token); |
| 4809 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4810 | } |
| 4811 | |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 4812 | /** |
| 4813 | * Get the IMS service registration state for the MmTelFeature associated with this sub id. |
| 4814 | */ |
| 4815 | @Override |
| 4816 | public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) { |
| 4817 | enforceReadPrivilegedPermission("getImsMmTelRegistrationState"); |
| 4818 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4819 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4820 | "IMS not available on device."); |
| 4821 | } |
| 4822 | final long token = Binder.clearCallingIdentity(); |
| 4823 | try { |
| 4824 | Phone phone = getPhone(subId); |
| 4825 | if (phone == null) { |
| 4826 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 4827 | + subId + "'"); |
| 4828 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 4829 | } |
| 4830 | phone.getImsRegistrationState(regState -> { |
| 4831 | try { |
| 4832 | consumer.accept((regState == null) |
| 4833 | ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState); |
| 4834 | } catch (RemoteException e) { |
| 4835 | // Ignore if the remote process is no longer available to call back. |
| 4836 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 4837 | } |
| 4838 | }); |
| 4839 | } finally { |
| 4840 | Binder.restoreCallingIdentity(token); |
| 4841 | } |
| 4842 | } |
| 4843 | |
| 4844 | /** |
| 4845 | * Get the transport type for the IMS service registration state. |
| 4846 | */ |
| 4847 | @Override |
| 4848 | public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4849 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4850 | mApp, subId, "getImsMmTelRegistrationTransportType"); |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 4851 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4852 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4853 | "IMS not available on device."); |
| 4854 | } |
| 4855 | final long token = Binder.clearCallingIdentity(); |
| 4856 | try { |
| 4857 | Phone phone = getPhone(subId); |
| 4858 | if (phone == null) { |
| 4859 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 4860 | + subId + "'"); |
| 4861 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 4862 | } |
| 4863 | phone.getImsRegistrationTech(regTech -> { |
| 4864 | // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager |
| 4865 | int regTechConverted = (regTech == null) |
| 4866 | ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech; |
| 4867 | regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get( |
| 4868 | regTechConverted); |
| 4869 | try { |
| 4870 | consumer.accept(regTechConverted); |
| 4871 | } catch (RemoteException e) { |
| 4872 | // Ignore if the remote process is no longer available to call back. |
| 4873 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 4874 | } |
| 4875 | }); |
| 4876 | } finally { |
| 4877 | Binder.restoreCallingIdentity(token); |
| 4878 | } |
| 4879 | } |
| 4880 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4881 | /** |
| 4882 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4883 | * @param subId The subscription to use to check the configuration. |
| 4884 | * @param c The callback that will be used to send the result. |
| 4885 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4886 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4887 | public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) |
| 4888 | throws RemoteException { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4889 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4890 | mApp, subId, "registerMmTelCapabilityCallback"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4891 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4892 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4893 | "IMS not available on device."); |
| 4894 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4895 | final long token = Binder.clearCallingIdentity(); |
| 4896 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4897 | int slotId = getSlotIndexOrException(subId); |
| 4898 | verifyImsMmTelConfiguredOrThrow(slotId); |
Hwangoo Park | 8646b0d | 2023-01-13 02:42:34 +0000 | [diff] [blame] | 4899 | |
| 4900 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4901 | if (controller != null) { |
| 4902 | ImsManager imsManager = controller.getImsManager(subId); |
| 4903 | if (imsManager != null) { |
| 4904 | imsManager.addCapabilitiesCallbackForSubscription(c, subId); |
| 4905 | } else { |
| 4906 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE); |
| 4907 | } |
| 4908 | } else { |
| 4909 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION); |
| 4910 | } |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4911 | } catch (ImsException e) { |
| 4912 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4913 | } finally { |
| 4914 | Binder.restoreCallingIdentity(token); |
| 4915 | } |
| 4916 | } |
| 4917 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4918 | /** |
| 4919 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4920 | * @param subId The subscription to use to check the configuration. |
| 4921 | * @param c The callback that will be used to send the result. |
| 4922 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4923 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4924 | public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4925 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4926 | mApp, subId, "unregisterMmTelCapabilityCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4927 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4928 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4929 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4930 | |
| 4931 | final long token = Binder.clearCallingIdentity(); |
| 4932 | try { |
Hwangoo Park | 8646b0d | 2023-01-13 02:42:34 +0000 | [diff] [blame] | 4933 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4934 | if (controller != null) { |
| 4935 | ImsManager imsManager = controller.getImsManager(subId); |
| 4936 | if (imsManager != null) { |
| 4937 | imsManager.removeCapabilitiesCallbackForSubscription(c, subId); |
| 4938 | } else { |
| 4939 | Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId |
| 4940 | + " is inactive, ignoring unregister."); |
| 4941 | // If the ImsManager is not valid, just return, since the callback |
| 4942 | // will already have been removed internally. |
| 4943 | } |
| 4944 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4945 | } finally { |
| 4946 | Binder.restoreCallingIdentity(token); |
| 4947 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4948 | } |
| 4949 | |
| 4950 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4951 | public boolean isCapable(int subId, int capability, int regTech) { |
| 4952 | enforceReadPrivilegedPermission("isCapable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4953 | final long token = Binder.clearCallingIdentity(); |
| 4954 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4955 | int slotId = getSlotIndexOrException(subId); |
| 4956 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 4957 | return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech); |
| 4958 | } catch (com.android.ims.ImsException e) { |
| 4959 | Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage()); |
| 4960 | return false; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4961 | } catch (ImsException e) { |
Brad Ebinger | 6b5ac22 | 2019-02-04 14:36:52 -0800 | [diff] [blame] | 4962 | Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false."); |
| 4963 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4964 | } finally { |
| 4965 | Binder.restoreCallingIdentity(token); |
| 4966 | } |
| 4967 | } |
| 4968 | |
| 4969 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4970 | public boolean isAvailable(int subId, int capability, int regTech) { |
| 4971 | enforceReadPrivilegedPermission("isAvailable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4972 | final long token = Binder.clearCallingIdentity(); |
| 4973 | try { |
| 4974 | Phone phone = getPhone(subId); |
| 4975 | if (phone == null) return false; |
| 4976 | return phone.isImsCapabilityAvailable(capability, regTech); |
Daniel Bright | 5e40e4e | 2020-03-11 16:35:39 -0700 | [diff] [blame] | 4977 | } catch (com.android.ims.ImsException e) { |
| 4978 | Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage()); |
| 4979 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4980 | } finally { |
| 4981 | Binder.restoreCallingIdentity(token); |
| 4982 | } |
| 4983 | } |
| 4984 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4985 | /** |
| 4986 | * Determines if the MmTel feature capability is supported by the carrier configuration for this |
| 4987 | * subscription. |
| 4988 | * @param subId The subscription to use to check the configuration. |
| 4989 | * @param callback The callback that will be used to send the result. |
| 4990 | * @param capability The MmTelFeature capability that will be used to send the result. |
| 4991 | * @param transportType The transport type of the MmTelFeature capability. |
| 4992 | */ |
| 4993 | @Override |
| 4994 | public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability, |
| 4995 | int transportType) { |
| 4996 | enforceReadPrivilegedPermission("isMmTelCapabilitySupported"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4997 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4998 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4999 | "IMS not available on device."); |
| 5000 | } |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 5001 | final long token = Binder.clearCallingIdentity(); |
| 5002 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 5003 | int slotId = getSlotIndex(subId); |
| 5004 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5005 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '" |
| 5006 | + subId + "'"); |
| 5007 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 5008 | } |
| 5009 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 5010 | ImsManager.getInstance(mApp, slotId).isSupported(capability, |
| 5011 | transportType, aBoolean -> { |
| 5012 | try { |
| 5013 | callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0)); |
| 5014 | } catch (RemoteException e) { |
| 5015 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not " |
| 5016 | + "running. Ignore"); |
| 5017 | } |
| 5018 | }); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5019 | } catch (ImsException e) { |
| 5020 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 5021 | } finally { |
| 5022 | Binder.restoreCallingIdentity(token); |
| 5023 | } |
| 5024 | } |
| 5025 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 5026 | /** |
| 5027 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 5028 | * @param subId The subscription to use to check the configuration. |
| 5029 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5030 | @Override |
| 5031 | public boolean isAdvancedCallingSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 5032 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 5033 | mApp, subId, "isAdvancedCallingSettingEnabled"); |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 5034 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5035 | final long token = Binder.clearCallingIdentity(); |
| 5036 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5037 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5038 | // 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] | 5039 | return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5040 | } catch (ImsException e) { |
| 5041 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5042 | } finally { |
| 5043 | Binder.restoreCallingIdentity(token); |
| 5044 | } |
| 5045 | } |
| 5046 | |
| 5047 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 5048 | public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5049 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 5050 | "setAdvancedCallingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5051 | final long identity = Binder.clearCallingIdentity(); |
| 5052 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5053 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5054 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 5055 | // 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] | 5056 | ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5057 | } catch (ImsException e) { |
| 5058 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5059 | } finally { |
| 5060 | Binder.restoreCallingIdentity(identity); |
| 5061 | } |
| 5062 | } |
| 5063 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 5064 | /** |
| 5065 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 5066 | * @param subId The subscription to use to check the configuration. |
| 5067 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5068 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 5069 | public boolean isVtSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 5070 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 5071 | mApp, subId, "isVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5072 | final long identity = Binder.clearCallingIdentity(); |
| 5073 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5074 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5075 | // 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] | 5076 | return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5077 | } catch (ImsException e) { |
| 5078 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5079 | } finally { |
| 5080 | Binder.restoreCallingIdentity(identity); |
| 5081 | } |
| 5082 | } |
| 5083 | |
| 5084 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 5085 | public void setVtSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5086 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 5087 | "setVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5088 | final long identity = Binder.clearCallingIdentity(); |
| 5089 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5090 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5091 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 5092 | // 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] | 5093 | ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5094 | } catch (ImsException e) { |
| 5095 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5096 | } finally { |
| 5097 | Binder.restoreCallingIdentity(identity); |
| 5098 | } |
| 5099 | } |
| 5100 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 5101 | /** |
| 5102 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 5103 | * @param subId The subscription to use to check the configuration. |
| 5104 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5105 | @Override |
| 5106 | public boolean isVoWiFiSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 5107 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 5108 | mApp, subId, "isVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5109 | final long identity = Binder.clearCallingIdentity(); |
| 5110 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5111 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5112 | // 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] | 5113 | return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5114 | } catch (ImsException e) { |
| 5115 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5116 | } finally { |
| 5117 | Binder.restoreCallingIdentity(identity); |
| 5118 | } |
| 5119 | } |
| 5120 | |
| 5121 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 5122 | public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5123 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 5124 | "setVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5125 | final long identity = Binder.clearCallingIdentity(); |
| 5126 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5127 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5128 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 5129 | // 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] | 5130 | ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5131 | } catch (ImsException e) { |
| 5132 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5133 | } finally { |
| 5134 | Binder.restoreCallingIdentity(identity); |
| 5135 | } |
| 5136 | } |
| 5137 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 5138 | /** |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 5139 | * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not |
| 5140 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 5141 | * @param subId The subscription to use to check the configuration. |
| 5142 | */ |
| 5143 | @Override |
| 5144 | public boolean isCrossSimCallingEnabledByUser(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 5145 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 5146 | mApp, subId, "isCrossSimCallingEnabledByUser"); |
| 5147 | final long identity = Binder.clearCallingIdentity(); |
| 5148 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5149 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5150 | // 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] | 5151 | return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser(); |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 5152 | } catch (ImsException e) { |
| 5153 | throw new ServiceSpecificException(e.getCode()); |
| 5154 | } finally { |
| 5155 | Binder.restoreCallingIdentity(identity); |
| 5156 | } |
| 5157 | } |
| 5158 | |
| 5159 | /** |
| 5160 | * Sets the user's setting for whether or not Voice over Cross SIM is enabled. |
| 5161 | * Requires MODIFY_PHONE_STATE permission. |
| 5162 | * @param subId The subscription to use to check the configuration. |
| 5163 | * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled, |
| 5164 | * false otherwise |
| 5165 | */ |
| 5166 | @Override |
| 5167 | public void setCrossSimCallingEnabled(int subId, boolean isEnabled) { |
| 5168 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5169 | "setCrossSimCallingEnabled"); |
| 5170 | final long identity = Binder.clearCallingIdentity(); |
| 5171 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5172 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5173 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 5174 | // 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] | 5175 | ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled); |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 5176 | } catch (ImsException e) { |
| 5177 | throw new ServiceSpecificException(e.getCode()); |
| 5178 | } finally { |
| 5179 | Binder.restoreCallingIdentity(identity); |
| 5180 | } |
| 5181 | } |
| 5182 | |
| 5183 | /** |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 5184 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 5185 | * @param subId The subscription to use to check the configuration. |
| 5186 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5187 | @Override |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 5188 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5189 | public boolean isVoWiFiRoamingSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 5190 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 5191 | mApp, subId, "isVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5192 | final long identity = Binder.clearCallingIdentity(); |
| 5193 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5194 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5195 | // 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] | 5196 | return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5197 | } catch (ImsException e) { |
| 5198 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5199 | } finally { |
| 5200 | Binder.restoreCallingIdentity(identity); |
| 5201 | } |
| 5202 | } |
| 5203 | |
| 5204 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 5205 | public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5206 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 5207 | "setVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5208 | final long identity = Binder.clearCallingIdentity(); |
| 5209 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5210 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5211 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 5212 | // 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] | 5213 | ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5214 | } catch (ImsException e) { |
| 5215 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5216 | } finally { |
| 5217 | Binder.restoreCallingIdentity(identity); |
| 5218 | } |
| 5219 | } |
| 5220 | |
| 5221 | @Override |
| 5222 | public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) { |
| 5223 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5224 | "setVoWiFiNonPersistent"); |
| 5225 | final long identity = Binder.clearCallingIdentity(); |
| 5226 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5227 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5228 | // This setting will be ignored if the ImsService isn't up. |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5229 | ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5230 | } catch (ImsException e) { |
| 5231 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5232 | } finally { |
| 5233 | Binder.restoreCallingIdentity(identity); |
| 5234 | } |
| 5235 | } |
| 5236 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 5237 | /** |
| 5238 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 5239 | * @param subId The subscription to use to check the configuration. |
| 5240 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5241 | @Override |
| 5242 | public int getVoWiFiModeSetting(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 5243 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 5244 | mApp, subId, "getVoWiFiModeSetting"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5245 | final long identity = Binder.clearCallingIdentity(); |
| 5246 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5247 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5248 | // 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] | 5249 | return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5250 | } catch (ImsException e) { |
| 5251 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5252 | } finally { |
| 5253 | Binder.restoreCallingIdentity(identity); |
| 5254 | } |
| 5255 | } |
| 5256 | |
| 5257 | @Override |
| 5258 | public void setVoWiFiModeSetting(int subId, int mode) { |
| 5259 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5260 | "setVoWiFiModeSetting"); |
| 5261 | final long identity = Binder.clearCallingIdentity(); |
| 5262 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5263 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5264 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 5265 | // 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] | 5266 | ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5267 | } catch (ImsException e) { |
| 5268 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5269 | } finally { |
| 5270 | Binder.restoreCallingIdentity(identity); |
| 5271 | } |
| 5272 | } |
| 5273 | |
| 5274 | @Override |
| 5275 | public int getVoWiFiRoamingModeSetting(int subId) { |
| 5276 | enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting"); |
| 5277 | final long identity = Binder.clearCallingIdentity(); |
| 5278 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5279 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5280 | // 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] | 5281 | return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5282 | } catch (ImsException e) { |
| 5283 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5284 | } finally { |
| 5285 | Binder.restoreCallingIdentity(identity); |
| 5286 | } |
| 5287 | } |
| 5288 | |
| 5289 | @Override |
| 5290 | public void setVoWiFiRoamingModeSetting(int subId, int mode) { |
| 5291 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5292 | "setVoWiFiRoamingModeSetting"); |
| 5293 | final long identity = Binder.clearCallingIdentity(); |
| 5294 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5295 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5296 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 5297 | // 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] | 5298 | ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5299 | } catch (ImsException e) { |
| 5300 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5301 | } finally { |
| 5302 | Binder.restoreCallingIdentity(identity); |
| 5303 | } |
| 5304 | } |
| 5305 | |
| 5306 | @Override |
| 5307 | public void setRttCapabilitySetting(int subId, boolean isEnabled) { |
| 5308 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5309 | "setRttCapabilityEnabled"); |
| 5310 | final long identity = Binder.clearCallingIdentity(); |
| 5311 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5312 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5313 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 5314 | // 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] | 5315 | ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5316 | } catch (ImsException e) { |
| 5317 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5318 | } finally { |
| 5319 | Binder.restoreCallingIdentity(identity); |
| 5320 | } |
| 5321 | } |
| 5322 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 5323 | /** |
| 5324 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 5325 | * @param subId The subscription to use to check the configuration. |
| 5326 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5327 | @Override |
| 5328 | public boolean isTtyOverVolteEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 5329 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 5330 | mApp, subId, "isTtyOverVolteEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5331 | final long identity = Binder.clearCallingIdentity(); |
| 5332 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5333 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5334 | // 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] | 5335 | return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5336 | } catch (ImsException e) { |
| 5337 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5338 | } finally { |
| 5339 | Binder.restoreCallingIdentity(identity); |
| 5340 | } |
| 5341 | } |
| 5342 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5343 | @Override |
| 5344 | public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 5345 | enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5346 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5347 | final long identity = Binder.clearCallingIdentity(); |
| 5348 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 5349 | if (!isImsAvailableOnDevice()) { |
| 5350 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 5351 | "IMS not available on device."); |
| 5352 | } |
| 5353 | int slotId = getSlotIndexOrException(subId); |
| 5354 | verifyImsMmTelConfiguredOrThrow(slotId); |
Hwangoo Park | 8646b0d | 2023-01-13 02:42:34 +0000 | [diff] [blame] | 5355 | |
| 5356 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 5357 | if (controller != null) { |
| 5358 | ImsManager imsManager = controller.getImsManager(subId); |
| 5359 | if (imsManager != null) { |
| 5360 | imsManager.addProvisioningCallbackForSubscription(callback, subId); |
| 5361 | } else { |
| 5362 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE); |
| 5363 | } |
| 5364 | } else { |
| 5365 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION); |
| 5366 | } |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5367 | } catch (ImsException e) { |
| 5368 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5369 | } finally { |
| 5370 | Binder.restoreCallingIdentity(identity); |
| 5371 | } |
| 5372 | } |
| 5373 | |
| 5374 | @Override |
| 5375 | public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 5376 | enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5377 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5378 | final long identity = Binder.clearCallingIdentity(); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 5379 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5380 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 5381 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5382 | try { |
Hwangoo Park | 8646b0d | 2023-01-13 02:42:34 +0000 | [diff] [blame] | 5383 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 5384 | if (controller != null) { |
| 5385 | ImsManager imsManager = controller.getImsManager(subId); |
| 5386 | if (imsManager != null) { |
| 5387 | imsManager.removeProvisioningCallbackForSubscription(callback, subId); |
| 5388 | } else { |
| 5389 | Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId |
| 5390 | + " is inactive, ignoring unregister."); |
| 5391 | // If the ImsManager is not valid, just return, since the callback will already |
| 5392 | // have been removed internally. |
| 5393 | } |
| 5394 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5395 | } finally { |
| 5396 | Binder.restoreCallingIdentity(identity); |
| 5397 | } |
| 5398 | } |
| 5399 | |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5400 | @Override |
| 5401 | public void registerFeatureProvisioningChangedCallback(int subId, |
| 5402 | IFeatureProvisioningCallback callback) { |
| 5403 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5404 | mApp, subId, "registerFeatureProvisioningChangedCallback"); |
| 5405 | |
| 5406 | final long identity = Binder.clearCallingIdentity(); |
| 5407 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5408 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 5409 | } |
| 5410 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5411 | try { |
| 5412 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5413 | if (controller == null) { |
| 5414 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 5415 | "Device does not support IMS"); |
| 5416 | } |
| 5417 | controller.addFeatureProvisioningChangedCallback(subId, callback); |
| 5418 | } finally { |
| 5419 | Binder.restoreCallingIdentity(identity); |
| 5420 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5421 | } |
| 5422 | |
| 5423 | @Override |
| 5424 | public void unregisterFeatureProvisioningChangedCallback(int subId, |
| 5425 | IFeatureProvisioningCallback callback) { |
| 5426 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5427 | mApp, subId, "unregisterFeatureProvisioningChangedCallback"); |
| 5428 | |
| 5429 | final long identity = Binder.clearCallingIdentity(); |
| 5430 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5431 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 5432 | } |
| 5433 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5434 | try { |
| 5435 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5436 | if (controller == null) { |
| 5437 | loge("unregisterFeatureProvisioningChangedCallback: Device does not support IMS"); |
| 5438 | return; |
| 5439 | } |
| 5440 | controller.removeFeatureProvisioningChangedCallback(subId, callback); |
| 5441 | } finally { |
| 5442 | Binder.restoreCallingIdentity(identity); |
| 5443 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5444 | } |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5445 | |
| 5446 | private void checkModifyPhoneStatePermission(int subId, String message) { |
| 5447 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5448 | message); |
| 5449 | } |
| 5450 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5451 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5452 | public void setRcsProvisioningStatusForCapability(int subId, int capability, int tech, |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5453 | boolean isProvisioned) { |
| 5454 | checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability"); |
| 5455 | |
| 5456 | final long identity = Binder.clearCallingIdentity(); |
| 5457 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5458 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5459 | if (controller == null) { |
| 5460 | loge("setRcsProvisioningStatusForCapability: Device does not support IMS"); |
| 5461 | return; |
| 5462 | } |
| 5463 | controller.setRcsProvisioningStatusForCapability( |
| 5464 | subId, capability, tech, isProvisioned); |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5465 | } finally { |
| 5466 | Binder.restoreCallingIdentity(identity); |
| 5467 | } |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5468 | } |
| 5469 | |
| 5470 | |
| 5471 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5472 | public boolean getRcsProvisioningStatusForCapability(int subId, int capability, int tech) { |
| 5473 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5474 | mApp, subId, "getRcsProvisioningStatusForCapability"); |
| 5475 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5476 | final long identity = Binder.clearCallingIdentity(); |
| 5477 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5478 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5479 | if (controller == null) { |
| 5480 | loge("getRcsProvisioningStatusForCapability: Device does not support IMS"); |
| 5481 | |
| 5482 | // device does not support IMS, this method will return true always. |
| 5483 | return true; |
| 5484 | } |
| 5485 | return controller.getRcsProvisioningStatusForCapability(subId, capability, tech); |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5486 | } finally { |
| 5487 | Binder.restoreCallingIdentity(identity); |
| 5488 | } |
| 5489 | } |
| 5490 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5491 | @Override |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5492 | public void setImsProvisioningStatusForCapability(int subId, int capability, int tech, |
| 5493 | boolean isProvisioned) { |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5494 | checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5495 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5496 | final long identity = Binder.clearCallingIdentity(); |
| 5497 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5498 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5499 | if (controller == null) { |
| 5500 | loge("setImsProvisioningStatusForCapability: Device does not support IMS"); |
| 5501 | return; |
| 5502 | } |
| 5503 | controller.setImsProvisioningStatusForCapability( |
| 5504 | subId, capability, tech, isProvisioned); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5505 | } finally { |
| 5506 | Binder.restoreCallingIdentity(identity); |
| 5507 | } |
| 5508 | } |
| 5509 | |
| 5510 | @Override |
| 5511 | public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) { |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5512 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5513 | mApp, subId, "getProvisioningStatusForCapability"); |
| 5514 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5515 | final long identity = Binder.clearCallingIdentity(); |
| 5516 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5517 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5518 | if (controller == null) { |
| 5519 | loge("getImsProvisioningStatusForCapability: Device does not support IMS"); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5520 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5521 | // device does not support IMS, this method will return true always. |
| 5522 | return true; |
| 5523 | } |
| 5524 | return controller.getImsProvisioningStatusForCapability(subId, capability, tech); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5525 | } finally { |
| 5526 | Binder.restoreCallingIdentity(identity); |
| 5527 | } |
| 5528 | } |
| 5529 | |
| 5530 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5531 | public boolean isProvisioningRequiredForCapability(int subId, int capability, int tech) { |
| 5532 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5533 | mApp, subId, "isProvisioningRequiredForCapability"); |
| 5534 | |
| 5535 | final long identity = Binder.clearCallingIdentity(); |
| 5536 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5537 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5538 | if (controller == null) { |
| 5539 | loge("isProvisioningRequiredForCapability: Device does not support IMS"); |
| 5540 | |
| 5541 | // device does not support IMS, this method will return false |
| 5542 | return false; |
| 5543 | } |
| 5544 | return controller.isImsProvisioningRequiredForCapability(subId, capability, tech); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5545 | } finally { |
| 5546 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5547 | } |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5548 | } |
| 5549 | |
| 5550 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5551 | public boolean isRcsProvisioningRequiredForCapability(int subId, int capability, int tech) { |
| 5552 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5553 | mApp, subId, "isProvisioningRequiredForCapability"); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5554 | |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5555 | final long identity = Binder.clearCallingIdentity(); |
| 5556 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5557 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5558 | if (controller == null) { |
| 5559 | loge("isRcsProvisioningRequiredForCapability: Device does not support IMS"); |
| 5560 | |
| 5561 | // device does not support IMS, this method will return false |
| 5562 | return false; |
| 5563 | } |
| 5564 | return controller.isRcsProvisioningRequiredForCapability(subId, capability, tech); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5565 | } finally { |
| 5566 | Binder.restoreCallingIdentity(identity); |
| 5567 | } |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5568 | } |
| 5569 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5570 | @Override |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5571 | public int getImsProvisioningInt(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5572 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5573 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 5574 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5575 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5576 | mApp, subId, "getImsProvisioningInt"); |
| 5577 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5578 | final long identity = Binder.clearCallingIdentity(); |
| 5579 | try { |
| 5580 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5581 | int slotId = getSlotIndex(subId); |
| 5582 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5583 | Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '" |
| 5584 | + subId + "' for key:" + key); |
| 5585 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
| 5586 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5587 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5588 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5589 | if (controller == null) { |
| 5590 | loge("getImsProvisioningInt: Device does not support IMS"); |
| 5591 | |
| 5592 | // device does not support IMS, this method will return CONFIG_RESULT_UNKNOWN. |
| 5593 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
| 5594 | } |
| 5595 | int retVal = controller.getProvisioningValue(subId, key); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5596 | if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) { |
| 5597 | return retVal; |
| 5598 | } |
| 5599 | |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5600 | return ImsManager.getInstance(mApp, slotId).getConfigInt(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5601 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5602 | Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '" |
| 5603 | + subId + "' for key:" + key); |
| 5604 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5605 | } finally { |
| 5606 | Binder.restoreCallingIdentity(identity); |
| 5607 | } |
| 5608 | } |
| 5609 | |
| 5610 | @Override |
| 5611 | public String getImsProvisioningString(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5612 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5613 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 5614 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5615 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5616 | mApp, subId, "getImsProvisioningString"); |
| 5617 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5618 | final long identity = Binder.clearCallingIdentity(); |
| 5619 | try { |
| 5620 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5621 | int slotId = getSlotIndex(subId); |
| 5622 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5623 | Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '" |
| 5624 | + subId + "' for key:" + key); |
| 5625 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC; |
| 5626 | } |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5627 | return ImsManager.getInstance(mApp, slotId).getConfigString(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5628 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5629 | Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '" |
| 5630 | + subId + "' for key:" + key); |
| 5631 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5632 | } finally { |
| 5633 | Binder.restoreCallingIdentity(identity); |
| 5634 | } |
| 5635 | } |
| 5636 | |
| 5637 | @Override |
| 5638 | public int setImsProvisioningInt(int subId, int key, int value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5639 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5640 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 5641 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 5642 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5643 | "setImsProvisioningInt"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5644 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5645 | final long identity = Binder.clearCallingIdentity(); |
| 5646 | try { |
| 5647 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5648 | int slotId = getSlotIndex(subId); |
| 5649 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5650 | Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '" |
| 5651 | + subId + "' for key:" + key); |
| 5652 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 5653 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5654 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5655 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5656 | if (controller == null) { |
| 5657 | loge("setImsProvisioningInt: Device does not support IMS"); |
| 5658 | |
| 5659 | // device does not support IMS, this method will return CONFIG_RESULT_FAILED. |
| 5660 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 5661 | } |
| 5662 | int retVal = controller.setProvisioningValue(subId, key, value); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5663 | if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) { |
| 5664 | return retVal; |
| 5665 | } |
| 5666 | |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5667 | return ImsManager.getInstance(mApp, slotId).setConfig(key, value); |
| 5668 | } catch (com.android.ims.ImsException | RemoteException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5669 | Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5670 | + "' for key:" + key, e); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5671 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5672 | } finally { |
| 5673 | Binder.restoreCallingIdentity(identity); |
| 5674 | } |
| 5675 | } |
| 5676 | |
| 5677 | @Override |
| 5678 | public int setImsProvisioningString(int subId, int key, String value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5679 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5680 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 5681 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 5682 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5683 | "setImsProvisioningString"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5684 | final long identity = Binder.clearCallingIdentity(); |
| 5685 | try { |
| 5686 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5687 | int slotId = getSlotIndex(subId); |
| 5688 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5689 | Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '" |
| 5690 | + subId + "' for key:" + key); |
| 5691 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 5692 | } |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5693 | return ImsManager.getInstance(mApp, slotId).setConfig(key, value); |
| 5694 | } catch (com.android.ims.ImsException | RemoteException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5695 | Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5696 | + "' for key:" + key, e); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5697 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5698 | } finally { |
| 5699 | Binder.restoreCallingIdentity(identity); |
| 5700 | } |
| 5701 | } |
| 5702 | |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5703 | /** |
| 5704 | * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL |
| 5705 | * for the given slot ID or no ImsResolver instance has been created. |
| 5706 | * @param slotId The slot ID that the IMS service is created for. |
| 5707 | * @throws ImsException If there is no ImsService configured for this slot. |
| 5708 | */ |
| 5709 | private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException { |
| 5710 | if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId, |
| 5711 | ImsFeature.FEATURE_MMTEL)) { |
| 5712 | throw new ImsException("This subscription does not support MMTEL over IMS", |
| 5713 | ImsException.CODE_ERROR_UNSUPPORTED_OPERATION); |
| 5714 | } |
| 5715 | } |
| 5716 | |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5717 | private int getSlotIndexOrException(int subId) throws ImsException { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5718 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 5719 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5720 | throw new ImsException("Invalid Subscription Id, subId=" + subId, |
| 5721 | ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5722 | } |
| 5723 | return slotId; |
| 5724 | } |
| 5725 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5726 | private int getSlotIndex(int subId) { |
| 5727 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 5728 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
| 5729 | return SubscriptionManager.INVALID_SIM_SLOT_INDEX; |
| 5730 | } |
| 5731 | return slotId; |
| 5732 | } |
| 5733 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5734 | /** |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 5735 | * Returns the data network type for a subId; does not throw SecurityException. |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5736 | */ |
| 5737 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5738 | public int getNetworkTypeForSubscriber(int subId, String callingPackage, |
| 5739 | String callingFeatureId) { |
Shuo Qian | 13d8915 | 2021-05-10 23:58:11 -0700 | [diff] [blame] | 5740 | try { |
| 5741 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 5742 | } catch (SecurityException se) { |
| 5743 | EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid()); |
| 5744 | throw new SecurityException("Package " + callingPackage + " does not belong to " |
| 5745 | + Binder.getCallingUid()); |
| 5746 | } |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 5747 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 5748 | if (targetSdk > android.os.Build.VERSION_CODES.Q) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5749 | return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 5750 | } else if (targetSdk == android.os.Build.VERSION_CODES.Q |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 5751 | && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 5752 | mApp, subId, callingPackage, callingFeatureId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5753 | "getNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5754 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5755 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 5756 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5757 | final long identity = Binder.clearCallingIdentity(); |
| 5758 | try { |
| 5759 | final Phone phone = getPhone(subId); |
| 5760 | if (phone != null) { |
| 5761 | return phone.getServiceState().getDataNetworkType(); |
| 5762 | } else { |
| 5763 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5764 | } |
| 5765 | } finally { |
| 5766 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5767 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5768 | } |
| 5769 | |
| 5770 | /** |
| 5771 | * Returns the data network type |
| 5772 | */ |
| 5773 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5774 | public int getDataNetworkType(String callingPackage, String callingFeatureId) { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5775 | return getDataNetworkTypeForSubscriber(SubscriptionManager.getDefaultDataSubscriptionId(), |
Zoey Chen | fd61f7f | 2021-04-21 13:42:10 +0800 | [diff] [blame] | 5776 | callingPackage, callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5777 | } |
| 5778 | |
| 5779 | /** |
| 5780 | * Returns the data network type for a subId |
| 5781 | */ |
| 5782 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5783 | public int getDataNetworkTypeForSubscriber(int subId, String callingPackage, |
| 5784 | String callingFeatureId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 5785 | String functionName = "getDataNetworkTypeForSubscriber"; |
| 5786 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 5787 | mApp, functionName)) { |
| 5788 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 5789 | mApp, subId, callingPackage, callingFeatureId, functionName)) { |
| 5790 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5791 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5792 | } |
| 5793 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5794 | final long identity = Binder.clearCallingIdentity(); |
| 5795 | try { |
| 5796 | final Phone phone = getPhone(subId); |
| 5797 | if (phone != null) { |
| 5798 | return phone.getServiceState().getDataNetworkType(); |
| 5799 | } else { |
| 5800 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5801 | } |
| 5802 | } finally { |
| 5803 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5804 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5805 | } |
| 5806 | |
| 5807 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5808 | * Returns the Voice network type for a subId |
| 5809 | */ |
| 5810 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5811 | public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage, |
| 5812 | String callingFeatureId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 5813 | String functionName = "getVoiceNetworkTypeForSubscriber"; |
| 5814 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 5815 | mApp, functionName)) { |
| 5816 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 5817 | mApp, subId, callingPackage, callingFeatureId, functionName)) { |
| 5818 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5819 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 5820 | } |
| 5821 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5822 | final long identity = Binder.clearCallingIdentity(); |
| 5823 | try { |
| 5824 | final Phone phone = getPhone(subId); |
| 5825 | if (phone != null) { |
| 5826 | return phone.getServiceState().getVoiceNetworkType(); |
| 5827 | } else { |
| 5828 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5829 | } |
| 5830 | } finally { |
| 5831 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5832 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5833 | } |
| 5834 | |
| 5835 | /** |
| 5836 | * @return true if a ICC card is present |
| 5837 | */ |
| 5838 | public boolean hasIccCard() { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5839 | // FIXME Make changes to pass defaultSimId of type int |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5840 | return hasIccCardUsingSlotIndex(SubscriptionManager.getSlotIndex( |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5841 | getDefaultSubscription())); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5842 | } |
| 5843 | |
| 5844 | /** |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5845 | * @return true if a ICC card is present for a slotIndex |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5846 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5847 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5848 | public boolean hasIccCardUsingSlotIndex(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5849 | final long identity = Binder.clearCallingIdentity(); |
| 5850 | try { |
| 5851 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5852 | if (phone != null) { |
| 5853 | return phone.getIccCard().hasIccCard(); |
| 5854 | } else { |
| 5855 | return false; |
| 5856 | } |
| 5857 | } finally { |
| 5858 | Binder.restoreCallingIdentity(identity); |
Amit Mahajan | a6fc2a8 | 2015-01-06 11:53:51 -0800 | [diff] [blame] | 5859 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5860 | } |
| 5861 | |
| 5862 | /** |
| 5863 | * Return if the current radio is LTE on CDMA. This |
| 5864 | * is a tri-state return value as for a period of time |
| 5865 | * the mode may be unknown. |
| 5866 | * |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5867 | * @param callingPackage the name of the package making the call. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5868 | * @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] | 5869 | * or {@link Phone#LTE_ON_CDMA_TRUE} |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5870 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5871 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5872 | public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) { |
| 5873 | return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 5874 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5875 | } |
| 5876 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5877 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5878 | public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage, |
| 5879 | String callingFeatureId) { |
Sarah Chin | 790d292 | 2020-01-16 12:17:23 -0800 | [diff] [blame] | 5880 | try { |
| 5881 | enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber"); |
| 5882 | } catch (SecurityException e) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5883 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 5884 | } |
| 5885 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5886 | final long identity = Binder.clearCallingIdentity(); |
| 5887 | try { |
| 5888 | final Phone phone = getPhone(subId); |
| 5889 | if (phone == null) { |
| 5890 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 5891 | } else { |
Nathan Harold | 05ad633 | 2020-07-10 11:54:36 -0700 | [diff] [blame] | 5892 | return TelephonyProperties.lte_on_cdma_device() |
| 5893 | .orElse(PhoneConstants.LTE_ON_CDMA_FALSE); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5894 | } |
| 5895 | } finally { |
| 5896 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5897 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5898 | } |
| 5899 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5900 | /** |
| 5901 | * {@hide} |
| 5902 | * Returns Default subId, 0 in the case of single standby. |
| 5903 | */ |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 5904 | private int getDefaultSubscription() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5905 | return SubscriptionManager.getDefaultSubscriptionId(); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5906 | } |
| 5907 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 5908 | private int getSlotForDefaultSubscription() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5909 | return SubscriptionManager.getPhoneId(getDefaultSubscription()); |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 5910 | } |
| 5911 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 5912 | private int getPreferredVoiceSubscription() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5913 | return SubscriptionManager.getDefaultVoiceSubscriptionId(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5914 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5915 | |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 5916 | private boolean isActiveSubscription(int subId) { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5917 | if (PhoneFactory.isSubscriptionManagerServiceEnabled()) { |
Jack Yu | fa8ed01 | 2023-02-11 15:42:28 -0800 | [diff] [blame] | 5918 | return getSubscriptionManagerService().isActiveSubId(subId, |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5919 | mApp.getOpPackageName(), mApp.getFeatureId()); |
| 5920 | } |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 5921 | return mSubscriptionController.isActiveSubId(subId); |
| 5922 | } |
| 5923 | |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5924 | /** |
| 5925 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 5926 | */ |
| 5927 | public int getWhenToMakeWifiCalls() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5928 | final long identity = Binder.clearCallingIdentity(); |
| 5929 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5930 | return Settings.System.getInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5931 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, |
| 5932 | getWhenToMakeWifiCallsDefaultPreference()); |
| 5933 | } finally { |
| 5934 | Binder.restoreCallingIdentity(identity); |
| 5935 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5936 | } |
| 5937 | |
| 5938 | /** |
| 5939 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 5940 | */ |
| 5941 | public void setWhenToMakeWifiCalls(int preference) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5942 | final long identity = Binder.clearCallingIdentity(); |
| 5943 | try { |
| 5944 | if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5945 | Settings.System.putInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5946 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference); |
| 5947 | } finally { |
| 5948 | Binder.restoreCallingIdentity(identity); |
| 5949 | } |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 5950 | } |
| 5951 | |
Sailesh Nepal | d1e6815 | 2013-12-12 19:08:02 -0800 | [diff] [blame] | 5952 | private static int getWhenToMakeWifiCallsDefaultPreference() { |
Santos Cordon | da120f4 | 2014-08-06 04:44:34 -0700 | [diff] [blame] | 5953 | // TODO: Use a build property to choose this value. |
Evan Charlton | 9829e88 | 2013-12-19 15:30:38 -0800 | [diff] [blame] | 5954 | return TelephonyManager.WifiCallingChoices.ALWAYS_USE; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5955 | } |
Shishir Agrawal | 69f6812 | 2013-12-16 17:25:49 -0800 | [diff] [blame] | 5956 | |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5957 | private Phone getPhoneFromSlotPortIndexOrThrowException(int slotIndex, int portIndex) { |
| 5958 | int phoneId = UiccController.getInstance().getPhoneIdFromSlotPortIndex(slotIndex, |
| 5959 | portIndex); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5960 | if (phoneId == -1) { |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5961 | throw new IllegalArgumentException("Given slot index: " + slotIndex + " port index: " |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 5962 | + portIndex + " does not correspond to an active phone"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5963 | } |
| 5964 | return PhoneFactory.getPhone(phoneId); |
| 5965 | } |
| 5966 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5967 | @Override |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 5968 | public IccOpenLogicalChannelResponse iccOpenLogicalChannel( |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5969 | @NonNull IccLogicalChannelRequest request) { |
| 5970 | Phone phone = getPhoneFromValidIccLogicalChannelRequest(request, |
| 5971 | /*message=*/ "iccOpenLogicalChannel"); |
| 5972 | |
| 5973 | if (DBG) log("iccOpenLogicalChannel: request=" + request); |
| 5974 | // Verify that the callingPackage in the request belongs to the calling UID |
| 5975 | mAppOps.checkPackage(Binder.getCallingUid(), request.callingPackage); |
| 5976 | |
| 5977 | return iccOpenLogicalChannelWithPermission(phone, request); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5978 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5979 | |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5980 | private Phone getPhoneFromValidIccLogicalChannelRequest( |
| 5981 | @NonNull IccLogicalChannelRequest request, String message) { |
| 5982 | Phone phone; |
| 5983 | if (request.subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) { |
| 5984 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5985 | mApp, request.subId, message); |
| 5986 | phone = getPhoneFromSubId(request.subId); |
| 5987 | } else if (request.slotIndex != SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5988 | enforceModifyPermission(); |
| 5989 | phone = getPhoneFromSlotPortIndexOrThrowException(request.slotIndex, request.portIndex); |
| 5990 | } else { |
| 5991 | throw new IllegalArgumentException("Both subId and slotIndex in request are invalid."); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5992 | } |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5993 | return phone; |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5994 | } |
| 5995 | |
| 5996 | private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone, |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5997 | IccLogicalChannelRequest channelRequest) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5998 | final long identity = Binder.clearCallingIdentity(); |
| 5999 | try { |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 6000 | if (TextUtils.equals(ISDR_AID, channelRequest.aid)) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6001 | // Only allows LPA to open logical channel to ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6002 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 6003 | .getContext().getPackageManager()); |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 6004 | if (bestComponent == null || !TextUtils.equals(channelRequest.callingPackage, |
| 6005 | bestComponent.packageName)) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6006 | loge("The calling package is not allowed to access ISD-R."); |
| 6007 | throw new SecurityException( |
| 6008 | "The calling package is not allowed to access ISD-R."); |
| 6009 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 6010 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 6011 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6012 | IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest( |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 6013 | CMD_OPEN_CHANNEL, channelRequest, phone, null /* workSource */); |
| 6014 | if (DBG) log("iccOpenLogicalChannelWithPermission: response=" + response); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6015 | return response; |
| 6016 | } finally { |
| 6017 | Binder.restoreCallingIdentity(identity); |
| 6018 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 6019 | } |
| 6020 | |
| 6021 | @Override |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 6022 | public boolean iccCloseLogicalChannel(@NonNull IccLogicalChannelRequest request) { |
| 6023 | Phone phone = getPhoneFromValidIccLogicalChannelRequest(request, |
| 6024 | /*message=*/"iccCloseLogicalChannel"); |
| 6025 | |
| 6026 | if (DBG) log("iccCloseLogicalChannel: request=" + request); |
| 6027 | |
| 6028 | return iccCloseLogicalChannelWithPermission(phone, request); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6029 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 6030 | |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 6031 | private boolean iccCloseLogicalChannelWithPermission(Phone phone, |
| 6032 | IccLogicalChannelRequest request) { |
Chen Xu | a8f0dff | 2022-02-12 00:34:15 -0800 | [diff] [blame] | 6033 | // before this feature is enabled, this API should only return false if |
| 6034 | // the operation fails instead of throwing runtime exception for |
| 6035 | // backward-compatibility. |
| 6036 | final boolean shouldThrowExceptionOnFailure = CompatChanges.isChangeEnabled( |
| 6037 | ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE, Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6038 | final long identity = Binder.clearCallingIdentity(); |
| 6039 | try { |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 6040 | if (request.channel < 0) { |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 6041 | throw new IllegalArgumentException("request.channel is less than 0"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6042 | } |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 6043 | Object result = sendRequest(CMD_CLOSE_CHANNEL, request.channel, phone, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6044 | null /* workSource */); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 6045 | Boolean success = false; |
| 6046 | if (result instanceof RuntimeException) { |
| 6047 | // if there is an exception returned, throw from the binder thread here. |
Chen Xu | a8f0dff | 2022-02-12 00:34:15 -0800 | [diff] [blame] | 6048 | if (shouldThrowExceptionOnFailure) { |
| 6049 | throw (RuntimeException) result; |
| 6050 | } else { |
| 6051 | return false; |
| 6052 | } |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 6053 | } else if (result instanceof Boolean) { |
| 6054 | success = (Boolean) result; |
| 6055 | } else { |
| 6056 | loge("iccCloseLogicalChannelWithPermission: supported return type " + result); |
| 6057 | } |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 6058 | if (DBG) log("iccCloseLogicalChannelWithPermission: success=" + success); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6059 | return success; |
| 6060 | } finally { |
| 6061 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 6062 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 6063 | } |
| 6064 | |
| 6065 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6066 | public String iccTransmitApduLogicalChannel(int subId, int channel, int cla, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 6067 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6068 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6069 | mApp, subId, "iccTransmitApduLogicalChannel"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6070 | if (DBG) { |
| 6071 | log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel |
| 6072 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 6073 | + p3 + " data=" + data); |
| 6074 | } |
| 6075 | return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla, |
| 6076 | command, p1, p2, p3, data); |
| 6077 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 6078 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6079 | @Override |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 6080 | public String iccTransmitApduLogicalChannelByPort(int slotIndex, int portIndex, int channel, |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6081 | int cla, int command, int p1, int p2, int p3, String data) { |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6082 | enforceModifyPermission(); |
| 6083 | if (DBG) { |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 6084 | log("iccTransmitApduLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex=" |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6085 | + portIndex + " chnl=" + channel + " cla=" + cla + " cmd=" + command + " p1=" |
| 6086 | + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6087 | } |
| 6088 | return iccTransmitApduLogicalChannelWithPermission( |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 6089 | getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel, cla, |
| 6090 | command, p1, p2, p3, data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6091 | } |
| 6092 | |
| 6093 | private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla, |
| 6094 | int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6095 | final long identity = Binder.clearCallingIdentity(); |
| 6096 | try { |
Hall Liu | 4fd771b | 2019-05-02 09:16:29 -0700 | [diff] [blame] | 6097 | if (channel <= 0) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6098 | return ""; |
| 6099 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 6100 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6101 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6102 | new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone, |
| 6103 | null /* workSource */); |
| 6104 | if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 6105 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6106 | // Append the returned status code to the end of the response payload. |
| 6107 | String s = Integer.toHexString( |
| 6108 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 6109 | if (response.payload != null) { |
| 6110 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 6111 | } |
| 6112 | return s; |
| 6113 | } finally { |
| 6114 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 6115 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 6116 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 6117 | |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 6118 | @Override |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 6119 | public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla, |
| 6120 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6121 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6122 | mApp, subId, "iccTransmitApduBasicChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6123 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6124 | if (DBG) { |
| 6125 | log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" |
| 6126 | + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
| 6127 | } |
| 6128 | return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage, |
| 6129 | cla, command, p1, p2, p3, data); |
| 6130 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 6131 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6132 | @Override |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 6133 | public String iccTransmitApduBasicChannelByPort(int slotIndex, int portIndex, |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6134 | 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] | 6135 | enforceModifyPermission(); |
| 6136 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 6137 | if (DBG) { |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 6138 | log("iccTransmitApduBasicChannelByPort: slotIndex=" + slotIndex + " portIndex=" |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6139 | + portIndex + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" |
| 6140 | + p2 + " p3=" + p3 + " data=" + data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6141 | } |
| 6142 | |
| 6143 | return iccTransmitApduBasicChannelWithPermission( |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 6144 | getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), callingPackage, |
| 6145 | cla, command, p1, p2, p3, data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6146 | } |
| 6147 | |
| 6148 | // open APDU basic channel assuming the caller has sufficient permissions |
| 6149 | private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage, |
| 6150 | int cla, int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6151 | final long identity = Binder.clearCallingIdentity(); |
| 6152 | try { |
| 6153 | if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3 |
| 6154 | && TextUtils.equals(ISDR_AID, data)) { |
| 6155 | // Only allows LPA to select ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6156 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 6157 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6158 | if (bestComponent == null |
| 6159 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 6160 | loge("The calling package is not allowed to select ISD-R."); |
| 6161 | throw new SecurityException( |
| 6162 | "The calling package is not allowed to select ISD-R."); |
| 6163 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 6164 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 6165 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6166 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6167 | new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone, |
| 6168 | null /* workSource */); |
| 6169 | if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 6170 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6171 | // Append the returned status code to the end of the response payload. |
| 6172 | String s = Integer.toHexString( |
| 6173 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 6174 | if (response.payload != null) { |
| 6175 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 6176 | } |
| 6177 | return s; |
| 6178 | } finally { |
| 6179 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 6180 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 6181 | } |
| 6182 | |
| 6183 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6184 | 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] | 6185 | String filePath) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6186 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6187 | mApp, subId, "iccExchangeSimIO"); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 6188 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6189 | final long identity = Binder.clearCallingIdentity(); |
| 6190 | try { |
| 6191 | if (DBG) { |
| 6192 | log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " |
| 6193 | + p1 + " " + p2 + " " + p3 + ":" + filePath); |
| 6194 | } |
| 6195 | |
| 6196 | IccIoResult response = |
| 6197 | (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO, |
| 6198 | new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath), |
| 6199 | subId); |
| 6200 | |
| 6201 | if (DBG) { |
| 6202 | log("Exchange SIM_IO [R]" + response); |
| 6203 | } |
| 6204 | |
| 6205 | byte[] result = null; |
| 6206 | int length = 2; |
| 6207 | if (response.payload != null) { |
| 6208 | length = 2 + response.payload.length; |
| 6209 | result = new byte[length]; |
| 6210 | System.arraycopy(response.payload, 0, result, 0, response.payload.length); |
| 6211 | } else { |
| 6212 | result = new byte[length]; |
| 6213 | } |
| 6214 | |
| 6215 | result[length - 1] = (byte) response.sw2; |
| 6216 | result[length - 2] = (byte) response.sw1; |
| 6217 | return result; |
| 6218 | } finally { |
| 6219 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 6220 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 6221 | } |
| 6222 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 6223 | /** |
| 6224 | * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM) |
| 6225 | * on a particular subscription |
| 6226 | */ |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6227 | public String[] getForbiddenPlmns(int subId, int appType, String callingPackage, |
| 6228 | String callingFeatureId) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 6229 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6230 | mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 6231 | return null; |
| 6232 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6233 | |
| 6234 | final long identity = Binder.clearCallingIdentity(); |
| 6235 | try { |
| 6236 | if (appType != TelephonyManager.APPTYPE_USIM |
| 6237 | && appType != TelephonyManager.APPTYPE_SIM) { |
| 6238 | loge("getForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 6239 | return null; |
| 6240 | } |
| 6241 | Object response = sendRequest( |
| 6242 | CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId); |
| 6243 | if (response instanceof String[]) { |
| 6244 | return (String[]) response; |
| 6245 | } |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 6246 | // Response is an Exception of some kind |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6247 | // which is signalled to the user as a NULL retval |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 6248 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6249 | } finally { |
| 6250 | Binder.restoreCallingIdentity(identity); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 6251 | } |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 6252 | } |
| 6253 | |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 6254 | /** |
| 6255 | * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular |
| 6256 | * subscription. |
| 6257 | * |
| 6258 | * @param subId the id of the subscription. |
| 6259 | * @param appType the uicc app type, must be USIM or SIM. |
| 6260 | * @param fplmns the Forbiden plmns list that needed to be written to the SIM. |
| 6261 | * @param callingPackage the op Package name. |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6262 | * @param callingFeatureId the feature in the package. |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 6263 | * @return number of fplmns that is successfully written to the SIM. |
| 6264 | */ |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6265 | public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage, |
| 6266 | String callingFeatureId) { |
Jayachandran C | 5b0d75a | 2021-10-21 22:15:27 -0700 | [diff] [blame] | 6267 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6268 | mApp, subId, "setForbiddenPlmns"); |
| 6269 | |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 6270 | if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) { |
| 6271 | loge("setForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 6272 | throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM"); |
| 6273 | } |
| 6274 | if (fplmns == null) { |
| 6275 | throw new IllegalArgumentException("Fplmn List provided is null"); |
| 6276 | } |
| 6277 | for (String fplmn : fplmns) { |
| 6278 | if (!CellIdentity.isValidPlmn(fplmn)) { |
| 6279 | throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn); |
| 6280 | } |
| 6281 | } |
| 6282 | final long identity = Binder.clearCallingIdentity(); |
| 6283 | try { |
| 6284 | Object response = sendRequest( |
| 6285 | CMD_SET_FORBIDDEN_PLMNS, |
| 6286 | new Pair<Integer, List<String>>(new Integer(appType), fplmns), |
| 6287 | subId); |
| 6288 | return (int) response; |
| 6289 | } finally { |
| 6290 | Binder.restoreCallingIdentity(identity); |
| 6291 | } |
| 6292 | } |
| 6293 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 6294 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6295 | public String sendEnvelopeWithStatus(int subId, String content) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6296 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6297 | mApp, subId, "sendEnvelopeWithStatus"); |
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 | final long identity = Binder.clearCallingIdentity(); |
| 6300 | try { |
| 6301 | IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId); |
| 6302 | if (response.payload == null) { |
| 6303 | return ""; |
| 6304 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 6305 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6306 | // Append the returned status code to the end of the response payload. |
| 6307 | String s = Integer.toHexString( |
| 6308 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 6309 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 6310 | return s; |
| 6311 | } finally { |
| 6312 | Binder.restoreCallingIdentity(identity); |
| 6313 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 6314 | } |
| 6315 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 6316 | /** |
| 6317 | * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 6318 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 6319 | * |
| 6320 | * @param itemID the ID of the item to read |
| 6321 | * @return the NV item as a String, or null on error. |
| 6322 | */ |
| 6323 | @Override |
| 6324 | public String nvReadItem(int itemID) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6325 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6326 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6327 | mApp, getDefaultSubscription(), "nvReadItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6328 | |
| 6329 | final long identity = Binder.clearCallingIdentity(); |
| 6330 | try { |
| 6331 | if (DBG) log("nvReadItem: item " + itemID); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6332 | String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6333 | if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"'); |
| 6334 | return value; |
| 6335 | } finally { |
| 6336 | Binder.restoreCallingIdentity(identity); |
| 6337 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 6338 | } |
| 6339 | |
| 6340 | /** |
| 6341 | * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 6342 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 6343 | * |
| 6344 | * @param itemID the ID of the item to read |
| 6345 | * @param itemValue the value to write, as a String |
| 6346 | * @return true on success; false on any failure |
| 6347 | */ |
| 6348 | @Override |
| 6349 | public boolean nvWriteItem(int itemID, String itemValue) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6350 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6351 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6352 | mApp, getDefaultSubscription(), "nvWriteItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6353 | |
| 6354 | final long identity = Binder.clearCallingIdentity(); |
| 6355 | try { |
| 6356 | if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"'); |
| 6357 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6358 | new Pair<Integer, String>(itemID, itemValue), workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6359 | if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail")); |
| 6360 | return success; |
| 6361 | } finally { |
| 6362 | Binder.restoreCallingIdentity(identity); |
| 6363 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 6364 | } |
| 6365 | |
| 6366 | /** |
| 6367 | * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage. |
| 6368 | * Used for device configuration by some CDMA operators. |
| 6369 | * |
| 6370 | * @param preferredRoamingList byte array containing the new PRL |
| 6371 | * @return true on success; false on any failure |
| 6372 | */ |
| 6373 | @Override |
| 6374 | public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6375 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6376 | mApp, getDefaultSubscription(), "nvWriteCdmaPrl"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6377 | |
| 6378 | final long identity = Binder.clearCallingIdentity(); |
| 6379 | try { |
| 6380 | if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList)); |
| 6381 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList); |
| 6382 | if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail")); |
| 6383 | return success; |
| 6384 | } finally { |
| 6385 | Binder.restoreCallingIdentity(identity); |
| 6386 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 6387 | } |
| 6388 | |
| 6389 | /** |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 6390 | * 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] | 6391 | * Used for device configuration by some CDMA operators. |
| 6392 | * |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 6393 | * @param slotIndex - device slot. |
| 6394 | * |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 6395 | * @return true on success; false on any failure |
| 6396 | */ |
| 6397 | @Override |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 6398 | public boolean resetModemConfig(int slotIndex) { |
| 6399 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 6400 | if (phone != null) { |
| 6401 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6402 | mApp, phone.getSubId(), "resetModemConfig"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6403 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 6404 | final long identity = Binder.clearCallingIdentity(); |
| 6405 | try { |
| 6406 | Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null); |
| 6407 | if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 6408 | return success; |
| 6409 | } finally { |
| 6410 | Binder.restoreCallingIdentity(identity); |
| 6411 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6412 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 6413 | return false; |
| 6414 | } |
| 6415 | |
| 6416 | /** |
| 6417 | * Generate a radio modem reset. Used for device configuration by some CDMA operators. |
| 6418 | * |
| 6419 | * @param slotIndex - device slot. |
| 6420 | * |
| 6421 | * @return true on success; false on any failure |
| 6422 | */ |
| 6423 | @Override |
| 6424 | public boolean rebootModem(int slotIndex) { |
| 6425 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 6426 | if (phone != null) { |
| 6427 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6428 | mApp, phone.getSubId(), "rebootModem"); |
| 6429 | |
| 6430 | final long identity = Binder.clearCallingIdentity(); |
| 6431 | try { |
| 6432 | Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null); |
| 6433 | if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail")); |
| 6434 | return success; |
| 6435 | } finally { |
| 6436 | Binder.restoreCallingIdentity(identity); |
| 6437 | } |
| 6438 | } |
| 6439 | return false; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 6440 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 6441 | |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 6442 | /** |
Grace Jia | aa2eb6b | 2020-01-09 16:26:08 -0800 | [diff] [blame] | 6443 | * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and |
| 6444 | * {@link #disableIms(int)}. |
| 6445 | * @param slotIndex device slot. |
| 6446 | */ |
| 6447 | public void resetIms(int slotIndex) { |
| 6448 | enforceModifyPermission(); |
| 6449 | |
| 6450 | final long identity = Binder.clearCallingIdentity(); |
| 6451 | try { |
| 6452 | if (mImsResolver == null) { |
| 6453 | // may happen if the does not support IMS. |
| 6454 | return; |
| 6455 | } |
Hyunho | a17ac7c | 2022-08-30 12:03:04 +0000 | [diff] [blame] | 6456 | mImsResolver.resetIms(slotIndex); |
Grace Jia | aa2eb6b | 2020-01-09 16:26:08 -0800 | [diff] [blame] | 6457 | } finally { |
| 6458 | Binder.restoreCallingIdentity(identity); |
| 6459 | } |
| 6460 | } |
| 6461 | |
| 6462 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6463 | * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability |
| 6464 | * status updates, if not already enabled. |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 6465 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6466 | public void enableIms(int slotId) { |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 6467 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6468 | |
| 6469 | final long identity = Binder.clearCallingIdentity(); |
| 6470 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6471 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6472 | // may happen if the device does not support IMS. |
| 6473 | return; |
| 6474 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6475 | mImsResolver.enableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6476 | } finally { |
| 6477 | Binder.restoreCallingIdentity(identity); |
| 6478 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 6479 | } |
| 6480 | |
| 6481 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6482 | * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature |
| 6483 | * status updates to disabled. |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 6484 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6485 | public void disableIms(int slotId) { |
| 6486 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6487 | |
| 6488 | final long identity = Binder.clearCallingIdentity(); |
| 6489 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6490 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6491 | // may happen if the device does not support IMS. |
| 6492 | return; |
| 6493 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6494 | mImsResolver.disableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6495 | } finally { |
| 6496 | Binder.restoreCallingIdentity(identity); |
| 6497 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6498 | } |
| 6499 | |
| 6500 | /** |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 6501 | * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback |
| 6502 | * callback. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6503 | */ |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 6504 | @Override |
Brad Ebinger | f6aca00 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 6505 | public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) { |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 6506 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6507 | |
| 6508 | final long identity = Binder.clearCallingIdentity(); |
| 6509 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6510 | if (mImsResolver == null) { |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 6511 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 6512 | "Device does not support IMS"); |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6513 | } |
Brad Ebinger | f6aca00 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 6514 | mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6515 | } finally { |
| 6516 | Binder.restoreCallingIdentity(identity); |
| 6517 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 6518 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 6519 | /** |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 6520 | * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature. |
| 6521 | */ |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 6522 | @Override |
| 6523 | public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) { |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 6524 | enforceModifyPermission(); |
| 6525 | |
| 6526 | final long identity = Binder.clearCallingIdentity(); |
| 6527 | try { |
| 6528 | if (mImsResolver == null) return; |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 6529 | mImsResolver.unregisterImsFeatureCallback(callback); |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 6530 | } finally { |
| 6531 | Binder.restoreCallingIdentity(identity); |
| 6532 | } |
| 6533 | } |
| 6534 | |
| 6535 | /** |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 6536 | * Returns the {@link IImsRegistration} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6537 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 6538 | */ |
| 6539 | public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException { |
| 6540 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6541 | |
| 6542 | final long identity = Binder.clearCallingIdentity(); |
| 6543 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6544 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6545 | // may happen if the device does not support IMS. |
| 6546 | return null; |
| 6547 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6548 | return mImsResolver.getImsRegistration(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6549 | } finally { |
| 6550 | Binder.restoreCallingIdentity(identity); |
| 6551 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 6552 | } |
| 6553 | |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6554 | /** |
| 6555 | * Returns the {@link IImsConfig} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6556 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6557 | */ |
| 6558 | public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException { |
| 6559 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6560 | |
| 6561 | final long identity = Binder.clearCallingIdentity(); |
| 6562 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6563 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6564 | // may happen if the device does not support IMS. |
| 6565 | return null; |
| 6566 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6567 | return mImsResolver.getImsConfig(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6568 | } finally { |
| 6569 | Binder.restoreCallingIdentity(identity); |
| 6570 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6571 | } |
| 6572 | |
Brad Ebinger | 884c07b | 2018-02-15 16:17:40 -0800 | [diff] [blame] | 6573 | /** |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6574 | * Sets the ImsService Package Name that Telephony will bind to. |
| 6575 | * |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6576 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 6577 | * @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] | 6578 | * ImsService is the device default ImsService. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6579 | * @param featureTypes An integer array of feature types associated with a packageName. |
| 6580 | * @param packageName The name of the package that the current configuration will be replaced |
| 6581 | * with. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6582 | * @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] | 6583 | */ |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6584 | public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService, |
| 6585 | int[] featureTypes, String packageName) { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6586 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 6587 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
Jack Yu | 00ece8c | 2022-11-19 22:29:12 -0800 | [diff] [blame] | 6588 | SubscriptionManager.getSubscriptionId(slotIndex), "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 6589 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6590 | final long identity = Binder.clearCallingIdentity(); |
| 6591 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6592 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6593 | // may happen if the device does not support IMS. |
| 6594 | return false; |
| 6595 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6596 | Map<Integer, String> featureConfig = new HashMap<>(); |
| 6597 | for (int featureType : featureTypes) { |
| 6598 | featureConfig.put(featureType, packageName); |
| 6599 | } |
| 6600 | return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService, |
| 6601 | featureConfig); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6602 | } finally { |
| 6603 | Binder.restoreCallingIdentity(identity); |
| 6604 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6605 | } |
| 6606 | |
| 6607 | /** |
Brad Ebinger | 999d330 | 2020-11-25 14:31:39 -0800 | [diff] [blame] | 6608 | * Clears any carrier ImsService overrides for the slot index specified that were previously |
| 6609 | * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}. |
| 6610 | * |
| 6611 | * This should only be used for testing. |
| 6612 | * |
| 6613 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 6614 | * @return true if clearing the carrier ImsService override succeeded or false if it did not. |
| 6615 | */ |
| 6616 | @Override |
| 6617 | public boolean clearCarrierImsServiceOverride(int slotIndex) { |
Brad Ebinger | 999d330 | 2020-11-25 14:31:39 -0800 | [diff] [blame] | 6618 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 6619 | "clearCarrierImsServiceOverride"); |
| 6620 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
Jack Yu | 00ece8c | 2022-11-19 22:29:12 -0800 | [diff] [blame] | 6621 | SubscriptionManager.getSubscriptionId(slotIndex), "clearCarrierImsServiceOverride"); |
Brad Ebinger | 999d330 | 2020-11-25 14:31:39 -0800 | [diff] [blame] | 6622 | |
| 6623 | final long identity = Binder.clearCallingIdentity(); |
| 6624 | try { |
| 6625 | if (mImsResolver == null) { |
| 6626 | // may happen if the device does not support IMS. |
| 6627 | return false; |
| 6628 | } |
| 6629 | return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex); |
| 6630 | } finally { |
| 6631 | Binder.restoreCallingIdentity(identity); |
| 6632 | } |
| 6633 | } |
| 6634 | |
| 6635 | /** |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6636 | * Return the package name of the currently bound ImsService. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6637 | * |
| 6638 | * @param slotId The slot that the ImsService is associated with. |
| 6639 | * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is |
| 6640 | * the device default. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6641 | * @param featureType The feature associated with the queried configuration. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6642 | * @return the package name of the ImsService configuration. |
| 6643 | */ |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6644 | public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService, |
| 6645 | @ImsFeature.FeatureType int featureType) { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6646 | TelephonyPermissions |
Jack Yu | 00ece8c | 2022-11-19 22:29:12 -0800 | [diff] [blame] | 6647 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(mApp, |
| 6648 | SubscriptionManager.getSubscriptionId(slotId), "getBoundImsServicePackage"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 6649 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6650 | final long identity = Binder.clearCallingIdentity(); |
| 6651 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6652 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6653 | // may happen if the device does not support IMS. |
| 6654 | return ""; |
| 6655 | } |
Brad Ebinger | a80c331 | 2019-12-02 10:59:39 -0800 | [diff] [blame] | 6656 | // TODO: change API to query RCS separately. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6657 | return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService, |
| 6658 | featureType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6659 | } finally { |
| 6660 | Binder.restoreCallingIdentity(identity); |
| 6661 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6662 | } |
| 6663 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6664 | /** |
| 6665 | * Get the MmTelFeature state associated with the requested subscription id. |
| 6666 | * @param subId The subscription that the MmTelFeature is associated with. |
| 6667 | * @param callback A callback with an integer containing the |
| 6668 | * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature. |
| 6669 | */ |
| 6670 | @Override |
| 6671 | public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) { |
| 6672 | enforceReadPrivilegedPermission("getImsMmTelFeatureState"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 6673 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 6674 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 6675 | "IMS not available on device."); |
| 6676 | } |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6677 | final long token = Binder.clearCallingIdentity(); |
| 6678 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 6679 | int slotId = getSlotIndex(subId); |
| 6680 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 6681 | Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '" |
| 6682 | + subId + "'"); |
| 6683 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 6684 | } |
| 6685 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 6686 | ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> { |
| 6687 | try { |
| 6688 | callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger); |
| 6689 | } catch (RemoteException e) { |
| 6690 | Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. " |
| 6691 | + "Ignore"); |
| 6692 | } |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6693 | }); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 6694 | } catch (ImsException e) { |
| 6695 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6696 | } finally { |
| 6697 | Binder.restoreCallingIdentity(token); |
| 6698 | } |
| 6699 | } |
| 6700 | |
Daniel Bright | bb5840b | 2021-01-12 15:48:18 -0800 | [diff] [blame] | 6701 | /** |
| 6702 | * Sets the ims registration state on all valid {@link Phone}s. |
| 6703 | */ |
| 6704 | public void setImsRegistrationState(final boolean registered) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 6705 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6706 | |
| 6707 | final long identity = Binder.clearCallingIdentity(); |
| 6708 | try { |
Daniel Bright | bb5840b | 2021-01-12 15:48:18 -0800 | [diff] [blame] | 6709 | // NOTE: Before S, this method only set the default phone. |
| 6710 | for (final Phone phone : PhoneFactory.getPhones()) { |
| 6711 | if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) { |
| 6712 | phone.setImsRegistrationState(registered); |
| 6713 | } |
| 6714 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6715 | } finally { |
| 6716 | Binder.restoreCallingIdentity(identity); |
| 6717 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 6718 | } |
| 6719 | |
| 6720 | /** |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 6721 | * Set the network selection mode to automatic. |
| 6722 | * |
| 6723 | */ |
| 6724 | @Override |
| 6725 | public void setNetworkSelectionModeAutomatic(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6726 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6727 | mApp, subId, "setNetworkSelectionModeAutomatic"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6728 | |
| 6729 | final long identity = Binder.clearCallingIdentity(); |
| 6730 | try { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 6731 | if (!isActiveSubscription(subId)) { |
| 6732 | return; |
| 6733 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6734 | if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId); |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 6735 | sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId, |
| 6736 | SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6737 | } finally { |
| 6738 | Binder.restoreCallingIdentity(identity); |
| 6739 | } |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 6740 | } |
| 6741 | |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 6742 | /** |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6743 | * Ask the radio to connect to the input network and change selection mode to manual. |
| 6744 | * |
| 6745 | * @param subId the id of the subscription. |
| 6746 | * @param operatorInfo the operator information, included the PLMN, long name and short name of |
| 6747 | * the operator to attach to. |
| 6748 | * @param persistSelection whether the selection will persist until reboot. If true, only allows |
| 6749 | * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume |
| 6750 | * normal network selection next time. |
| 6751 | * @return {@code true} on success; {@code true} on any failure. |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6752 | */ |
| 6753 | @Override |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6754 | public boolean setNetworkSelectionModeManual( |
| 6755 | int subId, OperatorInfo operatorInfo, boolean persistSelection) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6756 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6757 | mApp, subId, "setNetworkSelectionModeManual"); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 6758 | |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 6759 | final long identity = Binder.clearCallingIdentity(); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 6760 | if (!isActiveSubscription(subId)) { |
| 6761 | return false; |
| 6762 | } |
| 6763 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6764 | try { |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6765 | ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6766 | persistSelection); |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6767 | if (DBG) { |
| 6768 | log("setNetworkSelectionModeManual: subId: " + subId |
| 6769 | + " operator: " + operatorInfo); |
| 6770 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6771 | return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId); |
| 6772 | } finally { |
| 6773 | Binder.restoreCallingIdentity(identity); |
| 6774 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6775 | } |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6776 | /** |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6777 | * Get the manual network selection |
| 6778 | * |
| 6779 | * @param subId the id of the subscription. |
| 6780 | * |
| 6781 | * @return the previously saved user selected PLMN |
| 6782 | */ |
| 6783 | @Override |
| 6784 | public String getManualNetworkSelectionPlmn(int subId) { |
| 6785 | TelephonyPermissions |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6786 | .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 6787 | mApp, subId, "getManualNetworkSelectionPlmn"); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6788 | |
| 6789 | final long identity = Binder.clearCallingIdentity(); |
| 6790 | try { |
| 6791 | if (!isActiveSubscription(subId)) { |
shilu | fa1c259 | 2020-03-10 10:59:43 -0700 | [diff] [blame] | 6792 | throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6793 | } |
| 6794 | |
| 6795 | final Phone phone = getPhone(subId); |
| 6796 | if (phone == null) { |
shilu | fa1c259 | 2020-03-10 10:59:43 -0700 | [diff] [blame] | 6797 | throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6798 | } |
| 6799 | OperatorInfo networkSelection = phone.getSavedNetworkSelection(); |
| 6800 | return TextUtils.isEmpty(networkSelection.getOperatorNumeric()) |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6801 | ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric(); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6802 | } finally { |
| 6803 | Binder.restoreCallingIdentity(identity); |
| 6804 | } |
| 6805 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6806 | |
| 6807 | /** |
| 6808 | * Scans for available networks. |
| 6809 | */ |
| 6810 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6811 | public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage, |
| 6812 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6813 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6814 | mApp, subId, "getCellNetworkScanResults"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6815 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 6816 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 6817 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 6818 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6819 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6820 | .setCallingPid(Binder.getCallingPid()) |
| 6821 | .setCallingUid(Binder.getCallingUid()) |
| 6822 | .setMethod("getCellNetworkScanResults") |
| 6823 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
Hall Liu | c4a3e42 | 2020-05-26 17:18:03 -0700 | [diff] [blame] | 6824 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 6825 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6826 | .build()); |
| 6827 | switch (locationResult) { |
| 6828 | case DENIED_HARD: |
| 6829 | throw new SecurityException("Not allowed to access scan results -- location"); |
| 6830 | case DENIED_SOFT: |
| 6831 | return null; |
| 6832 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6833 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6834 | long identity = Binder.clearCallingIdentity(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6835 | try { |
| 6836 | if (DBG) log("getCellNetworkScanResults: subId " + subId); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6837 | return (CellNetworkScanResult) sendRequest( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6838 | CMD_PERFORM_NETWORK_SCAN, null, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6839 | } finally { |
| 6840 | Binder.restoreCallingIdentity(identity); |
| 6841 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6842 | } |
| 6843 | |
| 6844 | /** |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6845 | * Get the call forwarding info, given the call forwarding reason. |
| 6846 | */ |
| 6847 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6848 | public void getCallForwarding(int subId, int callForwardingReason, |
| 6849 | ICallForwardingInfoCallback callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6850 | enforceReadPrivilegedPermission("getCallForwarding"); |
| 6851 | long identity = Binder.clearCallingIdentity(); |
| 6852 | try { |
| 6853 | if (DBG) { |
| 6854 | log("getCallForwarding: subId " + subId |
| 6855 | + " callForwardingReason" + callForwardingReason); |
| 6856 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6857 | |
| 6858 | Phone phone = getPhone(subId); |
| 6859 | if (phone == null) { |
| 6860 | try { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 6861 | callback.onError( |
| 6862 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6863 | } catch (RemoteException e) { |
| 6864 | // ignore |
| 6865 | } |
| 6866 | return; |
| 6867 | } |
| 6868 | |
| 6869 | Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create( |
| 6870 | callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() { |
| 6871 | @Override |
| 6872 | public void onCallForwardingInfoAvailable(CallForwardingInfo info) { |
| 6873 | try { |
| 6874 | callback.onCallForwardingInfoAvailable(info); |
| 6875 | } catch (RemoteException e) { |
| 6876 | // ignore |
| 6877 | } |
| 6878 | } |
| 6879 | |
| 6880 | @Override |
| 6881 | public void onError(int error) { |
| 6882 | try { |
| 6883 | callback.onError(error); |
| 6884 | } catch (RemoteException e) { |
| 6885 | // ignore |
| 6886 | } |
| 6887 | } |
| 6888 | }); |
| 6889 | sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6890 | } finally { |
| 6891 | Binder.restoreCallingIdentity(identity); |
| 6892 | } |
| 6893 | } |
| 6894 | |
| 6895 | /** |
| 6896 | * Sets the voice call forwarding info including status (enable/disable), call forwarding |
| 6897 | * reason, the number to forward, and the timeout before the forwarding is attempted. |
| 6898 | */ |
| 6899 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6900 | public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo, |
| 6901 | IIntegerConsumer callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6902 | enforceModifyPermission(); |
| 6903 | long identity = Binder.clearCallingIdentity(); |
| 6904 | try { |
| 6905 | if (DBG) { |
| 6906 | log("setCallForwarding: subId " + subId |
| 6907 | + " callForwardingInfo" + callForwardingInfo); |
| 6908 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6909 | |
| 6910 | Phone phone = getPhone(subId); |
| 6911 | if (phone == null) { |
| 6912 | try { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 6913 | callback.accept( |
| 6914 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6915 | } catch (RemoteException e) { |
| 6916 | // ignore |
| 6917 | } |
| 6918 | return; |
| 6919 | } |
| 6920 | |
| 6921 | Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo, |
| 6922 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 6923 | |
| 6924 | sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6925 | } finally { |
| 6926 | Binder.restoreCallingIdentity(identity); |
| 6927 | } |
| 6928 | } |
| 6929 | |
| 6930 | /** |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6931 | * Get the call waiting status for a subId. |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6932 | */ |
| 6933 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6934 | public void getCallWaitingStatus(int subId, IIntegerConsumer callback) { |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6935 | enforceReadPrivilegedPermission("getCallWaitingStatus"); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6936 | long identity = Binder.clearCallingIdentity(); |
| 6937 | try { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6938 | Phone phone = getPhone(subId); |
| 6939 | if (phone == null) { |
| 6940 | try { |
| 6941 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 6942 | } catch (RemoteException e) { |
| 6943 | // ignore |
| 6944 | } |
| 6945 | return; |
| 6946 | } |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6947 | CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext()); |
| 6948 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 6949 | boolean requireUssd = c.getBoolean( |
| 6950 | CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6951 | |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6952 | if (DBG) log("getCallWaitingStatus: subId " + subId); |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6953 | if (requireUssd) { |
| 6954 | CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(), |
| 6955 | getSubscriptionCarrierId(subId)); |
| 6956 | String newUssdCommand = ""; |
| 6957 | try { |
| 6958 | newUssdCommand = carrierXmlParser.getFeature( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6959 | CarrierXmlParser.FEATURE_CALL_WAITING) |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6960 | .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null); |
| 6961 | } catch (NullPointerException e) { |
| 6962 | loge("Failed to generate USSD number" + e); |
| 6963 | } |
| 6964 | ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver( |
| 6965 | mMainThreadHandler, callback, carrierXmlParser, |
| 6966 | CarrierXmlParser.SsEntry.SSAction.QUERY); |
| 6967 | final String ussdCommand = newUssdCommand; |
| 6968 | Executors.newSingleThreadExecutor().execute(() -> { |
| 6969 | handleUssdRequest(subId, ussdCommand, wrappedCallback); |
| 6970 | }); |
| 6971 | } else { |
| 6972 | Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException( |
| 6973 | callback::accept); |
| 6974 | sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null); |
| 6975 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6976 | } finally { |
| 6977 | Binder.restoreCallingIdentity(identity); |
| 6978 | } |
| 6979 | } |
| 6980 | |
| 6981 | /** |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6982 | * Sets whether call waiting is enabled for a given subId. |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6983 | */ |
| 6984 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6985 | public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6986 | enforceModifyPermission(); |
| 6987 | long identity = Binder.clearCallingIdentity(); |
| 6988 | try { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6989 | if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable); |
| 6990 | |
| 6991 | Phone phone = getPhone(subId); |
| 6992 | if (phone == null) { |
| 6993 | try { |
| 6994 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 6995 | } catch (RemoteException e) { |
| 6996 | // ignore |
| 6997 | } |
| 6998 | return; |
| 6999 | } |
| 7000 | |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 7001 | CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext()); |
| 7002 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 7003 | boolean requireUssd = c.getBoolean( |
| 7004 | CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 7005 | |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 7006 | if (DBG) log("getCallWaitingStatus: subId " + subId); |
| 7007 | if (requireUssd) { |
| 7008 | CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(), |
| 7009 | getSubscriptionCarrierId(subId)); |
| 7010 | CarrierXmlParser.SsEntry.SSAction ssAction = |
| 7011 | enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE |
| 7012 | : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE; |
| 7013 | String newUssdCommand = ""; |
| 7014 | try { |
| 7015 | newUssdCommand = carrierXmlParser.getFeature( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 7016 | CarrierXmlParser.FEATURE_CALL_WAITING) |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 7017 | .makeCommand(ssAction, null); |
| 7018 | } catch (NullPointerException e) { |
| 7019 | loge("Failed to generate USSD number" + e); |
| 7020 | } |
| 7021 | ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver( |
| 7022 | mMainThreadHandler, callback, carrierXmlParser, ssAction); |
| 7023 | final String ussdCommand = newUssdCommand; |
| 7024 | Executors.newSingleThreadExecutor().execute(() -> { |
| 7025 | handleUssdRequest(subId, ussdCommand, wrappedCallback); |
| 7026 | }); |
| 7027 | } else { |
| 7028 | Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable, |
| 7029 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 7030 | |
| 7031 | sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null); |
| 7032 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 7033 | } finally { |
| 7034 | Binder.restoreCallingIdentity(identity); |
| 7035 | } |
| 7036 | } |
| 7037 | |
| 7038 | /** |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 7039 | * Starts a new network scan and returns the id of this scan. |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 7040 | * |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 7041 | * @param subId id of the subscription |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 7042 | * @param renounceFineLocationAccess Set this to true if the caller would not like to receive |
| 7043 | * location related information which will be sent if the caller already possess |
| 7044 | * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 7045 | * @param request contains the radio access networks with bands/channels to scan |
| 7046 | * @param messenger callback messenger for scan results or errors |
| 7047 | * @param binder for the purpose of auto clean when the user thread crashes |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 7048 | * @return the id of the requested scan which can be used to stop the scan. |
| 7049 | */ |
| 7050 | @Override |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 7051 | public int requestNetworkScan(int subId, boolean renounceFineLocationAccess, |
| 7052 | NetworkScanRequest request, Messenger messenger, |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 7053 | IBinder binder, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7054 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7055 | mApp, subId, "requestNetworkScan"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7056 | LocationAccessPolicy.LocationPermissionResult locationResult = |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 7057 | LocationAccessPolicy.LocationPermissionResult.DENIED_HARD; |
| 7058 | if (!renounceFineLocationAccess) { |
| 7059 | locationResult = LocationAccessPolicy.checkLocationPermission(mApp, |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 7060 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 7061 | .setCallingPackage(callingPackage) |
| 7062 | .setCallingFeatureId(callingFeatureId) |
| 7063 | .setCallingPid(Binder.getCallingPid()) |
| 7064 | .setCallingUid(Binder.getCallingUid()) |
| 7065 | .setMethod("requestNetworkScan") |
| 7066 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 7067 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 7068 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 7069 | .build()); |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 7070 | } |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 7071 | if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) { |
Nathan Harold | 1c11dba | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 7072 | SecurityException e = checkNetworkRequestForSanitizedLocationAccess( |
| 7073 | request, subId, callingPackage); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 7074 | if (e != null) { |
| 7075 | if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) { |
| 7076 | throw e; |
| 7077 | } else { |
Hall Liu | 0e5abaf | 2019-04-04 01:25:30 -0700 | [diff] [blame] | 7078 | loge(e.getMessage()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 7079 | return TelephonyScanManager.INVALID_SCAN_ID; |
| 7080 | } |
| 7081 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7082 | } |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 7083 | int callingUid = Binder.getCallingUid(); |
| 7084 | int callingPid = Binder.getCallingPid(); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 7085 | final long identity = Binder.clearCallingIdentity(); |
| 7086 | try { |
| 7087 | return mNetworkScanRequestTracker.startNetworkScan( |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 7088 | renounceFineLocationAccess, request, messenger, binder, getPhone(subId), |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 7089 | callingUid, callingPid, callingPackage); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 7090 | } finally { |
| 7091 | Binder.restoreCallingIdentity(identity); |
| 7092 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 7093 | } |
| 7094 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 7095 | private SecurityException checkNetworkRequestForSanitizedLocationAccess( |
Nathan Harold | 1c11dba | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 7096 | NetworkScanRequest request, int subId, String callingPackage) { |
Rambo Wang | 3dee30a | 2022-10-20 16:52:29 +0000 | [diff] [blame] | 7097 | boolean hasCarrierPriv; |
| 7098 | final long identity = Binder.clearCallingIdentity(); |
| 7099 | try { |
| 7100 | hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage) |
| 7101 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 7102 | } finally { |
| 7103 | Binder.restoreCallingIdentity(identity); |
| 7104 | } |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 7105 | boolean hasNetworkScanPermission = |
| 7106 | mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN) |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 7107 | == PERMISSION_GRANTED; |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 7108 | |
| 7109 | if (!hasCarrierPriv && !hasNetworkScanPermission) { |
| 7110 | return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed" |
| 7111 | + " for network scans without location access."); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 7112 | } |
| 7113 | |
| 7114 | if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) { |
| 7115 | for (RadioAccessSpecifier ras : request.getSpecifiers()) { |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 7116 | if (ras.getChannels() != null && ras.getChannels().length > 0) { |
| 7117 | return new SecurityException("Specific channels must not be" |
| 7118 | + " scanned without location access."); |
| 7119 | } |
| 7120 | } |
| 7121 | } |
| 7122 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 7123 | return null; |
| 7124 | } |
| 7125 | |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 7126 | /** |
| 7127 | * Stops an existing network scan with the given scanId. |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 7128 | * |
| 7129 | * @param subId id of the subscription |
| 7130 | * @param scanId id of the scan that needs to be stopped |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 7131 | */ |
| 7132 | @Override |
| 7133 | public void stopNetworkScan(int subId, int scanId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7134 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7135 | mApp, subId, "stopNetworkScan"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7136 | |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 7137 | int callingUid = Binder.getCallingUid(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7138 | final long identity = Binder.clearCallingIdentity(); |
| 7139 | try { |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 7140 | mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7141 | } finally { |
| 7142 | Binder.restoreCallingIdentity(identity); |
| 7143 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 7144 | } |
| 7145 | |
| 7146 | /** |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7147 | * Get the allowed network types bitmask. |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 7148 | * |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7149 | * @return the allowed network types bitmask, defined in RILConstants.java. |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 7150 | */ |
| 7151 | @Override |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7152 | public int getAllowedNetworkTypesBitmask(int subId) { |
Pengquan Meng | a4009cb | 2018-12-20 11:00:24 -0800 | [diff] [blame] | 7153 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 7154 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7155 | mApp, subId, "getAllowedNetworkTypesBitmask"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7156 | |
| 7157 | final long identity = Binder.clearCallingIdentity(); |
| 7158 | try { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7159 | if (DBG) log("getAllowedNetworkTypesBitmask"); |
| 7160 | int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId); |
| 7161 | int networkTypesBitmask = (result != null ? result[0] : -1); |
| 7162 | if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask); |
| 7163 | return networkTypesBitmask; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7164 | } finally { |
| 7165 | Binder.restoreCallingIdentity(identity); |
| 7166 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 7167 | } |
| 7168 | |
| 7169 | /** |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 7170 | * Get the allowed network types for certain reason. |
| 7171 | * |
| 7172 | * @param subId the id of the subscription. |
| 7173 | * @param reason the reason the allowed network type change is taking place |
| 7174 | * @return the allowed network types. |
| 7175 | */ |
| 7176 | @Override |
| 7177 | public long getAllowedNetworkTypesForReason(int subId, |
| 7178 | @TelephonyManager.AllowedNetworkTypesReason int reason) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 7179 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 7180 | mApp, subId, "getAllowedNetworkTypesForReason"); |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 7181 | final long identity = Binder.clearCallingIdentity(); |
| 7182 | try { |
| 7183 | return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason); |
| 7184 | } finally { |
| 7185 | Binder.restoreCallingIdentity(identity); |
| 7186 | } |
| 7187 | } |
| 7188 | |
| 7189 | /** |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 7190 | * Enable/Disable E-UTRA-NR Dual Connectivity |
| 7191 | * @param subId subscription id of the sim card |
| 7192 | * @param nrDualConnectivityState expected NR dual connectivity state |
| 7193 | * This can be passed following states |
| 7194 | * <ol> |
| 7195 | * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE} |
| 7196 | * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE} |
| 7197 | * <li>Disable NR dual connectivity and force secondary cell to be released |
| 7198 | * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE} |
| 7199 | * </ol> |
| 7200 | * @return operation result. |
| 7201 | */ |
| 7202 | @Override |
| 7203 | public int setNrDualConnectivityState(int subId, |
| 7204 | @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) { |
| 7205 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7206 | mApp, subId, "enableNRDualConnectivity"); |
Sooraj Sasindran | 0e4e00a | 2021-03-16 18:02:32 -0700 | [diff] [blame] | 7207 | if (!isRadioInterfaceCapabilitySupported( |
Sooraj Sasindran | dfd595b | 2021-03-11 17:38:13 -0800 | [diff] [blame] | 7208 | TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) { |
| 7209 | return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED; |
| 7210 | } |
| 7211 | |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 7212 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 7213 | final long identity = Binder.clearCallingIdentity(); |
| 7214 | try { |
| 7215 | int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY, |
| 7216 | nrDualConnectivityState, subId, |
| 7217 | workSource); |
| 7218 | if (DBG) log("enableNRDualConnectivity result: " + result); |
| 7219 | return result; |
| 7220 | } finally { |
| 7221 | Binder.restoreCallingIdentity(identity); |
| 7222 | } |
| 7223 | } |
| 7224 | |
| 7225 | /** |
| 7226 | * Is E-UTRA-NR Dual Connectivity enabled |
| 7227 | * @return true if dual connectivity is enabled else false |
| 7228 | */ |
| 7229 | @Override |
| 7230 | public boolean isNrDualConnectivityEnabled(int subId) { |
| 7231 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 7232 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 7233 | mApp, subId, "isNRDualConnectivityEnabled"); |
Sooraj Sasindran | 0e4e00a | 2021-03-16 18:02:32 -0700 | [diff] [blame] | 7234 | if (!isRadioInterfaceCapabilitySupported( |
Sooraj Sasindran | dfd595b | 2021-03-11 17:38:13 -0800 | [diff] [blame] | 7235 | TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) { |
| 7236 | return false; |
| 7237 | } |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 7238 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 7239 | final long identity = Binder.clearCallingIdentity(); |
| 7240 | try { |
| 7241 | boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED, |
| 7242 | null, subId, workSource); |
| 7243 | if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled); |
| 7244 | return isEnabled; |
| 7245 | } finally { |
| 7246 | Binder.restoreCallingIdentity(identity); |
| 7247 | } |
| 7248 | } |
| 7249 | |
| 7250 | /** |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 7251 | * Set the allowed network types of the device and |
| 7252 | * provide the reason triggering the allowed network change. |
| 7253 | * |
| 7254 | * @param subId the id of the subscription. |
| 7255 | * @param reason the reason the allowed network type change is taking place |
| 7256 | * @param allowedNetworkTypes the allowed network types. |
| 7257 | * @return true on success; false on any failure. |
| 7258 | */ |
| 7259 | @Override |
| 7260 | public boolean setAllowedNetworkTypesForReason(int subId, |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7261 | @TelephonyManager.AllowedNetworkTypesReason int reason, |
| 7262 | @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) { |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 7263 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7264 | mApp, subId, "setAllowedNetworkTypesForReason"); |
Gil Cukierman | 1d3d375 | 2022-10-03 21:31:33 +0000 | [diff] [blame] | 7265 | // If the caller only has carrier privileges, then they should not be able to override |
| 7266 | // any network types which were set for security reasons. |
| 7267 | if (mApp.checkCallingOrSelfPermission(Manifest.permission.MODIFY_PHONE_STATE) |
| 7268 | != PERMISSION_GRANTED |
Gil Cukierman | 2a8f48b | 2023-01-26 20:26:20 +0000 | [diff] [blame] | 7269 | && reason == TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_ENABLE_2G) { |
Gil Cukierman | 1d3d375 | 2022-10-03 21:31:33 +0000 | [diff] [blame] | 7270 | throw new SecurityException( |
| 7271 | "setAllowedNetworkTypesForReason cannot be called with carrier privileges for" |
Gil Cukierman | 2a8f48b | 2023-01-26 20:26:20 +0000 | [diff] [blame] | 7272 | + " reason " + reason); |
Gil Cukierman | 1d3d375 | 2022-10-03 21:31:33 +0000 | [diff] [blame] | 7273 | } |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7274 | if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) { |
Jack Yu | 5b49433 | 2023-01-23 18:18:04 +0000 | [diff] [blame] | 7275 | loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason); |
SongFerngWang | 7ffc273 | 2021-04-15 19:46:33 +0800 | [diff] [blame] | 7276 | return false; |
| 7277 | } |
| 7278 | if (!SubscriptionManager.isUsableSubscriptionId(subId)) { |
| 7279 | loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId); |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7280 | return false; |
| 7281 | } |
| 7282 | |
Jack Yu | 5b49433 | 2023-01-23 18:18:04 +0000 | [diff] [blame] | 7283 | log("setAllowedNetworkTypesForReason: subId=" + subId + ", reason=" + reason + " value: " |
| 7284 | + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes)); |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 7285 | |
Jack Yu | e37dd26 | 2022-12-16 11:53:37 -0800 | [diff] [blame] | 7286 | Phone phone = getPhone(subId); |
| 7287 | if (phone == null) { |
| 7288 | return false; |
| 7289 | } |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 7290 | |
Jack Yu | e37dd26 | 2022-12-16 11:53:37 -0800 | [diff] [blame] | 7291 | if (allowedNetworkTypes == phone.getAllowedNetworkTypes(reason)) { |
Jack Yu | 5b49433 | 2023-01-23 18:18:04 +0000 | [diff] [blame] | 7292 | log("setAllowedNetworkTypesForReason: " + reason + "does not change value"); |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 7293 | return true; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7294 | } |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 7295 | |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 7296 | final long identity = Binder.clearCallingIdentity(); |
| 7297 | try { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7298 | Boolean success = (Boolean) sendRequest( |
| 7299 | CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON, |
| 7300 | new Pair<Integer, Long>(reason, allowedNetworkTypes), subId); |
| 7301 | |
| 7302 | if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail")); |
| 7303 | return success; |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 7304 | } finally { |
| 7305 | Binder.restoreCallingIdentity(identity); |
| 7306 | } |
| 7307 | } |
| 7308 | |
| 7309 | /** |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 7310 | * Check whether DUN APN is required for tethering with subId. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 7311 | * |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 7312 | * @param subId the id of the subscription to require tethering. |
Amit Mahajan | fe58cdf | 2017-07-11 12:01:53 -0700 | [diff] [blame] | 7313 | * @return {@code true} if DUN APN is required for tethering. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 7314 | * @hide |
| 7315 | */ |
| 7316 | @Override |
SongFerngWang | f08d812 | 2019-11-15 14:58:44 +0800 | [diff] [blame] | 7317 | public boolean isTetheringApnRequiredForSubscriber(int subId) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7318 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7319 | final long identity = Binder.clearCallingIdentity(); |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 7320 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7321 | try { |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 7322 | if (phone != null) { |
| 7323 | return phone.hasMatchedTetherApnSetting(); |
| 7324 | } else { |
| 7325 | return false; |
| 7326 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7327 | } finally { |
| 7328 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 7329 | } |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 7330 | } |
| 7331 | |
| 7332 | /** |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 7333 | * Get the user enabled state of Mobile Data. |
| 7334 | * |
| 7335 | * TODO: remove and use isUserDataEnabled. |
| 7336 | * This can't be removed now because some vendor codes |
| 7337 | * calls through ITelephony directly while they should |
| 7338 | * use TelephonyManager. |
| 7339 | * |
| 7340 | * @return true on enabled |
| 7341 | */ |
| 7342 | @Override |
| 7343 | public boolean getDataEnabled(int subId) { |
| 7344 | return isUserDataEnabled(subId); |
| 7345 | } |
| 7346 | |
| 7347 | /** |
| 7348 | * Get whether mobile data is enabled per user setting. |
| 7349 | * |
| 7350 | * There are other factors deciding whether mobile data is actually enabled, but they are |
| 7351 | * not considered here. See {@link #isDataEnabled(int)} for more details. |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 7352 | * |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7353 | * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE |
| 7354 | * or carrier privileges. |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 7355 | * |
| 7356 | * @return {@code true} if data is enabled else {@code false} |
| 7357 | */ |
| 7358 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 7359 | public boolean isUserDataEnabled(int subId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7360 | String functionName = "isUserDataEnabled"; |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 7361 | try { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7362 | try { |
| 7363 | mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE, |
| 7364 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7365 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7366 | mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName); |
| 7367 | } |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7368 | } catch (SecurityException e) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7369 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7370 | mApp, subId, functionName); |
| 7371 | |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 7372 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7373 | |
| 7374 | final long identity = Binder.clearCallingIdentity(); |
| 7375 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 7376 | int phoneId = SubscriptionManager.getPhoneId(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7377 | if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 7378 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 7379 | if (phone != null) { |
| 7380 | boolean retVal = phone.isUserDataEnabled(); |
| 7381 | if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 7382 | return retVal; |
| 7383 | } else { |
| 7384 | if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 7385 | return false; |
| 7386 | } |
| 7387 | } finally { |
| 7388 | Binder.restoreCallingIdentity(identity); |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 7389 | } |
| 7390 | } |
| 7391 | |
| 7392 | /** |
Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 7393 | * Checks if the device is capable of mobile data by considering whether whether the |
| 7394 | * user has enabled mobile data, whether the carrier has enabled mobile data, and |
| 7395 | * whether the network policy allows data connections. |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 7396 | * |
Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 7397 | * @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] | 7398 | */ |
| 7399 | @Override |
| 7400 | public boolean isDataEnabled(int subId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7401 | String functionName = "isDataEnabled"; |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7402 | try { |
| 7403 | try { |
| 7404 | mApp.enforceCallingOrSelfPermission( |
| 7405 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7406 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7407 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7408 | try { |
| 7409 | mApp.enforceCallingOrSelfPermission( |
| 7410 | android.Manifest.permission.READ_PHONE_STATE, |
| 7411 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7412 | } catch (SecurityException e2) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7413 | mApp.enforceCallingOrSelfPermission( |
| 7414 | permission.READ_BASIC_PHONE_STATE, functionName); |
| 7415 | } |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7416 | } |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7417 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7418 | enforceReadPrivilegedPermission(functionName); |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7419 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7420 | |
| 7421 | final long identity = Binder.clearCallingIdentity(); |
| 7422 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 7423 | int phoneId = SubscriptionManager.getPhoneId(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7424 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 7425 | if (phone != null) { |
Sarah Chin | e04784a | 2022-10-31 20:32:34 -0700 | [diff] [blame] | 7426 | boolean retVal = phone.getDataSettingsManager().isDataEnabled(); |
Jack Yu | 4ad64e5 | 2021-12-03 14:23:53 -0800 | [diff] [blame] | 7427 | if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7428 | return retVal; |
| 7429 | } else { |
| 7430 | if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 7431 | return false; |
| 7432 | } |
| 7433 | } finally { |
| 7434 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 7435 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 7436 | } |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 7437 | |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7438 | /** |
| 7439 | * Check if data is enabled for a specific reason |
| 7440 | * @param subId Subscription index |
| 7441 | * @param reason the reason the data enable change is taking place |
| 7442 | * @return {@code true} if the overall data is enabled; {@code false} if not. |
| 7443 | */ |
| 7444 | @Override |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7445 | public boolean isDataEnabledForReason(int subId, |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7446 | @TelephonyManager.DataEnabledReason int reason) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7447 | String functionName = "isDataEnabledForReason"; |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7448 | try { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7449 | try { |
| 7450 | mApp.enforceCallingOrSelfPermission( |
| 7451 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 7452 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7453 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7454 | mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE, |
| 7455 | functionName); |
| 7456 | } |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7457 | } catch (SecurityException e) { |
Sooraj Sasindran | 0d909a0 | 2021-11-08 12:01:16 -0800 | [diff] [blame] | 7458 | try { |
| 7459 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7460 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7461 | } catch (SecurityException e2) { |
Sooraj Sasindran | 0d909a0 | 2021-11-08 12:01:16 -0800 | [diff] [blame] | 7462 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7463 | mApp, subId, functionName); |
Sooraj Sasindran | 0d909a0 | 2021-11-08 12:01:16 -0800 | [diff] [blame] | 7464 | } |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7465 | } |
| 7466 | |
| 7467 | |
| 7468 | final long identity = Binder.clearCallingIdentity(); |
| 7469 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 7470 | int phoneId = SubscriptionManager.getPhoneId(subId); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7471 | if (DBG) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7472 | log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7473 | + " reason=" + reason); |
| 7474 | } |
| 7475 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 7476 | if (phone != null) { |
| 7477 | boolean retVal; |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 7478 | retVal = phone.getDataSettingsManager().isDataEnabledForReason(reason); |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7479 | if (DBG) log("isDataEnabledForReason: retVal=" + retVal); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7480 | return retVal; |
| 7481 | } else { |
| 7482 | if (DBG) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7483 | loge("isDataEnabledForReason: no phone subId=" |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7484 | + subId + " retVal=false"); |
| 7485 | } |
| 7486 | return false; |
| 7487 | } |
| 7488 | } finally { |
| 7489 | Binder.restoreCallingIdentity(identity); |
| 7490 | } |
| 7491 | } |
| 7492 | |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 7493 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7494 | public int getCarrierPrivilegeStatus(int subId) { |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7495 | // No permission needed; this only lets the caller inspect their own status. |
| 7496 | return getCarrierPrivilegeStatusForUidWithPermission(subId, Binder.getCallingUid()); |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 7497 | } |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 7498 | |
| 7499 | @Override |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7500 | public int getCarrierPrivilegeStatusForUid(int subId, int uid) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 7501 | enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid"); |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7502 | return getCarrierPrivilegeStatusForUidWithPermission(subId, uid); |
| 7503 | } |
| 7504 | |
| 7505 | private int getCarrierPrivilegeStatusForUidWithPermission(int subId, int uid) { |
| 7506 | Phone phone = getPhone(subId); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7507 | if (phone == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 7508 | loge("getCarrierPrivilegeStatusForUid: Invalid subId"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7509 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 7510 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7511 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7512 | if (cpt == null) { |
| 7513 | loge("getCarrierPrivilegeStatusForUid: No CarrierPrivilegesTracker"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7514 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 7515 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7516 | return cpt.getCarrierPrivilegeStatusForUid(uid); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7517 | } |
| 7518 | |
| 7519 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7520 | public int checkCarrierPrivilegesForPackage(int subId, String pkgName) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 7521 | enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage"); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7522 | if (TextUtils.isEmpty(pkgName)) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 7523 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7524 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7525 | Phone phone = getPhone(subId); |
| 7526 | if (phone == null) { |
| 7527 | loge("checkCarrierPrivilegesForPackage: Invalid subId"); |
| 7528 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 7529 | } |
| 7530 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7531 | if (cpt == null) { |
| 7532 | loge("checkCarrierPrivilegesForPackage: No CarrierPrivilegesTracker"); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 7533 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 7534 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7535 | return cpt.getCarrierPrivilegeStatusForPackage(pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 7536 | } |
| 7537 | |
| 7538 | @Override |
| 7539 | public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) { |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7540 | enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackageAnyPhone"); |
Rambo Wang | e7209ce | 2022-02-23 13:41:02 -0800 | [diff] [blame] | 7541 | return checkCarrierPrivilegesForPackageAnyPhoneWithPermission(pkgName); |
| 7542 | } |
| 7543 | |
| 7544 | private int checkCarrierPrivilegesForPackageAnyPhoneWithPermission(String pkgName) { |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7545 | if (TextUtils.isEmpty(pkgName)) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 7546 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7547 | } |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 7548 | int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7549 | for (int phoneId = 0; phoneId < TelephonyManager.getDefault().getPhoneCount(); phoneId++) { |
| 7550 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 7551 | if (phone == null) { |
| 7552 | continue; |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 7553 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7554 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7555 | if (cpt == null) { |
| 7556 | continue; |
| 7557 | } |
| 7558 | result = cpt.getCarrierPrivilegeStatusForPackage(pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 7559 | if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 7560 | break; |
| 7561 | } |
| 7562 | } |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 7563 | return result; |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 7564 | } |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 7565 | |
| 7566 | @Override |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 7567 | public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 7568 | enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone"); |
Rambo Wang | 8a247eb | 2022-02-08 21:11:18 +0000 | [diff] [blame] | 7569 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 7570 | if (phone == null) { |
| 7571 | return Collections.emptyList(); |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 7572 | } |
Rambo Wang | 8a247eb | 2022-02-08 21:11:18 +0000 | [diff] [blame] | 7573 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7574 | if (cpt == null) { |
| 7575 | return Collections.emptyList(); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 7576 | } |
Rambo Wang | 8a247eb | 2022-02-08 21:11:18 +0000 | [diff] [blame] | 7577 | return cpt.getCarrierPackageNamesForIntent(intent); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 7578 | } |
| 7579 | |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 7580 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7581 | public List<String> getPackagesWithCarrierPrivileges(int phoneId) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 7582 | enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges"); |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7583 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 7584 | if (phone == null) { |
| 7585 | return Collections.emptyList(); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 7586 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7587 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7588 | if (cpt == null) { |
| 7589 | return Collections.emptyList(); |
| 7590 | } |
| 7591 | return new ArrayList<>(cpt.getPackagesWithCarrierPrivileges()); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 7592 | } |
| 7593 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7594 | @Override |
| 7595 | public List<String> getPackagesWithCarrierPrivilegesForAllPhones() { |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 7596 | enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones"); |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7597 | Set<String> privilegedPackages = new ArraySet<>(); |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 7598 | final long identity = Binder.clearCallingIdentity(); |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 7599 | try { |
| 7600 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 7601 | privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i)); |
| 7602 | } |
| 7603 | } finally { |
| 7604 | Binder.restoreCallingIdentity(identity); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7605 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7606 | return new ArrayList<>(privilegedPackages); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7607 | } |
| 7608 | |
Rambo Wang | 6812ffb | 2022-03-15 16:54:17 -0700 | [diff] [blame] | 7609 | @Override |
| 7610 | public @Nullable String getCarrierServicePackageNameForLogicalSlot(int logicalSlotIndex) { |
| 7611 | enforceReadPrivilegedPermission("getCarrierServicePackageNameForLogicalSlot"); |
| 7612 | |
| 7613 | final Phone phone = PhoneFactory.getPhone(logicalSlotIndex); |
| 7614 | if (phone == null) { |
| 7615 | return null; |
| 7616 | } |
| 7617 | final CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7618 | if (cpt == null) { |
| 7619 | return null; |
| 7620 | } |
| 7621 | return cpt.getCarrierServicePackageName(); |
| 7622 | } |
| 7623 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 7624 | private String getIccId(int subId) { |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 7625 | final Phone phone = getPhone(subId); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 7626 | UiccPort port = phone == null ? null : phone.getUiccPort(); |
| 7627 | if (port == null) { |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7628 | return null; |
| 7629 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 7630 | String iccId = port.getIccId(); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7631 | if (TextUtils.isEmpty(iccId)) { |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7632 | return null; |
| 7633 | } |
| 7634 | return iccId; |
| 7635 | } |
| 7636 | |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 7637 | @Override |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 7638 | public void setCallComposerStatus(int subId, int status) { |
| 7639 | enforceModifyPermission(); |
| 7640 | |
| 7641 | final long identity = Binder.clearCallingIdentity(); |
| 7642 | try { |
| 7643 | Phone phone = getPhone(subId); |
| 7644 | if (phone != null) { |
| 7645 | Phone defaultPhone = phone.getImsPhone(); |
| 7646 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 7647 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 7648 | imsPhone.setCallComposerStatus(status); |
Shuo Qian | 284ae75 | 2020-12-22 19:10:14 -0800 | [diff] [blame] | 7649 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| 7650 | .updateImsServiceConfig(); |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 7651 | } |
| 7652 | } |
Shuo Qian | 284ae75 | 2020-12-22 19:10:14 -0800 | [diff] [blame] | 7653 | } catch (ImsException e) { |
| 7654 | throw new ServiceSpecificException(e.getCode()); |
| 7655 | } finally { |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 7656 | Binder.restoreCallingIdentity(identity); |
| 7657 | } |
| 7658 | } |
| 7659 | |
| 7660 | @Override |
| 7661 | public int getCallComposerStatus(int subId) { |
| 7662 | enforceReadPrivilegedPermission("getCallComposerStatus"); |
| 7663 | |
| 7664 | final long identity = Binder.clearCallingIdentity(); |
| 7665 | try { |
| 7666 | Phone phone = getPhone(subId); |
| 7667 | if (phone != null) { |
| 7668 | Phone defaultPhone = phone.getImsPhone(); |
| 7669 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 7670 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 7671 | return imsPhone.getCallComposerStatus(); |
| 7672 | } |
| 7673 | } |
| 7674 | } finally { |
| 7675 | Binder.restoreCallingIdentity(identity); |
| 7676 | } |
| 7677 | return TelephonyManager.CALL_COMPOSER_STATUS_OFF; |
| 7678 | } |
| 7679 | |
| 7680 | @Override |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7681 | public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag, |
| 7682 | String number) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 7683 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7684 | subId, "setLine1NumberForDisplayForSubscriber"); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7685 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7686 | final long identity = Binder.clearCallingIdentity(); |
| 7687 | try { |
| 7688 | final String iccId = getIccId(subId); |
| 7689 | final Phone phone = getPhone(subId); |
| 7690 | if (phone == null) { |
| 7691 | return false; |
| 7692 | } |
| 7693 | final String subscriberId = phone.getSubscriberId(); |
| 7694 | |
| 7695 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 7696 | Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId=" |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7697 | + subscriberId + " to " + number); |
| 7698 | } |
| 7699 | |
| 7700 | if (TextUtils.isEmpty(iccId)) { |
| 7701 | return false; |
| 7702 | } |
| 7703 | |
| 7704 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 7705 | |
| 7706 | final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 7707 | if (alphaTag == null) { |
| 7708 | editor.remove(alphaTagPrefKey); |
| 7709 | } else { |
| 7710 | editor.putString(alphaTagPrefKey, alphaTag); |
| 7711 | } |
| 7712 | |
| 7713 | // Record both the line number and IMSI for this ICCID, since we need to |
| 7714 | // track all merged IMSIs based on line number |
| 7715 | final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 7716 | final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 7717 | if (number == null) { |
| 7718 | editor.remove(numberPrefKey); |
| 7719 | editor.remove(subscriberPrefKey); |
| 7720 | } else { |
| 7721 | editor.putString(numberPrefKey, number); |
| 7722 | editor.putString(subscriberPrefKey, subscriberId); |
| 7723 | } |
| 7724 | |
| 7725 | editor.commit(); |
| 7726 | return true; |
| 7727 | } finally { |
| 7728 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 7729 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7730 | } |
| 7731 | |
| 7732 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7733 | public String getLine1NumberForDisplay(int subId, String callingPackage, |
| 7734 | String callingFeatureId) { |
Makoto Onuki | fee6934 | 2015-06-29 14:44:50 -0700 | [diff] [blame] | 7735 | // This is open to apps with WRITE_SMS. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7736 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7737 | mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) { |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 7738 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission"); |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 7739 | return null; |
| 7740 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7741 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7742 | final long identity = Binder.clearCallingIdentity(); |
| 7743 | try { |
| 7744 | String iccId = getIccId(subId); |
| 7745 | if (iccId != null) { |
| 7746 | String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 7747 | if (DBG_MERGE) { |
| 7748 | log("getLine1NumberForDisplay returning " |
| 7749 | + mTelephonySharedPreferences.getString(numberPrefKey, null)); |
| 7750 | } |
| 7751 | return mTelephonySharedPreferences.getString(numberPrefKey, null); |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 7752 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7753 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null"); |
| 7754 | return null; |
| 7755 | } finally { |
| 7756 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7757 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7758 | } |
| 7759 | |
| 7760 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7761 | public String getLine1AlphaTagForDisplay(int subId, String callingPackage, |
| 7762 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7763 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7764 | mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 7765 | return null; |
| 7766 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7767 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7768 | final long identity = Binder.clearCallingIdentity(); |
| 7769 | try { |
| 7770 | String iccId = getIccId(subId); |
| 7771 | if (iccId != null) { |
| 7772 | String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 7773 | return mTelephonySharedPreferences.getString(alphaTagPrefKey, null); |
| 7774 | } |
| 7775 | return null; |
| 7776 | } finally { |
| 7777 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7778 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7779 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 7780 | |
| 7781 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7782 | public String[] getMergedSubscriberIds(int subId, String callingPackage, |
| 7783 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7784 | // This API isn't public, so no need to provide a valid subscription ID - we're not worried |
| 7785 | // about carrier-privileged callers not having access. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7786 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7787 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7788 | callingFeatureId, "getMergedSubscriberIds")) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7789 | return null; |
| 7790 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7791 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 7792 | // Clear calling identity, when calling TelephonyManager, because callerUid must be |
| 7793 | // the process, where TelephonyManager was instantiated. |
| 7794 | // Otherwise AppOps check will fail. |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7795 | final long identity = Binder.clearCallingIdentity(); |
| 7796 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7797 | final Context context = mApp; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7798 | final TelephonyManager tele = TelephonyManager.from(context); |
| 7799 | final SubscriptionManager sub = SubscriptionManager.from(context); |
| 7800 | |
| 7801 | // Figure out what subscribers are currently active |
| 7802 | final ArraySet<String> activeSubscriberIds = new ArraySet<>(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7803 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 7804 | // Only consider subs which match the current subId |
| 7805 | // This logic can be simplified. See b/131189269 for progress. |
| 7806 | if (isActiveSubscription(subId)) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7807 | activeSubscriberIds.add(tele.getSubscriberId(subId)); |
| 7808 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7809 | |
| 7810 | // First pass, find a number override for an active subscriber |
| 7811 | String mergeNumber = null; |
| 7812 | final Map<String, ?> prefs = mTelephonySharedPreferences.getAll(); |
| 7813 | for (String key : prefs.keySet()) { |
| 7814 | if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) { |
| 7815 | final String subscriberId = (String) prefs.get(key); |
| 7816 | if (activeSubscriberIds.contains(subscriberId)) { |
| 7817 | final String iccId = key.substring( |
| 7818 | PREF_CARRIERS_SUBSCRIBER_PREFIX.length()); |
| 7819 | final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 7820 | mergeNumber = (String) prefs.get(numberKey); |
| 7821 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 7822 | Rlog.d(LOG_TAG, "Found line number " + mergeNumber |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7823 | + " for active subscriber " + subscriberId); |
| 7824 | } |
| 7825 | if (!TextUtils.isEmpty(mergeNumber)) { |
| 7826 | break; |
| 7827 | } |
| 7828 | } |
| 7829 | } |
| 7830 | } |
| 7831 | |
| 7832 | // Shortcut when no active merged subscribers |
| 7833 | if (TextUtils.isEmpty(mergeNumber)) { |
| 7834 | return null; |
| 7835 | } |
| 7836 | |
| 7837 | // Second pass, find all subscribers under that line override |
| 7838 | final ArraySet<String> result = new ArraySet<>(); |
| 7839 | for (String key : prefs.keySet()) { |
| 7840 | if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) { |
| 7841 | final String number = (String) prefs.get(key); |
| 7842 | if (mergeNumber.equals(number)) { |
| 7843 | final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length()); |
| 7844 | final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 7845 | final String subscriberId = (String) prefs.get(subscriberKey); |
| 7846 | if (!TextUtils.isEmpty(subscriberId)) { |
| 7847 | result.add(subscriberId); |
| 7848 | } |
| 7849 | } |
| 7850 | } |
| 7851 | } |
| 7852 | |
| 7853 | final String[] resultArray = result.toArray(new String[result.size()]); |
| 7854 | Arrays.sort(resultArray); |
| 7855 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 7856 | Rlog.d(LOG_TAG, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7857 | "Found subscribers " + Arrays.toString(resultArray) + " after merge"); |
| 7858 | } |
| 7859 | return resultArray; |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7860 | } finally { |
| 7861 | Binder.restoreCallingIdentity(identity); |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7862 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7863 | } |
| 7864 | |
| 7865 | @Override |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 7866 | public String[] getMergedImsisFromGroup(int subId, String callingPackage) { |
| 7867 | enforceReadPrivilegedPermission("getMergedImsisFromGroup"); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7868 | |
| 7869 | final long identity = Binder.clearCallingIdentity(); |
| 7870 | try { |
| 7871 | final TelephonyManager telephonyManager = mApp.getSystemService( |
| 7872 | TelephonyManager.class); |
| 7873 | String subscriberId = telephonyManager.getSubscriberId(subId); |
| 7874 | if (subscriberId == null) { |
| 7875 | if (DBG) { |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 7876 | log("getMergedImsisFromGroup can't find subscriberId for subId " |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7877 | + subId); |
| 7878 | } |
| 7879 | return null; |
| 7880 | } |
| 7881 | |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 7882 | ParcelUuid groupUuid; |
| 7883 | if (PhoneFactory.isSubscriptionManagerServiceEnabled()) { |
Jack Yu | fa8ed01 | 2023-02-11 15:42:28 -0800 | [diff] [blame] | 7884 | final SubscriptionInfo info = getSubscriptionManagerService() |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 7885 | .getSubscriptionInfo(subId); |
| 7886 | groupUuid = info.getGroupUuid(); |
| 7887 | } else { |
| 7888 | final SubscriptionInfo info = mSubscriptionController |
| 7889 | .getSubscriptionInfo(subId); |
| 7890 | groupUuid = info.getGroupUuid(); |
| 7891 | } |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7892 | // If it doesn't belong to any group, return just subscriberId of itself. |
| 7893 | if (groupUuid == null) { |
| 7894 | return new String[]{subscriberId}; |
| 7895 | } |
| 7896 | |
| 7897 | // Get all subscriberIds from the group. |
| 7898 | final List<String> mergedSubscriberIds = new ArrayList<>(); |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 7899 | List<SubscriptionInfo> groupInfos; |
| 7900 | if (PhoneFactory.isSubscriptionManagerServiceEnabled()) { |
Jack Yu | fa8ed01 | 2023-02-11 15:42:28 -0800 | [diff] [blame] | 7901 | groupInfos = getSubscriptionManagerService() |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 7902 | .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(), |
| 7903 | mApp.getAttributionTag()); |
| 7904 | } else { |
| 7905 | groupInfos = mSubscriptionController |
| 7906 | .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(), |
| 7907 | mApp.getAttributionTag()); |
| 7908 | } |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7909 | for (SubscriptionInfo subInfo : groupInfos) { |
| 7910 | subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId()); |
| 7911 | if (subscriberId != null) { |
| 7912 | mergedSubscriberIds.add(subscriberId); |
| 7913 | } |
| 7914 | } |
| 7915 | |
| 7916 | return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]); |
| 7917 | } finally { |
| 7918 | Binder.restoreCallingIdentity(identity); |
| 7919 | |
| 7920 | } |
| 7921 | } |
| 7922 | |
| 7923 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7924 | public boolean setOperatorBrandOverride(int subId, String brand) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 7925 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7926 | subId, "setOperatorBrandOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7927 | |
| 7928 | final long identity = Binder.clearCallingIdentity(); |
| 7929 | try { |
| 7930 | final Phone phone = getPhone(subId); |
| 7931 | return phone == null ? false : phone.setOperatorBrandOverride(brand); |
| 7932 | } finally { |
| 7933 | Binder.restoreCallingIdentity(identity); |
| 7934 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 7935 | } |
Steven Liu | 4bf01bc | 2014-07-17 11:05:29 -0500 | [diff] [blame] | 7936 | |
| 7937 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7938 | public boolean setRoamingOverride(int subId, List<String> gsmRoamingList, |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 7939 | List<String> gsmNonRoamingList, List<String> cdmaRoamingList, |
| 7940 | List<String> cdmaNonRoamingList) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 7941 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 7942 | mApp, subId, "setRoamingOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7943 | |
| 7944 | final long identity = Binder.clearCallingIdentity(); |
| 7945 | try { |
| 7946 | final Phone phone = getPhone(subId); |
| 7947 | if (phone == null) { |
| 7948 | return false; |
| 7949 | } |
| 7950 | return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList, |
| 7951 | cdmaNonRoamingList); |
| 7952 | } finally { |
| 7953 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7954 | } |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 7955 | } |
| 7956 | |
| 7957 | @Override |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 7958 | @Deprecated |
| 7959 | public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) { |
| 7960 | enforceModifyPermission(); |
| 7961 | |
| 7962 | int returnValue = 0; |
| 7963 | try { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7964 | AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 7965 | if(result.exception == null) { |
| 7966 | if (result.result != null) { |
| 7967 | byte[] responseData = (byte[])(result.result); |
| 7968 | if(responseData.length > oemResp.length) { |
| 7969 | Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " + |
| 7970 | responseData.length + "bytes. Buffer Size is " + |
| 7971 | oemResp.length + "bytes."); |
| 7972 | } |
| 7973 | System.arraycopy(responseData, 0, oemResp, 0, responseData.length); |
| 7974 | returnValue = responseData.length; |
| 7975 | } |
| 7976 | } else { |
| 7977 | CommandException ex = (CommandException) result.exception; |
| 7978 | returnValue = ex.getCommandError().ordinal(); |
| 7979 | if(returnValue > 0) returnValue *= -1; |
| 7980 | } |
| 7981 | } catch (RuntimeException e) { |
| 7982 | Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception"); |
| 7983 | returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal()); |
| 7984 | if(returnValue > 0) returnValue *= -1; |
| 7985 | } |
| 7986 | |
| 7987 | return returnValue; |
| 7988 | } |
| 7989 | |
| 7990 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 7991 | public int getRadioAccessFamily(int phoneId, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7992 | Phone phone = PhoneFactory.getPhone(phoneId); |
Shuo Qian | dee5340 | 2020-05-29 14:08:15 -0700 | [diff] [blame] | 7993 | try { |
| 7994 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 7995 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Shuo Qian | dee5340 | 2020-05-29 14:08:15 -0700 | [diff] [blame] | 7996 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 7997 | } catch (SecurityException e) { |
| 7998 | EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission"); |
| 7999 | throw e; |
| 8000 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 8001 | int raf = RadioAccessFamily.RAF_UNKNOWN; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 8002 | if (phone == null) { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 8003 | return raf; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 8004 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8005 | final long identity = Binder.clearCallingIdentity(); |
| 8006 | try { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 8007 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 8008 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 8009 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 8010 | raf = ProxyController.getInstance().getRadioAccessFamily(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8011 | } finally { |
| 8012 | Binder.restoreCallingIdentity(identity); |
| 8013 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 8014 | return raf; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 8015 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 8016 | |
| 8017 | @Override |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 8018 | public void uploadCallComposerPicture(int subscriptionId, String callingPackage, |
Hall Liu | e31bac6 | 2020-12-23 19:16:10 -0800 | [diff] [blame] | 8019 | String contentType, ParcelFileDescriptor fd, ResultReceiver callback) { |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 8020 | try { |
| 8021 | if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0), |
| 8022 | Binder.getCallingUid())) { |
Tyler Gunn | b87925a | 2021-06-10 14:54:27 -0700 | [diff] [blame] | 8023 | throw new SecurityException("Invalid package:" + callingPackage); |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 8024 | } |
| 8025 | } catch (PackageManager.NameNotFoundException e) { |
Tyler Gunn | b87925a | 2021-06-10 14:54:27 -0700 | [diff] [blame] | 8026 | throw new SecurityException("Invalid package:" + callingPackage); |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 8027 | } |
| 8028 | RoleManager rm = mApp.getSystemService(RoleManager.class); |
| 8029 | List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER); |
| 8030 | if (!dialerRoleHolders.contains(callingPackage)) { |
| 8031 | throw new SecurityException("App must be the dialer role holder to" |
| 8032 | + " upload a call composer pic"); |
| 8033 | } |
| 8034 | |
| 8035 | Executors.newSingleThreadExecutor().execute(() -> { |
| 8036 | ByteArrayOutputStream output = new ByteArrayOutputStream( |
| 8037 | (int) TelephonyManager.getMaximumCallComposerPictureSize()); |
| 8038 | InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd); |
| 8039 | boolean readUntilEnd = false; |
| 8040 | int totalBytesRead = 0; |
| 8041 | byte[] buffer = new byte[16 * 1024]; |
| 8042 | while (true) { |
| 8043 | int numRead; |
| 8044 | try { |
| 8045 | numRead = input.read(buffer); |
| 8046 | } catch (IOException e) { |
| 8047 | try { |
| 8048 | fd.checkError(); |
| 8049 | callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED, |
| 8050 | null); |
| 8051 | } catch (IOException e1) { |
| 8052 | // This means that the other side closed explicitly with an error. If this |
| 8053 | // happens, log and ignore. |
| 8054 | loge("Remote end of call composer picture pipe closed: " + e1); |
| 8055 | } |
| 8056 | break; |
| 8057 | } |
| 8058 | if (numRead == -1) { |
| 8059 | readUntilEnd = true; |
| 8060 | break; |
| 8061 | } |
| 8062 | totalBytesRead += numRead; |
| 8063 | if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) { |
| 8064 | loge("Too many bytes read for call composer picture: " + totalBytesRead); |
| 8065 | try { |
| 8066 | input.close(); |
| 8067 | } catch (IOException e) { |
| 8068 | // ignore |
| 8069 | } |
| 8070 | break; |
| 8071 | } |
| 8072 | output.write(buffer, 0, numRead); |
| 8073 | } |
| 8074 | // Generally, the remote end will close the file descriptors. The only case where we |
| 8075 | // close is above, where the picture size is too big. |
| 8076 | |
| 8077 | try { |
| 8078 | fd.checkError(); |
| 8079 | } catch (IOException e) { |
| 8080 | loge("Remote end for call composer closed with an error: " + e); |
| 8081 | return; |
| 8082 | } |
| 8083 | |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 8084 | if (!readUntilEnd) { |
| 8085 | loge("Did not finish reading entire image; aborting"); |
| 8086 | return; |
| 8087 | } |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 8088 | |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 8089 | ImageData imageData = new ImageData(output.toByteArray(), contentType, null); |
| 8090 | CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer( |
| 8091 | new CallComposerPictureTransfer.Factory() {}, |
| 8092 | imageData, |
| 8093 | (result) -> { |
| 8094 | if (result.first != null) { |
| 8095 | ParcelUuid parcelUuid = new ParcelUuid(result.first); |
| 8096 | Bundle outputResult = new Bundle(); |
| 8097 | outputResult.putParcelable( |
| 8098 | TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid); |
| 8099 | callback.send(TelephonyManager.CallComposerException.SUCCESS, |
| 8100 | outputResult); |
| 8101 | } else { |
| 8102 | callback.send(result.second, null); |
| 8103 | } |
| 8104 | } |
| 8105 | ); |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 8106 | }); |
| 8107 | } |
| 8108 | |
| 8109 | @Override |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 8110 | public void enableVideoCalling(boolean enable) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8111 | final Phone defaultPhone = getDefaultPhone(); |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 8112 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8113 | |
| 8114 | final long identity = Binder.clearCallingIdentity(); |
| 8115 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8116 | ImsManager.getInstance(defaultPhone.getContext(), |
| 8117 | defaultPhone.getPhoneId()).setVtSetting(enable); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8118 | } finally { |
| 8119 | Binder.restoreCallingIdentity(identity); |
| 8120 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 8121 | } |
| 8122 | |
| 8123 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8124 | public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8125 | final Phone defaultPhone = getDefaultPhone(); |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8126 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 8127 | callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 8128 | return false; |
| 8129 | } |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 8130 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8131 | final long identity = Binder.clearCallingIdentity(); |
| 8132 | try { |
| 8133 | // Check the user preference and the system-level IMS setting. Even if the user has |
| 8134 | // enabled video calling, if IMS is disabled we aren't able to support video calling. |
| 8135 | // In the long run, we may instead need to check if there exists a connection service |
| 8136 | // which can support video calling. |
| 8137 | ImsManager imsManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8138 | ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8139 | return imsManager.isVtEnabledByPlatform() |
| 8140 | && imsManager.isEnhanced4gLteModeSettingEnabledByUser() |
| 8141 | && imsManager.isVtEnabledByUser(); |
| 8142 | } finally { |
| 8143 | Binder.restoreCallingIdentity(identity); |
| 8144 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 8145 | } |
Libin.Tang@motorola.com | afe8264 | 2014-12-18 13:27:53 -0600 | [diff] [blame] | 8146 | |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 8147 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8148 | public boolean canChangeDtmfToneLength(int subId, String callingPackage, |
| 8149 | String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8150 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8151 | mApp, subId, callingPackage, callingFeatureId, |
| 8152 | "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8153 | return false; |
| 8154 | } |
| 8155 | |
| 8156 | final long identity = Binder.clearCallingIdentity(); |
| 8157 | try { |
| 8158 | CarrierConfigManager configManager = |
| 8159 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8160 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8161 | .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL); |
| 8162 | } finally { |
| 8163 | Binder.restoreCallingIdentity(identity); |
| 8164 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 8165 | } |
| 8166 | |
| 8167 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8168 | public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8169 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8170 | mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8171 | return false; |
| 8172 | } |
| 8173 | |
| 8174 | final long identity = Binder.clearCallingIdentity(); |
| 8175 | try { |
| 8176 | CarrierConfigManager configManager = |
| 8177 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8178 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8179 | .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL); |
| 8180 | } finally { |
| 8181 | Binder.restoreCallingIdentity(identity); |
| 8182 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 8183 | } |
| 8184 | |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 8185 | @Override |
| 8186 | public boolean isTtyModeSupported() { |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 8187 | TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class); |
Wooki Wu | 1f82f7a | 2016-02-15 15:59:58 +0800 | [diff] [blame] | 8188 | return telecomManager.isTtySupported(); |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 8189 | } |
| 8190 | |
| 8191 | @Override |
| 8192 | public boolean isHearingAidCompatibilitySupported() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8193 | final long identity = Binder.clearCallingIdentity(); |
| 8194 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8195 | return mApp.getResources().getBoolean(R.bool.hac_enabled); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8196 | } finally { |
| 8197 | Binder.restoreCallingIdentity(identity); |
| 8198 | } |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 8199 | } |
| 8200 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 8201 | /** |
| 8202 | * Determines whether the device currently supports RTT (Real-time text). Based both on carrier |
| 8203 | * support for the feature and device firmware support. |
| 8204 | * |
| 8205 | * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise. |
| 8206 | */ |
| 8207 | @Override |
| 8208 | public boolean isRttSupported(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8209 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8210 | final Phone phone = getPhone(subscriptionId); |
| 8211 | if (phone == null) { |
| 8212 | loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId); |
| 8213 | return false; |
| 8214 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8215 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8216 | boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8217 | CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL); |
| 8218 | boolean isDeviceSupported = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8219 | phone.getContext().getResources().getBoolean(R.bool.config_support_rtt); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8220 | return isCarrierSupported && isDeviceSupported; |
| 8221 | } finally { |
| 8222 | Binder.restoreCallingIdentity(identity); |
| 8223 | } |
Hall Liu | 9818758 | 2018-01-22 19:15:32 -0800 | [diff] [blame] | 8224 | } |
| 8225 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 8226 | /** |
Hall Liu | f2daa02 | 2019-07-23 18:39:00 -0700 | [diff] [blame] | 8227 | * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set |
| 8228 | * RTT setting, will return true if the device and carrier both support RTT. |
| 8229 | * 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] | 8230 | */ |
| 8231 | public boolean isRttEnabled(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8232 | final long identity = Binder.clearCallingIdentity(); |
| 8233 | try { |
Hall Liu | 5bab75c | 2019-12-11 23:58:20 +0000 | [diff] [blame] | 8234 | boolean isRttSupported = isRttSupported(subscriptionId); |
| 8235 | boolean isUserRttSettingOn = Settings.Secure.getInt( |
| 8236 | mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0; |
| 8237 | boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId) |
| 8238 | .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL); |
| 8239 | return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8240 | } finally { |
| 8241 | Binder.restoreCallingIdentity(identity); |
| 8242 | } |
Hall Liu | 3ad5f01 | 2018-04-06 16:23:39 -0700 | [diff] [blame] | 8243 | } |
| 8244 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8245 | @Deprecated |
| 8246 | @Override |
| 8247 | public String getDeviceId(String callingPackage) { |
| 8248 | return getDeviceIdWithFeature(callingPackage, null); |
| 8249 | } |
| 8250 | |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 8251 | /** |
| 8252 | * Returns the unique device ID of phone, for example, the IMEI for |
| 8253 | * GSM and the MEID for CDMA phones. Return null if device ID is not available. |
| 8254 | * |
| 8255 | * <p>Requires Permission: |
| 8256 | * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} |
| 8257 | */ |
| 8258 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8259 | public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) { |
Shuo Qian | 13d8915 | 2021-05-10 23:58:11 -0700 | [diff] [blame] | 8260 | try { |
| 8261 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 8262 | } catch (SecurityException se) { |
| 8263 | EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid()); |
| 8264 | throw new SecurityException("Package " + callingPackage + " does not belong to " |
| 8265 | + Binder.getCallingUid()); |
| 8266 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 8267 | final Phone phone = PhoneFactory.getPhone(0); |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 8268 | if (phone == null) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 8269 | return null; |
| 8270 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 8271 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 8272 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8273 | callingPackage, callingFeatureId, "getDeviceId")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 8274 | return null; |
| 8275 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8276 | |
| 8277 | final long identity = Binder.clearCallingIdentity(); |
| 8278 | try { |
| 8279 | return phone.getDeviceId(); |
| 8280 | } finally { |
| 8281 | Binder.restoreCallingIdentity(identity); |
| 8282 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 8283 | } |
| 8284 | |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 8285 | /** |
| 8286 | * {@hide} |
| 8287 | * Returns the IMS Registration Status on a particular subid |
| 8288 | * |
| 8289 | * @param subId |
| 8290 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8291 | public boolean isImsRegistered(int subId) { |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 8292 | Phone phone = getPhone(subId); |
| 8293 | if (phone != null) { |
| 8294 | return phone.isImsRegistered(); |
| 8295 | } else { |
| 8296 | return false; |
| 8297 | } |
| 8298 | } |
| 8299 | |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 8300 | @Override |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 8301 | public int getSubIdForPhoneAccountHandle( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8302 | PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) { |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 8303 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(), |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8304 | callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) { |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 8305 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 8306 | } |
| 8307 | final long identity = Binder.clearCallingIdentity(); |
| 8308 | try { |
| 8309 | return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle); |
| 8310 | } finally { |
| 8311 | Binder.restoreCallingIdentity(identity); |
| 8312 | } |
| 8313 | } |
| 8314 | |
| 8315 | @Override |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 8316 | public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) { |
Alireza Forouzan | 4ac4f98 | 2021-03-16 22:18:52 -0700 | [diff] [blame] | 8317 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 8318 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 8319 | mApp, |
| 8320 | subscriptionId, |
| 8321 | "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: " |
| 8322 | + subscriptionId); |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 8323 | final long identity = Binder.clearCallingIdentity(); |
| 8324 | try { |
| 8325 | Phone phone = getPhone(subscriptionId); |
| 8326 | if (phone == null) { |
| 8327 | return null; |
| 8328 | } |
| 8329 | return PhoneUtils.makePstnPhoneAccountHandle(phone); |
| 8330 | } finally { |
| 8331 | Binder.restoreCallingIdentity(identity); |
| 8332 | } |
| 8333 | } |
| 8334 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8335 | /** |
| 8336 | * @return the VoWiFi calling availability. |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 8337 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8338 | public boolean isWifiCallingAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8339 | final long identity = Binder.clearCallingIdentity(); |
| 8340 | try { |
| 8341 | Phone phone = getPhone(subId); |
| 8342 | if (phone != null) { |
| 8343 | return phone.isWifiCallingEnabled(); |
| 8344 | } else { |
| 8345 | return false; |
| 8346 | } |
| 8347 | } finally { |
| 8348 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8349 | } |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 8350 | } |
| 8351 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8352 | /** |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8353 | * @return the VT calling availability. |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 8354 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8355 | public boolean isVideoTelephonyAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8356 | final long identity = Binder.clearCallingIdentity(); |
| 8357 | try { |
| 8358 | Phone phone = getPhone(subId); |
| 8359 | if (phone != null) { |
| 8360 | return phone.isVideoEnabled(); |
| 8361 | } else { |
| 8362 | return false; |
| 8363 | } |
| 8364 | } finally { |
| 8365 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8366 | } |
| 8367 | } |
| 8368 | |
| 8369 | /** |
| 8370 | * @return the IMS registration technology for the MMTEL feature. Valid return values are |
| 8371 | * defined in {@link ImsRegistrationImplBase}. |
| 8372 | */ |
| 8373 | public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8374 | final long identity = Binder.clearCallingIdentity(); |
| 8375 | try { |
| 8376 | Phone phone = getPhone(subId); |
| 8377 | if (phone != null) { |
| 8378 | return phone.getImsRegistrationTech(); |
| 8379 | } else { |
| 8380 | return ImsRegistrationImplBase.REGISTRATION_TECH_NONE; |
| 8381 | } |
| 8382 | } finally { |
| 8383 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8384 | } |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 8385 | } |
| 8386 | |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 8387 | @Override |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 8388 | public void factoryReset(int subId, String callingPackage) { |
paulhu | 5a77360 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 8389 | enforceSettingsPermission(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 8390 | if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) { |
| 8391 | return; |
| 8392 | } |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 8393 | Phone defaultPhone = getDefaultPhone(); |
| 8394 | if (defaultPhone != null) { |
| 8395 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8396 | mApp, getDefaultPhone().getSubId(), "factoryReset"); |
| 8397 | } |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 8398 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8399 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 8400 | try { |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 8401 | if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction( |
| 8402 | UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 8403 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 8404 | getDefaultDataEnabled(), callingPackage); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 8405 | setNetworkSelectionModeAutomatic(subId); |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 8406 | Phone phone = getPhone(subId); |
SongFerngWang | fd89b10 | 2021-05-27 22:44:54 +0800 | [diff] [blame] | 8407 | cleanUpAllowedNetworkTypes(phone, subId); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8408 | setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId)); |
Jordan Liu | 857e73a | 2021-03-05 16:24:04 -0800 | [diff] [blame] | 8409 | getPhone(subId).resetCarrierKeysForImsiEncryption(); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 8410 | } |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 8411 | // There has been issues when Sms raw table somehow stores orphan |
| 8412 | // fragments. They lead to garbled message when new fragments come |
| 8413 | // in and combined with those stale ones. In case this happens again, |
| 8414 | // user can reset all network settings which will clean up this table. |
| 8415 | cleanUpSmsRawTable(getDefaultPhone().getContext()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 8416 | // Clean up IMS settings as well here. |
| 8417 | int slotId = getSlotIndex(subId); |
| 8418 | if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 8419 | ImsManager.getInstance(mApp, slotId).factoryReset(); |
| 8420 | } |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 8421 | |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 8422 | if (defaultPhone == null) { |
| 8423 | return; |
| 8424 | } |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 8425 | // Erase modem config if erase modem on network setting is enabled. |
| 8426 | String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY, |
| 8427 | RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED); |
| 8428 | if (configValue != null && Boolean.parseBoolean(configValue)) { |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 8429 | sendEraseModemConfig(defaultPhone); |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 8430 | } |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 8431 | |
| 8432 | sendEraseDataInSharedPreferences(defaultPhone); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 8433 | } finally { |
| 8434 | Binder.restoreCallingIdentity(identity); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 8435 | } |
| 8436 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 8437 | |
SongFerngWang | fd89b10 | 2021-05-27 22:44:54 +0800 | [diff] [blame] | 8438 | @VisibleForTesting |
| 8439 | void cleanUpAllowedNetworkTypes(Phone phone, int subId) { |
| 8440 | if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) { |
| 8441 | return; |
| 8442 | } |
| 8443 | long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType( |
| 8444 | RILConstants.PREFERRED_NETWORK_MODE); |
| 8445 | SubscriptionManager.setSubscriptionProperty(subId, |
| 8446 | SubscriptionManager.ALLOWED_NETWORK_TYPES, |
| 8447 | "user=" + defaultNetworkType); |
| 8448 | phone.loadAllowedNetworksFromSubscriptionDatabase(); |
| 8449 | phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER, |
| 8450 | defaultNetworkType, null); |
| 8451 | } |
| 8452 | |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 8453 | private void cleanUpSmsRawTable(Context context) { |
| 8454 | ContentResolver resolver = context.getContentResolver(); |
| 8455 | Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete"); |
| 8456 | resolver.delete(uri, null, null); |
| 8457 | } |
| 8458 | |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 8459 | @Override |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 8460 | public String getSimLocaleForSubscriber(int subId) { |
| 8461 | enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId); |
| 8462 | final Phone phone = getPhone(subId); |
| 8463 | if (phone == null) { |
| 8464 | log("getSimLocaleForSubscriber, invalid subId"); |
chen xu | 2bb91e4 | 2019-01-24 14:35:54 -0800 | [diff] [blame] | 8465 | return null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 8466 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8467 | final long identity = Binder.clearCallingIdentity(); |
| 8468 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 8469 | SubscriptionInfo info; |
| 8470 | if (PhoneFactory.isSubscriptionManagerServiceEnabled()) { |
Jack Yu | fa8ed01 | 2023-02-11 15:42:28 -0800 | [diff] [blame] | 8471 | info = getSubscriptionManagerService().getActiveSubscriptionInfo(subId, |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 8472 | phone.getContext().getOpPackageName(), |
| 8473 | phone.getContext().getAttributionTag()); |
| 8474 | if (info == null) { |
| 8475 | log("getSimLocaleForSubscriber, inactive subId: " + subId); |
| 8476 | return null; |
| 8477 | } |
| 8478 | } else { |
| 8479 | info = mSubscriptionController.getActiveSubscriptionInfo(subId, |
| 8480 | phone.getContext().getOpPackageName(), |
| 8481 | phone.getContext().getAttributionTag()); |
| 8482 | if (info == null) { |
| 8483 | log("getSimLocaleForSubscriber, inactive subId: " + subId); |
| 8484 | return null; |
| 8485 | } |
chen xu | 6291c47 | 2019-02-04 12:55:53 -0800 | [diff] [blame] | 8486 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8487 | // Try and fetch the locale from the carrier properties or from the SIM language |
| 8488 | // preferences (EF-PL and EF-LI)... |
| 8489 | final int mcc = info.getMcc(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8490 | String simLanguage = null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 8491 | final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs(); |
| 8492 | if (localeFromDefaultSim != null) { |
| 8493 | if (!localeFromDefaultSim.getCountry().isEmpty()) { |
| 8494 | if (DBG) log("Using locale from subId: " + subId + " locale: " |
| 8495 | + localeFromDefaultSim); |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 8496 | return matchLocaleFromSupportedLocaleList(phone, localeFromDefaultSim); |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 8497 | } else { |
| 8498 | simLanguage = localeFromDefaultSim.getLanguage(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8499 | } |
| 8500 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 8501 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8502 | // The SIM language preferences only store a language (e.g. fr = French), not an |
| 8503 | // exact locale (e.g. fr_FR = French/France). So, if the locale returned from |
| 8504 | // the SIM and carrier preferences does not include a country we add the country |
| 8505 | // determined from the SIM MCC to provide an exact locale. |
zoey chen | c730df8 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 8506 | final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8507 | if (mccLocale != null) { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 8508 | if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale); |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 8509 | return matchLocaleFromSupportedLocaleList(phone, mccLocale); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8510 | } |
| 8511 | |
| 8512 | if (DBG) log("No locale found - returning null"); |
| 8513 | return null; |
| 8514 | } finally { |
| 8515 | Binder.restoreCallingIdentity(identity); |
| 8516 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 8517 | } |
| 8518 | |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 8519 | @VisibleForTesting |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 8520 | String matchLocaleFromSupportedLocaleList(Phone phone, @NonNull Locale inputLocale) { |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 8521 | String[] supportedLocale = com.android.internal.app.LocalePicker.getSupportedLocales( |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 8522 | phone.getContext()); |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 8523 | for (String localeTag : supportedLocale) { |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 8524 | if (LocaleList.matchesLanguageAndScript(inputLocale, Locale.forLanguageTag(localeTag)) |
| 8525 | && TextUtils.equals(inputLocale.getCountry(), |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 8526 | Locale.forLanguageTag(localeTag).getCountry())) { |
| 8527 | return localeTag; |
| 8528 | } |
| 8529 | } |
| 8530 | return inputLocale.toLanguageTag(); |
| 8531 | } |
| 8532 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8533 | /** |
| 8534 | * NOTE: this method assumes permission checks are done and caller identity has been cleared. |
| 8535 | */ |
| 8536 | private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 8537 | if (PhoneFactory.isSubscriptionManagerServiceEnabled()) { |
Jack Yu | fa8ed01 | 2023-02-11 15:42:28 -0800 | [diff] [blame] | 8538 | return getSubscriptionManagerService().getActiveSubscriptionInfoList( |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 8539 | mApp.getOpPackageName(), mApp.getAttributionTag()); |
| 8540 | } |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8541 | return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(), |
Philip P. Moltmann | 8d34f0c | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 8542 | mApp.getAttributionTag()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 8543 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 8544 | |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8545 | private ActivityStatsTechSpecificInfo[] mLastModemActivitySpecificInfo = null; |
| 8546 | private ModemActivityInfo mLastModemActivityInfo = null; |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 8547 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 8548 | /** |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 8549 | * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object |
| 8550 | * representing the state of the modem. |
| 8551 | * |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 8552 | * NOTE: The underlying implementation clears the modem state, so there should only ever be one |
| 8553 | * caller to it. Everyone should call this class to get cumulative data. |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 8554 | * @hide |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 8555 | */ |
| 8556 | @Override |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 8557 | public void requestModemActivityInfo(ResultReceiver result) { |
| 8558 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8559 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8560 | |
| 8561 | final long identity = Binder.clearCallingIdentity(); |
| 8562 | try { |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 8563 | sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8564 | } finally { |
| 8565 | Binder.restoreCallingIdentity(identity); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 8566 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 8567 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8568 | |
Gary Jian | 76280a4 | 2022-12-07 16:18:33 +0800 | [diff] [blame] | 8569 | // Checks that ModemActivityInfo is valid. Sleep time and Idle time should be |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 8570 | // less than total activity duration. |
| 8571 | private boolean isModemActivityInfoValid(ModemActivityInfo info) { |
| 8572 | if (info == null) { |
| 8573 | return false; |
| 8574 | } |
| 8575 | int activityDurationMs = |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 8576 | (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis()); |
Gary Jian | 76280a4 | 2022-12-07 16:18:33 +0800 | [diff] [blame] | 8577 | activityDurationMs += MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS; |
| 8578 | |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 8579 | int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum(); |
| 8580 | |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 8581 | return (info.isValid() |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 8582 | && (info.getSleepTimeMillis() <= activityDurationMs) |
| 8583 | && (info.getIdleTimeMillis() <= activityDurationMs)); |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 8584 | } |
| 8585 | |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8586 | private void updateLastModemActivityInfo(ModemActivityInfo info, int rat, int freq) { |
| 8587 | int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()]; |
| 8588 | int[] txTimeMs = info.getTransmitTimeMillis(rat, freq); |
| 8589 | int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat, freq); |
| 8590 | |
| 8591 | for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) { |
| 8592 | mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl]; |
| 8593 | } |
| 8594 | |
| 8595 | mLastModemActivityInfo.setTransmitTimeMillis(rat, freq, mergedTxTimeMs); |
| 8596 | mLastModemActivityInfo.setReceiveTimeMillis( |
| 8597 | rat, |
| 8598 | freq, |
| 8599 | info.getReceiveTimeMillis(rat, freq) |
| 8600 | + mLastModemActivityInfo.getReceiveTimeMillis(rat, freq)); |
| 8601 | } |
| 8602 | |
| 8603 | private void updateLastModemActivityInfo(ModemActivityInfo info, int rat) { |
| 8604 | int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()]; |
| 8605 | int[] txTimeMs = info.getTransmitTimeMillis(rat); |
| 8606 | int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat); |
| 8607 | |
| 8608 | for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) { |
| 8609 | mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl]; |
| 8610 | } |
| 8611 | mLastModemActivityInfo.setTransmitTimeMillis(rat, mergedTxTimeMs); |
| 8612 | mLastModemActivityInfo.setReceiveTimeMillis( |
| 8613 | rat, |
| 8614 | info.getReceiveTimeMillis(rat) + mLastModemActivityInfo.getReceiveTimeMillis(rat)); |
| 8615 | } |
| 8616 | |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 8617 | /** |
| 8618 | * Merge this ModemActivityInfo with mLastModemActivitySpecificInfo |
| 8619 | * @param info recent ModemActivityInfo |
| 8620 | */ |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8621 | private void mergeModemActivityInfo(ModemActivityInfo info) { |
| 8622 | List<ActivityStatsTechSpecificInfo> merged = new ArrayList<>(); |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 8623 | ActivityStatsTechSpecificInfo deltaSpecificInfo; |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8624 | boolean matched; |
| 8625 | for (int i = 0; i < info.getSpecificInfoLength(); i++) { |
| 8626 | matched = false; |
| 8627 | int rat = info.getSpecificInfoRat(i); |
| 8628 | int freq = info.getSpecificInfoFrequencyRange(i); |
| 8629 | //Check each ActivityStatsTechSpecificInfo in this ModemActivityInfo for new rat returns |
| 8630 | //Add a new ActivityStatsTechSpecificInfo if is a new rat, and merge with the original |
| 8631 | //if it already exists |
| 8632 | for (int j = 0; j < mLastModemActivitySpecificInfo.length; j++) { |
| 8633 | if (rat == mLastModemActivityInfo.getSpecificInfoRat(j) && !matched) { |
| 8634 | //Merged based on frequency range (MMWAVE vs SUB6) for 5G |
| 8635 | if (rat == AccessNetworkConstants.AccessNetworkType.NGRAN) { |
| 8636 | if (freq == mLastModemActivityInfo.getSpecificInfoFrequencyRange(j)) { |
| 8637 | updateLastModemActivityInfo(info, rat, freq); |
| 8638 | matched = true; |
| 8639 | } |
| 8640 | } else { |
| 8641 | updateLastModemActivityInfo(info, rat); |
| 8642 | matched = true; |
| 8643 | } |
| 8644 | } |
| 8645 | } |
| 8646 | |
| 8647 | if (!matched) { |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 8648 | deltaSpecificInfo = |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8649 | new ActivityStatsTechSpecificInfo( |
| 8650 | rat, |
| 8651 | freq, |
| 8652 | info.getTransmitTimeMillis(rat, freq), |
| 8653 | (int) info.getReceiveTimeMillis(rat, freq)); |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 8654 | merged.addAll(Arrays.asList(deltaSpecificInfo)); |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8655 | } |
| 8656 | } |
| 8657 | merged.addAll(Arrays.asList(mLastModemActivitySpecificInfo)); |
| 8658 | mLastModemActivitySpecificInfo = |
| 8659 | new ActivityStatsTechSpecificInfo[merged.size()]; |
| 8660 | merged.toArray(mLastModemActivitySpecificInfo); |
| 8661 | |
| 8662 | mLastModemActivityInfo.setTimestamp(info.getTimestampMillis()); |
| 8663 | mLastModemActivityInfo.setSleepTimeMillis( |
| 8664 | info.getSleepTimeMillis() |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 8665 | + mLastModemActivityInfo.getSleepTimeMillis()); |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8666 | mLastModemActivityInfo.setIdleTimeMillis( |
| 8667 | info.getIdleTimeMillis() |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 8668 | + mLastModemActivityInfo.getIdleTimeMillis()); |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 8669 | |
| 8670 | mLastModemActivityInfo = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 8671 | new ModemActivityInfo( |
| 8672 | mLastModemActivityInfo.getTimestampMillis(), |
| 8673 | mLastModemActivityInfo.getSleepTimeMillis(), |
| 8674 | mLastModemActivityInfo.getIdleTimeMillis(), |
| 8675 | mLastModemActivitySpecificInfo); |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 8676 | } |
| 8677 | |
| 8678 | private ActivityStatsTechSpecificInfo[] deepCopyModemActivitySpecificInfo( |
| 8679 | ActivityStatsTechSpecificInfo[] info) { |
| 8680 | int infoSize = info.length; |
| 8681 | ActivityStatsTechSpecificInfo[] ret = new ActivityStatsTechSpecificInfo[infoSize]; |
| 8682 | for (int i = 0; i < infoSize; i++) { |
| 8683 | ret[i] = new ActivityStatsTechSpecificInfo( |
| 8684 | info[i].getRat(), info[i].getFrequencyRange(), |
| 8685 | info[i].getTransmitTimeMillis(), |
| 8686 | (int) info[i].getReceiveTimeMillis()); |
| 8687 | } |
| 8688 | return ret; |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8689 | } |
| 8690 | |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8691 | /** |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8692 | * Returns the service state information on specified subscription. |
| 8693 | */ |
| 8694 | @Override |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 8695 | public ServiceState getServiceStateForSubscriber(int subId, |
| 8696 | boolean renounceFineLocationAccess, boolean renounceCoarseLocationAccess, |
| 8697 | String callingPackage, String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8698 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8699 | mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) { |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8700 | return null; |
| 8701 | } |
| 8702 | |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 8703 | boolean hasFinePermission = false; |
| 8704 | boolean hasCoarsePermission = false; |
| 8705 | if (!renounceFineLocationAccess) { |
| 8706 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 8707 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 8708 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 8709 | .setCallingPackage(callingPackage) |
| 8710 | .setCallingFeatureId(callingFeatureId) |
| 8711 | .setCallingPid(Binder.getCallingPid()) |
| 8712 | .setCallingUid(Binder.getCallingUid()) |
| 8713 | .setMethod("getServiceStateForSubscriber") |
| 8714 | .setLogAsInfo(true) |
| 8715 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 8716 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 8717 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 8718 | .build()); |
| 8719 | hasFinePermission = |
| 8720 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 8721 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 8722 | |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 8723 | if (!renounceCoarseLocationAccess) { |
| 8724 | LocationAccessPolicy.LocationPermissionResult coarseLocationResult = |
| 8725 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 8726 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 8727 | .setCallingPackage(callingPackage) |
| 8728 | .setCallingFeatureId(callingFeatureId) |
| 8729 | .setCallingPid(Binder.getCallingPid()) |
| 8730 | .setCallingUid(Binder.getCallingUid()) |
| 8731 | .setMethod("getServiceStateForSubscriber") |
| 8732 | .setLogAsInfo(true) |
| 8733 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 8734 | .setMinSdkVersionForFine(Integer.MAX_VALUE) |
| 8735 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 8736 | .build()); |
| 8737 | hasCoarsePermission = |
| 8738 | coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 8739 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 8740 | |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 8741 | final Phone phone = getPhone(subId); |
| 8742 | if (phone == null) { |
| 8743 | return null; |
| 8744 | } |
| 8745 | |
Jordan Liu | 0f2bc44 | 2020-11-18 16:47:37 -0800 | [diff] [blame] | 8746 | final long identity = Binder.clearCallingIdentity(); |
| 8747 | |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 8748 | boolean isCallingPackageDataService = phone.getDataServicePackages() |
| 8749 | .contains(callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8750 | try { |
Jordan Liu | c437b19 | 2020-08-17 10:59:12 -0700 | [diff] [blame] | 8751 | // isActiveSubId requires READ_PHONE_STATE, which we already check for above |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 8752 | if (PhoneFactory.isSubscriptionManagerServiceEnabled()) { |
Jack Yu | fa8ed01 | 2023-02-11 15:42:28 -0800 | [diff] [blame] | 8753 | SubscriptionInfoInternal subInfo = getSubscriptionManagerService() |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 8754 | .getSubscriptionInfoInternal(subId); |
| 8755 | if (subInfo == null || !subInfo.isActive()) { |
| 8756 | Rlog.d(LOG_TAG, "getServiceStateForSubscriber returning null for inactive " |
| 8757 | + "subId=" + subId); |
| 8758 | return null; |
| 8759 | } |
| 8760 | } else { |
| 8761 | if (!mSubscriptionController.isActiveSubId(subId, callingPackage, |
| 8762 | callingFeatureId)) { |
| 8763 | Rlog.d(LOG_TAG, "getServiceStateForSubscriber returning null for inactive " |
| 8764 | + "subId=" + subId); |
| 8765 | return null; |
| 8766 | } |
Jordan Liu | c437b19 | 2020-08-17 10:59:12 -0700 | [diff] [blame] | 8767 | } |
| 8768 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 8769 | ServiceState ss = phone.getServiceState(); |
| 8770 | |
| 8771 | // Scrub out the location info in ServiceState depending on what level of access |
| 8772 | // the caller has. |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 8773 | if (hasFinePermission || isCallingPackageDataService) return ss; |
Malcolm Chen | 5052de6 | 2019-12-30 13:56:38 -0800 | [diff] [blame] | 8774 | if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false); |
| 8775 | return ss.createLocationInfoSanitizedCopy(true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8776 | } finally { |
| 8777 | Binder.restoreCallingIdentity(identity); |
| 8778 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8779 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8780 | |
| 8781 | /** |
| 8782 | * Returns the URI for the per-account voicemail ringtone set in Phone settings. |
| 8783 | * |
| 8784 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 8785 | * voicemail ringtone. |
| 8786 | * @return The URI for the ringtone to play when receiving a voicemail from a specific |
| 8787 | * PhoneAccount. |
| 8788 | */ |
| 8789 | @Override |
| 8790 | public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8791 | final long identity = Binder.clearCallingIdentity(); |
| 8792 | try { |
| 8793 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 8794 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8795 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8796 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8797 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8798 | return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext()); |
| 8799 | } finally { |
| 8800 | Binder.restoreCallingIdentity(identity); |
| 8801 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8802 | } |
| 8803 | |
| 8804 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8805 | * Sets the per-account voicemail ringtone. |
| 8806 | * |
| 8807 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 8808 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 8809 | * |
| 8810 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 8811 | * voicemail ringtone. |
| 8812 | * @param uri The URI for the ringtone to play when receiving a voicemail from a specific |
| 8813 | * PhoneAccount. |
| 8814 | */ |
| 8815 | @Override |
| 8816 | public void setVoicemailRingtoneUri(String callingPackage, |
| 8817 | PhoneAccountHandle phoneAccountHandle, Uri uri) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8818 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8819 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 8820 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 8821 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8822 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8823 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 8824 | "setVoicemailRingtoneUri"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8825 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8826 | |
| 8827 | final long identity = Binder.clearCallingIdentity(); |
| 8828 | try { |
| 8829 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 8830 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8831 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8832 | } |
| 8833 | VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri); |
| 8834 | } finally { |
| 8835 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8836 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8837 | } |
| 8838 | |
| 8839 | /** |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8840 | * Returns whether vibration is set for voicemail notification in Phone settings. |
| 8841 | * |
| 8842 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 8843 | * voicemail vibration setting. |
| 8844 | * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise. |
| 8845 | */ |
| 8846 | @Override |
| 8847 | public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8848 | final long identity = Binder.clearCallingIdentity(); |
| 8849 | try { |
| 8850 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 8851 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8852 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8853 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8854 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8855 | return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext()); |
| 8856 | } finally { |
| 8857 | Binder.restoreCallingIdentity(identity); |
| 8858 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8859 | } |
| 8860 | |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8861 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8862 | * Sets the per-account voicemail vibration. |
| 8863 | * |
| 8864 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 8865 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 8866 | * |
| 8867 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 8868 | * voicemail vibration setting. |
| 8869 | * @param enabled Whether to enable or disable vibration for voicemail notifications from a |
| 8870 | * specific PhoneAccount. |
| 8871 | */ |
| 8872 | @Override |
| 8873 | public void setVoicemailVibrationEnabled(String callingPackage, |
| 8874 | PhoneAccountHandle phoneAccountHandle, boolean enabled) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8875 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8876 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 8877 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 8878 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8879 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8880 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 8881 | "setVoicemailVibrationEnabled"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8882 | } |
| 8883 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8884 | final long identity = Binder.clearCallingIdentity(); |
| 8885 | try { |
| 8886 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 8887 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8888 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8889 | } |
| 8890 | VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled); |
| 8891 | } finally { |
| 8892 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8893 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8894 | } |
| 8895 | |
| 8896 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8897 | * Make sure either called from same process as self (phone) or IPC caller has read privilege. |
| 8898 | * |
| 8899 | * @throws SecurityException if the caller does not have the required permission |
| 8900 | */ |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 8901 | @VisibleForTesting |
| 8902 | public void enforceReadPrivilegedPermission(String message) { |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8903 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8904 | message); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8905 | } |
| 8906 | |
| 8907 | /** |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 8908 | * Make sure either called from same process as self (phone) or IPC caller has send SMS |
| 8909 | * permission. |
| 8910 | * |
| 8911 | * @throws SecurityException if the caller does not have the required permission |
| 8912 | */ |
| 8913 | private void enforceSendSmsPermission() { |
| 8914 | mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null); |
| 8915 | } |
| 8916 | |
| 8917 | /** |
Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame] | 8918 | * Make sure either called from same process as self (phone) or IPC caller has interact across |
| 8919 | * users permission. |
| 8920 | * |
| 8921 | * @throws SecurityException if the caller does not have the required permission |
| 8922 | */ |
| 8923 | private void enforceInteractAcrossUsersPermission(String message) { |
| 8924 | mApp.enforceCallingOrSelfPermission(permission.INTERACT_ACROSS_USERS, message); |
| 8925 | } |
| 8926 | |
| 8927 | /** |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 8928 | * Make sure called from the package in charge of visual voicemail. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 8929 | * |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 8930 | * @throws SecurityException if the caller is not the visual voicemail package. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 8931 | */ |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 8932 | private void enforceVisualVoicemailPackage(String callingPackage, int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8933 | final long identity = Binder.clearCallingIdentity(); |
| 8934 | try { |
| 8935 | ComponentName componentName = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8936 | RemoteVvmTaskManager.getRemotePackage(mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8937 | if (componentName == null) { |
| 8938 | throw new SecurityException( |
| 8939 | "Caller not current active visual voicemail package[null]"); |
| 8940 | } |
| 8941 | String vvmPackage = componentName.getPackageName(); |
| 8942 | if (!callingPackage.equals(vvmPackage)) { |
Hui Wang | 7f65755 | 2022-08-16 16:58:25 +0000 | [diff] [blame] | 8943 | throw new SecurityException("Caller not current active visual voicemail package"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8944 | } |
| 8945 | } finally { |
| 8946 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 8947 | } |
| 8948 | } |
| 8949 | |
| 8950 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8951 | * Return the application ID for the app type. |
| 8952 | * |
| 8953 | * @param subId the subscription ID that this request applies to. |
| 8954 | * @param appType the uicc app type. |
| 8955 | * @return Application ID for specificied app type, or null if no uicc. |
| 8956 | */ |
| 8957 | @Override |
| 8958 | public String getAidForAppType(int subId, int appType) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8959 | enforceReadPrivilegedPermission("getAidForAppType"); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8960 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8961 | |
| 8962 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8963 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8964 | if (phone == null) { |
| 8965 | return null; |
| 8966 | } |
| 8967 | String aid = null; |
| 8968 | try { |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 8969 | aid = UiccController.getInstance().getUiccPort(phone.getPhoneId()) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8970 | .getApplicationByType(appType).getAid(); |
| 8971 | } catch (Exception e) { |
| 8972 | Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e); |
| 8973 | } |
| 8974 | return aid; |
| 8975 | } finally { |
| 8976 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8977 | } |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8978 | } |
| 8979 | |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8980 | /** |
| 8981 | * Return the Electronic Serial Number. |
| 8982 | * |
| 8983 | * @param subId the subscription ID that this request applies to. |
| 8984 | * @return ESN or null if error. |
| 8985 | */ |
| 8986 | @Override |
| 8987 | public String getEsn(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8988 | enforceReadPrivilegedPermission("getEsn"); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8989 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8990 | |
| 8991 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8992 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8993 | if (phone == null) { |
| 8994 | return null; |
| 8995 | } |
| 8996 | String esn = null; |
| 8997 | try { |
| 8998 | esn = phone.getEsn(); |
| 8999 | } catch (Exception e) { |
| 9000 | Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e); |
| 9001 | } |
| 9002 | return esn; |
| 9003 | } finally { |
| 9004 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 9005 | } |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 9006 | } |
| 9007 | |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 9008 | /** |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 9009 | * Return the Preferred Roaming List Version. |
| 9010 | * |
| 9011 | * @param subId the subscription ID that this request applies to. |
| 9012 | * @return PRLVersion or null if error. |
| 9013 | */ |
| 9014 | @Override |
| 9015 | public String getCdmaPrlVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 9016 | enforceReadPrivilegedPermission("getCdmaPrlVersion"); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 9017 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9018 | |
| 9019 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 9020 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9021 | if (phone == null) { |
| 9022 | return null; |
| 9023 | } |
| 9024 | String cdmaPrlVersion = null; |
| 9025 | try { |
| 9026 | cdmaPrlVersion = phone.getCdmaPrlVersion(); |
| 9027 | } catch (Exception e) { |
| 9028 | Log.e(LOG_TAG, "Not getting PRLVersion", e); |
| 9029 | } |
| 9030 | return cdmaPrlVersion; |
| 9031 | } finally { |
| 9032 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 9033 | } |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 9034 | } |
| 9035 | |
| 9036 | /** |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 9037 | * Get snapshot of Telephony histograms |
| 9038 | * @return List of Telephony histograms |
| 9039 | * @hide |
| 9040 | */ |
| 9041 | @Override |
| 9042 | public List<TelephonyHistogram> getTelephonyHistograms() { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 9043 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9044 | mApp, getDefaultSubscription(), "getTelephonyHistograms"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9045 | |
| 9046 | final long identity = Binder.clearCallingIdentity(); |
| 9047 | try { |
| 9048 | return RIL.getTelephonyRILTimingHistograms(); |
| 9049 | } finally { |
| 9050 | Binder.restoreCallingIdentity(identity); |
| 9051 | } |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 9052 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 9053 | |
| 9054 | /** |
| 9055 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 9056 | * Set the allowed carrier list and the excluded carrier list, indicating the priority between |
| 9057 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 9058 | * Require system privileges. In the future we may add this to carrier APIs. |
| 9059 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 9060 | * @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] | 9061 | */ |
| 9062 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 9063 | @TelephonyManager.SetCarrierRestrictionResult |
| 9064 | public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) { |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 9065 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 9066 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 9067 | |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 9068 | if (carrierRestrictionRules == null) { |
| 9069 | throw new NullPointerException("carrier restriction cannot be null"); |
Meng Wang | 9b7c4e9 | 2017-02-17 11:41:27 -0800 | [diff] [blame] | 9070 | } |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 9071 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9072 | final long identity = Binder.clearCallingIdentity(); |
| 9073 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 9074 | return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 9075 | workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9076 | } finally { |
| 9077 | Binder.restoreCallingIdentity(identity); |
| 9078 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 9079 | } |
| 9080 | |
| 9081 | /** |
| 9082 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 9083 | * Get the allowed carrier list and the excluded carrier list, including the priority between |
| 9084 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 9085 | * Require system privileges. In the future we may add this to carrier APIs. |
| 9086 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 9087 | * @return {@link android.telephony.CarrierRestrictionRules} |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 9088 | */ |
| 9089 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 9090 | public CarrierRestrictionRules getAllowedCarriers() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 9091 | enforceReadPrivilegedPermission("getAllowedCarriers"); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 9092 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9093 | |
| 9094 | final long identity = Binder.clearCallingIdentity(); |
| 9095 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 9096 | Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource); |
| 9097 | if (response instanceof CarrierRestrictionRules) { |
| 9098 | return (CarrierRestrictionRules) response; |
| 9099 | } |
| 9100 | // Response is an Exception of some kind, |
| 9101 | // which is signalled to the user as a NULL retval |
| 9102 | return null; |
| 9103 | } catch (Exception e) { |
| 9104 | Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e); |
| 9105 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9106 | } finally { |
| 9107 | Binder.restoreCallingIdentity(identity); |
| 9108 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 9109 | } |
| 9110 | |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 9111 | /** |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 9112 | * Fetches the carrier restriction status of the device and sends the status to the caller |
| 9113 | * through the callback. |
| 9114 | * |
| 9115 | * @param callback The callback that will be used to send the result. |
| 9116 | * @throws SecurityException if the caller does not have the required permission/privileges or |
| 9117 | * the caller is not allowlisted. |
| 9118 | */ |
| 9119 | @Override |
| 9120 | public void getCarrierRestrictionStatus(IIntegerConsumer callback, String packageName) { |
| 9121 | enforceReadPermission("getCarrierRestrictionStatus"); |
| 9122 | int carrierId = validateCallerAndGetCarrierId(packageName); |
| 9123 | if (carrierId == CarrierAllowListInfo.INVALID_CARRIER_ID) { |
| 9124 | Rlog.e(LOG_TAG, "getCarrierRestrictionStatus: caller is not registered"); |
| 9125 | throw new SecurityException("Not an authorized caller"); |
| 9126 | } |
| 9127 | final long identity = Binder.clearCallingIdentity(); |
| 9128 | try { |
| 9129 | Consumer<Integer> consumer = FunctionalUtils.ignoreRemoteException(callback::accept); |
| 9130 | CallerCallbackInfo callbackInfo = new CallerCallbackInfo(consumer, carrierId); |
| 9131 | sendRequestAsync(CMD_GET_ALLOWED_CARRIERS, callbackInfo); |
| 9132 | } finally { |
| 9133 | Binder.restoreCallingIdentity(identity); |
| 9134 | } |
| 9135 | } |
| 9136 | |
| 9137 | @VisibleForTesting |
| 9138 | public int validateCallerAndGetCarrierId(String packageName) { |
| 9139 | CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp); |
| 9140 | return allowListInfo.validateCallerAndGetCarrierId(packageName); |
| 9141 | } |
| 9142 | |
| 9143 | /** |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 9144 | * Action set from carrier signalling broadcast receivers to enable/disable radio |
| 9145 | * @param subId the subscription ID that this action applies to. |
| 9146 | * @param enabled control enable or disable radio. |
| 9147 | * {@hide} |
| 9148 | */ |
| 9149 | @Override |
| 9150 | public void carrierActionSetRadioEnabled(int subId, boolean enabled) { |
| 9151 | enforceModifyPermission(); |
| 9152 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9153 | |
| 9154 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 9155 | if (phone == null) { |
| 9156 | loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId); |
| 9157 | return; |
| 9158 | } |
| 9159 | try { |
| 9160 | phone.carrierActionSetRadioEnabled(enabled); |
| 9161 | } catch (Exception e) { |
| 9162 | Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9163 | } finally { |
| 9164 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 9165 | } |
| 9166 | } |
| 9167 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 9168 | /** |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 9169 | * Enable or disable Voice over NR (VoNR) |
| 9170 | * @param subId the subscription ID that this action applies to. |
| 9171 | * @param enabled enable or disable VoNR. |
| 9172 | * @return operation result. |
| 9173 | */ |
| 9174 | @Override |
| 9175 | public int setVoNrEnabled(int subId, boolean enabled) { |
| 9176 | enforceModifyPermission(); |
| 9177 | final Phone phone = getPhone(subId); |
| 9178 | |
| 9179 | final long identity = Binder.clearCallingIdentity(); |
| 9180 | if (phone == null) { |
| 9181 | loge("setVoNrEnabled fails with no phone object for subId: " + subId); |
| 9182 | return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE; |
| 9183 | } |
| 9184 | |
| 9185 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 9186 | try { |
| 9187 | int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId, |
| 9188 | workSource); |
| 9189 | if (DBG) log("setVoNrEnabled result: " + result); |
Gary Jian | 8dd305f | 2021-10-14 16:31:35 +0800 | [diff] [blame] | 9190 | |
| 9191 | if (result == TelephonyManager.ENABLE_VONR_SUCCESS) { |
| 9192 | if (DBG) { |
| 9193 | log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled); |
| 9194 | } |
| 9195 | SubscriptionManager.setSubscriptionProperty( |
| 9196 | subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED, |
| 9197 | (enabled ? "1" : "0")); |
| 9198 | } |
| 9199 | |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 9200 | return result; |
| 9201 | } finally { |
| 9202 | Binder.restoreCallingIdentity(identity); |
| 9203 | } |
| 9204 | } |
| 9205 | |
| 9206 | /** |
| 9207 | * Is voice over NR enabled |
| 9208 | * @return true if VoNR is enabled else false |
| 9209 | */ |
| 9210 | @Override |
| 9211 | public boolean isVoNrEnabled(int subId) { |
| 9212 | enforceReadPrivilegedPermission("isVoNrEnabled"); |
| 9213 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 9214 | final long identity = Binder.clearCallingIdentity(); |
| 9215 | try { |
| 9216 | boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED, |
| 9217 | null, subId, workSource); |
| 9218 | if (DBG) log("isVoNrEnabled: " + isEnabled); |
| 9219 | return isEnabled; |
| 9220 | } finally { |
| 9221 | Binder.restoreCallingIdentity(identity); |
| 9222 | } |
| 9223 | } |
| 9224 | |
| 9225 | /** |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 9226 | * Action set from carrier signalling broadcast receivers to start/stop reporting the default |
| 9227 | * network status based on which carrier apps could apply actions accordingly, |
| 9228 | * enable/disable default url handler for example. |
| 9229 | * |
| 9230 | * @param subId the subscription ID that this action applies to. |
| 9231 | * @param report control start/stop reporting the default network status. |
| 9232 | * {@hide} |
| 9233 | */ |
| 9234 | @Override |
| 9235 | public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) { |
| 9236 | enforceModifyPermission(); |
| 9237 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9238 | |
| 9239 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 9240 | if (phone == null) { |
| 9241 | loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId); |
| 9242 | return; |
| 9243 | } |
| 9244 | try { |
| 9245 | phone.carrierActionReportDefaultNetworkStatus(report); |
| 9246 | } catch (Exception e) { |
| 9247 | Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9248 | } finally { |
| 9249 | Binder.restoreCallingIdentity(identity); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 9250 | } |
| 9251 | } |
| 9252 | |
| 9253 | /** |
fionaxu | d962228 | 2017-07-17 17:51:30 -0700 | [diff] [blame] | 9254 | * Action set from carrier signalling broadcast receivers to reset all carrier actions |
| 9255 | * @param subId the subscription ID that this action applies to. |
| 9256 | * {@hide} |
| 9257 | */ |
| 9258 | @Override |
| 9259 | public void carrierActionResetAll(int subId) { |
| 9260 | enforceModifyPermission(); |
| 9261 | final Phone phone = getPhone(subId); |
| 9262 | if (phone == null) { |
| 9263 | loge("carrierAction: ResetAll fails with invalid sibId: " + subId); |
| 9264 | return; |
| 9265 | } |
| 9266 | try { |
| 9267 | phone.carrierActionResetAll(); |
| 9268 | } catch (Exception e) { |
| 9269 | Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e); |
| 9270 | } |
| 9271 | } |
| 9272 | |
| 9273 | /** |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 9274 | * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a |
| 9275 | * bug report is being generated. |
| 9276 | */ |
| 9277 | @Override |
Ta-wei Yen | 99282e0 | 2016-06-21 18:19:35 -0700 | [diff] [blame] | 9278 | protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9279 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 9280 | != PackageManager.PERMISSION_GRANTED) { |
dcashman | 22b950d | 2016-06-27 11:39:02 -0700 | [diff] [blame] | 9281 | writer.println("Permission Denial: can't dump Phone from pid=" |
| 9282 | + Binder.getCallingPid() |
| 9283 | + ", uid=" + Binder.getCallingUid() |
| 9284 | + "without permission " |
| 9285 | + android.Manifest.permission.DUMP); |
| 9286 | return; |
| 9287 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9288 | DumpsysHandler.dump(mApp, fd, writer, args); |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 9289 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 9290 | |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 9291 | @Override |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 9292 | public int handleShellCommand(@NonNull ParcelFileDescriptor in, |
| 9293 | @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err, |
| 9294 | @NonNull String[] args) { |
| 9295 | return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec( |
| 9296 | this, in.getFileDescriptor(), out.getFileDescriptor(), |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 9297 | err.getFileDescriptor(), args); |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 9298 | } |
| 9299 | |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 9300 | /** |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 9301 | * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason} |
Greg Kaiser | 17f4175 | 2020-05-05 16:47:47 +0000 | [diff] [blame] | 9302 | * @param subId Subscription index |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 9303 | * @param reason The reason the data enable change is taking place. |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 9304 | * @param enabled True if enabling the data, otherwise disabling. |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 9305 | * @param callingPackage The package that changed the data enabled state. |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 9306 | * @hide |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 9307 | */ |
| 9308 | @Override |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 9309 | public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 9310 | boolean enabled, String callingPackage) { |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 9311 | if (reason == TelephonyManager.DATA_ENABLED_REASON_USER |
| 9312 | || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 9313 | try { |
| 9314 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 9315 | mApp, subId, "setDataEnabledForReason"); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 9316 | } catch (SecurityException se) { |
| 9317 | enforceModifyPermission(); |
| 9318 | } |
| 9319 | } else { |
| 9320 | enforceModifyPermission(); |
| 9321 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9322 | |
| 9323 | final long identity = Binder.clearCallingIdentity(); |
| 9324 | try { |
| 9325 | Phone phone = getPhone(subId); |
| 9326 | if (phone != null) { |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 9327 | if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 9328 | phone.carrierActionSetMeteredApnsEnabled(enabled); |
| 9329 | } else { |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 9330 | phone.getDataSettingsManager().setDataEnabled( |
| 9331 | reason, enabled, callingPackage); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 9332 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9333 | } |
| 9334 | } finally { |
| 9335 | Binder.restoreCallingIdentity(identity); |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 9336 | } |
| 9337 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 9338 | |
| 9339 | /** |
| 9340 | * Get Client request stats |
| 9341 | * @return List of Client Request Stats |
| 9342 | * @hide |
| 9343 | */ |
| 9344 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9345 | public List<ClientRequestStats> getClientRequestStats(String callingPackage, |
| 9346 | String callingFeatureId, int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 9347 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9348 | mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) { |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 9349 | return null; |
| 9350 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 9351 | Phone phone = getPhone(subId); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 9352 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9353 | final long identity = Binder.clearCallingIdentity(); |
| 9354 | try { |
| 9355 | if (phone != null) { |
| 9356 | return phone.getClientRequestStats(); |
| 9357 | } |
| 9358 | |
| 9359 | return null; |
| 9360 | } finally { |
| 9361 | Binder.restoreCallingIdentity(identity); |
| 9362 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 9363 | } |
| 9364 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 9365 | private WorkSource getWorkSource(int uid) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9366 | String packageName = mApp.getPackageManager().getNameForUid(uid); |
Hunter Knepshield | d03383b | 2022-03-29 22:47:54 +0000 | [diff] [blame] | 9367 | if (uid == Process.ROOT_UID && packageName == null) { |
| 9368 | // Downstream WorkSource attribution inside the RIL requires both a UID and package name |
| 9369 | // to be set for wakelock tracking, otherwise RIL requests fail with a runtime |
| 9370 | // exception. ROOT_UID seems not to have a valid package name returned by |
| 9371 | // PackageManager, so just fake it here to avoid issues when running telephony shell |
| 9372 | // commands that plumb through the RIL as root, like so: |
| 9373 | // $ adb root |
| 9374 | // $ adb shell cmd phone ... |
| 9375 | packageName = "root"; |
| 9376 | } |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 9377 | return new WorkSource(uid, packageName); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 9378 | } |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 9379 | |
| 9380 | /** |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 9381 | * Set SIM card power state. |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 9382 | * |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 9383 | * @param slotIndex SIM slot id. |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 9384 | * @param state State of SIM (power down, power up, pass through) |
| 9385 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 9386 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 9387 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 9388 | * |
| 9389 | **/ |
| 9390 | @Override |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 9391 | public void setSimPowerStateForSlot(int slotIndex, int state) { |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 9392 | enforceModifyPermission(); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 9393 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 9394 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 9395 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 9396 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9397 | final long identity = Binder.clearCallingIdentity(); |
| 9398 | try { |
| 9399 | if (phone != null) { |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 9400 | phone.setSimPowerState(state, null, workSource); |
| 9401 | } |
| 9402 | } finally { |
| 9403 | Binder.restoreCallingIdentity(identity); |
| 9404 | } |
| 9405 | } |
| 9406 | |
| 9407 | /** |
| 9408 | * Set SIM card power state. |
| 9409 | * |
| 9410 | * @param slotIndex SIM slot id. |
| 9411 | * @param state State of SIM (power down, power up, pass through) |
| 9412 | * @param callback callback to trigger after success or failure |
| 9413 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 9414 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 9415 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
| 9416 | * |
| 9417 | **/ |
| 9418 | @Override |
| 9419 | public void setSimPowerStateForSlotWithCallback(int slotIndex, int state, |
| 9420 | IIntegerConsumer callback) { |
| 9421 | enforceModifyPermission(); |
| 9422 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 9423 | |
| 9424 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 9425 | |
| 9426 | final long identity = Binder.clearCallingIdentity(); |
| 9427 | try { |
| 9428 | if (phone != null) { |
| 9429 | Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback); |
| 9430 | sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9431 | } |
| 9432 | } finally { |
| 9433 | Binder.restoreCallingIdentity(identity); |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 9434 | } |
| 9435 | } |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 9436 | |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 9437 | private boolean isUssdApiAllowed(int subId) { |
| 9438 | CarrierConfigManager configManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9439 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 9440 | if (configManager == null) { |
| 9441 | return false; |
| 9442 | } |
| 9443 | PersistableBundle pb = configManager.getConfigForSubId(subId); |
| 9444 | if (pb == null) { |
| 9445 | return false; |
| 9446 | } |
| 9447 | return pb.getBoolean( |
| 9448 | CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL); |
| 9449 | } |
| 9450 | |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 9451 | /** |
| 9452 | * Check if phone is in emergency callback mode |
| 9453 | * @return true if phone is in emergency callback mode |
| 9454 | * @param subId sub id |
| 9455 | */ |
goneil | 9c5f487 | 2017-12-05 14:07:56 -0800 | [diff] [blame] | 9456 | @Override |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 9457 | public boolean getEmergencyCallbackMode(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 9458 | enforceReadPrivilegedPermission("getEmergencyCallbackMode"); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 9459 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9460 | |
| 9461 | final long identity = Binder.clearCallingIdentity(); |
| 9462 | try { |
| 9463 | if (phone != null) { |
| 9464 | return phone.isInEcm(); |
| 9465 | } else { |
| 9466 | return false; |
| 9467 | } |
| 9468 | } finally { |
| 9469 | Binder.restoreCallingIdentity(identity); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 9470 | } |
| 9471 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 9472 | |
| 9473 | /** |
| 9474 | * Get the current signal strength information for the given subscription. |
| 9475 | * Because this information is not updated when the device is in a low power state |
| 9476 | * it should not be relied-upon to be current. |
| 9477 | * @param subId Subscription index |
| 9478 | * @return the most recent cached signal strength info from the modem |
| 9479 | */ |
| 9480 | @Override |
| 9481 | public SignalStrength getSignalStrength(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9482 | final long identity = Binder.clearCallingIdentity(); |
| 9483 | try { |
| 9484 | Phone p = getPhone(subId); |
| 9485 | if (p == null) { |
| 9486 | return null; |
| 9487 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 9488 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9489 | return p.getSignalStrength(); |
| 9490 | } finally { |
| 9491 | Binder.restoreCallingIdentity(identity); |
| 9492 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 9493 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9494 | |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9495 | /** |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 9496 | * Get the current modem radio state for the given slot. |
| 9497 | * @param slotIndex slot index. |
| 9498 | * @param callingPackage the name of the package making the call. |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9499 | * @param callingFeatureId The feature in the package. |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 9500 | * @return the current radio power state from the modem |
| 9501 | */ |
| 9502 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9503 | public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 9504 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 9505 | if (phone != null) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9506 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(), |
| 9507 | callingPackage, callingFeatureId, "getRadioPowerState")) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 9508 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 9509 | } |
| 9510 | |
| 9511 | final long identity = Binder.clearCallingIdentity(); |
| 9512 | try { |
| 9513 | return phone.getRadioPowerState(); |
| 9514 | } finally { |
| 9515 | Binder.restoreCallingIdentity(identity); |
| 9516 | } |
| 9517 | } |
| 9518 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 9519 | } |
| 9520 | |
| 9521 | /** |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9522 | * Checks if data roaming is enabled on the subscription with id {@code subId}. |
| 9523 | * |
| 9524 | * <p>Requires one of the following permissions: |
| 9525 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}, |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 9526 | * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE}, |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9527 | * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier |
| 9528 | * privileges. |
| 9529 | * |
| 9530 | * @param subId subscription id |
| 9531 | * @return {@code true} if data roaming is enabled on this subscription, otherwise return |
| 9532 | * {@code false}. |
| 9533 | */ |
| 9534 | @Override |
| 9535 | public boolean isDataRoamingEnabled(int subId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 9536 | String functionName = "isDataRoamingEnabled"; |
Shuo Qian | 093013d | 2020-08-13 15:42:55 -0700 | [diff] [blame] | 9537 | try { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 9538 | try { |
| 9539 | mApp.enforceCallingOrSelfPermission( |
| 9540 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 9541 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 9542 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 9543 | mApp.enforceCallingOrSelfPermission( |
| 9544 | permission.READ_BASIC_PHONE_STATE, functionName); |
| 9545 | } |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 9546 | } catch (SecurityException e) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9547 | TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 9548 | mApp, subId, functionName); |
Shuo Qian | 093013d | 2020-08-13 15:42:55 -0700 | [diff] [blame] | 9549 | } |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 9550 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9551 | boolean isEnabled = false; |
| 9552 | final long identity = Binder.clearCallingIdentity(); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9553 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9554 | Phone phone = getPhone(subId); |
| 9555 | isEnabled = phone != null ? phone.getDataRoamingEnabled() : false; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9556 | } finally { |
| 9557 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9558 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9559 | return isEnabled; |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9560 | } |
| 9561 | |
| 9562 | |
| 9563 | /** |
| 9564 | * Enables/Disables the data roaming on the subscription with id {@code subId}. |
| 9565 | * |
| 9566 | * <p> Requires permission: |
| 9567 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier |
| 9568 | * privileges. |
| 9569 | * |
| 9570 | * @param subId subscription id |
| 9571 | * @param isEnabled {@code true} means enable, {@code false} means disable. |
| 9572 | */ |
| 9573 | @Override |
| 9574 | public void setDataRoamingEnabled(int subId, boolean isEnabled) { |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 9575 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9576 | mApp, subId, "setDataRoamingEnabled"); |
| 9577 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9578 | final long identity = Binder.clearCallingIdentity(); |
| 9579 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9580 | Phone phone = getPhone(subId); |
| 9581 | if (phone != null) { |
| 9582 | phone.setDataRoamingEnabled(isEnabled); |
| 9583 | } |
| 9584 | } finally { |
| 9585 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9586 | } |
| 9587 | } |
| 9588 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9589 | @Override |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 9590 | public boolean isManualNetworkSelectionAllowed(int subId) { |
tom hsu | c91afc7 | 2020-01-06 23:46:07 +0800 | [diff] [blame] | 9591 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9592 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 9593 | mApp, subId, "isManualNetworkSelectionAllowed"); |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 9594 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 9595 | boolean isAllowed = true; |
| 9596 | final long identity = Binder.clearCallingIdentity(); |
| 9597 | try { |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 9598 | Phone phone = getPhone(subId); |
| 9599 | if (phone != null) { |
| 9600 | isAllowed = phone.isCspPlmnEnabled(); |
| 9601 | } |
| 9602 | } finally { |
| 9603 | Binder.restoreCallingIdentity(identity); |
| 9604 | } |
| 9605 | return isAllowed; |
| 9606 | } |
| 9607 | |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9608 | private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) { |
| 9609 | UiccProfile profile = port.getUiccProfile(); |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 9610 | if (profile == null) { |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9611 | return false; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9612 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 9613 | Phone phone = PhoneFactory.getPhone(profile.getPhoneId()); |
| 9614 | if (phone == null) { |
| 9615 | return false; |
| 9616 | } |
| 9617 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 9618 | return cpt != null && cpt.getCarrierPrivilegeStatusForPackage(callingPackage) |
| 9619 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9620 | } |
| 9621 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 9622 | @Override |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 9623 | public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) { |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9624 | // Verify that the callingPackage belongs to the calling UID |
Jordan Liu | 4cda455 | 2020-03-23 11:55:07 -0700 | [diff] [blame] | 9625 | mApp.getSystemService(AppOpsManager.class) |
| 9626 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 9627 | |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9628 | boolean hasReadPermission = false; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9629 | boolean isIccIdAccessRestricted = false; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 9630 | try { |
| 9631 | enforceReadPrivilegedPermission("getUiccCardsInfo"); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9632 | hasReadPermission = true; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 9633 | } catch (SecurityException e) { |
| 9634 | // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller |
| 9635 | // has carrier privileges on an active UICC |
Rambo Wang | e7209ce | 2022-02-23 13:41:02 -0800 | [diff] [blame] | 9636 | if (checkCarrierPrivilegesForPackageAnyPhoneWithPermission(callingPackage) |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 9637 | != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9638 | throw new SecurityException("Caller does not have permission."); |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 9639 | } |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 9640 | } |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9641 | // checking compatibility, if calling app's target SDK is T and beyond. |
| 9642 | if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO, |
| 9643 | Binder.getCallingUid())) { |
| 9644 | isIccIdAccessRestricted = true; |
| 9645 | } |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 9646 | final long identity = Binder.clearCallingIdentity(); |
| 9647 | try { |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 9648 | UiccController uiccController = UiccController.getInstance(); |
| 9649 | ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos(); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9650 | if (hasReadPermission) { |
| 9651 | return cardInfos; |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 9652 | } |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9653 | |
| 9654 | // Remove private info if the caller doesn't have access |
| 9655 | ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>(); |
| 9656 | for (UiccCardInfo cardInfo : cardInfos) { |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9657 | //setting the value after compatibility check |
| 9658 | cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9659 | // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo |
| 9660 | // is available |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9661 | UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex()); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9662 | if (card == null) { |
| 9663 | // assume no access if the card is unavailable |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9664 | filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo)); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9665 | continue; |
| 9666 | } |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9667 | Collection<UiccPortInfo> portInfos = cardInfo.getPorts(); |
| 9668 | if (portInfos.isEmpty()) { |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9669 | filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo)); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9670 | continue; |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9671 | } |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9672 | List<UiccPortInfo> uiccPortInfos = new ArrayList<>(); |
| 9673 | for (UiccPortInfo portInfo : portInfos) { |
| 9674 | UiccPort port = uiccController.getUiccPortForSlot( |
| 9675 | cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex()); |
| 9676 | if (port == null) { |
| 9677 | // assume no access if port is null |
| 9678 | uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo)); |
| 9679 | continue; |
| 9680 | } |
| 9681 | if (haveCarrierPrivilegeAccess(port, callingPackage)) { |
| 9682 | uiccPortInfos.add(portInfo); |
| 9683 | } else { |
| 9684 | uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo)); |
| 9685 | } |
| 9686 | } |
| 9687 | filteredInfos.add(new UiccCardInfo( |
| 9688 | cardInfo.isEuicc(), |
| 9689 | cardInfo.getCardId(), |
| 9690 | null, |
| 9691 | cardInfo.getPhysicalSlotIndex(), |
| 9692 | cardInfo.isRemovable(), |
| 9693 | cardInfo.isMultipleEnabledProfilesSupported(), |
| 9694 | uiccPortInfos)); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9695 | } |
| 9696 | return filteredInfos; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 9697 | } finally { |
| 9698 | Binder.restoreCallingIdentity(identity); |
| 9699 | } |
| 9700 | } |
| 9701 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9702 | /** |
| 9703 | * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are |
| 9704 | * generally private and require carrier privileges to view. |
| 9705 | * |
| 9706 | * @hide |
| 9707 | */ |
| 9708 | @NonNull |
| 9709 | public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) { |
| 9710 | List<UiccPortInfo> portinfo = new ArrayList<>(); |
| 9711 | for (UiccPortInfo portinfos : cardInfo.getPorts()) { |
| 9712 | portinfo.add(getUiccPortInfoUnPrivileged(portinfos)); |
| 9713 | } |
| 9714 | return new UiccCardInfo( |
| 9715 | cardInfo.isEuicc(), |
| 9716 | cardInfo.getCardId(), |
| 9717 | null, |
| 9718 | cardInfo.getPhysicalSlotIndex(), |
| 9719 | cardInfo.isRemovable(), |
| 9720 | cardInfo.isMultipleEnabledProfilesSupported(), |
| 9721 | portinfo |
| 9722 | ); |
| 9723 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9724 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9725 | /** |
| 9726 | * @hide |
| 9727 | * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}. |
| 9728 | * These values are generally private and require carrier privileges to view. |
| 9729 | */ |
| 9730 | @NonNull |
| 9731 | public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) { |
| 9732 | return new UiccPortInfo( |
| 9733 | UiccPortInfo.ICCID_REDACTED, |
| 9734 | portInfo.getPortIndex(), |
| 9735 | portInfo.getLogicalSlotIndex(), |
| 9736 | portInfo.isActive() |
| 9737 | ); |
| 9738 | } |
| 9739 | @Override |
| 9740 | public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) { |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9741 | // Verify that the callingPackage belongs to the calling UID |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9742 | mApp.getSystemService(AppOpsManager.class) |
| 9743 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 9744 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9745 | boolean isLogicalSlotAccessRestricted = false; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9746 | |
Aman Gupta | f3c90b3 | 2022-03-17 04:54:16 +0000 | [diff] [blame] | 9747 | // This will make sure caller has the READ_PRIVILEGED_PHONE_STATE. Do not remove this as |
| 9748 | // we are reading iccId which is PII data. |
| 9749 | enforceReadPrivilegedPermission("getUiccSlotsInfo"); |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9750 | |
| 9751 | // checking compatibility, if calling app's target SDK is T and beyond. |
| 9752 | if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO, |
| 9753 | Binder.getCallingUid())) { |
| 9754 | isLogicalSlotAccessRestricted = true; |
| 9755 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9756 | final long identity = Binder.clearCallingIdentity(); |
| 9757 | try { |
| 9758 | UiccSlot[] slots = UiccController.getInstance().getUiccSlots(); |
Muralidhar Reddy | d196bbf | 2022-01-17 17:56:30 +0000 | [diff] [blame] | 9759 | if (slots == null || slots.length == 0) { |
| 9760 | Rlog.i(LOG_TAG, "slots is null or empty."); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9761 | return null; |
| 9762 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9763 | UiccSlotInfo[] infos = new UiccSlotInfo[slots.length]; |
| 9764 | for (int i = 0; i < slots.length; i++) { |
| 9765 | UiccSlot slot = slots[i]; |
| 9766 | if (slot == null) { |
| 9767 | continue; |
| 9768 | } |
| 9769 | |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 9770 | String cardId; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9771 | UiccCard card = slot.getUiccCard(); |
| 9772 | if (card != null) { |
| 9773 | cardId = card.getCardId(); |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 9774 | } else { |
Jordan Liu | 01bd00d | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 9775 | cardId = slot.getEid(); |
| 9776 | if (TextUtils.isEmpty(cardId)) { |
Aman Gupta | f3c90b3 | 2022-03-17 04:54:16 +0000 | [diff] [blame] | 9777 | // If cardId is null, use iccId of default port as cardId. |
| 9778 | cardId = slot.getIccId(TelephonyManager.DEFAULT_PORT_INDEX); |
Jordan Liu | 01bd00d | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 9779 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9780 | } |
| 9781 | |
Jordan Liu | 857451f | 2019-05-09 16:35:35 -0700 | [diff] [blame] | 9782 | if (cardId != null) { |
| 9783 | // if cardId is an ICCID, strip off trailing Fs before exposing to user |
| 9784 | // if cardId is an EID, it's all digits so this is fine |
| 9785 | cardId = IccUtils.stripTrailingFs(cardId); |
| 9786 | } |
| 9787 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9788 | int cardState = 0; |
| 9789 | switch (slot.getCardState()) { |
| 9790 | case CARDSTATE_ABSENT: |
| 9791 | cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT; |
| 9792 | break; |
| 9793 | case CARDSTATE_PRESENT: |
| 9794 | cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT; |
| 9795 | break; |
| 9796 | case CARDSTATE_ERROR: |
| 9797 | cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR; |
| 9798 | break; |
| 9799 | case CARDSTATE_RESTRICTED: |
| 9800 | cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED; |
| 9801 | break; |
| 9802 | default: |
| 9803 | break; |
| 9804 | |
| 9805 | } |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9806 | List<UiccPortInfo> portInfos = new ArrayList<>(); |
| 9807 | int[] portIndexes = slot.getPortList(); |
| 9808 | for (int portIdx : portIndexes) { |
| 9809 | String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx, |
Aman Gupta | f3c90b3 | 2022-03-17 04:54:16 +0000 | [diff] [blame] | 9810 | callingPackage, /* hasReadPermission= */ true)); |
Muralidhar Reddy | fbcff0c | 2022-01-19 13:07:57 +0000 | [diff] [blame] | 9811 | portInfos.add(new UiccPortInfo(iccId, portIdx, |
| 9812 | slot.getPhoneIdFromPortIndex(portIdx), slot.isPortActive(portIdx))); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9813 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9814 | infos[i] = new UiccSlotInfo( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9815 | slot.isEuicc(), |
| 9816 | cardId, |
| 9817 | cardState, |
Jordan Liu | a261958 | 2019-02-14 12:56:40 -0800 | [diff] [blame] | 9818 | slot.isExtendedApduSupported(), |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9819 | slot.isRemovable(), portInfos); |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9820 | //setting the value after compatibility check |
| 9821 | infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9822 | } |
| 9823 | return infos; |
| 9824 | } finally { |
| 9825 | Binder.restoreCallingIdentity(identity); |
Holly Jiuyu Sun | 1d957c5 | 2018-04-04 13:52:42 -0700 | [diff] [blame] | 9826 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9827 | } |
| 9828 | |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9829 | /* Returns null if doesn't have read permission or carrier privilege access. */ |
| 9830 | private String getIccId(UiccSlot slot, int portIndex, String callingPackage, |
| 9831 | boolean hasReadPermission) { |
| 9832 | String iccId = slot.getIccId(portIndex); |
| 9833 | if (hasReadPermission) { // if has read permission |
| 9834 | return iccId; |
| 9835 | } else { |
| 9836 | if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) { |
| 9837 | UiccPort port = slot.getUiccCard().getUiccPort(portIndex); |
| 9838 | // if no read permission, checking carrier privilege access |
| 9839 | if (haveCarrierPrivilegeAccess(port, callingPackage)) { |
| 9840 | return iccId; |
| 9841 | } |
| 9842 | } |
| 9843 | } |
| 9844 | // No read permission or carrier privilege access. |
| 9845 | return UiccPortInfo.ICCID_REDACTED; |
| 9846 | } |
| 9847 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9848 | @Override |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9849 | @Deprecated |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9850 | public boolean switchSlots(int[] physicalSlots) { |
| 9851 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9852 | |
| 9853 | final long identity = Binder.clearCallingIdentity(); |
| 9854 | try { |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9855 | List<UiccSlotMapping> slotMappings = new ArrayList<>(); |
| 9856 | for (int i = 0; i < physicalSlots.length; i++) { |
| 9857 | // Deprecated API, hence MEP is not supported. Adding default portIndex 0. |
| 9858 | slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX, |
| 9859 | physicalSlots[i], i)); |
| 9860 | } |
| 9861 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9862 | } finally { |
| 9863 | Binder.restoreCallingIdentity(identity); |
| 9864 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9865 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 9866 | |
| 9867 | @Override |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9868 | @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 9869 | public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) { |
| 9870 | enforceModifyPermission(); |
| 9871 | |
| 9872 | final long identity = Binder.clearCallingIdentity(); |
| 9873 | try { |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9874 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping); |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9875 | } finally { |
| 9876 | Binder.restoreCallingIdentity(identity); |
| 9877 | } |
| 9878 | } |
| 9879 | |
| 9880 | @Override |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 9881 | public int getCardIdForDefaultEuicc(int subId, String callingPackage) { |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 9882 | final long identity = Binder.clearCallingIdentity(); |
| 9883 | try { |
| 9884 | return UiccController.getInstance().getCardIdForDefaultEuicc(); |
| 9885 | } finally { |
| 9886 | Binder.restoreCallingIdentity(identity); |
| 9887 | } |
| 9888 | } |
| 9889 | |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9890 | /** |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 9891 | * A test API to reload the UICC profile. |
| 9892 | * |
| 9893 | * <p>Requires that the calling app has permission |
| 9894 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 9895 | * @hide |
| 9896 | */ |
| 9897 | @Override |
| 9898 | public void refreshUiccProfile(int subId) { |
| 9899 | enforceModifyPermission(); |
| 9900 | |
| 9901 | final long identity = Binder.clearCallingIdentity(); |
| 9902 | try { |
| 9903 | Phone phone = getPhone(subId); |
| 9904 | if (phone == null) { |
| 9905 | return; |
| 9906 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9907 | UiccPort uiccPort = phone.getUiccPort(); |
| 9908 | if (uiccPort == null) { |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 9909 | return; |
| 9910 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9911 | UiccProfile uiccProfile = uiccPort.getUiccProfile(); |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 9912 | if (uiccProfile == null) { |
| 9913 | return; |
| 9914 | } |
| 9915 | uiccProfile.refresh(); |
| 9916 | } finally { |
| 9917 | Binder.restoreCallingIdentity(identity); |
| 9918 | } |
| 9919 | } |
| 9920 | |
| 9921 | /** |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9922 | * Returns false if the mobile data is disabled by default, otherwise return true. |
| 9923 | */ |
| 9924 | private boolean getDefaultDataEnabled() { |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 9925 | return TelephonyProperties.mobile_data().orElse(true); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9926 | } |
| 9927 | |
| 9928 | /** |
| 9929 | * Returns true if the data roaming is enabled by default, i.e the system property |
| 9930 | * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of |
| 9931 | * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true. |
| 9932 | */ |
| 9933 | private boolean getDefaultDataRoamingEnabled(int subId) { |
| 9934 | final CarrierConfigManager configMgr = (CarrierConfigManager) |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9935 | mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Shuo Qian | 1d84a0e | 2020-07-15 12:36:44 -0700 | [diff] [blame] | 9936 | boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9937 | isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean( |
| 9938 | CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL); |
| 9939 | return isDataRoamingEnabled; |
| 9940 | } |
| 9941 | |
| 9942 | /** |
| 9943 | * Returns the default network type for the given {@code subId}, if the default network type is |
| 9944 | * not set, return {@link Phone#PREFERRED_NT_MODE}. |
| 9945 | */ |
| 9946 | private int getDefaultNetworkType(int subId) { |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 9947 | List<Integer> list = TelephonyProperties.default_network(); |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 9948 | int phoneId = SubscriptionManager.getPhoneId(subId); |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 9949 | if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) { |
| 9950 | return list.get(phoneId); |
| 9951 | } |
| 9952 | return Phone.PREFERRED_NT_MODE; |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9953 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9954 | |
| 9955 | @Override |
| 9956 | public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 9957 | gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) { |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9958 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9959 | |
| 9960 | final long identity = Binder.clearCallingIdentity(); |
| 9961 | try { |
| 9962 | final Phone phone = getPhone(subId); |
| 9963 | if (phone == null) { |
| 9964 | loge("setCarrierTestOverride fails with invalid subId: " + subId); |
| 9965 | return; |
| 9966 | } |
Rambo Wang | 9c9ffdd | 2022-01-13 21:51:44 -0800 | [diff] [blame] | 9967 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 9968 | if (cpt != null) { |
| 9969 | cpt.setTestOverrideCarrierPrivilegeRules(carrierPrivilegeRules); |
| 9970 | } |
| 9971 | // 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] | 9972 | phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn, |
| 9973 | carrierPrivilegeRules, apn); |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 9974 | if (carrierPrivilegeRules == null) { |
| 9975 | mCarrierPrivilegeTestOverrideSubIds.remove(subId); |
| 9976 | } else { |
| 9977 | mCarrierPrivilegeTestOverrideSubIds.add(subId); |
| 9978 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9979 | } finally { |
| 9980 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9981 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9982 | } |
| 9983 | |
| 9984 | @Override |
| 9985 | public int getCarrierIdListVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 9986 | enforceReadPrivilegedPermission("getCarrierIdListVersion"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9987 | |
| 9988 | final long identity = Binder.clearCallingIdentity(); |
| 9989 | try { |
| 9990 | final Phone phone = getPhone(subId); |
| 9991 | if (phone == null) { |
| 9992 | loge("getCarrierIdListVersion fails with invalid subId: " + subId); |
| 9993 | return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION; |
| 9994 | } |
| 9995 | return phone.getCarrierIdListVersion(); |
| 9996 | } finally { |
| 9997 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9998 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9999 | } |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 10000 | |
| 10001 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10002 | public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage, |
| 10003 | String callingFeatureId) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 10004 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10005 | mApp, subId, callingPackage, callingFeatureId, |
| 10006 | "getNumberOfModemsWithSimultaneousDataConnections")) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 10007 | return -1; |
| 10008 | } |
| 10009 | |
| 10010 | final long identity = Binder.clearCallingIdentity(); |
| 10011 | try { |
| 10012 | return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections(); |
| 10013 | } finally { |
| 10014 | Binder.restoreCallingIdentity(identity); |
| 10015 | } |
| 10016 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 10017 | |
| 10018 | @Override |
| 10019 | public int getCdmaRoamingMode(int subId) { |
zoey chen | 7e6d4e5 | 2019-12-17 18:18:59 +0800 | [diff] [blame] | 10020 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 10021 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 10022 | mApp, subId, "getCdmaRoamingMode"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 10023 | |
| 10024 | final long identity = Binder.clearCallingIdentity(); |
| 10025 | try { |
| 10026 | return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId); |
| 10027 | } finally { |
| 10028 | Binder.restoreCallingIdentity(identity); |
| 10029 | } |
| 10030 | } |
| 10031 | |
| 10032 | @Override |
| 10033 | public boolean setCdmaRoamingMode(int subId, int mode) { |
| 10034 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 10035 | mApp, subId, "setCdmaRoamingMode"); |
| 10036 | |
| 10037 | final long identity = Binder.clearCallingIdentity(); |
| 10038 | try { |
| 10039 | return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId); |
| 10040 | } finally { |
| 10041 | Binder.restoreCallingIdentity(identity); |
| 10042 | } |
| 10043 | } |
| 10044 | |
| 10045 | @Override |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 10046 | public int getCdmaSubscriptionMode(int subId) { |
| 10047 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 10048 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 10049 | mApp, subId, "getCdmaSubscriptionMode"); |
| 10050 | |
| 10051 | final long identity = Binder.clearCallingIdentity(); |
| 10052 | try { |
| 10053 | return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId); |
| 10054 | } finally { |
| 10055 | Binder.restoreCallingIdentity(identity); |
| 10056 | } |
| 10057 | } |
| 10058 | |
| 10059 | @Override |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 10060 | public boolean setCdmaSubscriptionMode(int subId, int mode) { |
| 10061 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 10062 | mApp, subId, "setCdmaSubscriptionMode"); |
| 10063 | |
| 10064 | final long identity = Binder.clearCallingIdentity(); |
| 10065 | try { |
| 10066 | return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId); |
| 10067 | } finally { |
| 10068 | Binder.restoreCallingIdentity(identity); |
| 10069 | } |
| 10070 | } |
Makoto Onuki | da3bf79 | 2018-09-18 16:06:29 -0700 | [diff] [blame] | 10071 | |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 10072 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 10073 | public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10074 | String callingPackage, String callingFeatureId) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10075 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10076 | mApp, getDefaultSubscription(), callingPackage, callingFeatureId, |
| 10077 | "getEmergencyNumberList")) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10078 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 10079 | } |
| 10080 | final long identity = Binder.clearCallingIdentity(); |
| 10081 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 10082 | Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>(); |
| 10083 | for (Phone phone: PhoneFactory.getPhones()) { |
| 10084 | if (phone.getEmergencyNumberTracker() != null |
| 10085 | && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) { |
| 10086 | emergencyNumberListInternal.put( |
| 10087 | phone.getSubId(), |
| 10088 | phone.getEmergencyNumberTracker().getEmergencyNumberList()); |
| 10089 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10090 | } |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 10091 | return emergencyNumberListInternal; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10092 | } finally { |
| 10093 | Binder.restoreCallingIdentity(identity); |
| 10094 | } |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 10095 | } |
| 10096 | |
| 10097 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 10098 | public boolean isEmergencyNumber(String number, boolean exactMatch) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 10099 | final Phone defaultPhone = getDefaultPhone(); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10100 | if (!exactMatch) { |
| 10101 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 10102 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 10103 | mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)"); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10104 | } |
| 10105 | final long identity = Binder.clearCallingIdentity(); |
| 10106 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 10107 | for (Phone phone: PhoneFactory.getPhones()) { |
Chinmay Dhodapkar | d521bb1 | 2022-08-16 15:49:54 -0700 | [diff] [blame] | 10108 | //Note: we ignore passed in param exactMatch. We can remove it once |
| 10109 | // TelephonyManager#isPotentialEmergencyNumber is removed completely |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 10110 | if (phone.getEmergencyNumberTracker() != null |
Taesu Lee | e050c00 | 2020-10-13 17:19:35 +0900 | [diff] [blame] | 10111 | && phone.getEmergencyNumberTracker() |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 10112 | .isEmergencyNumber(number)) { |
Taesu Lee | e050c00 | 2020-10-13 17:19:35 +0900 | [diff] [blame] | 10113 | return true; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10114 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10115 | } |
| 10116 | return false; |
| 10117 | } finally { |
| 10118 | Binder.restoreCallingIdentity(identity); |
| 10119 | } |
| 10120 | } |
| 10121 | |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 10122 | /** |
Shuo Qian | ccbaf74 | 2021-02-22 18:32:21 -0800 | [diff] [blame] | 10123 | * Start emergency callback mode for GsmCdmaPhone for testing. |
| 10124 | */ |
| 10125 | @Override |
| 10126 | public void startEmergencyCallbackMode() { |
| 10127 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10128 | "startEmergencyCallbackMode"); |
| 10129 | enforceModifyPermission(); |
| 10130 | final long identity = Binder.clearCallingIdentity(); |
| 10131 | try { |
| 10132 | for (Phone phone : PhoneFactory.getPhones()) { |
| 10133 | Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType()); |
| 10134 | if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM) |
| 10135 | || (phone.getPhoneType() == PHONE_TYPE_CDMA))) { |
| 10136 | GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone; |
| 10137 | gsmCdmaPhone.obtainMessage( |
| 10138 | GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget(); |
| 10139 | Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered"); |
| 10140 | } |
| 10141 | } |
| 10142 | } finally { |
| 10143 | Binder.restoreCallingIdentity(identity); |
| 10144 | } |
| 10145 | } |
| 10146 | |
| 10147 | /** |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 10148 | * Update emergency number list for test mode. |
| 10149 | */ |
| 10150 | @Override |
| 10151 | public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) { |
| 10152 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10153 | "updateEmergencyNumberListTestMode"); |
| 10154 | |
| 10155 | final long identity = Binder.clearCallingIdentity(); |
| 10156 | try { |
| 10157 | for (Phone phone: PhoneFactory.getPhones()) { |
| 10158 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 10159 | if (tracker != null) { |
| 10160 | tracker.executeEmergencyNumberTestModeCommand(action, num); |
| 10161 | } |
| 10162 | } |
| 10163 | } finally { |
| 10164 | Binder.restoreCallingIdentity(identity); |
| 10165 | } |
| 10166 | } |
| 10167 | |
| 10168 | /** |
| 10169 | * Get the full emergency number list for test mode. |
| 10170 | */ |
| 10171 | @Override |
| 10172 | public List<String> getEmergencyNumberListTestMode() { |
| 10173 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10174 | "getEmergencyNumberListTestMode"); |
| 10175 | |
| 10176 | final long identity = Binder.clearCallingIdentity(); |
| 10177 | try { |
| 10178 | Set<String> emergencyNumbers = new HashSet<>(); |
| 10179 | for (Phone phone: PhoneFactory.getPhones()) { |
| 10180 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 10181 | if (tracker != null) { |
| 10182 | for (EmergencyNumber num : tracker.getEmergencyNumberList()) { |
| 10183 | emergencyNumbers.add(num.getNumber()); |
| 10184 | } |
| 10185 | } |
| 10186 | } |
| 10187 | return new ArrayList<>(emergencyNumbers); |
| 10188 | } finally { |
| 10189 | Binder.restoreCallingIdentity(identity); |
| 10190 | } |
| 10191 | } |
| 10192 | |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 10193 | @Override |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 10194 | public int getEmergencyNumberDbVersion(int subId) { |
| 10195 | enforceReadPrivilegedPermission("getEmergencyNumberDbVersion"); |
| 10196 | |
| 10197 | final long identity = Binder.clearCallingIdentity(); |
| 10198 | try { |
| 10199 | final Phone phone = getPhone(subId); |
| 10200 | if (phone == null) { |
| 10201 | loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId); |
| 10202 | return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION; |
| 10203 | } |
| 10204 | return phone.getEmergencyNumberDbVersion(); |
| 10205 | } finally { |
| 10206 | Binder.restoreCallingIdentity(identity); |
| 10207 | } |
| 10208 | } |
| 10209 | |
| 10210 | @Override |
| 10211 | public void notifyOtaEmergencyNumberDbInstalled() { |
| 10212 | enforceModifyPermission(); |
| 10213 | |
| 10214 | final long identity = Binder.clearCallingIdentity(); |
| 10215 | try { |
| 10216 | for (Phone phone: PhoneFactory.getPhones()) { |
| 10217 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 10218 | if (tracker != null) { |
| 10219 | tracker.updateOtaEmergencyNumberDatabase(); |
| 10220 | } |
| 10221 | } |
| 10222 | } finally { |
| 10223 | Binder.restoreCallingIdentity(identity); |
| 10224 | } |
| 10225 | } |
| 10226 | |
| 10227 | @Override |
Shuo Qian | c373f11 | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 10228 | public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) { |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 10229 | enforceActiveEmergencySessionPermission(); |
| 10230 | |
| 10231 | final long identity = Binder.clearCallingIdentity(); |
| 10232 | try { |
| 10233 | for (Phone phone: PhoneFactory.getPhones()) { |
| 10234 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 10235 | if (tracker != null) { |
Shuo Qian | c373f11 | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 10236 | tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor); |
| 10237 | } |
| 10238 | } |
| 10239 | } finally { |
| 10240 | Binder.restoreCallingIdentity(identity); |
| 10241 | } |
| 10242 | } |
| 10243 | |
| 10244 | @Override |
| 10245 | public void resetOtaEmergencyNumberDbFilePath() { |
| 10246 | enforceActiveEmergencySessionPermission(); |
| 10247 | |
| 10248 | final long identity = Binder.clearCallingIdentity(); |
| 10249 | try { |
| 10250 | for (Phone phone: PhoneFactory.getPhones()) { |
| 10251 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 10252 | if (tracker != null) { |
| 10253 | tracker.resetOtaEmergencyNumberDbFilePath(); |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 10254 | } |
| 10255 | } |
| 10256 | } finally { |
| 10257 | Binder.restoreCallingIdentity(identity); |
| 10258 | } |
| 10259 | } |
| 10260 | |
| 10261 | @Override |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 10262 | public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) { |
| 10263 | enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules"); |
| 10264 | Phone phone = getPhone(subId); |
| 10265 | if (phone == null) { |
| 10266 | return null; |
| 10267 | } |
| 10268 | final long identity = Binder.clearCallingIdentity(); |
| 10269 | try { |
| 10270 | UiccProfile profile = UiccController.getInstance() |
| 10271 | .getUiccProfileForPhone(phone.getPhoneId()); |
| 10272 | if (profile != null) { |
| 10273 | return profile.getCertsFromCarrierPrivilegeAccessRules(); |
| 10274 | } |
| 10275 | } finally { |
| 10276 | Binder.restoreCallingIdentity(identity); |
| 10277 | } |
| 10278 | return null; |
| 10279 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 10280 | |
| 10281 | /** |
| 10282 | * Enable or disable a modem stack. |
| 10283 | */ |
| 10284 | @Override |
| 10285 | public boolean enableModemForSlot(int slotIndex, boolean enable) { |
| 10286 | enforceModifyPermission(); |
| 10287 | |
| 10288 | final long identity = Binder.clearCallingIdentity(); |
| 10289 | try { |
| 10290 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 10291 | if (phone == null) { |
| 10292 | return false; |
| 10293 | } else { |
| 10294 | return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null); |
| 10295 | } |
| 10296 | } finally { |
| 10297 | Binder.restoreCallingIdentity(identity); |
| 10298 | } |
| 10299 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 10300 | |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 10301 | /** |
| 10302 | * Whether a modem stack is enabled or not. |
| 10303 | */ |
| 10304 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10305 | public boolean isModemEnabledForSlot(int slotIndex, String callingPackage, |
| 10306 | String callingFeatureId) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 10307 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 10308 | if (phone == null) return false; |
| 10309 | |
| 10310 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10311 | mApp, phone.getSubId(), callingPackage, callingFeatureId, |
| 10312 | "isModemEnabledForSlot")) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 10313 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 10314 | } |
| 10315 | |
| 10316 | final long identity = Binder.clearCallingIdentity(); |
| 10317 | try { |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 10318 | try { |
| 10319 | return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId()); |
| 10320 | } catch (NoSuchElementException ex) { |
| 10321 | return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null); |
| 10322 | } |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 10323 | } finally { |
| 10324 | Binder.restoreCallingIdentity(identity); |
| 10325 | } |
| 10326 | } |
| 10327 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 10328 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10329 | public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) { |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 10330 | enforceModifyPermission(); |
| 10331 | |
| 10332 | final long identity = Binder.clearCallingIdentity(); |
| 10333 | try { |
| 10334 | mTelephonySharedPreferences.edit() |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10335 | .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted) |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 10336 | .commit(); |
| 10337 | } finally { |
| 10338 | Binder.restoreCallingIdentity(identity); |
| 10339 | } |
| 10340 | } |
| 10341 | |
| 10342 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10343 | @TelephonyManager.IsMultiSimSupportedResult |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10344 | public int isMultiSimSupported(String callingPackage, String callingFeatureId) { |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 10345 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10346 | getDefaultPhone().getSubId(), callingPackage, callingFeatureId, |
| 10347 | "isMultiSimSupported")) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10348 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 10349 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 10350 | |
| 10351 | final long identity = Binder.clearCallingIdentity(); |
| 10352 | try { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10353 | return isMultiSimSupportedInternal(); |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 10354 | } finally { |
| 10355 | Binder.restoreCallingIdentity(identity); |
| 10356 | } |
| 10357 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 10358 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10359 | @TelephonyManager.IsMultiSimSupportedResult |
| 10360 | private int isMultiSimSupportedInternal() { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10361 | // If the device has less than 2 SIM cards, indicate that multisim is restricted. |
| 10362 | int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length; |
| 10363 | if (numPhysicalSlots < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10364 | loge("isMultiSimSupportedInternal: requires at least 2 cards"); |
| 10365 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10366 | } |
| 10367 | // Check if the hardware supports multisim functionality. If usage of multisim is not |
| 10368 | // supported by the modem, indicate that it is restricted. |
| 10369 | PhoneCapability staticCapability = |
| 10370 | mPhoneConfigurationManager.getStaticPhoneCapability(); |
| 10371 | if (staticCapability == null) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10372 | loge("isMultiSimSupportedInternal: no static configuration available"); |
| 10373 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10374 | } |
SongFerngWang | 8236caa | 2021-01-17 21:51:44 +0800 | [diff] [blame] | 10375 | if (staticCapability.getLogicalModemList().size() < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10376 | loge("isMultiSimSupportedInternal: maximum number of modem is < 2"); |
| 10377 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10378 | } |
| 10379 | // Check if support of multiple SIMs is restricted by carrier |
| 10380 | if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10381 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10382 | } |
| 10383 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10384 | return TelephonyManager.MULTISIM_ALLOWED; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10385 | } |
| 10386 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 10387 | /** |
| 10388 | * Switch configs to enable multi-sim or switch back to single-sim |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 10389 | * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE |
| 10390 | * permission, but the other way around is possible with either MODIFY_PHONE_STATE |
| 10391 | * or carrier privileges |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 10392 | * @param numOfSims number of active sims we want to switch to |
| 10393 | */ |
| 10394 | @Override |
| 10395 | public void switchMultiSimConfig(int numOfSims) { |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 10396 | if (numOfSims == 1) { |
| 10397 | enforceModifyPermission(); |
| 10398 | } else { |
| 10399 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 10400 | mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig"); |
| 10401 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 10402 | final long identity = Binder.clearCallingIdentity(); |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10403 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 10404 | try { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10405 | //only proceed if multi-sim is not restricted |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10406 | if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10407 | loge("switchMultiSimConfig not possible. It is restricted or not supported."); |
| 10408 | return; |
| 10409 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 10410 | mPhoneConfigurationManager.switchMultiSimConfig(numOfSims); |
| 10411 | } finally { |
| 10412 | Binder.restoreCallingIdentity(identity); |
| 10413 | } |
| 10414 | } |
| 10415 | |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 10416 | @Override |
| 10417 | public boolean isApplicationOnUicc(int subId, int appType) { |
| 10418 | enforceReadPrivilegedPermission("isApplicationOnUicc"); |
| 10419 | Phone phone = getPhone(subId); |
| 10420 | if (phone == null) { |
| 10421 | return false; |
| 10422 | } |
| 10423 | final long identity = Binder.clearCallingIdentity(); |
| 10424 | try { |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 10425 | UiccPort uiccPort = phone.getUiccPort(); |
| 10426 | if (uiccPort == null) { |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 10427 | return false; |
| 10428 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 10429 | UiccProfile uiccProfile = uiccPort.getUiccProfile(); |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 10430 | if (uiccProfile == null) { |
| 10431 | return false; |
| 10432 | } |
| 10433 | if (TelephonyManager.APPTYPE_SIM <= appType |
| 10434 | && appType <= TelephonyManager.APPTYPE_ISIM) { |
| 10435 | return uiccProfile.isApplicationOnIcc(AppType.values()[appType]); |
| 10436 | } |
| 10437 | return false; |
| 10438 | } finally { |
| 10439 | Binder.restoreCallingIdentity(identity); |
| 10440 | } |
| 10441 | } |
| 10442 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 10443 | /** |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 10444 | * Get whether making changes to modem configurations will trigger reboot. |
| 10445 | * Return value defaults to true. |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 10446 | */ |
| 10447 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10448 | public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage, |
| 10449 | String callingFeatureId) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 10450 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10451 | mApp, subId, callingPackage, callingFeatureId, |
| 10452 | "doesSwitchMultiSimConfigTriggerReboot")) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 10453 | return false; |
| 10454 | } |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 10455 | final long identity = Binder.clearCallingIdentity(); |
| 10456 | try { |
| 10457 | return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange(); |
| 10458 | } finally { |
| 10459 | Binder.restoreCallingIdentity(identity); |
| 10460 | } |
| 10461 | } |
| 10462 | |
Nathan Harold | 29f5f05 | 2019-02-15 13:41:57 -0800 | [diff] [blame] | 10463 | private void updateModemStateMetrics() { |
| 10464 | TelephonyMetrics metrics = TelephonyMetrics.getInstance(); |
| 10465 | // TODO: check the state for each modem if the api is ready. |
| 10466 | metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1); |
| 10467 | } |
| 10468 | |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10469 | @Override |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 10470 | public List<UiccSlotMapping> getSlotsMapping(String callingPackage) { |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10471 | enforceReadPrivilegedPermission("getSlotsMapping"); |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 10472 | // Verify that the callingPackage belongs to the calling UID |
| 10473 | mApp.getSystemService(AppOpsManager.class) |
| 10474 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10475 | final long identity = Binder.clearCallingIdentity(); |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 10476 | List<UiccSlotMapping> slotMap = new ArrayList<>(); |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10477 | try { |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 10478 | UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName()); |
| 10479 | if (slotInfos != null) { |
| 10480 | for (int i = 0; i < slotInfos.length; i++) { |
| 10481 | for (UiccPortInfo portInfo : slotInfos[i].getPorts()) { |
| 10482 | if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) { |
| 10483 | slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i, |
| 10484 | portInfo.getLogicalSlotIndex())); |
| 10485 | } |
| 10486 | } |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10487 | } |
| 10488 | } |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 10489 | return slotMap; |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10490 | } finally { |
| 10491 | Binder.restoreCallingIdentity(identity); |
| 10492 | } |
| 10493 | } |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 10494 | |
| 10495 | /** |
| 10496 | * Get the IRadio HAL Version |
jimsun | f9ec162 | 2022-09-13 21:18:43 +0800 | [diff] [blame] | 10497 | * @deprecated use getHalVersion instead |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 10498 | */ |
jimsun | f9ec162 | 2022-09-13 21:18:43 +0800 | [diff] [blame] | 10499 | @Deprecated |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 10500 | @Override |
| 10501 | public int getRadioHalVersion() { |
jimsun | f9ec162 | 2022-09-13 21:18:43 +0800 | [diff] [blame] | 10502 | return getHalVersion(HAL_SERVICE_RADIO); |
| 10503 | } |
| 10504 | |
| 10505 | /** |
| 10506 | * Get the HAL Version of a specific service |
| 10507 | */ |
| 10508 | @Override |
| 10509 | public int getHalVersion(int service) { |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 10510 | Phone phone = getDefaultPhone(); |
| 10511 | if (phone == null) return -1; |
jimsun | f9ec162 | 2022-09-13 21:18:43 +0800 | [diff] [blame] | 10512 | HalVersion hv = phone.getHalVersion(service); |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 10513 | if (hv.equals(HalVersion.UNKNOWN)) return -1; |
| 10514 | return hv.major * 100 + hv.minor; |
| 10515 | } |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 10516 | |
| 10517 | /** |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 10518 | * Get the current calling package name. |
| 10519 | * @return the current calling package name |
| 10520 | */ |
| 10521 | @Override |
| 10522 | public String getCurrentPackageName() { |
| 10523 | return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0]; |
| 10524 | } |
| 10525 | |
| 10526 | /** |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10527 | * Return whether data is enabled for certain APN type. This will tell if framework will accept |
| 10528 | * corresponding network requests on a subId. |
| 10529 | * |
| 10530 | * Data is enabled if: |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 10531 | * 1) user data is turned on, or |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10532 | * 2) APN is un-metered for this subscription, or |
| 10533 | * 3) APN type is whitelisted. E.g. MMS is whitelisted if |
Hall Liu | 746e03c | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 10534 | * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled. |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10535 | * |
| 10536 | * @return whether data is allowed for a apn type. |
| 10537 | * |
| 10538 | * @hide |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 10539 | */ |
| 10540 | @Override |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10541 | public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) { |
Amit Mahajan | 5d4e192 | 2019-10-07 16:20:43 -0700 | [diff] [blame] | 10542 | enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for " |
| 10543 | + "isDataEnabledForApn"); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 10544 | |
| 10545 | // Now that all security checks passes, perform the operation as ourselves. |
| 10546 | final long identity = Binder.clearCallingIdentity(); |
| 10547 | try { |
| 10548 | Phone phone = getPhone(subId); |
| 10549 | if (phone == null) return false; |
| 10550 | |
Jack Yu | 27422a5 | 2022-03-21 10:38:05 -0700 | [diff] [blame] | 10551 | boolean isMetered; |
Jack Yu | 99e8733 | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 10552 | boolean isDataEnabled; |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 10553 | isMetered = phone.getDataNetworkController().getDataConfigManager() |
| 10554 | .isMeteredCapability(DataUtils.apnTypeToNetworkCapability(apnType), |
| 10555 | phone.getServiceState().getDataRoaming()); |
| 10556 | isDataEnabled = phone.getDataSettingsManager().isDataEnabled(apnType); |
Jack Yu | 99e8733 | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 10557 | return !isMetered || isDataEnabled; |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10558 | } finally { |
| 10559 | Binder.restoreCallingIdentity(identity); |
| 10560 | } |
| 10561 | } |
| 10562 | |
| 10563 | @Override |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 10564 | public boolean isApnMetered(@ApnType int apnType, int subId) { |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10565 | enforceReadPrivilegedPermission("isApnMetered"); |
| 10566 | |
| 10567 | // Now that all security checks passes, perform the operation as ourselves. |
| 10568 | final long identity = Binder.clearCallingIdentity(); |
| 10569 | try { |
| 10570 | Phone phone = getPhone(subId); |
| 10571 | if (phone == null) return true; // By default return true. |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 10572 | return phone.getDataNetworkController().getDataConfigManager().isMeteredCapability( |
| 10573 | DataUtils.apnTypeToNetworkCapability(apnType), |
| 10574 | phone.getServiceState().getDataRoaming()); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 10575 | } finally { |
| 10576 | Binder.restoreCallingIdentity(identity); |
| 10577 | } |
| 10578 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 10579 | |
| 10580 | @Override |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 10581 | public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers, |
| 10582 | int subscriptionId, IBooleanConsumer resultCallback) { |
| 10583 | enforceModifyPermission(); |
| 10584 | long token = Binder.clearCallingIdentity(); |
| 10585 | try { |
| 10586 | Phone phone = getPhone(subscriptionId); |
| 10587 | if (phone == null) { |
| 10588 | try { |
| 10589 | if (resultCallback != null) { |
| 10590 | resultCallback.accept(false); |
| 10591 | } |
| 10592 | } catch (RemoteException e) { |
| 10593 | // ignore |
| 10594 | } |
| 10595 | return; |
| 10596 | } |
| 10597 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument = |
| 10598 | Pair.create(specifiers, (x) -> { |
| 10599 | try { |
| 10600 | if (resultCallback != null) { |
| 10601 | resultCallback.accept(x); |
| 10602 | } |
| 10603 | } catch (RemoteException e) { |
| 10604 | // ignore |
| 10605 | } |
| 10606 | }); |
| 10607 | sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null); |
| 10608 | } finally { |
| 10609 | Binder.restoreCallingIdentity(token); |
| 10610 | } |
| 10611 | } |
| 10612 | |
| 10613 | @Override |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 10614 | public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) { |
| 10615 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 10616 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 10617 | mApp, subId, "getSystemSelectionChannels"); |
| 10618 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 10619 | final long identity = Binder.clearCallingIdentity(); |
| 10620 | try { |
Sarah Chin | 428d1d6 | 2021-03-13 03:17:40 -0800 | [diff] [blame] | 10621 | Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource); |
| 10622 | if (result instanceof IllegalStateException) { |
| 10623 | throw (IllegalStateException) result; |
| 10624 | } |
| 10625 | List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 10626 | if (DBG) log("getSystemSelectionChannels: " + specifiers); |
| 10627 | return specifiers; |
| 10628 | } finally { |
| 10629 | Binder.restoreCallingIdentity(identity); |
| 10630 | } |
| 10631 | } |
| 10632 | |
| 10633 | @Override |
Jack Yu | 8b766fc | 2022-03-21 09:42:33 -0700 | [diff] [blame] | 10634 | public boolean isMvnoMatched(int slotIndex, int mvnoType, @NonNull String mvnoMatchData) { |
changbetty | ca3d40d | 2020-03-03 16:27:31 +0800 | [diff] [blame] | 10635 | enforceReadPrivilegedPermission("isMvnoMatched"); |
Jack Yu | 8b766fc | 2022-03-21 09:42:33 -0700 | [diff] [blame] | 10636 | return UiccController.getInstance().mvnoMatches(slotIndex, mvnoType, mvnoMatchData); |
changbetty | 7157e9e | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 10637 | } |
| 10638 | |
| 10639 | @Override |
Philip P. Moltmann | d02b737 | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 10640 | public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag, |
| 10641 | IIntegerConsumer pendingSubIdResult) { |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 10642 | if (callingPackage == null) { |
| 10643 | callingPackage = getCurrentPackageName(); |
| 10644 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 10645 | SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp, |
| 10646 | (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE)); |
Philip P. Moltmann | d02b737 | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 10647 | if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag, |
| 10648 | "Sending message")) { |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 10649 | throw new SecurityException("Requires SEND_SMS permission to perform this operation"); |
| 10650 | } |
| 10651 | PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult); |
| 10652 | Intent intent = new Intent(); |
| 10653 | intent.setClass(mApp, PickSmsSubscriptionActivity.class); |
| 10654 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 10655 | // Bring up choose default SMS subscription dialog right now |
| 10656 | intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY, |
| 10657 | PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE); |
| 10658 | mApp.startActivity(intent); |
| 10659 | } |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 10660 | |
| 10661 | @Override |
Ayush Sharma | 787854b | 2022-12-12 14:55:02 +0000 | [diff] [blame] | 10662 | public void showSwitchToManagedProfileDialog() { |
| 10663 | enforceModifyPermission(); |
| 10664 | |
| 10665 | Intent intent = new Intent(); |
| 10666 | intent.setClass(mApp, ErrorDialogActivity.class); |
| 10667 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 10668 | mApp.startActivity(intent); |
| 10669 | } |
| 10670 | |
| 10671 | @Override |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 10672 | public String getMmsUAProfUrl(int subId) { |
| 10673 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 10674 | final long identity = Binder.clearCallingIdentity(); |
| 10675 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 10676 | String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString( |
| 10677 | CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING); |
| 10678 | if (!TextUtils.isEmpty(carrierUAProfUrl)) { |
| 10679 | return carrierUAProfUrl; |
| 10680 | } |
Daniel Bright | ebb4eb7 | 2020-02-18 15:16:33 -0800 | [diff] [blame] | 10681 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 10682 | .getString(com.android.internal.R.string.config_mms_user_agent_profile_url); |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 10683 | } finally { |
| 10684 | Binder.restoreCallingIdentity(identity); |
| 10685 | } |
| 10686 | } |
| 10687 | |
| 10688 | @Override |
| 10689 | public String getMmsUserAgent(int subId) { |
| 10690 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 10691 | final long identity = Binder.clearCallingIdentity(); |
| 10692 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 10693 | String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString( |
| 10694 | CarrierConfigManager.KEY_MMS_USER_AGENT_STRING); |
| 10695 | if (!TextUtils.isEmpty(carrierUserAgent)) { |
| 10696 | return carrierUserAgent; |
| 10697 | } |
Daniel Bright | ebb4eb7 | 2020-02-18 15:16:33 -0800 | [diff] [blame] | 10698 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 10699 | .getString(com.android.internal.R.string.config_mms_user_agent); |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 10700 | } finally { |
| 10701 | Binder.restoreCallingIdentity(identity); |
| 10702 | } |
| 10703 | } |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 10704 | |
| 10705 | @Override |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 10706 | public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) { |
| 10707 | enforceReadPrivilegedPermission("isMobileDataPolicyEnabled"); |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 10708 | |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 10709 | final long identity = Binder.clearCallingIdentity(); |
| 10710 | try { |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 10711 | Phone phone = getPhone(subscriptionId); |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 10712 | if (phone == null) return false; |
| 10713 | |
Ling Ma | f188d50 | 2022-09-16 15:22:36 -0700 | [diff] [blame] | 10714 | return phone.getDataSettingsManager().isMobileDataPolicyEnabled(policy); |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 10715 | } finally { |
| 10716 | Binder.restoreCallingIdentity(identity); |
| 10717 | } |
| 10718 | } |
| 10719 | |
| 10720 | @Override |
Hall Liu | c66bb11 | 2021-02-02 12:09:32 -0800 | [diff] [blame] | 10721 | public void setMobileDataPolicyEnabled(int subscriptionId, int policy, |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 10722 | boolean enabled) { |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 10723 | enforceModifyPermission(); |
| 10724 | |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 10725 | final long identity = Binder.clearCallingIdentity(); |
| 10726 | try { |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 10727 | Phone phone = getPhone(subscriptionId); |
| 10728 | if (phone == null) return; |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 10729 | |
Ling Ma | f188d50 | 2022-09-16 15:22:36 -0700 | [diff] [blame] | 10730 | phone.getDataSettingsManager().setMobileDataPolicy(policy, enabled); |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 10731 | } finally { |
| 10732 | Binder.restoreCallingIdentity(identity); |
| 10733 | } |
| 10734 | } |
| 10735 | |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 10736 | /** |
Hall Liu | 746e03c | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 10737 | * Updates whether conference event package handling is enabled. |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 10738 | * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false} |
| 10739 | * otherwise. |
| 10740 | */ |
| 10741 | @Override |
| 10742 | public void setCepEnabled(boolean isCepEnabled) { |
| 10743 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled"); |
| 10744 | |
| 10745 | final long identity = Binder.clearCallingIdentity(); |
| 10746 | try { |
| 10747 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled); |
| 10748 | for (Phone phone : PhoneFactory.getPhones()) { |
| 10749 | Phone defaultPhone = phone.getImsPhone(); |
| 10750 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 10751 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 10752 | ImsPhoneCallTracker imsPhoneCallTracker = |
| 10753 | (ImsPhoneCallTracker) imsPhone.getCallTracker(); |
| 10754 | imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled); |
| 10755 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone " |
| 10756 | + imsPhone.getMsisdn()); |
| 10757 | } |
| 10758 | } |
| 10759 | } finally { |
| 10760 | Binder.restoreCallingIdentity(identity); |
| 10761 | } |
| 10762 | } |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 10763 | |
| 10764 | /** |
| 10765 | * Notify that an RCS autoconfiguration XML file has been received for provisioning. |
| 10766 | * |
| 10767 | * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed. |
| 10768 | * @param isCompressed The XML file is compressed in gzip format and must be decompressed |
| 10769 | * before being read. |
| 10770 | */ |
| 10771 | @Override |
| 10772 | public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean |
| 10773 | isCompressed) { |
| 10774 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 10775 | mApp, subId, "notifyRcsAutoConfigurationReceived"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10776 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10777 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10778 | } |
| 10779 | if (!isImsAvailableOnDevice()) { |
joonhunshin | 46b49a3 | 2022-12-21 05:33:23 +0000 | [diff] [blame] | 10780 | // ProvisioningManager can not handle ServiceSpecificException. |
| 10781 | // Throw the IllegalStateException and annotate ProvisioningManager. |
| 10782 | throw new IllegalStateException("IMS not available on device."); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10783 | } |
| 10784 | |
| 10785 | final long identity = Binder.clearCallingIdentity(); |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 10786 | try { |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10787 | RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed); |
| 10788 | } finally { |
| 10789 | Binder.restoreCallingIdentity(identity); |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 10790 | } |
| 10791 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 10792 | |
| 10793 | @Override |
| 10794 | public boolean isIccLockEnabled(int subId) { |
| 10795 | enforceReadPrivilegedPermission("isIccLockEnabled"); |
| 10796 | |
| 10797 | // Now that all security checks passes, perform the operation as ourselves. |
| 10798 | final long identity = Binder.clearCallingIdentity(); |
| 10799 | try { |
| 10800 | Phone phone = getPhone(subId); |
| 10801 | if (phone != null && phone.getIccCard() != null) { |
| 10802 | return phone.getIccCard().getIccLockEnabled(); |
| 10803 | } else { |
| 10804 | return false; |
| 10805 | } |
| 10806 | } finally { |
| 10807 | Binder.restoreCallingIdentity(identity); |
| 10808 | } |
| 10809 | } |
| 10810 | |
| 10811 | /** |
| 10812 | * Set the ICC pin lock enabled or disabled. |
| 10813 | * |
| 10814 | * @return an integer representing the status of IccLock enabled or disabled in the following |
| 10815 | * three cases: |
| 10816 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock |
| 10817 | * successfully. |
| 10818 | * - Positive number and zero for remaining password attempts. |
| 10819 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
| 10820 | * |
| 10821 | */ |
| 10822 | @Override |
| 10823 | public int setIccLockEnabled(int subId, boolean enabled, String password) { |
| 10824 | enforceModifyPermission(); |
| 10825 | |
| 10826 | Phone phone = getPhone(subId); |
| 10827 | if (phone == null) { |
| 10828 | return 0; |
| 10829 | } |
| 10830 | // Now that all security checks passes, perform the operation as ourselves. |
| 10831 | final long identity = Binder.clearCallingIdentity(); |
| 10832 | try { |
| 10833 | int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED, |
| 10834 | new Pair<Boolean, String>(enabled, password), phone, null); |
| 10835 | return attemptsRemaining; |
| 10836 | |
| 10837 | } catch (Exception e) { |
| 10838 | Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e); |
| 10839 | } finally { |
| 10840 | Binder.restoreCallingIdentity(identity); |
| 10841 | } |
| 10842 | return 0; |
| 10843 | } |
| 10844 | |
| 10845 | /** |
| 10846 | * Change the ICC password used in ICC pin lock. |
| 10847 | * |
| 10848 | * @return an integer representing the status of IccLock changed in the following three cases: |
| 10849 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully. |
| 10850 | * - Positive number and zero for remaining password attempts. |
| 10851 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
| 10852 | * |
| 10853 | */ |
| 10854 | @Override |
| 10855 | public int changeIccLockPassword(int subId, String oldPassword, String newPassword) { |
| 10856 | enforceModifyPermission(); |
| 10857 | |
| 10858 | Phone phone = getPhone(subId); |
| 10859 | if (phone == null) { |
| 10860 | return 0; |
| 10861 | } |
| 10862 | // Now that all security checks passes, perform the operation as ourselves. |
| 10863 | final long identity = Binder.clearCallingIdentity(); |
| 10864 | try { |
| 10865 | int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD, |
| 10866 | new Pair<String, String>(oldPassword, newPassword), phone, null); |
| 10867 | return attemptsRemaining; |
| 10868 | |
| 10869 | } catch (Exception e) { |
| 10870 | Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e); |
| 10871 | } finally { |
| 10872 | Binder.restoreCallingIdentity(identity); |
| 10873 | } |
| 10874 | return 0; |
| 10875 | } |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 10876 | |
| 10877 | /** |
| 10878 | * Request for receiving user activity notification |
| 10879 | */ |
| 10880 | @Override |
| 10881 | public void requestUserActivityNotification() { |
| 10882 | if (!mNotifyUserActivity.get() |
| 10883 | && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) { |
| 10884 | mNotifyUserActivity.set(true); |
| 10885 | } |
| 10886 | } |
| 10887 | |
| 10888 | /** |
| 10889 | * Called when userActivity is signalled in the power manager. |
| 10890 | * This is safe to call from any thread, with any window manager locks held or not. |
| 10891 | */ |
| 10892 | @Override |
| 10893 | public void userActivity() { |
| 10894 | // *************************************** |
| 10895 | // * Inherited from PhoneWindowManager * |
| 10896 | // *************************************** |
| 10897 | // THIS IS CALLED FROM DEEP IN THE POWER MANAGER |
| 10898 | // WITH ITS LOCKS HELD. |
| 10899 | // |
| 10900 | // This code must be VERY careful about the locks |
| 10901 | // it acquires. |
| 10902 | // In fact, the current code acquires way too many, |
| 10903 | // and probably has lurking deadlocks. |
| 10904 | |
| 10905 | if (Binder.getCallingUid() != Process.SYSTEM_UID) { |
| 10906 | throw new SecurityException("Only the OS may call notifyUserActivity()"); |
| 10907 | } |
| 10908 | |
| 10909 | if (mNotifyUserActivity.getAndSet(false)) { |
| 10910 | mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY, |
| 10911 | USER_ACTIVITY_NOTIFICATION_DELAY); |
| 10912 | } |
| 10913 | } |
Malcolm Chen | 4639c56 | 2020-04-13 11:59:40 -0700 | [diff] [blame] | 10914 | |
| 10915 | @Override |
| 10916 | public boolean canConnectTo5GInDsdsMode() { |
| 10917 | return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode); |
| 10918 | } |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 10919 | |
| 10920 | @Override |
| 10921 | public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage, |
| 10922 | String callingFeatureId) { |
| 10923 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 10924 | mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) { |
| 10925 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 10926 | } |
| 10927 | |
| 10928 | Phone phone = getPhone(subId); |
| 10929 | if (phone == null) { |
| 10930 | throw new RuntimeException("phone is not available"); |
| 10931 | } |
| 10932 | // Now that all security checks passes, perform the operation as ourselves. |
| 10933 | final long identity = Binder.clearCallingIdentity(); |
| 10934 | try { |
| 10935 | return phone.getEquivalentHomePlmns(); |
| 10936 | } finally { |
| 10937 | Binder.restoreCallingIdentity(identity); |
| 10938 | } |
| 10939 | } |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 10940 | |
| 10941 | @Override |
| 10942 | public boolean isRadioInterfaceCapabilitySupported( |
Daniel Bright | 95a4c1f | 2021-02-11 09:57:16 -0800 | [diff] [blame] | 10943 | final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) { |
| 10944 | Set<String> radioInterfaceCapabilities = |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 10945 | mRadioInterfaceCapabilities.getCapabilities(); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 10946 | if (radioInterfaceCapabilities == null) { |
| 10947 | throw new RuntimeException("radio interface capabilities are not available"); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 10948 | } |
Daniel Bright | 95a4c1f | 2021-02-11 09:57:16 -0800 | [diff] [blame] | 10949 | return radioInterfaceCapabilities.contains(capability); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 10950 | } |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10951 | |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 10952 | @Override |
| 10953 | public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl, |
| 10954 | UaSecurityProtocolIdentifier securityProtocol, |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10955 | boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) { |
| 10956 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 10957 | Binder.getCallingUid(), "bootstrapAuthenticationRequest", |
| 10958 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 10959 | Manifest.permission.MODIFY_PHONE_STATE); |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 10960 | if (DBG) { |
| 10961 | log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:" |
| 10962 | + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol |
| 10963 | + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback); |
| 10964 | } |
| 10965 | |
| 10966 | if (!SubscriptionManager.isValidSubscriptionId(subId) |
| 10967 | || appType < TelephonyManager.APPTYPE_UNKNOWN |
| 10968 | || appType > TelephonyManager.APPTYPE_ISIM |
| 10969 | || nafUrl == null || securityProtocol == null || callback == null) { |
| 10970 | Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters"); |
| 10971 | if (callback != null) { |
| 10972 | try { |
| 10973 | callback.onAuthenticationFailure( |
| 10974 | 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED); |
| 10975 | } catch (RemoteException exception) { |
| 10976 | log("Fail to notify onAuthenticationFailure due to " + exception); |
| 10977 | } |
| 10978 | return; |
| 10979 | } |
| 10980 | } |
| 10981 | |
| 10982 | final long token = Binder.clearCallingIdentity(); |
| 10983 | try { |
| 10984 | getGbaManager(subId).bootstrapAuthenticationRequest( |
| 10985 | new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(), |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 10986 | forceBootStrapping, callback)); |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 10987 | } finally { |
| 10988 | Binder.restoreCallingIdentity(token); |
| 10989 | } |
| 10990 | } |
| 10991 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10992 | /** |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10993 | * Attempts to set the radio power state for all phones for thermal reason. |
| 10994 | * This does not guarantee that the |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10995 | * requested radio power state will actually be set. See {@link |
| 10996 | * PhoneInternalInterface#setRadioPowerForReason} for more details. |
| 10997 | * |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10998 | * @param enable {@code true} if trying to turn radio on. |
| 10999 | * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code |
| 11000 | * false}. |
| 11001 | */ |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 11002 | private boolean setRadioPowerForThermal(boolean enable) { |
| 11003 | boolean isPhoneAvailable = false; |
| 11004 | for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) { |
| 11005 | Phone phone = PhoneFactory.getPhone(i); |
| 11006 | if (phone != null) { |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 11007 | phone.setRadioPowerForReason(enable, TelephonyManager.RADIO_POWER_REASON_THERMAL); |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 11008 | isPhoneAvailable = true; |
| 11009 | } |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11010 | } |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 11011 | |
| 11012 | // return true if successfully informed the phone object about the thermal radio power |
| 11013 | // request. |
| 11014 | return isPhoneAvailable; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11015 | } |
| 11016 | |
| 11017 | private int handleDataThrottlingRequest(int subId, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 11018 | DataThrottlingRequest dataThrottlingRequest, String callingPackage) { |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 11019 | boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported( |
| 11020 | TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING); |
| 11021 | if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction() |
| 11022 | != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) { |
| 11023 | throw new IllegalArgumentException("modem does not support data throttling"); |
| 11024 | } |
| 11025 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11026 | // Ensure that radio is on. If not able to power on due to phone being unavailable, return |
| 11027 | // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 11028 | if (!setRadioPowerForThermal(true)) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11029 | return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 11030 | } |
| 11031 | |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 11032 | setDataEnabledForReason( |
| 11033 | subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true, callingPackage); |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11034 | |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 11035 | if (isDataThrottlingSupported) { |
| 11036 | int thermalMitigationResult = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 11037 | (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId); |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 11038 | if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) { |
| 11039 | throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS"); |
| 11040 | } else if (thermalMitigationResult |
| 11041 | == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) { |
Jack Nudelman | 760d096 | 2021-05-20 13:57:30 -0700 | [diff] [blame] | 11042 | log("Modem likely does not support data throttling on secondary carrier. Data " + |
| 11043 | "throttling action = " + dataThrottlingRequest.getDataThrottlingAction()); |
| 11044 | return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 11045 | } |
| 11046 | return thermalMitigationResult; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11047 | } |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 11048 | |
| 11049 | return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11050 | } |
| 11051 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 11052 | private static List<String> getThermalMitigationAllowlist(Context context) { |
| 11053 | if (sThermalMitigationAllowlistedPackages.isEmpty()) { |
| 11054 | for (String pckg : context.getResources() |
| 11055 | .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) { |
| 11056 | sThermalMitigationAllowlistedPackages.add(pckg); |
| 11057 | } |
| 11058 | } |
| 11059 | |
| 11060 | return sThermalMitigationAllowlistedPackages; |
| 11061 | } |
| 11062 | |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 11063 | private boolean isAnyPhoneInEmergencyState() { |
| 11064 | TelecomManager tm = mApp.getSystemService(TelecomManager.class); |
| 11065 | if (tm.isInEmergencyCall()) { |
| 11066 | Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call"); |
| 11067 | return true; |
| 11068 | } |
| 11069 | for (Phone phone : PhoneFactory.getPhones()) { |
| 11070 | if (phone.isInEmergencySmsMode() || phone.isInEcm()) { |
| 11071 | Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = " |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 11072 | + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = " |
| 11073 | + phone.isInEcm()); |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 11074 | return true; |
| 11075 | } |
| 11076 | } |
| 11077 | |
| 11078 | return false; |
| 11079 | } |
| 11080 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 11081 | /** |
| 11082 | * Used by shell commands to add an authorized package name for thermal mitigation. |
| 11083 | * @param packageName name of package to be allowlisted |
| 11084 | * @param context |
| 11085 | */ |
| 11086 | static void addPackageToThermalMitigationAllowlist(String packageName, Context context) { |
| 11087 | sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context); |
| 11088 | sThermalMitigationAllowlistedPackages.add(packageName); |
| 11089 | } |
| 11090 | |
| 11091 | /** |
| 11092 | * Used by shell commands to remove an authorized package name for thermal mitigation. |
| 11093 | * @param packageName name of package to remove from allowlist |
| 11094 | * @param context |
| 11095 | */ |
| 11096 | static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) { |
| 11097 | sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context); |
| 11098 | sThermalMitigationAllowlistedPackages.remove(packageName); |
| 11099 | } |
| 11100 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11101 | /** |
| 11102 | * Thermal mitigation request to control functionalities at modem. |
| 11103 | * |
| 11104 | * @param subId the id of the subscription. |
| 11105 | * @param thermalMitigationRequest holds all necessary information to be passed down to modem. |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 11106 | * @param callingPackage the package name of the calling package. |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11107 | * |
| 11108 | * @return thermalMitigationResult enum as defined in android.telephony.Annotation. |
| 11109 | */ |
| 11110 | @Override |
| 11111 | @ThermalMitigationResult |
| 11112 | public int sendThermalMitigationRequest( |
| 11113 | int subId, |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 11114 | ThermalMitigationRequest thermalMitigationRequest, |
| 11115 | String callingPackage) throws IllegalArgumentException { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11116 | enforceModifyPermission(); |
| 11117 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 11118 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 11119 | if (!getThermalMitigationAllowlist(getDefaultPhone().getContext()) |
| 11120 | .contains(callingPackage)) { |
| 11121 | throw new SecurityException("Calling package must be configured in the device config. " |
| 11122 | + "calling package: " + callingPackage); |
| 11123 | } |
| 11124 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11125 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 11126 | final long identity = Binder.clearCallingIdentity(); |
| 11127 | |
| 11128 | int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR; |
| 11129 | try { |
| 11130 | int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction(); |
| 11131 | switch (thermalMitigationAction) { |
| 11132 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING: |
| 11133 | thermalMitigationResult = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 11134 | handleDataThrottlingRequest(subId, |
| 11135 | thermalMitigationRequest.getDataThrottlingRequest(), |
| 11136 | callingPackage); |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11137 | break; |
| 11138 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY: |
| 11139 | if (thermalMitigationRequest.getDataThrottlingRequest() != null) { |
| 11140 | throw new IllegalArgumentException("dataThrottlingRequest must be null for " |
| 11141 | + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY"); |
| 11142 | } |
| 11143 | |
| 11144 | // Ensure that radio is on. If not able to power on due to phone being |
| 11145 | // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 11146 | if (!setRadioPowerForThermal(true)) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11147 | thermalMitigationResult = |
| 11148 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 11149 | break; |
| 11150 | } |
| 11151 | |
| 11152 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 11153 | false, callingPackage); |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11154 | thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 11155 | break; |
| 11156 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF: |
| 11157 | if (thermalMitigationRequest.getDataThrottlingRequest() != null) { |
| 11158 | throw new IllegalArgumentException("dataThrottlingRequest must be null for" |
| 11159 | + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF"); |
| 11160 | } |
| 11161 | |
| 11162 | TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null); |
| 11163 | if (registry != null) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11164 | Phone phone = getPhone(subId); |
| 11165 | if (phone == null) { |
| 11166 | thermalMitigationResult = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 11167 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11168 | break; |
| 11169 | } |
| 11170 | |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 11171 | TelephonyConnectionService service = |
| 11172 | registry.getTelephonyConnectionService(); |
Jack Nudelman | b30ac30 | 2021-06-17 15:39:58 -0700 | [diff] [blame] | 11173 | if (service != null && service.isEmergencyCallPending()) { |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 11174 | Log.e(LOG_TAG, "An emergency call is pending"); |
| 11175 | thermalMitigationResult = |
| 11176 | TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE; |
| 11177 | break; |
| 11178 | } else if (isAnyPhoneInEmergencyState()) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11179 | thermalMitigationResult = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 11180 | TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11181 | break; |
| 11182 | } |
| 11183 | } else { |
| 11184 | thermalMitigationResult = |
| 11185 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 11186 | break; |
| 11187 | } |
| 11188 | |
| 11189 | // Turn radio off. If not able to power off due to phone being unavailable, |
| 11190 | // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 11191 | if (!setRadioPowerForThermal(false)) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11192 | thermalMitigationResult = |
| 11193 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 11194 | break; |
| 11195 | } |
| 11196 | thermalMitigationResult = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 11197 | TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11198 | break; |
| 11199 | default: |
| 11200 | throw new IllegalArgumentException("the requested thermalMitigationAction does " |
| 11201 | + "not exist. Requested action: " + thermalMitigationAction); |
| 11202 | } |
| 11203 | } catch (IllegalArgumentException e) { |
| 11204 | throw e; |
| 11205 | } catch (Exception e) { |
| 11206 | Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e); |
| 11207 | thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 11208 | } finally { |
| 11209 | Binder.restoreCallingIdentity(identity); |
| 11210 | } |
| 11211 | |
| 11212 | if (DBG) { |
| 11213 | log("thermalMitigationRequest returning with thermalMitigationResult: " |
| 11214 | + thermalMitigationResult); |
| 11215 | } |
| 11216 | |
| 11217 | return thermalMitigationResult; |
| 11218 | } |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 11219 | |
| 11220 | /** |
| 11221 | * Set the GbaService Package Name that Telephony will bind to. |
| 11222 | * |
| 11223 | * @param subId The sim that the GbaService is associated with. |
| 11224 | * @param packageName The name of the package to be replaced with. |
| 11225 | * @return true if setting the GbaService to bind to succeeded, false if it did not. |
| 11226 | */ |
| 11227 | @Override |
| 11228 | public boolean setBoundGbaServiceOverride(int subId, String packageName) { |
| 11229 | enforceModifyPermission(); |
| 11230 | |
| 11231 | final long identity = Binder.clearCallingIdentity(); |
| 11232 | try { |
| 11233 | return getGbaManager(subId).overrideServicePackage(packageName); |
| 11234 | } finally { |
| 11235 | Binder.restoreCallingIdentity(identity); |
| 11236 | } |
| 11237 | } |
| 11238 | |
| 11239 | /** |
| 11240 | * Return the package name of the currently bound GbaService. |
| 11241 | * |
| 11242 | * @param subId The sim that the GbaService is associated with. |
| 11243 | * @return the package name of the GbaService configuration, null if GBA is not supported. |
| 11244 | */ |
| 11245 | @Override |
| 11246 | public String getBoundGbaService(int subId) { |
| 11247 | enforceReadPrivilegedPermission("getBoundGbaServicePackage"); |
| 11248 | |
| 11249 | final long identity = Binder.clearCallingIdentity(); |
| 11250 | try { |
| 11251 | return getGbaManager(subId).getServicePackage(); |
| 11252 | } finally { |
| 11253 | Binder.restoreCallingIdentity(identity); |
| 11254 | } |
| 11255 | } |
| 11256 | |
| 11257 | /** |
| 11258 | * Set the release time for telephony to unbind GbaService. |
| 11259 | * |
| 11260 | * @param subId The sim that the GbaService is associated with. |
| 11261 | * @param interval The release time to unbind GbaService by millisecond. |
| 11262 | * @return true if setting the GbaService to bind to succeeded, false if it did not. |
| 11263 | */ |
| 11264 | @Override |
| 11265 | public boolean setGbaReleaseTimeOverride(int subId, int interval) { |
| 11266 | enforceModifyPermission(); |
| 11267 | |
| 11268 | final long identity = Binder.clearCallingIdentity(); |
| 11269 | try { |
| 11270 | return getGbaManager(subId).overrideReleaseTime(interval); |
| 11271 | } finally { |
| 11272 | Binder.restoreCallingIdentity(identity); |
| 11273 | } |
| 11274 | } |
| 11275 | |
| 11276 | /** |
| 11277 | * Return the release time for telephony to unbind GbaService. |
| 11278 | * |
| 11279 | * @param subId The sim that the GbaService is associated with. |
| 11280 | * @return The release time to unbind GbaService by millisecond. |
| 11281 | */ |
| 11282 | @Override |
| 11283 | public int getGbaReleaseTime(int subId) { |
| 11284 | enforceReadPrivilegedPermission("getGbaReleaseTime"); |
| 11285 | |
| 11286 | final long identity = Binder.clearCallingIdentity(); |
| 11287 | try { |
| 11288 | return getGbaManager(subId).getReleaseTime(); |
| 11289 | } finally { |
| 11290 | Binder.restoreCallingIdentity(identity); |
| 11291 | } |
| 11292 | } |
| 11293 | |
| 11294 | private GbaManager getGbaManager(int subId) { |
| 11295 | GbaManager instance = GbaManager.getInstance(subId); |
| 11296 | if (instance == null) { |
| 11297 | String packageName = mApp.getResources().getString(R.string.config_gba_package); |
| 11298 | int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time); |
| 11299 | instance = GbaManager.make(mApp, subId, packageName, releaseTime); |
| 11300 | } |
| 11301 | return instance; |
| 11302 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11303 | |
| 11304 | /** |
| 11305 | * indicate whether the device and the carrier can support |
| 11306 | * RCS VoLTE single registration. |
| 11307 | */ |
| 11308 | @Override |
| 11309 | public boolean isRcsVolteSingleRegistrationCapable(int subId) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 11310 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 11311 | Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable", |
| 11312 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 11313 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11314 | |
| 11315 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 11316 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 11317 | } |
| 11318 | |
| 11319 | final long identity = Binder.clearCallingIdentity(); |
| 11320 | try { |
| 11321 | RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance(); |
| 11322 | if (rpm != null) { |
Hui Wang | 67af90e | 2021-06-04 16:57:15 -0700 | [diff] [blame] | 11323 | Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId); |
| 11324 | if (isCapable != null) { |
| 11325 | return isCapable; |
| 11326 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11327 | } |
Hui Wang | 67af90e | 2021-06-04 16:57:15 -0700 | [diff] [blame] | 11328 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE, |
| 11329 | "service is temporarily unavailable."); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11330 | } finally { |
| 11331 | Binder.restoreCallingIdentity(identity); |
| 11332 | } |
| 11333 | } |
| 11334 | |
| 11335 | /** |
| 11336 | * Register RCS provisioning callback. |
| 11337 | */ |
| 11338 | @Override |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 11339 | public void registerRcsProvisioningCallback(int subId, |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11340 | IRcsConfigCallback callback) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 11341 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 11342 | Binder.getCallingUid(), "registerRcsProvisioningCallback", |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 11343 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 11344 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11345 | |
| 11346 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 11347 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 11348 | } |
| 11349 | if (!isImsAvailableOnDevice()) { |
| 11350 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 11351 | "IMS not available on device."); |
| 11352 | } |
| 11353 | |
| 11354 | final long identity = Binder.clearCallingIdentity(); |
| 11355 | try { |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 11356 | if (!RcsProvisioningMonitor.getInstance() |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 11357 | .registerRcsProvisioningCallback(subId, callback)) { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 11358 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION, |
| 11359 | "Active subscription not found."); |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 11360 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11361 | } finally { |
| 11362 | Binder.restoreCallingIdentity(identity); |
| 11363 | } |
| 11364 | } |
| 11365 | |
| 11366 | /** |
| 11367 | * Unregister RCS provisioning callback. |
| 11368 | */ |
| 11369 | @Override |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 11370 | public void unregisterRcsProvisioningCallback(int subId, |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11371 | IRcsConfigCallback callback) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 11372 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 11373 | Binder.getCallingUid(), "unregisterRcsProvisioningCallback", |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 11374 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 11375 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11376 | |
| 11377 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 11378 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 11379 | } |
| 11380 | if (!isImsAvailableOnDevice()) { |
joonhunshin | 46b49a3 | 2022-12-21 05:33:23 +0000 | [diff] [blame] | 11381 | // operation failed silently |
| 11382 | Rlog.w(LOG_TAG, "IMS not available on device."); |
| 11383 | return; |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11384 | } |
| 11385 | |
| 11386 | final long identity = Binder.clearCallingIdentity(); |
| 11387 | try { |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 11388 | RcsProvisioningMonitor.getInstance() |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 11389 | .unregisterRcsProvisioningCallback(subId, callback); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11390 | } finally { |
| 11391 | Binder.restoreCallingIdentity(identity); |
| 11392 | } |
| 11393 | } |
| 11394 | |
| 11395 | /** |
| 11396 | * trigger RCS reconfiguration. |
| 11397 | */ |
| 11398 | public void triggerRcsReconfiguration(int subId) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 11399 | TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(), |
| 11400 | "triggerRcsReconfiguration", |
| 11401 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11402 | |
| 11403 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 11404 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 11405 | } |
| 11406 | if (!isImsAvailableOnDevice()) { |
joonhunshin | 46b49a3 | 2022-12-21 05:33:23 +0000 | [diff] [blame] | 11407 | // ProvisioningManager can not handle ServiceSpecificException. |
| 11408 | // Throw the IllegalStateException and annotate ProvisioningManager. |
| 11409 | throw new IllegalStateException("IMS not available on device."); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11410 | } |
| 11411 | |
| 11412 | final long identity = Binder.clearCallingIdentity(); |
| 11413 | try { |
| 11414 | RcsProvisioningMonitor.getInstance().requestReconfig(subId); |
| 11415 | } finally { |
| 11416 | Binder.restoreCallingIdentity(identity); |
| 11417 | } |
| 11418 | } |
| 11419 | |
| 11420 | /** |
| 11421 | * Provide the client configuration parameters of the RCS application. |
| 11422 | */ |
| 11423 | public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 11424 | TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(), |
| 11425 | "setRcsClientConfiguration", |
| 11426 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11427 | |
| 11428 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 11429 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 11430 | } |
| 11431 | if (!isImsAvailableOnDevice()) { |
| 11432 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 11433 | "IMS not available on device."); |
| 11434 | } |
| 11435 | |
| 11436 | final long identity = Binder.clearCallingIdentity(); |
| 11437 | |
| 11438 | try { |
| 11439 | IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS); |
| 11440 | if (configBinder == null) { |
| 11441 | Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration"); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 11442 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION, |
| 11443 | "could not find the requested subscription"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11444 | } else { |
| 11445 | configBinder.setRcsClientConfiguration(rcc); |
| 11446 | } |
joonhunshin | 3e15424 | 2021-09-17 06:33:39 +0000 | [diff] [blame] | 11447 | |
| 11448 | RcsStats.getInstance().onRcsClientProvisioningStats(subId, |
| 11449 | RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11450 | } catch (RemoteException e) { |
| 11451 | Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage()); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 11452 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE, |
| 11453 | "service is temporarily unavailable."); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11454 | } finally { |
| 11455 | Binder.restoreCallingIdentity(identity); |
| 11456 | } |
| 11457 | } |
| 11458 | |
| 11459 | /** |
Hui Wang | baaee6a | 2021-02-19 20:45:36 -0800 | [diff] [blame] | 11460 | * Enables or disables the test mode for RCS VoLTE single registration. |
| 11461 | */ |
| 11462 | @Override |
| 11463 | public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) { |
| 11464 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11465 | "setRcsSingleRegistrationTestModeEnabled"); |
| 11466 | |
| 11467 | RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled); |
| 11468 | } |
| 11469 | |
| 11470 | /** |
| 11471 | * Gets the test mode for RCS VoLTE single registration. |
| 11472 | */ |
| 11473 | @Override |
| 11474 | public boolean getRcsSingleRegistrationTestModeEnabled() { |
| 11475 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11476 | "getRcsSingleRegistrationTestModeEnabled"); |
| 11477 | |
| 11478 | return RcsProvisioningMonitor.getInstance().getTestModeEnabled(); |
| 11479 | } |
| 11480 | |
| 11481 | /** |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11482 | * Overrides the config of RCS VoLTE single registration enabled for the device. |
| 11483 | */ |
| 11484 | @Override |
| 11485 | public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) { |
| 11486 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11487 | "setDeviceSingleRegistrationEnabledOverride"); |
| 11488 | enforceModifyPermission(); |
| 11489 | |
| 11490 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 11491 | : Boolean.parseBoolean(enabledStr); |
| 11492 | RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled); |
Brad Ebinger | 49a72b4 | 2021-01-29 00:55:24 +0000 | [diff] [blame] | 11493 | mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11494 | } |
| 11495 | |
| 11496 | /** |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 11497 | * Sends a device to device communication message. Only usable via shell. |
| 11498 | * @param message message to send. |
| 11499 | * @param value message value. |
| 11500 | */ |
| 11501 | @Override |
| 11502 | public void sendDeviceToDeviceMessage(int message, int value) { |
| 11503 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
Tyler Gunn | babbda0 | 2021-02-10 11:05:02 -0800 | [diff] [blame] | 11504 | "sendDeviceToDeviceMessage"); |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 11505 | enforceModifyPermission(); |
| 11506 | |
| 11507 | final long identity = Binder.clearCallingIdentity(); |
| 11508 | try { |
| 11509 | TelephonyConnectionService service = |
| 11510 | TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService(); |
| 11511 | if (service == null) { |
| 11512 | Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call."); |
| 11513 | return; |
| 11514 | } |
| 11515 | service.sendTestDeviceToDeviceMessage(message, value); |
| 11516 | } finally { |
| 11517 | Binder.restoreCallingIdentity(identity); |
| 11518 | } |
| 11519 | } |
| 11520 | |
Tyler Gunn | babbda0 | 2021-02-10 11:05:02 -0800 | [diff] [blame] | 11521 | /** |
| 11522 | * Sets the specified device to device transport active. |
| 11523 | * @param transport The transport to set active. |
| 11524 | */ |
| 11525 | @Override |
| 11526 | public void setActiveDeviceToDeviceTransport(@NonNull String transport) { |
| 11527 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11528 | "setActiveDeviceToDeviceTransport"); |
| 11529 | enforceModifyPermission(); |
| 11530 | |
| 11531 | final long identity = Binder.clearCallingIdentity(); |
| 11532 | try { |
| 11533 | TelephonyConnectionService service = |
| 11534 | TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService(); |
| 11535 | if (service == null) { |
| 11536 | Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call."); |
| 11537 | return; |
| 11538 | } |
| 11539 | service.setActiveDeviceToDeviceTransport(transport); |
| 11540 | } finally { |
| 11541 | Binder.restoreCallingIdentity(identity); |
| 11542 | } |
| 11543 | } |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 11544 | |
Tyler Gunn | d433926 | 2021-05-03 14:46:49 -0700 | [diff] [blame] | 11545 | @Override |
| 11546 | public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) { |
| 11547 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11548 | "setDeviceToDeviceForceEnabled"); |
| 11549 | |
| 11550 | final long identity = Binder.clearCallingIdentity(); |
| 11551 | try { |
| 11552 | Arrays.stream(PhoneFactory.getPhones()).forEach( |
| 11553 | p -> { |
| 11554 | Phone thePhone = p.getImsPhone(); |
| 11555 | if (thePhone != null && thePhone instanceof ImsPhone) { |
| 11556 | ImsPhone imsPhone = (ImsPhone) thePhone; |
| 11557 | CallTracker tracker = imsPhone.getCallTracker(); |
| 11558 | if (tracker != null && tracker instanceof ImsPhoneCallTracker) { |
| 11559 | ImsPhoneCallTracker imsPhoneCallTracker = |
| 11560 | (ImsPhoneCallTracker) tracker; |
| 11561 | imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled); |
| 11562 | } |
| 11563 | } |
| 11564 | } |
| 11565 | ); |
| 11566 | } finally { |
| 11567 | Binder.restoreCallingIdentity(identity); |
| 11568 | } |
| 11569 | } |
| 11570 | |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 11571 | /** |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11572 | * Gets the config of RCS VoLTE single registration enabled for the device. |
| 11573 | */ |
| 11574 | @Override |
| 11575 | public boolean getDeviceSingleRegistrationEnabled() { |
| 11576 | enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled"); |
| 11577 | return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled(); |
| 11578 | } |
| 11579 | |
| 11580 | /** |
| 11581 | * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription. |
| 11582 | */ |
| 11583 | @Override |
| 11584 | public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) { |
| 11585 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11586 | "setCarrierSingleRegistrationEnabledOverride"); |
| 11587 | enforceModifyPermission(); |
| 11588 | |
| 11589 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 11590 | : Boolean.parseBoolean(enabledStr); |
| 11591 | return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled( |
| 11592 | subId, enabled); |
| 11593 | } |
| 11594 | |
| 11595 | /** |
| 11596 | * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription. |
| 11597 | */ |
| 11598 | @Override |
| 11599 | public boolean getCarrierSingleRegistrationEnabled(int subId) { |
| 11600 | enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled"); |
| 11601 | return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId); |
| 11602 | } |
Chiachang Wang | d6d3477 | 2020-12-22 11:38:27 +0800 | [diff] [blame] | 11603 | |
| 11604 | /** |
Hui Wang | b647abe | 2021-02-26 09:33:38 -0800 | [diff] [blame] | 11605 | * Overrides the ims feature validation result |
| 11606 | */ |
| 11607 | @Override |
| 11608 | public boolean setImsFeatureValidationOverride(int subId, String enabledStr) { |
| 11609 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11610 | "setImsFeatureValidationOverride"); |
| 11611 | |
| 11612 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 11613 | : Boolean.parseBoolean(enabledStr); |
| 11614 | return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation( |
| 11615 | subId, enabled); |
| 11616 | } |
| 11617 | |
| 11618 | /** |
| 11619 | * Gets the ims feature validation override value |
| 11620 | */ |
| 11621 | @Override |
| 11622 | public boolean getImsFeatureValidationOverride(int subId) { |
| 11623 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11624 | "getImsFeatureValidationOverride"); |
| 11625 | return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId); |
| 11626 | } |
| 11627 | |
| 11628 | /** |
Chiachang Wang | d6d3477 | 2020-12-22 11:38:27 +0800 | [diff] [blame] | 11629 | * Get the mobile provisioning url that is used to launch a browser to allow users to manage |
| 11630 | * their mobile plan. |
| 11631 | */ |
| 11632 | @Override |
| 11633 | public String getMobileProvisioningUrl() { |
| 11634 | enforceReadPrivilegedPermission("getMobileProvisioningUrl"); |
| 11635 | final long identity = Binder.clearCallingIdentity(); |
| 11636 | try { |
| 11637 | return getDefaultPhone().getMobileProvisioningUrl(); |
| 11638 | } finally { |
| 11639 | Binder.restoreCallingIdentity(identity); |
| 11640 | } |
| 11641 | } |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11642 | |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 11643 | /** |
calvinpan | e4a8a1d | 2021-01-25 13:51:18 +0800 | [diff] [blame] | 11644 | * Get the EAB contact from the EAB database. |
| 11645 | */ |
| 11646 | @Override |
| 11647 | public String getContactFromEab(String contact) { |
| 11648 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab"); |
| 11649 | enforceModifyPermission(); |
| 11650 | final long identity = Binder.clearCallingIdentity(); |
| 11651 | try { |
| 11652 | return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact); |
| 11653 | } finally { |
| 11654 | Binder.restoreCallingIdentity(identity); |
| 11655 | } |
| 11656 | } |
| 11657 | |
| 11658 | /** |
Calvin Pan | a143432 | 2021-07-01 19:27:01 +0800 | [diff] [blame] | 11659 | * Get the EAB capability from the EAB database. |
| 11660 | */ |
| 11661 | @Override |
| 11662 | public String getCapabilityFromEab(String contact) { |
| 11663 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab"); |
| 11664 | enforceModifyPermission(); |
| 11665 | final long identity = Binder.clearCallingIdentity(); |
| 11666 | try { |
| 11667 | return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact); |
| 11668 | } finally { |
| 11669 | Binder.restoreCallingIdentity(identity); |
| 11670 | } |
| 11671 | } |
| 11672 | |
| 11673 | /** |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 11674 | * Remove the EAB contacts from the EAB database. |
| 11675 | */ |
| 11676 | @Override |
| 11677 | public int removeContactFromEab(int subId, String contacts) { |
| 11678 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab"); |
| 11679 | enforceModifyPermission(); |
| 11680 | final long identity = Binder.clearCallingIdentity(); |
| 11681 | try { |
| 11682 | return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext()); |
| 11683 | } finally { |
| 11684 | Binder.restoreCallingIdentity(identity); |
| 11685 | } |
| 11686 | } |
| 11687 | |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11688 | @Override |
James.cf Lin | 4b784aa | 2021-01-31 03:25:15 +0800 | [diff] [blame] | 11689 | public boolean getDeviceUceEnabled() { |
| 11690 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled"); |
| 11691 | final long identity = Binder.clearCallingIdentity(); |
| 11692 | try { |
| 11693 | return mApp.getDeviceUceEnabled(); |
| 11694 | } finally { |
| 11695 | Binder.restoreCallingIdentity(identity); |
| 11696 | } |
| 11697 | } |
| 11698 | |
| 11699 | @Override |
| 11700 | public void setDeviceUceEnabled(boolean isEnabled) { |
| 11701 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled"); |
| 11702 | final long identity = Binder.clearCallingIdentity(); |
| 11703 | try { |
| 11704 | mApp.setDeviceUceEnabled(isEnabled); |
| 11705 | } finally { |
| 11706 | Binder.restoreCallingIdentity(identity); |
| 11707 | } |
| 11708 | } |
| 11709 | |
Brad Ebinger | 14d467f | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 11710 | /** |
| 11711 | * Add new feature tags to the Set used to calculate the capabilities in PUBLISH. |
| 11712 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 11713 | */ |
| 11714 | // Used for SHELL command only right now. |
| 11715 | @Override |
| 11716 | public RcsContactUceCapability addUceRegistrationOverrideShell(int subId, |
| 11717 | List<String> featureTags) { |
| 11718 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11719 | "addUceRegistrationOverrideShell"); |
| 11720 | final long identity = Binder.clearCallingIdentity(); |
| 11721 | try { |
| 11722 | return mApp.imsRcsController.addUceRegistrationOverrideShell(subId, |
| 11723 | new ArraySet<>(featureTags)); |
| 11724 | } catch (ImsException e) { |
| 11725 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 11726 | } finally { |
| 11727 | Binder.restoreCallingIdentity(identity); |
| 11728 | } |
| 11729 | } |
| 11730 | |
| 11731 | /** |
| 11732 | * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH. |
| 11733 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 11734 | */ |
| 11735 | // Used for SHELL command only right now. |
| 11736 | @Override |
| 11737 | public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId, |
| 11738 | List<String> featureTags) { |
| 11739 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11740 | "removeUceRegistrationOverrideShell"); |
| 11741 | final long identity = Binder.clearCallingIdentity(); |
| 11742 | try { |
| 11743 | return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId, |
| 11744 | new ArraySet<>(featureTags)); |
| 11745 | } catch (ImsException e) { |
| 11746 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 11747 | } finally { |
| 11748 | Binder.restoreCallingIdentity(identity); |
| 11749 | } |
| 11750 | } |
| 11751 | |
| 11752 | /** |
| 11753 | * Clear all overrides in the Set used to calculate the capabilities in PUBLISH. |
| 11754 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 11755 | */ |
| 11756 | // Used for SHELL command only right now. |
| 11757 | @Override |
| 11758 | public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) { |
| 11759 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11760 | "clearUceRegistrationOverrideShell"); |
| 11761 | final long identity = Binder.clearCallingIdentity(); |
| 11762 | try { |
| 11763 | return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId); |
| 11764 | } catch (ImsException e) { |
| 11765 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 11766 | } finally { |
| 11767 | Binder.restoreCallingIdentity(identity); |
| 11768 | } |
| 11769 | } |
| 11770 | |
| 11771 | /** |
| 11772 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 11773 | */ |
| 11774 | // Used for SHELL command only right now. |
| 11775 | @Override |
| 11776 | public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) { |
| 11777 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11778 | "getLatestRcsContactUceCapabilityShell"); |
| 11779 | final long identity = Binder.clearCallingIdentity(); |
| 11780 | try { |
| 11781 | return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId); |
| 11782 | } catch (ImsException e) { |
| 11783 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 11784 | } finally { |
| 11785 | Binder.restoreCallingIdentity(identity); |
| 11786 | } |
| 11787 | } |
| 11788 | |
| 11789 | /** |
| 11790 | * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the |
| 11791 | * device does not have an active PUBLISH. |
| 11792 | */ |
| 11793 | // Used for SHELL command only right now. |
| 11794 | @Override |
| 11795 | public String getLastUcePidfXmlShell(int subId) { |
| 11796 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml"); |
| 11797 | final long identity = Binder.clearCallingIdentity(); |
| 11798 | try { |
| 11799 | return mApp.imsRcsController.getLastUcePidfXmlShell(subId); |
| 11800 | } catch (ImsException e) { |
| 11801 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 11802 | } finally { |
| 11803 | Binder.restoreCallingIdentity(identity); |
| 11804 | } |
| 11805 | } |
| 11806 | |
James.cf Lin | e8713a4 | 2021-04-29 16:04:26 +0800 | [diff] [blame] | 11807 | /** |
| 11808 | * Remove UCE requests cannot be sent to the network status. |
| 11809 | */ |
| 11810 | // Used for SHELL command only right now. |
| 11811 | @Override |
| 11812 | public boolean removeUceRequestDisallowedStatus(int subId) { |
| 11813 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus"); |
| 11814 | final long identity = Binder.clearCallingIdentity(); |
| 11815 | try { |
| 11816 | return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId); |
| 11817 | } catch (ImsException e) { |
| 11818 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 11819 | } finally { |
| 11820 | Binder.restoreCallingIdentity(identity); |
| 11821 | } |
| 11822 | } |
| 11823 | |
James.cf Lin | 18bb900 | 2021-05-25 01:37:38 +0800 | [diff] [blame] | 11824 | /** |
| 11825 | * Remove UCE requests cannot be sent to the network status. |
| 11826 | */ |
| 11827 | // Used for SHELL command only. |
| 11828 | @Override |
| 11829 | public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) { |
| 11830 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout"); |
| 11831 | final long identity = Binder.clearCallingIdentity(); |
| 11832 | try { |
| 11833 | return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs); |
| 11834 | } catch (ImsException e) { |
| 11835 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 11836 | } finally { |
| 11837 | Binder.restoreCallingIdentity(identity); |
| 11838 | } |
| 11839 | } |
Brad Ebinger | 14d467f | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 11840 | |
James.cf Lin | 4b784aa | 2021-01-31 03:25:15 +0800 | [diff] [blame] | 11841 | @Override |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11842 | public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request, |
| 11843 | String callingPackage) { |
| 11844 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 11845 | mApp, subId, "setSignalStrengthUpdateRequest"); |
| 11846 | |
| 11847 | final int callingUid = Binder.getCallingUid(); |
| 11848 | // Verify that tha callingPackage belongs to the calling UID |
| 11849 | mApp.getSystemService(AppOpsManager.class) |
| 11850 | .checkPackage(callingUid, callingPackage); |
| 11851 | |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 11852 | validateSignalStrengthUpdateRequest(mApp, request, callingUid); |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11853 | |
| 11854 | final long identity = Binder.clearCallingIdentity(); |
| 11855 | try { |
| 11856 | Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST, |
| 11857 | new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId); |
| 11858 | |
| 11859 | if (result instanceof IllegalStateException) { |
| 11860 | throw (IllegalStateException) result; |
| 11861 | } |
| 11862 | } finally { |
| 11863 | Binder.restoreCallingIdentity(identity); |
| 11864 | } |
| 11865 | } |
| 11866 | |
| 11867 | @Override |
| 11868 | public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request, |
| 11869 | String callingPackage) { |
| 11870 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 11871 | mApp, subId, "clearSignalStrengthUpdateRequest"); |
| 11872 | |
| 11873 | final int callingUid = Binder.getCallingUid(); |
| 11874 | // Verify that tha callingPackage belongs to the calling UID |
| 11875 | mApp.getSystemService(AppOpsManager.class) |
| 11876 | .checkPackage(callingUid, callingPackage); |
| 11877 | |
| 11878 | final long identity = Binder.clearCallingIdentity(); |
| 11879 | try { |
| 11880 | Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST, |
| 11881 | new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId); |
| 11882 | |
| 11883 | if (result instanceof IllegalStateException) { |
| 11884 | throw (IllegalStateException) result; |
| 11885 | } |
| 11886 | } finally { |
| 11887 | Binder.restoreCallingIdentity(identity); |
| 11888 | } |
| 11889 | } |
| 11890 | |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 11891 | private static void validateSignalStrengthUpdateRequest(Context context, |
| 11892 | SignalStrengthUpdateRequest request, int callingUid) { |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11893 | if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) { |
| 11894 | // phone/system process do not have further restriction on request |
| 11895 | return; |
| 11896 | } |
| 11897 | |
| 11898 | // Applications has restrictions on how to use the request: |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 11899 | // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11900 | if (request.isSystemThresholdReportingRequestedWhileIdle()) { |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 11901 | context.enforceCallingOrSelfPermission( |
| 11902 | android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH, |
| 11903 | "validateSignalStrengthUpdateRequest"); |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11904 | } |
| 11905 | |
| 11906 | for (SignalThresholdInfo info : request.getSignalThresholdInfos()) { |
Nagendra Prasad Nagarle Basavaraju | fee544c | 2022-12-07 16:34:52 +0000 | [diff] [blame] | 11907 | // Only system caller can set mHysteresisMs/mIsEnabled. |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11908 | if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11909 | || info.isEnabled()) { |
| 11910 | throw new IllegalArgumentException( |
| 11911 | "Only system can set hide fields in SignalThresholdInfo"); |
| 11912 | } |
| 11913 | |
| 11914 | // Thresholds length for each RAN need in range. This has been validated in |
| 11915 | // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method |
| 11916 | // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds |
| 11917 | final int[] thresholds = info.getThresholds(); |
| 11918 | Objects.requireNonNull(thresholds); |
| 11919 | if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed() |
| 11920 | || thresholds.length |
| 11921 | > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) { |
| 11922 | throw new IllegalArgumentException( |
| 11923 | "thresholds length is out of range: " + thresholds.length); |
| 11924 | } |
| 11925 | } |
| 11926 | } |
SongFerngWang | 8236caa | 2021-01-17 21:51:44 +0800 | [diff] [blame] | 11927 | |
| 11928 | /** |
| 11929 | * Gets the current phone capability. |
| 11930 | * |
| 11931 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 11932 | * @return the PhoneCapability which describes the data connection capability of modem. |
| 11933 | * It's used to evaluate possible phone config change, for example from single |
| 11934 | * SIM device to multi-SIM device. |
| 11935 | */ |
| 11936 | @Override |
| 11937 | public PhoneCapability getPhoneCapability() { |
| 11938 | enforceReadPrivilegedPermission("getPhoneCapability"); |
| 11939 | final long identity = Binder.clearCallingIdentity(); |
| 11940 | try { |
| 11941 | return mPhoneConfigurationManager.getCurrentPhoneCapability(); |
| 11942 | } finally { |
| 11943 | Binder.restoreCallingIdentity(identity); |
| 11944 | } |
| 11945 | } |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 11946 | |
| 11947 | /** |
| 11948 | * Prepare TelephonyManager for an unattended reboot. The reboot is |
| 11949 | * required to be done shortly after the API is invoked. |
| 11950 | */ |
| 11951 | @Override |
| 11952 | @TelephonyManager.PrepareUnattendedRebootResult |
| 11953 | public int prepareForUnattendedReboot() { |
Rafael Higuera Silva | d963064 | 2021-09-20 15:32:01 +0000 | [diff] [blame] | 11954 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 11955 | enforceRebootPermission(); |
| 11956 | |
| 11957 | final long identity = Binder.clearCallingIdentity(); |
| 11958 | try { |
Rafael Higuera Silva | d963064 | 2021-09-20 15:32:01 +0000 | [diff] [blame] | 11959 | return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 11960 | } finally { |
| 11961 | Binder.restoreCallingIdentity(identity); |
| 11962 | } |
| 11963 | } |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 11964 | |
| 11965 | /** |
| 11966 | * Request to get the current slicing configuration including URSP rules and |
| 11967 | * NSSAIs (configured, allowed and rejected). |
| 11968 | * |
| 11969 | * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission. |
| 11970 | */ |
| 11971 | @Override |
| 11972 | public void getSlicingConfig(ResultReceiver callback) { |
Hongbo Zeng | 1b2063d | 2022-02-21 01:33:03 +0000 | [diff] [blame] | 11973 | TelephonyPermissions |
| 11974 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 11975 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, "getSlicingConfig"); |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 11976 | |
| 11977 | final long identity = Binder.clearCallingIdentity(); |
| 11978 | try { |
| 11979 | Phone phone = getDefaultPhone(); |
| 11980 | sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null); |
| 11981 | } finally { |
| 11982 | Binder.restoreCallingIdentity(identity); |
| 11983 | } |
| 11984 | } |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 11985 | |
| 11986 | /** |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 11987 | * Check whether the given premium capability is available for purchase from the carrier. |
| 11988 | * |
| 11989 | * @param capability The premium capability to check. |
| 11990 | * @param subId The subId to check the premium capability for. |
| 11991 | * |
| 11992 | * @return Whether the given premium capability is available to purchase. |
| 11993 | */ |
| 11994 | @Override |
| 11995 | public boolean isPremiumCapabilityAvailableForPurchase(int capability, int subId) { |
| 11996 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 11997 | mApp, "isPremiumCapabilityAvailableForPurchase")) { |
| 11998 | log("Premium capability " |
| 11999 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 12000 | + " is not available for purchase due to missing permissions."); |
| 12001 | throw new SecurityException("isPremiumCapabilityAvailableForPurchase requires " |
| 12002 | + "permission READ_BASIC_PHONE_STATE."); |
| 12003 | } |
| 12004 | |
| 12005 | Phone phone = getPhone(subId); |
Thomas Nguyen | 7216ed6 | 2022-11-29 16:45:31 -0800 | [diff] [blame] | 12006 | if (phone == null) { |
| 12007 | loge("isPremiumCapabilityAvailableForPurchase: phone is null, subId=" + subId); |
| 12008 | return false; |
| 12009 | } |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 12010 | final long identity = Binder.clearCallingIdentity(); |
| 12011 | try { |
Sarah Chin | 46355ba | 2022-11-01 23:51:16 -0700 | [diff] [blame] | 12012 | return SlicePurchaseController.getInstance(phone) |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 12013 | .isPremiumCapabilityAvailableForPurchase(capability); |
| 12014 | } finally { |
| 12015 | Binder.restoreCallingIdentity(identity); |
| 12016 | } |
| 12017 | } |
| 12018 | |
| 12019 | /** |
| 12020 | * Purchase the given premium capability from the carrier. |
| 12021 | * |
| 12022 | * @param capability The premium capability to purchase. |
| 12023 | * @param callback The result of the purchase request. |
| 12024 | * @param subId The subId to purchase the premium capability for. |
| 12025 | */ |
| 12026 | @Override |
| 12027 | public void purchasePremiumCapability(int capability, IIntegerConsumer callback, int subId) { |
| 12028 | log("purchasePremiumCapability: capability=" |
| 12029 | + TelephonyManager.convertPremiumCapabilityToString(capability) + ", caller=" |
| 12030 | + getCurrentPackageName()); |
| 12031 | |
| 12032 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 12033 | mApp, "purchasePremiumCapability")) { |
| 12034 | log("purchasePremiumCapability " |
| 12035 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 12036 | + " failed due to missing permissions."); |
| 12037 | throw new SecurityException("purchasePremiumCapability requires permission " |
| 12038 | + "READ_BASIC_PHONE_STATE."); |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 12039 | } else if (!TelephonyPermissions.checkInternetPermissionNoThrow( |
| 12040 | mApp, "purchasePremiumCapability")) { |
| 12041 | log("purchasePremiumCapability " |
| 12042 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 12043 | + " failed due to missing permissions."); |
| 12044 | throw new SecurityException("purchasePremiumCapability requires permission INTERNET."); |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 12045 | } |
| 12046 | |
| 12047 | Phone phone = getPhone(subId); |
Sarah Chin | 1969411 | 2022-12-06 15:41:37 -0800 | [diff] [blame] | 12048 | if (phone == null) { |
| 12049 | try { |
| 12050 | int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_REQUEST_FAILED; |
| 12051 | callback.accept(result); |
| 12052 | loge("purchasePremiumCapability: phone is null, subId=" + subId); |
| 12053 | } catch (RemoteException e) { |
| 12054 | String logStr = "Purchase premium capability " |
| 12055 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 12056 | + " failed due to RemoteException handling null phone: " + e; |
| 12057 | if (DBG) log(logStr); |
| 12058 | AnomalyReporter.reportAnomaly( |
| 12059 | UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr); |
| 12060 | } |
| 12061 | return; |
| 12062 | } |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 12063 | |
| 12064 | String callingProcess; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 12065 | try { |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 12066 | callingProcess = mApp.getPackageManager().getApplicationInfo( |
| 12067 | getCurrentPackageName(), 0).processName; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 12068 | } catch (PackageManager.NameNotFoundException e) { |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 12069 | callingProcess = getCurrentPackageName(); |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 12070 | } |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 12071 | |
| 12072 | boolean isVisible = false; |
| 12073 | ActivityManager am = mApp.getSystemService(ActivityManager.class); |
| 12074 | if (am != null) { |
| 12075 | List<ActivityManager.RunningAppProcessInfo> processes = am.getRunningAppProcesses(); |
| 12076 | if (processes != null) { |
| 12077 | for (ActivityManager.RunningAppProcessInfo process : processes) { |
| 12078 | log("purchasePremiumCapability: process " + process.processName |
| 12079 | + "has importance " + process.importance); |
| 12080 | if (process.processName.equals(callingProcess) && process.importance |
| 12081 | <= ActivityManager.RunningAppProcessInfo.IMPORTANCE_VISIBLE) { |
| 12082 | isVisible = true; |
| 12083 | break; |
| 12084 | } |
| 12085 | } |
| 12086 | } |
| 12087 | } |
| 12088 | |
| 12089 | if (!isVisible) { |
| 12090 | try { |
| 12091 | int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_NOT_FOREGROUND; |
| 12092 | callback.accept(result); |
| 12093 | loge("purchasePremiumCapability: " + callingProcess + " is not in the foreground."); |
| 12094 | } catch (RemoteException e) { |
| 12095 | String logStr = "Purchase premium capability " |
| 12096 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 12097 | + " failed due to RemoteException handling background application: " + e; |
| 12098 | if (DBG) log(logStr); |
| 12099 | AnomalyReporter.reportAnomaly( |
| 12100 | UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr); |
| 12101 | } |
| 12102 | return; |
| 12103 | } |
| 12104 | |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 12105 | sendRequestAsync(CMD_PURCHASE_PREMIUM_CAPABILITY, |
Sarah Chin | b8218c2 | 2023-01-04 13:35:29 -0800 | [diff] [blame] | 12106 | new PurchasePremiumCapabilityArgument(capability, callback), phone, null); |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 12107 | } |
| 12108 | |
| 12109 | /** |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 12110 | * Register an IMS connection state callback |
| 12111 | */ |
| 12112 | @Override |
Hunsuk Choi | 89bd22c | 2021-11-01 13:04:54 +0000 | [diff] [blame] | 12113 | public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb, |
| 12114 | String callingPackage) { |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 12115 | if (feature == ImsFeature.FEATURE_MMTEL) { |
| 12116 | // ImsMmTelManager |
| 12117 | // The following also checks READ_PRIVILEGED_PHONE_STATE. |
| 12118 | TelephonyPermissions |
| 12119 | .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 12120 | mApp, subId, "registerImsStateCallback"); |
| 12121 | } else if (feature == ImsFeature.FEATURE_RCS) { |
| 12122 | // ImsRcsManager or SipDelegateManager |
| 12123 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 12124 | Binder.getCallingUid(), "registerImsStateCallback", |
| 12125 | Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
| 12126 | Manifest.permission.READ_PRECISE_PHONE_STATE, |
| 12127 | Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE, |
| 12128 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
| 12129 | } |
| 12130 | |
| 12131 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 12132 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 12133 | "IMS not available on device."); |
| 12134 | } |
| 12135 | |
| 12136 | if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) { |
| 12137 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 12138 | } |
| 12139 | |
| 12140 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 12141 | if (controller == null) { |
| 12142 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 12143 | "IMS not available on device."); |
| 12144 | } |
| 12145 | |
Hunsuk Choi | 89bd22c | 2021-11-01 13:04:54 +0000 | [diff] [blame] | 12146 | if (callingPackage == null) { |
| 12147 | callingPackage = getCurrentPackageName(); |
| 12148 | } |
| 12149 | |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 12150 | final long token = Binder.clearCallingIdentity(); |
| 12151 | try { |
| 12152 | int slotId = getSlotIndexOrException(subId); |
Hunsuk Choi | 89bd22c | 2021-11-01 13:04:54 +0000 | [diff] [blame] | 12153 | controller.registerImsStateCallback(subId, feature, cb, callingPackage); |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 12154 | } catch (ImsException e) { |
| 12155 | throw new ServiceSpecificException(e.getCode()); |
| 12156 | } finally { |
| 12157 | Binder.restoreCallingIdentity(token); |
| 12158 | } |
| 12159 | } |
| 12160 | |
| 12161 | /** |
| 12162 | * Unregister an IMS connection state callback |
| 12163 | */ |
| 12164 | @Override |
| 12165 | public void unregisterImsStateCallback(IImsStateCallback cb) { |
| 12166 | final long token = Binder.clearCallingIdentity(); |
| 12167 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 12168 | if (controller == null) { |
| 12169 | return; |
| 12170 | } |
| 12171 | try { |
| 12172 | controller.unregisterImsStateCallback(cb); |
| 12173 | } finally { |
| 12174 | Binder.restoreCallingIdentity(token); |
| 12175 | } |
| 12176 | } |
Sooraj Sasindran | fae41b3 | 2021-10-26 02:10:05 -0700 | [diff] [blame] | 12177 | |
| 12178 | /** |
| 12179 | * @return {@CellIdentity} last known cell identity {@CellIdentity}. |
| 12180 | * |
| 12181 | * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and |
| 12182 | * com.android.phone.permission.ACCESS_LAST_KNOWN_CELL_ID, otherwise throws |
| 12183 | * SecurityException. |
| 12184 | * If there is current registered network this value will be same as the registered cell |
| 12185 | * identity. If the device goes out of service the previous cell identity is cached and |
| 12186 | * will be returned. If the cache age of the Cell identity is more than 24 hours |
| 12187 | * it will be cleared and null will be returned. |
| 12188 | * |
| 12189 | */ |
| 12190 | @Override |
| 12191 | public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage, |
| 12192 | String callingFeatureId) { |
| 12193 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 12194 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 12195 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 12196 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 12197 | .setCallingPackage(callingPackage) |
| 12198 | .setCallingFeatureId(callingFeatureId) |
| 12199 | .setCallingPid(Binder.getCallingPid()) |
| 12200 | .setCallingUid(Binder.getCallingUid()) |
| 12201 | .setMethod("getLastKnownCellIdentity") |
| 12202 | .setLogAsInfo(true) |
| 12203 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 12204 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 12205 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 12206 | .build()); |
| 12207 | |
| 12208 | boolean hasFinePermission = |
| 12209 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 12210 | if (!hasFinePermission |
| 12211 | || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) { |
| 12212 | throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION " |
Rambo Wang | 918993a | 2022-04-27 09:08:36 -0700 | [diff] [blame] | 12213 | + "and ACCESS_LAST_KNOWN_CELL_ID permission."); |
Sooraj Sasindran | fae41b3 | 2021-10-26 02:10:05 -0700 | [diff] [blame] | 12214 | } |
| 12215 | |
| 12216 | final long identity = Binder.clearCallingIdentity(); |
| 12217 | try { |
| 12218 | Phone phone = getPhone(subId); |
| 12219 | if (phone == null) return null; |
| 12220 | ServiceStateTracker sst = phone.getServiceStateTracker(); |
| 12221 | if (sst == null) return null; |
| 12222 | return sst.getLastKnownCellIdentity(); |
| 12223 | } finally { |
| 12224 | Binder.restoreCallingIdentity(identity); |
| 12225 | } |
| 12226 | } |
Jack Yu | 4c0a550 | 2021-12-03 23:58:26 -0800 | [diff] [blame] | 12227 | |
jimsun | 3b9ccac | 2021-10-26 15:01:23 +0800 | [diff] [blame] | 12228 | /** |
| 12229 | * Sets the modem service class Name that Telephony will bind to. |
| 12230 | * |
| 12231 | * @param serviceName The class name of the modem service. |
| 12232 | * @return true if the operation is succeed, otherwise false. |
| 12233 | */ |
| 12234 | public boolean setModemService(String serviceName) { |
| 12235 | Log.d(LOG_TAG, "setModemService - " + serviceName); |
| 12236 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService"); |
| 12237 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12238 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 12239 | "setModemService"); |
jimsun | 3b9ccac | 2021-10-26 15:01:23 +0800 | [diff] [blame] | 12240 | return mPhoneConfigurationManager.setModemService(serviceName); |
| 12241 | } |
| 12242 | |
| 12243 | /** |
| 12244 | * Return the class name of the currently bounded modem service. |
| 12245 | * |
| 12246 | * @return the class name of the modem service. |
| 12247 | */ |
| 12248 | public String getModemService() { |
| 12249 | String result; |
| 12250 | Log.d(LOG_TAG, "getModemService"); |
| 12251 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService"); |
| 12252 | TelephonyPermissions |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12253 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
jimsun | 3b9ccac | 2021-10-26 15:01:23 +0800 | [diff] [blame] | 12254 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 12255 | "getModemService"); |
| 12256 | result = mPhoneConfigurationManager.getModemService(); |
| 12257 | Log.d(LOG_TAG, "result = " + result); |
| 12258 | return result; |
| 12259 | } |
Hunter Knepshield | 2b076fa | 2022-01-19 02:26:22 -0800 | [diff] [blame] | 12260 | |
| 12261 | @Override |
| 12262 | public void setVoiceServiceStateOverride(int subId, boolean hasService, String callingPackage) { |
| 12263 | // Only telecom (and shell, for CTS purposes) is allowed to call this method. |
| 12264 | mApp.enforceCallingOrSelfPermission( |
| 12265 | permission.BIND_TELECOM_CONNECTION_SERVICE, "setVoiceServiceStateOverride"); |
| 12266 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 12267 | |
| 12268 | final long identity = Binder.clearCallingIdentity(); |
| 12269 | try { |
| 12270 | Phone phone = getPhone(subId); |
| 12271 | if (phone == null) return; |
Grant Menke | 63ade12 | 2023-01-20 14:31:54 -0800 | [diff] [blame] | 12272 | Log.i(LOG_TAG, "setVoiceServiceStateOverride: subId=" + subId + ", phone=" + phone |
| 12273 | + ", hasService=" + hasService + ", callingPackage=" + callingPackage); |
Hunter Knepshield | 2b076fa | 2022-01-19 02:26:22 -0800 | [diff] [blame] | 12274 | phone.setVoiceServiceStateOverride(hasService); |
| 12275 | } finally { |
| 12276 | Binder.restoreCallingIdentity(identity); |
| 12277 | } |
| 12278 | } |
Muralidhar Reddy | 4e5a801 | 2022-05-11 14:49:00 +0000 | [diff] [blame] | 12279 | |
| 12280 | /** |
| 12281 | * set removable eSIM as default eUICC. |
| 12282 | * |
| 12283 | * @hide |
| 12284 | */ |
| 12285 | @Override |
| 12286 | public void setRemovableEsimAsDefaultEuicc(boolean isDefault, String callingPackage) { |
| 12287 | enforceModifyPermission(); |
| 12288 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 12289 | |
| 12290 | final long identity = Binder.clearCallingIdentity(); |
| 12291 | try { |
| 12292 | UiccController.getInstance().setRemovableEsimAsDefaultEuicc(isDefault); |
| 12293 | } finally { |
| 12294 | Binder.restoreCallingIdentity(identity); |
| 12295 | } |
| 12296 | } |
| 12297 | |
| 12298 | /** |
| 12299 | * Returns whether the removable eSIM is default eUICC or not. |
| 12300 | * |
| 12301 | * @hide |
| 12302 | */ |
| 12303 | @Override |
| 12304 | public boolean isRemovableEsimDefaultEuicc(String callingPackage) { |
| 12305 | enforceReadPrivilegedPermission("isRemovableEsimDefaultEuicc"); |
| 12306 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 12307 | |
| 12308 | final long identity = Binder.clearCallingIdentity(); |
| 12309 | try { |
| 12310 | return UiccController.getInstance().isRemovableEsimDefaultEuicc(); |
| 12311 | } finally { |
| 12312 | Binder.restoreCallingIdentity(identity); |
| 12313 | } |
| 12314 | } |
| 12315 | |
Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame] | 12316 | /** |
| 12317 | * Get the component name of the default app to direct respond-via-message intent for the |
| 12318 | * user associated with this subscription, update the cache if there is no respond-via-message |
| 12319 | * application currently configured for this user. |
| 12320 | * @return component name of the app and class to direct Respond Via Message intent to, or |
| 12321 | * {@code null} if the functionality is not supported. |
| 12322 | * @hide |
| 12323 | */ |
| 12324 | @Override |
| 12325 | public @Nullable ComponentName getDefaultRespondViaMessageApplication(int subId, |
| 12326 | boolean updateIfNeeded) { |
| 12327 | enforceInteractAcrossUsersPermission("getDefaultRespondViaMessageApplication"); |
Muralidhar Reddy | 4e5a801 | 2022-05-11 14:49:00 +0000 | [diff] [blame] | 12328 | |
Aishwarya Mallampati | 5e581e1 | 2023-01-17 21:57:06 +0000 | [diff] [blame] | 12329 | Context context = getPhoneFromSubIdOrDefault(subId).getContext(); |
| 12330 | |
Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame] | 12331 | UserHandle userHandle = null; |
| 12332 | final long identity = Binder.clearCallingIdentity(); |
| 12333 | try { |
| 12334 | userHandle = TelephonyUtils.getSubscriptionUserHandle(context, subId); |
| 12335 | } finally { |
| 12336 | Binder.restoreCallingIdentity(identity); |
| 12337 | } |
| 12338 | return SmsApplication.getDefaultRespondViaMessageApplicationAsUser(context, |
| 12339 | updateIfNeeded, userHandle); |
| 12340 | } |
Jack Yu | f5badd9 | 2022-12-08 00:50:53 -0800 | [diff] [blame] | 12341 | |
| 12342 | /** |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 12343 | * Set whether the device is able to connect with null ciphering or integrity |
| 12344 | * algorithms. This is a global setting and will apply to all active subscriptions |
| 12345 | * and all new subscriptions after this. |
| 12346 | * |
| 12347 | * @param enabled when true, null cipher and integrity algorithms are allowed. |
| 12348 | * @hide |
| 12349 | */ |
| 12350 | @Override |
| 12351 | @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 12352 | public void setNullCipherAndIntegrityEnabled(boolean enabled) { |
| 12353 | enforceModifyPermission(); |
| 12354 | checkForNullCipherAndIntegritySupport(); |
| 12355 | |
| 12356 | // Persist the state of our preference. Each GsmCdmaPhone instance is responsible |
| 12357 | // for listening to these preference changes and applying them immediately. |
| 12358 | SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 12359 | editor.putBoolean(Phone.PREF_NULL_CIPHER_AND_INTEGRITY_ENABLED, enabled); |
| 12360 | editor.apply(); |
| 12361 | |
| 12362 | for (Phone phone: PhoneFactory.getPhones()) { |
| 12363 | phone.handleNullCipherEnabledChange(); |
| 12364 | } |
| 12365 | } |
| 12366 | |
| 12367 | |
| 12368 | /** |
| 12369 | * Get whether the device is able to connect with null ciphering or integrity |
| 12370 | * algorithms. Note that this retrieves the phone-global preference and not |
| 12371 | * the state of the radio. |
| 12372 | * |
| 12373 | * @throws SecurityException if {@link permission#MODIFY_PHONE_STATE} is not satisfied |
| 12374 | * @throws UnsupportedOperationException if the device does not support the minimum HAL |
| 12375 | * version for this feature. |
| 12376 | * @hide |
| 12377 | */ |
| 12378 | @Override |
| 12379 | @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) |
| 12380 | public boolean isNullCipherAndIntegrityPreferenceEnabled() { |
| 12381 | enforceReadPermission(); |
| 12382 | checkForNullCipherAndIntegritySupport(); |
| 12383 | return getDefaultPhone().getNullCipherAndIntegrityEnabledPreference(); |
| 12384 | } |
| 12385 | |
| 12386 | private void checkForNullCipherAndIntegritySupport() { |
| 12387 | if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_NULL_CIPHER_AND_INTEGRITY_VERSION) { |
| 12388 | throw new UnsupportedOperationException( |
| 12389 | "Null cipher and integrity operations require HAL 2.1 or above"); |
| 12390 | } |
Gil Cukierman | 92cc7db | 2023-01-06 19:25:53 +0000 | [diff] [blame] | 12391 | if (!getDefaultPhone().isNullCipherAndIntegritySupported()) { |
| 12392 | throw new UnsupportedOperationException( |
| 12393 | "Null cipher and integrity operations unsupported by modem"); |
| 12394 | } |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 12395 | } |
| 12396 | |
| 12397 | /** |
Jack Yu | f5badd9 | 2022-12-08 00:50:53 -0800 | [diff] [blame] | 12398 | * Get the SIM state for the slot index. |
| 12399 | * For Remote-SIMs, this method returns {@link IccCardConstants.State#UNKNOWN} |
| 12400 | * |
| 12401 | * @return SIM state as the ordinal of {@link IccCardConstants.State} |
| 12402 | */ |
| 12403 | @Override |
| 12404 | @SimState |
| 12405 | public int getSimStateForSlotIndex(int slotIndex) { |
| 12406 | IccCardConstants.State simState; |
| 12407 | if (slotIndex < 0) { |
| 12408 | simState = IccCardConstants.State.UNKNOWN; |
| 12409 | } else { |
| 12410 | Phone phone = null; |
| 12411 | try { |
| 12412 | phone = PhoneFactory.getPhone(slotIndex); |
| 12413 | } catch (IllegalStateException e) { |
| 12414 | // ignore |
| 12415 | } |
| 12416 | if (phone == null) { |
| 12417 | simState = IccCardConstants.State.UNKNOWN; |
| 12418 | } else { |
| 12419 | IccCard icc = phone.getIccCard(); |
| 12420 | if (icc == null) { |
| 12421 | simState = IccCardConstants.State.UNKNOWN; |
| 12422 | } else { |
| 12423 | simState = icc.getState(); |
| 12424 | } |
| 12425 | } |
| 12426 | } |
| 12427 | return simState.ordinal(); |
| 12428 | } |
Hui Wang | 9b5793a | 2022-12-05 14:38:06 -0600 | [diff] [blame] | 12429 | |
| 12430 | /** |
| 12431 | * Get current cell broadcast ranges. |
| 12432 | */ |
| 12433 | @Override |
| 12434 | @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS) |
| 12435 | public List<CellBroadcastIdRange> getCellBroadcastIdRanges(int subId) { |
| 12436 | mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS, |
| 12437 | "getCellBroadcastIdRanges"); |
| 12438 | final long identity = Binder.clearCallingIdentity(); |
| 12439 | try { |
| 12440 | return getPhone(subId).getCellBroadcastIdRanges(); |
| 12441 | } finally { |
| 12442 | Binder.restoreCallingIdentity(identity); |
| 12443 | } |
| 12444 | } |
| 12445 | |
| 12446 | /** |
| 12447 | * Set reception of cell broadcast messages with the list of the given ranges |
| 12448 | * |
| 12449 | * @param ranges the list of {@link CellBroadcastIdRange} to be enabled |
| 12450 | */ |
| 12451 | @Override |
| 12452 | @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS) |
| 12453 | public void setCellBroadcastIdRanges(int subId, @NonNull List<CellBroadcastIdRange> ranges, |
| 12454 | @Nullable IIntegerConsumer callback) { |
| 12455 | mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS, |
| 12456 | "setCellBroadcastIdRanges"); |
| 12457 | final long identity = Binder.clearCallingIdentity(); |
| 12458 | try { |
| 12459 | Phone phone = getPhoneFromSubId(subId); |
| 12460 | if (DBG) { |
| 12461 | log("setCellBroadcastIdRanges for subId :" + subId + ", phone:" + phone); |
| 12462 | } |
| 12463 | phone.setCellBroadcastIdRanges(ranges, result -> { |
| 12464 | if (callback != null) { |
| 12465 | try { |
| 12466 | callback.accept(result); |
| 12467 | } catch (RemoteException e) { |
| 12468 | Log.w(LOG_TAG, "setCellBroadcastIdRanges: callback not available."); |
| 12469 | } |
| 12470 | } |
| 12471 | }); |
| 12472 | } finally { |
| 12473 | Binder.restoreCallingIdentity(identity); |
| 12474 | } |
| 12475 | } |
Hunsuk Choi | 42cc62a | 2022-10-16 06:03:40 +0000 | [diff] [blame] | 12476 | |
| 12477 | /** |
| 12478 | * Returns whether the device supports the domain selection service. |
| 12479 | * |
| 12480 | * @return {@code true} if the device supports the domain selection service. |
| 12481 | */ |
| 12482 | @Override |
| 12483 | public boolean isDomainSelectionSupported() { |
| 12484 | mApp.enforceCallingOrSelfPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
| 12485 | "isDomainSelectionSupported"); |
| 12486 | |
| 12487 | final long identity = Binder.clearCallingIdentity(); |
| 12488 | try { |
| 12489 | return DomainSelectionResolver.getInstance().isDomainSelectionSupported(); |
| 12490 | } finally { |
| 12491 | Binder.restoreCallingIdentity(identity); |
| 12492 | } |
| 12493 | } |
arunvoddu | d5c6ce0 | 2022-12-11 06:03:12 +0000 | [diff] [blame] | 12494 | |
| 12495 | /** |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame^] | 12496 | * Enable or disable the satellite modem. If the satellite modem is enabled, this will also |
| 12497 | * disable the cellular modem, and if the satellite modem is disabled, this will also re-enable |
| 12498 | * the cellular modem. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12499 | * |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame^] | 12500 | * @param subId The subId to set satellite enabled for. |
| 12501 | * @param enable {@code true} to enable the satellite modem and {@code false} to disable. |
| 12502 | * @param callback The callback to get the error code of the request. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12503 | * |
| 12504 | * @throws SecurityException if the caller doesn't have the required permission. |
| 12505 | */ |
| 12506 | @Override |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame^] | 12507 | public void setSatelliteEnabled(int subId, boolean enable, @NonNull IIntegerConsumer callback) { |
| 12508 | enforceSatelliteCommunicationPermission("setSatelliteEnabled"); |
| 12509 | Consumer<Integer> result = FunctionalUtils.ignoreRemoteException(callback::accept); |
Thomas Nguyen | e77de6d | 2023-02-10 17:42:43 -0800 | [diff] [blame] | 12510 | if (!isSatelliteSupported()) { |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame^] | 12511 | result.accept(SatelliteManager.SATELLITE_NOT_SUPPORTED); |
| 12512 | return; |
Thomas Nguyen | e77de6d | 2023-02-10 17:42:43 -0800 | [diff] [blame] | 12513 | } |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12514 | |
| 12515 | final int validSubId = getValidSatelliteSubId(subId); |
Thomas Nguyen | e77de6d | 2023-02-10 17:42:43 -0800 | [diff] [blame] | 12516 | if (!isSatelliteProvisioned(validSubId)) { |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame^] | 12517 | result.accept(SatelliteManager.SATELLITE_SERVICE_NOT_PROVISIONED); |
| 12518 | return; |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12519 | } |
| 12520 | |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame^] | 12521 | Phone phone = getPhoneOrDefault(validSubId, "setSatelliteEnabled"); |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12522 | if (phone == null) { |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame^] | 12523 | result.accept(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE); |
| 12524 | return; |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12525 | } |
| 12526 | |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame^] | 12527 | Pair<Boolean, Consumer<Integer>> arg = new Pair<>(enable, result); |
| 12528 | sendRequestAsync(CMD_SET_SATELLITE_ENABLED, arg, phone, null); |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12529 | } |
| 12530 | |
| 12531 | /** |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame^] | 12532 | * Request to get whether the satellite modem is enabled. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12533 | * |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame^] | 12534 | * @param subId The subId to check whether satellite is enabled for. |
| 12535 | * @param result The result receiver that returns whether the satellite modem is enabled |
| 12536 | * 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] | 12537 | * |
| 12538 | * @throws SecurityException if the caller doesn't have the required permission. |
| 12539 | */ |
| 12540 | @Override |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame^] | 12541 | public void requestIsSatelliteEnabled(int subId, @NonNull ResultReceiver result) { |
| 12542 | enforceSatelliteCommunicationPermission("requestIsSatelliteEnabled"); |
Thomas Nguyen | e77de6d | 2023-02-10 17:42:43 -0800 | [diff] [blame] | 12543 | if (!isSatelliteSupported()) { |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame^] | 12544 | result.send(SatelliteManager.SATELLITE_NOT_SUPPORTED, null); |
| 12545 | return; |
Thomas Nguyen | e77de6d | 2023-02-10 17:42:43 -0800 | [diff] [blame] | 12546 | } |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12547 | |
| 12548 | final int validSubId = getValidSatelliteSubId(subId); |
Thomas Nguyen | e77de6d | 2023-02-10 17:42:43 -0800 | [diff] [blame] | 12549 | if (!isSatelliteProvisioned(validSubId)) { |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame^] | 12550 | result.send(SatelliteManager.SATELLITE_SERVICE_NOT_PROVISIONED, null); |
| 12551 | return; |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12552 | } |
| 12553 | |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame^] | 12554 | Phone phone = getPhoneOrDefault(validSubId, "requestIsSatelliteEnabled"); |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12555 | if (phone == null) { |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame^] | 12556 | result.send(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE, null); |
| 12557 | return; |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12558 | } |
| 12559 | |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame^] | 12560 | sendRequest(CMD_IS_SATELLITE_ENABLED, result, subId); |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12561 | } |
| 12562 | |
| 12563 | /** |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame^] | 12564 | * Request to get whether the satellite service is supported on the device. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12565 | * |
| 12566 | * @param subId The subId to check satellite service support for. |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame^] | 12567 | * @param result The result receiver that returns whether the satellite service is supported on |
| 12568 | * 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] | 12569 | */ |
| 12570 | @Override |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame^] | 12571 | public void requestIsSatelliteSupported(int subId, @NonNull ResultReceiver result) { |
Thomas Nguyen | e77de6d | 2023-02-10 17:42:43 -0800 | [diff] [blame] | 12572 | synchronized (mIsSatelliteSupportedLock) { |
| 12573 | if (mIsSatelliteSupported != null) { |
| 12574 | /* We have already successfully queried the satellite modem. */ |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame^] | 12575 | Bundle bundle = new Bundle(); |
| 12576 | bundle.putBoolean(SatelliteManager.KEY_SATELLITE_SUPPORTED, mIsSatelliteSupported); |
| 12577 | result.send(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE, bundle); |
| 12578 | return; |
Thomas Nguyen | e77de6d | 2023-02-10 17:42:43 -0800 | [diff] [blame] | 12579 | } |
| 12580 | } |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12581 | |
| 12582 | final int validSubId = getValidSatelliteSubId(subId); |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame^] | 12583 | Phone phone = getPhoneOrDefault(validSubId, "requestIsSatelliteSupported"); |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12584 | if (phone == null) { |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame^] | 12585 | result.send(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE, null); |
| 12586 | return; |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12587 | } |
| 12588 | |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame^] | 12589 | sendRequestAsync(CMD_IS_SATELLITE_SUPPORTED, result, phone, null); |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12590 | } |
| 12591 | |
| 12592 | /** |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame^] | 12593 | * Request to get the {@link SatelliteCapabilities} of the satellite service. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12594 | * |
| 12595 | * @param subId The subId to get the satellite capabilities for. |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame^] | 12596 | * @param result The result receiver that returns the {@link SatelliteCapabilities} |
| 12597 | * 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] | 12598 | * |
| 12599 | * @throws SecurityException if the caller doesn't have required permission. |
| 12600 | */ |
| 12601 | @Override |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame^] | 12602 | public void requestSatelliteCapabilities(int subId, @NonNull ResultReceiver result) { |
| 12603 | enforceSatelliteCommunicationPermission("requestSatelliteCapabilities"); |
Thomas Nguyen | e77de6d | 2023-02-10 17:42:43 -0800 | [diff] [blame] | 12604 | if (!isSatelliteSupported()) { |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame^] | 12605 | result.send(SatelliteManager.SATELLITE_NOT_SUPPORTED, null); |
| 12606 | return; |
Thomas Nguyen | e77de6d | 2023-02-10 17:42:43 -0800 | [diff] [blame] | 12607 | } |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12608 | |
| 12609 | final int validSubId = getValidSatelliteSubId(subId); |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame^] | 12610 | Phone phone = getPhoneOrDefault(validSubId, "requestSatelliteCapabilities"); |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12611 | if (phone == null) { |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame^] | 12612 | result.send(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE, null); |
| 12613 | return; |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12614 | } |
| 12615 | |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame^] | 12616 | sendRequestAsync(CMD_GET_SATELLITE_CAPABILITIES, result, phone, null); |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12617 | } |
| 12618 | |
| 12619 | /** |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 12620 | * Start receiving satellite position updates. |
| 12621 | * This can be called by the pointing UI when the user starts pointing to the satellite. |
| 12622 | * Modem should continue to report the pointing input as the device or satellite moves. |
| 12623 | * |
| 12624 | * @param subId The subId to start satellite position updates for. |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame^] | 12625 | * @param errorCallback The callback to get the error code of the request. |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 12626 | * @param callback The callback to notify of changes in satellite position. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12627 | * |
| 12628 | * @throws SecurityException if the caller doesn't have the required permission. |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 12629 | */ |
| 12630 | @Override |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame^] | 12631 | public void startSatellitePositionUpdates(int subId, @NonNull IIntegerConsumer errorCallback, |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12632 | @NonNull ISatelliteStateListener callback) { |
Sarah Chin | f75afa7 | 2023-02-01 01:32:19 -0800 | [diff] [blame] | 12633 | enforceSatelliteCommunicationPermission("startSatellitePositionUpdates"); |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame^] | 12634 | Consumer<Integer> result = FunctionalUtils.ignoreRemoteException(errorCallback::accept); |
Thomas Nguyen | e77de6d | 2023-02-10 17:42:43 -0800 | [diff] [blame] | 12635 | if (!isSatelliteSupported()) { |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame^] | 12636 | result.accept(SatelliteManager.SATELLITE_NOT_SUPPORTED); |
| 12637 | return; |
Thomas Nguyen | e77de6d | 2023-02-10 17:42:43 -0800 | [diff] [blame] | 12638 | } |
Sarah Chin | f75afa7 | 2023-02-01 01:32:19 -0800 | [diff] [blame] | 12639 | |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12640 | final int validSubId = getValidSatelliteSubId(subId); |
Thomas Nguyen | e77de6d | 2023-02-10 17:42:43 -0800 | [diff] [blame] | 12641 | if (!isSatelliteProvisioned(validSubId)) { |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame^] | 12642 | result.accept(SatelliteManager.SATELLITE_SERVICE_NOT_PROVISIONED); |
| 12643 | return; |
Sarah Chin | f75afa7 | 2023-02-01 01:32:19 -0800 | [diff] [blame] | 12644 | } |
| 12645 | |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12646 | Phone phone = getPhoneOrDefault(validSubId, "startSatellitePositionUpdates"); |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 12647 | if (phone == null) { |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame^] | 12648 | result.accept(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE); |
| 12649 | return; |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 12650 | } |
| 12651 | |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12652 | if (mSatellitePositionUpdateHandlers.containsKey(callback.asBinder())) { |
Thomas Nguyen | e77de6d | 2023-02-10 17:42:43 -0800 | [diff] [blame] | 12653 | if (DBG) { |
| 12654 | log("startSatellitePositionUpdates: callback already registered: " |
| 12655 | + callback.asBinder()); |
| 12656 | } |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame^] | 12657 | result.accept(SatelliteManager.SATELLITE_ERROR_NONE); |
| 12658 | return; |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 12659 | } |
| 12660 | |
| 12661 | SatellitePositionUpdateHandler handler = |
| 12662 | new SatellitePositionUpdateHandler(callback, Looper.getMainLooper()); |
| 12663 | phone.registerForSatellitePointingInfoChanged(handler, |
| 12664 | SatellitePositionUpdateHandler.EVENT_POSITION_UPDATE, null); |
| 12665 | phone.registerForSatelliteMessagesTransferComplete(handler, |
| 12666 | SatellitePositionUpdateHandler.EVENT_MESSAGE_TRANSFER_STATE_UPDATE, null); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12667 | mSatellitePositionUpdateHandlers.put(callback.asBinder(), handler); |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 12668 | |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame^] | 12669 | sendRequestAsync(CMD_START_SATELLITE_POSITION_UPDATES, result, phone, null); |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 12670 | } |
| 12671 | |
| 12672 | /** |
| 12673 | * Stop receiving satellite position updates. |
| 12674 | * This can be called by the pointing UI when the user stops pointing to the satellite. |
| 12675 | * |
| 12676 | * @param subId The subId to stop satellite position updates for. |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame^] | 12677 | * @param errorCallback The callback to get the error code of the request. |
| 12678 | * @param callback The callback that was passed to {@link |
| 12679 | * #startSatellitePositionUpdates(int, IIntegerConsumer, ISatelliteStateListener)} |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12680 | * |
| 12681 | * @throws SecurityException if the caller doesn't have the required permission. |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 12682 | */ |
| 12683 | @Override |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame^] | 12684 | public void stopSatellitePositionUpdates(int subId, @NonNull IIntegerConsumer errorCallback, |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12685 | @NonNull ISatelliteStateListener callback) { |
Sarah Chin | f75afa7 | 2023-02-01 01:32:19 -0800 | [diff] [blame] | 12686 | enforceSatelliteCommunicationPermission("stopSatellitePositionUpdates"); |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame^] | 12687 | Consumer<Integer> result = FunctionalUtils.ignoreRemoteException(errorCallback::accept); |
Thomas Nguyen | e77de6d | 2023-02-10 17:42:43 -0800 | [diff] [blame] | 12688 | if (!isSatelliteSupported()) { |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame^] | 12689 | result.accept(SatelliteManager.SATELLITE_NOT_SUPPORTED); |
| 12690 | return; |
Thomas Nguyen | e77de6d | 2023-02-10 17:42:43 -0800 | [diff] [blame] | 12691 | } |
Sarah Chin | f75afa7 | 2023-02-01 01:32:19 -0800 | [diff] [blame] | 12692 | |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12693 | final int validSubId = getValidSatelliteSubId(subId); |
Thomas Nguyen | e77de6d | 2023-02-10 17:42:43 -0800 | [diff] [blame] | 12694 | if (!isSatelliteProvisioned(validSubId)) { |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame^] | 12695 | result.accept(SatelliteManager.SATELLITE_SERVICE_NOT_PROVISIONED); |
| 12696 | return; |
Sarah Chin | f75afa7 | 2023-02-01 01:32:19 -0800 | [diff] [blame] | 12697 | } |
| 12698 | |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12699 | Phone phone = getPhoneOrDefault(validSubId, "stopSatellitePositionUpdates"); |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 12700 | if (phone == null) { |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame^] | 12701 | result.accept(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE); |
| 12702 | return; |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 12703 | } |
| 12704 | |
| 12705 | SatellitePositionUpdateHandler handler = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12706 | mSatellitePositionUpdateHandlers.remove(callback.asBinder()); |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 12707 | if (handler == null) { |
| 12708 | loge("stopSatellitePositionUpdates: No SatellitePositionArgument"); |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame^] | 12709 | result.accept(SatelliteManager.SATELLITE_INVALID_ARGUMENTS); |
| 12710 | return; |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 12711 | } else { |
| 12712 | phone.unregisterForSatellitePointingInfoChanged(handler); |
| 12713 | phone.unregisterForSatelliteMessagesTransferComplete(handler); |
| 12714 | } |
| 12715 | |
| 12716 | if (!mSatellitePositionUpdateHandlers.isEmpty()) { |
| 12717 | log("stopSatellitePositionUpdates: other listeners still exist."); |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame^] | 12718 | result.accept(SatelliteManager.SATELLITE_ERROR_NONE); |
| 12719 | return; |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 12720 | } |
| 12721 | |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame^] | 12722 | sendRequestAsync(CMD_STOP_SATELLITE_POSITION_UPDATES, result, phone, null); |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 12723 | } |
| 12724 | |
| 12725 | /** |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame^] | 12726 | * Request to get the maximum number of characters per text message on satellite. |
| 12727 | * |
| 12728 | * @param subId The subId of the subscription. |
| 12729 | * @param result The result receiver that returns the maximum number of characters per text |
| 12730 | * message on satellite if the request is successful or an error code |
| 12731 | * if the request failed. |
Aishwarya Mallampati | 60fe113 | 2023-01-24 19:07:21 +0000 | [diff] [blame] | 12732 | * |
| 12733 | * @throws SecurityException if the caller doesn't have the required permission. |
| 12734 | */ |
| 12735 | @Override |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame^] | 12736 | public void requestMaxCharactersPerSatelliteTextMessage(int subId, |
| 12737 | @NonNull ResultReceiver result) { |
| 12738 | enforceSatelliteCommunicationPermission("requestMaxCharactersPerSatelliteTextMessage"); |
Thomas Nguyen | e77de6d | 2023-02-10 17:42:43 -0800 | [diff] [blame] | 12739 | if (!isSatelliteSupported()) { |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame^] | 12740 | result.send(SatelliteManager.SATELLITE_NOT_SUPPORTED, null); |
| 12741 | return; |
Thomas Nguyen | e77de6d | 2023-02-10 17:42:43 -0800 | [diff] [blame] | 12742 | } |
Aishwarya Mallampati | 60fe113 | 2023-01-24 19:07:21 +0000 | [diff] [blame] | 12743 | |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12744 | final int validSubId = getValidSatelliteSubId(subId); |
Thomas Nguyen | e77de6d | 2023-02-10 17:42:43 -0800 | [diff] [blame] | 12745 | if (!isSatelliteProvisioned(validSubId)) { |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame^] | 12746 | result.send(SatelliteManager.SATELLITE_SERVICE_NOT_PROVISIONED, null); |
| 12747 | return; |
Aishwarya Mallampati | 60fe113 | 2023-01-24 19:07:21 +0000 | [diff] [blame] | 12748 | } |
| 12749 | |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame^] | 12750 | Phone phone = getPhoneOrDefault(validSubId, "requestMaxCharactersPerSatelliteTextMessage"); |
Aishwarya Mallampati | 60fe113 | 2023-01-24 19:07:21 +0000 | [diff] [blame] | 12751 | if (phone == null) { |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame^] | 12752 | result.send(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE, null); |
| 12753 | return; |
Aishwarya Mallampati | 60fe113 | 2023-01-24 19:07:21 +0000 | [diff] [blame] | 12754 | } |
| 12755 | |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame^] | 12756 | sendRequestAsync(CMD_GET_MAX_CHAR_PER_SATELLITE_TEXT_MSG, result, phone, null); |
Aishwarya Mallampati | 60fe113 | 2023-01-24 19:07:21 +0000 | [diff] [blame] | 12757 | } |
| 12758 | |
| 12759 | /** |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12760 | * Register the subscription with a satellite provider. |
| 12761 | * This is needed to register the subscription if the provider allows dynamic registration. |
| 12762 | * |
| 12763 | * @param subId The subId of the subscription to be provisioned. |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame^] | 12764 | * @param token The security token of the device/subscription to be provisioned. |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12765 | * @param callback The callback to get the error code of the request. |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame^] | 12766 | * @return The signal transport used by the caller to cancel the provision request, |
| 12767 | * or {@code null} if the request failed. |
| 12768 | * |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12769 | * @throws SecurityException if the caller doesn't have the required permission. |
| 12770 | */ |
| 12771 | @Override |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame^] | 12772 | @Nullable public ICancellationSignal provisionSatelliteService(int subId, |
| 12773 | @NonNull String token, @NonNull IIntegerConsumer callback) { |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12774 | enforceSatelliteCommunicationPermission("provisionSatelliteService"); |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame^] | 12775 | Consumer<Integer> result = FunctionalUtils.ignoreRemoteException(callback::accept); |
Thomas Nguyen | e77de6d | 2023-02-10 17:42:43 -0800 | [diff] [blame] | 12776 | if (!isSatelliteSupported()) { |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame^] | 12777 | result.accept(SatelliteManager.SATELLITE_NOT_SUPPORTED); |
Thomas Nguyen | e77de6d | 2023-02-10 17:42:43 -0800 | [diff] [blame] | 12778 | return null; |
| 12779 | } |
| 12780 | |
| 12781 | final int validSubId = getValidSatelliteSubId(subId); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12782 | Phone phone = getPhoneOrDefault(validSubId, "provisionSatelliteService"); |
| 12783 | if (phone == null) { |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame^] | 12784 | result.accept(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12785 | return null; |
| 12786 | } |
| 12787 | |
| 12788 | if (mSatelliteProvisionCallbacks.containsKey(validSubId)) { |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame^] | 12789 | result.accept(SatelliteManager.SATELLITE_SERVICE_PROVISION_IN_PROGRESS); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12790 | return null; |
| 12791 | } |
| 12792 | |
Thomas Nguyen | e77de6d | 2023-02-10 17:42:43 -0800 | [diff] [blame] | 12793 | if (isSatelliteProvisioned(validSubId)) { |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame^] | 12794 | result.accept(SatelliteManager.SATELLITE_ERROR_NONE); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12795 | return null; |
| 12796 | } |
| 12797 | |
| 12798 | sendRequestAsync(CMD_PROVISION_SATELLITE_SERVICE, |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame^] | 12799 | new ProvisionSatelliteServiceArgument(token, result, validSubId), phone, null); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12800 | |
| 12801 | ICancellationSignal cancelTransport = CancellationSignal.createTransport(); |
| 12802 | CancellationSignal.fromTransport(cancelTransport) |
| 12803 | .setOnCancelListener(() -> { |
| 12804 | sendRequestAsync(CMD_CANCEL_PROVISION_SATELLITE_SERVICE, validSubId); |
| 12805 | }); |
| 12806 | return cancelTransport; |
| 12807 | } |
| 12808 | |
| 12809 | /** |
| 12810 | * Register for the satellite provision state change. |
| 12811 | * |
| 12812 | * @param subId The subId of the subscription associated with the satellite service. |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame^] | 12813 | * @param errorCallback The callback to get the error code of the request. |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12814 | * @param callback The callback to handle the satellite provision state changed event. |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame^] | 12815 | * |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12816 | * @throws SecurityException if the caller doesn't have the required permission. |
| 12817 | */ |
| 12818 | @Override |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame^] | 12819 | public void registerForSatelliteProvisionStateChanged(int subId, |
| 12820 | @NonNull IIntegerConsumer errorCallback, @NonNull ISatelliteStateListener callback) { |
Thomas Nguyen | e77de6d | 2023-02-10 17:42:43 -0800 | [diff] [blame] | 12821 | enforceSatelliteCommunicationPermission("registerForSatelliteProvisionStateChanged"); |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame^] | 12822 | Consumer<Integer> result = null; |
| 12823 | if (errorCallback != null) { |
| 12824 | result = FunctionalUtils.ignoreRemoteException(errorCallback::accept); |
| 12825 | } |
Thomas Nguyen | e77de6d | 2023-02-10 17:42:43 -0800 | [diff] [blame] | 12826 | if (!isSatelliteSupported()) { |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame^] | 12827 | if (result != null) { |
| 12828 | result.accept(SatelliteManager.SATELLITE_NOT_SUPPORTED); |
| 12829 | } |
| 12830 | return; |
Thomas Nguyen | e77de6d | 2023-02-10 17:42:43 -0800 | [diff] [blame] | 12831 | } |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12832 | |
| 12833 | final int validSubId = getValidSatelliteSubId(subId); |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame^] | 12834 | Phone phone = getPhoneOrDefault(validSubId, "registerForSatelliteProvisionStateChanged"); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12835 | if (phone == null) { |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame^] | 12836 | if (result != null) { |
| 12837 | result.accept(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE); |
| 12838 | } |
| 12839 | return; |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12840 | } |
| 12841 | |
| 12842 | SatelliteProvisionStateChangedHandler satelliteProvisionStateChangedHandler = |
| 12843 | mSatelliteProvisionStateChangedHandlers.get(validSubId); |
| 12844 | if (satelliteProvisionStateChangedHandler == null) { |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame^] | 12845 | satelliteProvisionStateChangedHandler = new SatelliteProvisionStateChangedHandler( |
| 12846 | Looper.getMainLooper(), validSubId); |
| 12847 | phone.registerForSatelliteProvisionStateChanged(satelliteProvisionStateChangedHandler, |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12848 | SatelliteProvisionStateChangedHandler.EVENT_PROVISION_STATE_CHANGED, null); |
| 12849 | } |
| 12850 | |
| 12851 | if (callback != null) { |
| 12852 | satelliteProvisionStateChangedHandler.addListener(callback); |
| 12853 | } |
| 12854 | mSatelliteProvisionStateChangedHandlers.put( |
| 12855 | validSubId, satelliteProvisionStateChangedHandler); |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame^] | 12856 | if (result != null) { |
| 12857 | result.accept(SatelliteManager.SATELLITE_ERROR_NONE); |
| 12858 | } |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12859 | } |
| 12860 | |
| 12861 | /** |
| 12862 | * Unregister for the satellite provision state change. |
| 12863 | * |
| 12864 | * @param subId The subId of the subscription associated with the satellite service. |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame^] | 12865 | * @param errorCallback The callback to get the error code of the request. |
| 12866 | * @param callback The callback that was passed to {@link |
| 12867 | * #registerForSatelliteProvisionStateChanged(int, IIntegerConsumer, ISatelliteStateListener)}. |
| 12868 | * |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12869 | * @throws SecurityException if the caller doesn't have the required permission. |
| 12870 | */ |
| 12871 | @Override |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame^] | 12872 | public void unregisterForSatelliteProvisionStateChanged(int subId, |
| 12873 | @NonNull IIntegerConsumer errorCallback, @NonNull ISatelliteStateListener callback) { |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12874 | enforceSatelliteCommunicationPermission("unregisterForSatelliteProvisionStateChanged"); |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame^] | 12875 | Consumer<Integer> result = FunctionalUtils.ignoreRemoteException(errorCallback::accept); |
Thomas Nguyen | e77de6d | 2023-02-10 17:42:43 -0800 | [diff] [blame] | 12876 | if (!isSatelliteSupported()) { |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame^] | 12877 | result.accept(SatelliteManager.SATELLITE_NOT_SUPPORTED); |
| 12878 | return; |
Thomas Nguyen | e77de6d | 2023-02-10 17:42:43 -0800 | [diff] [blame] | 12879 | } |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12880 | |
| 12881 | final int validSubId = getValidSatelliteSubId(subId); |
| 12882 | SatelliteProvisionStateChangedHandler satelliteProvisionStateChangedHandler = |
| 12883 | mSatelliteProvisionStateChangedHandlers.get(validSubId); |
| 12884 | if (satelliteProvisionStateChangedHandler != null) { |
| 12885 | if (satelliteProvisionStateChangedHandler.removeListener(callback)) { |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame^] | 12886 | result.accept(SatelliteManager.SATELLITE_ERROR_NONE); |
| 12887 | return; |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12888 | } |
| 12889 | } |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame^] | 12890 | result.accept(SatelliteManager.SATELLITE_INVALID_ARGUMENTS); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12891 | } |
| 12892 | |
| 12893 | /** |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame^] | 12894 | * Request to get whether the device is provisioned with a satellite provider. |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12895 | * |
| 12896 | * @param subId The subId of the subscription associated with the satellite service. |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame^] | 12897 | * @param result The result receiver that returns whether the device is provisioned with a |
| 12898 | * satellite provider if the request is successful or an error code if the |
| 12899 | * request failed. |
| 12900 | * |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12901 | * @throws SecurityException if the caller doesn't have the required permission. |
| 12902 | */ |
| 12903 | @Override |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame^] | 12904 | public void requestIsSatelliteProvisioned(int subId, @NonNull ResultReceiver result) { |
| 12905 | enforceSatelliteCommunicationPermission("requestIsSatelliteProvisioned"); |
Thomas Nguyen | e77de6d | 2023-02-10 17:42:43 -0800 | [diff] [blame] | 12906 | if (!isSatelliteSupported()) { |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame^] | 12907 | result.send(SatelliteManager.SATELLITE_NOT_SUPPORTED, null); |
| 12908 | return; |
Thomas Nguyen | e77de6d | 2023-02-10 17:42:43 -0800 | [diff] [blame] | 12909 | } |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12910 | |
| 12911 | final int validSubId = getValidSatelliteSubId(subId); |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame^] | 12912 | Bundle bundle = new Bundle(); |
| 12913 | bundle.putBoolean(SatelliteManager.KEY_SATELLITE_PROVISIONED, |
| 12914 | isSatelliteProvisioned(validSubId)); |
| 12915 | result.send(SatelliteManager.SATELLITE_ERROR_NONE, bundle); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12916 | } |
| 12917 | |
| 12918 | private void handleCmdProvisionSatelliteService(@NonNull ProvisionSatelliteServiceArgument arg, |
| 12919 | @NonNull Phone phone, Message onCompleted) { |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12920 | if (arg == null) { |
| 12921 | loge("handleCmdProvisionSatelliteService: arg is null"); |
| 12922 | return; |
| 12923 | } |
| 12924 | if (phone == null) { |
| 12925 | loge("handleCmdProvisionSatelliteService: phone is null"); |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame^] | 12926 | arg.callback.accept(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12927 | return; |
| 12928 | } |
| 12929 | |
| 12930 | if (!mSatelliteProvisionCallbacks.containsKey(arg.subId)) { |
| 12931 | mSatelliteProvisionCallbacks.put(arg.subId, arg.callback); |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame^] | 12932 | phone.provisionSatelliteService(onCompleted, arg.token, phone.getImei(), |
| 12933 | phone.getMsisdn(), getSatelliteImsi(arg.subId)); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12934 | } else { |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame^] | 12935 | arg.callback.accept(SatelliteManager.SATELLITE_SERVICE_PROVISION_IN_PROGRESS); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12936 | } |
| 12937 | } |
| 12938 | |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame^] | 12939 | private void handleEventProvisionSatelliteServiceDone(int subId, |
| 12940 | @SatelliteManager.SatelliteError int result) { |
| 12941 | Consumer<Integer> callback = mSatelliteProvisionCallbacks.remove(subId); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12942 | if (callback == null) { |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame^] | 12943 | loge("handleEventProvisionSatelliteServiceDone: callback is null for subId=" + subId); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12944 | return; |
| 12945 | } |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame^] | 12946 | callback.accept(result); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12947 | |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12948 | if (DBG) { |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame^] | 12949 | log("handleEventProvisionSatelliteServiceDone: result=" + result + ", subId=" |
| 12950 | + subId); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12951 | } |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12952 | |
Thomas Nguyen | e77de6d | 2023-02-10 17:42:43 -0800 | [diff] [blame] | 12953 | if (result == SatelliteManager.SATELLITE_ERROR_NONE) { |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame^] | 12954 | setSatelliteProvisioned(subId, true); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12955 | } |
| 12956 | |
| 12957 | /** |
| 12958 | * We need to update satellite provision status in SubscriptionController |
| 12959 | * or SatelliteController. |
| 12960 | * TODO (b/267826133) we need to do this for all subscriptions on the device. |
| 12961 | */ |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame^] | 12962 | registerForSatelliteProvisionStateChanged(subId, null, null); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12963 | } |
| 12964 | |
| 12965 | private void handleCmdCancelProvisionSatelliteService(int subId, Message onCompleted) { |
| 12966 | final Phone phone = getPhoneOrDefault( |
| 12967 | subId, "handleCmdCancelProvisionSatelliteService"); |
| 12968 | if (phone == null) { |
| 12969 | return; |
| 12970 | } |
| 12971 | phone.cancelProvisionSatelliteService(onCompleted, getSatelliteImsi(subId)); |
| 12972 | } |
| 12973 | |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12974 | private String getSatelliteImsi(int subId) { |
| 12975 | if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) { |
| 12976 | return ""; |
| 12977 | } |
| 12978 | |
| 12979 | if (mSubscriptionController == null) { |
| 12980 | loge("getSatelliteImsi: mSubscriptionController is null"); |
| 12981 | return ""; |
| 12982 | } |
| 12983 | return mSubscriptionController.getImsiPrivileged(subId); |
| 12984 | } |
| 12985 | |
| 12986 | private Phone getPhoneOrDefault(int subId, String caller) { |
| 12987 | Phone phone = getPhone(subId); |
| 12988 | if (phone == null) { |
| 12989 | loge(caller + " called with invalid subId: " + subId |
| 12990 | + ". Retrying with default phone."); |
| 12991 | phone = getDefaultPhone(); |
| 12992 | if (phone == null) { |
| 12993 | loge(caller + " failed with no phone object."); |
| 12994 | } |
| 12995 | } |
| 12996 | return phone; |
| 12997 | } |
| 12998 | |
| 12999 | /** |
Thomas Nguyen | e77de6d | 2023-02-10 17:42:43 -0800 | [diff] [blame] | 13000 | * Check if satellite is provisioned for a subscription or the device. |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13001 | * |
| 13002 | * Note: this is the version without permission check for telephony internal use only. The |
| 13003 | * caller need to take care of the permission check. |
| 13004 | */ |
Thomas Nguyen | e77de6d | 2023-02-10 17:42:43 -0800 | [diff] [blame] | 13005 | private boolean isSatelliteProvisioned(int subId) { |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13006 | if (subId != SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) { |
| 13007 | if (mSubscriptionController == null) { |
Thomas Nguyen | e77de6d | 2023-02-10 17:42:43 -0800 | [diff] [blame] | 13008 | loge("isSatelliteProvisioned mSubscriptionController is null"); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13009 | return false; |
| 13010 | } |
| 13011 | |
| 13012 | String strResult = mSubscriptionController.getSubscriptionProperty( |
| 13013 | subId, SubscriptionManager.SATELLITE_ENABLED); |
| 13014 | if (strResult != null) { |
| 13015 | int intResult = Integer.parseInt(strResult); |
| 13016 | return (intResult == 1) ? true : false; |
| 13017 | } |
| 13018 | } else { |
| 13019 | //TODO (b/267826133): check via SatelliteController |
| 13020 | } |
| 13021 | return false; |
| 13022 | } |
| 13023 | |
| 13024 | /** |
Thomas Nguyen | e77de6d | 2023-02-10 17:42:43 -0800 | [diff] [blame] | 13025 | * Set satellite provisioned for a subscription or the device. |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13026 | * |
| 13027 | * The permission {@link android.Manifest.permission#MODIFY_PHONE_STATE} will be enforced by |
| 13028 | * {@link SubscriptionController} when setting satellite enabled for an active subscription. |
| 13029 | * Otherwise, {@link android.Manifest.permission#SATELLITE_COMMUNICATION} will be enforced. |
| 13030 | */ |
Thomas Nguyen | e77de6d | 2023-02-10 17:42:43 -0800 | [diff] [blame] | 13031 | private void setSatelliteProvisioned(int subId, boolean isEnabled) { |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13032 | if (subId != SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) { |
| 13033 | if (mSubscriptionController == null) { |
Thomas Nguyen | e77de6d | 2023-02-10 17:42:43 -0800 | [diff] [blame] | 13034 | loge("setSatelliteProvisioned mSubscriptionController is null"); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13035 | return; |
| 13036 | } |
| 13037 | mSubscriptionController.setSubscriptionProperty( |
| 13038 | subId, SubscriptionManager.SATELLITE_ENABLED, isEnabled ? "1" : "0"); |
| 13039 | } else { |
Thomas Nguyen | e77de6d | 2023-02-10 17:42:43 -0800 | [diff] [blame] | 13040 | //TODO (b/267826133): set via SatelliteController |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13041 | } |
| 13042 | } |
| 13043 | |
| 13044 | private int getValidSatelliteSubId(int subId) { |
| 13045 | if (mSubscriptionController == null) { |
| 13046 | loge("getValidSatelliteSubId mSubscriptionController is null. " |
| 13047 | + "Use DEFAULT_SUBSCRIPTION_ID for subId=" + subId); |
| 13048 | return SubscriptionManager.DEFAULT_SUBSCRIPTION_ID; |
| 13049 | } |
| 13050 | final long identity = Binder.clearCallingIdentity(); |
| 13051 | try { |
| 13052 | Context context = getDefaultPhone().getContext(); |
| 13053 | if (mSubscriptionController.isActiveSubId( |
| 13054 | subId, context.getOpPackageName(), context.getAttributionTag())) { |
| 13055 | return subId; |
| 13056 | } |
| 13057 | } finally { |
| 13058 | Binder.restoreCallingIdentity(identity); |
| 13059 | } |
| 13060 | if (DBG) log("getValidSatelliteSubId: use DEFAULT_SUBSCRIPTION_ID for subId=" + subId); |
| 13061 | return SubscriptionManager.DEFAULT_SUBSCRIPTION_ID; |
| 13062 | } |
| 13063 | |
| 13064 | /** |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame^] | 13065 | * If we have not successfully queried the satellite modem for its satellite service support, |
| 13066 | * 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] | 13067 | */ |
| 13068 | private boolean isSatelliteSupported() { |
| 13069 | synchronized (mIsSatelliteSupportedLock) { |
| 13070 | if (mIsSatelliteSupported != null) { |
| 13071 | /* We have already successfully queried the satellite modem. */ |
| 13072 | return mIsSatelliteSupported; |
| 13073 | } |
| 13074 | } |
| 13075 | /** |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame^] | 13076 | * We have not successfully checked whether the modem supports satellite service. |
| 13077 | * Thus, we need to retry it now. |
Thomas Nguyen | e77de6d | 2023-02-10 17:42:43 -0800 | [diff] [blame] | 13078 | */ |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame^] | 13079 | requestIsSatelliteSupported(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, |
| 13080 | mSatelliteSupportedReceiver); |
| 13081 | return false; |
| 13082 | } |
| 13083 | |
| 13084 | /** |
| 13085 | * Get the {@link SatelliteManager.SatelliteError} from the provided result. |
| 13086 | * @param ar AsyncResult used to determine the error code. |
| 13087 | * @param caller The satellite request. |
| 13088 | * @param checkResult Whether to check if the result exists. |
| 13089 | * @return The {@link SatelliteManager.SatelliteError} error code from the request. |
| 13090 | */ |
| 13091 | @SatelliteManager.SatelliteError private int getSatelliteError(@NonNull AsyncResult ar, |
| 13092 | @NonNull String caller, boolean checkResult) { |
| 13093 | int errorCode; |
| 13094 | if (ar.exception == null) { |
| 13095 | errorCode = SatelliteManager.SATELLITE_ERROR_NONE; |
| 13096 | if (checkResult && ar.result == null) { |
| 13097 | loge(caller + ": result is null"); |
| 13098 | errorCode = SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE; |
| 13099 | } |
| 13100 | } else { |
| 13101 | errorCode = SatelliteManager.SATELLITE_ERROR; |
| 13102 | if (ar.exception instanceof CommandException) { |
| 13103 | CommandException.Error error = |
| 13104 | ((CommandException) (ar.exception)).getCommandError(); |
| 13105 | errorCode = RILUtils.convertToSatelliteError(error); |
| 13106 | loge(caller + " CommandException: " + ar.exception); |
| 13107 | } else { |
| 13108 | loge(caller + " unknown exception: " + ar.exception); |
Thomas Nguyen | e77de6d | 2023-02-10 17:42:43 -0800 | [diff] [blame] | 13109 | } |
| 13110 | } |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame^] | 13111 | log(caller + " error: " + errorCode); |
| 13112 | return errorCode; |
Thomas Nguyen | e77de6d | 2023-02-10 17:42:43 -0800 | [diff] [blame] | 13113 | } |
| 13114 | |
| 13115 | /** |
arunvoddu | d5c6ce0 | 2022-12-11 06:03:12 +0000 | [diff] [blame] | 13116 | * Check whether the caller (or self, if not processing an IPC) can read device identifiers. |
| 13117 | * |
| 13118 | * <p>This method behaves in one of the following ways: |
| 13119 | * <ul> |
| 13120 | * <li>return true : if the calling package has the appop permission {@link |
| 13121 | * Manifest.permission#USE_ICC_AUTH_WITH_DEVICE_IDENTIFIER} in the manifest </> |
| 13122 | * <li>return true : if any one subscription has the READ_PRIVILEGED_PHONE_STATE |
| 13123 | * permission, the calling package passes a DevicePolicyManager Device Owner / Profile |
| 13124 | * Owner device identifier access check, or the calling package has carrier privileges</> |
| 13125 | * <li>throw SecurityException: if the caller does not meet any of the requirements. |
| 13126 | * </ul> |
| 13127 | */ |
| 13128 | private static boolean checkCallingOrSelfReadDeviceIdentifiersForAnySub(Context context, |
| 13129 | String callingPackage, @Nullable String callingFeatureId, String message) { |
| 13130 | for (Phone phone : PhoneFactory.getPhones()) { |
| 13131 | if (TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(context, |
| 13132 | phone.getSubId(), callingPackage, callingFeatureId, message)) { |
| 13133 | return true; |
| 13134 | } |
| 13135 | } |
| 13136 | return false; |
| 13137 | } |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 13138 | |
| 13139 | /** |
Jack Yu | fa8ed01 | 2023-02-11 15:42:28 -0800 | [diff] [blame] | 13140 | * @return The subscription manager service instance. |
| 13141 | */ |
| 13142 | public SubscriptionManagerService getSubscriptionManagerService() { |
| 13143 | return SubscriptionManagerService.getInstance(); |
| 13144 | } |
| 13145 | |
| 13146 | /** |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 13147 | * Class binds the consumer[callback] and carrierId. |
| 13148 | */ |
| 13149 | private static class CallerCallbackInfo { |
| 13150 | private final Consumer<Integer> mConsumer; |
| 13151 | private final int mCarrierId; |
| 13152 | |
| 13153 | public CallerCallbackInfo(Consumer<Integer> consumer, int carrierId) { |
| 13154 | mConsumer = consumer; |
| 13155 | mCarrierId = carrierId; |
| 13156 | } |
| 13157 | |
| 13158 | public Consumer<Integer> getConsumer() { |
| 13159 | return mConsumer; |
| 13160 | } |
| 13161 | |
| 13162 | public int getCarrierId() { |
| 13163 | return mCarrierId; |
| 13164 | } |
| 13165 | } |
Jack Yu | fa8ed01 | 2023-02-11 15:42:28 -0800 | [diff] [blame] | 13166 | } |