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; |
| 54 | import android.os.Handler; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 55 | import android.os.IBinder; |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 56 | import android.os.LocaleList; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 57 | import android.os.Looper; |
| 58 | import android.os.Message; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 59 | import android.os.Messenger; |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 60 | import android.os.ParcelFileDescriptor; |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 61 | import android.os.ParcelUuid; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 62 | import android.os.PersistableBundle; |
Shuo Qian | cd19c46 | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 63 | import android.os.Process; |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 64 | import android.os.RemoteException; |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 65 | import android.os.ResultReceiver; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 66 | import android.os.ServiceSpecificException; |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 67 | import android.os.SystemClock; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 68 | import android.os.UserHandle; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 69 | import android.os.UserManager; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 70 | import android.os.WorkSource; |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 71 | import android.preference.PreferenceManager; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 72 | import android.provider.DeviceConfig; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 73 | import android.provider.Settings; |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 74 | import android.provider.Telephony; |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 75 | import android.service.carrier.CarrierIdentifier; |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 76 | import android.sysprop.TelephonyProperties; |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 77 | import android.telecom.PhoneAccount; |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 78 | import android.telecom.PhoneAccountHandle; |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 79 | import android.telecom.TelecomManager; |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 80 | import android.telephony.AccessNetworkConstants; |
| 81 | import android.telephony.ActivityStatsTechSpecificInfo; |
Chen Xu | 227e06f | 2019-09-26 22:48:11 -0700 | [diff] [blame] | 82 | import android.telephony.Annotation.ApnType; |
Jack Yu | 0eda684 | 2022-04-18 00:34:46 -0700 | [diff] [blame] | 83 | import android.telephony.Annotation.DataActivityType; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 84 | import android.telephony.Annotation.ThermalMitigationResult; |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 85 | import android.telephony.AnomalyReporter; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 86 | import android.telephony.CallForwardingInfo; |
Junda Liu | 12f7d80 | 2015-05-01 12:06:44 -0700 | [diff] [blame] | 87 | import android.telephony.CarrierConfigManager; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 88 | import android.telephony.CarrierRestrictionRules; |
Hui Wang | 9b5793a | 2022-12-05 14:38:06 -0600 | [diff] [blame] | 89 | import android.telephony.CellBroadcastIdRange; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 90 | import android.telephony.CellIdentity; |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 91 | import android.telephony.CellIdentityCdma; |
| 92 | import android.telephony.CellIdentityGsm; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 93 | import android.telephony.CellInfo; |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 94 | import android.telephony.CellInfoGsm; |
| 95 | import android.telephony.CellInfoWcdma; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 96 | import android.telephony.ClientRequestStats; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 97 | import android.telephony.DataThrottlingRequest; |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 98 | import android.telephony.IBootstrapAuthenticationCallback; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 99 | import android.telephony.ICellInfoCallback; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 100 | import android.telephony.IccOpenLogicalChannelResponse; |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 101 | import android.telephony.LocationAccessPolicy; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 102 | import android.telephony.ModemActivityInfo; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 103 | import android.telephony.NeighboringCellInfo; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 104 | import android.telephony.NetworkScanRequest; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 105 | import android.telephony.PhoneCapability; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 106 | import android.telephony.PhoneNumberRange; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 107 | import android.telephony.RadioAccessFamily; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 108 | import android.telephony.RadioAccessSpecifier; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 109 | import android.telephony.ServiceState; |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 110 | import android.telephony.SignalStrength; |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 111 | import android.telephony.SignalStrengthUpdateRequest; |
| 112 | import android.telephony.SignalThresholdInfo; |
Wink Saville | 0f3b5fc | 2014-11-11 08:40:49 -0800 | [diff] [blame] | 113 | import android.telephony.SubscriptionInfo; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 114 | import android.telephony.SubscriptionManager; |
Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 115 | import android.telephony.TelephonyFrameworkInitializer; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 116 | import android.telephony.TelephonyHistogram; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 117 | import android.telephony.TelephonyManager; |
Jack Yu | f5badd9 | 2022-12-08 00:50:53 -0800 | [diff] [blame] | 118 | import android.telephony.TelephonyManager.SimState; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 119 | import android.telephony.TelephonyScanManager; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 120 | import android.telephony.ThermalMitigationRequest; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 121 | import android.telephony.UiccCardInfo; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 122 | import android.telephony.UiccPortInfo; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 123 | import android.telephony.UiccSlotInfo; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 124 | import android.telephony.UiccSlotMapping; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 125 | import android.telephony.UssdResponse; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 126 | import android.telephony.VisualVoicemailSmsFilterSettings; |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 127 | import android.telephony.data.NetworkSlicingConfig; |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 128 | import android.telephony.emergency.EmergencyNumber; |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 129 | import android.telephony.gba.GbaAuthRequest; |
| 130 | import android.telephony.gba.UaSecurityProtocolIdentifier; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 131 | import android.telephony.ims.ImsException; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 132 | import android.telephony.ims.ProvisioningManager; |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 133 | import android.telephony.ims.RcsClientConfiguration; |
Brad Ebinger | 14d467f | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 134 | import android.telephony.ims.RcsContactUceCapability; |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 135 | import android.telephony.ims.RegistrationManager; |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 136 | import android.telephony.ims.aidl.IFeatureProvisioningCallback; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 137 | import android.telephony.ims.aidl.IImsCapabilityCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 138 | import android.telephony.ims.aidl.IImsConfig; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 139 | import android.telephony.ims.aidl.IImsConfigCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 140 | import android.telephony.ims.aidl.IImsRegistration; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 141 | import android.telephony.ims.aidl.IImsRegistrationCallback; |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 142 | import android.telephony.ims.aidl.IRcsConfigCallback; |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 143 | import android.telephony.ims.feature.ImsFeature; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 144 | import android.telephony.ims.stub.ImsConfigImplBase; |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 145 | import android.telephony.ims.stub.ImsRegistrationImplBase; |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 146 | import android.telephony.satellite.ISatellitePositionUpdateCallback; |
| 147 | import android.telephony.satellite.PointingInfo; |
| 148 | import android.telephony.satellite.SatelliteManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 149 | import android.text.TextUtils; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 150 | import android.util.ArraySet; |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 151 | import android.util.EventLog; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 152 | import android.util.Log; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 153 | import android.util.Pair; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 154 | |
Andrew Lee | 312e817 | 2014-10-23 17:01:36 -0700 | [diff] [blame] | 155 | import com.android.ims.ImsManager; |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 156 | import com.android.ims.internal.IImsServiceFeatureCallback; |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 157 | import com.android.ims.rcs.uce.eab.EabUtil; |
SongFerngWang | fd89b10 | 2021-05-27 22:44:54 +0800 | [diff] [blame] | 158 | import com.android.internal.annotations.VisibleForTesting; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 159 | import com.android.internal.telephony.CallForwardInfo; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 160 | import com.android.internal.telephony.CallManager; |
Tyler Gunn | 52dcf77 | 2017-04-26 11:30:31 -0700 | [diff] [blame] | 161 | import com.android.internal.telephony.CallStateException; |
Tyler Gunn | d433926 | 2021-05-03 14:46:49 -0700 | [diff] [blame] | 162 | import com.android.internal.telephony.CallTracker; |
Rambo Wang | 9c9ffdd | 2022-01-13 21:51:44 -0800 | [diff] [blame] | 163 | import com.android.internal.telephony.CarrierPrivilegesTracker; |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 164 | import com.android.internal.telephony.CarrierResolver; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 165 | import com.android.internal.telephony.CellNetworkScanResult; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 166 | import com.android.internal.telephony.CommandException; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 167 | import com.android.internal.telephony.CommandsInterface; |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 168 | import com.android.internal.telephony.GbaManager; |
Shuo Qian | ccbaf74 | 2021-02-22 18:32:21 -0800 | [diff] [blame] | 169 | import com.android.internal.telephony.GsmCdmaPhone; |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 170 | import com.android.internal.telephony.HalVersion; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 171 | import com.android.internal.telephony.IBooleanConsumer; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 172 | import com.android.internal.telephony.ICallForwardingInfoCallback; |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 173 | import com.android.internal.telephony.IImsStateCallback; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 174 | import com.android.internal.telephony.IIntegerConsumer; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 175 | import com.android.internal.telephony.INumberVerificationCallback; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 176 | import com.android.internal.telephony.ITelephony; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 177 | import com.android.internal.telephony.IccCard; |
Jack Yu | f5badd9 | 2022-12-08 00:50:53 -0800 | [diff] [blame] | 178 | import com.android.internal.telephony.IccCardConstants; |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 179 | import com.android.internal.telephony.IccLogicalChannelRequest; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 180 | import com.android.internal.telephony.LocaleTracker; |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 181 | import com.android.internal.telephony.NetworkScanRequestTracker; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 182 | import com.android.internal.telephony.OperatorInfo; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 183 | import com.android.internal.telephony.Phone; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 184 | import com.android.internal.telephony.PhoneConfigurationManager; |
Nathan Harold | a667c15 | 2016-12-14 11:27:20 -0800 | [diff] [blame] | 185 | import com.android.internal.telephony.PhoneConstantConversions; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 186 | import com.android.internal.telephony.PhoneConstants; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 187 | import com.android.internal.telephony.PhoneFactory; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 188 | import com.android.internal.telephony.ProxyController; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 189 | import com.android.internal.telephony.RIL; |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 190 | import com.android.internal.telephony.RILConstants; |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 191 | import com.android.internal.telephony.RILUtils; |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 192 | import com.android.internal.telephony.RadioInterfaceCapabilityController; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 193 | import com.android.internal.telephony.ServiceStateTracker; |
Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame] | 194 | import com.android.internal.telephony.SmsApplication; |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 195 | import com.android.internal.telephony.SmsController; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 196 | import com.android.internal.telephony.SmsPermissions; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 197 | import com.android.internal.telephony.SubscriptionController; |
Peter Wang | 59571be | 2020-01-27 12:35:15 +0800 | [diff] [blame] | 198 | import com.android.internal.telephony.TelephonyIntents; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 199 | import com.android.internal.telephony.TelephonyPermissions; |
Jack Yu | 27422a5 | 2022-03-21 10:38:05 -0700 | [diff] [blame] | 200 | import com.android.internal.telephony.data.DataUtils; |
Hunsuk Choi | 42cc62a | 2022-10-16 06:03:40 +0000 | [diff] [blame] | 201 | import com.android.internal.telephony.domainselection.DomainSelectionResolver; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 202 | import com.android.internal.telephony.emergency.EmergencyNumberTracker; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 203 | import com.android.internal.telephony.euicc.EuiccConnector; |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 204 | import com.android.internal.telephony.ims.ImsResolver; |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 205 | import com.android.internal.telephony.imsphone.ImsPhone; |
| 206 | import com.android.internal.telephony.imsphone.ImsPhoneCallTracker; |
joonhunshin | 3e15424 | 2021-09-17 06:33:39 +0000 | [diff] [blame] | 207 | import com.android.internal.telephony.metrics.RcsStats; |
Pengquan Meng | 6c2dc9f | 2019-02-06 11:12:53 -0800 | [diff] [blame] | 208 | import com.android.internal.telephony.metrics.TelephonyMetrics; |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 209 | import com.android.internal.telephony.subscription.SubscriptionInfoInternal; |
| 210 | import com.android.internal.telephony.subscription.SubscriptionManagerService; |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 211 | import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 212 | import com.android.internal.telephony.uicc.IccIoResult; |
| 213 | import com.android.internal.telephony.uicc.IccUtils; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 214 | import com.android.internal.telephony.uicc.SIMRecords; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 215 | import com.android.internal.telephony.uicc.UiccCard; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 216 | import com.android.internal.telephony.uicc.UiccCardApplication; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 217 | import com.android.internal.telephony.uicc.UiccController; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 218 | import com.android.internal.telephony.uicc.UiccPort; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 219 | import com.android.internal.telephony.uicc.UiccProfile; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 220 | import com.android.internal.telephony.uicc.UiccSlot; |
zoey chen | c730df8 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 221 | import com.android.internal.telephony.util.LocaleUtils; |
Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame] | 222 | import com.android.internal.telephony.util.TelephonyUtils; |
fionaxu | 7ed723d | 2017-05-30 18:58:54 -0700 | [diff] [blame] | 223 | import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 224 | import com.android.internal.util.FunctionalUtils; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 225 | import com.android.internal.util.HexDump; |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 226 | import com.android.phone.callcomposer.CallComposerPictureManager; |
| 227 | import com.android.phone.callcomposer.CallComposerPictureTransfer; |
| 228 | import com.android.phone.callcomposer.ImageData; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 229 | import com.android.phone.settings.PickSmsSubscriptionActivity; |
Sarah Chin | 46355ba | 2022-11-01 23:51:16 -0700 | [diff] [blame] | 230 | import com.android.phone.slice.SlicePurchaseController; |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 231 | import com.android.phone.utils.CarrierAllowListInfo; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 232 | import com.android.phone.vvm.PhoneAccountHandleConverter; |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 233 | import com.android.phone.vvm.RemoteVvmTaskManager; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 234 | import com.android.phone.vvm.VisualVoicemailSettingsUtil; |
Ta-wei Yen | c890531 | 2017-03-28 11:14:45 -0700 | [diff] [blame] | 235 | import com.android.phone.vvm.VisualVoicemailSmsFilterConfig; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 236 | import com.android.services.telephony.TelecomAccountRegistry; |
| 237 | import com.android.services.telephony.TelephonyConnectionService; |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 238 | import com.android.telephony.Rlog; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 239 | |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 240 | import java.io.ByteArrayOutputStream; |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 241 | import java.io.FileDescriptor; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 242 | import java.io.IOException; |
| 243 | import java.io.InputStream; |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 244 | import java.io.PrintWriter; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 245 | import java.util.ArrayList; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 246 | import java.util.Arrays; |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 247 | import java.util.Collection; |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 248 | import java.util.Collections; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 249 | import java.util.HashMap; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 250 | import java.util.HashSet; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 251 | import java.util.List; |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 252 | import java.util.Locale; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 253 | import java.util.Map; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 254 | import java.util.NoSuchElementException; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 255 | import java.util.Objects; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 256 | import java.util.Set; |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 257 | import java.util.UUID; |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 258 | import java.util.concurrent.ConcurrentHashMap; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 259 | import java.util.concurrent.Executors; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 260 | import java.util.concurrent.atomic.AtomicBoolean; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 261 | import java.util.function.Consumer; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 262 | |
| 263 | /** |
| 264 | * Implementation of the ITelephony interface. |
| 265 | */ |
Santos Cordon | 117fee7 | 2014-05-16 17:56:12 -0700 | [diff] [blame] | 266 | public class PhoneInterfaceManager extends ITelephony.Stub { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 267 | private static final String LOG_TAG = "PhoneInterfaceManager"; |
| 268 | private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2); |
| 269 | private static final boolean DBG_LOC = false; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 270 | private static final boolean DBG_MERGE = false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 271 | |
| 272 | // Message codes used with mMainThreadHandler |
| 273 | private static final int CMD_HANDLE_PIN_MMI = 1; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 274 | private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7; |
| 275 | private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 276 | private static final int CMD_OPEN_CHANNEL = 9; |
| 277 | private static final int EVENT_OPEN_CHANNEL_DONE = 10; |
| 278 | private static final int CMD_CLOSE_CHANNEL = 11; |
| 279 | private static final int EVENT_CLOSE_CHANNEL_DONE = 12; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 280 | private static final int CMD_NV_READ_ITEM = 13; |
| 281 | private static final int EVENT_NV_READ_ITEM_DONE = 14; |
| 282 | private static final int CMD_NV_WRITE_ITEM = 15; |
| 283 | private static final int EVENT_NV_WRITE_ITEM_DONE = 16; |
| 284 | private static final int CMD_NV_WRITE_CDMA_PRL = 17; |
| 285 | private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 286 | private static final int CMD_RESET_MODEM_CONFIG = 19; |
| 287 | private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 288 | private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21; |
| 289 | private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22; |
Sailesh Nepal | 35b5945 | 2014-03-06 09:26:56 -0800 | [diff] [blame] | 290 | private static final int CMD_SEND_ENVELOPE = 25; |
| 291 | private static final int EVENT_SEND_ENVELOPE_DONE = 26; |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 292 | private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27; |
| 293 | private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28; |
Derek Tan | 6b088ee | 2014-09-05 14:15:18 -0700 | [diff] [blame] | 294 | private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29; |
| 295 | private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30; |
| 296 | private static final int CMD_EXCHANGE_SIM_IO = 31; |
| 297 | private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 298 | private static final int CMD_SET_VOICEMAIL_NUMBER = 33; |
| 299 | private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 300 | private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35; |
| 301 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 302 | private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37; |
| 303 | private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 304 | private static final int CMD_PERFORM_NETWORK_SCAN = 39; |
| 305 | private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40; |
| 306 | private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41; |
| 307 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 308 | private static final int CMD_SET_ALLOWED_CARRIERS = 43; |
| 309 | private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44; |
| 310 | private static final int CMD_GET_ALLOWED_CARRIERS = 45; |
| 311 | private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 312 | private static final int CMD_HANDLE_USSD_REQUEST = 47; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 313 | private static final int CMD_GET_FORBIDDEN_PLMNS = 48; |
| 314 | private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 315 | private static final int CMD_SWITCH_SLOTS = 50; |
| 316 | private static final int EVENT_SWITCH_SLOTS_DONE = 51; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 317 | private static final int CMD_GET_NETWORK_SELECTION_MODE = 52; |
| 318 | private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53; |
| 319 | private static final int CMD_GET_CDMA_ROAMING_MODE = 54; |
| 320 | private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55; |
| 321 | private static final int CMD_SET_CDMA_ROAMING_MODE = 56; |
| 322 | private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57; |
| 323 | private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58; |
| 324 | private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 325 | private static final int CMD_GET_ALL_CELL_INFO = 60; |
| 326 | private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61; |
| 327 | private static final int CMD_GET_CELL_LOCATION = 62; |
| 328 | private static final int EVENT_GET_CELL_LOCATION_DONE = 63; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 329 | private static final int CMD_MODEM_REBOOT = 64; |
| 330 | private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 331 | private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66; |
| 332 | private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 333 | private static final int CMD_REQUEST_ENABLE_MODEM = 68; |
| 334 | private static final int EVENT_ENABLE_MODEM_DONE = 69; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 335 | private static final int CMD_GET_MODEM_STATUS = 70; |
| 336 | private static final int EVENT_GET_MODEM_STATUS_DONE = 71; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 337 | private static final int CMD_SET_FORBIDDEN_PLMNS = 72; |
| 338 | private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 339 | private static final int CMD_ERASE_MODEM_CONFIG = 74; |
| 340 | private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75; |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 341 | private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76; |
| 342 | private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77; |
| 343 | private static final int CMD_SET_ICC_LOCK_ENABLED = 78; |
| 344 | private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 345 | private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80; |
| 346 | private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 347 | private static final int MSG_NOTIFY_USER_ACTIVITY = 82; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 348 | private static final int CMD_GET_CALL_FORWARDING = 83; |
| 349 | private static final int EVENT_GET_CALL_FORWARDING_DONE = 84; |
| 350 | private static final int CMD_SET_CALL_FORWARDING = 85; |
| 351 | private static final int EVENT_SET_CALL_FORWARDING_DONE = 86; |
| 352 | private static final int CMD_GET_CALL_WAITING = 87; |
| 353 | private static final int EVENT_GET_CALL_WAITING_DONE = 88; |
| 354 | private static final int CMD_SET_CALL_WAITING = 89; |
| 355 | private static final int EVENT_SET_CALL_WAITING_DONE = 90; |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 356 | private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91; |
| 357 | private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92; |
| 358 | private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93; |
| 359 | private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 360 | private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95; |
| 361 | private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 362 | private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97; |
| 363 | private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 364 | private static final int CMD_SET_DATA_THROTTLING = 99; |
| 365 | private static final int EVENT_SET_DATA_THROTTLING_DONE = 100; |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 366 | private static final int CMD_SET_SIM_POWER = 101; |
| 367 | private static final int EVENT_SET_SIM_POWER_DONE = 102; |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 368 | private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103; |
| 369 | private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104; |
| 370 | private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105; |
| 371 | private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 372 | private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107; |
| 373 | 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] | 374 | private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 375 | private static final int CMD_GET_SLICING_CONFIG = 110; |
| 376 | private static final int EVENT_GET_SLICING_CONFIG_DONE = 111; |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 377 | private static final int CMD_ERASE_DATA_SHARED_PREFERENCES = 112; |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 378 | private static final int CMD_ENABLE_VONR = 113; |
| 379 | private static final int EVENT_ENABLE_VONR_DONE = 114; |
| 380 | private static final int CMD_IS_VONR_ENABLED = 115; |
| 381 | private static final int EVENT_IS_VONR_ENABLED_DONE = 116; |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 382 | private static final int CMD_PURCHASE_PREMIUM_CAPABILITY = 117; |
| 383 | private static final int EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE = 118; |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 384 | private static final int CMD_START_SATELLITE_POSITION_UPDATES = 119; |
| 385 | private static final int EVENT_START_SATELLITE_POSITION_UPDATES_DONE = 120; |
| 386 | private static final int CMD_STOP_SATELLITE_POSITION_UPDATES = 121; |
| 387 | private static final int EVENT_STOP_SATELLITE_POSITION_UPDATES_DONE = 122; |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 388 | // Parameters of select command. |
| 389 | private static final int SELECT_COMMAND = 0xA4; |
| 390 | private static final int SELECT_P1 = 0x04; |
| 391 | private static final int SELECT_P2 = 0; |
| 392 | private static final int SELECT_P3 = 0x10; |
| 393 | |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 394 | // Toggling null cipher and integrity support was added in IRadioNetwork 2.1 |
| 395 | private static final int MIN_NULL_CIPHER_AND_INTEGRITY_VERSION = 201; |
| 396 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 397 | /** The singleton instance. */ |
| 398 | private static PhoneInterfaceManager sInstance; |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 399 | private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 400 | |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 401 | private PhoneGlobals mApp; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 402 | private CallManager mCM; |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 403 | private ImsResolver mImsResolver; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 404 | private UserManager mUserManager; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 405 | private AppOpsManager mAppOps; |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 406 | private PackageManager mPm; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 407 | private MainThreadHandler mMainThreadHandler; |
Jack Yu | e37dd26 | 2022-12-16 11:53:37 -0800 | [diff] [blame] | 408 | private final SubscriptionController mSubscriptionController; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 409 | private SharedPreferences mTelephonySharedPreferences; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 410 | private PhoneConfigurationManager mPhoneConfigurationManager; |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 411 | private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 412 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 413 | /** User Activity */ |
| 414 | private AtomicBoolean mNotifyUserActivity; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 415 | private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200; |
| 416 | |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 417 | private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>(); |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 418 | private Map<Integer, SatellitePositionUpdateHandler> mSatellitePositionUpdateHandlers = |
| 419 | new ConcurrentHashMap<>(); |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 420 | |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 421 | private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_"; |
| 422 | private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_"; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 423 | private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_"; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 424 | private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_"; |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 425 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 426 | // String to store multi SIM allowed |
| 427 | private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted"; |
| 428 | |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 429 | // The AID of ISD-R. |
| 430 | private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100"; |
| 431 | |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 432 | private NetworkScanRequestTracker mNetworkScanRequestTracker; |
| 433 | |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 434 | private static final int TYPE_ALLOCATION_CODE_LENGTH = 8; |
| 435 | private static final int MANUFACTURER_CODE_LENGTH = 8; |
| 436 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 437 | private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1; |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 438 | private static final int MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE = -2; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 439 | |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 440 | private static final String PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID = |
| 441 | "24bf97a6-e8a6-44d8-a6a4-255d7548733c"; |
| 442 | |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 443 | /** |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 444 | * Experiment flag to enable erase modem config on reset network, default value is false |
| 445 | */ |
| 446 | public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED = |
| 447 | "reset_network_erase_modem_config_enabled"; |
| 448 | |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 449 | private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 450 | |
Gary Jian | 76280a4 | 2022-12-07 16:18:33 +0800 | [diff] [blame] | 451 | private static final int MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS = 50; |
| 452 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 453 | /** |
| 454 | * With support for MEP(multiple enabled profile) in Android T, a SIM card can have more than |
| 455 | * one ICCID active at the same time. |
| 456 | * Apps should use below API signatures if targeting SDK is T and beyond. |
| 457 | * |
| 458 | * @hide |
| 459 | */ |
| 460 | @ChangeId |
| 461 | @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU) |
| 462 | public static final long GET_API_SIGNATURES_FROM_UICC_PORT_INFO = 202110963L; |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 463 | |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 464 | /** |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 465 | * Apps targeting on Android T and beyond will get exception whenever icc close channel |
| 466 | * operation fails. |
| 467 | */ |
| 468 | @ChangeId |
| 469 | @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU) |
| 470 | public static final long ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE = 208739934L; |
| 471 | |
| 472 | /** |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 473 | * A request object to use for transmitting data to an ICC. |
| 474 | */ |
| 475 | private static final class IccAPDUArgument { |
| 476 | public int channel, cla, command, p1, p2, p3; |
| 477 | public String data; |
| 478 | |
| 479 | public IccAPDUArgument(int channel, int cla, int command, |
| 480 | int p1, int p2, int p3, String data) { |
| 481 | this.channel = channel; |
| 482 | this.cla = cla; |
| 483 | this.command = command; |
| 484 | this.p1 = p1; |
| 485 | this.p2 = p2; |
| 486 | this.p3 = p3; |
| 487 | this.data = data; |
| 488 | } |
| 489 | } |
| 490 | |
| 491 | /** |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 492 | * A request object to use for transmitting data to an ICC. |
| 493 | */ |
| 494 | private static final class ManualNetworkSelectionArgument { |
| 495 | public OperatorInfo operatorInfo; |
| 496 | public boolean persistSelection; |
| 497 | |
| 498 | public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) { |
| 499 | this.operatorInfo = operatorInfo; |
| 500 | this.persistSelection = persistSelection; |
| 501 | } |
| 502 | } |
| 503 | |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 504 | private static final class PurchasePremiumCapabilityArgument { |
| 505 | public @TelephonyManager.PremiumCapability int capability; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 506 | public @NonNull IIntegerConsumer callback; |
| 507 | |
| 508 | PurchasePremiumCapabilityArgument(@TelephonyManager.PremiumCapability int capability, |
Sarah Chin | b8218c2 | 2023-01-04 13:35:29 -0800 | [diff] [blame] | 509 | @NonNull IIntegerConsumer callback) { |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 510 | this.capability = capability; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 511 | this.callback = callback; |
| 512 | } |
| 513 | } |
| 514 | |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 515 | private static final class SatellitePositionUpdateHandler extends Handler { |
| 516 | public static final int EVENT_POSITION_UPDATE = 1; |
| 517 | public static final int EVENT_MESSAGE_TRANSFER_STATE_UPDATE = 2; |
| 518 | |
| 519 | private final ISatellitePositionUpdateCallback mCallback; |
| 520 | |
| 521 | SatellitePositionUpdateHandler(ISatellitePositionUpdateCallback callback, Looper looper) { |
| 522 | super(looper); |
| 523 | mCallback = callback; |
| 524 | } |
| 525 | |
| 526 | @Override |
| 527 | public void handleMessage(@NonNull Message msg) { |
| 528 | switch (msg.what) { |
| 529 | case EVENT_POSITION_UPDATE: { |
| 530 | AsyncResult ar = (AsyncResult) msg.obj; |
| 531 | PointingInfo pointingInfo = (PointingInfo) ar.result; |
| 532 | try { |
| 533 | mCallback.onSatellitePositionUpdate(pointingInfo); |
| 534 | } catch (RemoteException e) { |
| 535 | loge("EVENT_POSITION_UPDATE RemoteException: " + e); |
| 536 | } |
| 537 | break; |
| 538 | } |
| 539 | case EVENT_MESSAGE_TRANSFER_STATE_UPDATE: { |
| 540 | AsyncResult ar = (AsyncResult) msg.obj; |
| 541 | int state = (int) ar.result; |
| 542 | try { |
| 543 | mCallback.onMessageTransferStateUpdate(state); |
| 544 | } catch (RemoteException e) { |
| 545 | loge("EVENT_MESSAGE_TRANSFER_STATE_UPDATE RemoteException: " + e); |
| 546 | } |
| 547 | break; |
| 548 | } |
| 549 | default: |
| 550 | loge("SatellitePositionUpdateHandler unknown event: " + msg.what); |
| 551 | } |
| 552 | } |
| 553 | } |
| 554 | |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 555 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 556 | * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the |
| 557 | * request after sending. The main thread will notify the request when it is complete. |
| 558 | */ |
| 559 | private static final class MainThreadRequest { |
| 560 | /** The argument to use for the request */ |
| 561 | public Object argument; |
| 562 | /** The result of the request that is run on the main thread */ |
| 563 | public Object result; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 564 | // The subscriber id that this request applies to. Defaults to |
| 565 | // SubscriptionManager.INVALID_SUBSCRIPTION_ID |
| 566 | public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 567 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 568 | // In cases where subId is unavailable, the caller needs to specify the phone. |
| 569 | public Phone phone; |
| 570 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 571 | public WorkSource workSource; |
| 572 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 573 | public MainThreadRequest(Object argument) { |
| 574 | this.argument = argument; |
| 575 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 576 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 577 | MainThreadRequest(Object argument, Phone phone, WorkSource workSource) { |
| 578 | this.argument = argument; |
| 579 | if (phone != null) { |
| 580 | this.phone = phone; |
| 581 | } |
| 582 | this.workSource = workSource; |
| 583 | } |
| 584 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 585 | MainThreadRequest(Object argument, Integer subId, WorkSource workSource) { |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 586 | this.argument = argument; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 587 | if (subId != null) { |
| 588 | this.subId = subId; |
| 589 | } |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 590 | this.workSource = workSource; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 591 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 592 | } |
| 593 | |
Sailesh Nepal | cc0375f | 2013-11-13 09:15:18 -0800 | [diff] [blame] | 594 | private static final class IncomingThirdPartyCallArgs { |
| 595 | public final ComponentName component; |
| 596 | public final String callId; |
| 597 | public final String callerDisplayName; |
| 598 | |
| 599 | public IncomingThirdPartyCallArgs(ComponentName component, String callId, |
| 600 | String callerDisplayName) { |
| 601 | this.component = component; |
| 602 | this.callId = callId; |
| 603 | this.callerDisplayName = callerDisplayName; |
| 604 | } |
| 605 | } |
| 606 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 607 | /** |
| 608 | * A handler that processes messages on the main thread in the phone process. Since many |
| 609 | * of the Phone calls are not thread safe this is needed to shuttle the requests from the |
| 610 | * inbound binder threads to the main thread in the phone process. The Binder thread |
| 611 | * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting |
| 612 | * on, which will be notified when the operation completes and will contain the result of the |
| 613 | * request. |
| 614 | * |
| 615 | * <p>If a MainThreadRequest object is provided in the msg.obj field, |
| 616 | * note that request.result must be set to something non-null for the calling thread to |
| 617 | * unblock. |
| 618 | */ |
| 619 | private final class MainThreadHandler extends Handler { |
| 620 | @Override |
| 621 | public void handleMessage(Message msg) { |
| 622 | MainThreadRequest request; |
| 623 | Message onCompleted; |
| 624 | AsyncResult ar; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 625 | UiccPort uiccPort; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 626 | IccAPDUArgument iccArgument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 627 | final Phone defaultPhone = getDefaultPhone(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 628 | |
| 629 | switch (msg.what) { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 630 | case CMD_HANDLE_USSD_REQUEST: { |
| 631 | request = (MainThreadRequest) msg.obj; |
| 632 | final Phone phone = getPhoneFromRequest(request); |
| 633 | Pair<String, ResultReceiver> ussdObject = (Pair) request.argument; |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 634 | String ussdRequest = ussdObject.first; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 635 | ResultReceiver wrappedCallback = ussdObject.second; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 636 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 637 | if (!isUssdApiAllowed(request.subId)) { |
| 638 | // Carrier does not support use of this API, return failure. |
| 639 | Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis."); |
| 640 | UssdResponse response = new UssdResponse(ussdRequest, null); |
| 641 | Bundle returnData = new Bundle(); |
| 642 | returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response); |
| 643 | wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 644 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 645 | request.result = true; |
| 646 | notifyRequester(request); |
| 647 | return; |
| 648 | } |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 649 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 650 | try { |
| 651 | request.result = phone != null |
| 652 | ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false; |
| 653 | } catch (CallStateException cse) { |
| 654 | request.result = false; |
| 655 | } |
| 656 | // Wake up the requesting thread |
| 657 | notifyRequester(request); |
| 658 | break; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 659 | } |
| 660 | |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 661 | case CMD_HANDLE_PIN_MMI: { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 662 | request = (MainThreadRequest) msg.obj; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 663 | final Phone phone = getPhoneFromRequest(request); |
| 664 | request.result = phone != null ? |
| 665 | getPhoneFromRequest(request).handlePinMmi((String) request.argument) |
| 666 | : false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 667 | // Wake up the requesting thread |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 668 | notifyRequester(request); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 669 | break; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 670 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 671 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 672 | case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 673 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 674 | iccArgument = (IccAPDUArgument) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 675 | uiccPort = getUiccPortFromRequest(request); |
| 676 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 677 | loge("iccTransmitApduLogicalChannel: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 678 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 679 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 680 | } else { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 681 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE, |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 682 | request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 683 | uiccPort.iccTransmitApduLogicalChannel( |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 684 | iccArgument.channel, iccArgument.cla, iccArgument.command, |
| 685 | iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data, |
| 686 | onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 687 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 688 | break; |
| 689 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 690 | case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 691 | ar = (AsyncResult) msg.obj; |
| 692 | request = (MainThreadRequest) ar.userObj; |
| 693 | if (ar.exception == null && ar.result != null) { |
| 694 | request.result = ar.result; |
| 695 | } else { |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 696 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 697 | if (ar.result == null) { |
| 698 | loge("iccTransmitApduLogicalChannel: Empty response"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 699 | } else if (ar.exception instanceof CommandException) { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 700 | loge("iccTransmitApduLogicalChannel: CommandException: " + |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 701 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 702 | } else { |
| 703 | loge("iccTransmitApduLogicalChannel: Unknown exception"); |
| 704 | } |
| 705 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 706 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 707 | break; |
| 708 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 709 | case CMD_TRANSMIT_APDU_BASIC_CHANNEL: |
| 710 | request = (MainThreadRequest) msg.obj; |
| 711 | iccArgument = (IccAPDUArgument) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 712 | uiccPort = getUiccPortFromRequest(request); |
| 713 | if (uiccPort == null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 714 | loge("iccTransmitApduBasicChannel: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 715 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 716 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 717 | } else { |
| 718 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE, |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 719 | request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 720 | uiccPort.iccTransmitApduBasicChannel( |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 721 | iccArgument.cla, iccArgument.command, iccArgument.p1, |
| 722 | iccArgument.p2, |
| 723 | iccArgument.p3, iccArgument.data, onCompleted); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 724 | } |
| 725 | break; |
| 726 | |
| 727 | case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE: |
| 728 | ar = (AsyncResult) msg.obj; |
| 729 | request = (MainThreadRequest) ar.userObj; |
| 730 | if (ar.exception == null && ar.result != null) { |
| 731 | request.result = ar.result; |
| 732 | } else { |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 733 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 734 | if (ar.result == null) { |
| 735 | loge("iccTransmitApduBasicChannel: Empty response"); |
| 736 | } else if (ar.exception instanceof CommandException) { |
| 737 | loge("iccTransmitApduBasicChannel: CommandException: " + |
| 738 | ar.exception); |
| 739 | } else { |
| 740 | loge("iccTransmitApduBasicChannel: Unknown exception"); |
| 741 | } |
| 742 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 743 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 744 | break; |
| 745 | |
| 746 | case CMD_EXCHANGE_SIM_IO: |
| 747 | request = (MainThreadRequest) msg.obj; |
| 748 | iccArgument = (IccAPDUArgument) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 749 | uiccPort = getUiccPortFromRequest(request); |
| 750 | if (uiccPort == null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 751 | loge("iccExchangeSimIO: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 752 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 753 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 754 | } else { |
| 755 | onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE, |
| 756 | request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 757 | uiccPort.iccExchangeSimIO(iccArgument.cla, /* fileID */ |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 758 | iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3, |
| 759 | iccArgument.data, onCompleted); |
| 760 | } |
| 761 | break; |
| 762 | |
| 763 | case EVENT_EXCHANGE_SIM_IO_DONE: |
| 764 | ar = (AsyncResult) msg.obj; |
| 765 | request = (MainThreadRequest) ar.userObj; |
| 766 | if (ar.exception == null && ar.result != null) { |
| 767 | request.result = ar.result; |
| 768 | } else { |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 769 | request.result = new IccIoResult(0x6f, 0, (byte[]) null); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 770 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 771 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 772 | break; |
| 773 | |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 774 | case CMD_SEND_ENVELOPE: |
| 775 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 776 | uiccPort = getUiccPortFromRequest(request); |
| 777 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 778 | loge("sendEnvelopeWithStatus: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 779 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 780 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 781 | } else { |
| 782 | onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 783 | uiccPort.sendEnvelopeWithStatus((String) request.argument, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 784 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 785 | break; |
| 786 | |
| 787 | case EVENT_SEND_ENVELOPE_DONE: |
| 788 | ar = (AsyncResult) msg.obj; |
| 789 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 790 | if (ar.exception == null && ar.result != null) { |
| 791 | request.result = ar.result; |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 792 | } else { |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 793 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 794 | if (ar.result == null) { |
| 795 | loge("sendEnvelopeWithStatus: Empty response"); |
| 796 | } else if (ar.exception instanceof CommandException) { |
| 797 | loge("sendEnvelopeWithStatus: CommandException: " + |
| 798 | ar.exception); |
| 799 | } else { |
| 800 | loge("sendEnvelopeWithStatus: exception:" + ar.exception); |
| 801 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 802 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 803 | notifyRequester(request); |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 804 | break; |
| 805 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 806 | case CMD_OPEN_CHANNEL: |
| 807 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 808 | uiccPort = getUiccPortFromRequest(request); |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 809 | IccLogicalChannelRequest openChannelRequest = |
| 810 | (IccLogicalChannelRequest) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 811 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 812 | loge("iccOpenLogicalChannel: No UICC"); |
Shishir Agrawal | fc0492a | 2016-02-17 11:15:33 -0800 | [diff] [blame] | 813 | request.result = new IccOpenLogicalChannelResponse(-1, |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 814 | IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 815 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 816 | } else { |
| 817 | onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request); |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 818 | uiccPort.iccOpenLogicalChannel(openChannelRequest.aid, |
| 819 | openChannelRequest.p2, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 820 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 821 | break; |
| 822 | |
| 823 | case EVENT_OPEN_CHANNEL_DONE: |
| 824 | ar = (AsyncResult) msg.obj; |
| 825 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 826 | IccOpenLogicalChannelResponse openChannelResp; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 827 | if (ar.exception == null && ar.result != null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 828 | int[] result = (int[]) ar.result; |
| 829 | int channelId = result[0]; |
| 830 | byte[] selectResponse = null; |
| 831 | if (result.length > 1) { |
| 832 | selectResponse = new byte[result.length - 1]; |
| 833 | for (int i = 1; i < result.length; ++i) { |
| 834 | selectResponse[i - 1] = (byte) result[i]; |
| 835 | } |
| 836 | } |
| 837 | openChannelResp = new IccOpenLogicalChannelResponse(channelId, |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 838 | IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse); |
Rambo Wang | 3b77c4c | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 839 | |
| 840 | uiccPort = getUiccPortFromRequest(request); |
Rambo Wang | e53e07d | 2022-05-10 13:01:13 -0700 | [diff] [blame] | 841 | if (uiccPort == null) { |
| 842 | loge("EVENT_OPEN_CHANNEL_DONE: UiccPort is null"); |
| 843 | } else { |
| 844 | IccLogicalChannelRequest channelRequest = |
| 845 | (IccLogicalChannelRequest) request.argument; |
| 846 | channelRequest.channel = channelId; |
| 847 | uiccPort.onLogicalChannelOpened(channelRequest); |
| 848 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 849 | } else { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 850 | if (ar.result == null) { |
| 851 | loge("iccOpenLogicalChannel: Empty response"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 852 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 853 | if (ar.exception != null) { |
| 854 | loge("iccOpenLogicalChannel: Exception: " + ar.exception); |
| 855 | } |
| 856 | |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 857 | int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 858 | if (ar.exception instanceof CommandException) { |
| 859 | CommandException.Error error = |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 860 | ((CommandException) (ar.exception)).getCommandError(); |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 861 | if (error == CommandException.Error.MISSING_RESOURCE) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 862 | errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 863 | } else if (error == CommandException.Error.NO_SUCH_ELEMENT) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 864 | errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 865 | } |
| 866 | } |
| 867 | openChannelResp = new IccOpenLogicalChannelResponse( |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 868 | IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 869 | } |
Shishir Agrawal | 82c8a46 | 2014-07-31 18:13:17 -0700 | [diff] [blame] | 870 | request.result = openChannelResp; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 871 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 872 | break; |
| 873 | |
| 874 | case CMD_CLOSE_CHANNEL: |
| 875 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 876 | uiccPort = getUiccPortFromRequest(request); |
| 877 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 878 | loge("iccCloseLogicalChannel: No UICC"); |
Chen Xu | a8f0dff | 2022-02-12 00:34:15 -0800 | [diff] [blame] | 879 | request.result = new IllegalArgumentException( |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 880 | "iccCloseLogicalChannel: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 881 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 882 | } else { |
| 883 | onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 884 | uiccPort.iccCloseLogicalChannel((Integer) request.argument, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 885 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 886 | break; |
| 887 | |
| 888 | case EVENT_CLOSE_CHANNEL_DONE: |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 889 | ar = (AsyncResult) msg.obj; |
| 890 | request = (MainThreadRequest) ar.userObj; |
| 891 | if (ar.exception == null) { |
| 892 | request.result = true; |
Rambo Wang | 3b77c4c | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 893 | uiccPort = getUiccPortFromRequest(request); |
Rambo Wang | e53e07d | 2022-05-10 13:01:13 -0700 | [diff] [blame] | 894 | if (uiccPort == null) { |
| 895 | loge("EVENT_CLOSE_CHANNEL_DONE: UiccPort is null"); |
| 896 | } else { |
| 897 | final int channelId = (Integer) request.argument; |
| 898 | uiccPort.onLogicalChannelClosed(channelId); |
| 899 | } |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 900 | } else { |
| 901 | request.result = false; |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 902 | Exception exception = null; |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 903 | if (ar.exception instanceof CommandException) { |
| 904 | loge("iccCloseLogicalChannel: CommandException: " + ar.exception); |
| 905 | CommandException.Error error = |
| 906 | ((CommandException) (ar.exception)).getCommandError(); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 907 | if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 908 | // should only throw exceptions from the binder threads. |
| 909 | exception = new IllegalArgumentException( |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 910 | "iccCloseLogicalChannel: invalid argument "); |
| 911 | } |
| 912 | } else { |
| 913 | loge("iccCloseLogicalChannel: Unknown exception"); |
| 914 | } |
Chen Xu | a8f0dff | 2022-02-12 00:34:15 -0800 | [diff] [blame] | 915 | request.result = (exception != null) ? exception : |
| 916 | new IllegalStateException( |
| 917 | "exception from modem to close iccLogical Channel"); |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 918 | } |
| 919 | notifyRequester(request); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 920 | break; |
| 921 | |
| 922 | case CMD_NV_READ_ITEM: |
| 923 | request = (MainThreadRequest) msg.obj; |
| 924 | onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 925 | defaultPhone.nvReadItem((Integer) request.argument, onCompleted, |
| 926 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 927 | break; |
| 928 | |
| 929 | case EVENT_NV_READ_ITEM_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 930 | ar = (AsyncResult) msg.obj; |
| 931 | request = (MainThreadRequest) ar.userObj; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 932 | if (ar.exception == null && ar.result != null) { |
| 933 | request.result = ar.result; // String |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 934 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 935 | request.result = ""; |
| 936 | if (ar.result == null) { |
| 937 | loge("nvReadItem: Empty response"); |
| 938 | } else if (ar.exception instanceof CommandException) { |
| 939 | loge("nvReadItem: CommandException: " + |
| 940 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 941 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 942 | loge("nvReadItem: Unknown exception"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 943 | } |
| 944 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 945 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 946 | break; |
| 947 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 948 | case CMD_NV_WRITE_ITEM: |
| 949 | request = (MainThreadRequest) msg.obj; |
| 950 | onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request); |
| 951 | Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 952 | defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 953 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 954 | break; |
| 955 | |
| 956 | case EVENT_NV_WRITE_ITEM_DONE: |
| 957 | handleNullReturnEvent(msg, "nvWriteItem"); |
| 958 | break; |
| 959 | |
| 960 | case CMD_NV_WRITE_CDMA_PRL: |
| 961 | request = (MainThreadRequest) msg.obj; |
| 962 | onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 963 | defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 964 | break; |
| 965 | |
| 966 | case EVENT_NV_WRITE_CDMA_PRL_DONE: |
| 967 | handleNullReturnEvent(msg, "nvWriteCdmaPrl"); |
| 968 | break; |
| 969 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 970 | case CMD_RESET_MODEM_CONFIG: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 971 | request = (MainThreadRequest) msg.obj; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 972 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 973 | defaultPhone.resetModemConfig(onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 974 | break; |
| 975 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 976 | case EVENT_RESET_MODEM_CONFIG_DONE: |
| 977 | handleNullReturnEvent(msg, "resetModemConfig"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 978 | break; |
| 979 | |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 980 | case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: { |
| 981 | request = (MainThreadRequest) msg.obj; |
| 982 | onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE, |
| 983 | request); |
| 984 | Phone phone = getPhoneFromRequest(request); |
| 985 | if (phone != null) { |
| 986 | phone.isNrDualConnectivityEnabled(onCompleted, request.workSource); |
| 987 | } else { |
| 988 | loge("isNRDualConnectivityEnabled: No phone object"); |
| 989 | request.result = false; |
| 990 | notifyRequester(request); |
| 991 | } |
| 992 | break; |
| 993 | } |
| 994 | |
| 995 | case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE: |
| 996 | ar = (AsyncResult) msg.obj; |
| 997 | request = (MainThreadRequest) ar.userObj; |
| 998 | if (ar.exception == null && ar.result != null) { |
| 999 | request.result = ar.result; |
| 1000 | } else { |
| 1001 | // request.result must be set to something non-null |
| 1002 | // for the calling thread to unblock |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 1003 | if (ar.result != null) { |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 1004 | request.result = ar.result; |
| 1005 | } else { |
| 1006 | request.result = false; |
| 1007 | } |
| 1008 | if (ar.result == null) { |
| 1009 | loge("isNRDualConnectivityEnabled: Empty response"); |
| 1010 | } else if (ar.exception instanceof CommandException) { |
| 1011 | loge("isNRDualConnectivityEnabled: CommandException: " |
| 1012 | + ar.exception); |
| 1013 | } else { |
| 1014 | loge("isNRDualConnectivityEnabled: Unknown exception"); |
| 1015 | } |
| 1016 | } |
| 1017 | notifyRequester(request); |
| 1018 | break; |
| 1019 | |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 1020 | case CMD_IS_VONR_ENABLED: { |
| 1021 | request = (MainThreadRequest) msg.obj; |
| 1022 | onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE, |
| 1023 | request); |
| 1024 | Phone phone = getPhoneFromRequest(request); |
| 1025 | if (phone != null) { |
| 1026 | phone.isVoNrEnabled(onCompleted, request.workSource); |
| 1027 | } else { |
| 1028 | loge("isVoNrEnabled: No phone object"); |
| 1029 | request.result = false; |
| 1030 | notifyRequester(request); |
| 1031 | } |
| 1032 | break; |
| 1033 | } |
| 1034 | |
| 1035 | case EVENT_IS_VONR_ENABLED_DONE: |
| 1036 | ar = (AsyncResult) msg.obj; |
| 1037 | request = (MainThreadRequest) ar.userObj; |
| 1038 | if (ar.exception == null && ar.result != null) { |
| 1039 | request.result = ar.result; |
| 1040 | } else { |
| 1041 | // request.result must be set to something non-null |
| 1042 | // for the calling thread to unblock |
| 1043 | if (ar.result != null) { |
| 1044 | request.result = ar.result; |
| 1045 | } else { |
| 1046 | request.result = false; |
| 1047 | } |
| 1048 | if (ar.result == null) { |
| 1049 | loge("isVoNrEnabled: Empty response"); |
| 1050 | } else if (ar.exception instanceof CommandException) { |
| 1051 | loge("isVoNrEnabled: CommandException: " |
| 1052 | + ar.exception); |
| 1053 | } else { |
| 1054 | loge("isVoNrEnabled: Unknown exception"); |
| 1055 | } |
| 1056 | } |
| 1057 | notifyRequester(request); |
| 1058 | break; |
| 1059 | |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 1060 | case CMD_ENABLE_NR_DUAL_CONNECTIVITY: { |
| 1061 | request = (MainThreadRequest) msg.obj; |
| 1062 | onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request); |
| 1063 | Phone phone = getPhoneFromRequest(request); |
| 1064 | if (phone != null) { |
| 1065 | phone.setNrDualConnectivityState((int) request.argument, onCompleted, |
| 1066 | request.workSource); |
| 1067 | } else { |
| 1068 | loge("enableNrDualConnectivity: No phone object"); |
| 1069 | request.result = |
| 1070 | TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE; |
| 1071 | notifyRequester(request); |
| 1072 | } |
| 1073 | break; |
| 1074 | } |
| 1075 | |
| 1076 | case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: { |
| 1077 | ar = (AsyncResult) msg.obj; |
| 1078 | request = (MainThreadRequest) ar.userObj; |
| 1079 | if (ar.exception == null) { |
| 1080 | request.result = |
| 1081 | TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS; |
| 1082 | } else { |
| 1083 | request.result = |
| 1084 | TelephonyManager |
| 1085 | .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR; |
| 1086 | if (ar.exception instanceof CommandException) { |
| 1087 | CommandException.Error error = |
| 1088 | ((CommandException) (ar.exception)).getCommandError(); |
| 1089 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1090 | request.result = |
| 1091 | TelephonyManager |
| 1092 | .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE; |
Sooraj Sasindran | 2965416 | 2021-03-03 23:00:01 +0000 | [diff] [blame] | 1093 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1094 | request.result = |
| 1095 | TelephonyManager |
| 1096 | .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED; |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 1097 | } |
| 1098 | loge("enableNrDualConnectivity" + ": CommandException: " |
| 1099 | + ar.exception); |
| 1100 | } else { |
| 1101 | loge("enableNrDualConnectivity" + ": Unknown exception"); |
| 1102 | } |
| 1103 | } |
| 1104 | notifyRequester(request); |
| 1105 | break; |
| 1106 | } |
| 1107 | |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 1108 | case CMD_ENABLE_VONR: { |
| 1109 | request = (MainThreadRequest) msg.obj; |
| 1110 | onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request); |
| 1111 | Phone phone = getPhoneFromRequest(request); |
| 1112 | if (phone != null) { |
| 1113 | phone.setVoNrEnabled((boolean) request.argument, onCompleted, |
| 1114 | request.workSource); |
| 1115 | } else { |
| 1116 | loge("setVoNrEnabled: No phone object"); |
| 1117 | request.result = |
| 1118 | TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE; |
| 1119 | notifyRequester(request); |
| 1120 | } |
| 1121 | break; |
| 1122 | } |
| 1123 | |
| 1124 | case EVENT_ENABLE_VONR_DONE: { |
| 1125 | ar = (AsyncResult) msg.obj; |
| 1126 | request = (MainThreadRequest) ar.userObj; |
| 1127 | if (ar.exception == null) { |
| 1128 | request.result = TelephonyManager.ENABLE_VONR_SUCCESS; |
| 1129 | } else { |
| 1130 | request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR; |
| 1131 | if (ar.exception instanceof CommandException) { |
| 1132 | CommandException.Error error = |
| 1133 | ((CommandException) (ar.exception)).getCommandError(); |
| 1134 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1135 | request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE; |
| 1136 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1137 | request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED; |
| 1138 | } else { |
| 1139 | request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR; |
| 1140 | } |
| 1141 | loge("setVoNrEnabled" + ": CommandException: " |
| 1142 | + ar.exception); |
| 1143 | } else { |
| 1144 | loge("setVoNrEnabled" + ": Unknown exception"); |
| 1145 | } |
| 1146 | } |
| 1147 | notifyRequester(request); |
| 1148 | break; |
| 1149 | } |
| 1150 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1151 | case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1152 | request = (MainThreadRequest) msg.obj; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1153 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE, |
| 1154 | request); |
| 1155 | getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1156 | break; |
| 1157 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1158 | case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1159 | ar = (AsyncResult) msg.obj; |
| 1160 | request = (MainThreadRequest) ar.userObj; |
| 1161 | if (ar.exception == null && ar.result != null) { |
| 1162 | request.result = ar.result; // Integer |
| 1163 | } else { |
Nazish Tabassum | e8ba43a | 2020-07-28 14:49:25 +0530 | [diff] [blame] | 1164 | // request.result must be set to something non-null |
| 1165 | // for the calling thread to unblock |
| 1166 | request.result = new int[]{-1}; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1167 | if (ar.result == null) { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1168 | loge("getAllowedNetworkTypesBitmask: Empty response"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1169 | } else if (ar.exception instanceof CommandException) { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1170 | loge("getAllowedNetworkTypesBitmask: CommandException: " |
| 1171 | + ar.exception); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1172 | } else { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1173 | loge("getAllowedNetworkTypesBitmask: Unknown exception"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1174 | } |
| 1175 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1176 | notifyRequester(request); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1177 | break; |
| 1178 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1179 | case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1180 | request = (MainThreadRequest) msg.obj; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1181 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE, |
| 1182 | request); |
| 1183 | Pair<Integer, Long> reasonWithNetworkTypes = |
| 1184 | (Pair<Integer, Long>) request.argument; |
| 1185 | getPhoneFromRequest(request).setAllowedNetworkTypes( |
| 1186 | reasonWithNetworkTypes.first, |
| 1187 | reasonWithNetworkTypes.second, |
| 1188 | onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1189 | break; |
| 1190 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1191 | case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE: |
| 1192 | handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1193 | break; |
| 1194 | |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 1195 | case CMD_INVOKE_OEM_RIL_REQUEST_RAW: |
| 1196 | request = (MainThreadRequest)msg.obj; |
| 1197 | onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1198 | defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 1199 | break; |
| 1200 | |
| 1201 | case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE: |
| 1202 | ar = (AsyncResult)msg.obj; |
| 1203 | request = (MainThreadRequest)ar.userObj; |
| 1204 | request.result = ar; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1205 | notifyRequester(request); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 1206 | break; |
| 1207 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1208 | case CMD_SET_VOICEMAIL_NUMBER: |
| 1209 | request = (MainThreadRequest) msg.obj; |
| 1210 | onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request); |
| 1211 | Pair<String, String> tagNum = (Pair<String, String>) request.argument; |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1212 | getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second, |
| 1213 | onCompleted); |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1214 | break; |
| 1215 | |
| 1216 | case EVENT_SET_VOICEMAIL_NUMBER_DONE: |
| 1217 | handleNullReturnEvent(msg, "setVoicemailNumber"); |
| 1218 | break; |
| 1219 | |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 1220 | case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC: |
| 1221 | request = (MainThreadRequest) msg.obj; |
| 1222 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE, |
| 1223 | request); |
| 1224 | getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted); |
| 1225 | break; |
| 1226 | |
| 1227 | case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE: |
| 1228 | handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic"); |
| 1229 | break; |
| 1230 | |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1231 | case CMD_PERFORM_NETWORK_SCAN: |
| 1232 | request = (MainThreadRequest) msg.obj; |
| 1233 | onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request); |
| 1234 | getPhoneFromRequest(request).getAvailableNetworks(onCompleted); |
| 1235 | break; |
| 1236 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1237 | case CMD_GET_CALL_FORWARDING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1238 | request = (MainThreadRequest) msg.obj; |
| 1239 | onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1240 | Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args = |
| 1241 | (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>) |
| 1242 | request.argument; |
| 1243 | int callForwardingReason = args.first; |
| 1244 | request.phone.getCallForwardingOption(callForwardingReason, onCompleted); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1245 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1246 | } |
| 1247 | case EVENT_GET_CALL_FORWARDING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1248 | ar = (AsyncResult) msg.obj; |
| 1249 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1250 | TelephonyManager.CallForwardingInfoCallback callback = |
| 1251 | ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>) |
| 1252 | request.argument).second; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1253 | if (ar.exception == null && ar.result != null) { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1254 | CallForwardingInfo callForwardingInfo = null; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1255 | CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result; |
| 1256 | for (CallForwardInfo callForwardInfo : callForwardInfos) { |
| 1257 | // Service Class is a bit mask per 3gpp 27.007. Search for |
| 1258 | // any service for voice call. |
| 1259 | if ((callForwardInfo.serviceClass |
| 1260 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0) { |
Yuchen Dong | 69cc141 | 2021-09-27 20:27:01 +0800 | [diff] [blame] | 1261 | callForwardingInfo = new CallForwardingInfo( |
| 1262 | callForwardInfo.status |
| 1263 | == CommandsInterface.CF_ACTION_ENABLE, |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1264 | callForwardInfo.reason, |
| 1265 | callForwardInfo.number, |
| 1266 | callForwardInfo.timeSeconds); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1267 | break; |
| 1268 | } |
| 1269 | } |
| 1270 | // Didn't find a call forward info for voice call. |
| 1271 | if (callForwardingInfo == null) { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1272 | callForwardingInfo = new CallForwardingInfo(false /* enabled */, |
| 1273 | 0 /* reason */, null /* number */, 0 /* timeout */); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1274 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1275 | callback.onCallForwardingInfoAvailable(callForwardingInfo); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1276 | } else { |
| 1277 | if (ar.result == null) { |
| 1278 | loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response"); |
| 1279 | } |
| 1280 | if (ar.exception != null) { |
| 1281 | loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception); |
| 1282 | } |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1283 | int errorCode = TelephonyManager |
| 1284 | .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1285 | if (ar.exception instanceof CommandException) { |
| 1286 | CommandException.Error error = |
| 1287 | ((CommandException) (ar.exception)).getCommandError(); |
| 1288 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1289 | errorCode = TelephonyManager |
| 1290 | .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1291 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1292 | errorCode = TelephonyManager |
| 1293 | .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1294 | } |
| 1295 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1296 | callback.onError(errorCode); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1297 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1298 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1299 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1300 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1301 | case CMD_SET_CALL_FORWARDING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1302 | request = (MainThreadRequest) msg.obj; |
| 1303 | onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1304 | request = (MainThreadRequest) msg.obj; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1305 | CallForwardingInfo callForwardingInfoToSet = |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1306 | ((Pair<CallForwardingInfo, Consumer<Integer>>) |
| 1307 | request.argument).first; |
| 1308 | request.phone.setCallForwardingOption( |
| 1309 | callForwardingInfoToSet.isEnabled() |
Calvin Pan | 258f1f7 | 2021-07-28 21:46:56 +0800 | [diff] [blame] | 1310 | ? CommandsInterface.CF_ACTION_REGISTRATION |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1311 | : CommandsInterface.CF_ACTION_DISABLE, |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1312 | callForwardingInfoToSet.getReason(), |
| 1313 | callForwardingInfoToSet.getNumber(), |
| 1314 | callForwardingInfoToSet.getTimeoutSeconds(), onCompleted); |
| 1315 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1316 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1317 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1318 | case EVENT_SET_CALL_FORWARDING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1319 | ar = (AsyncResult) msg.obj; |
| 1320 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1321 | Consumer<Integer> callback = |
| 1322 | ((Pair<CallForwardingInfo, Consumer<Integer>>) |
| 1323 | request.argument).second; |
| 1324 | if (ar.exception != null) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1325 | loge("setCallForwarding exception: " + ar.exception); |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1326 | int errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1327 | .RESULT_ERROR_UNKNOWN; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1328 | if (ar.exception instanceof CommandException) { |
| 1329 | CommandException.Error error = |
| 1330 | ((CommandException) (ar.exception)).getCommandError(); |
| 1331 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1332 | errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1333 | .RESULT_ERROR_FDN_CHECK_FAILURE; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1334 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1335 | errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1336 | .RESULT_ERROR_NOT_SUPPORTED; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1337 | } |
| 1338 | } |
| 1339 | callback.accept(errorCode); |
| 1340 | } else { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1341 | callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1342 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1343 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1344 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1345 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1346 | case CMD_GET_CALL_WAITING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1347 | request = (MainThreadRequest) msg.obj; |
| 1348 | onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request); |
| 1349 | getPhoneFromRequest(request).getCallWaiting(onCompleted); |
| 1350 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1351 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1352 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1353 | case EVENT_GET_CALL_WAITING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1354 | ar = (AsyncResult) msg.obj; |
| 1355 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1356 | Consumer<Integer> callback = (Consumer<Integer>) request.argument; |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1357 | int callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1358 | if (ar.exception == null && ar.result != null) { |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1359 | int[] callForwardResults = (int[]) ar.result; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1360 | // Service Class is a bit mask per 3gpp 27.007. |
| 1361 | // Search for any service for voice call. |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1362 | if (callForwardResults.length > 1 |
| 1363 | && ((callForwardResults[1] |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1364 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) { |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1365 | callWaitingStatus = callForwardResults[0] == 0 |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1366 | ? TelephonyManager.CALL_WAITING_STATUS_DISABLED |
| 1367 | : TelephonyManager.CALL_WAITING_STATUS_ENABLED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1368 | } else { |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1369 | callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1370 | } |
| 1371 | } else { |
| 1372 | if (ar.result == null) { |
| 1373 | loge("EVENT_GET_CALL_WAITING_DONE: Empty response"); |
| 1374 | } |
| 1375 | if (ar.exception != null) { |
| 1376 | loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception); |
| 1377 | } |
| 1378 | if (ar.exception instanceof CommandException) { |
| 1379 | CommandException.Error error = |
| 1380 | ((CommandException) (ar.exception)).getCommandError(); |
| 1381 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1382 | callWaitingStatus = |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1383 | TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED; |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1384 | } else if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
| 1385 | callWaitingStatus = |
| 1386 | TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1387 | } |
| 1388 | } |
| 1389 | } |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1390 | callback.accept(callWaitingStatus); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1391 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1392 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1393 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1394 | case CMD_SET_CALL_WAITING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1395 | request = (MainThreadRequest) msg.obj; |
| 1396 | onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1397 | boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first; |
| 1398 | getPhoneFromRequest(request).setCallWaiting(enable, onCompleted); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1399 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1400 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1401 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1402 | case EVENT_SET_CALL_WAITING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1403 | ar = (AsyncResult) msg.obj; |
| 1404 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1405 | boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first; |
| 1406 | Consumer<Integer> callback = |
| 1407 | ((Pair<Boolean, Consumer<Integer>>) request.argument).second; |
| 1408 | if (ar.exception != null) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1409 | loge("setCallWaiting exception: " + ar.exception); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1410 | if (ar.exception instanceof CommandException) { |
| 1411 | CommandException.Error error = |
| 1412 | ((CommandException) (ar.exception)).getCommandError(); |
| 1413 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1414 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED); |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1415 | } else if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
| 1416 | callback.accept( |
| 1417 | TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1418 | } else { |
| 1419 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 1420 | } |
| 1421 | } else { |
| 1422 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 1423 | } |
| 1424 | } else { |
| 1425 | callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED |
| 1426 | : TelephonyManager.CALL_WAITING_STATUS_DISABLED); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1427 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1428 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1429 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1430 | case EVENT_PERFORM_NETWORK_SCAN_DONE: |
| 1431 | ar = (AsyncResult) msg.obj; |
| 1432 | request = (MainThreadRequest) ar.userObj; |
| 1433 | CellNetworkScanResult cellScanResult; |
| 1434 | if (ar.exception == null && ar.result != null) { |
| 1435 | cellScanResult = new CellNetworkScanResult( |
| 1436 | CellNetworkScanResult.STATUS_SUCCESS, |
| 1437 | (List<OperatorInfo>) ar.result); |
| 1438 | } else { |
| 1439 | if (ar.result == null) { |
| 1440 | loge("getCellNetworkScanResults: Empty response"); |
| 1441 | } |
| 1442 | if (ar.exception != null) { |
| 1443 | loge("getCellNetworkScanResults: Exception: " + ar.exception); |
| 1444 | } |
| 1445 | int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR; |
| 1446 | if (ar.exception instanceof CommandException) { |
| 1447 | CommandException.Error error = |
| 1448 | ((CommandException) (ar.exception)).getCommandError(); |
| 1449 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1450 | errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE; |
| 1451 | } else if (error == CommandException.Error.GENERIC_FAILURE) { |
| 1452 | errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE; |
| 1453 | } |
| 1454 | } |
| 1455 | cellScanResult = new CellNetworkScanResult(errorCode, null); |
| 1456 | } |
| 1457 | request.result = cellScanResult; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1458 | notifyRequester(request); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1459 | break; |
| 1460 | |
| 1461 | case CMD_SET_NETWORK_SELECTION_MODE_MANUAL: |
| 1462 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1463 | ManualNetworkSelectionArgument selArg = |
| 1464 | (ManualNetworkSelectionArgument) request.argument; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1465 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE, |
| 1466 | request); |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1467 | getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo, |
| 1468 | selArg.persistSelection, onCompleted); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1469 | break; |
| 1470 | |
| 1471 | case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE: |
Pengquan Meng | e3d01e2 | 2018-09-20 15:25:35 -0700 | [diff] [blame] | 1472 | ar = (AsyncResult) msg.obj; |
| 1473 | request = (MainThreadRequest) ar.userObj; |
| 1474 | if (ar.exception == null) { |
| 1475 | request.result = true; |
| 1476 | } else { |
| 1477 | request.result = false; |
| 1478 | loge("setNetworkSelectionModeManual " + ar.exception); |
| 1479 | } |
| 1480 | notifyRequester(request); |
| 1481 | mApp.onNetworkSelectionChanged(request.subId); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1482 | break; |
| 1483 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1484 | case CMD_GET_MODEM_ACTIVITY_INFO: |
| 1485 | request = (MainThreadRequest) msg.obj; |
| 1486 | onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1487 | if (defaultPhone != null) { |
| 1488 | defaultPhone.getModemActivityInfo(onCompleted, request.workSource); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1489 | } else { |
| 1490 | ResultReceiver result = (ResultReceiver) request.argument; |
| 1491 | Bundle bundle = new Bundle(); |
| 1492 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 1493 | new ModemActivityInfo(0, 0, 0, |
| 1494 | new int[ModemActivityInfo.getNumTxPowerLevels()], 0)); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1495 | result.send(0, bundle); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1496 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1497 | break; |
| 1498 | |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1499 | case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: { |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1500 | ar = (AsyncResult) msg.obj; |
| 1501 | request = (MainThreadRequest) ar.userObj; |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1502 | ResultReceiver result = (ResultReceiver) request.argument; |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1503 | int error = 0; |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 1504 | ModemActivityInfo ret = null; |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1505 | if (mLastModemActivityInfo == null) { |
| 1506 | mLastModemActivitySpecificInfo = new ActivityStatsTechSpecificInfo[1]; |
| 1507 | mLastModemActivitySpecificInfo[0] = |
| 1508 | new ActivityStatsTechSpecificInfo( |
| 1509 | 0, |
| 1510 | 0, |
| 1511 | new int[ModemActivityInfo.getNumTxPowerLevels()], |
| 1512 | 0); |
| 1513 | mLastModemActivityInfo = |
| 1514 | new ModemActivityInfo(0, 0, 0, mLastModemActivitySpecificInfo); |
| 1515 | } |
| 1516 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1517 | if (ar.exception == null && ar.result != null) { |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1518 | // Update the last modem activity info and the result of the request. |
| 1519 | ModemActivityInfo info = (ModemActivityInfo) ar.result; |
| 1520 | if (isModemActivityInfoValid(info)) { |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1521 | mergeModemActivityInfo(info); |
Gary Jian | 76280a4 | 2022-12-07 16:18:33 +0800 | [diff] [blame] | 1522 | } else { |
| 1523 | loge("queryModemActivityInfo: invalid response"); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1524 | } |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 1525 | // This is needed to decouple ret from mLastModemActivityInfo |
| 1526 | // We don't want to return mLastModemActivityInfo which is updated |
| 1527 | // inside mergeModemActivityInfo() |
| 1528 | ret = new ModemActivityInfo( |
| 1529 | mLastModemActivityInfo.getTimestampMillis(), |
| 1530 | mLastModemActivityInfo.getSleepTimeMillis(), |
| 1531 | mLastModemActivityInfo.getIdleTimeMillis(), |
| 1532 | deepCopyModemActivitySpecificInfo(mLastModemActivitySpecificInfo)); |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1533 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1534 | } else { |
| 1535 | if (ar.result == null) { |
| 1536 | loge("queryModemActivityInfo: Empty response"); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1537 | error = TelephonyManager.ModemActivityInfoException |
| 1538 | .ERROR_INVALID_INFO_RECEIVED; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1539 | } else if (ar.exception instanceof CommandException) { |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1540 | loge("queryModemActivityInfo: CommandException: " + ar.exception); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1541 | error = TelephonyManager.ModemActivityInfoException |
| 1542 | .ERROR_MODEM_RESPONSE_ERROR; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1543 | } else { |
| 1544 | loge("queryModemActivityInfo: Unknown exception"); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1545 | error = TelephonyManager.ModemActivityInfoException |
| 1546 | .ERROR_UNKNOWN; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1547 | } |
| 1548 | } |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1549 | Bundle bundle = new Bundle(); |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 1550 | if (ret != null) { |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1551 | bundle.putParcelable( |
| 1552 | TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 1553 | ret); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1554 | } else { |
| 1555 | bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error); |
| 1556 | } |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1557 | result.send(0, bundle); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1558 | notifyRequester(request); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1559 | break; |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1560 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1561 | |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1562 | case CMD_SET_ALLOWED_CARRIERS: |
| 1563 | request = (MainThreadRequest) msg.obj; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1564 | CarrierRestrictionRules argument = |
| 1565 | (CarrierRestrictionRules) request.argument; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1566 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request); |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1567 | defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1568 | break; |
| 1569 | |
| 1570 | case EVENT_SET_ALLOWED_CARRIERS_DONE: |
| 1571 | ar = (AsyncResult) msg.obj; |
| 1572 | request = (MainThreadRequest) ar.userObj; |
| 1573 | if (ar.exception == null && ar.result != null) { |
| 1574 | request.result = ar.result; |
| 1575 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1576 | request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR; |
| 1577 | if (ar.exception instanceof CommandException) { |
| 1578 | loge("setAllowedCarriers: CommandException: " + ar.exception); |
| 1579 | CommandException.Error error = |
| 1580 | ((CommandException) (ar.exception)).getCommandError(); |
| 1581 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1582 | request.result = |
| 1583 | TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED; |
| 1584 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1585 | } else { |
| 1586 | loge("setAllowedCarriers: Unknown exception"); |
| 1587 | } |
| 1588 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1589 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1590 | break; |
| 1591 | |
| 1592 | case CMD_GET_ALLOWED_CARRIERS: |
| 1593 | request = (MainThreadRequest) msg.obj; |
| 1594 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1595 | defaultPhone.getAllowedCarriers(onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1596 | break; |
| 1597 | |
| 1598 | case EVENT_GET_ALLOWED_CARRIERS_DONE: |
| 1599 | ar = (AsyncResult) msg.obj; |
| 1600 | request = (MainThreadRequest) ar.userObj; |
| 1601 | if (ar.exception == null && ar.result != null) { |
| 1602 | request.result = ar.result; |
| 1603 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1604 | request.result = new IllegalStateException( |
| 1605 | "Failed to get carrier restrictions"); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1606 | if (ar.result == null) { |
| 1607 | loge("getAllowedCarriers: Empty response"); |
| 1608 | } else if (ar.exception instanceof CommandException) { |
| 1609 | loge("getAllowedCarriers: CommandException: " + |
| 1610 | ar.exception); |
| 1611 | } else { |
| 1612 | loge("getAllowedCarriers: Unknown exception"); |
| 1613 | } |
| 1614 | } |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 1615 | if (request.argument != null) { |
| 1616 | // This is for the implementation of carrierRestrictionStatus. |
| 1617 | CallerCallbackInfo callbackInfo = (CallerCallbackInfo) request.argument; |
| 1618 | Consumer<Integer> callback = callbackInfo.getConsumer(); |
| 1619 | int callerCarrierId = callbackInfo.getCarrierId(); |
| 1620 | int lockStatus = TelephonyManager.CARRIER_RESTRICTION_STATUS_UNKNOWN; |
| 1621 | if (ar.exception == null && ar.result instanceof CarrierRestrictionRules) { |
| 1622 | CarrierRestrictionRules carrierRestrictionRules = |
| 1623 | (CarrierRestrictionRules) ar.result; |
| 1624 | int carrierId = -1; |
| 1625 | try { |
| 1626 | CarrierIdentifier carrierIdentifier = |
| 1627 | carrierRestrictionRules.getAllowedCarriers().get(0); |
| 1628 | carrierId = CarrierResolver.getCarrierIdFromIdentifier(mApp, |
| 1629 | carrierIdentifier); |
| 1630 | } catch (NullPointerException | IndexOutOfBoundsException ex) { |
| 1631 | Rlog.e(LOG_TAG, "CarrierIdentifier exception = " + ex); |
| 1632 | } |
| 1633 | lockStatus = carrierRestrictionRules.getCarrierRestrictionStatus(); |
| 1634 | if (carrierId != -1 && callerCarrierId == carrierId && lockStatus |
| 1635 | == TelephonyManager.CARRIER_RESTRICTION_STATUS_RESTRICTED) { |
| 1636 | lockStatus = |
| 1637 | TelephonyManager.CARRIER_RESTRICTION_STATUS_RESTRICTED_TO_CALLER; |
| 1638 | } |
| 1639 | } else { |
| 1640 | Rlog.e(LOG_TAG, |
| 1641 | "getCarrierRestrictionStatus: exception ex = " + ar.exception); |
| 1642 | } |
| 1643 | callback.accept(lockStatus); |
| 1644 | } else { |
| 1645 | // This is for the implementation of getAllowedCarriers. |
| 1646 | notifyRequester(request); |
| 1647 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1648 | break; |
| 1649 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1650 | case EVENT_GET_FORBIDDEN_PLMNS_DONE: |
| 1651 | ar = (AsyncResult) msg.obj; |
| 1652 | request = (MainThreadRequest) ar.userObj; |
| 1653 | if (ar.exception == null && ar.result != null) { |
| 1654 | request.result = ar.result; |
| 1655 | } else { |
| 1656 | request.result = new IllegalArgumentException( |
| 1657 | "Failed to retrieve Forbidden Plmns"); |
| 1658 | if (ar.result == null) { |
| 1659 | loge("getForbiddenPlmns: Empty response"); |
| 1660 | } else { |
| 1661 | loge("getForbiddenPlmns: Unknown exception"); |
| 1662 | } |
| 1663 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1664 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1665 | break; |
| 1666 | |
| 1667 | case CMD_GET_FORBIDDEN_PLMNS: |
| 1668 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1669 | uiccPort = getUiccPortFromRequest(request); |
| 1670 | if (uiccPort == null) { |
| 1671 | loge("getForbiddenPlmns() UiccPort is null"); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1672 | request.result = new IllegalArgumentException( |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1673 | "getForbiddenPlmns() UiccPort is null"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1674 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1675 | break; |
| 1676 | } |
| 1677 | Integer appType = (Integer) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1678 | UiccCardApplication uiccApp = uiccPort.getApplicationByType(appType); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1679 | if (uiccApp == null) { |
| 1680 | loge("getForbiddenPlmns() no app with specified type -- " |
| 1681 | + appType); |
| 1682 | request.result = new IllegalArgumentException("Failed to get UICC App"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1683 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1684 | break; |
| 1685 | } else { |
| 1686 | if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid() |
| 1687 | + " specified type -- " + appType); |
| 1688 | } |
| 1689 | onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request); |
| 1690 | ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns( |
| 1691 | onCompleted); |
| 1692 | break; |
| 1693 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1694 | case CMD_SWITCH_SLOTS: |
| 1695 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 1696 | List<UiccSlotMapping> slotMapping = (List<UiccSlotMapping>) request.argument; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1697 | onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 1698 | UiccController.getInstance().switchSlots(slotMapping, onCompleted); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1699 | break; |
| 1700 | |
| 1701 | case EVENT_SWITCH_SLOTS_DONE: |
| 1702 | ar = (AsyncResult) msg.obj; |
| 1703 | request = (MainThreadRequest) ar.userObj; |
| 1704 | request.result = (ar.exception == null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1705 | notifyRequester(request); |
| 1706 | break; |
| 1707 | case CMD_GET_NETWORK_SELECTION_MODE: |
| 1708 | request = (MainThreadRequest) msg.obj; |
| 1709 | onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request); |
| 1710 | getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted); |
| 1711 | break; |
| 1712 | |
| 1713 | case EVENT_GET_NETWORK_SELECTION_MODE_DONE: |
| 1714 | ar = (AsyncResult) msg.obj; |
| 1715 | request = (MainThreadRequest) ar.userObj; |
| 1716 | if (ar.exception != null) { |
| 1717 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 1718 | } else { |
| 1719 | int mode = ((int[]) ar.result)[0]; |
| 1720 | if (mode == 0) { |
| 1721 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO; |
| 1722 | } else { |
| 1723 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL; |
| 1724 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1725 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1726 | notifyRequester(request); |
| 1727 | break; |
| 1728 | case CMD_GET_CDMA_ROAMING_MODE: |
| 1729 | request = (MainThreadRequest) msg.obj; |
| 1730 | onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request); |
| 1731 | getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted); |
| 1732 | break; |
| 1733 | case EVENT_GET_CDMA_ROAMING_MODE_DONE: |
| 1734 | ar = (AsyncResult) msg.obj; |
| 1735 | request = (MainThreadRequest) ar.userObj; |
| 1736 | if (ar.exception != null) { |
| 1737 | request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT; |
| 1738 | } else { |
| 1739 | request.result = ((int[]) ar.result)[0]; |
| 1740 | } |
| 1741 | notifyRequester(request); |
| 1742 | break; |
| 1743 | case CMD_SET_CDMA_ROAMING_MODE: |
| 1744 | request = (MainThreadRequest) msg.obj; |
| 1745 | onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request); |
| 1746 | int mode = (int) request.argument; |
| 1747 | getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted); |
| 1748 | break; |
| 1749 | case EVENT_SET_CDMA_ROAMING_MODE_DONE: |
| 1750 | ar = (AsyncResult) msg.obj; |
| 1751 | request = (MainThreadRequest) ar.userObj; |
| 1752 | request.result = ar.exception == null; |
| 1753 | notifyRequester(request); |
| 1754 | break; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 1755 | case CMD_GET_CDMA_SUBSCRIPTION_MODE: |
| 1756 | request = (MainThreadRequest) msg.obj; |
| 1757 | onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1758 | getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted); |
| 1759 | break; |
| 1760 | case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1761 | ar = (AsyncResult) msg.obj; |
| 1762 | request = (MainThreadRequest) ar.userObj; |
| 1763 | if (ar.exception != null) { |
| 1764 | request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM; |
| 1765 | } else { |
| 1766 | request.result = ((int[]) ar.result)[0]; |
| 1767 | } |
| 1768 | notifyRequester(request); |
| 1769 | break; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1770 | case CMD_SET_CDMA_SUBSCRIPTION_MODE: |
| 1771 | request = (MainThreadRequest) msg.obj; |
| 1772 | onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1773 | int subscriptionMode = (int) request.argument; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 1774 | getPhoneFromRequest(request).setCdmaSubscriptionMode( |
| 1775 | subscriptionMode, onCompleted); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1776 | break; |
| 1777 | case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1778 | ar = (AsyncResult) msg.obj; |
| 1779 | request = (MainThreadRequest) ar.userObj; |
| 1780 | request.result = ar.exception == null; |
| 1781 | notifyRequester(request); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1782 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1783 | case CMD_GET_ALL_CELL_INFO: |
| 1784 | request = (MainThreadRequest) msg.obj; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1785 | onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1786 | request.phone.requestCellInfoUpdate(request.workSource, onCompleted); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1787 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1788 | case EVENT_GET_ALL_CELL_INFO_DONE: |
| 1789 | ar = (AsyncResult) msg.obj; |
| 1790 | request = (MainThreadRequest) ar.userObj; |
Nathan Harold | 8d0f174 | 2018-10-02 12:14:47 -0700 | [diff] [blame] | 1791 | // If a timeout occurs, the response will be null |
| 1792 | request.result = (ar.exception == null && ar.result != null) |
| 1793 | ? ar.result : new ArrayList<CellInfo>(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1794 | synchronized (request) { |
| 1795 | request.notifyAll(); |
| 1796 | } |
| 1797 | break; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1798 | case CMD_REQUEST_CELL_INFO_UPDATE: |
| 1799 | request = (MainThreadRequest) msg.obj; |
| 1800 | request.phone.requestCellInfoUpdate(request.workSource, |
| 1801 | obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request)); |
| 1802 | break; |
| 1803 | case EVENT_REQUEST_CELL_INFO_UPDATE_DONE: |
| 1804 | ar = (AsyncResult) msg.obj; |
| 1805 | request = (MainThreadRequest) ar.userObj; |
| 1806 | ICellInfoCallback cb = (ICellInfoCallback) request.argument; |
| 1807 | try { |
| 1808 | if (ar.exception != null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1809 | Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception); |
Meng Wang | d8921f4 | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1810 | cb.onError( |
| 1811 | TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR, |
| 1812 | ar.exception.getClass().getName(), |
| 1813 | ar.exception.toString()); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1814 | } else if (ar.result == null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1815 | Log.w(LOG_TAG, "Timeout Waiting for CellInfo!"); |
Meng Wang | d8921f4 | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1816 | cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1817 | } else { |
| 1818 | // use the result as returned |
| 1819 | cb.onCellInfo((List<CellInfo>) ar.result); |
| 1820 | } |
| 1821 | } catch (RemoteException re) { |
| 1822 | Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException"); |
| 1823 | } |
| 1824 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1825 | case CMD_GET_CELL_LOCATION: { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1826 | request = (MainThreadRequest) msg.obj; |
| 1827 | WorkSource ws = (WorkSource) request.argument; |
| 1828 | Phone phone = getPhoneFromRequest(request); |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1829 | phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request)); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1830 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1831 | } |
| 1832 | case EVENT_GET_CELL_LOCATION_DONE: { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1833 | ar = (AsyncResult) msg.obj; |
| 1834 | request = (MainThreadRequest) ar.userObj; |
| 1835 | if (ar.exception == null) { |
| 1836 | request.result = ar.result; |
| 1837 | } else { |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1838 | Phone phone = getPhoneFromRequest(request); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1839 | request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1840 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1841 | } |
| 1842 | |
| 1843 | synchronized (request) { |
| 1844 | request.notifyAll(); |
| 1845 | } |
| 1846 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1847 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1848 | case CMD_MODEM_REBOOT: |
| 1849 | request = (MainThreadRequest) msg.obj; |
| 1850 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1851 | defaultPhone.rebootModem(onCompleted); |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1852 | break; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1853 | case EVENT_CMD_MODEM_REBOOT_DONE: |
| 1854 | handleNullReturnEvent(msg, "rebootModem"); |
| 1855 | break; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1856 | case CMD_REQUEST_ENABLE_MODEM: |
| 1857 | request = (MainThreadRequest) msg.obj; |
| 1858 | boolean enable = (boolean) request.argument; |
| 1859 | onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1860 | onCompleted.arg1 = enable ? 1 : 0; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1861 | PhoneConfigurationManager.getInstance() |
| 1862 | .enablePhone(request.phone, enable, onCompleted); |
| 1863 | break; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1864 | case EVENT_ENABLE_MODEM_DONE: { |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1865 | ar = (AsyncResult) msg.obj; |
| 1866 | request = (MainThreadRequest) ar.userObj; |
| 1867 | request.result = (ar.exception == null); |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1868 | int phoneId = request.phone.getPhoneId(); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1869 | //update the cache as modem status has changed |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1870 | if ((boolean) request.result) { |
| 1871 | mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1); |
| 1872 | updateModemStateMetrics(); |
| 1873 | } else { |
| 1874 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1875 | + ar.exception); |
| 1876 | } |
| 1877 | notifyRequester(request); |
| 1878 | break; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1879 | } |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1880 | case CMD_GET_MODEM_STATUS: |
| 1881 | request = (MainThreadRequest) msg.obj; |
| 1882 | onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request); |
| 1883 | PhoneConfigurationManager.getInstance() |
| 1884 | .getPhoneStatusFromModem(request.phone, onCompleted); |
| 1885 | break; |
| 1886 | case EVENT_GET_MODEM_STATUS_DONE: |
| 1887 | ar = (AsyncResult) msg.obj; |
| 1888 | request = (MainThreadRequest) ar.userObj; |
| 1889 | int id = request.phone.getPhoneId(); |
| 1890 | if (ar.exception == null && ar.result != null) { |
| 1891 | request.result = ar.result; |
| 1892 | //update the cache as modem status has changed |
| 1893 | mPhoneConfigurationManager.addToPhoneStatusCache(id, |
| 1894 | (boolean) request.result); |
| 1895 | } else { |
| 1896 | // Return true if modem status cannot be retrieved. For most cases, |
| 1897 | // modem status is on. And for older version modems, GET_MODEM_STATUS |
| 1898 | // and disable modem are not supported. Modem is always on. |
| 1899 | // TODO: this should be fixed in R to support a third |
| 1900 | // status UNKNOWN b/131631629 |
| 1901 | request.result = true; |
| 1902 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1903 | + ar.exception); |
| 1904 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1905 | notifyRequester(request); |
| 1906 | break; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 1907 | case CMD_SET_SYSTEM_SELECTION_CHANNELS: { |
| 1908 | request = (MainThreadRequest) msg.obj; |
| 1909 | onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request); |
| 1910 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 1911 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 1912 | request.phone.setSystemSelectionChannels(args.first, onCompleted); |
| 1913 | break; |
| 1914 | } |
| 1915 | case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: { |
| 1916 | ar = (AsyncResult) msg.obj; |
| 1917 | request = (MainThreadRequest) ar.userObj; |
| 1918 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 1919 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 1920 | args.second.accept(ar.exception == null); |
| 1921 | notifyRequester(request); |
| 1922 | break; |
| 1923 | } |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1924 | case CMD_GET_SYSTEM_SELECTION_CHANNELS: { |
| 1925 | request = (MainThreadRequest) msg.obj; |
| 1926 | onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request); |
| 1927 | Phone phone = getPhoneFromRequest(request); |
| 1928 | if (phone != null) { |
| 1929 | phone.getSystemSelectionChannels(onCompleted); |
| 1930 | } else { |
| 1931 | loge("getSystemSelectionChannels: No phone object"); |
| 1932 | request.result = new ArrayList<RadioAccessSpecifier>(); |
| 1933 | notifyRequester(request); |
| 1934 | } |
| 1935 | break; |
| 1936 | } |
| 1937 | case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE: |
| 1938 | ar = (AsyncResult) msg.obj; |
| 1939 | request = (MainThreadRequest) ar.userObj; |
| 1940 | if (ar.exception == null && ar.result != null) { |
| 1941 | request.result = ar.result; |
| 1942 | } else { |
Sarah Chin | 428d1d6 | 2021-03-13 03:17:40 -0800 | [diff] [blame] | 1943 | request.result = new IllegalStateException( |
| 1944 | "Failed to retrieve system selecton channels"); |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1945 | if (ar.result == null) { |
| 1946 | loge("getSystemSelectionChannels: Empty response"); |
| 1947 | } else { |
| 1948 | loge("getSystemSelectionChannels: Unknown exception"); |
| 1949 | } |
| 1950 | } |
| 1951 | notifyRequester(request); |
| 1952 | break; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1953 | case EVENT_SET_FORBIDDEN_PLMNS_DONE: |
| 1954 | ar = (AsyncResult) msg.obj; |
| 1955 | request = (MainThreadRequest) ar.userObj; |
| 1956 | if (ar.exception == null && ar.result != null) { |
| 1957 | request.result = ar.result; |
| 1958 | } else { |
| 1959 | request.result = -1; |
| 1960 | loge("Failed to set Forbidden Plmns"); |
| 1961 | if (ar.result == null) { |
| 1962 | loge("setForbidenPlmns: Empty response"); |
| 1963 | } else if (ar.exception != null) { |
| 1964 | loge("setForbiddenPlmns: Exception: " + ar.exception); |
| 1965 | request.result = -1; |
| 1966 | } else { |
| 1967 | loge("setForbiddenPlmns: Unknown exception"); |
| 1968 | } |
| 1969 | } |
| 1970 | notifyRequester(request); |
| 1971 | break; |
| 1972 | case CMD_SET_FORBIDDEN_PLMNS: |
| 1973 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1974 | uiccPort = getUiccPortFromRequest(request); |
| 1975 | if (uiccPort == null) { |
| 1976 | loge("setForbiddenPlmns: UiccPort is null"); |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1977 | request.result = -1; |
| 1978 | notifyRequester(request); |
| 1979 | break; |
| 1980 | } |
| 1981 | Pair<Integer, List<String>> setFplmnsArgs = |
| 1982 | (Pair<Integer, List<String>>) request.argument; |
| 1983 | appType = setFplmnsArgs.first; |
| 1984 | List<String> fplmns = setFplmnsArgs.second; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1985 | uiccApp = uiccPort.getApplicationByType(appType); |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1986 | if (uiccApp == null) { |
| 1987 | loge("setForbiddenPlmns: no app with specified type -- " + appType); |
| 1988 | request.result = -1; |
| 1989 | loge("Failed to get UICC App"); |
| 1990 | notifyRequester(request); |
| 1991 | } else { |
| 1992 | onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request); |
| 1993 | ((SIMRecords) uiccApp.getIccRecords()) |
| 1994 | .setForbiddenPlmns(onCompleted, fplmns); |
| 1995 | } |
yinchengzhao | 4d163c0 | 2019-12-12 15:21:47 -0800 | [diff] [blame] | 1996 | break; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 1997 | case CMD_ERASE_MODEM_CONFIG: |
| 1998 | request = (MainThreadRequest) msg.obj; |
| 1999 | onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request); |
| 2000 | defaultPhone.eraseModemConfig(onCompleted); |
| 2001 | break; |
| 2002 | case EVENT_ERASE_MODEM_CONFIG_DONE: |
| 2003 | handleNullReturnEvent(msg, "eraseModemConfig"); |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 2004 | break; |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 2005 | |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 2006 | case CMD_ERASE_DATA_SHARED_PREFERENCES: |
| 2007 | request = (MainThreadRequest) msg.obj; |
| 2008 | request.result = defaultPhone.eraseDataInSharedPreferences(); |
| 2009 | notifyRequester(request); |
| 2010 | break; |
| 2011 | |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 2012 | case CMD_CHANGE_ICC_LOCK_PASSWORD: |
| 2013 | request = (MainThreadRequest) msg.obj; |
| 2014 | onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request); |
| 2015 | Pair<String, String> changed = (Pair<String, String>) request.argument; |
| 2016 | getPhoneFromRequest(request).getIccCard().changeIccLockPassword( |
| 2017 | changed.first, changed.second, onCompleted); |
| 2018 | break; |
| 2019 | case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE: |
| 2020 | ar = (AsyncResult) msg.obj; |
| 2021 | request = (MainThreadRequest) ar.userObj; |
| 2022 | if (ar.exception == null) { |
| 2023 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2024 | // If the operation is successful, update the PIN storage |
| 2025 | Pair<String, String> passwords = (Pair<String, String>) request.argument; |
| 2026 | int phoneId = getPhoneFromRequest(request).getPhoneId(); |
Jon Spivack | 9c3bc76 | 2021-10-06 20:53:09 +0000 | [diff] [blame] | 2027 | UiccController.getInstance().getPinStorage() |
| 2028 | .storePin(passwords.second, phoneId); |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 2029 | } else { |
| 2030 | request.result = msg.arg1; |
| 2031 | } |
| 2032 | notifyRequester(request); |
| 2033 | break; |
| 2034 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2035 | case CMD_SET_ICC_LOCK_ENABLED: { |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 2036 | request = (MainThreadRequest) msg.obj; |
| 2037 | onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request); |
| 2038 | Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument; |
| 2039 | getPhoneFromRequest(request).getIccCard().setIccLockEnabled( |
| 2040 | enabled.first, enabled.second, onCompleted); |
| 2041 | break; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2042 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 2043 | case EVENT_SET_ICC_LOCK_ENABLED_DONE: |
| 2044 | ar = (AsyncResult) msg.obj; |
| 2045 | request = (MainThreadRequest) ar.userObj; |
| 2046 | if (ar.exception == null) { |
| 2047 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2048 | // If the operation is successful, update the PIN storage |
| 2049 | Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument; |
| 2050 | int phoneId = getPhoneFromRequest(request).getPhoneId(); |
| 2051 | if (enabled.first) { |
Jon Spivack | 9c3bc76 | 2021-10-06 20:53:09 +0000 | [diff] [blame] | 2052 | UiccController.getInstance().getPinStorage() |
| 2053 | .storePin(enabled.second, phoneId); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2054 | } else { |
| 2055 | UiccController.getInstance().getPinStorage().clearPin(phoneId); |
| 2056 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 2057 | } else { |
| 2058 | request.result = msg.arg1; |
| 2059 | } |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2060 | |
| 2061 | |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 2062 | notifyRequester(request); |
| 2063 | break; |
| 2064 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 2065 | case MSG_NOTIFY_USER_ACTIVITY: |
| 2066 | removeMessages(MSG_NOTIFY_USER_ACTIVITY); |
Peter Wang | 59571be | 2020-01-27 12:35:15 +0800 | [diff] [blame] | 2067 | Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION); |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 2068 | intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY); |
| 2069 | getDefaultPhone().getContext().sendBroadcastAsUser( |
| 2070 | intent, UserHandle.ALL, permission.USER_ACTIVITY); |
| 2071 | break; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 2072 | |
| 2073 | case CMD_SET_DATA_THROTTLING: { |
| 2074 | request = (MainThreadRequest) msg.obj; |
| 2075 | onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request); |
| 2076 | DataThrottlingRequest dataThrottlingRequest = |
| 2077 | (DataThrottlingRequest) request.argument; |
| 2078 | Phone phone = getPhoneFromRequest(request); |
| 2079 | if (phone != null) { |
| 2080 | phone.setDataThrottling(onCompleted, |
| 2081 | request.workSource, dataThrottlingRequest.getDataThrottlingAction(), |
| 2082 | dataThrottlingRequest.getCompletionDurationMillis()); |
| 2083 | } else { |
| 2084 | loge("setDataThrottling: No phone object"); |
| 2085 | request.result = |
| 2086 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 2087 | notifyRequester(request); |
| 2088 | } |
| 2089 | |
| 2090 | break; |
| 2091 | } |
| 2092 | case EVENT_SET_DATA_THROTTLING_DONE: |
| 2093 | ar = (AsyncResult) msg.obj; |
| 2094 | request = (MainThreadRequest) ar.userObj; |
| 2095 | |
| 2096 | if (ar.exception == null) { |
| 2097 | request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 2098 | } else if (ar.exception instanceof CommandException) { |
| 2099 | loge("setDataThrottling: CommandException: " + ar.exception); |
| 2100 | CommandException.Error error = |
| 2101 | ((CommandException) (ar.exception)).getCommandError(); |
| 2102 | |
| 2103 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 2104 | request.result = TelephonyManager |
| 2105 | .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 2106 | } else if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 2107 | request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS; |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 2108 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 2109 | request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 2110 | } else { |
| 2111 | request.result = |
| 2112 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 2113 | } |
| 2114 | } else { |
| 2115 | request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 2116 | } |
| 2117 | Log.w(LOG_TAG, "DataThrottlingResult = " + request.result); |
| 2118 | notifyRequester(request); |
| 2119 | break; |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 2120 | |
| 2121 | case CMD_SET_SIM_POWER: { |
| 2122 | request = (MainThreadRequest) msg.obj; |
| 2123 | onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request); |
| 2124 | request = (MainThreadRequest) msg.obj; |
| 2125 | int stateToSet = |
| 2126 | ((Pair<Integer, IIntegerConsumer>) |
| 2127 | request.argument).first; |
| 2128 | request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource); |
| 2129 | break; |
| 2130 | } |
| 2131 | case EVENT_SET_SIM_POWER_DONE: { |
| 2132 | ar = (AsyncResult) msg.obj; |
| 2133 | request = (MainThreadRequest) ar.userObj; |
| 2134 | IIntegerConsumer callback = |
| 2135 | ((Pair<Integer, IIntegerConsumer>) request.argument).second; |
| 2136 | if (ar.exception != null) { |
| 2137 | loge("setSimPower exception: " + ar.exception); |
| 2138 | int errorCode = TelephonyManager.CallForwardingInfoCallback |
| 2139 | .RESULT_ERROR_UNKNOWN; |
| 2140 | if (ar.exception instanceof CommandException) { |
| 2141 | CommandException.Error error = |
| 2142 | ((CommandException) (ar.exception)).getCommandError(); |
| 2143 | if (error == CommandException.Error.SIM_ERR) { |
| 2144 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR; |
| 2145 | } else if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 2146 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE; |
| 2147 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 2148 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED; |
| 2149 | } else { |
| 2150 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR; |
| 2151 | } |
| 2152 | } |
| 2153 | try { |
| 2154 | callback.accept(errorCode); |
| 2155 | } catch (RemoteException e) { |
| 2156 | // Ignore if the remote process is no longer available to call back. |
| 2157 | Log.w(LOG_TAG, "setSimPower: callback not available."); |
| 2158 | } |
| 2159 | } else { |
| 2160 | try { |
| 2161 | callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS); |
| 2162 | } catch (RemoteException e) { |
| 2163 | // Ignore if the remote process is no longer available to call back. |
| 2164 | Log.w(LOG_TAG, "setSimPower: callback not available."); |
| 2165 | } |
| 2166 | } |
| 2167 | break; |
| 2168 | } |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 2169 | case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: { |
| 2170 | request = (MainThreadRequest) msg.obj; |
| 2171 | |
| 2172 | final Phone phone = getPhoneFromRequest(request); |
| 2173 | if (phone == null || phone.getServiceStateTracker() == null) { |
| 2174 | request.result = new IllegalStateException("Phone or SST is null"); |
| 2175 | notifyRequester(request); |
| 2176 | break; |
| 2177 | } |
| 2178 | |
| 2179 | Pair<Integer, SignalStrengthUpdateRequest> pair = |
| 2180 | (Pair<Integer, SignalStrengthUpdateRequest>) request.argument; |
| 2181 | onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE, |
| 2182 | request); |
Rambo Wang | 6568f17 | 2021-02-03 16:56:47 -0800 | [diff] [blame] | 2183 | phone.getSignalStrengthController().setSignalStrengthUpdateRequest( |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 2184 | request.subId, pair.first /*callingUid*/, |
| 2185 | pair.second /*request*/, onCompleted); |
| 2186 | break; |
| 2187 | } |
| 2188 | case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: { |
| 2189 | ar = (AsyncResult) msg.obj; |
| 2190 | request = (MainThreadRequest) ar.userObj; |
| 2191 | // request.result will be the exception of ar if present, true otherwise. |
| 2192 | // Be cautious not to leave result null which will wait() forever |
| 2193 | request.result = ar.exception != null ? ar.exception : true; |
| 2194 | notifyRequester(request); |
| 2195 | break; |
| 2196 | } |
| 2197 | case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: { |
| 2198 | request = (MainThreadRequest) msg.obj; |
| 2199 | |
| 2200 | Phone phone = getPhoneFromRequest(request); |
| 2201 | if (phone == null || phone.getServiceStateTracker() == null) { |
| 2202 | request.result = new IllegalStateException("Phone or SST is null"); |
| 2203 | notifyRequester(request); |
| 2204 | break; |
| 2205 | } |
| 2206 | |
| 2207 | Pair<Integer, SignalStrengthUpdateRequest> pair = |
| 2208 | (Pair<Integer, SignalStrengthUpdateRequest>) request.argument; |
| 2209 | onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE, |
| 2210 | request); |
Rambo Wang | 6568f17 | 2021-02-03 16:56:47 -0800 | [diff] [blame] | 2211 | phone.getSignalStrengthController().clearSignalStrengthUpdateRequest( |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 2212 | request.subId, pair.first /*callingUid*/, |
| 2213 | pair.second /*request*/, onCompleted); |
| 2214 | break; |
| 2215 | } |
| 2216 | case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: { |
| 2217 | ar = (AsyncResult) msg.obj; |
| 2218 | request = (MainThreadRequest) ar.userObj; |
| 2219 | request.result = ar.exception != null ? ar.exception : true; |
| 2220 | notifyRequester(request); |
| 2221 | break; |
| 2222 | } |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 2223 | |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2224 | case CMD_GET_SLICING_CONFIG: { |
| 2225 | request = (MainThreadRequest) msg.obj; |
| 2226 | onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request); |
| 2227 | request.phone.getSlicingConfig(onCompleted); |
| 2228 | break; |
| 2229 | } |
| 2230 | case EVENT_GET_SLICING_CONFIG_DONE: { |
| 2231 | ar = (AsyncResult) msg.obj; |
| 2232 | request = (MainThreadRequest) ar.userObj; |
| 2233 | ResultReceiver result = (ResultReceiver) request.argument; |
| 2234 | |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2235 | NetworkSlicingConfig slicingConfig = null; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2236 | Bundle bundle = new Bundle(); |
| 2237 | int resultCode = 0; |
| 2238 | if (ar.exception != null) { |
| 2239 | Log.e(LOG_TAG, "Exception retrieving slicing configuration=" |
| 2240 | + ar.exception); |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2241 | resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2242 | } else if (ar.result == null) { |
| 2243 | Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!"); |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2244 | resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2245 | } else { |
| 2246 | // use the result as returned |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2247 | resultCode = TelephonyManager.NetworkSlicingException.SUCCESS; |
| 2248 | slicingConfig = (NetworkSlicingConfig) ar.result; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2249 | } |
| 2250 | |
| 2251 | if (slicingConfig == null) { |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2252 | slicingConfig = new NetworkSlicingConfig(); |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2253 | } |
| 2254 | bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig); |
| 2255 | result.send(resultCode, bundle); |
| 2256 | notifyRequester(request); |
| 2257 | break; |
| 2258 | } |
| 2259 | |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2260 | case CMD_PURCHASE_PREMIUM_CAPABILITY: { |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2261 | request = (MainThreadRequest) msg.obj; |
| 2262 | onCompleted = obtainMessage(EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE, request); |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2263 | PurchasePremiumCapabilityArgument arg = |
| 2264 | (PurchasePremiumCapabilityArgument) request.argument; |
Sarah Chin | 46355ba | 2022-11-01 23:51:16 -0700 | [diff] [blame] | 2265 | SlicePurchaseController.getInstance(request.phone).purchasePremiumCapability( |
Sarah Chin | b8218c2 | 2023-01-04 13:35:29 -0800 | [diff] [blame] | 2266 | arg.capability, onCompleted); |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2267 | break; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2268 | } |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2269 | |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2270 | case EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE: { |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2271 | ar = (AsyncResult) msg.obj; |
| 2272 | request = (MainThreadRequest) ar.userObj; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2273 | PurchasePremiumCapabilityArgument arg = |
| 2274 | (PurchasePremiumCapabilityArgument) request.argument; |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2275 | try { |
| 2276 | int result = (int) ar.result; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2277 | arg.callback.accept(result); |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2278 | log("purchasePremiumCapability: capability=" |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2279 | + TelephonyManager.convertPremiumCapabilityToString(arg.capability) |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2280 | + ", result= " |
| 2281 | + TelephonyManager.convertPurchaseResultToString(result)); |
| 2282 | } catch (RemoteException e) { |
| 2283 | String logStr = "Purchase premium capability " |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2284 | + TelephonyManager.convertPremiumCapabilityToString(arg.capability) |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2285 | + " failed: " + e; |
| 2286 | if (DBG) log(logStr); |
| 2287 | AnomalyReporter.reportAnomaly( |
| 2288 | UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr); |
| 2289 | } |
| 2290 | break; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2291 | } |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2292 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2293 | case CMD_PREPARE_UNATTENDED_REBOOT: |
| 2294 | request = (MainThreadRequest) msg.obj; |
| 2295 | request.result = |
Rafael Higuera Silva | d963064 | 2021-09-20 15:32:01 +0000 | [diff] [blame] | 2296 | UiccController.getInstance().getPinStorage() |
| 2297 | .prepareUnattendedReboot(request.workSource); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2298 | notifyRequester(request); |
| 2299 | break; |
| 2300 | |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 2301 | case CMD_START_SATELLITE_POSITION_UPDATES: { |
| 2302 | request = (MainThreadRequest) msg.obj; |
| 2303 | onCompleted = |
| 2304 | obtainMessage(EVENT_START_SATELLITE_POSITION_UPDATES_DONE, request); |
| 2305 | Phone phone = getPhoneFromRequest(request); |
| 2306 | if (phone != null) { |
| 2307 | phone.startSatellitePositionUpdates(onCompleted); |
| 2308 | } else { |
| 2309 | loge("startSatellitePositionUpdates: No phone object"); |
| 2310 | request.result = SatelliteManager.SATELLITE_SERVICE_REQUEST_FAILED; |
| 2311 | notifyRequester(request); |
| 2312 | } |
| 2313 | break; |
| 2314 | } |
| 2315 | |
| 2316 | case EVENT_START_SATELLITE_POSITION_UPDATES_DONE: { |
| 2317 | ar = (AsyncResult) msg.obj; |
| 2318 | request = (MainThreadRequest) ar.userObj; |
| 2319 | if (ar.exception == null) { |
| 2320 | request.result = SatelliteManager.SATELLITE_SERVICE_SUCCESS; |
| 2321 | } else { |
| 2322 | request.result = SatelliteManager.SATELLITE_SERVICE_ERROR; |
| 2323 | if (ar.exception instanceof CommandException) { |
| 2324 | CommandException.Error error = |
| 2325 | ((CommandException) (ar.exception)).getCommandError(); |
| 2326 | request.result = RILUtils.convertToSatelliteError(error); |
| 2327 | loge("startSatellitePositionUpdates CommandException: " + ar.exception); |
| 2328 | } else { |
| 2329 | loge("startSatellitePositionUpdates unknown exception:" + ar.exception); |
| 2330 | } |
| 2331 | } |
| 2332 | notifyRequester(request); |
| 2333 | break; |
| 2334 | } |
| 2335 | |
| 2336 | case CMD_STOP_SATELLITE_POSITION_UPDATES: { |
| 2337 | request = (MainThreadRequest) msg.obj; |
| 2338 | onCompleted = |
| 2339 | obtainMessage(EVENT_STOP_SATELLITE_POSITION_UPDATES_DONE, request); |
| 2340 | Phone phone = getPhoneFromRequest(request); |
| 2341 | if (phone != null) { |
| 2342 | phone.stopSatellitePositionUpdates(onCompleted); |
| 2343 | } else { |
| 2344 | loge("stopSatellitePositionUpdates: No phone object"); |
| 2345 | request.result = SatelliteManager.SATELLITE_SERVICE_REQUEST_FAILED; |
| 2346 | notifyRequester(request); |
| 2347 | } |
| 2348 | break; |
| 2349 | } |
| 2350 | |
| 2351 | case EVENT_STOP_SATELLITE_POSITION_UPDATES_DONE: { |
| 2352 | ar = (AsyncResult) msg.obj; |
| 2353 | request = (MainThreadRequest) ar.userObj; |
| 2354 | if (ar.exception == null) { |
| 2355 | request.result = SatelliteManager.SATELLITE_SERVICE_SUCCESS; |
| 2356 | } else { |
| 2357 | request.result = SatelliteManager.SATELLITE_SERVICE_ERROR; |
| 2358 | if (ar.exception instanceof CommandException) { |
| 2359 | CommandException.Error error = |
| 2360 | ((CommandException) (ar.exception)).getCommandError(); |
| 2361 | request.result = RILUtils.convertToSatelliteError(error); |
| 2362 | loge("stopSatellitePositionUpdates CommandException: " + ar.exception); |
| 2363 | } else { |
| 2364 | loge("stopSatellitePositionUpdates unknown exception:" + ar.exception); |
| 2365 | } |
| 2366 | } |
| 2367 | notifyRequester(request); |
| 2368 | break; |
| 2369 | } |
| 2370 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2371 | default: |
| 2372 | Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what); |
| 2373 | break; |
| 2374 | } |
| 2375 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2376 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 2377 | private void notifyRequester(MainThreadRequest request) { |
| 2378 | synchronized (request) { |
| 2379 | request.notifyAll(); |
| 2380 | } |
| 2381 | } |
| 2382 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2383 | private void handleNullReturnEvent(Message msg, String command) { |
| 2384 | AsyncResult ar = (AsyncResult) msg.obj; |
| 2385 | MainThreadRequest request = (MainThreadRequest) ar.userObj; |
| 2386 | if (ar.exception == null) { |
| 2387 | request.result = true; |
| 2388 | } else { |
| 2389 | request.result = false; |
| 2390 | if (ar.exception instanceof CommandException) { |
| 2391 | loge(command + ": CommandException: " + ar.exception); |
| 2392 | } else { |
| 2393 | loge(command + ": Unknown exception"); |
| 2394 | } |
| 2395 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 2396 | notifyRequester(request); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2397 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2398 | } |
| 2399 | |
| 2400 | /** |
| 2401 | * Posts the specified command to be executed on the main thread, |
| 2402 | * waits for the request to complete, and returns the result. |
| 2403 | * @see #sendRequestAsync |
| 2404 | */ |
| 2405 | private Object sendRequest(int command, Object argument) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2406 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, |
| 2407 | null, -1 /*timeoutInMs*/); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 2408 | } |
| 2409 | |
| 2410 | /** |
| 2411 | * Posts the specified command to be executed on the main thread, |
| 2412 | * waits for the request to complete, and returns the result. |
| 2413 | * @see #sendRequestAsync |
| 2414 | */ |
| 2415 | private Object sendRequest(int command, Object argument, WorkSource workSource) { |
| 2416 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2417 | null, workSource, -1 /*timeoutInMs*/); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2418 | } |
| 2419 | |
| 2420 | /** |
| 2421 | * Posts the specified command to be executed on the main thread, |
| 2422 | * waits for the request to complete, and returns the result. |
| 2423 | * @see #sendRequestAsync |
| 2424 | */ |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2425 | private Object sendRequest(int command, Object argument, Integer subId) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2426 | return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/); |
| 2427 | } |
| 2428 | |
| 2429 | /** |
| 2430 | * Posts the specified command to be executed on the main thread, |
| 2431 | * waits for the request to complete for at most {@code timeoutInMs}, and returns the result |
| 2432 | * if not timeout or null otherwise. |
| 2433 | * @see #sendRequestAsync |
| 2434 | */ |
| 2435 | private @Nullable Object sendRequest(int command, Object argument, Integer subId, |
| 2436 | long timeoutInMs) { |
| 2437 | return sendRequest(command, argument, subId, null, null, timeoutInMs); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 2438 | } |
| 2439 | |
| 2440 | /** |
| 2441 | * Posts the specified command to be executed on the main thread, |
| 2442 | * waits for the request to complete, and returns the result. |
| 2443 | * @see #sendRequestAsync |
| 2444 | */ |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2445 | private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2446 | return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2447 | } |
| 2448 | |
| 2449 | /** |
| 2450 | * Posts the specified command to be executed on the main thread, |
| 2451 | * waits for the request to complete, and returns the result. |
| 2452 | * @see #sendRequestAsync |
| 2453 | */ |
| 2454 | private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2455 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, |
| 2456 | workSource, -1 /*timeoutInMs*/); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2457 | } |
| 2458 | |
| 2459 | /** |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2460 | * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is |
| 2461 | * negative, waits for the request to complete, and returns the result. Otherwise, wait for |
| 2462 | * maximum of {@code timeoutInMs} milliseconds, interrupt and return null. |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2463 | * @see #sendRequestAsync |
| 2464 | */ |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2465 | private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone, |
| 2466 | WorkSource workSource, long timeoutInMs) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2467 | if (Looper.myLooper() == mMainThreadHandler.getLooper()) { |
| 2468 | throw new RuntimeException("This method will deadlock if called from the main thread."); |
| 2469 | } |
| 2470 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2471 | MainThreadRequest request = null; |
| 2472 | if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) { |
| 2473 | throw new IllegalArgumentException("subId and phone cannot both be specified!"); |
| 2474 | } else if (phone != null) { |
| 2475 | request = new MainThreadRequest(argument, phone, workSource); |
| 2476 | } else { |
| 2477 | request = new MainThreadRequest(argument, subId, workSource); |
| 2478 | } |
| 2479 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2480 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 2481 | msg.sendToTarget(); |
| 2482 | |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2483 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2484 | synchronized (request) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2485 | if (timeoutInMs >= 0) { |
| 2486 | // Wait for at least timeoutInMs before returning null request result |
| 2487 | long now = SystemClock.elapsedRealtime(); |
| 2488 | long deadline = now + timeoutInMs; |
Grace Jia | 8a0a1e8 | 2021-05-23 22:59:52 -0700 | [diff] [blame] | 2489 | while (request.result == null && now < deadline) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2490 | try { |
| 2491 | request.wait(deadline - now); |
| 2492 | } catch (InterruptedException e) { |
| 2493 | // Do nothing, go back and check if request is completed or timeout |
| 2494 | } finally { |
| 2495 | now = SystemClock.elapsedRealtime(); |
| 2496 | } |
| 2497 | } |
| 2498 | } else { |
| 2499 | // Wait for the request to complete |
| 2500 | while (request.result == null) { |
| 2501 | try { |
| 2502 | request.wait(); |
| 2503 | } catch (InterruptedException e) { |
| 2504 | // Do nothing, go back and wait until the request is complete |
| 2505 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2506 | } |
| 2507 | } |
| 2508 | } |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2509 | if (request.result == null) { |
| 2510 | Log.wtf(LOG_TAG, |
| 2511 | "sendRequest: Blocking command timed out. Something has gone terribly wrong."); |
| 2512 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2513 | return request.result; |
| 2514 | } |
| 2515 | |
| 2516 | /** |
| 2517 | * Asynchronous ("fire and forget") version of sendRequest(): |
| 2518 | * Posts the specified command to be executed on the main thread, and |
| 2519 | * returns immediately. |
| 2520 | * @see #sendRequest |
| 2521 | */ |
| 2522 | private void sendRequestAsync(int command) { |
| 2523 | mMainThreadHandler.sendEmptyMessage(command); |
| 2524 | } |
| 2525 | |
| 2526 | /** |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2527 | * Same as {@link #sendRequestAsync(int)} except it takes an argument. |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2528 | * @see {@link #sendRequest(int)} |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2529 | */ |
| 2530 | private void sendRequestAsync(int command, Object argument) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2531 | sendRequestAsync(command, argument, null, null); |
| 2532 | } |
| 2533 | |
| 2534 | /** |
| 2535 | * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource. |
| 2536 | * @see {@link #sendRequest(int,Object)} |
| 2537 | */ |
| 2538 | private void sendRequestAsync( |
| 2539 | int command, Object argument, Phone phone, WorkSource workSource) { |
| 2540 | MainThreadRequest request = new MainThreadRequest(argument, phone, workSource); |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2541 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 2542 | msg.sendToTarget(); |
| 2543 | } |
| 2544 | |
| 2545 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2546 | * Initialize the singleton PhoneInterfaceManager instance. |
| 2547 | * This is only done once, at startup, from PhoneApp.onCreate(). |
| 2548 | */ |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2549 | /* package */ static PhoneInterfaceManager init(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2550 | synchronized (PhoneInterfaceManager.class) { |
| 2551 | if (sInstance == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2552 | sInstance = new PhoneInterfaceManager(app); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2553 | } else { |
| 2554 | Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance); |
| 2555 | } |
| 2556 | return sInstance; |
| 2557 | } |
| 2558 | } |
| 2559 | |
| 2560 | /** Private constructor; @see init() */ |
Jordan Liu | 1979a04 | 2020-03-20 21:39:35 +0000 | [diff] [blame] | 2561 | private PhoneInterfaceManager(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2562 | mApp = app; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2563 | mCM = PhoneGlobals.getInstance().mCM; |
Brad Ebinger | d1947d8 | 2021-05-17 20:54:49 +0000 | [diff] [blame] | 2564 | mImsResolver = ImsResolver.getInstance(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 2565 | mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2566 | mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 2567 | mPm = app.getSystemService(PackageManager.class); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2568 | mMainThreadHandler = new MainThreadHandler(); |
Jack Yu | e37dd26 | 2022-12-16 11:53:37 -0800 | [diff] [blame] | 2569 | if (!PhoneFactory.isSubscriptionManagerServiceEnabled()) { |
| 2570 | mSubscriptionController = SubscriptionController.getInstance(); |
| 2571 | } else { |
| 2572 | mSubscriptionController = null; |
| 2573 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2574 | mTelephonySharedPreferences = |
| 2575 | PreferenceManager.getDefaultSharedPreferences(mApp); |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 2576 | mNetworkScanRequestTracker = new NetworkScanRequestTracker(); |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 2577 | mPhoneConfigurationManager = PhoneConfigurationManager.getInstance(); |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 2578 | mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance(); |
Peter Wang | a3cf4ac | 2020-01-27 09:39:46 +0800 | [diff] [blame] | 2579 | mNotifyUserActivity = new AtomicBoolean(false); |
Tyler Gunn | 64144d9 | 2022-03-17 14:16:41 -0700 | [diff] [blame] | 2580 | PropertyInvalidatedCache.invalidateCache(TelephonyManager.CACHE_KEY_PHONE_ACCOUNT_TO_SUBID); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2581 | publish(); |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 2582 | CarrierAllowListInfo.loadInstance(mApp); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2583 | } |
| 2584 | |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 2585 | @VisibleForTesting |
| 2586 | public SharedPreferences getSharedPreferences() { |
| 2587 | return mTelephonySharedPreferences; |
| 2588 | } |
| 2589 | |
Gil Cukierman | 92cc7db | 2023-01-06 19:25:53 +0000 | [diff] [blame] | 2590 | /** |
| 2591 | * Get the default phone for this device. |
| 2592 | */ |
| 2593 | @VisibleForTesting |
| 2594 | public Phone getDefaultPhone() { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2595 | Phone thePhone = getPhone(getDefaultSubscription()); |
| 2596 | return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone(); |
| 2597 | } |
| 2598 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2599 | private void publish() { |
| 2600 | if (DBG) log("publish: " + this); |
| 2601 | |
Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 2602 | TelephonyFrameworkInitializer |
| 2603 | .getTelephonyServiceManager() |
| 2604 | .getTelephonyServiceRegisterer() |
| 2605 | .register(this); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2606 | } |
| 2607 | |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 2608 | private Phone getPhoneFromRequest(MainThreadRequest request) { |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 2609 | if (request.phone != null) { |
| 2610 | return request.phone; |
| 2611 | } else { |
| 2612 | return getPhoneFromSubId(request.subId); |
| 2613 | } |
| 2614 | } |
| 2615 | |
| 2616 | private Phone getPhoneFromSubId(int subId) { |
| 2617 | return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) |
| 2618 | ? getDefaultPhone() : getPhone(subId); |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 2619 | } |
| 2620 | |
Aishwarya Mallampati | 5e581e1 | 2023-01-17 21:57:06 +0000 | [diff] [blame] | 2621 | /** |
| 2622 | * Get phone object associated with a subscription. |
| 2623 | * Return default phone if phone object associated with subscription is null |
| 2624 | * @param subId - subscriptionId |
| 2625 | * @return phone object associated with a subscription or default phone if null. |
| 2626 | */ |
| 2627 | private Phone getPhoneFromSubIdOrDefault(int subId) { |
| 2628 | Phone phone = getPhoneFromSubId(subId); |
| 2629 | if (phone == null) { |
| 2630 | phone = getDefaultPhone(); |
| 2631 | } |
| 2632 | return phone; |
| 2633 | } |
| 2634 | |
Rambo Wang | e53e07d | 2022-05-10 13:01:13 -0700 | [diff] [blame] | 2635 | @Nullable |
| 2636 | private UiccPort getUiccPortFromRequest(@NonNull MainThreadRequest request) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2637 | Phone phone = getPhoneFromRequest(request); |
| 2638 | return phone == null ? null : |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 2639 | UiccController.getInstance().getUiccPort(phone.getPhoneId()); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2640 | } |
| 2641 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2642 | // returns phone associated with the subId. |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2643 | private Phone getPhone(int subId) { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 2644 | return PhoneFactory.getPhone(SubscriptionManager.getPhoneId(subId)); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2645 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2646 | |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 2647 | private void sendEraseModemConfig(@NonNull Phone phone) { |
| 2648 | Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null); |
| 2649 | if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 2650 | } |
| 2651 | |
| 2652 | private void sendEraseDataInSharedPreferences(@NonNull Phone phone) { |
| 2653 | Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null); |
| 2654 | if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail")); |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 2655 | } |
| 2656 | |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 2657 | private boolean isImsAvailableOnDevice() { |
| 2658 | PackageManager pm = getDefaultPhone().getContext().getPackageManager(); |
| 2659 | if (pm == null) { |
| 2660 | // For some reason package manger is not available.. This will fail internally anyway, |
| 2661 | // so do not throw error and allow. |
| 2662 | return true; |
| 2663 | } |
| 2664 | return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0); |
| 2665 | } |
| 2666 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2667 | public void dial(String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2668 | dialForSubscriber(getPreferredVoiceSubscription(), number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2669 | } |
| 2670 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2671 | public void dialForSubscriber(int subId, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2672 | if (DBG) log("dial: " + number); |
| 2673 | // No permission check needed here: This is just a wrapper around the |
| 2674 | // ACTION_DIAL intent, which is available to any app since it puts up |
| 2675 | // the UI before it does anything. |
| 2676 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2677 | final long identity = Binder.clearCallingIdentity(); |
| 2678 | try { |
| 2679 | String url = createTelUrl(number); |
| 2680 | if (url == null) { |
| 2681 | return; |
| 2682 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2683 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2684 | // PENDING: should we just silently fail if phone is offhook or ringing? |
| 2685 | PhoneConstants.State state = mCM.getState(subId); |
| 2686 | if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) { |
| 2687 | Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url)); |
| 2688 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2689 | mApp.startActivity(intent); |
| 2690 | } |
| 2691 | } finally { |
| 2692 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2693 | } |
| 2694 | } |
| 2695 | |
| 2696 | public void call(String callingPackage, String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2697 | callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2698 | } |
| 2699 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2700 | public void callForSubscriber(int subId, String callingPackage, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2701 | if (DBG) log("call: " + number); |
| 2702 | |
| 2703 | // This is just a wrapper around the ACTION_CALL intent, but we still |
| 2704 | // need to do a permission check since we're calling startActivity() |
| 2705 | // from the context of the phone app. |
| 2706 | enforceCallPermission(); |
| 2707 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 2708 | if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage) |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2709 | != AppOpsManager.MODE_ALLOWED) { |
| 2710 | return; |
| 2711 | } |
| 2712 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2713 | final long identity = Binder.clearCallingIdentity(); |
| 2714 | try { |
| 2715 | String url = createTelUrl(number); |
| 2716 | if (url == null) { |
| 2717 | return; |
| 2718 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2719 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2720 | boolean isValid = false; |
| 2721 | final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged(); |
| 2722 | if (slist != null) { |
| 2723 | for (SubscriptionInfo subInfoRecord : slist) { |
| 2724 | if (subInfoRecord.getSubscriptionId() == subId) { |
| 2725 | isValid = true; |
| 2726 | break; |
| 2727 | } |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 2728 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 2729 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2730 | if (!isValid) { |
| 2731 | return; |
| 2732 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 2733 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2734 | Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url)); |
| 2735 | intent.putExtra(SUBSCRIPTION_KEY, subId); |
| 2736 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2737 | mApp.startActivity(intent); |
| 2738 | } finally { |
| 2739 | Binder.restoreCallingIdentity(identity); |
| 2740 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2741 | } |
| 2742 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2743 | public boolean supplyPinForSubscriber(int subId, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2744 | int [] resultArray = supplyPinReportResultForSubscriber(subId, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2745 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 2746 | } |
| 2747 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2748 | public boolean supplyPukForSubscriber(int subId, String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2749 | int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2750 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 2751 | } |
| 2752 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2753 | public int[] supplyPinReportResultForSubscriber(int subId, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2754 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2755 | |
| 2756 | final long identity = Binder.clearCallingIdentity(); |
| 2757 | try { |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2758 | Phone phone = getPhone(subId); |
| 2759 | final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2760 | checkSimPin.start(); |
| 2761 | return checkSimPin.unlockSim(null, pin); |
| 2762 | } finally { |
| 2763 | Binder.restoreCallingIdentity(identity); |
| 2764 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2765 | } |
| 2766 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2767 | public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2768 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2769 | |
| 2770 | final long identity = Binder.clearCallingIdentity(); |
| 2771 | try { |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2772 | Phone phone = getPhone(subId); |
| 2773 | final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2774 | checkSimPuk.start(); |
| 2775 | return checkSimPuk.unlockSim(puk, pin); |
| 2776 | } finally { |
| 2777 | Binder.restoreCallingIdentity(identity); |
| 2778 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2779 | } |
| 2780 | |
| 2781 | /** |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2782 | * Helper thread to turn async call to SimCard#supplyPin into |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2783 | * a synchronous one. |
| 2784 | */ |
| 2785 | private static class UnlockSim extends Thread { |
| 2786 | |
| 2787 | private final IccCard mSimCard; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2788 | private final int mPhoneId; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2789 | |
| 2790 | private boolean mDone = false; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2791 | private int mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 2792 | private int mRetryCount = -1; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2793 | |
| 2794 | // For replies from SimCard interface |
| 2795 | private Handler mHandler; |
| 2796 | |
| 2797 | // For async handler to identify request type |
| 2798 | private static final int SUPPLY_PIN_COMPLETE = 100; |
| 2799 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2800 | UnlockSim(int phoneId, IccCard simCard) { |
| 2801 | mPhoneId = phoneId; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2802 | mSimCard = simCard; |
| 2803 | } |
| 2804 | |
| 2805 | @Override |
| 2806 | public void run() { |
| 2807 | Looper.prepare(); |
| 2808 | synchronized (UnlockSim.this) { |
| 2809 | mHandler = new Handler() { |
| 2810 | @Override |
| 2811 | public void handleMessage(Message msg) { |
| 2812 | AsyncResult ar = (AsyncResult) msg.obj; |
| 2813 | switch (msg.what) { |
| 2814 | case SUPPLY_PIN_COMPLETE: |
| 2815 | Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE"); |
| 2816 | synchronized (UnlockSim.this) { |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2817 | mRetryCount = msg.arg1; |
| 2818 | if (ar.exception != null) { |
| 2819 | if (ar.exception instanceof CommandException && |
| 2820 | ((CommandException)(ar.exception)).getCommandError() |
| 2821 | == CommandException.Error.PASSWORD_INCORRECT) { |
| 2822 | mResult = PhoneConstants.PIN_PASSWORD_INCORRECT; |
vivi.li | b5e9ada | 2019-09-12 16:04:24 +0800 | [diff] [blame] | 2823 | } //When UiccCardApp dispose,handle message and return exception |
| 2824 | else if (ar.exception instanceof CommandException && |
| 2825 | ((CommandException) (ar.exception)).getCommandError() |
| 2826 | == CommandException.Error.ABORTED) { |
| 2827 | mResult = PhoneConstants.PIN_OPERATION_ABORTED; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2828 | } else { |
| 2829 | mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 2830 | } |
| 2831 | } else { |
| 2832 | mResult = PhoneConstants.PIN_RESULT_SUCCESS; |
| 2833 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2834 | mDone = true; |
| 2835 | UnlockSim.this.notifyAll(); |
| 2836 | } |
| 2837 | break; |
| 2838 | } |
| 2839 | } |
| 2840 | }; |
| 2841 | UnlockSim.this.notifyAll(); |
| 2842 | } |
| 2843 | Looper.loop(); |
| 2844 | } |
| 2845 | |
| 2846 | /* |
| 2847 | * Use PIN or PUK to unlock SIM card |
| 2848 | * |
| 2849 | * If PUK is null, unlock SIM card with PIN |
| 2850 | * |
| 2851 | * If PUK is not null, unlock SIM card with PUK and set PIN code |
| 2852 | */ |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2853 | synchronized int[] unlockSim(String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2854 | |
| 2855 | while (mHandler == null) { |
| 2856 | try { |
| 2857 | wait(); |
| 2858 | } catch (InterruptedException e) { |
| 2859 | Thread.currentThread().interrupt(); |
| 2860 | } |
| 2861 | } |
| 2862 | Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE); |
| 2863 | |
| 2864 | if (puk == null) { |
| 2865 | mSimCard.supplyPin(pin, callback); |
| 2866 | } else { |
| 2867 | mSimCard.supplyPuk(puk, pin, callback); |
| 2868 | } |
| 2869 | |
| 2870 | while (!mDone) { |
| 2871 | try { |
| 2872 | Log.d(LOG_TAG, "wait for done"); |
| 2873 | wait(); |
| 2874 | } catch (InterruptedException e) { |
| 2875 | // Restore the interrupted status |
| 2876 | Thread.currentThread().interrupt(); |
| 2877 | } |
| 2878 | } |
| 2879 | Log.d(LOG_TAG, "done"); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2880 | int[] resultArray = new int[2]; |
| 2881 | resultArray[0] = mResult; |
| 2882 | resultArray[1] = mRetryCount; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2883 | |
| 2884 | if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) { |
Jon Spivack | 9c3bc76 | 2021-10-06 20:53:09 +0000 | [diff] [blame] | 2885 | UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2886 | } |
| 2887 | |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2888 | return resultArray; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2889 | } |
| 2890 | } |
| 2891 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2892 | /** |
| 2893 | * This method has been removed due to privacy and stability concerns. |
| 2894 | */ |
| 2895 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2896 | public void updateServiceLocation() { |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2897 | Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()"); |
| 2898 | return; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2899 | } |
| 2900 | |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2901 | @Override |
| 2902 | public void updateServiceLocationWithPackageName(String callingPackage) { |
| 2903 | mApp.getSystemService(AppOpsManager.class) |
| 2904 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 2905 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 2906 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2907 | if (targetSdk > android.os.Build.VERSION_CODES.R) { |
| 2908 | // Callers targeting S have no business invoking this method. |
| 2909 | return; |
| 2910 | } |
| 2911 | |
| 2912 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2913 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2914 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2915 | .setCallingPackage(callingPackage) |
| 2916 | .setCallingFeatureId(null) |
| 2917 | .setCallingPid(Binder.getCallingPid()) |
| 2918 | .setCallingUid(Binder.getCallingUid()) |
| 2919 | .setMethod("updateServiceLocation") |
| 2920 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
| 2921 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2922 | .build()); |
| 2923 | // Apps that lack location permission have no business calling this method; |
| 2924 | // however, because no permission was declared in the public API, denials must |
| 2925 | // all be "soft". |
| 2926 | switch (locationResult) { |
| 2927 | case DENIED_HARD: /* fall through */ |
| 2928 | case DENIED_SOFT: |
| 2929 | return; |
| 2930 | } |
| 2931 | |
| 2932 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2933 | final long identity = Binder.clearCallingIdentity(); |
| 2934 | try { |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2935 | final Phone phone = getPhone(getDefaultSubscription()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2936 | if (phone != null) { |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2937 | phone.updateServiceLocation(workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2938 | } |
| 2939 | } finally { |
| 2940 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2941 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2942 | } |
| 2943 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2944 | @Deprecated |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2945 | @Override |
| 2946 | public boolean isRadioOn(String callingPackage) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2947 | return isRadioOnWithFeature(callingPackage, null); |
| 2948 | } |
| 2949 | |
| 2950 | |
| 2951 | @Override |
| 2952 | public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) { |
| 2953 | return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage, |
| 2954 | callingFeatureId); |
| 2955 | } |
| 2956 | |
| 2957 | @Deprecated |
| 2958 | @Override |
| 2959 | public boolean isRadioOnForSubscriber(int subId, String callingPackage) { |
| 2960 | return isRadioOnForSubscriberWithFeature(subId, callingPackage, null); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2961 | } |
| 2962 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2963 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2964 | public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage, |
| 2965 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2966 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2967 | mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2968 | return false; |
| 2969 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2970 | |
| 2971 | final long identity = Binder.clearCallingIdentity(); |
| 2972 | try { |
| 2973 | return isRadioOnForSubscriber(subId); |
| 2974 | } finally { |
| 2975 | Binder.restoreCallingIdentity(identity); |
| 2976 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2977 | } |
| 2978 | |
| 2979 | private boolean isRadioOnForSubscriber(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2980 | final long identity = Binder.clearCallingIdentity(); |
| 2981 | try { |
| 2982 | final Phone phone = getPhone(subId); |
| 2983 | if (phone != null) { |
| 2984 | return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF; |
| 2985 | } else { |
| 2986 | return false; |
| 2987 | } |
| 2988 | } finally { |
| 2989 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2990 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2991 | } |
| 2992 | |
| 2993 | public void toggleRadioOnOff() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2994 | toggleRadioOnOffForSubscriber(getDefaultSubscription()); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2995 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2996 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2997 | public void toggleRadioOnOffForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2998 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2999 | |
| 3000 | final long identity = Binder.clearCallingIdentity(); |
| 3001 | try { |
| 3002 | final Phone phone = getPhone(subId); |
| 3003 | if (phone != null) { |
| 3004 | phone.setRadioPower(!isRadioOnForSubscriber(subId)); |
| 3005 | } |
| 3006 | } finally { |
| 3007 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3008 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3009 | } |
| 3010 | |
| 3011 | public boolean setRadio(boolean turnOn) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 3012 | return setRadioForSubscriber(getDefaultSubscription(), turnOn); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3013 | } |
| 3014 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3015 | public boolean setRadioForSubscriber(int subId, boolean turnOn) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3016 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3017 | |
| 3018 | final long identity = Binder.clearCallingIdentity(); |
| 3019 | try { |
| 3020 | final Phone phone = getPhone(subId); |
| 3021 | if (phone == null) { |
| 3022 | return false; |
| 3023 | } |
| 3024 | if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) { |
| 3025 | toggleRadioOnOffForSubscriber(subId); |
| 3026 | } |
| 3027 | return true; |
| 3028 | } finally { |
| 3029 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3030 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3031 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3032 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3033 | public boolean needMobileRadioShutdown() { |
Shuo Qian | fa7b6b3 | 2019-12-10 10:40:38 -0800 | [diff] [blame] | 3034 | enforceReadPrivilegedPermission("needMobileRadioShutdown"); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3035 | /* |
| 3036 | * If any of the Radios are available, it will need to be |
| 3037 | * shutdown. So return true if any Radio is available. |
| 3038 | */ |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3039 | final long identity = Binder.clearCallingIdentity(); |
| 3040 | try { |
| 3041 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 3042 | Phone phone = PhoneFactory.getPhone(i); |
| 3043 | if (phone != null && phone.isRadioAvailable()) return true; |
| 3044 | } |
| 3045 | logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown."); |
| 3046 | return false; |
| 3047 | } finally { |
| 3048 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3049 | } |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3050 | } |
| 3051 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3052 | @Override |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3053 | public void shutdownMobileRadios() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3054 | enforceModifyPermission(); |
| 3055 | |
| 3056 | final long identity = Binder.clearCallingIdentity(); |
| 3057 | try { |
| 3058 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 3059 | logv("Shutting down Phone " + i); |
| 3060 | shutdownRadioUsingPhoneId(i); |
| 3061 | } |
| 3062 | } finally { |
| 3063 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3064 | } |
| 3065 | } |
| 3066 | |
| 3067 | private void shutdownRadioUsingPhoneId(int phoneId) { |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3068 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 3069 | if (phone != null && phone.isRadioAvailable()) { |
| 3070 | phone.shutdownRadio(); |
| 3071 | } |
| 3072 | } |
| 3073 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3074 | public boolean setRadioPower(boolean turnOn) { |
Jack Yu | b4e1616 | 2017-05-15 12:48:40 -0700 | [diff] [blame] | 3075 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3076 | |
Ling Ma | 83dc5ea | 2023-01-12 15:06:04 -0800 | [diff] [blame] | 3077 | if (!turnOn) { |
| 3078 | log("setRadioPower off: callingPackage=" + getCurrentPackageName()); |
| 3079 | } |
| 3080 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3081 | final long identity = Binder.clearCallingIdentity(); |
| 3082 | try { |
| 3083 | final Phone defaultPhone = PhoneFactory.getDefaultPhone(); |
| 3084 | if (defaultPhone != null) { |
| 3085 | defaultPhone.setRadioPower(turnOn); |
| 3086 | return true; |
| 3087 | } else { |
| 3088 | loge("There's no default phone."); |
| 3089 | return false; |
| 3090 | } |
| 3091 | } finally { |
| 3092 | Binder.restoreCallingIdentity(identity); |
Wei Liu | 9ae2a06 | 2016-08-08 11:09:34 -0700 | [diff] [blame] | 3093 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3094 | } |
| 3095 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3096 | public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3097 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3098 | |
Ling Ma | 83dc5ea | 2023-01-12 15:06:04 -0800 | [diff] [blame] | 3099 | if (!turnOn) { |
| 3100 | log("setRadioPowerForSubscriber off: subId=" + subId |
| 3101 | + ",callingPackage=" + getCurrentPackageName()); |
| 3102 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3103 | final long identity = Binder.clearCallingIdentity(); |
| 3104 | try { |
| 3105 | final Phone phone = getPhone(subId); |
| 3106 | if (phone != null) { |
| 3107 | phone.setRadioPower(turnOn); |
| 3108 | return true; |
| 3109 | } else { |
| 3110 | return false; |
| 3111 | } |
| 3112 | } finally { |
| 3113 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3114 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3115 | } |
| 3116 | |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3117 | /** |
| 3118 | * Vote on powering off the radio for a reason. The radio will be turned on only when there is |
| 3119 | * no reason to power it off. When any of the voters want to power it off, it will be turned |
| 3120 | * off. In case of emergency, the radio will be turned on even if there are some reasons for |
| 3121 | * powering it off, and these radio off votes will be cleared. |
| 3122 | * Multiple apps can vote for the same reason and the last vote will take effect. Each app is |
| 3123 | * responsible for its vote. A powering-off vote of a reason will be maintained until it is |
| 3124 | * cleared by calling {@link clearRadioPowerOffForReason} for that reason, or an emergency call |
| 3125 | * is made, or the device is rebooted. When an app comes backup from a crash, it needs to make |
| 3126 | * sure if its vote is as expected. An app can use the API {@link getRadioPowerOffReasons} to |
| 3127 | * check its vote. |
| 3128 | * |
| 3129 | * @param subId The subscription ID. |
| 3130 | * @param reason The reason for powering off radio. |
| 3131 | * @return true on success and false on failure. |
| 3132 | */ |
| 3133 | public boolean requestRadioPowerOffForReason(int subId, |
| 3134 | @TelephonyManager.RadioPowerReason int reason) { |
| 3135 | enforceModifyPermission(); |
| 3136 | |
Ling Ma | 83dc5ea | 2023-01-12 15:06:04 -0800 | [diff] [blame] | 3137 | log("requestRadioPowerOffForReason: subId=" + subId |
| 3138 | + ",reason=" + reason + ",callingPackage=" + getCurrentPackageName()); |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3139 | final long identity = Binder.clearCallingIdentity(); |
| 3140 | try { |
| 3141 | final Phone phone = getPhone(subId); |
| 3142 | if (phone != null) { |
| 3143 | phone.setRadioPowerForReason(false, reason); |
| 3144 | return true; |
| 3145 | } else { |
| 3146 | return false; |
| 3147 | } |
| 3148 | } finally { |
| 3149 | Binder.restoreCallingIdentity(identity); |
| 3150 | } |
| 3151 | } |
| 3152 | |
| 3153 | /** |
| 3154 | * Remove the vote on powering off the radio for a reason, as requested by |
| 3155 | * {@link requestRadioPowerOffForReason}. |
| 3156 | * |
| 3157 | * @param subId The subscription ID. |
| 3158 | * @param reason The reason for powering off radio. |
| 3159 | * @return true on success and false on failure. |
| 3160 | */ |
| 3161 | public boolean clearRadioPowerOffForReason(int subId, |
| 3162 | @TelephonyManager.RadioPowerReason int reason) { |
| 3163 | enforceModifyPermission(); |
| 3164 | |
| 3165 | final long identity = Binder.clearCallingIdentity(); |
| 3166 | try { |
| 3167 | final Phone phone = getPhone(subId); |
| 3168 | if (phone != null) { |
| 3169 | phone.setRadioPowerForReason(true, reason); |
| 3170 | return true; |
| 3171 | } else { |
| 3172 | return false; |
| 3173 | } |
| 3174 | } finally { |
| 3175 | Binder.restoreCallingIdentity(identity); |
| 3176 | } |
| 3177 | } |
| 3178 | |
| 3179 | /** |
| 3180 | * Get reasons for powering off radio, as requested by {@link requestRadioPowerOffForReason}. |
| 3181 | * |
| 3182 | * @param subId The subscription ID. |
| 3183 | * @param callingPackage The package making the call. |
| 3184 | * @param callingFeatureId The feature in the package. |
| 3185 | * @return List of reasons for powering off radio. |
| 3186 | */ |
| 3187 | public List getRadioPowerOffReasons(int subId, String callingPackage, String callingFeatureId) { |
| 3188 | enforceReadPrivilegedPermission("getRadioPowerOffReasons"); |
| 3189 | |
| 3190 | final long identity = Binder.clearCallingIdentity(); |
| 3191 | List result = new ArrayList(); |
| 3192 | try { |
| 3193 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, |
| 3194 | callingPackage, callingFeatureId, "getRadioPowerOffReasons")) { |
| 3195 | return result; |
| 3196 | } |
| 3197 | |
| 3198 | final Phone phone = getPhone(subId); |
| 3199 | if (phone != null) { |
| 3200 | result.addAll(phone.getRadioPowerOffReasons()); |
| 3201 | } |
| 3202 | } finally { |
| 3203 | Binder.restoreCallingIdentity(identity); |
| 3204 | } |
| 3205 | return result; |
| 3206 | } |
| 3207 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3208 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3209 | @Override |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 3210 | public boolean enableDataConnectivity(String callingPackage) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3211 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3212 | |
| 3213 | final long identity = Binder.clearCallingIdentity(); |
| 3214 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3215 | int subId = SubscriptionManager.getDefaultDataSubscriptionId(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3216 | final Phone phone = getPhone(subId); |
| 3217 | if (phone != null) { |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 3218 | phone.getDataSettingsManager().setDataEnabled( |
| 3219 | TelephonyManager.DATA_ENABLED_REASON_USER, true, callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3220 | return true; |
| 3221 | } else { |
| 3222 | return false; |
| 3223 | } |
| 3224 | } finally { |
| 3225 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3226 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3227 | } |
| 3228 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3229 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3230 | @Override |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 3231 | public boolean disableDataConnectivity(String callingPackage) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3232 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3233 | |
| 3234 | final long identity = Binder.clearCallingIdentity(); |
| 3235 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3236 | int subId = SubscriptionManager.getDefaultDataSubscriptionId(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3237 | final Phone phone = getPhone(subId); |
| 3238 | if (phone != null) { |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 3239 | phone.getDataSettingsManager().setDataEnabled( |
| 3240 | TelephonyManager.DATA_ENABLED_REASON_USER, false, callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3241 | return true; |
| 3242 | } else { |
| 3243 | return false; |
| 3244 | } |
| 3245 | } finally { |
| 3246 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3247 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3248 | } |
| 3249 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3250 | @Override |
Jack Yu | acf8a13 | 2017-05-01 17:00:48 -0700 | [diff] [blame] | 3251 | public boolean isDataConnectivityPossible(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3252 | final long identity = Binder.clearCallingIdentity(); |
| 3253 | try { |
| 3254 | final Phone phone = getPhone(subId); |
| 3255 | if (phone != null) { |
Jack Yu | 59824e1 | 2022-03-23 01:42:44 -0700 | [diff] [blame] | 3256 | return phone.isDataAllowed(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3257 | } else { |
| 3258 | return false; |
| 3259 | } |
| 3260 | } finally { |
| 3261 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3262 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3263 | } |
| 3264 | |
| 3265 | public boolean handlePinMmi(String dialString) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 3266 | return handlePinMmiForSubscriber(getDefaultSubscription(), dialString); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3267 | } |
| 3268 | |
pkanwar | ae03a6b | 2016-11-06 20:37:09 -0800 | [diff] [blame] | 3269 | public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3270 | enforceCallPermission(); |
| 3271 | |
| 3272 | final long identity = Binder.clearCallingIdentity(); |
| 3273 | try { |
| 3274 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3275 | return; |
| 3276 | } |
| 3277 | Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback); |
| 3278 | sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId); |
| 3279 | } finally { |
| 3280 | Binder.restoreCallingIdentity(identity); |
| 3281 | } |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 3282 | }; |
| 3283 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3284 | public boolean handlePinMmiForSubscriber(int subId, String dialString) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3285 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3286 | |
| 3287 | final long identity = Binder.clearCallingIdentity(); |
| 3288 | try { |
| 3289 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3290 | return false; |
| 3291 | } |
| 3292 | return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId); |
| 3293 | } finally { |
| 3294 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3295 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3296 | } |
| 3297 | |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 3298 | /** |
| 3299 | * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage |
| 3300 | * tag on getCallState Binder call. |
| 3301 | */ |
| 3302 | @Deprecated |
| 3303 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3304 | public int getCallState() { |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 3305 | if (CompatChanges.isChangeEnabled( |
| 3306 | TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION, |
| 3307 | Binder.getCallingUid())) { |
| 3308 | // Do not allow this API to be called on API version 31+, it should only be |
| 3309 | // called on old apps using this Binder call directly. |
| 3310 | throw new SecurityException("This method can only be used for applications " |
| 3311 | + "targeting API version 30 or less."); |
| 3312 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3313 | final long identity = Binder.clearCallingIdentity(); |
| 3314 | try { |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 3315 | Phone phone = getPhone(getDefaultSubscription()); |
| 3316 | return phone == null ? TelephonyManager.CALL_STATE_IDLE : |
| 3317 | PhoneConstantConversions.convertCallState(phone.getState()); |
| 3318 | } finally { |
| 3319 | Binder.restoreCallingIdentity(identity); |
| 3320 | } |
| 3321 | } |
| 3322 | |
| 3323 | @Override |
| 3324 | public int getCallStateForSubscription(int subId, String callingPackage, String featureId) { |
| 3325 | if (CompatChanges.isChangeEnabled( |
| 3326 | TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION, |
| 3327 | Binder.getCallingUid())) { |
| 3328 | // Check READ_PHONE_STATE for API version 31+ |
| 3329 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage, |
| 3330 | featureId, "getCallStateForSubscription")) { |
| 3331 | throw new SecurityException("getCallState requires READ_PHONE_STATE for apps " |
| 3332 | + "targeting API level 31+."); |
| 3333 | } |
| 3334 | } |
| 3335 | final long identity = Binder.clearCallingIdentity(); |
| 3336 | try { |
| 3337 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3338 | return phone == null ? TelephonyManager.CALL_STATE_IDLE : |
| 3339 | PhoneConstantConversions.convertCallState(phone.getState()); |
| 3340 | } finally { |
| 3341 | Binder.restoreCallingIdentity(identity); |
| 3342 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3343 | } |
| 3344 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3345 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 3346 | public int getDataState() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3347 | return getDataStateForSubId(SubscriptionManager.getDefaultDataSubscriptionId()); |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 3348 | } |
| 3349 | |
| 3350 | @Override |
| 3351 | public int getDataStateForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3352 | final long identity = Binder.clearCallingIdentity(); |
| 3353 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 3354 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3355 | if (phone != null) { |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 3356 | return phone.getDataNetworkController().getInternetDataNetworkState(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3357 | } else { |
| 3358 | return PhoneConstantConversions.convertDataState( |
| 3359 | PhoneConstants.DataState.DISCONNECTED); |
| 3360 | } |
| 3361 | } finally { |
| 3362 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3363 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3364 | } |
| 3365 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3366 | @Override |
Jack Yu | 0eda684 | 2022-04-18 00:34:46 -0700 | [diff] [blame] | 3367 | public @DataActivityType int getDataActivity() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3368 | return getDataActivityForSubId(SubscriptionManager.getDefaultDataSubscriptionId()); |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 3369 | } |
| 3370 | |
| 3371 | @Override |
Jack Yu | 0eda684 | 2022-04-18 00:34:46 -0700 | [diff] [blame] | 3372 | public @DataActivityType int getDataActivityForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3373 | final long identity = Binder.clearCallingIdentity(); |
| 3374 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 3375 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3376 | if (phone != null) { |
Jack Yu | 0eda684 | 2022-04-18 00:34:46 -0700 | [diff] [blame] | 3377 | return phone.getDataActivityState(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3378 | } else { |
| 3379 | return TelephonyManager.DATA_ACTIVITY_NONE; |
| 3380 | } |
| 3381 | } finally { |
| 3382 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3383 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3384 | } |
| 3385 | |
| 3386 | @Override |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 3387 | public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3388 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 3389 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3390 | |
| 3391 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 3392 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 3393 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 3394 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3395 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3396 | .setCallingPid(Binder.getCallingPid()) |
| 3397 | .setCallingUid(Binder.getCallingUid()) |
| 3398 | .setMethod("getCellLocation") |
Hall Liu | 773ba02 | 2020-01-24 18:07:12 -0800 | [diff] [blame] | 3399 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3400 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 3401 | .build()); |
| 3402 | switch (locationResult) { |
| 3403 | case DENIED_HARD: |
| 3404 | throw new SecurityException("Not allowed to access cell location"); |
| 3405 | case DENIED_SOFT: |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 3406 | return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
| 3407 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3408 | } |
| 3409 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 3410 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3411 | final long identity = Binder.clearCallingIdentity(); |
| 3412 | try { |
| 3413 | if (DBG_LOC) log("getCellLocation: is active user"); |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3414 | int subId = SubscriptionManager.getDefaultDataSubscriptionId(); |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 3415 | return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3416 | } finally { |
| 3417 | Binder.restoreCallingIdentity(identity); |
| 3418 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 3419 | } |
| 3420 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3421 | @Override |
Jack Yu | eb1e7fe | 2020-02-22 19:38:58 -0800 | [diff] [blame] | 3422 | public String getNetworkCountryIsoForPhone(int phoneId) { |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3423 | // Reporting the correct network country is ambiguous when IWLAN could conflict with |
| 3424 | // registered cell info, so return a NULL country instead. |
| 3425 | final long identity = Binder.clearCallingIdentity(); |
| 3426 | try { |
Malcolm Chen | 3732c2b | 2018-07-18 20:15:24 -0700 | [diff] [blame] | 3427 | if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) { |
| 3428 | // Get default phone in this case. |
| 3429 | phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX; |
| 3430 | } |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3431 | final int subId = SubscriptionManager.getSubscriptionId(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3432 | Phone phone = PhoneFactory.getPhone(phoneId); |
Nathan Harold | 532f51c | 2020-04-21 19:31:10 -0700 | [diff] [blame] | 3433 | if (phone == null) return ""; |
| 3434 | ServiceStateTracker sst = phone.getServiceStateTracker(); |
| 3435 | if (sst == null) return ""; |
| 3436 | LocaleTracker lt = sst.getLocaleTracker(); |
| 3437 | if (lt == null) return ""; |
Shuo Qian | 9418a92 | 2021-03-09 11:21:16 -0800 | [diff] [blame] | 3438 | return lt.getCurrentCountry(); |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3439 | } finally { |
| 3440 | Binder.restoreCallingIdentity(identity); |
| 3441 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3442 | } |
| 3443 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 3444 | /** |
| 3445 | * This method was removed due to potential issues caused by performing partial |
| 3446 | * updates of service state, and lack of a credible use case. |
| 3447 | * |
| 3448 | * This has the ability to break the telephony implementation by disabling notification of |
| 3449 | * changes in device connectivity. DO NOT USE THIS! |
| 3450 | */ |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3451 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3452 | public void enableLocationUpdates() { |
| 3453 | mApp.enforceCallingOrSelfPermission( |
| 3454 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3455 | } |
| 3456 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 3457 | /** |
| 3458 | * This method was removed due to potential issues caused by performing partial |
| 3459 | * updates of service state, and lack of a credible use case. |
| 3460 | * |
| 3461 | * This has the ability to break the telephony implementation by disabling notification of |
| 3462 | * changes in device connectivity. DO NOT USE THIS! |
| 3463 | */ |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3464 | @Override |
| 3465 | public void disableLocationUpdates() { |
| 3466 | mApp.enforceCallingOrSelfPermission( |
| 3467 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3468 | } |
| 3469 | |
| 3470 | @Override |
| 3471 | @SuppressWarnings("unchecked") |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3472 | public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage, |
| 3473 | String callingFeatureId) { |
Nathan Harold | b55f63b | 2021-07-27 11:27:38 -0700 | [diff] [blame] | 3474 | try { |
| 3475 | mApp.getSystemService(AppOpsManager.class) |
| 3476 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 3477 | } catch (SecurityException e) { |
| 3478 | EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid()); |
| 3479 | throw e; |
| 3480 | } |
| 3481 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3482 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | dbea45a | 2018-08-30 14:35:07 -0700 | [diff] [blame] | 3483 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 3484 | throw new SecurityException( |
| 3485 | "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels."); |
| 3486 | } |
Nathan Harold | b4d5561 | 2018-07-20 13:13:08 -0700 | [diff] [blame] | 3487 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 3488 | if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(), |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3489 | callingPackage) != AppOpsManager.MODE_ALLOWED) { |
| 3490 | return null; |
| 3491 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 3492 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 3493 | if (DBG_LOC) log("getNeighboringCellInfo: is active user"); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3494 | |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3495 | List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId); |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 3496 | if (info == null) return null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3497 | |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 3498 | List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>(); |
| 3499 | for (CellInfo ci : info) { |
| 3500 | if (ci instanceof CellInfoGsm) { |
| 3501 | neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci)); |
| 3502 | } else if (ci instanceof CellInfoWcdma) { |
| 3503 | neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci)); |
| 3504 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3505 | } |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 3506 | return (neighbors.size()) > 0 ? neighbors : null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3507 | } |
| 3508 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3509 | private List<CellInfo> getCachedCellInfo() { |
| 3510 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 3511 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3512 | List<CellInfo> info = phone.getAllCellInfo(); |
| 3513 | if (info != null) cellInfos.addAll(info); |
| 3514 | } |
| 3515 | return cellInfos; |
| 3516 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3517 | |
| 3518 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3519 | public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3520 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 3521 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3522 | |
| 3523 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 3524 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 3525 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 3526 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3527 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3528 | .setCallingPid(Binder.getCallingPid()) |
| 3529 | .setCallingUid(Binder.getCallingUid()) |
| 3530 | .setMethod("getAllCellInfo") |
Nathan Harold | 5ae50b5 | 2019-02-20 15:46:36 -0800 | [diff] [blame] | 3531 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3532 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 3533 | .build()); |
| 3534 | switch (locationResult) { |
| 3535 | case DENIED_HARD: |
| 3536 | throw new SecurityException("Not allowed to access cell info"); |
| 3537 | case DENIED_SOFT: |
| 3538 | return new ArrayList<>(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3539 | } |
| 3540 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3541 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3542 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 3543 | return getCachedCellInfo(); |
| 3544 | } |
| 3545 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 3546 | if (DBG_LOC) log("getAllCellInfo: is active user"); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 3547 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3548 | final long identity = Binder.clearCallingIdentity(); |
| 3549 | try { |
| 3550 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 3551 | for (Phone phone : PhoneFactory.getPhones()) { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 3552 | final List<CellInfo> info = (List<CellInfo>) sendRequest( |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 3553 | CMD_GET_ALL_CELL_INFO, null, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3554 | if (info != null) cellInfos.addAll(info); |
| 3555 | } |
| 3556 | return cellInfos; |
| 3557 | } finally { |
| 3558 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3559 | } |
| 3560 | } |
| 3561 | |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 3562 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3563 | public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage, |
| 3564 | String callingFeatureId) { |
| 3565 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, |
| 3566 | getWorkSource(Binder.getCallingUid())); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3567 | } |
| 3568 | |
| 3569 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3570 | public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb, |
| 3571 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3572 | enforceModifyPermission(); |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3573 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3574 | } |
| 3575 | |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3576 | private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb, |
| 3577 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3578 | mApp.getSystemService(AppOpsManager.class) |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3579 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3580 | |
| 3581 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 3582 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 3583 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 3584 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3585 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3586 | .setCallingPid(Binder.getCallingPid()) |
| 3587 | .setCallingUid(Binder.getCallingUid()) |
| 3588 | .setMethod("requestCellInfoUpdate") |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 3589 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
| 3590 | .setMinSdkVersionForFine(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3591 | .build()); |
| 3592 | switch (locationResult) { |
| 3593 | case DENIED_HARD: |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3594 | if (TelephonyPermissions |
| 3595 | .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) { |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 3596 | // Safetynet logging for b/154934934 |
| 3597 | EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid()); |
| 3598 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3599 | throw new SecurityException("Not allowed to access cell info"); |
| 3600 | case DENIED_SOFT: |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3601 | if (TelephonyPermissions |
| 3602 | .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) { |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 3603 | // Safetynet logging for b/154934934 |
| 3604 | EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid()); |
| 3605 | } |
Nathan Harold | 5320c42 | 2019-05-09 10:26:08 -0700 | [diff] [blame] | 3606 | try { |
| 3607 | cb.onCellInfo(new ArrayList<CellInfo>()); |
| 3608 | } catch (RemoteException re) { |
| 3609 | // Drop without consequences |
| 3610 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3611 | return; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3612 | } |
| 3613 | |
Nathan Harold | a939a96 | 2019-05-09 10:13:47 -0700 | [diff] [blame] | 3614 | |
| 3615 | final Phone phone = getPhoneFromSubId(subId); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3616 | if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
| 3617 | |
| 3618 | sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource); |
| 3619 | } |
| 3620 | |
| 3621 | @Override |
Aishwarya Mallampati | 0603fb1 | 2022-08-24 21:16:56 +0000 | [diff] [blame] | 3622 | public void setCellInfoListRate(int rateInMillis, int subId) { |
Jack Yu | a8d8cb8 | 2017-01-16 10:15:34 -0800 | [diff] [blame] | 3623 | enforceModifyPermission(); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 3624 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3625 | |
| 3626 | final long identity = Binder.clearCallingIdentity(); |
| 3627 | try { |
Aishwarya Mallampati | 0603fb1 | 2022-08-24 21:16:56 +0000 | [diff] [blame] | 3628 | Phone phone = getPhone(subId); |
| 3629 | if (phone == null) { |
| 3630 | getDefaultPhone().setCellInfoListRate(rateInMillis, workSource); |
| 3631 | } else { |
| 3632 | phone.setCellInfoListRate(rateInMillis, workSource); |
| 3633 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3634 | } finally { |
| 3635 | Binder.restoreCallingIdentity(identity); |
| 3636 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3637 | } |
| 3638 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3639 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3640 | public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3641 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3642 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3643 | return null; |
| 3644 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3645 | int subId = phone.getSubId(); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3646 | enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot"); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 3647 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3648 | callingPackage, callingFeatureId, "getImeiForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3649 | return null; |
| 3650 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3651 | |
| 3652 | final long identity = Binder.clearCallingIdentity(); |
| 3653 | try { |
| 3654 | return phone.getImei(); |
| 3655 | } finally { |
| 3656 | Binder.restoreCallingIdentity(identity); |
| 3657 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3658 | } |
| 3659 | |
| 3660 | @Override |
arunvoddu | d5c6ce0 | 2022-12-11 06:03:12 +0000 | [diff] [blame] | 3661 | public String getPrimaryImei(String callingPackage, String callingFeatureId) { |
| 3662 | enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getPrimaryImei"); |
| 3663 | if (!checkCallingOrSelfReadDeviceIdentifiersForAnySub(mApp, callingPackage, |
| 3664 | callingFeatureId, "getPrimaryImei")) { |
| 3665 | throw new SecurityException("Caller does not have permission"); |
| 3666 | } |
| 3667 | final long identity = Binder.clearCallingIdentity(); |
| 3668 | try { |
| 3669 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3670 | if (phone.getImeiType() == Phone.IMEI_TYPE_PRIMARY) { |
| 3671 | return phone.getImei(); |
| 3672 | } |
| 3673 | } |
| 3674 | throw new UnsupportedOperationException("Operation not supported"); |
| 3675 | } finally { |
| 3676 | Binder.restoreCallingIdentity(identity); |
| 3677 | } |
| 3678 | } |
| 3679 | |
| 3680 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3681 | public String getTypeAllocationCodeForSlot(int slotIndex) { |
| 3682 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3683 | String tac = null; |
| 3684 | if (phone != null) { |
| 3685 | String imei = phone.getImei(); |
Vala Zadeh | ab00555 | 2021-09-21 15:54:29 -0700 | [diff] [blame] | 3686 | try { |
| 3687 | tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH); |
| 3688 | } catch (IndexOutOfBoundsException e) { |
| 3689 | Log.e(LOG_TAG, "IMEI length shorter than upper index."); |
| 3690 | return null; |
| 3691 | } |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3692 | } |
| 3693 | return tac; |
| 3694 | } |
| 3695 | |
| 3696 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3697 | public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Shuo Qian | 13d8915 | 2021-05-10 23:58:11 -0700 | [diff] [blame] | 3698 | try { |
| 3699 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 3700 | } catch (SecurityException se) { |
| 3701 | EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid()); |
| 3702 | throw new SecurityException("Package " + callingPackage + " does not belong to " |
| 3703 | + Binder.getCallingUid()); |
| 3704 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3705 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3706 | if (phone == null) { |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 3707 | return null; |
| 3708 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3709 | |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3710 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 3711 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3712 | callingPackage, callingFeatureId, "getMeidForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3713 | return null; |
| 3714 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3715 | |
| 3716 | final long identity = Binder.clearCallingIdentity(); |
| 3717 | try { |
| 3718 | return phone.getMeid(); |
| 3719 | } finally { |
| 3720 | Binder.restoreCallingIdentity(identity); |
| 3721 | } |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 3722 | } |
| 3723 | |
| 3724 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3725 | public String getManufacturerCodeForSlot(int slotIndex) { |
| 3726 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3727 | String manufacturerCode = null; |
| 3728 | if (phone != null) { |
| 3729 | String meid = phone.getMeid(); |
Vala Zadeh | ab00555 | 2021-09-21 15:54:29 -0700 | [diff] [blame] | 3730 | try { |
| 3731 | manufacturerCode = |
| 3732 | meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH); |
| 3733 | } catch (IndexOutOfBoundsException e) { |
| 3734 | Log.e(LOG_TAG, "MEID length shorter than upper index."); |
| 3735 | return null; |
| 3736 | } |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3737 | } |
| 3738 | return manufacturerCode; |
| 3739 | } |
| 3740 | |
| 3741 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3742 | public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage, |
| 3743 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3744 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3745 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3746 | return null; |
| 3747 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3748 | int subId = phone.getSubId(); |
| 3749 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3750 | mApp, subId, callingPackage, callingFeatureId, |
| 3751 | "getDeviceSoftwareVersionForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3752 | return null; |
| 3753 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3754 | |
| 3755 | final long identity = Binder.clearCallingIdentity(); |
| 3756 | try { |
| 3757 | return phone.getDeviceSvn(); |
| 3758 | } finally { |
| 3759 | Binder.restoreCallingIdentity(identity); |
| 3760 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3761 | } |
| 3762 | |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3763 | @Override |
| 3764 | public int getSubscriptionCarrierId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3765 | final long identity = Binder.clearCallingIdentity(); |
| 3766 | try { |
| 3767 | final Phone phone = getPhone(subId); |
| 3768 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId(); |
| 3769 | } finally { |
| 3770 | Binder.restoreCallingIdentity(identity); |
| 3771 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3772 | } |
| 3773 | |
| 3774 | @Override |
| 3775 | public String getSubscriptionCarrierName(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3776 | final long identity = Binder.clearCallingIdentity(); |
| 3777 | try { |
| 3778 | final Phone phone = getPhone(subId); |
| 3779 | return phone == null ? null : phone.getCarrierName(); |
| 3780 | } finally { |
| 3781 | Binder.restoreCallingIdentity(identity); |
| 3782 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3783 | } |
| 3784 | |
calvinpan | ffe225e | 2018-11-01 19:43:06 +0800 | [diff] [blame] | 3785 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3786 | public int getSubscriptionSpecificCarrierId(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3787 | final long identity = Binder.clearCallingIdentity(); |
| 3788 | try { |
| 3789 | final Phone phone = getPhone(subId); |
| 3790 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3791 | : phone.getSpecificCarrierId(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3792 | } finally { |
| 3793 | Binder.restoreCallingIdentity(identity); |
| 3794 | } |
| 3795 | } |
| 3796 | |
| 3797 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3798 | public String getSubscriptionSpecificCarrierName(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3799 | final long identity = Binder.clearCallingIdentity(); |
| 3800 | try { |
| 3801 | final Phone phone = getPhone(subId); |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3802 | return phone == null ? null : phone.getSpecificCarrierName(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3803 | } finally { |
| 3804 | Binder.restoreCallingIdentity(identity); |
| 3805 | } |
| 3806 | } |
| 3807 | |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 3808 | @Override |
chen xu | 864e11c | 2018-12-06 22:10:03 -0800 | [diff] [blame] | 3809 | public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) { |
| 3810 | if (!isSubscriptionMccMnc) { |
| 3811 | enforceReadPrivilegedPermission("getCarrierIdFromMccMnc"); |
| 3812 | } |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 3813 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3814 | if (phone == null) { |
| 3815 | return TelephonyManager.UNKNOWN_CARRIER_ID; |
| 3816 | } |
| 3817 | final long identity = Binder.clearCallingIdentity(); |
| 3818 | try { |
| 3819 | return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc); |
| 3820 | } finally { |
| 3821 | Binder.restoreCallingIdentity(identity); |
| 3822 | } |
| 3823 | } |
| 3824 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3825 | // |
| 3826 | // Internal helper methods. |
| 3827 | // |
| 3828 | |
Sanket Padawe | ee13a9b | 2016-03-08 17:30:28 -0800 | [diff] [blame] | 3829 | /** |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3830 | * Make sure the caller is the calling package itself |
| 3831 | * |
| 3832 | * @throws SecurityException if the caller is not the calling package |
| 3833 | */ |
| 3834 | private void enforceCallingPackage(String callingPackage, int callingUid, String message) { |
| 3835 | int packageUid = -1; |
Grace Jia | dbefca0 | 2021-04-26 15:13:31 -0700 | [diff] [blame] | 3836 | PackageManager pm = mApp.getBaseContext().createContextAsUser( |
| 3837 | UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager(); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3838 | try { |
Grace Jia | dbefca0 | 2021-04-26 15:13:31 -0700 | [diff] [blame] | 3839 | packageUid = pm.getPackageUid(callingPackage, 0); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3840 | } catch (PackageManager.NameNotFoundException e) { |
| 3841 | // packageUid is -1 |
| 3842 | } |
| 3843 | if (packageUid != callingUid) { |
| 3844 | throw new SecurityException(message + ": Package " + callingPackage |
| 3845 | + " does not belong to " + callingUid); |
| 3846 | } |
| 3847 | } |
| 3848 | |
| 3849 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3850 | * Make sure the caller has the MODIFY_PHONE_STATE permission. |
| 3851 | * |
| 3852 | * @throws SecurityException if the caller does not have the required permission |
| 3853 | */ |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 3854 | @VisibleForTesting |
| 3855 | public void enforceModifyPermission() { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3856 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null); |
| 3857 | } |
| 3858 | |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 3859 | /** |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 3860 | * Make sure the caller has the READ_PHONE_STATE permission. |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 3861 | * |
| 3862 | * @throws SecurityException if the caller does not have the required permission |
| 3863 | */ |
| 3864 | @VisibleForTesting |
| 3865 | public void enforceReadPermission() { |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 3866 | enforceReadPermission(null); |
| 3867 | } |
| 3868 | |
| 3869 | /** |
| 3870 | * Make sure the caller has the READ_PHONE_STATE permissions. |
| 3871 | * |
| 3872 | * @throws SecurityException if the caller does not have the READ_PHONE_STATE permission. |
| 3873 | */ |
| 3874 | @VisibleForTesting |
| 3875 | public void enforceReadPermission(String msg) { |
| 3876 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, msg); |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 3877 | } |
| 3878 | |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 3879 | private void enforceActiveEmergencySessionPermission() { |
| 3880 | mApp.enforceCallingOrSelfPermission( |
| 3881 | android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null); |
| 3882 | } |
| 3883 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3884 | /** |
| 3885 | * Make sure the caller has the CALL_PHONE permission. |
| 3886 | * |
| 3887 | * @throws SecurityException if the caller does not have the required permission |
| 3888 | */ |
| 3889 | private void enforceCallPermission() { |
| 3890 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null); |
| 3891 | } |
| 3892 | |
paulhu | 5a77360 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 3893 | private void enforceSettingsPermission() { |
| 3894 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 3895 | } |
| 3896 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 3897 | private void enforceRebootPermission() { |
| 3898 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null); |
| 3899 | } |
| 3900 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3901 | private String createTelUrl(String number) { |
| 3902 | if (TextUtils.isEmpty(number)) { |
| 3903 | return null; |
| 3904 | } |
| 3905 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3906 | return "tel:" + number; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3907 | } |
| 3908 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3909 | private static void log(String msg) { |
Ling Ma | 83dc5ea | 2023-01-12 15:06:04 -0800 | [diff] [blame] | 3910 | Log.d(LOG_TAG, msg); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3911 | } |
| 3912 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3913 | private static void logv(String msg) { |
| 3914 | Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 3915 | } |
| 3916 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3917 | private static void loge(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3918 | Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 3919 | } |
| 3920 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3921 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3922 | public int getActivePhoneType() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3923 | return getActivePhoneTypeForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3924 | } |
| 3925 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3926 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3927 | public int getActivePhoneTypeForSlot(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3928 | final long identity = Binder.clearCallingIdentity(); |
| 3929 | try { |
| 3930 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3931 | if (phone == null) { |
| 3932 | return PhoneConstants.PHONE_TYPE_NONE; |
| 3933 | } else { |
| 3934 | return phone.getPhoneType(); |
| 3935 | } |
| 3936 | } finally { |
| 3937 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3938 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3939 | } |
| 3940 | |
| 3941 | /** |
| 3942 | * Returns the CDMA ERI icon index to display |
| 3943 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3944 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3945 | public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) { |
| 3946 | return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage, |
| 3947 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3948 | } |
| 3949 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3950 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3951 | public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage, |
| 3952 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3953 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3954 | mApp, subId, callingPackage, callingFeatureId, |
| 3955 | "getCdmaEriIconIndexForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3956 | return -1; |
| 3957 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3958 | |
| 3959 | final long identity = Binder.clearCallingIdentity(); |
| 3960 | try { |
| 3961 | final Phone phone = getPhone(subId); |
| 3962 | if (phone != null) { |
| 3963 | return phone.getCdmaEriIconIndex(); |
| 3964 | } else { |
| 3965 | return -1; |
| 3966 | } |
| 3967 | } finally { |
| 3968 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3969 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3970 | } |
| 3971 | |
| 3972 | /** |
| 3973 | * Returns the CDMA ERI icon mode, |
| 3974 | * 0 - ON |
| 3975 | * 1 - FLASHING |
| 3976 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3977 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3978 | public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) { |
| 3979 | return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 3980 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3981 | } |
| 3982 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3983 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3984 | public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage, |
| 3985 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3986 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3987 | mApp, subId, callingPackage, callingFeatureId, |
| 3988 | "getCdmaEriIconModeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3989 | return -1; |
| 3990 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3991 | |
| 3992 | final long identity = Binder.clearCallingIdentity(); |
| 3993 | try { |
| 3994 | final Phone phone = getPhone(subId); |
| 3995 | if (phone != null) { |
| 3996 | return phone.getCdmaEriIconMode(); |
| 3997 | } else { |
| 3998 | return -1; |
| 3999 | } |
| 4000 | } finally { |
| 4001 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4002 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4003 | } |
| 4004 | |
| 4005 | /** |
| 4006 | * Returns the CDMA ERI text, |
| 4007 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4008 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4009 | public String getCdmaEriText(String callingPackage, String callingFeatureId) { |
| 4010 | return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage, |
| 4011 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4012 | } |
| 4013 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4014 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4015 | public String getCdmaEriTextForSubscriber(int subId, String callingPackage, |
| 4016 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4017 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4018 | mApp, subId, callingPackage, callingFeatureId, |
| 4019 | "getCdmaEriIconTextForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4020 | return null; |
| 4021 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4022 | |
| 4023 | final long identity = Binder.clearCallingIdentity(); |
| 4024 | try { |
| 4025 | final Phone phone = getPhone(subId); |
| 4026 | if (phone != null) { |
| 4027 | return phone.getCdmaEriText(); |
| 4028 | } else { |
| 4029 | return null; |
| 4030 | } |
| 4031 | } finally { |
| 4032 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4033 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4034 | } |
| 4035 | |
| 4036 | /** |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 4037 | * Returns the CDMA MDN. |
| 4038 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4039 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 4040 | public String getCdmaMdn(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4041 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4042 | mApp, subId, "getCdmaMdn"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4043 | |
| 4044 | final long identity = Binder.clearCallingIdentity(); |
| 4045 | try { |
| 4046 | final Phone phone = getPhone(subId); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4047 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4048 | return phone.getLine1Number(); |
| 4049 | } else { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4050 | loge("getCdmaMdn: no phone found. Invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4051 | return null; |
| 4052 | } |
| 4053 | } finally { |
| 4054 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 4055 | } |
| 4056 | } |
| 4057 | |
| 4058 | /** |
| 4059 | * Returns the CDMA MIN. |
| 4060 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4061 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 4062 | public String getCdmaMin(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4063 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4064 | mApp, subId, "getCdmaMin"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4065 | |
| 4066 | final long identity = Binder.clearCallingIdentity(); |
| 4067 | try { |
| 4068 | final Phone phone = getPhone(subId); |
| 4069 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
| 4070 | return phone.getCdmaMin(); |
| 4071 | } else { |
| 4072 | return null; |
| 4073 | } |
| 4074 | } finally { |
| 4075 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 4076 | } |
| 4077 | } |
| 4078 | |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 4079 | @Override |
| 4080 | public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis, |
| 4081 | INumberVerificationCallback callback, String callingPackage) { |
| 4082 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 4083 | != PERMISSION_GRANTED) { |
| 4084 | throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission"); |
| 4085 | } |
| 4086 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 4087 | |
| 4088 | String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp); |
| 4089 | if (!TextUtils.equals(callingPackage, authorizedPackage)) { |
Hall Liu | b9d8feb | 2021-01-13 10:28:04 -0800 | [diff] [blame] | 4090 | throw new SecurityException("Calling package must be configured in the device config: " |
| 4091 | + "calling package: " + callingPackage |
| 4092 | + ", configured package: " + authorizedPackage); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 4093 | } |
| 4094 | |
| 4095 | if (range == null) { |
| 4096 | throw new NullPointerException("Range must be non-null"); |
| 4097 | } |
| 4098 | |
| 4099 | timeoutMillis = Math.min(timeoutMillis, |
Hall Liu | bd069e3 | 2019-02-28 18:56:30 -0800 | [diff] [blame] | 4100 | TelephonyManager.getMaxNumberVerificationTimeoutMillis()); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 4101 | |
| 4102 | NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis); |
| 4103 | } |
| 4104 | |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 4105 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4106 | * Returns true if CDMA provisioning needs to run. |
| 4107 | */ |
| 4108 | public boolean needsOtaServiceProvisioning() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4109 | final long identity = Binder.clearCallingIdentity(); |
| 4110 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4111 | return getDefaultPhone().needsOtaServiceProvisioning(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4112 | } finally { |
| 4113 | Binder.restoreCallingIdentity(identity); |
| 4114 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4115 | } |
| 4116 | |
| 4117 | /** |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 4118 | * Sets the voice mail number of a given subId. |
| 4119 | */ |
| 4120 | @Override |
| 4121 | public boolean setVoiceMailNumber(int subId, String alphaTag, String number) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 4122 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 4123 | mApp, subId, "setVoiceMailNumber"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4124 | |
| 4125 | final long identity = Binder.clearCallingIdentity(); |
| 4126 | try { |
| 4127 | Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER, |
| 4128 | new Pair<String, String>(alphaTag, number), new Integer(subId)); |
| 4129 | return success; |
| 4130 | } finally { |
| 4131 | Binder.restoreCallingIdentity(identity); |
| 4132 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 4133 | } |
| 4134 | |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 4135 | @Override |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 4136 | public Bundle getVisualVoicemailSettings(String callingPackage, int subId) { |
| 4137 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 4138 | TelecomManager tm = mApp.getSystemService(TelecomManager.class); |
| 4139 | String systemDialer = tm.getSystemDialerPackage(); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 4140 | if (!TextUtils.equals(callingPackage, systemDialer)) { |
| 4141 | throw new SecurityException("caller must be system dialer"); |
| 4142 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4143 | |
| 4144 | final long identity = Binder.clearCallingIdentity(); |
| 4145 | try { |
| 4146 | PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId); |
| 4147 | if (phoneAccountHandle == null) { |
| 4148 | return null; |
| 4149 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4150 | return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4151 | } finally { |
| 4152 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 4153 | } |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 4154 | } |
| 4155 | |
| 4156 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4157 | public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId, |
| 4158 | int subId) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 4159 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4160 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4161 | mApp, subId, callingPackage, callingFeatureId, |
| 4162 | "getVisualVoicemailPackageName")) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 4163 | return null; |
| 4164 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4165 | |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 4166 | final long identity = Binder.clearCallingIdentity(); |
| 4167 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4168 | return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName(); |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 4169 | } finally { |
| 4170 | Binder.restoreCallingIdentity(identity); |
| 4171 | } |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 4172 | } |
| 4173 | |
| 4174 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 4175 | public void enableVisualVoicemailSmsFilter(String callingPackage, int subId, |
| 4176 | VisualVoicemailSmsFilterSettings settings) { |
| 4177 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4178 | |
| 4179 | final long identity = Binder.clearCallingIdentity(); |
| 4180 | try { |
| 4181 | VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4182 | mApp, callingPackage, subId, settings); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4183 | } finally { |
| 4184 | Binder.restoreCallingIdentity(identity); |
| 4185 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 4186 | } |
| 4187 | |
| 4188 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 4189 | public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) { |
| 4190 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4191 | |
| 4192 | final long identity = Binder.clearCallingIdentity(); |
| 4193 | try { |
| 4194 | VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4195 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4196 | } finally { |
| 4197 | Binder.restoreCallingIdentity(identity); |
| 4198 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 4199 | } |
| 4200 | |
| 4201 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 4202 | public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings( |
| 4203 | String callingPackage, int subId) { |
| 4204 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4205 | |
| 4206 | final long identity = Binder.clearCallingIdentity(); |
| 4207 | try { |
| 4208 | return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4209 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4210 | } finally { |
| 4211 | Binder.restoreCallingIdentity(identity); |
| 4212 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 4213 | } |
| 4214 | |
| 4215 | @Override |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 4216 | public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4217 | enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4218 | |
| 4219 | final long identity = Binder.clearCallingIdentity(); |
| 4220 | try { |
| 4221 | return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4222 | mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4223 | } finally { |
| 4224 | Binder.restoreCallingIdentity(identity); |
| 4225 | } |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 4226 | } |
| 4227 | |
| 4228 | @Override |
Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 4229 | public void sendVisualVoicemailSmsForSubscriber(String callingPackage, |
| 4230 | String callingAttributionTag, int subId, String number, int port, String text, |
| 4231 | PendingIntent sentIntent) { |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 4232 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 4233 | enforceVisualVoicemailPackage(callingPackage, subId); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 4234 | enforceSendSmsPermission(); |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 4235 | SmsController smsController = PhoneFactory.getSmsController(); |
Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 4236 | smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag, |
| 4237 | subId, number, port, text, sentIntent); |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 4238 | } |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 4239 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 4240 | /** |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4241 | * Sets the voice activation state of a given subId. |
| 4242 | */ |
| 4243 | @Override |
| 4244 | public void setVoiceActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4245 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4246 | mApp, subId, "setVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4247 | |
| 4248 | final long identity = Binder.clearCallingIdentity(); |
| 4249 | try { |
| 4250 | final Phone phone = getPhone(subId); |
| 4251 | if (phone != null) { |
| 4252 | phone.setVoiceActivationState(activationState); |
| 4253 | } else { |
| 4254 | loge("setVoiceActivationState fails with invalid subId: " + subId); |
| 4255 | } |
| 4256 | } finally { |
| 4257 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4258 | } |
| 4259 | } |
| 4260 | |
| 4261 | /** |
| 4262 | * Sets the data activation state of a given subId. |
| 4263 | */ |
| 4264 | @Override |
| 4265 | public void setDataActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4266 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4267 | mApp, subId, "setDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4268 | |
| 4269 | final long identity = Binder.clearCallingIdentity(); |
| 4270 | try { |
| 4271 | final Phone phone = getPhone(subId); |
| 4272 | if (phone != null) { |
| 4273 | phone.setDataActivationState(activationState); |
| 4274 | } else { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 4275 | loge("setDataActivationState fails with invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4276 | } |
| 4277 | } finally { |
| 4278 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4279 | } |
| 4280 | } |
| 4281 | |
| 4282 | /** |
| 4283 | * Returns the voice activation state of a given subId. |
| 4284 | */ |
| 4285 | @Override |
| 4286 | public int getVoiceActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4287 | enforceReadPrivilegedPermission("getVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4288 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4289 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4290 | final long identity = Binder.clearCallingIdentity(); |
| 4291 | try { |
| 4292 | if (phone != null) { |
| 4293 | return phone.getVoiceActivationState(); |
| 4294 | } else { |
| 4295 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 4296 | } |
| 4297 | } finally { |
| 4298 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4299 | } |
| 4300 | } |
| 4301 | |
| 4302 | /** |
| 4303 | * Returns the data activation state of a given subId. |
| 4304 | */ |
| 4305 | @Override |
| 4306 | public int getDataActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4307 | enforceReadPrivilegedPermission("getDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4308 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4309 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4310 | final long identity = Binder.clearCallingIdentity(); |
| 4311 | try { |
| 4312 | if (phone != null) { |
| 4313 | return phone.getDataActivationState(); |
| 4314 | } else { |
| 4315 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 4316 | } |
| 4317 | } finally { |
| 4318 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4319 | } |
| 4320 | } |
| 4321 | |
| 4322 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4323 | * Returns the unread count of voicemails for a subId |
| 4324 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4325 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4326 | public int getVoiceMessageCountForSubscriber(int subId, String callingPackage, |
| 4327 | String callingFeatureId) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 4328 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4329 | mApp, subId, callingPackage, callingFeatureId, |
| 4330 | "getVoiceMessageCountForSubscriber")) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 4331 | return 0; |
| 4332 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4333 | final long identity = Binder.clearCallingIdentity(); |
| 4334 | try { |
| 4335 | final Phone phone = getPhone(subId); |
| 4336 | if (phone != null) { |
| 4337 | return phone.getVoiceMessageCount(); |
| 4338 | } else { |
| 4339 | return 0; |
| 4340 | } |
| 4341 | } finally { |
| 4342 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4343 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4344 | } |
| 4345 | |
| 4346 | /** |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 4347 | * returns true, if the device is in a state where both voice and data |
| 4348 | * are supported simultaneously. This can change based on location or network condition. |
| 4349 | */ |
| 4350 | @Override |
| 4351 | public boolean isConcurrentVoiceAndDataAllowed(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4352 | final long identity = Binder.clearCallingIdentity(); |
| 4353 | try { |
| 4354 | final Phone phone = getPhone(subId); |
| 4355 | return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed()); |
| 4356 | } finally { |
| 4357 | Binder.restoreCallingIdentity(identity); |
| 4358 | } |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 4359 | } |
| 4360 | |
| 4361 | /** |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4362 | * Send the dialer code if called from the current default dialer or the caller has |
| 4363 | * carrier privilege. |
| 4364 | * @param inputCode The dialer code to send |
| 4365 | */ |
| 4366 | @Override |
| 4367 | public void sendDialerSpecialCode(String callingPackage, String inputCode) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4368 | final Phone defaultPhone = getDefaultPhone(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4369 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 4370 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 4371 | String defaultDialer = tm.getDefaultDialerPackage(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4372 | if (!TextUtils.equals(callingPackage, defaultDialer)) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 4373 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4374 | getDefaultSubscription(), "sendDialerSpecialCode"); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4375 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4376 | |
| 4377 | final long identity = Binder.clearCallingIdentity(); |
| 4378 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4379 | defaultPhone.sendDialerSpecialCode(inputCode); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4380 | } finally { |
| 4381 | Binder.restoreCallingIdentity(identity); |
| 4382 | } |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4383 | } |
| 4384 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 4385 | @Override |
| 4386 | public int getNetworkSelectionMode(int subId) { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 4387 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4388 | .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 4389 | mApp, subId, "getNetworkSelectionMode"); |
| 4390 | final long identity = Binder.clearCallingIdentity(); |
| 4391 | try { |
| 4392 | if (!isActiveSubscription(subId)) { |
| 4393 | return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 4394 | } |
| 4395 | return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId); |
| 4396 | } finally { |
| 4397 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 4398 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 4399 | } |
| 4400 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4401 | @Override |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 4402 | public boolean isInEmergencySmsMode() { |
| 4403 | enforceReadPrivilegedPermission("isInEmergencySmsMode"); |
| 4404 | final long identity = Binder.clearCallingIdentity(); |
| 4405 | try { |
| 4406 | for (Phone phone : PhoneFactory.getPhones()) { |
| 4407 | if (phone.isInEmergencySmsMode()) { |
| 4408 | return true; |
| 4409 | } |
| 4410 | } |
| 4411 | } finally { |
| 4412 | Binder.restoreCallingIdentity(identity); |
| 4413 | } |
| 4414 | return false; |
| 4415 | } |
| 4416 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4417 | /** |
| 4418 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4419 | * @param subId The subscription to use to check the configuration. |
| 4420 | * @param c The callback that will be used to send the result. |
| 4421 | */ |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 4422 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4423 | public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c) |
| 4424 | throws RemoteException { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4425 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4426 | mApp, subId, "registerImsRegistrationCallback"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4427 | |
| 4428 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4429 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4430 | "IMS not available on device."); |
| 4431 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4432 | final long token = Binder.clearCallingIdentity(); |
| 4433 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4434 | int slotId = getSlotIndexOrException(subId); |
| 4435 | verifyImsMmTelConfiguredOrThrow(slotId); |
joonhunshin | 49f0aed | 2022-08-05 08:33:05 +0000 | [diff] [blame] | 4436 | |
| 4437 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4438 | if (controller != null) { |
| 4439 | ImsManager imsManager = controller.getImsManager(subId); |
| 4440 | if (imsManager != null) { |
| 4441 | imsManager.addRegistrationCallbackForSubscription(c, subId); |
| 4442 | } else { |
| 4443 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE); |
| 4444 | } |
| 4445 | } else { |
| 4446 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION); |
| 4447 | } |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4448 | } catch (ImsException e) { |
| 4449 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4450 | } finally { |
| 4451 | Binder.restoreCallingIdentity(token); |
| 4452 | } |
| 4453 | } |
| 4454 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4455 | /** |
| 4456 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4457 | * @param subId The subscription to use to check the configuration. |
| 4458 | * @param c The callback that will be used to send the result. |
| 4459 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4460 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4461 | public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4462 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4463 | mApp, subId, "unregisterImsRegistrationCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4464 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4465 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4466 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4467 | final long token = Binder.clearCallingIdentity(); |
joonhunshin | 49f0aed | 2022-08-05 08:33:05 +0000 | [diff] [blame] | 4468 | |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4469 | try { |
joonhunshin | 49f0aed | 2022-08-05 08:33:05 +0000 | [diff] [blame] | 4470 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4471 | if (controller != null) { |
| 4472 | ImsManager imsManager = controller.getImsManager(subId); |
| 4473 | if (imsManager != null) { |
| 4474 | imsManager.removeRegistrationCallbackForSubscription(c, subId); |
| 4475 | } else { |
| 4476 | Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId |
| 4477 | + "is inactive, ignoring unregister."); |
| 4478 | // If the ImsManager is not valid, just return, since the callback |
| 4479 | // will already have been removed internally. |
| 4480 | } |
| 4481 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4482 | } finally { |
| 4483 | Binder.restoreCallingIdentity(token); |
| 4484 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4485 | } |
| 4486 | |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 4487 | /** |
| 4488 | * Get the IMS service registration state for the MmTelFeature associated with this sub id. |
| 4489 | */ |
| 4490 | @Override |
| 4491 | public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) { |
| 4492 | enforceReadPrivilegedPermission("getImsMmTelRegistrationState"); |
| 4493 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4494 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4495 | "IMS not available on device."); |
| 4496 | } |
| 4497 | final long token = Binder.clearCallingIdentity(); |
| 4498 | try { |
| 4499 | Phone phone = getPhone(subId); |
| 4500 | if (phone == null) { |
| 4501 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 4502 | + subId + "'"); |
| 4503 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 4504 | } |
| 4505 | phone.getImsRegistrationState(regState -> { |
| 4506 | try { |
| 4507 | consumer.accept((regState == null) |
| 4508 | ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState); |
| 4509 | } catch (RemoteException e) { |
| 4510 | // Ignore if the remote process is no longer available to call back. |
| 4511 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 4512 | } |
| 4513 | }); |
| 4514 | } finally { |
| 4515 | Binder.restoreCallingIdentity(token); |
| 4516 | } |
| 4517 | } |
| 4518 | |
| 4519 | /** |
| 4520 | * Get the transport type for the IMS service registration state. |
| 4521 | */ |
| 4522 | @Override |
| 4523 | public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4524 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4525 | mApp, subId, "getImsMmTelRegistrationTransportType"); |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 4526 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4527 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4528 | "IMS not available on device."); |
| 4529 | } |
| 4530 | final long token = Binder.clearCallingIdentity(); |
| 4531 | try { |
| 4532 | Phone phone = getPhone(subId); |
| 4533 | if (phone == null) { |
| 4534 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 4535 | + subId + "'"); |
| 4536 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 4537 | } |
| 4538 | phone.getImsRegistrationTech(regTech -> { |
| 4539 | // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager |
| 4540 | int regTechConverted = (regTech == null) |
| 4541 | ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech; |
| 4542 | regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get( |
| 4543 | regTechConverted); |
| 4544 | try { |
| 4545 | consumer.accept(regTechConverted); |
| 4546 | } catch (RemoteException e) { |
| 4547 | // Ignore if the remote process is no longer available to call back. |
| 4548 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 4549 | } |
| 4550 | }); |
| 4551 | } finally { |
| 4552 | Binder.restoreCallingIdentity(token); |
| 4553 | } |
| 4554 | } |
| 4555 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4556 | /** |
| 4557 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4558 | * @param subId The subscription to use to check the configuration. |
| 4559 | * @param c The callback that will be used to send the result. |
| 4560 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4561 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4562 | public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) |
| 4563 | throws RemoteException { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4564 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4565 | mApp, subId, "registerMmTelCapabilityCallback"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4566 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4567 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4568 | "IMS not available on device."); |
| 4569 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4570 | final long token = Binder.clearCallingIdentity(); |
| 4571 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4572 | int slotId = getSlotIndexOrException(subId); |
| 4573 | verifyImsMmTelConfiguredOrThrow(slotId); |
Hwangoo Park | 8646b0d | 2023-01-13 02:42:34 +0000 | [diff] [blame] | 4574 | |
| 4575 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4576 | if (controller != null) { |
| 4577 | ImsManager imsManager = controller.getImsManager(subId); |
| 4578 | if (imsManager != null) { |
| 4579 | imsManager.addCapabilitiesCallbackForSubscription(c, subId); |
| 4580 | } else { |
| 4581 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE); |
| 4582 | } |
| 4583 | } else { |
| 4584 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION); |
| 4585 | } |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4586 | } catch (ImsException e) { |
| 4587 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4588 | } finally { |
| 4589 | Binder.restoreCallingIdentity(token); |
| 4590 | } |
| 4591 | } |
| 4592 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4593 | /** |
| 4594 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4595 | * @param subId The subscription to use to check the configuration. |
| 4596 | * @param c The callback that will be used to send the result. |
| 4597 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4598 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4599 | public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4600 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4601 | mApp, subId, "unregisterMmTelCapabilityCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4602 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4603 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4604 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4605 | |
| 4606 | final long token = Binder.clearCallingIdentity(); |
| 4607 | try { |
Hwangoo Park | 8646b0d | 2023-01-13 02:42:34 +0000 | [diff] [blame] | 4608 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4609 | if (controller != null) { |
| 4610 | ImsManager imsManager = controller.getImsManager(subId); |
| 4611 | if (imsManager != null) { |
| 4612 | imsManager.removeCapabilitiesCallbackForSubscription(c, subId); |
| 4613 | } else { |
| 4614 | Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId |
| 4615 | + " is inactive, ignoring unregister."); |
| 4616 | // If the ImsManager is not valid, just return, since the callback |
| 4617 | // will already have been removed internally. |
| 4618 | } |
| 4619 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4620 | } finally { |
| 4621 | Binder.restoreCallingIdentity(token); |
| 4622 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4623 | } |
| 4624 | |
| 4625 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4626 | public boolean isCapable(int subId, int capability, int regTech) { |
| 4627 | enforceReadPrivilegedPermission("isCapable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4628 | final long token = Binder.clearCallingIdentity(); |
| 4629 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4630 | int slotId = getSlotIndexOrException(subId); |
| 4631 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 4632 | return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech); |
| 4633 | } catch (com.android.ims.ImsException e) { |
| 4634 | Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage()); |
| 4635 | return false; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4636 | } catch (ImsException e) { |
Brad Ebinger | 6b5ac22 | 2019-02-04 14:36:52 -0800 | [diff] [blame] | 4637 | Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false."); |
| 4638 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4639 | } finally { |
| 4640 | Binder.restoreCallingIdentity(token); |
| 4641 | } |
| 4642 | } |
| 4643 | |
| 4644 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4645 | public boolean isAvailable(int subId, int capability, int regTech) { |
| 4646 | enforceReadPrivilegedPermission("isAvailable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4647 | final long token = Binder.clearCallingIdentity(); |
| 4648 | try { |
| 4649 | Phone phone = getPhone(subId); |
| 4650 | if (phone == null) return false; |
| 4651 | return phone.isImsCapabilityAvailable(capability, regTech); |
Daniel Bright | 5e40e4e | 2020-03-11 16:35:39 -0700 | [diff] [blame] | 4652 | } catch (com.android.ims.ImsException e) { |
| 4653 | Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage()); |
| 4654 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4655 | } finally { |
| 4656 | Binder.restoreCallingIdentity(token); |
| 4657 | } |
| 4658 | } |
| 4659 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4660 | /** |
| 4661 | * Determines if the MmTel feature capability is supported by the carrier configuration for this |
| 4662 | * subscription. |
| 4663 | * @param subId The subscription to use to check the configuration. |
| 4664 | * @param callback The callback that will be used to send the result. |
| 4665 | * @param capability The MmTelFeature capability that will be used to send the result. |
| 4666 | * @param transportType The transport type of the MmTelFeature capability. |
| 4667 | */ |
| 4668 | @Override |
| 4669 | public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability, |
| 4670 | int transportType) { |
| 4671 | enforceReadPrivilegedPermission("isMmTelCapabilitySupported"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4672 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4673 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4674 | "IMS not available on device."); |
| 4675 | } |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4676 | final long token = Binder.clearCallingIdentity(); |
| 4677 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4678 | int slotId = getSlotIndex(subId); |
| 4679 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4680 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '" |
| 4681 | + subId + "'"); |
| 4682 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 4683 | } |
| 4684 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 4685 | ImsManager.getInstance(mApp, slotId).isSupported(capability, |
| 4686 | transportType, aBoolean -> { |
| 4687 | try { |
| 4688 | callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0)); |
| 4689 | } catch (RemoteException e) { |
| 4690 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not " |
| 4691 | + "running. Ignore"); |
| 4692 | } |
| 4693 | }); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4694 | } catch (ImsException e) { |
| 4695 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4696 | } finally { |
| 4697 | Binder.restoreCallingIdentity(token); |
| 4698 | } |
| 4699 | } |
| 4700 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4701 | /** |
| 4702 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4703 | * @param subId The subscription to use to check the configuration. |
| 4704 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4705 | @Override |
| 4706 | public boolean isAdvancedCallingSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4707 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4708 | mApp, subId, "isAdvancedCallingSettingEnabled"); |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4709 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4710 | final long token = Binder.clearCallingIdentity(); |
| 4711 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4712 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4713 | // 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] | 4714 | return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4715 | } catch (ImsException e) { |
| 4716 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4717 | } finally { |
| 4718 | Binder.restoreCallingIdentity(token); |
| 4719 | } |
| 4720 | } |
| 4721 | |
| 4722 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4723 | public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4724 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4725 | "setAdvancedCallingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4726 | final long identity = Binder.clearCallingIdentity(); |
| 4727 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4728 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4729 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4730 | // 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] | 4731 | ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4732 | } catch (ImsException e) { |
| 4733 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4734 | } finally { |
| 4735 | Binder.restoreCallingIdentity(identity); |
| 4736 | } |
| 4737 | } |
| 4738 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4739 | /** |
| 4740 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4741 | * @param subId The subscription to use to check the configuration. |
| 4742 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4743 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4744 | public boolean isVtSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4745 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4746 | mApp, subId, "isVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4747 | final long identity = Binder.clearCallingIdentity(); |
| 4748 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4749 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4750 | // 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] | 4751 | return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4752 | } catch (ImsException e) { |
| 4753 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4754 | } finally { |
| 4755 | Binder.restoreCallingIdentity(identity); |
| 4756 | } |
| 4757 | } |
| 4758 | |
| 4759 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4760 | public void setVtSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4761 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4762 | "setVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4763 | final long identity = Binder.clearCallingIdentity(); |
| 4764 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4765 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4766 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4767 | // 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] | 4768 | ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4769 | } catch (ImsException e) { |
| 4770 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4771 | } finally { |
| 4772 | Binder.restoreCallingIdentity(identity); |
| 4773 | } |
| 4774 | } |
| 4775 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4776 | /** |
| 4777 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4778 | * @param subId The subscription to use to check the configuration. |
| 4779 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4780 | @Override |
| 4781 | public boolean isVoWiFiSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4782 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4783 | mApp, subId, "isVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4784 | final long identity = Binder.clearCallingIdentity(); |
| 4785 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4786 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4787 | // 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] | 4788 | return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4789 | } catch (ImsException e) { |
| 4790 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4791 | } finally { |
| 4792 | Binder.restoreCallingIdentity(identity); |
| 4793 | } |
| 4794 | } |
| 4795 | |
| 4796 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4797 | public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4798 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4799 | "setVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4800 | final long identity = Binder.clearCallingIdentity(); |
| 4801 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4802 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4803 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4804 | // 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] | 4805 | ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4806 | } catch (ImsException e) { |
| 4807 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4808 | } finally { |
| 4809 | Binder.restoreCallingIdentity(identity); |
| 4810 | } |
| 4811 | } |
| 4812 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4813 | /** |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 4814 | * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not |
| 4815 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4816 | * @param subId The subscription to use to check the configuration. |
| 4817 | */ |
| 4818 | @Override |
| 4819 | public boolean isCrossSimCallingEnabledByUser(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4820 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 4821 | mApp, subId, "isCrossSimCallingEnabledByUser"); |
| 4822 | final long identity = Binder.clearCallingIdentity(); |
| 4823 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4824 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4825 | // 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] | 4826 | return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser(); |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 4827 | } catch (ImsException e) { |
| 4828 | throw new ServiceSpecificException(e.getCode()); |
| 4829 | } finally { |
| 4830 | Binder.restoreCallingIdentity(identity); |
| 4831 | } |
| 4832 | } |
| 4833 | |
| 4834 | /** |
| 4835 | * Sets the user's setting for whether or not Voice over Cross SIM is enabled. |
| 4836 | * Requires MODIFY_PHONE_STATE permission. |
| 4837 | * @param subId The subscription to use to check the configuration. |
| 4838 | * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled, |
| 4839 | * false otherwise |
| 4840 | */ |
| 4841 | @Override |
| 4842 | public void setCrossSimCallingEnabled(int subId, boolean isEnabled) { |
| 4843 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4844 | "setCrossSimCallingEnabled"); |
| 4845 | final long identity = Binder.clearCallingIdentity(); |
| 4846 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4847 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4848 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4849 | // 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] | 4850 | ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled); |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 4851 | } catch (ImsException e) { |
| 4852 | throw new ServiceSpecificException(e.getCode()); |
| 4853 | } finally { |
| 4854 | Binder.restoreCallingIdentity(identity); |
| 4855 | } |
| 4856 | } |
| 4857 | |
| 4858 | /** |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4859 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4860 | * @param subId The subscription to use to check the configuration. |
| 4861 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4862 | @Override |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4863 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4864 | public boolean isVoWiFiRoamingSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4865 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4866 | mApp, subId, "isVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4867 | final long identity = Binder.clearCallingIdentity(); |
| 4868 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4869 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4870 | // 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] | 4871 | return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4872 | } catch (ImsException e) { |
| 4873 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4874 | } finally { |
| 4875 | Binder.restoreCallingIdentity(identity); |
| 4876 | } |
| 4877 | } |
| 4878 | |
| 4879 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4880 | public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4881 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4882 | "setVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4883 | final long identity = Binder.clearCallingIdentity(); |
| 4884 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4885 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4886 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4887 | // 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] | 4888 | ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4889 | } catch (ImsException e) { |
| 4890 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4891 | } finally { |
| 4892 | Binder.restoreCallingIdentity(identity); |
| 4893 | } |
| 4894 | } |
| 4895 | |
| 4896 | @Override |
| 4897 | public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) { |
| 4898 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4899 | "setVoWiFiNonPersistent"); |
| 4900 | final long identity = Binder.clearCallingIdentity(); |
| 4901 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4902 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4903 | // This setting will be ignored if the ImsService isn't up. |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4904 | ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4905 | } catch (ImsException e) { |
| 4906 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4907 | } finally { |
| 4908 | Binder.restoreCallingIdentity(identity); |
| 4909 | } |
| 4910 | } |
| 4911 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4912 | /** |
| 4913 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4914 | * @param subId The subscription to use to check the configuration. |
| 4915 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4916 | @Override |
| 4917 | public int getVoWiFiModeSetting(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4918 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4919 | mApp, subId, "getVoWiFiModeSetting"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4920 | final long identity = Binder.clearCallingIdentity(); |
| 4921 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4922 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4923 | // 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] | 4924 | return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4925 | } catch (ImsException e) { |
| 4926 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4927 | } finally { |
| 4928 | Binder.restoreCallingIdentity(identity); |
| 4929 | } |
| 4930 | } |
| 4931 | |
| 4932 | @Override |
| 4933 | public void setVoWiFiModeSetting(int subId, int mode) { |
| 4934 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4935 | "setVoWiFiModeSetting"); |
| 4936 | final long identity = Binder.clearCallingIdentity(); |
| 4937 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4938 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4939 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4940 | // 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] | 4941 | ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4942 | } catch (ImsException e) { |
| 4943 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4944 | } finally { |
| 4945 | Binder.restoreCallingIdentity(identity); |
| 4946 | } |
| 4947 | } |
| 4948 | |
| 4949 | @Override |
| 4950 | public int getVoWiFiRoamingModeSetting(int subId) { |
| 4951 | enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting"); |
| 4952 | final long identity = Binder.clearCallingIdentity(); |
| 4953 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4954 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4955 | // 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] | 4956 | return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4957 | } catch (ImsException e) { |
| 4958 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4959 | } finally { |
| 4960 | Binder.restoreCallingIdentity(identity); |
| 4961 | } |
| 4962 | } |
| 4963 | |
| 4964 | @Override |
| 4965 | public void setVoWiFiRoamingModeSetting(int subId, int mode) { |
| 4966 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4967 | "setVoWiFiRoamingModeSetting"); |
| 4968 | final long identity = Binder.clearCallingIdentity(); |
| 4969 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4970 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4971 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4972 | // 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] | 4973 | ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4974 | } catch (ImsException e) { |
| 4975 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4976 | } finally { |
| 4977 | Binder.restoreCallingIdentity(identity); |
| 4978 | } |
| 4979 | } |
| 4980 | |
| 4981 | @Override |
| 4982 | public void setRttCapabilitySetting(int subId, boolean isEnabled) { |
| 4983 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4984 | "setRttCapabilityEnabled"); |
| 4985 | final long identity = Binder.clearCallingIdentity(); |
| 4986 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4987 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4988 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4989 | // 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] | 4990 | ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4991 | } catch (ImsException e) { |
| 4992 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4993 | } finally { |
| 4994 | Binder.restoreCallingIdentity(identity); |
| 4995 | } |
| 4996 | } |
| 4997 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4998 | /** |
| 4999 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 5000 | * @param subId The subscription to use to check the configuration. |
| 5001 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5002 | @Override |
| 5003 | public boolean isTtyOverVolteEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 5004 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 5005 | mApp, subId, "isTtyOverVolteEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5006 | final long identity = Binder.clearCallingIdentity(); |
| 5007 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5008 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5009 | // 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] | 5010 | return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5011 | } catch (ImsException e) { |
| 5012 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5013 | } finally { |
| 5014 | Binder.restoreCallingIdentity(identity); |
| 5015 | } |
| 5016 | } |
| 5017 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5018 | @Override |
| 5019 | public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 5020 | enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5021 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5022 | final long identity = Binder.clearCallingIdentity(); |
| 5023 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 5024 | if (!isImsAvailableOnDevice()) { |
| 5025 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 5026 | "IMS not available on device."); |
| 5027 | } |
| 5028 | int slotId = getSlotIndexOrException(subId); |
| 5029 | verifyImsMmTelConfiguredOrThrow(slotId); |
Hwangoo Park | 8646b0d | 2023-01-13 02:42:34 +0000 | [diff] [blame] | 5030 | |
| 5031 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 5032 | if (controller != null) { |
| 5033 | ImsManager imsManager = controller.getImsManager(subId); |
| 5034 | if (imsManager != null) { |
| 5035 | imsManager.addProvisioningCallbackForSubscription(callback, subId); |
| 5036 | } else { |
| 5037 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE); |
| 5038 | } |
| 5039 | } else { |
| 5040 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION); |
| 5041 | } |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5042 | } catch (ImsException e) { |
| 5043 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5044 | } finally { |
| 5045 | Binder.restoreCallingIdentity(identity); |
| 5046 | } |
| 5047 | } |
| 5048 | |
| 5049 | @Override |
| 5050 | public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 5051 | enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5052 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5053 | final long identity = Binder.clearCallingIdentity(); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 5054 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5055 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 5056 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5057 | try { |
Hwangoo Park | 8646b0d | 2023-01-13 02:42:34 +0000 | [diff] [blame] | 5058 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 5059 | if (controller != null) { |
| 5060 | ImsManager imsManager = controller.getImsManager(subId); |
| 5061 | if (imsManager != null) { |
| 5062 | imsManager.removeProvisioningCallbackForSubscription(callback, subId); |
| 5063 | } else { |
| 5064 | Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId |
| 5065 | + " is inactive, ignoring unregister."); |
| 5066 | // If the ImsManager is not valid, just return, since the callback will already |
| 5067 | // have been removed internally. |
| 5068 | } |
| 5069 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5070 | } finally { |
| 5071 | Binder.restoreCallingIdentity(identity); |
| 5072 | } |
| 5073 | } |
| 5074 | |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5075 | @Override |
| 5076 | public void registerFeatureProvisioningChangedCallback(int subId, |
| 5077 | IFeatureProvisioningCallback callback) { |
| 5078 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5079 | mApp, subId, "registerFeatureProvisioningChangedCallback"); |
| 5080 | |
| 5081 | final long identity = Binder.clearCallingIdentity(); |
| 5082 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5083 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 5084 | } |
| 5085 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5086 | try { |
| 5087 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5088 | if (controller == null) { |
| 5089 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 5090 | "Device does not support IMS"); |
| 5091 | } |
| 5092 | controller.addFeatureProvisioningChangedCallback(subId, callback); |
| 5093 | } finally { |
| 5094 | Binder.restoreCallingIdentity(identity); |
| 5095 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5096 | } |
| 5097 | |
| 5098 | @Override |
| 5099 | public void unregisterFeatureProvisioningChangedCallback(int subId, |
| 5100 | IFeatureProvisioningCallback callback) { |
| 5101 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5102 | mApp, subId, "unregisterFeatureProvisioningChangedCallback"); |
| 5103 | |
| 5104 | final long identity = Binder.clearCallingIdentity(); |
| 5105 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5106 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 5107 | } |
| 5108 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5109 | try { |
| 5110 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5111 | if (controller == null) { |
| 5112 | loge("unregisterFeatureProvisioningChangedCallback: Device does not support IMS"); |
| 5113 | return; |
| 5114 | } |
| 5115 | controller.removeFeatureProvisioningChangedCallback(subId, callback); |
| 5116 | } finally { |
| 5117 | Binder.restoreCallingIdentity(identity); |
| 5118 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5119 | } |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5120 | |
| 5121 | private void checkModifyPhoneStatePermission(int subId, String message) { |
| 5122 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5123 | message); |
| 5124 | } |
| 5125 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5126 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5127 | public void setRcsProvisioningStatusForCapability(int subId, int capability, int tech, |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5128 | boolean isProvisioned) { |
| 5129 | checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability"); |
| 5130 | |
| 5131 | final long identity = Binder.clearCallingIdentity(); |
| 5132 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5133 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5134 | if (controller == null) { |
| 5135 | loge("setRcsProvisioningStatusForCapability: Device does not support IMS"); |
| 5136 | return; |
| 5137 | } |
| 5138 | controller.setRcsProvisioningStatusForCapability( |
| 5139 | subId, capability, tech, isProvisioned); |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5140 | } finally { |
| 5141 | Binder.restoreCallingIdentity(identity); |
| 5142 | } |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5143 | } |
| 5144 | |
| 5145 | |
| 5146 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5147 | public boolean getRcsProvisioningStatusForCapability(int subId, int capability, int tech) { |
| 5148 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5149 | mApp, subId, "getRcsProvisioningStatusForCapability"); |
| 5150 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5151 | final long identity = Binder.clearCallingIdentity(); |
| 5152 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5153 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5154 | if (controller == null) { |
| 5155 | loge("getRcsProvisioningStatusForCapability: Device does not support IMS"); |
| 5156 | |
| 5157 | // device does not support IMS, this method will return true always. |
| 5158 | return true; |
| 5159 | } |
| 5160 | return controller.getRcsProvisioningStatusForCapability(subId, capability, tech); |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5161 | } finally { |
| 5162 | Binder.restoreCallingIdentity(identity); |
| 5163 | } |
| 5164 | } |
| 5165 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5166 | @Override |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5167 | public void setImsProvisioningStatusForCapability(int subId, int capability, int tech, |
| 5168 | boolean isProvisioned) { |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5169 | checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5170 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5171 | final long identity = Binder.clearCallingIdentity(); |
| 5172 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5173 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5174 | if (controller == null) { |
| 5175 | loge("setImsProvisioningStatusForCapability: Device does not support IMS"); |
| 5176 | return; |
| 5177 | } |
| 5178 | controller.setImsProvisioningStatusForCapability( |
| 5179 | subId, capability, tech, isProvisioned); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5180 | } finally { |
| 5181 | Binder.restoreCallingIdentity(identity); |
| 5182 | } |
| 5183 | } |
| 5184 | |
| 5185 | @Override |
| 5186 | public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) { |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5187 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5188 | mApp, subId, "getProvisioningStatusForCapability"); |
| 5189 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5190 | final long identity = Binder.clearCallingIdentity(); |
| 5191 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5192 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5193 | if (controller == null) { |
| 5194 | loge("getImsProvisioningStatusForCapability: Device does not support IMS"); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5195 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5196 | // device does not support IMS, this method will return true always. |
| 5197 | return true; |
| 5198 | } |
| 5199 | return controller.getImsProvisioningStatusForCapability(subId, capability, tech); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5200 | } finally { |
| 5201 | Binder.restoreCallingIdentity(identity); |
| 5202 | } |
| 5203 | } |
| 5204 | |
| 5205 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5206 | public boolean isProvisioningRequiredForCapability(int subId, int capability, int tech) { |
| 5207 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5208 | mApp, subId, "isProvisioningRequiredForCapability"); |
| 5209 | |
| 5210 | final long identity = Binder.clearCallingIdentity(); |
| 5211 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5212 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5213 | if (controller == null) { |
| 5214 | loge("isProvisioningRequiredForCapability: Device does not support IMS"); |
| 5215 | |
| 5216 | // device does not support IMS, this method will return false |
| 5217 | return false; |
| 5218 | } |
| 5219 | return controller.isImsProvisioningRequiredForCapability(subId, capability, tech); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5220 | } finally { |
| 5221 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5222 | } |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5223 | } |
| 5224 | |
| 5225 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5226 | public boolean isRcsProvisioningRequiredForCapability(int subId, int capability, int tech) { |
| 5227 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5228 | mApp, subId, "isProvisioningRequiredForCapability"); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5229 | |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5230 | final long identity = Binder.clearCallingIdentity(); |
| 5231 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5232 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5233 | if (controller == null) { |
| 5234 | loge("isRcsProvisioningRequiredForCapability: Device does not support IMS"); |
| 5235 | |
| 5236 | // device does not support IMS, this method will return false |
| 5237 | return false; |
| 5238 | } |
| 5239 | return controller.isRcsProvisioningRequiredForCapability(subId, capability, tech); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5240 | } finally { |
| 5241 | Binder.restoreCallingIdentity(identity); |
| 5242 | } |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5243 | } |
| 5244 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5245 | @Override |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5246 | public int getImsProvisioningInt(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5247 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5248 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 5249 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5250 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5251 | mApp, subId, "getImsProvisioningInt"); |
| 5252 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5253 | final long identity = Binder.clearCallingIdentity(); |
| 5254 | try { |
| 5255 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5256 | int slotId = getSlotIndex(subId); |
| 5257 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5258 | Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '" |
| 5259 | + subId + "' for key:" + key); |
| 5260 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
| 5261 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5262 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5263 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5264 | if (controller == null) { |
| 5265 | loge("getImsProvisioningInt: Device does not support IMS"); |
| 5266 | |
| 5267 | // device does not support IMS, this method will return CONFIG_RESULT_UNKNOWN. |
| 5268 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
| 5269 | } |
| 5270 | int retVal = controller.getProvisioningValue(subId, key); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5271 | if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) { |
| 5272 | return retVal; |
| 5273 | } |
| 5274 | |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5275 | return ImsManager.getInstance(mApp, slotId).getConfigInt(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5276 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5277 | Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '" |
| 5278 | + subId + "' for key:" + key); |
| 5279 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5280 | } finally { |
| 5281 | Binder.restoreCallingIdentity(identity); |
| 5282 | } |
| 5283 | } |
| 5284 | |
| 5285 | @Override |
| 5286 | public String getImsProvisioningString(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5287 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5288 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 5289 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5290 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5291 | mApp, subId, "getImsProvisioningString"); |
| 5292 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5293 | final long identity = Binder.clearCallingIdentity(); |
| 5294 | try { |
| 5295 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5296 | int slotId = getSlotIndex(subId); |
| 5297 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5298 | Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '" |
| 5299 | + subId + "' for key:" + key); |
| 5300 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC; |
| 5301 | } |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5302 | return ImsManager.getInstance(mApp, slotId).getConfigString(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5303 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5304 | Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '" |
| 5305 | + subId + "' for key:" + key); |
| 5306 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5307 | } finally { |
| 5308 | Binder.restoreCallingIdentity(identity); |
| 5309 | } |
| 5310 | } |
| 5311 | |
| 5312 | @Override |
| 5313 | public int setImsProvisioningInt(int subId, int key, int value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5314 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5315 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 5316 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 5317 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5318 | "setImsProvisioningInt"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5319 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5320 | final long identity = Binder.clearCallingIdentity(); |
| 5321 | try { |
| 5322 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5323 | int slotId = getSlotIndex(subId); |
| 5324 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5325 | Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '" |
| 5326 | + subId + "' for key:" + key); |
| 5327 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 5328 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5329 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5330 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5331 | if (controller == null) { |
| 5332 | loge("setImsProvisioningInt: Device does not support IMS"); |
| 5333 | |
| 5334 | // device does not support IMS, this method will return CONFIG_RESULT_FAILED. |
| 5335 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 5336 | } |
| 5337 | int retVal = controller.setProvisioningValue(subId, key, value); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5338 | if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) { |
| 5339 | return retVal; |
| 5340 | } |
| 5341 | |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5342 | return ImsManager.getInstance(mApp, slotId).setConfig(key, value); |
| 5343 | } catch (com.android.ims.ImsException | RemoteException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5344 | Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5345 | + "' for key:" + key, e); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5346 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5347 | } finally { |
| 5348 | Binder.restoreCallingIdentity(identity); |
| 5349 | } |
| 5350 | } |
| 5351 | |
| 5352 | @Override |
| 5353 | public int setImsProvisioningString(int subId, int key, String value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5354 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5355 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 5356 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 5357 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5358 | "setImsProvisioningString"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5359 | final long identity = Binder.clearCallingIdentity(); |
| 5360 | try { |
| 5361 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5362 | int slotId = getSlotIndex(subId); |
| 5363 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5364 | Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '" |
| 5365 | + subId + "' for key:" + key); |
| 5366 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 5367 | } |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5368 | return ImsManager.getInstance(mApp, slotId).setConfig(key, value); |
| 5369 | } catch (com.android.ims.ImsException | RemoteException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5370 | Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5371 | + "' for key:" + key, e); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5372 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5373 | } finally { |
| 5374 | Binder.restoreCallingIdentity(identity); |
| 5375 | } |
| 5376 | } |
| 5377 | |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5378 | /** |
| 5379 | * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL |
| 5380 | * for the given slot ID or no ImsResolver instance has been created. |
| 5381 | * @param slotId The slot ID that the IMS service is created for. |
| 5382 | * @throws ImsException If there is no ImsService configured for this slot. |
| 5383 | */ |
| 5384 | private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException { |
| 5385 | if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId, |
| 5386 | ImsFeature.FEATURE_MMTEL)) { |
| 5387 | throw new ImsException("This subscription does not support MMTEL over IMS", |
| 5388 | ImsException.CODE_ERROR_UNSUPPORTED_OPERATION); |
| 5389 | } |
| 5390 | } |
| 5391 | |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5392 | private int getSlotIndexOrException(int subId) throws ImsException { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5393 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 5394 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5395 | throw new ImsException("Invalid Subscription Id, subId=" + subId, |
| 5396 | ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5397 | } |
| 5398 | return slotId; |
| 5399 | } |
| 5400 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5401 | private int getSlotIndex(int subId) { |
| 5402 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 5403 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
| 5404 | return SubscriptionManager.INVALID_SIM_SLOT_INDEX; |
| 5405 | } |
| 5406 | return slotId; |
| 5407 | } |
| 5408 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5409 | /** |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 5410 | * Returns the data network type for a subId; does not throw SecurityException. |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5411 | */ |
| 5412 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5413 | public int getNetworkTypeForSubscriber(int subId, String callingPackage, |
| 5414 | String callingFeatureId) { |
Shuo Qian | 13d8915 | 2021-05-10 23:58:11 -0700 | [diff] [blame] | 5415 | try { |
| 5416 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 5417 | } catch (SecurityException se) { |
| 5418 | EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid()); |
| 5419 | throw new SecurityException("Package " + callingPackage + " does not belong to " |
| 5420 | + Binder.getCallingUid()); |
| 5421 | } |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 5422 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 5423 | if (targetSdk > android.os.Build.VERSION_CODES.Q) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5424 | return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 5425 | } else if (targetSdk == android.os.Build.VERSION_CODES.Q |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 5426 | && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5427 | mApp, subId, callingPackage, callingFeatureId, |
| 5428 | "getNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5429 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5430 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 5431 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5432 | final long identity = Binder.clearCallingIdentity(); |
| 5433 | try { |
| 5434 | final Phone phone = getPhone(subId); |
| 5435 | if (phone != null) { |
| 5436 | return phone.getServiceState().getDataNetworkType(); |
| 5437 | } else { |
| 5438 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5439 | } |
| 5440 | } finally { |
| 5441 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5442 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5443 | } |
| 5444 | |
| 5445 | /** |
| 5446 | * Returns the data network type |
| 5447 | */ |
| 5448 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5449 | public int getDataNetworkType(String callingPackage, String callingFeatureId) { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5450 | return getDataNetworkTypeForSubscriber(SubscriptionManager.getDefaultDataSubscriptionId(), |
Zoey Chen | fd61f7f | 2021-04-21 13:42:10 +0800 | [diff] [blame] | 5451 | callingPackage, callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5452 | } |
| 5453 | |
| 5454 | /** |
| 5455 | * Returns the data network type for a subId |
| 5456 | */ |
| 5457 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5458 | public int getDataNetworkTypeForSubscriber(int subId, String callingPackage, |
| 5459 | String callingFeatureId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 5460 | String functionName = "getDataNetworkTypeForSubscriber"; |
| 5461 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 5462 | mApp, functionName)) { |
| 5463 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 5464 | mApp, subId, callingPackage, callingFeatureId, functionName)) { |
| 5465 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5466 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5467 | } |
| 5468 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5469 | final long identity = Binder.clearCallingIdentity(); |
| 5470 | try { |
| 5471 | final Phone phone = getPhone(subId); |
| 5472 | if (phone != null) { |
| 5473 | return phone.getServiceState().getDataNetworkType(); |
| 5474 | } else { |
| 5475 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5476 | } |
| 5477 | } finally { |
| 5478 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5479 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5480 | } |
| 5481 | |
| 5482 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5483 | * Returns the Voice network type for a subId |
| 5484 | */ |
| 5485 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5486 | public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage, |
| 5487 | String callingFeatureId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 5488 | String functionName = "getVoiceNetworkTypeForSubscriber"; |
| 5489 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 5490 | mApp, functionName)) { |
| 5491 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 5492 | mApp, subId, callingPackage, callingFeatureId, functionName)) { |
| 5493 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5494 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 5495 | } |
| 5496 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5497 | final long identity = Binder.clearCallingIdentity(); |
| 5498 | try { |
| 5499 | final Phone phone = getPhone(subId); |
| 5500 | if (phone != null) { |
| 5501 | return phone.getServiceState().getVoiceNetworkType(); |
| 5502 | } else { |
| 5503 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5504 | } |
| 5505 | } finally { |
| 5506 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5507 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5508 | } |
| 5509 | |
| 5510 | /** |
| 5511 | * @return true if a ICC card is present |
| 5512 | */ |
| 5513 | public boolean hasIccCard() { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5514 | // FIXME Make changes to pass defaultSimId of type int |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5515 | return hasIccCardUsingSlotIndex(SubscriptionManager.getSlotIndex( |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5516 | getDefaultSubscription())); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5517 | } |
| 5518 | |
| 5519 | /** |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5520 | * @return true if a ICC card is present for a slotIndex |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5521 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5522 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5523 | public boolean hasIccCardUsingSlotIndex(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5524 | final long identity = Binder.clearCallingIdentity(); |
| 5525 | try { |
| 5526 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5527 | if (phone != null) { |
| 5528 | return phone.getIccCard().hasIccCard(); |
| 5529 | } else { |
| 5530 | return false; |
| 5531 | } |
| 5532 | } finally { |
| 5533 | Binder.restoreCallingIdentity(identity); |
Amit Mahajan | a6fc2a8 | 2015-01-06 11:53:51 -0800 | [diff] [blame] | 5534 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5535 | } |
| 5536 | |
| 5537 | /** |
| 5538 | * Return if the current radio is LTE on CDMA. This |
| 5539 | * is a tri-state return value as for a period of time |
| 5540 | * the mode may be unknown. |
| 5541 | * |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5542 | * @param callingPackage the name of the package making the call. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5543 | * @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] | 5544 | * or {@link Phone#LTE_ON_CDMA_TRUE} |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5545 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5546 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5547 | public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) { |
| 5548 | return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 5549 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5550 | } |
| 5551 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5552 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5553 | public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage, |
| 5554 | String callingFeatureId) { |
Sarah Chin | 790d292 | 2020-01-16 12:17:23 -0800 | [diff] [blame] | 5555 | try { |
| 5556 | enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber"); |
| 5557 | } catch (SecurityException e) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5558 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 5559 | } |
| 5560 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5561 | final long identity = Binder.clearCallingIdentity(); |
| 5562 | try { |
| 5563 | final Phone phone = getPhone(subId); |
| 5564 | if (phone == null) { |
| 5565 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 5566 | } else { |
Nathan Harold | 05ad633 | 2020-07-10 11:54:36 -0700 | [diff] [blame] | 5567 | return TelephonyProperties.lte_on_cdma_device() |
| 5568 | .orElse(PhoneConstants.LTE_ON_CDMA_FALSE); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5569 | } |
| 5570 | } finally { |
| 5571 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5572 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5573 | } |
| 5574 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5575 | /** |
| 5576 | * {@hide} |
| 5577 | * Returns Default subId, 0 in the case of single standby. |
| 5578 | */ |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 5579 | private int getDefaultSubscription() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5580 | return SubscriptionManager.getDefaultSubscriptionId(); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5581 | } |
| 5582 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 5583 | private int getSlotForDefaultSubscription() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5584 | return SubscriptionManager.getPhoneId(getDefaultSubscription()); |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 5585 | } |
| 5586 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 5587 | private int getPreferredVoiceSubscription() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5588 | return SubscriptionManager.getDefaultVoiceSubscriptionId(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5589 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5590 | |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 5591 | private boolean isActiveSubscription(int subId) { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5592 | if (PhoneFactory.isSubscriptionManagerServiceEnabled()) { |
| 5593 | return SubscriptionManagerService.getInstance().isActiveSubId(subId, |
| 5594 | mApp.getOpPackageName(), mApp.getFeatureId()); |
| 5595 | } |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 5596 | return mSubscriptionController.isActiveSubId(subId); |
| 5597 | } |
| 5598 | |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5599 | /** |
| 5600 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 5601 | */ |
| 5602 | public int getWhenToMakeWifiCalls() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5603 | final long identity = Binder.clearCallingIdentity(); |
| 5604 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5605 | return Settings.System.getInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5606 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, |
| 5607 | getWhenToMakeWifiCallsDefaultPreference()); |
| 5608 | } finally { |
| 5609 | Binder.restoreCallingIdentity(identity); |
| 5610 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5611 | } |
| 5612 | |
| 5613 | /** |
| 5614 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 5615 | */ |
| 5616 | public void setWhenToMakeWifiCalls(int preference) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5617 | final long identity = Binder.clearCallingIdentity(); |
| 5618 | try { |
| 5619 | if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5620 | Settings.System.putInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5621 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference); |
| 5622 | } finally { |
| 5623 | Binder.restoreCallingIdentity(identity); |
| 5624 | } |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 5625 | } |
| 5626 | |
Sailesh Nepal | d1e6815 | 2013-12-12 19:08:02 -0800 | [diff] [blame] | 5627 | private static int getWhenToMakeWifiCallsDefaultPreference() { |
Santos Cordon | da120f4 | 2014-08-06 04:44:34 -0700 | [diff] [blame] | 5628 | // TODO: Use a build property to choose this value. |
Evan Charlton | 9829e88 | 2013-12-19 15:30:38 -0800 | [diff] [blame] | 5629 | return TelephonyManager.WifiCallingChoices.ALWAYS_USE; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5630 | } |
Shishir Agrawal | 69f6812 | 2013-12-16 17:25:49 -0800 | [diff] [blame] | 5631 | |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5632 | private Phone getPhoneFromSlotPortIndexOrThrowException(int slotIndex, int portIndex) { |
| 5633 | int phoneId = UiccController.getInstance().getPhoneIdFromSlotPortIndex(slotIndex, |
| 5634 | portIndex); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5635 | if (phoneId == -1) { |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5636 | throw new IllegalArgumentException("Given slot index: " + slotIndex + " port index: " |
| 5637 | + portIndex + " does not correspond to an active phone"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5638 | } |
| 5639 | return PhoneFactory.getPhone(phoneId); |
| 5640 | } |
| 5641 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5642 | @Override |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 5643 | public IccOpenLogicalChannelResponse iccOpenLogicalChannel( |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5644 | @NonNull IccLogicalChannelRequest request) { |
| 5645 | Phone phone = getPhoneFromValidIccLogicalChannelRequest(request, |
| 5646 | /*message=*/ "iccOpenLogicalChannel"); |
| 5647 | |
| 5648 | if (DBG) log("iccOpenLogicalChannel: request=" + request); |
| 5649 | // Verify that the callingPackage in the request belongs to the calling UID |
| 5650 | mAppOps.checkPackage(Binder.getCallingUid(), request.callingPackage); |
| 5651 | |
| 5652 | return iccOpenLogicalChannelWithPermission(phone, request); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5653 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5654 | |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5655 | private Phone getPhoneFromValidIccLogicalChannelRequest( |
| 5656 | @NonNull IccLogicalChannelRequest request, String message) { |
| 5657 | Phone phone; |
| 5658 | if (request.subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) { |
| 5659 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5660 | mApp, request.subId, message); |
| 5661 | phone = getPhoneFromSubId(request.subId); |
| 5662 | } else if (request.slotIndex != SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5663 | enforceModifyPermission(); |
| 5664 | phone = getPhoneFromSlotPortIndexOrThrowException(request.slotIndex, request.portIndex); |
| 5665 | } else { |
| 5666 | throw new IllegalArgumentException("Both subId and slotIndex in request are invalid."); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5667 | } |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5668 | return phone; |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5669 | } |
| 5670 | |
| 5671 | private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone, |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5672 | IccLogicalChannelRequest channelRequest) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5673 | final long identity = Binder.clearCallingIdentity(); |
| 5674 | try { |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5675 | if (TextUtils.equals(ISDR_AID, channelRequest.aid)) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5676 | // Only allows LPA to open logical channel to ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5677 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 5678 | .getContext().getPackageManager()); |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5679 | if (bestComponent == null || !TextUtils.equals(channelRequest.callingPackage, |
| 5680 | bestComponent.packageName)) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5681 | loge("The calling package is not allowed to access ISD-R."); |
| 5682 | throw new SecurityException( |
| 5683 | "The calling package is not allowed to access ISD-R."); |
| 5684 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 5685 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 5686 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5687 | IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest( |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5688 | CMD_OPEN_CHANNEL, channelRequest, phone, null /* workSource */); |
| 5689 | if (DBG) log("iccOpenLogicalChannelWithPermission: response=" + response); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5690 | return response; |
| 5691 | } finally { |
| 5692 | Binder.restoreCallingIdentity(identity); |
| 5693 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5694 | } |
| 5695 | |
| 5696 | @Override |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5697 | public boolean iccCloseLogicalChannel(@NonNull IccLogicalChannelRequest request) { |
| 5698 | Phone phone = getPhoneFromValidIccLogicalChannelRequest(request, |
| 5699 | /*message=*/"iccCloseLogicalChannel"); |
| 5700 | |
| 5701 | if (DBG) log("iccCloseLogicalChannel: request=" + request); |
| 5702 | |
| 5703 | return iccCloseLogicalChannelWithPermission(phone, request); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5704 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5705 | |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5706 | private boolean iccCloseLogicalChannelWithPermission(Phone phone, |
| 5707 | IccLogicalChannelRequest request) { |
Chen Xu | a8f0dff | 2022-02-12 00:34:15 -0800 | [diff] [blame] | 5708 | // before this feature is enabled, this API should only return false if |
| 5709 | // the operation fails instead of throwing runtime exception for |
| 5710 | // backward-compatibility. |
| 5711 | final boolean shouldThrowExceptionOnFailure = CompatChanges.isChangeEnabled( |
| 5712 | ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE, Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5713 | final long identity = Binder.clearCallingIdentity(); |
| 5714 | try { |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5715 | if (request.channel < 0) { |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 5716 | throw new IllegalArgumentException("request.channel is less than 0"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5717 | } |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 5718 | Object result = sendRequest(CMD_CLOSE_CHANNEL, request.channel, phone, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5719 | null /* workSource */); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 5720 | Boolean success = false; |
| 5721 | if (result instanceof RuntimeException) { |
| 5722 | // if there is an exception returned, throw from the binder thread here. |
Chen Xu | a8f0dff | 2022-02-12 00:34:15 -0800 | [diff] [blame] | 5723 | if (shouldThrowExceptionOnFailure) { |
| 5724 | throw (RuntimeException) result; |
| 5725 | } else { |
| 5726 | return false; |
| 5727 | } |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 5728 | } else if (result instanceof Boolean) { |
| 5729 | success = (Boolean) result; |
| 5730 | } else { |
| 5731 | loge("iccCloseLogicalChannelWithPermission: supported return type " + result); |
| 5732 | } |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5733 | if (DBG) log("iccCloseLogicalChannelWithPermission: success=" + success); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5734 | return success; |
| 5735 | } finally { |
| 5736 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5737 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5738 | } |
| 5739 | |
| 5740 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5741 | public String iccTransmitApduLogicalChannel(int subId, int channel, int cla, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5742 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5743 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5744 | mApp, subId, "iccTransmitApduLogicalChannel"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5745 | if (DBG) { |
| 5746 | log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel |
| 5747 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 5748 | + p3 + " data=" + data); |
| 5749 | } |
| 5750 | return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla, |
| 5751 | command, p1, p2, p3, data); |
| 5752 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5753 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5754 | @Override |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5755 | public String iccTransmitApduLogicalChannelByPort(int slotIndex, int portIndex, int channel, |
| 5756 | int cla, int command, int p1, int p2, int p3, String data) { |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5757 | enforceModifyPermission(); |
| 5758 | if (DBG) { |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5759 | log("iccTransmitApduLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex=" |
| 5760 | + portIndex + " chnl=" + channel + " cla=" + cla + " cmd=" + command + " p1=" |
| 5761 | + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5762 | } |
| 5763 | return iccTransmitApduLogicalChannelWithPermission( |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5764 | getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel, cla, |
| 5765 | command, p1, p2, p3, data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5766 | } |
| 5767 | |
| 5768 | private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla, |
| 5769 | int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5770 | final long identity = Binder.clearCallingIdentity(); |
| 5771 | try { |
Hall Liu | 4fd771b | 2019-05-02 09:16:29 -0700 | [diff] [blame] | 5772 | if (channel <= 0) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5773 | return ""; |
| 5774 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5775 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5776 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5777 | new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone, |
| 5778 | null /* workSource */); |
| 5779 | if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5780 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5781 | // Append the returned status code to the end of the response payload. |
| 5782 | String s = Integer.toHexString( |
| 5783 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 5784 | if (response.payload != null) { |
| 5785 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 5786 | } |
| 5787 | return s; |
| 5788 | } finally { |
| 5789 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 5790 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5791 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5792 | |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5793 | @Override |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 5794 | public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla, |
| 5795 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5796 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5797 | mApp, subId, "iccTransmitApduBasicChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5798 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5799 | if (DBG) { |
| 5800 | log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" |
| 5801 | + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
| 5802 | } |
| 5803 | return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage, |
| 5804 | cla, command, p1, p2, p3, data); |
| 5805 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5806 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5807 | @Override |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5808 | public String iccTransmitApduBasicChannelByPort(int slotIndex, int portIndex, |
| 5809 | 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] | 5810 | enforceModifyPermission(); |
| 5811 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 5812 | if (DBG) { |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5813 | log("iccTransmitApduBasicChannelByPort: slotIndex=" + slotIndex + " portIndex=" |
| 5814 | + portIndex + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" |
| 5815 | + p2 + " p3=" + p3 + " data=" + data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5816 | } |
| 5817 | |
| 5818 | return iccTransmitApduBasicChannelWithPermission( |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5819 | getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), callingPackage, |
| 5820 | cla, command, p1, p2, p3, data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5821 | } |
| 5822 | |
| 5823 | // open APDU basic channel assuming the caller has sufficient permissions |
| 5824 | private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage, |
| 5825 | int cla, int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5826 | final long identity = Binder.clearCallingIdentity(); |
| 5827 | try { |
| 5828 | if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3 |
| 5829 | && TextUtils.equals(ISDR_AID, data)) { |
| 5830 | // Only allows LPA to select ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5831 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 5832 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5833 | if (bestComponent == null |
| 5834 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 5835 | loge("The calling package is not allowed to select ISD-R."); |
| 5836 | throw new SecurityException( |
| 5837 | "The calling package is not allowed to select ISD-R."); |
| 5838 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 5839 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 5840 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5841 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5842 | new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone, |
| 5843 | null /* workSource */); |
| 5844 | if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5845 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5846 | // Append the returned status code to the end of the response payload. |
| 5847 | String s = Integer.toHexString( |
| 5848 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 5849 | if (response.payload != null) { |
| 5850 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 5851 | } |
| 5852 | return s; |
| 5853 | } finally { |
| 5854 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 5855 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5856 | } |
| 5857 | |
| 5858 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5859 | 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] | 5860 | String filePath) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5861 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5862 | mApp, subId, "iccExchangeSimIO"); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5863 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5864 | final long identity = Binder.clearCallingIdentity(); |
| 5865 | try { |
| 5866 | if (DBG) { |
| 5867 | log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " |
| 5868 | + p1 + " " + p2 + " " + p3 + ":" + filePath); |
| 5869 | } |
| 5870 | |
| 5871 | IccIoResult response = |
| 5872 | (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO, |
| 5873 | new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath), |
| 5874 | subId); |
| 5875 | |
| 5876 | if (DBG) { |
| 5877 | log("Exchange SIM_IO [R]" + response); |
| 5878 | } |
| 5879 | |
| 5880 | byte[] result = null; |
| 5881 | int length = 2; |
| 5882 | if (response.payload != null) { |
| 5883 | length = 2 + response.payload.length; |
| 5884 | result = new byte[length]; |
| 5885 | System.arraycopy(response.payload, 0, result, 0, response.payload.length); |
| 5886 | } else { |
| 5887 | result = new byte[length]; |
| 5888 | } |
| 5889 | |
| 5890 | result[length - 1] = (byte) response.sw2; |
| 5891 | result[length - 2] = (byte) response.sw1; |
| 5892 | return result; |
| 5893 | } finally { |
| 5894 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5895 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5896 | } |
| 5897 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5898 | /** |
| 5899 | * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM) |
| 5900 | * on a particular subscription |
| 5901 | */ |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5902 | public String[] getForbiddenPlmns(int subId, int appType, String callingPackage, |
| 5903 | String callingFeatureId) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 5904 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5905 | mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 5906 | return null; |
| 5907 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5908 | |
| 5909 | final long identity = Binder.clearCallingIdentity(); |
| 5910 | try { |
| 5911 | if (appType != TelephonyManager.APPTYPE_USIM |
| 5912 | && appType != TelephonyManager.APPTYPE_SIM) { |
| 5913 | loge("getForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 5914 | return null; |
| 5915 | } |
| 5916 | Object response = sendRequest( |
| 5917 | CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId); |
| 5918 | if (response instanceof String[]) { |
| 5919 | return (String[]) response; |
| 5920 | } |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5921 | // Response is an Exception of some kind |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5922 | // which is signalled to the user as a NULL retval |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5923 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5924 | } finally { |
| 5925 | Binder.restoreCallingIdentity(identity); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5926 | } |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5927 | } |
| 5928 | |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5929 | /** |
| 5930 | * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular |
| 5931 | * subscription. |
| 5932 | * |
| 5933 | * @param subId the id of the subscription. |
| 5934 | * @param appType the uicc app type, must be USIM or SIM. |
| 5935 | * @param fplmns the Forbiden plmns list that needed to be written to the SIM. |
| 5936 | * @param callingPackage the op Package name. |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5937 | * @param callingFeatureId the feature in the package. |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5938 | * @return number of fplmns that is successfully written to the SIM. |
| 5939 | */ |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5940 | public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage, |
| 5941 | String callingFeatureId) { |
Jayachandran C | 5b0d75a | 2021-10-21 22:15:27 -0700 | [diff] [blame] | 5942 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5943 | mApp, subId, "setForbiddenPlmns"); |
| 5944 | |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5945 | if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) { |
| 5946 | loge("setForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 5947 | throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM"); |
| 5948 | } |
| 5949 | if (fplmns == null) { |
| 5950 | throw new IllegalArgumentException("Fplmn List provided is null"); |
| 5951 | } |
| 5952 | for (String fplmn : fplmns) { |
| 5953 | if (!CellIdentity.isValidPlmn(fplmn)) { |
| 5954 | throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn); |
| 5955 | } |
| 5956 | } |
| 5957 | final long identity = Binder.clearCallingIdentity(); |
| 5958 | try { |
| 5959 | Object response = sendRequest( |
| 5960 | CMD_SET_FORBIDDEN_PLMNS, |
| 5961 | new Pair<Integer, List<String>>(new Integer(appType), fplmns), |
| 5962 | subId); |
| 5963 | return (int) response; |
| 5964 | } finally { |
| 5965 | Binder.restoreCallingIdentity(identity); |
| 5966 | } |
| 5967 | } |
| 5968 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5969 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5970 | public String sendEnvelopeWithStatus(int subId, String content) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5971 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5972 | mApp, subId, "sendEnvelopeWithStatus"); |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5973 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5974 | final long identity = Binder.clearCallingIdentity(); |
| 5975 | try { |
| 5976 | IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId); |
| 5977 | if (response.payload == null) { |
| 5978 | return ""; |
| 5979 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5980 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5981 | // Append the returned status code to the end of the response payload. |
| 5982 | String s = Integer.toHexString( |
| 5983 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 5984 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 5985 | return s; |
| 5986 | } finally { |
| 5987 | Binder.restoreCallingIdentity(identity); |
| 5988 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5989 | } |
| 5990 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5991 | /** |
| 5992 | * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 5993 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 5994 | * |
| 5995 | * @param itemID the ID of the item to read |
| 5996 | * @return the NV item as a String, or null on error. |
| 5997 | */ |
| 5998 | @Override |
| 5999 | public String nvReadItem(int itemID) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6000 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6001 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6002 | mApp, getDefaultSubscription(), "nvReadItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6003 | |
| 6004 | final long identity = Binder.clearCallingIdentity(); |
| 6005 | try { |
| 6006 | if (DBG) log("nvReadItem: item " + itemID); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6007 | String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6008 | if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"'); |
| 6009 | return value; |
| 6010 | } finally { |
| 6011 | Binder.restoreCallingIdentity(identity); |
| 6012 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 6013 | } |
| 6014 | |
| 6015 | /** |
| 6016 | * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 6017 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 6018 | * |
| 6019 | * @param itemID the ID of the item to read |
| 6020 | * @param itemValue the value to write, as a String |
| 6021 | * @return true on success; false on any failure |
| 6022 | */ |
| 6023 | @Override |
| 6024 | public boolean nvWriteItem(int itemID, String itemValue) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6025 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6026 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6027 | mApp, getDefaultSubscription(), "nvWriteItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6028 | |
| 6029 | final long identity = Binder.clearCallingIdentity(); |
| 6030 | try { |
| 6031 | if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"'); |
| 6032 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6033 | new Pair<Integer, String>(itemID, itemValue), workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6034 | if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail")); |
| 6035 | return success; |
| 6036 | } finally { |
| 6037 | Binder.restoreCallingIdentity(identity); |
| 6038 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 6039 | } |
| 6040 | |
| 6041 | /** |
| 6042 | * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage. |
| 6043 | * Used for device configuration by some CDMA operators. |
| 6044 | * |
| 6045 | * @param preferredRoamingList byte array containing the new PRL |
| 6046 | * @return true on success; false on any failure |
| 6047 | */ |
| 6048 | @Override |
| 6049 | public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6050 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6051 | mApp, getDefaultSubscription(), "nvWriteCdmaPrl"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6052 | |
| 6053 | final long identity = Binder.clearCallingIdentity(); |
| 6054 | try { |
| 6055 | if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList)); |
| 6056 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList); |
| 6057 | if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail")); |
| 6058 | return success; |
| 6059 | } finally { |
| 6060 | Binder.restoreCallingIdentity(identity); |
| 6061 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 6062 | } |
| 6063 | |
| 6064 | /** |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 6065 | * 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] | 6066 | * Used for device configuration by some CDMA operators. |
| 6067 | * |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 6068 | * @param slotIndex - device slot. |
| 6069 | * |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 6070 | * @return true on success; false on any failure |
| 6071 | */ |
| 6072 | @Override |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 6073 | public boolean resetModemConfig(int slotIndex) { |
| 6074 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 6075 | if (phone != null) { |
| 6076 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6077 | mApp, phone.getSubId(), "resetModemConfig"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6078 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 6079 | final long identity = Binder.clearCallingIdentity(); |
| 6080 | try { |
| 6081 | Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null); |
| 6082 | if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 6083 | return success; |
| 6084 | } finally { |
| 6085 | Binder.restoreCallingIdentity(identity); |
| 6086 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6087 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 6088 | return false; |
| 6089 | } |
| 6090 | |
| 6091 | /** |
| 6092 | * Generate a radio modem reset. Used for device configuration by some CDMA operators. |
| 6093 | * |
| 6094 | * @param slotIndex - device slot. |
| 6095 | * |
| 6096 | * @return true on success; false on any failure |
| 6097 | */ |
| 6098 | @Override |
| 6099 | public boolean rebootModem(int slotIndex) { |
| 6100 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 6101 | if (phone != null) { |
| 6102 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6103 | mApp, phone.getSubId(), "rebootModem"); |
| 6104 | |
| 6105 | final long identity = Binder.clearCallingIdentity(); |
| 6106 | try { |
| 6107 | Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null); |
| 6108 | if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail")); |
| 6109 | return success; |
| 6110 | } finally { |
| 6111 | Binder.restoreCallingIdentity(identity); |
| 6112 | } |
| 6113 | } |
| 6114 | return false; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 6115 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 6116 | |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 6117 | /** |
Grace Jia | aa2eb6b | 2020-01-09 16:26:08 -0800 | [diff] [blame] | 6118 | * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and |
| 6119 | * {@link #disableIms(int)}. |
| 6120 | * @param slotIndex device slot. |
| 6121 | */ |
| 6122 | public void resetIms(int slotIndex) { |
| 6123 | enforceModifyPermission(); |
| 6124 | |
| 6125 | final long identity = Binder.clearCallingIdentity(); |
| 6126 | try { |
| 6127 | if (mImsResolver == null) { |
| 6128 | // may happen if the does not support IMS. |
| 6129 | return; |
| 6130 | } |
Hyunho | a17ac7c | 2022-08-30 12:03:04 +0000 | [diff] [blame] | 6131 | mImsResolver.resetIms(slotIndex); |
Grace Jia | aa2eb6b | 2020-01-09 16:26:08 -0800 | [diff] [blame] | 6132 | } finally { |
| 6133 | Binder.restoreCallingIdentity(identity); |
| 6134 | } |
| 6135 | } |
| 6136 | |
| 6137 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6138 | * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability |
| 6139 | * status updates, if not already enabled. |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 6140 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6141 | public void enableIms(int slotId) { |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 6142 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6143 | |
| 6144 | final long identity = Binder.clearCallingIdentity(); |
| 6145 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6146 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6147 | // may happen if the device does not support IMS. |
| 6148 | return; |
| 6149 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6150 | mImsResolver.enableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6151 | } finally { |
| 6152 | Binder.restoreCallingIdentity(identity); |
| 6153 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 6154 | } |
| 6155 | |
| 6156 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6157 | * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature |
| 6158 | * status updates to disabled. |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 6159 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6160 | public void disableIms(int slotId) { |
| 6161 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6162 | |
| 6163 | final long identity = Binder.clearCallingIdentity(); |
| 6164 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6165 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6166 | // may happen if the device does not support IMS. |
| 6167 | return; |
| 6168 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6169 | mImsResolver.disableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6170 | } finally { |
| 6171 | Binder.restoreCallingIdentity(identity); |
| 6172 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6173 | } |
| 6174 | |
| 6175 | /** |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 6176 | * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback |
| 6177 | * callback. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6178 | */ |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 6179 | @Override |
Brad Ebinger | f6aca00 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 6180 | public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) { |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 6181 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6182 | |
| 6183 | final long identity = Binder.clearCallingIdentity(); |
| 6184 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6185 | if (mImsResolver == null) { |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 6186 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 6187 | "Device does not support IMS"); |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6188 | } |
Brad Ebinger | f6aca00 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 6189 | mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6190 | } finally { |
| 6191 | Binder.restoreCallingIdentity(identity); |
| 6192 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 6193 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 6194 | /** |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 6195 | * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature. |
| 6196 | */ |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 6197 | @Override |
| 6198 | public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) { |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 6199 | enforceModifyPermission(); |
| 6200 | |
| 6201 | final long identity = Binder.clearCallingIdentity(); |
| 6202 | try { |
| 6203 | if (mImsResolver == null) return; |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 6204 | mImsResolver.unregisterImsFeatureCallback(callback); |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 6205 | } finally { |
| 6206 | Binder.restoreCallingIdentity(identity); |
| 6207 | } |
| 6208 | } |
| 6209 | |
| 6210 | /** |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 6211 | * Returns the {@link IImsRegistration} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6212 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 6213 | */ |
| 6214 | public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException { |
| 6215 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6216 | |
| 6217 | final long identity = Binder.clearCallingIdentity(); |
| 6218 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6219 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6220 | // may happen if the device does not support IMS. |
| 6221 | return null; |
| 6222 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6223 | return mImsResolver.getImsRegistration(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6224 | } finally { |
| 6225 | Binder.restoreCallingIdentity(identity); |
| 6226 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 6227 | } |
| 6228 | |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6229 | /** |
| 6230 | * Returns the {@link IImsConfig} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6231 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6232 | */ |
| 6233 | public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException { |
| 6234 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6235 | |
| 6236 | final long identity = Binder.clearCallingIdentity(); |
| 6237 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6238 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6239 | // may happen if the device does not support IMS. |
| 6240 | return null; |
| 6241 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6242 | return mImsResolver.getImsConfig(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6243 | } finally { |
| 6244 | Binder.restoreCallingIdentity(identity); |
| 6245 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6246 | } |
| 6247 | |
Brad Ebinger | 884c07b | 2018-02-15 16:17:40 -0800 | [diff] [blame] | 6248 | /** |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6249 | * Sets the ImsService Package Name that Telephony will bind to. |
| 6250 | * |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6251 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 6252 | * @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] | 6253 | * ImsService is the device default ImsService. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6254 | * @param featureTypes An integer array of feature types associated with a packageName. |
| 6255 | * @param packageName The name of the package that the current configuration will be replaced |
| 6256 | * with. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6257 | * @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] | 6258 | */ |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6259 | public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService, |
| 6260 | int[] featureTypes, String packageName) { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6261 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 6262 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
Jack Yu | 00ece8c | 2022-11-19 22:29:12 -0800 | [diff] [blame] | 6263 | SubscriptionManager.getSubscriptionId(slotIndex), "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 6264 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6265 | final long identity = Binder.clearCallingIdentity(); |
| 6266 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6267 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6268 | // may happen if the device does not support IMS. |
| 6269 | return false; |
| 6270 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6271 | Map<Integer, String> featureConfig = new HashMap<>(); |
| 6272 | for (int featureType : featureTypes) { |
| 6273 | featureConfig.put(featureType, packageName); |
| 6274 | } |
| 6275 | return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService, |
| 6276 | featureConfig); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6277 | } finally { |
| 6278 | Binder.restoreCallingIdentity(identity); |
| 6279 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6280 | } |
| 6281 | |
| 6282 | /** |
Brad Ebinger | 999d330 | 2020-11-25 14:31:39 -0800 | [diff] [blame] | 6283 | * Clears any carrier ImsService overrides for the slot index specified that were previously |
| 6284 | * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}. |
| 6285 | * |
| 6286 | * This should only be used for testing. |
| 6287 | * |
| 6288 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 6289 | * @return true if clearing the carrier ImsService override succeeded or false if it did not. |
| 6290 | */ |
| 6291 | @Override |
| 6292 | public boolean clearCarrierImsServiceOverride(int slotIndex) { |
Brad Ebinger | 999d330 | 2020-11-25 14:31:39 -0800 | [diff] [blame] | 6293 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 6294 | "clearCarrierImsServiceOverride"); |
| 6295 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
Jack Yu | 00ece8c | 2022-11-19 22:29:12 -0800 | [diff] [blame] | 6296 | SubscriptionManager.getSubscriptionId(slotIndex), "clearCarrierImsServiceOverride"); |
Brad Ebinger | 999d330 | 2020-11-25 14:31:39 -0800 | [diff] [blame] | 6297 | |
| 6298 | final long identity = Binder.clearCallingIdentity(); |
| 6299 | try { |
| 6300 | if (mImsResolver == null) { |
| 6301 | // may happen if the device does not support IMS. |
| 6302 | return false; |
| 6303 | } |
| 6304 | return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex); |
| 6305 | } finally { |
| 6306 | Binder.restoreCallingIdentity(identity); |
| 6307 | } |
| 6308 | } |
| 6309 | |
| 6310 | /** |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6311 | * Return the package name of the currently bound ImsService. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6312 | * |
| 6313 | * @param slotId The slot that the ImsService is associated with. |
| 6314 | * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is |
| 6315 | * the device default. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6316 | * @param featureType The feature associated with the queried configuration. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6317 | * @return the package name of the ImsService configuration. |
| 6318 | */ |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6319 | public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService, |
| 6320 | @ImsFeature.FeatureType int featureType) { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6321 | TelephonyPermissions |
Jack Yu | 00ece8c | 2022-11-19 22:29:12 -0800 | [diff] [blame] | 6322 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(mApp, |
| 6323 | SubscriptionManager.getSubscriptionId(slotId), "getBoundImsServicePackage"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 6324 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6325 | final long identity = Binder.clearCallingIdentity(); |
| 6326 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6327 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6328 | // may happen if the device does not support IMS. |
| 6329 | return ""; |
| 6330 | } |
Brad Ebinger | a80c331 | 2019-12-02 10:59:39 -0800 | [diff] [blame] | 6331 | // TODO: change API to query RCS separately. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6332 | return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService, |
| 6333 | featureType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6334 | } finally { |
| 6335 | Binder.restoreCallingIdentity(identity); |
| 6336 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6337 | } |
| 6338 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6339 | /** |
| 6340 | * Get the MmTelFeature state associated with the requested subscription id. |
| 6341 | * @param subId The subscription that the MmTelFeature is associated with. |
| 6342 | * @param callback A callback with an integer containing the |
| 6343 | * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature. |
| 6344 | */ |
| 6345 | @Override |
| 6346 | public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) { |
| 6347 | enforceReadPrivilegedPermission("getImsMmTelFeatureState"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 6348 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 6349 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 6350 | "IMS not available on device."); |
| 6351 | } |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6352 | final long token = Binder.clearCallingIdentity(); |
| 6353 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 6354 | int slotId = getSlotIndex(subId); |
| 6355 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 6356 | Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '" |
| 6357 | + subId + "'"); |
| 6358 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 6359 | } |
| 6360 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 6361 | ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> { |
| 6362 | try { |
| 6363 | callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger); |
| 6364 | } catch (RemoteException e) { |
| 6365 | Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. " |
| 6366 | + "Ignore"); |
| 6367 | } |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6368 | }); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 6369 | } catch (ImsException e) { |
| 6370 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6371 | } finally { |
| 6372 | Binder.restoreCallingIdentity(token); |
| 6373 | } |
| 6374 | } |
| 6375 | |
Daniel Bright | bb5840b | 2021-01-12 15:48:18 -0800 | [diff] [blame] | 6376 | /** |
| 6377 | * Sets the ims registration state on all valid {@link Phone}s. |
| 6378 | */ |
| 6379 | public void setImsRegistrationState(final boolean registered) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 6380 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6381 | |
| 6382 | final long identity = Binder.clearCallingIdentity(); |
| 6383 | try { |
Daniel Bright | bb5840b | 2021-01-12 15:48:18 -0800 | [diff] [blame] | 6384 | // NOTE: Before S, this method only set the default phone. |
| 6385 | for (final Phone phone : PhoneFactory.getPhones()) { |
| 6386 | if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) { |
| 6387 | phone.setImsRegistrationState(registered); |
| 6388 | } |
| 6389 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6390 | } finally { |
| 6391 | Binder.restoreCallingIdentity(identity); |
| 6392 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 6393 | } |
| 6394 | |
| 6395 | /** |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 6396 | * Set the network selection mode to automatic. |
| 6397 | * |
| 6398 | */ |
| 6399 | @Override |
| 6400 | public void setNetworkSelectionModeAutomatic(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6401 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6402 | mApp, subId, "setNetworkSelectionModeAutomatic"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6403 | |
| 6404 | final long identity = Binder.clearCallingIdentity(); |
| 6405 | try { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 6406 | if (!isActiveSubscription(subId)) { |
| 6407 | return; |
| 6408 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6409 | if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId); |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 6410 | sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId, |
| 6411 | SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6412 | } finally { |
| 6413 | Binder.restoreCallingIdentity(identity); |
| 6414 | } |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 6415 | } |
| 6416 | |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 6417 | /** |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6418 | * Ask the radio to connect to the input network and change selection mode to manual. |
| 6419 | * |
| 6420 | * @param subId the id of the subscription. |
| 6421 | * @param operatorInfo the operator information, included the PLMN, long name and short name of |
| 6422 | * the operator to attach to. |
| 6423 | * @param persistSelection whether the selection will persist until reboot. If true, only allows |
| 6424 | * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume |
| 6425 | * normal network selection next time. |
| 6426 | * @return {@code true} on success; {@code true} on any failure. |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6427 | */ |
| 6428 | @Override |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6429 | public boolean setNetworkSelectionModeManual( |
| 6430 | int subId, OperatorInfo operatorInfo, boolean persistSelection) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6431 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6432 | mApp, subId, "setNetworkSelectionModeManual"); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 6433 | |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 6434 | final long identity = Binder.clearCallingIdentity(); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 6435 | if (!isActiveSubscription(subId)) { |
| 6436 | return false; |
| 6437 | } |
| 6438 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6439 | try { |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6440 | ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6441 | persistSelection); |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6442 | if (DBG) { |
| 6443 | log("setNetworkSelectionModeManual: subId: " + subId |
| 6444 | + " operator: " + operatorInfo); |
| 6445 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6446 | return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId); |
| 6447 | } finally { |
| 6448 | Binder.restoreCallingIdentity(identity); |
| 6449 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6450 | } |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6451 | /** |
| 6452 | * Get the manual network selection |
| 6453 | * |
| 6454 | * @param subId the id of the subscription. |
| 6455 | * |
| 6456 | * @return the previously saved user selected PLMN |
| 6457 | */ |
| 6458 | @Override |
| 6459 | public String getManualNetworkSelectionPlmn(int subId) { |
| 6460 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 6461 | .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6462 | mApp, subId, "getManualNetworkSelectionPlmn"); |
| 6463 | |
| 6464 | final long identity = Binder.clearCallingIdentity(); |
| 6465 | try { |
| 6466 | if (!isActiveSubscription(subId)) { |
shilu | fa1c259 | 2020-03-10 10:59:43 -0700 | [diff] [blame] | 6467 | throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6468 | } |
| 6469 | |
| 6470 | final Phone phone = getPhone(subId); |
| 6471 | if (phone == null) { |
shilu | fa1c259 | 2020-03-10 10:59:43 -0700 | [diff] [blame] | 6472 | throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6473 | } |
| 6474 | OperatorInfo networkSelection = phone.getSavedNetworkSelection(); |
| 6475 | return TextUtils.isEmpty(networkSelection.getOperatorNumeric()) |
| 6476 | ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric(); |
| 6477 | } finally { |
| 6478 | Binder.restoreCallingIdentity(identity); |
| 6479 | } |
| 6480 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6481 | |
| 6482 | /** |
| 6483 | * Scans for available networks. |
| 6484 | */ |
| 6485 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6486 | public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage, |
| 6487 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6488 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6489 | mApp, subId, "getCellNetworkScanResults"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6490 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 6491 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 6492 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 6493 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6494 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6495 | .setCallingPid(Binder.getCallingPid()) |
| 6496 | .setCallingUid(Binder.getCallingUid()) |
| 6497 | .setMethod("getCellNetworkScanResults") |
| 6498 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
Hall Liu | c4a3e42 | 2020-05-26 17:18:03 -0700 | [diff] [blame] | 6499 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 6500 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6501 | .build()); |
| 6502 | switch (locationResult) { |
| 6503 | case DENIED_HARD: |
| 6504 | throw new SecurityException("Not allowed to access scan results -- location"); |
| 6505 | case DENIED_SOFT: |
| 6506 | return null; |
| 6507 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6508 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6509 | long identity = Binder.clearCallingIdentity(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6510 | try { |
| 6511 | if (DBG) log("getCellNetworkScanResults: subId " + subId); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6512 | return (CellNetworkScanResult) sendRequest( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6513 | CMD_PERFORM_NETWORK_SCAN, null, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6514 | } finally { |
| 6515 | Binder.restoreCallingIdentity(identity); |
| 6516 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6517 | } |
| 6518 | |
| 6519 | /** |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6520 | * Get the call forwarding info, given the call forwarding reason. |
| 6521 | */ |
| 6522 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6523 | public void getCallForwarding(int subId, int callForwardingReason, |
| 6524 | ICallForwardingInfoCallback callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6525 | enforceReadPrivilegedPermission("getCallForwarding"); |
| 6526 | long identity = Binder.clearCallingIdentity(); |
| 6527 | try { |
| 6528 | if (DBG) { |
| 6529 | log("getCallForwarding: subId " + subId |
| 6530 | + " callForwardingReason" + callForwardingReason); |
| 6531 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6532 | |
| 6533 | Phone phone = getPhone(subId); |
| 6534 | if (phone == null) { |
| 6535 | try { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 6536 | callback.onError( |
| 6537 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6538 | } catch (RemoteException e) { |
| 6539 | // ignore |
| 6540 | } |
| 6541 | return; |
| 6542 | } |
| 6543 | |
| 6544 | Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create( |
| 6545 | callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() { |
| 6546 | @Override |
| 6547 | public void onCallForwardingInfoAvailable(CallForwardingInfo info) { |
| 6548 | try { |
| 6549 | callback.onCallForwardingInfoAvailable(info); |
| 6550 | } catch (RemoteException e) { |
| 6551 | // ignore |
| 6552 | } |
| 6553 | } |
| 6554 | |
| 6555 | @Override |
| 6556 | public void onError(int error) { |
| 6557 | try { |
| 6558 | callback.onError(error); |
| 6559 | } catch (RemoteException e) { |
| 6560 | // ignore |
| 6561 | } |
| 6562 | } |
| 6563 | }); |
| 6564 | sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6565 | } finally { |
| 6566 | Binder.restoreCallingIdentity(identity); |
| 6567 | } |
| 6568 | } |
| 6569 | |
| 6570 | /** |
| 6571 | * Sets the voice call forwarding info including status (enable/disable), call forwarding |
| 6572 | * reason, the number to forward, and the timeout before the forwarding is attempted. |
| 6573 | */ |
| 6574 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6575 | public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo, |
| 6576 | IIntegerConsumer callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6577 | enforceModifyPermission(); |
| 6578 | long identity = Binder.clearCallingIdentity(); |
| 6579 | try { |
| 6580 | if (DBG) { |
| 6581 | log("setCallForwarding: subId " + subId |
| 6582 | + " callForwardingInfo" + callForwardingInfo); |
| 6583 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6584 | |
| 6585 | Phone phone = getPhone(subId); |
| 6586 | if (phone == null) { |
| 6587 | try { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 6588 | callback.accept( |
| 6589 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6590 | } catch (RemoteException e) { |
| 6591 | // ignore |
| 6592 | } |
| 6593 | return; |
| 6594 | } |
| 6595 | |
| 6596 | Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo, |
| 6597 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 6598 | |
| 6599 | sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6600 | } finally { |
| 6601 | Binder.restoreCallingIdentity(identity); |
| 6602 | } |
| 6603 | } |
| 6604 | |
| 6605 | /** |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6606 | * Get the call waiting status for a subId. |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6607 | */ |
| 6608 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6609 | public void getCallWaitingStatus(int subId, IIntegerConsumer callback) { |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6610 | enforceReadPrivilegedPermission("getCallWaitingStatus"); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6611 | long identity = Binder.clearCallingIdentity(); |
| 6612 | try { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6613 | Phone phone = getPhone(subId); |
| 6614 | if (phone == null) { |
| 6615 | try { |
| 6616 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 6617 | } catch (RemoteException e) { |
| 6618 | // ignore |
| 6619 | } |
| 6620 | return; |
| 6621 | } |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6622 | CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext()); |
| 6623 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 6624 | boolean requireUssd = c.getBoolean( |
| 6625 | CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6626 | |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6627 | if (DBG) log("getCallWaitingStatus: subId " + subId); |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6628 | if (requireUssd) { |
| 6629 | CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(), |
| 6630 | getSubscriptionCarrierId(subId)); |
| 6631 | String newUssdCommand = ""; |
| 6632 | try { |
| 6633 | newUssdCommand = carrierXmlParser.getFeature( |
| 6634 | CarrierXmlParser.FEATURE_CALL_WAITING) |
| 6635 | .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null); |
| 6636 | } catch (NullPointerException e) { |
| 6637 | loge("Failed to generate USSD number" + e); |
| 6638 | } |
| 6639 | ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver( |
| 6640 | mMainThreadHandler, callback, carrierXmlParser, |
| 6641 | CarrierXmlParser.SsEntry.SSAction.QUERY); |
| 6642 | final String ussdCommand = newUssdCommand; |
| 6643 | Executors.newSingleThreadExecutor().execute(() -> { |
| 6644 | handleUssdRequest(subId, ussdCommand, wrappedCallback); |
| 6645 | }); |
| 6646 | } else { |
| 6647 | Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException( |
| 6648 | callback::accept); |
| 6649 | sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null); |
| 6650 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6651 | } finally { |
| 6652 | Binder.restoreCallingIdentity(identity); |
| 6653 | } |
| 6654 | } |
| 6655 | |
| 6656 | /** |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6657 | * Sets whether call waiting is enabled for a given subId. |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6658 | */ |
| 6659 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6660 | public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6661 | enforceModifyPermission(); |
| 6662 | long identity = Binder.clearCallingIdentity(); |
| 6663 | try { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6664 | if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable); |
| 6665 | |
| 6666 | Phone phone = getPhone(subId); |
| 6667 | if (phone == null) { |
| 6668 | try { |
| 6669 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 6670 | } catch (RemoteException e) { |
| 6671 | // ignore |
| 6672 | } |
| 6673 | return; |
| 6674 | } |
| 6675 | |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6676 | CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext()); |
| 6677 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 6678 | boolean requireUssd = c.getBoolean( |
| 6679 | CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6680 | |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6681 | if (DBG) log("getCallWaitingStatus: subId " + subId); |
| 6682 | if (requireUssd) { |
| 6683 | CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(), |
| 6684 | getSubscriptionCarrierId(subId)); |
| 6685 | CarrierXmlParser.SsEntry.SSAction ssAction = |
| 6686 | enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE |
| 6687 | : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE; |
| 6688 | String newUssdCommand = ""; |
| 6689 | try { |
| 6690 | newUssdCommand = carrierXmlParser.getFeature( |
| 6691 | CarrierXmlParser.FEATURE_CALL_WAITING) |
| 6692 | .makeCommand(ssAction, null); |
| 6693 | } catch (NullPointerException e) { |
| 6694 | loge("Failed to generate USSD number" + e); |
| 6695 | } |
| 6696 | ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver( |
| 6697 | mMainThreadHandler, callback, carrierXmlParser, ssAction); |
| 6698 | final String ussdCommand = newUssdCommand; |
| 6699 | Executors.newSingleThreadExecutor().execute(() -> { |
| 6700 | handleUssdRequest(subId, ussdCommand, wrappedCallback); |
| 6701 | }); |
| 6702 | } else { |
| 6703 | Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable, |
| 6704 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 6705 | |
| 6706 | sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null); |
| 6707 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6708 | } finally { |
| 6709 | Binder.restoreCallingIdentity(identity); |
| 6710 | } |
| 6711 | } |
| 6712 | |
| 6713 | /** |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 6714 | * Starts a new network scan and returns the id of this scan. |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6715 | * |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 6716 | * @param subId id of the subscription |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 6717 | * @param renounceFineLocationAccess Set this to true if the caller would not like to receive |
| 6718 | * location related information which will be sent if the caller already possess |
| 6719 | * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 6720 | * @param request contains the radio access networks with bands/channels to scan |
| 6721 | * @param messenger callback messenger for scan results or errors |
| 6722 | * @param binder for the purpose of auto clean when the user thread crashes |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6723 | * @return the id of the requested scan which can be used to stop the scan. |
| 6724 | */ |
| 6725 | @Override |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 6726 | public int requestNetworkScan(int subId, boolean renounceFineLocationAccess, |
| 6727 | NetworkScanRequest request, Messenger messenger, |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6728 | IBinder binder, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6729 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6730 | mApp, subId, "requestNetworkScan"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6731 | LocationAccessPolicy.LocationPermissionResult locationResult = |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 6732 | LocationAccessPolicy.LocationPermissionResult.DENIED_HARD; |
| 6733 | if (!renounceFineLocationAccess) { |
| 6734 | locationResult = LocationAccessPolicy.checkLocationPermission(mApp, |
| 6735 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 6736 | .setCallingPackage(callingPackage) |
| 6737 | .setCallingFeatureId(callingFeatureId) |
| 6738 | .setCallingPid(Binder.getCallingPid()) |
| 6739 | .setCallingUid(Binder.getCallingUid()) |
| 6740 | .setMethod("requestNetworkScan") |
| 6741 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 6742 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 6743 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 6744 | .build()); |
| 6745 | } |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6746 | if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) { |
Nathan Harold | 1c11dba | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 6747 | SecurityException e = checkNetworkRequestForSanitizedLocationAccess( |
| 6748 | request, subId, callingPackage); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6749 | if (e != null) { |
| 6750 | if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) { |
| 6751 | throw e; |
| 6752 | } else { |
Hall Liu | 0e5abaf | 2019-04-04 01:25:30 -0700 | [diff] [blame] | 6753 | loge(e.getMessage()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6754 | return TelephonyScanManager.INVALID_SCAN_ID; |
| 6755 | } |
| 6756 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6757 | } |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6758 | int callingUid = Binder.getCallingUid(); |
| 6759 | int callingPid = Binder.getCallingPid(); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 6760 | final long identity = Binder.clearCallingIdentity(); |
| 6761 | try { |
| 6762 | return mNetworkScanRequestTracker.startNetworkScan( |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 6763 | renounceFineLocationAccess, request, messenger, binder, getPhone(subId), |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6764 | callingUid, callingPid, callingPackage); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 6765 | } finally { |
| 6766 | Binder.restoreCallingIdentity(identity); |
| 6767 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6768 | } |
| 6769 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6770 | private SecurityException checkNetworkRequestForSanitizedLocationAccess( |
Nathan Harold | 1c11dba | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 6771 | NetworkScanRequest request, int subId, String callingPackage) { |
Rambo Wang | 3dee30a | 2022-10-20 16:52:29 +0000 | [diff] [blame] | 6772 | boolean hasCarrierPriv; |
| 6773 | final long identity = Binder.clearCallingIdentity(); |
| 6774 | try { |
| 6775 | hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage) |
| 6776 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 6777 | } finally { |
| 6778 | Binder.restoreCallingIdentity(identity); |
| 6779 | } |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 6780 | boolean hasNetworkScanPermission = |
| 6781 | mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN) |
| 6782 | == PERMISSION_GRANTED; |
| 6783 | |
| 6784 | if (!hasCarrierPriv && !hasNetworkScanPermission) { |
| 6785 | return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed" |
| 6786 | + " for network scans without location access."); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6787 | } |
| 6788 | |
| 6789 | if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) { |
| 6790 | for (RadioAccessSpecifier ras : request.getSpecifiers()) { |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6791 | if (ras.getChannels() != null && ras.getChannels().length > 0) { |
| 6792 | return new SecurityException("Specific channels must not be" |
| 6793 | + " scanned without location access."); |
| 6794 | } |
| 6795 | } |
| 6796 | } |
| 6797 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6798 | return null; |
| 6799 | } |
| 6800 | |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6801 | /** |
| 6802 | * Stops an existing network scan with the given scanId. |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 6803 | * |
| 6804 | * @param subId id of the subscription |
| 6805 | * @param scanId id of the scan that needs to be stopped |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6806 | */ |
| 6807 | @Override |
| 6808 | public void stopNetworkScan(int subId, int scanId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6809 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6810 | mApp, subId, "stopNetworkScan"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6811 | |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6812 | int callingUid = Binder.getCallingUid(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6813 | final long identity = Binder.clearCallingIdentity(); |
| 6814 | try { |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6815 | mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6816 | } finally { |
| 6817 | Binder.restoreCallingIdentity(identity); |
| 6818 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6819 | } |
| 6820 | |
| 6821 | /** |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6822 | * Get the allowed network types bitmask. |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 6823 | * |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6824 | * @return the allowed network types bitmask, defined in RILConstants.java. |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 6825 | */ |
| 6826 | @Override |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6827 | public int getAllowedNetworkTypesBitmask(int subId) { |
Pengquan Meng | a4009cb | 2018-12-20 11:00:24 -0800 | [diff] [blame] | 6828 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 6829 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6830 | mApp, subId, "getAllowedNetworkTypesBitmask"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6831 | |
| 6832 | final long identity = Binder.clearCallingIdentity(); |
| 6833 | try { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6834 | if (DBG) log("getAllowedNetworkTypesBitmask"); |
| 6835 | int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId); |
| 6836 | int networkTypesBitmask = (result != null ? result[0] : -1); |
| 6837 | if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask); |
| 6838 | return networkTypesBitmask; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6839 | } finally { |
| 6840 | Binder.restoreCallingIdentity(identity); |
| 6841 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 6842 | } |
| 6843 | |
| 6844 | /** |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6845 | * Get the allowed network types for certain reason. |
| 6846 | * |
| 6847 | * @param subId the id of the subscription. |
| 6848 | * @param reason the reason the allowed network type change is taking place |
| 6849 | * @return the allowed network types. |
| 6850 | */ |
| 6851 | @Override |
| 6852 | public long getAllowedNetworkTypesForReason(int subId, |
| 6853 | @TelephonyManager.AllowedNetworkTypesReason int reason) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 6854 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 6855 | mApp, subId, "getAllowedNetworkTypesForReason"); |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6856 | final long identity = Binder.clearCallingIdentity(); |
| 6857 | try { |
| 6858 | return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason); |
| 6859 | } finally { |
| 6860 | Binder.restoreCallingIdentity(identity); |
| 6861 | } |
| 6862 | } |
| 6863 | |
| 6864 | /** |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6865 | * Enable/Disable E-UTRA-NR Dual Connectivity |
| 6866 | * @param subId subscription id of the sim card |
| 6867 | * @param nrDualConnectivityState expected NR dual connectivity state |
| 6868 | * This can be passed following states |
| 6869 | * <ol> |
| 6870 | * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE} |
| 6871 | * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE} |
| 6872 | * <li>Disable NR dual connectivity and force secondary cell to be released |
| 6873 | * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE} |
| 6874 | * </ol> |
| 6875 | * @return operation result. |
| 6876 | */ |
| 6877 | @Override |
| 6878 | public int setNrDualConnectivityState(int subId, |
| 6879 | @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) { |
| 6880 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6881 | mApp, subId, "enableNRDualConnectivity"); |
Sooraj Sasindran | 0e4e00a | 2021-03-16 18:02:32 -0700 | [diff] [blame] | 6882 | if (!isRadioInterfaceCapabilitySupported( |
Sooraj Sasindran | dfd595b | 2021-03-11 17:38:13 -0800 | [diff] [blame] | 6883 | TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) { |
| 6884 | return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED; |
| 6885 | } |
| 6886 | |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6887 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 6888 | final long identity = Binder.clearCallingIdentity(); |
| 6889 | try { |
| 6890 | int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY, |
| 6891 | nrDualConnectivityState, subId, |
| 6892 | workSource); |
| 6893 | if (DBG) log("enableNRDualConnectivity result: " + result); |
| 6894 | return result; |
| 6895 | } finally { |
| 6896 | Binder.restoreCallingIdentity(identity); |
| 6897 | } |
| 6898 | } |
| 6899 | |
| 6900 | /** |
| 6901 | * Is E-UTRA-NR Dual Connectivity enabled |
| 6902 | * @return true if dual connectivity is enabled else false |
| 6903 | */ |
| 6904 | @Override |
| 6905 | public boolean isNrDualConnectivityEnabled(int subId) { |
| 6906 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 6907 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6908 | mApp, subId, "isNRDualConnectivityEnabled"); |
Sooraj Sasindran | 0e4e00a | 2021-03-16 18:02:32 -0700 | [diff] [blame] | 6909 | if (!isRadioInterfaceCapabilitySupported( |
Sooraj Sasindran | dfd595b | 2021-03-11 17:38:13 -0800 | [diff] [blame] | 6910 | TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) { |
| 6911 | return false; |
| 6912 | } |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6913 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 6914 | final long identity = Binder.clearCallingIdentity(); |
| 6915 | try { |
| 6916 | boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED, |
| 6917 | null, subId, workSource); |
| 6918 | if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled); |
| 6919 | return isEnabled; |
| 6920 | } finally { |
| 6921 | Binder.restoreCallingIdentity(identity); |
| 6922 | } |
| 6923 | } |
| 6924 | |
| 6925 | /** |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6926 | * Set the allowed network types of the device and |
| 6927 | * provide the reason triggering the allowed network change. |
| 6928 | * |
| 6929 | * @param subId the id of the subscription. |
| 6930 | * @param reason the reason the allowed network type change is taking place |
| 6931 | * @param allowedNetworkTypes the allowed network types. |
| 6932 | * @return true on success; false on any failure. |
| 6933 | */ |
| 6934 | @Override |
| 6935 | public boolean setAllowedNetworkTypesForReason(int subId, |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6936 | @TelephonyManager.AllowedNetworkTypesReason int reason, |
| 6937 | @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) { |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6938 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6939 | mApp, subId, "setAllowedNetworkTypesForReason"); |
Gil Cukierman | 1d3d375 | 2022-10-03 21:31:33 +0000 | [diff] [blame] | 6940 | // If the caller only has carrier privileges, then they should not be able to override |
| 6941 | // any network types which were set for security reasons. |
| 6942 | if (mApp.checkCallingOrSelfPermission(Manifest.permission.MODIFY_PHONE_STATE) |
| 6943 | != PERMISSION_GRANTED |
Gil Cukierman | 2a8f48b | 2023-01-26 20:26:20 +0000 | [diff] [blame] | 6944 | && reason == TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_ENABLE_2G) { |
Gil Cukierman | 1d3d375 | 2022-10-03 21:31:33 +0000 | [diff] [blame] | 6945 | throw new SecurityException( |
| 6946 | "setAllowedNetworkTypesForReason cannot be called with carrier privileges for" |
Gil Cukierman | 2a8f48b | 2023-01-26 20:26:20 +0000 | [diff] [blame] | 6947 | + " reason " + reason); |
Gil Cukierman | 1d3d375 | 2022-10-03 21:31:33 +0000 | [diff] [blame] | 6948 | } |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6949 | if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) { |
Jack Yu | 5b49433 | 2023-01-23 18:18:04 +0000 | [diff] [blame] | 6950 | loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason); |
SongFerngWang | 7ffc273 | 2021-04-15 19:46:33 +0800 | [diff] [blame] | 6951 | return false; |
| 6952 | } |
| 6953 | if (!SubscriptionManager.isUsableSubscriptionId(subId)) { |
| 6954 | loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId); |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6955 | return false; |
| 6956 | } |
| 6957 | |
Jack Yu | 5b49433 | 2023-01-23 18:18:04 +0000 | [diff] [blame] | 6958 | log("setAllowedNetworkTypesForReason: subId=" + subId + ", reason=" + reason + " value: " |
| 6959 | + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes)); |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 6960 | |
Jack Yu | e37dd26 | 2022-12-16 11:53:37 -0800 | [diff] [blame] | 6961 | Phone phone = getPhone(subId); |
| 6962 | if (phone == null) { |
| 6963 | return false; |
| 6964 | } |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 6965 | |
Jack Yu | e37dd26 | 2022-12-16 11:53:37 -0800 | [diff] [blame] | 6966 | if (allowedNetworkTypes == phone.getAllowedNetworkTypes(reason)) { |
Jack Yu | 5b49433 | 2023-01-23 18:18:04 +0000 | [diff] [blame] | 6967 | log("setAllowedNetworkTypesForReason: " + reason + "does not change value"); |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 6968 | return true; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6969 | } |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 6970 | |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6971 | final long identity = Binder.clearCallingIdentity(); |
| 6972 | try { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6973 | Boolean success = (Boolean) sendRequest( |
| 6974 | CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON, |
| 6975 | new Pair<Integer, Long>(reason, allowedNetworkTypes), subId); |
| 6976 | |
| 6977 | if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail")); |
| 6978 | return success; |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6979 | } finally { |
| 6980 | Binder.restoreCallingIdentity(identity); |
| 6981 | } |
| 6982 | } |
| 6983 | |
| 6984 | /** |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6985 | * Check whether DUN APN is required for tethering with subId. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6986 | * |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6987 | * @param subId the id of the subscription to require tethering. |
Amit Mahajan | fe58cdf | 2017-07-11 12:01:53 -0700 | [diff] [blame] | 6988 | * @return {@code true} if DUN APN is required for tethering. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6989 | * @hide |
| 6990 | */ |
| 6991 | @Override |
SongFerngWang | f08d812 | 2019-11-15 14:58:44 +0800 | [diff] [blame] | 6992 | public boolean isTetheringApnRequiredForSubscriber(int subId) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6993 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6994 | final long identity = Binder.clearCallingIdentity(); |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6995 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6996 | try { |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6997 | if (phone != null) { |
| 6998 | return phone.hasMatchedTetherApnSetting(); |
| 6999 | } else { |
| 7000 | return false; |
| 7001 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7002 | } finally { |
| 7003 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 7004 | } |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 7005 | } |
| 7006 | |
| 7007 | /** |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 7008 | * Get the user enabled state of Mobile Data. |
| 7009 | * |
| 7010 | * TODO: remove and use isUserDataEnabled. |
| 7011 | * This can't be removed now because some vendor codes |
| 7012 | * calls through ITelephony directly while they should |
| 7013 | * use TelephonyManager. |
| 7014 | * |
| 7015 | * @return true on enabled |
| 7016 | */ |
| 7017 | @Override |
| 7018 | public boolean getDataEnabled(int subId) { |
| 7019 | return isUserDataEnabled(subId); |
| 7020 | } |
| 7021 | |
| 7022 | /** |
| 7023 | * Get whether mobile data is enabled per user setting. |
| 7024 | * |
| 7025 | * There are other factors deciding whether mobile data is actually enabled, but they are |
| 7026 | * not considered here. See {@link #isDataEnabled(int)} for more details. |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 7027 | * |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7028 | * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE |
| 7029 | * or carrier privileges. |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 7030 | * |
| 7031 | * @return {@code true} if data is enabled else {@code false} |
| 7032 | */ |
| 7033 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 7034 | public boolean isUserDataEnabled(int subId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7035 | String functionName = "isUserDataEnabled"; |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 7036 | try { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7037 | try { |
| 7038 | mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE, |
| 7039 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7040 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7041 | mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName); |
| 7042 | } |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7043 | } catch (SecurityException e) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7044 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7045 | mApp, subId, functionName); |
| 7046 | |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 7047 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7048 | |
| 7049 | final long identity = Binder.clearCallingIdentity(); |
| 7050 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 7051 | int phoneId = SubscriptionManager.getPhoneId(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7052 | if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 7053 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 7054 | if (phone != null) { |
| 7055 | boolean retVal = phone.isUserDataEnabled(); |
| 7056 | if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 7057 | return retVal; |
| 7058 | } else { |
| 7059 | if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 7060 | return false; |
| 7061 | } |
| 7062 | } finally { |
| 7063 | Binder.restoreCallingIdentity(identity); |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 7064 | } |
| 7065 | } |
| 7066 | |
| 7067 | /** |
Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 7068 | * Checks if the device is capable of mobile data by considering whether whether the |
| 7069 | * user has enabled mobile data, whether the carrier has enabled mobile data, and |
| 7070 | * whether the network policy allows data connections. |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 7071 | * |
Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 7072 | * @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] | 7073 | */ |
| 7074 | @Override |
| 7075 | public boolean isDataEnabled(int subId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7076 | String functionName = "isDataEnabled"; |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7077 | try { |
| 7078 | try { |
| 7079 | mApp.enforceCallingOrSelfPermission( |
| 7080 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7081 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7082 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7083 | try { |
| 7084 | mApp.enforceCallingOrSelfPermission( |
| 7085 | android.Manifest.permission.READ_PHONE_STATE, |
| 7086 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7087 | } catch (SecurityException e2) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7088 | mApp.enforceCallingOrSelfPermission( |
| 7089 | permission.READ_BASIC_PHONE_STATE, functionName); |
| 7090 | } |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7091 | } |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7092 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7093 | enforceReadPrivilegedPermission(functionName); |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7094 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7095 | |
| 7096 | final long identity = Binder.clearCallingIdentity(); |
| 7097 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 7098 | int phoneId = SubscriptionManager.getPhoneId(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7099 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 7100 | if (phone != null) { |
Sarah Chin | e04784a | 2022-10-31 20:32:34 -0700 | [diff] [blame] | 7101 | boolean retVal = phone.getDataSettingsManager().isDataEnabled(); |
Jack Yu | 4ad64e5 | 2021-12-03 14:23:53 -0800 | [diff] [blame] | 7102 | if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7103 | return retVal; |
| 7104 | } else { |
| 7105 | if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 7106 | return false; |
| 7107 | } |
| 7108 | } finally { |
| 7109 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 7110 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 7111 | } |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 7112 | |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7113 | /** |
| 7114 | * Check if data is enabled for a specific reason |
| 7115 | * @param subId Subscription index |
| 7116 | * @param reason the reason the data enable change is taking place |
| 7117 | * @return {@code true} if the overall data is enabled; {@code false} if not. |
| 7118 | */ |
| 7119 | @Override |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7120 | public boolean isDataEnabledForReason(int subId, |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7121 | @TelephonyManager.DataEnabledReason int reason) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7122 | String functionName = "isDataEnabledForReason"; |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7123 | try { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7124 | try { |
| 7125 | mApp.enforceCallingOrSelfPermission( |
| 7126 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 7127 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7128 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7129 | mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE, |
| 7130 | functionName); |
| 7131 | } |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7132 | } catch (SecurityException e) { |
Sooraj Sasindran | 0d909a0 | 2021-11-08 12:01:16 -0800 | [diff] [blame] | 7133 | try { |
| 7134 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7135 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7136 | } catch (SecurityException e2) { |
Sooraj Sasindran | 0d909a0 | 2021-11-08 12:01:16 -0800 | [diff] [blame] | 7137 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7138 | mApp, subId, functionName); |
Sooraj Sasindran | 0d909a0 | 2021-11-08 12:01:16 -0800 | [diff] [blame] | 7139 | } |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7140 | } |
| 7141 | |
| 7142 | |
| 7143 | final long identity = Binder.clearCallingIdentity(); |
| 7144 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 7145 | int phoneId = SubscriptionManager.getPhoneId(subId); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7146 | if (DBG) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7147 | log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7148 | + " reason=" + reason); |
| 7149 | } |
| 7150 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 7151 | if (phone != null) { |
| 7152 | boolean retVal; |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 7153 | retVal = phone.getDataSettingsManager().isDataEnabledForReason(reason); |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7154 | if (DBG) log("isDataEnabledForReason: retVal=" + retVal); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7155 | return retVal; |
| 7156 | } else { |
| 7157 | if (DBG) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7158 | loge("isDataEnabledForReason: no phone subId=" |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7159 | + subId + " retVal=false"); |
| 7160 | } |
| 7161 | return false; |
| 7162 | } |
| 7163 | } finally { |
| 7164 | Binder.restoreCallingIdentity(identity); |
| 7165 | } |
| 7166 | } |
| 7167 | |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 7168 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7169 | public int getCarrierPrivilegeStatus(int subId) { |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7170 | // No permission needed; this only lets the caller inspect their own status. |
| 7171 | return getCarrierPrivilegeStatusForUidWithPermission(subId, Binder.getCallingUid()); |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 7172 | } |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 7173 | |
| 7174 | @Override |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7175 | public int getCarrierPrivilegeStatusForUid(int subId, int uid) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 7176 | enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid"); |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7177 | return getCarrierPrivilegeStatusForUidWithPermission(subId, uid); |
| 7178 | } |
| 7179 | |
| 7180 | private int getCarrierPrivilegeStatusForUidWithPermission(int subId, int uid) { |
| 7181 | Phone phone = getPhone(subId); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7182 | if (phone == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 7183 | loge("getCarrierPrivilegeStatusForUid: Invalid subId"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7184 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 7185 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7186 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7187 | if (cpt == null) { |
| 7188 | loge("getCarrierPrivilegeStatusForUid: No CarrierPrivilegesTracker"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7189 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 7190 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7191 | return cpt.getCarrierPrivilegeStatusForUid(uid); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7192 | } |
| 7193 | |
| 7194 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7195 | public int checkCarrierPrivilegesForPackage(int subId, String pkgName) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 7196 | enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage"); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7197 | if (TextUtils.isEmpty(pkgName)) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 7198 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7199 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7200 | Phone phone = getPhone(subId); |
| 7201 | if (phone == null) { |
| 7202 | loge("checkCarrierPrivilegesForPackage: Invalid subId"); |
| 7203 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 7204 | } |
| 7205 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7206 | if (cpt == null) { |
| 7207 | loge("checkCarrierPrivilegesForPackage: No CarrierPrivilegesTracker"); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 7208 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 7209 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7210 | return cpt.getCarrierPrivilegeStatusForPackage(pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 7211 | } |
| 7212 | |
| 7213 | @Override |
| 7214 | public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) { |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7215 | enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackageAnyPhone"); |
Rambo Wang | e7209ce | 2022-02-23 13:41:02 -0800 | [diff] [blame] | 7216 | return checkCarrierPrivilegesForPackageAnyPhoneWithPermission(pkgName); |
| 7217 | } |
| 7218 | |
| 7219 | private int checkCarrierPrivilegesForPackageAnyPhoneWithPermission(String pkgName) { |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7220 | if (TextUtils.isEmpty(pkgName)) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 7221 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7222 | } |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 7223 | int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7224 | for (int phoneId = 0; phoneId < TelephonyManager.getDefault().getPhoneCount(); phoneId++) { |
| 7225 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 7226 | if (phone == null) { |
| 7227 | continue; |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 7228 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7229 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7230 | if (cpt == null) { |
| 7231 | continue; |
| 7232 | } |
| 7233 | result = cpt.getCarrierPrivilegeStatusForPackage(pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 7234 | if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 7235 | break; |
| 7236 | } |
| 7237 | } |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 7238 | return result; |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 7239 | } |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 7240 | |
| 7241 | @Override |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 7242 | public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 7243 | enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone"); |
Rambo Wang | 8a247eb | 2022-02-08 21:11:18 +0000 | [diff] [blame] | 7244 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 7245 | if (phone == null) { |
| 7246 | return Collections.emptyList(); |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 7247 | } |
Rambo Wang | 8a247eb | 2022-02-08 21:11:18 +0000 | [diff] [blame] | 7248 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7249 | if (cpt == null) { |
| 7250 | return Collections.emptyList(); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 7251 | } |
Rambo Wang | 8a247eb | 2022-02-08 21:11:18 +0000 | [diff] [blame] | 7252 | return cpt.getCarrierPackageNamesForIntent(intent); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 7253 | } |
| 7254 | |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 7255 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7256 | public List<String> getPackagesWithCarrierPrivileges(int phoneId) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 7257 | enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges"); |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7258 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 7259 | if (phone == null) { |
| 7260 | return Collections.emptyList(); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 7261 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7262 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7263 | if (cpt == null) { |
| 7264 | return Collections.emptyList(); |
| 7265 | } |
| 7266 | return new ArrayList<>(cpt.getPackagesWithCarrierPrivileges()); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 7267 | } |
| 7268 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7269 | @Override |
| 7270 | public List<String> getPackagesWithCarrierPrivilegesForAllPhones() { |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 7271 | enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones"); |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7272 | Set<String> privilegedPackages = new ArraySet<>(); |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 7273 | final long identity = Binder.clearCallingIdentity(); |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 7274 | try { |
| 7275 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 7276 | privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i)); |
| 7277 | } |
| 7278 | } finally { |
| 7279 | Binder.restoreCallingIdentity(identity); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7280 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7281 | return new ArrayList<>(privilegedPackages); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7282 | } |
| 7283 | |
Rambo Wang | 6812ffb | 2022-03-15 16:54:17 -0700 | [diff] [blame] | 7284 | @Override |
| 7285 | public @Nullable String getCarrierServicePackageNameForLogicalSlot(int logicalSlotIndex) { |
| 7286 | enforceReadPrivilegedPermission("getCarrierServicePackageNameForLogicalSlot"); |
| 7287 | |
| 7288 | final Phone phone = PhoneFactory.getPhone(logicalSlotIndex); |
| 7289 | if (phone == null) { |
| 7290 | return null; |
| 7291 | } |
| 7292 | final CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7293 | if (cpt == null) { |
| 7294 | return null; |
| 7295 | } |
| 7296 | return cpt.getCarrierServicePackageName(); |
| 7297 | } |
| 7298 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 7299 | private String getIccId(int subId) { |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 7300 | final Phone phone = getPhone(subId); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 7301 | UiccPort port = phone == null ? null : phone.getUiccPort(); |
| 7302 | if (port == null) { |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7303 | return null; |
| 7304 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 7305 | String iccId = port.getIccId(); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7306 | if (TextUtils.isEmpty(iccId)) { |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7307 | return null; |
| 7308 | } |
| 7309 | return iccId; |
| 7310 | } |
| 7311 | |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 7312 | @Override |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 7313 | public void setCallComposerStatus(int subId, int status) { |
| 7314 | enforceModifyPermission(); |
| 7315 | |
| 7316 | final long identity = Binder.clearCallingIdentity(); |
| 7317 | try { |
| 7318 | Phone phone = getPhone(subId); |
| 7319 | if (phone != null) { |
| 7320 | Phone defaultPhone = phone.getImsPhone(); |
| 7321 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 7322 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 7323 | imsPhone.setCallComposerStatus(status); |
Shuo Qian | 284ae75 | 2020-12-22 19:10:14 -0800 | [diff] [blame] | 7324 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| 7325 | .updateImsServiceConfig(); |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 7326 | } |
| 7327 | } |
Shuo Qian | 284ae75 | 2020-12-22 19:10:14 -0800 | [diff] [blame] | 7328 | } catch (ImsException e) { |
| 7329 | throw new ServiceSpecificException(e.getCode()); |
| 7330 | } finally { |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 7331 | Binder.restoreCallingIdentity(identity); |
| 7332 | } |
| 7333 | } |
| 7334 | |
| 7335 | @Override |
| 7336 | public int getCallComposerStatus(int subId) { |
| 7337 | enforceReadPrivilegedPermission("getCallComposerStatus"); |
| 7338 | |
| 7339 | final long identity = Binder.clearCallingIdentity(); |
| 7340 | try { |
| 7341 | Phone phone = getPhone(subId); |
| 7342 | if (phone != null) { |
| 7343 | Phone defaultPhone = phone.getImsPhone(); |
| 7344 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 7345 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 7346 | return imsPhone.getCallComposerStatus(); |
| 7347 | } |
| 7348 | } |
| 7349 | } finally { |
| 7350 | Binder.restoreCallingIdentity(identity); |
| 7351 | } |
| 7352 | return TelephonyManager.CALL_COMPOSER_STATUS_OFF; |
| 7353 | } |
| 7354 | |
| 7355 | @Override |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7356 | public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag, |
| 7357 | String number) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 7358 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7359 | subId, "setLine1NumberForDisplayForSubscriber"); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7360 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7361 | final long identity = Binder.clearCallingIdentity(); |
| 7362 | try { |
| 7363 | final String iccId = getIccId(subId); |
| 7364 | final Phone phone = getPhone(subId); |
| 7365 | if (phone == null) { |
| 7366 | return false; |
| 7367 | } |
| 7368 | final String subscriberId = phone.getSubscriberId(); |
| 7369 | |
| 7370 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 7371 | Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId=" |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7372 | + subscriberId + " to " + number); |
| 7373 | } |
| 7374 | |
| 7375 | if (TextUtils.isEmpty(iccId)) { |
| 7376 | return false; |
| 7377 | } |
| 7378 | |
| 7379 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 7380 | |
| 7381 | final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 7382 | if (alphaTag == null) { |
| 7383 | editor.remove(alphaTagPrefKey); |
| 7384 | } else { |
| 7385 | editor.putString(alphaTagPrefKey, alphaTag); |
| 7386 | } |
| 7387 | |
| 7388 | // Record both the line number and IMSI for this ICCID, since we need to |
| 7389 | // track all merged IMSIs based on line number |
| 7390 | final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 7391 | final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 7392 | if (number == null) { |
| 7393 | editor.remove(numberPrefKey); |
| 7394 | editor.remove(subscriberPrefKey); |
| 7395 | } else { |
| 7396 | editor.putString(numberPrefKey, number); |
| 7397 | editor.putString(subscriberPrefKey, subscriberId); |
| 7398 | } |
| 7399 | |
| 7400 | editor.commit(); |
| 7401 | return true; |
| 7402 | } finally { |
| 7403 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 7404 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7405 | } |
| 7406 | |
| 7407 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7408 | public String getLine1NumberForDisplay(int subId, String callingPackage, |
| 7409 | String callingFeatureId) { |
Makoto Onuki | fee6934 | 2015-06-29 14:44:50 -0700 | [diff] [blame] | 7410 | // This is open to apps with WRITE_SMS. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7411 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7412 | mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) { |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 7413 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission"); |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 7414 | return null; |
| 7415 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7416 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7417 | final long identity = Binder.clearCallingIdentity(); |
| 7418 | try { |
| 7419 | String iccId = getIccId(subId); |
| 7420 | if (iccId != null) { |
| 7421 | String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 7422 | if (DBG_MERGE) { |
| 7423 | log("getLine1NumberForDisplay returning " |
| 7424 | + mTelephonySharedPreferences.getString(numberPrefKey, null)); |
| 7425 | } |
| 7426 | return mTelephonySharedPreferences.getString(numberPrefKey, null); |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 7427 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7428 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null"); |
| 7429 | return null; |
| 7430 | } finally { |
| 7431 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7432 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7433 | } |
| 7434 | |
| 7435 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7436 | public String getLine1AlphaTagForDisplay(int subId, String callingPackage, |
| 7437 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7438 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7439 | mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 7440 | return null; |
| 7441 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7442 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7443 | final long identity = Binder.clearCallingIdentity(); |
| 7444 | try { |
| 7445 | String iccId = getIccId(subId); |
| 7446 | if (iccId != null) { |
| 7447 | String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 7448 | return mTelephonySharedPreferences.getString(alphaTagPrefKey, null); |
| 7449 | } |
| 7450 | return null; |
| 7451 | } finally { |
| 7452 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7453 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7454 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 7455 | |
| 7456 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7457 | public String[] getMergedSubscriberIds(int subId, String callingPackage, |
| 7458 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7459 | // This API isn't public, so no need to provide a valid subscription ID - we're not worried |
| 7460 | // about carrier-privileged callers not having access. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7461 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7462 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7463 | callingFeatureId, "getMergedSubscriberIds")) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7464 | return null; |
| 7465 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7466 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 7467 | // Clear calling identity, when calling TelephonyManager, because callerUid must be |
| 7468 | // the process, where TelephonyManager was instantiated. |
| 7469 | // Otherwise AppOps check will fail. |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7470 | final long identity = Binder.clearCallingIdentity(); |
| 7471 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7472 | final Context context = mApp; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7473 | final TelephonyManager tele = TelephonyManager.from(context); |
| 7474 | final SubscriptionManager sub = SubscriptionManager.from(context); |
| 7475 | |
| 7476 | // Figure out what subscribers are currently active |
| 7477 | final ArraySet<String> activeSubscriberIds = new ArraySet<>(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7478 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 7479 | // Only consider subs which match the current subId |
| 7480 | // This logic can be simplified. See b/131189269 for progress. |
| 7481 | if (isActiveSubscription(subId)) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7482 | activeSubscriberIds.add(tele.getSubscriberId(subId)); |
| 7483 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7484 | |
| 7485 | // First pass, find a number override for an active subscriber |
| 7486 | String mergeNumber = null; |
| 7487 | final Map<String, ?> prefs = mTelephonySharedPreferences.getAll(); |
| 7488 | for (String key : prefs.keySet()) { |
| 7489 | if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) { |
| 7490 | final String subscriberId = (String) prefs.get(key); |
| 7491 | if (activeSubscriberIds.contains(subscriberId)) { |
| 7492 | final String iccId = key.substring( |
| 7493 | PREF_CARRIERS_SUBSCRIBER_PREFIX.length()); |
| 7494 | final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 7495 | mergeNumber = (String) prefs.get(numberKey); |
| 7496 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 7497 | Rlog.d(LOG_TAG, "Found line number " + mergeNumber |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7498 | + " for active subscriber " + subscriberId); |
| 7499 | } |
| 7500 | if (!TextUtils.isEmpty(mergeNumber)) { |
| 7501 | break; |
| 7502 | } |
| 7503 | } |
| 7504 | } |
| 7505 | } |
| 7506 | |
| 7507 | // Shortcut when no active merged subscribers |
| 7508 | if (TextUtils.isEmpty(mergeNumber)) { |
| 7509 | return null; |
| 7510 | } |
| 7511 | |
| 7512 | // Second pass, find all subscribers under that line override |
| 7513 | final ArraySet<String> result = new ArraySet<>(); |
| 7514 | for (String key : prefs.keySet()) { |
| 7515 | if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) { |
| 7516 | final String number = (String) prefs.get(key); |
| 7517 | if (mergeNumber.equals(number)) { |
| 7518 | final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length()); |
| 7519 | final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 7520 | final String subscriberId = (String) prefs.get(subscriberKey); |
| 7521 | if (!TextUtils.isEmpty(subscriberId)) { |
| 7522 | result.add(subscriberId); |
| 7523 | } |
| 7524 | } |
| 7525 | } |
| 7526 | } |
| 7527 | |
| 7528 | final String[] resultArray = result.toArray(new String[result.size()]); |
| 7529 | Arrays.sort(resultArray); |
| 7530 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 7531 | Rlog.d(LOG_TAG, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7532 | "Found subscribers " + Arrays.toString(resultArray) + " after merge"); |
| 7533 | } |
| 7534 | return resultArray; |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7535 | } finally { |
| 7536 | Binder.restoreCallingIdentity(identity); |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7537 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7538 | } |
| 7539 | |
| 7540 | @Override |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 7541 | public String[] getMergedImsisFromGroup(int subId, String callingPackage) { |
| 7542 | enforceReadPrivilegedPermission("getMergedImsisFromGroup"); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7543 | |
| 7544 | final long identity = Binder.clearCallingIdentity(); |
| 7545 | try { |
| 7546 | final TelephonyManager telephonyManager = mApp.getSystemService( |
| 7547 | TelephonyManager.class); |
| 7548 | String subscriberId = telephonyManager.getSubscriberId(subId); |
| 7549 | if (subscriberId == null) { |
| 7550 | if (DBG) { |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 7551 | log("getMergedImsisFromGroup can't find subscriberId for subId " |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7552 | + subId); |
| 7553 | } |
| 7554 | return null; |
| 7555 | } |
| 7556 | |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 7557 | ParcelUuid groupUuid; |
| 7558 | if (PhoneFactory.isSubscriptionManagerServiceEnabled()) { |
| 7559 | final SubscriptionInfo info = SubscriptionManagerService.getInstance() |
| 7560 | .getSubscriptionInfo(subId); |
| 7561 | groupUuid = info.getGroupUuid(); |
| 7562 | } else { |
| 7563 | final SubscriptionInfo info = mSubscriptionController |
| 7564 | .getSubscriptionInfo(subId); |
| 7565 | groupUuid = info.getGroupUuid(); |
| 7566 | } |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7567 | // If it doesn't belong to any group, return just subscriberId of itself. |
| 7568 | if (groupUuid == null) { |
| 7569 | return new String[]{subscriberId}; |
| 7570 | } |
| 7571 | |
| 7572 | // Get all subscriberIds from the group. |
| 7573 | final List<String> mergedSubscriberIds = new ArrayList<>(); |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 7574 | List<SubscriptionInfo> groupInfos; |
| 7575 | if (PhoneFactory.isSubscriptionManagerServiceEnabled()) { |
| 7576 | groupInfos = SubscriptionManagerService.getInstance() |
| 7577 | .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(), |
| 7578 | mApp.getAttributionTag()); |
| 7579 | } else { |
| 7580 | groupInfos = mSubscriptionController |
| 7581 | .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(), |
| 7582 | mApp.getAttributionTag()); |
| 7583 | } |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7584 | for (SubscriptionInfo subInfo : groupInfos) { |
| 7585 | subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId()); |
| 7586 | if (subscriberId != null) { |
| 7587 | mergedSubscriberIds.add(subscriberId); |
| 7588 | } |
| 7589 | } |
| 7590 | |
| 7591 | return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]); |
| 7592 | } finally { |
| 7593 | Binder.restoreCallingIdentity(identity); |
| 7594 | |
| 7595 | } |
| 7596 | } |
| 7597 | |
| 7598 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7599 | public boolean setOperatorBrandOverride(int subId, String brand) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 7600 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7601 | subId, "setOperatorBrandOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7602 | |
| 7603 | final long identity = Binder.clearCallingIdentity(); |
| 7604 | try { |
| 7605 | final Phone phone = getPhone(subId); |
| 7606 | return phone == null ? false : phone.setOperatorBrandOverride(brand); |
| 7607 | } finally { |
| 7608 | Binder.restoreCallingIdentity(identity); |
| 7609 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 7610 | } |
Steven Liu | 4bf01bc | 2014-07-17 11:05:29 -0500 | [diff] [blame] | 7611 | |
| 7612 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7613 | public boolean setRoamingOverride(int subId, List<String> gsmRoamingList, |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 7614 | List<String> gsmNonRoamingList, List<String> cdmaRoamingList, |
| 7615 | List<String> cdmaNonRoamingList) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 7616 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 7617 | mApp, subId, "setRoamingOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7618 | |
| 7619 | final long identity = Binder.clearCallingIdentity(); |
| 7620 | try { |
| 7621 | final Phone phone = getPhone(subId); |
| 7622 | if (phone == null) { |
| 7623 | return false; |
| 7624 | } |
| 7625 | return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList, |
| 7626 | cdmaNonRoamingList); |
| 7627 | } finally { |
| 7628 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7629 | } |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 7630 | } |
| 7631 | |
| 7632 | @Override |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 7633 | @Deprecated |
| 7634 | public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) { |
| 7635 | enforceModifyPermission(); |
| 7636 | |
| 7637 | int returnValue = 0; |
| 7638 | try { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7639 | AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 7640 | if(result.exception == null) { |
| 7641 | if (result.result != null) { |
| 7642 | byte[] responseData = (byte[])(result.result); |
| 7643 | if(responseData.length > oemResp.length) { |
| 7644 | Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " + |
| 7645 | responseData.length + "bytes. Buffer Size is " + |
| 7646 | oemResp.length + "bytes."); |
| 7647 | } |
| 7648 | System.arraycopy(responseData, 0, oemResp, 0, responseData.length); |
| 7649 | returnValue = responseData.length; |
| 7650 | } |
| 7651 | } else { |
| 7652 | CommandException ex = (CommandException) result.exception; |
| 7653 | returnValue = ex.getCommandError().ordinal(); |
| 7654 | if(returnValue > 0) returnValue *= -1; |
| 7655 | } |
| 7656 | } catch (RuntimeException e) { |
| 7657 | Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception"); |
| 7658 | returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal()); |
| 7659 | if(returnValue > 0) returnValue *= -1; |
| 7660 | } |
| 7661 | |
| 7662 | return returnValue; |
| 7663 | } |
| 7664 | |
| 7665 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 7666 | public int getRadioAccessFamily(int phoneId, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7667 | Phone phone = PhoneFactory.getPhone(phoneId); |
Shuo Qian | dee5340 | 2020-05-29 14:08:15 -0700 | [diff] [blame] | 7668 | try { |
| 7669 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 7670 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Shuo Qian | dee5340 | 2020-05-29 14:08:15 -0700 | [diff] [blame] | 7671 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 7672 | } catch (SecurityException e) { |
| 7673 | EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission"); |
| 7674 | throw e; |
| 7675 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7676 | int raf = RadioAccessFamily.RAF_UNKNOWN; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7677 | if (phone == null) { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7678 | return raf; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7679 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7680 | final long identity = Binder.clearCallingIdentity(); |
| 7681 | try { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7682 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 7683 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7684 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 7685 | raf = ProxyController.getInstance().getRadioAccessFamily(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7686 | } finally { |
| 7687 | Binder.restoreCallingIdentity(identity); |
| 7688 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7689 | return raf; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 7690 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7691 | |
| 7692 | @Override |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7693 | public void uploadCallComposerPicture(int subscriptionId, String callingPackage, |
Hall Liu | e31bac6 | 2020-12-23 19:16:10 -0800 | [diff] [blame] | 7694 | String contentType, ParcelFileDescriptor fd, ResultReceiver callback) { |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7695 | try { |
| 7696 | if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0), |
| 7697 | Binder.getCallingUid())) { |
Tyler Gunn | b87925a | 2021-06-10 14:54:27 -0700 | [diff] [blame] | 7698 | throw new SecurityException("Invalid package:" + callingPackage); |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7699 | } |
| 7700 | } catch (PackageManager.NameNotFoundException e) { |
Tyler Gunn | b87925a | 2021-06-10 14:54:27 -0700 | [diff] [blame] | 7701 | throw new SecurityException("Invalid package:" + callingPackage); |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7702 | } |
| 7703 | RoleManager rm = mApp.getSystemService(RoleManager.class); |
| 7704 | List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER); |
| 7705 | if (!dialerRoleHolders.contains(callingPackage)) { |
| 7706 | throw new SecurityException("App must be the dialer role holder to" |
| 7707 | + " upload a call composer pic"); |
| 7708 | } |
| 7709 | |
| 7710 | Executors.newSingleThreadExecutor().execute(() -> { |
| 7711 | ByteArrayOutputStream output = new ByteArrayOutputStream( |
| 7712 | (int) TelephonyManager.getMaximumCallComposerPictureSize()); |
| 7713 | InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd); |
| 7714 | boolean readUntilEnd = false; |
| 7715 | int totalBytesRead = 0; |
| 7716 | byte[] buffer = new byte[16 * 1024]; |
| 7717 | while (true) { |
| 7718 | int numRead; |
| 7719 | try { |
| 7720 | numRead = input.read(buffer); |
| 7721 | } catch (IOException e) { |
| 7722 | try { |
| 7723 | fd.checkError(); |
| 7724 | callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED, |
| 7725 | null); |
| 7726 | } catch (IOException e1) { |
| 7727 | // This means that the other side closed explicitly with an error. If this |
| 7728 | // happens, log and ignore. |
| 7729 | loge("Remote end of call composer picture pipe closed: " + e1); |
| 7730 | } |
| 7731 | break; |
| 7732 | } |
| 7733 | if (numRead == -1) { |
| 7734 | readUntilEnd = true; |
| 7735 | break; |
| 7736 | } |
| 7737 | totalBytesRead += numRead; |
| 7738 | if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) { |
| 7739 | loge("Too many bytes read for call composer picture: " + totalBytesRead); |
| 7740 | try { |
| 7741 | input.close(); |
| 7742 | } catch (IOException e) { |
| 7743 | // ignore |
| 7744 | } |
| 7745 | break; |
| 7746 | } |
| 7747 | output.write(buffer, 0, numRead); |
| 7748 | } |
| 7749 | // Generally, the remote end will close the file descriptors. The only case where we |
| 7750 | // close is above, where the picture size is too big. |
| 7751 | |
| 7752 | try { |
| 7753 | fd.checkError(); |
| 7754 | } catch (IOException e) { |
| 7755 | loge("Remote end for call composer closed with an error: " + e); |
| 7756 | return; |
| 7757 | } |
| 7758 | |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 7759 | if (!readUntilEnd) { |
| 7760 | loge("Did not finish reading entire image; aborting"); |
| 7761 | return; |
| 7762 | } |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7763 | |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 7764 | ImageData imageData = new ImageData(output.toByteArray(), contentType, null); |
| 7765 | CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer( |
| 7766 | new CallComposerPictureTransfer.Factory() {}, |
| 7767 | imageData, |
| 7768 | (result) -> { |
| 7769 | if (result.first != null) { |
| 7770 | ParcelUuid parcelUuid = new ParcelUuid(result.first); |
| 7771 | Bundle outputResult = new Bundle(); |
| 7772 | outputResult.putParcelable( |
| 7773 | TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid); |
| 7774 | callback.send(TelephonyManager.CallComposerException.SUCCESS, |
| 7775 | outputResult); |
| 7776 | } else { |
| 7777 | callback.send(result.second, null); |
| 7778 | } |
| 7779 | } |
| 7780 | ); |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7781 | }); |
| 7782 | } |
| 7783 | |
| 7784 | @Override |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7785 | public void enableVideoCalling(boolean enable) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7786 | final Phone defaultPhone = getDefaultPhone(); |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7787 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7788 | |
| 7789 | final long identity = Binder.clearCallingIdentity(); |
| 7790 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7791 | ImsManager.getInstance(defaultPhone.getContext(), |
| 7792 | defaultPhone.getPhoneId()).setVtSetting(enable); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7793 | } finally { |
| 7794 | Binder.restoreCallingIdentity(identity); |
| 7795 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7796 | } |
| 7797 | |
| 7798 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7799 | public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7800 | final Phone defaultPhone = getDefaultPhone(); |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7801 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 7802 | callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 7803 | return false; |
| 7804 | } |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 7805 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7806 | final long identity = Binder.clearCallingIdentity(); |
| 7807 | try { |
| 7808 | // Check the user preference and the system-level IMS setting. Even if the user has |
| 7809 | // enabled video calling, if IMS is disabled we aren't able to support video calling. |
| 7810 | // In the long run, we may instead need to check if there exists a connection service |
| 7811 | // which can support video calling. |
| 7812 | ImsManager imsManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7813 | ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7814 | return imsManager.isVtEnabledByPlatform() |
| 7815 | && imsManager.isEnhanced4gLteModeSettingEnabledByUser() |
| 7816 | && imsManager.isVtEnabledByUser(); |
| 7817 | } finally { |
| 7818 | Binder.restoreCallingIdentity(identity); |
| 7819 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7820 | } |
Libin.Tang@motorola.com | afe8264 | 2014-12-18 13:27:53 -0600 | [diff] [blame] | 7821 | |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7822 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7823 | public boolean canChangeDtmfToneLength(int subId, String callingPackage, |
| 7824 | String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7825 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7826 | mApp, subId, callingPackage, callingFeatureId, |
| 7827 | "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7828 | return false; |
| 7829 | } |
| 7830 | |
| 7831 | final long identity = Binder.clearCallingIdentity(); |
| 7832 | try { |
| 7833 | CarrierConfigManager configManager = |
| 7834 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7835 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7836 | .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL); |
| 7837 | } finally { |
| 7838 | Binder.restoreCallingIdentity(identity); |
| 7839 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7840 | } |
| 7841 | |
| 7842 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7843 | public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7844 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7845 | mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7846 | return false; |
| 7847 | } |
| 7848 | |
| 7849 | final long identity = Binder.clearCallingIdentity(); |
| 7850 | try { |
| 7851 | CarrierConfigManager configManager = |
| 7852 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7853 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7854 | .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL); |
| 7855 | } finally { |
| 7856 | Binder.restoreCallingIdentity(identity); |
| 7857 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7858 | } |
| 7859 | |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7860 | @Override |
| 7861 | public boolean isTtyModeSupported() { |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 7862 | TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class); |
Wooki Wu | 1f82f7a | 2016-02-15 15:59:58 +0800 | [diff] [blame] | 7863 | return telecomManager.isTtySupported(); |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7864 | } |
| 7865 | |
| 7866 | @Override |
| 7867 | public boolean isHearingAidCompatibilitySupported() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7868 | final long identity = Binder.clearCallingIdentity(); |
| 7869 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7870 | return mApp.getResources().getBoolean(R.bool.hac_enabled); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7871 | } finally { |
| 7872 | Binder.restoreCallingIdentity(identity); |
| 7873 | } |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7874 | } |
| 7875 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 7876 | /** |
| 7877 | * Determines whether the device currently supports RTT (Real-time text). Based both on carrier |
| 7878 | * support for the feature and device firmware support. |
| 7879 | * |
| 7880 | * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise. |
| 7881 | */ |
| 7882 | @Override |
| 7883 | public boolean isRttSupported(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7884 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7885 | final Phone phone = getPhone(subscriptionId); |
| 7886 | if (phone == null) { |
| 7887 | loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId); |
| 7888 | return false; |
| 7889 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7890 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7891 | boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7892 | CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL); |
| 7893 | boolean isDeviceSupported = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7894 | phone.getContext().getResources().getBoolean(R.bool.config_support_rtt); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7895 | return isCarrierSupported && isDeviceSupported; |
| 7896 | } finally { |
| 7897 | Binder.restoreCallingIdentity(identity); |
| 7898 | } |
Hall Liu | 9818758 | 2018-01-22 19:15:32 -0800 | [diff] [blame] | 7899 | } |
| 7900 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 7901 | /** |
Hall Liu | f2daa02 | 2019-07-23 18:39:00 -0700 | [diff] [blame] | 7902 | * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set |
| 7903 | * RTT setting, will return true if the device and carrier both support RTT. |
| 7904 | * 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] | 7905 | */ |
| 7906 | public boolean isRttEnabled(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7907 | final long identity = Binder.clearCallingIdentity(); |
| 7908 | try { |
Hall Liu | 5bab75c | 2019-12-11 23:58:20 +0000 | [diff] [blame] | 7909 | boolean isRttSupported = isRttSupported(subscriptionId); |
| 7910 | boolean isUserRttSettingOn = Settings.Secure.getInt( |
| 7911 | mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0; |
| 7912 | boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId) |
| 7913 | .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL); |
| 7914 | return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7915 | } finally { |
| 7916 | Binder.restoreCallingIdentity(identity); |
| 7917 | } |
Hall Liu | 3ad5f01 | 2018-04-06 16:23:39 -0700 | [diff] [blame] | 7918 | } |
| 7919 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7920 | @Deprecated |
| 7921 | @Override |
| 7922 | public String getDeviceId(String callingPackage) { |
| 7923 | return getDeviceIdWithFeature(callingPackage, null); |
| 7924 | } |
| 7925 | |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7926 | /** |
| 7927 | * Returns the unique device ID of phone, for example, the IMEI for |
| 7928 | * GSM and the MEID for CDMA phones. Return null if device ID is not available. |
| 7929 | * |
| 7930 | * <p>Requires Permission: |
| 7931 | * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} |
| 7932 | */ |
| 7933 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7934 | public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) { |
Shuo Qian | 13d8915 | 2021-05-10 23:58:11 -0700 | [diff] [blame] | 7935 | try { |
| 7936 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 7937 | } catch (SecurityException se) { |
| 7938 | EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid()); |
| 7939 | throw new SecurityException("Package " + callingPackage + " does not belong to " |
| 7940 | + Binder.getCallingUid()); |
| 7941 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7942 | final Phone phone = PhoneFactory.getPhone(0); |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7943 | if (phone == null) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7944 | return null; |
| 7945 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7946 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 7947 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7948 | callingPackage, callingFeatureId, "getDeviceId")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7949 | return null; |
| 7950 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7951 | |
| 7952 | final long identity = Binder.clearCallingIdentity(); |
| 7953 | try { |
| 7954 | return phone.getDeviceId(); |
| 7955 | } finally { |
| 7956 | Binder.restoreCallingIdentity(identity); |
| 7957 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7958 | } |
| 7959 | |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 7960 | /** |
| 7961 | * {@hide} |
| 7962 | * Returns the IMS Registration Status on a particular subid |
| 7963 | * |
| 7964 | * @param subId |
| 7965 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7966 | public boolean isImsRegistered(int subId) { |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 7967 | Phone phone = getPhone(subId); |
| 7968 | if (phone != null) { |
| 7969 | return phone.isImsRegistered(); |
| 7970 | } else { |
| 7971 | return false; |
| 7972 | } |
| 7973 | } |
| 7974 | |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 7975 | @Override |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7976 | public int getSubIdForPhoneAccountHandle( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7977 | PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) { |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7978 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(), |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7979 | callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) { |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7980 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 7981 | } |
| 7982 | final long identity = Binder.clearCallingIdentity(); |
| 7983 | try { |
| 7984 | return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle); |
| 7985 | } finally { |
| 7986 | Binder.restoreCallingIdentity(identity); |
| 7987 | } |
| 7988 | } |
| 7989 | |
| 7990 | @Override |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 7991 | public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) { |
Alireza Forouzan | 4ac4f98 | 2021-03-16 22:18:52 -0700 | [diff] [blame] | 7992 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 7993 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Alireza Forouzan | 4ac4f98 | 2021-03-16 22:18:52 -0700 | [diff] [blame] | 7994 | mApp, |
| 7995 | subscriptionId, |
| 7996 | "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: " + subscriptionId); |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 7997 | final long identity = Binder.clearCallingIdentity(); |
| 7998 | try { |
| 7999 | Phone phone = getPhone(subscriptionId); |
| 8000 | if (phone == null) { |
| 8001 | return null; |
| 8002 | } |
| 8003 | return PhoneUtils.makePstnPhoneAccountHandle(phone); |
| 8004 | } finally { |
| 8005 | Binder.restoreCallingIdentity(identity); |
| 8006 | } |
| 8007 | } |
| 8008 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8009 | /** |
| 8010 | * @return the VoWiFi calling availability. |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 8011 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8012 | public boolean isWifiCallingAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8013 | final long identity = Binder.clearCallingIdentity(); |
| 8014 | try { |
| 8015 | Phone phone = getPhone(subId); |
| 8016 | if (phone != null) { |
| 8017 | return phone.isWifiCallingEnabled(); |
| 8018 | } else { |
| 8019 | return false; |
| 8020 | } |
| 8021 | } finally { |
| 8022 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8023 | } |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 8024 | } |
| 8025 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8026 | /** |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8027 | * @return the VT calling availability. |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 8028 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8029 | public boolean isVideoTelephonyAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8030 | final long identity = Binder.clearCallingIdentity(); |
| 8031 | try { |
| 8032 | Phone phone = getPhone(subId); |
| 8033 | if (phone != null) { |
| 8034 | return phone.isVideoEnabled(); |
| 8035 | } else { |
| 8036 | return false; |
| 8037 | } |
| 8038 | } finally { |
| 8039 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8040 | } |
| 8041 | } |
| 8042 | |
| 8043 | /** |
| 8044 | * @return the IMS registration technology for the MMTEL feature. Valid return values are |
| 8045 | * defined in {@link ImsRegistrationImplBase}. |
| 8046 | */ |
| 8047 | public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8048 | final long identity = Binder.clearCallingIdentity(); |
| 8049 | try { |
| 8050 | Phone phone = getPhone(subId); |
| 8051 | if (phone != null) { |
| 8052 | return phone.getImsRegistrationTech(); |
| 8053 | } else { |
| 8054 | return ImsRegistrationImplBase.REGISTRATION_TECH_NONE; |
| 8055 | } |
| 8056 | } finally { |
| 8057 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8058 | } |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 8059 | } |
| 8060 | |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 8061 | @Override |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 8062 | public void factoryReset(int subId, String callingPackage) { |
paulhu | 5a77360 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 8063 | enforceSettingsPermission(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 8064 | if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) { |
| 8065 | return; |
| 8066 | } |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 8067 | Phone defaultPhone = getDefaultPhone(); |
| 8068 | if (defaultPhone != null) { |
| 8069 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8070 | mApp, getDefaultPhone().getSubId(), "factoryReset"); |
| 8071 | } |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 8072 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8073 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 8074 | try { |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 8075 | if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction( |
| 8076 | UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 8077 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 8078 | getDefaultDataEnabled(), callingPackage); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 8079 | setNetworkSelectionModeAutomatic(subId); |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 8080 | Phone phone = getPhone(subId); |
SongFerngWang | fd89b10 | 2021-05-27 22:44:54 +0800 | [diff] [blame] | 8081 | cleanUpAllowedNetworkTypes(phone, subId); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8082 | setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId)); |
Jordan Liu | 857e73a | 2021-03-05 16:24:04 -0800 | [diff] [blame] | 8083 | getPhone(subId).resetCarrierKeysForImsiEncryption(); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 8084 | } |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 8085 | // There has been issues when Sms raw table somehow stores orphan |
| 8086 | // fragments. They lead to garbled message when new fragments come |
| 8087 | // in and combined with those stale ones. In case this happens again, |
| 8088 | // user can reset all network settings which will clean up this table. |
| 8089 | cleanUpSmsRawTable(getDefaultPhone().getContext()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 8090 | // Clean up IMS settings as well here. |
| 8091 | int slotId = getSlotIndex(subId); |
| 8092 | if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 8093 | ImsManager.getInstance(mApp, slotId).factoryReset(); |
| 8094 | } |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 8095 | |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 8096 | if (defaultPhone == null) { |
| 8097 | return; |
| 8098 | } |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 8099 | // Erase modem config if erase modem on network setting is enabled. |
| 8100 | String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY, |
| 8101 | RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED); |
| 8102 | if (configValue != null && Boolean.parseBoolean(configValue)) { |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 8103 | sendEraseModemConfig(defaultPhone); |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 8104 | } |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 8105 | |
| 8106 | sendEraseDataInSharedPreferences(defaultPhone); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 8107 | } finally { |
| 8108 | Binder.restoreCallingIdentity(identity); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 8109 | } |
| 8110 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 8111 | |
SongFerngWang | fd89b10 | 2021-05-27 22:44:54 +0800 | [diff] [blame] | 8112 | @VisibleForTesting |
| 8113 | void cleanUpAllowedNetworkTypes(Phone phone, int subId) { |
| 8114 | if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) { |
| 8115 | return; |
| 8116 | } |
| 8117 | long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType( |
| 8118 | RILConstants.PREFERRED_NETWORK_MODE); |
| 8119 | SubscriptionManager.setSubscriptionProperty(subId, |
| 8120 | SubscriptionManager.ALLOWED_NETWORK_TYPES, |
| 8121 | "user=" + defaultNetworkType); |
| 8122 | phone.loadAllowedNetworksFromSubscriptionDatabase(); |
| 8123 | phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER, |
| 8124 | defaultNetworkType, null); |
| 8125 | } |
| 8126 | |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 8127 | private void cleanUpSmsRawTable(Context context) { |
| 8128 | ContentResolver resolver = context.getContentResolver(); |
| 8129 | Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete"); |
| 8130 | resolver.delete(uri, null, null); |
| 8131 | } |
| 8132 | |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 8133 | @Override |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 8134 | public String getSimLocaleForSubscriber(int subId) { |
| 8135 | enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId); |
| 8136 | final Phone phone = getPhone(subId); |
| 8137 | if (phone == null) { |
| 8138 | log("getSimLocaleForSubscriber, invalid subId"); |
chen xu | 2bb91e4 | 2019-01-24 14:35:54 -0800 | [diff] [blame] | 8139 | return null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 8140 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8141 | final long identity = Binder.clearCallingIdentity(); |
| 8142 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 8143 | SubscriptionInfo info; |
| 8144 | if (PhoneFactory.isSubscriptionManagerServiceEnabled()) { |
| 8145 | info = SubscriptionManagerService.getInstance().getActiveSubscriptionInfo(subId, |
| 8146 | phone.getContext().getOpPackageName(), |
| 8147 | phone.getContext().getAttributionTag()); |
| 8148 | if (info == null) { |
| 8149 | log("getSimLocaleForSubscriber, inactive subId: " + subId); |
| 8150 | return null; |
| 8151 | } |
| 8152 | } else { |
| 8153 | info = mSubscriptionController.getActiveSubscriptionInfo(subId, |
| 8154 | phone.getContext().getOpPackageName(), |
| 8155 | phone.getContext().getAttributionTag()); |
| 8156 | if (info == null) { |
| 8157 | log("getSimLocaleForSubscriber, inactive subId: " + subId); |
| 8158 | return null; |
| 8159 | } |
chen xu | 6291c47 | 2019-02-04 12:55:53 -0800 | [diff] [blame] | 8160 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8161 | // Try and fetch the locale from the carrier properties or from the SIM language |
| 8162 | // preferences (EF-PL and EF-LI)... |
| 8163 | final int mcc = info.getMcc(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8164 | String simLanguage = null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 8165 | final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs(); |
| 8166 | if (localeFromDefaultSim != null) { |
| 8167 | if (!localeFromDefaultSim.getCountry().isEmpty()) { |
| 8168 | if (DBG) log("Using locale from subId: " + subId + " locale: " |
| 8169 | + localeFromDefaultSim); |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 8170 | return matchLocaleFromSupportedLocaleList(phone, localeFromDefaultSim); |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 8171 | } else { |
| 8172 | simLanguage = localeFromDefaultSim.getLanguage(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8173 | } |
| 8174 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 8175 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8176 | // The SIM language preferences only store a language (e.g. fr = French), not an |
| 8177 | // exact locale (e.g. fr_FR = French/France). So, if the locale returned from |
| 8178 | // the SIM and carrier preferences does not include a country we add the country |
| 8179 | // determined from the SIM MCC to provide an exact locale. |
zoey chen | c730df8 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 8180 | final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8181 | if (mccLocale != null) { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 8182 | if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale); |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 8183 | return matchLocaleFromSupportedLocaleList(phone, mccLocale); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8184 | } |
| 8185 | |
| 8186 | if (DBG) log("No locale found - returning null"); |
| 8187 | return null; |
| 8188 | } finally { |
| 8189 | Binder.restoreCallingIdentity(identity); |
| 8190 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 8191 | } |
| 8192 | |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 8193 | @VisibleForTesting |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 8194 | String matchLocaleFromSupportedLocaleList(Phone phone, @NonNull Locale inputLocale) { |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 8195 | String[] supportedLocale = com.android.internal.app.LocalePicker.getSupportedLocales( |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 8196 | phone.getContext()); |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 8197 | for (String localeTag : supportedLocale) { |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 8198 | if (LocaleList.matchesLanguageAndScript(inputLocale, Locale.forLanguageTag(localeTag)) |
| 8199 | && TextUtils.equals(inputLocale.getCountry(), |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 8200 | Locale.forLanguageTag(localeTag).getCountry())) { |
| 8201 | return localeTag; |
| 8202 | } |
| 8203 | } |
| 8204 | return inputLocale.toLanguageTag(); |
| 8205 | } |
| 8206 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8207 | /** |
| 8208 | * NOTE: this method assumes permission checks are done and caller identity has been cleared. |
| 8209 | */ |
| 8210 | private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 8211 | if (PhoneFactory.isSubscriptionManagerServiceEnabled()) { |
| 8212 | return SubscriptionManagerService.getInstance().getActiveSubscriptionInfoList( |
| 8213 | mApp.getOpPackageName(), mApp.getAttributionTag()); |
| 8214 | } |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8215 | return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(), |
Philip P. Moltmann | 8d34f0c | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 8216 | mApp.getAttributionTag()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 8217 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 8218 | |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8219 | private ActivityStatsTechSpecificInfo[] mLastModemActivitySpecificInfo = null; |
| 8220 | private ModemActivityInfo mLastModemActivityInfo = null; |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 8221 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 8222 | /** |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 8223 | * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object |
| 8224 | * representing the state of the modem. |
| 8225 | * |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 8226 | * NOTE: The underlying implementation clears the modem state, so there should only ever be one |
| 8227 | * caller to it. Everyone should call this class to get cumulative data. |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 8228 | * @hide |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 8229 | */ |
| 8230 | @Override |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 8231 | public void requestModemActivityInfo(ResultReceiver result) { |
| 8232 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8233 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8234 | |
| 8235 | final long identity = Binder.clearCallingIdentity(); |
| 8236 | try { |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 8237 | sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8238 | } finally { |
| 8239 | Binder.restoreCallingIdentity(identity); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 8240 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 8241 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8242 | |
Gary Jian | 76280a4 | 2022-12-07 16:18:33 +0800 | [diff] [blame] | 8243 | // Checks that ModemActivityInfo is valid. Sleep time and Idle time should be |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 8244 | // less than total activity duration. |
| 8245 | private boolean isModemActivityInfoValid(ModemActivityInfo info) { |
| 8246 | if (info == null) { |
| 8247 | return false; |
| 8248 | } |
| 8249 | int activityDurationMs = |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 8250 | (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis()); |
Gary Jian | 76280a4 | 2022-12-07 16:18:33 +0800 | [diff] [blame] | 8251 | activityDurationMs += MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS; |
| 8252 | |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 8253 | int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum(); |
| 8254 | |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 8255 | return (info.isValid() |
| 8256 | && (info.getSleepTimeMillis() <= activityDurationMs) |
Gary Jian | 76280a4 | 2022-12-07 16:18:33 +0800 | [diff] [blame] | 8257 | && (info.getIdleTimeMillis() <= activityDurationMs)); |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 8258 | } |
| 8259 | |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8260 | private void updateLastModemActivityInfo(ModemActivityInfo info, int rat, int freq) { |
| 8261 | int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()]; |
| 8262 | int[] txTimeMs = info.getTransmitTimeMillis(rat, freq); |
| 8263 | int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat, freq); |
| 8264 | |
| 8265 | for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) { |
| 8266 | mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl]; |
| 8267 | } |
| 8268 | |
| 8269 | mLastModemActivityInfo.setTransmitTimeMillis(rat, freq, mergedTxTimeMs); |
| 8270 | mLastModemActivityInfo.setReceiveTimeMillis( |
| 8271 | rat, |
| 8272 | freq, |
| 8273 | info.getReceiveTimeMillis(rat, freq) |
| 8274 | + mLastModemActivityInfo.getReceiveTimeMillis(rat, freq)); |
| 8275 | } |
| 8276 | |
| 8277 | private void updateLastModemActivityInfo(ModemActivityInfo info, int rat) { |
| 8278 | int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()]; |
| 8279 | int[] txTimeMs = info.getTransmitTimeMillis(rat); |
| 8280 | int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat); |
| 8281 | |
| 8282 | for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) { |
| 8283 | mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl]; |
| 8284 | } |
| 8285 | mLastModemActivityInfo.setTransmitTimeMillis(rat, mergedTxTimeMs); |
| 8286 | mLastModemActivityInfo.setReceiveTimeMillis( |
| 8287 | rat, |
| 8288 | info.getReceiveTimeMillis(rat) + mLastModemActivityInfo.getReceiveTimeMillis(rat)); |
| 8289 | } |
| 8290 | |
| 8291 | /** |
| 8292 | * Merge this ModemActivityInfo with mLastModemActivitySpecificInfo |
| 8293 | * @param info recent ModemActivityInfo |
| 8294 | */ |
| 8295 | private void mergeModemActivityInfo(ModemActivityInfo info) { |
| 8296 | List<ActivityStatsTechSpecificInfo> merged = new ArrayList<>(); |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 8297 | ActivityStatsTechSpecificInfo deltaSpecificInfo; |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8298 | boolean matched; |
| 8299 | for (int i = 0; i < info.getSpecificInfoLength(); i++) { |
| 8300 | matched = false; |
| 8301 | int rat = info.getSpecificInfoRat(i); |
| 8302 | int freq = info.getSpecificInfoFrequencyRange(i); |
| 8303 | //Check each ActivityStatsTechSpecificInfo in this ModemActivityInfo for new rat returns |
| 8304 | //Add a new ActivityStatsTechSpecificInfo if is a new rat, and merge with the original |
| 8305 | //if it already exists |
| 8306 | for (int j = 0; j < mLastModemActivitySpecificInfo.length; j++) { |
| 8307 | if (rat == mLastModemActivityInfo.getSpecificInfoRat(j) && !matched) { |
| 8308 | //Merged based on frequency range (MMWAVE vs SUB6) for 5G |
| 8309 | if (rat == AccessNetworkConstants.AccessNetworkType.NGRAN) { |
| 8310 | if (freq == mLastModemActivityInfo.getSpecificInfoFrequencyRange(j)) { |
| 8311 | updateLastModemActivityInfo(info, rat, freq); |
| 8312 | matched = true; |
| 8313 | } |
| 8314 | } else { |
| 8315 | updateLastModemActivityInfo(info, rat); |
| 8316 | matched = true; |
| 8317 | } |
| 8318 | } |
| 8319 | } |
| 8320 | |
| 8321 | if (!matched) { |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 8322 | deltaSpecificInfo = |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8323 | new ActivityStatsTechSpecificInfo( |
| 8324 | rat, |
| 8325 | freq, |
| 8326 | info.getTransmitTimeMillis(rat, freq), |
| 8327 | (int) info.getReceiveTimeMillis(rat, freq)); |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 8328 | merged.addAll(Arrays.asList(deltaSpecificInfo)); |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8329 | } |
| 8330 | } |
| 8331 | merged.addAll(Arrays.asList(mLastModemActivitySpecificInfo)); |
| 8332 | mLastModemActivitySpecificInfo = |
| 8333 | new ActivityStatsTechSpecificInfo[merged.size()]; |
| 8334 | merged.toArray(mLastModemActivitySpecificInfo); |
| 8335 | |
| 8336 | mLastModemActivityInfo.setTimestamp(info.getTimestampMillis()); |
| 8337 | mLastModemActivityInfo.setSleepTimeMillis( |
| 8338 | info.getSleepTimeMillis() |
| 8339 | + mLastModemActivityInfo.getSleepTimeMillis()); |
| 8340 | mLastModemActivityInfo.setIdleTimeMillis( |
| 8341 | info.getIdleTimeMillis() |
| 8342 | + mLastModemActivityInfo.getIdleTimeMillis()); |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 8343 | |
| 8344 | mLastModemActivityInfo = |
| 8345 | new ModemActivityInfo( |
| 8346 | mLastModemActivityInfo.getTimestampMillis(), |
| 8347 | mLastModemActivityInfo.getSleepTimeMillis(), |
| 8348 | mLastModemActivityInfo.getIdleTimeMillis(), |
| 8349 | mLastModemActivitySpecificInfo); |
| 8350 | } |
| 8351 | |
| 8352 | private ActivityStatsTechSpecificInfo[] deepCopyModemActivitySpecificInfo( |
| 8353 | ActivityStatsTechSpecificInfo[] info) { |
| 8354 | int infoSize = info.length; |
| 8355 | ActivityStatsTechSpecificInfo[] ret = new ActivityStatsTechSpecificInfo[infoSize]; |
| 8356 | for (int i = 0; i < infoSize; i++) { |
| 8357 | ret[i] = new ActivityStatsTechSpecificInfo( |
| 8358 | info[i].getRat(), info[i].getFrequencyRange(), |
| 8359 | info[i].getTransmitTimeMillis(), |
| 8360 | (int) info[i].getReceiveTimeMillis()); |
| 8361 | } |
| 8362 | return ret; |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8363 | } |
| 8364 | |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8365 | /** |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8366 | * Returns the service state information on specified subscription. |
| 8367 | */ |
| 8368 | @Override |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 8369 | public ServiceState getServiceStateForSubscriber(int subId, |
| 8370 | boolean renounceFineLocationAccess, boolean renounceCoarseLocationAccess, |
| 8371 | String callingPackage, String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8372 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8373 | mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) { |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8374 | return null; |
| 8375 | } |
| 8376 | |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 8377 | boolean hasFinePermission = false; |
| 8378 | boolean hasCoarsePermission = false; |
| 8379 | if (!renounceFineLocationAccess) { |
| 8380 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 8381 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 8382 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 8383 | .setCallingPackage(callingPackage) |
| 8384 | .setCallingFeatureId(callingFeatureId) |
| 8385 | .setCallingPid(Binder.getCallingPid()) |
| 8386 | .setCallingUid(Binder.getCallingUid()) |
| 8387 | .setMethod("getServiceStateForSubscriber") |
| 8388 | .setLogAsInfo(true) |
| 8389 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 8390 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 8391 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 8392 | .build()); |
| 8393 | hasFinePermission = |
| 8394 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 8395 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 8396 | |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 8397 | if (!renounceCoarseLocationAccess) { |
| 8398 | LocationAccessPolicy.LocationPermissionResult coarseLocationResult = |
| 8399 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 8400 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 8401 | .setCallingPackage(callingPackage) |
| 8402 | .setCallingFeatureId(callingFeatureId) |
| 8403 | .setCallingPid(Binder.getCallingPid()) |
| 8404 | .setCallingUid(Binder.getCallingUid()) |
| 8405 | .setMethod("getServiceStateForSubscriber") |
| 8406 | .setLogAsInfo(true) |
| 8407 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 8408 | .setMinSdkVersionForFine(Integer.MAX_VALUE) |
| 8409 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 8410 | .build()); |
| 8411 | hasCoarsePermission = |
| 8412 | coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 8413 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 8414 | |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 8415 | final Phone phone = getPhone(subId); |
| 8416 | if (phone == null) { |
| 8417 | return null; |
| 8418 | } |
| 8419 | |
Jordan Liu | 0f2bc44 | 2020-11-18 16:47:37 -0800 | [diff] [blame] | 8420 | final long identity = Binder.clearCallingIdentity(); |
| 8421 | |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 8422 | boolean isCallingPackageDataService = phone.getDataServicePackages() |
| 8423 | .contains(callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8424 | try { |
Jordan Liu | c437b19 | 2020-08-17 10:59:12 -0700 | [diff] [blame] | 8425 | // isActiveSubId requires READ_PHONE_STATE, which we already check for above |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 8426 | if (PhoneFactory.isSubscriptionManagerServiceEnabled()) { |
| 8427 | SubscriptionInfoInternal subInfo = SubscriptionManagerService.getInstance() |
| 8428 | .getSubscriptionInfoInternal(subId); |
| 8429 | if (subInfo == null || !subInfo.isActive()) { |
| 8430 | Rlog.d(LOG_TAG, "getServiceStateForSubscriber returning null for inactive " |
| 8431 | + "subId=" + subId); |
| 8432 | return null; |
| 8433 | } |
| 8434 | } else { |
| 8435 | if (!mSubscriptionController.isActiveSubId(subId, callingPackage, |
| 8436 | callingFeatureId)) { |
| 8437 | Rlog.d(LOG_TAG, "getServiceStateForSubscriber returning null for inactive " |
| 8438 | + "subId=" + subId); |
| 8439 | return null; |
| 8440 | } |
Jordan Liu | c437b19 | 2020-08-17 10:59:12 -0700 | [diff] [blame] | 8441 | } |
| 8442 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 8443 | ServiceState ss = phone.getServiceState(); |
| 8444 | |
| 8445 | // Scrub out the location info in ServiceState depending on what level of access |
| 8446 | // the caller has. |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 8447 | if (hasFinePermission || isCallingPackageDataService) return ss; |
Malcolm Chen | 5052de6 | 2019-12-30 13:56:38 -0800 | [diff] [blame] | 8448 | if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false); |
| 8449 | return ss.createLocationInfoSanitizedCopy(true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8450 | } finally { |
| 8451 | Binder.restoreCallingIdentity(identity); |
| 8452 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8453 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8454 | |
| 8455 | /** |
| 8456 | * Returns the URI for the per-account voicemail ringtone set in Phone settings. |
| 8457 | * |
| 8458 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 8459 | * voicemail ringtone. |
| 8460 | * @return The URI for the ringtone to play when receiving a voicemail from a specific |
| 8461 | * PhoneAccount. |
| 8462 | */ |
| 8463 | @Override |
| 8464 | public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8465 | final long identity = Binder.clearCallingIdentity(); |
| 8466 | try { |
| 8467 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 8468 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8469 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8470 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8471 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8472 | return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext()); |
| 8473 | } finally { |
| 8474 | Binder.restoreCallingIdentity(identity); |
| 8475 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8476 | } |
| 8477 | |
| 8478 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8479 | * Sets the per-account voicemail ringtone. |
| 8480 | * |
| 8481 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 8482 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 8483 | * |
| 8484 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 8485 | * voicemail ringtone. |
| 8486 | * @param uri The URI for the ringtone to play when receiving a voicemail from a specific |
| 8487 | * PhoneAccount. |
| 8488 | */ |
| 8489 | @Override |
| 8490 | public void setVoicemailRingtoneUri(String callingPackage, |
| 8491 | PhoneAccountHandle phoneAccountHandle, Uri uri) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8492 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8493 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 8494 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 8495 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8496 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8497 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 8498 | "setVoicemailRingtoneUri"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8499 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8500 | |
| 8501 | final long identity = Binder.clearCallingIdentity(); |
| 8502 | try { |
| 8503 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 8504 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8505 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8506 | } |
| 8507 | VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri); |
| 8508 | } finally { |
| 8509 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8510 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8511 | } |
| 8512 | |
| 8513 | /** |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8514 | * Returns whether vibration is set for voicemail notification in Phone settings. |
| 8515 | * |
| 8516 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 8517 | * voicemail vibration setting. |
| 8518 | * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise. |
| 8519 | */ |
| 8520 | @Override |
| 8521 | public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8522 | final long identity = Binder.clearCallingIdentity(); |
| 8523 | try { |
| 8524 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 8525 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8526 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8527 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8528 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8529 | return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext()); |
| 8530 | } finally { |
| 8531 | Binder.restoreCallingIdentity(identity); |
| 8532 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8533 | } |
| 8534 | |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8535 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8536 | * Sets the per-account voicemail vibration. |
| 8537 | * |
| 8538 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 8539 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 8540 | * |
| 8541 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 8542 | * voicemail vibration setting. |
| 8543 | * @param enabled Whether to enable or disable vibration for voicemail notifications from a |
| 8544 | * specific PhoneAccount. |
| 8545 | */ |
| 8546 | @Override |
| 8547 | public void setVoicemailVibrationEnabled(String callingPackage, |
| 8548 | PhoneAccountHandle phoneAccountHandle, boolean enabled) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8549 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8550 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 8551 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 8552 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8553 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8554 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 8555 | "setVoicemailVibrationEnabled"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8556 | } |
| 8557 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8558 | final long identity = Binder.clearCallingIdentity(); |
| 8559 | try { |
| 8560 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 8561 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8562 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8563 | } |
| 8564 | VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled); |
| 8565 | } finally { |
| 8566 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8567 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8568 | } |
| 8569 | |
| 8570 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8571 | * Make sure either called from same process as self (phone) or IPC caller has read privilege. |
| 8572 | * |
| 8573 | * @throws SecurityException if the caller does not have the required permission |
| 8574 | */ |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 8575 | @VisibleForTesting |
| 8576 | public void enforceReadPrivilegedPermission(String message) { |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8577 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8578 | message); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8579 | } |
| 8580 | |
| 8581 | /** |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 8582 | * Make sure either called from same process as self (phone) or IPC caller has send SMS |
| 8583 | * permission. |
| 8584 | * |
| 8585 | * @throws SecurityException if the caller does not have the required permission |
| 8586 | */ |
| 8587 | private void enforceSendSmsPermission() { |
| 8588 | mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null); |
| 8589 | } |
| 8590 | |
| 8591 | /** |
Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame] | 8592 | * Make sure either called from same process as self (phone) or IPC caller has interact across |
| 8593 | * users permission. |
| 8594 | * |
| 8595 | * @throws SecurityException if the caller does not have the required permission |
| 8596 | */ |
| 8597 | private void enforceInteractAcrossUsersPermission(String message) { |
| 8598 | mApp.enforceCallingOrSelfPermission(permission.INTERACT_ACROSS_USERS, message); |
| 8599 | } |
| 8600 | |
| 8601 | /** |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 8602 | * Make sure called from the package in charge of visual voicemail. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 8603 | * |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 8604 | * @throws SecurityException if the caller is not the visual voicemail package. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 8605 | */ |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 8606 | private void enforceVisualVoicemailPackage(String callingPackage, int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8607 | final long identity = Binder.clearCallingIdentity(); |
| 8608 | try { |
| 8609 | ComponentName componentName = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8610 | RemoteVvmTaskManager.getRemotePackage(mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8611 | if (componentName == null) { |
| 8612 | throw new SecurityException( |
| 8613 | "Caller not current active visual voicemail package[null]"); |
| 8614 | } |
| 8615 | String vvmPackage = componentName.getPackageName(); |
| 8616 | if (!callingPackage.equals(vvmPackage)) { |
Hui Wang | 7f65755 | 2022-08-16 16:58:25 +0000 | [diff] [blame] | 8617 | throw new SecurityException("Caller not current active visual voicemail package"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8618 | } |
| 8619 | } finally { |
| 8620 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 8621 | } |
| 8622 | } |
| 8623 | |
| 8624 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8625 | * Return the application ID for the app type. |
| 8626 | * |
| 8627 | * @param subId the subscription ID that this request applies to. |
| 8628 | * @param appType the uicc app type. |
| 8629 | * @return Application ID for specificied app type, or null if no uicc. |
| 8630 | */ |
| 8631 | @Override |
| 8632 | public String getAidForAppType(int subId, int appType) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8633 | enforceReadPrivilegedPermission("getAidForAppType"); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8634 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8635 | |
| 8636 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8637 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8638 | if (phone == null) { |
| 8639 | return null; |
| 8640 | } |
| 8641 | String aid = null; |
| 8642 | try { |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 8643 | aid = UiccController.getInstance().getUiccPort(phone.getPhoneId()) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8644 | .getApplicationByType(appType).getAid(); |
| 8645 | } catch (Exception e) { |
| 8646 | Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e); |
| 8647 | } |
| 8648 | return aid; |
| 8649 | } finally { |
| 8650 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8651 | } |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8652 | } |
| 8653 | |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8654 | /** |
| 8655 | * Return the Electronic Serial Number. |
| 8656 | * |
| 8657 | * @param subId the subscription ID that this request applies to. |
| 8658 | * @return ESN or null if error. |
| 8659 | */ |
| 8660 | @Override |
| 8661 | public String getEsn(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8662 | enforceReadPrivilegedPermission("getEsn"); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8663 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8664 | |
| 8665 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8666 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8667 | if (phone == null) { |
| 8668 | return null; |
| 8669 | } |
| 8670 | String esn = null; |
| 8671 | try { |
| 8672 | esn = phone.getEsn(); |
| 8673 | } catch (Exception e) { |
| 8674 | Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e); |
| 8675 | } |
| 8676 | return esn; |
| 8677 | } finally { |
| 8678 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8679 | } |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8680 | } |
| 8681 | |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 8682 | /** |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8683 | * Return the Preferred Roaming List Version. |
| 8684 | * |
| 8685 | * @param subId the subscription ID that this request applies to. |
| 8686 | * @return PRLVersion or null if error. |
| 8687 | */ |
| 8688 | @Override |
| 8689 | public String getCdmaPrlVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8690 | enforceReadPrivilegedPermission("getCdmaPrlVersion"); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8691 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8692 | |
| 8693 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8694 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8695 | if (phone == null) { |
| 8696 | return null; |
| 8697 | } |
| 8698 | String cdmaPrlVersion = null; |
| 8699 | try { |
| 8700 | cdmaPrlVersion = phone.getCdmaPrlVersion(); |
| 8701 | } catch (Exception e) { |
| 8702 | Log.e(LOG_TAG, "Not getting PRLVersion", e); |
| 8703 | } |
| 8704 | return cdmaPrlVersion; |
| 8705 | } finally { |
| 8706 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8707 | } |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8708 | } |
| 8709 | |
| 8710 | /** |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 8711 | * Get snapshot of Telephony histograms |
| 8712 | * @return List of Telephony histograms |
| 8713 | * @hide |
| 8714 | */ |
| 8715 | @Override |
| 8716 | public List<TelephonyHistogram> getTelephonyHistograms() { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8717 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8718 | mApp, getDefaultSubscription(), "getTelephonyHistograms"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8719 | |
| 8720 | final long identity = Binder.clearCallingIdentity(); |
| 8721 | try { |
| 8722 | return RIL.getTelephonyRILTimingHistograms(); |
| 8723 | } finally { |
| 8724 | Binder.restoreCallingIdentity(identity); |
| 8725 | } |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 8726 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8727 | |
| 8728 | /** |
| 8729 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8730 | * Set the allowed carrier list and the excluded carrier list, indicating the priority between |
| 8731 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8732 | * Require system privileges. In the future we may add this to carrier APIs. |
| 8733 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8734 | * @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] | 8735 | */ |
| 8736 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8737 | @TelephonyManager.SetCarrierRestrictionResult |
| 8738 | public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) { |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8739 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8740 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8741 | |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8742 | if (carrierRestrictionRules == null) { |
| 8743 | throw new NullPointerException("carrier restriction cannot be null"); |
Meng Wang | 9b7c4e9 | 2017-02-17 11:41:27 -0800 | [diff] [blame] | 8744 | } |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8745 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8746 | final long identity = Binder.clearCallingIdentity(); |
| 8747 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8748 | return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8749 | workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8750 | } finally { |
| 8751 | Binder.restoreCallingIdentity(identity); |
| 8752 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8753 | } |
| 8754 | |
| 8755 | /** |
| 8756 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8757 | * Get the allowed carrier list and the excluded carrier list, including the priority between |
| 8758 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8759 | * Require system privileges. In the future we may add this to carrier APIs. |
| 8760 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8761 | * @return {@link android.telephony.CarrierRestrictionRules} |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8762 | */ |
| 8763 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8764 | public CarrierRestrictionRules getAllowedCarriers() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8765 | enforceReadPrivilegedPermission("getAllowedCarriers"); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8766 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8767 | |
| 8768 | final long identity = Binder.clearCallingIdentity(); |
| 8769 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8770 | Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource); |
| 8771 | if (response instanceof CarrierRestrictionRules) { |
| 8772 | return (CarrierRestrictionRules) response; |
| 8773 | } |
| 8774 | // Response is an Exception of some kind, |
| 8775 | // which is signalled to the user as a NULL retval |
| 8776 | return null; |
| 8777 | } catch (Exception e) { |
| 8778 | Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e); |
| 8779 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8780 | } finally { |
| 8781 | Binder.restoreCallingIdentity(identity); |
| 8782 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8783 | } |
| 8784 | |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 8785 | /** |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 8786 | * Fetches the carrier restriction status of the device and sends the status to the caller |
| 8787 | * through the callback. |
| 8788 | * |
| 8789 | * @param callback The callback that will be used to send the result. |
| 8790 | * @throws SecurityException if the caller does not have the required permission/privileges or |
| 8791 | * the caller is not allowlisted. |
| 8792 | */ |
| 8793 | @Override |
| 8794 | public void getCarrierRestrictionStatus(IIntegerConsumer callback, String packageName) { |
| 8795 | enforceReadPermission("getCarrierRestrictionStatus"); |
| 8796 | int carrierId = validateCallerAndGetCarrierId(packageName); |
| 8797 | if (carrierId == CarrierAllowListInfo.INVALID_CARRIER_ID) { |
| 8798 | Rlog.e(LOG_TAG, "getCarrierRestrictionStatus: caller is not registered"); |
| 8799 | throw new SecurityException("Not an authorized caller"); |
| 8800 | } |
| 8801 | final long identity = Binder.clearCallingIdentity(); |
| 8802 | try { |
| 8803 | Consumer<Integer> consumer = FunctionalUtils.ignoreRemoteException(callback::accept); |
| 8804 | CallerCallbackInfo callbackInfo = new CallerCallbackInfo(consumer, carrierId); |
| 8805 | sendRequestAsync(CMD_GET_ALLOWED_CARRIERS, callbackInfo); |
| 8806 | } finally { |
| 8807 | Binder.restoreCallingIdentity(identity); |
| 8808 | } |
| 8809 | } |
| 8810 | |
| 8811 | @VisibleForTesting |
| 8812 | public int validateCallerAndGetCarrierId(String packageName) { |
| 8813 | CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp); |
| 8814 | return allowListInfo.validateCallerAndGetCarrierId(packageName); |
| 8815 | } |
| 8816 | |
| 8817 | /** |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 8818 | * Action set from carrier signalling broadcast receivers to enable/disable radio |
| 8819 | * @param subId the subscription ID that this action applies to. |
| 8820 | * @param enabled control enable or disable radio. |
| 8821 | * {@hide} |
| 8822 | */ |
| 8823 | @Override |
| 8824 | public void carrierActionSetRadioEnabled(int subId, boolean enabled) { |
| 8825 | enforceModifyPermission(); |
| 8826 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8827 | |
| 8828 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 8829 | if (phone == null) { |
| 8830 | loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId); |
| 8831 | return; |
| 8832 | } |
| 8833 | try { |
| 8834 | phone.carrierActionSetRadioEnabled(enabled); |
| 8835 | } catch (Exception e) { |
| 8836 | Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8837 | } finally { |
| 8838 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 8839 | } |
| 8840 | } |
| 8841 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 8842 | /** |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 8843 | * Enable or disable Voice over NR (VoNR) |
| 8844 | * @param subId the subscription ID that this action applies to. |
| 8845 | * @param enabled enable or disable VoNR. |
| 8846 | * @return operation result. |
| 8847 | */ |
| 8848 | @Override |
| 8849 | public int setVoNrEnabled(int subId, boolean enabled) { |
| 8850 | enforceModifyPermission(); |
| 8851 | final Phone phone = getPhone(subId); |
| 8852 | |
| 8853 | final long identity = Binder.clearCallingIdentity(); |
| 8854 | if (phone == null) { |
| 8855 | loge("setVoNrEnabled fails with no phone object for subId: " + subId); |
| 8856 | return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE; |
| 8857 | } |
| 8858 | |
| 8859 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8860 | try { |
| 8861 | int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId, |
| 8862 | workSource); |
| 8863 | if (DBG) log("setVoNrEnabled result: " + result); |
Gary Jian | 8dd305f | 2021-10-14 16:31:35 +0800 | [diff] [blame] | 8864 | |
| 8865 | if (result == TelephonyManager.ENABLE_VONR_SUCCESS) { |
| 8866 | if (DBG) { |
| 8867 | log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled); |
| 8868 | } |
| 8869 | SubscriptionManager.setSubscriptionProperty( |
| 8870 | subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED, |
| 8871 | (enabled ? "1" : "0")); |
| 8872 | } |
| 8873 | |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 8874 | return result; |
| 8875 | } finally { |
| 8876 | Binder.restoreCallingIdentity(identity); |
| 8877 | } |
| 8878 | } |
| 8879 | |
| 8880 | /** |
| 8881 | * Is voice over NR enabled |
| 8882 | * @return true if VoNR is enabled else false |
| 8883 | */ |
| 8884 | @Override |
| 8885 | public boolean isVoNrEnabled(int subId) { |
| 8886 | enforceReadPrivilegedPermission("isVoNrEnabled"); |
| 8887 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8888 | final long identity = Binder.clearCallingIdentity(); |
| 8889 | try { |
| 8890 | boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED, |
| 8891 | null, subId, workSource); |
| 8892 | if (DBG) log("isVoNrEnabled: " + isEnabled); |
| 8893 | return isEnabled; |
| 8894 | } finally { |
| 8895 | Binder.restoreCallingIdentity(identity); |
| 8896 | } |
| 8897 | } |
| 8898 | |
| 8899 | /** |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 8900 | * Action set from carrier signalling broadcast receivers to start/stop reporting the default |
| 8901 | * network status based on which carrier apps could apply actions accordingly, |
| 8902 | * enable/disable default url handler for example. |
| 8903 | * |
| 8904 | * @param subId the subscription ID that this action applies to. |
| 8905 | * @param report control start/stop reporting the default network status. |
| 8906 | * {@hide} |
| 8907 | */ |
| 8908 | @Override |
| 8909 | public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) { |
| 8910 | enforceModifyPermission(); |
| 8911 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8912 | |
| 8913 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 8914 | if (phone == null) { |
| 8915 | loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId); |
| 8916 | return; |
| 8917 | } |
| 8918 | try { |
| 8919 | phone.carrierActionReportDefaultNetworkStatus(report); |
| 8920 | } catch (Exception e) { |
| 8921 | Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8922 | } finally { |
| 8923 | Binder.restoreCallingIdentity(identity); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 8924 | } |
| 8925 | } |
| 8926 | |
| 8927 | /** |
fionaxu | d962228 | 2017-07-17 17:51:30 -0700 | [diff] [blame] | 8928 | * Action set from carrier signalling broadcast receivers to reset all carrier actions |
| 8929 | * @param subId the subscription ID that this action applies to. |
| 8930 | * {@hide} |
| 8931 | */ |
| 8932 | @Override |
| 8933 | public void carrierActionResetAll(int subId) { |
| 8934 | enforceModifyPermission(); |
| 8935 | final Phone phone = getPhone(subId); |
| 8936 | if (phone == null) { |
| 8937 | loge("carrierAction: ResetAll fails with invalid sibId: " + subId); |
| 8938 | return; |
| 8939 | } |
| 8940 | try { |
| 8941 | phone.carrierActionResetAll(); |
| 8942 | } catch (Exception e) { |
| 8943 | Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e); |
| 8944 | } |
| 8945 | } |
| 8946 | |
| 8947 | /** |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 8948 | * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a |
| 8949 | * bug report is being generated. |
| 8950 | */ |
| 8951 | @Override |
Ta-wei Yen | 99282e0 | 2016-06-21 18:19:35 -0700 | [diff] [blame] | 8952 | protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8953 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 8954 | != PackageManager.PERMISSION_GRANTED) { |
dcashman | 22b950d | 2016-06-27 11:39:02 -0700 | [diff] [blame] | 8955 | writer.println("Permission Denial: can't dump Phone from pid=" |
| 8956 | + Binder.getCallingPid() |
| 8957 | + ", uid=" + Binder.getCallingUid() |
| 8958 | + "without permission " |
| 8959 | + android.Manifest.permission.DUMP); |
| 8960 | return; |
| 8961 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8962 | DumpsysHandler.dump(mApp, fd, writer, args); |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 8963 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 8964 | |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 8965 | @Override |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 8966 | public int handleShellCommand(@NonNull ParcelFileDescriptor in, |
| 8967 | @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err, |
| 8968 | @NonNull String[] args) { |
| 8969 | return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec( |
| 8970 | this, in.getFileDescriptor(), out.getFileDescriptor(), |
| 8971 | err.getFileDescriptor(), args); |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 8972 | } |
| 8973 | |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 8974 | /** |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8975 | * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason} |
Greg Kaiser | 17f4175 | 2020-05-05 16:47:47 +0000 | [diff] [blame] | 8976 | * @param subId Subscription index |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 8977 | * @param reason The reason the data enable change is taking place. |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8978 | * @param enabled True if enabling the data, otherwise disabling. |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 8979 | * @param callingPackage The package that changed the data enabled state. |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8980 | * @hide |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 8981 | */ |
| 8982 | @Override |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 8983 | public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 8984 | boolean enabled, String callingPackage) { |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8985 | if (reason == TelephonyManager.DATA_ENABLED_REASON_USER |
| 8986 | || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 8987 | try { |
| 8988 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 8989 | mApp, subId, "setDataEnabledForReason"); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8990 | } catch (SecurityException se) { |
| 8991 | enforceModifyPermission(); |
| 8992 | } |
| 8993 | } else { |
| 8994 | enforceModifyPermission(); |
| 8995 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8996 | |
| 8997 | final long identity = Binder.clearCallingIdentity(); |
| 8998 | try { |
| 8999 | Phone phone = getPhone(subId); |
| 9000 | if (phone != null) { |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 9001 | if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 9002 | phone.carrierActionSetMeteredApnsEnabled(enabled); |
| 9003 | } else { |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 9004 | phone.getDataSettingsManager().setDataEnabled( |
| 9005 | reason, enabled, callingPackage); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 9006 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9007 | } |
| 9008 | } finally { |
| 9009 | Binder.restoreCallingIdentity(identity); |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 9010 | } |
| 9011 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 9012 | |
| 9013 | /** |
| 9014 | * Get Client request stats |
| 9015 | * @return List of Client Request Stats |
| 9016 | * @hide |
| 9017 | */ |
| 9018 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9019 | public List<ClientRequestStats> getClientRequestStats(String callingPackage, |
| 9020 | String callingFeatureId, int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 9021 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9022 | mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) { |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 9023 | return null; |
| 9024 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 9025 | Phone phone = getPhone(subId); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 9026 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9027 | final long identity = Binder.clearCallingIdentity(); |
| 9028 | try { |
| 9029 | if (phone != null) { |
| 9030 | return phone.getClientRequestStats(); |
| 9031 | } |
| 9032 | |
| 9033 | return null; |
| 9034 | } finally { |
| 9035 | Binder.restoreCallingIdentity(identity); |
| 9036 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 9037 | } |
| 9038 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 9039 | private WorkSource getWorkSource(int uid) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9040 | String packageName = mApp.getPackageManager().getNameForUid(uid); |
Hunter Knepshield | d03383b | 2022-03-29 22:47:54 +0000 | [diff] [blame] | 9041 | if (uid == Process.ROOT_UID && packageName == null) { |
| 9042 | // Downstream WorkSource attribution inside the RIL requires both a UID and package name |
| 9043 | // to be set for wakelock tracking, otherwise RIL requests fail with a runtime |
| 9044 | // exception. ROOT_UID seems not to have a valid package name returned by |
| 9045 | // PackageManager, so just fake it here to avoid issues when running telephony shell |
| 9046 | // commands that plumb through the RIL as root, like so: |
| 9047 | // $ adb root |
| 9048 | // $ adb shell cmd phone ... |
| 9049 | packageName = "root"; |
| 9050 | } |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 9051 | return new WorkSource(uid, packageName); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 9052 | } |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 9053 | |
| 9054 | /** |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 9055 | * Set SIM card power state. |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 9056 | * |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 9057 | * @param slotIndex SIM slot id. |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 9058 | * @param state State of SIM (power down, power up, pass through) |
| 9059 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 9060 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 9061 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 9062 | * |
| 9063 | **/ |
| 9064 | @Override |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 9065 | public void setSimPowerStateForSlot(int slotIndex, int state) { |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 9066 | enforceModifyPermission(); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 9067 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 9068 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 9069 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 9070 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9071 | final long identity = Binder.clearCallingIdentity(); |
| 9072 | try { |
| 9073 | if (phone != null) { |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 9074 | phone.setSimPowerState(state, null, workSource); |
| 9075 | } |
| 9076 | } finally { |
| 9077 | Binder.restoreCallingIdentity(identity); |
| 9078 | } |
| 9079 | } |
| 9080 | |
| 9081 | /** |
| 9082 | * Set SIM card power state. |
| 9083 | * |
| 9084 | * @param slotIndex SIM slot id. |
| 9085 | * @param state State of SIM (power down, power up, pass through) |
| 9086 | * @param callback callback to trigger after success or failure |
| 9087 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 9088 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 9089 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
| 9090 | * |
| 9091 | **/ |
| 9092 | @Override |
| 9093 | public void setSimPowerStateForSlotWithCallback(int slotIndex, int state, |
| 9094 | IIntegerConsumer callback) { |
| 9095 | enforceModifyPermission(); |
| 9096 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 9097 | |
| 9098 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 9099 | |
| 9100 | final long identity = Binder.clearCallingIdentity(); |
| 9101 | try { |
| 9102 | if (phone != null) { |
| 9103 | Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback); |
| 9104 | sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9105 | } |
| 9106 | } finally { |
| 9107 | Binder.restoreCallingIdentity(identity); |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 9108 | } |
| 9109 | } |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 9110 | |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 9111 | private boolean isUssdApiAllowed(int subId) { |
| 9112 | CarrierConfigManager configManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9113 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 9114 | if (configManager == null) { |
| 9115 | return false; |
| 9116 | } |
| 9117 | PersistableBundle pb = configManager.getConfigForSubId(subId); |
| 9118 | if (pb == null) { |
| 9119 | return false; |
| 9120 | } |
| 9121 | return pb.getBoolean( |
| 9122 | CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL); |
| 9123 | } |
| 9124 | |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 9125 | /** |
| 9126 | * Check if phone is in emergency callback mode |
| 9127 | * @return true if phone is in emergency callback mode |
| 9128 | * @param subId sub id |
| 9129 | */ |
goneil | 9c5f487 | 2017-12-05 14:07:56 -0800 | [diff] [blame] | 9130 | @Override |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 9131 | public boolean getEmergencyCallbackMode(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 9132 | enforceReadPrivilegedPermission("getEmergencyCallbackMode"); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 9133 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9134 | |
| 9135 | final long identity = Binder.clearCallingIdentity(); |
| 9136 | try { |
| 9137 | if (phone != null) { |
| 9138 | return phone.isInEcm(); |
| 9139 | } else { |
| 9140 | return false; |
| 9141 | } |
| 9142 | } finally { |
| 9143 | Binder.restoreCallingIdentity(identity); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 9144 | } |
| 9145 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 9146 | |
| 9147 | /** |
| 9148 | * Get the current signal strength information for the given subscription. |
| 9149 | * Because this information is not updated when the device is in a low power state |
| 9150 | * it should not be relied-upon to be current. |
| 9151 | * @param subId Subscription index |
| 9152 | * @return the most recent cached signal strength info from the modem |
| 9153 | */ |
| 9154 | @Override |
| 9155 | public SignalStrength getSignalStrength(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9156 | final long identity = Binder.clearCallingIdentity(); |
| 9157 | try { |
| 9158 | Phone p = getPhone(subId); |
| 9159 | if (p == null) { |
| 9160 | return null; |
| 9161 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 9162 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9163 | return p.getSignalStrength(); |
| 9164 | } finally { |
| 9165 | Binder.restoreCallingIdentity(identity); |
| 9166 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 9167 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9168 | |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9169 | /** |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 9170 | * Get the current modem radio state for the given slot. |
| 9171 | * @param slotIndex slot index. |
| 9172 | * @param callingPackage the name of the package making the call. |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9173 | * @param callingFeatureId The feature in the package. |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 9174 | * @return the current radio power state from the modem |
| 9175 | */ |
| 9176 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9177 | public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 9178 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 9179 | if (phone != null) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9180 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(), |
| 9181 | callingPackage, callingFeatureId, "getRadioPowerState")) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 9182 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 9183 | } |
| 9184 | |
| 9185 | final long identity = Binder.clearCallingIdentity(); |
| 9186 | try { |
| 9187 | return phone.getRadioPowerState(); |
| 9188 | } finally { |
| 9189 | Binder.restoreCallingIdentity(identity); |
| 9190 | } |
| 9191 | } |
| 9192 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 9193 | } |
| 9194 | |
| 9195 | /** |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9196 | * Checks if data roaming is enabled on the subscription with id {@code subId}. |
| 9197 | * |
| 9198 | * <p>Requires one of the following permissions: |
| 9199 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}, |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 9200 | * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE}, |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9201 | * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier |
| 9202 | * privileges. |
| 9203 | * |
| 9204 | * @param subId subscription id |
| 9205 | * @return {@code true} if data roaming is enabled on this subscription, otherwise return |
| 9206 | * {@code false}. |
| 9207 | */ |
| 9208 | @Override |
| 9209 | public boolean isDataRoamingEnabled(int subId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 9210 | String functionName = "isDataRoamingEnabled"; |
Shuo Qian | 093013d | 2020-08-13 15:42:55 -0700 | [diff] [blame] | 9211 | try { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 9212 | try { |
| 9213 | mApp.enforceCallingOrSelfPermission( |
| 9214 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 9215 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 9216 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 9217 | mApp.enforceCallingOrSelfPermission( |
| 9218 | permission.READ_BASIC_PHONE_STATE, functionName); |
| 9219 | } |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 9220 | } catch (SecurityException e) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9221 | TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 9222 | mApp, subId, functionName); |
Shuo Qian | 093013d | 2020-08-13 15:42:55 -0700 | [diff] [blame] | 9223 | } |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 9224 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9225 | boolean isEnabled = false; |
| 9226 | final long identity = Binder.clearCallingIdentity(); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9227 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9228 | Phone phone = getPhone(subId); |
| 9229 | isEnabled = phone != null ? phone.getDataRoamingEnabled() : false; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9230 | } finally { |
| 9231 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9232 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9233 | return isEnabled; |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9234 | } |
| 9235 | |
| 9236 | |
| 9237 | /** |
| 9238 | * Enables/Disables the data roaming on the subscription with id {@code subId}. |
| 9239 | * |
| 9240 | * <p> Requires permission: |
| 9241 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier |
| 9242 | * privileges. |
| 9243 | * |
| 9244 | * @param subId subscription id |
| 9245 | * @param isEnabled {@code true} means enable, {@code false} means disable. |
| 9246 | */ |
| 9247 | @Override |
| 9248 | public void setDataRoamingEnabled(int subId, boolean isEnabled) { |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 9249 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9250 | mApp, subId, "setDataRoamingEnabled"); |
| 9251 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9252 | final long identity = Binder.clearCallingIdentity(); |
| 9253 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9254 | Phone phone = getPhone(subId); |
| 9255 | if (phone != null) { |
| 9256 | phone.setDataRoamingEnabled(isEnabled); |
| 9257 | } |
| 9258 | } finally { |
| 9259 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9260 | } |
| 9261 | } |
| 9262 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9263 | @Override |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 9264 | public boolean isManualNetworkSelectionAllowed(int subId) { |
tom hsu | c91afc7 | 2020-01-06 23:46:07 +0800 | [diff] [blame] | 9265 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9266 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 9267 | mApp, subId, "isManualNetworkSelectionAllowed"); |
| 9268 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 9269 | boolean isAllowed = true; |
| 9270 | final long identity = Binder.clearCallingIdentity(); |
| 9271 | try { |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 9272 | Phone phone = getPhone(subId); |
| 9273 | if (phone != null) { |
| 9274 | isAllowed = phone.isCspPlmnEnabled(); |
| 9275 | } |
| 9276 | } finally { |
| 9277 | Binder.restoreCallingIdentity(identity); |
| 9278 | } |
| 9279 | return isAllowed; |
| 9280 | } |
| 9281 | |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9282 | private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) { |
| 9283 | UiccProfile profile = port.getUiccProfile(); |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 9284 | if (profile == null) { |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9285 | return false; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9286 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 9287 | Phone phone = PhoneFactory.getPhone(profile.getPhoneId()); |
| 9288 | if (phone == null) { |
| 9289 | return false; |
| 9290 | } |
| 9291 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 9292 | return cpt != null && cpt.getCarrierPrivilegeStatusForPackage(callingPackage) |
| 9293 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9294 | } |
| 9295 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 9296 | @Override |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 9297 | public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) { |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9298 | // Verify that the callingPackage belongs to the calling UID |
Jordan Liu | 4cda455 | 2020-03-23 11:55:07 -0700 | [diff] [blame] | 9299 | mApp.getSystemService(AppOpsManager.class) |
| 9300 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 9301 | |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9302 | boolean hasReadPermission = false; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9303 | boolean isIccIdAccessRestricted = false; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 9304 | try { |
| 9305 | enforceReadPrivilegedPermission("getUiccCardsInfo"); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9306 | hasReadPermission = true; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 9307 | } catch (SecurityException e) { |
| 9308 | // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller |
| 9309 | // has carrier privileges on an active UICC |
Rambo Wang | e7209ce | 2022-02-23 13:41:02 -0800 | [diff] [blame] | 9310 | if (checkCarrierPrivilegesForPackageAnyPhoneWithPermission(callingPackage) |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 9311 | != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9312 | throw new SecurityException("Caller does not have permission."); |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 9313 | } |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 9314 | } |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9315 | // checking compatibility, if calling app's target SDK is T and beyond. |
| 9316 | if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO, |
| 9317 | Binder.getCallingUid())) { |
| 9318 | isIccIdAccessRestricted = true; |
| 9319 | } |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 9320 | final long identity = Binder.clearCallingIdentity(); |
| 9321 | try { |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 9322 | UiccController uiccController = UiccController.getInstance(); |
| 9323 | ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos(); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9324 | if (hasReadPermission) { |
| 9325 | return cardInfos; |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 9326 | } |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9327 | |
| 9328 | // Remove private info if the caller doesn't have access |
| 9329 | ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>(); |
| 9330 | for (UiccCardInfo cardInfo : cardInfos) { |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9331 | //setting the value after compatibility check |
| 9332 | cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9333 | // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo |
| 9334 | // is available |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9335 | UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex()); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9336 | if (card == null) { |
| 9337 | // assume no access if the card is unavailable |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9338 | filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo)); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9339 | continue; |
| 9340 | } |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9341 | Collection<UiccPortInfo> portInfos = cardInfo.getPorts(); |
| 9342 | if (portInfos.isEmpty()) { |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9343 | filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo)); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9344 | continue; |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9345 | } |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9346 | List<UiccPortInfo> uiccPortInfos = new ArrayList<>(); |
| 9347 | for (UiccPortInfo portInfo : portInfos) { |
| 9348 | UiccPort port = uiccController.getUiccPortForSlot( |
| 9349 | cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex()); |
| 9350 | if (port == null) { |
| 9351 | // assume no access if port is null |
| 9352 | uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo)); |
| 9353 | continue; |
| 9354 | } |
| 9355 | if (haveCarrierPrivilegeAccess(port, callingPackage)) { |
| 9356 | uiccPortInfos.add(portInfo); |
| 9357 | } else { |
| 9358 | uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo)); |
| 9359 | } |
| 9360 | } |
| 9361 | filteredInfos.add(new UiccCardInfo( |
| 9362 | cardInfo.isEuicc(), |
| 9363 | cardInfo.getCardId(), |
| 9364 | null, |
| 9365 | cardInfo.getPhysicalSlotIndex(), |
| 9366 | cardInfo.isRemovable(), |
| 9367 | cardInfo.isMultipleEnabledProfilesSupported(), |
| 9368 | uiccPortInfos)); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9369 | } |
| 9370 | return filteredInfos; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 9371 | } finally { |
| 9372 | Binder.restoreCallingIdentity(identity); |
| 9373 | } |
| 9374 | } |
| 9375 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9376 | /** |
| 9377 | * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are |
| 9378 | * generally private and require carrier privileges to view. |
| 9379 | * |
| 9380 | * @hide |
| 9381 | */ |
| 9382 | @NonNull |
| 9383 | public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) { |
| 9384 | List<UiccPortInfo> portinfo = new ArrayList<>(); |
| 9385 | for (UiccPortInfo portinfos : cardInfo.getPorts()) { |
| 9386 | portinfo.add(getUiccPortInfoUnPrivileged(portinfos)); |
| 9387 | } |
| 9388 | return new UiccCardInfo( |
| 9389 | cardInfo.isEuicc(), |
| 9390 | cardInfo.getCardId(), |
| 9391 | null, |
| 9392 | cardInfo.getPhysicalSlotIndex(), |
| 9393 | cardInfo.isRemovable(), |
| 9394 | cardInfo.isMultipleEnabledProfilesSupported(), |
| 9395 | portinfo |
| 9396 | ); |
| 9397 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9398 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9399 | /** |
| 9400 | * @hide |
| 9401 | * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}. |
| 9402 | * These values are generally private and require carrier privileges to view. |
| 9403 | */ |
| 9404 | @NonNull |
| 9405 | public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) { |
| 9406 | return new UiccPortInfo( |
| 9407 | UiccPortInfo.ICCID_REDACTED, |
| 9408 | portInfo.getPortIndex(), |
| 9409 | portInfo.getLogicalSlotIndex(), |
| 9410 | portInfo.isActive() |
| 9411 | ); |
| 9412 | } |
| 9413 | @Override |
| 9414 | public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) { |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9415 | // Verify that the callingPackage belongs to the calling UID |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9416 | mApp.getSystemService(AppOpsManager.class) |
| 9417 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 9418 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9419 | boolean isLogicalSlotAccessRestricted = false; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9420 | |
Aman Gupta | f3c90b3 | 2022-03-17 04:54:16 +0000 | [diff] [blame] | 9421 | // This will make sure caller has the READ_PRIVILEGED_PHONE_STATE. Do not remove this as |
| 9422 | // we are reading iccId which is PII data. |
| 9423 | enforceReadPrivilegedPermission("getUiccSlotsInfo"); |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9424 | |
| 9425 | // checking compatibility, if calling app's target SDK is T and beyond. |
| 9426 | if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO, |
| 9427 | Binder.getCallingUid())) { |
| 9428 | isLogicalSlotAccessRestricted = true; |
| 9429 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9430 | final long identity = Binder.clearCallingIdentity(); |
| 9431 | try { |
| 9432 | UiccSlot[] slots = UiccController.getInstance().getUiccSlots(); |
Muralidhar Reddy | d196bbf | 2022-01-17 17:56:30 +0000 | [diff] [blame] | 9433 | if (slots == null || slots.length == 0) { |
| 9434 | Rlog.i(LOG_TAG, "slots is null or empty."); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9435 | return null; |
| 9436 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9437 | UiccSlotInfo[] infos = new UiccSlotInfo[slots.length]; |
| 9438 | for (int i = 0; i < slots.length; i++) { |
| 9439 | UiccSlot slot = slots[i]; |
| 9440 | if (slot == null) { |
| 9441 | continue; |
| 9442 | } |
| 9443 | |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 9444 | String cardId; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9445 | UiccCard card = slot.getUiccCard(); |
| 9446 | if (card != null) { |
| 9447 | cardId = card.getCardId(); |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 9448 | } else { |
Jordan Liu | 01bd00d | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 9449 | cardId = slot.getEid(); |
| 9450 | if (TextUtils.isEmpty(cardId)) { |
Aman Gupta | f3c90b3 | 2022-03-17 04:54:16 +0000 | [diff] [blame] | 9451 | // If cardId is null, use iccId of default port as cardId. |
| 9452 | cardId = slot.getIccId(TelephonyManager.DEFAULT_PORT_INDEX); |
Jordan Liu | 01bd00d | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 9453 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9454 | } |
| 9455 | |
Jordan Liu | 857451f | 2019-05-09 16:35:35 -0700 | [diff] [blame] | 9456 | if (cardId != null) { |
| 9457 | // if cardId is an ICCID, strip off trailing Fs before exposing to user |
| 9458 | // if cardId is an EID, it's all digits so this is fine |
| 9459 | cardId = IccUtils.stripTrailingFs(cardId); |
| 9460 | } |
| 9461 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9462 | int cardState = 0; |
| 9463 | switch (slot.getCardState()) { |
| 9464 | case CARDSTATE_ABSENT: |
| 9465 | cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT; |
| 9466 | break; |
| 9467 | case CARDSTATE_PRESENT: |
| 9468 | cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT; |
| 9469 | break; |
| 9470 | case CARDSTATE_ERROR: |
| 9471 | cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR; |
| 9472 | break; |
| 9473 | case CARDSTATE_RESTRICTED: |
| 9474 | cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED; |
| 9475 | break; |
| 9476 | default: |
| 9477 | break; |
| 9478 | |
| 9479 | } |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9480 | List<UiccPortInfo> portInfos = new ArrayList<>(); |
| 9481 | int[] portIndexes = slot.getPortList(); |
| 9482 | for (int portIdx : portIndexes) { |
| 9483 | String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx, |
Aman Gupta | f3c90b3 | 2022-03-17 04:54:16 +0000 | [diff] [blame] | 9484 | callingPackage, /* hasReadPermission= */ true)); |
Muralidhar Reddy | fbcff0c | 2022-01-19 13:07:57 +0000 | [diff] [blame] | 9485 | portInfos.add(new UiccPortInfo(iccId, portIdx, |
| 9486 | slot.getPhoneIdFromPortIndex(portIdx), slot.isPortActive(portIdx))); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9487 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9488 | infos[i] = new UiccSlotInfo( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9489 | slot.isEuicc(), |
| 9490 | cardId, |
| 9491 | cardState, |
Jordan Liu | a261958 | 2019-02-14 12:56:40 -0800 | [diff] [blame] | 9492 | slot.isExtendedApduSupported(), |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9493 | slot.isRemovable(), portInfos); |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9494 | //setting the value after compatibility check |
| 9495 | infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9496 | } |
| 9497 | return infos; |
| 9498 | } finally { |
| 9499 | Binder.restoreCallingIdentity(identity); |
Holly Jiuyu Sun | 1d957c5 | 2018-04-04 13:52:42 -0700 | [diff] [blame] | 9500 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9501 | } |
| 9502 | |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9503 | /* Returns null if doesn't have read permission or carrier privilege access. */ |
| 9504 | private String getIccId(UiccSlot slot, int portIndex, String callingPackage, |
| 9505 | boolean hasReadPermission) { |
| 9506 | String iccId = slot.getIccId(portIndex); |
| 9507 | if (hasReadPermission) { // if has read permission |
| 9508 | return iccId; |
| 9509 | } else { |
| 9510 | if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) { |
| 9511 | UiccPort port = slot.getUiccCard().getUiccPort(portIndex); |
| 9512 | // if no read permission, checking carrier privilege access |
| 9513 | if (haveCarrierPrivilegeAccess(port, callingPackage)) { |
| 9514 | return iccId; |
| 9515 | } |
| 9516 | } |
| 9517 | } |
| 9518 | // No read permission or carrier privilege access. |
| 9519 | return UiccPortInfo.ICCID_REDACTED; |
| 9520 | } |
| 9521 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9522 | @Override |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9523 | @Deprecated |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9524 | public boolean switchSlots(int[] physicalSlots) { |
| 9525 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9526 | |
| 9527 | final long identity = Binder.clearCallingIdentity(); |
| 9528 | try { |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9529 | List<UiccSlotMapping> slotMappings = new ArrayList<>(); |
| 9530 | for (int i = 0; i < physicalSlots.length; i++) { |
| 9531 | // Deprecated API, hence MEP is not supported. Adding default portIndex 0. |
| 9532 | slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX, |
| 9533 | physicalSlots[i], i)); |
| 9534 | } |
| 9535 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9536 | } finally { |
| 9537 | Binder.restoreCallingIdentity(identity); |
| 9538 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9539 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 9540 | |
| 9541 | @Override |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9542 | @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 9543 | public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) { |
| 9544 | enforceModifyPermission(); |
| 9545 | |
| 9546 | final long identity = Binder.clearCallingIdentity(); |
| 9547 | try { |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9548 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping); |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9549 | } finally { |
| 9550 | Binder.restoreCallingIdentity(identity); |
| 9551 | } |
| 9552 | } |
| 9553 | |
| 9554 | @Override |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 9555 | public int getCardIdForDefaultEuicc(int subId, String callingPackage) { |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 9556 | final long identity = Binder.clearCallingIdentity(); |
| 9557 | try { |
| 9558 | return UiccController.getInstance().getCardIdForDefaultEuicc(); |
| 9559 | } finally { |
| 9560 | Binder.restoreCallingIdentity(identity); |
| 9561 | } |
| 9562 | } |
| 9563 | |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9564 | /** |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 9565 | * A test API to reload the UICC profile. |
| 9566 | * |
| 9567 | * <p>Requires that the calling app has permission |
| 9568 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 9569 | * @hide |
| 9570 | */ |
| 9571 | @Override |
| 9572 | public void refreshUiccProfile(int subId) { |
| 9573 | enforceModifyPermission(); |
| 9574 | |
| 9575 | final long identity = Binder.clearCallingIdentity(); |
| 9576 | try { |
| 9577 | Phone phone = getPhone(subId); |
| 9578 | if (phone == null) { |
| 9579 | return; |
| 9580 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9581 | UiccPort uiccPort = phone.getUiccPort(); |
| 9582 | if (uiccPort == null) { |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 9583 | return; |
| 9584 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9585 | UiccProfile uiccProfile = uiccPort.getUiccProfile(); |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 9586 | if (uiccProfile == null) { |
| 9587 | return; |
| 9588 | } |
| 9589 | uiccProfile.refresh(); |
| 9590 | } finally { |
| 9591 | Binder.restoreCallingIdentity(identity); |
| 9592 | } |
| 9593 | } |
| 9594 | |
| 9595 | /** |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9596 | * Returns false if the mobile data is disabled by default, otherwise return true. |
| 9597 | */ |
| 9598 | private boolean getDefaultDataEnabled() { |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 9599 | return TelephonyProperties.mobile_data().orElse(true); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9600 | } |
| 9601 | |
| 9602 | /** |
| 9603 | * Returns true if the data roaming is enabled by default, i.e the system property |
| 9604 | * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of |
| 9605 | * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true. |
| 9606 | */ |
| 9607 | private boolean getDefaultDataRoamingEnabled(int subId) { |
| 9608 | final CarrierConfigManager configMgr = (CarrierConfigManager) |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9609 | mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Shuo Qian | 1d84a0e | 2020-07-15 12:36:44 -0700 | [diff] [blame] | 9610 | boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9611 | isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean( |
| 9612 | CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL); |
| 9613 | return isDataRoamingEnabled; |
| 9614 | } |
| 9615 | |
| 9616 | /** |
| 9617 | * Returns the default network type for the given {@code subId}, if the default network type is |
| 9618 | * not set, return {@link Phone#PREFERRED_NT_MODE}. |
| 9619 | */ |
| 9620 | private int getDefaultNetworkType(int subId) { |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 9621 | List<Integer> list = TelephonyProperties.default_network(); |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 9622 | int phoneId = SubscriptionManager.getPhoneId(subId); |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 9623 | if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) { |
| 9624 | return list.get(phoneId); |
| 9625 | } |
| 9626 | return Phone.PREFERRED_NT_MODE; |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9627 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9628 | |
| 9629 | @Override |
| 9630 | public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 9631 | gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) { |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9632 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9633 | |
| 9634 | final long identity = Binder.clearCallingIdentity(); |
| 9635 | try { |
| 9636 | final Phone phone = getPhone(subId); |
| 9637 | if (phone == null) { |
| 9638 | loge("setCarrierTestOverride fails with invalid subId: " + subId); |
| 9639 | return; |
| 9640 | } |
Rambo Wang | 9c9ffdd | 2022-01-13 21:51:44 -0800 | [diff] [blame] | 9641 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 9642 | if (cpt != null) { |
| 9643 | cpt.setTestOverrideCarrierPrivilegeRules(carrierPrivilegeRules); |
| 9644 | } |
| 9645 | // 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] | 9646 | phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn, |
| 9647 | carrierPrivilegeRules, apn); |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 9648 | if (carrierPrivilegeRules == null) { |
| 9649 | mCarrierPrivilegeTestOverrideSubIds.remove(subId); |
| 9650 | } else { |
| 9651 | mCarrierPrivilegeTestOverrideSubIds.add(subId); |
| 9652 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9653 | } finally { |
| 9654 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9655 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9656 | } |
| 9657 | |
| 9658 | @Override |
| 9659 | public int getCarrierIdListVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 9660 | enforceReadPrivilegedPermission("getCarrierIdListVersion"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9661 | |
| 9662 | final long identity = Binder.clearCallingIdentity(); |
| 9663 | try { |
| 9664 | final Phone phone = getPhone(subId); |
| 9665 | if (phone == null) { |
| 9666 | loge("getCarrierIdListVersion fails with invalid subId: " + subId); |
| 9667 | return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION; |
| 9668 | } |
| 9669 | return phone.getCarrierIdListVersion(); |
| 9670 | } finally { |
| 9671 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9672 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9673 | } |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 9674 | |
| 9675 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9676 | public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage, |
| 9677 | String callingFeatureId) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 9678 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9679 | mApp, subId, callingPackage, callingFeatureId, |
| 9680 | "getNumberOfModemsWithSimultaneousDataConnections")) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 9681 | return -1; |
| 9682 | } |
| 9683 | |
| 9684 | final long identity = Binder.clearCallingIdentity(); |
| 9685 | try { |
| 9686 | return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections(); |
| 9687 | } finally { |
| 9688 | Binder.restoreCallingIdentity(identity); |
| 9689 | } |
| 9690 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9691 | |
| 9692 | @Override |
| 9693 | public int getCdmaRoamingMode(int subId) { |
zoey chen | 7e6d4e5 | 2019-12-17 18:18:59 +0800 | [diff] [blame] | 9694 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9695 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9696 | mApp, subId, "getCdmaRoamingMode"); |
| 9697 | |
| 9698 | final long identity = Binder.clearCallingIdentity(); |
| 9699 | try { |
| 9700 | return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId); |
| 9701 | } finally { |
| 9702 | Binder.restoreCallingIdentity(identity); |
| 9703 | } |
| 9704 | } |
| 9705 | |
| 9706 | @Override |
| 9707 | public boolean setCdmaRoamingMode(int subId, int mode) { |
| 9708 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9709 | mApp, subId, "setCdmaRoamingMode"); |
| 9710 | |
| 9711 | final long identity = Binder.clearCallingIdentity(); |
| 9712 | try { |
| 9713 | return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId); |
| 9714 | } finally { |
| 9715 | Binder.restoreCallingIdentity(identity); |
| 9716 | } |
| 9717 | } |
| 9718 | |
| 9719 | @Override |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 9720 | public int getCdmaSubscriptionMode(int subId) { |
| 9721 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9722 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 9723 | mApp, subId, "getCdmaSubscriptionMode"); |
| 9724 | |
| 9725 | final long identity = Binder.clearCallingIdentity(); |
| 9726 | try { |
| 9727 | return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId); |
| 9728 | } finally { |
| 9729 | Binder.restoreCallingIdentity(identity); |
| 9730 | } |
| 9731 | } |
| 9732 | |
| 9733 | @Override |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9734 | public boolean setCdmaSubscriptionMode(int subId, int mode) { |
| 9735 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9736 | mApp, subId, "setCdmaSubscriptionMode"); |
| 9737 | |
| 9738 | final long identity = Binder.clearCallingIdentity(); |
| 9739 | try { |
| 9740 | return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId); |
| 9741 | } finally { |
| 9742 | Binder.restoreCallingIdentity(identity); |
| 9743 | } |
| 9744 | } |
Makoto Onuki | da3bf79 | 2018-09-18 16:06:29 -0700 | [diff] [blame] | 9745 | |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 9746 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 9747 | public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9748 | String callingPackage, String callingFeatureId) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9749 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9750 | mApp, getDefaultSubscription(), callingPackage, callingFeatureId, |
| 9751 | "getEmergencyNumberList")) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9752 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 9753 | } |
| 9754 | final long identity = Binder.clearCallingIdentity(); |
| 9755 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 9756 | Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>(); |
| 9757 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9758 | if (phone.getEmergencyNumberTracker() != null |
| 9759 | && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) { |
| 9760 | emergencyNumberListInternal.put( |
| 9761 | phone.getSubId(), |
| 9762 | phone.getEmergencyNumberTracker().getEmergencyNumberList()); |
| 9763 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9764 | } |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 9765 | return emergencyNumberListInternal; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9766 | } finally { |
| 9767 | Binder.restoreCallingIdentity(identity); |
| 9768 | } |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 9769 | } |
| 9770 | |
| 9771 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 9772 | public boolean isEmergencyNumber(String number, boolean exactMatch) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9773 | final Phone defaultPhone = getDefaultPhone(); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9774 | if (!exactMatch) { |
| 9775 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9776 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 9777 | mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)"); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9778 | } |
| 9779 | final long identity = Binder.clearCallingIdentity(); |
| 9780 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 9781 | for (Phone phone: PhoneFactory.getPhones()) { |
Chinmay Dhodapkar | d521bb1 | 2022-08-16 15:49:54 -0700 | [diff] [blame] | 9782 | //Note: we ignore passed in param exactMatch. We can remove it once |
| 9783 | // TelephonyManager#isPotentialEmergencyNumber is removed completely |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 9784 | if (phone.getEmergencyNumberTracker() != null |
Taesu Lee | e050c00 | 2020-10-13 17:19:35 +0900 | [diff] [blame] | 9785 | && phone.getEmergencyNumberTracker() |
Chinmay Dhodapkar | d521bb1 | 2022-08-16 15:49:54 -0700 | [diff] [blame] | 9786 | .isEmergencyNumber(number)) { |
Taesu Lee | e050c00 | 2020-10-13 17:19:35 +0900 | [diff] [blame] | 9787 | return true; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9788 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9789 | } |
| 9790 | return false; |
| 9791 | } finally { |
| 9792 | Binder.restoreCallingIdentity(identity); |
| 9793 | } |
| 9794 | } |
| 9795 | |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 9796 | /** |
Shuo Qian | ccbaf74 | 2021-02-22 18:32:21 -0800 | [diff] [blame] | 9797 | * Start emergency callback mode for GsmCdmaPhone for testing. |
| 9798 | */ |
| 9799 | @Override |
| 9800 | public void startEmergencyCallbackMode() { |
| 9801 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9802 | "startEmergencyCallbackMode"); |
| 9803 | enforceModifyPermission(); |
| 9804 | final long identity = Binder.clearCallingIdentity(); |
| 9805 | try { |
| 9806 | for (Phone phone : PhoneFactory.getPhones()) { |
| 9807 | Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType()); |
| 9808 | if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM) |
| 9809 | || (phone.getPhoneType() == PHONE_TYPE_CDMA))) { |
| 9810 | GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone; |
| 9811 | gsmCdmaPhone.obtainMessage( |
| 9812 | GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget(); |
| 9813 | Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered"); |
| 9814 | } |
| 9815 | } |
| 9816 | } finally { |
| 9817 | Binder.restoreCallingIdentity(identity); |
| 9818 | } |
| 9819 | } |
| 9820 | |
| 9821 | /** |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 9822 | * Update emergency number list for test mode. |
| 9823 | */ |
| 9824 | @Override |
| 9825 | public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) { |
| 9826 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9827 | "updateEmergencyNumberListTestMode"); |
| 9828 | |
| 9829 | final long identity = Binder.clearCallingIdentity(); |
| 9830 | try { |
| 9831 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9832 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9833 | if (tracker != null) { |
| 9834 | tracker.executeEmergencyNumberTestModeCommand(action, num); |
| 9835 | } |
| 9836 | } |
| 9837 | } finally { |
| 9838 | Binder.restoreCallingIdentity(identity); |
| 9839 | } |
| 9840 | } |
| 9841 | |
| 9842 | /** |
| 9843 | * Get the full emergency number list for test mode. |
| 9844 | */ |
| 9845 | @Override |
| 9846 | public List<String> getEmergencyNumberListTestMode() { |
| 9847 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9848 | "getEmergencyNumberListTestMode"); |
| 9849 | |
| 9850 | final long identity = Binder.clearCallingIdentity(); |
| 9851 | try { |
| 9852 | Set<String> emergencyNumbers = new HashSet<>(); |
| 9853 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9854 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9855 | if (tracker != null) { |
| 9856 | for (EmergencyNumber num : tracker.getEmergencyNumberList()) { |
| 9857 | emergencyNumbers.add(num.getNumber()); |
| 9858 | } |
| 9859 | } |
| 9860 | } |
| 9861 | return new ArrayList<>(emergencyNumbers); |
| 9862 | } finally { |
| 9863 | Binder.restoreCallingIdentity(identity); |
| 9864 | } |
| 9865 | } |
| 9866 | |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 9867 | @Override |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 9868 | public int getEmergencyNumberDbVersion(int subId) { |
| 9869 | enforceReadPrivilegedPermission("getEmergencyNumberDbVersion"); |
| 9870 | |
| 9871 | final long identity = Binder.clearCallingIdentity(); |
| 9872 | try { |
| 9873 | final Phone phone = getPhone(subId); |
| 9874 | if (phone == null) { |
| 9875 | loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId); |
| 9876 | return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION; |
| 9877 | } |
| 9878 | return phone.getEmergencyNumberDbVersion(); |
| 9879 | } finally { |
| 9880 | Binder.restoreCallingIdentity(identity); |
| 9881 | } |
| 9882 | } |
| 9883 | |
| 9884 | @Override |
| 9885 | public void notifyOtaEmergencyNumberDbInstalled() { |
| 9886 | enforceModifyPermission(); |
| 9887 | |
| 9888 | final long identity = Binder.clearCallingIdentity(); |
| 9889 | try { |
| 9890 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9891 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9892 | if (tracker != null) { |
| 9893 | tracker.updateOtaEmergencyNumberDatabase(); |
| 9894 | } |
| 9895 | } |
| 9896 | } finally { |
| 9897 | Binder.restoreCallingIdentity(identity); |
| 9898 | } |
| 9899 | } |
| 9900 | |
| 9901 | @Override |
Shuo Qian | c373f11 | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 9902 | public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) { |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 9903 | enforceActiveEmergencySessionPermission(); |
| 9904 | |
| 9905 | final long identity = Binder.clearCallingIdentity(); |
| 9906 | try { |
| 9907 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9908 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9909 | if (tracker != null) { |
Shuo Qian | c373f11 | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 9910 | tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor); |
| 9911 | } |
| 9912 | } |
| 9913 | } finally { |
| 9914 | Binder.restoreCallingIdentity(identity); |
| 9915 | } |
| 9916 | } |
| 9917 | |
| 9918 | @Override |
| 9919 | public void resetOtaEmergencyNumberDbFilePath() { |
| 9920 | enforceActiveEmergencySessionPermission(); |
| 9921 | |
| 9922 | final long identity = Binder.clearCallingIdentity(); |
| 9923 | try { |
| 9924 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9925 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9926 | if (tracker != null) { |
| 9927 | tracker.resetOtaEmergencyNumberDbFilePath(); |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 9928 | } |
| 9929 | } |
| 9930 | } finally { |
| 9931 | Binder.restoreCallingIdentity(identity); |
| 9932 | } |
| 9933 | } |
| 9934 | |
| 9935 | @Override |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 9936 | public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) { |
| 9937 | enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules"); |
| 9938 | Phone phone = getPhone(subId); |
| 9939 | if (phone == null) { |
| 9940 | return null; |
| 9941 | } |
| 9942 | final long identity = Binder.clearCallingIdentity(); |
| 9943 | try { |
| 9944 | UiccProfile profile = UiccController.getInstance() |
| 9945 | .getUiccProfileForPhone(phone.getPhoneId()); |
| 9946 | if (profile != null) { |
| 9947 | return profile.getCertsFromCarrierPrivilegeAccessRules(); |
| 9948 | } |
| 9949 | } finally { |
| 9950 | Binder.restoreCallingIdentity(identity); |
| 9951 | } |
| 9952 | return null; |
| 9953 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 9954 | |
| 9955 | /** |
| 9956 | * Enable or disable a modem stack. |
| 9957 | */ |
| 9958 | @Override |
| 9959 | public boolean enableModemForSlot(int slotIndex, boolean enable) { |
| 9960 | enforceModifyPermission(); |
| 9961 | |
| 9962 | final long identity = Binder.clearCallingIdentity(); |
| 9963 | try { |
| 9964 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 9965 | if (phone == null) { |
| 9966 | return false; |
| 9967 | } else { |
| 9968 | return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null); |
| 9969 | } |
| 9970 | } finally { |
| 9971 | Binder.restoreCallingIdentity(identity); |
| 9972 | } |
| 9973 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9974 | |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 9975 | /** |
| 9976 | * Whether a modem stack is enabled or not. |
| 9977 | */ |
| 9978 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9979 | public boolean isModemEnabledForSlot(int slotIndex, String callingPackage, |
| 9980 | String callingFeatureId) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 9981 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 9982 | if (phone == null) return false; |
| 9983 | |
| 9984 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9985 | mApp, phone.getSubId(), callingPackage, callingFeatureId, |
| 9986 | "isModemEnabledForSlot")) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 9987 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 9988 | } |
| 9989 | |
| 9990 | final long identity = Binder.clearCallingIdentity(); |
| 9991 | try { |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 9992 | try { |
| 9993 | return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId()); |
| 9994 | } catch (NoSuchElementException ex) { |
| 9995 | return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null); |
| 9996 | } |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 9997 | } finally { |
| 9998 | Binder.restoreCallingIdentity(identity); |
| 9999 | } |
| 10000 | } |
| 10001 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 10002 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10003 | public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) { |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 10004 | enforceModifyPermission(); |
| 10005 | |
| 10006 | final long identity = Binder.clearCallingIdentity(); |
| 10007 | try { |
| 10008 | mTelephonySharedPreferences.edit() |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10009 | .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted) |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 10010 | .commit(); |
| 10011 | } finally { |
| 10012 | Binder.restoreCallingIdentity(identity); |
| 10013 | } |
| 10014 | } |
| 10015 | |
| 10016 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10017 | @TelephonyManager.IsMultiSimSupportedResult |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10018 | public int isMultiSimSupported(String callingPackage, String callingFeatureId) { |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 10019 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10020 | getDefaultPhone().getSubId(), callingPackage, callingFeatureId, |
| 10021 | "isMultiSimSupported")) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10022 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 10023 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 10024 | |
| 10025 | final long identity = Binder.clearCallingIdentity(); |
| 10026 | try { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10027 | return isMultiSimSupportedInternal(); |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 10028 | } finally { |
| 10029 | Binder.restoreCallingIdentity(identity); |
| 10030 | } |
| 10031 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 10032 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10033 | @TelephonyManager.IsMultiSimSupportedResult |
| 10034 | private int isMultiSimSupportedInternal() { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10035 | // If the device has less than 2 SIM cards, indicate that multisim is restricted. |
| 10036 | int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length; |
| 10037 | if (numPhysicalSlots < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10038 | loge("isMultiSimSupportedInternal: requires at least 2 cards"); |
| 10039 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10040 | } |
| 10041 | // Check if the hardware supports multisim functionality. If usage of multisim is not |
| 10042 | // supported by the modem, indicate that it is restricted. |
| 10043 | PhoneCapability staticCapability = |
| 10044 | mPhoneConfigurationManager.getStaticPhoneCapability(); |
| 10045 | if (staticCapability == null) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10046 | loge("isMultiSimSupportedInternal: no static configuration available"); |
| 10047 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10048 | } |
SongFerngWang | 8236caa | 2021-01-17 21:51:44 +0800 | [diff] [blame] | 10049 | if (staticCapability.getLogicalModemList().size() < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10050 | loge("isMultiSimSupportedInternal: maximum number of modem is < 2"); |
| 10051 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10052 | } |
| 10053 | // Check if support of multiple SIMs is restricted by carrier |
| 10054 | if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10055 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10056 | } |
| 10057 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10058 | return TelephonyManager.MULTISIM_ALLOWED; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10059 | } |
| 10060 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 10061 | /** |
| 10062 | * Switch configs to enable multi-sim or switch back to single-sim |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 10063 | * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE |
| 10064 | * permission, but the other way around is possible with either MODIFY_PHONE_STATE |
| 10065 | * or carrier privileges |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 10066 | * @param numOfSims number of active sims we want to switch to |
| 10067 | */ |
| 10068 | @Override |
| 10069 | public void switchMultiSimConfig(int numOfSims) { |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 10070 | if (numOfSims == 1) { |
| 10071 | enforceModifyPermission(); |
| 10072 | } else { |
| 10073 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 10074 | mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig"); |
| 10075 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 10076 | final long identity = Binder.clearCallingIdentity(); |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10077 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 10078 | try { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10079 | //only proceed if multi-sim is not restricted |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10080 | if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10081 | loge("switchMultiSimConfig not possible. It is restricted or not supported."); |
| 10082 | return; |
| 10083 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 10084 | mPhoneConfigurationManager.switchMultiSimConfig(numOfSims); |
| 10085 | } finally { |
| 10086 | Binder.restoreCallingIdentity(identity); |
| 10087 | } |
| 10088 | } |
| 10089 | |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 10090 | @Override |
| 10091 | public boolean isApplicationOnUicc(int subId, int appType) { |
| 10092 | enforceReadPrivilegedPermission("isApplicationOnUicc"); |
| 10093 | Phone phone = getPhone(subId); |
| 10094 | if (phone == null) { |
| 10095 | return false; |
| 10096 | } |
| 10097 | final long identity = Binder.clearCallingIdentity(); |
| 10098 | try { |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 10099 | UiccPort uiccPort = phone.getUiccPort(); |
| 10100 | if (uiccPort == null) { |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 10101 | return false; |
| 10102 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 10103 | UiccProfile uiccProfile = uiccPort.getUiccProfile(); |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 10104 | if (uiccProfile == null) { |
| 10105 | return false; |
| 10106 | } |
| 10107 | if (TelephonyManager.APPTYPE_SIM <= appType |
| 10108 | && appType <= TelephonyManager.APPTYPE_ISIM) { |
| 10109 | return uiccProfile.isApplicationOnIcc(AppType.values()[appType]); |
| 10110 | } |
| 10111 | return false; |
| 10112 | } finally { |
| 10113 | Binder.restoreCallingIdentity(identity); |
| 10114 | } |
| 10115 | } |
| 10116 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 10117 | /** |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 10118 | * Get whether making changes to modem configurations will trigger reboot. |
| 10119 | * Return value defaults to true. |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 10120 | */ |
| 10121 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10122 | public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage, |
| 10123 | String callingFeatureId) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 10124 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10125 | mApp, subId, callingPackage, callingFeatureId, |
| 10126 | "doesSwitchMultiSimConfigTriggerReboot")) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 10127 | return false; |
| 10128 | } |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 10129 | final long identity = Binder.clearCallingIdentity(); |
| 10130 | try { |
| 10131 | return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange(); |
| 10132 | } finally { |
| 10133 | Binder.restoreCallingIdentity(identity); |
| 10134 | } |
| 10135 | } |
| 10136 | |
Nathan Harold | 29f5f05 | 2019-02-15 13:41:57 -0800 | [diff] [blame] | 10137 | private void updateModemStateMetrics() { |
| 10138 | TelephonyMetrics metrics = TelephonyMetrics.getInstance(); |
| 10139 | // TODO: check the state for each modem if the api is ready. |
| 10140 | metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1); |
| 10141 | } |
| 10142 | |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10143 | @Override |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 10144 | public List<UiccSlotMapping> getSlotsMapping(String callingPackage) { |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10145 | enforceReadPrivilegedPermission("getSlotsMapping"); |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 10146 | // Verify that the callingPackage belongs to the calling UID |
| 10147 | mApp.getSystemService(AppOpsManager.class) |
| 10148 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10149 | final long identity = Binder.clearCallingIdentity(); |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 10150 | List<UiccSlotMapping> slotMap = new ArrayList<>(); |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10151 | try { |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 10152 | UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName()); |
| 10153 | if (slotInfos != null) { |
| 10154 | for (int i = 0; i < slotInfos.length; i++) { |
| 10155 | for (UiccPortInfo portInfo : slotInfos[i].getPorts()) { |
| 10156 | if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) { |
| 10157 | slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i, |
| 10158 | portInfo.getLogicalSlotIndex())); |
| 10159 | } |
| 10160 | } |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10161 | } |
| 10162 | } |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 10163 | return slotMap; |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10164 | } finally { |
| 10165 | Binder.restoreCallingIdentity(identity); |
| 10166 | } |
| 10167 | } |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 10168 | |
| 10169 | /** |
| 10170 | * Get the IRadio HAL Version |
jimsun | f9ec162 | 2022-09-13 21:18:43 +0800 | [diff] [blame] | 10171 | * @deprecated use getHalVersion instead |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 10172 | */ |
jimsun | f9ec162 | 2022-09-13 21:18:43 +0800 | [diff] [blame] | 10173 | @Deprecated |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 10174 | @Override |
| 10175 | public int getRadioHalVersion() { |
jimsun | f9ec162 | 2022-09-13 21:18:43 +0800 | [diff] [blame] | 10176 | return getHalVersion(HAL_SERVICE_RADIO); |
| 10177 | } |
| 10178 | |
| 10179 | /** |
| 10180 | * Get the HAL Version of a specific service |
| 10181 | */ |
| 10182 | @Override |
| 10183 | public int getHalVersion(int service) { |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 10184 | Phone phone = getDefaultPhone(); |
| 10185 | if (phone == null) return -1; |
jimsun | f9ec162 | 2022-09-13 21:18:43 +0800 | [diff] [blame] | 10186 | HalVersion hv = phone.getHalVersion(service); |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 10187 | if (hv.equals(HalVersion.UNKNOWN)) return -1; |
| 10188 | return hv.major * 100 + hv.minor; |
| 10189 | } |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 10190 | |
| 10191 | /** |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 10192 | * Get the current calling package name. |
| 10193 | * @return the current calling package name |
| 10194 | */ |
| 10195 | @Override |
| 10196 | public String getCurrentPackageName() { |
| 10197 | return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0]; |
| 10198 | } |
| 10199 | |
| 10200 | /** |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10201 | * Return whether data is enabled for certain APN type. This will tell if framework will accept |
| 10202 | * corresponding network requests on a subId. |
| 10203 | * |
| 10204 | * Data is enabled if: |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 10205 | * 1) user data is turned on, or |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10206 | * 2) APN is un-metered for this subscription, or |
| 10207 | * 3) APN type is whitelisted. E.g. MMS is whitelisted if |
Hall Liu | 746e03c | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 10208 | * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled. |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10209 | * |
| 10210 | * @return whether data is allowed for a apn type. |
| 10211 | * |
| 10212 | * @hide |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 10213 | */ |
| 10214 | @Override |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10215 | public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) { |
Amit Mahajan | 5d4e192 | 2019-10-07 16:20:43 -0700 | [diff] [blame] | 10216 | enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for " |
| 10217 | + "isDataEnabledForApn"); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 10218 | |
| 10219 | // Now that all security checks passes, perform the operation as ourselves. |
| 10220 | final long identity = Binder.clearCallingIdentity(); |
| 10221 | try { |
| 10222 | Phone phone = getPhone(subId); |
| 10223 | if (phone == null) return false; |
| 10224 | |
Jack Yu | 27422a5 | 2022-03-21 10:38:05 -0700 | [diff] [blame] | 10225 | boolean isMetered; |
Jack Yu | 99e8733 | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 10226 | boolean isDataEnabled; |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 10227 | isMetered = phone.getDataNetworkController().getDataConfigManager() |
| 10228 | .isMeteredCapability(DataUtils.apnTypeToNetworkCapability(apnType), |
| 10229 | phone.getServiceState().getDataRoaming()); |
| 10230 | isDataEnabled = phone.getDataSettingsManager().isDataEnabled(apnType); |
Jack Yu | 99e8733 | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 10231 | return !isMetered || isDataEnabled; |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10232 | } finally { |
| 10233 | Binder.restoreCallingIdentity(identity); |
| 10234 | } |
| 10235 | } |
| 10236 | |
| 10237 | @Override |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 10238 | public boolean isApnMetered(@ApnType int apnType, int subId) { |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10239 | enforceReadPrivilegedPermission("isApnMetered"); |
| 10240 | |
| 10241 | // Now that all security checks passes, perform the operation as ourselves. |
| 10242 | final long identity = Binder.clearCallingIdentity(); |
| 10243 | try { |
| 10244 | Phone phone = getPhone(subId); |
| 10245 | if (phone == null) return true; // By default return true. |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 10246 | return phone.getDataNetworkController().getDataConfigManager().isMeteredCapability( |
| 10247 | DataUtils.apnTypeToNetworkCapability(apnType), |
| 10248 | phone.getServiceState().getDataRoaming()); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 10249 | } finally { |
| 10250 | Binder.restoreCallingIdentity(identity); |
| 10251 | } |
| 10252 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 10253 | |
| 10254 | @Override |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 10255 | public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers, |
| 10256 | int subscriptionId, IBooleanConsumer resultCallback) { |
| 10257 | enforceModifyPermission(); |
| 10258 | long token = Binder.clearCallingIdentity(); |
| 10259 | try { |
| 10260 | Phone phone = getPhone(subscriptionId); |
| 10261 | if (phone == null) { |
| 10262 | try { |
| 10263 | if (resultCallback != null) { |
| 10264 | resultCallback.accept(false); |
| 10265 | } |
| 10266 | } catch (RemoteException e) { |
| 10267 | // ignore |
| 10268 | } |
| 10269 | return; |
| 10270 | } |
| 10271 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument = |
| 10272 | Pair.create(specifiers, (x) -> { |
| 10273 | try { |
| 10274 | if (resultCallback != null) { |
| 10275 | resultCallback.accept(x); |
| 10276 | } |
| 10277 | } catch (RemoteException e) { |
| 10278 | // ignore |
| 10279 | } |
| 10280 | }); |
| 10281 | sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null); |
| 10282 | } finally { |
| 10283 | Binder.restoreCallingIdentity(token); |
| 10284 | } |
| 10285 | } |
| 10286 | |
| 10287 | @Override |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 10288 | public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) { |
| 10289 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 10290 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 10291 | mApp, subId, "getSystemSelectionChannels"); |
| 10292 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 10293 | final long identity = Binder.clearCallingIdentity(); |
| 10294 | try { |
Sarah Chin | 428d1d6 | 2021-03-13 03:17:40 -0800 | [diff] [blame] | 10295 | Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource); |
| 10296 | if (result instanceof IllegalStateException) { |
| 10297 | throw (IllegalStateException) result; |
| 10298 | } |
| 10299 | List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 10300 | if (DBG) log("getSystemSelectionChannels: " + specifiers); |
| 10301 | return specifiers; |
| 10302 | } finally { |
| 10303 | Binder.restoreCallingIdentity(identity); |
| 10304 | } |
| 10305 | } |
| 10306 | |
| 10307 | @Override |
Jack Yu | 8b766fc | 2022-03-21 09:42:33 -0700 | [diff] [blame] | 10308 | public boolean isMvnoMatched(int slotIndex, int mvnoType, @NonNull String mvnoMatchData) { |
changbetty | ca3d40d | 2020-03-03 16:27:31 +0800 | [diff] [blame] | 10309 | enforceReadPrivilegedPermission("isMvnoMatched"); |
Jack Yu | 8b766fc | 2022-03-21 09:42:33 -0700 | [diff] [blame] | 10310 | return UiccController.getInstance().mvnoMatches(slotIndex, mvnoType, mvnoMatchData); |
changbetty | 7157e9e | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 10311 | } |
| 10312 | |
| 10313 | @Override |
Philip P. Moltmann | d02b737 | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 10314 | public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag, |
| 10315 | IIntegerConsumer pendingSubIdResult) { |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 10316 | if (callingPackage == null) { |
| 10317 | callingPackage = getCurrentPackageName(); |
| 10318 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 10319 | SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp, |
| 10320 | (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE)); |
Philip P. Moltmann | d02b737 | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 10321 | if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag, |
| 10322 | "Sending message")) { |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 10323 | throw new SecurityException("Requires SEND_SMS permission to perform this operation"); |
| 10324 | } |
| 10325 | PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult); |
| 10326 | Intent intent = new Intent(); |
| 10327 | intent.setClass(mApp, PickSmsSubscriptionActivity.class); |
| 10328 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 10329 | // Bring up choose default SMS subscription dialog right now |
| 10330 | intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY, |
| 10331 | PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE); |
| 10332 | mApp.startActivity(intent); |
| 10333 | } |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 10334 | |
| 10335 | @Override |
Ayush Sharma | 787854b | 2022-12-12 14:55:02 +0000 | [diff] [blame] | 10336 | public void showSwitchToManagedProfileDialog() { |
| 10337 | enforceModifyPermission(); |
| 10338 | |
| 10339 | Intent intent = new Intent(); |
| 10340 | intent.setClass(mApp, ErrorDialogActivity.class); |
| 10341 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 10342 | mApp.startActivity(intent); |
| 10343 | } |
| 10344 | |
| 10345 | @Override |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 10346 | public String getMmsUAProfUrl(int subId) { |
| 10347 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 10348 | final long identity = Binder.clearCallingIdentity(); |
| 10349 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 10350 | String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString( |
| 10351 | CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING); |
| 10352 | if (!TextUtils.isEmpty(carrierUAProfUrl)) { |
| 10353 | return carrierUAProfUrl; |
| 10354 | } |
Daniel Bright | ebb4eb7 | 2020-02-18 15:16:33 -0800 | [diff] [blame] | 10355 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 10356 | .getString(com.android.internal.R.string.config_mms_user_agent_profile_url); |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 10357 | } finally { |
| 10358 | Binder.restoreCallingIdentity(identity); |
| 10359 | } |
| 10360 | } |
| 10361 | |
| 10362 | @Override |
| 10363 | public String getMmsUserAgent(int subId) { |
| 10364 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 10365 | final long identity = Binder.clearCallingIdentity(); |
| 10366 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 10367 | String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString( |
| 10368 | CarrierConfigManager.KEY_MMS_USER_AGENT_STRING); |
| 10369 | if (!TextUtils.isEmpty(carrierUserAgent)) { |
| 10370 | return carrierUserAgent; |
| 10371 | } |
Daniel Bright | ebb4eb7 | 2020-02-18 15:16:33 -0800 | [diff] [blame] | 10372 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 10373 | .getString(com.android.internal.R.string.config_mms_user_agent); |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 10374 | } finally { |
| 10375 | Binder.restoreCallingIdentity(identity); |
| 10376 | } |
| 10377 | } |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 10378 | |
| 10379 | @Override |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 10380 | public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) { |
| 10381 | enforceReadPrivilegedPermission("isMobileDataPolicyEnabled"); |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 10382 | |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 10383 | final long identity = Binder.clearCallingIdentity(); |
| 10384 | try { |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 10385 | Phone phone = getPhone(subscriptionId); |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 10386 | if (phone == null) return false; |
| 10387 | |
Ling Ma | f188d50 | 2022-09-16 15:22:36 -0700 | [diff] [blame] | 10388 | return phone.getDataSettingsManager().isMobileDataPolicyEnabled(policy); |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 10389 | } finally { |
| 10390 | Binder.restoreCallingIdentity(identity); |
| 10391 | } |
| 10392 | } |
| 10393 | |
| 10394 | @Override |
Hall Liu | c66bb11 | 2021-02-02 12:09:32 -0800 | [diff] [blame] | 10395 | public void setMobileDataPolicyEnabled(int subscriptionId, int policy, |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 10396 | boolean enabled) { |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 10397 | enforceModifyPermission(); |
| 10398 | |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 10399 | final long identity = Binder.clearCallingIdentity(); |
| 10400 | try { |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 10401 | Phone phone = getPhone(subscriptionId); |
| 10402 | if (phone == null) return; |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 10403 | |
Ling Ma | f188d50 | 2022-09-16 15:22:36 -0700 | [diff] [blame] | 10404 | phone.getDataSettingsManager().setMobileDataPolicy(policy, enabled); |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 10405 | } finally { |
| 10406 | Binder.restoreCallingIdentity(identity); |
| 10407 | } |
| 10408 | } |
| 10409 | |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 10410 | /** |
Hall Liu | 746e03c | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 10411 | * Updates whether conference event package handling is enabled. |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 10412 | * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false} |
| 10413 | * otherwise. |
| 10414 | */ |
| 10415 | @Override |
| 10416 | public void setCepEnabled(boolean isCepEnabled) { |
| 10417 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled"); |
| 10418 | |
| 10419 | final long identity = Binder.clearCallingIdentity(); |
| 10420 | try { |
| 10421 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled); |
| 10422 | for (Phone phone : PhoneFactory.getPhones()) { |
| 10423 | Phone defaultPhone = phone.getImsPhone(); |
| 10424 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 10425 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 10426 | ImsPhoneCallTracker imsPhoneCallTracker = |
| 10427 | (ImsPhoneCallTracker) imsPhone.getCallTracker(); |
| 10428 | imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled); |
| 10429 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone " |
| 10430 | + imsPhone.getMsisdn()); |
| 10431 | } |
| 10432 | } |
| 10433 | } finally { |
| 10434 | Binder.restoreCallingIdentity(identity); |
| 10435 | } |
| 10436 | } |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 10437 | |
| 10438 | /** |
| 10439 | * Notify that an RCS autoconfiguration XML file has been received for provisioning. |
| 10440 | * |
| 10441 | * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed. |
| 10442 | * @param isCompressed The XML file is compressed in gzip format and must be decompressed |
| 10443 | * before being read. |
| 10444 | */ |
| 10445 | @Override |
| 10446 | public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean |
| 10447 | isCompressed) { |
| 10448 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 10449 | mApp, subId, "notifyRcsAutoConfigurationReceived"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10450 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10451 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10452 | } |
| 10453 | if (!isImsAvailableOnDevice()) { |
joonhunshin | 46b49a3 | 2022-12-21 05:33:23 +0000 | [diff] [blame] | 10454 | // ProvisioningManager can not handle ServiceSpecificException. |
| 10455 | // Throw the IllegalStateException and annotate ProvisioningManager. |
| 10456 | throw new IllegalStateException("IMS not available on device."); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10457 | } |
| 10458 | |
| 10459 | final long identity = Binder.clearCallingIdentity(); |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 10460 | try { |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10461 | RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed); |
| 10462 | } finally { |
| 10463 | Binder.restoreCallingIdentity(identity); |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 10464 | } |
| 10465 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 10466 | |
| 10467 | @Override |
| 10468 | public boolean isIccLockEnabled(int subId) { |
| 10469 | enforceReadPrivilegedPermission("isIccLockEnabled"); |
| 10470 | |
| 10471 | // Now that all security checks passes, perform the operation as ourselves. |
| 10472 | final long identity = Binder.clearCallingIdentity(); |
| 10473 | try { |
| 10474 | Phone phone = getPhone(subId); |
| 10475 | if (phone != null && phone.getIccCard() != null) { |
| 10476 | return phone.getIccCard().getIccLockEnabled(); |
| 10477 | } else { |
| 10478 | return false; |
| 10479 | } |
| 10480 | } finally { |
| 10481 | Binder.restoreCallingIdentity(identity); |
| 10482 | } |
| 10483 | } |
| 10484 | |
| 10485 | /** |
| 10486 | * Set the ICC pin lock enabled or disabled. |
| 10487 | * |
| 10488 | * @return an integer representing the status of IccLock enabled or disabled in the following |
| 10489 | * three cases: |
| 10490 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock |
| 10491 | * successfully. |
| 10492 | * - Positive number and zero for remaining password attempts. |
| 10493 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
| 10494 | * |
| 10495 | */ |
| 10496 | @Override |
| 10497 | public int setIccLockEnabled(int subId, boolean enabled, String password) { |
| 10498 | enforceModifyPermission(); |
| 10499 | |
| 10500 | Phone phone = getPhone(subId); |
| 10501 | if (phone == null) { |
| 10502 | return 0; |
| 10503 | } |
| 10504 | // Now that all security checks passes, perform the operation as ourselves. |
| 10505 | final long identity = Binder.clearCallingIdentity(); |
| 10506 | try { |
| 10507 | int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED, |
| 10508 | new Pair<Boolean, String>(enabled, password), phone, null); |
| 10509 | return attemptsRemaining; |
| 10510 | |
| 10511 | } catch (Exception e) { |
| 10512 | Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e); |
| 10513 | } finally { |
| 10514 | Binder.restoreCallingIdentity(identity); |
| 10515 | } |
| 10516 | return 0; |
| 10517 | } |
| 10518 | |
| 10519 | /** |
| 10520 | * Change the ICC password used in ICC pin lock. |
| 10521 | * |
| 10522 | * @return an integer representing the status of IccLock changed in the following three cases: |
| 10523 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully. |
| 10524 | * - Positive number and zero for remaining password attempts. |
| 10525 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
| 10526 | * |
| 10527 | */ |
| 10528 | @Override |
| 10529 | public int changeIccLockPassword(int subId, String oldPassword, String newPassword) { |
| 10530 | enforceModifyPermission(); |
| 10531 | |
| 10532 | Phone phone = getPhone(subId); |
| 10533 | if (phone == null) { |
| 10534 | return 0; |
| 10535 | } |
| 10536 | // Now that all security checks passes, perform the operation as ourselves. |
| 10537 | final long identity = Binder.clearCallingIdentity(); |
| 10538 | try { |
| 10539 | int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD, |
| 10540 | new Pair<String, String>(oldPassword, newPassword), phone, null); |
| 10541 | return attemptsRemaining; |
| 10542 | |
| 10543 | } catch (Exception e) { |
| 10544 | Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e); |
| 10545 | } finally { |
| 10546 | Binder.restoreCallingIdentity(identity); |
| 10547 | } |
| 10548 | return 0; |
| 10549 | } |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 10550 | |
| 10551 | /** |
| 10552 | * Request for receiving user activity notification |
| 10553 | */ |
| 10554 | @Override |
| 10555 | public void requestUserActivityNotification() { |
| 10556 | if (!mNotifyUserActivity.get() |
| 10557 | && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) { |
| 10558 | mNotifyUserActivity.set(true); |
| 10559 | } |
| 10560 | } |
| 10561 | |
| 10562 | /** |
| 10563 | * Called when userActivity is signalled in the power manager. |
| 10564 | * This is safe to call from any thread, with any window manager locks held or not. |
| 10565 | */ |
| 10566 | @Override |
| 10567 | public void userActivity() { |
| 10568 | // *************************************** |
| 10569 | // * Inherited from PhoneWindowManager * |
| 10570 | // *************************************** |
| 10571 | // THIS IS CALLED FROM DEEP IN THE POWER MANAGER |
| 10572 | // WITH ITS LOCKS HELD. |
| 10573 | // |
| 10574 | // This code must be VERY careful about the locks |
| 10575 | // it acquires. |
| 10576 | // In fact, the current code acquires way too many, |
| 10577 | // and probably has lurking deadlocks. |
| 10578 | |
| 10579 | if (Binder.getCallingUid() != Process.SYSTEM_UID) { |
| 10580 | throw new SecurityException("Only the OS may call notifyUserActivity()"); |
| 10581 | } |
| 10582 | |
| 10583 | if (mNotifyUserActivity.getAndSet(false)) { |
| 10584 | mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY, |
| 10585 | USER_ACTIVITY_NOTIFICATION_DELAY); |
| 10586 | } |
| 10587 | } |
Malcolm Chen | 4639c56 | 2020-04-13 11:59:40 -0700 | [diff] [blame] | 10588 | |
| 10589 | @Override |
| 10590 | public boolean canConnectTo5GInDsdsMode() { |
| 10591 | return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode); |
| 10592 | } |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 10593 | |
| 10594 | @Override |
| 10595 | public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage, |
| 10596 | String callingFeatureId) { |
| 10597 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 10598 | mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) { |
| 10599 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 10600 | } |
| 10601 | |
| 10602 | Phone phone = getPhone(subId); |
| 10603 | if (phone == null) { |
| 10604 | throw new RuntimeException("phone is not available"); |
| 10605 | } |
| 10606 | // Now that all security checks passes, perform the operation as ourselves. |
| 10607 | final long identity = Binder.clearCallingIdentity(); |
| 10608 | try { |
| 10609 | return phone.getEquivalentHomePlmns(); |
| 10610 | } finally { |
| 10611 | Binder.restoreCallingIdentity(identity); |
| 10612 | } |
| 10613 | } |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 10614 | |
| 10615 | @Override |
| 10616 | public boolean isRadioInterfaceCapabilitySupported( |
Daniel Bright | 95a4c1f | 2021-02-11 09:57:16 -0800 | [diff] [blame] | 10617 | final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) { |
| 10618 | Set<String> radioInterfaceCapabilities = |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 10619 | mRadioInterfaceCapabilities.getCapabilities(); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 10620 | if (radioInterfaceCapabilities == null) { |
| 10621 | throw new RuntimeException("radio interface capabilities are not available"); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 10622 | } |
Daniel Bright | 95a4c1f | 2021-02-11 09:57:16 -0800 | [diff] [blame] | 10623 | return radioInterfaceCapabilities.contains(capability); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 10624 | } |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10625 | |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 10626 | @Override |
| 10627 | public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl, |
| 10628 | UaSecurityProtocolIdentifier securityProtocol, |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10629 | boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) { |
| 10630 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 10631 | Binder.getCallingUid(), "bootstrapAuthenticationRequest", |
| 10632 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 10633 | Manifest.permission.MODIFY_PHONE_STATE); |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 10634 | if (DBG) { |
| 10635 | log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:" |
| 10636 | + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol |
| 10637 | + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback); |
| 10638 | } |
| 10639 | |
| 10640 | if (!SubscriptionManager.isValidSubscriptionId(subId) |
| 10641 | || appType < TelephonyManager.APPTYPE_UNKNOWN |
| 10642 | || appType > TelephonyManager.APPTYPE_ISIM |
| 10643 | || nafUrl == null || securityProtocol == null || callback == null) { |
| 10644 | Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters"); |
| 10645 | if (callback != null) { |
| 10646 | try { |
| 10647 | callback.onAuthenticationFailure( |
| 10648 | 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED); |
| 10649 | } catch (RemoteException exception) { |
| 10650 | log("Fail to notify onAuthenticationFailure due to " + exception); |
| 10651 | } |
| 10652 | return; |
| 10653 | } |
| 10654 | } |
| 10655 | |
| 10656 | final long token = Binder.clearCallingIdentity(); |
| 10657 | try { |
| 10658 | getGbaManager(subId).bootstrapAuthenticationRequest( |
| 10659 | new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(), |
| 10660 | forceBootStrapping, callback)); |
| 10661 | } finally { |
| 10662 | Binder.restoreCallingIdentity(token); |
| 10663 | } |
| 10664 | } |
| 10665 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10666 | /** |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10667 | * Attempts to set the radio power state for all phones for thermal reason. |
| 10668 | * This does not guarantee that the |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10669 | * requested radio power state will actually be set. See {@link |
| 10670 | * PhoneInternalInterface#setRadioPowerForReason} for more details. |
| 10671 | * |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10672 | * @param enable {@code true} if trying to turn radio on. |
| 10673 | * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code |
| 10674 | * false}. |
| 10675 | */ |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10676 | private boolean setRadioPowerForThermal(boolean enable) { |
| 10677 | boolean isPhoneAvailable = false; |
| 10678 | for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) { |
| 10679 | Phone phone = PhoneFactory.getPhone(i); |
| 10680 | if (phone != null) { |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 10681 | phone.setRadioPowerForReason(enable, TelephonyManager.RADIO_POWER_REASON_THERMAL); |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10682 | isPhoneAvailable = true; |
| 10683 | } |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10684 | } |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10685 | |
| 10686 | // return true if successfully informed the phone object about the thermal radio power |
| 10687 | // request. |
| 10688 | return isPhoneAvailable; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10689 | } |
| 10690 | |
| 10691 | private int handleDataThrottlingRequest(int subId, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 10692 | DataThrottlingRequest dataThrottlingRequest, String callingPackage) { |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10693 | boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported( |
| 10694 | TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING); |
| 10695 | if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction() |
| 10696 | != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) { |
| 10697 | throw new IllegalArgumentException("modem does not support data throttling"); |
| 10698 | } |
| 10699 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10700 | // Ensure that radio is on. If not able to power on due to phone being unavailable, return |
| 10701 | // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10702 | if (!setRadioPowerForThermal(true)) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10703 | return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 10704 | } |
| 10705 | |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 10706 | setDataEnabledForReason( |
| 10707 | subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true, callingPackage); |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10708 | |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10709 | if (isDataThrottlingSupported) { |
| 10710 | int thermalMitigationResult = |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10711 | (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId); |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10712 | if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) { |
| 10713 | throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS"); |
| 10714 | } else if (thermalMitigationResult |
| 10715 | == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) { |
Jack Nudelman | 760d096 | 2021-05-20 13:57:30 -0700 | [diff] [blame] | 10716 | log("Modem likely does not support data throttling on secondary carrier. Data " + |
| 10717 | "throttling action = " + dataThrottlingRequest.getDataThrottlingAction()); |
| 10718 | return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10719 | } |
| 10720 | return thermalMitigationResult; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10721 | } |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10722 | |
| 10723 | return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10724 | } |
| 10725 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10726 | private static List<String> getThermalMitigationAllowlist(Context context) { |
| 10727 | if (sThermalMitigationAllowlistedPackages.isEmpty()) { |
| 10728 | for (String pckg : context.getResources() |
| 10729 | .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) { |
| 10730 | sThermalMitigationAllowlistedPackages.add(pckg); |
| 10731 | } |
| 10732 | } |
| 10733 | |
| 10734 | return sThermalMitigationAllowlistedPackages; |
| 10735 | } |
| 10736 | |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 10737 | private boolean isAnyPhoneInEmergencyState() { |
| 10738 | TelecomManager tm = mApp.getSystemService(TelecomManager.class); |
| 10739 | if (tm.isInEmergencyCall()) { |
| 10740 | Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call"); |
| 10741 | return true; |
| 10742 | } |
| 10743 | for (Phone phone : PhoneFactory.getPhones()) { |
| 10744 | if (phone.isInEmergencySmsMode() || phone.isInEcm()) { |
| 10745 | Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = " |
| 10746 | + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = " |
| 10747 | + phone.isInEcm()); |
| 10748 | return true; |
| 10749 | } |
| 10750 | } |
| 10751 | |
| 10752 | return false; |
| 10753 | } |
| 10754 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10755 | /** |
| 10756 | * Used by shell commands to add an authorized package name for thermal mitigation. |
| 10757 | * @param packageName name of package to be allowlisted |
| 10758 | * @param context |
| 10759 | */ |
| 10760 | static void addPackageToThermalMitigationAllowlist(String packageName, Context context) { |
| 10761 | sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context); |
| 10762 | sThermalMitigationAllowlistedPackages.add(packageName); |
| 10763 | } |
| 10764 | |
| 10765 | /** |
| 10766 | * Used by shell commands to remove an authorized package name for thermal mitigation. |
| 10767 | * @param packageName name of package to remove from allowlist |
| 10768 | * @param context |
| 10769 | */ |
| 10770 | static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) { |
| 10771 | sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context); |
| 10772 | sThermalMitigationAllowlistedPackages.remove(packageName); |
| 10773 | } |
| 10774 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10775 | /** |
| 10776 | * Thermal mitigation request to control functionalities at modem. |
| 10777 | * |
| 10778 | * @param subId the id of the subscription. |
| 10779 | * @param thermalMitigationRequest holds all necessary information to be passed down to modem. |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10780 | * @param callingPackage the package name of the calling package. |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10781 | * |
| 10782 | * @return thermalMitigationResult enum as defined in android.telephony.Annotation. |
| 10783 | */ |
| 10784 | @Override |
| 10785 | @ThermalMitigationResult |
| 10786 | public int sendThermalMitigationRequest( |
| 10787 | int subId, |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10788 | ThermalMitigationRequest thermalMitigationRequest, |
| 10789 | String callingPackage) throws IllegalArgumentException { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10790 | enforceModifyPermission(); |
| 10791 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10792 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 10793 | if (!getThermalMitigationAllowlist(getDefaultPhone().getContext()) |
| 10794 | .contains(callingPackage)) { |
| 10795 | throw new SecurityException("Calling package must be configured in the device config. " |
| 10796 | + "calling package: " + callingPackage); |
| 10797 | } |
| 10798 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10799 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 10800 | final long identity = Binder.clearCallingIdentity(); |
| 10801 | |
| 10802 | int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR; |
| 10803 | try { |
| 10804 | int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction(); |
| 10805 | switch (thermalMitigationAction) { |
| 10806 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING: |
| 10807 | thermalMitigationResult = |
| 10808 | handleDataThrottlingRequest(subId, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 10809 | thermalMitigationRequest.getDataThrottlingRequest(), |
| 10810 | callingPackage); |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10811 | break; |
| 10812 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY: |
| 10813 | if (thermalMitigationRequest.getDataThrottlingRequest() != null) { |
| 10814 | throw new IllegalArgumentException("dataThrottlingRequest must be null for " |
| 10815 | + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY"); |
| 10816 | } |
| 10817 | |
| 10818 | // Ensure that radio is on. If not able to power on due to phone being |
| 10819 | // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10820 | if (!setRadioPowerForThermal(true)) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10821 | thermalMitigationResult = |
| 10822 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 10823 | break; |
| 10824 | } |
| 10825 | |
| 10826 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 10827 | false, callingPackage); |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10828 | thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 10829 | break; |
| 10830 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF: |
| 10831 | if (thermalMitigationRequest.getDataThrottlingRequest() != null) { |
| 10832 | throw new IllegalArgumentException("dataThrottlingRequest must be null for" |
| 10833 | + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF"); |
| 10834 | } |
| 10835 | |
| 10836 | TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null); |
| 10837 | if (registry != null) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10838 | Phone phone = getPhone(subId); |
| 10839 | if (phone == null) { |
| 10840 | thermalMitigationResult = |
| 10841 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 10842 | break; |
| 10843 | } |
| 10844 | |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 10845 | TelephonyConnectionService service = |
| 10846 | registry.getTelephonyConnectionService(); |
Jack Nudelman | b30ac30 | 2021-06-17 15:39:58 -0700 | [diff] [blame] | 10847 | if (service != null && service.isEmergencyCallPending()) { |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 10848 | Log.e(LOG_TAG, "An emergency call is pending"); |
| 10849 | thermalMitigationResult = |
| 10850 | TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE; |
| 10851 | break; |
| 10852 | } else if (isAnyPhoneInEmergencyState()) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10853 | thermalMitigationResult = |
| 10854 | TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE; |
| 10855 | break; |
| 10856 | } |
| 10857 | } else { |
| 10858 | thermalMitigationResult = |
| 10859 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 10860 | break; |
| 10861 | } |
| 10862 | |
| 10863 | // Turn radio off. If not able to power off due to phone being unavailable, |
| 10864 | // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10865 | if (!setRadioPowerForThermal(false)) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10866 | thermalMitigationResult = |
| 10867 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 10868 | break; |
| 10869 | } |
| 10870 | thermalMitigationResult = |
| 10871 | TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 10872 | break; |
| 10873 | default: |
| 10874 | throw new IllegalArgumentException("the requested thermalMitigationAction does " |
| 10875 | + "not exist. Requested action: " + thermalMitigationAction); |
| 10876 | } |
| 10877 | } catch (IllegalArgumentException e) { |
| 10878 | throw e; |
| 10879 | } catch (Exception e) { |
| 10880 | Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e); |
| 10881 | thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 10882 | } finally { |
| 10883 | Binder.restoreCallingIdentity(identity); |
| 10884 | } |
| 10885 | |
| 10886 | if (DBG) { |
| 10887 | log("thermalMitigationRequest returning with thermalMitigationResult: " |
| 10888 | + thermalMitigationResult); |
| 10889 | } |
| 10890 | |
| 10891 | return thermalMitigationResult; |
| 10892 | } |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 10893 | |
| 10894 | /** |
| 10895 | * Set the GbaService Package Name that Telephony will bind to. |
| 10896 | * |
| 10897 | * @param subId The sim that the GbaService is associated with. |
| 10898 | * @param packageName The name of the package to be replaced with. |
| 10899 | * @return true if setting the GbaService to bind to succeeded, false if it did not. |
| 10900 | */ |
| 10901 | @Override |
| 10902 | public boolean setBoundGbaServiceOverride(int subId, String packageName) { |
| 10903 | enforceModifyPermission(); |
| 10904 | |
| 10905 | final long identity = Binder.clearCallingIdentity(); |
| 10906 | try { |
| 10907 | return getGbaManager(subId).overrideServicePackage(packageName); |
| 10908 | } finally { |
| 10909 | Binder.restoreCallingIdentity(identity); |
| 10910 | } |
| 10911 | } |
| 10912 | |
| 10913 | /** |
| 10914 | * Return the package name of the currently bound GbaService. |
| 10915 | * |
| 10916 | * @param subId The sim that the GbaService is associated with. |
| 10917 | * @return the package name of the GbaService configuration, null if GBA is not supported. |
| 10918 | */ |
| 10919 | @Override |
| 10920 | public String getBoundGbaService(int subId) { |
| 10921 | enforceReadPrivilegedPermission("getBoundGbaServicePackage"); |
| 10922 | |
| 10923 | final long identity = Binder.clearCallingIdentity(); |
| 10924 | try { |
| 10925 | return getGbaManager(subId).getServicePackage(); |
| 10926 | } finally { |
| 10927 | Binder.restoreCallingIdentity(identity); |
| 10928 | } |
| 10929 | } |
| 10930 | |
| 10931 | /** |
| 10932 | * Set the release time for telephony to unbind GbaService. |
| 10933 | * |
| 10934 | * @param subId The sim that the GbaService is associated with. |
| 10935 | * @param interval The release time to unbind GbaService by millisecond. |
| 10936 | * @return true if setting the GbaService to bind to succeeded, false if it did not. |
| 10937 | */ |
| 10938 | @Override |
| 10939 | public boolean setGbaReleaseTimeOverride(int subId, int interval) { |
| 10940 | enforceModifyPermission(); |
| 10941 | |
| 10942 | final long identity = Binder.clearCallingIdentity(); |
| 10943 | try { |
| 10944 | return getGbaManager(subId).overrideReleaseTime(interval); |
| 10945 | } finally { |
| 10946 | Binder.restoreCallingIdentity(identity); |
| 10947 | } |
| 10948 | } |
| 10949 | |
| 10950 | /** |
| 10951 | * Return the release time for telephony to unbind GbaService. |
| 10952 | * |
| 10953 | * @param subId The sim that the GbaService is associated with. |
| 10954 | * @return The release time to unbind GbaService by millisecond. |
| 10955 | */ |
| 10956 | @Override |
| 10957 | public int getGbaReleaseTime(int subId) { |
| 10958 | enforceReadPrivilegedPermission("getGbaReleaseTime"); |
| 10959 | |
| 10960 | final long identity = Binder.clearCallingIdentity(); |
| 10961 | try { |
| 10962 | return getGbaManager(subId).getReleaseTime(); |
| 10963 | } finally { |
| 10964 | Binder.restoreCallingIdentity(identity); |
| 10965 | } |
| 10966 | } |
| 10967 | |
| 10968 | private GbaManager getGbaManager(int subId) { |
| 10969 | GbaManager instance = GbaManager.getInstance(subId); |
| 10970 | if (instance == null) { |
| 10971 | String packageName = mApp.getResources().getString(R.string.config_gba_package); |
| 10972 | int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time); |
| 10973 | instance = GbaManager.make(mApp, subId, packageName, releaseTime); |
| 10974 | } |
| 10975 | return instance; |
| 10976 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10977 | |
| 10978 | /** |
| 10979 | * indicate whether the device and the carrier can support |
| 10980 | * RCS VoLTE single registration. |
| 10981 | */ |
| 10982 | @Override |
| 10983 | public boolean isRcsVolteSingleRegistrationCapable(int subId) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10984 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 10985 | Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable", |
| 10986 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 10987 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10988 | |
| 10989 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10990 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10991 | } |
| 10992 | |
| 10993 | final long identity = Binder.clearCallingIdentity(); |
| 10994 | try { |
| 10995 | RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance(); |
| 10996 | if (rpm != null) { |
Hui Wang | 67af90e | 2021-06-04 16:57:15 -0700 | [diff] [blame] | 10997 | Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId); |
| 10998 | if (isCapable != null) { |
| 10999 | return isCapable; |
| 11000 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11001 | } |
Hui Wang | 67af90e | 2021-06-04 16:57:15 -0700 | [diff] [blame] | 11002 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE, |
| 11003 | "service is temporarily unavailable."); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11004 | } finally { |
| 11005 | Binder.restoreCallingIdentity(identity); |
| 11006 | } |
| 11007 | } |
| 11008 | |
| 11009 | /** |
| 11010 | * Register RCS provisioning callback. |
| 11011 | */ |
| 11012 | @Override |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 11013 | public void registerRcsProvisioningCallback(int subId, |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11014 | IRcsConfigCallback callback) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 11015 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 11016 | Binder.getCallingUid(), "registerRcsProvisioningCallback", |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 11017 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 11018 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11019 | |
| 11020 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 11021 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 11022 | } |
| 11023 | if (!isImsAvailableOnDevice()) { |
| 11024 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 11025 | "IMS not available on device."); |
| 11026 | } |
| 11027 | |
| 11028 | final long identity = Binder.clearCallingIdentity(); |
| 11029 | try { |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 11030 | if (!RcsProvisioningMonitor.getInstance() |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 11031 | .registerRcsProvisioningCallback(subId, callback)) { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 11032 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION, |
| 11033 | "Active subscription not found."); |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 11034 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11035 | } finally { |
| 11036 | Binder.restoreCallingIdentity(identity); |
| 11037 | } |
| 11038 | } |
| 11039 | |
| 11040 | /** |
| 11041 | * Unregister RCS provisioning callback. |
| 11042 | */ |
| 11043 | @Override |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 11044 | public void unregisterRcsProvisioningCallback(int subId, |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11045 | IRcsConfigCallback callback) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 11046 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 11047 | Binder.getCallingUid(), "unregisterRcsProvisioningCallback", |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 11048 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 11049 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11050 | |
| 11051 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 11052 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 11053 | } |
| 11054 | if (!isImsAvailableOnDevice()) { |
joonhunshin | 46b49a3 | 2022-12-21 05:33:23 +0000 | [diff] [blame] | 11055 | // operation failed silently |
| 11056 | Rlog.w(LOG_TAG, "IMS not available on device."); |
| 11057 | return; |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11058 | } |
| 11059 | |
| 11060 | final long identity = Binder.clearCallingIdentity(); |
| 11061 | try { |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 11062 | RcsProvisioningMonitor.getInstance() |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 11063 | .unregisterRcsProvisioningCallback(subId, callback); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11064 | } finally { |
| 11065 | Binder.restoreCallingIdentity(identity); |
| 11066 | } |
| 11067 | } |
| 11068 | |
| 11069 | /** |
| 11070 | * trigger RCS reconfiguration. |
| 11071 | */ |
| 11072 | public void triggerRcsReconfiguration(int subId) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 11073 | TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(), |
| 11074 | "triggerRcsReconfiguration", |
| 11075 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11076 | |
| 11077 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 11078 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 11079 | } |
| 11080 | if (!isImsAvailableOnDevice()) { |
joonhunshin | 46b49a3 | 2022-12-21 05:33:23 +0000 | [diff] [blame] | 11081 | // ProvisioningManager can not handle ServiceSpecificException. |
| 11082 | // Throw the IllegalStateException and annotate ProvisioningManager. |
| 11083 | throw new IllegalStateException("IMS not available on device."); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11084 | } |
| 11085 | |
| 11086 | final long identity = Binder.clearCallingIdentity(); |
| 11087 | try { |
| 11088 | RcsProvisioningMonitor.getInstance().requestReconfig(subId); |
| 11089 | } finally { |
| 11090 | Binder.restoreCallingIdentity(identity); |
| 11091 | } |
| 11092 | } |
| 11093 | |
| 11094 | /** |
| 11095 | * Provide the client configuration parameters of the RCS application. |
| 11096 | */ |
| 11097 | public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 11098 | TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(), |
| 11099 | "setRcsClientConfiguration", |
| 11100 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11101 | |
| 11102 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 11103 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 11104 | } |
| 11105 | if (!isImsAvailableOnDevice()) { |
| 11106 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 11107 | "IMS not available on device."); |
| 11108 | } |
| 11109 | |
| 11110 | final long identity = Binder.clearCallingIdentity(); |
| 11111 | |
| 11112 | try { |
| 11113 | IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS); |
| 11114 | if (configBinder == null) { |
| 11115 | Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration"); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 11116 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION, |
| 11117 | "could not find the requested subscription"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11118 | } else { |
| 11119 | configBinder.setRcsClientConfiguration(rcc); |
| 11120 | } |
joonhunshin | 3e15424 | 2021-09-17 06:33:39 +0000 | [diff] [blame] | 11121 | |
| 11122 | RcsStats.getInstance().onRcsClientProvisioningStats(subId, |
| 11123 | RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11124 | } catch (RemoteException e) { |
| 11125 | Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage()); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 11126 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE, |
| 11127 | "service is temporarily unavailable."); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11128 | } finally { |
| 11129 | Binder.restoreCallingIdentity(identity); |
| 11130 | } |
| 11131 | } |
| 11132 | |
| 11133 | /** |
Hui Wang | baaee6a | 2021-02-19 20:45:36 -0800 | [diff] [blame] | 11134 | * Enables or disables the test mode for RCS VoLTE single registration. |
| 11135 | */ |
| 11136 | @Override |
| 11137 | public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) { |
| 11138 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11139 | "setRcsSingleRegistrationTestModeEnabled"); |
| 11140 | |
| 11141 | RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled); |
| 11142 | } |
| 11143 | |
| 11144 | /** |
| 11145 | * Gets the test mode for RCS VoLTE single registration. |
| 11146 | */ |
| 11147 | @Override |
| 11148 | public boolean getRcsSingleRegistrationTestModeEnabled() { |
| 11149 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11150 | "getRcsSingleRegistrationTestModeEnabled"); |
| 11151 | |
| 11152 | return RcsProvisioningMonitor.getInstance().getTestModeEnabled(); |
| 11153 | } |
| 11154 | |
| 11155 | /** |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11156 | * Overrides the config of RCS VoLTE single registration enabled for the device. |
| 11157 | */ |
| 11158 | @Override |
| 11159 | public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) { |
| 11160 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11161 | "setDeviceSingleRegistrationEnabledOverride"); |
| 11162 | enforceModifyPermission(); |
| 11163 | |
| 11164 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 11165 | : Boolean.parseBoolean(enabledStr); |
| 11166 | RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled); |
Brad Ebinger | 49a72b4 | 2021-01-29 00:55:24 +0000 | [diff] [blame] | 11167 | mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11168 | } |
| 11169 | |
| 11170 | /** |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 11171 | * Sends a device to device communication message. Only usable via shell. |
| 11172 | * @param message message to send. |
| 11173 | * @param value message value. |
| 11174 | */ |
| 11175 | @Override |
| 11176 | public void sendDeviceToDeviceMessage(int message, int value) { |
| 11177 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
Tyler Gunn | babbda0 | 2021-02-10 11:05:02 -0800 | [diff] [blame] | 11178 | "sendDeviceToDeviceMessage"); |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 11179 | enforceModifyPermission(); |
| 11180 | |
| 11181 | final long identity = Binder.clearCallingIdentity(); |
| 11182 | try { |
| 11183 | TelephonyConnectionService service = |
| 11184 | TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService(); |
| 11185 | if (service == null) { |
| 11186 | Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call."); |
| 11187 | return; |
| 11188 | } |
| 11189 | service.sendTestDeviceToDeviceMessage(message, value); |
| 11190 | } finally { |
| 11191 | Binder.restoreCallingIdentity(identity); |
| 11192 | } |
| 11193 | } |
| 11194 | |
Tyler Gunn | babbda0 | 2021-02-10 11:05:02 -0800 | [diff] [blame] | 11195 | /** |
| 11196 | * Sets the specified device to device transport active. |
| 11197 | * @param transport The transport to set active. |
| 11198 | */ |
| 11199 | @Override |
| 11200 | public void setActiveDeviceToDeviceTransport(@NonNull String transport) { |
| 11201 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11202 | "setActiveDeviceToDeviceTransport"); |
| 11203 | enforceModifyPermission(); |
| 11204 | |
| 11205 | final long identity = Binder.clearCallingIdentity(); |
| 11206 | try { |
| 11207 | TelephonyConnectionService service = |
| 11208 | TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService(); |
| 11209 | if (service == null) { |
| 11210 | Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call."); |
| 11211 | return; |
| 11212 | } |
| 11213 | service.setActiveDeviceToDeviceTransport(transport); |
| 11214 | } finally { |
| 11215 | Binder.restoreCallingIdentity(identity); |
| 11216 | } |
| 11217 | } |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 11218 | |
Tyler Gunn | d433926 | 2021-05-03 14:46:49 -0700 | [diff] [blame] | 11219 | @Override |
| 11220 | public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) { |
| 11221 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11222 | "setDeviceToDeviceForceEnabled"); |
| 11223 | |
| 11224 | final long identity = Binder.clearCallingIdentity(); |
| 11225 | try { |
| 11226 | Arrays.stream(PhoneFactory.getPhones()).forEach( |
| 11227 | p -> { |
| 11228 | Phone thePhone = p.getImsPhone(); |
| 11229 | if (thePhone != null && thePhone instanceof ImsPhone) { |
| 11230 | ImsPhone imsPhone = (ImsPhone) thePhone; |
| 11231 | CallTracker tracker = imsPhone.getCallTracker(); |
| 11232 | if (tracker != null && tracker instanceof ImsPhoneCallTracker) { |
| 11233 | ImsPhoneCallTracker imsPhoneCallTracker = |
| 11234 | (ImsPhoneCallTracker) tracker; |
| 11235 | imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled); |
| 11236 | } |
| 11237 | } |
| 11238 | } |
| 11239 | ); |
| 11240 | } finally { |
| 11241 | Binder.restoreCallingIdentity(identity); |
| 11242 | } |
| 11243 | } |
| 11244 | |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 11245 | /** |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11246 | * Gets the config of RCS VoLTE single registration enabled for the device. |
| 11247 | */ |
| 11248 | @Override |
| 11249 | public boolean getDeviceSingleRegistrationEnabled() { |
| 11250 | enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled"); |
| 11251 | return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled(); |
| 11252 | } |
| 11253 | |
| 11254 | /** |
| 11255 | * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription. |
| 11256 | */ |
| 11257 | @Override |
| 11258 | public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) { |
| 11259 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11260 | "setCarrierSingleRegistrationEnabledOverride"); |
| 11261 | enforceModifyPermission(); |
| 11262 | |
| 11263 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 11264 | : Boolean.parseBoolean(enabledStr); |
| 11265 | return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled( |
| 11266 | subId, enabled); |
| 11267 | } |
| 11268 | |
| 11269 | /** |
| 11270 | * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription. |
| 11271 | */ |
| 11272 | @Override |
| 11273 | public boolean getCarrierSingleRegistrationEnabled(int subId) { |
| 11274 | enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled"); |
| 11275 | return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId); |
| 11276 | } |
Chiachang Wang | d6d3477 | 2020-12-22 11:38:27 +0800 | [diff] [blame] | 11277 | |
| 11278 | /** |
Hui Wang | b647abe | 2021-02-26 09:33:38 -0800 | [diff] [blame] | 11279 | * Overrides the ims feature validation result |
| 11280 | */ |
| 11281 | @Override |
| 11282 | public boolean setImsFeatureValidationOverride(int subId, String enabledStr) { |
| 11283 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11284 | "setImsFeatureValidationOverride"); |
| 11285 | |
| 11286 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 11287 | : Boolean.parseBoolean(enabledStr); |
| 11288 | return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation( |
| 11289 | subId, enabled); |
| 11290 | } |
| 11291 | |
| 11292 | /** |
| 11293 | * Gets the ims feature validation override value |
| 11294 | */ |
| 11295 | @Override |
| 11296 | public boolean getImsFeatureValidationOverride(int subId) { |
| 11297 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11298 | "getImsFeatureValidationOverride"); |
| 11299 | return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId); |
| 11300 | } |
| 11301 | |
| 11302 | /** |
Chiachang Wang | d6d3477 | 2020-12-22 11:38:27 +0800 | [diff] [blame] | 11303 | * Get the mobile provisioning url that is used to launch a browser to allow users to manage |
| 11304 | * their mobile plan. |
| 11305 | */ |
| 11306 | @Override |
| 11307 | public String getMobileProvisioningUrl() { |
| 11308 | enforceReadPrivilegedPermission("getMobileProvisioningUrl"); |
| 11309 | final long identity = Binder.clearCallingIdentity(); |
| 11310 | try { |
| 11311 | return getDefaultPhone().getMobileProvisioningUrl(); |
| 11312 | } finally { |
| 11313 | Binder.restoreCallingIdentity(identity); |
| 11314 | } |
| 11315 | } |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11316 | |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 11317 | /** |
calvinpan | e4a8a1d | 2021-01-25 13:51:18 +0800 | [diff] [blame] | 11318 | * Get the EAB contact from the EAB database. |
| 11319 | */ |
| 11320 | @Override |
| 11321 | public String getContactFromEab(String contact) { |
| 11322 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab"); |
| 11323 | enforceModifyPermission(); |
| 11324 | final long identity = Binder.clearCallingIdentity(); |
| 11325 | try { |
| 11326 | return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact); |
| 11327 | } finally { |
| 11328 | Binder.restoreCallingIdentity(identity); |
| 11329 | } |
| 11330 | } |
| 11331 | |
| 11332 | /** |
Calvin Pan | a143432 | 2021-07-01 19:27:01 +0800 | [diff] [blame] | 11333 | * Get the EAB capability from the EAB database. |
| 11334 | */ |
| 11335 | @Override |
| 11336 | public String getCapabilityFromEab(String contact) { |
| 11337 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab"); |
| 11338 | enforceModifyPermission(); |
| 11339 | final long identity = Binder.clearCallingIdentity(); |
| 11340 | try { |
| 11341 | return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact); |
| 11342 | } finally { |
| 11343 | Binder.restoreCallingIdentity(identity); |
| 11344 | } |
| 11345 | } |
| 11346 | |
| 11347 | /** |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 11348 | * Remove the EAB contacts from the EAB database. |
| 11349 | */ |
| 11350 | @Override |
| 11351 | public int removeContactFromEab(int subId, String contacts) { |
| 11352 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab"); |
| 11353 | enforceModifyPermission(); |
| 11354 | final long identity = Binder.clearCallingIdentity(); |
| 11355 | try { |
| 11356 | return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext()); |
| 11357 | } finally { |
| 11358 | Binder.restoreCallingIdentity(identity); |
| 11359 | } |
| 11360 | } |
| 11361 | |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11362 | @Override |
James.cf Lin | 4b784aa | 2021-01-31 03:25:15 +0800 | [diff] [blame] | 11363 | public boolean getDeviceUceEnabled() { |
| 11364 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled"); |
| 11365 | final long identity = Binder.clearCallingIdentity(); |
| 11366 | try { |
| 11367 | return mApp.getDeviceUceEnabled(); |
| 11368 | } finally { |
| 11369 | Binder.restoreCallingIdentity(identity); |
| 11370 | } |
| 11371 | } |
| 11372 | |
| 11373 | @Override |
| 11374 | public void setDeviceUceEnabled(boolean isEnabled) { |
| 11375 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled"); |
| 11376 | final long identity = Binder.clearCallingIdentity(); |
| 11377 | try { |
| 11378 | mApp.setDeviceUceEnabled(isEnabled); |
| 11379 | } finally { |
| 11380 | Binder.restoreCallingIdentity(identity); |
| 11381 | } |
| 11382 | } |
| 11383 | |
Brad Ebinger | 14d467f | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 11384 | /** |
| 11385 | * Add new feature tags to the Set used to calculate the capabilities in PUBLISH. |
| 11386 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 11387 | */ |
| 11388 | // Used for SHELL command only right now. |
| 11389 | @Override |
| 11390 | public RcsContactUceCapability addUceRegistrationOverrideShell(int subId, |
| 11391 | List<String> featureTags) { |
| 11392 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11393 | "addUceRegistrationOverrideShell"); |
| 11394 | final long identity = Binder.clearCallingIdentity(); |
| 11395 | try { |
| 11396 | return mApp.imsRcsController.addUceRegistrationOverrideShell(subId, |
| 11397 | new ArraySet<>(featureTags)); |
| 11398 | } catch (ImsException e) { |
| 11399 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 11400 | } finally { |
| 11401 | Binder.restoreCallingIdentity(identity); |
| 11402 | } |
| 11403 | } |
| 11404 | |
| 11405 | /** |
| 11406 | * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH. |
| 11407 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 11408 | */ |
| 11409 | // Used for SHELL command only right now. |
| 11410 | @Override |
| 11411 | public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId, |
| 11412 | List<String> featureTags) { |
| 11413 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11414 | "removeUceRegistrationOverrideShell"); |
| 11415 | final long identity = Binder.clearCallingIdentity(); |
| 11416 | try { |
| 11417 | return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId, |
| 11418 | new ArraySet<>(featureTags)); |
| 11419 | } catch (ImsException e) { |
| 11420 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 11421 | } finally { |
| 11422 | Binder.restoreCallingIdentity(identity); |
| 11423 | } |
| 11424 | } |
| 11425 | |
| 11426 | /** |
| 11427 | * Clear all overrides in the Set used to calculate the capabilities in PUBLISH. |
| 11428 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 11429 | */ |
| 11430 | // Used for SHELL command only right now. |
| 11431 | @Override |
| 11432 | public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) { |
| 11433 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11434 | "clearUceRegistrationOverrideShell"); |
| 11435 | final long identity = Binder.clearCallingIdentity(); |
| 11436 | try { |
| 11437 | return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId); |
| 11438 | } catch (ImsException e) { |
| 11439 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 11440 | } finally { |
| 11441 | Binder.restoreCallingIdentity(identity); |
| 11442 | } |
| 11443 | } |
| 11444 | |
| 11445 | /** |
| 11446 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 11447 | */ |
| 11448 | // Used for SHELL command only right now. |
| 11449 | @Override |
| 11450 | public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) { |
| 11451 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11452 | "getLatestRcsContactUceCapabilityShell"); |
| 11453 | final long identity = Binder.clearCallingIdentity(); |
| 11454 | try { |
| 11455 | return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId); |
| 11456 | } catch (ImsException e) { |
| 11457 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 11458 | } finally { |
| 11459 | Binder.restoreCallingIdentity(identity); |
| 11460 | } |
| 11461 | } |
| 11462 | |
| 11463 | /** |
| 11464 | * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the |
| 11465 | * device does not have an active PUBLISH. |
| 11466 | */ |
| 11467 | // Used for SHELL command only right now. |
| 11468 | @Override |
| 11469 | public String getLastUcePidfXmlShell(int subId) { |
| 11470 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml"); |
| 11471 | final long identity = Binder.clearCallingIdentity(); |
| 11472 | try { |
| 11473 | return mApp.imsRcsController.getLastUcePidfXmlShell(subId); |
| 11474 | } catch (ImsException e) { |
| 11475 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 11476 | } finally { |
| 11477 | Binder.restoreCallingIdentity(identity); |
| 11478 | } |
| 11479 | } |
| 11480 | |
James.cf Lin | e8713a4 | 2021-04-29 16:04:26 +0800 | [diff] [blame] | 11481 | /** |
| 11482 | * Remove UCE requests cannot be sent to the network status. |
| 11483 | */ |
| 11484 | // Used for SHELL command only right now. |
| 11485 | @Override |
| 11486 | public boolean removeUceRequestDisallowedStatus(int subId) { |
| 11487 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus"); |
| 11488 | final long identity = Binder.clearCallingIdentity(); |
| 11489 | try { |
| 11490 | return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId); |
| 11491 | } catch (ImsException e) { |
| 11492 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 11493 | } finally { |
| 11494 | Binder.restoreCallingIdentity(identity); |
| 11495 | } |
| 11496 | } |
| 11497 | |
James.cf Lin | 18bb900 | 2021-05-25 01:37:38 +0800 | [diff] [blame] | 11498 | /** |
| 11499 | * Remove UCE requests cannot be sent to the network status. |
| 11500 | */ |
| 11501 | // Used for SHELL command only. |
| 11502 | @Override |
| 11503 | public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) { |
| 11504 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout"); |
| 11505 | final long identity = Binder.clearCallingIdentity(); |
| 11506 | try { |
| 11507 | return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs); |
| 11508 | } catch (ImsException e) { |
| 11509 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 11510 | } finally { |
| 11511 | Binder.restoreCallingIdentity(identity); |
| 11512 | } |
| 11513 | } |
Brad Ebinger | 14d467f | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 11514 | |
James.cf Lin | 4b784aa | 2021-01-31 03:25:15 +0800 | [diff] [blame] | 11515 | @Override |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11516 | public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request, |
| 11517 | String callingPackage) { |
| 11518 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 11519 | mApp, subId, "setSignalStrengthUpdateRequest"); |
| 11520 | |
| 11521 | final int callingUid = Binder.getCallingUid(); |
| 11522 | // Verify that tha callingPackage belongs to the calling UID |
| 11523 | mApp.getSystemService(AppOpsManager.class) |
| 11524 | .checkPackage(callingUid, callingPackage); |
| 11525 | |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 11526 | validateSignalStrengthUpdateRequest(mApp, request, callingUid); |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11527 | |
| 11528 | final long identity = Binder.clearCallingIdentity(); |
| 11529 | try { |
| 11530 | Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST, |
| 11531 | new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId); |
| 11532 | |
| 11533 | if (result instanceof IllegalStateException) { |
| 11534 | throw (IllegalStateException) result; |
| 11535 | } |
| 11536 | } finally { |
| 11537 | Binder.restoreCallingIdentity(identity); |
| 11538 | } |
| 11539 | } |
| 11540 | |
| 11541 | @Override |
| 11542 | public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request, |
| 11543 | String callingPackage) { |
| 11544 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 11545 | mApp, subId, "clearSignalStrengthUpdateRequest"); |
| 11546 | |
| 11547 | final int callingUid = Binder.getCallingUid(); |
| 11548 | // Verify that tha callingPackage belongs to the calling UID |
| 11549 | mApp.getSystemService(AppOpsManager.class) |
| 11550 | .checkPackage(callingUid, callingPackage); |
| 11551 | |
| 11552 | final long identity = Binder.clearCallingIdentity(); |
| 11553 | try { |
| 11554 | Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST, |
| 11555 | new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId); |
| 11556 | |
| 11557 | if (result instanceof IllegalStateException) { |
| 11558 | throw (IllegalStateException) result; |
| 11559 | } |
| 11560 | } finally { |
| 11561 | Binder.restoreCallingIdentity(identity); |
| 11562 | } |
| 11563 | } |
| 11564 | |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 11565 | private static void validateSignalStrengthUpdateRequest(Context context, |
| 11566 | SignalStrengthUpdateRequest request, int callingUid) { |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11567 | if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) { |
| 11568 | // phone/system process do not have further restriction on request |
| 11569 | return; |
| 11570 | } |
| 11571 | |
| 11572 | // Applications has restrictions on how to use the request: |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 11573 | // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11574 | if (request.isSystemThresholdReportingRequestedWhileIdle()) { |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 11575 | context.enforceCallingOrSelfPermission( |
| 11576 | android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH, |
| 11577 | "validateSignalStrengthUpdateRequest"); |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11578 | } |
| 11579 | |
| 11580 | for (SignalThresholdInfo info : request.getSignalThresholdInfos()) { |
Nagendra Prasad Nagarle Basavaraju | fee544c | 2022-12-07 16:34:52 +0000 | [diff] [blame] | 11581 | // Only system caller can set mHysteresisMs/mIsEnabled. |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11582 | if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11583 | || info.isEnabled()) { |
| 11584 | throw new IllegalArgumentException( |
| 11585 | "Only system can set hide fields in SignalThresholdInfo"); |
| 11586 | } |
| 11587 | |
| 11588 | // Thresholds length for each RAN need in range. This has been validated in |
| 11589 | // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method |
| 11590 | // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds |
| 11591 | final int[] thresholds = info.getThresholds(); |
| 11592 | Objects.requireNonNull(thresholds); |
| 11593 | if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed() |
| 11594 | || thresholds.length |
| 11595 | > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) { |
| 11596 | throw new IllegalArgumentException( |
| 11597 | "thresholds length is out of range: " + thresholds.length); |
| 11598 | } |
| 11599 | } |
| 11600 | } |
SongFerngWang | 8236caa | 2021-01-17 21:51:44 +0800 | [diff] [blame] | 11601 | |
| 11602 | /** |
| 11603 | * Gets the current phone capability. |
| 11604 | * |
| 11605 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 11606 | * @return the PhoneCapability which describes the data connection capability of modem. |
| 11607 | * It's used to evaluate possible phone config change, for example from single |
| 11608 | * SIM device to multi-SIM device. |
| 11609 | */ |
| 11610 | @Override |
| 11611 | public PhoneCapability getPhoneCapability() { |
| 11612 | enforceReadPrivilegedPermission("getPhoneCapability"); |
| 11613 | final long identity = Binder.clearCallingIdentity(); |
| 11614 | try { |
| 11615 | return mPhoneConfigurationManager.getCurrentPhoneCapability(); |
| 11616 | } finally { |
| 11617 | Binder.restoreCallingIdentity(identity); |
| 11618 | } |
| 11619 | } |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 11620 | |
| 11621 | /** |
| 11622 | * Prepare TelephonyManager for an unattended reboot. The reboot is |
| 11623 | * required to be done shortly after the API is invoked. |
| 11624 | */ |
| 11625 | @Override |
| 11626 | @TelephonyManager.PrepareUnattendedRebootResult |
| 11627 | public int prepareForUnattendedReboot() { |
Rafael Higuera Silva | d963064 | 2021-09-20 15:32:01 +0000 | [diff] [blame] | 11628 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 11629 | enforceRebootPermission(); |
| 11630 | |
| 11631 | final long identity = Binder.clearCallingIdentity(); |
| 11632 | try { |
Rafael Higuera Silva | d963064 | 2021-09-20 15:32:01 +0000 | [diff] [blame] | 11633 | return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 11634 | } finally { |
| 11635 | Binder.restoreCallingIdentity(identity); |
| 11636 | } |
| 11637 | } |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 11638 | |
| 11639 | /** |
| 11640 | * Request to get the current slicing configuration including URSP rules and |
| 11641 | * NSSAIs (configured, allowed and rejected). |
| 11642 | * |
| 11643 | * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission. |
| 11644 | */ |
| 11645 | @Override |
| 11646 | public void getSlicingConfig(ResultReceiver callback) { |
Hongbo Zeng | 1b2063d | 2022-02-21 01:33:03 +0000 | [diff] [blame] | 11647 | TelephonyPermissions |
| 11648 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 11649 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, "getSlicingConfig"); |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 11650 | |
| 11651 | final long identity = Binder.clearCallingIdentity(); |
| 11652 | try { |
| 11653 | Phone phone = getDefaultPhone(); |
| 11654 | sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null); |
| 11655 | } finally { |
| 11656 | Binder.restoreCallingIdentity(identity); |
| 11657 | } |
| 11658 | } |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 11659 | |
| 11660 | /** |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 11661 | * Check whether the given premium capability is available for purchase from the carrier. |
| 11662 | * |
| 11663 | * @param capability The premium capability to check. |
| 11664 | * @param subId The subId to check the premium capability for. |
| 11665 | * |
| 11666 | * @return Whether the given premium capability is available to purchase. |
| 11667 | */ |
| 11668 | @Override |
| 11669 | public boolean isPremiumCapabilityAvailableForPurchase(int capability, int subId) { |
| 11670 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 11671 | mApp, "isPremiumCapabilityAvailableForPurchase")) { |
| 11672 | log("Premium capability " |
| 11673 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 11674 | + " is not available for purchase due to missing permissions."); |
| 11675 | throw new SecurityException("isPremiumCapabilityAvailableForPurchase requires " |
| 11676 | + "permission READ_BASIC_PHONE_STATE."); |
| 11677 | } |
| 11678 | |
| 11679 | Phone phone = getPhone(subId); |
Thomas Nguyen | 7216ed6 | 2022-11-29 16:45:31 -0800 | [diff] [blame] | 11680 | if (phone == null) { |
| 11681 | loge("isPremiumCapabilityAvailableForPurchase: phone is null, subId=" + subId); |
| 11682 | return false; |
| 11683 | } |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 11684 | final long identity = Binder.clearCallingIdentity(); |
| 11685 | try { |
Sarah Chin | 46355ba | 2022-11-01 23:51:16 -0700 | [diff] [blame] | 11686 | return SlicePurchaseController.getInstance(phone) |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 11687 | .isPremiumCapabilityAvailableForPurchase(capability); |
| 11688 | } finally { |
| 11689 | Binder.restoreCallingIdentity(identity); |
| 11690 | } |
| 11691 | } |
| 11692 | |
| 11693 | /** |
| 11694 | * Purchase the given premium capability from the carrier. |
| 11695 | * |
| 11696 | * @param capability The premium capability to purchase. |
| 11697 | * @param callback The result of the purchase request. |
| 11698 | * @param subId The subId to purchase the premium capability for. |
| 11699 | */ |
| 11700 | @Override |
| 11701 | public void purchasePremiumCapability(int capability, IIntegerConsumer callback, int subId) { |
| 11702 | log("purchasePremiumCapability: capability=" |
| 11703 | + TelephonyManager.convertPremiumCapabilityToString(capability) + ", caller=" |
| 11704 | + getCurrentPackageName()); |
| 11705 | |
| 11706 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 11707 | mApp, "purchasePremiumCapability")) { |
| 11708 | log("purchasePremiumCapability " |
| 11709 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 11710 | + " failed due to missing permissions."); |
| 11711 | throw new SecurityException("purchasePremiumCapability requires permission " |
| 11712 | + "READ_BASIC_PHONE_STATE."); |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 11713 | } else if (!TelephonyPermissions.checkInternetPermissionNoThrow( |
| 11714 | mApp, "purchasePremiumCapability")) { |
| 11715 | log("purchasePremiumCapability " |
| 11716 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 11717 | + " failed due to missing permissions."); |
| 11718 | throw new SecurityException("purchasePremiumCapability requires permission INTERNET."); |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 11719 | } |
| 11720 | |
| 11721 | Phone phone = getPhone(subId); |
Sarah Chin | 1969411 | 2022-12-06 15:41:37 -0800 | [diff] [blame] | 11722 | if (phone == null) { |
| 11723 | try { |
| 11724 | int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_REQUEST_FAILED; |
| 11725 | callback.accept(result); |
| 11726 | loge("purchasePremiumCapability: phone is null, subId=" + subId); |
| 11727 | } catch (RemoteException e) { |
| 11728 | String logStr = "Purchase premium capability " |
| 11729 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 11730 | + " failed due to RemoteException handling null phone: " + e; |
| 11731 | if (DBG) log(logStr); |
| 11732 | AnomalyReporter.reportAnomaly( |
| 11733 | UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr); |
| 11734 | } |
| 11735 | return; |
| 11736 | } |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 11737 | |
| 11738 | String callingProcess; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 11739 | try { |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 11740 | callingProcess = mApp.getPackageManager().getApplicationInfo( |
| 11741 | getCurrentPackageName(), 0).processName; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 11742 | } catch (PackageManager.NameNotFoundException e) { |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 11743 | callingProcess = getCurrentPackageName(); |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 11744 | } |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 11745 | |
| 11746 | boolean isVisible = false; |
| 11747 | ActivityManager am = mApp.getSystemService(ActivityManager.class); |
| 11748 | if (am != null) { |
| 11749 | List<ActivityManager.RunningAppProcessInfo> processes = am.getRunningAppProcesses(); |
| 11750 | if (processes != null) { |
| 11751 | for (ActivityManager.RunningAppProcessInfo process : processes) { |
| 11752 | log("purchasePremiumCapability: process " + process.processName |
| 11753 | + "has importance " + process.importance); |
| 11754 | if (process.processName.equals(callingProcess) && process.importance |
| 11755 | <= ActivityManager.RunningAppProcessInfo.IMPORTANCE_VISIBLE) { |
| 11756 | isVisible = true; |
| 11757 | break; |
| 11758 | } |
| 11759 | } |
| 11760 | } |
| 11761 | } |
| 11762 | |
| 11763 | if (!isVisible) { |
| 11764 | try { |
| 11765 | int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_NOT_FOREGROUND; |
| 11766 | callback.accept(result); |
| 11767 | loge("purchasePremiumCapability: " + callingProcess + " is not in the foreground."); |
| 11768 | } catch (RemoteException e) { |
| 11769 | String logStr = "Purchase premium capability " |
| 11770 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 11771 | + " failed due to RemoteException handling background application: " + e; |
| 11772 | if (DBG) log(logStr); |
| 11773 | AnomalyReporter.reportAnomaly( |
| 11774 | UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr); |
| 11775 | } |
| 11776 | return; |
| 11777 | } |
| 11778 | |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 11779 | sendRequestAsync(CMD_PURCHASE_PREMIUM_CAPABILITY, |
Sarah Chin | b8218c2 | 2023-01-04 13:35:29 -0800 | [diff] [blame] | 11780 | new PurchasePremiumCapabilityArgument(capability, callback), phone, null); |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 11781 | } |
| 11782 | |
| 11783 | /** |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 11784 | * Register an IMS connection state callback |
| 11785 | */ |
| 11786 | @Override |
Hunsuk Choi | 89bd22c | 2021-11-01 13:04:54 +0000 | [diff] [blame] | 11787 | public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb, |
| 11788 | String callingPackage) { |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 11789 | if (feature == ImsFeature.FEATURE_MMTEL) { |
| 11790 | // ImsMmTelManager |
| 11791 | // The following also checks READ_PRIVILEGED_PHONE_STATE. |
| 11792 | TelephonyPermissions |
| 11793 | .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 11794 | mApp, subId, "registerImsStateCallback"); |
| 11795 | } else if (feature == ImsFeature.FEATURE_RCS) { |
| 11796 | // ImsRcsManager or SipDelegateManager |
| 11797 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 11798 | Binder.getCallingUid(), "registerImsStateCallback", |
| 11799 | Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
| 11800 | Manifest.permission.READ_PRECISE_PHONE_STATE, |
| 11801 | Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE, |
| 11802 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
| 11803 | } |
| 11804 | |
| 11805 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 11806 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 11807 | "IMS not available on device."); |
| 11808 | } |
| 11809 | |
| 11810 | if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) { |
| 11811 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 11812 | } |
| 11813 | |
| 11814 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 11815 | if (controller == null) { |
| 11816 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 11817 | "IMS not available on device."); |
| 11818 | } |
| 11819 | |
Hunsuk Choi | 89bd22c | 2021-11-01 13:04:54 +0000 | [diff] [blame] | 11820 | if (callingPackage == null) { |
| 11821 | callingPackage = getCurrentPackageName(); |
| 11822 | } |
| 11823 | |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 11824 | final long token = Binder.clearCallingIdentity(); |
| 11825 | try { |
| 11826 | int slotId = getSlotIndexOrException(subId); |
Hunsuk Choi | 89bd22c | 2021-11-01 13:04:54 +0000 | [diff] [blame] | 11827 | controller.registerImsStateCallback(subId, feature, cb, callingPackage); |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 11828 | } catch (ImsException e) { |
| 11829 | throw new ServiceSpecificException(e.getCode()); |
| 11830 | } finally { |
| 11831 | Binder.restoreCallingIdentity(token); |
| 11832 | } |
| 11833 | } |
| 11834 | |
| 11835 | /** |
| 11836 | * Unregister an IMS connection state callback |
| 11837 | */ |
| 11838 | @Override |
| 11839 | public void unregisterImsStateCallback(IImsStateCallback cb) { |
| 11840 | final long token = Binder.clearCallingIdentity(); |
| 11841 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 11842 | if (controller == null) { |
| 11843 | return; |
| 11844 | } |
| 11845 | try { |
| 11846 | controller.unregisterImsStateCallback(cb); |
| 11847 | } finally { |
| 11848 | Binder.restoreCallingIdentity(token); |
| 11849 | } |
| 11850 | } |
Sooraj Sasindran | fae41b3 | 2021-10-26 02:10:05 -0700 | [diff] [blame] | 11851 | |
| 11852 | /** |
| 11853 | * @return {@CellIdentity} last known cell identity {@CellIdentity}. |
| 11854 | * |
| 11855 | * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and |
| 11856 | * com.android.phone.permission.ACCESS_LAST_KNOWN_CELL_ID, otherwise throws |
| 11857 | * SecurityException. |
| 11858 | * If there is current registered network this value will be same as the registered cell |
| 11859 | * identity. If the device goes out of service the previous cell identity is cached and |
| 11860 | * will be returned. If the cache age of the Cell identity is more than 24 hours |
| 11861 | * it will be cleared and null will be returned. |
| 11862 | * |
| 11863 | */ |
| 11864 | @Override |
| 11865 | public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage, |
| 11866 | String callingFeatureId) { |
| 11867 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 11868 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 11869 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 11870 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 11871 | .setCallingPackage(callingPackage) |
| 11872 | .setCallingFeatureId(callingFeatureId) |
| 11873 | .setCallingPid(Binder.getCallingPid()) |
| 11874 | .setCallingUid(Binder.getCallingUid()) |
| 11875 | .setMethod("getLastKnownCellIdentity") |
| 11876 | .setLogAsInfo(true) |
| 11877 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 11878 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 11879 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 11880 | .build()); |
| 11881 | |
| 11882 | boolean hasFinePermission = |
| 11883 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 11884 | if (!hasFinePermission |
| 11885 | || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) { |
| 11886 | throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION " |
Rambo Wang | 918993a | 2022-04-27 09:08:36 -0700 | [diff] [blame] | 11887 | + "and ACCESS_LAST_KNOWN_CELL_ID permission."); |
Sooraj Sasindran | fae41b3 | 2021-10-26 02:10:05 -0700 | [diff] [blame] | 11888 | } |
| 11889 | |
| 11890 | final long identity = Binder.clearCallingIdentity(); |
| 11891 | try { |
| 11892 | Phone phone = getPhone(subId); |
| 11893 | if (phone == null) return null; |
| 11894 | ServiceStateTracker sst = phone.getServiceStateTracker(); |
| 11895 | if (sst == null) return null; |
| 11896 | return sst.getLastKnownCellIdentity(); |
| 11897 | } finally { |
| 11898 | Binder.restoreCallingIdentity(identity); |
| 11899 | } |
| 11900 | } |
Jack Yu | 4c0a550 | 2021-12-03 23:58:26 -0800 | [diff] [blame] | 11901 | |
jimsun | 3b9ccac | 2021-10-26 15:01:23 +0800 | [diff] [blame] | 11902 | /** |
| 11903 | * Sets the modem service class Name that Telephony will bind to. |
| 11904 | * |
| 11905 | * @param serviceName The class name of the modem service. |
| 11906 | * @return true if the operation is succeed, otherwise false. |
| 11907 | */ |
| 11908 | public boolean setModemService(String serviceName) { |
| 11909 | Log.d(LOG_TAG, "setModemService - " + serviceName); |
| 11910 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService"); |
| 11911 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 11912 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 11913 | "setModemService"); |
| 11914 | return mPhoneConfigurationManager.setModemService(serviceName); |
| 11915 | } |
| 11916 | |
| 11917 | /** |
| 11918 | * Return the class name of the currently bounded modem service. |
| 11919 | * |
| 11920 | * @return the class name of the modem service. |
| 11921 | */ |
| 11922 | public String getModemService() { |
| 11923 | String result; |
| 11924 | Log.d(LOG_TAG, "getModemService"); |
| 11925 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService"); |
| 11926 | TelephonyPermissions |
| 11927 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 11928 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 11929 | "getModemService"); |
| 11930 | result = mPhoneConfigurationManager.getModemService(); |
| 11931 | Log.d(LOG_TAG, "result = " + result); |
| 11932 | return result; |
| 11933 | } |
Hunter Knepshield | 2b076fa | 2022-01-19 02:26:22 -0800 | [diff] [blame] | 11934 | |
| 11935 | @Override |
| 11936 | public void setVoiceServiceStateOverride(int subId, boolean hasService, String callingPackage) { |
| 11937 | // Only telecom (and shell, for CTS purposes) is allowed to call this method. |
| 11938 | mApp.enforceCallingOrSelfPermission( |
| 11939 | permission.BIND_TELECOM_CONNECTION_SERVICE, "setVoiceServiceStateOverride"); |
| 11940 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 11941 | |
| 11942 | final long identity = Binder.clearCallingIdentity(); |
| 11943 | try { |
| 11944 | Phone phone = getPhone(subId); |
| 11945 | if (phone == null) return; |
Grant Menke | 63ade12 | 2023-01-20 14:31:54 -0800 | [diff] [blame] | 11946 | Log.i(LOG_TAG, "setVoiceServiceStateOverride: subId=" + subId + ", phone=" + phone |
| 11947 | + ", hasService=" + hasService + ", callingPackage=" + callingPackage); |
Hunter Knepshield | 2b076fa | 2022-01-19 02:26:22 -0800 | [diff] [blame] | 11948 | phone.setVoiceServiceStateOverride(hasService); |
| 11949 | } finally { |
| 11950 | Binder.restoreCallingIdentity(identity); |
| 11951 | } |
| 11952 | } |
Muralidhar Reddy | 4e5a801 | 2022-05-11 14:49:00 +0000 | [diff] [blame] | 11953 | |
| 11954 | /** |
| 11955 | * set removable eSIM as default eUICC. |
| 11956 | * |
| 11957 | * @hide |
| 11958 | */ |
| 11959 | @Override |
| 11960 | public void setRemovableEsimAsDefaultEuicc(boolean isDefault, String callingPackage) { |
| 11961 | enforceModifyPermission(); |
| 11962 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 11963 | |
| 11964 | final long identity = Binder.clearCallingIdentity(); |
| 11965 | try { |
| 11966 | UiccController.getInstance().setRemovableEsimAsDefaultEuicc(isDefault); |
| 11967 | } finally { |
| 11968 | Binder.restoreCallingIdentity(identity); |
| 11969 | } |
| 11970 | } |
| 11971 | |
| 11972 | /** |
| 11973 | * Returns whether the removable eSIM is default eUICC or not. |
| 11974 | * |
| 11975 | * @hide |
| 11976 | */ |
| 11977 | @Override |
| 11978 | public boolean isRemovableEsimDefaultEuicc(String callingPackage) { |
| 11979 | enforceReadPrivilegedPermission("isRemovableEsimDefaultEuicc"); |
| 11980 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 11981 | |
| 11982 | final long identity = Binder.clearCallingIdentity(); |
| 11983 | try { |
| 11984 | return UiccController.getInstance().isRemovableEsimDefaultEuicc(); |
| 11985 | } finally { |
| 11986 | Binder.restoreCallingIdentity(identity); |
| 11987 | } |
| 11988 | } |
| 11989 | |
Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame] | 11990 | /** |
| 11991 | * Get the component name of the default app to direct respond-via-message intent for the |
| 11992 | * user associated with this subscription, update the cache if there is no respond-via-message |
| 11993 | * application currently configured for this user. |
| 11994 | * @return component name of the app and class to direct Respond Via Message intent to, or |
| 11995 | * {@code null} if the functionality is not supported. |
| 11996 | * @hide |
| 11997 | */ |
| 11998 | @Override |
| 11999 | public @Nullable ComponentName getDefaultRespondViaMessageApplication(int subId, |
| 12000 | boolean updateIfNeeded) { |
| 12001 | enforceInteractAcrossUsersPermission("getDefaultRespondViaMessageApplication"); |
Muralidhar Reddy | 4e5a801 | 2022-05-11 14:49:00 +0000 | [diff] [blame] | 12002 | |
Aishwarya Mallampati | 5e581e1 | 2023-01-17 21:57:06 +0000 | [diff] [blame] | 12003 | Context context = getPhoneFromSubIdOrDefault(subId).getContext(); |
| 12004 | |
Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame] | 12005 | UserHandle userHandle = null; |
| 12006 | final long identity = Binder.clearCallingIdentity(); |
| 12007 | try { |
| 12008 | userHandle = TelephonyUtils.getSubscriptionUserHandle(context, subId); |
| 12009 | } finally { |
| 12010 | Binder.restoreCallingIdentity(identity); |
| 12011 | } |
| 12012 | return SmsApplication.getDefaultRespondViaMessageApplicationAsUser(context, |
| 12013 | updateIfNeeded, userHandle); |
| 12014 | } |
Jack Yu | f5badd9 | 2022-12-08 00:50:53 -0800 | [diff] [blame] | 12015 | |
| 12016 | /** |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 12017 | * Set whether the device is able to connect with null ciphering or integrity |
| 12018 | * algorithms. This is a global setting and will apply to all active subscriptions |
| 12019 | * and all new subscriptions after this. |
| 12020 | * |
| 12021 | * @param enabled when true, null cipher and integrity algorithms are allowed. |
| 12022 | * @hide |
| 12023 | */ |
| 12024 | @Override |
| 12025 | @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 12026 | public void setNullCipherAndIntegrityEnabled(boolean enabled) { |
| 12027 | enforceModifyPermission(); |
| 12028 | checkForNullCipherAndIntegritySupport(); |
| 12029 | |
| 12030 | // Persist the state of our preference. Each GsmCdmaPhone instance is responsible |
| 12031 | // for listening to these preference changes and applying them immediately. |
| 12032 | SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 12033 | editor.putBoolean(Phone.PREF_NULL_CIPHER_AND_INTEGRITY_ENABLED, enabled); |
| 12034 | editor.apply(); |
| 12035 | |
| 12036 | for (Phone phone: PhoneFactory.getPhones()) { |
| 12037 | phone.handleNullCipherEnabledChange(); |
| 12038 | } |
| 12039 | } |
| 12040 | |
| 12041 | |
| 12042 | /** |
| 12043 | * Get whether the device is able to connect with null ciphering or integrity |
| 12044 | * algorithms. Note that this retrieves the phone-global preference and not |
| 12045 | * the state of the radio. |
| 12046 | * |
| 12047 | * @throws SecurityException if {@link permission#MODIFY_PHONE_STATE} is not satisfied |
| 12048 | * @throws UnsupportedOperationException if the device does not support the minimum HAL |
| 12049 | * version for this feature. |
| 12050 | * @hide |
| 12051 | */ |
| 12052 | @Override |
| 12053 | @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) |
| 12054 | public boolean isNullCipherAndIntegrityPreferenceEnabled() { |
| 12055 | enforceReadPermission(); |
| 12056 | checkForNullCipherAndIntegritySupport(); |
| 12057 | return getDefaultPhone().getNullCipherAndIntegrityEnabledPreference(); |
| 12058 | } |
| 12059 | |
| 12060 | private void checkForNullCipherAndIntegritySupport() { |
| 12061 | if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_NULL_CIPHER_AND_INTEGRITY_VERSION) { |
| 12062 | throw new UnsupportedOperationException( |
| 12063 | "Null cipher and integrity operations require HAL 2.1 or above"); |
| 12064 | } |
Gil Cukierman | 92cc7db | 2023-01-06 19:25:53 +0000 | [diff] [blame] | 12065 | if (!getDefaultPhone().isNullCipherAndIntegritySupported()) { |
| 12066 | throw new UnsupportedOperationException( |
| 12067 | "Null cipher and integrity operations unsupported by modem"); |
| 12068 | } |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 12069 | } |
| 12070 | |
| 12071 | /** |
Jack Yu | f5badd9 | 2022-12-08 00:50:53 -0800 | [diff] [blame] | 12072 | * Get the SIM state for the slot index. |
| 12073 | * For Remote-SIMs, this method returns {@link IccCardConstants.State#UNKNOWN} |
| 12074 | * |
| 12075 | * @return SIM state as the ordinal of {@link IccCardConstants.State} |
| 12076 | */ |
| 12077 | @Override |
| 12078 | @SimState |
| 12079 | public int getSimStateForSlotIndex(int slotIndex) { |
| 12080 | IccCardConstants.State simState; |
| 12081 | if (slotIndex < 0) { |
| 12082 | simState = IccCardConstants.State.UNKNOWN; |
| 12083 | } else { |
| 12084 | Phone phone = null; |
| 12085 | try { |
| 12086 | phone = PhoneFactory.getPhone(slotIndex); |
| 12087 | } catch (IllegalStateException e) { |
| 12088 | // ignore |
| 12089 | } |
| 12090 | if (phone == null) { |
| 12091 | simState = IccCardConstants.State.UNKNOWN; |
| 12092 | } else { |
| 12093 | IccCard icc = phone.getIccCard(); |
| 12094 | if (icc == null) { |
| 12095 | simState = IccCardConstants.State.UNKNOWN; |
| 12096 | } else { |
| 12097 | simState = icc.getState(); |
| 12098 | } |
| 12099 | } |
| 12100 | } |
| 12101 | return simState.ordinal(); |
| 12102 | } |
Hui Wang | 9b5793a | 2022-12-05 14:38:06 -0600 | [diff] [blame] | 12103 | |
| 12104 | /** |
| 12105 | * Get current cell broadcast ranges. |
| 12106 | */ |
| 12107 | @Override |
| 12108 | @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS) |
| 12109 | public List<CellBroadcastIdRange> getCellBroadcastIdRanges(int subId) { |
| 12110 | mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS, |
| 12111 | "getCellBroadcastIdRanges"); |
| 12112 | final long identity = Binder.clearCallingIdentity(); |
| 12113 | try { |
| 12114 | return getPhone(subId).getCellBroadcastIdRanges(); |
| 12115 | } finally { |
| 12116 | Binder.restoreCallingIdentity(identity); |
| 12117 | } |
| 12118 | } |
| 12119 | |
| 12120 | /** |
| 12121 | * Set reception of cell broadcast messages with the list of the given ranges |
| 12122 | * |
| 12123 | * @param ranges the list of {@link CellBroadcastIdRange} to be enabled |
| 12124 | */ |
| 12125 | @Override |
| 12126 | @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS) |
| 12127 | public void setCellBroadcastIdRanges(int subId, @NonNull List<CellBroadcastIdRange> ranges, |
| 12128 | @Nullable IIntegerConsumer callback) { |
| 12129 | mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS, |
| 12130 | "setCellBroadcastIdRanges"); |
| 12131 | final long identity = Binder.clearCallingIdentity(); |
| 12132 | try { |
| 12133 | Phone phone = getPhoneFromSubId(subId); |
| 12134 | if (DBG) { |
| 12135 | log("setCellBroadcastIdRanges for subId :" + subId + ", phone:" + phone); |
| 12136 | } |
| 12137 | phone.setCellBroadcastIdRanges(ranges, result -> { |
| 12138 | if (callback != null) { |
| 12139 | try { |
| 12140 | callback.accept(result); |
| 12141 | } catch (RemoteException e) { |
| 12142 | Log.w(LOG_TAG, "setCellBroadcastIdRanges: callback not available."); |
| 12143 | } |
| 12144 | } |
| 12145 | }); |
| 12146 | } finally { |
| 12147 | Binder.restoreCallingIdentity(identity); |
| 12148 | } |
| 12149 | } |
Hunsuk Choi | 42cc62a | 2022-10-16 06:03:40 +0000 | [diff] [blame] | 12150 | |
| 12151 | /** |
| 12152 | * Returns whether the device supports the domain selection service. |
| 12153 | * |
| 12154 | * @return {@code true} if the device supports the domain selection service. |
| 12155 | */ |
| 12156 | @Override |
| 12157 | public boolean isDomainSelectionSupported() { |
| 12158 | mApp.enforceCallingOrSelfPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
| 12159 | "isDomainSelectionSupported"); |
| 12160 | |
| 12161 | final long identity = Binder.clearCallingIdentity(); |
| 12162 | try { |
| 12163 | return DomainSelectionResolver.getInstance().isDomainSelectionSupported(); |
| 12164 | } finally { |
| 12165 | Binder.restoreCallingIdentity(identity); |
| 12166 | } |
| 12167 | } |
arunvoddu | d5c6ce0 | 2022-12-11 06:03:12 +0000 | [diff] [blame] | 12168 | |
| 12169 | /** |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 12170 | * Start receiving satellite position updates. |
| 12171 | * This can be called by the pointing UI when the user starts pointing to the satellite. |
| 12172 | * Modem should continue to report the pointing input as the device or satellite moves. |
| 12173 | * |
| 12174 | * @param subId The subId to start satellite position updates for. |
| 12175 | * @param callbackId The callback ID associating the public SatellitePositionUpdateCallback to |
| 12176 | * the internal ISatellitePositionUpdateCallback below. |
| 12177 | * @param callback The callback to notify of changes in satellite position. |
| 12178 | * @return The result of the operation. |
| 12179 | */ |
| 12180 | @Override |
| 12181 | @SatelliteManager.SatelliteServiceResult public int startSatellitePositionUpdates(int subId, |
| 12182 | int callbackId, @NonNull ISatellitePositionUpdateCallback callback) { |
| 12183 | // TODO: check for SATELLITE_COMMUNICATION permission |
| 12184 | Phone phone = getPhone(subId); |
| 12185 | if (phone == null) { |
| 12186 | loge("startSatellitePositionUpdates called with invalid subId: " + subId |
| 12187 | + ". Retrying with default phone."); |
| 12188 | phone = getDefaultPhone(); |
| 12189 | if (phone == null) { |
| 12190 | loge("startSatellitePositionUpdates failed with no phone object."); |
| 12191 | return SatelliteManager.SATELLITE_SERVICE_REQUEST_FAILED; |
| 12192 | } |
| 12193 | } |
| 12194 | |
| 12195 | if (mSatellitePositionUpdateHandlers.containsKey(callbackId)) { |
| 12196 | log("startSatellitePositionUpdates: callback already registered: " + callbackId); |
| 12197 | return SatelliteManager.SATELLITE_SERVICE_SUCCESS; |
| 12198 | } |
| 12199 | |
| 12200 | SatellitePositionUpdateHandler handler = |
| 12201 | new SatellitePositionUpdateHandler(callback, Looper.getMainLooper()); |
| 12202 | phone.registerForSatellitePointingInfoChanged(handler, |
| 12203 | SatellitePositionUpdateHandler.EVENT_POSITION_UPDATE, null); |
| 12204 | phone.registerForSatelliteMessagesTransferComplete(handler, |
| 12205 | SatellitePositionUpdateHandler.EVENT_MESSAGE_TRANSFER_STATE_UPDATE, null); |
| 12206 | mSatellitePositionUpdateHandlers.put(callbackId, handler); |
| 12207 | |
| 12208 | int result = (int) sendRequest(CMD_START_SATELLITE_POSITION_UPDATES, null, subId); |
| 12209 | if (DBG) log("startSatellitePositionUpdates result: " + result); |
| 12210 | return result; |
| 12211 | } |
| 12212 | |
| 12213 | /** |
| 12214 | * Stop receiving satellite position updates. |
| 12215 | * This can be called by the pointing UI when the user stops pointing to the satellite. |
| 12216 | * |
| 12217 | * @param subId The subId to stop satellite position updates for. |
| 12218 | * @param callbackId The ID of the callback that was passed in {@link |
| 12219 | * #startSatellitePositionUpdates(int, int, ISatellitePositionUpdateCallback)} |
| 12220 | * @return The result of the operation. |
| 12221 | */ |
| 12222 | @Override |
| 12223 | @SatelliteManager.SatelliteServiceResult public int stopSatellitePositionUpdates(int subId, |
| 12224 | int callbackId) { |
| 12225 | // TODO: check for SATELLITE_COMMUNICATION permission |
| 12226 | Phone phone = getPhone(subId); |
| 12227 | if (phone == null) { |
| 12228 | loge("stopSatellitePositionUpdates called with invalid subId: " + subId |
| 12229 | + ". Retrying with default phone."); |
| 12230 | phone = getDefaultPhone(); |
| 12231 | if (phone == null) { |
| 12232 | loge("stopSatellitePositionUpdates failed with no phone object."); |
| 12233 | return SatelliteManager.SATELLITE_SERVICE_REQUEST_FAILED; |
| 12234 | } |
| 12235 | } |
| 12236 | |
| 12237 | SatellitePositionUpdateHandler handler = |
| 12238 | mSatellitePositionUpdateHandlers.remove(callbackId); |
| 12239 | if (handler == null) { |
| 12240 | loge("stopSatellitePositionUpdates: No SatellitePositionArgument"); |
| 12241 | return SatelliteManager.SATELLITE_SERVICE_REQUEST_FAILED; |
| 12242 | } else { |
| 12243 | phone.unregisterForSatellitePointingInfoChanged(handler); |
| 12244 | phone.unregisterForSatelliteMessagesTransferComplete(handler); |
| 12245 | } |
| 12246 | |
| 12247 | if (!mSatellitePositionUpdateHandlers.isEmpty()) { |
| 12248 | log("stopSatellitePositionUpdates: other listeners still exist."); |
| 12249 | return SatelliteManager.SATELLITE_SERVICE_SUCCESS; |
| 12250 | } |
| 12251 | |
| 12252 | int result = (int) sendRequest(CMD_STOP_SATELLITE_POSITION_UPDATES, null, subId); |
| 12253 | if (DBG) log("stopSatellitePositionUpdates result: " + result); |
| 12254 | return result; |
| 12255 | } |
| 12256 | |
| 12257 | /** |
arunvoddu | d5c6ce0 | 2022-12-11 06:03:12 +0000 | [diff] [blame] | 12258 | * Check whether the caller (or self, if not processing an IPC) can read device identifiers. |
| 12259 | * |
| 12260 | * <p>This method behaves in one of the following ways: |
| 12261 | * <ul> |
| 12262 | * <li>return true : if the calling package has the appop permission {@link |
| 12263 | * Manifest.permission#USE_ICC_AUTH_WITH_DEVICE_IDENTIFIER} in the manifest </> |
| 12264 | * <li>return true : if any one subscription has the READ_PRIVILEGED_PHONE_STATE |
| 12265 | * permission, the calling package passes a DevicePolicyManager Device Owner / Profile |
| 12266 | * Owner device identifier access check, or the calling package has carrier privileges</> |
| 12267 | * <li>throw SecurityException: if the caller does not meet any of the requirements. |
| 12268 | * </ul> |
| 12269 | */ |
| 12270 | private static boolean checkCallingOrSelfReadDeviceIdentifiersForAnySub(Context context, |
| 12271 | String callingPackage, @Nullable String callingFeatureId, String message) { |
| 12272 | for (Phone phone : PhoneFactory.getPhones()) { |
| 12273 | if (TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(context, |
| 12274 | phone.getSubId(), callingPackage, callingFeatureId, message)) { |
| 12275 | return true; |
| 12276 | } |
| 12277 | } |
| 12278 | return false; |
| 12279 | } |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 12280 | |
| 12281 | /** |
| 12282 | * Class binds the consumer[callback] and carrierId. |
| 12283 | */ |
| 12284 | private static class CallerCallbackInfo { |
| 12285 | private final Consumer<Integer> mConsumer; |
| 12286 | private final int mCarrierId; |
| 12287 | |
| 12288 | public CallerCallbackInfo(Consumer<Integer> consumer, int carrierId) { |
| 12289 | mConsumer = consumer; |
| 12290 | mCarrierId = carrierId; |
| 12291 | } |
| 12292 | |
| 12293 | public Consumer<Integer> getConsumer() { |
| 12294 | return mConsumer; |
| 12295 | } |
| 12296 | |
| 12297 | public int getCarrierId() { |
| 12298 | return mCarrierId; |
| 12299 | } |
| 12300 | } |
arunvoddu | d5c6ce0 | 2022-12-11 06:03:12 +0000 | [diff] [blame] | 12301 | } |