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; |
| 150 | import android.telephony.satellite.SatelliteManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 151 | import android.text.TextUtils; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 152 | import android.util.ArraySet; |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 153 | import android.util.EventLog; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 154 | import android.util.Log; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 155 | import android.util.Pair; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 156 | |
Andrew Lee | 312e817 | 2014-10-23 17:01:36 -0700 | [diff] [blame] | 157 | import com.android.ims.ImsManager; |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 158 | import com.android.ims.internal.IImsServiceFeatureCallback; |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 159 | import com.android.ims.rcs.uce.eab.EabUtil; |
SongFerngWang | fd89b10 | 2021-05-27 22:44:54 +0800 | [diff] [blame] | 160 | import com.android.internal.annotations.VisibleForTesting; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 161 | import com.android.internal.telephony.CallForwardInfo; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 162 | import com.android.internal.telephony.CallManager; |
Tyler Gunn | 52dcf77 | 2017-04-26 11:30:31 -0700 | [diff] [blame] | 163 | import com.android.internal.telephony.CallStateException; |
Tyler Gunn | d433926 | 2021-05-03 14:46:49 -0700 | [diff] [blame] | 164 | import com.android.internal.telephony.CallTracker; |
Rambo Wang | 9c9ffdd | 2022-01-13 21:51:44 -0800 | [diff] [blame] | 165 | import com.android.internal.telephony.CarrierPrivilegesTracker; |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 166 | import com.android.internal.telephony.CarrierResolver; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 167 | import com.android.internal.telephony.CellNetworkScanResult; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 168 | import com.android.internal.telephony.CommandException; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 169 | import com.android.internal.telephony.CommandsInterface; |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 170 | import com.android.internal.telephony.GbaManager; |
Shuo Qian | ccbaf74 | 2021-02-22 18:32:21 -0800 | [diff] [blame] | 171 | import com.android.internal.telephony.GsmCdmaPhone; |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 172 | import com.android.internal.telephony.HalVersion; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 173 | import com.android.internal.telephony.IBooleanConsumer; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 174 | import com.android.internal.telephony.ICallForwardingInfoCallback; |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 175 | import com.android.internal.telephony.IImsStateCallback; |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame^] | 176 | import com.android.internal.telephony.IIntArrayConsumer; |
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; |
| 397 | private static final int CMD_GET_PROVISIONED_SATELLITE_FEATURES = 129; |
| 398 | private static final int EVENT_GET_PROVISIONED_SATELLITE_FEATURES_DONE = 130; |
| 399 | |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 400 | // Parameters of select command. |
| 401 | private static final int SELECT_COMMAND = 0xA4; |
| 402 | private static final int SELECT_P1 = 0x04; |
| 403 | private static final int SELECT_P2 = 0; |
| 404 | private static final int SELECT_P3 = 0x10; |
| 405 | |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 406 | // Toggling null cipher and integrity support was added in IRadioNetwork 2.1 |
| 407 | private static final int MIN_NULL_CIPHER_AND_INTEGRITY_VERSION = 201; |
| 408 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 409 | /** The singleton instance. */ |
| 410 | private static PhoneInterfaceManager sInstance; |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 411 | private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 412 | |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 413 | private PhoneGlobals mApp; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 414 | private CallManager mCM; |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 415 | private ImsResolver mImsResolver; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 416 | private UserManager mUserManager; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 417 | private AppOpsManager mAppOps; |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 418 | private PackageManager mPm; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 419 | private MainThreadHandler mMainThreadHandler; |
Jack Yu | e37dd26 | 2022-12-16 11:53:37 -0800 | [diff] [blame] | 420 | private final SubscriptionController mSubscriptionController; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 421 | private SharedPreferences mTelephonySharedPreferences; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 422 | private PhoneConfigurationManager mPhoneConfigurationManager; |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 423 | private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 424 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 425 | /** User Activity */ |
| 426 | private AtomicBoolean mNotifyUserActivity; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 427 | private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200; |
| 428 | |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 429 | private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>(); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame^] | 430 | private ConcurrentHashMap<IBinder, SatellitePositionUpdateHandler> |
| 431 | mSatellitePositionUpdateHandlers = new ConcurrentHashMap<>(); |
| 432 | /** |
| 433 | * Map key: subId, value: callback to get error code of the provision request. |
| 434 | */ |
| 435 | private ConcurrentHashMap<Integer, IIntegerConsumer> mSatelliteProvisionCallbacks = |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 436 | new ConcurrentHashMap<>(); |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 437 | |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame^] | 438 | /** |
| 439 | * Map key: subId, value: SatelliteProvisionStateChangedHandler to notify registrants. |
| 440 | */ |
| 441 | private ConcurrentHashMap<Integer, SatelliteProvisionStateChangedHandler> |
| 442 | mSatelliteProvisionStateChangedHandlers = new ConcurrentHashMap<>(); |
| 443 | |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 444 | private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_"; |
| 445 | private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_"; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 446 | private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_"; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 447 | private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_"; |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 448 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 449 | // String to store multi SIM allowed |
| 450 | private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted"; |
| 451 | |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 452 | // The AID of ISD-R. |
| 453 | private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100"; |
| 454 | |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 455 | private NetworkScanRequestTracker mNetworkScanRequestTracker; |
| 456 | |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 457 | private static final int TYPE_ALLOCATION_CODE_LENGTH = 8; |
| 458 | private static final int MANUFACTURER_CODE_LENGTH = 8; |
| 459 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 460 | private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1; |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 461 | 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] | 462 | |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 463 | private static final String PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID = |
| 464 | "24bf97a6-e8a6-44d8-a6a4-255d7548733c"; |
| 465 | |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 466 | /** |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 467 | * Experiment flag to enable erase modem config on reset network, default value is false |
| 468 | */ |
| 469 | public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED = |
| 470 | "reset_network_erase_modem_config_enabled"; |
| 471 | |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 472 | 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] | 473 | |
Gary Jian | 76280a4 | 2022-12-07 16:18:33 +0800 | [diff] [blame] | 474 | private static final int MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS = 50; |
| 475 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 476 | /** |
| 477 | * With support for MEP(multiple enabled profile) in Android T, a SIM card can have more than |
| 478 | * one ICCID active at the same time. |
| 479 | * Apps should use below API signatures if targeting SDK is T and beyond. |
| 480 | * |
| 481 | * @hide |
| 482 | */ |
| 483 | @ChangeId |
| 484 | @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU) |
| 485 | public static final long GET_API_SIGNATURES_FROM_UICC_PORT_INFO = 202110963L; |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 486 | |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 487 | /** |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 488 | * Apps targeting on Android T and beyond will get exception whenever icc close channel |
| 489 | * operation fails. |
| 490 | */ |
| 491 | @ChangeId |
| 492 | @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU) |
| 493 | public static final long ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE = 208739934L; |
| 494 | |
| 495 | /** |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 496 | * A request object to use for transmitting data to an ICC. |
| 497 | */ |
| 498 | private static final class IccAPDUArgument { |
| 499 | public int channel, cla, command, p1, p2, p3; |
| 500 | public String data; |
| 501 | |
| 502 | public IccAPDUArgument(int channel, int cla, int command, |
| 503 | int p1, int p2, int p3, String data) { |
| 504 | this.channel = channel; |
| 505 | this.cla = cla; |
| 506 | this.command = command; |
| 507 | this.p1 = p1; |
| 508 | this.p2 = p2; |
| 509 | this.p3 = p3; |
| 510 | this.data = data; |
| 511 | } |
| 512 | } |
| 513 | |
| 514 | /** |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 515 | * A request object to use for transmitting data to an ICC. |
| 516 | */ |
| 517 | private static final class ManualNetworkSelectionArgument { |
| 518 | public OperatorInfo operatorInfo; |
| 519 | public boolean persistSelection; |
| 520 | |
| 521 | public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) { |
| 522 | this.operatorInfo = operatorInfo; |
| 523 | this.persistSelection = persistSelection; |
| 524 | } |
| 525 | } |
| 526 | |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 527 | private static final class PurchasePremiumCapabilityArgument { |
| 528 | public @TelephonyManager.PremiumCapability int capability; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 529 | public @NonNull IIntegerConsumer callback; |
| 530 | |
| 531 | PurchasePremiumCapabilityArgument(@TelephonyManager.PremiumCapability int capability, |
Sarah Chin | b8218c2 | 2023-01-04 13:35:29 -0800 | [diff] [blame] | 532 | @NonNull IIntegerConsumer callback) { |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 533 | this.capability = capability; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 534 | this.callback = callback; |
| 535 | } |
| 536 | } |
| 537 | |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame^] | 538 | private static final class ProvisionSatelliteServiceArgument { |
| 539 | public @NonNull int[] features; |
| 540 | public @NonNull IIntegerConsumer callback; |
| 541 | public int subId; |
| 542 | |
| 543 | ProvisionSatelliteServiceArgument(int[] features, IIntegerConsumer callback, int subId) { |
| 544 | this.features = features; |
| 545 | this.callback = callback; |
| 546 | this.subId = subId; |
| 547 | } |
| 548 | } |
| 549 | |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 550 | private static final class SatellitePositionUpdateHandler extends Handler { |
| 551 | public static final int EVENT_POSITION_UPDATE = 1; |
| 552 | public static final int EVENT_MESSAGE_TRANSFER_STATE_UPDATE = 2; |
| 553 | |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame^] | 554 | private final ISatelliteStateListener mCallback; |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 555 | |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame^] | 556 | SatellitePositionUpdateHandler(ISatelliteStateListener callback, Looper looper) { |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 557 | super(looper); |
| 558 | mCallback = callback; |
| 559 | } |
| 560 | |
| 561 | @Override |
| 562 | public void handleMessage(@NonNull Message msg) { |
| 563 | switch (msg.what) { |
| 564 | case EVENT_POSITION_UPDATE: { |
| 565 | AsyncResult ar = (AsyncResult) msg.obj; |
| 566 | PointingInfo pointingInfo = (PointingInfo) ar.result; |
| 567 | try { |
| 568 | mCallback.onSatellitePositionUpdate(pointingInfo); |
| 569 | } catch (RemoteException e) { |
| 570 | loge("EVENT_POSITION_UPDATE RemoteException: " + e); |
| 571 | } |
| 572 | break; |
| 573 | } |
| 574 | case EVENT_MESSAGE_TRANSFER_STATE_UPDATE: { |
| 575 | AsyncResult ar = (AsyncResult) msg.obj; |
| 576 | int state = (int) ar.result; |
| 577 | try { |
| 578 | mCallback.onMessageTransferStateUpdate(state); |
| 579 | } catch (RemoteException e) { |
| 580 | loge("EVENT_MESSAGE_TRANSFER_STATE_UPDATE RemoteException: " + e); |
| 581 | } |
| 582 | break; |
| 583 | } |
| 584 | default: |
| 585 | loge("SatellitePositionUpdateHandler unknown event: " + msg.what); |
| 586 | } |
| 587 | } |
| 588 | } |
| 589 | |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame^] | 590 | private static final class SatelliteProvisionStateChangedHandler extends Handler { |
| 591 | public static final int EVENT_PROVISION_STATE_CHANGED = 1; |
| 592 | |
| 593 | private ConcurrentHashMap<IBinder, ISatelliteStateListener> mListeners; |
| 594 | private final int mSubId; |
| 595 | |
| 596 | SatelliteProvisionStateChangedHandler(Looper looper, int subId) { |
| 597 | super(looper); |
| 598 | mListeners = new ConcurrentHashMap<>(); |
| 599 | mSubId = subId; |
| 600 | } |
| 601 | |
| 602 | public void addListener(ISatelliteStateListener listener) { |
| 603 | mListeners.put(listener.asBinder(), listener); |
| 604 | } |
| 605 | |
| 606 | public boolean removeListener(ISatelliteStateListener listener) { |
| 607 | return (mListeners.remove(listener.asBinder()) != null); |
| 608 | } |
| 609 | |
| 610 | @Override |
| 611 | public void handleMessage(@NonNull Message msg) { |
| 612 | switch (msg.what) { |
| 613 | case EVENT_PROVISION_STATE_CHANGED: { |
| 614 | AsyncResult ar = (AsyncResult) msg.obj; |
| 615 | boolean provisioned = (boolean) ar.userObj; |
| 616 | int[] features = (int[]) ar.result; |
| 617 | log("Received EVENT_PROVISION_STATE_CHANGED for subId=" + mSubId |
| 618 | + ", features=" + Arrays.toString(features) |
| 619 | + ", provisioned=" + provisioned); |
| 620 | mListeners.values().forEach(listener -> { |
| 621 | try { |
| 622 | listener.onSatelliteProvisionStateChanged(features, provisioned); |
| 623 | } catch (RemoteException e) { |
| 624 | log("EVENT_PROVISION_STATE_CHANGED RemoteException: " + e); |
| 625 | } |
| 626 | }); |
| 627 | |
| 628 | setSatelliteEnabled(provisioned); |
| 629 | /** |
| 630 | * TODO: Take bugreport if provisioned is true and user did not initiate the |
| 631 | * provision procedure for the corresponding subscription. |
| 632 | */ |
| 633 | break; |
| 634 | } |
| 635 | default: |
| 636 | loge("SatelliteProvisionStateChangedHandler unknown event: " + msg.what); |
| 637 | } |
| 638 | } |
| 639 | |
| 640 | private void setSatelliteEnabled(boolean isEnabled) { |
| 641 | if (mSubId != SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) { |
| 642 | SubscriptionManager.setSubscriptionProperty( |
| 643 | mSubId, SubscriptionManager.SATELLITE_ENABLED, isEnabled ? "1" : "0"); |
| 644 | } else { |
| 645 | //TODO (b/267826133): set enabled via SatelliteController. |
| 646 | } |
| 647 | } |
| 648 | } |
| 649 | |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 650 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 651 | * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the |
| 652 | * request after sending. The main thread will notify the request when it is complete. |
| 653 | */ |
| 654 | private static final class MainThreadRequest { |
| 655 | /** The argument to use for the request */ |
| 656 | public Object argument; |
| 657 | /** The result of the request that is run on the main thread */ |
| 658 | public Object result; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 659 | // The subscriber id that this request applies to. Defaults to |
| 660 | // SubscriptionManager.INVALID_SUBSCRIPTION_ID |
| 661 | public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 662 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 663 | // In cases where subId is unavailable, the caller needs to specify the phone. |
| 664 | public Phone phone; |
| 665 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 666 | public WorkSource workSource; |
| 667 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 668 | public MainThreadRequest(Object argument) { |
| 669 | this.argument = argument; |
| 670 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 671 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 672 | MainThreadRequest(Object argument, Phone phone, WorkSource workSource) { |
| 673 | this.argument = argument; |
| 674 | if (phone != null) { |
| 675 | this.phone = phone; |
| 676 | } |
| 677 | this.workSource = workSource; |
| 678 | } |
| 679 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 680 | MainThreadRequest(Object argument, Integer subId, WorkSource workSource) { |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 681 | this.argument = argument; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 682 | if (subId != null) { |
| 683 | this.subId = subId; |
| 684 | } |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 685 | this.workSource = workSource; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 686 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 687 | } |
| 688 | |
Sailesh Nepal | cc0375f | 2013-11-13 09:15:18 -0800 | [diff] [blame] | 689 | private static final class IncomingThirdPartyCallArgs { |
| 690 | public final ComponentName component; |
| 691 | public final String callId; |
| 692 | public final String callerDisplayName; |
| 693 | |
| 694 | public IncomingThirdPartyCallArgs(ComponentName component, String callId, |
| 695 | String callerDisplayName) { |
| 696 | this.component = component; |
| 697 | this.callId = callId; |
| 698 | this.callerDisplayName = callerDisplayName; |
| 699 | } |
| 700 | } |
| 701 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 702 | /** |
| 703 | * A handler that processes messages on the main thread in the phone process. Since many |
| 704 | * of the Phone calls are not thread safe this is needed to shuttle the requests from the |
| 705 | * inbound binder threads to the main thread in the phone process. The Binder thread |
| 706 | * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting |
| 707 | * on, which will be notified when the operation completes and will contain the result of the |
| 708 | * request. |
| 709 | * |
| 710 | * <p>If a MainThreadRequest object is provided in the msg.obj field, |
| 711 | * note that request.result must be set to something non-null for the calling thread to |
| 712 | * unblock. |
| 713 | */ |
| 714 | private final class MainThreadHandler extends Handler { |
| 715 | @Override |
| 716 | public void handleMessage(Message msg) { |
| 717 | MainThreadRequest request; |
| 718 | Message onCompleted; |
| 719 | AsyncResult ar; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 720 | UiccPort uiccPort; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 721 | IccAPDUArgument iccArgument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 722 | final Phone defaultPhone = getDefaultPhone(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 723 | |
| 724 | switch (msg.what) { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 725 | case CMD_HANDLE_USSD_REQUEST: { |
| 726 | request = (MainThreadRequest) msg.obj; |
| 727 | final Phone phone = getPhoneFromRequest(request); |
| 728 | Pair<String, ResultReceiver> ussdObject = (Pair) request.argument; |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 729 | String ussdRequest = ussdObject.first; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 730 | ResultReceiver wrappedCallback = ussdObject.second; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 731 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 732 | if (!isUssdApiAllowed(request.subId)) { |
| 733 | // Carrier does not support use of this API, return failure. |
| 734 | Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis."); |
| 735 | UssdResponse response = new UssdResponse(ussdRequest, null); |
| 736 | Bundle returnData = new Bundle(); |
| 737 | returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response); |
| 738 | wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 739 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 740 | request.result = true; |
| 741 | notifyRequester(request); |
| 742 | return; |
| 743 | } |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 744 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 745 | try { |
| 746 | request.result = phone != null |
| 747 | ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false; |
| 748 | } catch (CallStateException cse) { |
| 749 | request.result = false; |
| 750 | } |
| 751 | // Wake up the requesting thread |
| 752 | notifyRequester(request); |
| 753 | break; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 754 | } |
| 755 | |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 756 | case CMD_HANDLE_PIN_MMI: { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 757 | request = (MainThreadRequest) msg.obj; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 758 | final Phone phone = getPhoneFromRequest(request); |
| 759 | request.result = phone != null ? |
| 760 | getPhoneFromRequest(request).handlePinMmi((String) request.argument) |
| 761 | : false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 762 | // Wake up the requesting thread |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 763 | notifyRequester(request); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 764 | break; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 765 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 766 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 767 | case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 768 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 769 | iccArgument = (IccAPDUArgument) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 770 | uiccPort = getUiccPortFromRequest(request); |
| 771 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 772 | loge("iccTransmitApduLogicalChannel: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 773 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 774 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 775 | } else { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 776 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE, |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 777 | request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 778 | uiccPort.iccTransmitApduLogicalChannel( |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 779 | iccArgument.channel, iccArgument.cla, iccArgument.command, |
| 780 | iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data, |
| 781 | onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 782 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 783 | break; |
| 784 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 785 | case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 786 | ar = (AsyncResult) msg.obj; |
| 787 | request = (MainThreadRequest) ar.userObj; |
| 788 | if (ar.exception == null && ar.result != null) { |
| 789 | request.result = ar.result; |
| 790 | } else { |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 791 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 792 | if (ar.result == null) { |
| 793 | loge("iccTransmitApduLogicalChannel: Empty response"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 794 | } else if (ar.exception instanceof CommandException) { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 795 | loge("iccTransmitApduLogicalChannel: CommandException: " + |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 796 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 797 | } else { |
| 798 | loge("iccTransmitApduLogicalChannel: Unknown exception"); |
| 799 | } |
| 800 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 801 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 802 | break; |
| 803 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 804 | case CMD_TRANSMIT_APDU_BASIC_CHANNEL: |
| 805 | request = (MainThreadRequest) msg.obj; |
| 806 | iccArgument = (IccAPDUArgument) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 807 | uiccPort = getUiccPortFromRequest(request); |
| 808 | if (uiccPort == null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 809 | loge("iccTransmitApduBasicChannel: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 810 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 811 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 812 | } else { |
| 813 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE, |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 814 | request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 815 | uiccPort.iccTransmitApduBasicChannel( |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 816 | iccArgument.cla, iccArgument.command, iccArgument.p1, |
| 817 | iccArgument.p2, |
| 818 | iccArgument.p3, iccArgument.data, onCompleted); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 819 | } |
| 820 | break; |
| 821 | |
| 822 | case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE: |
| 823 | ar = (AsyncResult) msg.obj; |
| 824 | request = (MainThreadRequest) ar.userObj; |
| 825 | if (ar.exception == null && ar.result != null) { |
| 826 | request.result = ar.result; |
| 827 | } else { |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 828 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 829 | if (ar.result == null) { |
| 830 | loge("iccTransmitApduBasicChannel: Empty response"); |
| 831 | } else if (ar.exception instanceof CommandException) { |
| 832 | loge("iccTransmitApduBasicChannel: CommandException: " + |
| 833 | ar.exception); |
| 834 | } else { |
| 835 | loge("iccTransmitApduBasicChannel: Unknown exception"); |
| 836 | } |
| 837 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 838 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 839 | break; |
| 840 | |
| 841 | case CMD_EXCHANGE_SIM_IO: |
| 842 | request = (MainThreadRequest) msg.obj; |
| 843 | iccArgument = (IccAPDUArgument) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 844 | uiccPort = getUiccPortFromRequest(request); |
| 845 | if (uiccPort == null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 846 | loge("iccExchangeSimIO: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 847 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 848 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 849 | } else { |
| 850 | onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE, |
| 851 | request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 852 | uiccPort.iccExchangeSimIO(iccArgument.cla, /* fileID */ |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 853 | iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3, |
| 854 | iccArgument.data, onCompleted); |
| 855 | } |
| 856 | break; |
| 857 | |
| 858 | case EVENT_EXCHANGE_SIM_IO_DONE: |
| 859 | ar = (AsyncResult) msg.obj; |
| 860 | request = (MainThreadRequest) ar.userObj; |
| 861 | if (ar.exception == null && ar.result != null) { |
| 862 | request.result = ar.result; |
| 863 | } else { |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 864 | request.result = new IccIoResult(0x6f, 0, (byte[]) null); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 865 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 866 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 867 | break; |
| 868 | |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 869 | case CMD_SEND_ENVELOPE: |
| 870 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 871 | uiccPort = getUiccPortFromRequest(request); |
| 872 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 873 | loge("sendEnvelopeWithStatus: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 874 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 875 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 876 | } else { |
| 877 | onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 878 | uiccPort.sendEnvelopeWithStatus((String) request.argument, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 879 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 880 | break; |
| 881 | |
| 882 | case EVENT_SEND_ENVELOPE_DONE: |
| 883 | ar = (AsyncResult) msg.obj; |
| 884 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 885 | if (ar.exception == null && ar.result != null) { |
| 886 | request.result = ar.result; |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 887 | } else { |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 888 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 889 | if (ar.result == null) { |
| 890 | loge("sendEnvelopeWithStatus: Empty response"); |
| 891 | } else if (ar.exception instanceof CommandException) { |
| 892 | loge("sendEnvelopeWithStatus: CommandException: " + |
| 893 | ar.exception); |
| 894 | } else { |
| 895 | loge("sendEnvelopeWithStatus: exception:" + ar.exception); |
| 896 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 897 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 898 | notifyRequester(request); |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 899 | break; |
| 900 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 901 | case CMD_OPEN_CHANNEL: |
| 902 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 903 | uiccPort = getUiccPortFromRequest(request); |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 904 | IccLogicalChannelRequest openChannelRequest = |
| 905 | (IccLogicalChannelRequest) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 906 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 907 | loge("iccOpenLogicalChannel: No UICC"); |
Shishir Agrawal | fc0492a | 2016-02-17 11:15:33 -0800 | [diff] [blame] | 908 | request.result = new IccOpenLogicalChannelResponse(-1, |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 909 | IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 910 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 911 | } else { |
| 912 | onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request); |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 913 | uiccPort.iccOpenLogicalChannel(openChannelRequest.aid, |
| 914 | openChannelRequest.p2, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 915 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 916 | break; |
| 917 | |
| 918 | case EVENT_OPEN_CHANNEL_DONE: |
| 919 | ar = (AsyncResult) msg.obj; |
| 920 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 921 | IccOpenLogicalChannelResponse openChannelResp; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 922 | if (ar.exception == null && ar.result != null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 923 | int[] result = (int[]) ar.result; |
| 924 | int channelId = result[0]; |
| 925 | byte[] selectResponse = null; |
| 926 | if (result.length > 1) { |
| 927 | selectResponse = new byte[result.length - 1]; |
| 928 | for (int i = 1; i < result.length; ++i) { |
| 929 | selectResponse[i - 1] = (byte) result[i]; |
| 930 | } |
| 931 | } |
| 932 | openChannelResp = new IccOpenLogicalChannelResponse(channelId, |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 933 | IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse); |
Rambo Wang | 3b77c4c | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 934 | |
| 935 | uiccPort = getUiccPortFromRequest(request); |
Rambo Wang | e53e07d | 2022-05-10 13:01:13 -0700 | [diff] [blame] | 936 | if (uiccPort == null) { |
| 937 | loge("EVENT_OPEN_CHANNEL_DONE: UiccPort is null"); |
| 938 | } else { |
| 939 | IccLogicalChannelRequest channelRequest = |
| 940 | (IccLogicalChannelRequest) request.argument; |
| 941 | channelRequest.channel = channelId; |
| 942 | uiccPort.onLogicalChannelOpened(channelRequest); |
| 943 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 944 | } else { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 945 | if (ar.result == null) { |
| 946 | loge("iccOpenLogicalChannel: Empty response"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 947 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 948 | if (ar.exception != null) { |
| 949 | loge("iccOpenLogicalChannel: Exception: " + ar.exception); |
| 950 | } |
| 951 | |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 952 | int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 953 | if (ar.exception instanceof CommandException) { |
| 954 | CommandException.Error error = |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 955 | ((CommandException) (ar.exception)).getCommandError(); |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 956 | if (error == CommandException.Error.MISSING_RESOURCE) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 957 | errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 958 | } else if (error == CommandException.Error.NO_SUCH_ELEMENT) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 959 | errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 960 | } |
| 961 | } |
| 962 | openChannelResp = new IccOpenLogicalChannelResponse( |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 963 | IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 964 | } |
Shishir Agrawal | 82c8a46 | 2014-07-31 18:13:17 -0700 | [diff] [blame] | 965 | request.result = openChannelResp; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 966 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 967 | break; |
| 968 | |
| 969 | case CMD_CLOSE_CHANNEL: |
| 970 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 971 | uiccPort = getUiccPortFromRequest(request); |
| 972 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 973 | loge("iccCloseLogicalChannel: No UICC"); |
Chen Xu | a8f0dff | 2022-02-12 00:34:15 -0800 | [diff] [blame] | 974 | request.result = new IllegalArgumentException( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame^] | 975 | "iccCloseLogicalChannel: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 976 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 977 | } else { |
| 978 | onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 979 | uiccPort.iccCloseLogicalChannel((Integer) request.argument, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 980 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 981 | break; |
| 982 | |
| 983 | case EVENT_CLOSE_CHANNEL_DONE: |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 984 | ar = (AsyncResult) msg.obj; |
| 985 | request = (MainThreadRequest) ar.userObj; |
| 986 | if (ar.exception == null) { |
| 987 | request.result = true; |
Rambo Wang | 3b77c4c | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 988 | uiccPort = getUiccPortFromRequest(request); |
Rambo Wang | e53e07d | 2022-05-10 13:01:13 -0700 | [diff] [blame] | 989 | if (uiccPort == null) { |
| 990 | loge("EVENT_CLOSE_CHANNEL_DONE: UiccPort is null"); |
| 991 | } else { |
| 992 | final int channelId = (Integer) request.argument; |
| 993 | uiccPort.onLogicalChannelClosed(channelId); |
| 994 | } |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 995 | } else { |
| 996 | request.result = false; |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 997 | Exception exception = null; |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 998 | if (ar.exception instanceof CommandException) { |
| 999 | loge("iccCloseLogicalChannel: CommandException: " + ar.exception); |
| 1000 | CommandException.Error error = |
| 1001 | ((CommandException) (ar.exception)).getCommandError(); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 1002 | if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 1003 | // should only throw exceptions from the binder threads. |
| 1004 | exception = new IllegalArgumentException( |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 1005 | "iccCloseLogicalChannel: invalid argument "); |
| 1006 | } |
| 1007 | } else { |
| 1008 | loge("iccCloseLogicalChannel: Unknown exception"); |
| 1009 | } |
Chen Xu | a8f0dff | 2022-02-12 00:34:15 -0800 | [diff] [blame] | 1010 | request.result = (exception != null) ? exception : |
| 1011 | new IllegalStateException( |
| 1012 | "exception from modem to close iccLogical Channel"); |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 1013 | } |
| 1014 | notifyRequester(request); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1015 | break; |
| 1016 | |
| 1017 | case CMD_NV_READ_ITEM: |
| 1018 | request = (MainThreadRequest) msg.obj; |
| 1019 | onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1020 | defaultPhone.nvReadItem((Integer) request.argument, onCompleted, |
| 1021 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1022 | break; |
| 1023 | |
| 1024 | case EVENT_NV_READ_ITEM_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 1025 | ar = (AsyncResult) msg.obj; |
| 1026 | request = (MainThreadRequest) ar.userObj; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1027 | if (ar.exception == null && ar.result != null) { |
| 1028 | request.result = ar.result; // String |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 1029 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1030 | request.result = ""; |
| 1031 | if (ar.result == null) { |
| 1032 | loge("nvReadItem: Empty response"); |
| 1033 | } else if (ar.exception instanceof CommandException) { |
| 1034 | loge("nvReadItem: CommandException: " + |
| 1035 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 1036 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1037 | loge("nvReadItem: Unknown exception"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 1038 | } |
| 1039 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1040 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 1041 | break; |
| 1042 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1043 | case CMD_NV_WRITE_ITEM: |
| 1044 | request = (MainThreadRequest) msg.obj; |
| 1045 | onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request); |
| 1046 | Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1047 | defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 1048 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1049 | break; |
| 1050 | |
| 1051 | case EVENT_NV_WRITE_ITEM_DONE: |
| 1052 | handleNullReturnEvent(msg, "nvWriteItem"); |
| 1053 | break; |
| 1054 | |
| 1055 | case CMD_NV_WRITE_CDMA_PRL: |
| 1056 | request = (MainThreadRequest) msg.obj; |
| 1057 | onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1058 | defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1059 | break; |
| 1060 | |
| 1061 | case EVENT_NV_WRITE_CDMA_PRL_DONE: |
| 1062 | handleNullReturnEvent(msg, "nvWriteCdmaPrl"); |
| 1063 | break; |
| 1064 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1065 | case CMD_RESET_MODEM_CONFIG: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1066 | request = (MainThreadRequest) msg.obj; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1067 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1068 | defaultPhone.resetModemConfig(onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1069 | break; |
| 1070 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1071 | case EVENT_RESET_MODEM_CONFIG_DONE: |
| 1072 | handleNullReturnEvent(msg, "resetModemConfig"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1073 | break; |
| 1074 | |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 1075 | case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: { |
| 1076 | request = (MainThreadRequest) msg.obj; |
| 1077 | onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE, |
| 1078 | request); |
| 1079 | Phone phone = getPhoneFromRequest(request); |
| 1080 | if (phone != null) { |
| 1081 | phone.isNrDualConnectivityEnabled(onCompleted, request.workSource); |
| 1082 | } else { |
| 1083 | loge("isNRDualConnectivityEnabled: No phone object"); |
| 1084 | request.result = false; |
| 1085 | notifyRequester(request); |
| 1086 | } |
| 1087 | break; |
| 1088 | } |
| 1089 | |
| 1090 | case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE: |
| 1091 | ar = (AsyncResult) msg.obj; |
| 1092 | request = (MainThreadRequest) ar.userObj; |
| 1093 | if (ar.exception == null && ar.result != null) { |
| 1094 | request.result = ar.result; |
| 1095 | } else { |
| 1096 | // request.result must be set to something non-null |
| 1097 | // for the calling thread to unblock |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 1098 | if (ar.result != null) { |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 1099 | request.result = ar.result; |
| 1100 | } else { |
| 1101 | request.result = false; |
| 1102 | } |
| 1103 | if (ar.result == null) { |
| 1104 | loge("isNRDualConnectivityEnabled: Empty response"); |
| 1105 | } else if (ar.exception instanceof CommandException) { |
| 1106 | loge("isNRDualConnectivityEnabled: CommandException: " |
| 1107 | + ar.exception); |
| 1108 | } else { |
| 1109 | loge("isNRDualConnectivityEnabled: Unknown exception"); |
| 1110 | } |
| 1111 | } |
| 1112 | notifyRequester(request); |
| 1113 | break; |
| 1114 | |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 1115 | case CMD_IS_VONR_ENABLED: { |
| 1116 | request = (MainThreadRequest) msg.obj; |
| 1117 | onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE, |
| 1118 | request); |
| 1119 | Phone phone = getPhoneFromRequest(request); |
| 1120 | if (phone != null) { |
| 1121 | phone.isVoNrEnabled(onCompleted, request.workSource); |
| 1122 | } else { |
| 1123 | loge("isVoNrEnabled: No phone object"); |
| 1124 | request.result = false; |
| 1125 | notifyRequester(request); |
| 1126 | } |
| 1127 | break; |
| 1128 | } |
| 1129 | |
| 1130 | case EVENT_IS_VONR_ENABLED_DONE: |
| 1131 | ar = (AsyncResult) msg.obj; |
| 1132 | request = (MainThreadRequest) ar.userObj; |
| 1133 | if (ar.exception == null && ar.result != null) { |
| 1134 | request.result = ar.result; |
| 1135 | } else { |
| 1136 | // request.result must be set to something non-null |
| 1137 | // for the calling thread to unblock |
| 1138 | if (ar.result != null) { |
| 1139 | request.result = ar.result; |
| 1140 | } else { |
| 1141 | request.result = false; |
| 1142 | } |
| 1143 | if (ar.result == null) { |
| 1144 | loge("isVoNrEnabled: Empty response"); |
| 1145 | } else if (ar.exception instanceof CommandException) { |
| 1146 | loge("isVoNrEnabled: CommandException: " |
| 1147 | + ar.exception); |
| 1148 | } else { |
| 1149 | loge("isVoNrEnabled: Unknown exception"); |
| 1150 | } |
| 1151 | } |
| 1152 | notifyRequester(request); |
| 1153 | break; |
| 1154 | |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 1155 | case CMD_ENABLE_NR_DUAL_CONNECTIVITY: { |
| 1156 | request = (MainThreadRequest) msg.obj; |
| 1157 | onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request); |
| 1158 | Phone phone = getPhoneFromRequest(request); |
| 1159 | if (phone != null) { |
| 1160 | phone.setNrDualConnectivityState((int) request.argument, onCompleted, |
| 1161 | request.workSource); |
| 1162 | } else { |
| 1163 | loge("enableNrDualConnectivity: No phone object"); |
| 1164 | request.result = |
| 1165 | TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE; |
| 1166 | notifyRequester(request); |
| 1167 | } |
| 1168 | break; |
| 1169 | } |
| 1170 | |
| 1171 | case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: { |
| 1172 | ar = (AsyncResult) msg.obj; |
| 1173 | request = (MainThreadRequest) ar.userObj; |
| 1174 | if (ar.exception == null) { |
| 1175 | request.result = |
| 1176 | TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS; |
| 1177 | } else { |
| 1178 | request.result = |
| 1179 | TelephonyManager |
| 1180 | .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR; |
| 1181 | if (ar.exception instanceof CommandException) { |
| 1182 | CommandException.Error error = |
| 1183 | ((CommandException) (ar.exception)).getCommandError(); |
| 1184 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1185 | request.result = |
| 1186 | TelephonyManager |
| 1187 | .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE; |
Sooraj Sasindran | 2965416 | 2021-03-03 23:00:01 +0000 | [diff] [blame] | 1188 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1189 | request.result = |
| 1190 | TelephonyManager |
| 1191 | .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED; |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 1192 | } |
| 1193 | loge("enableNrDualConnectivity" + ": CommandException: " |
| 1194 | + ar.exception); |
| 1195 | } else { |
| 1196 | loge("enableNrDualConnectivity" + ": Unknown exception"); |
| 1197 | } |
| 1198 | } |
| 1199 | notifyRequester(request); |
| 1200 | break; |
| 1201 | } |
| 1202 | |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 1203 | case CMD_ENABLE_VONR: { |
| 1204 | request = (MainThreadRequest) msg.obj; |
| 1205 | onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request); |
| 1206 | Phone phone = getPhoneFromRequest(request); |
| 1207 | if (phone != null) { |
| 1208 | phone.setVoNrEnabled((boolean) request.argument, onCompleted, |
| 1209 | request.workSource); |
| 1210 | } else { |
| 1211 | loge("setVoNrEnabled: No phone object"); |
| 1212 | request.result = |
| 1213 | TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE; |
| 1214 | notifyRequester(request); |
| 1215 | } |
| 1216 | break; |
| 1217 | } |
| 1218 | |
| 1219 | case EVENT_ENABLE_VONR_DONE: { |
| 1220 | ar = (AsyncResult) msg.obj; |
| 1221 | request = (MainThreadRequest) ar.userObj; |
| 1222 | if (ar.exception == null) { |
| 1223 | request.result = TelephonyManager.ENABLE_VONR_SUCCESS; |
| 1224 | } else { |
| 1225 | request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR; |
| 1226 | if (ar.exception instanceof CommandException) { |
| 1227 | CommandException.Error error = |
| 1228 | ((CommandException) (ar.exception)).getCommandError(); |
| 1229 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1230 | request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE; |
| 1231 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1232 | request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED; |
| 1233 | } else { |
| 1234 | request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR; |
| 1235 | } |
| 1236 | loge("setVoNrEnabled" + ": CommandException: " |
| 1237 | + ar.exception); |
| 1238 | } else { |
| 1239 | loge("setVoNrEnabled" + ": Unknown exception"); |
| 1240 | } |
| 1241 | } |
| 1242 | notifyRequester(request); |
| 1243 | break; |
| 1244 | } |
| 1245 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1246 | case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1247 | request = (MainThreadRequest) msg.obj; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1248 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE, |
| 1249 | request); |
| 1250 | getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1251 | break; |
| 1252 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1253 | case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1254 | ar = (AsyncResult) msg.obj; |
| 1255 | request = (MainThreadRequest) ar.userObj; |
| 1256 | if (ar.exception == null && ar.result != null) { |
| 1257 | request.result = ar.result; // Integer |
| 1258 | } else { |
Nazish Tabassum | e8ba43a | 2020-07-28 14:49:25 +0530 | [diff] [blame] | 1259 | // request.result must be set to something non-null |
| 1260 | // for the calling thread to unblock |
| 1261 | request.result = new int[]{-1}; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1262 | if (ar.result == null) { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1263 | loge("getAllowedNetworkTypesBitmask: Empty response"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1264 | } else if (ar.exception instanceof CommandException) { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1265 | loge("getAllowedNetworkTypesBitmask: CommandException: " |
| 1266 | + ar.exception); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1267 | } else { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1268 | loge("getAllowedNetworkTypesBitmask: Unknown exception"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1269 | } |
| 1270 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1271 | notifyRequester(request); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1272 | break; |
| 1273 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1274 | case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1275 | request = (MainThreadRequest) msg.obj; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1276 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE, |
| 1277 | request); |
| 1278 | Pair<Integer, Long> reasonWithNetworkTypes = |
| 1279 | (Pair<Integer, Long>) request.argument; |
| 1280 | getPhoneFromRequest(request).setAllowedNetworkTypes( |
| 1281 | reasonWithNetworkTypes.first, |
| 1282 | reasonWithNetworkTypes.second, |
| 1283 | onCompleted); |
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 EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE: |
| 1287 | handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1288 | break; |
| 1289 | |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 1290 | case CMD_INVOKE_OEM_RIL_REQUEST_RAW: |
| 1291 | request = (MainThreadRequest)msg.obj; |
| 1292 | onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1293 | defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 1294 | break; |
| 1295 | |
| 1296 | case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE: |
| 1297 | ar = (AsyncResult)msg.obj; |
| 1298 | request = (MainThreadRequest)ar.userObj; |
| 1299 | request.result = ar; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1300 | notifyRequester(request); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 1301 | break; |
| 1302 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1303 | case CMD_SET_VOICEMAIL_NUMBER: |
| 1304 | request = (MainThreadRequest) msg.obj; |
| 1305 | onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request); |
| 1306 | Pair<String, String> tagNum = (Pair<String, String>) request.argument; |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1307 | getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second, |
| 1308 | onCompleted); |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1309 | break; |
| 1310 | |
| 1311 | case EVENT_SET_VOICEMAIL_NUMBER_DONE: |
| 1312 | handleNullReturnEvent(msg, "setVoicemailNumber"); |
| 1313 | break; |
| 1314 | |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 1315 | case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC: |
| 1316 | request = (MainThreadRequest) msg.obj; |
| 1317 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE, |
| 1318 | request); |
| 1319 | getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted); |
| 1320 | break; |
| 1321 | |
| 1322 | case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE: |
| 1323 | handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic"); |
| 1324 | break; |
| 1325 | |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1326 | case CMD_PERFORM_NETWORK_SCAN: |
| 1327 | request = (MainThreadRequest) msg.obj; |
| 1328 | onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request); |
| 1329 | getPhoneFromRequest(request).getAvailableNetworks(onCompleted); |
| 1330 | break; |
| 1331 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1332 | case CMD_GET_CALL_FORWARDING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1333 | request = (MainThreadRequest) msg.obj; |
| 1334 | onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1335 | Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args = |
| 1336 | (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>) |
| 1337 | request.argument; |
| 1338 | int callForwardingReason = args.first; |
| 1339 | request.phone.getCallForwardingOption(callForwardingReason, onCompleted); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1340 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1341 | } |
| 1342 | case EVENT_GET_CALL_FORWARDING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1343 | ar = (AsyncResult) msg.obj; |
| 1344 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1345 | TelephonyManager.CallForwardingInfoCallback callback = |
| 1346 | ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>) |
| 1347 | request.argument).second; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1348 | if (ar.exception == null && ar.result != null) { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1349 | CallForwardingInfo callForwardingInfo = null; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1350 | CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result; |
| 1351 | for (CallForwardInfo callForwardInfo : callForwardInfos) { |
| 1352 | // Service Class is a bit mask per 3gpp 27.007. Search for |
| 1353 | // any service for voice call. |
| 1354 | if ((callForwardInfo.serviceClass |
| 1355 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0) { |
Yuchen Dong | 69cc141 | 2021-09-27 20:27:01 +0800 | [diff] [blame] | 1356 | callForwardingInfo = new CallForwardingInfo( |
| 1357 | callForwardInfo.status |
| 1358 | == CommandsInterface.CF_ACTION_ENABLE, |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1359 | callForwardInfo.reason, |
| 1360 | callForwardInfo.number, |
| 1361 | callForwardInfo.timeSeconds); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1362 | break; |
| 1363 | } |
| 1364 | } |
| 1365 | // Didn't find a call forward info for voice call. |
| 1366 | if (callForwardingInfo == null) { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1367 | callForwardingInfo = new CallForwardingInfo(false /* enabled */, |
| 1368 | 0 /* reason */, null /* number */, 0 /* timeout */); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1369 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1370 | callback.onCallForwardingInfoAvailable(callForwardingInfo); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1371 | } else { |
| 1372 | if (ar.result == null) { |
| 1373 | loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response"); |
| 1374 | } |
| 1375 | if (ar.exception != null) { |
| 1376 | loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception); |
| 1377 | } |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1378 | int errorCode = TelephonyManager |
| 1379 | .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1380 | if (ar.exception instanceof CommandException) { |
| 1381 | CommandException.Error error = |
| 1382 | ((CommandException) (ar.exception)).getCommandError(); |
| 1383 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1384 | errorCode = TelephonyManager |
| 1385 | .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1386 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1387 | errorCode = TelephonyManager |
| 1388 | .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1389 | } |
| 1390 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1391 | callback.onError(errorCode); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1392 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1393 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1394 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1395 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1396 | case CMD_SET_CALL_FORWARDING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1397 | request = (MainThreadRequest) msg.obj; |
| 1398 | onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1399 | request = (MainThreadRequest) msg.obj; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1400 | CallForwardingInfo callForwardingInfoToSet = |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1401 | ((Pair<CallForwardingInfo, Consumer<Integer>>) |
| 1402 | request.argument).first; |
| 1403 | request.phone.setCallForwardingOption( |
| 1404 | callForwardingInfoToSet.isEnabled() |
Calvin Pan | 258f1f7 | 2021-07-28 21:46:56 +0800 | [diff] [blame] | 1405 | ? CommandsInterface.CF_ACTION_REGISTRATION |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1406 | : CommandsInterface.CF_ACTION_DISABLE, |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1407 | callForwardingInfoToSet.getReason(), |
| 1408 | callForwardingInfoToSet.getNumber(), |
| 1409 | callForwardingInfoToSet.getTimeoutSeconds(), onCompleted); |
| 1410 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1411 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1412 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1413 | case EVENT_SET_CALL_FORWARDING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1414 | ar = (AsyncResult) msg.obj; |
| 1415 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1416 | Consumer<Integer> callback = |
| 1417 | ((Pair<CallForwardingInfo, Consumer<Integer>>) |
| 1418 | request.argument).second; |
| 1419 | if (ar.exception != null) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1420 | loge("setCallForwarding exception: " + ar.exception); |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1421 | int errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1422 | .RESULT_ERROR_UNKNOWN; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1423 | if (ar.exception instanceof CommandException) { |
| 1424 | CommandException.Error error = |
| 1425 | ((CommandException) (ar.exception)).getCommandError(); |
| 1426 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1427 | errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1428 | .RESULT_ERROR_FDN_CHECK_FAILURE; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1429 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1430 | errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1431 | .RESULT_ERROR_NOT_SUPPORTED; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1432 | } |
| 1433 | } |
| 1434 | callback.accept(errorCode); |
| 1435 | } else { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1436 | callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1437 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1438 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1439 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1440 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1441 | case CMD_GET_CALL_WAITING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1442 | request = (MainThreadRequest) msg.obj; |
| 1443 | onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request); |
| 1444 | getPhoneFromRequest(request).getCallWaiting(onCompleted); |
| 1445 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1446 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1447 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1448 | case EVENT_GET_CALL_WAITING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1449 | ar = (AsyncResult) msg.obj; |
| 1450 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1451 | Consumer<Integer> callback = (Consumer<Integer>) request.argument; |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1452 | int callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1453 | if (ar.exception == null && ar.result != null) { |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1454 | int[] callForwardResults = (int[]) ar.result; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1455 | // Service Class is a bit mask per 3gpp 27.007. |
| 1456 | // Search for any service for voice call. |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1457 | if (callForwardResults.length > 1 |
| 1458 | && ((callForwardResults[1] |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1459 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) { |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1460 | callWaitingStatus = callForwardResults[0] == 0 |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1461 | ? TelephonyManager.CALL_WAITING_STATUS_DISABLED |
| 1462 | : TelephonyManager.CALL_WAITING_STATUS_ENABLED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1463 | } else { |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1464 | callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1465 | } |
| 1466 | } else { |
| 1467 | if (ar.result == null) { |
| 1468 | loge("EVENT_GET_CALL_WAITING_DONE: Empty response"); |
| 1469 | } |
| 1470 | if (ar.exception != null) { |
| 1471 | loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception); |
| 1472 | } |
| 1473 | if (ar.exception instanceof CommandException) { |
| 1474 | CommandException.Error error = |
| 1475 | ((CommandException) (ar.exception)).getCommandError(); |
| 1476 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1477 | callWaitingStatus = |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1478 | TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED; |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1479 | } else if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
| 1480 | callWaitingStatus = |
| 1481 | TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1482 | } |
| 1483 | } |
| 1484 | } |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1485 | callback.accept(callWaitingStatus); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1486 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1487 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1488 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1489 | case CMD_SET_CALL_WAITING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1490 | request = (MainThreadRequest) msg.obj; |
| 1491 | onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1492 | boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first; |
| 1493 | getPhoneFromRequest(request).setCallWaiting(enable, onCompleted); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1494 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1495 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1496 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1497 | case EVENT_SET_CALL_WAITING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1498 | ar = (AsyncResult) msg.obj; |
| 1499 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1500 | boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first; |
| 1501 | Consumer<Integer> callback = |
| 1502 | ((Pair<Boolean, Consumer<Integer>>) request.argument).second; |
| 1503 | if (ar.exception != null) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1504 | loge("setCallWaiting exception: " + ar.exception); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1505 | if (ar.exception instanceof CommandException) { |
| 1506 | CommandException.Error error = |
| 1507 | ((CommandException) (ar.exception)).getCommandError(); |
| 1508 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1509 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED); |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1510 | } else if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
| 1511 | callback.accept( |
| 1512 | TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1513 | } else { |
| 1514 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 1515 | } |
| 1516 | } else { |
| 1517 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 1518 | } |
| 1519 | } else { |
| 1520 | callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED |
| 1521 | : TelephonyManager.CALL_WAITING_STATUS_DISABLED); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1522 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1523 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1524 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1525 | case EVENT_PERFORM_NETWORK_SCAN_DONE: |
| 1526 | ar = (AsyncResult) msg.obj; |
| 1527 | request = (MainThreadRequest) ar.userObj; |
| 1528 | CellNetworkScanResult cellScanResult; |
| 1529 | if (ar.exception == null && ar.result != null) { |
| 1530 | cellScanResult = new CellNetworkScanResult( |
| 1531 | CellNetworkScanResult.STATUS_SUCCESS, |
| 1532 | (List<OperatorInfo>) ar.result); |
| 1533 | } else { |
| 1534 | if (ar.result == null) { |
| 1535 | loge("getCellNetworkScanResults: Empty response"); |
| 1536 | } |
| 1537 | if (ar.exception != null) { |
| 1538 | loge("getCellNetworkScanResults: Exception: " + ar.exception); |
| 1539 | } |
| 1540 | int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR; |
| 1541 | if (ar.exception instanceof CommandException) { |
| 1542 | CommandException.Error error = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame^] | 1543 | ((CommandException) (ar.exception)).getCommandError(); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1544 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1545 | errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE; |
| 1546 | } else if (error == CommandException.Error.GENERIC_FAILURE) { |
| 1547 | errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE; |
| 1548 | } |
| 1549 | } |
| 1550 | cellScanResult = new CellNetworkScanResult(errorCode, null); |
| 1551 | } |
| 1552 | request.result = cellScanResult; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1553 | notifyRequester(request); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1554 | break; |
| 1555 | |
| 1556 | case CMD_SET_NETWORK_SELECTION_MODE_MANUAL: |
| 1557 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1558 | ManualNetworkSelectionArgument selArg = |
| 1559 | (ManualNetworkSelectionArgument) request.argument; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1560 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE, |
| 1561 | request); |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1562 | getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo, |
| 1563 | selArg.persistSelection, onCompleted); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1564 | break; |
| 1565 | |
| 1566 | case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE: |
Pengquan Meng | e3d01e2 | 2018-09-20 15:25:35 -0700 | [diff] [blame] | 1567 | ar = (AsyncResult) msg.obj; |
| 1568 | request = (MainThreadRequest) ar.userObj; |
| 1569 | if (ar.exception == null) { |
| 1570 | request.result = true; |
| 1571 | } else { |
| 1572 | request.result = false; |
| 1573 | loge("setNetworkSelectionModeManual " + ar.exception); |
| 1574 | } |
| 1575 | notifyRequester(request); |
| 1576 | mApp.onNetworkSelectionChanged(request.subId); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1577 | break; |
| 1578 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1579 | case CMD_GET_MODEM_ACTIVITY_INFO: |
| 1580 | request = (MainThreadRequest) msg.obj; |
| 1581 | onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1582 | if (defaultPhone != null) { |
| 1583 | defaultPhone.getModemActivityInfo(onCompleted, request.workSource); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1584 | } else { |
| 1585 | ResultReceiver result = (ResultReceiver) request.argument; |
| 1586 | Bundle bundle = new Bundle(); |
| 1587 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 1588 | new ModemActivityInfo(0, 0, 0, |
| 1589 | new int[ModemActivityInfo.getNumTxPowerLevels()], 0)); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1590 | result.send(0, bundle); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1591 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1592 | break; |
| 1593 | |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1594 | case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: { |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1595 | ar = (AsyncResult) msg.obj; |
| 1596 | request = (MainThreadRequest) ar.userObj; |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1597 | ResultReceiver result = (ResultReceiver) request.argument; |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1598 | int error = 0; |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 1599 | ModemActivityInfo ret = null; |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1600 | if (mLastModemActivityInfo == null) { |
| 1601 | mLastModemActivitySpecificInfo = new ActivityStatsTechSpecificInfo[1]; |
| 1602 | mLastModemActivitySpecificInfo[0] = |
| 1603 | new ActivityStatsTechSpecificInfo( |
| 1604 | 0, |
| 1605 | 0, |
| 1606 | new int[ModemActivityInfo.getNumTxPowerLevels()], |
| 1607 | 0); |
| 1608 | mLastModemActivityInfo = |
| 1609 | new ModemActivityInfo(0, 0, 0, mLastModemActivitySpecificInfo); |
| 1610 | } |
| 1611 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1612 | if (ar.exception == null && ar.result != null) { |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1613 | // Update the last modem activity info and the result of the request. |
| 1614 | ModemActivityInfo info = (ModemActivityInfo) ar.result; |
| 1615 | if (isModemActivityInfoValid(info)) { |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1616 | mergeModemActivityInfo(info); |
Gary Jian | 76280a4 | 2022-12-07 16:18:33 +0800 | [diff] [blame] | 1617 | } else { |
| 1618 | loge("queryModemActivityInfo: invalid response"); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1619 | } |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 1620 | // This is needed to decouple ret from mLastModemActivityInfo |
| 1621 | // We don't want to return mLastModemActivityInfo which is updated |
| 1622 | // inside mergeModemActivityInfo() |
| 1623 | ret = new ModemActivityInfo( |
| 1624 | mLastModemActivityInfo.getTimestampMillis(), |
| 1625 | mLastModemActivityInfo.getSleepTimeMillis(), |
| 1626 | mLastModemActivityInfo.getIdleTimeMillis(), |
| 1627 | deepCopyModemActivitySpecificInfo(mLastModemActivitySpecificInfo)); |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1628 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1629 | } else { |
| 1630 | if (ar.result == null) { |
| 1631 | loge("queryModemActivityInfo: Empty response"); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1632 | error = TelephonyManager.ModemActivityInfoException |
| 1633 | .ERROR_INVALID_INFO_RECEIVED; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1634 | } else if (ar.exception instanceof CommandException) { |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1635 | loge("queryModemActivityInfo: CommandException: " + ar.exception); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1636 | error = TelephonyManager.ModemActivityInfoException |
| 1637 | .ERROR_MODEM_RESPONSE_ERROR; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1638 | } else { |
| 1639 | loge("queryModemActivityInfo: Unknown exception"); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1640 | error = TelephonyManager.ModemActivityInfoException |
| 1641 | .ERROR_UNKNOWN; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1642 | } |
| 1643 | } |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1644 | Bundle bundle = new Bundle(); |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 1645 | if (ret != null) { |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1646 | bundle.putParcelable( |
| 1647 | TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 1648 | ret); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1649 | } else { |
| 1650 | bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error); |
| 1651 | } |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1652 | result.send(0, bundle); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1653 | notifyRequester(request); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1654 | break; |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1655 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1656 | |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1657 | case CMD_SET_ALLOWED_CARRIERS: |
| 1658 | request = (MainThreadRequest) msg.obj; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1659 | CarrierRestrictionRules argument = |
| 1660 | (CarrierRestrictionRules) request.argument; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1661 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request); |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1662 | defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1663 | break; |
| 1664 | |
| 1665 | case EVENT_SET_ALLOWED_CARRIERS_DONE: |
| 1666 | ar = (AsyncResult) msg.obj; |
| 1667 | request = (MainThreadRequest) ar.userObj; |
| 1668 | if (ar.exception == null && ar.result != null) { |
| 1669 | request.result = ar.result; |
| 1670 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1671 | request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR; |
| 1672 | if (ar.exception instanceof CommandException) { |
| 1673 | loge("setAllowedCarriers: CommandException: " + ar.exception); |
| 1674 | CommandException.Error error = |
| 1675 | ((CommandException) (ar.exception)).getCommandError(); |
| 1676 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1677 | request.result = |
| 1678 | TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED; |
| 1679 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1680 | } else { |
| 1681 | loge("setAllowedCarriers: Unknown exception"); |
| 1682 | } |
| 1683 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1684 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1685 | break; |
| 1686 | |
| 1687 | case CMD_GET_ALLOWED_CARRIERS: |
| 1688 | request = (MainThreadRequest) msg.obj; |
| 1689 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1690 | defaultPhone.getAllowedCarriers(onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1691 | break; |
| 1692 | |
| 1693 | case EVENT_GET_ALLOWED_CARRIERS_DONE: |
| 1694 | ar = (AsyncResult) msg.obj; |
| 1695 | request = (MainThreadRequest) ar.userObj; |
| 1696 | if (ar.exception == null && ar.result != null) { |
| 1697 | request.result = ar.result; |
| 1698 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1699 | request.result = new IllegalStateException( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame^] | 1700 | "Failed to get carrier restrictions"); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1701 | if (ar.result == null) { |
| 1702 | loge("getAllowedCarriers: Empty response"); |
| 1703 | } else if (ar.exception instanceof CommandException) { |
| 1704 | loge("getAllowedCarriers: CommandException: " + |
| 1705 | ar.exception); |
| 1706 | } else { |
| 1707 | loge("getAllowedCarriers: Unknown exception"); |
| 1708 | } |
| 1709 | } |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 1710 | if (request.argument != null) { |
| 1711 | // This is for the implementation of carrierRestrictionStatus. |
| 1712 | CallerCallbackInfo callbackInfo = (CallerCallbackInfo) request.argument; |
| 1713 | Consumer<Integer> callback = callbackInfo.getConsumer(); |
| 1714 | int callerCarrierId = callbackInfo.getCarrierId(); |
| 1715 | int lockStatus = TelephonyManager.CARRIER_RESTRICTION_STATUS_UNKNOWN; |
| 1716 | if (ar.exception == null && ar.result instanceof CarrierRestrictionRules) { |
| 1717 | CarrierRestrictionRules carrierRestrictionRules = |
| 1718 | (CarrierRestrictionRules) ar.result; |
| 1719 | int carrierId = -1; |
| 1720 | try { |
| 1721 | CarrierIdentifier carrierIdentifier = |
| 1722 | carrierRestrictionRules.getAllowedCarriers().get(0); |
| 1723 | carrierId = CarrierResolver.getCarrierIdFromIdentifier(mApp, |
| 1724 | carrierIdentifier); |
| 1725 | } catch (NullPointerException | IndexOutOfBoundsException ex) { |
| 1726 | Rlog.e(LOG_TAG, "CarrierIdentifier exception = " + ex); |
| 1727 | } |
| 1728 | lockStatus = carrierRestrictionRules.getCarrierRestrictionStatus(); |
| 1729 | if (carrierId != -1 && callerCarrierId == carrierId && lockStatus |
| 1730 | == TelephonyManager.CARRIER_RESTRICTION_STATUS_RESTRICTED) { |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame^] | 1731 | lockStatus = TelephonyManager |
| 1732 | .CARRIER_RESTRICTION_STATUS_RESTRICTED_TO_CALLER; |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 1733 | } |
| 1734 | } else { |
| 1735 | Rlog.e(LOG_TAG, |
| 1736 | "getCarrierRestrictionStatus: exception ex = " + ar.exception); |
| 1737 | } |
| 1738 | callback.accept(lockStatus); |
| 1739 | } else { |
| 1740 | // This is for the implementation of getAllowedCarriers. |
| 1741 | notifyRequester(request); |
| 1742 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1743 | break; |
| 1744 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1745 | case EVENT_GET_FORBIDDEN_PLMNS_DONE: |
| 1746 | ar = (AsyncResult) msg.obj; |
| 1747 | request = (MainThreadRequest) ar.userObj; |
| 1748 | if (ar.exception == null && ar.result != null) { |
| 1749 | request.result = ar.result; |
| 1750 | } else { |
| 1751 | request.result = new IllegalArgumentException( |
| 1752 | "Failed to retrieve Forbidden Plmns"); |
| 1753 | if (ar.result == null) { |
| 1754 | loge("getForbiddenPlmns: Empty response"); |
| 1755 | } else { |
| 1756 | loge("getForbiddenPlmns: Unknown exception"); |
| 1757 | } |
| 1758 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1759 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1760 | break; |
| 1761 | |
| 1762 | case CMD_GET_FORBIDDEN_PLMNS: |
| 1763 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1764 | uiccPort = getUiccPortFromRequest(request); |
| 1765 | if (uiccPort == null) { |
| 1766 | loge("getForbiddenPlmns() UiccPort is null"); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1767 | request.result = new IllegalArgumentException( |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1768 | "getForbiddenPlmns() UiccPort is null"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1769 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1770 | break; |
| 1771 | } |
| 1772 | Integer appType = (Integer) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1773 | UiccCardApplication uiccApp = uiccPort.getApplicationByType(appType); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1774 | if (uiccApp == null) { |
| 1775 | loge("getForbiddenPlmns() no app with specified type -- " |
| 1776 | + appType); |
| 1777 | request.result = new IllegalArgumentException("Failed to get UICC App"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1778 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1779 | break; |
| 1780 | } else { |
| 1781 | if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid() |
| 1782 | + " specified type -- " + appType); |
| 1783 | } |
| 1784 | onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request); |
| 1785 | ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame^] | 1786 | onCompleted); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1787 | break; |
| 1788 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1789 | case CMD_SWITCH_SLOTS: |
| 1790 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 1791 | List<UiccSlotMapping> slotMapping = (List<UiccSlotMapping>) request.argument; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1792 | onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 1793 | UiccController.getInstance().switchSlots(slotMapping, onCompleted); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1794 | break; |
| 1795 | |
| 1796 | case EVENT_SWITCH_SLOTS_DONE: |
| 1797 | ar = (AsyncResult) msg.obj; |
| 1798 | request = (MainThreadRequest) ar.userObj; |
| 1799 | request.result = (ar.exception == null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1800 | notifyRequester(request); |
| 1801 | break; |
| 1802 | case CMD_GET_NETWORK_SELECTION_MODE: |
| 1803 | request = (MainThreadRequest) msg.obj; |
| 1804 | onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request); |
| 1805 | getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted); |
| 1806 | break; |
| 1807 | |
| 1808 | case EVENT_GET_NETWORK_SELECTION_MODE_DONE: |
| 1809 | ar = (AsyncResult) msg.obj; |
| 1810 | request = (MainThreadRequest) ar.userObj; |
| 1811 | if (ar.exception != null) { |
| 1812 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 1813 | } else { |
| 1814 | int mode = ((int[]) ar.result)[0]; |
| 1815 | if (mode == 0) { |
| 1816 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO; |
| 1817 | } else { |
| 1818 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL; |
| 1819 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1820 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1821 | notifyRequester(request); |
| 1822 | break; |
| 1823 | case CMD_GET_CDMA_ROAMING_MODE: |
| 1824 | request = (MainThreadRequest) msg.obj; |
| 1825 | onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request); |
| 1826 | getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted); |
| 1827 | break; |
| 1828 | case EVENT_GET_CDMA_ROAMING_MODE_DONE: |
| 1829 | ar = (AsyncResult) msg.obj; |
| 1830 | request = (MainThreadRequest) ar.userObj; |
| 1831 | if (ar.exception != null) { |
| 1832 | request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT; |
| 1833 | } else { |
| 1834 | request.result = ((int[]) ar.result)[0]; |
| 1835 | } |
| 1836 | notifyRequester(request); |
| 1837 | break; |
| 1838 | case CMD_SET_CDMA_ROAMING_MODE: |
| 1839 | request = (MainThreadRequest) msg.obj; |
| 1840 | onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request); |
| 1841 | int mode = (int) request.argument; |
| 1842 | getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted); |
| 1843 | break; |
| 1844 | case EVENT_SET_CDMA_ROAMING_MODE_DONE: |
| 1845 | ar = (AsyncResult) msg.obj; |
| 1846 | request = (MainThreadRequest) ar.userObj; |
| 1847 | request.result = ar.exception == null; |
| 1848 | notifyRequester(request); |
| 1849 | break; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 1850 | case CMD_GET_CDMA_SUBSCRIPTION_MODE: |
| 1851 | request = (MainThreadRequest) msg.obj; |
| 1852 | onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1853 | getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted); |
| 1854 | break; |
| 1855 | case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1856 | ar = (AsyncResult) msg.obj; |
| 1857 | request = (MainThreadRequest) ar.userObj; |
| 1858 | if (ar.exception != null) { |
| 1859 | request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM; |
| 1860 | } else { |
| 1861 | request.result = ((int[]) ar.result)[0]; |
| 1862 | } |
| 1863 | notifyRequester(request); |
| 1864 | break; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1865 | case CMD_SET_CDMA_SUBSCRIPTION_MODE: |
| 1866 | request = (MainThreadRequest) msg.obj; |
| 1867 | onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1868 | int subscriptionMode = (int) request.argument; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 1869 | getPhoneFromRequest(request).setCdmaSubscriptionMode( |
| 1870 | subscriptionMode, onCompleted); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1871 | break; |
| 1872 | case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1873 | ar = (AsyncResult) msg.obj; |
| 1874 | request = (MainThreadRequest) ar.userObj; |
| 1875 | request.result = ar.exception == null; |
| 1876 | notifyRequester(request); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1877 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1878 | case CMD_GET_ALL_CELL_INFO: |
| 1879 | request = (MainThreadRequest) msg.obj; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1880 | onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1881 | request.phone.requestCellInfoUpdate(request.workSource, onCompleted); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1882 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1883 | case EVENT_GET_ALL_CELL_INFO_DONE: |
| 1884 | ar = (AsyncResult) msg.obj; |
| 1885 | request = (MainThreadRequest) ar.userObj; |
Nathan Harold | 8d0f174 | 2018-10-02 12:14:47 -0700 | [diff] [blame] | 1886 | // If a timeout occurs, the response will be null |
| 1887 | request.result = (ar.exception == null && ar.result != null) |
| 1888 | ? ar.result : new ArrayList<CellInfo>(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1889 | synchronized (request) { |
| 1890 | request.notifyAll(); |
| 1891 | } |
| 1892 | break; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1893 | case CMD_REQUEST_CELL_INFO_UPDATE: |
| 1894 | request = (MainThreadRequest) msg.obj; |
| 1895 | request.phone.requestCellInfoUpdate(request.workSource, |
| 1896 | obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request)); |
| 1897 | break; |
| 1898 | case EVENT_REQUEST_CELL_INFO_UPDATE_DONE: |
| 1899 | ar = (AsyncResult) msg.obj; |
| 1900 | request = (MainThreadRequest) ar.userObj; |
| 1901 | ICellInfoCallback cb = (ICellInfoCallback) request.argument; |
| 1902 | try { |
| 1903 | if (ar.exception != null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1904 | Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception); |
Meng Wang | d8921f4 | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1905 | cb.onError( |
| 1906 | TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR, |
| 1907 | ar.exception.getClass().getName(), |
| 1908 | ar.exception.toString()); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1909 | } else if (ar.result == null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1910 | Log.w(LOG_TAG, "Timeout Waiting for CellInfo!"); |
Meng Wang | d8921f4 | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1911 | cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1912 | } else { |
| 1913 | // use the result as returned |
| 1914 | cb.onCellInfo((List<CellInfo>) ar.result); |
| 1915 | } |
| 1916 | } catch (RemoteException re) { |
| 1917 | Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException"); |
| 1918 | } |
| 1919 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1920 | case CMD_GET_CELL_LOCATION: { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1921 | request = (MainThreadRequest) msg.obj; |
| 1922 | WorkSource ws = (WorkSource) request.argument; |
| 1923 | Phone phone = getPhoneFromRequest(request); |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1924 | phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request)); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1925 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1926 | } |
| 1927 | case EVENT_GET_CELL_LOCATION_DONE: { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1928 | ar = (AsyncResult) msg.obj; |
| 1929 | request = (MainThreadRequest) ar.userObj; |
| 1930 | if (ar.exception == null) { |
| 1931 | request.result = ar.result; |
| 1932 | } else { |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1933 | Phone phone = getPhoneFromRequest(request); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1934 | request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1935 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1936 | } |
| 1937 | |
| 1938 | synchronized (request) { |
| 1939 | request.notifyAll(); |
| 1940 | } |
| 1941 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1942 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1943 | case CMD_MODEM_REBOOT: |
| 1944 | request = (MainThreadRequest) msg.obj; |
| 1945 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1946 | defaultPhone.rebootModem(onCompleted); |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1947 | break; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1948 | case EVENT_CMD_MODEM_REBOOT_DONE: |
| 1949 | handleNullReturnEvent(msg, "rebootModem"); |
| 1950 | break; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1951 | case CMD_REQUEST_ENABLE_MODEM: |
| 1952 | request = (MainThreadRequest) msg.obj; |
| 1953 | boolean enable = (boolean) request.argument; |
| 1954 | onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1955 | onCompleted.arg1 = enable ? 1 : 0; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1956 | PhoneConfigurationManager.getInstance() |
| 1957 | .enablePhone(request.phone, enable, onCompleted); |
| 1958 | break; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1959 | case EVENT_ENABLE_MODEM_DONE: { |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1960 | ar = (AsyncResult) msg.obj; |
| 1961 | request = (MainThreadRequest) ar.userObj; |
| 1962 | request.result = (ar.exception == null); |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1963 | int phoneId = request.phone.getPhoneId(); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1964 | //update the cache as modem status has changed |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1965 | if ((boolean) request.result) { |
| 1966 | mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1); |
| 1967 | updateModemStateMetrics(); |
| 1968 | } else { |
| 1969 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1970 | + ar.exception); |
| 1971 | } |
| 1972 | notifyRequester(request); |
| 1973 | break; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1974 | } |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1975 | case CMD_GET_MODEM_STATUS: |
| 1976 | request = (MainThreadRequest) msg.obj; |
| 1977 | onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request); |
| 1978 | PhoneConfigurationManager.getInstance() |
| 1979 | .getPhoneStatusFromModem(request.phone, onCompleted); |
| 1980 | break; |
| 1981 | case EVENT_GET_MODEM_STATUS_DONE: |
| 1982 | ar = (AsyncResult) msg.obj; |
| 1983 | request = (MainThreadRequest) ar.userObj; |
| 1984 | int id = request.phone.getPhoneId(); |
| 1985 | if (ar.exception == null && ar.result != null) { |
| 1986 | request.result = ar.result; |
| 1987 | //update the cache as modem status has changed |
| 1988 | mPhoneConfigurationManager.addToPhoneStatusCache(id, |
| 1989 | (boolean) request.result); |
| 1990 | } else { |
| 1991 | // Return true if modem status cannot be retrieved. For most cases, |
| 1992 | // modem status is on. And for older version modems, GET_MODEM_STATUS |
| 1993 | // and disable modem are not supported. Modem is always on. |
| 1994 | // TODO: this should be fixed in R to support a third |
| 1995 | // status UNKNOWN b/131631629 |
| 1996 | request.result = true; |
| 1997 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1998 | + ar.exception); |
| 1999 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 2000 | notifyRequester(request); |
| 2001 | break; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 2002 | case CMD_SET_SYSTEM_SELECTION_CHANNELS: { |
| 2003 | request = (MainThreadRequest) msg.obj; |
| 2004 | onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request); |
| 2005 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 2006 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 2007 | request.phone.setSystemSelectionChannels(args.first, onCompleted); |
| 2008 | break; |
| 2009 | } |
| 2010 | case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: { |
| 2011 | ar = (AsyncResult) msg.obj; |
| 2012 | request = (MainThreadRequest) ar.userObj; |
| 2013 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 2014 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 2015 | args.second.accept(ar.exception == null); |
| 2016 | notifyRequester(request); |
| 2017 | break; |
| 2018 | } |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 2019 | case CMD_GET_SYSTEM_SELECTION_CHANNELS: { |
| 2020 | request = (MainThreadRequest) msg.obj; |
| 2021 | onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request); |
| 2022 | Phone phone = getPhoneFromRequest(request); |
| 2023 | if (phone != null) { |
| 2024 | phone.getSystemSelectionChannels(onCompleted); |
| 2025 | } else { |
| 2026 | loge("getSystemSelectionChannels: No phone object"); |
| 2027 | request.result = new ArrayList<RadioAccessSpecifier>(); |
| 2028 | notifyRequester(request); |
| 2029 | } |
| 2030 | break; |
| 2031 | } |
| 2032 | case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE: |
| 2033 | ar = (AsyncResult) msg.obj; |
| 2034 | request = (MainThreadRequest) ar.userObj; |
| 2035 | if (ar.exception == null && ar.result != null) { |
| 2036 | request.result = ar.result; |
| 2037 | } else { |
Sarah Chin | 428d1d6 | 2021-03-13 03:17:40 -0800 | [diff] [blame] | 2038 | request.result = new IllegalStateException( |
| 2039 | "Failed to retrieve system selecton channels"); |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 2040 | if (ar.result == null) { |
| 2041 | loge("getSystemSelectionChannels: Empty response"); |
| 2042 | } else { |
| 2043 | loge("getSystemSelectionChannels: Unknown exception"); |
| 2044 | } |
| 2045 | } |
| 2046 | notifyRequester(request); |
| 2047 | break; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 2048 | case EVENT_SET_FORBIDDEN_PLMNS_DONE: |
| 2049 | ar = (AsyncResult) msg.obj; |
| 2050 | request = (MainThreadRequest) ar.userObj; |
| 2051 | if (ar.exception == null && ar.result != null) { |
| 2052 | request.result = ar.result; |
| 2053 | } else { |
| 2054 | request.result = -1; |
| 2055 | loge("Failed to set Forbidden Plmns"); |
| 2056 | if (ar.result == null) { |
| 2057 | loge("setForbidenPlmns: Empty response"); |
| 2058 | } else if (ar.exception != null) { |
| 2059 | loge("setForbiddenPlmns: Exception: " + ar.exception); |
| 2060 | request.result = -1; |
| 2061 | } else { |
| 2062 | loge("setForbiddenPlmns: Unknown exception"); |
| 2063 | } |
| 2064 | } |
| 2065 | notifyRequester(request); |
| 2066 | break; |
| 2067 | case CMD_SET_FORBIDDEN_PLMNS: |
| 2068 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 2069 | uiccPort = getUiccPortFromRequest(request); |
| 2070 | if (uiccPort == null) { |
| 2071 | loge("setForbiddenPlmns: UiccPort is null"); |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 2072 | request.result = -1; |
| 2073 | notifyRequester(request); |
| 2074 | break; |
| 2075 | } |
| 2076 | Pair<Integer, List<String>> setFplmnsArgs = |
| 2077 | (Pair<Integer, List<String>>) request.argument; |
| 2078 | appType = setFplmnsArgs.first; |
| 2079 | List<String> fplmns = setFplmnsArgs.second; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 2080 | uiccApp = uiccPort.getApplicationByType(appType); |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 2081 | if (uiccApp == null) { |
| 2082 | loge("setForbiddenPlmns: no app with specified type -- " + appType); |
| 2083 | request.result = -1; |
| 2084 | loge("Failed to get UICC App"); |
| 2085 | notifyRequester(request); |
| 2086 | } else { |
| 2087 | onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request); |
| 2088 | ((SIMRecords) uiccApp.getIccRecords()) |
| 2089 | .setForbiddenPlmns(onCompleted, fplmns); |
| 2090 | } |
yinchengzhao | 4d163c0 | 2019-12-12 15:21:47 -0800 | [diff] [blame] | 2091 | break; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 2092 | case CMD_ERASE_MODEM_CONFIG: |
| 2093 | request = (MainThreadRequest) msg.obj; |
| 2094 | onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request); |
| 2095 | defaultPhone.eraseModemConfig(onCompleted); |
| 2096 | break; |
| 2097 | case EVENT_ERASE_MODEM_CONFIG_DONE: |
| 2098 | handleNullReturnEvent(msg, "eraseModemConfig"); |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 2099 | break; |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 2100 | |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 2101 | case CMD_ERASE_DATA_SHARED_PREFERENCES: |
| 2102 | request = (MainThreadRequest) msg.obj; |
| 2103 | request.result = defaultPhone.eraseDataInSharedPreferences(); |
| 2104 | notifyRequester(request); |
| 2105 | break; |
| 2106 | |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 2107 | case CMD_CHANGE_ICC_LOCK_PASSWORD: |
| 2108 | request = (MainThreadRequest) msg.obj; |
| 2109 | onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request); |
| 2110 | Pair<String, String> changed = (Pair<String, String>) request.argument; |
| 2111 | getPhoneFromRequest(request).getIccCard().changeIccLockPassword( |
| 2112 | changed.first, changed.second, onCompleted); |
| 2113 | break; |
| 2114 | case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE: |
| 2115 | ar = (AsyncResult) msg.obj; |
| 2116 | request = (MainThreadRequest) ar.userObj; |
| 2117 | if (ar.exception == null) { |
| 2118 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2119 | // If the operation is successful, update the PIN storage |
| 2120 | Pair<String, String> passwords = (Pair<String, String>) request.argument; |
| 2121 | int phoneId = getPhoneFromRequest(request).getPhoneId(); |
Jon Spivack | 9c3bc76 | 2021-10-06 20:53:09 +0000 | [diff] [blame] | 2122 | UiccController.getInstance().getPinStorage() |
| 2123 | .storePin(passwords.second, phoneId); |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 2124 | } else { |
| 2125 | request.result = msg.arg1; |
| 2126 | } |
| 2127 | notifyRequester(request); |
| 2128 | break; |
| 2129 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2130 | case CMD_SET_ICC_LOCK_ENABLED: { |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 2131 | request = (MainThreadRequest) msg.obj; |
| 2132 | onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request); |
| 2133 | Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument; |
| 2134 | getPhoneFromRequest(request).getIccCard().setIccLockEnabled( |
| 2135 | enabled.first, enabled.second, onCompleted); |
| 2136 | break; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2137 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 2138 | case EVENT_SET_ICC_LOCK_ENABLED_DONE: |
| 2139 | ar = (AsyncResult) msg.obj; |
| 2140 | request = (MainThreadRequest) ar.userObj; |
| 2141 | if (ar.exception == null) { |
| 2142 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2143 | // If the operation is successful, update the PIN storage |
| 2144 | Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument; |
| 2145 | int phoneId = getPhoneFromRequest(request).getPhoneId(); |
| 2146 | if (enabled.first) { |
Jon Spivack | 9c3bc76 | 2021-10-06 20:53:09 +0000 | [diff] [blame] | 2147 | UiccController.getInstance().getPinStorage() |
| 2148 | .storePin(enabled.second, phoneId); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2149 | } else { |
| 2150 | UiccController.getInstance().getPinStorage().clearPin(phoneId); |
| 2151 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 2152 | } else { |
| 2153 | request.result = msg.arg1; |
| 2154 | } |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2155 | |
| 2156 | |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 2157 | notifyRequester(request); |
| 2158 | break; |
| 2159 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 2160 | case MSG_NOTIFY_USER_ACTIVITY: |
| 2161 | removeMessages(MSG_NOTIFY_USER_ACTIVITY); |
Peter Wang | 59571be | 2020-01-27 12:35:15 +0800 | [diff] [blame] | 2162 | Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION); |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 2163 | intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY); |
| 2164 | getDefaultPhone().getContext().sendBroadcastAsUser( |
| 2165 | intent, UserHandle.ALL, permission.USER_ACTIVITY); |
| 2166 | break; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 2167 | |
| 2168 | case CMD_SET_DATA_THROTTLING: { |
| 2169 | request = (MainThreadRequest) msg.obj; |
| 2170 | onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request); |
| 2171 | DataThrottlingRequest dataThrottlingRequest = |
| 2172 | (DataThrottlingRequest) request.argument; |
| 2173 | Phone phone = getPhoneFromRequest(request); |
| 2174 | if (phone != null) { |
| 2175 | phone.setDataThrottling(onCompleted, |
| 2176 | request.workSource, dataThrottlingRequest.getDataThrottlingAction(), |
| 2177 | dataThrottlingRequest.getCompletionDurationMillis()); |
| 2178 | } else { |
| 2179 | loge("setDataThrottling: No phone object"); |
| 2180 | request.result = |
| 2181 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 2182 | notifyRequester(request); |
| 2183 | } |
| 2184 | |
| 2185 | break; |
| 2186 | } |
| 2187 | case EVENT_SET_DATA_THROTTLING_DONE: |
| 2188 | ar = (AsyncResult) msg.obj; |
| 2189 | request = (MainThreadRequest) ar.userObj; |
| 2190 | |
| 2191 | if (ar.exception == null) { |
| 2192 | request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 2193 | } else if (ar.exception instanceof CommandException) { |
| 2194 | loge("setDataThrottling: CommandException: " + ar.exception); |
| 2195 | CommandException.Error error = |
| 2196 | ((CommandException) (ar.exception)).getCommandError(); |
| 2197 | |
| 2198 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 2199 | request.result = TelephonyManager |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame^] | 2200 | .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 2201 | } else if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 2202 | request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS; |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 2203 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 2204 | request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 2205 | } else { |
| 2206 | request.result = |
| 2207 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 2208 | } |
| 2209 | } else { |
| 2210 | request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 2211 | } |
| 2212 | Log.w(LOG_TAG, "DataThrottlingResult = " + request.result); |
| 2213 | notifyRequester(request); |
| 2214 | break; |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 2215 | |
| 2216 | case CMD_SET_SIM_POWER: { |
| 2217 | request = (MainThreadRequest) msg.obj; |
| 2218 | onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request); |
| 2219 | request = (MainThreadRequest) msg.obj; |
| 2220 | int stateToSet = |
| 2221 | ((Pair<Integer, IIntegerConsumer>) |
| 2222 | request.argument).first; |
| 2223 | request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource); |
| 2224 | break; |
| 2225 | } |
| 2226 | case EVENT_SET_SIM_POWER_DONE: { |
| 2227 | ar = (AsyncResult) msg.obj; |
| 2228 | request = (MainThreadRequest) ar.userObj; |
| 2229 | IIntegerConsumer callback = |
| 2230 | ((Pair<Integer, IIntegerConsumer>) request.argument).second; |
| 2231 | if (ar.exception != null) { |
| 2232 | loge("setSimPower exception: " + ar.exception); |
| 2233 | int errorCode = TelephonyManager.CallForwardingInfoCallback |
| 2234 | .RESULT_ERROR_UNKNOWN; |
| 2235 | if (ar.exception instanceof CommandException) { |
| 2236 | CommandException.Error error = |
| 2237 | ((CommandException) (ar.exception)).getCommandError(); |
| 2238 | if (error == CommandException.Error.SIM_ERR) { |
| 2239 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR; |
| 2240 | } else if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 2241 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE; |
| 2242 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 2243 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED; |
| 2244 | } else { |
| 2245 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR; |
| 2246 | } |
| 2247 | } |
| 2248 | try { |
| 2249 | callback.accept(errorCode); |
| 2250 | } catch (RemoteException e) { |
| 2251 | // Ignore if the remote process is no longer available to call back. |
| 2252 | Log.w(LOG_TAG, "setSimPower: callback not available."); |
| 2253 | } |
| 2254 | } else { |
| 2255 | try { |
| 2256 | callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS); |
| 2257 | } catch (RemoteException e) { |
| 2258 | // Ignore if the remote process is no longer available to call back. |
| 2259 | Log.w(LOG_TAG, "setSimPower: callback not available."); |
| 2260 | } |
| 2261 | } |
| 2262 | break; |
| 2263 | } |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 2264 | case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: { |
| 2265 | request = (MainThreadRequest) msg.obj; |
| 2266 | |
| 2267 | final Phone phone = getPhoneFromRequest(request); |
| 2268 | if (phone == null || phone.getServiceStateTracker() == null) { |
| 2269 | request.result = new IllegalStateException("Phone or SST is null"); |
| 2270 | notifyRequester(request); |
| 2271 | break; |
| 2272 | } |
| 2273 | |
| 2274 | Pair<Integer, SignalStrengthUpdateRequest> pair = |
| 2275 | (Pair<Integer, SignalStrengthUpdateRequest>) request.argument; |
| 2276 | onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE, |
| 2277 | request); |
Rambo Wang | 6568f17 | 2021-02-03 16:56:47 -0800 | [diff] [blame] | 2278 | phone.getSignalStrengthController().setSignalStrengthUpdateRequest( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame^] | 2279 | request.subId, pair.first /*callingUid*/, |
| 2280 | pair.second /*request*/, onCompleted); |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 2281 | break; |
| 2282 | } |
| 2283 | case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: { |
| 2284 | ar = (AsyncResult) msg.obj; |
| 2285 | request = (MainThreadRequest) ar.userObj; |
| 2286 | // request.result will be the exception of ar if present, true otherwise. |
| 2287 | // Be cautious not to leave result null which will wait() forever |
| 2288 | request.result = ar.exception != null ? ar.exception : true; |
| 2289 | notifyRequester(request); |
| 2290 | break; |
| 2291 | } |
| 2292 | case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: { |
| 2293 | request = (MainThreadRequest) msg.obj; |
| 2294 | |
| 2295 | Phone phone = getPhoneFromRequest(request); |
| 2296 | if (phone == null || phone.getServiceStateTracker() == null) { |
| 2297 | request.result = new IllegalStateException("Phone or SST is null"); |
| 2298 | notifyRequester(request); |
| 2299 | break; |
| 2300 | } |
| 2301 | |
| 2302 | Pair<Integer, SignalStrengthUpdateRequest> pair = |
| 2303 | (Pair<Integer, SignalStrengthUpdateRequest>) request.argument; |
| 2304 | onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE, |
| 2305 | request); |
Rambo Wang | 6568f17 | 2021-02-03 16:56:47 -0800 | [diff] [blame] | 2306 | phone.getSignalStrengthController().clearSignalStrengthUpdateRequest( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame^] | 2307 | request.subId, pair.first /*callingUid*/, |
| 2308 | pair.second /*request*/, onCompleted); |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 2309 | break; |
| 2310 | } |
| 2311 | case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: { |
| 2312 | ar = (AsyncResult) msg.obj; |
| 2313 | request = (MainThreadRequest) ar.userObj; |
| 2314 | request.result = ar.exception != null ? ar.exception : true; |
| 2315 | notifyRequester(request); |
| 2316 | break; |
| 2317 | } |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 2318 | |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2319 | case CMD_GET_SLICING_CONFIG: { |
| 2320 | request = (MainThreadRequest) msg.obj; |
| 2321 | onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request); |
| 2322 | request.phone.getSlicingConfig(onCompleted); |
| 2323 | break; |
| 2324 | } |
| 2325 | case EVENT_GET_SLICING_CONFIG_DONE: { |
| 2326 | ar = (AsyncResult) msg.obj; |
| 2327 | request = (MainThreadRequest) ar.userObj; |
| 2328 | ResultReceiver result = (ResultReceiver) request.argument; |
| 2329 | |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2330 | NetworkSlicingConfig slicingConfig = null; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2331 | Bundle bundle = new Bundle(); |
| 2332 | int resultCode = 0; |
| 2333 | if (ar.exception != null) { |
| 2334 | Log.e(LOG_TAG, "Exception retrieving slicing configuration=" |
| 2335 | + ar.exception); |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2336 | resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2337 | } else if (ar.result == null) { |
| 2338 | Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!"); |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2339 | resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2340 | } else { |
| 2341 | // use the result as returned |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2342 | resultCode = TelephonyManager.NetworkSlicingException.SUCCESS; |
| 2343 | slicingConfig = (NetworkSlicingConfig) ar.result; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2344 | } |
| 2345 | |
| 2346 | if (slicingConfig == null) { |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2347 | slicingConfig = new NetworkSlicingConfig(); |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2348 | } |
| 2349 | bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig); |
| 2350 | result.send(resultCode, bundle); |
| 2351 | notifyRequester(request); |
| 2352 | break; |
| 2353 | } |
| 2354 | |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2355 | case CMD_PURCHASE_PREMIUM_CAPABILITY: { |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2356 | request = (MainThreadRequest) msg.obj; |
| 2357 | onCompleted = obtainMessage(EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE, request); |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2358 | PurchasePremiumCapabilityArgument arg = |
| 2359 | (PurchasePremiumCapabilityArgument) request.argument; |
Sarah Chin | 46355ba | 2022-11-01 23:51:16 -0700 | [diff] [blame] | 2360 | SlicePurchaseController.getInstance(request.phone).purchasePremiumCapability( |
Sarah Chin | b8218c2 | 2023-01-04 13:35:29 -0800 | [diff] [blame] | 2361 | arg.capability, onCompleted); |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2362 | break; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2363 | } |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2364 | |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2365 | case EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE: { |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2366 | ar = (AsyncResult) msg.obj; |
| 2367 | request = (MainThreadRequest) ar.userObj; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2368 | PurchasePremiumCapabilityArgument arg = |
| 2369 | (PurchasePremiumCapabilityArgument) request.argument; |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2370 | try { |
| 2371 | int result = (int) ar.result; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2372 | arg.callback.accept(result); |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2373 | log("purchasePremiumCapability: capability=" |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2374 | + TelephonyManager.convertPremiumCapabilityToString(arg.capability) |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2375 | + ", result= " |
| 2376 | + TelephonyManager.convertPurchaseResultToString(result)); |
| 2377 | } catch (RemoteException e) { |
| 2378 | String logStr = "Purchase premium capability " |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2379 | + TelephonyManager.convertPremiumCapabilityToString(arg.capability) |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2380 | + " failed: " + e; |
| 2381 | if (DBG) log(logStr); |
| 2382 | AnomalyReporter.reportAnomaly( |
| 2383 | UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr); |
| 2384 | } |
| 2385 | break; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2386 | } |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2387 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2388 | case CMD_PREPARE_UNATTENDED_REBOOT: |
| 2389 | request = (MainThreadRequest) msg.obj; |
| 2390 | request.result = |
Rafael Higuera Silva | d963064 | 2021-09-20 15:32:01 +0000 | [diff] [blame] | 2391 | UiccController.getInstance().getPinStorage() |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame^] | 2392 | .prepareUnattendedReboot(request.workSource); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2393 | notifyRequester(request); |
| 2394 | break; |
| 2395 | |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 2396 | case CMD_START_SATELLITE_POSITION_UPDATES: { |
| 2397 | request = (MainThreadRequest) msg.obj; |
| 2398 | onCompleted = |
| 2399 | obtainMessage(EVENT_START_SATELLITE_POSITION_UPDATES_DONE, request); |
| 2400 | Phone phone = getPhoneFromRequest(request); |
| 2401 | if (phone != null) { |
| 2402 | phone.startSatellitePositionUpdates(onCompleted); |
| 2403 | } else { |
| 2404 | loge("startSatellitePositionUpdates: No phone object"); |
Sarah Chin | f75afa7 | 2023-02-01 01:32:19 -0800 | [diff] [blame] | 2405 | request.result = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame^] | 2406 | SatelliteManager.SATELLITE_SERVICE_INVALID_TELEPHONY_STATE; |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 2407 | notifyRequester(request); |
| 2408 | } |
| 2409 | break; |
| 2410 | } |
| 2411 | |
| 2412 | case EVENT_START_SATELLITE_POSITION_UPDATES_DONE: { |
| 2413 | ar = (AsyncResult) msg.obj; |
| 2414 | request = (MainThreadRequest) ar.userObj; |
| 2415 | if (ar.exception == null) { |
| 2416 | request.result = SatelliteManager.SATELLITE_SERVICE_SUCCESS; |
| 2417 | } else { |
| 2418 | request.result = SatelliteManager.SATELLITE_SERVICE_ERROR; |
| 2419 | if (ar.exception instanceof CommandException) { |
| 2420 | CommandException.Error error = |
| 2421 | ((CommandException) (ar.exception)).getCommandError(); |
| 2422 | request.result = RILUtils.convertToSatelliteError(error); |
| 2423 | loge("startSatellitePositionUpdates CommandException: " + ar.exception); |
| 2424 | } else { |
| 2425 | loge("startSatellitePositionUpdates unknown exception:" + ar.exception); |
| 2426 | } |
| 2427 | } |
| 2428 | notifyRequester(request); |
| 2429 | break; |
| 2430 | } |
| 2431 | |
| 2432 | case CMD_STOP_SATELLITE_POSITION_UPDATES: { |
| 2433 | request = (MainThreadRequest) msg.obj; |
| 2434 | onCompleted = |
| 2435 | obtainMessage(EVENT_STOP_SATELLITE_POSITION_UPDATES_DONE, request); |
| 2436 | Phone phone = getPhoneFromRequest(request); |
| 2437 | if (phone != null) { |
| 2438 | phone.stopSatellitePositionUpdates(onCompleted); |
| 2439 | } else { |
| 2440 | loge("stopSatellitePositionUpdates: No phone object"); |
Sarah Chin | f75afa7 | 2023-02-01 01:32:19 -0800 | [diff] [blame] | 2441 | request.result = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame^] | 2442 | SatelliteManager.SATELLITE_SERVICE_INVALID_TELEPHONY_STATE; |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 2443 | notifyRequester(request); |
| 2444 | } |
| 2445 | break; |
| 2446 | } |
| 2447 | |
| 2448 | case EVENT_STOP_SATELLITE_POSITION_UPDATES_DONE: { |
| 2449 | ar = (AsyncResult) msg.obj; |
| 2450 | request = (MainThreadRequest) ar.userObj; |
| 2451 | if (ar.exception == null) { |
| 2452 | request.result = SatelliteManager.SATELLITE_SERVICE_SUCCESS; |
| 2453 | } else { |
| 2454 | request.result = SatelliteManager.SATELLITE_SERVICE_ERROR; |
| 2455 | if (ar.exception instanceof CommandException) { |
| 2456 | CommandException.Error error = |
| 2457 | ((CommandException) (ar.exception)).getCommandError(); |
| 2458 | request.result = RILUtils.convertToSatelliteError(error); |
| 2459 | loge("stopSatellitePositionUpdates CommandException: " + ar.exception); |
| 2460 | } else { |
| 2461 | loge("stopSatellitePositionUpdates unknown exception:" + ar.exception); |
| 2462 | } |
| 2463 | } |
| 2464 | notifyRequester(request); |
| 2465 | break; |
| 2466 | } |
| 2467 | |
Aishwarya Mallampati | 60fe113 | 2023-01-24 19:07:21 +0000 | [diff] [blame] | 2468 | case CMD_GET_MAX_CHAR_PER_SATELLITE_TEXT_MSG: { |
| 2469 | request = (MainThreadRequest) msg.obj; |
| 2470 | onCompleted = obtainMessage(EVENT_GET_MAX_CHAR_PER_SATELLITE_TEXT_MSG_DONE, |
| 2471 | request); |
| 2472 | Phone phone = getPhoneFromRequest(request); |
| 2473 | if (phone != null) { |
| 2474 | phone.getMaxCharactersPerSatelliteTextMessage(onCompleted); |
| 2475 | } else { |
| 2476 | loge("getMaxCharactersPerSatelliteTextMessage: No phone object"); |
| 2477 | request.result = SatelliteManager |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame^] | 2478 | .SATELLITE_SERVICE_INVALID_TELEPHONY_STATE; |
Aishwarya Mallampati | 60fe113 | 2023-01-24 19:07:21 +0000 | [diff] [blame] | 2479 | notifyRequester(request); |
| 2480 | } |
| 2481 | break; |
| 2482 | } |
| 2483 | |
| 2484 | case EVENT_GET_MAX_CHAR_PER_SATELLITE_TEXT_MSG_DONE: { |
| 2485 | ar = (AsyncResult) msg.obj; |
| 2486 | request = (MainThreadRequest) ar.userObj; |
| 2487 | Consumer<Integer> callback = (Consumer<Integer>) request.argument; |
| 2488 | if (ar.exception != null) { |
| 2489 | request.result = SatelliteManager.SATELLITE_SERVICE_ERROR; |
| 2490 | if (ar.exception instanceof CommandException) { |
| 2491 | CommandException.Error error = |
| 2492 | ((CommandException) (ar.exception)).getCommandError(); |
| 2493 | request.result = RILUtils.convertToSatelliteError(error); |
| 2494 | loge("getMaxCharactersPerSatelliteTextMessage: " |
| 2495 | + "CommandException: " + ar.exception); |
| 2496 | } else { |
| 2497 | loge("getMaxCharactersPerSatelliteTextMessage: " |
| 2498 | + "unknown exception:" + ar.exception); |
| 2499 | } |
| 2500 | } else if (ar.result == null) { |
| 2501 | request.result = SatelliteManager |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame^] | 2502 | .SATELLITE_SERVICE_INVALID_TELEPHONY_STATE; |
Aishwarya Mallampati | 60fe113 | 2023-01-24 19:07:21 +0000 | [diff] [blame] | 2503 | loge("getMaxCharactersPerSatelliteTextMessage: result is null"); |
| 2504 | } else { |
| 2505 | request.result = SatelliteManager.SATELLITE_SERVICE_SUCCESS; |
| 2506 | int maxCharLimit = ((int[]) ar.result)[0]; |
| 2507 | if(DBG) log("getMaxCharactersPerSatelliteTextMessage " |
| 2508 | + "maxCharLimit:" + maxCharLimit); |
| 2509 | callback.accept(maxCharLimit); |
| 2510 | } |
| 2511 | notifyRequester(request); |
| 2512 | break; |
| 2513 | } |
| 2514 | |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame^] | 2515 | case CMD_PROVISION_SATELLITE_SERVICE: { |
| 2516 | request = (MainThreadRequest) msg.obj; |
| 2517 | onCompleted = |
| 2518 | obtainMessage(EVENT_PROVISION_SATELLITE_SERVICE_DONE, request); |
| 2519 | Phone phone = getPhoneFromRequest(request); |
| 2520 | if (phone != null) { |
| 2521 | handleCmdProvisionSatelliteService( |
| 2522 | (ProvisionSatelliteServiceArgument) request.argument, |
| 2523 | phone, onCompleted); |
| 2524 | } else { |
| 2525 | loge("provisionSatelliteService: No phone object"); |
| 2526 | request.result = |
| 2527 | SatelliteManager.SATELLITE_SERVICE_INVALID_TELEPHONY_STATE; |
| 2528 | notifyRequester(request); |
| 2529 | } |
| 2530 | break; |
| 2531 | } |
| 2532 | |
| 2533 | case EVENT_PROVISION_SATELLITE_SERVICE_DONE: { |
| 2534 | ar = (AsyncResult) msg.obj; |
| 2535 | request = (MainThreadRequest) ar.userObj; |
| 2536 | if (ar.exception == null) { |
| 2537 | request.result = SatelliteManager.SATELLITE_SERVICE_SUCCESS; |
| 2538 | } else { |
| 2539 | request.result = SatelliteManager.SATELLITE_SERVICE_ERROR; |
| 2540 | if (ar.exception instanceof CommandException) { |
| 2541 | CommandException.Error error = |
| 2542 | ((CommandException) (ar.exception)).getCommandError(); |
| 2543 | request.result = RILUtils.convertToSatelliteError(error); |
| 2544 | loge("provisionSatelliteService CommandException: " + ar.exception); |
| 2545 | } else { |
| 2546 | loge("provisionSatelliteService unknown exception:" + ar.exception); |
| 2547 | } |
| 2548 | } |
| 2549 | handleEventProvisionSatelliteServiceDone(request); |
| 2550 | notifyRequester(request); |
| 2551 | break; |
| 2552 | } |
| 2553 | |
| 2554 | case CMD_CANCEL_PROVISION_SATELLITE_SERVICE: { |
| 2555 | request = (MainThreadRequest) msg.obj; |
| 2556 | onCompleted = |
| 2557 | obtainMessage(EVENT_CANCEL_PROVISION_SATELLITE_SERVICE_DONE, request); |
| 2558 | handleCmdCancelProvisionSatelliteService((int) request.argument, onCompleted); |
| 2559 | break; |
| 2560 | } |
| 2561 | |
| 2562 | case EVENT_CANCEL_PROVISION_SATELLITE_SERVICE_DONE: { |
| 2563 | ar = (AsyncResult) msg.obj; |
| 2564 | request = (MainThreadRequest) ar.userObj; |
| 2565 | |
| 2566 | if (ar.exception == null) { |
| 2567 | request.result = SatelliteManager.SATELLITE_SERVICE_SUCCESS; |
| 2568 | log("cancelProvisionSatelliteService succeeded for subId=" |
| 2569 | + (int) request.argument); |
| 2570 | } else { |
| 2571 | request.result = SatelliteManager.SATELLITE_SERVICE_ERROR; |
| 2572 | if (ar.exception instanceof CommandException) { |
| 2573 | CommandException.Error error = |
| 2574 | ((CommandException) (ar.exception)).getCommandError(); |
| 2575 | request.result = RILUtils.convertToSatelliteError(error); |
| 2576 | loge("cancelProvisionSatelliteService CommandException: " |
| 2577 | + ar.exception + ", error code:" + request.result); |
| 2578 | } else { |
| 2579 | loge("cancelProvisionSatelliteService unknown exception:" |
| 2580 | + ar.exception); |
| 2581 | } |
| 2582 | } |
| 2583 | notifyRequester(request); |
| 2584 | break; |
| 2585 | } |
| 2586 | |
| 2587 | case CMD_GET_PROVISIONED_SATELLITE_FEATURES: { |
| 2588 | request = (MainThreadRequest) msg.obj; |
| 2589 | onCompleted = obtainMessage(EVENT_GET_PROVISIONED_SATELLITE_FEATURES_DONE, |
| 2590 | request); |
| 2591 | Phone phone = getPhoneFromRequest(request); |
| 2592 | if (phone != null) { |
| 2593 | phone.getProvisionedSatelliteFeatures(onCompleted); |
| 2594 | } else { |
| 2595 | loge("getProvisionedSatelliteFeatures: No phone object"); |
| 2596 | request.result = SatelliteManager |
| 2597 | .SATELLITE_SERVICE_INVALID_TELEPHONY_STATE; |
| 2598 | notifyRequester(request); |
| 2599 | } |
| 2600 | break; |
| 2601 | } |
| 2602 | |
| 2603 | case EVENT_GET_PROVISIONED_SATELLITE_FEATURES_DONE: { |
| 2604 | ar = (AsyncResult) msg.obj; |
| 2605 | request = (MainThreadRequest) ar.userObj; |
| 2606 | if (ar.exception != null) { |
| 2607 | request.result = SatelliteManager.SATELLITE_SERVICE_ERROR; |
| 2608 | if (ar.exception instanceof CommandException) { |
| 2609 | CommandException.Error error = |
| 2610 | ((CommandException) (ar.exception)).getCommandError(); |
| 2611 | request.result = RILUtils.convertToSatelliteError(error); |
| 2612 | loge("getProvisionedSatelliteFeatures: " |
| 2613 | + "CommandException: " + ar.exception); |
| 2614 | } else { |
| 2615 | loge("getProvisionedSatelliteFeatures: " |
| 2616 | + "unknown exception:" + ar.exception); |
| 2617 | } |
| 2618 | } else if (ar.result == null) { |
| 2619 | request.result = SatelliteManager |
| 2620 | .SATELLITE_SERVICE_INVALID_TELEPHONY_STATE; |
| 2621 | loge("getProvisionedSatelliteFeatures: result is null"); |
| 2622 | } else { |
| 2623 | request.result = SatelliteManager.SATELLITE_SERVICE_SUCCESS; |
| 2624 | int[] features = ((int[]) ar.result); |
| 2625 | if (DBG) { |
| 2626 | log("getProvisionedSatelliteFeatures features:" |
| 2627 | + Arrays.toString(features)); |
| 2628 | } |
| 2629 | IIntArrayConsumer callback = (IIntArrayConsumer) request.argument; |
| 2630 | if (callback != null) { |
| 2631 | try { |
| 2632 | callback.accept(features); |
| 2633 | } catch (RemoteException ex) { |
| 2634 | log("getProvisionedSatelliteFeatures: remote callback" |
| 2635 | + " not available"); |
| 2636 | } |
| 2637 | } else { |
| 2638 | log("getProvisionedSatelliteFeatures: callback is null"); |
| 2639 | } |
| 2640 | } |
| 2641 | notifyRequester(request); |
| 2642 | break; |
| 2643 | } |
| 2644 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2645 | default: |
| 2646 | Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what); |
| 2647 | break; |
| 2648 | } |
| 2649 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2650 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 2651 | private void notifyRequester(MainThreadRequest request) { |
| 2652 | synchronized (request) { |
| 2653 | request.notifyAll(); |
| 2654 | } |
| 2655 | } |
| 2656 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2657 | private void handleNullReturnEvent(Message msg, String command) { |
| 2658 | AsyncResult ar = (AsyncResult) msg.obj; |
| 2659 | MainThreadRequest request = (MainThreadRequest) ar.userObj; |
| 2660 | if (ar.exception == null) { |
| 2661 | request.result = true; |
| 2662 | } else { |
| 2663 | request.result = false; |
| 2664 | if (ar.exception instanceof CommandException) { |
| 2665 | loge(command + ": CommandException: " + ar.exception); |
| 2666 | } else { |
| 2667 | loge(command + ": Unknown exception"); |
| 2668 | } |
| 2669 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 2670 | notifyRequester(request); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2671 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2672 | } |
| 2673 | |
| 2674 | /** |
| 2675 | * Posts the specified command to be executed on the main thread, |
| 2676 | * waits for the request to complete, and returns the result. |
| 2677 | * @see #sendRequestAsync |
| 2678 | */ |
| 2679 | private Object sendRequest(int command, Object argument) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2680 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, |
| 2681 | null, -1 /*timeoutInMs*/); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 2682 | } |
| 2683 | |
| 2684 | /** |
| 2685 | * Posts the specified command to be executed on the main thread, |
| 2686 | * waits for the request to complete, and returns the result. |
| 2687 | * @see #sendRequestAsync |
| 2688 | */ |
| 2689 | private Object sendRequest(int command, Object argument, WorkSource workSource) { |
| 2690 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2691 | null, workSource, -1 /*timeoutInMs*/); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2692 | } |
| 2693 | |
| 2694 | /** |
| 2695 | * Posts the specified command to be executed on the main thread, |
| 2696 | * waits for the request to complete, and returns the result. |
| 2697 | * @see #sendRequestAsync |
| 2698 | */ |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2699 | private Object sendRequest(int command, Object argument, Integer subId) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2700 | return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/); |
| 2701 | } |
| 2702 | |
| 2703 | /** |
| 2704 | * Posts the specified command to be executed on the main thread, |
| 2705 | * waits for the request to complete for at most {@code timeoutInMs}, and returns the result |
| 2706 | * if not timeout or null otherwise. |
| 2707 | * @see #sendRequestAsync |
| 2708 | */ |
| 2709 | private @Nullable Object sendRequest(int command, Object argument, Integer subId, |
| 2710 | long timeoutInMs) { |
| 2711 | return sendRequest(command, argument, subId, null, null, timeoutInMs); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 2712 | } |
| 2713 | |
| 2714 | /** |
| 2715 | * Posts the specified command to be executed on the main thread, |
| 2716 | * waits for the request to complete, and returns the result. |
| 2717 | * @see #sendRequestAsync |
| 2718 | */ |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2719 | private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2720 | return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2721 | } |
| 2722 | |
| 2723 | /** |
| 2724 | * Posts the specified command to be executed on the main thread, |
| 2725 | * waits for the request to complete, and returns the result. |
| 2726 | * @see #sendRequestAsync |
| 2727 | */ |
| 2728 | private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2729 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, |
| 2730 | workSource, -1 /*timeoutInMs*/); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2731 | } |
| 2732 | |
| 2733 | /** |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2734 | * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is |
| 2735 | * negative, waits for the request to complete, and returns the result. Otherwise, wait for |
| 2736 | * maximum of {@code timeoutInMs} milliseconds, interrupt and return null. |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2737 | * @see #sendRequestAsync |
| 2738 | */ |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2739 | private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone, |
| 2740 | WorkSource workSource, long timeoutInMs) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2741 | if (Looper.myLooper() == mMainThreadHandler.getLooper()) { |
| 2742 | throw new RuntimeException("This method will deadlock if called from the main thread."); |
| 2743 | } |
| 2744 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2745 | MainThreadRequest request = null; |
| 2746 | if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) { |
| 2747 | throw new IllegalArgumentException("subId and phone cannot both be specified!"); |
| 2748 | } else if (phone != null) { |
| 2749 | request = new MainThreadRequest(argument, phone, workSource); |
| 2750 | } else { |
| 2751 | request = new MainThreadRequest(argument, subId, workSource); |
| 2752 | } |
| 2753 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2754 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 2755 | msg.sendToTarget(); |
| 2756 | |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2757 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2758 | synchronized (request) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2759 | if (timeoutInMs >= 0) { |
| 2760 | // Wait for at least timeoutInMs before returning null request result |
| 2761 | long now = SystemClock.elapsedRealtime(); |
| 2762 | long deadline = now + timeoutInMs; |
Grace Jia | 8a0a1e8 | 2021-05-23 22:59:52 -0700 | [diff] [blame] | 2763 | while (request.result == null && now < deadline) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2764 | try { |
| 2765 | request.wait(deadline - now); |
| 2766 | } catch (InterruptedException e) { |
| 2767 | // Do nothing, go back and check if request is completed or timeout |
| 2768 | } finally { |
| 2769 | now = SystemClock.elapsedRealtime(); |
| 2770 | } |
| 2771 | } |
| 2772 | } else { |
| 2773 | // Wait for the request to complete |
| 2774 | while (request.result == null) { |
| 2775 | try { |
| 2776 | request.wait(); |
| 2777 | } catch (InterruptedException e) { |
| 2778 | // Do nothing, go back and wait until the request is complete |
| 2779 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2780 | } |
| 2781 | } |
| 2782 | } |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2783 | if (request.result == null) { |
| 2784 | Log.wtf(LOG_TAG, |
| 2785 | "sendRequest: Blocking command timed out. Something has gone terribly wrong."); |
| 2786 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2787 | return request.result; |
| 2788 | } |
| 2789 | |
| 2790 | /** |
| 2791 | * Asynchronous ("fire and forget") version of sendRequest(): |
| 2792 | * Posts the specified command to be executed on the main thread, and |
| 2793 | * returns immediately. |
| 2794 | * @see #sendRequest |
| 2795 | */ |
| 2796 | private void sendRequestAsync(int command) { |
| 2797 | mMainThreadHandler.sendEmptyMessage(command); |
| 2798 | } |
| 2799 | |
| 2800 | /** |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2801 | * Same as {@link #sendRequestAsync(int)} except it takes an argument. |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2802 | * @see {@link #sendRequest(int)} |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2803 | */ |
| 2804 | private void sendRequestAsync(int command, Object argument) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2805 | sendRequestAsync(command, argument, null, null); |
| 2806 | } |
| 2807 | |
| 2808 | /** |
| 2809 | * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource. |
| 2810 | * @see {@link #sendRequest(int,Object)} |
| 2811 | */ |
| 2812 | private void sendRequestAsync( |
| 2813 | int command, Object argument, Phone phone, WorkSource workSource) { |
| 2814 | MainThreadRequest request = new MainThreadRequest(argument, phone, workSource); |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2815 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 2816 | msg.sendToTarget(); |
| 2817 | } |
| 2818 | |
| 2819 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2820 | * Initialize the singleton PhoneInterfaceManager instance. |
| 2821 | * This is only done once, at startup, from PhoneApp.onCreate(). |
| 2822 | */ |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2823 | /* package */ static PhoneInterfaceManager init(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2824 | synchronized (PhoneInterfaceManager.class) { |
| 2825 | if (sInstance == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2826 | sInstance = new PhoneInterfaceManager(app); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2827 | } else { |
| 2828 | Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance); |
| 2829 | } |
| 2830 | return sInstance; |
| 2831 | } |
| 2832 | } |
| 2833 | |
| 2834 | /** Private constructor; @see init() */ |
Jordan Liu | 1979a04 | 2020-03-20 21:39:35 +0000 | [diff] [blame] | 2835 | private PhoneInterfaceManager(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2836 | mApp = app; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2837 | mCM = PhoneGlobals.getInstance().mCM; |
Brad Ebinger | d1947d8 | 2021-05-17 20:54:49 +0000 | [diff] [blame] | 2838 | mImsResolver = ImsResolver.getInstance(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 2839 | mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2840 | mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 2841 | mPm = app.getSystemService(PackageManager.class); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2842 | mMainThreadHandler = new MainThreadHandler(); |
Jack Yu | e37dd26 | 2022-12-16 11:53:37 -0800 | [diff] [blame] | 2843 | if (!PhoneFactory.isSubscriptionManagerServiceEnabled()) { |
| 2844 | mSubscriptionController = SubscriptionController.getInstance(); |
| 2845 | } else { |
| 2846 | mSubscriptionController = null; |
| 2847 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2848 | mTelephonySharedPreferences = |
| 2849 | PreferenceManager.getDefaultSharedPreferences(mApp); |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 2850 | mNetworkScanRequestTracker = new NetworkScanRequestTracker(); |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 2851 | mPhoneConfigurationManager = PhoneConfigurationManager.getInstance(); |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 2852 | mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance(); |
Peter Wang | a3cf4ac | 2020-01-27 09:39:46 +0800 | [diff] [blame] | 2853 | mNotifyUserActivity = new AtomicBoolean(false); |
Tyler Gunn | 64144d9 | 2022-03-17 14:16:41 -0700 | [diff] [blame] | 2854 | PropertyInvalidatedCache.invalidateCache(TelephonyManager.CACHE_KEY_PHONE_ACCOUNT_TO_SUBID); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2855 | publish(); |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 2856 | CarrierAllowListInfo.loadInstance(mApp); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2857 | } |
| 2858 | |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 2859 | @VisibleForTesting |
| 2860 | public SharedPreferences getSharedPreferences() { |
| 2861 | return mTelephonySharedPreferences; |
| 2862 | } |
| 2863 | |
Gil Cukierman | 92cc7db | 2023-01-06 19:25:53 +0000 | [diff] [blame] | 2864 | /** |
| 2865 | * Get the default phone for this device. |
| 2866 | */ |
| 2867 | @VisibleForTesting |
| 2868 | public Phone getDefaultPhone() { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2869 | Phone thePhone = getPhone(getDefaultSubscription()); |
| 2870 | return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone(); |
| 2871 | } |
| 2872 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2873 | private void publish() { |
| 2874 | if (DBG) log("publish: " + this); |
| 2875 | |
Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 2876 | TelephonyFrameworkInitializer |
| 2877 | .getTelephonyServiceManager() |
| 2878 | .getTelephonyServiceRegisterer() |
| 2879 | .register(this); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2880 | } |
| 2881 | |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 2882 | private Phone getPhoneFromRequest(MainThreadRequest request) { |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 2883 | if (request.phone != null) { |
| 2884 | return request.phone; |
| 2885 | } else { |
| 2886 | return getPhoneFromSubId(request.subId); |
| 2887 | } |
| 2888 | } |
| 2889 | |
| 2890 | private Phone getPhoneFromSubId(int subId) { |
| 2891 | return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) |
| 2892 | ? getDefaultPhone() : getPhone(subId); |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 2893 | } |
| 2894 | |
Aishwarya Mallampati | 5e581e1 | 2023-01-17 21:57:06 +0000 | [diff] [blame] | 2895 | /** |
| 2896 | * Get phone object associated with a subscription. |
| 2897 | * Return default phone if phone object associated with subscription is null |
| 2898 | * @param subId - subscriptionId |
| 2899 | * @return phone object associated with a subscription or default phone if null. |
| 2900 | */ |
| 2901 | private Phone getPhoneFromSubIdOrDefault(int subId) { |
| 2902 | Phone phone = getPhoneFromSubId(subId); |
| 2903 | if (phone == null) { |
| 2904 | phone = getDefaultPhone(); |
| 2905 | } |
| 2906 | return phone; |
| 2907 | } |
| 2908 | |
Rambo Wang | e53e07d | 2022-05-10 13:01:13 -0700 | [diff] [blame] | 2909 | @Nullable |
| 2910 | private UiccPort getUiccPortFromRequest(@NonNull MainThreadRequest request) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2911 | Phone phone = getPhoneFromRequest(request); |
| 2912 | return phone == null ? null : |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 2913 | UiccController.getInstance().getUiccPort(phone.getPhoneId()); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2914 | } |
| 2915 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2916 | // returns phone associated with the subId. |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2917 | private Phone getPhone(int subId) { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 2918 | return PhoneFactory.getPhone(SubscriptionManager.getPhoneId(subId)); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2919 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2920 | |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 2921 | private void sendEraseModemConfig(@NonNull Phone phone) { |
| 2922 | Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null); |
| 2923 | if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 2924 | } |
| 2925 | |
| 2926 | private void sendEraseDataInSharedPreferences(@NonNull Phone phone) { |
| 2927 | Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null); |
| 2928 | if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail")); |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 2929 | } |
| 2930 | |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 2931 | private boolean isImsAvailableOnDevice() { |
| 2932 | PackageManager pm = getDefaultPhone().getContext().getPackageManager(); |
| 2933 | if (pm == null) { |
| 2934 | // For some reason package manger is not available.. This will fail internally anyway, |
| 2935 | // so do not throw error and allow. |
| 2936 | return true; |
| 2937 | } |
| 2938 | return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0); |
| 2939 | } |
| 2940 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2941 | public void dial(String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2942 | dialForSubscriber(getPreferredVoiceSubscription(), number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2943 | } |
| 2944 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2945 | public void dialForSubscriber(int subId, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2946 | if (DBG) log("dial: " + number); |
| 2947 | // No permission check needed here: This is just a wrapper around the |
| 2948 | // ACTION_DIAL intent, which is available to any app since it puts up |
| 2949 | // the UI before it does anything. |
| 2950 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2951 | final long identity = Binder.clearCallingIdentity(); |
| 2952 | try { |
| 2953 | String url = createTelUrl(number); |
| 2954 | if (url == null) { |
| 2955 | return; |
| 2956 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2957 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2958 | // PENDING: should we just silently fail if phone is offhook or ringing? |
| 2959 | PhoneConstants.State state = mCM.getState(subId); |
| 2960 | if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) { |
| 2961 | Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url)); |
| 2962 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2963 | mApp.startActivity(intent); |
| 2964 | } |
| 2965 | } finally { |
| 2966 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2967 | } |
| 2968 | } |
| 2969 | |
| 2970 | public void call(String callingPackage, String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2971 | callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2972 | } |
| 2973 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2974 | public void callForSubscriber(int subId, String callingPackage, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2975 | if (DBG) log("call: " + number); |
| 2976 | |
| 2977 | // This is just a wrapper around the ACTION_CALL intent, but we still |
| 2978 | // need to do a permission check since we're calling startActivity() |
| 2979 | // from the context of the phone app. |
| 2980 | enforceCallPermission(); |
| 2981 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 2982 | if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage) |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2983 | != AppOpsManager.MODE_ALLOWED) { |
| 2984 | return; |
| 2985 | } |
| 2986 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2987 | final long identity = Binder.clearCallingIdentity(); |
| 2988 | try { |
| 2989 | String url = createTelUrl(number); |
| 2990 | if (url == null) { |
| 2991 | return; |
| 2992 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2993 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2994 | boolean isValid = false; |
| 2995 | final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged(); |
| 2996 | if (slist != null) { |
| 2997 | for (SubscriptionInfo subInfoRecord : slist) { |
| 2998 | if (subInfoRecord.getSubscriptionId() == subId) { |
| 2999 | isValid = true; |
| 3000 | break; |
| 3001 | } |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 3002 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 3003 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3004 | if (!isValid) { |
| 3005 | return; |
| 3006 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 3007 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3008 | Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url)); |
| 3009 | intent.putExtra(SUBSCRIPTION_KEY, subId); |
| 3010 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 3011 | mApp.startActivity(intent); |
| 3012 | } finally { |
| 3013 | Binder.restoreCallingIdentity(identity); |
| 3014 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3015 | } |
| 3016 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3017 | public boolean supplyPinForSubscriber(int subId, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 3018 | int [] resultArray = supplyPinReportResultForSubscriber(subId, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 3019 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 3020 | } |
| 3021 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3022 | public boolean supplyPukForSubscriber(int subId, String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 3023 | int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 3024 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 3025 | } |
| 3026 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3027 | public int[] supplyPinReportResultForSubscriber(int subId, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3028 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3029 | |
| 3030 | final long identity = Binder.clearCallingIdentity(); |
| 3031 | try { |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 3032 | Phone phone = getPhone(subId); |
| 3033 | final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3034 | checkSimPin.start(); |
| 3035 | return checkSimPin.unlockSim(null, pin); |
| 3036 | } finally { |
| 3037 | Binder.restoreCallingIdentity(identity); |
| 3038 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3039 | } |
| 3040 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3041 | public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3042 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3043 | |
| 3044 | final long identity = Binder.clearCallingIdentity(); |
| 3045 | try { |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 3046 | Phone phone = getPhone(subId); |
| 3047 | final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3048 | checkSimPuk.start(); |
| 3049 | return checkSimPuk.unlockSim(puk, pin); |
| 3050 | } finally { |
| 3051 | Binder.restoreCallingIdentity(identity); |
| 3052 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3053 | } |
| 3054 | |
| 3055 | /** |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 3056 | * Helper thread to turn async call to SimCard#supplyPin into |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3057 | * a synchronous one. |
| 3058 | */ |
| 3059 | private static class UnlockSim extends Thread { |
| 3060 | |
| 3061 | private final IccCard mSimCard; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 3062 | private final int mPhoneId; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3063 | |
| 3064 | private boolean mDone = false; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 3065 | private int mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 3066 | private int mRetryCount = -1; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3067 | |
| 3068 | // For replies from SimCard interface |
| 3069 | private Handler mHandler; |
| 3070 | |
| 3071 | // For async handler to identify request type |
| 3072 | private static final int SUPPLY_PIN_COMPLETE = 100; |
| 3073 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 3074 | UnlockSim(int phoneId, IccCard simCard) { |
| 3075 | mPhoneId = phoneId; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3076 | mSimCard = simCard; |
| 3077 | } |
| 3078 | |
| 3079 | @Override |
| 3080 | public void run() { |
| 3081 | Looper.prepare(); |
| 3082 | synchronized (UnlockSim.this) { |
| 3083 | mHandler = new Handler() { |
| 3084 | @Override |
| 3085 | public void handleMessage(Message msg) { |
| 3086 | AsyncResult ar = (AsyncResult) msg.obj; |
| 3087 | switch (msg.what) { |
| 3088 | case SUPPLY_PIN_COMPLETE: |
| 3089 | Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE"); |
| 3090 | synchronized (UnlockSim.this) { |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 3091 | mRetryCount = msg.arg1; |
| 3092 | if (ar.exception != null) { |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame^] | 3093 | CommandException.Error error = null; |
| 3094 | if (ar.exception instanceof CommandException) { |
| 3095 | error = ((CommandException) (ar.exception)) |
| 3096 | .getCommandError(); |
| 3097 | } |
| 3098 | if (error == CommandException.Error.PASSWORD_INCORRECT) { |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 3099 | mResult = PhoneConstants.PIN_PASSWORD_INCORRECT; |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame^] | 3100 | } else if (error == CommandException.Error.ABORTED) { |
| 3101 | /* When UiccCardApp dispose, handle message and return |
| 3102 | exception */ |
vivi.li | b5e9ada | 2019-09-12 16:04:24 +0800 | [diff] [blame] | 3103 | mResult = PhoneConstants.PIN_OPERATION_ABORTED; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 3104 | } else { |
| 3105 | mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 3106 | } |
| 3107 | } else { |
| 3108 | mResult = PhoneConstants.PIN_RESULT_SUCCESS; |
| 3109 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3110 | mDone = true; |
| 3111 | UnlockSim.this.notifyAll(); |
| 3112 | } |
| 3113 | break; |
| 3114 | } |
| 3115 | } |
| 3116 | }; |
| 3117 | UnlockSim.this.notifyAll(); |
| 3118 | } |
| 3119 | Looper.loop(); |
| 3120 | } |
| 3121 | |
| 3122 | /* |
| 3123 | * Use PIN or PUK to unlock SIM card |
| 3124 | * |
| 3125 | * If PUK is null, unlock SIM card with PIN |
| 3126 | * |
| 3127 | * If PUK is not null, unlock SIM card with PUK and set PIN code |
| 3128 | */ |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 3129 | synchronized int[] unlockSim(String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3130 | |
| 3131 | while (mHandler == null) { |
| 3132 | try { |
| 3133 | wait(); |
| 3134 | } catch (InterruptedException e) { |
| 3135 | Thread.currentThread().interrupt(); |
| 3136 | } |
| 3137 | } |
| 3138 | Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE); |
| 3139 | |
| 3140 | if (puk == null) { |
| 3141 | mSimCard.supplyPin(pin, callback); |
| 3142 | } else { |
| 3143 | mSimCard.supplyPuk(puk, pin, callback); |
| 3144 | } |
| 3145 | |
| 3146 | while (!mDone) { |
| 3147 | try { |
| 3148 | Log.d(LOG_TAG, "wait for done"); |
| 3149 | wait(); |
| 3150 | } catch (InterruptedException e) { |
| 3151 | // Restore the interrupted status |
| 3152 | Thread.currentThread().interrupt(); |
| 3153 | } |
| 3154 | } |
| 3155 | Log.d(LOG_TAG, "done"); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 3156 | int[] resultArray = new int[2]; |
| 3157 | resultArray[0] = mResult; |
| 3158 | resultArray[1] = mRetryCount; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 3159 | |
| 3160 | if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) { |
Jon Spivack | 9c3bc76 | 2021-10-06 20:53:09 +0000 | [diff] [blame] | 3161 | UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 3162 | } |
| 3163 | |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 3164 | return resultArray; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3165 | } |
| 3166 | } |
| 3167 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 3168 | /** |
| 3169 | * This method has been removed due to privacy and stability concerns. |
| 3170 | */ |
| 3171 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3172 | public void updateServiceLocation() { |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 3173 | Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()"); |
| 3174 | return; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3175 | } |
| 3176 | |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 3177 | @Override |
| 3178 | public void updateServiceLocationWithPackageName(String callingPackage) { |
| 3179 | mApp.getSystemService(AppOpsManager.class) |
| 3180 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 3181 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3182 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 3183 | if (targetSdk > android.os.Build.VERSION_CODES.R) { |
| 3184 | // Callers targeting S have no business invoking this method. |
| 3185 | return; |
| 3186 | } |
| 3187 | |
| 3188 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 3189 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 3190 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 3191 | .setCallingPackage(callingPackage) |
| 3192 | .setCallingFeatureId(null) |
| 3193 | .setCallingPid(Binder.getCallingPid()) |
| 3194 | .setCallingUid(Binder.getCallingUid()) |
| 3195 | .setMethod("updateServiceLocation") |
| 3196 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
| 3197 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 3198 | .build()); |
| 3199 | // Apps that lack location permission have no business calling this method; |
| 3200 | // however, because no permission was declared in the public API, denials must |
| 3201 | // all be "soft". |
| 3202 | switch (locationResult) { |
| 3203 | case DENIED_HARD: /* fall through */ |
| 3204 | case DENIED_SOFT: |
| 3205 | return; |
| 3206 | } |
| 3207 | |
| 3208 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3209 | final long identity = Binder.clearCallingIdentity(); |
| 3210 | try { |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 3211 | final Phone phone = getPhone(getDefaultSubscription()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3212 | if (phone != null) { |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 3213 | phone.updateServiceLocation(workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3214 | } |
| 3215 | } finally { |
| 3216 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3217 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3218 | } |
| 3219 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3220 | @Deprecated |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3221 | @Override |
| 3222 | public boolean isRadioOn(String callingPackage) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3223 | return isRadioOnWithFeature(callingPackage, null); |
| 3224 | } |
| 3225 | |
| 3226 | |
| 3227 | @Override |
| 3228 | public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) { |
| 3229 | return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage, |
| 3230 | callingFeatureId); |
| 3231 | } |
| 3232 | |
| 3233 | @Deprecated |
| 3234 | @Override |
| 3235 | public boolean isRadioOnForSubscriber(int subId, String callingPackage) { |
| 3236 | return isRadioOnForSubscriberWithFeature(subId, callingPackage, null); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3237 | } |
| 3238 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3239 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3240 | public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage, |
| 3241 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3242 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3243 | mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3244 | return false; |
| 3245 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3246 | |
| 3247 | final long identity = Binder.clearCallingIdentity(); |
| 3248 | try { |
| 3249 | return isRadioOnForSubscriber(subId); |
| 3250 | } finally { |
| 3251 | Binder.restoreCallingIdentity(identity); |
| 3252 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3253 | } |
| 3254 | |
| 3255 | private boolean isRadioOnForSubscriber(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3256 | final long identity = Binder.clearCallingIdentity(); |
| 3257 | try { |
| 3258 | final Phone phone = getPhone(subId); |
| 3259 | if (phone != null) { |
| 3260 | return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF; |
| 3261 | } else { |
| 3262 | return false; |
| 3263 | } |
| 3264 | } finally { |
| 3265 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3266 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3267 | } |
| 3268 | |
| 3269 | public void toggleRadioOnOff() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 3270 | toggleRadioOnOffForSubscriber(getDefaultSubscription()); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3271 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3272 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3273 | public void toggleRadioOnOffForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3274 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3275 | |
| 3276 | final long identity = Binder.clearCallingIdentity(); |
| 3277 | try { |
| 3278 | final Phone phone = getPhone(subId); |
| 3279 | if (phone != null) { |
| 3280 | phone.setRadioPower(!isRadioOnForSubscriber(subId)); |
| 3281 | } |
| 3282 | } finally { |
| 3283 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3284 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3285 | } |
| 3286 | |
| 3287 | public boolean setRadio(boolean turnOn) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 3288 | return setRadioForSubscriber(getDefaultSubscription(), turnOn); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3289 | } |
| 3290 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3291 | public boolean setRadioForSubscriber(int subId, boolean turnOn) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3292 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3293 | |
| 3294 | final long identity = Binder.clearCallingIdentity(); |
| 3295 | try { |
| 3296 | final Phone phone = getPhone(subId); |
| 3297 | if (phone == null) { |
| 3298 | return false; |
| 3299 | } |
| 3300 | if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) { |
| 3301 | toggleRadioOnOffForSubscriber(subId); |
| 3302 | } |
| 3303 | return true; |
| 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 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3308 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3309 | public boolean needMobileRadioShutdown() { |
Shuo Qian | fa7b6b3 | 2019-12-10 10:40:38 -0800 | [diff] [blame] | 3310 | enforceReadPrivilegedPermission("needMobileRadioShutdown"); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3311 | /* |
| 3312 | * If any of the Radios are available, it will need to be |
| 3313 | * shutdown. So return true if any Radio is available. |
| 3314 | */ |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3315 | final long identity = Binder.clearCallingIdentity(); |
| 3316 | try { |
| 3317 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 3318 | Phone phone = PhoneFactory.getPhone(i); |
| 3319 | if (phone != null && phone.isRadioAvailable()) return true; |
| 3320 | } |
| 3321 | logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown."); |
| 3322 | return false; |
| 3323 | } finally { |
| 3324 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3325 | } |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3326 | } |
| 3327 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3328 | @Override |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3329 | public void shutdownMobileRadios() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3330 | enforceModifyPermission(); |
| 3331 | |
| 3332 | final long identity = Binder.clearCallingIdentity(); |
| 3333 | try { |
| 3334 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 3335 | logv("Shutting down Phone " + i); |
| 3336 | shutdownRadioUsingPhoneId(i); |
| 3337 | } |
| 3338 | } finally { |
| 3339 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3340 | } |
| 3341 | } |
| 3342 | |
| 3343 | private void shutdownRadioUsingPhoneId(int phoneId) { |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3344 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 3345 | if (phone != null && phone.isRadioAvailable()) { |
| 3346 | phone.shutdownRadio(); |
| 3347 | } |
| 3348 | } |
| 3349 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3350 | public boolean setRadioPower(boolean turnOn) { |
Jack Yu | b4e1616 | 2017-05-15 12:48:40 -0700 | [diff] [blame] | 3351 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3352 | |
Ling Ma | 83dc5ea | 2023-01-12 15:06:04 -0800 | [diff] [blame] | 3353 | if (!turnOn) { |
| 3354 | log("setRadioPower off: callingPackage=" + getCurrentPackageName()); |
| 3355 | } |
| 3356 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3357 | final long identity = Binder.clearCallingIdentity(); |
| 3358 | try { |
| 3359 | final Phone defaultPhone = PhoneFactory.getDefaultPhone(); |
| 3360 | if (defaultPhone != null) { |
| 3361 | defaultPhone.setRadioPower(turnOn); |
| 3362 | return true; |
| 3363 | } else { |
| 3364 | loge("There's no default phone."); |
| 3365 | return false; |
| 3366 | } |
| 3367 | } finally { |
| 3368 | Binder.restoreCallingIdentity(identity); |
Wei Liu | 9ae2a06 | 2016-08-08 11:09:34 -0700 | [diff] [blame] | 3369 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3370 | } |
| 3371 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3372 | public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3373 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3374 | |
Ling Ma | 83dc5ea | 2023-01-12 15:06:04 -0800 | [diff] [blame] | 3375 | if (!turnOn) { |
| 3376 | log("setRadioPowerForSubscriber off: subId=" + subId |
| 3377 | + ",callingPackage=" + getCurrentPackageName()); |
| 3378 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3379 | final long identity = Binder.clearCallingIdentity(); |
| 3380 | try { |
| 3381 | final Phone phone = getPhone(subId); |
| 3382 | if (phone != null) { |
| 3383 | phone.setRadioPower(turnOn); |
| 3384 | return true; |
| 3385 | } else { |
| 3386 | return false; |
| 3387 | } |
| 3388 | } finally { |
| 3389 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3390 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3391 | } |
| 3392 | |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3393 | /** |
| 3394 | * Vote on powering off the radio for a reason. The radio will be turned on only when there is |
| 3395 | * no reason to power it off. When any of the voters want to power it off, it will be turned |
| 3396 | * off. In case of emergency, the radio will be turned on even if there are some reasons for |
| 3397 | * powering it off, and these radio off votes will be cleared. |
| 3398 | * Multiple apps can vote for the same reason and the last vote will take effect. Each app is |
| 3399 | * responsible for its vote. A powering-off vote of a reason will be maintained until it is |
| 3400 | * cleared by calling {@link clearRadioPowerOffForReason} for that reason, or an emergency call |
| 3401 | * is made, or the device is rebooted. When an app comes backup from a crash, it needs to make |
| 3402 | * sure if its vote is as expected. An app can use the API {@link getRadioPowerOffReasons} to |
| 3403 | * check its vote. |
| 3404 | * |
| 3405 | * @param subId The subscription ID. |
| 3406 | * @param reason The reason for powering off radio. |
| 3407 | * @return true on success and false on failure. |
| 3408 | */ |
| 3409 | public boolean requestRadioPowerOffForReason(int subId, |
| 3410 | @TelephonyManager.RadioPowerReason int reason) { |
| 3411 | enforceModifyPermission(); |
| 3412 | |
Ling Ma | 83dc5ea | 2023-01-12 15:06:04 -0800 | [diff] [blame] | 3413 | log("requestRadioPowerOffForReason: subId=" + subId |
| 3414 | + ",reason=" + reason + ",callingPackage=" + getCurrentPackageName()); |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3415 | final long identity = Binder.clearCallingIdentity(); |
| 3416 | try { |
| 3417 | final Phone phone = getPhone(subId); |
| 3418 | if (phone != null) { |
| 3419 | phone.setRadioPowerForReason(false, reason); |
| 3420 | return true; |
| 3421 | } else { |
| 3422 | return false; |
| 3423 | } |
| 3424 | } finally { |
| 3425 | Binder.restoreCallingIdentity(identity); |
| 3426 | } |
| 3427 | } |
| 3428 | |
| 3429 | /** |
| 3430 | * Remove the vote on powering off the radio for a reason, as requested by |
| 3431 | * {@link requestRadioPowerOffForReason}. |
| 3432 | * |
| 3433 | * @param subId The subscription ID. |
| 3434 | * @param reason The reason for powering off radio. |
| 3435 | * @return true on success and false on failure. |
| 3436 | */ |
| 3437 | public boolean clearRadioPowerOffForReason(int subId, |
| 3438 | @TelephonyManager.RadioPowerReason int reason) { |
| 3439 | enforceModifyPermission(); |
| 3440 | |
| 3441 | final long identity = Binder.clearCallingIdentity(); |
| 3442 | try { |
| 3443 | final Phone phone = getPhone(subId); |
| 3444 | if (phone != null) { |
| 3445 | phone.setRadioPowerForReason(true, reason); |
| 3446 | return true; |
| 3447 | } else { |
| 3448 | return false; |
| 3449 | } |
| 3450 | } finally { |
| 3451 | Binder.restoreCallingIdentity(identity); |
| 3452 | } |
| 3453 | } |
| 3454 | |
| 3455 | /** |
| 3456 | * Get reasons for powering off radio, as requested by {@link requestRadioPowerOffForReason}. |
| 3457 | * |
| 3458 | * @param subId The subscription ID. |
| 3459 | * @param callingPackage The package making the call. |
| 3460 | * @param callingFeatureId The feature in the package. |
| 3461 | * @return List of reasons for powering off radio. |
| 3462 | */ |
| 3463 | public List getRadioPowerOffReasons(int subId, String callingPackage, String callingFeatureId) { |
| 3464 | enforceReadPrivilegedPermission("getRadioPowerOffReasons"); |
| 3465 | |
| 3466 | final long identity = Binder.clearCallingIdentity(); |
| 3467 | List result = new ArrayList(); |
| 3468 | try { |
| 3469 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, |
| 3470 | callingPackage, callingFeatureId, "getRadioPowerOffReasons")) { |
| 3471 | return result; |
| 3472 | } |
| 3473 | |
| 3474 | final Phone phone = getPhone(subId); |
| 3475 | if (phone != null) { |
| 3476 | result.addAll(phone.getRadioPowerOffReasons()); |
| 3477 | } |
| 3478 | } finally { |
| 3479 | Binder.restoreCallingIdentity(identity); |
| 3480 | } |
| 3481 | return result; |
| 3482 | } |
| 3483 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3484 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3485 | @Override |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 3486 | public boolean enableDataConnectivity(String callingPackage) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3487 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3488 | |
| 3489 | final long identity = Binder.clearCallingIdentity(); |
| 3490 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3491 | int subId = SubscriptionManager.getDefaultDataSubscriptionId(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3492 | final Phone phone = getPhone(subId); |
| 3493 | if (phone != null) { |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 3494 | phone.getDataSettingsManager().setDataEnabled( |
| 3495 | TelephonyManager.DATA_ENABLED_REASON_USER, true, callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3496 | return true; |
| 3497 | } else { |
| 3498 | return false; |
| 3499 | } |
| 3500 | } finally { |
| 3501 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3502 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3503 | } |
| 3504 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3505 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3506 | @Override |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 3507 | public boolean disableDataConnectivity(String callingPackage) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3508 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3509 | |
| 3510 | final long identity = Binder.clearCallingIdentity(); |
| 3511 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3512 | int subId = SubscriptionManager.getDefaultDataSubscriptionId(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3513 | final Phone phone = getPhone(subId); |
| 3514 | if (phone != null) { |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 3515 | phone.getDataSettingsManager().setDataEnabled( |
| 3516 | TelephonyManager.DATA_ENABLED_REASON_USER, false, callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3517 | return true; |
| 3518 | } else { |
| 3519 | return false; |
| 3520 | } |
| 3521 | } finally { |
| 3522 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3523 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3524 | } |
| 3525 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3526 | @Override |
Jack Yu | acf8a13 | 2017-05-01 17:00:48 -0700 | [diff] [blame] | 3527 | public boolean isDataConnectivityPossible(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3528 | final long identity = Binder.clearCallingIdentity(); |
| 3529 | try { |
| 3530 | final Phone phone = getPhone(subId); |
| 3531 | if (phone != null) { |
Jack Yu | 59824e1 | 2022-03-23 01:42:44 -0700 | [diff] [blame] | 3532 | return phone.isDataAllowed(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3533 | } else { |
| 3534 | return false; |
| 3535 | } |
| 3536 | } finally { |
| 3537 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3538 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3539 | } |
| 3540 | |
| 3541 | public boolean handlePinMmi(String dialString) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 3542 | return handlePinMmiForSubscriber(getDefaultSubscription(), dialString); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3543 | } |
| 3544 | |
pkanwar | ae03a6b | 2016-11-06 20:37:09 -0800 | [diff] [blame] | 3545 | public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3546 | enforceCallPermission(); |
| 3547 | |
| 3548 | final long identity = Binder.clearCallingIdentity(); |
| 3549 | try { |
| 3550 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3551 | return; |
| 3552 | } |
| 3553 | Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback); |
| 3554 | sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId); |
| 3555 | } finally { |
| 3556 | Binder.restoreCallingIdentity(identity); |
| 3557 | } |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 3558 | }; |
| 3559 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3560 | public boolean handlePinMmiForSubscriber(int subId, String dialString) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3561 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3562 | |
| 3563 | final long identity = Binder.clearCallingIdentity(); |
| 3564 | try { |
| 3565 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3566 | return false; |
| 3567 | } |
| 3568 | return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId); |
| 3569 | } finally { |
| 3570 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3571 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3572 | } |
| 3573 | |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 3574 | /** |
| 3575 | * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage |
| 3576 | * tag on getCallState Binder call. |
| 3577 | */ |
| 3578 | @Deprecated |
| 3579 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3580 | public int getCallState() { |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 3581 | if (CompatChanges.isChangeEnabled( |
| 3582 | TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION, |
| 3583 | Binder.getCallingUid())) { |
| 3584 | // Do not allow this API to be called on API version 31+, it should only be |
| 3585 | // called on old apps using this Binder call directly. |
| 3586 | throw new SecurityException("This method can only be used for applications " |
| 3587 | + "targeting API version 30 or less."); |
| 3588 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3589 | final long identity = Binder.clearCallingIdentity(); |
| 3590 | try { |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 3591 | Phone phone = getPhone(getDefaultSubscription()); |
| 3592 | return phone == null ? TelephonyManager.CALL_STATE_IDLE : |
| 3593 | PhoneConstantConversions.convertCallState(phone.getState()); |
| 3594 | } finally { |
| 3595 | Binder.restoreCallingIdentity(identity); |
| 3596 | } |
| 3597 | } |
| 3598 | |
| 3599 | @Override |
| 3600 | public int getCallStateForSubscription(int subId, String callingPackage, String featureId) { |
| 3601 | if (CompatChanges.isChangeEnabled( |
| 3602 | TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION, |
| 3603 | Binder.getCallingUid())) { |
| 3604 | // Check READ_PHONE_STATE for API version 31+ |
| 3605 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage, |
| 3606 | featureId, "getCallStateForSubscription")) { |
| 3607 | throw new SecurityException("getCallState requires READ_PHONE_STATE for apps " |
| 3608 | + "targeting API level 31+."); |
| 3609 | } |
| 3610 | } |
| 3611 | final long identity = Binder.clearCallingIdentity(); |
| 3612 | try { |
| 3613 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3614 | return phone == null ? TelephonyManager.CALL_STATE_IDLE : |
| 3615 | PhoneConstantConversions.convertCallState(phone.getState()); |
| 3616 | } finally { |
| 3617 | Binder.restoreCallingIdentity(identity); |
| 3618 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3619 | } |
| 3620 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3621 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 3622 | public int getDataState() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3623 | return getDataStateForSubId(SubscriptionManager.getDefaultDataSubscriptionId()); |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 3624 | } |
| 3625 | |
| 3626 | @Override |
| 3627 | public int getDataStateForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3628 | final long identity = Binder.clearCallingIdentity(); |
| 3629 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 3630 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3631 | if (phone != null) { |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 3632 | return phone.getDataNetworkController().getInternetDataNetworkState(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3633 | } else { |
| 3634 | return PhoneConstantConversions.convertDataState( |
| 3635 | PhoneConstants.DataState.DISCONNECTED); |
| 3636 | } |
| 3637 | } finally { |
| 3638 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3639 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3640 | } |
| 3641 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3642 | @Override |
Jack Yu | 0eda684 | 2022-04-18 00:34:46 -0700 | [diff] [blame] | 3643 | public @DataActivityType int getDataActivity() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3644 | return getDataActivityForSubId(SubscriptionManager.getDefaultDataSubscriptionId()); |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 3645 | } |
| 3646 | |
| 3647 | @Override |
Jack Yu | 0eda684 | 2022-04-18 00:34:46 -0700 | [diff] [blame] | 3648 | public @DataActivityType int getDataActivityForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3649 | final long identity = Binder.clearCallingIdentity(); |
| 3650 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 3651 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3652 | if (phone != null) { |
Jack Yu | 0eda684 | 2022-04-18 00:34:46 -0700 | [diff] [blame] | 3653 | return phone.getDataActivityState(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3654 | } else { |
| 3655 | return TelephonyManager.DATA_ACTIVITY_NONE; |
| 3656 | } |
| 3657 | } finally { |
| 3658 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3659 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3660 | } |
| 3661 | |
| 3662 | @Override |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 3663 | public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3664 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 3665 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3666 | |
| 3667 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 3668 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 3669 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 3670 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3671 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3672 | .setCallingPid(Binder.getCallingPid()) |
| 3673 | .setCallingUid(Binder.getCallingUid()) |
| 3674 | .setMethod("getCellLocation") |
Hall Liu | 773ba02 | 2020-01-24 18:07:12 -0800 | [diff] [blame] | 3675 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3676 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 3677 | .build()); |
| 3678 | switch (locationResult) { |
| 3679 | case DENIED_HARD: |
| 3680 | throw new SecurityException("Not allowed to access cell location"); |
| 3681 | case DENIED_SOFT: |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 3682 | return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
| 3683 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3684 | } |
| 3685 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 3686 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3687 | final long identity = Binder.clearCallingIdentity(); |
| 3688 | try { |
| 3689 | if (DBG_LOC) log("getCellLocation: is active user"); |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3690 | int subId = SubscriptionManager.getDefaultDataSubscriptionId(); |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 3691 | return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3692 | } finally { |
| 3693 | Binder.restoreCallingIdentity(identity); |
| 3694 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 3695 | } |
| 3696 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3697 | @Override |
Jack Yu | eb1e7fe | 2020-02-22 19:38:58 -0800 | [diff] [blame] | 3698 | public String getNetworkCountryIsoForPhone(int phoneId) { |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3699 | // Reporting the correct network country is ambiguous when IWLAN could conflict with |
| 3700 | // registered cell info, so return a NULL country instead. |
| 3701 | final long identity = Binder.clearCallingIdentity(); |
| 3702 | try { |
Malcolm Chen | 3732c2b | 2018-07-18 20:15:24 -0700 | [diff] [blame] | 3703 | if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) { |
| 3704 | // Get default phone in this case. |
| 3705 | phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX; |
| 3706 | } |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3707 | final int subId = SubscriptionManager.getSubscriptionId(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3708 | Phone phone = PhoneFactory.getPhone(phoneId); |
Nathan Harold | 532f51c | 2020-04-21 19:31:10 -0700 | [diff] [blame] | 3709 | if (phone == null) return ""; |
| 3710 | ServiceStateTracker sst = phone.getServiceStateTracker(); |
| 3711 | if (sst == null) return ""; |
| 3712 | LocaleTracker lt = sst.getLocaleTracker(); |
| 3713 | if (lt == null) return ""; |
Shuo Qian | 9418a92 | 2021-03-09 11:21:16 -0800 | [diff] [blame] | 3714 | return lt.getCurrentCountry(); |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3715 | } finally { |
| 3716 | Binder.restoreCallingIdentity(identity); |
| 3717 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3718 | } |
| 3719 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 3720 | /** |
| 3721 | * This method was removed due to potential issues caused by performing partial |
| 3722 | * updates of service state, and lack of a credible use case. |
| 3723 | * |
| 3724 | * This has the ability to break the telephony implementation by disabling notification of |
| 3725 | * changes in device connectivity. DO NOT USE THIS! |
| 3726 | */ |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3727 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3728 | public void enableLocationUpdates() { |
| 3729 | mApp.enforceCallingOrSelfPermission( |
| 3730 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3731 | } |
| 3732 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 3733 | /** |
| 3734 | * This method was removed due to potential issues caused by performing partial |
| 3735 | * updates of service state, and lack of a credible use case. |
| 3736 | * |
| 3737 | * This has the ability to break the telephony implementation by disabling notification of |
| 3738 | * changes in device connectivity. DO NOT USE THIS! |
| 3739 | */ |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3740 | @Override |
| 3741 | public void disableLocationUpdates() { |
| 3742 | mApp.enforceCallingOrSelfPermission( |
| 3743 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3744 | } |
| 3745 | |
| 3746 | @Override |
| 3747 | @SuppressWarnings("unchecked") |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3748 | public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage, |
| 3749 | String callingFeatureId) { |
Nathan Harold | b55f63b | 2021-07-27 11:27:38 -0700 | [diff] [blame] | 3750 | try { |
| 3751 | mApp.getSystemService(AppOpsManager.class) |
| 3752 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 3753 | } catch (SecurityException e) { |
| 3754 | EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid()); |
| 3755 | throw e; |
| 3756 | } |
| 3757 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3758 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | dbea45a | 2018-08-30 14:35:07 -0700 | [diff] [blame] | 3759 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 3760 | throw new SecurityException( |
| 3761 | "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels."); |
| 3762 | } |
Nathan Harold | b4d5561 | 2018-07-20 13:13:08 -0700 | [diff] [blame] | 3763 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 3764 | if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(), |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3765 | callingPackage) != AppOpsManager.MODE_ALLOWED) { |
| 3766 | return null; |
| 3767 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 3768 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 3769 | if (DBG_LOC) log("getNeighboringCellInfo: is active user"); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3770 | |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3771 | List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId); |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 3772 | if (info == null) return null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3773 | |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 3774 | List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>(); |
| 3775 | for (CellInfo ci : info) { |
| 3776 | if (ci instanceof CellInfoGsm) { |
| 3777 | neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci)); |
| 3778 | } else if (ci instanceof CellInfoWcdma) { |
| 3779 | neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci)); |
| 3780 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3781 | } |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 3782 | return (neighbors.size()) > 0 ? neighbors : null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3783 | } |
| 3784 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3785 | private List<CellInfo> getCachedCellInfo() { |
| 3786 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 3787 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3788 | List<CellInfo> info = phone.getAllCellInfo(); |
| 3789 | if (info != null) cellInfos.addAll(info); |
| 3790 | } |
| 3791 | return cellInfos; |
| 3792 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3793 | |
| 3794 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3795 | public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3796 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 3797 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3798 | |
| 3799 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 3800 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 3801 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 3802 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3803 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3804 | .setCallingPid(Binder.getCallingPid()) |
| 3805 | .setCallingUid(Binder.getCallingUid()) |
| 3806 | .setMethod("getAllCellInfo") |
Nathan Harold | 5ae50b5 | 2019-02-20 15:46:36 -0800 | [diff] [blame] | 3807 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3808 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 3809 | .build()); |
| 3810 | switch (locationResult) { |
| 3811 | case DENIED_HARD: |
| 3812 | throw new SecurityException("Not allowed to access cell info"); |
| 3813 | case DENIED_SOFT: |
| 3814 | return new ArrayList<>(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3815 | } |
| 3816 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3817 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3818 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 3819 | return getCachedCellInfo(); |
| 3820 | } |
| 3821 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 3822 | if (DBG_LOC) log("getAllCellInfo: is active user"); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 3823 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3824 | final long identity = Binder.clearCallingIdentity(); |
| 3825 | try { |
| 3826 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 3827 | for (Phone phone : PhoneFactory.getPhones()) { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 3828 | final List<CellInfo> info = (List<CellInfo>) sendRequest( |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 3829 | CMD_GET_ALL_CELL_INFO, null, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3830 | if (info != null) cellInfos.addAll(info); |
| 3831 | } |
| 3832 | return cellInfos; |
| 3833 | } finally { |
| 3834 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3835 | } |
| 3836 | } |
| 3837 | |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 3838 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3839 | public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage, |
| 3840 | String callingFeatureId) { |
| 3841 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, |
| 3842 | getWorkSource(Binder.getCallingUid())); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3843 | } |
| 3844 | |
| 3845 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3846 | public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb, |
| 3847 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3848 | enforceModifyPermission(); |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3849 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3850 | } |
| 3851 | |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3852 | private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb, |
| 3853 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3854 | mApp.getSystemService(AppOpsManager.class) |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3855 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3856 | |
| 3857 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 3858 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 3859 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 3860 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3861 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3862 | .setCallingPid(Binder.getCallingPid()) |
| 3863 | .setCallingUid(Binder.getCallingUid()) |
| 3864 | .setMethod("requestCellInfoUpdate") |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 3865 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
| 3866 | .setMinSdkVersionForFine(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3867 | .build()); |
| 3868 | switch (locationResult) { |
| 3869 | case DENIED_HARD: |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3870 | if (TelephonyPermissions |
| 3871 | .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) { |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 3872 | // Safetynet logging for b/154934934 |
| 3873 | EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid()); |
| 3874 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3875 | throw new SecurityException("Not allowed to access cell info"); |
| 3876 | case DENIED_SOFT: |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3877 | if (TelephonyPermissions |
| 3878 | .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) { |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 3879 | // Safetynet logging for b/154934934 |
| 3880 | EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid()); |
| 3881 | } |
Nathan Harold | 5320c42 | 2019-05-09 10:26:08 -0700 | [diff] [blame] | 3882 | try { |
| 3883 | cb.onCellInfo(new ArrayList<CellInfo>()); |
| 3884 | } catch (RemoteException re) { |
| 3885 | // Drop without consequences |
| 3886 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3887 | return; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3888 | } |
| 3889 | |
Nathan Harold | a939a96 | 2019-05-09 10:13:47 -0700 | [diff] [blame] | 3890 | |
| 3891 | final Phone phone = getPhoneFromSubId(subId); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3892 | if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
| 3893 | |
| 3894 | sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource); |
| 3895 | } |
| 3896 | |
| 3897 | @Override |
Aishwarya Mallampati | 0603fb1 | 2022-08-24 21:16:56 +0000 | [diff] [blame] | 3898 | public void setCellInfoListRate(int rateInMillis, int subId) { |
Jack Yu | a8d8cb8 | 2017-01-16 10:15:34 -0800 | [diff] [blame] | 3899 | enforceModifyPermission(); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 3900 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3901 | |
| 3902 | final long identity = Binder.clearCallingIdentity(); |
| 3903 | try { |
Aishwarya Mallampati | 0603fb1 | 2022-08-24 21:16:56 +0000 | [diff] [blame] | 3904 | Phone phone = getPhone(subId); |
| 3905 | if (phone == null) { |
| 3906 | getDefaultPhone().setCellInfoListRate(rateInMillis, workSource); |
| 3907 | } else { |
| 3908 | phone.setCellInfoListRate(rateInMillis, workSource); |
| 3909 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3910 | } finally { |
| 3911 | Binder.restoreCallingIdentity(identity); |
| 3912 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3913 | } |
| 3914 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3915 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3916 | public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3917 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3918 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3919 | return null; |
| 3920 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3921 | int subId = phone.getSubId(); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3922 | enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot"); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 3923 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3924 | callingPackage, callingFeatureId, "getImeiForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3925 | return null; |
| 3926 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3927 | |
| 3928 | final long identity = Binder.clearCallingIdentity(); |
| 3929 | try { |
| 3930 | return phone.getImei(); |
| 3931 | } finally { |
| 3932 | Binder.restoreCallingIdentity(identity); |
| 3933 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3934 | } |
| 3935 | |
| 3936 | @Override |
arunvoddu | d5c6ce0 | 2022-12-11 06:03:12 +0000 | [diff] [blame] | 3937 | public String getPrimaryImei(String callingPackage, String callingFeatureId) { |
| 3938 | enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getPrimaryImei"); |
| 3939 | if (!checkCallingOrSelfReadDeviceIdentifiersForAnySub(mApp, callingPackage, |
| 3940 | callingFeatureId, "getPrimaryImei")) { |
| 3941 | throw new SecurityException("Caller does not have permission"); |
| 3942 | } |
| 3943 | final long identity = Binder.clearCallingIdentity(); |
| 3944 | try { |
| 3945 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3946 | if (phone.getImeiType() == Phone.IMEI_TYPE_PRIMARY) { |
| 3947 | return phone.getImei(); |
| 3948 | } |
| 3949 | } |
| 3950 | throw new UnsupportedOperationException("Operation not supported"); |
| 3951 | } finally { |
| 3952 | Binder.restoreCallingIdentity(identity); |
| 3953 | } |
| 3954 | } |
| 3955 | |
| 3956 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3957 | public String getTypeAllocationCodeForSlot(int slotIndex) { |
| 3958 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3959 | String tac = null; |
| 3960 | if (phone != null) { |
| 3961 | String imei = phone.getImei(); |
Vala Zadeh | ab00555 | 2021-09-21 15:54:29 -0700 | [diff] [blame] | 3962 | try { |
| 3963 | tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH); |
| 3964 | } catch (IndexOutOfBoundsException e) { |
| 3965 | Log.e(LOG_TAG, "IMEI length shorter than upper index."); |
| 3966 | return null; |
| 3967 | } |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3968 | } |
| 3969 | return tac; |
| 3970 | } |
| 3971 | |
| 3972 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3973 | public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Shuo Qian | 13d8915 | 2021-05-10 23:58:11 -0700 | [diff] [blame] | 3974 | try { |
| 3975 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 3976 | } catch (SecurityException se) { |
| 3977 | EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid()); |
| 3978 | throw new SecurityException("Package " + callingPackage + " does not belong to " |
| 3979 | + Binder.getCallingUid()); |
| 3980 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3981 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3982 | if (phone == null) { |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 3983 | return null; |
| 3984 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3985 | |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3986 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 3987 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3988 | callingPackage, callingFeatureId, "getMeidForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3989 | return null; |
| 3990 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3991 | |
| 3992 | final long identity = Binder.clearCallingIdentity(); |
| 3993 | try { |
| 3994 | return phone.getMeid(); |
| 3995 | } finally { |
| 3996 | Binder.restoreCallingIdentity(identity); |
| 3997 | } |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 3998 | } |
| 3999 | |
| 4000 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 4001 | public String getManufacturerCodeForSlot(int slotIndex) { |
| 4002 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 4003 | String manufacturerCode = null; |
| 4004 | if (phone != null) { |
| 4005 | String meid = phone.getMeid(); |
Vala Zadeh | ab00555 | 2021-09-21 15:54:29 -0700 | [diff] [blame] | 4006 | try { |
| 4007 | manufacturerCode = |
| 4008 | meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH); |
| 4009 | } catch (IndexOutOfBoundsException e) { |
| 4010 | Log.e(LOG_TAG, "MEID length shorter than upper index."); |
| 4011 | return null; |
| 4012 | } |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 4013 | } |
| 4014 | return manufacturerCode; |
| 4015 | } |
| 4016 | |
| 4017 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4018 | public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage, |
| 4019 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 4020 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 4021 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4022 | return null; |
| 4023 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 4024 | int subId = phone.getSubId(); |
| 4025 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4026 | mApp, subId, callingPackage, callingFeatureId, |
| 4027 | "getDeviceSoftwareVersionForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 4028 | return null; |
| 4029 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4030 | |
| 4031 | final long identity = Binder.clearCallingIdentity(); |
| 4032 | try { |
| 4033 | return phone.getDeviceSvn(); |
| 4034 | } finally { |
| 4035 | Binder.restoreCallingIdentity(identity); |
| 4036 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 4037 | } |
| 4038 | |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 4039 | @Override |
| 4040 | public int getSubscriptionCarrierId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4041 | final long identity = Binder.clearCallingIdentity(); |
| 4042 | try { |
| 4043 | final Phone phone = getPhone(subId); |
| 4044 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId(); |
| 4045 | } finally { |
| 4046 | Binder.restoreCallingIdentity(identity); |
| 4047 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 4048 | } |
| 4049 | |
| 4050 | @Override |
| 4051 | public String getSubscriptionCarrierName(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4052 | final long identity = Binder.clearCallingIdentity(); |
| 4053 | try { |
| 4054 | final Phone phone = getPhone(subId); |
| 4055 | return phone == null ? null : phone.getCarrierName(); |
| 4056 | } finally { |
| 4057 | Binder.restoreCallingIdentity(identity); |
| 4058 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 4059 | } |
| 4060 | |
calvinpan | ffe225e | 2018-11-01 19:43:06 +0800 | [diff] [blame] | 4061 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 4062 | public int getSubscriptionSpecificCarrierId(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 4063 | final long identity = Binder.clearCallingIdentity(); |
| 4064 | try { |
| 4065 | final Phone phone = getPhone(subId); |
| 4066 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 4067 | : phone.getSpecificCarrierId(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 4068 | } finally { |
| 4069 | Binder.restoreCallingIdentity(identity); |
| 4070 | } |
| 4071 | } |
| 4072 | |
| 4073 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 4074 | public String getSubscriptionSpecificCarrierName(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 4075 | final long identity = Binder.clearCallingIdentity(); |
| 4076 | try { |
| 4077 | final Phone phone = getPhone(subId); |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 4078 | return phone == null ? null : phone.getSpecificCarrierName(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 4079 | } finally { |
| 4080 | Binder.restoreCallingIdentity(identity); |
| 4081 | } |
| 4082 | } |
| 4083 | |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 4084 | @Override |
chen xu | 864e11c | 2018-12-06 22:10:03 -0800 | [diff] [blame] | 4085 | public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) { |
| 4086 | if (!isSubscriptionMccMnc) { |
| 4087 | enforceReadPrivilegedPermission("getCarrierIdFromMccMnc"); |
| 4088 | } |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 4089 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 4090 | if (phone == null) { |
| 4091 | return TelephonyManager.UNKNOWN_CARRIER_ID; |
| 4092 | } |
| 4093 | final long identity = Binder.clearCallingIdentity(); |
| 4094 | try { |
| 4095 | return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc); |
| 4096 | } finally { |
| 4097 | Binder.restoreCallingIdentity(identity); |
| 4098 | } |
| 4099 | } |
| 4100 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4101 | // |
| 4102 | // Internal helper methods. |
| 4103 | // |
| 4104 | |
Sanket Padawe | ee13a9b | 2016-03-08 17:30:28 -0800 | [diff] [blame] | 4105 | /** |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 4106 | * Make sure the caller is the calling package itself |
| 4107 | * |
| 4108 | * @throws SecurityException if the caller is not the calling package |
| 4109 | */ |
| 4110 | private void enforceCallingPackage(String callingPackage, int callingUid, String message) { |
| 4111 | int packageUid = -1; |
Grace Jia | dbefca0 | 2021-04-26 15:13:31 -0700 | [diff] [blame] | 4112 | PackageManager pm = mApp.getBaseContext().createContextAsUser( |
| 4113 | UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager(); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 4114 | try { |
Grace Jia | dbefca0 | 2021-04-26 15:13:31 -0700 | [diff] [blame] | 4115 | packageUid = pm.getPackageUid(callingPackage, 0); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 4116 | } catch (PackageManager.NameNotFoundException e) { |
| 4117 | // packageUid is -1 |
| 4118 | } |
| 4119 | if (packageUid != callingUid) { |
| 4120 | throw new SecurityException(message + ": Package " + callingPackage |
| 4121 | + " does not belong to " + callingUid); |
| 4122 | } |
| 4123 | } |
| 4124 | |
| 4125 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4126 | * Make sure the caller has the MODIFY_PHONE_STATE permission. |
| 4127 | * |
| 4128 | * @throws SecurityException if the caller does not have the required permission |
| 4129 | */ |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 4130 | @VisibleForTesting |
| 4131 | public void enforceModifyPermission() { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4132 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null); |
| 4133 | } |
| 4134 | |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 4135 | /** |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 4136 | * Make sure the caller has the READ_PHONE_STATE permission. |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 4137 | * |
| 4138 | * @throws SecurityException if the caller does not have the required permission |
| 4139 | */ |
| 4140 | @VisibleForTesting |
| 4141 | public void enforceReadPermission() { |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 4142 | enforceReadPermission(null); |
| 4143 | } |
| 4144 | |
| 4145 | /** |
| 4146 | * Make sure the caller has the READ_PHONE_STATE permissions. |
| 4147 | * |
| 4148 | * @throws SecurityException if the caller does not have the READ_PHONE_STATE permission. |
| 4149 | */ |
| 4150 | @VisibleForTesting |
| 4151 | public void enforceReadPermission(String msg) { |
| 4152 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, msg); |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 4153 | } |
| 4154 | |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 4155 | private void enforceActiveEmergencySessionPermission() { |
| 4156 | mApp.enforceCallingOrSelfPermission( |
| 4157 | android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null); |
| 4158 | } |
| 4159 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4160 | /** |
| 4161 | * Make sure the caller has the CALL_PHONE permission. |
| 4162 | * |
| 4163 | * @throws SecurityException if the caller does not have the required permission |
| 4164 | */ |
| 4165 | private void enforceCallPermission() { |
| 4166 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null); |
| 4167 | } |
| 4168 | |
paulhu | 5a77360 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 4169 | private void enforceSettingsPermission() { |
| 4170 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 4171 | } |
| 4172 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 4173 | private void enforceRebootPermission() { |
| 4174 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null); |
| 4175 | } |
| 4176 | |
Aishwarya Mallampati | 60fe113 | 2023-01-24 19:07:21 +0000 | [diff] [blame] | 4177 | /** |
| 4178 | * Make sure the caller has SATELLITE_COMMUNICATION permission. |
| 4179 | * @param message - log message to print. |
| 4180 | * @throws SecurityException if the caller does not have the required permission |
| 4181 | */ |
| 4182 | private void enforceSatelliteCommunicationPermission(String message) { |
| 4183 | mApp.enforceCallingOrSelfPermission(permission.SATELLITE_COMMUNICATION, message); |
| 4184 | } |
| 4185 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4186 | private String createTelUrl(String number) { |
| 4187 | if (TextUtils.isEmpty(number)) { |
| 4188 | return null; |
| 4189 | } |
| 4190 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4191 | return "tel:" + number; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4192 | } |
| 4193 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 4194 | private static void log(String msg) { |
Ling Ma | 83dc5ea | 2023-01-12 15:06:04 -0800 | [diff] [blame] | 4195 | Log.d(LOG_TAG, msg); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4196 | } |
| 4197 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 4198 | private static void logv(String msg) { |
| 4199 | Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 4200 | } |
| 4201 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 4202 | private static void loge(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4203 | Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 4204 | } |
| 4205 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4206 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4207 | public int getActivePhoneType() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 4208 | return getActivePhoneTypeForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4209 | } |
| 4210 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4211 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 4212 | public int getActivePhoneTypeForSlot(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4213 | final long identity = Binder.clearCallingIdentity(); |
| 4214 | try { |
| 4215 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 4216 | if (phone == null) { |
| 4217 | return PhoneConstants.PHONE_TYPE_NONE; |
| 4218 | } else { |
| 4219 | return phone.getPhoneType(); |
| 4220 | } |
| 4221 | } finally { |
| 4222 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4223 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4224 | } |
| 4225 | |
| 4226 | /** |
| 4227 | * Returns the CDMA ERI icon index to display |
| 4228 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4229 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4230 | public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) { |
| 4231 | return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage, |
| 4232 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4233 | } |
| 4234 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4235 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4236 | public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage, |
| 4237 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4238 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4239 | mApp, subId, callingPackage, callingFeatureId, |
| 4240 | "getCdmaEriIconIndexForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4241 | return -1; |
| 4242 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4243 | |
| 4244 | final long identity = Binder.clearCallingIdentity(); |
| 4245 | try { |
| 4246 | final Phone phone = getPhone(subId); |
| 4247 | if (phone != null) { |
| 4248 | return phone.getCdmaEriIconIndex(); |
| 4249 | } else { |
| 4250 | return -1; |
| 4251 | } |
| 4252 | } finally { |
| 4253 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4254 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4255 | } |
| 4256 | |
| 4257 | /** |
| 4258 | * Returns the CDMA ERI icon mode, |
| 4259 | * 0 - ON |
| 4260 | * 1 - FLASHING |
| 4261 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4262 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4263 | public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) { |
| 4264 | return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 4265 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4266 | } |
| 4267 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4268 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4269 | public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage, |
| 4270 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4271 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4272 | mApp, subId, callingPackage, callingFeatureId, |
| 4273 | "getCdmaEriIconModeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4274 | return -1; |
| 4275 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4276 | |
| 4277 | final long identity = Binder.clearCallingIdentity(); |
| 4278 | try { |
| 4279 | final Phone phone = getPhone(subId); |
| 4280 | if (phone != null) { |
| 4281 | return phone.getCdmaEriIconMode(); |
| 4282 | } else { |
| 4283 | return -1; |
| 4284 | } |
| 4285 | } finally { |
| 4286 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4287 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4288 | } |
| 4289 | |
| 4290 | /** |
| 4291 | * Returns the CDMA ERI text, |
| 4292 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4293 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4294 | public String getCdmaEriText(String callingPackage, String callingFeatureId) { |
| 4295 | return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage, |
| 4296 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4297 | } |
| 4298 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4299 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4300 | public String getCdmaEriTextForSubscriber(int subId, String callingPackage, |
| 4301 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4302 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4303 | mApp, subId, callingPackage, callingFeatureId, |
| 4304 | "getCdmaEriIconTextForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4305 | return null; |
| 4306 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4307 | |
| 4308 | final long identity = Binder.clearCallingIdentity(); |
| 4309 | try { |
| 4310 | final Phone phone = getPhone(subId); |
| 4311 | if (phone != null) { |
| 4312 | return phone.getCdmaEriText(); |
| 4313 | } else { |
| 4314 | return null; |
| 4315 | } |
| 4316 | } finally { |
| 4317 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4318 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4319 | } |
| 4320 | |
| 4321 | /** |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 4322 | * Returns the CDMA MDN. |
| 4323 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4324 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 4325 | public String getCdmaMdn(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4326 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4327 | mApp, subId, "getCdmaMdn"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4328 | |
| 4329 | final long identity = Binder.clearCallingIdentity(); |
| 4330 | try { |
| 4331 | final Phone phone = getPhone(subId); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4332 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4333 | return phone.getLine1Number(); |
| 4334 | } else { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4335 | loge("getCdmaMdn: no phone found. Invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4336 | return null; |
| 4337 | } |
| 4338 | } finally { |
| 4339 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 4340 | } |
| 4341 | } |
| 4342 | |
| 4343 | /** |
| 4344 | * Returns the CDMA MIN. |
| 4345 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4346 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 4347 | public String getCdmaMin(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4348 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4349 | mApp, subId, "getCdmaMin"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4350 | |
| 4351 | final long identity = Binder.clearCallingIdentity(); |
| 4352 | try { |
| 4353 | final Phone phone = getPhone(subId); |
| 4354 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
| 4355 | return phone.getCdmaMin(); |
| 4356 | } else { |
| 4357 | return null; |
| 4358 | } |
| 4359 | } finally { |
| 4360 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 4361 | } |
| 4362 | } |
| 4363 | |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 4364 | @Override |
| 4365 | public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis, |
| 4366 | INumberVerificationCallback callback, String callingPackage) { |
| 4367 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 4368 | != PERMISSION_GRANTED) { |
| 4369 | throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission"); |
| 4370 | } |
| 4371 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 4372 | |
| 4373 | String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp); |
| 4374 | if (!TextUtils.equals(callingPackage, authorizedPackage)) { |
Hall Liu | b9d8feb | 2021-01-13 10:28:04 -0800 | [diff] [blame] | 4375 | throw new SecurityException("Calling package must be configured in the device config: " |
| 4376 | + "calling package: " + callingPackage |
| 4377 | + ", configured package: " + authorizedPackage); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 4378 | } |
| 4379 | |
| 4380 | if (range == null) { |
| 4381 | throw new NullPointerException("Range must be non-null"); |
| 4382 | } |
| 4383 | |
| 4384 | timeoutMillis = Math.min(timeoutMillis, |
Hall Liu | bd069e3 | 2019-02-28 18:56:30 -0800 | [diff] [blame] | 4385 | TelephonyManager.getMaxNumberVerificationTimeoutMillis()); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 4386 | |
| 4387 | NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis); |
| 4388 | } |
| 4389 | |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 4390 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4391 | * Returns true if CDMA provisioning needs to run. |
| 4392 | */ |
| 4393 | public boolean needsOtaServiceProvisioning() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4394 | final long identity = Binder.clearCallingIdentity(); |
| 4395 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4396 | return getDefaultPhone().needsOtaServiceProvisioning(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4397 | } finally { |
| 4398 | Binder.restoreCallingIdentity(identity); |
| 4399 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4400 | } |
| 4401 | |
| 4402 | /** |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 4403 | * Sets the voice mail number of a given subId. |
| 4404 | */ |
| 4405 | @Override |
| 4406 | public boolean setVoiceMailNumber(int subId, String alphaTag, String number) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 4407 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 4408 | mApp, subId, "setVoiceMailNumber"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4409 | |
| 4410 | final long identity = Binder.clearCallingIdentity(); |
| 4411 | try { |
| 4412 | Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER, |
| 4413 | new Pair<String, String>(alphaTag, number), new Integer(subId)); |
| 4414 | return success; |
| 4415 | } finally { |
| 4416 | Binder.restoreCallingIdentity(identity); |
| 4417 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 4418 | } |
| 4419 | |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 4420 | @Override |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 4421 | public Bundle getVisualVoicemailSettings(String callingPackage, int subId) { |
| 4422 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 4423 | TelecomManager tm = mApp.getSystemService(TelecomManager.class); |
| 4424 | String systemDialer = tm.getSystemDialerPackage(); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 4425 | if (!TextUtils.equals(callingPackage, systemDialer)) { |
| 4426 | throw new SecurityException("caller must be system dialer"); |
| 4427 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4428 | |
| 4429 | final long identity = Binder.clearCallingIdentity(); |
| 4430 | try { |
| 4431 | PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId); |
| 4432 | if (phoneAccountHandle == null) { |
| 4433 | return null; |
| 4434 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4435 | return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4436 | } finally { |
| 4437 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 4438 | } |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 4439 | } |
| 4440 | |
| 4441 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4442 | public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId, |
| 4443 | int subId) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 4444 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4445 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4446 | mApp, subId, callingPackage, callingFeatureId, |
| 4447 | "getVisualVoicemailPackageName")) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 4448 | return null; |
| 4449 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4450 | |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 4451 | final long identity = Binder.clearCallingIdentity(); |
| 4452 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4453 | return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName(); |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 4454 | } finally { |
| 4455 | Binder.restoreCallingIdentity(identity); |
| 4456 | } |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 4457 | } |
| 4458 | |
| 4459 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 4460 | public void enableVisualVoicemailSmsFilter(String callingPackage, int subId, |
| 4461 | VisualVoicemailSmsFilterSettings settings) { |
| 4462 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4463 | |
| 4464 | final long identity = Binder.clearCallingIdentity(); |
| 4465 | try { |
| 4466 | VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4467 | mApp, callingPackage, subId, settings); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4468 | } finally { |
| 4469 | Binder.restoreCallingIdentity(identity); |
| 4470 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 4471 | } |
| 4472 | |
| 4473 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 4474 | public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) { |
| 4475 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4476 | |
| 4477 | final long identity = Binder.clearCallingIdentity(); |
| 4478 | try { |
| 4479 | VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4480 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4481 | } finally { |
| 4482 | Binder.restoreCallingIdentity(identity); |
| 4483 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 4484 | } |
| 4485 | |
| 4486 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 4487 | public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings( |
| 4488 | String callingPackage, int subId) { |
| 4489 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4490 | |
| 4491 | final long identity = Binder.clearCallingIdentity(); |
| 4492 | try { |
| 4493 | return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4494 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4495 | } finally { |
| 4496 | Binder.restoreCallingIdentity(identity); |
| 4497 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 4498 | } |
| 4499 | |
| 4500 | @Override |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 4501 | public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4502 | enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4503 | |
| 4504 | final long identity = Binder.clearCallingIdentity(); |
| 4505 | try { |
| 4506 | return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4507 | mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4508 | } finally { |
| 4509 | Binder.restoreCallingIdentity(identity); |
| 4510 | } |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 4511 | } |
| 4512 | |
| 4513 | @Override |
Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 4514 | public void sendVisualVoicemailSmsForSubscriber(String callingPackage, |
| 4515 | String callingAttributionTag, int subId, String number, int port, String text, |
| 4516 | PendingIntent sentIntent) { |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 4517 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 4518 | enforceVisualVoicemailPackage(callingPackage, subId); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 4519 | enforceSendSmsPermission(); |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 4520 | SmsController smsController = PhoneFactory.getSmsController(); |
Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 4521 | smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag, |
| 4522 | subId, number, port, text, sentIntent); |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 4523 | } |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 4524 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 4525 | /** |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4526 | * Sets the voice activation state of a given subId. |
| 4527 | */ |
| 4528 | @Override |
| 4529 | public void setVoiceActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4530 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4531 | mApp, subId, "setVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4532 | |
| 4533 | final long identity = Binder.clearCallingIdentity(); |
| 4534 | try { |
| 4535 | final Phone phone = getPhone(subId); |
| 4536 | if (phone != null) { |
| 4537 | phone.setVoiceActivationState(activationState); |
| 4538 | } else { |
| 4539 | loge("setVoiceActivationState fails with invalid subId: " + subId); |
| 4540 | } |
| 4541 | } finally { |
| 4542 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4543 | } |
| 4544 | } |
| 4545 | |
| 4546 | /** |
| 4547 | * Sets the data activation state of a given subId. |
| 4548 | */ |
| 4549 | @Override |
| 4550 | public void setDataActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4551 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4552 | mApp, subId, "setDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4553 | |
| 4554 | final long identity = Binder.clearCallingIdentity(); |
| 4555 | try { |
| 4556 | final Phone phone = getPhone(subId); |
| 4557 | if (phone != null) { |
| 4558 | phone.setDataActivationState(activationState); |
| 4559 | } else { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 4560 | loge("setDataActivationState fails with invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4561 | } |
| 4562 | } finally { |
| 4563 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4564 | } |
| 4565 | } |
| 4566 | |
| 4567 | /** |
| 4568 | * Returns the voice activation state of a given subId. |
| 4569 | */ |
| 4570 | @Override |
| 4571 | public int getVoiceActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4572 | enforceReadPrivilegedPermission("getVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4573 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4574 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4575 | final long identity = Binder.clearCallingIdentity(); |
| 4576 | try { |
| 4577 | if (phone != null) { |
| 4578 | return phone.getVoiceActivationState(); |
| 4579 | } else { |
| 4580 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 4581 | } |
| 4582 | } finally { |
| 4583 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4584 | } |
| 4585 | } |
| 4586 | |
| 4587 | /** |
| 4588 | * Returns the data activation state of a given subId. |
| 4589 | */ |
| 4590 | @Override |
| 4591 | public int getDataActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4592 | enforceReadPrivilegedPermission("getDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4593 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4594 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4595 | final long identity = Binder.clearCallingIdentity(); |
| 4596 | try { |
| 4597 | if (phone != null) { |
| 4598 | return phone.getDataActivationState(); |
| 4599 | } else { |
| 4600 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 4601 | } |
| 4602 | } finally { |
| 4603 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4604 | } |
| 4605 | } |
| 4606 | |
| 4607 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4608 | * Returns the unread count of voicemails for a subId |
| 4609 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4610 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4611 | public int getVoiceMessageCountForSubscriber(int subId, String callingPackage, |
| 4612 | String callingFeatureId) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 4613 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4614 | mApp, subId, callingPackage, callingFeatureId, |
| 4615 | "getVoiceMessageCountForSubscriber")) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 4616 | return 0; |
| 4617 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4618 | final long identity = Binder.clearCallingIdentity(); |
| 4619 | try { |
| 4620 | final Phone phone = getPhone(subId); |
| 4621 | if (phone != null) { |
| 4622 | return phone.getVoiceMessageCount(); |
| 4623 | } else { |
| 4624 | return 0; |
| 4625 | } |
| 4626 | } finally { |
| 4627 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4628 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4629 | } |
| 4630 | |
| 4631 | /** |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame^] | 4632 | * returns true, if the device is in a state where both voice and data |
| 4633 | * are supported simultaneously. This can change based on location or network condition. |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 4634 | */ |
| 4635 | @Override |
| 4636 | public boolean isConcurrentVoiceAndDataAllowed(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4637 | final long identity = Binder.clearCallingIdentity(); |
| 4638 | try { |
| 4639 | final Phone phone = getPhone(subId); |
| 4640 | return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed()); |
| 4641 | } finally { |
| 4642 | Binder.restoreCallingIdentity(identity); |
| 4643 | } |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 4644 | } |
| 4645 | |
| 4646 | /** |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4647 | * Send the dialer code if called from the current default dialer or the caller has |
| 4648 | * carrier privilege. |
| 4649 | * @param inputCode The dialer code to send |
| 4650 | */ |
| 4651 | @Override |
| 4652 | public void sendDialerSpecialCode(String callingPackage, String inputCode) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4653 | final Phone defaultPhone = getDefaultPhone(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4654 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 4655 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 4656 | String defaultDialer = tm.getDefaultDialerPackage(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4657 | if (!TextUtils.equals(callingPackage, defaultDialer)) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 4658 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4659 | getDefaultSubscription(), "sendDialerSpecialCode"); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4660 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4661 | |
| 4662 | final long identity = Binder.clearCallingIdentity(); |
| 4663 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4664 | defaultPhone.sendDialerSpecialCode(inputCode); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4665 | } finally { |
| 4666 | Binder.restoreCallingIdentity(identity); |
| 4667 | } |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4668 | } |
| 4669 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 4670 | @Override |
| 4671 | public int getNetworkSelectionMode(int subId) { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 4672 | TelephonyPermissions |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame^] | 4673 | .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4674 | mApp, subId, "getNetworkSelectionMode"); |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 4675 | final long identity = Binder.clearCallingIdentity(); |
| 4676 | try { |
| 4677 | if (!isActiveSubscription(subId)) { |
| 4678 | return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 4679 | } |
| 4680 | return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId); |
| 4681 | } finally { |
| 4682 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 4683 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 4684 | } |
| 4685 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4686 | @Override |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 4687 | public boolean isInEmergencySmsMode() { |
| 4688 | enforceReadPrivilegedPermission("isInEmergencySmsMode"); |
| 4689 | final long identity = Binder.clearCallingIdentity(); |
| 4690 | try { |
| 4691 | for (Phone phone : PhoneFactory.getPhones()) { |
| 4692 | if (phone.isInEmergencySmsMode()) { |
| 4693 | return true; |
| 4694 | } |
| 4695 | } |
| 4696 | } finally { |
| 4697 | Binder.restoreCallingIdentity(identity); |
| 4698 | } |
| 4699 | return false; |
| 4700 | } |
| 4701 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4702 | /** |
| 4703 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4704 | * @param subId The subscription to use to check the configuration. |
| 4705 | * @param c The callback that will be used to send the result. |
| 4706 | */ |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 4707 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4708 | public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c) |
| 4709 | throws RemoteException { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4710 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4711 | mApp, subId, "registerImsRegistrationCallback"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4712 | |
| 4713 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4714 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4715 | "IMS not available on device."); |
| 4716 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4717 | final long token = Binder.clearCallingIdentity(); |
| 4718 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4719 | int slotId = getSlotIndexOrException(subId); |
| 4720 | verifyImsMmTelConfiguredOrThrow(slotId); |
joonhunshin | 49f0aed | 2022-08-05 08:33:05 +0000 | [diff] [blame] | 4721 | |
| 4722 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4723 | if (controller != null) { |
| 4724 | ImsManager imsManager = controller.getImsManager(subId); |
| 4725 | if (imsManager != null) { |
| 4726 | imsManager.addRegistrationCallbackForSubscription(c, subId); |
| 4727 | } else { |
| 4728 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE); |
| 4729 | } |
| 4730 | } else { |
| 4731 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION); |
| 4732 | } |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4733 | } catch (ImsException e) { |
| 4734 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4735 | } finally { |
| 4736 | Binder.restoreCallingIdentity(token); |
| 4737 | } |
| 4738 | } |
| 4739 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4740 | /** |
| 4741 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4742 | * @param subId The subscription to use to check the configuration. |
| 4743 | * @param c The callback that will be used to send the result. |
| 4744 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4745 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4746 | public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4747 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4748 | mApp, subId, "unregisterImsRegistrationCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4749 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4750 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4751 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4752 | final long token = Binder.clearCallingIdentity(); |
joonhunshin | 49f0aed | 2022-08-05 08:33:05 +0000 | [diff] [blame] | 4753 | |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4754 | try { |
joonhunshin | 49f0aed | 2022-08-05 08:33:05 +0000 | [diff] [blame] | 4755 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4756 | if (controller != null) { |
| 4757 | ImsManager imsManager = controller.getImsManager(subId); |
| 4758 | if (imsManager != null) { |
| 4759 | imsManager.removeRegistrationCallbackForSubscription(c, subId); |
| 4760 | } else { |
| 4761 | Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId |
| 4762 | + "is inactive, ignoring unregister."); |
| 4763 | // If the ImsManager is not valid, just return, since the callback |
| 4764 | // will already have been removed internally. |
| 4765 | } |
| 4766 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4767 | } finally { |
| 4768 | Binder.restoreCallingIdentity(token); |
| 4769 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4770 | } |
| 4771 | |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 4772 | /** |
| 4773 | * Get the IMS service registration state for the MmTelFeature associated with this sub id. |
| 4774 | */ |
| 4775 | @Override |
| 4776 | public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) { |
| 4777 | enforceReadPrivilegedPermission("getImsMmTelRegistrationState"); |
| 4778 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4779 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4780 | "IMS not available on device."); |
| 4781 | } |
| 4782 | final long token = Binder.clearCallingIdentity(); |
| 4783 | try { |
| 4784 | Phone phone = getPhone(subId); |
| 4785 | if (phone == null) { |
| 4786 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 4787 | + subId + "'"); |
| 4788 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 4789 | } |
| 4790 | phone.getImsRegistrationState(regState -> { |
| 4791 | try { |
| 4792 | consumer.accept((regState == null) |
| 4793 | ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState); |
| 4794 | } catch (RemoteException e) { |
| 4795 | // Ignore if the remote process is no longer available to call back. |
| 4796 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 4797 | } |
| 4798 | }); |
| 4799 | } finally { |
| 4800 | Binder.restoreCallingIdentity(token); |
| 4801 | } |
| 4802 | } |
| 4803 | |
| 4804 | /** |
| 4805 | * Get the transport type for the IMS service registration state. |
| 4806 | */ |
| 4807 | @Override |
| 4808 | public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4809 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4810 | mApp, subId, "getImsMmTelRegistrationTransportType"); |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 4811 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4812 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4813 | "IMS not available on device."); |
| 4814 | } |
| 4815 | final long token = Binder.clearCallingIdentity(); |
| 4816 | try { |
| 4817 | Phone phone = getPhone(subId); |
| 4818 | if (phone == null) { |
| 4819 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 4820 | + subId + "'"); |
| 4821 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 4822 | } |
| 4823 | phone.getImsRegistrationTech(regTech -> { |
| 4824 | // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager |
| 4825 | int regTechConverted = (regTech == null) |
| 4826 | ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech; |
| 4827 | regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get( |
| 4828 | regTechConverted); |
| 4829 | try { |
| 4830 | consumer.accept(regTechConverted); |
| 4831 | } catch (RemoteException e) { |
| 4832 | // Ignore if the remote process is no longer available to call back. |
| 4833 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 4834 | } |
| 4835 | }); |
| 4836 | } finally { |
| 4837 | Binder.restoreCallingIdentity(token); |
| 4838 | } |
| 4839 | } |
| 4840 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4841 | /** |
| 4842 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4843 | * @param subId The subscription to use to check the configuration. |
| 4844 | * @param c The callback that will be used to send the result. |
| 4845 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4846 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4847 | public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) |
| 4848 | throws RemoteException { |
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, "registerMmTelCapabilityCallback"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4851 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4852 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4853 | "IMS not available on device."); |
| 4854 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4855 | final long token = Binder.clearCallingIdentity(); |
| 4856 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4857 | int slotId = getSlotIndexOrException(subId); |
| 4858 | verifyImsMmTelConfiguredOrThrow(slotId); |
Hwangoo Park | 8646b0d | 2023-01-13 02:42:34 +0000 | [diff] [blame] | 4859 | |
| 4860 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4861 | if (controller != null) { |
| 4862 | ImsManager imsManager = controller.getImsManager(subId); |
| 4863 | if (imsManager != null) { |
| 4864 | imsManager.addCapabilitiesCallbackForSubscription(c, subId); |
| 4865 | } else { |
| 4866 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE); |
| 4867 | } |
| 4868 | } else { |
| 4869 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION); |
| 4870 | } |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4871 | } catch (ImsException e) { |
| 4872 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4873 | } finally { |
| 4874 | Binder.restoreCallingIdentity(token); |
| 4875 | } |
| 4876 | } |
| 4877 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4878 | /** |
| 4879 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4880 | * @param subId The subscription to use to check the configuration. |
| 4881 | * @param c The callback that will be used to send the result. |
| 4882 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4883 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4884 | public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4885 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4886 | mApp, subId, "unregisterMmTelCapabilityCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4887 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4888 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4889 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4890 | |
| 4891 | final long token = Binder.clearCallingIdentity(); |
| 4892 | try { |
Hwangoo Park | 8646b0d | 2023-01-13 02:42:34 +0000 | [diff] [blame] | 4893 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4894 | if (controller != null) { |
| 4895 | ImsManager imsManager = controller.getImsManager(subId); |
| 4896 | if (imsManager != null) { |
| 4897 | imsManager.removeCapabilitiesCallbackForSubscription(c, subId); |
| 4898 | } else { |
| 4899 | Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId |
| 4900 | + " is inactive, ignoring unregister."); |
| 4901 | // If the ImsManager is not valid, just return, since the callback |
| 4902 | // will already have been removed internally. |
| 4903 | } |
| 4904 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4905 | } finally { |
| 4906 | Binder.restoreCallingIdentity(token); |
| 4907 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4908 | } |
| 4909 | |
| 4910 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4911 | public boolean isCapable(int subId, int capability, int regTech) { |
| 4912 | enforceReadPrivilegedPermission("isCapable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4913 | final long token = Binder.clearCallingIdentity(); |
| 4914 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4915 | int slotId = getSlotIndexOrException(subId); |
| 4916 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 4917 | return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech); |
| 4918 | } catch (com.android.ims.ImsException e) { |
| 4919 | Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage()); |
| 4920 | return false; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4921 | } catch (ImsException e) { |
Brad Ebinger | 6b5ac22 | 2019-02-04 14:36:52 -0800 | [diff] [blame] | 4922 | Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false."); |
| 4923 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4924 | } finally { |
| 4925 | Binder.restoreCallingIdentity(token); |
| 4926 | } |
| 4927 | } |
| 4928 | |
| 4929 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4930 | public boolean isAvailable(int subId, int capability, int regTech) { |
| 4931 | enforceReadPrivilegedPermission("isAvailable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4932 | final long token = Binder.clearCallingIdentity(); |
| 4933 | try { |
| 4934 | Phone phone = getPhone(subId); |
| 4935 | if (phone == null) return false; |
| 4936 | return phone.isImsCapabilityAvailable(capability, regTech); |
Daniel Bright | 5e40e4e | 2020-03-11 16:35:39 -0700 | [diff] [blame] | 4937 | } catch (com.android.ims.ImsException e) { |
| 4938 | Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage()); |
| 4939 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4940 | } finally { |
| 4941 | Binder.restoreCallingIdentity(token); |
| 4942 | } |
| 4943 | } |
| 4944 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4945 | /** |
| 4946 | * Determines if the MmTel feature capability is supported by the carrier configuration for this |
| 4947 | * subscription. |
| 4948 | * @param subId The subscription to use to check the configuration. |
| 4949 | * @param callback The callback that will be used to send the result. |
| 4950 | * @param capability The MmTelFeature capability that will be used to send the result. |
| 4951 | * @param transportType The transport type of the MmTelFeature capability. |
| 4952 | */ |
| 4953 | @Override |
| 4954 | public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability, |
| 4955 | int transportType) { |
| 4956 | enforceReadPrivilegedPermission("isMmTelCapabilitySupported"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4957 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4958 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4959 | "IMS not available on device."); |
| 4960 | } |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4961 | final long token = Binder.clearCallingIdentity(); |
| 4962 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4963 | int slotId = getSlotIndex(subId); |
| 4964 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4965 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '" |
| 4966 | + subId + "'"); |
| 4967 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 4968 | } |
| 4969 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 4970 | ImsManager.getInstance(mApp, slotId).isSupported(capability, |
| 4971 | transportType, aBoolean -> { |
| 4972 | try { |
| 4973 | callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0)); |
| 4974 | } catch (RemoteException e) { |
| 4975 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not " |
| 4976 | + "running. Ignore"); |
| 4977 | } |
| 4978 | }); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4979 | } catch (ImsException e) { |
| 4980 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4981 | } finally { |
| 4982 | Binder.restoreCallingIdentity(token); |
| 4983 | } |
| 4984 | } |
| 4985 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4986 | /** |
| 4987 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4988 | * @param subId The subscription to use to check the configuration. |
| 4989 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4990 | @Override |
| 4991 | public boolean isAdvancedCallingSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4992 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4993 | mApp, subId, "isAdvancedCallingSettingEnabled"); |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4994 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4995 | final long token = Binder.clearCallingIdentity(); |
| 4996 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4997 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4998 | // 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] | 4999 | return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5000 | } catch (ImsException e) { |
| 5001 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5002 | } finally { |
| 5003 | Binder.restoreCallingIdentity(token); |
| 5004 | } |
| 5005 | } |
| 5006 | |
| 5007 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 5008 | public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5009 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 5010 | "setAdvancedCallingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5011 | final long identity = Binder.clearCallingIdentity(); |
| 5012 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5013 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5014 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 5015 | // 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] | 5016 | ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5017 | } catch (ImsException e) { |
| 5018 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5019 | } finally { |
| 5020 | Binder.restoreCallingIdentity(identity); |
| 5021 | } |
| 5022 | } |
| 5023 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 5024 | /** |
| 5025 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 5026 | * @param subId The subscription to use to check the configuration. |
| 5027 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5028 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 5029 | public boolean isVtSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 5030 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 5031 | mApp, subId, "isVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5032 | final long identity = Binder.clearCallingIdentity(); |
| 5033 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5034 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5035 | // 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] | 5036 | return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5037 | } catch (ImsException e) { |
| 5038 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5039 | } finally { |
| 5040 | Binder.restoreCallingIdentity(identity); |
| 5041 | } |
| 5042 | } |
| 5043 | |
| 5044 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 5045 | public void setVtSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5046 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 5047 | "setVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5048 | final long identity = Binder.clearCallingIdentity(); |
| 5049 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5050 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5051 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 5052 | // 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] | 5053 | ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5054 | } catch (ImsException e) { |
| 5055 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5056 | } finally { |
| 5057 | Binder.restoreCallingIdentity(identity); |
| 5058 | } |
| 5059 | } |
| 5060 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 5061 | /** |
| 5062 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 5063 | * @param subId The subscription to use to check the configuration. |
| 5064 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5065 | @Override |
| 5066 | public boolean isVoWiFiSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 5067 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 5068 | mApp, subId, "isVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5069 | final long identity = Binder.clearCallingIdentity(); |
| 5070 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5071 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5072 | // 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] | 5073 | return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5074 | } catch (ImsException e) { |
| 5075 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5076 | } finally { |
| 5077 | Binder.restoreCallingIdentity(identity); |
| 5078 | } |
| 5079 | } |
| 5080 | |
| 5081 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 5082 | public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5083 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 5084 | "setVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5085 | final long identity = Binder.clearCallingIdentity(); |
| 5086 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5087 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5088 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 5089 | // 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] | 5090 | ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5091 | } catch (ImsException e) { |
| 5092 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5093 | } finally { |
| 5094 | Binder.restoreCallingIdentity(identity); |
| 5095 | } |
| 5096 | } |
| 5097 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 5098 | /** |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 5099 | * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not |
| 5100 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 5101 | * @param subId The subscription to use to check the configuration. |
| 5102 | */ |
| 5103 | @Override |
| 5104 | public boolean isCrossSimCallingEnabledByUser(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 5105 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 5106 | mApp, subId, "isCrossSimCallingEnabledByUser"); |
| 5107 | final long identity = Binder.clearCallingIdentity(); |
| 5108 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5109 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5110 | // 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] | 5111 | return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser(); |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 5112 | } catch (ImsException e) { |
| 5113 | throw new ServiceSpecificException(e.getCode()); |
| 5114 | } finally { |
| 5115 | Binder.restoreCallingIdentity(identity); |
| 5116 | } |
| 5117 | } |
| 5118 | |
| 5119 | /** |
| 5120 | * Sets the user's setting for whether or not Voice over Cross SIM is enabled. |
| 5121 | * Requires MODIFY_PHONE_STATE permission. |
| 5122 | * @param subId The subscription to use to check the configuration. |
| 5123 | * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled, |
| 5124 | * false otherwise |
| 5125 | */ |
| 5126 | @Override |
| 5127 | public void setCrossSimCallingEnabled(int subId, boolean isEnabled) { |
| 5128 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5129 | "setCrossSimCallingEnabled"); |
| 5130 | final long identity = Binder.clearCallingIdentity(); |
| 5131 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5132 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5133 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 5134 | // 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] | 5135 | ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled); |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 5136 | } catch (ImsException e) { |
| 5137 | throw new ServiceSpecificException(e.getCode()); |
| 5138 | } finally { |
| 5139 | Binder.restoreCallingIdentity(identity); |
| 5140 | } |
| 5141 | } |
| 5142 | |
| 5143 | /** |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 5144 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 5145 | * @param subId The subscription to use to check the configuration. |
| 5146 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5147 | @Override |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 5148 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5149 | public boolean isVoWiFiRoamingSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 5150 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 5151 | mApp, subId, "isVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5152 | final long identity = Binder.clearCallingIdentity(); |
| 5153 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5154 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5155 | // 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] | 5156 | return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5157 | } catch (ImsException e) { |
| 5158 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5159 | } finally { |
| 5160 | Binder.restoreCallingIdentity(identity); |
| 5161 | } |
| 5162 | } |
| 5163 | |
| 5164 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 5165 | public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5166 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 5167 | "setVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5168 | final long identity = Binder.clearCallingIdentity(); |
| 5169 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5170 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5171 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 5172 | // 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] | 5173 | ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5174 | } catch (ImsException e) { |
| 5175 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5176 | } finally { |
| 5177 | Binder.restoreCallingIdentity(identity); |
| 5178 | } |
| 5179 | } |
| 5180 | |
| 5181 | @Override |
| 5182 | public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) { |
| 5183 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5184 | "setVoWiFiNonPersistent"); |
| 5185 | final long identity = Binder.clearCallingIdentity(); |
| 5186 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5187 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5188 | // This setting will be ignored if the ImsService isn't up. |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5189 | ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5190 | } catch (ImsException e) { |
| 5191 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5192 | } finally { |
| 5193 | Binder.restoreCallingIdentity(identity); |
| 5194 | } |
| 5195 | } |
| 5196 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 5197 | /** |
| 5198 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 5199 | * @param subId The subscription to use to check the configuration. |
| 5200 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5201 | @Override |
| 5202 | public int getVoWiFiModeSetting(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 5203 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 5204 | mApp, subId, "getVoWiFiModeSetting"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5205 | final long identity = Binder.clearCallingIdentity(); |
| 5206 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5207 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5208 | // 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] | 5209 | return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5210 | } catch (ImsException e) { |
| 5211 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5212 | } finally { |
| 5213 | Binder.restoreCallingIdentity(identity); |
| 5214 | } |
| 5215 | } |
| 5216 | |
| 5217 | @Override |
| 5218 | public void setVoWiFiModeSetting(int subId, int mode) { |
| 5219 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5220 | "setVoWiFiModeSetting"); |
| 5221 | final long identity = Binder.clearCallingIdentity(); |
| 5222 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5223 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5224 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 5225 | // 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] | 5226 | ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5227 | } catch (ImsException e) { |
| 5228 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5229 | } finally { |
| 5230 | Binder.restoreCallingIdentity(identity); |
| 5231 | } |
| 5232 | } |
| 5233 | |
| 5234 | @Override |
| 5235 | public int getVoWiFiRoamingModeSetting(int subId) { |
| 5236 | enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting"); |
| 5237 | final long identity = Binder.clearCallingIdentity(); |
| 5238 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5239 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5240 | // 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] | 5241 | return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5242 | } catch (ImsException e) { |
| 5243 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5244 | } finally { |
| 5245 | Binder.restoreCallingIdentity(identity); |
| 5246 | } |
| 5247 | } |
| 5248 | |
| 5249 | @Override |
| 5250 | public void setVoWiFiRoamingModeSetting(int subId, int mode) { |
| 5251 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5252 | "setVoWiFiRoamingModeSetting"); |
| 5253 | final long identity = Binder.clearCallingIdentity(); |
| 5254 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5255 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5256 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 5257 | // 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] | 5258 | ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5259 | } catch (ImsException e) { |
| 5260 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5261 | } finally { |
| 5262 | Binder.restoreCallingIdentity(identity); |
| 5263 | } |
| 5264 | } |
| 5265 | |
| 5266 | @Override |
| 5267 | public void setRttCapabilitySetting(int subId, boolean isEnabled) { |
| 5268 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5269 | "setRttCapabilityEnabled"); |
| 5270 | final long identity = Binder.clearCallingIdentity(); |
| 5271 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5272 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5273 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 5274 | // 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] | 5275 | ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5276 | } catch (ImsException e) { |
| 5277 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5278 | } finally { |
| 5279 | Binder.restoreCallingIdentity(identity); |
| 5280 | } |
| 5281 | } |
| 5282 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 5283 | /** |
| 5284 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 5285 | * @param subId The subscription to use to check the configuration. |
| 5286 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5287 | @Override |
| 5288 | public boolean isTtyOverVolteEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 5289 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 5290 | mApp, subId, "isTtyOverVolteEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5291 | final long identity = Binder.clearCallingIdentity(); |
| 5292 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5293 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5294 | // 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] | 5295 | return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5296 | } catch (ImsException e) { |
| 5297 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5298 | } finally { |
| 5299 | Binder.restoreCallingIdentity(identity); |
| 5300 | } |
| 5301 | } |
| 5302 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5303 | @Override |
| 5304 | public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 5305 | enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5306 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5307 | final long identity = Binder.clearCallingIdentity(); |
| 5308 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 5309 | if (!isImsAvailableOnDevice()) { |
| 5310 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 5311 | "IMS not available on device."); |
| 5312 | } |
| 5313 | int slotId = getSlotIndexOrException(subId); |
| 5314 | verifyImsMmTelConfiguredOrThrow(slotId); |
Hwangoo Park | 8646b0d | 2023-01-13 02:42:34 +0000 | [diff] [blame] | 5315 | |
| 5316 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 5317 | if (controller != null) { |
| 5318 | ImsManager imsManager = controller.getImsManager(subId); |
| 5319 | if (imsManager != null) { |
| 5320 | imsManager.addProvisioningCallbackForSubscription(callback, subId); |
| 5321 | } else { |
| 5322 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE); |
| 5323 | } |
| 5324 | } else { |
| 5325 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION); |
| 5326 | } |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5327 | } catch (ImsException e) { |
| 5328 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5329 | } finally { |
| 5330 | Binder.restoreCallingIdentity(identity); |
| 5331 | } |
| 5332 | } |
| 5333 | |
| 5334 | @Override |
| 5335 | public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 5336 | enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5337 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5338 | final long identity = Binder.clearCallingIdentity(); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 5339 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5340 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 5341 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5342 | try { |
Hwangoo Park | 8646b0d | 2023-01-13 02:42:34 +0000 | [diff] [blame] | 5343 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 5344 | if (controller != null) { |
| 5345 | ImsManager imsManager = controller.getImsManager(subId); |
| 5346 | if (imsManager != null) { |
| 5347 | imsManager.removeProvisioningCallbackForSubscription(callback, subId); |
| 5348 | } else { |
| 5349 | Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId |
| 5350 | + " is inactive, ignoring unregister."); |
| 5351 | // If the ImsManager is not valid, just return, since the callback will already |
| 5352 | // have been removed internally. |
| 5353 | } |
| 5354 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5355 | } finally { |
| 5356 | Binder.restoreCallingIdentity(identity); |
| 5357 | } |
| 5358 | } |
| 5359 | |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5360 | @Override |
| 5361 | public void registerFeatureProvisioningChangedCallback(int subId, |
| 5362 | IFeatureProvisioningCallback callback) { |
| 5363 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5364 | mApp, subId, "registerFeatureProvisioningChangedCallback"); |
| 5365 | |
| 5366 | final long identity = Binder.clearCallingIdentity(); |
| 5367 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5368 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 5369 | } |
| 5370 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5371 | try { |
| 5372 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5373 | if (controller == null) { |
| 5374 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 5375 | "Device does not support IMS"); |
| 5376 | } |
| 5377 | controller.addFeatureProvisioningChangedCallback(subId, callback); |
| 5378 | } finally { |
| 5379 | Binder.restoreCallingIdentity(identity); |
| 5380 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5381 | } |
| 5382 | |
| 5383 | @Override |
| 5384 | public void unregisterFeatureProvisioningChangedCallback(int subId, |
| 5385 | IFeatureProvisioningCallback callback) { |
| 5386 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5387 | mApp, subId, "unregisterFeatureProvisioningChangedCallback"); |
| 5388 | |
| 5389 | final long identity = Binder.clearCallingIdentity(); |
| 5390 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5391 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 5392 | } |
| 5393 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5394 | try { |
| 5395 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5396 | if (controller == null) { |
| 5397 | loge("unregisterFeatureProvisioningChangedCallback: Device does not support IMS"); |
| 5398 | return; |
| 5399 | } |
| 5400 | controller.removeFeatureProvisioningChangedCallback(subId, callback); |
| 5401 | } finally { |
| 5402 | Binder.restoreCallingIdentity(identity); |
| 5403 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5404 | } |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5405 | |
| 5406 | private void checkModifyPhoneStatePermission(int subId, String message) { |
| 5407 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5408 | message); |
| 5409 | } |
| 5410 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5411 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5412 | public void setRcsProvisioningStatusForCapability(int subId, int capability, int tech, |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5413 | boolean isProvisioned) { |
| 5414 | checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability"); |
| 5415 | |
| 5416 | final long identity = Binder.clearCallingIdentity(); |
| 5417 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5418 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5419 | if (controller == null) { |
| 5420 | loge("setRcsProvisioningStatusForCapability: Device does not support IMS"); |
| 5421 | return; |
| 5422 | } |
| 5423 | controller.setRcsProvisioningStatusForCapability( |
| 5424 | subId, capability, tech, isProvisioned); |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5425 | } finally { |
| 5426 | Binder.restoreCallingIdentity(identity); |
| 5427 | } |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5428 | } |
| 5429 | |
| 5430 | |
| 5431 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5432 | public boolean getRcsProvisioningStatusForCapability(int subId, int capability, int tech) { |
| 5433 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5434 | mApp, subId, "getRcsProvisioningStatusForCapability"); |
| 5435 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5436 | final long identity = Binder.clearCallingIdentity(); |
| 5437 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5438 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5439 | if (controller == null) { |
| 5440 | loge("getRcsProvisioningStatusForCapability: Device does not support IMS"); |
| 5441 | |
| 5442 | // device does not support IMS, this method will return true always. |
| 5443 | return true; |
| 5444 | } |
| 5445 | return controller.getRcsProvisioningStatusForCapability(subId, capability, tech); |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5446 | } finally { |
| 5447 | Binder.restoreCallingIdentity(identity); |
| 5448 | } |
| 5449 | } |
| 5450 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5451 | @Override |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5452 | public void setImsProvisioningStatusForCapability(int subId, int capability, int tech, |
| 5453 | boolean isProvisioned) { |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5454 | checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5455 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 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("setImsProvisioningStatusForCapability: Device does not support IMS"); |
| 5461 | return; |
| 5462 | } |
| 5463 | controller.setImsProvisioningStatusForCapability( |
| 5464 | subId, capability, tech, isProvisioned); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5465 | } finally { |
| 5466 | Binder.restoreCallingIdentity(identity); |
| 5467 | } |
| 5468 | } |
| 5469 | |
| 5470 | @Override |
| 5471 | public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) { |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5472 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5473 | mApp, subId, "getProvisioningStatusForCapability"); |
| 5474 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5475 | final long identity = Binder.clearCallingIdentity(); |
| 5476 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5477 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5478 | if (controller == null) { |
| 5479 | loge("getImsProvisioningStatusForCapability: Device does not support IMS"); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5480 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5481 | // device does not support IMS, this method will return true always. |
| 5482 | return true; |
| 5483 | } |
| 5484 | return controller.getImsProvisioningStatusForCapability(subId, capability, tech); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5485 | } finally { |
| 5486 | Binder.restoreCallingIdentity(identity); |
| 5487 | } |
| 5488 | } |
| 5489 | |
| 5490 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5491 | public boolean isProvisioningRequiredForCapability(int subId, int capability, int tech) { |
| 5492 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5493 | mApp, subId, "isProvisioningRequiredForCapability"); |
| 5494 | |
| 5495 | final long identity = Binder.clearCallingIdentity(); |
| 5496 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5497 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5498 | if (controller == null) { |
| 5499 | loge("isProvisioningRequiredForCapability: Device does not support IMS"); |
| 5500 | |
| 5501 | // device does not support IMS, this method will return false |
| 5502 | return false; |
| 5503 | } |
| 5504 | return controller.isImsProvisioningRequiredForCapability(subId, capability, tech); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5505 | } finally { |
| 5506 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5507 | } |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5508 | } |
| 5509 | |
| 5510 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5511 | public boolean isRcsProvisioningRequiredForCapability(int subId, int capability, int tech) { |
| 5512 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5513 | mApp, subId, "isProvisioningRequiredForCapability"); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5514 | |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [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("isRcsProvisioningRequiredForCapability: Device does not support IMS"); |
| 5520 | |
| 5521 | // device does not support IMS, this method will return false |
| 5522 | return false; |
| 5523 | } |
| 5524 | return controller.isRcsProvisioningRequiredForCapability(subId, capability, tech); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5525 | } finally { |
| 5526 | Binder.restoreCallingIdentity(identity); |
| 5527 | } |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5528 | } |
| 5529 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5530 | @Override |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5531 | public int getImsProvisioningInt(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5532 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5533 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 5534 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5535 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5536 | mApp, subId, "getImsProvisioningInt"); |
| 5537 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5538 | final long identity = Binder.clearCallingIdentity(); |
| 5539 | try { |
| 5540 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5541 | int slotId = getSlotIndex(subId); |
| 5542 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5543 | Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '" |
| 5544 | + subId + "' for key:" + key); |
| 5545 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
| 5546 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5547 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5548 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5549 | if (controller == null) { |
| 5550 | loge("getImsProvisioningInt: Device does not support IMS"); |
| 5551 | |
| 5552 | // device does not support IMS, this method will return CONFIG_RESULT_UNKNOWN. |
| 5553 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
| 5554 | } |
| 5555 | int retVal = controller.getProvisioningValue(subId, key); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5556 | if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) { |
| 5557 | return retVal; |
| 5558 | } |
| 5559 | |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5560 | return ImsManager.getInstance(mApp, slotId).getConfigInt(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5561 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5562 | Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '" |
| 5563 | + subId + "' for key:" + key); |
| 5564 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5565 | } finally { |
| 5566 | Binder.restoreCallingIdentity(identity); |
| 5567 | } |
| 5568 | } |
| 5569 | |
| 5570 | @Override |
| 5571 | public String getImsProvisioningString(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, "getImsProvisioningString"); |
| 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, "getImsProvisioningString: called for an inactive subscription id '" |
| 5584 | + subId + "' for key:" + key); |
| 5585 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC; |
| 5586 | } |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5587 | return ImsManager.getInstance(mApp, slotId).getConfigString(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5588 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5589 | Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '" |
| 5590 | + subId + "' for key:" + key); |
| 5591 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5592 | } finally { |
| 5593 | Binder.restoreCallingIdentity(identity); |
| 5594 | } |
| 5595 | } |
| 5596 | |
| 5597 | @Override |
| 5598 | public int setImsProvisioningInt(int subId, int key, int value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5599 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5600 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 5601 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 5602 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5603 | "setImsProvisioningInt"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5604 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5605 | final long identity = Binder.clearCallingIdentity(); |
| 5606 | try { |
| 5607 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5608 | int slotId = getSlotIndex(subId); |
| 5609 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5610 | Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '" |
| 5611 | + subId + "' for key:" + key); |
| 5612 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 5613 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5614 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5615 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5616 | if (controller == null) { |
| 5617 | loge("setImsProvisioningInt: Device does not support IMS"); |
| 5618 | |
| 5619 | // device does not support IMS, this method will return CONFIG_RESULT_FAILED. |
| 5620 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 5621 | } |
| 5622 | int retVal = controller.setProvisioningValue(subId, key, value); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5623 | if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) { |
| 5624 | return retVal; |
| 5625 | } |
| 5626 | |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5627 | return ImsManager.getInstance(mApp, slotId).setConfig(key, value); |
| 5628 | } catch (com.android.ims.ImsException | RemoteException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5629 | Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5630 | + "' for key:" + key, e); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5631 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
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 setImsProvisioningString(int subId, int key, String 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 | "setImsProvisioningString"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5644 | final long identity = Binder.clearCallingIdentity(); |
| 5645 | try { |
| 5646 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5647 | int slotId = getSlotIndex(subId); |
| 5648 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5649 | Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '" |
| 5650 | + subId + "' for key:" + key); |
| 5651 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 5652 | } |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5653 | return ImsManager.getInstance(mApp, slotId).setConfig(key, value); |
| 5654 | } catch (com.android.ims.ImsException | RemoteException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5655 | Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5656 | + "' for key:" + key, e); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5657 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5658 | } finally { |
| 5659 | Binder.restoreCallingIdentity(identity); |
| 5660 | } |
| 5661 | } |
| 5662 | |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5663 | /** |
| 5664 | * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL |
| 5665 | * for the given slot ID or no ImsResolver instance has been created. |
| 5666 | * @param slotId The slot ID that the IMS service is created for. |
| 5667 | * @throws ImsException If there is no ImsService configured for this slot. |
| 5668 | */ |
| 5669 | private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException { |
| 5670 | if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId, |
| 5671 | ImsFeature.FEATURE_MMTEL)) { |
| 5672 | throw new ImsException("This subscription does not support MMTEL over IMS", |
| 5673 | ImsException.CODE_ERROR_UNSUPPORTED_OPERATION); |
| 5674 | } |
| 5675 | } |
| 5676 | |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5677 | private int getSlotIndexOrException(int subId) throws ImsException { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5678 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 5679 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5680 | throw new ImsException("Invalid Subscription Id, subId=" + subId, |
| 5681 | ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5682 | } |
| 5683 | return slotId; |
| 5684 | } |
| 5685 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5686 | private int getSlotIndex(int subId) { |
| 5687 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 5688 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
| 5689 | return SubscriptionManager.INVALID_SIM_SLOT_INDEX; |
| 5690 | } |
| 5691 | return slotId; |
| 5692 | } |
| 5693 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5694 | /** |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 5695 | * Returns the data network type for a subId; does not throw SecurityException. |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5696 | */ |
| 5697 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5698 | public int getNetworkTypeForSubscriber(int subId, String callingPackage, |
| 5699 | String callingFeatureId) { |
Shuo Qian | 13d8915 | 2021-05-10 23:58:11 -0700 | [diff] [blame] | 5700 | try { |
| 5701 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 5702 | } catch (SecurityException se) { |
| 5703 | EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid()); |
| 5704 | throw new SecurityException("Package " + callingPackage + " does not belong to " |
| 5705 | + Binder.getCallingUid()); |
| 5706 | } |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 5707 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 5708 | if (targetSdk > android.os.Build.VERSION_CODES.Q) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5709 | return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 5710 | } else if (targetSdk == android.os.Build.VERSION_CODES.Q |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 5711 | && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame^] | 5712 | mApp, subId, callingPackage, callingFeatureId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5713 | "getNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5714 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5715 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 5716 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5717 | final long identity = Binder.clearCallingIdentity(); |
| 5718 | try { |
| 5719 | final Phone phone = getPhone(subId); |
| 5720 | if (phone != null) { |
| 5721 | return phone.getServiceState().getDataNetworkType(); |
| 5722 | } else { |
| 5723 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5724 | } |
| 5725 | } finally { |
| 5726 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5727 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5728 | } |
| 5729 | |
| 5730 | /** |
| 5731 | * Returns the data network type |
| 5732 | */ |
| 5733 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5734 | public int getDataNetworkType(String callingPackage, String callingFeatureId) { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5735 | return getDataNetworkTypeForSubscriber(SubscriptionManager.getDefaultDataSubscriptionId(), |
Zoey Chen | fd61f7f | 2021-04-21 13:42:10 +0800 | [diff] [blame] | 5736 | callingPackage, callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5737 | } |
| 5738 | |
| 5739 | /** |
| 5740 | * Returns the data network type for a subId |
| 5741 | */ |
| 5742 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5743 | public int getDataNetworkTypeForSubscriber(int subId, String callingPackage, |
| 5744 | String callingFeatureId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 5745 | String functionName = "getDataNetworkTypeForSubscriber"; |
| 5746 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 5747 | mApp, functionName)) { |
| 5748 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 5749 | mApp, subId, callingPackage, callingFeatureId, functionName)) { |
| 5750 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5751 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5752 | } |
| 5753 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5754 | final long identity = Binder.clearCallingIdentity(); |
| 5755 | try { |
| 5756 | final Phone phone = getPhone(subId); |
| 5757 | if (phone != null) { |
| 5758 | return phone.getServiceState().getDataNetworkType(); |
| 5759 | } else { |
| 5760 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5761 | } |
| 5762 | } finally { |
| 5763 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5764 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5765 | } |
| 5766 | |
| 5767 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5768 | * Returns the Voice network type for a subId |
| 5769 | */ |
| 5770 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5771 | public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage, |
| 5772 | String callingFeatureId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 5773 | String functionName = "getVoiceNetworkTypeForSubscriber"; |
| 5774 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 5775 | mApp, functionName)) { |
| 5776 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 5777 | mApp, subId, callingPackage, callingFeatureId, functionName)) { |
| 5778 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5779 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 5780 | } |
| 5781 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5782 | final long identity = Binder.clearCallingIdentity(); |
| 5783 | try { |
| 5784 | final Phone phone = getPhone(subId); |
| 5785 | if (phone != null) { |
| 5786 | return phone.getServiceState().getVoiceNetworkType(); |
| 5787 | } else { |
| 5788 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5789 | } |
| 5790 | } finally { |
| 5791 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5792 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5793 | } |
| 5794 | |
| 5795 | /** |
| 5796 | * @return true if a ICC card is present |
| 5797 | */ |
| 5798 | public boolean hasIccCard() { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5799 | // FIXME Make changes to pass defaultSimId of type int |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5800 | return hasIccCardUsingSlotIndex(SubscriptionManager.getSlotIndex( |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5801 | getDefaultSubscription())); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5802 | } |
| 5803 | |
| 5804 | /** |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5805 | * @return true if a ICC card is present for a slotIndex |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5806 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5807 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5808 | public boolean hasIccCardUsingSlotIndex(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5809 | final long identity = Binder.clearCallingIdentity(); |
| 5810 | try { |
| 5811 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5812 | if (phone != null) { |
| 5813 | return phone.getIccCard().hasIccCard(); |
| 5814 | } else { |
| 5815 | return false; |
| 5816 | } |
| 5817 | } finally { |
| 5818 | Binder.restoreCallingIdentity(identity); |
Amit Mahajan | a6fc2a8 | 2015-01-06 11:53:51 -0800 | [diff] [blame] | 5819 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5820 | } |
| 5821 | |
| 5822 | /** |
| 5823 | * Return if the current radio is LTE on CDMA. This |
| 5824 | * is a tri-state return value as for a period of time |
| 5825 | * the mode may be unknown. |
| 5826 | * |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5827 | * @param callingPackage the name of the package making the call. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5828 | * @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] | 5829 | * or {@link Phone#LTE_ON_CDMA_TRUE} |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5830 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5831 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5832 | public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) { |
| 5833 | return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 5834 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5835 | } |
| 5836 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5837 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5838 | public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage, |
| 5839 | String callingFeatureId) { |
Sarah Chin | 790d292 | 2020-01-16 12:17:23 -0800 | [diff] [blame] | 5840 | try { |
| 5841 | enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber"); |
| 5842 | } catch (SecurityException e) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5843 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 5844 | } |
| 5845 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5846 | final long identity = Binder.clearCallingIdentity(); |
| 5847 | try { |
| 5848 | final Phone phone = getPhone(subId); |
| 5849 | if (phone == null) { |
| 5850 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 5851 | } else { |
Nathan Harold | 05ad633 | 2020-07-10 11:54:36 -0700 | [diff] [blame] | 5852 | return TelephonyProperties.lte_on_cdma_device() |
| 5853 | .orElse(PhoneConstants.LTE_ON_CDMA_FALSE); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5854 | } |
| 5855 | } finally { |
| 5856 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5857 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5858 | } |
| 5859 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5860 | /** |
| 5861 | * {@hide} |
| 5862 | * Returns Default subId, 0 in the case of single standby. |
| 5863 | */ |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 5864 | private int getDefaultSubscription() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5865 | return SubscriptionManager.getDefaultSubscriptionId(); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5866 | } |
| 5867 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 5868 | private int getSlotForDefaultSubscription() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5869 | return SubscriptionManager.getPhoneId(getDefaultSubscription()); |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 5870 | } |
| 5871 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 5872 | private int getPreferredVoiceSubscription() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5873 | return SubscriptionManager.getDefaultVoiceSubscriptionId(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5874 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5875 | |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 5876 | private boolean isActiveSubscription(int subId) { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5877 | if (PhoneFactory.isSubscriptionManagerServiceEnabled()) { |
| 5878 | return SubscriptionManagerService.getInstance().isActiveSubId(subId, |
| 5879 | mApp.getOpPackageName(), mApp.getFeatureId()); |
| 5880 | } |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 5881 | return mSubscriptionController.isActiveSubId(subId); |
| 5882 | } |
| 5883 | |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5884 | /** |
| 5885 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 5886 | */ |
| 5887 | public int getWhenToMakeWifiCalls() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5888 | final long identity = Binder.clearCallingIdentity(); |
| 5889 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5890 | return Settings.System.getInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5891 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, |
| 5892 | getWhenToMakeWifiCallsDefaultPreference()); |
| 5893 | } finally { |
| 5894 | Binder.restoreCallingIdentity(identity); |
| 5895 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5896 | } |
| 5897 | |
| 5898 | /** |
| 5899 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 5900 | */ |
| 5901 | public void setWhenToMakeWifiCalls(int preference) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5902 | final long identity = Binder.clearCallingIdentity(); |
| 5903 | try { |
| 5904 | if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5905 | Settings.System.putInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5906 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference); |
| 5907 | } finally { |
| 5908 | Binder.restoreCallingIdentity(identity); |
| 5909 | } |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 5910 | } |
| 5911 | |
Sailesh Nepal | d1e6815 | 2013-12-12 19:08:02 -0800 | [diff] [blame] | 5912 | private static int getWhenToMakeWifiCallsDefaultPreference() { |
Santos Cordon | da120f4 | 2014-08-06 04:44:34 -0700 | [diff] [blame] | 5913 | // TODO: Use a build property to choose this value. |
Evan Charlton | 9829e88 | 2013-12-19 15:30:38 -0800 | [diff] [blame] | 5914 | return TelephonyManager.WifiCallingChoices.ALWAYS_USE; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5915 | } |
Shishir Agrawal | 69f6812 | 2013-12-16 17:25:49 -0800 | [diff] [blame] | 5916 | |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5917 | private Phone getPhoneFromSlotPortIndexOrThrowException(int slotIndex, int portIndex) { |
| 5918 | int phoneId = UiccController.getInstance().getPhoneIdFromSlotPortIndex(slotIndex, |
| 5919 | portIndex); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5920 | if (phoneId == -1) { |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5921 | throw new IllegalArgumentException("Given slot index: " + slotIndex + " port index: " |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame^] | 5922 | + portIndex + " does not correspond to an active phone"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5923 | } |
| 5924 | return PhoneFactory.getPhone(phoneId); |
| 5925 | } |
| 5926 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5927 | @Override |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 5928 | public IccOpenLogicalChannelResponse iccOpenLogicalChannel( |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5929 | @NonNull IccLogicalChannelRequest request) { |
| 5930 | Phone phone = getPhoneFromValidIccLogicalChannelRequest(request, |
| 5931 | /*message=*/ "iccOpenLogicalChannel"); |
| 5932 | |
| 5933 | if (DBG) log("iccOpenLogicalChannel: request=" + request); |
| 5934 | // Verify that the callingPackage in the request belongs to the calling UID |
| 5935 | mAppOps.checkPackage(Binder.getCallingUid(), request.callingPackage); |
| 5936 | |
| 5937 | return iccOpenLogicalChannelWithPermission(phone, request); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5938 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5939 | |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5940 | private Phone getPhoneFromValidIccLogicalChannelRequest( |
| 5941 | @NonNull IccLogicalChannelRequest request, String message) { |
| 5942 | Phone phone; |
| 5943 | if (request.subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) { |
| 5944 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5945 | mApp, request.subId, message); |
| 5946 | phone = getPhoneFromSubId(request.subId); |
| 5947 | } else if (request.slotIndex != SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5948 | enforceModifyPermission(); |
| 5949 | phone = getPhoneFromSlotPortIndexOrThrowException(request.slotIndex, request.portIndex); |
| 5950 | } else { |
| 5951 | throw new IllegalArgumentException("Both subId and slotIndex in request are invalid."); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5952 | } |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5953 | return phone; |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5954 | } |
| 5955 | |
| 5956 | private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone, |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5957 | IccLogicalChannelRequest channelRequest) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5958 | final long identity = Binder.clearCallingIdentity(); |
| 5959 | try { |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5960 | if (TextUtils.equals(ISDR_AID, channelRequest.aid)) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5961 | // Only allows LPA to open logical channel to ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5962 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 5963 | .getContext().getPackageManager()); |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5964 | if (bestComponent == null || !TextUtils.equals(channelRequest.callingPackage, |
| 5965 | bestComponent.packageName)) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5966 | loge("The calling package is not allowed to access ISD-R."); |
| 5967 | throw new SecurityException( |
| 5968 | "The calling package is not allowed to access ISD-R."); |
| 5969 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 5970 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 5971 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5972 | IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest( |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5973 | CMD_OPEN_CHANNEL, channelRequest, phone, null /* workSource */); |
| 5974 | if (DBG) log("iccOpenLogicalChannelWithPermission: response=" + response); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5975 | return response; |
| 5976 | } finally { |
| 5977 | Binder.restoreCallingIdentity(identity); |
| 5978 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5979 | } |
| 5980 | |
| 5981 | @Override |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5982 | public boolean iccCloseLogicalChannel(@NonNull IccLogicalChannelRequest request) { |
| 5983 | Phone phone = getPhoneFromValidIccLogicalChannelRequest(request, |
| 5984 | /*message=*/"iccCloseLogicalChannel"); |
| 5985 | |
| 5986 | if (DBG) log("iccCloseLogicalChannel: request=" + request); |
| 5987 | |
| 5988 | return iccCloseLogicalChannelWithPermission(phone, request); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5989 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5990 | |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5991 | private boolean iccCloseLogicalChannelWithPermission(Phone phone, |
| 5992 | IccLogicalChannelRequest request) { |
Chen Xu | a8f0dff | 2022-02-12 00:34:15 -0800 | [diff] [blame] | 5993 | // before this feature is enabled, this API should only return false if |
| 5994 | // the operation fails instead of throwing runtime exception for |
| 5995 | // backward-compatibility. |
| 5996 | final boolean shouldThrowExceptionOnFailure = CompatChanges.isChangeEnabled( |
| 5997 | ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE, Binder.getCallingUid()); |
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 (request.channel < 0) { |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 6001 | throw new IllegalArgumentException("request.channel is less than 0"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6002 | } |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 6003 | Object result = sendRequest(CMD_CLOSE_CHANNEL, request.channel, phone, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6004 | null /* workSource */); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 6005 | Boolean success = false; |
| 6006 | if (result instanceof RuntimeException) { |
| 6007 | // if there is an exception returned, throw from the binder thread here. |
Chen Xu | a8f0dff | 2022-02-12 00:34:15 -0800 | [diff] [blame] | 6008 | if (shouldThrowExceptionOnFailure) { |
| 6009 | throw (RuntimeException) result; |
| 6010 | } else { |
| 6011 | return false; |
| 6012 | } |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 6013 | } else if (result instanceof Boolean) { |
| 6014 | success = (Boolean) result; |
| 6015 | } else { |
| 6016 | loge("iccCloseLogicalChannelWithPermission: supported return type " + result); |
| 6017 | } |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 6018 | if (DBG) log("iccCloseLogicalChannelWithPermission: success=" + success); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6019 | return success; |
| 6020 | } finally { |
| 6021 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 6022 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 6023 | } |
| 6024 | |
| 6025 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6026 | public String iccTransmitApduLogicalChannel(int subId, int channel, int cla, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 6027 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6028 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6029 | mApp, subId, "iccTransmitApduLogicalChannel"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6030 | if (DBG) { |
| 6031 | log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel |
| 6032 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 6033 | + p3 + " data=" + data); |
| 6034 | } |
| 6035 | return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla, |
| 6036 | command, p1, p2, p3, data); |
| 6037 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 6038 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6039 | @Override |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 6040 | public String iccTransmitApduLogicalChannelByPort(int slotIndex, int portIndex, int channel, |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame^] | 6041 | int cla, int command, int p1, int p2, int p3, String data) { |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6042 | enforceModifyPermission(); |
| 6043 | if (DBG) { |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 6044 | log("iccTransmitApduLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex=" |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame^] | 6045 | + portIndex + " chnl=" + channel + " cla=" + cla + " cmd=" + command + " p1=" |
| 6046 | + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6047 | } |
| 6048 | return iccTransmitApduLogicalChannelWithPermission( |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 6049 | getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel, cla, |
| 6050 | command, p1, p2, p3, data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6051 | } |
| 6052 | |
| 6053 | private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla, |
| 6054 | int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6055 | final long identity = Binder.clearCallingIdentity(); |
| 6056 | try { |
Hall Liu | 4fd771b | 2019-05-02 09:16:29 -0700 | [diff] [blame] | 6057 | if (channel <= 0) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6058 | return ""; |
| 6059 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 6060 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6061 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6062 | new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone, |
| 6063 | null /* workSource */); |
| 6064 | if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 6065 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6066 | // Append the returned status code to the end of the response payload. |
| 6067 | String s = Integer.toHexString( |
| 6068 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 6069 | if (response.payload != null) { |
| 6070 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 6071 | } |
| 6072 | return s; |
| 6073 | } finally { |
| 6074 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 6075 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 6076 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 6077 | |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 6078 | @Override |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 6079 | public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla, |
| 6080 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6081 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6082 | mApp, subId, "iccTransmitApduBasicChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6083 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6084 | if (DBG) { |
| 6085 | log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" |
| 6086 | + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
| 6087 | } |
| 6088 | return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage, |
| 6089 | cla, command, p1, p2, p3, data); |
| 6090 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 6091 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6092 | @Override |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 6093 | public String iccTransmitApduBasicChannelByPort(int slotIndex, int portIndex, |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame^] | 6094 | 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] | 6095 | enforceModifyPermission(); |
| 6096 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 6097 | if (DBG) { |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 6098 | log("iccTransmitApduBasicChannelByPort: slotIndex=" + slotIndex + " portIndex=" |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame^] | 6099 | + portIndex + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" |
| 6100 | + p2 + " p3=" + p3 + " data=" + data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6101 | } |
| 6102 | |
| 6103 | return iccTransmitApduBasicChannelWithPermission( |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 6104 | getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), callingPackage, |
| 6105 | cla, command, p1, p2, p3, data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6106 | } |
| 6107 | |
| 6108 | // open APDU basic channel assuming the caller has sufficient permissions |
| 6109 | private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage, |
| 6110 | int cla, int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6111 | final long identity = Binder.clearCallingIdentity(); |
| 6112 | try { |
| 6113 | if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3 |
| 6114 | && TextUtils.equals(ISDR_AID, data)) { |
| 6115 | // Only allows LPA to select ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6116 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 6117 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6118 | if (bestComponent == null |
| 6119 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 6120 | loge("The calling package is not allowed to select ISD-R."); |
| 6121 | throw new SecurityException( |
| 6122 | "The calling package is not allowed to select ISD-R."); |
| 6123 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 6124 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 6125 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6126 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6127 | new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone, |
| 6128 | null /* workSource */); |
| 6129 | if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 6130 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6131 | // Append the returned status code to the end of the response payload. |
| 6132 | String s = Integer.toHexString( |
| 6133 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 6134 | if (response.payload != null) { |
| 6135 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 6136 | } |
| 6137 | return s; |
| 6138 | } finally { |
| 6139 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 6140 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 6141 | } |
| 6142 | |
| 6143 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6144 | 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] | 6145 | String filePath) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6146 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6147 | mApp, subId, "iccExchangeSimIO"); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 6148 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6149 | final long identity = Binder.clearCallingIdentity(); |
| 6150 | try { |
| 6151 | if (DBG) { |
| 6152 | log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " |
| 6153 | + p1 + " " + p2 + " " + p3 + ":" + filePath); |
| 6154 | } |
| 6155 | |
| 6156 | IccIoResult response = |
| 6157 | (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO, |
| 6158 | new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath), |
| 6159 | subId); |
| 6160 | |
| 6161 | if (DBG) { |
| 6162 | log("Exchange SIM_IO [R]" + response); |
| 6163 | } |
| 6164 | |
| 6165 | byte[] result = null; |
| 6166 | int length = 2; |
| 6167 | if (response.payload != null) { |
| 6168 | length = 2 + response.payload.length; |
| 6169 | result = new byte[length]; |
| 6170 | System.arraycopy(response.payload, 0, result, 0, response.payload.length); |
| 6171 | } else { |
| 6172 | result = new byte[length]; |
| 6173 | } |
| 6174 | |
| 6175 | result[length - 1] = (byte) response.sw2; |
| 6176 | result[length - 2] = (byte) response.sw1; |
| 6177 | return result; |
| 6178 | } finally { |
| 6179 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 6180 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 6181 | } |
| 6182 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 6183 | /** |
| 6184 | * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM) |
| 6185 | * on a particular subscription |
| 6186 | */ |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6187 | public String[] getForbiddenPlmns(int subId, int appType, String callingPackage, |
| 6188 | String callingFeatureId) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 6189 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6190 | mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 6191 | return null; |
| 6192 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6193 | |
| 6194 | final long identity = Binder.clearCallingIdentity(); |
| 6195 | try { |
| 6196 | if (appType != TelephonyManager.APPTYPE_USIM |
| 6197 | && appType != TelephonyManager.APPTYPE_SIM) { |
| 6198 | loge("getForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 6199 | return null; |
| 6200 | } |
| 6201 | Object response = sendRequest( |
| 6202 | CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId); |
| 6203 | if (response instanceof String[]) { |
| 6204 | return (String[]) response; |
| 6205 | } |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 6206 | // Response is an Exception of some kind |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6207 | // which is signalled to the user as a NULL retval |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 6208 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6209 | } finally { |
| 6210 | Binder.restoreCallingIdentity(identity); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 6211 | } |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 6212 | } |
| 6213 | |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 6214 | /** |
| 6215 | * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular |
| 6216 | * subscription. |
| 6217 | * |
| 6218 | * @param subId the id of the subscription. |
| 6219 | * @param appType the uicc app type, must be USIM or SIM. |
| 6220 | * @param fplmns the Forbiden plmns list that needed to be written to the SIM. |
| 6221 | * @param callingPackage the op Package name. |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6222 | * @param callingFeatureId the feature in the package. |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 6223 | * @return number of fplmns that is successfully written to the SIM. |
| 6224 | */ |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6225 | public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage, |
| 6226 | String callingFeatureId) { |
Jayachandran C | 5b0d75a | 2021-10-21 22:15:27 -0700 | [diff] [blame] | 6227 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6228 | mApp, subId, "setForbiddenPlmns"); |
| 6229 | |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 6230 | if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) { |
| 6231 | loge("setForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 6232 | throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM"); |
| 6233 | } |
| 6234 | if (fplmns == null) { |
| 6235 | throw new IllegalArgumentException("Fplmn List provided is null"); |
| 6236 | } |
| 6237 | for (String fplmn : fplmns) { |
| 6238 | if (!CellIdentity.isValidPlmn(fplmn)) { |
| 6239 | throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn); |
| 6240 | } |
| 6241 | } |
| 6242 | final long identity = Binder.clearCallingIdentity(); |
| 6243 | try { |
| 6244 | Object response = sendRequest( |
| 6245 | CMD_SET_FORBIDDEN_PLMNS, |
| 6246 | new Pair<Integer, List<String>>(new Integer(appType), fplmns), |
| 6247 | subId); |
| 6248 | return (int) response; |
| 6249 | } finally { |
| 6250 | Binder.restoreCallingIdentity(identity); |
| 6251 | } |
| 6252 | } |
| 6253 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 6254 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6255 | public String sendEnvelopeWithStatus(int subId, String content) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6256 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6257 | mApp, subId, "sendEnvelopeWithStatus"); |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 6258 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6259 | final long identity = Binder.clearCallingIdentity(); |
| 6260 | try { |
| 6261 | IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId); |
| 6262 | if (response.payload == null) { |
| 6263 | return ""; |
| 6264 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 6265 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6266 | // Append the returned status code to the end of the response payload. |
| 6267 | String s = Integer.toHexString( |
| 6268 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 6269 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 6270 | return s; |
| 6271 | } finally { |
| 6272 | Binder.restoreCallingIdentity(identity); |
| 6273 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 6274 | } |
| 6275 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 6276 | /** |
| 6277 | * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 6278 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 6279 | * |
| 6280 | * @param itemID the ID of the item to read |
| 6281 | * @return the NV item as a String, or null on error. |
| 6282 | */ |
| 6283 | @Override |
| 6284 | public String nvReadItem(int itemID) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6285 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6286 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6287 | mApp, getDefaultSubscription(), "nvReadItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6288 | |
| 6289 | final long identity = Binder.clearCallingIdentity(); |
| 6290 | try { |
| 6291 | if (DBG) log("nvReadItem: item " + itemID); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6292 | String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6293 | if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"'); |
| 6294 | return value; |
| 6295 | } finally { |
| 6296 | Binder.restoreCallingIdentity(identity); |
| 6297 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 6298 | } |
| 6299 | |
| 6300 | /** |
| 6301 | * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 6302 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 6303 | * |
| 6304 | * @param itemID the ID of the item to read |
| 6305 | * @param itemValue the value to write, as a String |
| 6306 | * @return true on success; false on any failure |
| 6307 | */ |
| 6308 | @Override |
| 6309 | public boolean nvWriteItem(int itemID, String itemValue) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6310 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6311 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6312 | mApp, getDefaultSubscription(), "nvWriteItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6313 | |
| 6314 | final long identity = Binder.clearCallingIdentity(); |
| 6315 | try { |
| 6316 | if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"'); |
| 6317 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6318 | new Pair<Integer, String>(itemID, itemValue), workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6319 | if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail")); |
| 6320 | return success; |
| 6321 | } finally { |
| 6322 | Binder.restoreCallingIdentity(identity); |
| 6323 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 6324 | } |
| 6325 | |
| 6326 | /** |
| 6327 | * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage. |
| 6328 | * Used for device configuration by some CDMA operators. |
| 6329 | * |
| 6330 | * @param preferredRoamingList byte array containing the new PRL |
| 6331 | * @return true on success; false on any failure |
| 6332 | */ |
| 6333 | @Override |
| 6334 | public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6335 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6336 | mApp, getDefaultSubscription(), "nvWriteCdmaPrl"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6337 | |
| 6338 | final long identity = Binder.clearCallingIdentity(); |
| 6339 | try { |
| 6340 | if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList)); |
| 6341 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList); |
| 6342 | if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail")); |
| 6343 | return success; |
| 6344 | } finally { |
| 6345 | Binder.restoreCallingIdentity(identity); |
| 6346 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 6347 | } |
| 6348 | |
| 6349 | /** |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 6350 | * 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] | 6351 | * Used for device configuration by some CDMA operators. |
| 6352 | * |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 6353 | * @param slotIndex - device slot. |
| 6354 | * |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 6355 | * @return true on success; false on any failure |
| 6356 | */ |
| 6357 | @Override |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 6358 | public boolean resetModemConfig(int slotIndex) { |
| 6359 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 6360 | if (phone != null) { |
| 6361 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6362 | mApp, phone.getSubId(), "resetModemConfig"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6363 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 6364 | final long identity = Binder.clearCallingIdentity(); |
| 6365 | try { |
| 6366 | Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null); |
| 6367 | if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 6368 | return success; |
| 6369 | } finally { |
| 6370 | Binder.restoreCallingIdentity(identity); |
| 6371 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6372 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 6373 | return false; |
| 6374 | } |
| 6375 | |
| 6376 | /** |
| 6377 | * Generate a radio modem reset. Used for device configuration by some CDMA operators. |
| 6378 | * |
| 6379 | * @param slotIndex - device slot. |
| 6380 | * |
| 6381 | * @return true on success; false on any failure |
| 6382 | */ |
| 6383 | @Override |
| 6384 | public boolean rebootModem(int slotIndex) { |
| 6385 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 6386 | if (phone != null) { |
| 6387 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6388 | mApp, phone.getSubId(), "rebootModem"); |
| 6389 | |
| 6390 | final long identity = Binder.clearCallingIdentity(); |
| 6391 | try { |
| 6392 | Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null); |
| 6393 | if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail")); |
| 6394 | return success; |
| 6395 | } finally { |
| 6396 | Binder.restoreCallingIdentity(identity); |
| 6397 | } |
| 6398 | } |
| 6399 | return false; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 6400 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 6401 | |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 6402 | /** |
Grace Jia | aa2eb6b | 2020-01-09 16:26:08 -0800 | [diff] [blame] | 6403 | * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and |
| 6404 | * {@link #disableIms(int)}. |
| 6405 | * @param slotIndex device slot. |
| 6406 | */ |
| 6407 | public void resetIms(int slotIndex) { |
| 6408 | enforceModifyPermission(); |
| 6409 | |
| 6410 | final long identity = Binder.clearCallingIdentity(); |
| 6411 | try { |
| 6412 | if (mImsResolver == null) { |
| 6413 | // may happen if the does not support IMS. |
| 6414 | return; |
| 6415 | } |
Hyunho | a17ac7c | 2022-08-30 12:03:04 +0000 | [diff] [blame] | 6416 | mImsResolver.resetIms(slotIndex); |
Grace Jia | aa2eb6b | 2020-01-09 16:26:08 -0800 | [diff] [blame] | 6417 | } finally { |
| 6418 | Binder.restoreCallingIdentity(identity); |
| 6419 | } |
| 6420 | } |
| 6421 | |
| 6422 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6423 | * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability |
| 6424 | * status updates, if not already enabled. |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 6425 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6426 | public void enableIms(int slotId) { |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 6427 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6428 | |
| 6429 | final long identity = Binder.clearCallingIdentity(); |
| 6430 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6431 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6432 | // may happen if the device does not support IMS. |
| 6433 | return; |
| 6434 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6435 | mImsResolver.enableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6436 | } finally { |
| 6437 | Binder.restoreCallingIdentity(identity); |
| 6438 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 6439 | } |
| 6440 | |
| 6441 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6442 | * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature |
| 6443 | * status updates to disabled. |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 6444 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6445 | public void disableIms(int slotId) { |
| 6446 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6447 | |
| 6448 | final long identity = Binder.clearCallingIdentity(); |
| 6449 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6450 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6451 | // may happen if the device does not support IMS. |
| 6452 | return; |
| 6453 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6454 | mImsResolver.disableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6455 | } finally { |
| 6456 | Binder.restoreCallingIdentity(identity); |
| 6457 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6458 | } |
| 6459 | |
| 6460 | /** |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 6461 | * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback |
| 6462 | * callback. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6463 | */ |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 6464 | @Override |
Brad Ebinger | f6aca00 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 6465 | public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) { |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 6466 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6467 | |
| 6468 | final long identity = Binder.clearCallingIdentity(); |
| 6469 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6470 | if (mImsResolver == null) { |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 6471 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 6472 | "Device does not support IMS"); |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6473 | } |
Brad Ebinger | f6aca00 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 6474 | mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6475 | } finally { |
| 6476 | Binder.restoreCallingIdentity(identity); |
| 6477 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 6478 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 6479 | /** |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 6480 | * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature. |
| 6481 | */ |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 6482 | @Override |
| 6483 | public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) { |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 6484 | enforceModifyPermission(); |
| 6485 | |
| 6486 | final long identity = Binder.clearCallingIdentity(); |
| 6487 | try { |
| 6488 | if (mImsResolver == null) return; |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 6489 | mImsResolver.unregisterImsFeatureCallback(callback); |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 6490 | } finally { |
| 6491 | Binder.restoreCallingIdentity(identity); |
| 6492 | } |
| 6493 | } |
| 6494 | |
| 6495 | /** |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 6496 | * Returns the {@link IImsRegistration} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6497 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 6498 | */ |
| 6499 | public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException { |
| 6500 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6501 | |
| 6502 | final long identity = Binder.clearCallingIdentity(); |
| 6503 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6504 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6505 | // may happen if the device does not support IMS. |
| 6506 | return null; |
| 6507 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6508 | return mImsResolver.getImsRegistration(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6509 | } finally { |
| 6510 | Binder.restoreCallingIdentity(identity); |
| 6511 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 6512 | } |
| 6513 | |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6514 | /** |
| 6515 | * Returns the {@link IImsConfig} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6516 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6517 | */ |
| 6518 | public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException { |
| 6519 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6520 | |
| 6521 | final long identity = Binder.clearCallingIdentity(); |
| 6522 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6523 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6524 | // may happen if the device does not support IMS. |
| 6525 | return null; |
| 6526 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6527 | return mImsResolver.getImsConfig(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6528 | } finally { |
| 6529 | Binder.restoreCallingIdentity(identity); |
| 6530 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6531 | } |
| 6532 | |
Brad Ebinger | 884c07b | 2018-02-15 16:17:40 -0800 | [diff] [blame] | 6533 | /** |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6534 | * Sets the ImsService Package Name that Telephony will bind to. |
| 6535 | * |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6536 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 6537 | * @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] | 6538 | * ImsService is the device default ImsService. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6539 | * @param featureTypes An integer array of feature types associated with a packageName. |
| 6540 | * @param packageName The name of the package that the current configuration will be replaced |
| 6541 | * with. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6542 | * @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] | 6543 | */ |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6544 | public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService, |
| 6545 | int[] featureTypes, String packageName) { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6546 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 6547 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
Jack Yu | 00ece8c | 2022-11-19 22:29:12 -0800 | [diff] [blame] | 6548 | SubscriptionManager.getSubscriptionId(slotIndex), "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 6549 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6550 | final long identity = Binder.clearCallingIdentity(); |
| 6551 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6552 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6553 | // may happen if the device does not support IMS. |
| 6554 | return false; |
| 6555 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6556 | Map<Integer, String> featureConfig = new HashMap<>(); |
| 6557 | for (int featureType : featureTypes) { |
| 6558 | featureConfig.put(featureType, packageName); |
| 6559 | } |
| 6560 | return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService, |
| 6561 | featureConfig); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6562 | } finally { |
| 6563 | Binder.restoreCallingIdentity(identity); |
| 6564 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6565 | } |
| 6566 | |
| 6567 | /** |
Brad Ebinger | 999d330 | 2020-11-25 14:31:39 -0800 | [diff] [blame] | 6568 | * Clears any carrier ImsService overrides for the slot index specified that were previously |
| 6569 | * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}. |
| 6570 | * |
| 6571 | * This should only be used for testing. |
| 6572 | * |
| 6573 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 6574 | * @return true if clearing the carrier ImsService override succeeded or false if it did not. |
| 6575 | */ |
| 6576 | @Override |
| 6577 | public boolean clearCarrierImsServiceOverride(int slotIndex) { |
Brad Ebinger | 999d330 | 2020-11-25 14:31:39 -0800 | [diff] [blame] | 6578 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 6579 | "clearCarrierImsServiceOverride"); |
| 6580 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
Jack Yu | 00ece8c | 2022-11-19 22:29:12 -0800 | [diff] [blame] | 6581 | SubscriptionManager.getSubscriptionId(slotIndex), "clearCarrierImsServiceOverride"); |
Brad Ebinger | 999d330 | 2020-11-25 14:31:39 -0800 | [diff] [blame] | 6582 | |
| 6583 | final long identity = Binder.clearCallingIdentity(); |
| 6584 | try { |
| 6585 | if (mImsResolver == null) { |
| 6586 | // may happen if the device does not support IMS. |
| 6587 | return false; |
| 6588 | } |
| 6589 | return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex); |
| 6590 | } finally { |
| 6591 | Binder.restoreCallingIdentity(identity); |
| 6592 | } |
| 6593 | } |
| 6594 | |
| 6595 | /** |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6596 | * Return the package name of the currently bound ImsService. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6597 | * |
| 6598 | * @param slotId The slot that the ImsService is associated with. |
| 6599 | * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is |
| 6600 | * the device default. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6601 | * @param featureType The feature associated with the queried configuration. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6602 | * @return the package name of the ImsService configuration. |
| 6603 | */ |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6604 | public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService, |
| 6605 | @ImsFeature.FeatureType int featureType) { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6606 | TelephonyPermissions |
Jack Yu | 00ece8c | 2022-11-19 22:29:12 -0800 | [diff] [blame] | 6607 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(mApp, |
| 6608 | SubscriptionManager.getSubscriptionId(slotId), "getBoundImsServicePackage"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 6609 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6610 | final long identity = Binder.clearCallingIdentity(); |
| 6611 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6612 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6613 | // may happen if the device does not support IMS. |
| 6614 | return ""; |
| 6615 | } |
Brad Ebinger | a80c331 | 2019-12-02 10:59:39 -0800 | [diff] [blame] | 6616 | // TODO: change API to query RCS separately. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6617 | return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService, |
| 6618 | featureType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6619 | } finally { |
| 6620 | Binder.restoreCallingIdentity(identity); |
| 6621 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6622 | } |
| 6623 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6624 | /** |
| 6625 | * Get the MmTelFeature state associated with the requested subscription id. |
| 6626 | * @param subId The subscription that the MmTelFeature is associated with. |
| 6627 | * @param callback A callback with an integer containing the |
| 6628 | * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature. |
| 6629 | */ |
| 6630 | @Override |
| 6631 | public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) { |
| 6632 | enforceReadPrivilegedPermission("getImsMmTelFeatureState"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 6633 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 6634 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 6635 | "IMS not available on device."); |
| 6636 | } |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6637 | final long token = Binder.clearCallingIdentity(); |
| 6638 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 6639 | int slotId = getSlotIndex(subId); |
| 6640 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 6641 | Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '" |
| 6642 | + subId + "'"); |
| 6643 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 6644 | } |
| 6645 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 6646 | ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> { |
| 6647 | try { |
| 6648 | callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger); |
| 6649 | } catch (RemoteException e) { |
| 6650 | Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. " |
| 6651 | + "Ignore"); |
| 6652 | } |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6653 | }); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 6654 | } catch (ImsException e) { |
| 6655 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6656 | } finally { |
| 6657 | Binder.restoreCallingIdentity(token); |
| 6658 | } |
| 6659 | } |
| 6660 | |
Daniel Bright | bb5840b | 2021-01-12 15:48:18 -0800 | [diff] [blame] | 6661 | /** |
| 6662 | * Sets the ims registration state on all valid {@link Phone}s. |
| 6663 | */ |
| 6664 | public void setImsRegistrationState(final boolean registered) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 6665 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6666 | |
| 6667 | final long identity = Binder.clearCallingIdentity(); |
| 6668 | try { |
Daniel Bright | bb5840b | 2021-01-12 15:48:18 -0800 | [diff] [blame] | 6669 | // NOTE: Before S, this method only set the default phone. |
| 6670 | for (final Phone phone : PhoneFactory.getPhones()) { |
| 6671 | if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) { |
| 6672 | phone.setImsRegistrationState(registered); |
| 6673 | } |
| 6674 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6675 | } finally { |
| 6676 | Binder.restoreCallingIdentity(identity); |
| 6677 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 6678 | } |
| 6679 | |
| 6680 | /** |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 6681 | * Set the network selection mode to automatic. |
| 6682 | * |
| 6683 | */ |
| 6684 | @Override |
| 6685 | public void setNetworkSelectionModeAutomatic(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6686 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6687 | mApp, subId, "setNetworkSelectionModeAutomatic"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6688 | |
| 6689 | final long identity = Binder.clearCallingIdentity(); |
| 6690 | try { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 6691 | if (!isActiveSubscription(subId)) { |
| 6692 | return; |
| 6693 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6694 | if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId); |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 6695 | sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId, |
| 6696 | SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6697 | } finally { |
| 6698 | Binder.restoreCallingIdentity(identity); |
| 6699 | } |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 6700 | } |
| 6701 | |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 6702 | /** |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6703 | * Ask the radio to connect to the input network and change selection mode to manual. |
| 6704 | * |
| 6705 | * @param subId the id of the subscription. |
| 6706 | * @param operatorInfo the operator information, included the PLMN, long name and short name of |
| 6707 | * the operator to attach to. |
| 6708 | * @param persistSelection whether the selection will persist until reboot. If true, only allows |
| 6709 | * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume |
| 6710 | * normal network selection next time. |
| 6711 | * @return {@code true} on success; {@code true} on any failure. |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6712 | */ |
| 6713 | @Override |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6714 | public boolean setNetworkSelectionModeManual( |
| 6715 | int subId, OperatorInfo operatorInfo, boolean persistSelection) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6716 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6717 | mApp, subId, "setNetworkSelectionModeManual"); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 6718 | |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 6719 | final long identity = Binder.clearCallingIdentity(); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 6720 | if (!isActiveSubscription(subId)) { |
| 6721 | return false; |
| 6722 | } |
| 6723 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6724 | try { |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6725 | ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6726 | persistSelection); |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6727 | if (DBG) { |
| 6728 | log("setNetworkSelectionModeManual: subId: " + subId |
| 6729 | + " operator: " + operatorInfo); |
| 6730 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6731 | return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId); |
| 6732 | } finally { |
| 6733 | Binder.restoreCallingIdentity(identity); |
| 6734 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6735 | } |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame^] | 6736 | /** |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6737 | * Get the manual network selection |
| 6738 | * |
| 6739 | * @param subId the id of the subscription. |
| 6740 | * |
| 6741 | * @return the previously saved user selected PLMN |
| 6742 | */ |
| 6743 | @Override |
| 6744 | public String getManualNetworkSelectionPlmn(int subId) { |
| 6745 | TelephonyPermissions |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame^] | 6746 | .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 6747 | mApp, subId, "getManualNetworkSelectionPlmn"); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6748 | |
| 6749 | final long identity = Binder.clearCallingIdentity(); |
| 6750 | try { |
| 6751 | if (!isActiveSubscription(subId)) { |
shilu | fa1c259 | 2020-03-10 10:59:43 -0700 | [diff] [blame] | 6752 | throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6753 | } |
| 6754 | |
| 6755 | final Phone phone = getPhone(subId); |
| 6756 | if (phone == null) { |
shilu | fa1c259 | 2020-03-10 10:59:43 -0700 | [diff] [blame] | 6757 | throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6758 | } |
| 6759 | OperatorInfo networkSelection = phone.getSavedNetworkSelection(); |
| 6760 | return TextUtils.isEmpty(networkSelection.getOperatorNumeric()) |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame^] | 6761 | ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric(); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6762 | } finally { |
| 6763 | Binder.restoreCallingIdentity(identity); |
| 6764 | } |
| 6765 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6766 | |
| 6767 | /** |
| 6768 | * Scans for available networks. |
| 6769 | */ |
| 6770 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6771 | public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage, |
| 6772 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6773 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6774 | mApp, subId, "getCellNetworkScanResults"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6775 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 6776 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 6777 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 6778 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6779 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6780 | .setCallingPid(Binder.getCallingPid()) |
| 6781 | .setCallingUid(Binder.getCallingUid()) |
| 6782 | .setMethod("getCellNetworkScanResults") |
| 6783 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
Hall Liu | c4a3e42 | 2020-05-26 17:18:03 -0700 | [diff] [blame] | 6784 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 6785 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6786 | .build()); |
| 6787 | switch (locationResult) { |
| 6788 | case DENIED_HARD: |
| 6789 | throw new SecurityException("Not allowed to access scan results -- location"); |
| 6790 | case DENIED_SOFT: |
| 6791 | return null; |
| 6792 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6793 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6794 | long identity = Binder.clearCallingIdentity(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6795 | try { |
| 6796 | if (DBG) log("getCellNetworkScanResults: subId " + subId); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6797 | return (CellNetworkScanResult) sendRequest( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6798 | CMD_PERFORM_NETWORK_SCAN, null, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6799 | } finally { |
| 6800 | Binder.restoreCallingIdentity(identity); |
| 6801 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6802 | } |
| 6803 | |
| 6804 | /** |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6805 | * Get the call forwarding info, given the call forwarding reason. |
| 6806 | */ |
| 6807 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6808 | public void getCallForwarding(int subId, int callForwardingReason, |
| 6809 | ICallForwardingInfoCallback callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6810 | enforceReadPrivilegedPermission("getCallForwarding"); |
| 6811 | long identity = Binder.clearCallingIdentity(); |
| 6812 | try { |
| 6813 | if (DBG) { |
| 6814 | log("getCallForwarding: subId " + subId |
| 6815 | + " callForwardingReason" + callForwardingReason); |
| 6816 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6817 | |
| 6818 | Phone phone = getPhone(subId); |
| 6819 | if (phone == null) { |
| 6820 | try { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 6821 | callback.onError( |
| 6822 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6823 | } catch (RemoteException e) { |
| 6824 | // ignore |
| 6825 | } |
| 6826 | return; |
| 6827 | } |
| 6828 | |
| 6829 | Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create( |
| 6830 | callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() { |
| 6831 | @Override |
| 6832 | public void onCallForwardingInfoAvailable(CallForwardingInfo info) { |
| 6833 | try { |
| 6834 | callback.onCallForwardingInfoAvailable(info); |
| 6835 | } catch (RemoteException e) { |
| 6836 | // ignore |
| 6837 | } |
| 6838 | } |
| 6839 | |
| 6840 | @Override |
| 6841 | public void onError(int error) { |
| 6842 | try { |
| 6843 | callback.onError(error); |
| 6844 | } catch (RemoteException e) { |
| 6845 | // ignore |
| 6846 | } |
| 6847 | } |
| 6848 | }); |
| 6849 | sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6850 | } finally { |
| 6851 | Binder.restoreCallingIdentity(identity); |
| 6852 | } |
| 6853 | } |
| 6854 | |
| 6855 | /** |
| 6856 | * Sets the voice call forwarding info including status (enable/disable), call forwarding |
| 6857 | * reason, the number to forward, and the timeout before the forwarding is attempted. |
| 6858 | */ |
| 6859 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6860 | public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo, |
| 6861 | IIntegerConsumer callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6862 | enforceModifyPermission(); |
| 6863 | long identity = Binder.clearCallingIdentity(); |
| 6864 | try { |
| 6865 | if (DBG) { |
| 6866 | log("setCallForwarding: subId " + subId |
| 6867 | + " callForwardingInfo" + callForwardingInfo); |
| 6868 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6869 | |
| 6870 | Phone phone = getPhone(subId); |
| 6871 | if (phone == null) { |
| 6872 | try { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 6873 | callback.accept( |
| 6874 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6875 | } catch (RemoteException e) { |
| 6876 | // ignore |
| 6877 | } |
| 6878 | return; |
| 6879 | } |
| 6880 | |
| 6881 | Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo, |
| 6882 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 6883 | |
| 6884 | sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6885 | } finally { |
| 6886 | Binder.restoreCallingIdentity(identity); |
| 6887 | } |
| 6888 | } |
| 6889 | |
| 6890 | /** |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6891 | * Get the call waiting status for a subId. |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6892 | */ |
| 6893 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6894 | public void getCallWaitingStatus(int subId, IIntegerConsumer callback) { |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6895 | enforceReadPrivilegedPermission("getCallWaitingStatus"); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6896 | long identity = Binder.clearCallingIdentity(); |
| 6897 | try { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6898 | Phone phone = getPhone(subId); |
| 6899 | if (phone == null) { |
| 6900 | try { |
| 6901 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 6902 | } catch (RemoteException e) { |
| 6903 | // ignore |
| 6904 | } |
| 6905 | return; |
| 6906 | } |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6907 | CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext()); |
| 6908 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 6909 | boolean requireUssd = c.getBoolean( |
| 6910 | CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6911 | |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6912 | if (DBG) log("getCallWaitingStatus: subId " + subId); |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6913 | if (requireUssd) { |
| 6914 | CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(), |
| 6915 | getSubscriptionCarrierId(subId)); |
| 6916 | String newUssdCommand = ""; |
| 6917 | try { |
| 6918 | newUssdCommand = carrierXmlParser.getFeature( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame^] | 6919 | CarrierXmlParser.FEATURE_CALL_WAITING) |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6920 | .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null); |
| 6921 | } catch (NullPointerException e) { |
| 6922 | loge("Failed to generate USSD number" + e); |
| 6923 | } |
| 6924 | ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver( |
| 6925 | mMainThreadHandler, callback, carrierXmlParser, |
| 6926 | CarrierXmlParser.SsEntry.SSAction.QUERY); |
| 6927 | final String ussdCommand = newUssdCommand; |
| 6928 | Executors.newSingleThreadExecutor().execute(() -> { |
| 6929 | handleUssdRequest(subId, ussdCommand, wrappedCallback); |
| 6930 | }); |
| 6931 | } else { |
| 6932 | Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException( |
| 6933 | callback::accept); |
| 6934 | sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null); |
| 6935 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6936 | } finally { |
| 6937 | Binder.restoreCallingIdentity(identity); |
| 6938 | } |
| 6939 | } |
| 6940 | |
| 6941 | /** |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6942 | * Sets whether call waiting is enabled for a given subId. |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6943 | */ |
| 6944 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6945 | public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6946 | enforceModifyPermission(); |
| 6947 | long identity = Binder.clearCallingIdentity(); |
| 6948 | try { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6949 | if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable); |
| 6950 | |
| 6951 | Phone phone = getPhone(subId); |
| 6952 | if (phone == null) { |
| 6953 | try { |
| 6954 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 6955 | } catch (RemoteException e) { |
| 6956 | // ignore |
| 6957 | } |
| 6958 | return; |
| 6959 | } |
| 6960 | |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6961 | CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext()); |
| 6962 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 6963 | boolean requireUssd = c.getBoolean( |
| 6964 | CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6965 | |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6966 | if (DBG) log("getCallWaitingStatus: subId " + subId); |
| 6967 | if (requireUssd) { |
| 6968 | CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(), |
| 6969 | getSubscriptionCarrierId(subId)); |
| 6970 | CarrierXmlParser.SsEntry.SSAction ssAction = |
| 6971 | enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE |
| 6972 | : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE; |
| 6973 | String newUssdCommand = ""; |
| 6974 | try { |
| 6975 | newUssdCommand = carrierXmlParser.getFeature( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame^] | 6976 | CarrierXmlParser.FEATURE_CALL_WAITING) |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6977 | .makeCommand(ssAction, null); |
| 6978 | } catch (NullPointerException e) { |
| 6979 | loge("Failed to generate USSD number" + e); |
| 6980 | } |
| 6981 | ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver( |
| 6982 | mMainThreadHandler, callback, carrierXmlParser, ssAction); |
| 6983 | final String ussdCommand = newUssdCommand; |
| 6984 | Executors.newSingleThreadExecutor().execute(() -> { |
| 6985 | handleUssdRequest(subId, ussdCommand, wrappedCallback); |
| 6986 | }); |
| 6987 | } else { |
| 6988 | Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable, |
| 6989 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 6990 | |
| 6991 | sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null); |
| 6992 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6993 | } finally { |
| 6994 | Binder.restoreCallingIdentity(identity); |
| 6995 | } |
| 6996 | } |
| 6997 | |
| 6998 | /** |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 6999 | * Starts a new network scan and returns the id of this scan. |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 7000 | * |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 7001 | * @param subId id of the subscription |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 7002 | * @param renounceFineLocationAccess Set this to true if the caller would not like to receive |
| 7003 | * location related information which will be sent if the caller already possess |
| 7004 | * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 7005 | * @param request contains the radio access networks with bands/channels to scan |
| 7006 | * @param messenger callback messenger for scan results or errors |
| 7007 | * @param binder for the purpose of auto clean when the user thread crashes |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 7008 | * @return the id of the requested scan which can be used to stop the scan. |
| 7009 | */ |
| 7010 | @Override |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 7011 | public int requestNetworkScan(int subId, boolean renounceFineLocationAccess, |
| 7012 | NetworkScanRequest request, Messenger messenger, |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 7013 | IBinder binder, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7014 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7015 | mApp, subId, "requestNetworkScan"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7016 | LocationAccessPolicy.LocationPermissionResult locationResult = |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 7017 | LocationAccessPolicy.LocationPermissionResult.DENIED_HARD; |
| 7018 | if (!renounceFineLocationAccess) { |
| 7019 | locationResult = LocationAccessPolicy.checkLocationPermission(mApp, |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame^] | 7020 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 7021 | .setCallingPackage(callingPackage) |
| 7022 | .setCallingFeatureId(callingFeatureId) |
| 7023 | .setCallingPid(Binder.getCallingPid()) |
| 7024 | .setCallingUid(Binder.getCallingUid()) |
| 7025 | .setMethod("requestNetworkScan") |
| 7026 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 7027 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 7028 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 7029 | .build()); |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 7030 | } |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 7031 | if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) { |
Nathan Harold | 1c11dba | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 7032 | SecurityException e = checkNetworkRequestForSanitizedLocationAccess( |
| 7033 | request, subId, callingPackage); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 7034 | if (e != null) { |
| 7035 | if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) { |
| 7036 | throw e; |
| 7037 | } else { |
Hall Liu | 0e5abaf | 2019-04-04 01:25:30 -0700 | [diff] [blame] | 7038 | loge(e.getMessage()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 7039 | return TelephonyScanManager.INVALID_SCAN_ID; |
| 7040 | } |
| 7041 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7042 | } |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 7043 | int callingUid = Binder.getCallingUid(); |
| 7044 | int callingPid = Binder.getCallingPid(); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 7045 | final long identity = Binder.clearCallingIdentity(); |
| 7046 | try { |
| 7047 | return mNetworkScanRequestTracker.startNetworkScan( |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 7048 | renounceFineLocationAccess, request, messenger, binder, getPhone(subId), |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 7049 | callingUid, callingPid, callingPackage); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 7050 | } finally { |
| 7051 | Binder.restoreCallingIdentity(identity); |
| 7052 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 7053 | } |
| 7054 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 7055 | private SecurityException checkNetworkRequestForSanitizedLocationAccess( |
Nathan Harold | 1c11dba | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 7056 | NetworkScanRequest request, int subId, String callingPackage) { |
Rambo Wang | 3dee30a | 2022-10-20 16:52:29 +0000 | [diff] [blame] | 7057 | boolean hasCarrierPriv; |
| 7058 | final long identity = Binder.clearCallingIdentity(); |
| 7059 | try { |
| 7060 | hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage) |
| 7061 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 7062 | } finally { |
| 7063 | Binder.restoreCallingIdentity(identity); |
| 7064 | } |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 7065 | boolean hasNetworkScanPermission = |
| 7066 | mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN) |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame^] | 7067 | == PERMISSION_GRANTED; |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 7068 | |
| 7069 | if (!hasCarrierPriv && !hasNetworkScanPermission) { |
| 7070 | return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed" |
| 7071 | + " for network scans without location access."); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 7072 | } |
| 7073 | |
| 7074 | if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) { |
| 7075 | for (RadioAccessSpecifier ras : request.getSpecifiers()) { |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 7076 | if (ras.getChannels() != null && ras.getChannels().length > 0) { |
| 7077 | return new SecurityException("Specific channels must not be" |
| 7078 | + " scanned without location access."); |
| 7079 | } |
| 7080 | } |
| 7081 | } |
| 7082 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 7083 | return null; |
| 7084 | } |
| 7085 | |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 7086 | /** |
| 7087 | * Stops an existing network scan with the given scanId. |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 7088 | * |
| 7089 | * @param subId id of the subscription |
| 7090 | * @param scanId id of the scan that needs to be stopped |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 7091 | */ |
| 7092 | @Override |
| 7093 | public void stopNetworkScan(int subId, int scanId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7094 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7095 | mApp, subId, "stopNetworkScan"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7096 | |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 7097 | int callingUid = Binder.getCallingUid(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7098 | final long identity = Binder.clearCallingIdentity(); |
| 7099 | try { |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 7100 | mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7101 | } finally { |
| 7102 | Binder.restoreCallingIdentity(identity); |
| 7103 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 7104 | } |
| 7105 | |
| 7106 | /** |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7107 | * Get the allowed network types bitmask. |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 7108 | * |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7109 | * @return the allowed network types bitmask, defined in RILConstants.java. |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 7110 | */ |
| 7111 | @Override |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7112 | public int getAllowedNetworkTypesBitmask(int subId) { |
Pengquan Meng | a4009cb | 2018-12-20 11:00:24 -0800 | [diff] [blame] | 7113 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 7114 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7115 | mApp, subId, "getAllowedNetworkTypesBitmask"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7116 | |
| 7117 | final long identity = Binder.clearCallingIdentity(); |
| 7118 | try { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7119 | if (DBG) log("getAllowedNetworkTypesBitmask"); |
| 7120 | int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId); |
| 7121 | int networkTypesBitmask = (result != null ? result[0] : -1); |
| 7122 | if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask); |
| 7123 | return networkTypesBitmask; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7124 | } finally { |
| 7125 | Binder.restoreCallingIdentity(identity); |
| 7126 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 7127 | } |
| 7128 | |
| 7129 | /** |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 7130 | * Get the allowed network types for certain reason. |
| 7131 | * |
| 7132 | * @param subId the id of the subscription. |
| 7133 | * @param reason the reason the allowed network type change is taking place |
| 7134 | * @return the allowed network types. |
| 7135 | */ |
| 7136 | @Override |
| 7137 | public long getAllowedNetworkTypesForReason(int subId, |
| 7138 | @TelephonyManager.AllowedNetworkTypesReason int reason) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 7139 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 7140 | mApp, subId, "getAllowedNetworkTypesForReason"); |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 7141 | final long identity = Binder.clearCallingIdentity(); |
| 7142 | try { |
| 7143 | return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason); |
| 7144 | } finally { |
| 7145 | Binder.restoreCallingIdentity(identity); |
| 7146 | } |
| 7147 | } |
| 7148 | |
| 7149 | /** |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 7150 | * Enable/Disable E-UTRA-NR Dual Connectivity |
| 7151 | * @param subId subscription id of the sim card |
| 7152 | * @param nrDualConnectivityState expected NR dual connectivity state |
| 7153 | * This can be passed following states |
| 7154 | * <ol> |
| 7155 | * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE} |
| 7156 | * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE} |
| 7157 | * <li>Disable NR dual connectivity and force secondary cell to be released |
| 7158 | * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE} |
| 7159 | * </ol> |
| 7160 | * @return operation result. |
| 7161 | */ |
| 7162 | @Override |
| 7163 | public int setNrDualConnectivityState(int subId, |
| 7164 | @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) { |
| 7165 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7166 | mApp, subId, "enableNRDualConnectivity"); |
Sooraj Sasindran | 0e4e00a | 2021-03-16 18:02:32 -0700 | [diff] [blame] | 7167 | if (!isRadioInterfaceCapabilitySupported( |
Sooraj Sasindran | dfd595b | 2021-03-11 17:38:13 -0800 | [diff] [blame] | 7168 | TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) { |
| 7169 | return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED; |
| 7170 | } |
| 7171 | |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 7172 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 7173 | final long identity = Binder.clearCallingIdentity(); |
| 7174 | try { |
| 7175 | int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY, |
| 7176 | nrDualConnectivityState, subId, |
| 7177 | workSource); |
| 7178 | if (DBG) log("enableNRDualConnectivity result: " + result); |
| 7179 | return result; |
| 7180 | } finally { |
| 7181 | Binder.restoreCallingIdentity(identity); |
| 7182 | } |
| 7183 | } |
| 7184 | |
| 7185 | /** |
| 7186 | * Is E-UTRA-NR Dual Connectivity enabled |
| 7187 | * @return true if dual connectivity is enabled else false |
| 7188 | */ |
| 7189 | @Override |
| 7190 | public boolean isNrDualConnectivityEnabled(int subId) { |
| 7191 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 7192 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 7193 | mApp, subId, "isNRDualConnectivityEnabled"); |
Sooraj Sasindran | 0e4e00a | 2021-03-16 18:02:32 -0700 | [diff] [blame] | 7194 | if (!isRadioInterfaceCapabilitySupported( |
Sooraj Sasindran | dfd595b | 2021-03-11 17:38:13 -0800 | [diff] [blame] | 7195 | TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) { |
| 7196 | return false; |
| 7197 | } |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 7198 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 7199 | final long identity = Binder.clearCallingIdentity(); |
| 7200 | try { |
| 7201 | boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED, |
| 7202 | null, subId, workSource); |
| 7203 | if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled); |
| 7204 | return isEnabled; |
| 7205 | } finally { |
| 7206 | Binder.restoreCallingIdentity(identity); |
| 7207 | } |
| 7208 | } |
| 7209 | |
| 7210 | /** |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 7211 | * Set the allowed network types of the device and |
| 7212 | * provide the reason triggering the allowed network change. |
| 7213 | * |
| 7214 | * @param subId the id of the subscription. |
| 7215 | * @param reason the reason the allowed network type change is taking place |
| 7216 | * @param allowedNetworkTypes the allowed network types. |
| 7217 | * @return true on success; false on any failure. |
| 7218 | */ |
| 7219 | @Override |
| 7220 | public boolean setAllowedNetworkTypesForReason(int subId, |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7221 | @TelephonyManager.AllowedNetworkTypesReason int reason, |
| 7222 | @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) { |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 7223 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7224 | mApp, subId, "setAllowedNetworkTypesForReason"); |
Gil Cukierman | 1d3d375 | 2022-10-03 21:31:33 +0000 | [diff] [blame] | 7225 | // If the caller only has carrier privileges, then they should not be able to override |
| 7226 | // any network types which were set for security reasons. |
| 7227 | if (mApp.checkCallingOrSelfPermission(Manifest.permission.MODIFY_PHONE_STATE) |
| 7228 | != PERMISSION_GRANTED |
Gil Cukierman | 2a8f48b | 2023-01-26 20:26:20 +0000 | [diff] [blame] | 7229 | && reason == TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_ENABLE_2G) { |
Gil Cukierman | 1d3d375 | 2022-10-03 21:31:33 +0000 | [diff] [blame] | 7230 | throw new SecurityException( |
| 7231 | "setAllowedNetworkTypesForReason cannot be called with carrier privileges for" |
Gil Cukierman | 2a8f48b | 2023-01-26 20:26:20 +0000 | [diff] [blame] | 7232 | + " reason " + reason); |
Gil Cukierman | 1d3d375 | 2022-10-03 21:31:33 +0000 | [diff] [blame] | 7233 | } |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7234 | if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) { |
Jack Yu | 5b49433 | 2023-01-23 18:18:04 +0000 | [diff] [blame] | 7235 | loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason); |
SongFerngWang | 7ffc273 | 2021-04-15 19:46:33 +0800 | [diff] [blame] | 7236 | return false; |
| 7237 | } |
| 7238 | if (!SubscriptionManager.isUsableSubscriptionId(subId)) { |
| 7239 | loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId); |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7240 | return false; |
| 7241 | } |
| 7242 | |
Jack Yu | 5b49433 | 2023-01-23 18:18:04 +0000 | [diff] [blame] | 7243 | log("setAllowedNetworkTypesForReason: subId=" + subId + ", reason=" + reason + " value: " |
| 7244 | + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes)); |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 7245 | |
Jack Yu | e37dd26 | 2022-12-16 11:53:37 -0800 | [diff] [blame] | 7246 | Phone phone = getPhone(subId); |
| 7247 | if (phone == null) { |
| 7248 | return false; |
| 7249 | } |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 7250 | |
Jack Yu | e37dd26 | 2022-12-16 11:53:37 -0800 | [diff] [blame] | 7251 | if (allowedNetworkTypes == phone.getAllowedNetworkTypes(reason)) { |
Jack Yu | 5b49433 | 2023-01-23 18:18:04 +0000 | [diff] [blame] | 7252 | log("setAllowedNetworkTypesForReason: " + reason + "does not change value"); |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 7253 | return true; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7254 | } |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 7255 | |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 7256 | final long identity = Binder.clearCallingIdentity(); |
| 7257 | try { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7258 | Boolean success = (Boolean) sendRequest( |
| 7259 | CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON, |
| 7260 | new Pair<Integer, Long>(reason, allowedNetworkTypes), subId); |
| 7261 | |
| 7262 | if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail")); |
| 7263 | return success; |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 7264 | } finally { |
| 7265 | Binder.restoreCallingIdentity(identity); |
| 7266 | } |
| 7267 | } |
| 7268 | |
| 7269 | /** |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 7270 | * Check whether DUN APN is required for tethering with subId. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 7271 | * |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 7272 | * @param subId the id of the subscription to require tethering. |
Amit Mahajan | fe58cdf | 2017-07-11 12:01:53 -0700 | [diff] [blame] | 7273 | * @return {@code true} if DUN APN is required for tethering. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 7274 | * @hide |
| 7275 | */ |
| 7276 | @Override |
SongFerngWang | f08d812 | 2019-11-15 14:58:44 +0800 | [diff] [blame] | 7277 | public boolean isTetheringApnRequiredForSubscriber(int subId) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7278 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7279 | final long identity = Binder.clearCallingIdentity(); |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 7280 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7281 | try { |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 7282 | if (phone != null) { |
| 7283 | return phone.hasMatchedTetherApnSetting(); |
| 7284 | } else { |
| 7285 | return false; |
| 7286 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7287 | } finally { |
| 7288 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 7289 | } |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 7290 | } |
| 7291 | |
| 7292 | /** |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 7293 | * Get the user enabled state of Mobile Data. |
| 7294 | * |
| 7295 | * TODO: remove and use isUserDataEnabled. |
| 7296 | * This can't be removed now because some vendor codes |
| 7297 | * calls through ITelephony directly while they should |
| 7298 | * use TelephonyManager. |
| 7299 | * |
| 7300 | * @return true on enabled |
| 7301 | */ |
| 7302 | @Override |
| 7303 | public boolean getDataEnabled(int subId) { |
| 7304 | return isUserDataEnabled(subId); |
| 7305 | } |
| 7306 | |
| 7307 | /** |
| 7308 | * Get whether mobile data is enabled per user setting. |
| 7309 | * |
| 7310 | * There are other factors deciding whether mobile data is actually enabled, but they are |
| 7311 | * not considered here. See {@link #isDataEnabled(int)} for more details. |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 7312 | * |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7313 | * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE |
| 7314 | * or carrier privileges. |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 7315 | * |
| 7316 | * @return {@code true} if data is enabled else {@code false} |
| 7317 | */ |
| 7318 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 7319 | public boolean isUserDataEnabled(int subId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7320 | String functionName = "isUserDataEnabled"; |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 7321 | try { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7322 | try { |
| 7323 | mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE, |
| 7324 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7325 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7326 | mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName); |
| 7327 | } |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7328 | } catch (SecurityException e) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7329 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7330 | mApp, subId, functionName); |
| 7331 | |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 7332 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7333 | |
| 7334 | final long identity = Binder.clearCallingIdentity(); |
| 7335 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 7336 | int phoneId = SubscriptionManager.getPhoneId(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7337 | if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 7338 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 7339 | if (phone != null) { |
| 7340 | boolean retVal = phone.isUserDataEnabled(); |
| 7341 | if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 7342 | return retVal; |
| 7343 | } else { |
| 7344 | if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 7345 | return false; |
| 7346 | } |
| 7347 | } finally { |
| 7348 | Binder.restoreCallingIdentity(identity); |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 7349 | } |
| 7350 | } |
| 7351 | |
| 7352 | /** |
Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 7353 | * Checks if the device is capable of mobile data by considering whether whether the |
| 7354 | * user has enabled mobile data, whether the carrier has enabled mobile data, and |
| 7355 | * whether the network policy allows data connections. |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 7356 | * |
Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 7357 | * @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] | 7358 | */ |
| 7359 | @Override |
| 7360 | public boolean isDataEnabled(int subId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7361 | String functionName = "isDataEnabled"; |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7362 | try { |
| 7363 | try { |
| 7364 | mApp.enforceCallingOrSelfPermission( |
| 7365 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7366 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7367 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7368 | try { |
| 7369 | mApp.enforceCallingOrSelfPermission( |
| 7370 | android.Manifest.permission.READ_PHONE_STATE, |
| 7371 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7372 | } catch (SecurityException e2) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7373 | mApp.enforceCallingOrSelfPermission( |
| 7374 | permission.READ_BASIC_PHONE_STATE, functionName); |
| 7375 | } |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7376 | } |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7377 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7378 | enforceReadPrivilegedPermission(functionName); |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7379 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7380 | |
| 7381 | final long identity = Binder.clearCallingIdentity(); |
| 7382 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 7383 | int phoneId = SubscriptionManager.getPhoneId(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7384 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 7385 | if (phone != null) { |
Sarah Chin | e04784a | 2022-10-31 20:32:34 -0700 | [diff] [blame] | 7386 | boolean retVal = phone.getDataSettingsManager().isDataEnabled(); |
Jack Yu | 4ad64e5 | 2021-12-03 14:23:53 -0800 | [diff] [blame] | 7387 | if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7388 | return retVal; |
| 7389 | } else { |
| 7390 | if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 7391 | return false; |
| 7392 | } |
| 7393 | } finally { |
| 7394 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 7395 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 7396 | } |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 7397 | |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7398 | /** |
| 7399 | * Check if data is enabled for a specific reason |
| 7400 | * @param subId Subscription index |
| 7401 | * @param reason the reason the data enable change is taking place |
| 7402 | * @return {@code true} if the overall data is enabled; {@code false} if not. |
| 7403 | */ |
| 7404 | @Override |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7405 | public boolean isDataEnabledForReason(int subId, |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7406 | @TelephonyManager.DataEnabledReason int reason) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7407 | String functionName = "isDataEnabledForReason"; |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7408 | try { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7409 | try { |
| 7410 | mApp.enforceCallingOrSelfPermission( |
| 7411 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 7412 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7413 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7414 | mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE, |
| 7415 | functionName); |
| 7416 | } |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7417 | } catch (SecurityException e) { |
Sooraj Sasindran | 0d909a0 | 2021-11-08 12:01:16 -0800 | [diff] [blame] | 7418 | try { |
| 7419 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7420 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7421 | } catch (SecurityException e2) { |
Sooraj Sasindran | 0d909a0 | 2021-11-08 12:01:16 -0800 | [diff] [blame] | 7422 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7423 | mApp, subId, functionName); |
Sooraj Sasindran | 0d909a0 | 2021-11-08 12:01:16 -0800 | [diff] [blame] | 7424 | } |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7425 | } |
| 7426 | |
| 7427 | |
| 7428 | final long identity = Binder.clearCallingIdentity(); |
| 7429 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 7430 | int phoneId = SubscriptionManager.getPhoneId(subId); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7431 | if (DBG) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7432 | log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7433 | + " reason=" + reason); |
| 7434 | } |
| 7435 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 7436 | if (phone != null) { |
| 7437 | boolean retVal; |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 7438 | retVal = phone.getDataSettingsManager().isDataEnabledForReason(reason); |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7439 | if (DBG) log("isDataEnabledForReason: retVal=" + retVal); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7440 | return retVal; |
| 7441 | } else { |
| 7442 | if (DBG) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7443 | loge("isDataEnabledForReason: no phone subId=" |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7444 | + subId + " retVal=false"); |
| 7445 | } |
| 7446 | return false; |
| 7447 | } |
| 7448 | } finally { |
| 7449 | Binder.restoreCallingIdentity(identity); |
| 7450 | } |
| 7451 | } |
| 7452 | |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 7453 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7454 | public int getCarrierPrivilegeStatus(int subId) { |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7455 | // No permission needed; this only lets the caller inspect their own status. |
| 7456 | return getCarrierPrivilegeStatusForUidWithPermission(subId, Binder.getCallingUid()); |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 7457 | } |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 7458 | |
| 7459 | @Override |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7460 | public int getCarrierPrivilegeStatusForUid(int subId, int uid) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 7461 | enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid"); |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7462 | return getCarrierPrivilegeStatusForUidWithPermission(subId, uid); |
| 7463 | } |
| 7464 | |
| 7465 | private int getCarrierPrivilegeStatusForUidWithPermission(int subId, int uid) { |
| 7466 | Phone phone = getPhone(subId); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7467 | if (phone == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 7468 | loge("getCarrierPrivilegeStatusForUid: Invalid subId"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7469 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 7470 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7471 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7472 | if (cpt == null) { |
| 7473 | loge("getCarrierPrivilegeStatusForUid: No CarrierPrivilegesTracker"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7474 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 7475 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7476 | return cpt.getCarrierPrivilegeStatusForUid(uid); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7477 | } |
| 7478 | |
| 7479 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7480 | public int checkCarrierPrivilegesForPackage(int subId, String pkgName) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 7481 | enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage"); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7482 | if (TextUtils.isEmpty(pkgName)) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 7483 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7484 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7485 | Phone phone = getPhone(subId); |
| 7486 | if (phone == null) { |
| 7487 | loge("checkCarrierPrivilegesForPackage: Invalid subId"); |
| 7488 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 7489 | } |
| 7490 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7491 | if (cpt == null) { |
| 7492 | loge("checkCarrierPrivilegesForPackage: No CarrierPrivilegesTracker"); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 7493 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 7494 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7495 | return cpt.getCarrierPrivilegeStatusForPackage(pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 7496 | } |
| 7497 | |
| 7498 | @Override |
| 7499 | public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) { |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7500 | enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackageAnyPhone"); |
Rambo Wang | e7209ce | 2022-02-23 13:41:02 -0800 | [diff] [blame] | 7501 | return checkCarrierPrivilegesForPackageAnyPhoneWithPermission(pkgName); |
| 7502 | } |
| 7503 | |
| 7504 | private int checkCarrierPrivilegesForPackageAnyPhoneWithPermission(String pkgName) { |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7505 | if (TextUtils.isEmpty(pkgName)) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 7506 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7507 | } |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 7508 | int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7509 | for (int phoneId = 0; phoneId < TelephonyManager.getDefault().getPhoneCount(); phoneId++) { |
| 7510 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 7511 | if (phone == null) { |
| 7512 | continue; |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 7513 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7514 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7515 | if (cpt == null) { |
| 7516 | continue; |
| 7517 | } |
| 7518 | result = cpt.getCarrierPrivilegeStatusForPackage(pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 7519 | if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 7520 | break; |
| 7521 | } |
| 7522 | } |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 7523 | return result; |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 7524 | } |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 7525 | |
| 7526 | @Override |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 7527 | public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 7528 | enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone"); |
Rambo Wang | 8a247eb | 2022-02-08 21:11:18 +0000 | [diff] [blame] | 7529 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 7530 | if (phone == null) { |
| 7531 | return Collections.emptyList(); |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 7532 | } |
Rambo Wang | 8a247eb | 2022-02-08 21:11:18 +0000 | [diff] [blame] | 7533 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7534 | if (cpt == null) { |
| 7535 | return Collections.emptyList(); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 7536 | } |
Rambo Wang | 8a247eb | 2022-02-08 21:11:18 +0000 | [diff] [blame] | 7537 | return cpt.getCarrierPackageNamesForIntent(intent); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 7538 | } |
| 7539 | |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 7540 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7541 | public List<String> getPackagesWithCarrierPrivileges(int phoneId) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 7542 | enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges"); |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7543 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 7544 | if (phone == null) { |
| 7545 | return Collections.emptyList(); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 7546 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7547 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7548 | if (cpt == null) { |
| 7549 | return Collections.emptyList(); |
| 7550 | } |
| 7551 | return new ArrayList<>(cpt.getPackagesWithCarrierPrivileges()); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 7552 | } |
| 7553 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7554 | @Override |
| 7555 | public List<String> getPackagesWithCarrierPrivilegesForAllPhones() { |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 7556 | enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones"); |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7557 | Set<String> privilegedPackages = new ArraySet<>(); |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 7558 | final long identity = Binder.clearCallingIdentity(); |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 7559 | try { |
| 7560 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 7561 | privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i)); |
| 7562 | } |
| 7563 | } finally { |
| 7564 | Binder.restoreCallingIdentity(identity); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7565 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7566 | return new ArrayList<>(privilegedPackages); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7567 | } |
| 7568 | |
Rambo Wang | 6812ffb | 2022-03-15 16:54:17 -0700 | [diff] [blame] | 7569 | @Override |
| 7570 | public @Nullable String getCarrierServicePackageNameForLogicalSlot(int logicalSlotIndex) { |
| 7571 | enforceReadPrivilegedPermission("getCarrierServicePackageNameForLogicalSlot"); |
| 7572 | |
| 7573 | final Phone phone = PhoneFactory.getPhone(logicalSlotIndex); |
| 7574 | if (phone == null) { |
| 7575 | return null; |
| 7576 | } |
| 7577 | final CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7578 | if (cpt == null) { |
| 7579 | return null; |
| 7580 | } |
| 7581 | return cpt.getCarrierServicePackageName(); |
| 7582 | } |
| 7583 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 7584 | private String getIccId(int subId) { |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 7585 | final Phone phone = getPhone(subId); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 7586 | UiccPort port = phone == null ? null : phone.getUiccPort(); |
| 7587 | if (port == null) { |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7588 | return null; |
| 7589 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 7590 | String iccId = port.getIccId(); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7591 | if (TextUtils.isEmpty(iccId)) { |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7592 | return null; |
| 7593 | } |
| 7594 | return iccId; |
| 7595 | } |
| 7596 | |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 7597 | @Override |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 7598 | public void setCallComposerStatus(int subId, int status) { |
| 7599 | enforceModifyPermission(); |
| 7600 | |
| 7601 | final long identity = Binder.clearCallingIdentity(); |
| 7602 | try { |
| 7603 | Phone phone = getPhone(subId); |
| 7604 | if (phone != null) { |
| 7605 | Phone defaultPhone = phone.getImsPhone(); |
| 7606 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 7607 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 7608 | imsPhone.setCallComposerStatus(status); |
Shuo Qian | 284ae75 | 2020-12-22 19:10:14 -0800 | [diff] [blame] | 7609 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| 7610 | .updateImsServiceConfig(); |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 7611 | } |
| 7612 | } |
Shuo Qian | 284ae75 | 2020-12-22 19:10:14 -0800 | [diff] [blame] | 7613 | } catch (ImsException e) { |
| 7614 | throw new ServiceSpecificException(e.getCode()); |
| 7615 | } finally { |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 7616 | Binder.restoreCallingIdentity(identity); |
| 7617 | } |
| 7618 | } |
| 7619 | |
| 7620 | @Override |
| 7621 | public int getCallComposerStatus(int subId) { |
| 7622 | enforceReadPrivilegedPermission("getCallComposerStatus"); |
| 7623 | |
| 7624 | final long identity = Binder.clearCallingIdentity(); |
| 7625 | try { |
| 7626 | Phone phone = getPhone(subId); |
| 7627 | if (phone != null) { |
| 7628 | Phone defaultPhone = phone.getImsPhone(); |
| 7629 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 7630 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 7631 | return imsPhone.getCallComposerStatus(); |
| 7632 | } |
| 7633 | } |
| 7634 | } finally { |
| 7635 | Binder.restoreCallingIdentity(identity); |
| 7636 | } |
| 7637 | return TelephonyManager.CALL_COMPOSER_STATUS_OFF; |
| 7638 | } |
| 7639 | |
| 7640 | @Override |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7641 | public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag, |
| 7642 | String number) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 7643 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7644 | subId, "setLine1NumberForDisplayForSubscriber"); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7645 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7646 | final long identity = Binder.clearCallingIdentity(); |
| 7647 | try { |
| 7648 | final String iccId = getIccId(subId); |
| 7649 | final Phone phone = getPhone(subId); |
| 7650 | if (phone == null) { |
| 7651 | return false; |
| 7652 | } |
| 7653 | final String subscriberId = phone.getSubscriberId(); |
| 7654 | |
| 7655 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 7656 | Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId=" |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7657 | + subscriberId + " to " + number); |
| 7658 | } |
| 7659 | |
| 7660 | if (TextUtils.isEmpty(iccId)) { |
| 7661 | return false; |
| 7662 | } |
| 7663 | |
| 7664 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 7665 | |
| 7666 | final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 7667 | if (alphaTag == null) { |
| 7668 | editor.remove(alphaTagPrefKey); |
| 7669 | } else { |
| 7670 | editor.putString(alphaTagPrefKey, alphaTag); |
| 7671 | } |
| 7672 | |
| 7673 | // Record both the line number and IMSI for this ICCID, since we need to |
| 7674 | // track all merged IMSIs based on line number |
| 7675 | final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 7676 | final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 7677 | if (number == null) { |
| 7678 | editor.remove(numberPrefKey); |
| 7679 | editor.remove(subscriberPrefKey); |
| 7680 | } else { |
| 7681 | editor.putString(numberPrefKey, number); |
| 7682 | editor.putString(subscriberPrefKey, subscriberId); |
| 7683 | } |
| 7684 | |
| 7685 | editor.commit(); |
| 7686 | return true; |
| 7687 | } finally { |
| 7688 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 7689 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7690 | } |
| 7691 | |
| 7692 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7693 | public String getLine1NumberForDisplay(int subId, String callingPackage, |
| 7694 | String callingFeatureId) { |
Makoto Onuki | fee6934 | 2015-06-29 14:44:50 -0700 | [diff] [blame] | 7695 | // This is open to apps with WRITE_SMS. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7696 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7697 | mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) { |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 7698 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission"); |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 7699 | return null; |
| 7700 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7701 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7702 | final long identity = Binder.clearCallingIdentity(); |
| 7703 | try { |
| 7704 | String iccId = getIccId(subId); |
| 7705 | if (iccId != null) { |
| 7706 | String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 7707 | if (DBG_MERGE) { |
| 7708 | log("getLine1NumberForDisplay returning " |
| 7709 | + mTelephonySharedPreferences.getString(numberPrefKey, null)); |
| 7710 | } |
| 7711 | return mTelephonySharedPreferences.getString(numberPrefKey, null); |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 7712 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7713 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null"); |
| 7714 | return null; |
| 7715 | } finally { |
| 7716 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7717 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7718 | } |
| 7719 | |
| 7720 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7721 | public String getLine1AlphaTagForDisplay(int subId, String callingPackage, |
| 7722 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7723 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7724 | mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 7725 | return null; |
| 7726 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7727 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7728 | final long identity = Binder.clearCallingIdentity(); |
| 7729 | try { |
| 7730 | String iccId = getIccId(subId); |
| 7731 | if (iccId != null) { |
| 7732 | String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 7733 | return mTelephonySharedPreferences.getString(alphaTagPrefKey, null); |
| 7734 | } |
| 7735 | return null; |
| 7736 | } finally { |
| 7737 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7738 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7739 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 7740 | |
| 7741 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7742 | public String[] getMergedSubscriberIds(int subId, String callingPackage, |
| 7743 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7744 | // This API isn't public, so no need to provide a valid subscription ID - we're not worried |
| 7745 | // about carrier-privileged callers not having access. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7746 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7747 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7748 | callingFeatureId, "getMergedSubscriberIds")) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7749 | return null; |
| 7750 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7751 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 7752 | // Clear calling identity, when calling TelephonyManager, because callerUid must be |
| 7753 | // the process, where TelephonyManager was instantiated. |
| 7754 | // Otherwise AppOps check will fail. |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7755 | final long identity = Binder.clearCallingIdentity(); |
| 7756 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7757 | final Context context = mApp; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7758 | final TelephonyManager tele = TelephonyManager.from(context); |
| 7759 | final SubscriptionManager sub = SubscriptionManager.from(context); |
| 7760 | |
| 7761 | // Figure out what subscribers are currently active |
| 7762 | final ArraySet<String> activeSubscriberIds = new ArraySet<>(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7763 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 7764 | // Only consider subs which match the current subId |
| 7765 | // This logic can be simplified. See b/131189269 for progress. |
| 7766 | if (isActiveSubscription(subId)) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7767 | activeSubscriberIds.add(tele.getSubscriberId(subId)); |
| 7768 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7769 | |
| 7770 | // First pass, find a number override for an active subscriber |
| 7771 | String mergeNumber = null; |
| 7772 | final Map<String, ?> prefs = mTelephonySharedPreferences.getAll(); |
| 7773 | for (String key : prefs.keySet()) { |
| 7774 | if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) { |
| 7775 | final String subscriberId = (String) prefs.get(key); |
| 7776 | if (activeSubscriberIds.contains(subscriberId)) { |
| 7777 | final String iccId = key.substring( |
| 7778 | PREF_CARRIERS_SUBSCRIBER_PREFIX.length()); |
| 7779 | final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 7780 | mergeNumber = (String) prefs.get(numberKey); |
| 7781 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 7782 | Rlog.d(LOG_TAG, "Found line number " + mergeNumber |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7783 | + " for active subscriber " + subscriberId); |
| 7784 | } |
| 7785 | if (!TextUtils.isEmpty(mergeNumber)) { |
| 7786 | break; |
| 7787 | } |
| 7788 | } |
| 7789 | } |
| 7790 | } |
| 7791 | |
| 7792 | // Shortcut when no active merged subscribers |
| 7793 | if (TextUtils.isEmpty(mergeNumber)) { |
| 7794 | return null; |
| 7795 | } |
| 7796 | |
| 7797 | // Second pass, find all subscribers under that line override |
| 7798 | final ArraySet<String> result = new ArraySet<>(); |
| 7799 | for (String key : prefs.keySet()) { |
| 7800 | if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) { |
| 7801 | final String number = (String) prefs.get(key); |
| 7802 | if (mergeNumber.equals(number)) { |
| 7803 | final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length()); |
| 7804 | final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 7805 | final String subscriberId = (String) prefs.get(subscriberKey); |
| 7806 | if (!TextUtils.isEmpty(subscriberId)) { |
| 7807 | result.add(subscriberId); |
| 7808 | } |
| 7809 | } |
| 7810 | } |
| 7811 | } |
| 7812 | |
| 7813 | final String[] resultArray = result.toArray(new String[result.size()]); |
| 7814 | Arrays.sort(resultArray); |
| 7815 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 7816 | Rlog.d(LOG_TAG, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7817 | "Found subscribers " + Arrays.toString(resultArray) + " after merge"); |
| 7818 | } |
| 7819 | return resultArray; |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7820 | } finally { |
| 7821 | Binder.restoreCallingIdentity(identity); |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7822 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7823 | } |
| 7824 | |
| 7825 | @Override |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 7826 | public String[] getMergedImsisFromGroup(int subId, String callingPackage) { |
| 7827 | enforceReadPrivilegedPermission("getMergedImsisFromGroup"); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7828 | |
| 7829 | final long identity = Binder.clearCallingIdentity(); |
| 7830 | try { |
| 7831 | final TelephonyManager telephonyManager = mApp.getSystemService( |
| 7832 | TelephonyManager.class); |
| 7833 | String subscriberId = telephonyManager.getSubscriberId(subId); |
| 7834 | if (subscriberId == null) { |
| 7835 | if (DBG) { |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 7836 | log("getMergedImsisFromGroup can't find subscriberId for subId " |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7837 | + subId); |
| 7838 | } |
| 7839 | return null; |
| 7840 | } |
| 7841 | |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 7842 | ParcelUuid groupUuid; |
| 7843 | if (PhoneFactory.isSubscriptionManagerServiceEnabled()) { |
| 7844 | final SubscriptionInfo info = SubscriptionManagerService.getInstance() |
| 7845 | .getSubscriptionInfo(subId); |
| 7846 | groupUuid = info.getGroupUuid(); |
| 7847 | } else { |
| 7848 | final SubscriptionInfo info = mSubscriptionController |
| 7849 | .getSubscriptionInfo(subId); |
| 7850 | groupUuid = info.getGroupUuid(); |
| 7851 | } |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7852 | // If it doesn't belong to any group, return just subscriberId of itself. |
| 7853 | if (groupUuid == null) { |
| 7854 | return new String[]{subscriberId}; |
| 7855 | } |
| 7856 | |
| 7857 | // Get all subscriberIds from the group. |
| 7858 | final List<String> mergedSubscriberIds = new ArrayList<>(); |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 7859 | List<SubscriptionInfo> groupInfos; |
| 7860 | if (PhoneFactory.isSubscriptionManagerServiceEnabled()) { |
| 7861 | groupInfos = SubscriptionManagerService.getInstance() |
| 7862 | .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(), |
| 7863 | mApp.getAttributionTag()); |
| 7864 | } else { |
| 7865 | groupInfos = mSubscriptionController |
| 7866 | .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(), |
| 7867 | mApp.getAttributionTag()); |
| 7868 | } |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7869 | for (SubscriptionInfo subInfo : groupInfos) { |
| 7870 | subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId()); |
| 7871 | if (subscriberId != null) { |
| 7872 | mergedSubscriberIds.add(subscriberId); |
| 7873 | } |
| 7874 | } |
| 7875 | |
| 7876 | return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]); |
| 7877 | } finally { |
| 7878 | Binder.restoreCallingIdentity(identity); |
| 7879 | |
| 7880 | } |
| 7881 | } |
| 7882 | |
| 7883 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7884 | public boolean setOperatorBrandOverride(int subId, String brand) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 7885 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7886 | subId, "setOperatorBrandOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7887 | |
| 7888 | final long identity = Binder.clearCallingIdentity(); |
| 7889 | try { |
| 7890 | final Phone phone = getPhone(subId); |
| 7891 | return phone == null ? false : phone.setOperatorBrandOverride(brand); |
| 7892 | } finally { |
| 7893 | Binder.restoreCallingIdentity(identity); |
| 7894 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 7895 | } |
Steven Liu | 4bf01bc | 2014-07-17 11:05:29 -0500 | [diff] [blame] | 7896 | |
| 7897 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7898 | public boolean setRoamingOverride(int subId, List<String> gsmRoamingList, |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 7899 | List<String> gsmNonRoamingList, List<String> cdmaRoamingList, |
| 7900 | List<String> cdmaNonRoamingList) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 7901 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 7902 | mApp, subId, "setRoamingOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7903 | |
| 7904 | final long identity = Binder.clearCallingIdentity(); |
| 7905 | try { |
| 7906 | final Phone phone = getPhone(subId); |
| 7907 | if (phone == null) { |
| 7908 | return false; |
| 7909 | } |
| 7910 | return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList, |
| 7911 | cdmaNonRoamingList); |
| 7912 | } finally { |
| 7913 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7914 | } |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 7915 | } |
| 7916 | |
| 7917 | @Override |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 7918 | @Deprecated |
| 7919 | public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) { |
| 7920 | enforceModifyPermission(); |
| 7921 | |
| 7922 | int returnValue = 0; |
| 7923 | try { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7924 | AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 7925 | if(result.exception == null) { |
| 7926 | if (result.result != null) { |
| 7927 | byte[] responseData = (byte[])(result.result); |
| 7928 | if(responseData.length > oemResp.length) { |
| 7929 | Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " + |
| 7930 | responseData.length + "bytes. Buffer Size is " + |
| 7931 | oemResp.length + "bytes."); |
| 7932 | } |
| 7933 | System.arraycopy(responseData, 0, oemResp, 0, responseData.length); |
| 7934 | returnValue = responseData.length; |
| 7935 | } |
| 7936 | } else { |
| 7937 | CommandException ex = (CommandException) result.exception; |
| 7938 | returnValue = ex.getCommandError().ordinal(); |
| 7939 | if(returnValue > 0) returnValue *= -1; |
| 7940 | } |
| 7941 | } catch (RuntimeException e) { |
| 7942 | Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception"); |
| 7943 | returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal()); |
| 7944 | if(returnValue > 0) returnValue *= -1; |
| 7945 | } |
| 7946 | |
| 7947 | return returnValue; |
| 7948 | } |
| 7949 | |
| 7950 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 7951 | public int getRadioAccessFamily(int phoneId, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7952 | Phone phone = PhoneFactory.getPhone(phoneId); |
Shuo Qian | dee5340 | 2020-05-29 14:08:15 -0700 | [diff] [blame] | 7953 | try { |
| 7954 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 7955 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Shuo Qian | dee5340 | 2020-05-29 14:08:15 -0700 | [diff] [blame] | 7956 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 7957 | } catch (SecurityException e) { |
| 7958 | EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission"); |
| 7959 | throw e; |
| 7960 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7961 | int raf = RadioAccessFamily.RAF_UNKNOWN; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7962 | if (phone == null) { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7963 | return raf; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7964 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7965 | final long identity = Binder.clearCallingIdentity(); |
| 7966 | try { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7967 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 7968 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7969 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 7970 | raf = ProxyController.getInstance().getRadioAccessFamily(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7971 | } finally { |
| 7972 | Binder.restoreCallingIdentity(identity); |
| 7973 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7974 | return raf; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 7975 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7976 | |
| 7977 | @Override |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7978 | public void uploadCallComposerPicture(int subscriptionId, String callingPackage, |
Hall Liu | e31bac6 | 2020-12-23 19:16:10 -0800 | [diff] [blame] | 7979 | String contentType, ParcelFileDescriptor fd, ResultReceiver callback) { |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7980 | try { |
| 7981 | if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0), |
| 7982 | Binder.getCallingUid())) { |
Tyler Gunn | b87925a | 2021-06-10 14:54:27 -0700 | [diff] [blame] | 7983 | throw new SecurityException("Invalid package:" + callingPackage); |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7984 | } |
| 7985 | } catch (PackageManager.NameNotFoundException e) { |
Tyler Gunn | b87925a | 2021-06-10 14:54:27 -0700 | [diff] [blame] | 7986 | throw new SecurityException("Invalid package:" + callingPackage); |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7987 | } |
| 7988 | RoleManager rm = mApp.getSystemService(RoleManager.class); |
| 7989 | List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER); |
| 7990 | if (!dialerRoleHolders.contains(callingPackage)) { |
| 7991 | throw new SecurityException("App must be the dialer role holder to" |
| 7992 | + " upload a call composer pic"); |
| 7993 | } |
| 7994 | |
| 7995 | Executors.newSingleThreadExecutor().execute(() -> { |
| 7996 | ByteArrayOutputStream output = new ByteArrayOutputStream( |
| 7997 | (int) TelephonyManager.getMaximumCallComposerPictureSize()); |
| 7998 | InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd); |
| 7999 | boolean readUntilEnd = false; |
| 8000 | int totalBytesRead = 0; |
| 8001 | byte[] buffer = new byte[16 * 1024]; |
| 8002 | while (true) { |
| 8003 | int numRead; |
| 8004 | try { |
| 8005 | numRead = input.read(buffer); |
| 8006 | } catch (IOException e) { |
| 8007 | try { |
| 8008 | fd.checkError(); |
| 8009 | callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED, |
| 8010 | null); |
| 8011 | } catch (IOException e1) { |
| 8012 | // This means that the other side closed explicitly with an error. If this |
| 8013 | // happens, log and ignore. |
| 8014 | loge("Remote end of call composer picture pipe closed: " + e1); |
| 8015 | } |
| 8016 | break; |
| 8017 | } |
| 8018 | if (numRead == -1) { |
| 8019 | readUntilEnd = true; |
| 8020 | break; |
| 8021 | } |
| 8022 | totalBytesRead += numRead; |
| 8023 | if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) { |
| 8024 | loge("Too many bytes read for call composer picture: " + totalBytesRead); |
| 8025 | try { |
| 8026 | input.close(); |
| 8027 | } catch (IOException e) { |
| 8028 | // ignore |
| 8029 | } |
| 8030 | break; |
| 8031 | } |
| 8032 | output.write(buffer, 0, numRead); |
| 8033 | } |
| 8034 | // Generally, the remote end will close the file descriptors. The only case where we |
| 8035 | // close is above, where the picture size is too big. |
| 8036 | |
| 8037 | try { |
| 8038 | fd.checkError(); |
| 8039 | } catch (IOException e) { |
| 8040 | loge("Remote end for call composer closed with an error: " + e); |
| 8041 | return; |
| 8042 | } |
| 8043 | |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 8044 | if (!readUntilEnd) { |
| 8045 | loge("Did not finish reading entire image; aborting"); |
| 8046 | return; |
| 8047 | } |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 8048 | |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 8049 | ImageData imageData = new ImageData(output.toByteArray(), contentType, null); |
| 8050 | CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer( |
| 8051 | new CallComposerPictureTransfer.Factory() {}, |
| 8052 | imageData, |
| 8053 | (result) -> { |
| 8054 | if (result.first != null) { |
| 8055 | ParcelUuid parcelUuid = new ParcelUuid(result.first); |
| 8056 | Bundle outputResult = new Bundle(); |
| 8057 | outputResult.putParcelable( |
| 8058 | TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid); |
| 8059 | callback.send(TelephonyManager.CallComposerException.SUCCESS, |
| 8060 | outputResult); |
| 8061 | } else { |
| 8062 | callback.send(result.second, null); |
| 8063 | } |
| 8064 | } |
| 8065 | ); |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 8066 | }); |
| 8067 | } |
| 8068 | |
| 8069 | @Override |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 8070 | public void enableVideoCalling(boolean enable) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8071 | final Phone defaultPhone = getDefaultPhone(); |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 8072 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8073 | |
| 8074 | final long identity = Binder.clearCallingIdentity(); |
| 8075 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8076 | ImsManager.getInstance(defaultPhone.getContext(), |
| 8077 | defaultPhone.getPhoneId()).setVtSetting(enable); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8078 | } finally { |
| 8079 | Binder.restoreCallingIdentity(identity); |
| 8080 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 8081 | } |
| 8082 | |
| 8083 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8084 | public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8085 | final Phone defaultPhone = getDefaultPhone(); |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8086 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 8087 | callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 8088 | return false; |
| 8089 | } |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 8090 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8091 | final long identity = Binder.clearCallingIdentity(); |
| 8092 | try { |
| 8093 | // Check the user preference and the system-level IMS setting. Even if the user has |
| 8094 | // enabled video calling, if IMS is disabled we aren't able to support video calling. |
| 8095 | // In the long run, we may instead need to check if there exists a connection service |
| 8096 | // which can support video calling. |
| 8097 | ImsManager imsManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8098 | ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8099 | return imsManager.isVtEnabledByPlatform() |
| 8100 | && imsManager.isEnhanced4gLteModeSettingEnabledByUser() |
| 8101 | && imsManager.isVtEnabledByUser(); |
| 8102 | } finally { |
| 8103 | Binder.restoreCallingIdentity(identity); |
| 8104 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 8105 | } |
Libin.Tang@motorola.com | afe8264 | 2014-12-18 13:27:53 -0600 | [diff] [blame] | 8106 | |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 8107 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8108 | public boolean canChangeDtmfToneLength(int subId, String callingPackage, |
| 8109 | String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8110 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8111 | mApp, subId, callingPackage, callingFeatureId, |
| 8112 | "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8113 | return false; |
| 8114 | } |
| 8115 | |
| 8116 | final long identity = Binder.clearCallingIdentity(); |
| 8117 | try { |
| 8118 | CarrierConfigManager configManager = |
| 8119 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8120 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8121 | .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL); |
| 8122 | } finally { |
| 8123 | Binder.restoreCallingIdentity(identity); |
| 8124 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 8125 | } |
| 8126 | |
| 8127 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8128 | public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8129 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8130 | mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8131 | return false; |
| 8132 | } |
| 8133 | |
| 8134 | final long identity = Binder.clearCallingIdentity(); |
| 8135 | try { |
| 8136 | CarrierConfigManager configManager = |
| 8137 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8138 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8139 | .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL); |
| 8140 | } finally { |
| 8141 | Binder.restoreCallingIdentity(identity); |
| 8142 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 8143 | } |
| 8144 | |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 8145 | @Override |
| 8146 | public boolean isTtyModeSupported() { |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 8147 | TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class); |
Wooki Wu | 1f82f7a | 2016-02-15 15:59:58 +0800 | [diff] [blame] | 8148 | return telecomManager.isTtySupported(); |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 8149 | } |
| 8150 | |
| 8151 | @Override |
| 8152 | public boolean isHearingAidCompatibilitySupported() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8153 | final long identity = Binder.clearCallingIdentity(); |
| 8154 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8155 | return mApp.getResources().getBoolean(R.bool.hac_enabled); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8156 | } finally { |
| 8157 | Binder.restoreCallingIdentity(identity); |
| 8158 | } |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 8159 | } |
| 8160 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 8161 | /** |
| 8162 | * Determines whether the device currently supports RTT (Real-time text). Based both on carrier |
| 8163 | * support for the feature and device firmware support. |
| 8164 | * |
| 8165 | * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise. |
| 8166 | */ |
| 8167 | @Override |
| 8168 | public boolean isRttSupported(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8169 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8170 | final Phone phone = getPhone(subscriptionId); |
| 8171 | if (phone == null) { |
| 8172 | loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId); |
| 8173 | return false; |
| 8174 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8175 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8176 | boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8177 | CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL); |
| 8178 | boolean isDeviceSupported = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8179 | phone.getContext().getResources().getBoolean(R.bool.config_support_rtt); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8180 | return isCarrierSupported && isDeviceSupported; |
| 8181 | } finally { |
| 8182 | Binder.restoreCallingIdentity(identity); |
| 8183 | } |
Hall Liu | 9818758 | 2018-01-22 19:15:32 -0800 | [diff] [blame] | 8184 | } |
| 8185 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 8186 | /** |
Hall Liu | f2daa02 | 2019-07-23 18:39:00 -0700 | [diff] [blame] | 8187 | * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set |
| 8188 | * RTT setting, will return true if the device and carrier both support RTT. |
| 8189 | * 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] | 8190 | */ |
| 8191 | public boolean isRttEnabled(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8192 | final long identity = Binder.clearCallingIdentity(); |
| 8193 | try { |
Hall Liu | 5bab75c | 2019-12-11 23:58:20 +0000 | [diff] [blame] | 8194 | boolean isRttSupported = isRttSupported(subscriptionId); |
| 8195 | boolean isUserRttSettingOn = Settings.Secure.getInt( |
| 8196 | mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0; |
| 8197 | boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId) |
| 8198 | .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL); |
| 8199 | return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8200 | } finally { |
| 8201 | Binder.restoreCallingIdentity(identity); |
| 8202 | } |
Hall Liu | 3ad5f01 | 2018-04-06 16:23:39 -0700 | [diff] [blame] | 8203 | } |
| 8204 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8205 | @Deprecated |
| 8206 | @Override |
| 8207 | public String getDeviceId(String callingPackage) { |
| 8208 | return getDeviceIdWithFeature(callingPackage, null); |
| 8209 | } |
| 8210 | |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 8211 | /** |
| 8212 | * Returns the unique device ID of phone, for example, the IMEI for |
| 8213 | * GSM and the MEID for CDMA phones. Return null if device ID is not available. |
| 8214 | * |
| 8215 | * <p>Requires Permission: |
| 8216 | * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} |
| 8217 | */ |
| 8218 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8219 | public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) { |
Shuo Qian | 13d8915 | 2021-05-10 23:58:11 -0700 | [diff] [blame] | 8220 | try { |
| 8221 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 8222 | } catch (SecurityException se) { |
| 8223 | EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid()); |
| 8224 | throw new SecurityException("Package " + callingPackage + " does not belong to " |
| 8225 | + Binder.getCallingUid()); |
| 8226 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 8227 | final Phone phone = PhoneFactory.getPhone(0); |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 8228 | if (phone == null) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 8229 | return null; |
| 8230 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 8231 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 8232 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8233 | callingPackage, callingFeatureId, "getDeviceId")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 8234 | return null; |
| 8235 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8236 | |
| 8237 | final long identity = Binder.clearCallingIdentity(); |
| 8238 | try { |
| 8239 | return phone.getDeviceId(); |
| 8240 | } finally { |
| 8241 | Binder.restoreCallingIdentity(identity); |
| 8242 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 8243 | } |
| 8244 | |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 8245 | /** |
| 8246 | * {@hide} |
| 8247 | * Returns the IMS Registration Status on a particular subid |
| 8248 | * |
| 8249 | * @param subId |
| 8250 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8251 | public boolean isImsRegistered(int subId) { |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 8252 | Phone phone = getPhone(subId); |
| 8253 | if (phone != null) { |
| 8254 | return phone.isImsRegistered(); |
| 8255 | } else { |
| 8256 | return false; |
| 8257 | } |
| 8258 | } |
| 8259 | |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 8260 | @Override |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 8261 | public int getSubIdForPhoneAccountHandle( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8262 | PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) { |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 8263 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(), |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8264 | callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) { |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 8265 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 8266 | } |
| 8267 | final long identity = Binder.clearCallingIdentity(); |
| 8268 | try { |
| 8269 | return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle); |
| 8270 | } finally { |
| 8271 | Binder.restoreCallingIdentity(identity); |
| 8272 | } |
| 8273 | } |
| 8274 | |
| 8275 | @Override |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 8276 | public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) { |
Alireza Forouzan | 4ac4f98 | 2021-03-16 22:18:52 -0700 | [diff] [blame] | 8277 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 8278 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame^] | 8279 | mApp, |
| 8280 | subscriptionId, |
| 8281 | "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: " |
| 8282 | + subscriptionId); |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 8283 | final long identity = Binder.clearCallingIdentity(); |
| 8284 | try { |
| 8285 | Phone phone = getPhone(subscriptionId); |
| 8286 | if (phone == null) { |
| 8287 | return null; |
| 8288 | } |
| 8289 | return PhoneUtils.makePstnPhoneAccountHandle(phone); |
| 8290 | } finally { |
| 8291 | Binder.restoreCallingIdentity(identity); |
| 8292 | } |
| 8293 | } |
| 8294 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8295 | /** |
| 8296 | * @return the VoWiFi calling availability. |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 8297 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8298 | public boolean isWifiCallingAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8299 | final long identity = Binder.clearCallingIdentity(); |
| 8300 | try { |
| 8301 | Phone phone = getPhone(subId); |
| 8302 | if (phone != null) { |
| 8303 | return phone.isWifiCallingEnabled(); |
| 8304 | } else { |
| 8305 | return false; |
| 8306 | } |
| 8307 | } finally { |
| 8308 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8309 | } |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 8310 | } |
| 8311 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8312 | /** |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8313 | * @return the VT calling availability. |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 8314 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8315 | public boolean isVideoTelephonyAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8316 | final long identity = Binder.clearCallingIdentity(); |
| 8317 | try { |
| 8318 | Phone phone = getPhone(subId); |
| 8319 | if (phone != null) { |
| 8320 | return phone.isVideoEnabled(); |
| 8321 | } else { |
| 8322 | return false; |
| 8323 | } |
| 8324 | } finally { |
| 8325 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8326 | } |
| 8327 | } |
| 8328 | |
| 8329 | /** |
| 8330 | * @return the IMS registration technology for the MMTEL feature. Valid return values are |
| 8331 | * defined in {@link ImsRegistrationImplBase}. |
| 8332 | */ |
| 8333 | public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8334 | final long identity = Binder.clearCallingIdentity(); |
| 8335 | try { |
| 8336 | Phone phone = getPhone(subId); |
| 8337 | if (phone != null) { |
| 8338 | return phone.getImsRegistrationTech(); |
| 8339 | } else { |
| 8340 | return ImsRegistrationImplBase.REGISTRATION_TECH_NONE; |
| 8341 | } |
| 8342 | } finally { |
| 8343 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8344 | } |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 8345 | } |
| 8346 | |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 8347 | @Override |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 8348 | public void factoryReset(int subId, String callingPackage) { |
paulhu | 5a77360 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 8349 | enforceSettingsPermission(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 8350 | if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) { |
| 8351 | return; |
| 8352 | } |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 8353 | Phone defaultPhone = getDefaultPhone(); |
| 8354 | if (defaultPhone != null) { |
| 8355 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8356 | mApp, getDefaultPhone().getSubId(), "factoryReset"); |
| 8357 | } |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 8358 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8359 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 8360 | try { |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 8361 | if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction( |
| 8362 | UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 8363 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 8364 | getDefaultDataEnabled(), callingPackage); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 8365 | setNetworkSelectionModeAutomatic(subId); |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 8366 | Phone phone = getPhone(subId); |
SongFerngWang | fd89b10 | 2021-05-27 22:44:54 +0800 | [diff] [blame] | 8367 | cleanUpAllowedNetworkTypes(phone, subId); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8368 | setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId)); |
Jordan Liu | 857e73a | 2021-03-05 16:24:04 -0800 | [diff] [blame] | 8369 | getPhone(subId).resetCarrierKeysForImsiEncryption(); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 8370 | } |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 8371 | // There has been issues when Sms raw table somehow stores orphan |
| 8372 | // fragments. They lead to garbled message when new fragments come |
| 8373 | // in and combined with those stale ones. In case this happens again, |
| 8374 | // user can reset all network settings which will clean up this table. |
| 8375 | cleanUpSmsRawTable(getDefaultPhone().getContext()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 8376 | // Clean up IMS settings as well here. |
| 8377 | int slotId = getSlotIndex(subId); |
| 8378 | if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 8379 | ImsManager.getInstance(mApp, slotId).factoryReset(); |
| 8380 | } |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 8381 | |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 8382 | if (defaultPhone == null) { |
| 8383 | return; |
| 8384 | } |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 8385 | // Erase modem config if erase modem on network setting is enabled. |
| 8386 | String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY, |
| 8387 | RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED); |
| 8388 | if (configValue != null && Boolean.parseBoolean(configValue)) { |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 8389 | sendEraseModemConfig(defaultPhone); |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 8390 | } |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 8391 | |
| 8392 | sendEraseDataInSharedPreferences(defaultPhone); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 8393 | } finally { |
| 8394 | Binder.restoreCallingIdentity(identity); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 8395 | } |
| 8396 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 8397 | |
SongFerngWang | fd89b10 | 2021-05-27 22:44:54 +0800 | [diff] [blame] | 8398 | @VisibleForTesting |
| 8399 | void cleanUpAllowedNetworkTypes(Phone phone, int subId) { |
| 8400 | if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) { |
| 8401 | return; |
| 8402 | } |
| 8403 | long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType( |
| 8404 | RILConstants.PREFERRED_NETWORK_MODE); |
| 8405 | SubscriptionManager.setSubscriptionProperty(subId, |
| 8406 | SubscriptionManager.ALLOWED_NETWORK_TYPES, |
| 8407 | "user=" + defaultNetworkType); |
| 8408 | phone.loadAllowedNetworksFromSubscriptionDatabase(); |
| 8409 | phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER, |
| 8410 | defaultNetworkType, null); |
| 8411 | } |
| 8412 | |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 8413 | private void cleanUpSmsRawTable(Context context) { |
| 8414 | ContentResolver resolver = context.getContentResolver(); |
| 8415 | Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete"); |
| 8416 | resolver.delete(uri, null, null); |
| 8417 | } |
| 8418 | |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 8419 | @Override |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 8420 | public String getSimLocaleForSubscriber(int subId) { |
| 8421 | enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId); |
| 8422 | final Phone phone = getPhone(subId); |
| 8423 | if (phone == null) { |
| 8424 | log("getSimLocaleForSubscriber, invalid subId"); |
chen xu | 2bb91e4 | 2019-01-24 14:35:54 -0800 | [diff] [blame] | 8425 | return null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 8426 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8427 | final long identity = Binder.clearCallingIdentity(); |
| 8428 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 8429 | SubscriptionInfo info; |
| 8430 | if (PhoneFactory.isSubscriptionManagerServiceEnabled()) { |
| 8431 | info = SubscriptionManagerService.getInstance().getActiveSubscriptionInfo(subId, |
| 8432 | phone.getContext().getOpPackageName(), |
| 8433 | phone.getContext().getAttributionTag()); |
| 8434 | if (info == null) { |
| 8435 | log("getSimLocaleForSubscriber, inactive subId: " + subId); |
| 8436 | return null; |
| 8437 | } |
| 8438 | } else { |
| 8439 | info = mSubscriptionController.getActiveSubscriptionInfo(subId, |
| 8440 | phone.getContext().getOpPackageName(), |
| 8441 | phone.getContext().getAttributionTag()); |
| 8442 | if (info == null) { |
| 8443 | log("getSimLocaleForSubscriber, inactive subId: " + subId); |
| 8444 | return null; |
| 8445 | } |
chen xu | 6291c47 | 2019-02-04 12:55:53 -0800 | [diff] [blame] | 8446 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8447 | // Try and fetch the locale from the carrier properties or from the SIM language |
| 8448 | // preferences (EF-PL and EF-LI)... |
| 8449 | final int mcc = info.getMcc(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8450 | String simLanguage = null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 8451 | final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs(); |
| 8452 | if (localeFromDefaultSim != null) { |
| 8453 | if (!localeFromDefaultSim.getCountry().isEmpty()) { |
| 8454 | if (DBG) log("Using locale from subId: " + subId + " locale: " |
| 8455 | + localeFromDefaultSim); |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 8456 | return matchLocaleFromSupportedLocaleList(phone, localeFromDefaultSim); |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 8457 | } else { |
| 8458 | simLanguage = localeFromDefaultSim.getLanguage(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8459 | } |
| 8460 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 8461 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8462 | // The SIM language preferences only store a language (e.g. fr = French), not an |
| 8463 | // exact locale (e.g. fr_FR = French/France). So, if the locale returned from |
| 8464 | // the SIM and carrier preferences does not include a country we add the country |
| 8465 | // determined from the SIM MCC to provide an exact locale. |
zoey chen | c730df8 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 8466 | final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8467 | if (mccLocale != null) { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 8468 | if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale); |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 8469 | return matchLocaleFromSupportedLocaleList(phone, mccLocale); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8470 | } |
| 8471 | |
| 8472 | if (DBG) log("No locale found - returning null"); |
| 8473 | return null; |
| 8474 | } finally { |
| 8475 | Binder.restoreCallingIdentity(identity); |
| 8476 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 8477 | } |
| 8478 | |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 8479 | @VisibleForTesting |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 8480 | String matchLocaleFromSupportedLocaleList(Phone phone, @NonNull Locale inputLocale) { |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 8481 | String[] supportedLocale = com.android.internal.app.LocalePicker.getSupportedLocales( |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 8482 | phone.getContext()); |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 8483 | for (String localeTag : supportedLocale) { |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 8484 | if (LocaleList.matchesLanguageAndScript(inputLocale, Locale.forLanguageTag(localeTag)) |
| 8485 | && TextUtils.equals(inputLocale.getCountry(), |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 8486 | Locale.forLanguageTag(localeTag).getCountry())) { |
| 8487 | return localeTag; |
| 8488 | } |
| 8489 | } |
| 8490 | return inputLocale.toLanguageTag(); |
| 8491 | } |
| 8492 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8493 | /** |
| 8494 | * NOTE: this method assumes permission checks are done and caller identity has been cleared. |
| 8495 | */ |
| 8496 | private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 8497 | if (PhoneFactory.isSubscriptionManagerServiceEnabled()) { |
| 8498 | return SubscriptionManagerService.getInstance().getActiveSubscriptionInfoList( |
| 8499 | mApp.getOpPackageName(), mApp.getAttributionTag()); |
| 8500 | } |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8501 | return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(), |
Philip P. Moltmann | 8d34f0c | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 8502 | mApp.getAttributionTag()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 8503 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 8504 | |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8505 | private ActivityStatsTechSpecificInfo[] mLastModemActivitySpecificInfo = null; |
| 8506 | private ModemActivityInfo mLastModemActivityInfo = null; |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 8507 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 8508 | /** |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 8509 | * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object |
| 8510 | * representing the state of the modem. |
| 8511 | * |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 8512 | * NOTE: The underlying implementation clears the modem state, so there should only ever be one |
| 8513 | * caller to it. Everyone should call this class to get cumulative data. |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 8514 | * @hide |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 8515 | */ |
| 8516 | @Override |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 8517 | public void requestModemActivityInfo(ResultReceiver result) { |
| 8518 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8519 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8520 | |
| 8521 | final long identity = Binder.clearCallingIdentity(); |
| 8522 | try { |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 8523 | sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8524 | } finally { |
| 8525 | Binder.restoreCallingIdentity(identity); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 8526 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 8527 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8528 | |
Gary Jian | 76280a4 | 2022-12-07 16:18:33 +0800 | [diff] [blame] | 8529 | // Checks that ModemActivityInfo is valid. Sleep time and Idle time should be |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 8530 | // less than total activity duration. |
| 8531 | private boolean isModemActivityInfoValid(ModemActivityInfo info) { |
| 8532 | if (info == null) { |
| 8533 | return false; |
| 8534 | } |
| 8535 | int activityDurationMs = |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 8536 | (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis()); |
Gary Jian | 76280a4 | 2022-12-07 16:18:33 +0800 | [diff] [blame] | 8537 | activityDurationMs += MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS; |
| 8538 | |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 8539 | int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum(); |
| 8540 | |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 8541 | return (info.isValid() |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame^] | 8542 | && (info.getSleepTimeMillis() <= activityDurationMs) |
| 8543 | && (info.getIdleTimeMillis() <= activityDurationMs)); |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 8544 | } |
| 8545 | |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8546 | private void updateLastModemActivityInfo(ModemActivityInfo info, int rat, int freq) { |
| 8547 | int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()]; |
| 8548 | int[] txTimeMs = info.getTransmitTimeMillis(rat, freq); |
| 8549 | int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat, freq); |
| 8550 | |
| 8551 | for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) { |
| 8552 | mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl]; |
| 8553 | } |
| 8554 | |
| 8555 | mLastModemActivityInfo.setTransmitTimeMillis(rat, freq, mergedTxTimeMs); |
| 8556 | mLastModemActivityInfo.setReceiveTimeMillis( |
| 8557 | rat, |
| 8558 | freq, |
| 8559 | info.getReceiveTimeMillis(rat, freq) |
| 8560 | + mLastModemActivityInfo.getReceiveTimeMillis(rat, freq)); |
| 8561 | } |
| 8562 | |
| 8563 | private void updateLastModemActivityInfo(ModemActivityInfo info, int rat) { |
| 8564 | int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()]; |
| 8565 | int[] txTimeMs = info.getTransmitTimeMillis(rat); |
| 8566 | int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat); |
| 8567 | |
| 8568 | for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) { |
| 8569 | mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl]; |
| 8570 | } |
| 8571 | mLastModemActivityInfo.setTransmitTimeMillis(rat, mergedTxTimeMs); |
| 8572 | mLastModemActivityInfo.setReceiveTimeMillis( |
| 8573 | rat, |
| 8574 | info.getReceiveTimeMillis(rat) + mLastModemActivityInfo.getReceiveTimeMillis(rat)); |
| 8575 | } |
| 8576 | |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame^] | 8577 | /** |
| 8578 | * Merge this ModemActivityInfo with mLastModemActivitySpecificInfo |
| 8579 | * @param info recent ModemActivityInfo |
| 8580 | */ |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8581 | private void mergeModemActivityInfo(ModemActivityInfo info) { |
| 8582 | List<ActivityStatsTechSpecificInfo> merged = new ArrayList<>(); |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 8583 | ActivityStatsTechSpecificInfo deltaSpecificInfo; |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8584 | boolean matched; |
| 8585 | for (int i = 0; i < info.getSpecificInfoLength(); i++) { |
| 8586 | matched = false; |
| 8587 | int rat = info.getSpecificInfoRat(i); |
| 8588 | int freq = info.getSpecificInfoFrequencyRange(i); |
| 8589 | //Check each ActivityStatsTechSpecificInfo in this ModemActivityInfo for new rat returns |
| 8590 | //Add a new ActivityStatsTechSpecificInfo if is a new rat, and merge with the original |
| 8591 | //if it already exists |
| 8592 | for (int j = 0; j < mLastModemActivitySpecificInfo.length; j++) { |
| 8593 | if (rat == mLastModemActivityInfo.getSpecificInfoRat(j) && !matched) { |
| 8594 | //Merged based on frequency range (MMWAVE vs SUB6) for 5G |
| 8595 | if (rat == AccessNetworkConstants.AccessNetworkType.NGRAN) { |
| 8596 | if (freq == mLastModemActivityInfo.getSpecificInfoFrequencyRange(j)) { |
| 8597 | updateLastModemActivityInfo(info, rat, freq); |
| 8598 | matched = true; |
| 8599 | } |
| 8600 | } else { |
| 8601 | updateLastModemActivityInfo(info, rat); |
| 8602 | matched = true; |
| 8603 | } |
| 8604 | } |
| 8605 | } |
| 8606 | |
| 8607 | if (!matched) { |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 8608 | deltaSpecificInfo = |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8609 | new ActivityStatsTechSpecificInfo( |
| 8610 | rat, |
| 8611 | freq, |
| 8612 | info.getTransmitTimeMillis(rat, freq), |
| 8613 | (int) info.getReceiveTimeMillis(rat, freq)); |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 8614 | merged.addAll(Arrays.asList(deltaSpecificInfo)); |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8615 | } |
| 8616 | } |
| 8617 | merged.addAll(Arrays.asList(mLastModemActivitySpecificInfo)); |
| 8618 | mLastModemActivitySpecificInfo = |
| 8619 | new ActivityStatsTechSpecificInfo[merged.size()]; |
| 8620 | merged.toArray(mLastModemActivitySpecificInfo); |
| 8621 | |
| 8622 | mLastModemActivityInfo.setTimestamp(info.getTimestampMillis()); |
| 8623 | mLastModemActivityInfo.setSleepTimeMillis( |
| 8624 | info.getSleepTimeMillis() |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame^] | 8625 | + mLastModemActivityInfo.getSleepTimeMillis()); |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8626 | mLastModemActivityInfo.setIdleTimeMillis( |
| 8627 | info.getIdleTimeMillis() |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame^] | 8628 | + mLastModemActivityInfo.getIdleTimeMillis()); |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 8629 | |
| 8630 | mLastModemActivityInfo = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame^] | 8631 | new ModemActivityInfo( |
| 8632 | mLastModemActivityInfo.getTimestampMillis(), |
| 8633 | mLastModemActivityInfo.getSleepTimeMillis(), |
| 8634 | mLastModemActivityInfo.getIdleTimeMillis(), |
| 8635 | mLastModemActivitySpecificInfo); |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 8636 | } |
| 8637 | |
| 8638 | private ActivityStatsTechSpecificInfo[] deepCopyModemActivitySpecificInfo( |
| 8639 | ActivityStatsTechSpecificInfo[] info) { |
| 8640 | int infoSize = info.length; |
| 8641 | ActivityStatsTechSpecificInfo[] ret = new ActivityStatsTechSpecificInfo[infoSize]; |
| 8642 | for (int i = 0; i < infoSize; i++) { |
| 8643 | ret[i] = new ActivityStatsTechSpecificInfo( |
| 8644 | info[i].getRat(), info[i].getFrequencyRange(), |
| 8645 | info[i].getTransmitTimeMillis(), |
| 8646 | (int) info[i].getReceiveTimeMillis()); |
| 8647 | } |
| 8648 | return ret; |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8649 | } |
| 8650 | |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8651 | /** |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8652 | * Returns the service state information on specified subscription. |
| 8653 | */ |
| 8654 | @Override |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 8655 | public ServiceState getServiceStateForSubscriber(int subId, |
| 8656 | boolean renounceFineLocationAccess, boolean renounceCoarseLocationAccess, |
| 8657 | String callingPackage, String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8658 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8659 | mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) { |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8660 | return null; |
| 8661 | } |
| 8662 | |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 8663 | boolean hasFinePermission = false; |
| 8664 | boolean hasCoarsePermission = false; |
| 8665 | if (!renounceFineLocationAccess) { |
| 8666 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 8667 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 8668 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 8669 | .setCallingPackage(callingPackage) |
| 8670 | .setCallingFeatureId(callingFeatureId) |
| 8671 | .setCallingPid(Binder.getCallingPid()) |
| 8672 | .setCallingUid(Binder.getCallingUid()) |
| 8673 | .setMethod("getServiceStateForSubscriber") |
| 8674 | .setLogAsInfo(true) |
| 8675 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 8676 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 8677 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 8678 | .build()); |
| 8679 | hasFinePermission = |
| 8680 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 8681 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 8682 | |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 8683 | if (!renounceCoarseLocationAccess) { |
| 8684 | LocationAccessPolicy.LocationPermissionResult coarseLocationResult = |
| 8685 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 8686 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 8687 | .setCallingPackage(callingPackage) |
| 8688 | .setCallingFeatureId(callingFeatureId) |
| 8689 | .setCallingPid(Binder.getCallingPid()) |
| 8690 | .setCallingUid(Binder.getCallingUid()) |
| 8691 | .setMethod("getServiceStateForSubscriber") |
| 8692 | .setLogAsInfo(true) |
| 8693 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 8694 | .setMinSdkVersionForFine(Integer.MAX_VALUE) |
| 8695 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 8696 | .build()); |
| 8697 | hasCoarsePermission = |
| 8698 | coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 8699 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 8700 | |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 8701 | final Phone phone = getPhone(subId); |
| 8702 | if (phone == null) { |
| 8703 | return null; |
| 8704 | } |
| 8705 | |
Jordan Liu | 0f2bc44 | 2020-11-18 16:47:37 -0800 | [diff] [blame] | 8706 | final long identity = Binder.clearCallingIdentity(); |
| 8707 | |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 8708 | boolean isCallingPackageDataService = phone.getDataServicePackages() |
| 8709 | .contains(callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8710 | try { |
Jordan Liu | c437b19 | 2020-08-17 10:59:12 -0700 | [diff] [blame] | 8711 | // isActiveSubId requires READ_PHONE_STATE, which we already check for above |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 8712 | if (PhoneFactory.isSubscriptionManagerServiceEnabled()) { |
| 8713 | SubscriptionInfoInternal subInfo = SubscriptionManagerService.getInstance() |
| 8714 | .getSubscriptionInfoInternal(subId); |
| 8715 | if (subInfo == null || !subInfo.isActive()) { |
| 8716 | Rlog.d(LOG_TAG, "getServiceStateForSubscriber returning null for inactive " |
| 8717 | + "subId=" + subId); |
| 8718 | return null; |
| 8719 | } |
| 8720 | } else { |
| 8721 | if (!mSubscriptionController.isActiveSubId(subId, callingPackage, |
| 8722 | callingFeatureId)) { |
| 8723 | Rlog.d(LOG_TAG, "getServiceStateForSubscriber returning null for inactive " |
| 8724 | + "subId=" + subId); |
| 8725 | return null; |
| 8726 | } |
Jordan Liu | c437b19 | 2020-08-17 10:59:12 -0700 | [diff] [blame] | 8727 | } |
| 8728 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 8729 | ServiceState ss = phone.getServiceState(); |
| 8730 | |
| 8731 | // Scrub out the location info in ServiceState depending on what level of access |
| 8732 | // the caller has. |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 8733 | if (hasFinePermission || isCallingPackageDataService) return ss; |
Malcolm Chen | 5052de6 | 2019-12-30 13:56:38 -0800 | [diff] [blame] | 8734 | if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false); |
| 8735 | return ss.createLocationInfoSanitizedCopy(true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8736 | } finally { |
| 8737 | Binder.restoreCallingIdentity(identity); |
| 8738 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8739 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8740 | |
| 8741 | /** |
| 8742 | * Returns the URI for the per-account voicemail ringtone set in Phone settings. |
| 8743 | * |
| 8744 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 8745 | * voicemail ringtone. |
| 8746 | * @return The URI for the ringtone to play when receiving a voicemail from a specific |
| 8747 | * PhoneAccount. |
| 8748 | */ |
| 8749 | @Override |
| 8750 | public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8751 | final long identity = Binder.clearCallingIdentity(); |
| 8752 | try { |
| 8753 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 8754 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8755 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8756 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8757 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8758 | return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext()); |
| 8759 | } finally { |
| 8760 | Binder.restoreCallingIdentity(identity); |
| 8761 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8762 | } |
| 8763 | |
| 8764 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8765 | * Sets the per-account voicemail ringtone. |
| 8766 | * |
| 8767 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 8768 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 8769 | * |
| 8770 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 8771 | * voicemail ringtone. |
| 8772 | * @param uri The URI for the ringtone to play when receiving a voicemail from a specific |
| 8773 | * PhoneAccount. |
| 8774 | */ |
| 8775 | @Override |
| 8776 | public void setVoicemailRingtoneUri(String callingPackage, |
| 8777 | PhoneAccountHandle phoneAccountHandle, Uri uri) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8778 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8779 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 8780 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 8781 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8782 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8783 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 8784 | "setVoicemailRingtoneUri"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8785 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8786 | |
| 8787 | final long identity = Binder.clearCallingIdentity(); |
| 8788 | try { |
| 8789 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 8790 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8791 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8792 | } |
| 8793 | VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri); |
| 8794 | } finally { |
| 8795 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8796 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8797 | } |
| 8798 | |
| 8799 | /** |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8800 | * Returns whether vibration is set for voicemail notification in Phone settings. |
| 8801 | * |
| 8802 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 8803 | * voicemail vibration setting. |
| 8804 | * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise. |
| 8805 | */ |
| 8806 | @Override |
| 8807 | public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8808 | final long identity = Binder.clearCallingIdentity(); |
| 8809 | try { |
| 8810 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 8811 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8812 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8813 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8814 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8815 | return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext()); |
| 8816 | } finally { |
| 8817 | Binder.restoreCallingIdentity(identity); |
| 8818 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8819 | } |
| 8820 | |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8821 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8822 | * Sets the per-account voicemail vibration. |
| 8823 | * |
| 8824 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 8825 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 8826 | * |
| 8827 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 8828 | * voicemail vibration setting. |
| 8829 | * @param enabled Whether to enable or disable vibration for voicemail notifications from a |
| 8830 | * specific PhoneAccount. |
| 8831 | */ |
| 8832 | @Override |
| 8833 | public void setVoicemailVibrationEnabled(String callingPackage, |
| 8834 | PhoneAccountHandle phoneAccountHandle, boolean enabled) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8835 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8836 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 8837 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 8838 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8839 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8840 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 8841 | "setVoicemailVibrationEnabled"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8842 | } |
| 8843 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8844 | final long identity = Binder.clearCallingIdentity(); |
| 8845 | try { |
| 8846 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 8847 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8848 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8849 | } |
| 8850 | VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled); |
| 8851 | } finally { |
| 8852 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8853 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8854 | } |
| 8855 | |
| 8856 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8857 | * Make sure either called from same process as self (phone) or IPC caller has read privilege. |
| 8858 | * |
| 8859 | * @throws SecurityException if the caller does not have the required permission |
| 8860 | */ |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 8861 | @VisibleForTesting |
| 8862 | public void enforceReadPrivilegedPermission(String message) { |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8863 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8864 | message); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8865 | } |
| 8866 | |
| 8867 | /** |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 8868 | * Make sure either called from same process as self (phone) or IPC caller has send SMS |
| 8869 | * permission. |
| 8870 | * |
| 8871 | * @throws SecurityException if the caller does not have the required permission |
| 8872 | */ |
| 8873 | private void enforceSendSmsPermission() { |
| 8874 | mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null); |
| 8875 | } |
| 8876 | |
| 8877 | /** |
Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame] | 8878 | * Make sure either called from same process as self (phone) or IPC caller has interact across |
| 8879 | * users permission. |
| 8880 | * |
| 8881 | * @throws SecurityException if the caller does not have the required permission |
| 8882 | */ |
| 8883 | private void enforceInteractAcrossUsersPermission(String message) { |
| 8884 | mApp.enforceCallingOrSelfPermission(permission.INTERACT_ACROSS_USERS, message); |
| 8885 | } |
| 8886 | |
| 8887 | /** |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 8888 | * Make sure called from the package in charge of visual voicemail. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 8889 | * |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 8890 | * @throws SecurityException if the caller is not the visual voicemail package. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 8891 | */ |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 8892 | private void enforceVisualVoicemailPackage(String callingPackage, int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8893 | final long identity = Binder.clearCallingIdentity(); |
| 8894 | try { |
| 8895 | ComponentName componentName = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8896 | RemoteVvmTaskManager.getRemotePackage(mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8897 | if (componentName == null) { |
| 8898 | throw new SecurityException( |
| 8899 | "Caller not current active visual voicemail package[null]"); |
| 8900 | } |
| 8901 | String vvmPackage = componentName.getPackageName(); |
| 8902 | if (!callingPackage.equals(vvmPackage)) { |
Hui Wang | 7f65755 | 2022-08-16 16:58:25 +0000 | [diff] [blame] | 8903 | throw new SecurityException("Caller not current active visual voicemail package"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8904 | } |
| 8905 | } finally { |
| 8906 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 8907 | } |
| 8908 | } |
| 8909 | |
| 8910 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8911 | * Return the application ID for the app type. |
| 8912 | * |
| 8913 | * @param subId the subscription ID that this request applies to. |
| 8914 | * @param appType the uicc app type. |
| 8915 | * @return Application ID for specificied app type, or null if no uicc. |
| 8916 | */ |
| 8917 | @Override |
| 8918 | public String getAidForAppType(int subId, int appType) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8919 | enforceReadPrivilegedPermission("getAidForAppType"); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8920 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8921 | |
| 8922 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8923 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8924 | if (phone == null) { |
| 8925 | return null; |
| 8926 | } |
| 8927 | String aid = null; |
| 8928 | try { |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 8929 | aid = UiccController.getInstance().getUiccPort(phone.getPhoneId()) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8930 | .getApplicationByType(appType).getAid(); |
| 8931 | } catch (Exception e) { |
| 8932 | Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e); |
| 8933 | } |
| 8934 | return aid; |
| 8935 | } finally { |
| 8936 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8937 | } |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8938 | } |
| 8939 | |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8940 | /** |
| 8941 | * Return the Electronic Serial Number. |
| 8942 | * |
| 8943 | * @param subId the subscription ID that this request applies to. |
| 8944 | * @return ESN or null if error. |
| 8945 | */ |
| 8946 | @Override |
| 8947 | public String getEsn(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8948 | enforceReadPrivilegedPermission("getEsn"); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8949 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8950 | |
| 8951 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8952 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8953 | if (phone == null) { |
| 8954 | return null; |
| 8955 | } |
| 8956 | String esn = null; |
| 8957 | try { |
| 8958 | esn = phone.getEsn(); |
| 8959 | } catch (Exception e) { |
| 8960 | Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e); |
| 8961 | } |
| 8962 | return esn; |
| 8963 | } finally { |
| 8964 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8965 | } |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8966 | } |
| 8967 | |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 8968 | /** |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8969 | * Return the Preferred Roaming List Version. |
| 8970 | * |
| 8971 | * @param subId the subscription ID that this request applies to. |
| 8972 | * @return PRLVersion or null if error. |
| 8973 | */ |
| 8974 | @Override |
| 8975 | public String getCdmaPrlVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8976 | enforceReadPrivilegedPermission("getCdmaPrlVersion"); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8977 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8978 | |
| 8979 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8980 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8981 | if (phone == null) { |
| 8982 | return null; |
| 8983 | } |
| 8984 | String cdmaPrlVersion = null; |
| 8985 | try { |
| 8986 | cdmaPrlVersion = phone.getCdmaPrlVersion(); |
| 8987 | } catch (Exception e) { |
| 8988 | Log.e(LOG_TAG, "Not getting PRLVersion", e); |
| 8989 | } |
| 8990 | return cdmaPrlVersion; |
| 8991 | } finally { |
| 8992 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8993 | } |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8994 | } |
| 8995 | |
| 8996 | /** |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 8997 | * Get snapshot of Telephony histograms |
| 8998 | * @return List of Telephony histograms |
| 8999 | * @hide |
| 9000 | */ |
| 9001 | @Override |
| 9002 | public List<TelephonyHistogram> getTelephonyHistograms() { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 9003 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9004 | mApp, getDefaultSubscription(), "getTelephonyHistograms"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9005 | |
| 9006 | final long identity = Binder.clearCallingIdentity(); |
| 9007 | try { |
| 9008 | return RIL.getTelephonyRILTimingHistograms(); |
| 9009 | } finally { |
| 9010 | Binder.restoreCallingIdentity(identity); |
| 9011 | } |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 9012 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 9013 | |
| 9014 | /** |
| 9015 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 9016 | * Set the allowed carrier list and the excluded carrier list, indicating the priority between |
| 9017 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 9018 | * Require system privileges. In the future we may add this to carrier APIs. |
| 9019 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 9020 | * @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] | 9021 | */ |
| 9022 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 9023 | @TelephonyManager.SetCarrierRestrictionResult |
| 9024 | public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) { |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 9025 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 9026 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 9027 | |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 9028 | if (carrierRestrictionRules == null) { |
| 9029 | throw new NullPointerException("carrier restriction cannot be null"); |
Meng Wang | 9b7c4e9 | 2017-02-17 11:41:27 -0800 | [diff] [blame] | 9030 | } |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 9031 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9032 | final long identity = Binder.clearCallingIdentity(); |
| 9033 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 9034 | return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 9035 | workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9036 | } finally { |
| 9037 | Binder.restoreCallingIdentity(identity); |
| 9038 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 9039 | } |
| 9040 | |
| 9041 | /** |
| 9042 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 9043 | * Get the allowed carrier list and the excluded carrier list, including the priority between |
| 9044 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 9045 | * Require system privileges. In the future we may add this to carrier APIs. |
| 9046 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 9047 | * @return {@link android.telephony.CarrierRestrictionRules} |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 9048 | */ |
| 9049 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 9050 | public CarrierRestrictionRules getAllowedCarriers() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 9051 | enforceReadPrivilegedPermission("getAllowedCarriers"); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 9052 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9053 | |
| 9054 | final long identity = Binder.clearCallingIdentity(); |
| 9055 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 9056 | Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource); |
| 9057 | if (response instanceof CarrierRestrictionRules) { |
| 9058 | return (CarrierRestrictionRules) response; |
| 9059 | } |
| 9060 | // Response is an Exception of some kind, |
| 9061 | // which is signalled to the user as a NULL retval |
| 9062 | return null; |
| 9063 | } catch (Exception e) { |
| 9064 | Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e); |
| 9065 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9066 | } finally { |
| 9067 | Binder.restoreCallingIdentity(identity); |
| 9068 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 9069 | } |
| 9070 | |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 9071 | /** |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 9072 | * Fetches the carrier restriction status of the device and sends the status to the caller |
| 9073 | * through the callback. |
| 9074 | * |
| 9075 | * @param callback The callback that will be used to send the result. |
| 9076 | * @throws SecurityException if the caller does not have the required permission/privileges or |
| 9077 | * the caller is not allowlisted. |
| 9078 | */ |
| 9079 | @Override |
| 9080 | public void getCarrierRestrictionStatus(IIntegerConsumer callback, String packageName) { |
| 9081 | enforceReadPermission("getCarrierRestrictionStatus"); |
| 9082 | int carrierId = validateCallerAndGetCarrierId(packageName); |
| 9083 | if (carrierId == CarrierAllowListInfo.INVALID_CARRIER_ID) { |
| 9084 | Rlog.e(LOG_TAG, "getCarrierRestrictionStatus: caller is not registered"); |
| 9085 | throw new SecurityException("Not an authorized caller"); |
| 9086 | } |
| 9087 | final long identity = Binder.clearCallingIdentity(); |
| 9088 | try { |
| 9089 | Consumer<Integer> consumer = FunctionalUtils.ignoreRemoteException(callback::accept); |
| 9090 | CallerCallbackInfo callbackInfo = new CallerCallbackInfo(consumer, carrierId); |
| 9091 | sendRequestAsync(CMD_GET_ALLOWED_CARRIERS, callbackInfo); |
| 9092 | } finally { |
| 9093 | Binder.restoreCallingIdentity(identity); |
| 9094 | } |
| 9095 | } |
| 9096 | |
| 9097 | @VisibleForTesting |
| 9098 | public int validateCallerAndGetCarrierId(String packageName) { |
| 9099 | CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp); |
| 9100 | return allowListInfo.validateCallerAndGetCarrierId(packageName); |
| 9101 | } |
| 9102 | |
| 9103 | /** |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 9104 | * Action set from carrier signalling broadcast receivers to enable/disable radio |
| 9105 | * @param subId the subscription ID that this action applies to. |
| 9106 | * @param enabled control enable or disable radio. |
| 9107 | * {@hide} |
| 9108 | */ |
| 9109 | @Override |
| 9110 | public void carrierActionSetRadioEnabled(int subId, boolean enabled) { |
| 9111 | enforceModifyPermission(); |
| 9112 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9113 | |
| 9114 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 9115 | if (phone == null) { |
| 9116 | loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId); |
| 9117 | return; |
| 9118 | } |
| 9119 | try { |
| 9120 | phone.carrierActionSetRadioEnabled(enabled); |
| 9121 | } catch (Exception e) { |
| 9122 | Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9123 | } finally { |
| 9124 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 9125 | } |
| 9126 | } |
| 9127 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 9128 | /** |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 9129 | * Enable or disable Voice over NR (VoNR) |
| 9130 | * @param subId the subscription ID that this action applies to. |
| 9131 | * @param enabled enable or disable VoNR. |
| 9132 | * @return operation result. |
| 9133 | */ |
| 9134 | @Override |
| 9135 | public int setVoNrEnabled(int subId, boolean enabled) { |
| 9136 | enforceModifyPermission(); |
| 9137 | final Phone phone = getPhone(subId); |
| 9138 | |
| 9139 | final long identity = Binder.clearCallingIdentity(); |
| 9140 | if (phone == null) { |
| 9141 | loge("setVoNrEnabled fails with no phone object for subId: " + subId); |
| 9142 | return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE; |
| 9143 | } |
| 9144 | |
| 9145 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 9146 | try { |
| 9147 | int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId, |
| 9148 | workSource); |
| 9149 | if (DBG) log("setVoNrEnabled result: " + result); |
Gary Jian | 8dd305f | 2021-10-14 16:31:35 +0800 | [diff] [blame] | 9150 | |
| 9151 | if (result == TelephonyManager.ENABLE_VONR_SUCCESS) { |
| 9152 | if (DBG) { |
| 9153 | log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled); |
| 9154 | } |
| 9155 | SubscriptionManager.setSubscriptionProperty( |
| 9156 | subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED, |
| 9157 | (enabled ? "1" : "0")); |
| 9158 | } |
| 9159 | |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 9160 | return result; |
| 9161 | } finally { |
| 9162 | Binder.restoreCallingIdentity(identity); |
| 9163 | } |
| 9164 | } |
| 9165 | |
| 9166 | /** |
| 9167 | * Is voice over NR enabled |
| 9168 | * @return true if VoNR is enabled else false |
| 9169 | */ |
| 9170 | @Override |
| 9171 | public boolean isVoNrEnabled(int subId) { |
| 9172 | enforceReadPrivilegedPermission("isVoNrEnabled"); |
| 9173 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 9174 | final long identity = Binder.clearCallingIdentity(); |
| 9175 | try { |
| 9176 | boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED, |
| 9177 | null, subId, workSource); |
| 9178 | if (DBG) log("isVoNrEnabled: " + isEnabled); |
| 9179 | return isEnabled; |
| 9180 | } finally { |
| 9181 | Binder.restoreCallingIdentity(identity); |
| 9182 | } |
| 9183 | } |
| 9184 | |
| 9185 | /** |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 9186 | * Action set from carrier signalling broadcast receivers to start/stop reporting the default |
| 9187 | * network status based on which carrier apps could apply actions accordingly, |
| 9188 | * enable/disable default url handler for example. |
| 9189 | * |
| 9190 | * @param subId the subscription ID that this action applies to. |
| 9191 | * @param report control start/stop reporting the default network status. |
| 9192 | * {@hide} |
| 9193 | */ |
| 9194 | @Override |
| 9195 | public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) { |
| 9196 | enforceModifyPermission(); |
| 9197 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9198 | |
| 9199 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 9200 | if (phone == null) { |
| 9201 | loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId); |
| 9202 | return; |
| 9203 | } |
| 9204 | try { |
| 9205 | phone.carrierActionReportDefaultNetworkStatus(report); |
| 9206 | } catch (Exception e) { |
| 9207 | Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9208 | } finally { |
| 9209 | Binder.restoreCallingIdentity(identity); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 9210 | } |
| 9211 | } |
| 9212 | |
| 9213 | /** |
fionaxu | d962228 | 2017-07-17 17:51:30 -0700 | [diff] [blame] | 9214 | * Action set from carrier signalling broadcast receivers to reset all carrier actions |
| 9215 | * @param subId the subscription ID that this action applies to. |
| 9216 | * {@hide} |
| 9217 | */ |
| 9218 | @Override |
| 9219 | public void carrierActionResetAll(int subId) { |
| 9220 | enforceModifyPermission(); |
| 9221 | final Phone phone = getPhone(subId); |
| 9222 | if (phone == null) { |
| 9223 | loge("carrierAction: ResetAll fails with invalid sibId: " + subId); |
| 9224 | return; |
| 9225 | } |
| 9226 | try { |
| 9227 | phone.carrierActionResetAll(); |
| 9228 | } catch (Exception e) { |
| 9229 | Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e); |
| 9230 | } |
| 9231 | } |
| 9232 | |
| 9233 | /** |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 9234 | * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a |
| 9235 | * bug report is being generated. |
| 9236 | */ |
| 9237 | @Override |
Ta-wei Yen | 99282e0 | 2016-06-21 18:19:35 -0700 | [diff] [blame] | 9238 | protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9239 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 9240 | != PackageManager.PERMISSION_GRANTED) { |
dcashman | 22b950d | 2016-06-27 11:39:02 -0700 | [diff] [blame] | 9241 | writer.println("Permission Denial: can't dump Phone from pid=" |
| 9242 | + Binder.getCallingPid() |
| 9243 | + ", uid=" + Binder.getCallingUid() |
| 9244 | + "without permission " |
| 9245 | + android.Manifest.permission.DUMP); |
| 9246 | return; |
| 9247 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9248 | DumpsysHandler.dump(mApp, fd, writer, args); |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 9249 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 9250 | |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 9251 | @Override |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 9252 | public int handleShellCommand(@NonNull ParcelFileDescriptor in, |
| 9253 | @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err, |
| 9254 | @NonNull String[] args) { |
| 9255 | return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec( |
| 9256 | this, in.getFileDescriptor(), out.getFileDescriptor(), |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame^] | 9257 | err.getFileDescriptor(), args); |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 9258 | } |
| 9259 | |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 9260 | /** |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 9261 | * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason} |
Greg Kaiser | 17f4175 | 2020-05-05 16:47:47 +0000 | [diff] [blame] | 9262 | * @param subId Subscription index |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 9263 | * @param reason The reason the data enable change is taking place. |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 9264 | * @param enabled True if enabling the data, otherwise disabling. |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 9265 | * @param callingPackage The package that changed the data enabled state. |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 9266 | * @hide |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 9267 | */ |
| 9268 | @Override |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 9269 | public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 9270 | boolean enabled, String callingPackage) { |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 9271 | if (reason == TelephonyManager.DATA_ENABLED_REASON_USER |
| 9272 | || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 9273 | try { |
| 9274 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 9275 | mApp, subId, "setDataEnabledForReason"); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 9276 | } catch (SecurityException se) { |
| 9277 | enforceModifyPermission(); |
| 9278 | } |
| 9279 | } else { |
| 9280 | enforceModifyPermission(); |
| 9281 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9282 | |
| 9283 | final long identity = Binder.clearCallingIdentity(); |
| 9284 | try { |
| 9285 | Phone phone = getPhone(subId); |
| 9286 | if (phone != null) { |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 9287 | if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 9288 | phone.carrierActionSetMeteredApnsEnabled(enabled); |
| 9289 | } else { |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 9290 | phone.getDataSettingsManager().setDataEnabled( |
| 9291 | reason, enabled, callingPackage); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 9292 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9293 | } |
| 9294 | } finally { |
| 9295 | Binder.restoreCallingIdentity(identity); |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 9296 | } |
| 9297 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 9298 | |
| 9299 | /** |
| 9300 | * Get Client request stats |
| 9301 | * @return List of Client Request Stats |
| 9302 | * @hide |
| 9303 | */ |
| 9304 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9305 | public List<ClientRequestStats> getClientRequestStats(String callingPackage, |
| 9306 | String callingFeatureId, int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 9307 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9308 | mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) { |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 9309 | return null; |
| 9310 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 9311 | Phone phone = getPhone(subId); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 9312 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9313 | final long identity = Binder.clearCallingIdentity(); |
| 9314 | try { |
| 9315 | if (phone != null) { |
| 9316 | return phone.getClientRequestStats(); |
| 9317 | } |
| 9318 | |
| 9319 | return null; |
| 9320 | } finally { |
| 9321 | Binder.restoreCallingIdentity(identity); |
| 9322 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 9323 | } |
| 9324 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 9325 | private WorkSource getWorkSource(int uid) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9326 | String packageName = mApp.getPackageManager().getNameForUid(uid); |
Hunter Knepshield | d03383b | 2022-03-29 22:47:54 +0000 | [diff] [blame] | 9327 | if (uid == Process.ROOT_UID && packageName == null) { |
| 9328 | // Downstream WorkSource attribution inside the RIL requires both a UID and package name |
| 9329 | // to be set for wakelock tracking, otherwise RIL requests fail with a runtime |
| 9330 | // exception. ROOT_UID seems not to have a valid package name returned by |
| 9331 | // PackageManager, so just fake it here to avoid issues when running telephony shell |
| 9332 | // commands that plumb through the RIL as root, like so: |
| 9333 | // $ adb root |
| 9334 | // $ adb shell cmd phone ... |
| 9335 | packageName = "root"; |
| 9336 | } |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 9337 | return new WorkSource(uid, packageName); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 9338 | } |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 9339 | |
| 9340 | /** |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 9341 | * Set SIM card power state. |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 9342 | * |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 9343 | * @param slotIndex SIM slot id. |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 9344 | * @param state State of SIM (power down, power up, pass through) |
| 9345 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 9346 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 9347 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 9348 | * |
| 9349 | **/ |
| 9350 | @Override |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 9351 | public void setSimPowerStateForSlot(int slotIndex, int state) { |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 9352 | enforceModifyPermission(); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 9353 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 9354 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 9355 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 9356 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9357 | final long identity = Binder.clearCallingIdentity(); |
| 9358 | try { |
| 9359 | if (phone != null) { |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 9360 | phone.setSimPowerState(state, null, workSource); |
| 9361 | } |
| 9362 | } finally { |
| 9363 | Binder.restoreCallingIdentity(identity); |
| 9364 | } |
| 9365 | } |
| 9366 | |
| 9367 | /** |
| 9368 | * Set SIM card power state. |
| 9369 | * |
| 9370 | * @param slotIndex SIM slot id. |
| 9371 | * @param state State of SIM (power down, power up, pass through) |
| 9372 | * @param callback callback to trigger after success or failure |
| 9373 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 9374 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 9375 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
| 9376 | * |
| 9377 | **/ |
| 9378 | @Override |
| 9379 | public void setSimPowerStateForSlotWithCallback(int slotIndex, int state, |
| 9380 | IIntegerConsumer callback) { |
| 9381 | enforceModifyPermission(); |
| 9382 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 9383 | |
| 9384 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 9385 | |
| 9386 | final long identity = Binder.clearCallingIdentity(); |
| 9387 | try { |
| 9388 | if (phone != null) { |
| 9389 | Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback); |
| 9390 | sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9391 | } |
| 9392 | } finally { |
| 9393 | Binder.restoreCallingIdentity(identity); |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 9394 | } |
| 9395 | } |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 9396 | |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 9397 | private boolean isUssdApiAllowed(int subId) { |
| 9398 | CarrierConfigManager configManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9399 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 9400 | if (configManager == null) { |
| 9401 | return false; |
| 9402 | } |
| 9403 | PersistableBundle pb = configManager.getConfigForSubId(subId); |
| 9404 | if (pb == null) { |
| 9405 | return false; |
| 9406 | } |
| 9407 | return pb.getBoolean( |
| 9408 | CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL); |
| 9409 | } |
| 9410 | |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 9411 | /** |
| 9412 | * Check if phone is in emergency callback mode |
| 9413 | * @return true if phone is in emergency callback mode |
| 9414 | * @param subId sub id |
| 9415 | */ |
goneil | 9c5f487 | 2017-12-05 14:07:56 -0800 | [diff] [blame] | 9416 | @Override |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 9417 | public boolean getEmergencyCallbackMode(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 9418 | enforceReadPrivilegedPermission("getEmergencyCallbackMode"); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 9419 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9420 | |
| 9421 | final long identity = Binder.clearCallingIdentity(); |
| 9422 | try { |
| 9423 | if (phone != null) { |
| 9424 | return phone.isInEcm(); |
| 9425 | } else { |
| 9426 | return false; |
| 9427 | } |
| 9428 | } finally { |
| 9429 | Binder.restoreCallingIdentity(identity); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 9430 | } |
| 9431 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 9432 | |
| 9433 | /** |
| 9434 | * Get the current signal strength information for the given subscription. |
| 9435 | * Because this information is not updated when the device is in a low power state |
| 9436 | * it should not be relied-upon to be current. |
| 9437 | * @param subId Subscription index |
| 9438 | * @return the most recent cached signal strength info from the modem |
| 9439 | */ |
| 9440 | @Override |
| 9441 | public SignalStrength getSignalStrength(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9442 | final long identity = Binder.clearCallingIdentity(); |
| 9443 | try { |
| 9444 | Phone p = getPhone(subId); |
| 9445 | if (p == null) { |
| 9446 | return null; |
| 9447 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 9448 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9449 | return p.getSignalStrength(); |
| 9450 | } finally { |
| 9451 | Binder.restoreCallingIdentity(identity); |
| 9452 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 9453 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9454 | |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9455 | /** |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 9456 | * Get the current modem radio state for the given slot. |
| 9457 | * @param slotIndex slot index. |
| 9458 | * @param callingPackage the name of the package making the call. |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9459 | * @param callingFeatureId The feature in the package. |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 9460 | * @return the current radio power state from the modem |
| 9461 | */ |
| 9462 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9463 | public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 9464 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 9465 | if (phone != null) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9466 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(), |
| 9467 | callingPackage, callingFeatureId, "getRadioPowerState")) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 9468 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 9469 | } |
| 9470 | |
| 9471 | final long identity = Binder.clearCallingIdentity(); |
| 9472 | try { |
| 9473 | return phone.getRadioPowerState(); |
| 9474 | } finally { |
| 9475 | Binder.restoreCallingIdentity(identity); |
| 9476 | } |
| 9477 | } |
| 9478 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 9479 | } |
| 9480 | |
| 9481 | /** |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9482 | * Checks if data roaming is enabled on the subscription with id {@code subId}. |
| 9483 | * |
| 9484 | * <p>Requires one of the following permissions: |
| 9485 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}, |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 9486 | * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE}, |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9487 | * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier |
| 9488 | * privileges. |
| 9489 | * |
| 9490 | * @param subId subscription id |
| 9491 | * @return {@code true} if data roaming is enabled on this subscription, otherwise return |
| 9492 | * {@code false}. |
| 9493 | */ |
| 9494 | @Override |
| 9495 | public boolean isDataRoamingEnabled(int subId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 9496 | String functionName = "isDataRoamingEnabled"; |
Shuo Qian | 093013d | 2020-08-13 15:42:55 -0700 | [diff] [blame] | 9497 | try { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 9498 | try { |
| 9499 | mApp.enforceCallingOrSelfPermission( |
| 9500 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 9501 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 9502 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 9503 | mApp.enforceCallingOrSelfPermission( |
| 9504 | permission.READ_BASIC_PHONE_STATE, functionName); |
| 9505 | } |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 9506 | } catch (SecurityException e) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9507 | TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 9508 | mApp, subId, functionName); |
Shuo Qian | 093013d | 2020-08-13 15:42:55 -0700 | [diff] [blame] | 9509 | } |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 9510 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9511 | boolean isEnabled = false; |
| 9512 | final long identity = Binder.clearCallingIdentity(); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9513 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9514 | Phone phone = getPhone(subId); |
| 9515 | isEnabled = phone != null ? phone.getDataRoamingEnabled() : false; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9516 | } finally { |
| 9517 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9518 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9519 | return isEnabled; |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9520 | } |
| 9521 | |
| 9522 | |
| 9523 | /** |
| 9524 | * Enables/Disables the data roaming on the subscription with id {@code subId}. |
| 9525 | * |
| 9526 | * <p> Requires permission: |
| 9527 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier |
| 9528 | * privileges. |
| 9529 | * |
| 9530 | * @param subId subscription id |
| 9531 | * @param isEnabled {@code true} means enable, {@code false} means disable. |
| 9532 | */ |
| 9533 | @Override |
| 9534 | public void setDataRoamingEnabled(int subId, boolean isEnabled) { |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 9535 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9536 | mApp, subId, "setDataRoamingEnabled"); |
| 9537 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9538 | final long identity = Binder.clearCallingIdentity(); |
| 9539 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9540 | Phone phone = getPhone(subId); |
| 9541 | if (phone != null) { |
| 9542 | phone.setDataRoamingEnabled(isEnabled); |
| 9543 | } |
| 9544 | } finally { |
| 9545 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9546 | } |
| 9547 | } |
| 9548 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9549 | @Override |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 9550 | public boolean isManualNetworkSelectionAllowed(int subId) { |
tom hsu | c91afc7 | 2020-01-06 23:46:07 +0800 | [diff] [blame] | 9551 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9552 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame^] | 9553 | mApp, subId, "isManualNetworkSelectionAllowed"); |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 9554 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 9555 | boolean isAllowed = true; |
| 9556 | final long identity = Binder.clearCallingIdentity(); |
| 9557 | try { |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 9558 | Phone phone = getPhone(subId); |
| 9559 | if (phone != null) { |
| 9560 | isAllowed = phone.isCspPlmnEnabled(); |
| 9561 | } |
| 9562 | } finally { |
| 9563 | Binder.restoreCallingIdentity(identity); |
| 9564 | } |
| 9565 | return isAllowed; |
| 9566 | } |
| 9567 | |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9568 | private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) { |
| 9569 | UiccProfile profile = port.getUiccProfile(); |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 9570 | if (profile == null) { |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9571 | return false; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9572 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 9573 | Phone phone = PhoneFactory.getPhone(profile.getPhoneId()); |
| 9574 | if (phone == null) { |
| 9575 | return false; |
| 9576 | } |
| 9577 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 9578 | return cpt != null && cpt.getCarrierPrivilegeStatusForPackage(callingPackage) |
| 9579 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9580 | } |
| 9581 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 9582 | @Override |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 9583 | public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) { |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9584 | // Verify that the callingPackage belongs to the calling UID |
Jordan Liu | 4cda455 | 2020-03-23 11:55:07 -0700 | [diff] [blame] | 9585 | mApp.getSystemService(AppOpsManager.class) |
| 9586 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 9587 | |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9588 | boolean hasReadPermission = false; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9589 | boolean isIccIdAccessRestricted = false; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 9590 | try { |
| 9591 | enforceReadPrivilegedPermission("getUiccCardsInfo"); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9592 | hasReadPermission = true; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 9593 | } catch (SecurityException e) { |
| 9594 | // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller |
| 9595 | // has carrier privileges on an active UICC |
Rambo Wang | e7209ce | 2022-02-23 13:41:02 -0800 | [diff] [blame] | 9596 | if (checkCarrierPrivilegesForPackageAnyPhoneWithPermission(callingPackage) |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame^] | 9597 | != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9598 | throw new SecurityException("Caller does not have permission."); |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 9599 | } |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 9600 | } |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9601 | // checking compatibility, if calling app's target SDK is T and beyond. |
| 9602 | if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO, |
| 9603 | Binder.getCallingUid())) { |
| 9604 | isIccIdAccessRestricted = true; |
| 9605 | } |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 9606 | final long identity = Binder.clearCallingIdentity(); |
| 9607 | try { |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 9608 | UiccController uiccController = UiccController.getInstance(); |
| 9609 | ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos(); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9610 | if (hasReadPermission) { |
| 9611 | return cardInfos; |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 9612 | } |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9613 | |
| 9614 | // Remove private info if the caller doesn't have access |
| 9615 | ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>(); |
| 9616 | for (UiccCardInfo cardInfo : cardInfos) { |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9617 | //setting the value after compatibility check |
| 9618 | cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9619 | // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo |
| 9620 | // is available |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9621 | UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex()); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9622 | if (card == null) { |
| 9623 | // assume no access if the card is unavailable |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9624 | filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo)); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9625 | continue; |
| 9626 | } |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9627 | Collection<UiccPortInfo> portInfos = cardInfo.getPorts(); |
| 9628 | if (portInfos.isEmpty()) { |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9629 | filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo)); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9630 | continue; |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9631 | } |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9632 | List<UiccPortInfo> uiccPortInfos = new ArrayList<>(); |
| 9633 | for (UiccPortInfo portInfo : portInfos) { |
| 9634 | UiccPort port = uiccController.getUiccPortForSlot( |
| 9635 | cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex()); |
| 9636 | if (port == null) { |
| 9637 | // assume no access if port is null |
| 9638 | uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo)); |
| 9639 | continue; |
| 9640 | } |
| 9641 | if (haveCarrierPrivilegeAccess(port, callingPackage)) { |
| 9642 | uiccPortInfos.add(portInfo); |
| 9643 | } else { |
| 9644 | uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo)); |
| 9645 | } |
| 9646 | } |
| 9647 | filteredInfos.add(new UiccCardInfo( |
| 9648 | cardInfo.isEuicc(), |
| 9649 | cardInfo.getCardId(), |
| 9650 | null, |
| 9651 | cardInfo.getPhysicalSlotIndex(), |
| 9652 | cardInfo.isRemovable(), |
| 9653 | cardInfo.isMultipleEnabledProfilesSupported(), |
| 9654 | uiccPortInfos)); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9655 | } |
| 9656 | return filteredInfos; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 9657 | } finally { |
| 9658 | Binder.restoreCallingIdentity(identity); |
| 9659 | } |
| 9660 | } |
| 9661 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9662 | /** |
| 9663 | * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are |
| 9664 | * generally private and require carrier privileges to view. |
| 9665 | * |
| 9666 | * @hide |
| 9667 | */ |
| 9668 | @NonNull |
| 9669 | public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) { |
| 9670 | List<UiccPortInfo> portinfo = new ArrayList<>(); |
| 9671 | for (UiccPortInfo portinfos : cardInfo.getPorts()) { |
| 9672 | portinfo.add(getUiccPortInfoUnPrivileged(portinfos)); |
| 9673 | } |
| 9674 | return new UiccCardInfo( |
| 9675 | cardInfo.isEuicc(), |
| 9676 | cardInfo.getCardId(), |
| 9677 | null, |
| 9678 | cardInfo.getPhysicalSlotIndex(), |
| 9679 | cardInfo.isRemovable(), |
| 9680 | cardInfo.isMultipleEnabledProfilesSupported(), |
| 9681 | portinfo |
| 9682 | ); |
| 9683 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9684 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9685 | /** |
| 9686 | * @hide |
| 9687 | * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}. |
| 9688 | * These values are generally private and require carrier privileges to view. |
| 9689 | */ |
| 9690 | @NonNull |
| 9691 | public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) { |
| 9692 | return new UiccPortInfo( |
| 9693 | UiccPortInfo.ICCID_REDACTED, |
| 9694 | portInfo.getPortIndex(), |
| 9695 | portInfo.getLogicalSlotIndex(), |
| 9696 | portInfo.isActive() |
| 9697 | ); |
| 9698 | } |
| 9699 | @Override |
| 9700 | public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) { |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9701 | // Verify that the callingPackage belongs to the calling UID |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9702 | mApp.getSystemService(AppOpsManager.class) |
| 9703 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 9704 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9705 | boolean isLogicalSlotAccessRestricted = false; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9706 | |
Aman Gupta | f3c90b3 | 2022-03-17 04:54:16 +0000 | [diff] [blame] | 9707 | // This will make sure caller has the READ_PRIVILEGED_PHONE_STATE. Do not remove this as |
| 9708 | // we are reading iccId which is PII data. |
| 9709 | enforceReadPrivilegedPermission("getUiccSlotsInfo"); |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9710 | |
| 9711 | // checking compatibility, if calling app's target SDK is T and beyond. |
| 9712 | if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO, |
| 9713 | Binder.getCallingUid())) { |
| 9714 | isLogicalSlotAccessRestricted = true; |
| 9715 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9716 | final long identity = Binder.clearCallingIdentity(); |
| 9717 | try { |
| 9718 | UiccSlot[] slots = UiccController.getInstance().getUiccSlots(); |
Muralidhar Reddy | d196bbf | 2022-01-17 17:56:30 +0000 | [diff] [blame] | 9719 | if (slots == null || slots.length == 0) { |
| 9720 | Rlog.i(LOG_TAG, "slots is null or empty."); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9721 | return null; |
| 9722 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9723 | UiccSlotInfo[] infos = new UiccSlotInfo[slots.length]; |
| 9724 | for (int i = 0; i < slots.length; i++) { |
| 9725 | UiccSlot slot = slots[i]; |
| 9726 | if (slot == null) { |
| 9727 | continue; |
| 9728 | } |
| 9729 | |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 9730 | String cardId; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9731 | UiccCard card = slot.getUiccCard(); |
| 9732 | if (card != null) { |
| 9733 | cardId = card.getCardId(); |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 9734 | } else { |
Jordan Liu | 01bd00d | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 9735 | cardId = slot.getEid(); |
| 9736 | if (TextUtils.isEmpty(cardId)) { |
Aman Gupta | f3c90b3 | 2022-03-17 04:54:16 +0000 | [diff] [blame] | 9737 | // If cardId is null, use iccId of default port as cardId. |
| 9738 | cardId = slot.getIccId(TelephonyManager.DEFAULT_PORT_INDEX); |
Jordan Liu | 01bd00d | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 9739 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9740 | } |
| 9741 | |
Jordan Liu | 857451f | 2019-05-09 16:35:35 -0700 | [diff] [blame] | 9742 | if (cardId != null) { |
| 9743 | // if cardId is an ICCID, strip off trailing Fs before exposing to user |
| 9744 | // if cardId is an EID, it's all digits so this is fine |
| 9745 | cardId = IccUtils.stripTrailingFs(cardId); |
| 9746 | } |
| 9747 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9748 | int cardState = 0; |
| 9749 | switch (slot.getCardState()) { |
| 9750 | case CARDSTATE_ABSENT: |
| 9751 | cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT; |
| 9752 | break; |
| 9753 | case CARDSTATE_PRESENT: |
| 9754 | cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT; |
| 9755 | break; |
| 9756 | case CARDSTATE_ERROR: |
| 9757 | cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR; |
| 9758 | break; |
| 9759 | case CARDSTATE_RESTRICTED: |
| 9760 | cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED; |
| 9761 | break; |
| 9762 | default: |
| 9763 | break; |
| 9764 | |
| 9765 | } |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9766 | List<UiccPortInfo> portInfos = new ArrayList<>(); |
| 9767 | int[] portIndexes = slot.getPortList(); |
| 9768 | for (int portIdx : portIndexes) { |
| 9769 | String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx, |
Aman Gupta | f3c90b3 | 2022-03-17 04:54:16 +0000 | [diff] [blame] | 9770 | callingPackage, /* hasReadPermission= */ true)); |
Muralidhar Reddy | fbcff0c | 2022-01-19 13:07:57 +0000 | [diff] [blame] | 9771 | portInfos.add(new UiccPortInfo(iccId, portIdx, |
| 9772 | slot.getPhoneIdFromPortIndex(portIdx), slot.isPortActive(portIdx))); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9773 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9774 | infos[i] = new UiccSlotInfo( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9775 | slot.isEuicc(), |
| 9776 | cardId, |
| 9777 | cardState, |
Jordan Liu | a261958 | 2019-02-14 12:56:40 -0800 | [diff] [blame] | 9778 | slot.isExtendedApduSupported(), |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9779 | slot.isRemovable(), portInfos); |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9780 | //setting the value after compatibility check |
| 9781 | infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9782 | } |
| 9783 | return infos; |
| 9784 | } finally { |
| 9785 | Binder.restoreCallingIdentity(identity); |
Holly Jiuyu Sun | 1d957c5 | 2018-04-04 13:52:42 -0700 | [diff] [blame] | 9786 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9787 | } |
| 9788 | |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9789 | /* Returns null if doesn't have read permission or carrier privilege access. */ |
| 9790 | private String getIccId(UiccSlot slot, int portIndex, String callingPackage, |
| 9791 | boolean hasReadPermission) { |
| 9792 | String iccId = slot.getIccId(portIndex); |
| 9793 | if (hasReadPermission) { // if has read permission |
| 9794 | return iccId; |
| 9795 | } else { |
| 9796 | if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) { |
| 9797 | UiccPort port = slot.getUiccCard().getUiccPort(portIndex); |
| 9798 | // if no read permission, checking carrier privilege access |
| 9799 | if (haveCarrierPrivilegeAccess(port, callingPackage)) { |
| 9800 | return iccId; |
| 9801 | } |
| 9802 | } |
| 9803 | } |
| 9804 | // No read permission or carrier privilege access. |
| 9805 | return UiccPortInfo.ICCID_REDACTED; |
| 9806 | } |
| 9807 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9808 | @Override |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9809 | @Deprecated |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9810 | public boolean switchSlots(int[] physicalSlots) { |
| 9811 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9812 | |
| 9813 | final long identity = Binder.clearCallingIdentity(); |
| 9814 | try { |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9815 | List<UiccSlotMapping> slotMappings = new ArrayList<>(); |
| 9816 | for (int i = 0; i < physicalSlots.length; i++) { |
| 9817 | // Deprecated API, hence MEP is not supported. Adding default portIndex 0. |
| 9818 | slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX, |
| 9819 | physicalSlots[i], i)); |
| 9820 | } |
| 9821 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9822 | } finally { |
| 9823 | Binder.restoreCallingIdentity(identity); |
| 9824 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9825 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 9826 | |
| 9827 | @Override |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9828 | @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 9829 | public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) { |
| 9830 | enforceModifyPermission(); |
| 9831 | |
| 9832 | final long identity = Binder.clearCallingIdentity(); |
| 9833 | try { |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9834 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping); |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9835 | } finally { |
| 9836 | Binder.restoreCallingIdentity(identity); |
| 9837 | } |
| 9838 | } |
| 9839 | |
| 9840 | @Override |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 9841 | public int getCardIdForDefaultEuicc(int subId, String callingPackage) { |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 9842 | final long identity = Binder.clearCallingIdentity(); |
| 9843 | try { |
| 9844 | return UiccController.getInstance().getCardIdForDefaultEuicc(); |
| 9845 | } finally { |
| 9846 | Binder.restoreCallingIdentity(identity); |
| 9847 | } |
| 9848 | } |
| 9849 | |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9850 | /** |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 9851 | * A test API to reload the UICC profile. |
| 9852 | * |
| 9853 | * <p>Requires that the calling app has permission |
| 9854 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 9855 | * @hide |
| 9856 | */ |
| 9857 | @Override |
| 9858 | public void refreshUiccProfile(int subId) { |
| 9859 | enforceModifyPermission(); |
| 9860 | |
| 9861 | final long identity = Binder.clearCallingIdentity(); |
| 9862 | try { |
| 9863 | Phone phone = getPhone(subId); |
| 9864 | if (phone == null) { |
| 9865 | return; |
| 9866 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9867 | UiccPort uiccPort = phone.getUiccPort(); |
| 9868 | if (uiccPort == null) { |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 9869 | return; |
| 9870 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9871 | UiccProfile uiccProfile = uiccPort.getUiccProfile(); |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 9872 | if (uiccProfile == null) { |
| 9873 | return; |
| 9874 | } |
| 9875 | uiccProfile.refresh(); |
| 9876 | } finally { |
| 9877 | Binder.restoreCallingIdentity(identity); |
| 9878 | } |
| 9879 | } |
| 9880 | |
| 9881 | /** |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9882 | * Returns false if the mobile data is disabled by default, otherwise return true. |
| 9883 | */ |
| 9884 | private boolean getDefaultDataEnabled() { |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 9885 | return TelephonyProperties.mobile_data().orElse(true); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9886 | } |
| 9887 | |
| 9888 | /** |
| 9889 | * Returns true if the data roaming is enabled by default, i.e the system property |
| 9890 | * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of |
| 9891 | * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true. |
| 9892 | */ |
| 9893 | private boolean getDefaultDataRoamingEnabled(int subId) { |
| 9894 | final CarrierConfigManager configMgr = (CarrierConfigManager) |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9895 | mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Shuo Qian | 1d84a0e | 2020-07-15 12:36:44 -0700 | [diff] [blame] | 9896 | boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9897 | isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean( |
| 9898 | CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL); |
| 9899 | return isDataRoamingEnabled; |
| 9900 | } |
| 9901 | |
| 9902 | /** |
| 9903 | * Returns the default network type for the given {@code subId}, if the default network type is |
| 9904 | * not set, return {@link Phone#PREFERRED_NT_MODE}. |
| 9905 | */ |
| 9906 | private int getDefaultNetworkType(int subId) { |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 9907 | List<Integer> list = TelephonyProperties.default_network(); |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 9908 | int phoneId = SubscriptionManager.getPhoneId(subId); |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 9909 | if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) { |
| 9910 | return list.get(phoneId); |
| 9911 | } |
| 9912 | return Phone.PREFERRED_NT_MODE; |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9913 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9914 | |
| 9915 | @Override |
| 9916 | public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 9917 | gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) { |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9918 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9919 | |
| 9920 | final long identity = Binder.clearCallingIdentity(); |
| 9921 | try { |
| 9922 | final Phone phone = getPhone(subId); |
| 9923 | if (phone == null) { |
| 9924 | loge("setCarrierTestOverride fails with invalid subId: " + subId); |
| 9925 | return; |
| 9926 | } |
Rambo Wang | 9c9ffdd | 2022-01-13 21:51:44 -0800 | [diff] [blame] | 9927 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 9928 | if (cpt != null) { |
| 9929 | cpt.setTestOverrideCarrierPrivilegeRules(carrierPrivilegeRules); |
| 9930 | } |
| 9931 | // 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] | 9932 | phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn, |
| 9933 | carrierPrivilegeRules, apn); |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 9934 | if (carrierPrivilegeRules == null) { |
| 9935 | mCarrierPrivilegeTestOverrideSubIds.remove(subId); |
| 9936 | } else { |
| 9937 | mCarrierPrivilegeTestOverrideSubIds.add(subId); |
| 9938 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9939 | } finally { |
| 9940 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9941 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9942 | } |
| 9943 | |
| 9944 | @Override |
| 9945 | public int getCarrierIdListVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 9946 | enforceReadPrivilegedPermission("getCarrierIdListVersion"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9947 | |
| 9948 | final long identity = Binder.clearCallingIdentity(); |
| 9949 | try { |
| 9950 | final Phone phone = getPhone(subId); |
| 9951 | if (phone == null) { |
| 9952 | loge("getCarrierIdListVersion fails with invalid subId: " + subId); |
| 9953 | return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION; |
| 9954 | } |
| 9955 | return phone.getCarrierIdListVersion(); |
| 9956 | } finally { |
| 9957 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9958 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9959 | } |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 9960 | |
| 9961 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9962 | public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage, |
| 9963 | String callingFeatureId) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 9964 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9965 | mApp, subId, callingPackage, callingFeatureId, |
| 9966 | "getNumberOfModemsWithSimultaneousDataConnections")) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 9967 | return -1; |
| 9968 | } |
| 9969 | |
| 9970 | final long identity = Binder.clearCallingIdentity(); |
| 9971 | try { |
| 9972 | return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections(); |
| 9973 | } finally { |
| 9974 | Binder.restoreCallingIdentity(identity); |
| 9975 | } |
| 9976 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9977 | |
| 9978 | @Override |
| 9979 | public int getCdmaRoamingMode(int subId) { |
zoey chen | 7e6d4e5 | 2019-12-17 18:18:59 +0800 | [diff] [blame] | 9980 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9981 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame^] | 9982 | mApp, subId, "getCdmaRoamingMode"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9983 | |
| 9984 | final long identity = Binder.clearCallingIdentity(); |
| 9985 | try { |
| 9986 | return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId); |
| 9987 | } finally { |
| 9988 | Binder.restoreCallingIdentity(identity); |
| 9989 | } |
| 9990 | } |
| 9991 | |
| 9992 | @Override |
| 9993 | public boolean setCdmaRoamingMode(int subId, int mode) { |
| 9994 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9995 | mApp, subId, "setCdmaRoamingMode"); |
| 9996 | |
| 9997 | final long identity = Binder.clearCallingIdentity(); |
| 9998 | try { |
| 9999 | return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId); |
| 10000 | } finally { |
| 10001 | Binder.restoreCallingIdentity(identity); |
| 10002 | } |
| 10003 | } |
| 10004 | |
| 10005 | @Override |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 10006 | public int getCdmaSubscriptionMode(int subId) { |
| 10007 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 10008 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 10009 | mApp, subId, "getCdmaSubscriptionMode"); |
| 10010 | |
| 10011 | final long identity = Binder.clearCallingIdentity(); |
| 10012 | try { |
| 10013 | return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId); |
| 10014 | } finally { |
| 10015 | Binder.restoreCallingIdentity(identity); |
| 10016 | } |
| 10017 | } |
| 10018 | |
| 10019 | @Override |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 10020 | public boolean setCdmaSubscriptionMode(int subId, int mode) { |
| 10021 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 10022 | mApp, subId, "setCdmaSubscriptionMode"); |
| 10023 | |
| 10024 | final long identity = Binder.clearCallingIdentity(); |
| 10025 | try { |
| 10026 | return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId); |
| 10027 | } finally { |
| 10028 | Binder.restoreCallingIdentity(identity); |
| 10029 | } |
| 10030 | } |
Makoto Onuki | da3bf79 | 2018-09-18 16:06:29 -0700 | [diff] [blame] | 10031 | |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 10032 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 10033 | public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10034 | String callingPackage, String callingFeatureId) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10035 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10036 | mApp, getDefaultSubscription(), callingPackage, callingFeatureId, |
| 10037 | "getEmergencyNumberList")) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10038 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 10039 | } |
| 10040 | final long identity = Binder.clearCallingIdentity(); |
| 10041 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 10042 | Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>(); |
| 10043 | for (Phone phone: PhoneFactory.getPhones()) { |
| 10044 | if (phone.getEmergencyNumberTracker() != null |
| 10045 | && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) { |
| 10046 | emergencyNumberListInternal.put( |
| 10047 | phone.getSubId(), |
| 10048 | phone.getEmergencyNumberTracker().getEmergencyNumberList()); |
| 10049 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10050 | } |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 10051 | return emergencyNumberListInternal; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10052 | } finally { |
| 10053 | Binder.restoreCallingIdentity(identity); |
| 10054 | } |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 10055 | } |
| 10056 | |
| 10057 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 10058 | public boolean isEmergencyNumber(String number, boolean exactMatch) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 10059 | final Phone defaultPhone = getDefaultPhone(); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10060 | if (!exactMatch) { |
| 10061 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 10062 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 10063 | mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)"); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10064 | } |
| 10065 | final long identity = Binder.clearCallingIdentity(); |
| 10066 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 10067 | for (Phone phone: PhoneFactory.getPhones()) { |
Chinmay Dhodapkar | d521bb1 | 2022-08-16 15:49:54 -0700 | [diff] [blame] | 10068 | //Note: we ignore passed in param exactMatch. We can remove it once |
| 10069 | // TelephonyManager#isPotentialEmergencyNumber is removed completely |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 10070 | if (phone.getEmergencyNumberTracker() != null |
Taesu Lee | e050c00 | 2020-10-13 17:19:35 +0900 | [diff] [blame] | 10071 | && phone.getEmergencyNumberTracker() |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame^] | 10072 | .isEmergencyNumber(number)) { |
Taesu Lee | e050c00 | 2020-10-13 17:19:35 +0900 | [diff] [blame] | 10073 | return true; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10074 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10075 | } |
| 10076 | return false; |
| 10077 | } finally { |
| 10078 | Binder.restoreCallingIdentity(identity); |
| 10079 | } |
| 10080 | } |
| 10081 | |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 10082 | /** |
Shuo Qian | ccbaf74 | 2021-02-22 18:32:21 -0800 | [diff] [blame] | 10083 | * Start emergency callback mode for GsmCdmaPhone for testing. |
| 10084 | */ |
| 10085 | @Override |
| 10086 | public void startEmergencyCallbackMode() { |
| 10087 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10088 | "startEmergencyCallbackMode"); |
| 10089 | enforceModifyPermission(); |
| 10090 | final long identity = Binder.clearCallingIdentity(); |
| 10091 | try { |
| 10092 | for (Phone phone : PhoneFactory.getPhones()) { |
| 10093 | Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType()); |
| 10094 | if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM) |
| 10095 | || (phone.getPhoneType() == PHONE_TYPE_CDMA))) { |
| 10096 | GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone; |
| 10097 | gsmCdmaPhone.obtainMessage( |
| 10098 | GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget(); |
| 10099 | Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered"); |
| 10100 | } |
| 10101 | } |
| 10102 | } finally { |
| 10103 | Binder.restoreCallingIdentity(identity); |
| 10104 | } |
| 10105 | } |
| 10106 | |
| 10107 | /** |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 10108 | * Update emergency number list for test mode. |
| 10109 | */ |
| 10110 | @Override |
| 10111 | public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) { |
| 10112 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10113 | "updateEmergencyNumberListTestMode"); |
| 10114 | |
| 10115 | final long identity = Binder.clearCallingIdentity(); |
| 10116 | try { |
| 10117 | for (Phone phone: PhoneFactory.getPhones()) { |
| 10118 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 10119 | if (tracker != null) { |
| 10120 | tracker.executeEmergencyNumberTestModeCommand(action, num); |
| 10121 | } |
| 10122 | } |
| 10123 | } finally { |
| 10124 | Binder.restoreCallingIdentity(identity); |
| 10125 | } |
| 10126 | } |
| 10127 | |
| 10128 | /** |
| 10129 | * Get the full emergency number list for test mode. |
| 10130 | */ |
| 10131 | @Override |
| 10132 | public List<String> getEmergencyNumberListTestMode() { |
| 10133 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10134 | "getEmergencyNumberListTestMode"); |
| 10135 | |
| 10136 | final long identity = Binder.clearCallingIdentity(); |
| 10137 | try { |
| 10138 | Set<String> emergencyNumbers = new HashSet<>(); |
| 10139 | for (Phone phone: PhoneFactory.getPhones()) { |
| 10140 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 10141 | if (tracker != null) { |
| 10142 | for (EmergencyNumber num : tracker.getEmergencyNumberList()) { |
| 10143 | emergencyNumbers.add(num.getNumber()); |
| 10144 | } |
| 10145 | } |
| 10146 | } |
| 10147 | return new ArrayList<>(emergencyNumbers); |
| 10148 | } finally { |
| 10149 | Binder.restoreCallingIdentity(identity); |
| 10150 | } |
| 10151 | } |
| 10152 | |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 10153 | @Override |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 10154 | public int getEmergencyNumberDbVersion(int subId) { |
| 10155 | enforceReadPrivilegedPermission("getEmergencyNumberDbVersion"); |
| 10156 | |
| 10157 | final long identity = Binder.clearCallingIdentity(); |
| 10158 | try { |
| 10159 | final Phone phone = getPhone(subId); |
| 10160 | if (phone == null) { |
| 10161 | loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId); |
| 10162 | return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION; |
| 10163 | } |
| 10164 | return phone.getEmergencyNumberDbVersion(); |
| 10165 | } finally { |
| 10166 | Binder.restoreCallingIdentity(identity); |
| 10167 | } |
| 10168 | } |
| 10169 | |
| 10170 | @Override |
| 10171 | public void notifyOtaEmergencyNumberDbInstalled() { |
| 10172 | enforceModifyPermission(); |
| 10173 | |
| 10174 | final long identity = Binder.clearCallingIdentity(); |
| 10175 | try { |
| 10176 | for (Phone phone: PhoneFactory.getPhones()) { |
| 10177 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 10178 | if (tracker != null) { |
| 10179 | tracker.updateOtaEmergencyNumberDatabase(); |
| 10180 | } |
| 10181 | } |
| 10182 | } finally { |
| 10183 | Binder.restoreCallingIdentity(identity); |
| 10184 | } |
| 10185 | } |
| 10186 | |
| 10187 | @Override |
Shuo Qian | c373f11 | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 10188 | public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) { |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 10189 | enforceActiveEmergencySessionPermission(); |
| 10190 | |
| 10191 | final long identity = Binder.clearCallingIdentity(); |
| 10192 | try { |
| 10193 | for (Phone phone: PhoneFactory.getPhones()) { |
| 10194 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 10195 | if (tracker != null) { |
Shuo Qian | c373f11 | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 10196 | tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor); |
| 10197 | } |
| 10198 | } |
| 10199 | } finally { |
| 10200 | Binder.restoreCallingIdentity(identity); |
| 10201 | } |
| 10202 | } |
| 10203 | |
| 10204 | @Override |
| 10205 | public void resetOtaEmergencyNumberDbFilePath() { |
| 10206 | enforceActiveEmergencySessionPermission(); |
| 10207 | |
| 10208 | final long identity = Binder.clearCallingIdentity(); |
| 10209 | try { |
| 10210 | for (Phone phone: PhoneFactory.getPhones()) { |
| 10211 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 10212 | if (tracker != null) { |
| 10213 | tracker.resetOtaEmergencyNumberDbFilePath(); |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 10214 | } |
| 10215 | } |
| 10216 | } finally { |
| 10217 | Binder.restoreCallingIdentity(identity); |
| 10218 | } |
| 10219 | } |
| 10220 | |
| 10221 | @Override |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 10222 | public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) { |
| 10223 | enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules"); |
| 10224 | Phone phone = getPhone(subId); |
| 10225 | if (phone == null) { |
| 10226 | return null; |
| 10227 | } |
| 10228 | final long identity = Binder.clearCallingIdentity(); |
| 10229 | try { |
| 10230 | UiccProfile profile = UiccController.getInstance() |
| 10231 | .getUiccProfileForPhone(phone.getPhoneId()); |
| 10232 | if (profile != null) { |
| 10233 | return profile.getCertsFromCarrierPrivilegeAccessRules(); |
| 10234 | } |
| 10235 | } finally { |
| 10236 | Binder.restoreCallingIdentity(identity); |
| 10237 | } |
| 10238 | return null; |
| 10239 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 10240 | |
| 10241 | /** |
| 10242 | * Enable or disable a modem stack. |
| 10243 | */ |
| 10244 | @Override |
| 10245 | public boolean enableModemForSlot(int slotIndex, boolean enable) { |
| 10246 | enforceModifyPermission(); |
| 10247 | |
| 10248 | final long identity = Binder.clearCallingIdentity(); |
| 10249 | try { |
| 10250 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 10251 | if (phone == null) { |
| 10252 | return false; |
| 10253 | } else { |
| 10254 | return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null); |
| 10255 | } |
| 10256 | } finally { |
| 10257 | Binder.restoreCallingIdentity(identity); |
| 10258 | } |
| 10259 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 10260 | |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 10261 | /** |
| 10262 | * Whether a modem stack is enabled or not. |
| 10263 | */ |
| 10264 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10265 | public boolean isModemEnabledForSlot(int slotIndex, String callingPackage, |
| 10266 | String callingFeatureId) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 10267 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 10268 | if (phone == null) return false; |
| 10269 | |
| 10270 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10271 | mApp, phone.getSubId(), callingPackage, callingFeatureId, |
| 10272 | "isModemEnabledForSlot")) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 10273 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 10274 | } |
| 10275 | |
| 10276 | final long identity = Binder.clearCallingIdentity(); |
| 10277 | try { |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 10278 | try { |
| 10279 | return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId()); |
| 10280 | } catch (NoSuchElementException ex) { |
| 10281 | return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null); |
| 10282 | } |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 10283 | } finally { |
| 10284 | Binder.restoreCallingIdentity(identity); |
| 10285 | } |
| 10286 | } |
| 10287 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 10288 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10289 | public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) { |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 10290 | enforceModifyPermission(); |
| 10291 | |
| 10292 | final long identity = Binder.clearCallingIdentity(); |
| 10293 | try { |
| 10294 | mTelephonySharedPreferences.edit() |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10295 | .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted) |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 10296 | .commit(); |
| 10297 | } finally { |
| 10298 | Binder.restoreCallingIdentity(identity); |
| 10299 | } |
| 10300 | } |
| 10301 | |
| 10302 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10303 | @TelephonyManager.IsMultiSimSupportedResult |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10304 | public int isMultiSimSupported(String callingPackage, String callingFeatureId) { |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 10305 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10306 | getDefaultPhone().getSubId(), callingPackage, callingFeatureId, |
| 10307 | "isMultiSimSupported")) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10308 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 10309 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 10310 | |
| 10311 | final long identity = Binder.clearCallingIdentity(); |
| 10312 | try { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10313 | return isMultiSimSupportedInternal(); |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 10314 | } finally { |
| 10315 | Binder.restoreCallingIdentity(identity); |
| 10316 | } |
| 10317 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 10318 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10319 | @TelephonyManager.IsMultiSimSupportedResult |
| 10320 | private int isMultiSimSupportedInternal() { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10321 | // If the device has less than 2 SIM cards, indicate that multisim is restricted. |
| 10322 | int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length; |
| 10323 | if (numPhysicalSlots < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10324 | loge("isMultiSimSupportedInternal: requires at least 2 cards"); |
| 10325 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10326 | } |
| 10327 | // Check if the hardware supports multisim functionality. If usage of multisim is not |
| 10328 | // supported by the modem, indicate that it is restricted. |
| 10329 | PhoneCapability staticCapability = |
| 10330 | mPhoneConfigurationManager.getStaticPhoneCapability(); |
| 10331 | if (staticCapability == null) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10332 | loge("isMultiSimSupportedInternal: no static configuration available"); |
| 10333 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10334 | } |
SongFerngWang | 8236caa | 2021-01-17 21:51:44 +0800 | [diff] [blame] | 10335 | if (staticCapability.getLogicalModemList().size() < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10336 | loge("isMultiSimSupportedInternal: maximum number of modem is < 2"); |
| 10337 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10338 | } |
| 10339 | // Check if support of multiple SIMs is restricted by carrier |
| 10340 | if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10341 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10342 | } |
| 10343 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10344 | return TelephonyManager.MULTISIM_ALLOWED; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10345 | } |
| 10346 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 10347 | /** |
| 10348 | * Switch configs to enable multi-sim or switch back to single-sim |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 10349 | * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE |
| 10350 | * permission, but the other way around is possible with either MODIFY_PHONE_STATE |
| 10351 | * or carrier privileges |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 10352 | * @param numOfSims number of active sims we want to switch to |
| 10353 | */ |
| 10354 | @Override |
| 10355 | public void switchMultiSimConfig(int numOfSims) { |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 10356 | if (numOfSims == 1) { |
| 10357 | enforceModifyPermission(); |
| 10358 | } else { |
| 10359 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 10360 | mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig"); |
| 10361 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 10362 | final long identity = Binder.clearCallingIdentity(); |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10363 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 10364 | try { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10365 | //only proceed if multi-sim is not restricted |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10366 | if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10367 | loge("switchMultiSimConfig not possible. It is restricted or not supported."); |
| 10368 | return; |
| 10369 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 10370 | mPhoneConfigurationManager.switchMultiSimConfig(numOfSims); |
| 10371 | } finally { |
| 10372 | Binder.restoreCallingIdentity(identity); |
| 10373 | } |
| 10374 | } |
| 10375 | |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 10376 | @Override |
| 10377 | public boolean isApplicationOnUicc(int subId, int appType) { |
| 10378 | enforceReadPrivilegedPermission("isApplicationOnUicc"); |
| 10379 | Phone phone = getPhone(subId); |
| 10380 | if (phone == null) { |
| 10381 | return false; |
| 10382 | } |
| 10383 | final long identity = Binder.clearCallingIdentity(); |
| 10384 | try { |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 10385 | UiccPort uiccPort = phone.getUiccPort(); |
| 10386 | if (uiccPort == null) { |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 10387 | return false; |
| 10388 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 10389 | UiccProfile uiccProfile = uiccPort.getUiccProfile(); |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 10390 | if (uiccProfile == null) { |
| 10391 | return false; |
| 10392 | } |
| 10393 | if (TelephonyManager.APPTYPE_SIM <= appType |
| 10394 | && appType <= TelephonyManager.APPTYPE_ISIM) { |
| 10395 | return uiccProfile.isApplicationOnIcc(AppType.values()[appType]); |
| 10396 | } |
| 10397 | return false; |
| 10398 | } finally { |
| 10399 | Binder.restoreCallingIdentity(identity); |
| 10400 | } |
| 10401 | } |
| 10402 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 10403 | /** |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 10404 | * Get whether making changes to modem configurations will trigger reboot. |
| 10405 | * Return value defaults to true. |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 10406 | */ |
| 10407 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10408 | public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage, |
| 10409 | String callingFeatureId) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 10410 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10411 | mApp, subId, callingPackage, callingFeatureId, |
| 10412 | "doesSwitchMultiSimConfigTriggerReboot")) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 10413 | return false; |
| 10414 | } |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 10415 | final long identity = Binder.clearCallingIdentity(); |
| 10416 | try { |
| 10417 | return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange(); |
| 10418 | } finally { |
| 10419 | Binder.restoreCallingIdentity(identity); |
| 10420 | } |
| 10421 | } |
| 10422 | |
Nathan Harold | 29f5f05 | 2019-02-15 13:41:57 -0800 | [diff] [blame] | 10423 | private void updateModemStateMetrics() { |
| 10424 | TelephonyMetrics metrics = TelephonyMetrics.getInstance(); |
| 10425 | // TODO: check the state for each modem if the api is ready. |
| 10426 | metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1); |
| 10427 | } |
| 10428 | |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10429 | @Override |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 10430 | public List<UiccSlotMapping> getSlotsMapping(String callingPackage) { |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10431 | enforceReadPrivilegedPermission("getSlotsMapping"); |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 10432 | // Verify that the callingPackage belongs to the calling UID |
| 10433 | mApp.getSystemService(AppOpsManager.class) |
| 10434 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10435 | final long identity = Binder.clearCallingIdentity(); |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 10436 | List<UiccSlotMapping> slotMap = new ArrayList<>(); |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10437 | try { |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 10438 | UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName()); |
| 10439 | if (slotInfos != null) { |
| 10440 | for (int i = 0; i < slotInfos.length; i++) { |
| 10441 | for (UiccPortInfo portInfo : slotInfos[i].getPorts()) { |
| 10442 | if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) { |
| 10443 | slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i, |
| 10444 | portInfo.getLogicalSlotIndex())); |
| 10445 | } |
| 10446 | } |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10447 | } |
| 10448 | } |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 10449 | return slotMap; |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10450 | } finally { |
| 10451 | Binder.restoreCallingIdentity(identity); |
| 10452 | } |
| 10453 | } |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 10454 | |
| 10455 | /** |
| 10456 | * Get the IRadio HAL Version |
jimsun | f9ec162 | 2022-09-13 21:18:43 +0800 | [diff] [blame] | 10457 | * @deprecated use getHalVersion instead |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 10458 | */ |
jimsun | f9ec162 | 2022-09-13 21:18:43 +0800 | [diff] [blame] | 10459 | @Deprecated |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 10460 | @Override |
| 10461 | public int getRadioHalVersion() { |
jimsun | f9ec162 | 2022-09-13 21:18:43 +0800 | [diff] [blame] | 10462 | return getHalVersion(HAL_SERVICE_RADIO); |
| 10463 | } |
| 10464 | |
| 10465 | /** |
| 10466 | * Get the HAL Version of a specific service |
| 10467 | */ |
| 10468 | @Override |
| 10469 | public int getHalVersion(int service) { |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 10470 | Phone phone = getDefaultPhone(); |
| 10471 | if (phone == null) return -1; |
jimsun | f9ec162 | 2022-09-13 21:18:43 +0800 | [diff] [blame] | 10472 | HalVersion hv = phone.getHalVersion(service); |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 10473 | if (hv.equals(HalVersion.UNKNOWN)) return -1; |
| 10474 | return hv.major * 100 + hv.minor; |
| 10475 | } |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 10476 | |
| 10477 | /** |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 10478 | * Get the current calling package name. |
| 10479 | * @return the current calling package name |
| 10480 | */ |
| 10481 | @Override |
| 10482 | public String getCurrentPackageName() { |
| 10483 | return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0]; |
| 10484 | } |
| 10485 | |
| 10486 | /** |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10487 | * Return whether data is enabled for certain APN type. This will tell if framework will accept |
| 10488 | * corresponding network requests on a subId. |
| 10489 | * |
| 10490 | * Data is enabled if: |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 10491 | * 1) user data is turned on, or |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10492 | * 2) APN is un-metered for this subscription, or |
| 10493 | * 3) APN type is whitelisted. E.g. MMS is whitelisted if |
Hall Liu | 746e03c | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 10494 | * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled. |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10495 | * |
| 10496 | * @return whether data is allowed for a apn type. |
| 10497 | * |
| 10498 | * @hide |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 10499 | */ |
| 10500 | @Override |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10501 | public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) { |
Amit Mahajan | 5d4e192 | 2019-10-07 16:20:43 -0700 | [diff] [blame] | 10502 | enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for " |
| 10503 | + "isDataEnabledForApn"); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 10504 | |
| 10505 | // Now that all security checks passes, perform the operation as ourselves. |
| 10506 | final long identity = Binder.clearCallingIdentity(); |
| 10507 | try { |
| 10508 | Phone phone = getPhone(subId); |
| 10509 | if (phone == null) return false; |
| 10510 | |
Jack Yu | 27422a5 | 2022-03-21 10:38:05 -0700 | [diff] [blame] | 10511 | boolean isMetered; |
Jack Yu | 99e8733 | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 10512 | boolean isDataEnabled; |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 10513 | isMetered = phone.getDataNetworkController().getDataConfigManager() |
| 10514 | .isMeteredCapability(DataUtils.apnTypeToNetworkCapability(apnType), |
| 10515 | phone.getServiceState().getDataRoaming()); |
| 10516 | isDataEnabled = phone.getDataSettingsManager().isDataEnabled(apnType); |
Jack Yu | 99e8733 | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 10517 | return !isMetered || isDataEnabled; |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10518 | } finally { |
| 10519 | Binder.restoreCallingIdentity(identity); |
| 10520 | } |
| 10521 | } |
| 10522 | |
| 10523 | @Override |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 10524 | public boolean isApnMetered(@ApnType int apnType, int subId) { |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10525 | enforceReadPrivilegedPermission("isApnMetered"); |
| 10526 | |
| 10527 | // Now that all security checks passes, perform the operation as ourselves. |
| 10528 | final long identity = Binder.clearCallingIdentity(); |
| 10529 | try { |
| 10530 | Phone phone = getPhone(subId); |
| 10531 | if (phone == null) return true; // By default return true. |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 10532 | return phone.getDataNetworkController().getDataConfigManager().isMeteredCapability( |
| 10533 | DataUtils.apnTypeToNetworkCapability(apnType), |
| 10534 | phone.getServiceState().getDataRoaming()); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 10535 | } finally { |
| 10536 | Binder.restoreCallingIdentity(identity); |
| 10537 | } |
| 10538 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 10539 | |
| 10540 | @Override |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 10541 | public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers, |
| 10542 | int subscriptionId, IBooleanConsumer resultCallback) { |
| 10543 | enforceModifyPermission(); |
| 10544 | long token = Binder.clearCallingIdentity(); |
| 10545 | try { |
| 10546 | Phone phone = getPhone(subscriptionId); |
| 10547 | if (phone == null) { |
| 10548 | try { |
| 10549 | if (resultCallback != null) { |
| 10550 | resultCallback.accept(false); |
| 10551 | } |
| 10552 | } catch (RemoteException e) { |
| 10553 | // ignore |
| 10554 | } |
| 10555 | return; |
| 10556 | } |
| 10557 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument = |
| 10558 | Pair.create(specifiers, (x) -> { |
| 10559 | try { |
| 10560 | if (resultCallback != null) { |
| 10561 | resultCallback.accept(x); |
| 10562 | } |
| 10563 | } catch (RemoteException e) { |
| 10564 | // ignore |
| 10565 | } |
| 10566 | }); |
| 10567 | sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null); |
| 10568 | } finally { |
| 10569 | Binder.restoreCallingIdentity(token); |
| 10570 | } |
| 10571 | } |
| 10572 | |
| 10573 | @Override |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 10574 | public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) { |
| 10575 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 10576 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 10577 | mApp, subId, "getSystemSelectionChannels"); |
| 10578 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 10579 | final long identity = Binder.clearCallingIdentity(); |
| 10580 | try { |
Sarah Chin | 428d1d6 | 2021-03-13 03:17:40 -0800 | [diff] [blame] | 10581 | Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource); |
| 10582 | if (result instanceof IllegalStateException) { |
| 10583 | throw (IllegalStateException) result; |
| 10584 | } |
| 10585 | List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 10586 | if (DBG) log("getSystemSelectionChannels: " + specifiers); |
| 10587 | return specifiers; |
| 10588 | } finally { |
| 10589 | Binder.restoreCallingIdentity(identity); |
| 10590 | } |
| 10591 | } |
| 10592 | |
| 10593 | @Override |
Jack Yu | 8b766fc | 2022-03-21 09:42:33 -0700 | [diff] [blame] | 10594 | public boolean isMvnoMatched(int slotIndex, int mvnoType, @NonNull String mvnoMatchData) { |
changbetty | ca3d40d | 2020-03-03 16:27:31 +0800 | [diff] [blame] | 10595 | enforceReadPrivilegedPermission("isMvnoMatched"); |
Jack Yu | 8b766fc | 2022-03-21 09:42:33 -0700 | [diff] [blame] | 10596 | return UiccController.getInstance().mvnoMatches(slotIndex, mvnoType, mvnoMatchData); |
changbetty | 7157e9e | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 10597 | } |
| 10598 | |
| 10599 | @Override |
Philip P. Moltmann | d02b737 | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 10600 | public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag, |
| 10601 | IIntegerConsumer pendingSubIdResult) { |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 10602 | if (callingPackage == null) { |
| 10603 | callingPackage = getCurrentPackageName(); |
| 10604 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 10605 | SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp, |
| 10606 | (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE)); |
Philip P. Moltmann | d02b737 | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 10607 | if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag, |
| 10608 | "Sending message")) { |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 10609 | throw new SecurityException("Requires SEND_SMS permission to perform this operation"); |
| 10610 | } |
| 10611 | PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult); |
| 10612 | Intent intent = new Intent(); |
| 10613 | intent.setClass(mApp, PickSmsSubscriptionActivity.class); |
| 10614 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 10615 | // Bring up choose default SMS subscription dialog right now |
| 10616 | intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY, |
| 10617 | PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE); |
| 10618 | mApp.startActivity(intent); |
| 10619 | } |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 10620 | |
| 10621 | @Override |
Ayush Sharma | 787854b | 2022-12-12 14:55:02 +0000 | [diff] [blame] | 10622 | public void showSwitchToManagedProfileDialog() { |
| 10623 | enforceModifyPermission(); |
| 10624 | |
| 10625 | Intent intent = new Intent(); |
| 10626 | intent.setClass(mApp, ErrorDialogActivity.class); |
| 10627 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 10628 | mApp.startActivity(intent); |
| 10629 | } |
| 10630 | |
| 10631 | @Override |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 10632 | public String getMmsUAProfUrl(int subId) { |
| 10633 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 10634 | final long identity = Binder.clearCallingIdentity(); |
| 10635 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 10636 | String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString( |
| 10637 | CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING); |
| 10638 | if (!TextUtils.isEmpty(carrierUAProfUrl)) { |
| 10639 | return carrierUAProfUrl; |
| 10640 | } |
Daniel Bright | ebb4eb7 | 2020-02-18 15:16:33 -0800 | [diff] [blame] | 10641 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 10642 | .getString(com.android.internal.R.string.config_mms_user_agent_profile_url); |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 10643 | } finally { |
| 10644 | Binder.restoreCallingIdentity(identity); |
| 10645 | } |
| 10646 | } |
| 10647 | |
| 10648 | @Override |
| 10649 | public String getMmsUserAgent(int subId) { |
| 10650 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 10651 | final long identity = Binder.clearCallingIdentity(); |
| 10652 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 10653 | String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString( |
| 10654 | CarrierConfigManager.KEY_MMS_USER_AGENT_STRING); |
| 10655 | if (!TextUtils.isEmpty(carrierUserAgent)) { |
| 10656 | return carrierUserAgent; |
| 10657 | } |
Daniel Bright | ebb4eb7 | 2020-02-18 15:16:33 -0800 | [diff] [blame] | 10658 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 10659 | .getString(com.android.internal.R.string.config_mms_user_agent); |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 10660 | } finally { |
| 10661 | Binder.restoreCallingIdentity(identity); |
| 10662 | } |
| 10663 | } |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 10664 | |
| 10665 | @Override |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 10666 | public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) { |
| 10667 | enforceReadPrivilegedPermission("isMobileDataPolicyEnabled"); |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 10668 | |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 10669 | final long identity = Binder.clearCallingIdentity(); |
| 10670 | try { |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 10671 | Phone phone = getPhone(subscriptionId); |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 10672 | if (phone == null) return false; |
| 10673 | |
Ling Ma | f188d50 | 2022-09-16 15:22:36 -0700 | [diff] [blame] | 10674 | return phone.getDataSettingsManager().isMobileDataPolicyEnabled(policy); |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 10675 | } finally { |
| 10676 | Binder.restoreCallingIdentity(identity); |
| 10677 | } |
| 10678 | } |
| 10679 | |
| 10680 | @Override |
Hall Liu | c66bb11 | 2021-02-02 12:09:32 -0800 | [diff] [blame] | 10681 | public void setMobileDataPolicyEnabled(int subscriptionId, int policy, |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 10682 | boolean enabled) { |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 10683 | enforceModifyPermission(); |
| 10684 | |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 10685 | final long identity = Binder.clearCallingIdentity(); |
| 10686 | try { |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 10687 | Phone phone = getPhone(subscriptionId); |
| 10688 | if (phone == null) return; |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 10689 | |
Ling Ma | f188d50 | 2022-09-16 15:22:36 -0700 | [diff] [blame] | 10690 | phone.getDataSettingsManager().setMobileDataPolicy(policy, enabled); |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 10691 | } finally { |
| 10692 | Binder.restoreCallingIdentity(identity); |
| 10693 | } |
| 10694 | } |
| 10695 | |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 10696 | /** |
Hall Liu | 746e03c | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 10697 | * Updates whether conference event package handling is enabled. |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 10698 | * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false} |
| 10699 | * otherwise. |
| 10700 | */ |
| 10701 | @Override |
| 10702 | public void setCepEnabled(boolean isCepEnabled) { |
| 10703 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled"); |
| 10704 | |
| 10705 | final long identity = Binder.clearCallingIdentity(); |
| 10706 | try { |
| 10707 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled); |
| 10708 | for (Phone phone : PhoneFactory.getPhones()) { |
| 10709 | Phone defaultPhone = phone.getImsPhone(); |
| 10710 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 10711 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 10712 | ImsPhoneCallTracker imsPhoneCallTracker = |
| 10713 | (ImsPhoneCallTracker) imsPhone.getCallTracker(); |
| 10714 | imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled); |
| 10715 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone " |
| 10716 | + imsPhone.getMsisdn()); |
| 10717 | } |
| 10718 | } |
| 10719 | } finally { |
| 10720 | Binder.restoreCallingIdentity(identity); |
| 10721 | } |
| 10722 | } |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 10723 | |
| 10724 | /** |
| 10725 | * Notify that an RCS autoconfiguration XML file has been received for provisioning. |
| 10726 | * |
| 10727 | * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed. |
| 10728 | * @param isCompressed The XML file is compressed in gzip format and must be decompressed |
| 10729 | * before being read. |
| 10730 | */ |
| 10731 | @Override |
| 10732 | public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean |
| 10733 | isCompressed) { |
| 10734 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 10735 | mApp, subId, "notifyRcsAutoConfigurationReceived"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10736 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10737 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10738 | } |
| 10739 | if (!isImsAvailableOnDevice()) { |
joonhunshin | 46b49a3 | 2022-12-21 05:33:23 +0000 | [diff] [blame] | 10740 | // ProvisioningManager can not handle ServiceSpecificException. |
| 10741 | // Throw the IllegalStateException and annotate ProvisioningManager. |
| 10742 | throw new IllegalStateException("IMS not available on device."); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10743 | } |
| 10744 | |
| 10745 | final long identity = Binder.clearCallingIdentity(); |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 10746 | try { |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10747 | RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed); |
| 10748 | } finally { |
| 10749 | Binder.restoreCallingIdentity(identity); |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 10750 | } |
| 10751 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 10752 | |
| 10753 | @Override |
| 10754 | public boolean isIccLockEnabled(int subId) { |
| 10755 | enforceReadPrivilegedPermission("isIccLockEnabled"); |
| 10756 | |
| 10757 | // Now that all security checks passes, perform the operation as ourselves. |
| 10758 | final long identity = Binder.clearCallingIdentity(); |
| 10759 | try { |
| 10760 | Phone phone = getPhone(subId); |
| 10761 | if (phone != null && phone.getIccCard() != null) { |
| 10762 | return phone.getIccCard().getIccLockEnabled(); |
| 10763 | } else { |
| 10764 | return false; |
| 10765 | } |
| 10766 | } finally { |
| 10767 | Binder.restoreCallingIdentity(identity); |
| 10768 | } |
| 10769 | } |
| 10770 | |
| 10771 | /** |
| 10772 | * Set the ICC pin lock enabled or disabled. |
| 10773 | * |
| 10774 | * @return an integer representing the status of IccLock enabled or disabled in the following |
| 10775 | * three cases: |
| 10776 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock |
| 10777 | * successfully. |
| 10778 | * - Positive number and zero for remaining password attempts. |
| 10779 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
| 10780 | * |
| 10781 | */ |
| 10782 | @Override |
| 10783 | public int setIccLockEnabled(int subId, boolean enabled, String password) { |
| 10784 | enforceModifyPermission(); |
| 10785 | |
| 10786 | Phone phone = getPhone(subId); |
| 10787 | if (phone == null) { |
| 10788 | return 0; |
| 10789 | } |
| 10790 | // Now that all security checks passes, perform the operation as ourselves. |
| 10791 | final long identity = Binder.clearCallingIdentity(); |
| 10792 | try { |
| 10793 | int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED, |
| 10794 | new Pair<Boolean, String>(enabled, password), phone, null); |
| 10795 | return attemptsRemaining; |
| 10796 | |
| 10797 | } catch (Exception e) { |
| 10798 | Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e); |
| 10799 | } finally { |
| 10800 | Binder.restoreCallingIdentity(identity); |
| 10801 | } |
| 10802 | return 0; |
| 10803 | } |
| 10804 | |
| 10805 | /** |
| 10806 | * Change the ICC password used in ICC pin lock. |
| 10807 | * |
| 10808 | * @return an integer representing the status of IccLock changed in the following three cases: |
| 10809 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully. |
| 10810 | * - Positive number and zero for remaining password attempts. |
| 10811 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
| 10812 | * |
| 10813 | */ |
| 10814 | @Override |
| 10815 | public int changeIccLockPassword(int subId, String oldPassword, String newPassword) { |
| 10816 | enforceModifyPermission(); |
| 10817 | |
| 10818 | Phone phone = getPhone(subId); |
| 10819 | if (phone == null) { |
| 10820 | return 0; |
| 10821 | } |
| 10822 | // Now that all security checks passes, perform the operation as ourselves. |
| 10823 | final long identity = Binder.clearCallingIdentity(); |
| 10824 | try { |
| 10825 | int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD, |
| 10826 | new Pair<String, String>(oldPassword, newPassword), phone, null); |
| 10827 | return attemptsRemaining; |
| 10828 | |
| 10829 | } catch (Exception e) { |
| 10830 | Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e); |
| 10831 | } finally { |
| 10832 | Binder.restoreCallingIdentity(identity); |
| 10833 | } |
| 10834 | return 0; |
| 10835 | } |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 10836 | |
| 10837 | /** |
| 10838 | * Request for receiving user activity notification |
| 10839 | */ |
| 10840 | @Override |
| 10841 | public void requestUserActivityNotification() { |
| 10842 | if (!mNotifyUserActivity.get() |
| 10843 | && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) { |
| 10844 | mNotifyUserActivity.set(true); |
| 10845 | } |
| 10846 | } |
| 10847 | |
| 10848 | /** |
| 10849 | * Called when userActivity is signalled in the power manager. |
| 10850 | * This is safe to call from any thread, with any window manager locks held or not. |
| 10851 | */ |
| 10852 | @Override |
| 10853 | public void userActivity() { |
| 10854 | // *************************************** |
| 10855 | // * Inherited from PhoneWindowManager * |
| 10856 | // *************************************** |
| 10857 | // THIS IS CALLED FROM DEEP IN THE POWER MANAGER |
| 10858 | // WITH ITS LOCKS HELD. |
| 10859 | // |
| 10860 | // This code must be VERY careful about the locks |
| 10861 | // it acquires. |
| 10862 | // In fact, the current code acquires way too many, |
| 10863 | // and probably has lurking deadlocks. |
| 10864 | |
| 10865 | if (Binder.getCallingUid() != Process.SYSTEM_UID) { |
| 10866 | throw new SecurityException("Only the OS may call notifyUserActivity()"); |
| 10867 | } |
| 10868 | |
| 10869 | if (mNotifyUserActivity.getAndSet(false)) { |
| 10870 | mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY, |
| 10871 | USER_ACTIVITY_NOTIFICATION_DELAY); |
| 10872 | } |
| 10873 | } |
Malcolm Chen | 4639c56 | 2020-04-13 11:59:40 -0700 | [diff] [blame] | 10874 | |
| 10875 | @Override |
| 10876 | public boolean canConnectTo5GInDsdsMode() { |
| 10877 | return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode); |
| 10878 | } |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 10879 | |
| 10880 | @Override |
| 10881 | public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage, |
| 10882 | String callingFeatureId) { |
| 10883 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 10884 | mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) { |
| 10885 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 10886 | } |
| 10887 | |
| 10888 | Phone phone = getPhone(subId); |
| 10889 | if (phone == null) { |
| 10890 | throw new RuntimeException("phone is not available"); |
| 10891 | } |
| 10892 | // Now that all security checks passes, perform the operation as ourselves. |
| 10893 | final long identity = Binder.clearCallingIdentity(); |
| 10894 | try { |
| 10895 | return phone.getEquivalentHomePlmns(); |
| 10896 | } finally { |
| 10897 | Binder.restoreCallingIdentity(identity); |
| 10898 | } |
| 10899 | } |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 10900 | |
| 10901 | @Override |
| 10902 | public boolean isRadioInterfaceCapabilitySupported( |
Daniel Bright | 95a4c1f | 2021-02-11 09:57:16 -0800 | [diff] [blame] | 10903 | final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) { |
| 10904 | Set<String> radioInterfaceCapabilities = |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 10905 | mRadioInterfaceCapabilities.getCapabilities(); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 10906 | if (radioInterfaceCapabilities == null) { |
| 10907 | throw new RuntimeException("radio interface capabilities are not available"); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 10908 | } |
Daniel Bright | 95a4c1f | 2021-02-11 09:57:16 -0800 | [diff] [blame] | 10909 | return radioInterfaceCapabilities.contains(capability); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 10910 | } |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10911 | |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 10912 | @Override |
| 10913 | public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl, |
| 10914 | UaSecurityProtocolIdentifier securityProtocol, |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10915 | boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) { |
| 10916 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 10917 | Binder.getCallingUid(), "bootstrapAuthenticationRequest", |
| 10918 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 10919 | Manifest.permission.MODIFY_PHONE_STATE); |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 10920 | if (DBG) { |
| 10921 | log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:" |
| 10922 | + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol |
| 10923 | + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback); |
| 10924 | } |
| 10925 | |
| 10926 | if (!SubscriptionManager.isValidSubscriptionId(subId) |
| 10927 | || appType < TelephonyManager.APPTYPE_UNKNOWN |
| 10928 | || appType > TelephonyManager.APPTYPE_ISIM |
| 10929 | || nafUrl == null || securityProtocol == null || callback == null) { |
| 10930 | Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters"); |
| 10931 | if (callback != null) { |
| 10932 | try { |
| 10933 | callback.onAuthenticationFailure( |
| 10934 | 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED); |
| 10935 | } catch (RemoteException exception) { |
| 10936 | log("Fail to notify onAuthenticationFailure due to " + exception); |
| 10937 | } |
| 10938 | return; |
| 10939 | } |
| 10940 | } |
| 10941 | |
| 10942 | final long token = Binder.clearCallingIdentity(); |
| 10943 | try { |
| 10944 | getGbaManager(subId).bootstrapAuthenticationRequest( |
| 10945 | new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(), |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame^] | 10946 | forceBootStrapping, callback)); |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 10947 | } finally { |
| 10948 | Binder.restoreCallingIdentity(token); |
| 10949 | } |
| 10950 | } |
| 10951 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10952 | /** |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10953 | * Attempts to set the radio power state for all phones for thermal reason. |
| 10954 | * This does not guarantee that the |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10955 | * requested radio power state will actually be set. See {@link |
| 10956 | * PhoneInternalInterface#setRadioPowerForReason} for more details. |
| 10957 | * |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10958 | * @param enable {@code true} if trying to turn radio on. |
| 10959 | * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code |
| 10960 | * false}. |
| 10961 | */ |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10962 | private boolean setRadioPowerForThermal(boolean enable) { |
| 10963 | boolean isPhoneAvailable = false; |
| 10964 | for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) { |
| 10965 | Phone phone = PhoneFactory.getPhone(i); |
| 10966 | if (phone != null) { |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 10967 | phone.setRadioPowerForReason(enable, TelephonyManager.RADIO_POWER_REASON_THERMAL); |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10968 | isPhoneAvailable = true; |
| 10969 | } |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10970 | } |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10971 | |
| 10972 | // return true if successfully informed the phone object about the thermal radio power |
| 10973 | // request. |
| 10974 | return isPhoneAvailable; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10975 | } |
| 10976 | |
| 10977 | private int handleDataThrottlingRequest(int subId, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 10978 | DataThrottlingRequest dataThrottlingRequest, String callingPackage) { |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10979 | boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported( |
| 10980 | TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING); |
| 10981 | if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction() |
| 10982 | != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) { |
| 10983 | throw new IllegalArgumentException("modem does not support data throttling"); |
| 10984 | } |
| 10985 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10986 | // Ensure that radio is on. If not able to power on due to phone being unavailable, return |
| 10987 | // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10988 | if (!setRadioPowerForThermal(true)) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10989 | return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 10990 | } |
| 10991 | |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 10992 | setDataEnabledForReason( |
| 10993 | subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true, callingPackage); |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10994 | |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10995 | if (isDataThrottlingSupported) { |
| 10996 | int thermalMitigationResult = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame^] | 10997 | (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId); |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10998 | if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) { |
| 10999 | throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS"); |
| 11000 | } else if (thermalMitigationResult |
| 11001 | == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) { |
Jack Nudelman | 760d096 | 2021-05-20 13:57:30 -0700 | [diff] [blame] | 11002 | log("Modem likely does not support data throttling on secondary carrier. Data " + |
| 11003 | "throttling action = " + dataThrottlingRequest.getDataThrottlingAction()); |
| 11004 | return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 11005 | } |
| 11006 | return thermalMitigationResult; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11007 | } |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 11008 | |
| 11009 | return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11010 | } |
| 11011 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 11012 | private static List<String> getThermalMitigationAllowlist(Context context) { |
| 11013 | if (sThermalMitigationAllowlistedPackages.isEmpty()) { |
| 11014 | for (String pckg : context.getResources() |
| 11015 | .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) { |
| 11016 | sThermalMitigationAllowlistedPackages.add(pckg); |
| 11017 | } |
| 11018 | } |
| 11019 | |
| 11020 | return sThermalMitigationAllowlistedPackages; |
| 11021 | } |
| 11022 | |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 11023 | private boolean isAnyPhoneInEmergencyState() { |
| 11024 | TelecomManager tm = mApp.getSystemService(TelecomManager.class); |
| 11025 | if (tm.isInEmergencyCall()) { |
| 11026 | Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call"); |
| 11027 | return true; |
| 11028 | } |
| 11029 | for (Phone phone : PhoneFactory.getPhones()) { |
| 11030 | if (phone.isInEmergencySmsMode() || phone.isInEcm()) { |
| 11031 | Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = " |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame^] | 11032 | + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = " |
| 11033 | + phone.isInEcm()); |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 11034 | return true; |
| 11035 | } |
| 11036 | } |
| 11037 | |
| 11038 | return false; |
| 11039 | } |
| 11040 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 11041 | /** |
| 11042 | * Used by shell commands to add an authorized package name for thermal mitigation. |
| 11043 | * @param packageName name of package to be allowlisted |
| 11044 | * @param context |
| 11045 | */ |
| 11046 | static void addPackageToThermalMitigationAllowlist(String packageName, Context context) { |
| 11047 | sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context); |
| 11048 | sThermalMitigationAllowlistedPackages.add(packageName); |
| 11049 | } |
| 11050 | |
| 11051 | /** |
| 11052 | * Used by shell commands to remove an authorized package name for thermal mitigation. |
| 11053 | * @param packageName name of package to remove from allowlist |
| 11054 | * @param context |
| 11055 | */ |
| 11056 | static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) { |
| 11057 | sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context); |
| 11058 | sThermalMitigationAllowlistedPackages.remove(packageName); |
| 11059 | } |
| 11060 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11061 | /** |
| 11062 | * Thermal mitigation request to control functionalities at modem. |
| 11063 | * |
| 11064 | * @param subId the id of the subscription. |
| 11065 | * @param thermalMitigationRequest holds all necessary information to be passed down to modem. |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 11066 | * @param callingPackage the package name of the calling package. |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11067 | * |
| 11068 | * @return thermalMitigationResult enum as defined in android.telephony.Annotation. |
| 11069 | */ |
| 11070 | @Override |
| 11071 | @ThermalMitigationResult |
| 11072 | public int sendThermalMitigationRequest( |
| 11073 | int subId, |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 11074 | ThermalMitigationRequest thermalMitigationRequest, |
| 11075 | String callingPackage) throws IllegalArgumentException { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11076 | enforceModifyPermission(); |
| 11077 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 11078 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 11079 | if (!getThermalMitigationAllowlist(getDefaultPhone().getContext()) |
| 11080 | .contains(callingPackage)) { |
| 11081 | throw new SecurityException("Calling package must be configured in the device config. " |
| 11082 | + "calling package: " + callingPackage); |
| 11083 | } |
| 11084 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11085 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 11086 | final long identity = Binder.clearCallingIdentity(); |
| 11087 | |
| 11088 | int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR; |
| 11089 | try { |
| 11090 | int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction(); |
| 11091 | switch (thermalMitigationAction) { |
| 11092 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING: |
| 11093 | thermalMitigationResult = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame^] | 11094 | handleDataThrottlingRequest(subId, |
| 11095 | thermalMitigationRequest.getDataThrottlingRequest(), |
| 11096 | callingPackage); |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11097 | break; |
| 11098 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY: |
| 11099 | if (thermalMitigationRequest.getDataThrottlingRequest() != null) { |
| 11100 | throw new IllegalArgumentException("dataThrottlingRequest must be null for " |
| 11101 | + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY"); |
| 11102 | } |
| 11103 | |
| 11104 | // Ensure that radio is on. If not able to power on due to phone being |
| 11105 | // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 11106 | if (!setRadioPowerForThermal(true)) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11107 | thermalMitigationResult = |
| 11108 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 11109 | break; |
| 11110 | } |
| 11111 | |
| 11112 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 11113 | false, callingPackage); |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11114 | thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 11115 | break; |
| 11116 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF: |
| 11117 | if (thermalMitigationRequest.getDataThrottlingRequest() != null) { |
| 11118 | throw new IllegalArgumentException("dataThrottlingRequest must be null for" |
| 11119 | + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF"); |
| 11120 | } |
| 11121 | |
| 11122 | TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null); |
| 11123 | if (registry != null) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11124 | Phone phone = getPhone(subId); |
| 11125 | if (phone == null) { |
| 11126 | thermalMitigationResult = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame^] | 11127 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11128 | break; |
| 11129 | } |
| 11130 | |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 11131 | TelephonyConnectionService service = |
| 11132 | registry.getTelephonyConnectionService(); |
Jack Nudelman | b30ac30 | 2021-06-17 15:39:58 -0700 | [diff] [blame] | 11133 | if (service != null && service.isEmergencyCallPending()) { |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 11134 | Log.e(LOG_TAG, "An emergency call is pending"); |
| 11135 | thermalMitigationResult = |
| 11136 | TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE; |
| 11137 | break; |
| 11138 | } else if (isAnyPhoneInEmergencyState()) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11139 | thermalMitigationResult = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame^] | 11140 | TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11141 | break; |
| 11142 | } |
| 11143 | } else { |
| 11144 | thermalMitigationResult = |
| 11145 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 11146 | break; |
| 11147 | } |
| 11148 | |
| 11149 | // Turn radio off. If not able to power off due to phone being unavailable, |
| 11150 | // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 11151 | if (!setRadioPowerForThermal(false)) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11152 | thermalMitigationResult = |
| 11153 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 11154 | break; |
| 11155 | } |
| 11156 | thermalMitigationResult = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame^] | 11157 | TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11158 | break; |
| 11159 | default: |
| 11160 | throw new IllegalArgumentException("the requested thermalMitigationAction does " |
| 11161 | + "not exist. Requested action: " + thermalMitigationAction); |
| 11162 | } |
| 11163 | } catch (IllegalArgumentException e) { |
| 11164 | throw e; |
| 11165 | } catch (Exception e) { |
| 11166 | Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e); |
| 11167 | thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 11168 | } finally { |
| 11169 | Binder.restoreCallingIdentity(identity); |
| 11170 | } |
| 11171 | |
| 11172 | if (DBG) { |
| 11173 | log("thermalMitigationRequest returning with thermalMitigationResult: " |
| 11174 | + thermalMitigationResult); |
| 11175 | } |
| 11176 | |
| 11177 | return thermalMitigationResult; |
| 11178 | } |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 11179 | |
| 11180 | /** |
| 11181 | * Set the GbaService Package Name that Telephony will bind to. |
| 11182 | * |
| 11183 | * @param subId The sim that the GbaService is associated with. |
| 11184 | * @param packageName The name of the package to be replaced with. |
| 11185 | * @return true if setting the GbaService to bind to succeeded, false if it did not. |
| 11186 | */ |
| 11187 | @Override |
| 11188 | public boolean setBoundGbaServiceOverride(int subId, String packageName) { |
| 11189 | enforceModifyPermission(); |
| 11190 | |
| 11191 | final long identity = Binder.clearCallingIdentity(); |
| 11192 | try { |
| 11193 | return getGbaManager(subId).overrideServicePackage(packageName); |
| 11194 | } finally { |
| 11195 | Binder.restoreCallingIdentity(identity); |
| 11196 | } |
| 11197 | } |
| 11198 | |
| 11199 | /** |
| 11200 | * Return the package name of the currently bound GbaService. |
| 11201 | * |
| 11202 | * @param subId The sim that the GbaService is associated with. |
| 11203 | * @return the package name of the GbaService configuration, null if GBA is not supported. |
| 11204 | */ |
| 11205 | @Override |
| 11206 | public String getBoundGbaService(int subId) { |
| 11207 | enforceReadPrivilegedPermission("getBoundGbaServicePackage"); |
| 11208 | |
| 11209 | final long identity = Binder.clearCallingIdentity(); |
| 11210 | try { |
| 11211 | return getGbaManager(subId).getServicePackage(); |
| 11212 | } finally { |
| 11213 | Binder.restoreCallingIdentity(identity); |
| 11214 | } |
| 11215 | } |
| 11216 | |
| 11217 | /** |
| 11218 | * Set the release time for telephony to unbind GbaService. |
| 11219 | * |
| 11220 | * @param subId The sim that the GbaService is associated with. |
| 11221 | * @param interval The release time to unbind GbaService by millisecond. |
| 11222 | * @return true if setting the GbaService to bind to succeeded, false if it did not. |
| 11223 | */ |
| 11224 | @Override |
| 11225 | public boolean setGbaReleaseTimeOverride(int subId, int interval) { |
| 11226 | enforceModifyPermission(); |
| 11227 | |
| 11228 | final long identity = Binder.clearCallingIdentity(); |
| 11229 | try { |
| 11230 | return getGbaManager(subId).overrideReleaseTime(interval); |
| 11231 | } finally { |
| 11232 | Binder.restoreCallingIdentity(identity); |
| 11233 | } |
| 11234 | } |
| 11235 | |
| 11236 | /** |
| 11237 | * Return the release time for telephony to unbind GbaService. |
| 11238 | * |
| 11239 | * @param subId The sim that the GbaService is associated with. |
| 11240 | * @return The release time to unbind GbaService by millisecond. |
| 11241 | */ |
| 11242 | @Override |
| 11243 | public int getGbaReleaseTime(int subId) { |
| 11244 | enforceReadPrivilegedPermission("getGbaReleaseTime"); |
| 11245 | |
| 11246 | final long identity = Binder.clearCallingIdentity(); |
| 11247 | try { |
| 11248 | return getGbaManager(subId).getReleaseTime(); |
| 11249 | } finally { |
| 11250 | Binder.restoreCallingIdentity(identity); |
| 11251 | } |
| 11252 | } |
| 11253 | |
| 11254 | private GbaManager getGbaManager(int subId) { |
| 11255 | GbaManager instance = GbaManager.getInstance(subId); |
| 11256 | if (instance == null) { |
| 11257 | String packageName = mApp.getResources().getString(R.string.config_gba_package); |
| 11258 | int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time); |
| 11259 | instance = GbaManager.make(mApp, subId, packageName, releaseTime); |
| 11260 | } |
| 11261 | return instance; |
| 11262 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11263 | |
| 11264 | /** |
| 11265 | * indicate whether the device and the carrier can support |
| 11266 | * RCS VoLTE single registration. |
| 11267 | */ |
| 11268 | @Override |
| 11269 | public boolean isRcsVolteSingleRegistrationCapable(int subId) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 11270 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 11271 | Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable", |
| 11272 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 11273 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11274 | |
| 11275 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 11276 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 11277 | } |
| 11278 | |
| 11279 | final long identity = Binder.clearCallingIdentity(); |
| 11280 | try { |
| 11281 | RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance(); |
| 11282 | if (rpm != null) { |
Hui Wang | 67af90e | 2021-06-04 16:57:15 -0700 | [diff] [blame] | 11283 | Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId); |
| 11284 | if (isCapable != null) { |
| 11285 | return isCapable; |
| 11286 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11287 | } |
Hui Wang | 67af90e | 2021-06-04 16:57:15 -0700 | [diff] [blame] | 11288 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE, |
| 11289 | "service is temporarily unavailable."); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11290 | } finally { |
| 11291 | Binder.restoreCallingIdentity(identity); |
| 11292 | } |
| 11293 | } |
| 11294 | |
| 11295 | /** |
| 11296 | * Register RCS provisioning callback. |
| 11297 | */ |
| 11298 | @Override |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 11299 | public void registerRcsProvisioningCallback(int subId, |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11300 | IRcsConfigCallback callback) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 11301 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 11302 | Binder.getCallingUid(), "registerRcsProvisioningCallback", |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 11303 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 11304 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11305 | |
| 11306 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 11307 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 11308 | } |
| 11309 | if (!isImsAvailableOnDevice()) { |
| 11310 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 11311 | "IMS not available on device."); |
| 11312 | } |
| 11313 | |
| 11314 | final long identity = Binder.clearCallingIdentity(); |
| 11315 | try { |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 11316 | if (!RcsProvisioningMonitor.getInstance() |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 11317 | .registerRcsProvisioningCallback(subId, callback)) { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 11318 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION, |
| 11319 | "Active subscription not found."); |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 11320 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11321 | } finally { |
| 11322 | Binder.restoreCallingIdentity(identity); |
| 11323 | } |
| 11324 | } |
| 11325 | |
| 11326 | /** |
| 11327 | * Unregister RCS provisioning callback. |
| 11328 | */ |
| 11329 | @Override |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 11330 | public void unregisterRcsProvisioningCallback(int subId, |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11331 | IRcsConfigCallback callback) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 11332 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 11333 | Binder.getCallingUid(), "unregisterRcsProvisioningCallback", |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 11334 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 11335 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11336 | |
| 11337 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 11338 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 11339 | } |
| 11340 | if (!isImsAvailableOnDevice()) { |
joonhunshin | 46b49a3 | 2022-12-21 05:33:23 +0000 | [diff] [blame] | 11341 | // operation failed silently |
| 11342 | Rlog.w(LOG_TAG, "IMS not available on device."); |
| 11343 | return; |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11344 | } |
| 11345 | |
| 11346 | final long identity = Binder.clearCallingIdentity(); |
| 11347 | try { |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 11348 | RcsProvisioningMonitor.getInstance() |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 11349 | .unregisterRcsProvisioningCallback(subId, callback); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11350 | } finally { |
| 11351 | Binder.restoreCallingIdentity(identity); |
| 11352 | } |
| 11353 | } |
| 11354 | |
| 11355 | /** |
| 11356 | * trigger RCS reconfiguration. |
| 11357 | */ |
| 11358 | public void triggerRcsReconfiguration(int subId) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 11359 | TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(), |
| 11360 | "triggerRcsReconfiguration", |
| 11361 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11362 | |
| 11363 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 11364 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 11365 | } |
| 11366 | if (!isImsAvailableOnDevice()) { |
joonhunshin | 46b49a3 | 2022-12-21 05:33:23 +0000 | [diff] [blame] | 11367 | // ProvisioningManager can not handle ServiceSpecificException. |
| 11368 | // Throw the IllegalStateException and annotate ProvisioningManager. |
| 11369 | throw new IllegalStateException("IMS not available on device."); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11370 | } |
| 11371 | |
| 11372 | final long identity = Binder.clearCallingIdentity(); |
| 11373 | try { |
| 11374 | RcsProvisioningMonitor.getInstance().requestReconfig(subId); |
| 11375 | } finally { |
| 11376 | Binder.restoreCallingIdentity(identity); |
| 11377 | } |
| 11378 | } |
| 11379 | |
| 11380 | /** |
| 11381 | * Provide the client configuration parameters of the RCS application. |
| 11382 | */ |
| 11383 | public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 11384 | TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(), |
| 11385 | "setRcsClientConfiguration", |
| 11386 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11387 | |
| 11388 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 11389 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 11390 | } |
| 11391 | if (!isImsAvailableOnDevice()) { |
| 11392 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 11393 | "IMS not available on device."); |
| 11394 | } |
| 11395 | |
| 11396 | final long identity = Binder.clearCallingIdentity(); |
| 11397 | |
| 11398 | try { |
| 11399 | IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS); |
| 11400 | if (configBinder == null) { |
| 11401 | Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration"); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 11402 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION, |
| 11403 | "could not find the requested subscription"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11404 | } else { |
| 11405 | configBinder.setRcsClientConfiguration(rcc); |
| 11406 | } |
joonhunshin | 3e15424 | 2021-09-17 06:33:39 +0000 | [diff] [blame] | 11407 | |
| 11408 | RcsStats.getInstance().onRcsClientProvisioningStats(subId, |
| 11409 | RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11410 | } catch (RemoteException e) { |
| 11411 | Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage()); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 11412 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE, |
| 11413 | "service is temporarily unavailable."); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11414 | } finally { |
| 11415 | Binder.restoreCallingIdentity(identity); |
| 11416 | } |
| 11417 | } |
| 11418 | |
| 11419 | /** |
Hui Wang | baaee6a | 2021-02-19 20:45:36 -0800 | [diff] [blame] | 11420 | * Enables or disables the test mode for RCS VoLTE single registration. |
| 11421 | */ |
| 11422 | @Override |
| 11423 | public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) { |
| 11424 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11425 | "setRcsSingleRegistrationTestModeEnabled"); |
| 11426 | |
| 11427 | RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled); |
| 11428 | } |
| 11429 | |
| 11430 | /** |
| 11431 | * Gets the test mode for RCS VoLTE single registration. |
| 11432 | */ |
| 11433 | @Override |
| 11434 | public boolean getRcsSingleRegistrationTestModeEnabled() { |
| 11435 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11436 | "getRcsSingleRegistrationTestModeEnabled"); |
| 11437 | |
| 11438 | return RcsProvisioningMonitor.getInstance().getTestModeEnabled(); |
| 11439 | } |
| 11440 | |
| 11441 | /** |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11442 | * Overrides the config of RCS VoLTE single registration enabled for the device. |
| 11443 | */ |
| 11444 | @Override |
| 11445 | public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) { |
| 11446 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11447 | "setDeviceSingleRegistrationEnabledOverride"); |
| 11448 | enforceModifyPermission(); |
| 11449 | |
| 11450 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 11451 | : Boolean.parseBoolean(enabledStr); |
| 11452 | RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled); |
Brad Ebinger | 49a72b4 | 2021-01-29 00:55:24 +0000 | [diff] [blame] | 11453 | mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11454 | } |
| 11455 | |
| 11456 | /** |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 11457 | * Sends a device to device communication message. Only usable via shell. |
| 11458 | * @param message message to send. |
| 11459 | * @param value message value. |
| 11460 | */ |
| 11461 | @Override |
| 11462 | public void sendDeviceToDeviceMessage(int message, int value) { |
| 11463 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
Tyler Gunn | babbda0 | 2021-02-10 11:05:02 -0800 | [diff] [blame] | 11464 | "sendDeviceToDeviceMessage"); |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 11465 | enforceModifyPermission(); |
| 11466 | |
| 11467 | final long identity = Binder.clearCallingIdentity(); |
| 11468 | try { |
| 11469 | TelephonyConnectionService service = |
| 11470 | TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService(); |
| 11471 | if (service == null) { |
| 11472 | Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call."); |
| 11473 | return; |
| 11474 | } |
| 11475 | service.sendTestDeviceToDeviceMessage(message, value); |
| 11476 | } finally { |
| 11477 | Binder.restoreCallingIdentity(identity); |
| 11478 | } |
| 11479 | } |
| 11480 | |
Tyler Gunn | babbda0 | 2021-02-10 11:05:02 -0800 | [diff] [blame] | 11481 | /** |
| 11482 | * Sets the specified device to device transport active. |
| 11483 | * @param transport The transport to set active. |
| 11484 | */ |
| 11485 | @Override |
| 11486 | public void setActiveDeviceToDeviceTransport(@NonNull String transport) { |
| 11487 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11488 | "setActiveDeviceToDeviceTransport"); |
| 11489 | enforceModifyPermission(); |
| 11490 | |
| 11491 | final long identity = Binder.clearCallingIdentity(); |
| 11492 | try { |
| 11493 | TelephonyConnectionService service = |
| 11494 | TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService(); |
| 11495 | if (service == null) { |
| 11496 | Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call."); |
| 11497 | return; |
| 11498 | } |
| 11499 | service.setActiveDeviceToDeviceTransport(transport); |
| 11500 | } finally { |
| 11501 | Binder.restoreCallingIdentity(identity); |
| 11502 | } |
| 11503 | } |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 11504 | |
Tyler Gunn | d433926 | 2021-05-03 14:46:49 -0700 | [diff] [blame] | 11505 | @Override |
| 11506 | public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) { |
| 11507 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11508 | "setDeviceToDeviceForceEnabled"); |
| 11509 | |
| 11510 | final long identity = Binder.clearCallingIdentity(); |
| 11511 | try { |
| 11512 | Arrays.stream(PhoneFactory.getPhones()).forEach( |
| 11513 | p -> { |
| 11514 | Phone thePhone = p.getImsPhone(); |
| 11515 | if (thePhone != null && thePhone instanceof ImsPhone) { |
| 11516 | ImsPhone imsPhone = (ImsPhone) thePhone; |
| 11517 | CallTracker tracker = imsPhone.getCallTracker(); |
| 11518 | if (tracker != null && tracker instanceof ImsPhoneCallTracker) { |
| 11519 | ImsPhoneCallTracker imsPhoneCallTracker = |
| 11520 | (ImsPhoneCallTracker) tracker; |
| 11521 | imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled); |
| 11522 | } |
| 11523 | } |
| 11524 | } |
| 11525 | ); |
| 11526 | } finally { |
| 11527 | Binder.restoreCallingIdentity(identity); |
| 11528 | } |
| 11529 | } |
| 11530 | |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 11531 | /** |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11532 | * Gets the config of RCS VoLTE single registration enabled for the device. |
| 11533 | */ |
| 11534 | @Override |
| 11535 | public boolean getDeviceSingleRegistrationEnabled() { |
| 11536 | enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled"); |
| 11537 | return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled(); |
| 11538 | } |
| 11539 | |
| 11540 | /** |
| 11541 | * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription. |
| 11542 | */ |
| 11543 | @Override |
| 11544 | public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) { |
| 11545 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11546 | "setCarrierSingleRegistrationEnabledOverride"); |
| 11547 | enforceModifyPermission(); |
| 11548 | |
| 11549 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 11550 | : Boolean.parseBoolean(enabledStr); |
| 11551 | return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled( |
| 11552 | subId, enabled); |
| 11553 | } |
| 11554 | |
| 11555 | /** |
| 11556 | * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription. |
| 11557 | */ |
| 11558 | @Override |
| 11559 | public boolean getCarrierSingleRegistrationEnabled(int subId) { |
| 11560 | enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled"); |
| 11561 | return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId); |
| 11562 | } |
Chiachang Wang | d6d3477 | 2020-12-22 11:38:27 +0800 | [diff] [blame] | 11563 | |
| 11564 | /** |
Hui Wang | b647abe | 2021-02-26 09:33:38 -0800 | [diff] [blame] | 11565 | * Overrides the ims feature validation result |
| 11566 | */ |
| 11567 | @Override |
| 11568 | public boolean setImsFeatureValidationOverride(int subId, String enabledStr) { |
| 11569 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11570 | "setImsFeatureValidationOverride"); |
| 11571 | |
| 11572 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 11573 | : Boolean.parseBoolean(enabledStr); |
| 11574 | return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation( |
| 11575 | subId, enabled); |
| 11576 | } |
| 11577 | |
| 11578 | /** |
| 11579 | * Gets the ims feature validation override value |
| 11580 | */ |
| 11581 | @Override |
| 11582 | public boolean getImsFeatureValidationOverride(int subId) { |
| 11583 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11584 | "getImsFeatureValidationOverride"); |
| 11585 | return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId); |
| 11586 | } |
| 11587 | |
| 11588 | /** |
Chiachang Wang | d6d3477 | 2020-12-22 11:38:27 +0800 | [diff] [blame] | 11589 | * Get the mobile provisioning url that is used to launch a browser to allow users to manage |
| 11590 | * their mobile plan. |
| 11591 | */ |
| 11592 | @Override |
| 11593 | public String getMobileProvisioningUrl() { |
| 11594 | enforceReadPrivilegedPermission("getMobileProvisioningUrl"); |
| 11595 | final long identity = Binder.clearCallingIdentity(); |
| 11596 | try { |
| 11597 | return getDefaultPhone().getMobileProvisioningUrl(); |
| 11598 | } finally { |
| 11599 | Binder.restoreCallingIdentity(identity); |
| 11600 | } |
| 11601 | } |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11602 | |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 11603 | /** |
calvinpan | e4a8a1d | 2021-01-25 13:51:18 +0800 | [diff] [blame] | 11604 | * Get the EAB contact from the EAB database. |
| 11605 | */ |
| 11606 | @Override |
| 11607 | public String getContactFromEab(String contact) { |
| 11608 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab"); |
| 11609 | enforceModifyPermission(); |
| 11610 | final long identity = Binder.clearCallingIdentity(); |
| 11611 | try { |
| 11612 | return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact); |
| 11613 | } finally { |
| 11614 | Binder.restoreCallingIdentity(identity); |
| 11615 | } |
| 11616 | } |
| 11617 | |
| 11618 | /** |
Calvin Pan | a143432 | 2021-07-01 19:27:01 +0800 | [diff] [blame] | 11619 | * Get the EAB capability from the EAB database. |
| 11620 | */ |
| 11621 | @Override |
| 11622 | public String getCapabilityFromEab(String contact) { |
| 11623 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab"); |
| 11624 | enforceModifyPermission(); |
| 11625 | final long identity = Binder.clearCallingIdentity(); |
| 11626 | try { |
| 11627 | return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact); |
| 11628 | } finally { |
| 11629 | Binder.restoreCallingIdentity(identity); |
| 11630 | } |
| 11631 | } |
| 11632 | |
| 11633 | /** |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 11634 | * Remove the EAB contacts from the EAB database. |
| 11635 | */ |
| 11636 | @Override |
| 11637 | public int removeContactFromEab(int subId, String contacts) { |
| 11638 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab"); |
| 11639 | enforceModifyPermission(); |
| 11640 | final long identity = Binder.clearCallingIdentity(); |
| 11641 | try { |
| 11642 | return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext()); |
| 11643 | } finally { |
| 11644 | Binder.restoreCallingIdentity(identity); |
| 11645 | } |
| 11646 | } |
| 11647 | |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11648 | @Override |
James.cf Lin | 4b784aa | 2021-01-31 03:25:15 +0800 | [diff] [blame] | 11649 | public boolean getDeviceUceEnabled() { |
| 11650 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled"); |
| 11651 | final long identity = Binder.clearCallingIdentity(); |
| 11652 | try { |
| 11653 | return mApp.getDeviceUceEnabled(); |
| 11654 | } finally { |
| 11655 | Binder.restoreCallingIdentity(identity); |
| 11656 | } |
| 11657 | } |
| 11658 | |
| 11659 | @Override |
| 11660 | public void setDeviceUceEnabled(boolean isEnabled) { |
| 11661 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled"); |
| 11662 | final long identity = Binder.clearCallingIdentity(); |
| 11663 | try { |
| 11664 | mApp.setDeviceUceEnabled(isEnabled); |
| 11665 | } finally { |
| 11666 | Binder.restoreCallingIdentity(identity); |
| 11667 | } |
| 11668 | } |
| 11669 | |
Brad Ebinger | 14d467f | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 11670 | /** |
| 11671 | * Add new feature tags to the Set used to calculate the capabilities in PUBLISH. |
| 11672 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 11673 | */ |
| 11674 | // Used for SHELL command only right now. |
| 11675 | @Override |
| 11676 | public RcsContactUceCapability addUceRegistrationOverrideShell(int subId, |
| 11677 | List<String> featureTags) { |
| 11678 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11679 | "addUceRegistrationOverrideShell"); |
| 11680 | final long identity = Binder.clearCallingIdentity(); |
| 11681 | try { |
| 11682 | return mApp.imsRcsController.addUceRegistrationOverrideShell(subId, |
| 11683 | new ArraySet<>(featureTags)); |
| 11684 | } catch (ImsException e) { |
| 11685 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 11686 | } finally { |
| 11687 | Binder.restoreCallingIdentity(identity); |
| 11688 | } |
| 11689 | } |
| 11690 | |
| 11691 | /** |
| 11692 | * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH. |
| 11693 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 11694 | */ |
| 11695 | // Used for SHELL command only right now. |
| 11696 | @Override |
| 11697 | public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId, |
| 11698 | List<String> featureTags) { |
| 11699 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11700 | "removeUceRegistrationOverrideShell"); |
| 11701 | final long identity = Binder.clearCallingIdentity(); |
| 11702 | try { |
| 11703 | return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId, |
| 11704 | new ArraySet<>(featureTags)); |
| 11705 | } catch (ImsException e) { |
| 11706 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 11707 | } finally { |
| 11708 | Binder.restoreCallingIdentity(identity); |
| 11709 | } |
| 11710 | } |
| 11711 | |
| 11712 | /** |
| 11713 | * Clear all overrides in the Set used to calculate the capabilities in PUBLISH. |
| 11714 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 11715 | */ |
| 11716 | // Used for SHELL command only right now. |
| 11717 | @Override |
| 11718 | public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) { |
| 11719 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11720 | "clearUceRegistrationOverrideShell"); |
| 11721 | final long identity = Binder.clearCallingIdentity(); |
| 11722 | try { |
| 11723 | return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId); |
| 11724 | } catch (ImsException e) { |
| 11725 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 11726 | } finally { |
| 11727 | Binder.restoreCallingIdentity(identity); |
| 11728 | } |
| 11729 | } |
| 11730 | |
| 11731 | /** |
| 11732 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 11733 | */ |
| 11734 | // Used for SHELL command only right now. |
| 11735 | @Override |
| 11736 | public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) { |
| 11737 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11738 | "getLatestRcsContactUceCapabilityShell"); |
| 11739 | final long identity = Binder.clearCallingIdentity(); |
| 11740 | try { |
| 11741 | return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId); |
| 11742 | } catch (ImsException e) { |
| 11743 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 11744 | } finally { |
| 11745 | Binder.restoreCallingIdentity(identity); |
| 11746 | } |
| 11747 | } |
| 11748 | |
| 11749 | /** |
| 11750 | * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the |
| 11751 | * device does not have an active PUBLISH. |
| 11752 | */ |
| 11753 | // Used for SHELL command only right now. |
| 11754 | @Override |
| 11755 | public String getLastUcePidfXmlShell(int subId) { |
| 11756 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml"); |
| 11757 | final long identity = Binder.clearCallingIdentity(); |
| 11758 | try { |
| 11759 | return mApp.imsRcsController.getLastUcePidfXmlShell(subId); |
| 11760 | } catch (ImsException e) { |
| 11761 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 11762 | } finally { |
| 11763 | Binder.restoreCallingIdentity(identity); |
| 11764 | } |
| 11765 | } |
| 11766 | |
James.cf Lin | e8713a4 | 2021-04-29 16:04:26 +0800 | [diff] [blame] | 11767 | /** |
| 11768 | * Remove UCE requests cannot be sent to the network status. |
| 11769 | */ |
| 11770 | // Used for SHELL command only right now. |
| 11771 | @Override |
| 11772 | public boolean removeUceRequestDisallowedStatus(int subId) { |
| 11773 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus"); |
| 11774 | final long identity = Binder.clearCallingIdentity(); |
| 11775 | try { |
| 11776 | return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId); |
| 11777 | } catch (ImsException e) { |
| 11778 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 11779 | } finally { |
| 11780 | Binder.restoreCallingIdentity(identity); |
| 11781 | } |
| 11782 | } |
| 11783 | |
James.cf Lin | 18bb900 | 2021-05-25 01:37:38 +0800 | [diff] [blame] | 11784 | /** |
| 11785 | * Remove UCE requests cannot be sent to the network status. |
| 11786 | */ |
| 11787 | // Used for SHELL command only. |
| 11788 | @Override |
| 11789 | public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) { |
| 11790 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout"); |
| 11791 | final long identity = Binder.clearCallingIdentity(); |
| 11792 | try { |
| 11793 | return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs); |
| 11794 | } catch (ImsException e) { |
| 11795 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 11796 | } finally { |
| 11797 | Binder.restoreCallingIdentity(identity); |
| 11798 | } |
| 11799 | } |
Brad Ebinger | 14d467f | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 11800 | |
James.cf Lin | 4b784aa | 2021-01-31 03:25:15 +0800 | [diff] [blame] | 11801 | @Override |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11802 | public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request, |
| 11803 | String callingPackage) { |
| 11804 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 11805 | mApp, subId, "setSignalStrengthUpdateRequest"); |
| 11806 | |
| 11807 | final int callingUid = Binder.getCallingUid(); |
| 11808 | // Verify that tha callingPackage belongs to the calling UID |
| 11809 | mApp.getSystemService(AppOpsManager.class) |
| 11810 | .checkPackage(callingUid, callingPackage); |
| 11811 | |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 11812 | validateSignalStrengthUpdateRequest(mApp, request, callingUid); |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11813 | |
| 11814 | final long identity = Binder.clearCallingIdentity(); |
| 11815 | try { |
| 11816 | Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST, |
| 11817 | new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId); |
| 11818 | |
| 11819 | if (result instanceof IllegalStateException) { |
| 11820 | throw (IllegalStateException) result; |
| 11821 | } |
| 11822 | } finally { |
| 11823 | Binder.restoreCallingIdentity(identity); |
| 11824 | } |
| 11825 | } |
| 11826 | |
| 11827 | @Override |
| 11828 | public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request, |
| 11829 | String callingPackage) { |
| 11830 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 11831 | mApp, subId, "clearSignalStrengthUpdateRequest"); |
| 11832 | |
| 11833 | final int callingUid = Binder.getCallingUid(); |
| 11834 | // Verify that tha callingPackage belongs to the calling UID |
| 11835 | mApp.getSystemService(AppOpsManager.class) |
| 11836 | .checkPackage(callingUid, callingPackage); |
| 11837 | |
| 11838 | final long identity = Binder.clearCallingIdentity(); |
| 11839 | try { |
| 11840 | Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST, |
| 11841 | new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId); |
| 11842 | |
| 11843 | if (result instanceof IllegalStateException) { |
| 11844 | throw (IllegalStateException) result; |
| 11845 | } |
| 11846 | } finally { |
| 11847 | Binder.restoreCallingIdentity(identity); |
| 11848 | } |
| 11849 | } |
| 11850 | |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 11851 | private static void validateSignalStrengthUpdateRequest(Context context, |
| 11852 | SignalStrengthUpdateRequest request, int callingUid) { |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11853 | if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) { |
| 11854 | // phone/system process do not have further restriction on request |
| 11855 | return; |
| 11856 | } |
| 11857 | |
| 11858 | // Applications has restrictions on how to use the request: |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 11859 | // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11860 | if (request.isSystemThresholdReportingRequestedWhileIdle()) { |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 11861 | context.enforceCallingOrSelfPermission( |
| 11862 | android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH, |
| 11863 | "validateSignalStrengthUpdateRequest"); |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11864 | } |
| 11865 | |
| 11866 | for (SignalThresholdInfo info : request.getSignalThresholdInfos()) { |
Nagendra Prasad Nagarle Basavaraju | fee544c | 2022-12-07 16:34:52 +0000 | [diff] [blame] | 11867 | // Only system caller can set mHysteresisMs/mIsEnabled. |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11868 | if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11869 | || info.isEnabled()) { |
| 11870 | throw new IllegalArgumentException( |
| 11871 | "Only system can set hide fields in SignalThresholdInfo"); |
| 11872 | } |
| 11873 | |
| 11874 | // Thresholds length for each RAN need in range. This has been validated in |
| 11875 | // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method |
| 11876 | // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds |
| 11877 | final int[] thresholds = info.getThresholds(); |
| 11878 | Objects.requireNonNull(thresholds); |
| 11879 | if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed() |
| 11880 | || thresholds.length |
| 11881 | > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) { |
| 11882 | throw new IllegalArgumentException( |
| 11883 | "thresholds length is out of range: " + thresholds.length); |
| 11884 | } |
| 11885 | } |
| 11886 | } |
SongFerngWang | 8236caa | 2021-01-17 21:51:44 +0800 | [diff] [blame] | 11887 | |
| 11888 | /** |
| 11889 | * Gets the current phone capability. |
| 11890 | * |
| 11891 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 11892 | * @return the PhoneCapability which describes the data connection capability of modem. |
| 11893 | * It's used to evaluate possible phone config change, for example from single |
| 11894 | * SIM device to multi-SIM device. |
| 11895 | */ |
| 11896 | @Override |
| 11897 | public PhoneCapability getPhoneCapability() { |
| 11898 | enforceReadPrivilegedPermission("getPhoneCapability"); |
| 11899 | final long identity = Binder.clearCallingIdentity(); |
| 11900 | try { |
| 11901 | return mPhoneConfigurationManager.getCurrentPhoneCapability(); |
| 11902 | } finally { |
| 11903 | Binder.restoreCallingIdentity(identity); |
| 11904 | } |
| 11905 | } |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 11906 | |
| 11907 | /** |
| 11908 | * Prepare TelephonyManager for an unattended reboot. The reboot is |
| 11909 | * required to be done shortly after the API is invoked. |
| 11910 | */ |
| 11911 | @Override |
| 11912 | @TelephonyManager.PrepareUnattendedRebootResult |
| 11913 | public int prepareForUnattendedReboot() { |
Rafael Higuera Silva | d963064 | 2021-09-20 15:32:01 +0000 | [diff] [blame] | 11914 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 11915 | enforceRebootPermission(); |
| 11916 | |
| 11917 | final long identity = Binder.clearCallingIdentity(); |
| 11918 | try { |
Rafael Higuera Silva | d963064 | 2021-09-20 15:32:01 +0000 | [diff] [blame] | 11919 | return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 11920 | } finally { |
| 11921 | Binder.restoreCallingIdentity(identity); |
| 11922 | } |
| 11923 | } |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 11924 | |
| 11925 | /** |
| 11926 | * Request to get the current slicing configuration including URSP rules and |
| 11927 | * NSSAIs (configured, allowed and rejected). |
| 11928 | * |
| 11929 | * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission. |
| 11930 | */ |
| 11931 | @Override |
| 11932 | public void getSlicingConfig(ResultReceiver callback) { |
Hongbo Zeng | 1b2063d | 2022-02-21 01:33:03 +0000 | [diff] [blame] | 11933 | TelephonyPermissions |
| 11934 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 11935 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, "getSlicingConfig"); |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 11936 | |
| 11937 | final long identity = Binder.clearCallingIdentity(); |
| 11938 | try { |
| 11939 | Phone phone = getDefaultPhone(); |
| 11940 | sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null); |
| 11941 | } finally { |
| 11942 | Binder.restoreCallingIdentity(identity); |
| 11943 | } |
| 11944 | } |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 11945 | |
| 11946 | /** |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 11947 | * Check whether the given premium capability is available for purchase from the carrier. |
| 11948 | * |
| 11949 | * @param capability The premium capability to check. |
| 11950 | * @param subId The subId to check the premium capability for. |
| 11951 | * |
| 11952 | * @return Whether the given premium capability is available to purchase. |
| 11953 | */ |
| 11954 | @Override |
| 11955 | public boolean isPremiumCapabilityAvailableForPurchase(int capability, int subId) { |
| 11956 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 11957 | mApp, "isPremiumCapabilityAvailableForPurchase")) { |
| 11958 | log("Premium capability " |
| 11959 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 11960 | + " is not available for purchase due to missing permissions."); |
| 11961 | throw new SecurityException("isPremiumCapabilityAvailableForPurchase requires " |
| 11962 | + "permission READ_BASIC_PHONE_STATE."); |
| 11963 | } |
| 11964 | |
| 11965 | Phone phone = getPhone(subId); |
Thomas Nguyen | 7216ed6 | 2022-11-29 16:45:31 -0800 | [diff] [blame] | 11966 | if (phone == null) { |
| 11967 | loge("isPremiumCapabilityAvailableForPurchase: phone is null, subId=" + subId); |
| 11968 | return false; |
| 11969 | } |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 11970 | final long identity = Binder.clearCallingIdentity(); |
| 11971 | try { |
Sarah Chin | 46355ba | 2022-11-01 23:51:16 -0700 | [diff] [blame] | 11972 | return SlicePurchaseController.getInstance(phone) |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 11973 | .isPremiumCapabilityAvailableForPurchase(capability); |
| 11974 | } finally { |
| 11975 | Binder.restoreCallingIdentity(identity); |
| 11976 | } |
| 11977 | } |
| 11978 | |
| 11979 | /** |
| 11980 | * Purchase the given premium capability from the carrier. |
| 11981 | * |
| 11982 | * @param capability The premium capability to purchase. |
| 11983 | * @param callback The result of the purchase request. |
| 11984 | * @param subId The subId to purchase the premium capability for. |
| 11985 | */ |
| 11986 | @Override |
| 11987 | public void purchasePremiumCapability(int capability, IIntegerConsumer callback, int subId) { |
| 11988 | log("purchasePremiumCapability: capability=" |
| 11989 | + TelephonyManager.convertPremiumCapabilityToString(capability) + ", caller=" |
| 11990 | + getCurrentPackageName()); |
| 11991 | |
| 11992 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 11993 | mApp, "purchasePremiumCapability")) { |
| 11994 | log("purchasePremiumCapability " |
| 11995 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 11996 | + " failed due to missing permissions."); |
| 11997 | throw new SecurityException("purchasePremiumCapability requires permission " |
| 11998 | + "READ_BASIC_PHONE_STATE."); |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 11999 | } else if (!TelephonyPermissions.checkInternetPermissionNoThrow( |
| 12000 | mApp, "purchasePremiumCapability")) { |
| 12001 | log("purchasePremiumCapability " |
| 12002 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 12003 | + " failed due to missing permissions."); |
| 12004 | throw new SecurityException("purchasePremiumCapability requires permission INTERNET."); |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 12005 | } |
| 12006 | |
| 12007 | Phone phone = getPhone(subId); |
Sarah Chin | 1969411 | 2022-12-06 15:41:37 -0800 | [diff] [blame] | 12008 | if (phone == null) { |
| 12009 | try { |
| 12010 | int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_REQUEST_FAILED; |
| 12011 | callback.accept(result); |
| 12012 | loge("purchasePremiumCapability: phone is null, subId=" + subId); |
| 12013 | } catch (RemoteException e) { |
| 12014 | String logStr = "Purchase premium capability " |
| 12015 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 12016 | + " failed due to RemoteException handling null phone: " + e; |
| 12017 | if (DBG) log(logStr); |
| 12018 | AnomalyReporter.reportAnomaly( |
| 12019 | UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr); |
| 12020 | } |
| 12021 | return; |
| 12022 | } |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 12023 | |
| 12024 | String callingProcess; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 12025 | try { |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 12026 | callingProcess = mApp.getPackageManager().getApplicationInfo( |
| 12027 | getCurrentPackageName(), 0).processName; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 12028 | } catch (PackageManager.NameNotFoundException e) { |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 12029 | callingProcess = getCurrentPackageName(); |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 12030 | } |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 12031 | |
| 12032 | boolean isVisible = false; |
| 12033 | ActivityManager am = mApp.getSystemService(ActivityManager.class); |
| 12034 | if (am != null) { |
| 12035 | List<ActivityManager.RunningAppProcessInfo> processes = am.getRunningAppProcesses(); |
| 12036 | if (processes != null) { |
| 12037 | for (ActivityManager.RunningAppProcessInfo process : processes) { |
| 12038 | log("purchasePremiumCapability: process " + process.processName |
| 12039 | + "has importance " + process.importance); |
| 12040 | if (process.processName.equals(callingProcess) && process.importance |
| 12041 | <= ActivityManager.RunningAppProcessInfo.IMPORTANCE_VISIBLE) { |
| 12042 | isVisible = true; |
| 12043 | break; |
| 12044 | } |
| 12045 | } |
| 12046 | } |
| 12047 | } |
| 12048 | |
| 12049 | if (!isVisible) { |
| 12050 | try { |
| 12051 | int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_NOT_FOREGROUND; |
| 12052 | callback.accept(result); |
| 12053 | loge("purchasePremiumCapability: " + callingProcess + " is not in the foreground."); |
| 12054 | } catch (RemoteException e) { |
| 12055 | String logStr = "Purchase premium capability " |
| 12056 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 12057 | + " failed due to RemoteException handling background application: " + e; |
| 12058 | if (DBG) log(logStr); |
| 12059 | AnomalyReporter.reportAnomaly( |
| 12060 | UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr); |
| 12061 | } |
| 12062 | return; |
| 12063 | } |
| 12064 | |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 12065 | sendRequestAsync(CMD_PURCHASE_PREMIUM_CAPABILITY, |
Sarah Chin | b8218c2 | 2023-01-04 13:35:29 -0800 | [diff] [blame] | 12066 | new PurchasePremiumCapabilityArgument(capability, callback), phone, null); |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 12067 | } |
| 12068 | |
| 12069 | /** |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 12070 | * Register an IMS connection state callback |
| 12071 | */ |
| 12072 | @Override |
Hunsuk Choi | 89bd22c | 2021-11-01 13:04:54 +0000 | [diff] [blame] | 12073 | public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb, |
| 12074 | String callingPackage) { |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 12075 | if (feature == ImsFeature.FEATURE_MMTEL) { |
| 12076 | // ImsMmTelManager |
| 12077 | // The following also checks READ_PRIVILEGED_PHONE_STATE. |
| 12078 | TelephonyPermissions |
| 12079 | .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 12080 | mApp, subId, "registerImsStateCallback"); |
| 12081 | } else if (feature == ImsFeature.FEATURE_RCS) { |
| 12082 | // ImsRcsManager or SipDelegateManager |
| 12083 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 12084 | Binder.getCallingUid(), "registerImsStateCallback", |
| 12085 | Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
| 12086 | Manifest.permission.READ_PRECISE_PHONE_STATE, |
| 12087 | Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE, |
| 12088 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
| 12089 | } |
| 12090 | |
| 12091 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 12092 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 12093 | "IMS not available on device."); |
| 12094 | } |
| 12095 | |
| 12096 | if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) { |
| 12097 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 12098 | } |
| 12099 | |
| 12100 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 12101 | if (controller == null) { |
| 12102 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 12103 | "IMS not available on device."); |
| 12104 | } |
| 12105 | |
Hunsuk Choi | 89bd22c | 2021-11-01 13:04:54 +0000 | [diff] [blame] | 12106 | if (callingPackage == null) { |
| 12107 | callingPackage = getCurrentPackageName(); |
| 12108 | } |
| 12109 | |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 12110 | final long token = Binder.clearCallingIdentity(); |
| 12111 | try { |
| 12112 | int slotId = getSlotIndexOrException(subId); |
Hunsuk Choi | 89bd22c | 2021-11-01 13:04:54 +0000 | [diff] [blame] | 12113 | controller.registerImsStateCallback(subId, feature, cb, callingPackage); |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 12114 | } catch (ImsException e) { |
| 12115 | throw new ServiceSpecificException(e.getCode()); |
| 12116 | } finally { |
| 12117 | Binder.restoreCallingIdentity(token); |
| 12118 | } |
| 12119 | } |
| 12120 | |
| 12121 | /** |
| 12122 | * Unregister an IMS connection state callback |
| 12123 | */ |
| 12124 | @Override |
| 12125 | public void unregisterImsStateCallback(IImsStateCallback cb) { |
| 12126 | final long token = Binder.clearCallingIdentity(); |
| 12127 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 12128 | if (controller == null) { |
| 12129 | return; |
| 12130 | } |
| 12131 | try { |
| 12132 | controller.unregisterImsStateCallback(cb); |
| 12133 | } finally { |
| 12134 | Binder.restoreCallingIdentity(token); |
| 12135 | } |
| 12136 | } |
Sooraj Sasindran | fae41b3 | 2021-10-26 02:10:05 -0700 | [diff] [blame] | 12137 | |
| 12138 | /** |
| 12139 | * @return {@CellIdentity} last known cell identity {@CellIdentity}. |
| 12140 | * |
| 12141 | * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and |
| 12142 | * com.android.phone.permission.ACCESS_LAST_KNOWN_CELL_ID, otherwise throws |
| 12143 | * SecurityException. |
| 12144 | * If there is current registered network this value will be same as the registered cell |
| 12145 | * identity. If the device goes out of service the previous cell identity is cached and |
| 12146 | * will be returned. If the cache age of the Cell identity is more than 24 hours |
| 12147 | * it will be cleared and null will be returned. |
| 12148 | * |
| 12149 | */ |
| 12150 | @Override |
| 12151 | public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage, |
| 12152 | String callingFeatureId) { |
| 12153 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 12154 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 12155 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 12156 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 12157 | .setCallingPackage(callingPackage) |
| 12158 | .setCallingFeatureId(callingFeatureId) |
| 12159 | .setCallingPid(Binder.getCallingPid()) |
| 12160 | .setCallingUid(Binder.getCallingUid()) |
| 12161 | .setMethod("getLastKnownCellIdentity") |
| 12162 | .setLogAsInfo(true) |
| 12163 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 12164 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 12165 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 12166 | .build()); |
| 12167 | |
| 12168 | boolean hasFinePermission = |
| 12169 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 12170 | if (!hasFinePermission |
| 12171 | || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) { |
| 12172 | throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION " |
Rambo Wang | 918993a | 2022-04-27 09:08:36 -0700 | [diff] [blame] | 12173 | + "and ACCESS_LAST_KNOWN_CELL_ID permission."); |
Sooraj Sasindran | fae41b3 | 2021-10-26 02:10:05 -0700 | [diff] [blame] | 12174 | } |
| 12175 | |
| 12176 | final long identity = Binder.clearCallingIdentity(); |
| 12177 | try { |
| 12178 | Phone phone = getPhone(subId); |
| 12179 | if (phone == null) return null; |
| 12180 | ServiceStateTracker sst = phone.getServiceStateTracker(); |
| 12181 | if (sst == null) return null; |
| 12182 | return sst.getLastKnownCellIdentity(); |
| 12183 | } finally { |
| 12184 | Binder.restoreCallingIdentity(identity); |
| 12185 | } |
| 12186 | } |
Jack Yu | 4c0a550 | 2021-12-03 23:58:26 -0800 | [diff] [blame] | 12187 | |
jimsun | 3b9ccac | 2021-10-26 15:01:23 +0800 | [diff] [blame] | 12188 | /** |
| 12189 | * Sets the modem service class Name that Telephony will bind to. |
| 12190 | * |
| 12191 | * @param serviceName The class name of the modem service. |
| 12192 | * @return true if the operation is succeed, otherwise false. |
| 12193 | */ |
| 12194 | public boolean setModemService(String serviceName) { |
| 12195 | Log.d(LOG_TAG, "setModemService - " + serviceName); |
| 12196 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService"); |
| 12197 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame^] | 12198 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 12199 | "setModemService"); |
jimsun | 3b9ccac | 2021-10-26 15:01:23 +0800 | [diff] [blame] | 12200 | return mPhoneConfigurationManager.setModemService(serviceName); |
| 12201 | } |
| 12202 | |
| 12203 | /** |
| 12204 | * Return the class name of the currently bounded modem service. |
| 12205 | * |
| 12206 | * @return the class name of the modem service. |
| 12207 | */ |
| 12208 | public String getModemService() { |
| 12209 | String result; |
| 12210 | Log.d(LOG_TAG, "getModemService"); |
| 12211 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService"); |
| 12212 | TelephonyPermissions |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame^] | 12213 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
jimsun | 3b9ccac | 2021-10-26 15:01:23 +0800 | [diff] [blame] | 12214 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 12215 | "getModemService"); |
| 12216 | result = mPhoneConfigurationManager.getModemService(); |
| 12217 | Log.d(LOG_TAG, "result = " + result); |
| 12218 | return result; |
| 12219 | } |
Hunter Knepshield | 2b076fa | 2022-01-19 02:26:22 -0800 | [diff] [blame] | 12220 | |
| 12221 | @Override |
| 12222 | public void setVoiceServiceStateOverride(int subId, boolean hasService, String callingPackage) { |
| 12223 | // Only telecom (and shell, for CTS purposes) is allowed to call this method. |
| 12224 | mApp.enforceCallingOrSelfPermission( |
| 12225 | permission.BIND_TELECOM_CONNECTION_SERVICE, "setVoiceServiceStateOverride"); |
| 12226 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 12227 | |
| 12228 | final long identity = Binder.clearCallingIdentity(); |
| 12229 | try { |
| 12230 | Phone phone = getPhone(subId); |
| 12231 | if (phone == null) return; |
Grant Menke | 63ade12 | 2023-01-20 14:31:54 -0800 | [diff] [blame] | 12232 | Log.i(LOG_TAG, "setVoiceServiceStateOverride: subId=" + subId + ", phone=" + phone |
| 12233 | + ", hasService=" + hasService + ", callingPackage=" + callingPackage); |
Hunter Knepshield | 2b076fa | 2022-01-19 02:26:22 -0800 | [diff] [blame] | 12234 | phone.setVoiceServiceStateOverride(hasService); |
| 12235 | } finally { |
| 12236 | Binder.restoreCallingIdentity(identity); |
| 12237 | } |
| 12238 | } |
Muralidhar Reddy | 4e5a801 | 2022-05-11 14:49:00 +0000 | [diff] [blame] | 12239 | |
| 12240 | /** |
| 12241 | * set removable eSIM as default eUICC. |
| 12242 | * |
| 12243 | * @hide |
| 12244 | */ |
| 12245 | @Override |
| 12246 | public void setRemovableEsimAsDefaultEuicc(boolean isDefault, String callingPackage) { |
| 12247 | enforceModifyPermission(); |
| 12248 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 12249 | |
| 12250 | final long identity = Binder.clearCallingIdentity(); |
| 12251 | try { |
| 12252 | UiccController.getInstance().setRemovableEsimAsDefaultEuicc(isDefault); |
| 12253 | } finally { |
| 12254 | Binder.restoreCallingIdentity(identity); |
| 12255 | } |
| 12256 | } |
| 12257 | |
| 12258 | /** |
| 12259 | * Returns whether the removable eSIM is default eUICC or not. |
| 12260 | * |
| 12261 | * @hide |
| 12262 | */ |
| 12263 | @Override |
| 12264 | public boolean isRemovableEsimDefaultEuicc(String callingPackage) { |
| 12265 | enforceReadPrivilegedPermission("isRemovableEsimDefaultEuicc"); |
| 12266 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 12267 | |
| 12268 | final long identity = Binder.clearCallingIdentity(); |
| 12269 | try { |
| 12270 | return UiccController.getInstance().isRemovableEsimDefaultEuicc(); |
| 12271 | } finally { |
| 12272 | Binder.restoreCallingIdentity(identity); |
| 12273 | } |
| 12274 | } |
| 12275 | |
Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame] | 12276 | /** |
| 12277 | * Get the component name of the default app to direct respond-via-message intent for the |
| 12278 | * user associated with this subscription, update the cache if there is no respond-via-message |
| 12279 | * application currently configured for this user. |
| 12280 | * @return component name of the app and class to direct Respond Via Message intent to, or |
| 12281 | * {@code null} if the functionality is not supported. |
| 12282 | * @hide |
| 12283 | */ |
| 12284 | @Override |
| 12285 | public @Nullable ComponentName getDefaultRespondViaMessageApplication(int subId, |
| 12286 | boolean updateIfNeeded) { |
| 12287 | enforceInteractAcrossUsersPermission("getDefaultRespondViaMessageApplication"); |
Muralidhar Reddy | 4e5a801 | 2022-05-11 14:49:00 +0000 | [diff] [blame] | 12288 | |
Aishwarya Mallampati | 5e581e1 | 2023-01-17 21:57:06 +0000 | [diff] [blame] | 12289 | Context context = getPhoneFromSubIdOrDefault(subId).getContext(); |
| 12290 | |
Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame] | 12291 | UserHandle userHandle = null; |
| 12292 | final long identity = Binder.clearCallingIdentity(); |
| 12293 | try { |
| 12294 | userHandle = TelephonyUtils.getSubscriptionUserHandle(context, subId); |
| 12295 | } finally { |
| 12296 | Binder.restoreCallingIdentity(identity); |
| 12297 | } |
| 12298 | return SmsApplication.getDefaultRespondViaMessageApplicationAsUser(context, |
| 12299 | updateIfNeeded, userHandle); |
| 12300 | } |
Jack Yu | f5badd9 | 2022-12-08 00:50:53 -0800 | [diff] [blame] | 12301 | |
| 12302 | /** |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 12303 | * Set whether the device is able to connect with null ciphering or integrity |
| 12304 | * algorithms. This is a global setting and will apply to all active subscriptions |
| 12305 | * and all new subscriptions after this. |
| 12306 | * |
| 12307 | * @param enabled when true, null cipher and integrity algorithms are allowed. |
| 12308 | * @hide |
| 12309 | */ |
| 12310 | @Override |
| 12311 | @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 12312 | public void setNullCipherAndIntegrityEnabled(boolean enabled) { |
| 12313 | enforceModifyPermission(); |
| 12314 | checkForNullCipherAndIntegritySupport(); |
| 12315 | |
| 12316 | // Persist the state of our preference. Each GsmCdmaPhone instance is responsible |
| 12317 | // for listening to these preference changes and applying them immediately. |
| 12318 | SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 12319 | editor.putBoolean(Phone.PREF_NULL_CIPHER_AND_INTEGRITY_ENABLED, enabled); |
| 12320 | editor.apply(); |
| 12321 | |
| 12322 | for (Phone phone: PhoneFactory.getPhones()) { |
| 12323 | phone.handleNullCipherEnabledChange(); |
| 12324 | } |
| 12325 | } |
| 12326 | |
| 12327 | |
| 12328 | /** |
| 12329 | * Get whether the device is able to connect with null ciphering or integrity |
| 12330 | * algorithms. Note that this retrieves the phone-global preference and not |
| 12331 | * the state of the radio. |
| 12332 | * |
| 12333 | * @throws SecurityException if {@link permission#MODIFY_PHONE_STATE} is not satisfied |
| 12334 | * @throws UnsupportedOperationException if the device does not support the minimum HAL |
| 12335 | * version for this feature. |
| 12336 | * @hide |
| 12337 | */ |
| 12338 | @Override |
| 12339 | @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) |
| 12340 | public boolean isNullCipherAndIntegrityPreferenceEnabled() { |
| 12341 | enforceReadPermission(); |
| 12342 | checkForNullCipherAndIntegritySupport(); |
| 12343 | return getDefaultPhone().getNullCipherAndIntegrityEnabledPreference(); |
| 12344 | } |
| 12345 | |
| 12346 | private void checkForNullCipherAndIntegritySupport() { |
| 12347 | if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_NULL_CIPHER_AND_INTEGRITY_VERSION) { |
| 12348 | throw new UnsupportedOperationException( |
| 12349 | "Null cipher and integrity operations require HAL 2.1 or above"); |
| 12350 | } |
Gil Cukierman | 92cc7db | 2023-01-06 19:25:53 +0000 | [diff] [blame] | 12351 | if (!getDefaultPhone().isNullCipherAndIntegritySupported()) { |
| 12352 | throw new UnsupportedOperationException( |
| 12353 | "Null cipher and integrity operations unsupported by modem"); |
| 12354 | } |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 12355 | } |
| 12356 | |
| 12357 | /** |
Jack Yu | f5badd9 | 2022-12-08 00:50:53 -0800 | [diff] [blame] | 12358 | * Get the SIM state for the slot index. |
| 12359 | * For Remote-SIMs, this method returns {@link IccCardConstants.State#UNKNOWN} |
| 12360 | * |
| 12361 | * @return SIM state as the ordinal of {@link IccCardConstants.State} |
| 12362 | */ |
| 12363 | @Override |
| 12364 | @SimState |
| 12365 | public int getSimStateForSlotIndex(int slotIndex) { |
| 12366 | IccCardConstants.State simState; |
| 12367 | if (slotIndex < 0) { |
| 12368 | simState = IccCardConstants.State.UNKNOWN; |
| 12369 | } else { |
| 12370 | Phone phone = null; |
| 12371 | try { |
| 12372 | phone = PhoneFactory.getPhone(slotIndex); |
| 12373 | } catch (IllegalStateException e) { |
| 12374 | // ignore |
| 12375 | } |
| 12376 | if (phone == null) { |
| 12377 | simState = IccCardConstants.State.UNKNOWN; |
| 12378 | } else { |
| 12379 | IccCard icc = phone.getIccCard(); |
| 12380 | if (icc == null) { |
| 12381 | simState = IccCardConstants.State.UNKNOWN; |
| 12382 | } else { |
| 12383 | simState = icc.getState(); |
| 12384 | } |
| 12385 | } |
| 12386 | } |
| 12387 | return simState.ordinal(); |
| 12388 | } |
Hui Wang | 9b5793a | 2022-12-05 14:38:06 -0600 | [diff] [blame] | 12389 | |
| 12390 | /** |
| 12391 | * Get current cell broadcast ranges. |
| 12392 | */ |
| 12393 | @Override |
| 12394 | @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS) |
| 12395 | public List<CellBroadcastIdRange> getCellBroadcastIdRanges(int subId) { |
| 12396 | mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS, |
| 12397 | "getCellBroadcastIdRanges"); |
| 12398 | final long identity = Binder.clearCallingIdentity(); |
| 12399 | try { |
| 12400 | return getPhone(subId).getCellBroadcastIdRanges(); |
| 12401 | } finally { |
| 12402 | Binder.restoreCallingIdentity(identity); |
| 12403 | } |
| 12404 | } |
| 12405 | |
| 12406 | /** |
| 12407 | * Set reception of cell broadcast messages with the list of the given ranges |
| 12408 | * |
| 12409 | * @param ranges the list of {@link CellBroadcastIdRange} to be enabled |
| 12410 | */ |
| 12411 | @Override |
| 12412 | @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS) |
| 12413 | public void setCellBroadcastIdRanges(int subId, @NonNull List<CellBroadcastIdRange> ranges, |
| 12414 | @Nullable IIntegerConsumer callback) { |
| 12415 | mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS, |
| 12416 | "setCellBroadcastIdRanges"); |
| 12417 | final long identity = Binder.clearCallingIdentity(); |
| 12418 | try { |
| 12419 | Phone phone = getPhoneFromSubId(subId); |
| 12420 | if (DBG) { |
| 12421 | log("setCellBroadcastIdRanges for subId :" + subId + ", phone:" + phone); |
| 12422 | } |
| 12423 | phone.setCellBroadcastIdRanges(ranges, result -> { |
| 12424 | if (callback != null) { |
| 12425 | try { |
| 12426 | callback.accept(result); |
| 12427 | } catch (RemoteException e) { |
| 12428 | Log.w(LOG_TAG, "setCellBroadcastIdRanges: callback not available."); |
| 12429 | } |
| 12430 | } |
| 12431 | }); |
| 12432 | } finally { |
| 12433 | Binder.restoreCallingIdentity(identity); |
| 12434 | } |
| 12435 | } |
Hunsuk Choi | 42cc62a | 2022-10-16 06:03:40 +0000 | [diff] [blame] | 12436 | |
| 12437 | /** |
| 12438 | * Returns whether the device supports the domain selection service. |
| 12439 | * |
| 12440 | * @return {@code true} if the device supports the domain selection service. |
| 12441 | */ |
| 12442 | @Override |
| 12443 | public boolean isDomainSelectionSupported() { |
| 12444 | mApp.enforceCallingOrSelfPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
| 12445 | "isDomainSelectionSupported"); |
| 12446 | |
| 12447 | final long identity = Binder.clearCallingIdentity(); |
| 12448 | try { |
| 12449 | return DomainSelectionResolver.getInstance().isDomainSelectionSupported(); |
| 12450 | } finally { |
| 12451 | Binder.restoreCallingIdentity(identity); |
| 12452 | } |
| 12453 | } |
arunvoddu | d5c6ce0 | 2022-12-11 06:03:12 +0000 | [diff] [blame] | 12454 | |
| 12455 | /** |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 12456 | * Start receiving satellite position updates. |
| 12457 | * This can be called by the pointing UI when the user starts pointing to the satellite. |
| 12458 | * Modem should continue to report the pointing input as the device or satellite moves. |
| 12459 | * |
| 12460 | * @param subId The subId to start satellite position updates for. |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 12461 | * @param callback The callback to notify of changes in satellite position. |
| 12462 | * @return The result of the operation. |
| 12463 | */ |
| 12464 | @Override |
| 12465 | @SatelliteManager.SatelliteServiceResult public int startSatellitePositionUpdates(int subId, |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame^] | 12466 | @NonNull ISatelliteStateListener callback) { |
Sarah Chin | f75afa7 | 2023-02-01 01:32:19 -0800 | [diff] [blame] | 12467 | enforceSatelliteCommunicationPermission("startSatellitePositionUpdates"); |
| 12468 | |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame^] | 12469 | final int validSubId = getValidSatelliteSubId(subId); |
| 12470 | if (!isSatelliteEnabled(validSubId)) { |
Sarah Chin | f75afa7 | 2023-02-01 01:32:19 -0800 | [diff] [blame] | 12471 | return SatelliteManager.SATELLITE_SERVICE_DISABLED; |
| 12472 | } |
| 12473 | |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame^] | 12474 | Phone phone = getPhoneOrDefault(validSubId, "startSatellitePositionUpdates"); |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 12475 | if (phone == null) { |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame^] | 12476 | return SatelliteManager.SATELLITE_SERVICE_INVALID_TELEPHONY_STATE; |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 12477 | } |
| 12478 | |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame^] | 12479 | if (mSatellitePositionUpdateHandlers.containsKey(callback.asBinder())) { |
| 12480 | log("startSatellitePositionUpdates: callback already registered: " |
| 12481 | + callback.asBinder()); |
| 12482 | return SatelliteManager.SATELLITE_SERVICE_CALLBACK_ALREADY_REGISTERED; |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 12483 | } |
| 12484 | |
| 12485 | SatellitePositionUpdateHandler handler = |
| 12486 | new SatellitePositionUpdateHandler(callback, Looper.getMainLooper()); |
| 12487 | phone.registerForSatellitePointingInfoChanged(handler, |
| 12488 | SatellitePositionUpdateHandler.EVENT_POSITION_UPDATE, null); |
| 12489 | phone.registerForSatelliteMessagesTransferComplete(handler, |
| 12490 | SatellitePositionUpdateHandler.EVENT_MESSAGE_TRANSFER_STATE_UPDATE, null); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame^] | 12491 | mSatellitePositionUpdateHandlers.put(callback.asBinder(), handler); |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 12492 | |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame^] | 12493 | int result = (int) sendRequest(CMD_START_SATELLITE_POSITION_UPDATES, null, validSubId); |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 12494 | if (DBG) log("startSatellitePositionUpdates result: " + result); |
| 12495 | return result; |
| 12496 | } |
| 12497 | |
| 12498 | /** |
| 12499 | * Stop receiving satellite position updates. |
| 12500 | * This can be called by the pointing UI when the user stops pointing to the satellite. |
| 12501 | * |
| 12502 | * @param subId The subId to stop satellite position updates for. |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame^] | 12503 | * @param callback The callback that was passed in {@link |
| 12504 | * #startSatellitePositionUpdates(int, ISatelliteStateListener)} |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 12505 | * @return The result of the operation. |
| 12506 | */ |
| 12507 | @Override |
| 12508 | @SatelliteManager.SatelliteServiceResult public int stopSatellitePositionUpdates(int subId, |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame^] | 12509 | @NonNull ISatelliteStateListener callback) { |
Sarah Chin | f75afa7 | 2023-02-01 01:32:19 -0800 | [diff] [blame] | 12510 | enforceSatelliteCommunicationPermission("stopSatellitePositionUpdates"); |
| 12511 | |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame^] | 12512 | final int validSubId = getValidSatelliteSubId(subId); |
| 12513 | if (!isSatelliteEnabled(validSubId)) { |
Sarah Chin | f75afa7 | 2023-02-01 01:32:19 -0800 | [diff] [blame] | 12514 | return SatelliteManager.SATELLITE_SERVICE_DISABLED; |
| 12515 | } |
| 12516 | |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame^] | 12517 | Phone phone = getPhoneOrDefault(validSubId, "stopSatellitePositionUpdates"); |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 12518 | if (phone == null) { |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame^] | 12519 | return SatelliteManager.SATELLITE_SERVICE_INVALID_TELEPHONY_STATE; |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 12520 | } |
| 12521 | |
| 12522 | SatellitePositionUpdateHandler handler = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame^] | 12523 | mSatellitePositionUpdateHandlers.remove(callback.asBinder()); |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 12524 | if (handler == null) { |
| 12525 | loge("stopSatellitePositionUpdates: No SatellitePositionArgument"); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame^] | 12526 | return SatelliteManager.SATELLITE_SERVICE_CALLBACK_NOT_REGISTERED; |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 12527 | } else { |
| 12528 | phone.unregisterForSatellitePointingInfoChanged(handler); |
| 12529 | phone.unregisterForSatelliteMessagesTransferComplete(handler); |
| 12530 | } |
| 12531 | |
| 12532 | if (!mSatellitePositionUpdateHandlers.isEmpty()) { |
| 12533 | log("stopSatellitePositionUpdates: other listeners still exist."); |
| 12534 | return SatelliteManager.SATELLITE_SERVICE_SUCCESS; |
| 12535 | } |
| 12536 | |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame^] | 12537 | int result = (int) sendRequest(CMD_STOP_SATELLITE_POSITION_UPDATES, null, validSubId); |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 12538 | if (DBG) log("stopSatellitePositionUpdates result: " + result); |
| 12539 | return result; |
| 12540 | } |
| 12541 | |
| 12542 | /** |
Aishwarya Mallampati | 60fe113 | 2023-01-24 19:07:21 +0000 | [diff] [blame] | 12543 | * Get maximum number of characters per text message on satellite. |
| 12544 | * @param subId - The subId of the subscription. |
| 12545 | * @param callback - The callback that will be used to send maximum characters limit |
| 12546 | * if operation is successful. |
| 12547 | * @return The result of the operation. |
| 12548 | * |
| 12549 | * @throws SecurityException if the caller doesn't have the required permission. |
| 12550 | */ |
| 12551 | @Override |
| 12552 | public int getMaxCharactersPerSatelliteTextMessage(int subId, IIntegerConsumer callback) { |
| 12553 | enforceSatelliteCommunicationPermission("getMaxCharactersPerSatelliteTextMessage"); |
| 12554 | |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame^] | 12555 | final int validSubId = getValidSatelliteSubId(subId); |
| 12556 | if (!isSatelliteEnabled(validSubId)) { |
Aishwarya Mallampati | 60fe113 | 2023-01-24 19:07:21 +0000 | [diff] [blame] | 12557 | return SatelliteManager.SATELLITE_SERVICE_DISABLED; |
| 12558 | } |
| 12559 | |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame^] | 12560 | Phone phone = getPhoneOrDefault(validSubId, "getMaxCharactersPerSatelliteTextMessage"); |
Aishwarya Mallampati | 60fe113 | 2023-01-24 19:07:21 +0000 | [diff] [blame] | 12561 | if (phone == null) { |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame^] | 12562 | return SatelliteManager.SATELLITE_SERVICE_INVALID_TELEPHONY_STATE; |
Aishwarya Mallampati | 60fe113 | 2023-01-24 19:07:21 +0000 | [diff] [blame] | 12563 | } |
| 12564 | |
| 12565 | Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(callback::accept); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame^] | 12566 | int result = (int) sendRequest( |
| 12567 | CMD_GET_MAX_CHAR_PER_SATELLITE_TEXT_MSG, argument, validSubId); |
Aishwarya Mallampati | 60fe113 | 2023-01-24 19:07:21 +0000 | [diff] [blame] | 12568 | if (DBG) log("getMaxCharPerTextMessageOnSatellite result: " + result); |
| 12569 | return result; |
| 12570 | } |
| 12571 | |
| 12572 | /** |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame^] | 12573 | * Register the subscription with a satellite provider. |
| 12574 | * This is needed to register the subscription if the provider allows dynamic registration. |
| 12575 | * |
| 12576 | * @param subId The subId of the subscription to be provisioned. |
| 12577 | * @param features List of features to be provisioned. |
| 12578 | * @param callback The callback to get the error code of the request. |
| 12579 | * @return The signal transport used by the caller to cancel the provision request. |
| 12580 | * @throws SecurityException if the caller doesn't have the required permission. |
| 12581 | */ |
| 12582 | @Override |
| 12583 | public ICancellationSignal provisionSatelliteService(int subId, int[] features, |
| 12584 | IIntegerConsumer callback) { |
| 12585 | enforceSatelliteCommunicationPermission("provisionSatelliteService"); |
| 12586 | |
| 12587 | final int validSubId = getValidSatelliteSubId(subId); |
| 12588 | String callbackRemoteExErrorMessage = "provisionSatelliteService: callback not available."; |
| 12589 | Phone phone = getPhoneOrDefault(validSubId, "provisionSatelliteService"); |
| 12590 | if (phone == null) { |
| 12591 | sendResponse(callback, SatelliteManager.SATELLITE_SERVICE_INVALID_TELEPHONY_STATE, |
| 12592 | callbackRemoteExErrorMessage); |
| 12593 | return null; |
| 12594 | } |
| 12595 | |
| 12596 | if (mSatelliteProvisionCallbacks.containsKey(validSubId)) { |
| 12597 | sendResponse(callback, SatelliteManager.SATELLITE_SERVICE_PROVISION_IN_PROGRESS, |
| 12598 | callbackRemoteExErrorMessage); |
| 12599 | return null; |
| 12600 | } |
| 12601 | |
| 12602 | if (isSatelliteEnabled(validSubId)) { |
| 12603 | sendResponse(callback, SatelliteManager.SATELLITE_SERVICE_ALREADY_PROVISIONED, |
| 12604 | callbackRemoteExErrorMessage); |
| 12605 | return null; |
| 12606 | } |
| 12607 | |
| 12608 | sendRequestAsync(CMD_PROVISION_SATELLITE_SERVICE, |
| 12609 | new ProvisionSatelliteServiceArgument(features, callback, validSubId), phone, null); |
| 12610 | |
| 12611 | ICancellationSignal cancelTransport = CancellationSignal.createTransport(); |
| 12612 | CancellationSignal.fromTransport(cancelTransport) |
| 12613 | .setOnCancelListener(() -> { |
| 12614 | sendRequestAsync(CMD_CANCEL_PROVISION_SATELLITE_SERVICE, validSubId); |
| 12615 | }); |
| 12616 | return cancelTransport; |
| 12617 | } |
| 12618 | |
| 12619 | /** |
| 12620 | * Register for the satellite provision state change. |
| 12621 | * |
| 12622 | * @param subId The subId of the subscription associated with the satellite service. |
| 12623 | * @param callback The callback to handle the satellite provision state changed event. |
| 12624 | * @throws SecurityException if the caller doesn't have the required permission. |
| 12625 | */ |
| 12626 | @Override |
| 12627 | @SatelliteManager.SatelliteServiceResult |
| 12628 | public int registerForSatelliteProvisionStateChanged( |
| 12629 | int subId, ISatelliteStateListener callback) { |
| 12630 | //enforceSatelliteCommunicationPermission("registerForSatelliteProvisionStateChanged"); |
| 12631 | |
| 12632 | final int validSubId = getValidSatelliteSubId(subId); |
| 12633 | Phone phone = getPhoneOrDefault( |
| 12634 | validSubId, "registerForSatelliteProvisionStateChanged"); |
| 12635 | if (phone == null) { |
| 12636 | return SatelliteManager.SATELLITE_SERVICE_INVALID_TELEPHONY_STATE; |
| 12637 | } |
| 12638 | |
| 12639 | SatelliteProvisionStateChangedHandler satelliteProvisionStateChangedHandler = |
| 12640 | mSatelliteProvisionStateChangedHandlers.get(validSubId); |
| 12641 | if (satelliteProvisionStateChangedHandler == null) { |
| 12642 | satelliteProvisionStateChangedHandler = |
| 12643 | new SatelliteProvisionStateChangedHandler( |
| 12644 | Looper.getMainLooper(), validSubId); |
| 12645 | phone.registerForSatelliteProvisionStateChanged( |
| 12646 | satelliteProvisionStateChangedHandler, |
| 12647 | SatelliteProvisionStateChangedHandler.EVENT_PROVISION_STATE_CHANGED, null); |
| 12648 | } |
| 12649 | |
| 12650 | if (callback != null) { |
| 12651 | satelliteProvisionStateChangedHandler.addListener(callback); |
| 12652 | } |
| 12653 | mSatelliteProvisionStateChangedHandlers.put( |
| 12654 | validSubId, satelliteProvisionStateChangedHandler); |
| 12655 | return SatelliteManager.SATELLITE_SERVICE_SUCCESS; |
| 12656 | } |
| 12657 | |
| 12658 | /** |
| 12659 | * Unregister for the satellite provision state change. |
| 12660 | * |
| 12661 | * @param subId The subId of the subscription associated with the satellite service. |
| 12662 | * @param callback The callback that was passed to |
| 12663 | * {@link #registerForSatelliteProvisionStateChanged(int, ISatelliteStateListener)} |
| 12664 | * @throws SecurityException if the caller doesn't have the required permission. |
| 12665 | */ |
| 12666 | @Override |
| 12667 | @SatelliteManager.SatelliteServiceResult |
| 12668 | public int unregisterForSatelliteProvisionStateChanged( |
| 12669 | int subId, ISatelliteStateListener callback) { |
| 12670 | enforceSatelliteCommunicationPermission("unregisterForSatelliteProvisionStateChanged"); |
| 12671 | |
| 12672 | final int validSubId = getValidSatelliteSubId(subId); |
| 12673 | SatelliteProvisionStateChangedHandler satelliteProvisionStateChangedHandler = |
| 12674 | mSatelliteProvisionStateChangedHandlers.get(validSubId); |
| 12675 | if (satelliteProvisionStateChangedHandler != null) { |
| 12676 | if (satelliteProvisionStateChangedHandler.removeListener(callback)) { |
| 12677 | return SatelliteManager.SATELLITE_SERVICE_SUCCESS; |
| 12678 | } |
| 12679 | } |
| 12680 | return SatelliteManager.SATELLITE_SERVICE_CALLBACK_NOT_REGISTERED; |
| 12681 | } |
| 12682 | |
| 12683 | /** |
| 12684 | * Get the list of provisioned satellite features. |
| 12685 | * |
| 12686 | * @param subId The subId of the subscription associated with the satellite service. |
| 12687 | * @param callback The callback to get the list of provisioned satellite features. |
| 12688 | * @return The error code of the request. |
| 12689 | * @throws SecurityException if the caller doesn't have the required permission. |
| 12690 | */ |
| 12691 | @Override |
| 12692 | @SatelliteManager.SatelliteServiceResult |
| 12693 | public int getProvisionedSatelliteFeatures(int subId, IIntArrayConsumer callback) { |
| 12694 | enforceSatelliteCommunicationPermission("getProvisionedSatelliteFeatures"); |
| 12695 | |
| 12696 | final int validSubId = getValidSatelliteSubId(subId); |
| 12697 | if (!isSatelliteEnabled(validSubId)) { |
| 12698 | return SatelliteManager.SATELLITE_SERVICE_DISABLED; |
| 12699 | } |
| 12700 | |
| 12701 | final Phone phone = getPhoneOrDefault(validSubId, "getProvisionedSatelliteFeatures"); |
| 12702 | if (phone == null) { |
| 12703 | return SatelliteManager.SATELLITE_SERVICE_INVALID_TELEPHONY_STATE; |
| 12704 | } |
| 12705 | |
| 12706 | int result = (int) sendRequest( |
| 12707 | CMD_GET_PROVISIONED_SATELLITE_FEATURES, callback, validSubId); |
| 12708 | if (DBG) log("getProvisionedSatelliteFeatures result: " + result); |
| 12709 | return result; |
| 12710 | } |
| 12711 | |
| 12712 | private void handleCmdProvisionSatelliteService(@NonNull ProvisionSatelliteServiceArgument arg, |
| 12713 | @NonNull Phone phone, Message onCompleted) { |
| 12714 | String callbackRemoteExErrorMessage = |
| 12715 | "handleCmdProvisionSatelliteService: callback not available."; |
| 12716 | if (arg == null) { |
| 12717 | loge("handleCmdProvisionSatelliteService: arg is null"); |
| 12718 | return; |
| 12719 | } |
| 12720 | if (phone == null) { |
| 12721 | loge("handleCmdProvisionSatelliteService: phone is null"); |
| 12722 | sendResponse(arg.callback, SatelliteManager.SATELLITE_SERVICE_INVALID_TELEPHONY_STATE, |
| 12723 | callbackRemoteExErrorMessage); |
| 12724 | return; |
| 12725 | } |
| 12726 | |
| 12727 | if (!mSatelliteProvisionCallbacks.containsKey(arg.subId)) { |
| 12728 | mSatelliteProvisionCallbacks.put(arg.subId, arg.callback); |
| 12729 | phone.provisionSatelliteService(onCompleted, phone.getImei(), phone.getMsisdn(), |
| 12730 | getSatelliteImsi(arg.subId), arg.features); |
| 12731 | } else { |
| 12732 | sendResponse(arg.callback, SatelliteManager.SATELLITE_SERVICE_PROVISION_IN_PROGRESS, |
| 12733 | callbackRemoteExErrorMessage); |
| 12734 | } |
| 12735 | } |
| 12736 | |
| 12737 | private void handleEventProvisionSatelliteServiceDone(MainThreadRequest request) { |
| 12738 | final ProvisionSatelliteServiceArgument arg = |
| 12739 | (ProvisionSatelliteServiceArgument) request.argument; |
| 12740 | if (arg == null) { |
| 12741 | loge("handleEventProvisionSatelliteServiceDone: arg is null"); |
| 12742 | return; |
| 12743 | } |
| 12744 | |
| 12745 | IIntegerConsumer callback = mSatelliteProvisionCallbacks.remove(arg.subId); |
| 12746 | if (callback == null) { |
| 12747 | loge("handleEventProvisionSatelliteServiceDone: callback is null for subId=" |
| 12748 | + arg.subId); |
| 12749 | return; |
| 12750 | } |
| 12751 | |
| 12752 | int result = (int) request.result; |
| 12753 | if (DBG) { |
| 12754 | log("handleEventProvisionSatelliteServiceDone: result=" |
| 12755 | + result + ", subId=" + arg.subId); |
| 12756 | } |
| 12757 | sendResponse(callback, result, |
| 12758 | "handleEventProvisionSatelliteServiceDone: callback not available."); |
| 12759 | |
| 12760 | if (result == SatelliteManager.SATELLITE_SERVICE_SUCCESS) { |
| 12761 | setSatelliteEnabled(arg.subId, true); |
| 12762 | } |
| 12763 | |
| 12764 | /** |
| 12765 | * We need to update satellite provision status in SubscriptionController |
| 12766 | * or SatelliteController. |
| 12767 | * TODO (b/267826133) we need to do this for all subscriptions on the device. |
| 12768 | */ |
| 12769 | registerForSatelliteProvisionStateChanged(arg.subId, null); |
| 12770 | } |
| 12771 | |
| 12772 | private void handleCmdCancelProvisionSatelliteService(int subId, Message onCompleted) { |
| 12773 | final Phone phone = getPhoneOrDefault( |
| 12774 | subId, "handleCmdCancelProvisionSatelliteService"); |
| 12775 | if (phone == null) { |
| 12776 | return; |
| 12777 | } |
| 12778 | phone.cancelProvisionSatelliteService(onCompleted, getSatelliteImsi(subId)); |
| 12779 | } |
| 12780 | |
| 12781 | private void sendResponse(@NonNull IIntegerConsumer callback, int result, String message) { |
| 12782 | Objects.requireNonNull(callback); |
| 12783 | |
| 12784 | try { |
| 12785 | callback.accept(result); |
| 12786 | } catch (RemoteException e) { |
| 12787 | Log.w(LOG_TAG, message); |
| 12788 | } |
| 12789 | } |
| 12790 | |
| 12791 | private String getSatelliteImsi(int subId) { |
| 12792 | if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) { |
| 12793 | return ""; |
| 12794 | } |
| 12795 | |
| 12796 | if (mSubscriptionController == null) { |
| 12797 | loge("getSatelliteImsi: mSubscriptionController is null"); |
| 12798 | return ""; |
| 12799 | } |
| 12800 | return mSubscriptionController.getImsiPrivileged(subId); |
| 12801 | } |
| 12802 | |
| 12803 | private Phone getPhoneOrDefault(int subId, String caller) { |
| 12804 | Phone phone = getPhone(subId); |
| 12805 | if (phone == null) { |
| 12806 | loge(caller + " called with invalid subId: " + subId |
| 12807 | + ". Retrying with default phone."); |
| 12808 | phone = getDefaultPhone(); |
| 12809 | if (phone == null) { |
| 12810 | loge(caller + " failed with no phone object."); |
| 12811 | } |
| 12812 | } |
| 12813 | return phone; |
| 12814 | } |
| 12815 | |
| 12816 | /** |
| 12817 | * Check if satellite is enabled for a subscription. |
| 12818 | * |
| 12819 | * Note: this is the version without permission check for telephony internal use only. The |
| 12820 | * caller need to take care of the permission check. |
| 12821 | */ |
| 12822 | private boolean isSatelliteEnabled(int subId) { |
| 12823 | if (subId != SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) { |
| 12824 | if (mSubscriptionController == null) { |
| 12825 | loge("setSatelliteEnabled mSubscriptionController is null"); |
| 12826 | return false; |
| 12827 | } |
| 12828 | |
| 12829 | String strResult = mSubscriptionController.getSubscriptionProperty( |
| 12830 | subId, SubscriptionManager.SATELLITE_ENABLED); |
| 12831 | if (strResult != null) { |
| 12832 | int intResult = Integer.parseInt(strResult); |
| 12833 | return (intResult == 1) ? true : false; |
| 12834 | } |
| 12835 | } else { |
| 12836 | //TODO (b/267826133): check via SatelliteController |
| 12837 | } |
| 12838 | return false; |
| 12839 | } |
| 12840 | |
| 12841 | /** |
| 12842 | * Set satellite enabled for a subscription. |
| 12843 | * |
| 12844 | * The permission {@link android.Manifest.permission#MODIFY_PHONE_STATE} will be enforced by |
| 12845 | * {@link SubscriptionController} when setting satellite enabled for an active subscription. |
| 12846 | * Otherwise, {@link android.Manifest.permission#SATELLITE_COMMUNICATION} will be enforced. |
| 12847 | */ |
| 12848 | private void setSatelliteEnabled(int subId, boolean isEnabled) { |
| 12849 | if (subId != SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) { |
| 12850 | if (mSubscriptionController == null) { |
| 12851 | loge("setSatelliteEnabled mSubscriptionController is null"); |
| 12852 | return; |
| 12853 | } |
| 12854 | mSubscriptionController.setSubscriptionProperty( |
| 12855 | subId, SubscriptionManager.SATELLITE_ENABLED, isEnabled ? "1" : "0"); |
| 12856 | } else { |
| 12857 | //TODO (b/267826133): enable via SatelliteController |
| 12858 | } |
| 12859 | } |
| 12860 | |
| 12861 | private int getValidSatelliteSubId(int subId) { |
| 12862 | if (mSubscriptionController == null) { |
| 12863 | loge("getValidSatelliteSubId mSubscriptionController is null. " |
| 12864 | + "Use DEFAULT_SUBSCRIPTION_ID for subId=" + subId); |
| 12865 | return SubscriptionManager.DEFAULT_SUBSCRIPTION_ID; |
| 12866 | } |
| 12867 | final long identity = Binder.clearCallingIdentity(); |
| 12868 | try { |
| 12869 | Context context = getDefaultPhone().getContext(); |
| 12870 | if (mSubscriptionController.isActiveSubId( |
| 12871 | subId, context.getOpPackageName(), context.getAttributionTag())) { |
| 12872 | return subId; |
| 12873 | } |
| 12874 | } finally { |
| 12875 | Binder.restoreCallingIdentity(identity); |
| 12876 | } |
| 12877 | if (DBG) log("getValidSatelliteSubId: use DEFAULT_SUBSCRIPTION_ID for subId=" + subId); |
| 12878 | return SubscriptionManager.DEFAULT_SUBSCRIPTION_ID; |
| 12879 | } |
| 12880 | |
| 12881 | /** |
arunvoddu | d5c6ce0 | 2022-12-11 06:03:12 +0000 | [diff] [blame] | 12882 | * Check whether the caller (or self, if not processing an IPC) can read device identifiers. |
| 12883 | * |
| 12884 | * <p>This method behaves in one of the following ways: |
| 12885 | * <ul> |
| 12886 | * <li>return true : if the calling package has the appop permission {@link |
| 12887 | * Manifest.permission#USE_ICC_AUTH_WITH_DEVICE_IDENTIFIER} in the manifest </> |
| 12888 | * <li>return true : if any one subscription has the READ_PRIVILEGED_PHONE_STATE |
| 12889 | * permission, the calling package passes a DevicePolicyManager Device Owner / Profile |
| 12890 | * Owner device identifier access check, or the calling package has carrier privileges</> |
| 12891 | * <li>throw SecurityException: if the caller does not meet any of the requirements. |
| 12892 | * </ul> |
| 12893 | */ |
| 12894 | private static boolean checkCallingOrSelfReadDeviceIdentifiersForAnySub(Context context, |
| 12895 | String callingPackage, @Nullable String callingFeatureId, String message) { |
| 12896 | for (Phone phone : PhoneFactory.getPhones()) { |
| 12897 | if (TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(context, |
| 12898 | phone.getSubId(), callingPackage, callingFeatureId, message)) { |
| 12899 | return true; |
| 12900 | } |
| 12901 | } |
| 12902 | return false; |
| 12903 | } |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 12904 | |
| 12905 | /** |
| 12906 | * Class binds the consumer[callback] and carrierId. |
| 12907 | */ |
| 12908 | private static class CallerCallbackInfo { |
| 12909 | private final Consumer<Integer> mConsumer; |
| 12910 | private final int mCarrierId; |
| 12911 | |
| 12912 | public CallerCallbackInfo(Consumer<Integer> consumer, int carrierId) { |
| 12913 | mConsumer = consumer; |
| 12914 | mCarrierId = carrierId; |
| 12915 | } |
| 12916 | |
| 12917 | public Consumer<Integer> getConsumer() { |
| 12918 | return mConsumer; |
| 12919 | } |
| 12920 | |
| 12921 | public int getCarrierId() { |
| 12922 | return mCarrierId; |
| 12923 | } |
| 12924 | } |
arunvoddu | d5c6ce0 | 2022-12-11 06:03:12 +0000 | [diff] [blame] | 12925 | } |