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; |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 75 | import android.sysprop.TelephonyProperties; |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 76 | import android.telecom.PhoneAccount; |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 77 | import android.telecom.PhoneAccountHandle; |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 78 | import android.telecom.TelecomManager; |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 79 | import android.telephony.AccessNetworkConstants; |
| 80 | import android.telephony.ActivityStatsTechSpecificInfo; |
Chen Xu | 227e06f | 2019-09-26 22:48:11 -0700 | [diff] [blame] | 81 | import android.telephony.Annotation.ApnType; |
Jack Yu | 0eda684 | 2022-04-18 00:34:46 -0700 | [diff] [blame] | 82 | import android.telephony.Annotation.DataActivityType; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 83 | import android.telephony.Annotation.ThermalMitigationResult; |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 84 | import android.telephony.AnomalyReporter; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 85 | import android.telephony.CallForwardingInfo; |
Junda Liu | 12f7d80 | 2015-05-01 12:06:44 -0700 | [diff] [blame] | 86 | import android.telephony.CarrierConfigManager; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 87 | import android.telephony.CarrierRestrictionRules; |
Hui Wang | 9b5793a | 2022-12-05 14:38:06 -0600 | [diff] [blame] | 88 | import android.telephony.CellBroadcastIdRange; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 89 | import android.telephony.CellIdentity; |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 90 | import android.telephony.CellIdentityCdma; |
| 91 | import android.telephony.CellIdentityGsm; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 92 | import android.telephony.CellInfo; |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 93 | import android.telephony.CellInfoGsm; |
| 94 | import android.telephony.CellInfoWcdma; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 95 | import android.telephony.ClientRequestStats; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 96 | import android.telephony.DataThrottlingRequest; |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 97 | import android.telephony.IBootstrapAuthenticationCallback; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 98 | import android.telephony.ICellInfoCallback; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 99 | import android.telephony.IccOpenLogicalChannelResponse; |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 100 | import android.telephony.LocationAccessPolicy; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 101 | import android.telephony.ModemActivityInfo; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 102 | import android.telephony.NeighboringCellInfo; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 103 | import android.telephony.NetworkScanRequest; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 104 | import android.telephony.PhoneCapability; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 105 | import android.telephony.PhoneNumberRange; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 106 | import android.telephony.RadioAccessFamily; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 107 | import android.telephony.RadioAccessSpecifier; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 108 | import android.telephony.ServiceState; |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 109 | import android.telephony.SignalStrength; |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 110 | import android.telephony.SignalStrengthUpdateRequest; |
| 111 | import android.telephony.SignalThresholdInfo; |
Wink Saville | 0f3b5fc | 2014-11-11 08:40:49 -0800 | [diff] [blame] | 112 | import android.telephony.SubscriptionInfo; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 113 | import android.telephony.SubscriptionManager; |
Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 114 | import android.telephony.TelephonyFrameworkInitializer; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 115 | import android.telephony.TelephonyHistogram; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 116 | import android.telephony.TelephonyManager; |
Jack Yu | f5badd9 | 2022-12-08 00:50:53 -0800 | [diff] [blame] | 117 | import android.telephony.TelephonyManager.SimState; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 118 | import android.telephony.TelephonyScanManager; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 119 | import android.telephony.ThermalMitigationRequest; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 120 | import android.telephony.UiccCardInfo; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 121 | import android.telephony.UiccPortInfo; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 122 | import android.telephony.UiccSlotInfo; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 123 | import android.telephony.UiccSlotMapping; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 124 | import android.telephony.UssdResponse; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 125 | import android.telephony.VisualVoicemailSmsFilterSettings; |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 126 | import android.telephony.data.NetworkSlicingConfig; |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 127 | import android.telephony.emergency.EmergencyNumber; |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 128 | import android.telephony.gba.GbaAuthRequest; |
| 129 | import android.telephony.gba.UaSecurityProtocolIdentifier; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 130 | import android.telephony.ims.ImsException; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 131 | import android.telephony.ims.ProvisioningManager; |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 132 | import android.telephony.ims.RcsClientConfiguration; |
Brad Ebinger | 14d467f | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 133 | import android.telephony.ims.RcsContactUceCapability; |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 134 | import android.telephony.ims.RegistrationManager; |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 135 | import android.telephony.ims.aidl.IFeatureProvisioningCallback; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 136 | import android.telephony.ims.aidl.IImsCapabilityCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 137 | import android.telephony.ims.aidl.IImsConfig; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 138 | import android.telephony.ims.aidl.IImsConfigCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 139 | import android.telephony.ims.aidl.IImsRegistration; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 140 | import android.telephony.ims.aidl.IImsRegistrationCallback; |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 141 | import android.telephony.ims.aidl.IRcsConfigCallback; |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 142 | import android.telephony.ims.feature.ImsFeature; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 143 | import android.telephony.ims.stub.ImsConfigImplBase; |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 144 | import android.telephony.ims.stub.ImsRegistrationImplBase; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 145 | import android.text.TextUtils; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 146 | import android.util.ArraySet; |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 147 | import android.util.EventLog; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 148 | import android.util.Log; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 149 | import android.util.Pair; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 150 | |
Andrew Lee | 312e817 | 2014-10-23 17:01:36 -0700 | [diff] [blame] | 151 | import com.android.ims.ImsManager; |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 152 | import com.android.ims.internal.IImsServiceFeatureCallback; |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 153 | import com.android.ims.rcs.uce.eab.EabUtil; |
SongFerngWang | fd89b10 | 2021-05-27 22:44:54 +0800 | [diff] [blame] | 154 | import com.android.internal.annotations.VisibleForTesting; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 155 | import com.android.internal.telephony.CallForwardInfo; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 156 | import com.android.internal.telephony.CallManager; |
Tyler Gunn | 52dcf77 | 2017-04-26 11:30:31 -0700 | [diff] [blame] | 157 | import com.android.internal.telephony.CallStateException; |
Tyler Gunn | d433926 | 2021-05-03 14:46:49 -0700 | [diff] [blame] | 158 | import com.android.internal.telephony.CallTracker; |
Rambo Wang | 9c9ffdd | 2022-01-13 21:51:44 -0800 | [diff] [blame] | 159 | import com.android.internal.telephony.CarrierPrivilegesTracker; |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 160 | import com.android.internal.telephony.CarrierResolver; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 161 | import com.android.internal.telephony.CellNetworkScanResult; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 162 | import com.android.internal.telephony.CommandException; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 163 | import com.android.internal.telephony.CommandsInterface; |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 164 | import com.android.internal.telephony.GbaManager; |
Shuo Qian | ccbaf74 | 2021-02-22 18:32:21 -0800 | [diff] [blame] | 165 | import com.android.internal.telephony.GsmCdmaPhone; |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 166 | import com.android.internal.telephony.HalVersion; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 167 | import com.android.internal.telephony.IBooleanConsumer; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 168 | import com.android.internal.telephony.ICallForwardingInfoCallback; |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 169 | import com.android.internal.telephony.IImsStateCallback; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 170 | import com.android.internal.telephony.IIntegerConsumer; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 171 | import com.android.internal.telephony.INumberVerificationCallback; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 172 | import com.android.internal.telephony.ITelephony; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 173 | import com.android.internal.telephony.IccCard; |
Jack Yu | f5badd9 | 2022-12-08 00:50:53 -0800 | [diff] [blame] | 174 | import com.android.internal.telephony.IccCardConstants; |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 175 | import com.android.internal.telephony.IccLogicalChannelRequest; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 176 | import com.android.internal.telephony.LocaleTracker; |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 177 | import com.android.internal.telephony.NetworkScanRequestTracker; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 178 | import com.android.internal.telephony.OperatorInfo; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 179 | import com.android.internal.telephony.Phone; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 180 | import com.android.internal.telephony.PhoneConfigurationManager; |
Nathan Harold | a667c15 | 2016-12-14 11:27:20 -0800 | [diff] [blame] | 181 | import com.android.internal.telephony.PhoneConstantConversions; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 182 | import com.android.internal.telephony.PhoneConstants; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 183 | import com.android.internal.telephony.PhoneFactory; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 184 | import com.android.internal.telephony.ProxyController; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 185 | import com.android.internal.telephony.RIL; |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 186 | import com.android.internal.telephony.RILConstants; |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 187 | import com.android.internal.telephony.RadioInterfaceCapabilityController; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 188 | import com.android.internal.telephony.ServiceStateTracker; |
Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame] | 189 | import com.android.internal.telephony.SmsApplication; |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 190 | import com.android.internal.telephony.SmsController; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 191 | import com.android.internal.telephony.SmsPermissions; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 192 | import com.android.internal.telephony.SubscriptionController; |
Peter Wang | 59571be | 2020-01-27 12:35:15 +0800 | [diff] [blame] | 193 | import com.android.internal.telephony.TelephonyIntents; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 194 | import com.android.internal.telephony.TelephonyPermissions; |
Jack Yu | 27422a5 | 2022-03-21 10:38:05 -0700 | [diff] [blame] | 195 | import com.android.internal.telephony.data.DataUtils; |
Hunsuk Choi | 42cc62a | 2022-10-16 06:03:40 +0000 | [diff] [blame] | 196 | import com.android.internal.telephony.domainselection.DomainSelectionResolver; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 197 | import com.android.internal.telephony.emergency.EmergencyNumberTracker; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 198 | import com.android.internal.telephony.euicc.EuiccConnector; |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 199 | import com.android.internal.telephony.ims.ImsResolver; |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 200 | import com.android.internal.telephony.imsphone.ImsPhone; |
| 201 | import com.android.internal.telephony.imsphone.ImsPhoneCallTracker; |
joonhunshin | 3e15424 | 2021-09-17 06:33:39 +0000 | [diff] [blame] | 202 | import com.android.internal.telephony.metrics.RcsStats; |
Pengquan Meng | 6c2dc9f | 2019-02-06 11:12:53 -0800 | [diff] [blame] | 203 | import com.android.internal.telephony.metrics.TelephonyMetrics; |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 204 | import com.android.internal.telephony.subscription.SubscriptionInfoInternal; |
| 205 | import com.android.internal.telephony.subscription.SubscriptionManagerService; |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 206 | import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 207 | import com.android.internal.telephony.uicc.IccIoResult; |
| 208 | import com.android.internal.telephony.uicc.IccUtils; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 209 | import com.android.internal.telephony.uicc.SIMRecords; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 210 | import com.android.internal.telephony.uicc.UiccCard; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 211 | import com.android.internal.telephony.uicc.UiccCardApplication; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 212 | import com.android.internal.telephony.uicc.UiccController; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 213 | import com.android.internal.telephony.uicc.UiccPort; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 214 | import com.android.internal.telephony.uicc.UiccProfile; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 215 | import com.android.internal.telephony.uicc.UiccSlot; |
zoey chen | c730df8 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 216 | import com.android.internal.telephony.util.LocaleUtils; |
Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame] | 217 | import com.android.internal.telephony.util.TelephonyUtils; |
fionaxu | 7ed723d | 2017-05-30 18:58:54 -0700 | [diff] [blame] | 218 | import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 219 | import com.android.internal.util.FunctionalUtils; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 220 | import com.android.internal.util.HexDump; |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 221 | import com.android.phone.callcomposer.CallComposerPictureManager; |
| 222 | import com.android.phone.callcomposer.CallComposerPictureTransfer; |
| 223 | import com.android.phone.callcomposer.ImageData; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 224 | import com.android.phone.settings.PickSmsSubscriptionActivity; |
Sarah Chin | 46355ba | 2022-11-01 23:51:16 -0700 | [diff] [blame] | 225 | import com.android.phone.slice.SlicePurchaseController; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 226 | import com.android.phone.vvm.PhoneAccountHandleConverter; |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 227 | import com.android.phone.vvm.RemoteVvmTaskManager; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 228 | import com.android.phone.vvm.VisualVoicemailSettingsUtil; |
Ta-wei Yen | c890531 | 2017-03-28 11:14:45 -0700 | [diff] [blame] | 229 | import com.android.phone.vvm.VisualVoicemailSmsFilterConfig; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 230 | import com.android.services.telephony.TelecomAccountRegistry; |
| 231 | import com.android.services.telephony.TelephonyConnectionService; |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 232 | import com.android.telephony.Rlog; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 233 | |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 234 | import java.io.ByteArrayOutputStream; |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 235 | import java.io.FileDescriptor; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 236 | import java.io.IOException; |
| 237 | import java.io.InputStream; |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 238 | import java.io.PrintWriter; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 239 | import java.util.ArrayList; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 240 | import java.util.Arrays; |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 241 | import java.util.Collection; |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 242 | import java.util.Collections; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 243 | import java.util.HashMap; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 244 | import java.util.HashSet; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 245 | import java.util.List; |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 246 | import java.util.Locale; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 247 | import java.util.Map; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 248 | import java.util.NoSuchElementException; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 249 | import java.util.Objects; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 250 | import java.util.Set; |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 251 | import java.util.UUID; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 252 | import java.util.concurrent.Executors; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 253 | import java.util.concurrent.atomic.AtomicBoolean; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 254 | import java.util.function.Consumer; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 255 | |
| 256 | /** |
| 257 | * Implementation of the ITelephony interface. |
| 258 | */ |
Santos Cordon | 117fee7 | 2014-05-16 17:56:12 -0700 | [diff] [blame] | 259 | public class PhoneInterfaceManager extends ITelephony.Stub { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 260 | private static final String LOG_TAG = "PhoneInterfaceManager"; |
| 261 | private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2); |
| 262 | private static final boolean DBG_LOC = false; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 263 | private static final boolean DBG_MERGE = false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 264 | |
| 265 | // Message codes used with mMainThreadHandler |
| 266 | private static final int CMD_HANDLE_PIN_MMI = 1; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 267 | private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7; |
| 268 | private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 269 | private static final int CMD_OPEN_CHANNEL = 9; |
| 270 | private static final int EVENT_OPEN_CHANNEL_DONE = 10; |
| 271 | private static final int CMD_CLOSE_CHANNEL = 11; |
| 272 | private static final int EVENT_CLOSE_CHANNEL_DONE = 12; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 273 | private static final int CMD_NV_READ_ITEM = 13; |
| 274 | private static final int EVENT_NV_READ_ITEM_DONE = 14; |
| 275 | private static final int CMD_NV_WRITE_ITEM = 15; |
| 276 | private static final int EVENT_NV_WRITE_ITEM_DONE = 16; |
| 277 | private static final int CMD_NV_WRITE_CDMA_PRL = 17; |
| 278 | private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 279 | private static final int CMD_RESET_MODEM_CONFIG = 19; |
| 280 | private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 281 | private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21; |
| 282 | private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22; |
Sailesh Nepal | 35b5945 | 2014-03-06 09:26:56 -0800 | [diff] [blame] | 283 | private static final int CMD_SEND_ENVELOPE = 25; |
| 284 | private static final int EVENT_SEND_ENVELOPE_DONE = 26; |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 285 | private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27; |
| 286 | private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28; |
Derek Tan | 6b088ee | 2014-09-05 14:15:18 -0700 | [diff] [blame] | 287 | private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29; |
| 288 | private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30; |
| 289 | private static final int CMD_EXCHANGE_SIM_IO = 31; |
| 290 | private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 291 | private static final int CMD_SET_VOICEMAIL_NUMBER = 33; |
| 292 | private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 293 | private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35; |
| 294 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 295 | private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37; |
| 296 | private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 297 | private static final int CMD_PERFORM_NETWORK_SCAN = 39; |
| 298 | private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40; |
| 299 | private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41; |
| 300 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 301 | private static final int CMD_SET_ALLOWED_CARRIERS = 43; |
| 302 | private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44; |
| 303 | private static final int CMD_GET_ALLOWED_CARRIERS = 45; |
| 304 | private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 305 | private static final int CMD_HANDLE_USSD_REQUEST = 47; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 306 | private static final int CMD_GET_FORBIDDEN_PLMNS = 48; |
| 307 | private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 308 | private static final int CMD_SWITCH_SLOTS = 50; |
| 309 | private static final int EVENT_SWITCH_SLOTS_DONE = 51; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 310 | private static final int CMD_GET_NETWORK_SELECTION_MODE = 52; |
| 311 | private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53; |
| 312 | private static final int CMD_GET_CDMA_ROAMING_MODE = 54; |
| 313 | private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55; |
| 314 | private static final int CMD_SET_CDMA_ROAMING_MODE = 56; |
| 315 | private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57; |
| 316 | private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58; |
| 317 | private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 318 | private static final int CMD_GET_ALL_CELL_INFO = 60; |
| 319 | private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61; |
| 320 | private static final int CMD_GET_CELL_LOCATION = 62; |
| 321 | private static final int EVENT_GET_CELL_LOCATION_DONE = 63; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 322 | private static final int CMD_MODEM_REBOOT = 64; |
| 323 | private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 324 | private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66; |
| 325 | private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 326 | private static final int CMD_REQUEST_ENABLE_MODEM = 68; |
| 327 | private static final int EVENT_ENABLE_MODEM_DONE = 69; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 328 | private static final int CMD_GET_MODEM_STATUS = 70; |
| 329 | private static final int EVENT_GET_MODEM_STATUS_DONE = 71; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 330 | private static final int CMD_SET_FORBIDDEN_PLMNS = 72; |
| 331 | private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 332 | private static final int CMD_ERASE_MODEM_CONFIG = 74; |
| 333 | private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75; |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 334 | private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76; |
| 335 | private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77; |
| 336 | private static final int CMD_SET_ICC_LOCK_ENABLED = 78; |
| 337 | private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 338 | private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80; |
| 339 | private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 340 | private static final int MSG_NOTIFY_USER_ACTIVITY = 82; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 341 | private static final int CMD_GET_CALL_FORWARDING = 83; |
| 342 | private static final int EVENT_GET_CALL_FORWARDING_DONE = 84; |
| 343 | private static final int CMD_SET_CALL_FORWARDING = 85; |
| 344 | private static final int EVENT_SET_CALL_FORWARDING_DONE = 86; |
| 345 | private static final int CMD_GET_CALL_WAITING = 87; |
| 346 | private static final int EVENT_GET_CALL_WAITING_DONE = 88; |
| 347 | private static final int CMD_SET_CALL_WAITING = 89; |
| 348 | private static final int EVENT_SET_CALL_WAITING_DONE = 90; |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 349 | private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91; |
| 350 | private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92; |
| 351 | private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93; |
| 352 | private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 353 | private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95; |
| 354 | private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 355 | private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97; |
| 356 | private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 357 | private static final int CMD_SET_DATA_THROTTLING = 99; |
| 358 | private static final int EVENT_SET_DATA_THROTTLING_DONE = 100; |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 359 | private static final int CMD_SET_SIM_POWER = 101; |
| 360 | private static final int EVENT_SET_SIM_POWER_DONE = 102; |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 361 | private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103; |
| 362 | private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104; |
| 363 | private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105; |
| 364 | private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 365 | private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107; |
| 366 | 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] | 367 | private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 368 | private static final int CMD_GET_SLICING_CONFIG = 110; |
| 369 | private static final int EVENT_GET_SLICING_CONFIG_DONE = 111; |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 370 | private static final int CMD_ERASE_DATA_SHARED_PREFERENCES = 112; |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 371 | private static final int CMD_ENABLE_VONR = 113; |
| 372 | private static final int EVENT_ENABLE_VONR_DONE = 114; |
| 373 | private static final int CMD_IS_VONR_ENABLED = 115; |
| 374 | private static final int EVENT_IS_VONR_ENABLED_DONE = 116; |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 375 | private static final int CMD_PURCHASE_PREMIUM_CAPABILITY = 117; |
| 376 | private static final int EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE = 118; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 377 | |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 378 | // Parameters of select command. |
| 379 | private static final int SELECT_COMMAND = 0xA4; |
| 380 | private static final int SELECT_P1 = 0x04; |
| 381 | private static final int SELECT_P2 = 0; |
| 382 | private static final int SELECT_P3 = 0x10; |
| 383 | |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 384 | // Toggling null cipher and integrity support was added in IRadioNetwork 2.1 |
| 385 | private static final int MIN_NULL_CIPHER_AND_INTEGRITY_VERSION = 201; |
| 386 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 387 | /** The singleton instance. */ |
| 388 | private static PhoneInterfaceManager sInstance; |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 389 | private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 390 | |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 391 | private PhoneGlobals mApp; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 392 | private CallManager mCM; |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 393 | private ImsResolver mImsResolver; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 394 | private UserManager mUserManager; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 395 | private AppOpsManager mAppOps; |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 396 | private PackageManager mPm; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 397 | private MainThreadHandler mMainThreadHandler; |
Aishwarya Mallampati | 32336e8 | 2023-01-04 23:02:56 +0000 | [diff] [blame] | 398 | private SubscriptionController mSubscriptionController; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 399 | private SharedPreferences mTelephonySharedPreferences; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 400 | private PhoneConfigurationManager mPhoneConfigurationManager; |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 401 | private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities; |
Gil Cukierman | 6dac5eb | 2022-09-19 16:09:04 +0000 | [diff] [blame] | 402 | private final Telephony2gUpdater mTelephony2gUpdater; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 403 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 404 | /** User Activity */ |
| 405 | private AtomicBoolean mNotifyUserActivity; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 406 | private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200; |
| 407 | |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 408 | private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>(); |
| 409 | |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 410 | private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_"; |
| 411 | private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_"; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 412 | private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_"; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 413 | private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_"; |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 414 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 415 | // String to store multi SIM allowed |
| 416 | private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted"; |
| 417 | |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 418 | // The AID of ISD-R. |
| 419 | private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100"; |
| 420 | |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 421 | private NetworkScanRequestTracker mNetworkScanRequestTracker; |
| 422 | |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 423 | private static final int TYPE_ALLOCATION_CODE_LENGTH = 8; |
| 424 | private static final int MANUFACTURER_CODE_LENGTH = 8; |
| 425 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 426 | private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1; |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 427 | 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] | 428 | |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 429 | private static final String PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID = |
| 430 | "24bf97a6-e8a6-44d8-a6a4-255d7548733c"; |
| 431 | |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 432 | /** |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 433 | * Experiment flag to enable erase modem config on reset network, default value is false |
| 434 | */ |
| 435 | public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED = |
| 436 | "reset_network_erase_modem_config_enabled"; |
| 437 | |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 438 | 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] | 439 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 440 | /** |
| 441 | * With support for MEP(multiple enabled profile) in Android T, a SIM card can have more than |
| 442 | * one ICCID active at the same time. |
| 443 | * Apps should use below API signatures if targeting SDK is T and beyond. |
| 444 | * |
| 445 | * @hide |
| 446 | */ |
| 447 | @ChangeId |
| 448 | @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU) |
| 449 | public static final long GET_API_SIGNATURES_FROM_UICC_PORT_INFO = 202110963L; |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 450 | |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 451 | /** |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 452 | * Apps targeting on Android T and beyond will get exception whenever icc close channel |
| 453 | * operation fails. |
| 454 | */ |
| 455 | @ChangeId |
| 456 | @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU) |
| 457 | public static final long ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE = 208739934L; |
| 458 | |
| 459 | /** |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 460 | * A request object to use for transmitting data to an ICC. |
| 461 | */ |
| 462 | private static final class IccAPDUArgument { |
| 463 | public int channel, cla, command, p1, p2, p3; |
| 464 | public String data; |
| 465 | |
| 466 | public IccAPDUArgument(int channel, int cla, int command, |
| 467 | int p1, int p2, int p3, String data) { |
| 468 | this.channel = channel; |
| 469 | this.cla = cla; |
| 470 | this.command = command; |
| 471 | this.p1 = p1; |
| 472 | this.p2 = p2; |
| 473 | this.p3 = p3; |
| 474 | this.data = data; |
| 475 | } |
| 476 | } |
| 477 | |
| 478 | /** |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 479 | * A request object to use for transmitting data to an ICC. |
| 480 | */ |
| 481 | private static final class ManualNetworkSelectionArgument { |
| 482 | public OperatorInfo operatorInfo; |
| 483 | public boolean persistSelection; |
| 484 | |
| 485 | public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) { |
| 486 | this.operatorInfo = operatorInfo; |
| 487 | this.persistSelection = persistSelection; |
| 488 | } |
| 489 | } |
| 490 | |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 491 | private static final class PurchasePremiumCapabilityArgument { |
| 492 | public @TelephonyManager.PremiumCapability int capability; |
| 493 | public @NonNull String appName; |
| 494 | public @NonNull IIntegerConsumer callback; |
| 495 | |
| 496 | PurchasePremiumCapabilityArgument(@TelephonyManager.PremiumCapability int capability, |
| 497 | @NonNull String appName, @NonNull IIntegerConsumer callback) { |
| 498 | this.capability = capability; |
| 499 | this.appName = appName; |
| 500 | this.callback = callback; |
| 501 | } |
| 502 | } |
| 503 | |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 504 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 505 | * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the |
| 506 | * request after sending. The main thread will notify the request when it is complete. |
| 507 | */ |
| 508 | private static final class MainThreadRequest { |
| 509 | /** The argument to use for the request */ |
| 510 | public Object argument; |
| 511 | /** The result of the request that is run on the main thread */ |
| 512 | public Object result; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 513 | // The subscriber id that this request applies to. Defaults to |
| 514 | // SubscriptionManager.INVALID_SUBSCRIPTION_ID |
| 515 | public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 516 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 517 | // In cases where subId is unavailable, the caller needs to specify the phone. |
| 518 | public Phone phone; |
| 519 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 520 | public WorkSource workSource; |
| 521 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 522 | public MainThreadRequest(Object argument) { |
| 523 | this.argument = argument; |
| 524 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 525 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 526 | MainThreadRequest(Object argument, Phone phone, WorkSource workSource) { |
| 527 | this.argument = argument; |
| 528 | if (phone != null) { |
| 529 | this.phone = phone; |
| 530 | } |
| 531 | this.workSource = workSource; |
| 532 | } |
| 533 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 534 | MainThreadRequest(Object argument, Integer subId, WorkSource workSource) { |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 535 | this.argument = argument; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 536 | if (subId != null) { |
| 537 | this.subId = subId; |
| 538 | } |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 539 | this.workSource = workSource; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 540 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 541 | } |
| 542 | |
Sailesh Nepal | cc0375f | 2013-11-13 09:15:18 -0800 | [diff] [blame] | 543 | private static final class IncomingThirdPartyCallArgs { |
| 544 | public final ComponentName component; |
| 545 | public final String callId; |
| 546 | public final String callerDisplayName; |
| 547 | |
| 548 | public IncomingThirdPartyCallArgs(ComponentName component, String callId, |
| 549 | String callerDisplayName) { |
| 550 | this.component = component; |
| 551 | this.callId = callId; |
| 552 | this.callerDisplayName = callerDisplayName; |
| 553 | } |
| 554 | } |
| 555 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 556 | /** |
| 557 | * A handler that processes messages on the main thread in the phone process. Since many |
| 558 | * of the Phone calls are not thread safe this is needed to shuttle the requests from the |
| 559 | * inbound binder threads to the main thread in the phone process. The Binder thread |
| 560 | * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting |
| 561 | * on, which will be notified when the operation completes and will contain the result of the |
| 562 | * request. |
| 563 | * |
| 564 | * <p>If a MainThreadRequest object is provided in the msg.obj field, |
| 565 | * note that request.result must be set to something non-null for the calling thread to |
| 566 | * unblock. |
| 567 | */ |
| 568 | private final class MainThreadHandler extends Handler { |
| 569 | @Override |
| 570 | public void handleMessage(Message msg) { |
| 571 | MainThreadRequest request; |
| 572 | Message onCompleted; |
| 573 | AsyncResult ar; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 574 | UiccPort uiccPort; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 575 | IccAPDUArgument iccArgument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 576 | final Phone defaultPhone = getDefaultPhone(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 577 | |
| 578 | switch (msg.what) { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 579 | case CMD_HANDLE_USSD_REQUEST: { |
| 580 | request = (MainThreadRequest) msg.obj; |
| 581 | final Phone phone = getPhoneFromRequest(request); |
| 582 | Pair<String, ResultReceiver> ussdObject = (Pair) request.argument; |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 583 | String ussdRequest = ussdObject.first; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 584 | ResultReceiver wrappedCallback = ussdObject.second; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 585 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 586 | if (!isUssdApiAllowed(request.subId)) { |
| 587 | // Carrier does not support use of this API, return failure. |
| 588 | Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis."); |
| 589 | UssdResponse response = new UssdResponse(ussdRequest, null); |
| 590 | Bundle returnData = new Bundle(); |
| 591 | returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response); |
| 592 | wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 593 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 594 | request.result = true; |
| 595 | notifyRequester(request); |
| 596 | return; |
| 597 | } |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 598 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 599 | try { |
| 600 | request.result = phone != null |
| 601 | ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false; |
| 602 | } catch (CallStateException cse) { |
| 603 | request.result = false; |
| 604 | } |
| 605 | // Wake up the requesting thread |
| 606 | notifyRequester(request); |
| 607 | break; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 608 | } |
| 609 | |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 610 | case CMD_HANDLE_PIN_MMI: { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 611 | request = (MainThreadRequest) msg.obj; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 612 | final Phone phone = getPhoneFromRequest(request); |
| 613 | request.result = phone != null ? |
| 614 | getPhoneFromRequest(request).handlePinMmi((String) request.argument) |
| 615 | : false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 616 | // Wake up the requesting thread |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 617 | notifyRequester(request); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 618 | break; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 619 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 620 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 621 | case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 622 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 623 | iccArgument = (IccAPDUArgument) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 624 | uiccPort = getUiccPortFromRequest(request); |
| 625 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 626 | loge("iccTransmitApduLogicalChannel: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 627 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 628 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 629 | } else { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 630 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE, |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 631 | request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 632 | uiccPort.iccTransmitApduLogicalChannel( |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 633 | iccArgument.channel, iccArgument.cla, iccArgument.command, |
| 634 | iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data, |
| 635 | onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 636 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 637 | break; |
| 638 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 639 | case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 640 | ar = (AsyncResult) msg.obj; |
| 641 | request = (MainThreadRequest) ar.userObj; |
| 642 | if (ar.exception == null && ar.result != null) { |
| 643 | request.result = ar.result; |
| 644 | } else { |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 645 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 646 | if (ar.result == null) { |
| 647 | loge("iccTransmitApduLogicalChannel: Empty response"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 648 | } else if (ar.exception instanceof CommandException) { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 649 | loge("iccTransmitApduLogicalChannel: CommandException: " + |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 650 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 651 | } else { |
| 652 | loge("iccTransmitApduLogicalChannel: Unknown exception"); |
| 653 | } |
| 654 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 655 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 656 | break; |
| 657 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 658 | case CMD_TRANSMIT_APDU_BASIC_CHANNEL: |
| 659 | request = (MainThreadRequest) msg.obj; |
| 660 | iccArgument = (IccAPDUArgument) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 661 | uiccPort = getUiccPortFromRequest(request); |
| 662 | if (uiccPort == null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 663 | loge("iccTransmitApduBasicChannel: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 664 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 665 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 666 | } else { |
| 667 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE, |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 668 | request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 669 | uiccPort.iccTransmitApduBasicChannel( |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 670 | iccArgument.cla, iccArgument.command, iccArgument.p1, |
| 671 | iccArgument.p2, |
| 672 | iccArgument.p3, iccArgument.data, onCompleted); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 673 | } |
| 674 | break; |
| 675 | |
| 676 | case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE: |
| 677 | ar = (AsyncResult) msg.obj; |
| 678 | request = (MainThreadRequest) ar.userObj; |
| 679 | if (ar.exception == null && ar.result != null) { |
| 680 | request.result = ar.result; |
| 681 | } else { |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 682 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 683 | if (ar.result == null) { |
| 684 | loge("iccTransmitApduBasicChannel: Empty response"); |
| 685 | } else if (ar.exception instanceof CommandException) { |
| 686 | loge("iccTransmitApduBasicChannel: CommandException: " + |
| 687 | ar.exception); |
| 688 | } else { |
| 689 | loge("iccTransmitApduBasicChannel: Unknown exception"); |
| 690 | } |
| 691 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 692 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 693 | break; |
| 694 | |
| 695 | case CMD_EXCHANGE_SIM_IO: |
| 696 | request = (MainThreadRequest) msg.obj; |
| 697 | iccArgument = (IccAPDUArgument) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 698 | uiccPort = getUiccPortFromRequest(request); |
| 699 | if (uiccPort == null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 700 | loge("iccExchangeSimIO: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 701 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 702 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 703 | } else { |
| 704 | onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE, |
| 705 | request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 706 | uiccPort.iccExchangeSimIO(iccArgument.cla, /* fileID */ |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 707 | iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3, |
| 708 | iccArgument.data, onCompleted); |
| 709 | } |
| 710 | break; |
| 711 | |
| 712 | case EVENT_EXCHANGE_SIM_IO_DONE: |
| 713 | ar = (AsyncResult) msg.obj; |
| 714 | request = (MainThreadRequest) ar.userObj; |
| 715 | if (ar.exception == null && ar.result != null) { |
| 716 | request.result = ar.result; |
| 717 | } else { |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 718 | request.result = new IccIoResult(0x6f, 0, (byte[]) null); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 719 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 720 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 721 | break; |
| 722 | |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 723 | case CMD_SEND_ENVELOPE: |
| 724 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 725 | uiccPort = getUiccPortFromRequest(request); |
| 726 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 727 | loge("sendEnvelopeWithStatus: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 728 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 729 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 730 | } else { |
| 731 | onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 732 | uiccPort.sendEnvelopeWithStatus((String) request.argument, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 733 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 734 | break; |
| 735 | |
| 736 | case EVENT_SEND_ENVELOPE_DONE: |
| 737 | ar = (AsyncResult) msg.obj; |
| 738 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 739 | if (ar.exception == null && ar.result != null) { |
| 740 | request.result = ar.result; |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 741 | } else { |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 742 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 743 | if (ar.result == null) { |
| 744 | loge("sendEnvelopeWithStatus: Empty response"); |
| 745 | } else if (ar.exception instanceof CommandException) { |
| 746 | loge("sendEnvelopeWithStatus: CommandException: " + |
| 747 | ar.exception); |
| 748 | } else { |
| 749 | loge("sendEnvelopeWithStatus: exception:" + ar.exception); |
| 750 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 751 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 752 | notifyRequester(request); |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 753 | break; |
| 754 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 755 | case CMD_OPEN_CHANNEL: |
| 756 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 757 | uiccPort = getUiccPortFromRequest(request); |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 758 | IccLogicalChannelRequest openChannelRequest = |
| 759 | (IccLogicalChannelRequest) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 760 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 761 | loge("iccOpenLogicalChannel: No UICC"); |
Shishir Agrawal | fc0492a | 2016-02-17 11:15:33 -0800 | [diff] [blame] | 762 | request.result = new IccOpenLogicalChannelResponse(-1, |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 763 | IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 764 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 765 | } else { |
| 766 | onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request); |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 767 | uiccPort.iccOpenLogicalChannel(openChannelRequest.aid, |
| 768 | openChannelRequest.p2, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 769 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 770 | break; |
| 771 | |
| 772 | case EVENT_OPEN_CHANNEL_DONE: |
| 773 | ar = (AsyncResult) msg.obj; |
| 774 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 775 | IccOpenLogicalChannelResponse openChannelResp; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 776 | if (ar.exception == null && ar.result != null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 777 | int[] result = (int[]) ar.result; |
| 778 | int channelId = result[0]; |
| 779 | byte[] selectResponse = null; |
| 780 | if (result.length > 1) { |
| 781 | selectResponse = new byte[result.length - 1]; |
| 782 | for (int i = 1; i < result.length; ++i) { |
| 783 | selectResponse[i - 1] = (byte) result[i]; |
| 784 | } |
| 785 | } |
| 786 | openChannelResp = new IccOpenLogicalChannelResponse(channelId, |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 787 | IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse); |
Rambo Wang | 3b77c4c | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 788 | |
| 789 | uiccPort = getUiccPortFromRequest(request); |
Rambo Wang | e53e07d | 2022-05-10 13:01:13 -0700 | [diff] [blame] | 790 | if (uiccPort == null) { |
| 791 | loge("EVENT_OPEN_CHANNEL_DONE: UiccPort is null"); |
| 792 | } else { |
| 793 | IccLogicalChannelRequest channelRequest = |
| 794 | (IccLogicalChannelRequest) request.argument; |
| 795 | channelRequest.channel = channelId; |
| 796 | uiccPort.onLogicalChannelOpened(channelRequest); |
| 797 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 798 | } else { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 799 | if (ar.result == null) { |
| 800 | loge("iccOpenLogicalChannel: Empty response"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 801 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 802 | if (ar.exception != null) { |
| 803 | loge("iccOpenLogicalChannel: Exception: " + ar.exception); |
| 804 | } |
| 805 | |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 806 | int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 807 | if (ar.exception instanceof CommandException) { |
| 808 | CommandException.Error error = |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 809 | ((CommandException) (ar.exception)).getCommandError(); |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 810 | if (error == CommandException.Error.MISSING_RESOURCE) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 811 | errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 812 | } else if (error == CommandException.Error.NO_SUCH_ELEMENT) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 813 | errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 814 | } |
| 815 | } |
| 816 | openChannelResp = new IccOpenLogicalChannelResponse( |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 817 | IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 818 | } |
Shishir Agrawal | 82c8a46 | 2014-07-31 18:13:17 -0700 | [diff] [blame] | 819 | request.result = openChannelResp; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 820 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 821 | break; |
| 822 | |
| 823 | case CMD_CLOSE_CHANNEL: |
| 824 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 825 | uiccPort = getUiccPortFromRequest(request); |
| 826 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 827 | loge("iccCloseLogicalChannel: No UICC"); |
Chen Xu | a8f0dff | 2022-02-12 00:34:15 -0800 | [diff] [blame] | 828 | request.result = new IllegalArgumentException( |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 829 | "iccCloseLogicalChannel: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 830 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 831 | } else { |
| 832 | onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 833 | uiccPort.iccCloseLogicalChannel((Integer) request.argument, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 834 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 835 | break; |
| 836 | |
| 837 | case EVENT_CLOSE_CHANNEL_DONE: |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 838 | ar = (AsyncResult) msg.obj; |
| 839 | request = (MainThreadRequest) ar.userObj; |
| 840 | if (ar.exception == null) { |
| 841 | request.result = true; |
Rambo Wang | 3b77c4c | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 842 | uiccPort = getUiccPortFromRequest(request); |
Rambo Wang | e53e07d | 2022-05-10 13:01:13 -0700 | [diff] [blame] | 843 | if (uiccPort == null) { |
| 844 | loge("EVENT_CLOSE_CHANNEL_DONE: UiccPort is null"); |
| 845 | } else { |
| 846 | final int channelId = (Integer) request.argument; |
| 847 | uiccPort.onLogicalChannelClosed(channelId); |
| 848 | } |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 849 | } else { |
| 850 | request.result = false; |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 851 | Exception exception = null; |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 852 | if (ar.exception instanceof CommandException) { |
| 853 | loge("iccCloseLogicalChannel: CommandException: " + ar.exception); |
| 854 | CommandException.Error error = |
| 855 | ((CommandException) (ar.exception)).getCommandError(); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 856 | if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 857 | // should only throw exceptions from the binder threads. |
| 858 | exception = new IllegalArgumentException( |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 859 | "iccCloseLogicalChannel: invalid argument "); |
| 860 | } |
| 861 | } else { |
| 862 | loge("iccCloseLogicalChannel: Unknown exception"); |
| 863 | } |
Chen Xu | a8f0dff | 2022-02-12 00:34:15 -0800 | [diff] [blame] | 864 | request.result = (exception != null) ? exception : |
| 865 | new IllegalStateException( |
| 866 | "exception from modem to close iccLogical Channel"); |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 867 | } |
| 868 | notifyRequester(request); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 869 | break; |
| 870 | |
| 871 | case CMD_NV_READ_ITEM: |
| 872 | request = (MainThreadRequest) msg.obj; |
| 873 | onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 874 | defaultPhone.nvReadItem((Integer) request.argument, onCompleted, |
| 875 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 876 | break; |
| 877 | |
| 878 | case EVENT_NV_READ_ITEM_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 879 | ar = (AsyncResult) msg.obj; |
| 880 | request = (MainThreadRequest) ar.userObj; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 881 | if (ar.exception == null && ar.result != null) { |
| 882 | request.result = ar.result; // String |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 883 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 884 | request.result = ""; |
| 885 | if (ar.result == null) { |
| 886 | loge("nvReadItem: Empty response"); |
| 887 | } else if (ar.exception instanceof CommandException) { |
| 888 | loge("nvReadItem: CommandException: " + |
| 889 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 890 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 891 | loge("nvReadItem: Unknown exception"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 892 | } |
| 893 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 894 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 895 | break; |
| 896 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 897 | case CMD_NV_WRITE_ITEM: |
| 898 | request = (MainThreadRequest) msg.obj; |
| 899 | onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request); |
| 900 | Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 901 | defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 902 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 903 | break; |
| 904 | |
| 905 | case EVENT_NV_WRITE_ITEM_DONE: |
| 906 | handleNullReturnEvent(msg, "nvWriteItem"); |
| 907 | break; |
| 908 | |
| 909 | case CMD_NV_WRITE_CDMA_PRL: |
| 910 | request = (MainThreadRequest) msg.obj; |
| 911 | onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 912 | defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 913 | break; |
| 914 | |
| 915 | case EVENT_NV_WRITE_CDMA_PRL_DONE: |
| 916 | handleNullReturnEvent(msg, "nvWriteCdmaPrl"); |
| 917 | break; |
| 918 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 919 | case CMD_RESET_MODEM_CONFIG: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 920 | request = (MainThreadRequest) msg.obj; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 921 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 922 | defaultPhone.resetModemConfig(onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 923 | break; |
| 924 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 925 | case EVENT_RESET_MODEM_CONFIG_DONE: |
| 926 | handleNullReturnEvent(msg, "resetModemConfig"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 927 | break; |
| 928 | |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 929 | case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: { |
| 930 | request = (MainThreadRequest) msg.obj; |
| 931 | onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE, |
| 932 | request); |
| 933 | Phone phone = getPhoneFromRequest(request); |
| 934 | if (phone != null) { |
| 935 | phone.isNrDualConnectivityEnabled(onCompleted, request.workSource); |
| 936 | } else { |
| 937 | loge("isNRDualConnectivityEnabled: No phone object"); |
| 938 | request.result = false; |
| 939 | notifyRequester(request); |
| 940 | } |
| 941 | break; |
| 942 | } |
| 943 | |
| 944 | case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE: |
| 945 | ar = (AsyncResult) msg.obj; |
| 946 | request = (MainThreadRequest) ar.userObj; |
| 947 | if (ar.exception == null && ar.result != null) { |
| 948 | request.result = ar.result; |
| 949 | } else { |
| 950 | // request.result must be set to something non-null |
| 951 | // for the calling thread to unblock |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 952 | if (ar.result != null) { |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 953 | request.result = ar.result; |
| 954 | } else { |
| 955 | request.result = false; |
| 956 | } |
| 957 | if (ar.result == null) { |
| 958 | loge("isNRDualConnectivityEnabled: Empty response"); |
| 959 | } else if (ar.exception instanceof CommandException) { |
| 960 | loge("isNRDualConnectivityEnabled: CommandException: " |
| 961 | + ar.exception); |
| 962 | } else { |
| 963 | loge("isNRDualConnectivityEnabled: Unknown exception"); |
| 964 | } |
| 965 | } |
| 966 | notifyRequester(request); |
| 967 | break; |
| 968 | |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 969 | case CMD_IS_VONR_ENABLED: { |
| 970 | request = (MainThreadRequest) msg.obj; |
| 971 | onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE, |
| 972 | request); |
| 973 | Phone phone = getPhoneFromRequest(request); |
| 974 | if (phone != null) { |
| 975 | phone.isVoNrEnabled(onCompleted, request.workSource); |
| 976 | } else { |
| 977 | loge("isVoNrEnabled: No phone object"); |
| 978 | request.result = false; |
| 979 | notifyRequester(request); |
| 980 | } |
| 981 | break; |
| 982 | } |
| 983 | |
| 984 | case EVENT_IS_VONR_ENABLED_DONE: |
| 985 | ar = (AsyncResult) msg.obj; |
| 986 | request = (MainThreadRequest) ar.userObj; |
| 987 | if (ar.exception == null && ar.result != null) { |
| 988 | request.result = ar.result; |
| 989 | } else { |
| 990 | // request.result must be set to something non-null |
| 991 | // for the calling thread to unblock |
| 992 | if (ar.result != null) { |
| 993 | request.result = ar.result; |
| 994 | } else { |
| 995 | request.result = false; |
| 996 | } |
| 997 | if (ar.result == null) { |
| 998 | loge("isVoNrEnabled: Empty response"); |
| 999 | } else if (ar.exception instanceof CommandException) { |
| 1000 | loge("isVoNrEnabled: CommandException: " |
| 1001 | + ar.exception); |
| 1002 | } else { |
| 1003 | loge("isVoNrEnabled: Unknown exception"); |
| 1004 | } |
| 1005 | } |
| 1006 | notifyRequester(request); |
| 1007 | break; |
| 1008 | |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 1009 | case CMD_ENABLE_NR_DUAL_CONNECTIVITY: { |
| 1010 | request = (MainThreadRequest) msg.obj; |
| 1011 | onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request); |
| 1012 | Phone phone = getPhoneFromRequest(request); |
| 1013 | if (phone != null) { |
| 1014 | phone.setNrDualConnectivityState((int) request.argument, onCompleted, |
| 1015 | request.workSource); |
| 1016 | } else { |
| 1017 | loge("enableNrDualConnectivity: No phone object"); |
| 1018 | request.result = |
| 1019 | TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE; |
| 1020 | notifyRequester(request); |
| 1021 | } |
| 1022 | break; |
| 1023 | } |
| 1024 | |
| 1025 | case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: { |
| 1026 | ar = (AsyncResult) msg.obj; |
| 1027 | request = (MainThreadRequest) ar.userObj; |
| 1028 | if (ar.exception == null) { |
| 1029 | request.result = |
| 1030 | TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS; |
| 1031 | } else { |
| 1032 | request.result = |
| 1033 | TelephonyManager |
| 1034 | .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR; |
| 1035 | if (ar.exception instanceof CommandException) { |
| 1036 | CommandException.Error error = |
| 1037 | ((CommandException) (ar.exception)).getCommandError(); |
| 1038 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1039 | request.result = |
| 1040 | TelephonyManager |
| 1041 | .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE; |
Sooraj Sasindran | 2965416 | 2021-03-03 23:00:01 +0000 | [diff] [blame] | 1042 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1043 | request.result = |
| 1044 | TelephonyManager |
| 1045 | .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED; |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 1046 | } |
| 1047 | loge("enableNrDualConnectivity" + ": CommandException: " |
| 1048 | + ar.exception); |
| 1049 | } else { |
| 1050 | loge("enableNrDualConnectivity" + ": Unknown exception"); |
| 1051 | } |
| 1052 | } |
| 1053 | notifyRequester(request); |
| 1054 | break; |
| 1055 | } |
| 1056 | |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 1057 | case CMD_ENABLE_VONR: { |
| 1058 | request = (MainThreadRequest) msg.obj; |
| 1059 | onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request); |
| 1060 | Phone phone = getPhoneFromRequest(request); |
| 1061 | if (phone != null) { |
| 1062 | phone.setVoNrEnabled((boolean) request.argument, onCompleted, |
| 1063 | request.workSource); |
| 1064 | } else { |
| 1065 | loge("setVoNrEnabled: No phone object"); |
| 1066 | request.result = |
| 1067 | TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE; |
| 1068 | notifyRequester(request); |
| 1069 | } |
| 1070 | break; |
| 1071 | } |
| 1072 | |
| 1073 | case EVENT_ENABLE_VONR_DONE: { |
| 1074 | ar = (AsyncResult) msg.obj; |
| 1075 | request = (MainThreadRequest) ar.userObj; |
| 1076 | if (ar.exception == null) { |
| 1077 | request.result = TelephonyManager.ENABLE_VONR_SUCCESS; |
| 1078 | } else { |
| 1079 | request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR; |
| 1080 | if (ar.exception instanceof CommandException) { |
| 1081 | CommandException.Error error = |
| 1082 | ((CommandException) (ar.exception)).getCommandError(); |
| 1083 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1084 | request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE; |
| 1085 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1086 | request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED; |
| 1087 | } else { |
| 1088 | request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR; |
| 1089 | } |
| 1090 | loge("setVoNrEnabled" + ": CommandException: " |
| 1091 | + ar.exception); |
| 1092 | } else { |
| 1093 | loge("setVoNrEnabled" + ": Unknown exception"); |
| 1094 | } |
| 1095 | } |
| 1096 | notifyRequester(request); |
| 1097 | break; |
| 1098 | } |
| 1099 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1100 | case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1101 | request = (MainThreadRequest) msg.obj; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1102 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE, |
| 1103 | request); |
| 1104 | getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1105 | break; |
| 1106 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1107 | case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1108 | ar = (AsyncResult) msg.obj; |
| 1109 | request = (MainThreadRequest) ar.userObj; |
| 1110 | if (ar.exception == null && ar.result != null) { |
| 1111 | request.result = ar.result; // Integer |
| 1112 | } else { |
Nazish Tabassum | e8ba43a | 2020-07-28 14:49:25 +0530 | [diff] [blame] | 1113 | // request.result must be set to something non-null |
| 1114 | // for the calling thread to unblock |
| 1115 | request.result = new int[]{-1}; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1116 | if (ar.result == null) { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1117 | loge("getAllowedNetworkTypesBitmask: Empty response"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1118 | } else if (ar.exception instanceof CommandException) { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1119 | loge("getAllowedNetworkTypesBitmask: CommandException: " |
| 1120 | + ar.exception); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1121 | } else { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1122 | loge("getAllowedNetworkTypesBitmask: Unknown exception"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1123 | } |
| 1124 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1125 | notifyRequester(request); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1126 | break; |
| 1127 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1128 | case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1129 | request = (MainThreadRequest) msg.obj; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1130 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE, |
| 1131 | request); |
| 1132 | Pair<Integer, Long> reasonWithNetworkTypes = |
| 1133 | (Pair<Integer, Long>) request.argument; |
| 1134 | getPhoneFromRequest(request).setAllowedNetworkTypes( |
| 1135 | reasonWithNetworkTypes.first, |
| 1136 | reasonWithNetworkTypes.second, |
| 1137 | onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1138 | break; |
| 1139 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1140 | case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE: |
| 1141 | handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1142 | break; |
| 1143 | |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 1144 | case CMD_INVOKE_OEM_RIL_REQUEST_RAW: |
| 1145 | request = (MainThreadRequest)msg.obj; |
| 1146 | onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1147 | defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 1148 | break; |
| 1149 | |
| 1150 | case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE: |
| 1151 | ar = (AsyncResult)msg.obj; |
| 1152 | request = (MainThreadRequest)ar.userObj; |
| 1153 | request.result = ar; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1154 | notifyRequester(request); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 1155 | break; |
| 1156 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1157 | case CMD_SET_VOICEMAIL_NUMBER: |
| 1158 | request = (MainThreadRequest) msg.obj; |
| 1159 | onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request); |
| 1160 | Pair<String, String> tagNum = (Pair<String, String>) request.argument; |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1161 | getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second, |
| 1162 | onCompleted); |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1163 | break; |
| 1164 | |
| 1165 | case EVENT_SET_VOICEMAIL_NUMBER_DONE: |
| 1166 | handleNullReturnEvent(msg, "setVoicemailNumber"); |
| 1167 | break; |
| 1168 | |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 1169 | case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC: |
| 1170 | request = (MainThreadRequest) msg.obj; |
| 1171 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE, |
| 1172 | request); |
| 1173 | getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted); |
| 1174 | break; |
| 1175 | |
| 1176 | case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE: |
| 1177 | handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic"); |
| 1178 | break; |
| 1179 | |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1180 | case CMD_PERFORM_NETWORK_SCAN: |
| 1181 | request = (MainThreadRequest) msg.obj; |
| 1182 | onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request); |
| 1183 | getPhoneFromRequest(request).getAvailableNetworks(onCompleted); |
| 1184 | break; |
| 1185 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1186 | case CMD_GET_CALL_FORWARDING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1187 | request = (MainThreadRequest) msg.obj; |
| 1188 | onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1189 | Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args = |
| 1190 | (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>) |
| 1191 | request.argument; |
| 1192 | int callForwardingReason = args.first; |
| 1193 | request.phone.getCallForwardingOption(callForwardingReason, onCompleted); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1194 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1195 | } |
| 1196 | case EVENT_GET_CALL_FORWARDING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1197 | ar = (AsyncResult) msg.obj; |
| 1198 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1199 | TelephonyManager.CallForwardingInfoCallback callback = |
| 1200 | ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>) |
| 1201 | request.argument).second; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1202 | if (ar.exception == null && ar.result != null) { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1203 | CallForwardingInfo callForwardingInfo = null; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1204 | CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result; |
| 1205 | for (CallForwardInfo callForwardInfo : callForwardInfos) { |
| 1206 | // Service Class is a bit mask per 3gpp 27.007. Search for |
| 1207 | // any service for voice call. |
| 1208 | if ((callForwardInfo.serviceClass |
| 1209 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0) { |
Yuchen Dong | 69cc141 | 2021-09-27 20:27:01 +0800 | [diff] [blame] | 1210 | callForwardingInfo = new CallForwardingInfo( |
| 1211 | callForwardInfo.status |
| 1212 | == CommandsInterface.CF_ACTION_ENABLE, |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1213 | callForwardInfo.reason, |
| 1214 | callForwardInfo.number, |
| 1215 | callForwardInfo.timeSeconds); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1216 | break; |
| 1217 | } |
| 1218 | } |
| 1219 | // Didn't find a call forward info for voice call. |
| 1220 | if (callForwardingInfo == null) { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1221 | callForwardingInfo = new CallForwardingInfo(false /* enabled */, |
| 1222 | 0 /* reason */, null /* number */, 0 /* timeout */); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1223 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1224 | callback.onCallForwardingInfoAvailable(callForwardingInfo); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1225 | } else { |
| 1226 | if (ar.result == null) { |
| 1227 | loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response"); |
| 1228 | } |
| 1229 | if (ar.exception != null) { |
| 1230 | loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception); |
| 1231 | } |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1232 | int errorCode = TelephonyManager |
| 1233 | .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1234 | if (ar.exception instanceof CommandException) { |
| 1235 | CommandException.Error error = |
| 1236 | ((CommandException) (ar.exception)).getCommandError(); |
| 1237 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1238 | errorCode = TelephonyManager |
| 1239 | .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1240 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1241 | errorCode = TelephonyManager |
| 1242 | .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1243 | } |
| 1244 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1245 | callback.onError(errorCode); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1246 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1247 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1248 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1249 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1250 | case CMD_SET_CALL_FORWARDING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1251 | request = (MainThreadRequest) msg.obj; |
| 1252 | onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1253 | request = (MainThreadRequest) msg.obj; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1254 | CallForwardingInfo callForwardingInfoToSet = |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1255 | ((Pair<CallForwardingInfo, Consumer<Integer>>) |
| 1256 | request.argument).first; |
| 1257 | request.phone.setCallForwardingOption( |
| 1258 | callForwardingInfoToSet.isEnabled() |
Calvin Pan | 258f1f7 | 2021-07-28 21:46:56 +0800 | [diff] [blame] | 1259 | ? CommandsInterface.CF_ACTION_REGISTRATION |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1260 | : CommandsInterface.CF_ACTION_DISABLE, |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1261 | callForwardingInfoToSet.getReason(), |
| 1262 | callForwardingInfoToSet.getNumber(), |
| 1263 | callForwardingInfoToSet.getTimeoutSeconds(), onCompleted); |
| 1264 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1265 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1266 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1267 | case EVENT_SET_CALL_FORWARDING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1268 | ar = (AsyncResult) msg.obj; |
| 1269 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1270 | Consumer<Integer> callback = |
| 1271 | ((Pair<CallForwardingInfo, Consumer<Integer>>) |
| 1272 | request.argument).second; |
| 1273 | if (ar.exception != null) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1274 | loge("setCallForwarding exception: " + ar.exception); |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1275 | int errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1276 | .RESULT_ERROR_UNKNOWN; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1277 | if (ar.exception instanceof CommandException) { |
| 1278 | CommandException.Error error = |
| 1279 | ((CommandException) (ar.exception)).getCommandError(); |
| 1280 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1281 | errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1282 | .RESULT_ERROR_FDN_CHECK_FAILURE; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1283 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1284 | errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1285 | .RESULT_ERROR_NOT_SUPPORTED; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1286 | } |
| 1287 | } |
| 1288 | callback.accept(errorCode); |
| 1289 | } else { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1290 | callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1291 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1292 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1293 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1294 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1295 | case CMD_GET_CALL_WAITING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1296 | request = (MainThreadRequest) msg.obj; |
| 1297 | onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request); |
| 1298 | getPhoneFromRequest(request).getCallWaiting(onCompleted); |
| 1299 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1300 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1301 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1302 | case EVENT_GET_CALL_WAITING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1303 | ar = (AsyncResult) msg.obj; |
| 1304 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1305 | Consumer<Integer> callback = (Consumer<Integer>) request.argument; |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1306 | int callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1307 | if (ar.exception == null && ar.result != null) { |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1308 | int[] callForwardResults = (int[]) ar.result; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1309 | // Service Class is a bit mask per 3gpp 27.007. |
| 1310 | // Search for any service for voice call. |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1311 | if (callForwardResults.length > 1 |
| 1312 | && ((callForwardResults[1] |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1313 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) { |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1314 | callWaitingStatus = callForwardResults[0] == 0 |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1315 | ? TelephonyManager.CALL_WAITING_STATUS_DISABLED |
| 1316 | : TelephonyManager.CALL_WAITING_STATUS_ENABLED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1317 | } else { |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1318 | callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1319 | } |
| 1320 | } else { |
| 1321 | if (ar.result == null) { |
| 1322 | loge("EVENT_GET_CALL_WAITING_DONE: Empty response"); |
| 1323 | } |
| 1324 | if (ar.exception != null) { |
| 1325 | loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception); |
| 1326 | } |
| 1327 | if (ar.exception instanceof CommandException) { |
| 1328 | CommandException.Error error = |
| 1329 | ((CommandException) (ar.exception)).getCommandError(); |
| 1330 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1331 | callWaitingStatus = |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1332 | TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED; |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1333 | } else if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
| 1334 | callWaitingStatus = |
| 1335 | TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1336 | } |
| 1337 | } |
| 1338 | } |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1339 | callback.accept(callWaitingStatus); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1340 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1341 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1342 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1343 | case CMD_SET_CALL_WAITING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1344 | request = (MainThreadRequest) msg.obj; |
| 1345 | onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1346 | boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first; |
| 1347 | getPhoneFromRequest(request).setCallWaiting(enable, onCompleted); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1348 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1349 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1350 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1351 | case EVENT_SET_CALL_WAITING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1352 | ar = (AsyncResult) msg.obj; |
| 1353 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1354 | boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first; |
| 1355 | Consumer<Integer> callback = |
| 1356 | ((Pair<Boolean, Consumer<Integer>>) request.argument).second; |
| 1357 | if (ar.exception != null) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1358 | loge("setCallWaiting exception: " + ar.exception); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1359 | if (ar.exception instanceof CommandException) { |
| 1360 | CommandException.Error error = |
| 1361 | ((CommandException) (ar.exception)).getCommandError(); |
| 1362 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1363 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED); |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1364 | } else if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
| 1365 | callback.accept( |
| 1366 | TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1367 | } else { |
| 1368 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 1369 | } |
| 1370 | } else { |
| 1371 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 1372 | } |
| 1373 | } else { |
| 1374 | callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED |
| 1375 | : TelephonyManager.CALL_WAITING_STATUS_DISABLED); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1376 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1377 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1378 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1379 | case EVENT_PERFORM_NETWORK_SCAN_DONE: |
| 1380 | ar = (AsyncResult) msg.obj; |
| 1381 | request = (MainThreadRequest) ar.userObj; |
| 1382 | CellNetworkScanResult cellScanResult; |
| 1383 | if (ar.exception == null && ar.result != null) { |
| 1384 | cellScanResult = new CellNetworkScanResult( |
| 1385 | CellNetworkScanResult.STATUS_SUCCESS, |
| 1386 | (List<OperatorInfo>) ar.result); |
| 1387 | } else { |
| 1388 | if (ar.result == null) { |
| 1389 | loge("getCellNetworkScanResults: Empty response"); |
| 1390 | } |
| 1391 | if (ar.exception != null) { |
| 1392 | loge("getCellNetworkScanResults: Exception: " + ar.exception); |
| 1393 | } |
| 1394 | int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR; |
| 1395 | if (ar.exception instanceof CommandException) { |
| 1396 | CommandException.Error error = |
| 1397 | ((CommandException) (ar.exception)).getCommandError(); |
| 1398 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1399 | errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE; |
| 1400 | } else if (error == CommandException.Error.GENERIC_FAILURE) { |
| 1401 | errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE; |
| 1402 | } |
| 1403 | } |
| 1404 | cellScanResult = new CellNetworkScanResult(errorCode, null); |
| 1405 | } |
| 1406 | request.result = cellScanResult; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1407 | notifyRequester(request); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1408 | break; |
| 1409 | |
| 1410 | case CMD_SET_NETWORK_SELECTION_MODE_MANUAL: |
| 1411 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1412 | ManualNetworkSelectionArgument selArg = |
| 1413 | (ManualNetworkSelectionArgument) request.argument; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1414 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE, |
| 1415 | request); |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1416 | getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo, |
| 1417 | selArg.persistSelection, onCompleted); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1418 | break; |
| 1419 | |
| 1420 | case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE: |
Pengquan Meng | e3d01e2 | 2018-09-20 15:25:35 -0700 | [diff] [blame] | 1421 | ar = (AsyncResult) msg.obj; |
| 1422 | request = (MainThreadRequest) ar.userObj; |
| 1423 | if (ar.exception == null) { |
| 1424 | request.result = true; |
| 1425 | } else { |
| 1426 | request.result = false; |
| 1427 | loge("setNetworkSelectionModeManual " + ar.exception); |
| 1428 | } |
| 1429 | notifyRequester(request); |
| 1430 | mApp.onNetworkSelectionChanged(request.subId); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1431 | break; |
| 1432 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1433 | case CMD_GET_MODEM_ACTIVITY_INFO: |
| 1434 | request = (MainThreadRequest) msg.obj; |
| 1435 | onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1436 | if (defaultPhone != null) { |
| 1437 | defaultPhone.getModemActivityInfo(onCompleted, request.workSource); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1438 | } else { |
| 1439 | ResultReceiver result = (ResultReceiver) request.argument; |
| 1440 | Bundle bundle = new Bundle(); |
| 1441 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 1442 | new ModemActivityInfo(0, 0, 0, |
| 1443 | new int[ModemActivityInfo.getNumTxPowerLevels()], 0)); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1444 | result.send(0, bundle); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1445 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1446 | break; |
| 1447 | |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1448 | case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: { |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1449 | ar = (AsyncResult) msg.obj; |
| 1450 | request = (MainThreadRequest) ar.userObj; |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1451 | ResultReceiver result = (ResultReceiver) request.argument; |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1452 | int error = 0; |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 1453 | ModemActivityInfo ret = null; |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1454 | if (mLastModemActivityInfo == null) { |
| 1455 | mLastModemActivitySpecificInfo = new ActivityStatsTechSpecificInfo[1]; |
| 1456 | mLastModemActivitySpecificInfo[0] = |
| 1457 | new ActivityStatsTechSpecificInfo( |
| 1458 | 0, |
| 1459 | 0, |
| 1460 | new int[ModemActivityInfo.getNumTxPowerLevels()], |
| 1461 | 0); |
| 1462 | mLastModemActivityInfo = |
| 1463 | new ModemActivityInfo(0, 0, 0, mLastModemActivitySpecificInfo); |
| 1464 | } |
| 1465 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1466 | if (ar.exception == null && ar.result != null) { |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1467 | // Update the last modem activity info and the result of the request. |
| 1468 | ModemActivityInfo info = (ModemActivityInfo) ar.result; |
| 1469 | if (isModemActivityInfoValid(info)) { |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1470 | mergeModemActivityInfo(info); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1471 | } |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 1472 | // This is needed to decouple ret from mLastModemActivityInfo |
| 1473 | // We don't want to return mLastModemActivityInfo which is updated |
| 1474 | // inside mergeModemActivityInfo() |
| 1475 | ret = new ModemActivityInfo( |
| 1476 | mLastModemActivityInfo.getTimestampMillis(), |
| 1477 | mLastModemActivityInfo.getSleepTimeMillis(), |
| 1478 | mLastModemActivityInfo.getIdleTimeMillis(), |
| 1479 | deepCopyModemActivitySpecificInfo(mLastModemActivitySpecificInfo)); |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1480 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1481 | } else { |
| 1482 | if (ar.result == null) { |
| 1483 | loge("queryModemActivityInfo: Empty response"); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1484 | error = TelephonyManager.ModemActivityInfoException |
| 1485 | .ERROR_INVALID_INFO_RECEIVED; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1486 | } else if (ar.exception instanceof CommandException) { |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1487 | loge("queryModemActivityInfo: CommandException: " + ar.exception); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1488 | error = TelephonyManager.ModemActivityInfoException |
| 1489 | .ERROR_MODEM_RESPONSE_ERROR; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1490 | } else { |
| 1491 | loge("queryModemActivityInfo: Unknown exception"); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1492 | error = TelephonyManager.ModemActivityInfoException |
| 1493 | .ERROR_UNKNOWN; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1494 | } |
| 1495 | } |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1496 | Bundle bundle = new Bundle(); |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 1497 | if (ret != null) { |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1498 | bundle.putParcelable( |
| 1499 | TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 1500 | ret); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1501 | } else { |
| 1502 | bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error); |
| 1503 | } |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1504 | result.send(0, bundle); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1505 | notifyRequester(request); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1506 | break; |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1507 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1508 | |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1509 | case CMD_SET_ALLOWED_CARRIERS: |
| 1510 | request = (MainThreadRequest) msg.obj; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1511 | CarrierRestrictionRules argument = |
| 1512 | (CarrierRestrictionRules) request.argument; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1513 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request); |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1514 | defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1515 | break; |
| 1516 | |
| 1517 | case EVENT_SET_ALLOWED_CARRIERS_DONE: |
| 1518 | ar = (AsyncResult) msg.obj; |
| 1519 | request = (MainThreadRequest) ar.userObj; |
| 1520 | if (ar.exception == null && ar.result != null) { |
| 1521 | request.result = ar.result; |
| 1522 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1523 | request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR; |
| 1524 | if (ar.exception instanceof CommandException) { |
| 1525 | loge("setAllowedCarriers: CommandException: " + ar.exception); |
| 1526 | CommandException.Error error = |
| 1527 | ((CommandException) (ar.exception)).getCommandError(); |
| 1528 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1529 | request.result = |
| 1530 | TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED; |
| 1531 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1532 | } else { |
| 1533 | loge("setAllowedCarriers: Unknown exception"); |
| 1534 | } |
| 1535 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1536 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1537 | break; |
| 1538 | |
| 1539 | case CMD_GET_ALLOWED_CARRIERS: |
| 1540 | request = (MainThreadRequest) msg.obj; |
| 1541 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1542 | defaultPhone.getAllowedCarriers(onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1543 | break; |
| 1544 | |
| 1545 | case EVENT_GET_ALLOWED_CARRIERS_DONE: |
| 1546 | ar = (AsyncResult) msg.obj; |
| 1547 | request = (MainThreadRequest) ar.userObj; |
| 1548 | if (ar.exception == null && ar.result != null) { |
| 1549 | request.result = ar.result; |
| 1550 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1551 | request.result = new IllegalStateException( |
| 1552 | "Failed to get carrier restrictions"); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1553 | if (ar.result == null) { |
| 1554 | loge("getAllowedCarriers: Empty response"); |
| 1555 | } else if (ar.exception instanceof CommandException) { |
| 1556 | loge("getAllowedCarriers: CommandException: " + |
| 1557 | ar.exception); |
| 1558 | } else { |
| 1559 | loge("getAllowedCarriers: Unknown exception"); |
| 1560 | } |
| 1561 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1562 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1563 | break; |
| 1564 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1565 | case EVENT_GET_FORBIDDEN_PLMNS_DONE: |
| 1566 | ar = (AsyncResult) msg.obj; |
| 1567 | request = (MainThreadRequest) ar.userObj; |
| 1568 | if (ar.exception == null && ar.result != null) { |
| 1569 | request.result = ar.result; |
| 1570 | } else { |
| 1571 | request.result = new IllegalArgumentException( |
| 1572 | "Failed to retrieve Forbidden Plmns"); |
| 1573 | if (ar.result == null) { |
| 1574 | loge("getForbiddenPlmns: Empty response"); |
| 1575 | } else { |
| 1576 | loge("getForbiddenPlmns: Unknown exception"); |
| 1577 | } |
| 1578 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1579 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1580 | break; |
| 1581 | |
| 1582 | case CMD_GET_FORBIDDEN_PLMNS: |
| 1583 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1584 | uiccPort = getUiccPortFromRequest(request); |
| 1585 | if (uiccPort == null) { |
| 1586 | loge("getForbiddenPlmns() UiccPort is null"); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1587 | request.result = new IllegalArgumentException( |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1588 | "getForbiddenPlmns() UiccPort is null"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1589 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1590 | break; |
| 1591 | } |
| 1592 | Integer appType = (Integer) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1593 | UiccCardApplication uiccApp = uiccPort.getApplicationByType(appType); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1594 | if (uiccApp == null) { |
| 1595 | loge("getForbiddenPlmns() no app with specified type -- " |
| 1596 | + appType); |
| 1597 | request.result = new IllegalArgumentException("Failed to get UICC App"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1598 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1599 | break; |
| 1600 | } else { |
| 1601 | if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid() |
| 1602 | + " specified type -- " + appType); |
| 1603 | } |
| 1604 | onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request); |
| 1605 | ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns( |
| 1606 | onCompleted); |
| 1607 | break; |
| 1608 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1609 | case CMD_SWITCH_SLOTS: |
| 1610 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 1611 | List<UiccSlotMapping> slotMapping = (List<UiccSlotMapping>) request.argument; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1612 | onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 1613 | UiccController.getInstance().switchSlots(slotMapping, onCompleted); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1614 | break; |
| 1615 | |
| 1616 | case EVENT_SWITCH_SLOTS_DONE: |
| 1617 | ar = (AsyncResult) msg.obj; |
| 1618 | request = (MainThreadRequest) ar.userObj; |
| 1619 | request.result = (ar.exception == null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1620 | notifyRequester(request); |
| 1621 | break; |
| 1622 | case CMD_GET_NETWORK_SELECTION_MODE: |
| 1623 | request = (MainThreadRequest) msg.obj; |
| 1624 | onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request); |
| 1625 | getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted); |
| 1626 | break; |
| 1627 | |
| 1628 | case EVENT_GET_NETWORK_SELECTION_MODE_DONE: |
| 1629 | ar = (AsyncResult) msg.obj; |
| 1630 | request = (MainThreadRequest) ar.userObj; |
| 1631 | if (ar.exception != null) { |
| 1632 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 1633 | } else { |
| 1634 | int mode = ((int[]) ar.result)[0]; |
| 1635 | if (mode == 0) { |
| 1636 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO; |
| 1637 | } else { |
| 1638 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL; |
| 1639 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1640 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1641 | notifyRequester(request); |
| 1642 | break; |
| 1643 | case CMD_GET_CDMA_ROAMING_MODE: |
| 1644 | request = (MainThreadRequest) msg.obj; |
| 1645 | onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request); |
| 1646 | getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted); |
| 1647 | break; |
| 1648 | case EVENT_GET_CDMA_ROAMING_MODE_DONE: |
| 1649 | ar = (AsyncResult) msg.obj; |
| 1650 | request = (MainThreadRequest) ar.userObj; |
| 1651 | if (ar.exception != null) { |
| 1652 | request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT; |
| 1653 | } else { |
| 1654 | request.result = ((int[]) ar.result)[0]; |
| 1655 | } |
| 1656 | notifyRequester(request); |
| 1657 | break; |
| 1658 | case CMD_SET_CDMA_ROAMING_MODE: |
| 1659 | request = (MainThreadRequest) msg.obj; |
| 1660 | onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request); |
| 1661 | int mode = (int) request.argument; |
| 1662 | getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted); |
| 1663 | break; |
| 1664 | case EVENT_SET_CDMA_ROAMING_MODE_DONE: |
| 1665 | ar = (AsyncResult) msg.obj; |
| 1666 | request = (MainThreadRequest) ar.userObj; |
| 1667 | request.result = ar.exception == null; |
| 1668 | notifyRequester(request); |
| 1669 | break; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 1670 | case CMD_GET_CDMA_SUBSCRIPTION_MODE: |
| 1671 | request = (MainThreadRequest) msg.obj; |
| 1672 | onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1673 | getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted); |
| 1674 | break; |
| 1675 | case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1676 | ar = (AsyncResult) msg.obj; |
| 1677 | request = (MainThreadRequest) ar.userObj; |
| 1678 | if (ar.exception != null) { |
| 1679 | request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM; |
| 1680 | } else { |
| 1681 | request.result = ((int[]) ar.result)[0]; |
| 1682 | } |
| 1683 | notifyRequester(request); |
| 1684 | break; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1685 | case CMD_SET_CDMA_SUBSCRIPTION_MODE: |
| 1686 | request = (MainThreadRequest) msg.obj; |
| 1687 | onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1688 | int subscriptionMode = (int) request.argument; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 1689 | getPhoneFromRequest(request).setCdmaSubscriptionMode( |
| 1690 | subscriptionMode, onCompleted); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1691 | break; |
| 1692 | case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1693 | ar = (AsyncResult) msg.obj; |
| 1694 | request = (MainThreadRequest) ar.userObj; |
| 1695 | request.result = ar.exception == null; |
| 1696 | notifyRequester(request); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1697 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1698 | case CMD_GET_ALL_CELL_INFO: |
| 1699 | request = (MainThreadRequest) msg.obj; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1700 | onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1701 | request.phone.requestCellInfoUpdate(request.workSource, onCompleted); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1702 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1703 | case EVENT_GET_ALL_CELL_INFO_DONE: |
| 1704 | ar = (AsyncResult) msg.obj; |
| 1705 | request = (MainThreadRequest) ar.userObj; |
Nathan Harold | 8d0f174 | 2018-10-02 12:14:47 -0700 | [diff] [blame] | 1706 | // If a timeout occurs, the response will be null |
| 1707 | request.result = (ar.exception == null && ar.result != null) |
| 1708 | ? ar.result : new ArrayList<CellInfo>(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1709 | synchronized (request) { |
| 1710 | request.notifyAll(); |
| 1711 | } |
| 1712 | break; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1713 | case CMD_REQUEST_CELL_INFO_UPDATE: |
| 1714 | request = (MainThreadRequest) msg.obj; |
| 1715 | request.phone.requestCellInfoUpdate(request.workSource, |
| 1716 | obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request)); |
| 1717 | break; |
| 1718 | case EVENT_REQUEST_CELL_INFO_UPDATE_DONE: |
| 1719 | ar = (AsyncResult) msg.obj; |
| 1720 | request = (MainThreadRequest) ar.userObj; |
| 1721 | ICellInfoCallback cb = (ICellInfoCallback) request.argument; |
| 1722 | try { |
| 1723 | if (ar.exception != null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1724 | Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception); |
Meng Wang | d8921f4 | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1725 | cb.onError( |
| 1726 | TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR, |
| 1727 | ar.exception.getClass().getName(), |
| 1728 | ar.exception.toString()); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1729 | } else if (ar.result == null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1730 | Log.w(LOG_TAG, "Timeout Waiting for CellInfo!"); |
Meng Wang | d8921f4 | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1731 | cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1732 | } else { |
| 1733 | // use the result as returned |
| 1734 | cb.onCellInfo((List<CellInfo>) ar.result); |
| 1735 | } |
| 1736 | } catch (RemoteException re) { |
| 1737 | Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException"); |
| 1738 | } |
| 1739 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1740 | case CMD_GET_CELL_LOCATION: { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1741 | request = (MainThreadRequest) msg.obj; |
| 1742 | WorkSource ws = (WorkSource) request.argument; |
| 1743 | Phone phone = getPhoneFromRequest(request); |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1744 | phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request)); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1745 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1746 | } |
| 1747 | case EVENT_GET_CELL_LOCATION_DONE: { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1748 | ar = (AsyncResult) msg.obj; |
| 1749 | request = (MainThreadRequest) ar.userObj; |
| 1750 | if (ar.exception == null) { |
| 1751 | request.result = ar.result; |
| 1752 | } else { |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1753 | Phone phone = getPhoneFromRequest(request); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1754 | request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1755 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1756 | } |
| 1757 | |
| 1758 | synchronized (request) { |
| 1759 | request.notifyAll(); |
| 1760 | } |
| 1761 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1762 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1763 | case CMD_MODEM_REBOOT: |
| 1764 | request = (MainThreadRequest) msg.obj; |
| 1765 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1766 | defaultPhone.rebootModem(onCompleted); |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1767 | break; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1768 | case EVENT_CMD_MODEM_REBOOT_DONE: |
| 1769 | handleNullReturnEvent(msg, "rebootModem"); |
| 1770 | break; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1771 | case CMD_REQUEST_ENABLE_MODEM: |
| 1772 | request = (MainThreadRequest) msg.obj; |
| 1773 | boolean enable = (boolean) request.argument; |
| 1774 | onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1775 | onCompleted.arg1 = enable ? 1 : 0; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1776 | PhoneConfigurationManager.getInstance() |
| 1777 | .enablePhone(request.phone, enable, onCompleted); |
| 1778 | break; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1779 | case EVENT_ENABLE_MODEM_DONE: { |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1780 | ar = (AsyncResult) msg.obj; |
| 1781 | request = (MainThreadRequest) ar.userObj; |
| 1782 | request.result = (ar.exception == null); |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1783 | int phoneId = request.phone.getPhoneId(); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1784 | //update the cache as modem status has changed |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1785 | if ((boolean) request.result) { |
| 1786 | mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1); |
| 1787 | updateModemStateMetrics(); |
| 1788 | } else { |
| 1789 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1790 | + ar.exception); |
| 1791 | } |
| 1792 | notifyRequester(request); |
| 1793 | break; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1794 | } |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1795 | case CMD_GET_MODEM_STATUS: |
| 1796 | request = (MainThreadRequest) msg.obj; |
| 1797 | onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request); |
| 1798 | PhoneConfigurationManager.getInstance() |
| 1799 | .getPhoneStatusFromModem(request.phone, onCompleted); |
| 1800 | break; |
| 1801 | case EVENT_GET_MODEM_STATUS_DONE: |
| 1802 | ar = (AsyncResult) msg.obj; |
| 1803 | request = (MainThreadRequest) ar.userObj; |
| 1804 | int id = request.phone.getPhoneId(); |
| 1805 | if (ar.exception == null && ar.result != null) { |
| 1806 | request.result = ar.result; |
| 1807 | //update the cache as modem status has changed |
| 1808 | mPhoneConfigurationManager.addToPhoneStatusCache(id, |
| 1809 | (boolean) request.result); |
| 1810 | } else { |
| 1811 | // Return true if modem status cannot be retrieved. For most cases, |
| 1812 | // modem status is on. And for older version modems, GET_MODEM_STATUS |
| 1813 | // and disable modem are not supported. Modem is always on. |
| 1814 | // TODO: this should be fixed in R to support a third |
| 1815 | // status UNKNOWN b/131631629 |
| 1816 | request.result = true; |
| 1817 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1818 | + ar.exception); |
| 1819 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1820 | notifyRequester(request); |
| 1821 | break; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 1822 | case CMD_SET_SYSTEM_SELECTION_CHANNELS: { |
| 1823 | request = (MainThreadRequest) msg.obj; |
| 1824 | onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request); |
| 1825 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 1826 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 1827 | request.phone.setSystemSelectionChannels(args.first, onCompleted); |
| 1828 | break; |
| 1829 | } |
| 1830 | case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: { |
| 1831 | ar = (AsyncResult) msg.obj; |
| 1832 | request = (MainThreadRequest) ar.userObj; |
| 1833 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 1834 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 1835 | args.second.accept(ar.exception == null); |
| 1836 | notifyRequester(request); |
| 1837 | break; |
| 1838 | } |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1839 | case CMD_GET_SYSTEM_SELECTION_CHANNELS: { |
| 1840 | request = (MainThreadRequest) msg.obj; |
| 1841 | onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request); |
| 1842 | Phone phone = getPhoneFromRequest(request); |
| 1843 | if (phone != null) { |
| 1844 | phone.getSystemSelectionChannels(onCompleted); |
| 1845 | } else { |
| 1846 | loge("getSystemSelectionChannels: No phone object"); |
| 1847 | request.result = new ArrayList<RadioAccessSpecifier>(); |
| 1848 | notifyRequester(request); |
| 1849 | } |
| 1850 | break; |
| 1851 | } |
| 1852 | case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE: |
| 1853 | ar = (AsyncResult) msg.obj; |
| 1854 | request = (MainThreadRequest) ar.userObj; |
| 1855 | if (ar.exception == null && ar.result != null) { |
| 1856 | request.result = ar.result; |
| 1857 | } else { |
Sarah Chin | 428d1d6 | 2021-03-13 03:17:40 -0800 | [diff] [blame] | 1858 | request.result = new IllegalStateException( |
| 1859 | "Failed to retrieve system selecton channels"); |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1860 | if (ar.result == null) { |
| 1861 | loge("getSystemSelectionChannels: Empty response"); |
| 1862 | } else { |
| 1863 | loge("getSystemSelectionChannels: Unknown exception"); |
| 1864 | } |
| 1865 | } |
| 1866 | notifyRequester(request); |
| 1867 | break; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1868 | case EVENT_SET_FORBIDDEN_PLMNS_DONE: |
| 1869 | ar = (AsyncResult) msg.obj; |
| 1870 | request = (MainThreadRequest) ar.userObj; |
| 1871 | if (ar.exception == null && ar.result != null) { |
| 1872 | request.result = ar.result; |
| 1873 | } else { |
| 1874 | request.result = -1; |
| 1875 | loge("Failed to set Forbidden Plmns"); |
| 1876 | if (ar.result == null) { |
| 1877 | loge("setForbidenPlmns: Empty response"); |
| 1878 | } else if (ar.exception != null) { |
| 1879 | loge("setForbiddenPlmns: Exception: " + ar.exception); |
| 1880 | request.result = -1; |
| 1881 | } else { |
| 1882 | loge("setForbiddenPlmns: Unknown exception"); |
| 1883 | } |
| 1884 | } |
| 1885 | notifyRequester(request); |
| 1886 | break; |
| 1887 | case CMD_SET_FORBIDDEN_PLMNS: |
| 1888 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1889 | uiccPort = getUiccPortFromRequest(request); |
| 1890 | if (uiccPort == null) { |
| 1891 | loge("setForbiddenPlmns: UiccPort is null"); |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1892 | request.result = -1; |
| 1893 | notifyRequester(request); |
| 1894 | break; |
| 1895 | } |
| 1896 | Pair<Integer, List<String>> setFplmnsArgs = |
| 1897 | (Pair<Integer, List<String>>) request.argument; |
| 1898 | appType = setFplmnsArgs.first; |
| 1899 | List<String> fplmns = setFplmnsArgs.second; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1900 | uiccApp = uiccPort.getApplicationByType(appType); |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1901 | if (uiccApp == null) { |
| 1902 | loge("setForbiddenPlmns: no app with specified type -- " + appType); |
| 1903 | request.result = -1; |
| 1904 | loge("Failed to get UICC App"); |
| 1905 | notifyRequester(request); |
| 1906 | } else { |
| 1907 | onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request); |
| 1908 | ((SIMRecords) uiccApp.getIccRecords()) |
| 1909 | .setForbiddenPlmns(onCompleted, fplmns); |
| 1910 | } |
yinchengzhao | 4d163c0 | 2019-12-12 15:21:47 -0800 | [diff] [blame] | 1911 | break; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 1912 | case CMD_ERASE_MODEM_CONFIG: |
| 1913 | request = (MainThreadRequest) msg.obj; |
| 1914 | onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request); |
| 1915 | defaultPhone.eraseModemConfig(onCompleted); |
| 1916 | break; |
| 1917 | case EVENT_ERASE_MODEM_CONFIG_DONE: |
| 1918 | handleNullReturnEvent(msg, "eraseModemConfig"); |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1919 | break; |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1920 | |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 1921 | case CMD_ERASE_DATA_SHARED_PREFERENCES: |
| 1922 | request = (MainThreadRequest) msg.obj; |
| 1923 | request.result = defaultPhone.eraseDataInSharedPreferences(); |
| 1924 | notifyRequester(request); |
| 1925 | break; |
| 1926 | |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1927 | case CMD_CHANGE_ICC_LOCK_PASSWORD: |
| 1928 | request = (MainThreadRequest) msg.obj; |
| 1929 | onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request); |
| 1930 | Pair<String, String> changed = (Pair<String, String>) request.argument; |
| 1931 | getPhoneFromRequest(request).getIccCard().changeIccLockPassword( |
| 1932 | changed.first, changed.second, onCompleted); |
| 1933 | break; |
| 1934 | case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE: |
| 1935 | ar = (AsyncResult) msg.obj; |
| 1936 | request = (MainThreadRequest) ar.userObj; |
| 1937 | if (ar.exception == null) { |
| 1938 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1939 | // If the operation is successful, update the PIN storage |
| 1940 | Pair<String, String> passwords = (Pair<String, String>) request.argument; |
| 1941 | int phoneId = getPhoneFromRequest(request).getPhoneId(); |
Jon Spivack | 9c3bc76 | 2021-10-06 20:53:09 +0000 | [diff] [blame] | 1942 | UiccController.getInstance().getPinStorage() |
| 1943 | .storePin(passwords.second, phoneId); |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1944 | } else { |
| 1945 | request.result = msg.arg1; |
| 1946 | } |
| 1947 | notifyRequester(request); |
| 1948 | break; |
| 1949 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1950 | case CMD_SET_ICC_LOCK_ENABLED: { |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1951 | request = (MainThreadRequest) msg.obj; |
| 1952 | onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request); |
| 1953 | Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument; |
| 1954 | getPhoneFromRequest(request).getIccCard().setIccLockEnabled( |
| 1955 | enabled.first, enabled.second, onCompleted); |
| 1956 | break; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1957 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1958 | case EVENT_SET_ICC_LOCK_ENABLED_DONE: |
| 1959 | ar = (AsyncResult) msg.obj; |
| 1960 | request = (MainThreadRequest) ar.userObj; |
| 1961 | if (ar.exception == null) { |
| 1962 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1963 | // If the operation is successful, update the PIN storage |
| 1964 | Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument; |
| 1965 | int phoneId = getPhoneFromRequest(request).getPhoneId(); |
| 1966 | if (enabled.first) { |
Jon Spivack | 9c3bc76 | 2021-10-06 20:53:09 +0000 | [diff] [blame] | 1967 | UiccController.getInstance().getPinStorage() |
| 1968 | .storePin(enabled.second, phoneId); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1969 | } else { |
| 1970 | UiccController.getInstance().getPinStorage().clearPin(phoneId); |
| 1971 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1972 | } else { |
| 1973 | request.result = msg.arg1; |
| 1974 | } |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1975 | |
| 1976 | |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1977 | notifyRequester(request); |
| 1978 | break; |
| 1979 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 1980 | case MSG_NOTIFY_USER_ACTIVITY: |
| 1981 | removeMessages(MSG_NOTIFY_USER_ACTIVITY); |
Peter Wang | 59571be | 2020-01-27 12:35:15 +0800 | [diff] [blame] | 1982 | Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION); |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 1983 | intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY); |
| 1984 | getDefaultPhone().getContext().sendBroadcastAsUser( |
| 1985 | intent, UserHandle.ALL, permission.USER_ACTIVITY); |
| 1986 | break; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 1987 | |
| 1988 | case CMD_SET_DATA_THROTTLING: { |
| 1989 | request = (MainThreadRequest) msg.obj; |
| 1990 | onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request); |
| 1991 | DataThrottlingRequest dataThrottlingRequest = |
| 1992 | (DataThrottlingRequest) request.argument; |
| 1993 | Phone phone = getPhoneFromRequest(request); |
| 1994 | if (phone != null) { |
| 1995 | phone.setDataThrottling(onCompleted, |
| 1996 | request.workSource, dataThrottlingRequest.getDataThrottlingAction(), |
| 1997 | dataThrottlingRequest.getCompletionDurationMillis()); |
| 1998 | } else { |
| 1999 | loge("setDataThrottling: No phone object"); |
| 2000 | request.result = |
| 2001 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 2002 | notifyRequester(request); |
| 2003 | } |
| 2004 | |
| 2005 | break; |
| 2006 | } |
| 2007 | case EVENT_SET_DATA_THROTTLING_DONE: |
| 2008 | ar = (AsyncResult) msg.obj; |
| 2009 | request = (MainThreadRequest) ar.userObj; |
| 2010 | |
| 2011 | if (ar.exception == null) { |
| 2012 | request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 2013 | } else if (ar.exception instanceof CommandException) { |
| 2014 | loge("setDataThrottling: CommandException: " + ar.exception); |
| 2015 | CommandException.Error error = |
| 2016 | ((CommandException) (ar.exception)).getCommandError(); |
| 2017 | |
| 2018 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 2019 | request.result = TelephonyManager |
| 2020 | .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 2021 | } else if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 2022 | request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS; |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 2023 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 2024 | request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 2025 | } else { |
| 2026 | request.result = |
| 2027 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 2028 | } |
| 2029 | } else { |
| 2030 | request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 2031 | } |
| 2032 | Log.w(LOG_TAG, "DataThrottlingResult = " + request.result); |
| 2033 | notifyRequester(request); |
| 2034 | break; |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 2035 | |
| 2036 | case CMD_SET_SIM_POWER: { |
| 2037 | request = (MainThreadRequest) msg.obj; |
| 2038 | onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request); |
| 2039 | request = (MainThreadRequest) msg.obj; |
| 2040 | int stateToSet = |
| 2041 | ((Pair<Integer, IIntegerConsumer>) |
| 2042 | request.argument).first; |
| 2043 | request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource); |
| 2044 | break; |
| 2045 | } |
| 2046 | case EVENT_SET_SIM_POWER_DONE: { |
| 2047 | ar = (AsyncResult) msg.obj; |
| 2048 | request = (MainThreadRequest) ar.userObj; |
| 2049 | IIntegerConsumer callback = |
| 2050 | ((Pair<Integer, IIntegerConsumer>) request.argument).second; |
| 2051 | if (ar.exception != null) { |
| 2052 | loge("setSimPower exception: " + ar.exception); |
| 2053 | int errorCode = TelephonyManager.CallForwardingInfoCallback |
| 2054 | .RESULT_ERROR_UNKNOWN; |
| 2055 | if (ar.exception instanceof CommandException) { |
| 2056 | CommandException.Error error = |
| 2057 | ((CommandException) (ar.exception)).getCommandError(); |
| 2058 | if (error == CommandException.Error.SIM_ERR) { |
| 2059 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR; |
| 2060 | } else if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 2061 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE; |
| 2062 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 2063 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED; |
| 2064 | } else { |
| 2065 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR; |
| 2066 | } |
| 2067 | } |
| 2068 | try { |
| 2069 | callback.accept(errorCode); |
| 2070 | } catch (RemoteException e) { |
| 2071 | // Ignore if the remote process is no longer available to call back. |
| 2072 | Log.w(LOG_TAG, "setSimPower: callback not available."); |
| 2073 | } |
| 2074 | } else { |
| 2075 | try { |
| 2076 | callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS); |
| 2077 | } catch (RemoteException e) { |
| 2078 | // Ignore if the remote process is no longer available to call back. |
| 2079 | Log.w(LOG_TAG, "setSimPower: callback not available."); |
| 2080 | } |
| 2081 | } |
| 2082 | break; |
| 2083 | } |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 2084 | case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: { |
| 2085 | request = (MainThreadRequest) msg.obj; |
| 2086 | |
| 2087 | final Phone phone = getPhoneFromRequest(request); |
| 2088 | if (phone == null || phone.getServiceStateTracker() == null) { |
| 2089 | request.result = new IllegalStateException("Phone or SST is null"); |
| 2090 | notifyRequester(request); |
| 2091 | break; |
| 2092 | } |
| 2093 | |
| 2094 | Pair<Integer, SignalStrengthUpdateRequest> pair = |
| 2095 | (Pair<Integer, SignalStrengthUpdateRequest>) request.argument; |
| 2096 | onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE, |
| 2097 | request); |
Rambo Wang | 6568f17 | 2021-02-03 16:56:47 -0800 | [diff] [blame] | 2098 | phone.getSignalStrengthController().setSignalStrengthUpdateRequest( |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 2099 | request.subId, pair.first /*callingUid*/, |
| 2100 | pair.second /*request*/, onCompleted); |
| 2101 | break; |
| 2102 | } |
| 2103 | case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: { |
| 2104 | ar = (AsyncResult) msg.obj; |
| 2105 | request = (MainThreadRequest) ar.userObj; |
| 2106 | // request.result will be the exception of ar if present, true otherwise. |
| 2107 | // Be cautious not to leave result null which will wait() forever |
| 2108 | request.result = ar.exception != null ? ar.exception : true; |
| 2109 | notifyRequester(request); |
| 2110 | break; |
| 2111 | } |
| 2112 | case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: { |
| 2113 | request = (MainThreadRequest) msg.obj; |
| 2114 | |
| 2115 | Phone phone = getPhoneFromRequest(request); |
| 2116 | if (phone == null || phone.getServiceStateTracker() == null) { |
| 2117 | request.result = new IllegalStateException("Phone or SST is null"); |
| 2118 | notifyRequester(request); |
| 2119 | break; |
| 2120 | } |
| 2121 | |
| 2122 | Pair<Integer, SignalStrengthUpdateRequest> pair = |
| 2123 | (Pair<Integer, SignalStrengthUpdateRequest>) request.argument; |
| 2124 | onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE, |
| 2125 | request); |
Rambo Wang | 6568f17 | 2021-02-03 16:56:47 -0800 | [diff] [blame] | 2126 | phone.getSignalStrengthController().clearSignalStrengthUpdateRequest( |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 2127 | request.subId, pair.first /*callingUid*/, |
| 2128 | pair.second /*request*/, onCompleted); |
| 2129 | break; |
| 2130 | } |
| 2131 | case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: { |
| 2132 | ar = (AsyncResult) msg.obj; |
| 2133 | request = (MainThreadRequest) ar.userObj; |
| 2134 | request.result = ar.exception != null ? ar.exception : true; |
| 2135 | notifyRequester(request); |
| 2136 | break; |
| 2137 | } |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 2138 | |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2139 | case CMD_GET_SLICING_CONFIG: { |
| 2140 | request = (MainThreadRequest) msg.obj; |
| 2141 | onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request); |
| 2142 | request.phone.getSlicingConfig(onCompleted); |
| 2143 | break; |
| 2144 | } |
| 2145 | case EVENT_GET_SLICING_CONFIG_DONE: { |
| 2146 | ar = (AsyncResult) msg.obj; |
| 2147 | request = (MainThreadRequest) ar.userObj; |
| 2148 | ResultReceiver result = (ResultReceiver) request.argument; |
| 2149 | |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2150 | NetworkSlicingConfig slicingConfig = null; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2151 | Bundle bundle = new Bundle(); |
| 2152 | int resultCode = 0; |
| 2153 | if (ar.exception != null) { |
| 2154 | Log.e(LOG_TAG, "Exception retrieving slicing configuration=" |
| 2155 | + ar.exception); |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2156 | resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2157 | } else if (ar.result == null) { |
| 2158 | Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!"); |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2159 | resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2160 | } else { |
| 2161 | // use the result as returned |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2162 | resultCode = TelephonyManager.NetworkSlicingException.SUCCESS; |
| 2163 | slicingConfig = (NetworkSlicingConfig) ar.result; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2164 | } |
| 2165 | |
| 2166 | if (slicingConfig == null) { |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2167 | slicingConfig = new NetworkSlicingConfig(); |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2168 | } |
| 2169 | bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig); |
| 2170 | result.send(resultCode, bundle); |
| 2171 | notifyRequester(request); |
| 2172 | break; |
| 2173 | } |
| 2174 | |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2175 | case CMD_PURCHASE_PREMIUM_CAPABILITY: { |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2176 | request = (MainThreadRequest) msg.obj; |
| 2177 | onCompleted = obtainMessage(EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE, request); |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2178 | PurchasePremiumCapabilityArgument arg = |
| 2179 | (PurchasePremiumCapabilityArgument) request.argument; |
Sarah Chin | 46355ba | 2022-11-01 23:51:16 -0700 | [diff] [blame] | 2180 | SlicePurchaseController.getInstance(request.phone).purchasePremiumCapability( |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2181 | arg.capability, arg.appName, onCompleted); |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2182 | break; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2183 | } |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2184 | |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2185 | case EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE: { |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2186 | ar = (AsyncResult) msg.obj; |
| 2187 | request = (MainThreadRequest) ar.userObj; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2188 | PurchasePremiumCapabilityArgument arg = |
| 2189 | (PurchasePremiumCapabilityArgument) request.argument; |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2190 | try { |
| 2191 | int result = (int) ar.result; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2192 | arg.callback.accept(result); |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2193 | log("purchasePremiumCapability: capability=" |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2194 | + TelephonyManager.convertPremiumCapabilityToString(arg.capability) |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2195 | + ", result= " |
| 2196 | + TelephonyManager.convertPurchaseResultToString(result)); |
| 2197 | } catch (RemoteException e) { |
| 2198 | String logStr = "Purchase premium capability " |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2199 | + TelephonyManager.convertPremiumCapabilityToString(arg.capability) |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2200 | + " failed: " + e; |
| 2201 | if (DBG) log(logStr); |
| 2202 | AnomalyReporter.reportAnomaly( |
| 2203 | UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr); |
| 2204 | } |
| 2205 | break; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2206 | } |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2207 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2208 | case CMD_PREPARE_UNATTENDED_REBOOT: |
| 2209 | request = (MainThreadRequest) msg.obj; |
| 2210 | request.result = |
Rafael Higuera Silva | d963064 | 2021-09-20 15:32:01 +0000 | [diff] [blame] | 2211 | UiccController.getInstance().getPinStorage() |
| 2212 | .prepareUnattendedReboot(request.workSource); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2213 | notifyRequester(request); |
| 2214 | break; |
| 2215 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2216 | default: |
| 2217 | Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what); |
| 2218 | break; |
| 2219 | } |
| 2220 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2221 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 2222 | private void notifyRequester(MainThreadRequest request) { |
| 2223 | synchronized (request) { |
| 2224 | request.notifyAll(); |
| 2225 | } |
| 2226 | } |
| 2227 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2228 | private void handleNullReturnEvent(Message msg, String command) { |
| 2229 | AsyncResult ar = (AsyncResult) msg.obj; |
| 2230 | MainThreadRequest request = (MainThreadRequest) ar.userObj; |
| 2231 | if (ar.exception == null) { |
| 2232 | request.result = true; |
| 2233 | } else { |
| 2234 | request.result = false; |
| 2235 | if (ar.exception instanceof CommandException) { |
| 2236 | loge(command + ": CommandException: " + ar.exception); |
| 2237 | } else { |
| 2238 | loge(command + ": Unknown exception"); |
| 2239 | } |
| 2240 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 2241 | notifyRequester(request); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2242 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2243 | } |
| 2244 | |
| 2245 | /** |
| 2246 | * Posts the specified command to be executed on the main thread, |
| 2247 | * waits for the request to complete, and returns the result. |
| 2248 | * @see #sendRequestAsync |
| 2249 | */ |
| 2250 | private Object sendRequest(int command, Object argument) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2251 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, |
| 2252 | null, -1 /*timeoutInMs*/); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 2253 | } |
| 2254 | |
| 2255 | /** |
| 2256 | * Posts the specified command to be executed on the main thread, |
| 2257 | * waits for the request to complete, and returns the result. |
| 2258 | * @see #sendRequestAsync |
| 2259 | */ |
| 2260 | private Object sendRequest(int command, Object argument, WorkSource workSource) { |
| 2261 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2262 | null, workSource, -1 /*timeoutInMs*/); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2263 | } |
| 2264 | |
| 2265 | /** |
| 2266 | * Posts the specified command to be executed on the main thread, |
| 2267 | * waits for the request to complete, and returns the result. |
| 2268 | * @see #sendRequestAsync |
| 2269 | */ |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2270 | private Object sendRequest(int command, Object argument, Integer subId) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2271 | return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/); |
| 2272 | } |
| 2273 | |
| 2274 | /** |
| 2275 | * Posts the specified command to be executed on the main thread, |
| 2276 | * waits for the request to complete for at most {@code timeoutInMs}, and returns the result |
| 2277 | * if not timeout or null otherwise. |
| 2278 | * @see #sendRequestAsync |
| 2279 | */ |
| 2280 | private @Nullable Object sendRequest(int command, Object argument, Integer subId, |
| 2281 | long timeoutInMs) { |
| 2282 | return sendRequest(command, argument, subId, null, null, timeoutInMs); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 2283 | } |
| 2284 | |
| 2285 | /** |
| 2286 | * Posts the specified command to be executed on the main thread, |
| 2287 | * waits for the request to complete, and returns the result. |
| 2288 | * @see #sendRequestAsync |
| 2289 | */ |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2290 | private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2291 | return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2292 | } |
| 2293 | |
| 2294 | /** |
| 2295 | * Posts the specified command to be executed on the main thread, |
| 2296 | * waits for the request to complete, and returns the result. |
| 2297 | * @see #sendRequestAsync |
| 2298 | */ |
| 2299 | private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2300 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, |
| 2301 | workSource, -1 /*timeoutInMs*/); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2302 | } |
| 2303 | |
| 2304 | /** |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2305 | * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is |
| 2306 | * negative, waits for the request to complete, and returns the result. Otherwise, wait for |
| 2307 | * maximum of {@code timeoutInMs} milliseconds, interrupt and return null. |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2308 | * @see #sendRequestAsync |
| 2309 | */ |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2310 | private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone, |
| 2311 | WorkSource workSource, long timeoutInMs) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2312 | if (Looper.myLooper() == mMainThreadHandler.getLooper()) { |
| 2313 | throw new RuntimeException("This method will deadlock if called from the main thread."); |
| 2314 | } |
| 2315 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2316 | MainThreadRequest request = null; |
| 2317 | if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) { |
| 2318 | throw new IllegalArgumentException("subId and phone cannot both be specified!"); |
| 2319 | } else if (phone != null) { |
| 2320 | request = new MainThreadRequest(argument, phone, workSource); |
| 2321 | } else { |
| 2322 | request = new MainThreadRequest(argument, subId, workSource); |
| 2323 | } |
| 2324 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2325 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 2326 | msg.sendToTarget(); |
| 2327 | |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2328 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2329 | synchronized (request) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2330 | if (timeoutInMs >= 0) { |
| 2331 | // Wait for at least timeoutInMs before returning null request result |
| 2332 | long now = SystemClock.elapsedRealtime(); |
| 2333 | long deadline = now + timeoutInMs; |
Grace Jia | 8a0a1e8 | 2021-05-23 22:59:52 -0700 | [diff] [blame] | 2334 | while (request.result == null && now < deadline) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2335 | try { |
| 2336 | request.wait(deadline - now); |
| 2337 | } catch (InterruptedException e) { |
| 2338 | // Do nothing, go back and check if request is completed or timeout |
| 2339 | } finally { |
| 2340 | now = SystemClock.elapsedRealtime(); |
| 2341 | } |
| 2342 | } |
| 2343 | } else { |
| 2344 | // Wait for the request to complete |
| 2345 | while (request.result == null) { |
| 2346 | try { |
| 2347 | request.wait(); |
| 2348 | } catch (InterruptedException e) { |
| 2349 | // Do nothing, go back and wait until the request is complete |
| 2350 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2351 | } |
| 2352 | } |
| 2353 | } |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2354 | if (request.result == null) { |
| 2355 | Log.wtf(LOG_TAG, |
| 2356 | "sendRequest: Blocking command timed out. Something has gone terribly wrong."); |
| 2357 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2358 | return request.result; |
| 2359 | } |
| 2360 | |
| 2361 | /** |
| 2362 | * Asynchronous ("fire and forget") version of sendRequest(): |
| 2363 | * Posts the specified command to be executed on the main thread, and |
| 2364 | * returns immediately. |
| 2365 | * @see #sendRequest |
| 2366 | */ |
| 2367 | private void sendRequestAsync(int command) { |
| 2368 | mMainThreadHandler.sendEmptyMessage(command); |
| 2369 | } |
| 2370 | |
| 2371 | /** |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2372 | * Same as {@link #sendRequestAsync(int)} except it takes an argument. |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2373 | * @see {@link #sendRequest(int)} |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2374 | */ |
| 2375 | private void sendRequestAsync(int command, Object argument) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2376 | sendRequestAsync(command, argument, null, null); |
| 2377 | } |
| 2378 | |
| 2379 | /** |
| 2380 | * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource. |
| 2381 | * @see {@link #sendRequest(int,Object)} |
| 2382 | */ |
| 2383 | private void sendRequestAsync( |
| 2384 | int command, Object argument, Phone phone, WorkSource workSource) { |
| 2385 | MainThreadRequest request = new MainThreadRequest(argument, phone, workSource); |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2386 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 2387 | msg.sendToTarget(); |
| 2388 | } |
| 2389 | |
| 2390 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2391 | * Initialize the singleton PhoneInterfaceManager instance. |
| 2392 | * This is only done once, at startup, from PhoneApp.onCreate(). |
| 2393 | */ |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2394 | /* package */ static PhoneInterfaceManager init(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2395 | synchronized (PhoneInterfaceManager.class) { |
| 2396 | if (sInstance == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2397 | sInstance = new PhoneInterfaceManager(app); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2398 | } else { |
| 2399 | Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance); |
| 2400 | } |
| 2401 | return sInstance; |
| 2402 | } |
| 2403 | } |
| 2404 | |
| 2405 | /** Private constructor; @see init() */ |
Jordan Liu | 1979a04 | 2020-03-20 21:39:35 +0000 | [diff] [blame] | 2406 | private PhoneInterfaceManager(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2407 | mApp = app; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2408 | mCM = PhoneGlobals.getInstance().mCM; |
Brad Ebinger | d1947d8 | 2021-05-17 20:54:49 +0000 | [diff] [blame] | 2409 | mImsResolver = ImsResolver.getInstance(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 2410 | mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2411 | mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 2412 | mPm = app.getSystemService(PackageManager.class); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2413 | mMainThreadHandler = new MainThreadHandler(); |
Aishwarya Mallampati | 32336e8 | 2023-01-04 23:02:56 +0000 | [diff] [blame] | 2414 | mSubscriptionController = SubscriptionController.getInstance(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2415 | mTelephonySharedPreferences = |
| 2416 | PreferenceManager.getDefaultSharedPreferences(mApp); |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 2417 | mNetworkScanRequestTracker = new NetworkScanRequestTracker(); |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 2418 | mPhoneConfigurationManager = PhoneConfigurationManager.getInstance(); |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 2419 | mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance(); |
Peter Wang | a3cf4ac | 2020-01-27 09:39:46 +0800 | [diff] [blame] | 2420 | mNotifyUserActivity = new AtomicBoolean(false); |
Tyler Gunn | 64144d9 | 2022-03-17 14:16:41 -0700 | [diff] [blame] | 2421 | PropertyInvalidatedCache.invalidateCache(TelephonyManager.CACHE_KEY_PHONE_ACCOUNT_TO_SUBID); |
Gil Cukierman | 6dac5eb | 2022-09-19 16:09:04 +0000 | [diff] [blame] | 2422 | mTelephony2gUpdater = new Telephony2gUpdater( |
| 2423 | Executors.newSingleThreadExecutor(), mApp); |
| 2424 | mTelephony2gUpdater.init(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2425 | publish(); |
| 2426 | } |
| 2427 | |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 2428 | @VisibleForTesting |
| 2429 | public SharedPreferences getSharedPreferences() { |
| 2430 | return mTelephonySharedPreferences; |
| 2431 | } |
| 2432 | |
Gil Cukierman | 92cc7db | 2023-01-06 19:25:53 +0000 | [diff] [blame] | 2433 | /** |
| 2434 | * Get the default phone for this device. |
| 2435 | */ |
| 2436 | @VisibleForTesting |
| 2437 | public Phone getDefaultPhone() { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2438 | Phone thePhone = getPhone(getDefaultSubscription()); |
| 2439 | return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone(); |
| 2440 | } |
| 2441 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2442 | private void publish() { |
| 2443 | if (DBG) log("publish: " + this); |
| 2444 | |
Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 2445 | TelephonyFrameworkInitializer |
| 2446 | .getTelephonyServiceManager() |
| 2447 | .getTelephonyServiceRegisterer() |
| 2448 | .register(this); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2449 | } |
| 2450 | |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 2451 | private Phone getPhoneFromRequest(MainThreadRequest request) { |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 2452 | if (request.phone != null) { |
| 2453 | return request.phone; |
| 2454 | } else { |
| 2455 | return getPhoneFromSubId(request.subId); |
| 2456 | } |
| 2457 | } |
| 2458 | |
| 2459 | private Phone getPhoneFromSubId(int subId) { |
| 2460 | return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) |
| 2461 | ? getDefaultPhone() : getPhone(subId); |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 2462 | } |
| 2463 | |
Rambo Wang | e53e07d | 2022-05-10 13:01:13 -0700 | [diff] [blame] | 2464 | @Nullable |
| 2465 | private UiccPort getUiccPortFromRequest(@NonNull MainThreadRequest request) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2466 | Phone phone = getPhoneFromRequest(request); |
| 2467 | return phone == null ? null : |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 2468 | UiccController.getInstance().getUiccPort(phone.getPhoneId()); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2469 | } |
| 2470 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2471 | // returns phone associated with the subId. |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2472 | private Phone getPhone(int subId) { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 2473 | return PhoneFactory.getPhone(SubscriptionManager.getPhoneId(subId)); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2474 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2475 | |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 2476 | private void sendEraseModemConfig(@NonNull Phone phone) { |
| 2477 | Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null); |
| 2478 | if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 2479 | } |
| 2480 | |
| 2481 | private void sendEraseDataInSharedPreferences(@NonNull Phone phone) { |
| 2482 | Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null); |
| 2483 | if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail")); |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 2484 | } |
| 2485 | |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 2486 | private boolean isImsAvailableOnDevice() { |
| 2487 | PackageManager pm = getDefaultPhone().getContext().getPackageManager(); |
| 2488 | if (pm == null) { |
| 2489 | // For some reason package manger is not available.. This will fail internally anyway, |
| 2490 | // so do not throw error and allow. |
| 2491 | return true; |
| 2492 | } |
| 2493 | return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0); |
| 2494 | } |
| 2495 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2496 | public void dial(String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2497 | dialForSubscriber(getPreferredVoiceSubscription(), number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2498 | } |
| 2499 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2500 | public void dialForSubscriber(int subId, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2501 | if (DBG) log("dial: " + number); |
| 2502 | // No permission check needed here: This is just a wrapper around the |
| 2503 | // ACTION_DIAL intent, which is available to any app since it puts up |
| 2504 | // the UI before it does anything. |
| 2505 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2506 | final long identity = Binder.clearCallingIdentity(); |
| 2507 | try { |
| 2508 | String url = createTelUrl(number); |
| 2509 | if (url == null) { |
| 2510 | return; |
| 2511 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2512 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2513 | // PENDING: should we just silently fail if phone is offhook or ringing? |
| 2514 | PhoneConstants.State state = mCM.getState(subId); |
| 2515 | if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) { |
| 2516 | Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url)); |
| 2517 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2518 | mApp.startActivity(intent); |
| 2519 | } |
| 2520 | } finally { |
| 2521 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2522 | } |
| 2523 | } |
| 2524 | |
| 2525 | public void call(String callingPackage, String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2526 | callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2527 | } |
| 2528 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2529 | public void callForSubscriber(int subId, String callingPackage, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2530 | if (DBG) log("call: " + number); |
| 2531 | |
| 2532 | // This is just a wrapper around the ACTION_CALL intent, but we still |
| 2533 | // need to do a permission check since we're calling startActivity() |
| 2534 | // from the context of the phone app. |
| 2535 | enforceCallPermission(); |
| 2536 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 2537 | if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage) |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2538 | != AppOpsManager.MODE_ALLOWED) { |
| 2539 | return; |
| 2540 | } |
| 2541 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2542 | final long identity = Binder.clearCallingIdentity(); |
| 2543 | try { |
| 2544 | String url = createTelUrl(number); |
| 2545 | if (url == null) { |
| 2546 | return; |
| 2547 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2548 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2549 | boolean isValid = false; |
| 2550 | final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged(); |
| 2551 | if (slist != null) { |
| 2552 | for (SubscriptionInfo subInfoRecord : slist) { |
| 2553 | if (subInfoRecord.getSubscriptionId() == subId) { |
| 2554 | isValid = true; |
| 2555 | break; |
| 2556 | } |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 2557 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 2558 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2559 | if (!isValid) { |
| 2560 | return; |
| 2561 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 2562 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2563 | Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url)); |
| 2564 | intent.putExtra(SUBSCRIPTION_KEY, subId); |
| 2565 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2566 | mApp.startActivity(intent); |
| 2567 | } finally { |
| 2568 | Binder.restoreCallingIdentity(identity); |
| 2569 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2570 | } |
| 2571 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2572 | public boolean supplyPinForSubscriber(int subId, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2573 | int [] resultArray = supplyPinReportResultForSubscriber(subId, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2574 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 2575 | } |
| 2576 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2577 | public boolean supplyPukForSubscriber(int subId, String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2578 | int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2579 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 2580 | } |
| 2581 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2582 | public int[] supplyPinReportResultForSubscriber(int subId, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2583 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2584 | |
| 2585 | final long identity = Binder.clearCallingIdentity(); |
| 2586 | try { |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2587 | Phone phone = getPhone(subId); |
| 2588 | final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2589 | checkSimPin.start(); |
| 2590 | return checkSimPin.unlockSim(null, pin); |
| 2591 | } finally { |
| 2592 | Binder.restoreCallingIdentity(identity); |
| 2593 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2594 | } |
| 2595 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2596 | public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2597 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2598 | |
| 2599 | final long identity = Binder.clearCallingIdentity(); |
| 2600 | try { |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2601 | Phone phone = getPhone(subId); |
| 2602 | final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2603 | checkSimPuk.start(); |
| 2604 | return checkSimPuk.unlockSim(puk, pin); |
| 2605 | } finally { |
| 2606 | Binder.restoreCallingIdentity(identity); |
| 2607 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2608 | } |
| 2609 | |
| 2610 | /** |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2611 | * Helper thread to turn async call to SimCard#supplyPin into |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2612 | * a synchronous one. |
| 2613 | */ |
| 2614 | private static class UnlockSim extends Thread { |
| 2615 | |
| 2616 | private final IccCard mSimCard; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2617 | private final int mPhoneId; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2618 | |
| 2619 | private boolean mDone = false; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2620 | private int mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 2621 | private int mRetryCount = -1; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2622 | |
| 2623 | // For replies from SimCard interface |
| 2624 | private Handler mHandler; |
| 2625 | |
| 2626 | // For async handler to identify request type |
| 2627 | private static final int SUPPLY_PIN_COMPLETE = 100; |
| 2628 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2629 | UnlockSim(int phoneId, IccCard simCard) { |
| 2630 | mPhoneId = phoneId; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2631 | mSimCard = simCard; |
| 2632 | } |
| 2633 | |
| 2634 | @Override |
| 2635 | public void run() { |
| 2636 | Looper.prepare(); |
| 2637 | synchronized (UnlockSim.this) { |
| 2638 | mHandler = new Handler() { |
| 2639 | @Override |
| 2640 | public void handleMessage(Message msg) { |
| 2641 | AsyncResult ar = (AsyncResult) msg.obj; |
| 2642 | switch (msg.what) { |
| 2643 | case SUPPLY_PIN_COMPLETE: |
| 2644 | Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE"); |
| 2645 | synchronized (UnlockSim.this) { |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2646 | mRetryCount = msg.arg1; |
| 2647 | if (ar.exception != null) { |
| 2648 | if (ar.exception instanceof CommandException && |
| 2649 | ((CommandException)(ar.exception)).getCommandError() |
| 2650 | == CommandException.Error.PASSWORD_INCORRECT) { |
| 2651 | mResult = PhoneConstants.PIN_PASSWORD_INCORRECT; |
vivi.li | b5e9ada | 2019-09-12 16:04:24 +0800 | [diff] [blame] | 2652 | } //When UiccCardApp dispose,handle message and return exception |
| 2653 | else if (ar.exception instanceof CommandException && |
| 2654 | ((CommandException) (ar.exception)).getCommandError() |
| 2655 | == CommandException.Error.ABORTED) { |
| 2656 | mResult = PhoneConstants.PIN_OPERATION_ABORTED; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2657 | } else { |
| 2658 | mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 2659 | } |
| 2660 | } else { |
| 2661 | mResult = PhoneConstants.PIN_RESULT_SUCCESS; |
| 2662 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2663 | mDone = true; |
| 2664 | UnlockSim.this.notifyAll(); |
| 2665 | } |
| 2666 | break; |
| 2667 | } |
| 2668 | } |
| 2669 | }; |
| 2670 | UnlockSim.this.notifyAll(); |
| 2671 | } |
| 2672 | Looper.loop(); |
| 2673 | } |
| 2674 | |
| 2675 | /* |
| 2676 | * Use PIN or PUK to unlock SIM card |
| 2677 | * |
| 2678 | * If PUK is null, unlock SIM card with PIN |
| 2679 | * |
| 2680 | * If PUK is not null, unlock SIM card with PUK and set PIN code |
| 2681 | */ |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2682 | synchronized int[] unlockSim(String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2683 | |
| 2684 | while (mHandler == null) { |
| 2685 | try { |
| 2686 | wait(); |
| 2687 | } catch (InterruptedException e) { |
| 2688 | Thread.currentThread().interrupt(); |
| 2689 | } |
| 2690 | } |
| 2691 | Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE); |
| 2692 | |
| 2693 | if (puk == null) { |
| 2694 | mSimCard.supplyPin(pin, callback); |
| 2695 | } else { |
| 2696 | mSimCard.supplyPuk(puk, pin, callback); |
| 2697 | } |
| 2698 | |
| 2699 | while (!mDone) { |
| 2700 | try { |
| 2701 | Log.d(LOG_TAG, "wait for done"); |
| 2702 | wait(); |
| 2703 | } catch (InterruptedException e) { |
| 2704 | // Restore the interrupted status |
| 2705 | Thread.currentThread().interrupt(); |
| 2706 | } |
| 2707 | } |
| 2708 | Log.d(LOG_TAG, "done"); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2709 | int[] resultArray = new int[2]; |
| 2710 | resultArray[0] = mResult; |
| 2711 | resultArray[1] = mRetryCount; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2712 | |
| 2713 | if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) { |
Jon Spivack | 9c3bc76 | 2021-10-06 20:53:09 +0000 | [diff] [blame] | 2714 | UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2715 | } |
| 2716 | |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2717 | return resultArray; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2718 | } |
| 2719 | } |
| 2720 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2721 | /** |
| 2722 | * This method has been removed due to privacy and stability concerns. |
| 2723 | */ |
| 2724 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2725 | public void updateServiceLocation() { |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2726 | Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()"); |
| 2727 | return; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2728 | } |
| 2729 | |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2730 | @Override |
| 2731 | public void updateServiceLocationWithPackageName(String callingPackage) { |
| 2732 | mApp.getSystemService(AppOpsManager.class) |
| 2733 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 2734 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 2735 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2736 | if (targetSdk > android.os.Build.VERSION_CODES.R) { |
| 2737 | // Callers targeting S have no business invoking this method. |
| 2738 | return; |
| 2739 | } |
| 2740 | |
| 2741 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2742 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2743 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2744 | .setCallingPackage(callingPackage) |
| 2745 | .setCallingFeatureId(null) |
| 2746 | .setCallingPid(Binder.getCallingPid()) |
| 2747 | .setCallingUid(Binder.getCallingUid()) |
| 2748 | .setMethod("updateServiceLocation") |
| 2749 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
| 2750 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2751 | .build()); |
| 2752 | // Apps that lack location permission have no business calling this method; |
| 2753 | // however, because no permission was declared in the public API, denials must |
| 2754 | // all be "soft". |
| 2755 | switch (locationResult) { |
| 2756 | case DENIED_HARD: /* fall through */ |
| 2757 | case DENIED_SOFT: |
| 2758 | return; |
| 2759 | } |
| 2760 | |
| 2761 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2762 | final long identity = Binder.clearCallingIdentity(); |
| 2763 | try { |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2764 | final Phone phone = getPhone(getDefaultSubscription()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2765 | if (phone != null) { |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2766 | phone.updateServiceLocation(workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2767 | } |
| 2768 | } finally { |
| 2769 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2770 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2771 | } |
| 2772 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2773 | @Deprecated |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2774 | @Override |
| 2775 | public boolean isRadioOn(String callingPackage) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2776 | return isRadioOnWithFeature(callingPackage, null); |
| 2777 | } |
| 2778 | |
| 2779 | |
| 2780 | @Override |
| 2781 | public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) { |
| 2782 | return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage, |
| 2783 | callingFeatureId); |
| 2784 | } |
| 2785 | |
| 2786 | @Deprecated |
| 2787 | @Override |
| 2788 | public boolean isRadioOnForSubscriber(int subId, String callingPackage) { |
| 2789 | return isRadioOnForSubscriberWithFeature(subId, callingPackage, null); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2790 | } |
| 2791 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2792 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2793 | public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage, |
| 2794 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2795 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2796 | mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2797 | return false; |
| 2798 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2799 | |
| 2800 | final long identity = Binder.clearCallingIdentity(); |
| 2801 | try { |
| 2802 | return isRadioOnForSubscriber(subId); |
| 2803 | } finally { |
| 2804 | Binder.restoreCallingIdentity(identity); |
| 2805 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2806 | } |
| 2807 | |
| 2808 | private boolean isRadioOnForSubscriber(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2809 | final long identity = Binder.clearCallingIdentity(); |
| 2810 | try { |
| 2811 | final Phone phone = getPhone(subId); |
| 2812 | if (phone != null) { |
| 2813 | return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF; |
| 2814 | } else { |
| 2815 | return false; |
| 2816 | } |
| 2817 | } finally { |
| 2818 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2819 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2820 | } |
| 2821 | |
| 2822 | public void toggleRadioOnOff() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2823 | toggleRadioOnOffForSubscriber(getDefaultSubscription()); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2824 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2825 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2826 | public void toggleRadioOnOffForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2827 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2828 | |
| 2829 | final long identity = Binder.clearCallingIdentity(); |
| 2830 | try { |
| 2831 | final Phone phone = getPhone(subId); |
| 2832 | if (phone != null) { |
| 2833 | phone.setRadioPower(!isRadioOnForSubscriber(subId)); |
| 2834 | } |
| 2835 | } finally { |
| 2836 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2837 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2838 | } |
| 2839 | |
| 2840 | public boolean setRadio(boolean turnOn) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2841 | return setRadioForSubscriber(getDefaultSubscription(), turnOn); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2842 | } |
| 2843 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2844 | public boolean setRadioForSubscriber(int subId, boolean turnOn) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2845 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2846 | |
| 2847 | final long identity = Binder.clearCallingIdentity(); |
| 2848 | try { |
| 2849 | final Phone phone = getPhone(subId); |
| 2850 | if (phone == null) { |
| 2851 | return false; |
| 2852 | } |
| 2853 | if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) { |
| 2854 | toggleRadioOnOffForSubscriber(subId); |
| 2855 | } |
| 2856 | return true; |
| 2857 | } finally { |
| 2858 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2859 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2860 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2861 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2862 | public boolean needMobileRadioShutdown() { |
Shuo Qian | fa7b6b3 | 2019-12-10 10:40:38 -0800 | [diff] [blame] | 2863 | enforceReadPrivilegedPermission("needMobileRadioShutdown"); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2864 | /* |
| 2865 | * If any of the Radios are available, it will need to be |
| 2866 | * shutdown. So return true if any Radio is available. |
| 2867 | */ |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2868 | final long identity = Binder.clearCallingIdentity(); |
| 2869 | try { |
| 2870 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 2871 | Phone phone = PhoneFactory.getPhone(i); |
| 2872 | if (phone != null && phone.isRadioAvailable()) return true; |
| 2873 | } |
| 2874 | logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown."); |
| 2875 | return false; |
| 2876 | } finally { |
| 2877 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2878 | } |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2879 | } |
| 2880 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2881 | @Override |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2882 | public void shutdownMobileRadios() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2883 | enforceModifyPermission(); |
| 2884 | |
| 2885 | final long identity = Binder.clearCallingIdentity(); |
| 2886 | try { |
| 2887 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 2888 | logv("Shutting down Phone " + i); |
| 2889 | shutdownRadioUsingPhoneId(i); |
| 2890 | } |
| 2891 | } finally { |
| 2892 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2893 | } |
| 2894 | } |
| 2895 | |
| 2896 | private void shutdownRadioUsingPhoneId(int phoneId) { |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2897 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 2898 | if (phone != null && phone.isRadioAvailable()) { |
| 2899 | phone.shutdownRadio(); |
| 2900 | } |
| 2901 | } |
| 2902 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2903 | public boolean setRadioPower(boolean turnOn) { |
Jack Yu | b4e1616 | 2017-05-15 12:48:40 -0700 | [diff] [blame] | 2904 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2905 | |
| 2906 | final long identity = Binder.clearCallingIdentity(); |
| 2907 | try { |
| 2908 | final Phone defaultPhone = PhoneFactory.getDefaultPhone(); |
| 2909 | if (defaultPhone != null) { |
| 2910 | defaultPhone.setRadioPower(turnOn); |
| 2911 | return true; |
| 2912 | } else { |
| 2913 | loge("There's no default phone."); |
| 2914 | return false; |
| 2915 | } |
| 2916 | } finally { |
| 2917 | Binder.restoreCallingIdentity(identity); |
Wei Liu | 9ae2a06 | 2016-08-08 11:09:34 -0700 | [diff] [blame] | 2918 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2919 | } |
| 2920 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2921 | public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2922 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2923 | |
| 2924 | final long identity = Binder.clearCallingIdentity(); |
| 2925 | try { |
| 2926 | final Phone phone = getPhone(subId); |
| 2927 | if (phone != null) { |
| 2928 | phone.setRadioPower(turnOn); |
| 2929 | return true; |
| 2930 | } else { |
| 2931 | return false; |
| 2932 | } |
| 2933 | } finally { |
| 2934 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2935 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2936 | } |
| 2937 | |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 2938 | /** |
| 2939 | * Vote on powering off the radio for a reason. The radio will be turned on only when there is |
| 2940 | * no reason to power it off. When any of the voters want to power it off, it will be turned |
| 2941 | * off. In case of emergency, the radio will be turned on even if there are some reasons for |
| 2942 | * powering it off, and these radio off votes will be cleared. |
| 2943 | * Multiple apps can vote for the same reason and the last vote will take effect. Each app is |
| 2944 | * responsible for its vote. A powering-off vote of a reason will be maintained until it is |
| 2945 | * cleared by calling {@link clearRadioPowerOffForReason} for that reason, or an emergency call |
| 2946 | * is made, or the device is rebooted. When an app comes backup from a crash, it needs to make |
| 2947 | * sure if its vote is as expected. An app can use the API {@link getRadioPowerOffReasons} to |
| 2948 | * check its vote. |
| 2949 | * |
| 2950 | * @param subId The subscription ID. |
| 2951 | * @param reason The reason for powering off radio. |
| 2952 | * @return true on success and false on failure. |
| 2953 | */ |
| 2954 | public boolean requestRadioPowerOffForReason(int subId, |
| 2955 | @TelephonyManager.RadioPowerReason int reason) { |
| 2956 | enforceModifyPermission(); |
| 2957 | |
| 2958 | final long identity = Binder.clearCallingIdentity(); |
| 2959 | try { |
| 2960 | final Phone phone = getPhone(subId); |
| 2961 | if (phone != null) { |
| 2962 | phone.setRadioPowerForReason(false, reason); |
| 2963 | return true; |
| 2964 | } else { |
| 2965 | return false; |
| 2966 | } |
| 2967 | } finally { |
| 2968 | Binder.restoreCallingIdentity(identity); |
| 2969 | } |
| 2970 | } |
| 2971 | |
| 2972 | /** |
| 2973 | * Remove the vote on powering off the radio for a reason, as requested by |
| 2974 | * {@link requestRadioPowerOffForReason}. |
| 2975 | * |
| 2976 | * @param subId The subscription ID. |
| 2977 | * @param reason The reason for powering off radio. |
| 2978 | * @return true on success and false on failure. |
| 2979 | */ |
| 2980 | public boolean clearRadioPowerOffForReason(int subId, |
| 2981 | @TelephonyManager.RadioPowerReason int reason) { |
| 2982 | enforceModifyPermission(); |
| 2983 | |
| 2984 | final long identity = Binder.clearCallingIdentity(); |
| 2985 | try { |
| 2986 | final Phone phone = getPhone(subId); |
| 2987 | if (phone != null) { |
| 2988 | phone.setRadioPowerForReason(true, reason); |
| 2989 | return true; |
| 2990 | } else { |
| 2991 | return false; |
| 2992 | } |
| 2993 | } finally { |
| 2994 | Binder.restoreCallingIdentity(identity); |
| 2995 | } |
| 2996 | } |
| 2997 | |
| 2998 | /** |
| 2999 | * Get reasons for powering off radio, as requested by {@link requestRadioPowerOffForReason}. |
| 3000 | * |
| 3001 | * @param subId The subscription ID. |
| 3002 | * @param callingPackage The package making the call. |
| 3003 | * @param callingFeatureId The feature in the package. |
| 3004 | * @return List of reasons for powering off radio. |
| 3005 | */ |
| 3006 | public List getRadioPowerOffReasons(int subId, String callingPackage, String callingFeatureId) { |
| 3007 | enforceReadPrivilegedPermission("getRadioPowerOffReasons"); |
| 3008 | |
| 3009 | final long identity = Binder.clearCallingIdentity(); |
| 3010 | List result = new ArrayList(); |
| 3011 | try { |
| 3012 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, |
| 3013 | callingPackage, callingFeatureId, "getRadioPowerOffReasons")) { |
| 3014 | return result; |
| 3015 | } |
| 3016 | |
| 3017 | final Phone phone = getPhone(subId); |
| 3018 | if (phone != null) { |
| 3019 | result.addAll(phone.getRadioPowerOffReasons()); |
| 3020 | } |
| 3021 | } finally { |
| 3022 | Binder.restoreCallingIdentity(identity); |
| 3023 | } |
| 3024 | return result; |
| 3025 | } |
| 3026 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3027 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3028 | @Override |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 3029 | public boolean enableDataConnectivity(String callingPackage) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3030 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3031 | |
| 3032 | final long identity = Binder.clearCallingIdentity(); |
| 3033 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3034 | int subId = SubscriptionManager.getDefaultDataSubscriptionId(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3035 | final Phone phone = getPhone(subId); |
| 3036 | if (phone != null) { |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 3037 | phone.getDataSettingsManager().setDataEnabled( |
| 3038 | TelephonyManager.DATA_ENABLED_REASON_USER, true, callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3039 | return true; |
| 3040 | } else { |
| 3041 | return false; |
| 3042 | } |
| 3043 | } finally { |
| 3044 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3045 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3046 | } |
| 3047 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3048 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3049 | @Override |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 3050 | public boolean disableDataConnectivity(String callingPackage) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3051 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3052 | |
| 3053 | final long identity = Binder.clearCallingIdentity(); |
| 3054 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3055 | int subId = SubscriptionManager.getDefaultDataSubscriptionId(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3056 | final Phone phone = getPhone(subId); |
| 3057 | if (phone != null) { |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 3058 | phone.getDataSettingsManager().setDataEnabled( |
| 3059 | TelephonyManager.DATA_ENABLED_REASON_USER, false, callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3060 | return true; |
| 3061 | } else { |
| 3062 | return false; |
| 3063 | } |
| 3064 | } finally { |
| 3065 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3066 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3067 | } |
| 3068 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3069 | @Override |
Jack Yu | acf8a13 | 2017-05-01 17:00:48 -0700 | [diff] [blame] | 3070 | public boolean isDataConnectivityPossible(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3071 | final long identity = Binder.clearCallingIdentity(); |
| 3072 | try { |
| 3073 | final Phone phone = getPhone(subId); |
| 3074 | if (phone != null) { |
Jack Yu | 59824e1 | 2022-03-23 01:42:44 -0700 | [diff] [blame] | 3075 | return phone.isDataAllowed(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3076 | } else { |
| 3077 | return false; |
| 3078 | } |
| 3079 | } finally { |
| 3080 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3081 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3082 | } |
| 3083 | |
| 3084 | public boolean handlePinMmi(String dialString) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 3085 | return handlePinMmiForSubscriber(getDefaultSubscription(), dialString); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3086 | } |
| 3087 | |
pkanwar | ae03a6b | 2016-11-06 20:37:09 -0800 | [diff] [blame] | 3088 | public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3089 | enforceCallPermission(); |
| 3090 | |
| 3091 | final long identity = Binder.clearCallingIdentity(); |
| 3092 | try { |
| 3093 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3094 | return; |
| 3095 | } |
| 3096 | Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback); |
| 3097 | sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId); |
| 3098 | } finally { |
| 3099 | Binder.restoreCallingIdentity(identity); |
| 3100 | } |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 3101 | }; |
| 3102 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3103 | public boolean handlePinMmiForSubscriber(int subId, String dialString) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3104 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3105 | |
| 3106 | final long identity = Binder.clearCallingIdentity(); |
| 3107 | try { |
| 3108 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3109 | return false; |
| 3110 | } |
| 3111 | return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId); |
| 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 | |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 3117 | /** |
| 3118 | * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage |
| 3119 | * tag on getCallState Binder call. |
| 3120 | */ |
| 3121 | @Deprecated |
| 3122 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3123 | public int getCallState() { |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 3124 | if (CompatChanges.isChangeEnabled( |
| 3125 | TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION, |
| 3126 | Binder.getCallingUid())) { |
| 3127 | // Do not allow this API to be called on API version 31+, it should only be |
| 3128 | // called on old apps using this Binder call directly. |
| 3129 | throw new SecurityException("This method can only be used for applications " |
| 3130 | + "targeting API version 30 or less."); |
| 3131 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3132 | final long identity = Binder.clearCallingIdentity(); |
| 3133 | try { |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 3134 | Phone phone = getPhone(getDefaultSubscription()); |
| 3135 | return phone == null ? TelephonyManager.CALL_STATE_IDLE : |
| 3136 | PhoneConstantConversions.convertCallState(phone.getState()); |
| 3137 | } finally { |
| 3138 | Binder.restoreCallingIdentity(identity); |
| 3139 | } |
| 3140 | } |
| 3141 | |
| 3142 | @Override |
| 3143 | public int getCallStateForSubscription(int subId, String callingPackage, String featureId) { |
| 3144 | if (CompatChanges.isChangeEnabled( |
| 3145 | TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION, |
| 3146 | Binder.getCallingUid())) { |
| 3147 | // Check READ_PHONE_STATE for API version 31+ |
| 3148 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage, |
| 3149 | featureId, "getCallStateForSubscription")) { |
| 3150 | throw new SecurityException("getCallState requires READ_PHONE_STATE for apps " |
| 3151 | + "targeting API level 31+."); |
| 3152 | } |
| 3153 | } |
| 3154 | final long identity = Binder.clearCallingIdentity(); |
| 3155 | try { |
| 3156 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3157 | return phone == null ? TelephonyManager.CALL_STATE_IDLE : |
| 3158 | PhoneConstantConversions.convertCallState(phone.getState()); |
| 3159 | } finally { |
| 3160 | Binder.restoreCallingIdentity(identity); |
| 3161 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3162 | } |
| 3163 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3164 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 3165 | public int getDataState() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3166 | return getDataStateForSubId(SubscriptionManager.getDefaultDataSubscriptionId()); |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 3167 | } |
| 3168 | |
| 3169 | @Override |
| 3170 | public int getDataStateForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3171 | final long identity = Binder.clearCallingIdentity(); |
| 3172 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 3173 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3174 | if (phone != null) { |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 3175 | return phone.getDataNetworkController().getInternetDataNetworkState(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3176 | } else { |
| 3177 | return PhoneConstantConversions.convertDataState( |
| 3178 | PhoneConstants.DataState.DISCONNECTED); |
| 3179 | } |
| 3180 | } finally { |
| 3181 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3182 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3183 | } |
| 3184 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3185 | @Override |
Jack Yu | 0eda684 | 2022-04-18 00:34:46 -0700 | [diff] [blame] | 3186 | public @DataActivityType int getDataActivity() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3187 | return getDataActivityForSubId(SubscriptionManager.getDefaultDataSubscriptionId()); |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 3188 | } |
| 3189 | |
| 3190 | @Override |
Jack Yu | 0eda684 | 2022-04-18 00:34:46 -0700 | [diff] [blame] | 3191 | public @DataActivityType int getDataActivityForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3192 | final long identity = Binder.clearCallingIdentity(); |
| 3193 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 3194 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3195 | if (phone != null) { |
Jack Yu | 0eda684 | 2022-04-18 00:34:46 -0700 | [diff] [blame] | 3196 | return phone.getDataActivityState(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3197 | } else { |
| 3198 | return TelephonyManager.DATA_ACTIVITY_NONE; |
| 3199 | } |
| 3200 | } finally { |
| 3201 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3202 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3203 | } |
| 3204 | |
| 3205 | @Override |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 3206 | public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3207 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 3208 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3209 | |
| 3210 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 3211 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 3212 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 3213 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3214 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3215 | .setCallingPid(Binder.getCallingPid()) |
| 3216 | .setCallingUid(Binder.getCallingUid()) |
| 3217 | .setMethod("getCellLocation") |
Hall Liu | 773ba02 | 2020-01-24 18:07:12 -0800 | [diff] [blame] | 3218 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3219 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 3220 | .build()); |
| 3221 | switch (locationResult) { |
| 3222 | case DENIED_HARD: |
| 3223 | throw new SecurityException("Not allowed to access cell location"); |
| 3224 | case DENIED_SOFT: |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 3225 | return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
| 3226 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3227 | } |
| 3228 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 3229 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3230 | final long identity = Binder.clearCallingIdentity(); |
| 3231 | try { |
| 3232 | if (DBG_LOC) log("getCellLocation: is active user"); |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3233 | int subId = SubscriptionManager.getDefaultDataSubscriptionId(); |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 3234 | return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3235 | } finally { |
| 3236 | Binder.restoreCallingIdentity(identity); |
| 3237 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 3238 | } |
| 3239 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3240 | @Override |
Jack Yu | eb1e7fe | 2020-02-22 19:38:58 -0800 | [diff] [blame] | 3241 | public String getNetworkCountryIsoForPhone(int phoneId) { |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3242 | // Reporting the correct network country is ambiguous when IWLAN could conflict with |
| 3243 | // registered cell info, so return a NULL country instead. |
| 3244 | final long identity = Binder.clearCallingIdentity(); |
| 3245 | try { |
Malcolm Chen | 3732c2b | 2018-07-18 20:15:24 -0700 | [diff] [blame] | 3246 | if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) { |
| 3247 | // Get default phone in this case. |
| 3248 | phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX; |
| 3249 | } |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3250 | final int subId = SubscriptionManager.getSubscriptionId(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3251 | Phone phone = PhoneFactory.getPhone(phoneId); |
Nathan Harold | 532f51c | 2020-04-21 19:31:10 -0700 | [diff] [blame] | 3252 | if (phone == null) return ""; |
| 3253 | ServiceStateTracker sst = phone.getServiceStateTracker(); |
| 3254 | if (sst == null) return ""; |
| 3255 | LocaleTracker lt = sst.getLocaleTracker(); |
| 3256 | if (lt == null) return ""; |
Shuo Qian | 9418a92 | 2021-03-09 11:21:16 -0800 | [diff] [blame] | 3257 | return lt.getCurrentCountry(); |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3258 | } finally { |
| 3259 | Binder.restoreCallingIdentity(identity); |
| 3260 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3261 | } |
| 3262 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 3263 | /** |
| 3264 | * This method was removed due to potential issues caused by performing partial |
| 3265 | * updates of service state, and lack of a credible use case. |
| 3266 | * |
| 3267 | * This has the ability to break the telephony implementation by disabling notification of |
| 3268 | * changes in device connectivity. DO NOT USE THIS! |
| 3269 | */ |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3270 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3271 | public void enableLocationUpdates() { |
| 3272 | mApp.enforceCallingOrSelfPermission( |
| 3273 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3274 | } |
| 3275 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 3276 | /** |
| 3277 | * This method was removed due to potential issues caused by performing partial |
| 3278 | * updates of service state, and lack of a credible use case. |
| 3279 | * |
| 3280 | * This has the ability to break the telephony implementation by disabling notification of |
| 3281 | * changes in device connectivity. DO NOT USE THIS! |
| 3282 | */ |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3283 | @Override |
| 3284 | public void disableLocationUpdates() { |
| 3285 | mApp.enforceCallingOrSelfPermission( |
| 3286 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3287 | } |
| 3288 | |
| 3289 | @Override |
| 3290 | @SuppressWarnings("unchecked") |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3291 | public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage, |
| 3292 | String callingFeatureId) { |
Nathan Harold | b55f63b | 2021-07-27 11:27:38 -0700 | [diff] [blame] | 3293 | try { |
| 3294 | mApp.getSystemService(AppOpsManager.class) |
| 3295 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 3296 | } catch (SecurityException e) { |
| 3297 | EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid()); |
| 3298 | throw e; |
| 3299 | } |
| 3300 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3301 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | dbea45a | 2018-08-30 14:35:07 -0700 | [diff] [blame] | 3302 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 3303 | throw new SecurityException( |
| 3304 | "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels."); |
| 3305 | } |
Nathan Harold | b4d5561 | 2018-07-20 13:13:08 -0700 | [diff] [blame] | 3306 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 3307 | if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(), |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3308 | callingPackage) != AppOpsManager.MODE_ALLOWED) { |
| 3309 | return null; |
| 3310 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 3311 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 3312 | if (DBG_LOC) log("getNeighboringCellInfo: is active user"); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3313 | |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3314 | List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId); |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 3315 | if (info == null) return null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3316 | |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 3317 | List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>(); |
| 3318 | for (CellInfo ci : info) { |
| 3319 | if (ci instanceof CellInfoGsm) { |
| 3320 | neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci)); |
| 3321 | } else if (ci instanceof CellInfoWcdma) { |
| 3322 | neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci)); |
| 3323 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3324 | } |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 3325 | return (neighbors.size()) > 0 ? neighbors : null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3326 | } |
| 3327 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3328 | private List<CellInfo> getCachedCellInfo() { |
| 3329 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 3330 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3331 | List<CellInfo> info = phone.getAllCellInfo(); |
| 3332 | if (info != null) cellInfos.addAll(info); |
| 3333 | } |
| 3334 | return cellInfos; |
| 3335 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3336 | |
| 3337 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3338 | public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3339 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 3340 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3341 | |
| 3342 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 3343 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 3344 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 3345 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3346 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3347 | .setCallingPid(Binder.getCallingPid()) |
| 3348 | .setCallingUid(Binder.getCallingUid()) |
| 3349 | .setMethod("getAllCellInfo") |
Nathan Harold | 5ae50b5 | 2019-02-20 15:46:36 -0800 | [diff] [blame] | 3350 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3351 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 3352 | .build()); |
| 3353 | switch (locationResult) { |
| 3354 | case DENIED_HARD: |
| 3355 | throw new SecurityException("Not allowed to access cell info"); |
| 3356 | case DENIED_SOFT: |
| 3357 | return new ArrayList<>(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3358 | } |
| 3359 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3360 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3361 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 3362 | return getCachedCellInfo(); |
| 3363 | } |
| 3364 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 3365 | if (DBG_LOC) log("getAllCellInfo: is active user"); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 3366 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3367 | final long identity = Binder.clearCallingIdentity(); |
| 3368 | try { |
| 3369 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 3370 | for (Phone phone : PhoneFactory.getPhones()) { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 3371 | final List<CellInfo> info = (List<CellInfo>) sendRequest( |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 3372 | CMD_GET_ALL_CELL_INFO, null, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3373 | if (info != null) cellInfos.addAll(info); |
| 3374 | } |
| 3375 | return cellInfos; |
| 3376 | } finally { |
| 3377 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3378 | } |
| 3379 | } |
| 3380 | |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 3381 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3382 | public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage, |
| 3383 | String callingFeatureId) { |
| 3384 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, |
| 3385 | getWorkSource(Binder.getCallingUid())); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3386 | } |
| 3387 | |
| 3388 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3389 | public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb, |
| 3390 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3391 | enforceModifyPermission(); |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3392 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3393 | } |
| 3394 | |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3395 | private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb, |
| 3396 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3397 | mApp.getSystemService(AppOpsManager.class) |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3398 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3399 | |
| 3400 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 3401 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 3402 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 3403 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3404 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3405 | .setCallingPid(Binder.getCallingPid()) |
| 3406 | .setCallingUid(Binder.getCallingUid()) |
| 3407 | .setMethod("requestCellInfoUpdate") |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 3408 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
| 3409 | .setMinSdkVersionForFine(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3410 | .build()); |
| 3411 | switch (locationResult) { |
| 3412 | case DENIED_HARD: |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3413 | if (TelephonyPermissions |
| 3414 | .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) { |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 3415 | // Safetynet logging for b/154934934 |
| 3416 | EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid()); |
| 3417 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3418 | throw new SecurityException("Not allowed to access cell info"); |
| 3419 | case DENIED_SOFT: |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3420 | if (TelephonyPermissions |
| 3421 | .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) { |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 3422 | // Safetynet logging for b/154934934 |
| 3423 | EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid()); |
| 3424 | } |
Nathan Harold | 5320c42 | 2019-05-09 10:26:08 -0700 | [diff] [blame] | 3425 | try { |
| 3426 | cb.onCellInfo(new ArrayList<CellInfo>()); |
| 3427 | } catch (RemoteException re) { |
| 3428 | // Drop without consequences |
| 3429 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3430 | return; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3431 | } |
| 3432 | |
Nathan Harold | a939a96 | 2019-05-09 10:13:47 -0700 | [diff] [blame] | 3433 | |
| 3434 | final Phone phone = getPhoneFromSubId(subId); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3435 | if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
| 3436 | |
| 3437 | sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource); |
| 3438 | } |
| 3439 | |
| 3440 | @Override |
Aishwarya Mallampati | 0603fb1 | 2022-08-24 21:16:56 +0000 | [diff] [blame] | 3441 | public void setCellInfoListRate(int rateInMillis, int subId) { |
Jack Yu | a8d8cb8 | 2017-01-16 10:15:34 -0800 | [diff] [blame] | 3442 | enforceModifyPermission(); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 3443 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3444 | |
| 3445 | final long identity = Binder.clearCallingIdentity(); |
| 3446 | try { |
Aishwarya Mallampati | 0603fb1 | 2022-08-24 21:16:56 +0000 | [diff] [blame] | 3447 | Phone phone = getPhone(subId); |
| 3448 | if (phone == null) { |
| 3449 | getDefaultPhone().setCellInfoListRate(rateInMillis, workSource); |
| 3450 | } else { |
| 3451 | phone.setCellInfoListRate(rateInMillis, workSource); |
| 3452 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3453 | } finally { |
| 3454 | Binder.restoreCallingIdentity(identity); |
| 3455 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3456 | } |
| 3457 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3458 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3459 | public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3460 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3461 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3462 | return null; |
| 3463 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3464 | int subId = phone.getSubId(); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3465 | enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot"); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 3466 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3467 | callingPackage, callingFeatureId, "getImeiForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3468 | return null; |
| 3469 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3470 | |
| 3471 | final long identity = Binder.clearCallingIdentity(); |
| 3472 | try { |
| 3473 | return phone.getImei(); |
| 3474 | } finally { |
| 3475 | Binder.restoreCallingIdentity(identity); |
| 3476 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3477 | } |
| 3478 | |
| 3479 | @Override |
arunvoddu | d5c6ce0 | 2022-12-11 06:03:12 +0000 | [diff] [blame] | 3480 | public String getPrimaryImei(String callingPackage, String callingFeatureId) { |
| 3481 | enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getPrimaryImei"); |
| 3482 | if (!checkCallingOrSelfReadDeviceIdentifiersForAnySub(mApp, callingPackage, |
| 3483 | callingFeatureId, "getPrimaryImei")) { |
| 3484 | throw new SecurityException("Caller does not have permission"); |
| 3485 | } |
| 3486 | final long identity = Binder.clearCallingIdentity(); |
| 3487 | try { |
| 3488 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3489 | if (phone.getImeiType() == Phone.IMEI_TYPE_PRIMARY) { |
| 3490 | return phone.getImei(); |
| 3491 | } |
| 3492 | } |
| 3493 | throw new UnsupportedOperationException("Operation not supported"); |
| 3494 | } finally { |
| 3495 | Binder.restoreCallingIdentity(identity); |
| 3496 | } |
| 3497 | } |
| 3498 | |
| 3499 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3500 | public String getTypeAllocationCodeForSlot(int slotIndex) { |
| 3501 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3502 | String tac = null; |
| 3503 | if (phone != null) { |
| 3504 | String imei = phone.getImei(); |
Vala Zadeh | ab00555 | 2021-09-21 15:54:29 -0700 | [diff] [blame] | 3505 | try { |
| 3506 | tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH); |
| 3507 | } catch (IndexOutOfBoundsException e) { |
| 3508 | Log.e(LOG_TAG, "IMEI length shorter than upper index."); |
| 3509 | return null; |
| 3510 | } |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3511 | } |
| 3512 | return tac; |
| 3513 | } |
| 3514 | |
| 3515 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3516 | public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Shuo Qian | 13d8915 | 2021-05-10 23:58:11 -0700 | [diff] [blame] | 3517 | try { |
| 3518 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 3519 | } catch (SecurityException se) { |
| 3520 | EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid()); |
| 3521 | throw new SecurityException("Package " + callingPackage + " does not belong to " |
| 3522 | + Binder.getCallingUid()); |
| 3523 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3524 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3525 | if (phone == null) { |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 3526 | return null; |
| 3527 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3528 | |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3529 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 3530 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3531 | callingPackage, callingFeatureId, "getMeidForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3532 | return null; |
| 3533 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3534 | |
| 3535 | final long identity = Binder.clearCallingIdentity(); |
| 3536 | try { |
| 3537 | return phone.getMeid(); |
| 3538 | } finally { |
| 3539 | Binder.restoreCallingIdentity(identity); |
| 3540 | } |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 3541 | } |
| 3542 | |
| 3543 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3544 | public String getManufacturerCodeForSlot(int slotIndex) { |
| 3545 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3546 | String manufacturerCode = null; |
| 3547 | if (phone != null) { |
| 3548 | String meid = phone.getMeid(); |
Vala Zadeh | ab00555 | 2021-09-21 15:54:29 -0700 | [diff] [blame] | 3549 | try { |
| 3550 | manufacturerCode = |
| 3551 | meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH); |
| 3552 | } catch (IndexOutOfBoundsException e) { |
| 3553 | Log.e(LOG_TAG, "MEID length shorter than upper index."); |
| 3554 | return null; |
| 3555 | } |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3556 | } |
| 3557 | return manufacturerCode; |
| 3558 | } |
| 3559 | |
| 3560 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3561 | public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage, |
| 3562 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3563 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3564 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3565 | return null; |
| 3566 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3567 | int subId = phone.getSubId(); |
| 3568 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3569 | mApp, subId, callingPackage, callingFeatureId, |
| 3570 | "getDeviceSoftwareVersionForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3571 | return null; |
| 3572 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3573 | |
| 3574 | final long identity = Binder.clearCallingIdentity(); |
| 3575 | try { |
| 3576 | return phone.getDeviceSvn(); |
| 3577 | } finally { |
| 3578 | Binder.restoreCallingIdentity(identity); |
| 3579 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3580 | } |
| 3581 | |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3582 | @Override |
| 3583 | public int getSubscriptionCarrierId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3584 | final long identity = Binder.clearCallingIdentity(); |
| 3585 | try { |
| 3586 | final Phone phone = getPhone(subId); |
| 3587 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId(); |
| 3588 | } finally { |
| 3589 | Binder.restoreCallingIdentity(identity); |
| 3590 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3591 | } |
| 3592 | |
| 3593 | @Override |
| 3594 | public String getSubscriptionCarrierName(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3595 | final long identity = Binder.clearCallingIdentity(); |
| 3596 | try { |
| 3597 | final Phone phone = getPhone(subId); |
| 3598 | return phone == null ? null : phone.getCarrierName(); |
| 3599 | } finally { |
| 3600 | Binder.restoreCallingIdentity(identity); |
| 3601 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3602 | } |
| 3603 | |
calvinpan | ffe225e | 2018-11-01 19:43:06 +0800 | [diff] [blame] | 3604 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3605 | public int getSubscriptionSpecificCarrierId(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3606 | final long identity = Binder.clearCallingIdentity(); |
| 3607 | try { |
| 3608 | final Phone phone = getPhone(subId); |
| 3609 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3610 | : phone.getSpecificCarrierId(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3611 | } finally { |
| 3612 | Binder.restoreCallingIdentity(identity); |
| 3613 | } |
| 3614 | } |
| 3615 | |
| 3616 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3617 | public String getSubscriptionSpecificCarrierName(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3618 | final long identity = Binder.clearCallingIdentity(); |
| 3619 | try { |
| 3620 | final Phone phone = getPhone(subId); |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3621 | return phone == null ? null : phone.getSpecificCarrierName(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3622 | } finally { |
| 3623 | Binder.restoreCallingIdentity(identity); |
| 3624 | } |
| 3625 | } |
| 3626 | |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 3627 | @Override |
chen xu | 864e11c | 2018-12-06 22:10:03 -0800 | [diff] [blame] | 3628 | public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) { |
| 3629 | if (!isSubscriptionMccMnc) { |
| 3630 | enforceReadPrivilegedPermission("getCarrierIdFromMccMnc"); |
| 3631 | } |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 3632 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3633 | if (phone == null) { |
| 3634 | return TelephonyManager.UNKNOWN_CARRIER_ID; |
| 3635 | } |
| 3636 | final long identity = Binder.clearCallingIdentity(); |
| 3637 | try { |
| 3638 | return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc); |
| 3639 | } finally { |
| 3640 | Binder.restoreCallingIdentity(identity); |
| 3641 | } |
| 3642 | } |
| 3643 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3644 | // |
| 3645 | // Internal helper methods. |
| 3646 | // |
| 3647 | |
Sanket Padawe | ee13a9b | 2016-03-08 17:30:28 -0800 | [diff] [blame] | 3648 | /** |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3649 | * Make sure the caller is the calling package itself |
| 3650 | * |
| 3651 | * @throws SecurityException if the caller is not the calling package |
| 3652 | */ |
| 3653 | private void enforceCallingPackage(String callingPackage, int callingUid, String message) { |
| 3654 | int packageUid = -1; |
Grace Jia | dbefca0 | 2021-04-26 15:13:31 -0700 | [diff] [blame] | 3655 | PackageManager pm = mApp.getBaseContext().createContextAsUser( |
| 3656 | UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager(); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3657 | try { |
Grace Jia | dbefca0 | 2021-04-26 15:13:31 -0700 | [diff] [blame] | 3658 | packageUid = pm.getPackageUid(callingPackage, 0); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3659 | } catch (PackageManager.NameNotFoundException e) { |
| 3660 | // packageUid is -1 |
| 3661 | } |
| 3662 | if (packageUid != callingUid) { |
| 3663 | throw new SecurityException(message + ": Package " + callingPackage |
| 3664 | + " does not belong to " + callingUid); |
| 3665 | } |
| 3666 | } |
| 3667 | |
| 3668 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3669 | * Make sure the caller has the MODIFY_PHONE_STATE permission. |
| 3670 | * |
| 3671 | * @throws SecurityException if the caller does not have the required permission |
| 3672 | */ |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 3673 | @VisibleForTesting |
| 3674 | public void enforceModifyPermission() { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3675 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null); |
| 3676 | } |
| 3677 | |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 3678 | /** |
| 3679 | * Make sure the caller has the MODIFY_PHONE_STATE permission. |
| 3680 | * |
| 3681 | * @throws SecurityException if the caller does not have the required permission |
| 3682 | */ |
| 3683 | @VisibleForTesting |
| 3684 | public void enforceReadPermission() { |
| 3685 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, null); |
| 3686 | } |
| 3687 | |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 3688 | private void enforceActiveEmergencySessionPermission() { |
| 3689 | mApp.enforceCallingOrSelfPermission( |
| 3690 | android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null); |
| 3691 | } |
| 3692 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3693 | /** |
| 3694 | * Make sure the caller has the CALL_PHONE permission. |
| 3695 | * |
| 3696 | * @throws SecurityException if the caller does not have the required permission |
| 3697 | */ |
| 3698 | private void enforceCallPermission() { |
| 3699 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null); |
| 3700 | } |
| 3701 | |
paulhu | 5a77360 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 3702 | private void enforceSettingsPermission() { |
| 3703 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 3704 | } |
| 3705 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 3706 | private void enforceRebootPermission() { |
| 3707 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null); |
| 3708 | } |
| 3709 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3710 | private String createTelUrl(String number) { |
| 3711 | if (TextUtils.isEmpty(number)) { |
| 3712 | return null; |
| 3713 | } |
| 3714 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3715 | return "tel:" + number; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3716 | } |
| 3717 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3718 | private static void log(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3719 | Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 3720 | } |
| 3721 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3722 | private static void logv(String msg) { |
| 3723 | Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 3724 | } |
| 3725 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3726 | private static void loge(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3727 | Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 3728 | } |
| 3729 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3730 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3731 | public int getActivePhoneType() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3732 | return getActivePhoneTypeForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3733 | } |
| 3734 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3735 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3736 | public int getActivePhoneTypeForSlot(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3737 | final long identity = Binder.clearCallingIdentity(); |
| 3738 | try { |
| 3739 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3740 | if (phone == null) { |
| 3741 | return PhoneConstants.PHONE_TYPE_NONE; |
| 3742 | } else { |
| 3743 | return phone.getPhoneType(); |
| 3744 | } |
| 3745 | } finally { |
| 3746 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3747 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3748 | } |
| 3749 | |
| 3750 | /** |
| 3751 | * Returns the CDMA ERI icon index to display |
| 3752 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3753 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3754 | public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) { |
| 3755 | return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage, |
| 3756 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3757 | } |
| 3758 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3759 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3760 | public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage, |
| 3761 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3762 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3763 | mApp, subId, callingPackage, callingFeatureId, |
| 3764 | "getCdmaEriIconIndexForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3765 | return -1; |
| 3766 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3767 | |
| 3768 | final long identity = Binder.clearCallingIdentity(); |
| 3769 | try { |
| 3770 | final Phone phone = getPhone(subId); |
| 3771 | if (phone != null) { |
| 3772 | return phone.getCdmaEriIconIndex(); |
| 3773 | } else { |
| 3774 | return -1; |
| 3775 | } |
| 3776 | } finally { |
| 3777 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3778 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3779 | } |
| 3780 | |
| 3781 | /** |
| 3782 | * Returns the CDMA ERI icon mode, |
| 3783 | * 0 - ON |
| 3784 | * 1 - FLASHING |
| 3785 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3786 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3787 | public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) { |
| 3788 | return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 3789 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3790 | } |
| 3791 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3792 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3793 | public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage, |
| 3794 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3795 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3796 | mApp, subId, callingPackage, callingFeatureId, |
| 3797 | "getCdmaEriIconModeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3798 | return -1; |
| 3799 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3800 | |
| 3801 | final long identity = Binder.clearCallingIdentity(); |
| 3802 | try { |
| 3803 | final Phone phone = getPhone(subId); |
| 3804 | if (phone != null) { |
| 3805 | return phone.getCdmaEriIconMode(); |
| 3806 | } else { |
| 3807 | return -1; |
| 3808 | } |
| 3809 | } finally { |
| 3810 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3811 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3812 | } |
| 3813 | |
| 3814 | /** |
| 3815 | * Returns the CDMA ERI text, |
| 3816 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3817 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3818 | public String getCdmaEriText(String callingPackage, String callingFeatureId) { |
| 3819 | return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage, |
| 3820 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3821 | } |
| 3822 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3823 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3824 | public String getCdmaEriTextForSubscriber(int subId, String callingPackage, |
| 3825 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3826 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3827 | mApp, subId, callingPackage, callingFeatureId, |
| 3828 | "getCdmaEriIconTextForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3829 | return null; |
| 3830 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3831 | |
| 3832 | final long identity = Binder.clearCallingIdentity(); |
| 3833 | try { |
| 3834 | final Phone phone = getPhone(subId); |
| 3835 | if (phone != null) { |
| 3836 | return phone.getCdmaEriText(); |
| 3837 | } else { |
| 3838 | return null; |
| 3839 | } |
| 3840 | } finally { |
| 3841 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3842 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3843 | } |
| 3844 | |
| 3845 | /** |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3846 | * Returns the CDMA MDN. |
| 3847 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3848 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3849 | public String getCdmaMdn(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3850 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3851 | mApp, subId, "getCdmaMdn"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3852 | |
| 3853 | final long identity = Binder.clearCallingIdentity(); |
| 3854 | try { |
| 3855 | final Phone phone = getPhone(subId); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3856 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3857 | return phone.getLine1Number(); |
| 3858 | } else { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3859 | loge("getCdmaMdn: no phone found. Invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3860 | return null; |
| 3861 | } |
| 3862 | } finally { |
| 3863 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3864 | } |
| 3865 | } |
| 3866 | |
| 3867 | /** |
| 3868 | * Returns the CDMA MIN. |
| 3869 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3870 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3871 | public String getCdmaMin(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3872 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3873 | mApp, subId, "getCdmaMin"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3874 | |
| 3875 | final long identity = Binder.clearCallingIdentity(); |
| 3876 | try { |
| 3877 | final Phone phone = getPhone(subId); |
| 3878 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
| 3879 | return phone.getCdmaMin(); |
| 3880 | } else { |
| 3881 | return null; |
| 3882 | } |
| 3883 | } finally { |
| 3884 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3885 | } |
| 3886 | } |
| 3887 | |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3888 | @Override |
| 3889 | public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis, |
| 3890 | INumberVerificationCallback callback, String callingPackage) { |
| 3891 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 3892 | != PERMISSION_GRANTED) { |
| 3893 | throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission"); |
| 3894 | } |
| 3895 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 3896 | |
| 3897 | String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp); |
| 3898 | if (!TextUtils.equals(callingPackage, authorizedPackage)) { |
Hall Liu | b9d8feb | 2021-01-13 10:28:04 -0800 | [diff] [blame] | 3899 | throw new SecurityException("Calling package must be configured in the device config: " |
| 3900 | + "calling package: " + callingPackage |
| 3901 | + ", configured package: " + authorizedPackage); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3902 | } |
| 3903 | |
| 3904 | if (range == null) { |
| 3905 | throw new NullPointerException("Range must be non-null"); |
| 3906 | } |
| 3907 | |
| 3908 | timeoutMillis = Math.min(timeoutMillis, |
Hall Liu | bd069e3 | 2019-02-28 18:56:30 -0800 | [diff] [blame] | 3909 | TelephonyManager.getMaxNumberVerificationTimeoutMillis()); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3910 | |
| 3911 | NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis); |
| 3912 | } |
| 3913 | |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3914 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3915 | * Returns true if CDMA provisioning needs to run. |
| 3916 | */ |
| 3917 | public boolean needsOtaServiceProvisioning() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3918 | final long identity = Binder.clearCallingIdentity(); |
| 3919 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3920 | return getDefaultPhone().needsOtaServiceProvisioning(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3921 | } finally { |
| 3922 | Binder.restoreCallingIdentity(identity); |
| 3923 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3924 | } |
| 3925 | |
| 3926 | /** |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3927 | * Sets the voice mail number of a given subId. |
| 3928 | */ |
| 3929 | @Override |
| 3930 | public boolean setVoiceMailNumber(int subId, String alphaTag, String number) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 3931 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 3932 | mApp, subId, "setVoiceMailNumber"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3933 | |
| 3934 | final long identity = Binder.clearCallingIdentity(); |
| 3935 | try { |
| 3936 | Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER, |
| 3937 | new Pair<String, String>(alphaTag, number), new Integer(subId)); |
| 3938 | return success; |
| 3939 | } finally { |
| 3940 | Binder.restoreCallingIdentity(identity); |
| 3941 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3942 | } |
| 3943 | |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3944 | @Override |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3945 | public Bundle getVisualVoicemailSettings(String callingPackage, int subId) { |
| 3946 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 3947 | TelecomManager tm = mApp.getSystemService(TelecomManager.class); |
| 3948 | String systemDialer = tm.getSystemDialerPackage(); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3949 | if (!TextUtils.equals(callingPackage, systemDialer)) { |
| 3950 | throw new SecurityException("caller must be system dialer"); |
| 3951 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3952 | |
| 3953 | final long identity = Binder.clearCallingIdentity(); |
| 3954 | try { |
| 3955 | PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId); |
| 3956 | if (phoneAccountHandle == null) { |
| 3957 | return null; |
| 3958 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3959 | return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3960 | } finally { |
| 3961 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3962 | } |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3963 | } |
| 3964 | |
| 3965 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3966 | public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId, |
| 3967 | int subId) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3968 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3969 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3970 | mApp, subId, callingPackage, callingFeatureId, |
| 3971 | "getVisualVoicemailPackageName")) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3972 | return null; |
| 3973 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3974 | |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 3975 | final long identity = Binder.clearCallingIdentity(); |
| 3976 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3977 | return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName(); |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 3978 | } finally { |
| 3979 | Binder.restoreCallingIdentity(identity); |
| 3980 | } |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3981 | } |
| 3982 | |
| 3983 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3984 | public void enableVisualVoicemailSmsFilter(String callingPackage, int subId, |
| 3985 | VisualVoicemailSmsFilterSettings settings) { |
| 3986 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3987 | |
| 3988 | final long identity = Binder.clearCallingIdentity(); |
| 3989 | try { |
| 3990 | VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3991 | mApp, callingPackage, subId, settings); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3992 | } finally { |
| 3993 | Binder.restoreCallingIdentity(identity); |
| 3994 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3995 | } |
| 3996 | |
| 3997 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3998 | public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) { |
| 3999 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4000 | |
| 4001 | final long identity = Binder.clearCallingIdentity(); |
| 4002 | try { |
| 4003 | VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4004 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4005 | } finally { |
| 4006 | Binder.restoreCallingIdentity(identity); |
| 4007 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 4008 | } |
| 4009 | |
| 4010 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 4011 | public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings( |
| 4012 | String callingPackage, int subId) { |
| 4013 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4014 | |
| 4015 | final long identity = Binder.clearCallingIdentity(); |
| 4016 | try { |
| 4017 | return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4018 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4019 | } finally { |
| 4020 | Binder.restoreCallingIdentity(identity); |
| 4021 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 4022 | } |
| 4023 | |
| 4024 | @Override |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 4025 | public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4026 | enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4027 | |
| 4028 | final long identity = Binder.clearCallingIdentity(); |
| 4029 | try { |
| 4030 | return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4031 | mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4032 | } finally { |
| 4033 | Binder.restoreCallingIdentity(identity); |
| 4034 | } |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 4035 | } |
| 4036 | |
| 4037 | @Override |
Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 4038 | public void sendVisualVoicemailSmsForSubscriber(String callingPackage, |
| 4039 | String callingAttributionTag, int subId, String number, int port, String text, |
| 4040 | PendingIntent sentIntent) { |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 4041 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 4042 | enforceVisualVoicemailPackage(callingPackage, subId); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 4043 | enforceSendSmsPermission(); |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 4044 | SmsController smsController = PhoneFactory.getSmsController(); |
Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 4045 | smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag, |
| 4046 | subId, number, port, text, sentIntent); |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 4047 | } |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 4048 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 4049 | /** |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4050 | * Sets the voice activation state of a given subId. |
| 4051 | */ |
| 4052 | @Override |
| 4053 | public void setVoiceActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4054 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4055 | mApp, subId, "setVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4056 | |
| 4057 | final long identity = Binder.clearCallingIdentity(); |
| 4058 | try { |
| 4059 | final Phone phone = getPhone(subId); |
| 4060 | if (phone != null) { |
| 4061 | phone.setVoiceActivationState(activationState); |
| 4062 | } else { |
| 4063 | loge("setVoiceActivationState fails with invalid subId: " + subId); |
| 4064 | } |
| 4065 | } finally { |
| 4066 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4067 | } |
| 4068 | } |
| 4069 | |
| 4070 | /** |
| 4071 | * Sets the data activation state of a given subId. |
| 4072 | */ |
| 4073 | @Override |
| 4074 | public void setDataActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4075 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4076 | mApp, subId, "setDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4077 | |
| 4078 | final long identity = Binder.clearCallingIdentity(); |
| 4079 | try { |
| 4080 | final Phone phone = getPhone(subId); |
| 4081 | if (phone != null) { |
| 4082 | phone.setDataActivationState(activationState); |
| 4083 | } else { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 4084 | loge("setDataActivationState fails with invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4085 | } |
| 4086 | } finally { |
| 4087 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4088 | } |
| 4089 | } |
| 4090 | |
| 4091 | /** |
| 4092 | * Returns the voice activation state of a given subId. |
| 4093 | */ |
| 4094 | @Override |
| 4095 | public int getVoiceActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4096 | enforceReadPrivilegedPermission("getVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4097 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4098 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4099 | final long identity = Binder.clearCallingIdentity(); |
| 4100 | try { |
| 4101 | if (phone != null) { |
| 4102 | return phone.getVoiceActivationState(); |
| 4103 | } else { |
| 4104 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 4105 | } |
| 4106 | } finally { |
| 4107 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4108 | } |
| 4109 | } |
| 4110 | |
| 4111 | /** |
| 4112 | * Returns the data activation state of a given subId. |
| 4113 | */ |
| 4114 | @Override |
| 4115 | public int getDataActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4116 | enforceReadPrivilegedPermission("getDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4117 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4118 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4119 | final long identity = Binder.clearCallingIdentity(); |
| 4120 | try { |
| 4121 | if (phone != null) { |
| 4122 | return phone.getDataActivationState(); |
| 4123 | } else { |
| 4124 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 4125 | } |
| 4126 | } finally { |
| 4127 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4128 | } |
| 4129 | } |
| 4130 | |
| 4131 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4132 | * Returns the unread count of voicemails for a subId |
| 4133 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4134 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4135 | public int getVoiceMessageCountForSubscriber(int subId, String callingPackage, |
| 4136 | String callingFeatureId) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 4137 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4138 | mApp, subId, callingPackage, callingFeatureId, |
| 4139 | "getVoiceMessageCountForSubscriber")) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 4140 | return 0; |
| 4141 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4142 | final long identity = Binder.clearCallingIdentity(); |
| 4143 | try { |
| 4144 | final Phone phone = getPhone(subId); |
| 4145 | if (phone != null) { |
| 4146 | return phone.getVoiceMessageCount(); |
| 4147 | } else { |
| 4148 | return 0; |
| 4149 | } |
| 4150 | } finally { |
| 4151 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4152 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4153 | } |
| 4154 | |
| 4155 | /** |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 4156 | * returns true, if the device is in a state where both voice and data |
| 4157 | * are supported simultaneously. This can change based on location or network condition. |
| 4158 | */ |
| 4159 | @Override |
| 4160 | public boolean isConcurrentVoiceAndDataAllowed(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4161 | final long identity = Binder.clearCallingIdentity(); |
| 4162 | try { |
| 4163 | final Phone phone = getPhone(subId); |
| 4164 | return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed()); |
| 4165 | } finally { |
| 4166 | Binder.restoreCallingIdentity(identity); |
| 4167 | } |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 4168 | } |
| 4169 | |
| 4170 | /** |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4171 | * Send the dialer code if called from the current default dialer or the caller has |
| 4172 | * carrier privilege. |
| 4173 | * @param inputCode The dialer code to send |
| 4174 | */ |
| 4175 | @Override |
| 4176 | public void sendDialerSpecialCode(String callingPackage, String inputCode) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4177 | final Phone defaultPhone = getDefaultPhone(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4178 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 4179 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 4180 | String defaultDialer = tm.getDefaultDialerPackage(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4181 | if (!TextUtils.equals(callingPackage, defaultDialer)) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 4182 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4183 | getDefaultSubscription(), "sendDialerSpecialCode"); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4184 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4185 | |
| 4186 | final long identity = Binder.clearCallingIdentity(); |
| 4187 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4188 | defaultPhone.sendDialerSpecialCode(inputCode); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4189 | } finally { |
| 4190 | Binder.restoreCallingIdentity(identity); |
| 4191 | } |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4192 | } |
| 4193 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 4194 | @Override |
| 4195 | public int getNetworkSelectionMode(int subId) { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 4196 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4197 | .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 4198 | mApp, subId, "getNetworkSelectionMode"); |
| 4199 | final long identity = Binder.clearCallingIdentity(); |
| 4200 | try { |
| 4201 | if (!isActiveSubscription(subId)) { |
| 4202 | return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 4203 | } |
| 4204 | return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId); |
| 4205 | } finally { |
| 4206 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 4207 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 4208 | } |
| 4209 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4210 | @Override |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 4211 | public boolean isInEmergencySmsMode() { |
| 4212 | enforceReadPrivilegedPermission("isInEmergencySmsMode"); |
| 4213 | final long identity = Binder.clearCallingIdentity(); |
| 4214 | try { |
| 4215 | for (Phone phone : PhoneFactory.getPhones()) { |
| 4216 | if (phone.isInEmergencySmsMode()) { |
| 4217 | return true; |
| 4218 | } |
| 4219 | } |
| 4220 | } finally { |
| 4221 | Binder.restoreCallingIdentity(identity); |
| 4222 | } |
| 4223 | return false; |
| 4224 | } |
| 4225 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4226 | /** |
| 4227 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4228 | * @param subId The subscription to use to check the configuration. |
| 4229 | * @param c The callback that will be used to send the result. |
| 4230 | */ |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 4231 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4232 | public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c) |
| 4233 | throws RemoteException { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4234 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4235 | mApp, subId, "registerImsRegistrationCallback"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4236 | |
| 4237 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4238 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4239 | "IMS not available on device."); |
| 4240 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4241 | final long token = Binder.clearCallingIdentity(); |
| 4242 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4243 | int slotId = getSlotIndexOrException(subId); |
| 4244 | verifyImsMmTelConfiguredOrThrow(slotId); |
joonhunshin | 49f0aed | 2022-08-05 08:33:05 +0000 | [diff] [blame] | 4245 | |
| 4246 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4247 | if (controller != null) { |
| 4248 | ImsManager imsManager = controller.getImsManager(subId); |
| 4249 | if (imsManager != null) { |
| 4250 | imsManager.addRegistrationCallbackForSubscription(c, subId); |
| 4251 | } else { |
| 4252 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE); |
| 4253 | } |
| 4254 | } else { |
| 4255 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION); |
| 4256 | } |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4257 | } catch (ImsException e) { |
| 4258 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4259 | } finally { |
| 4260 | Binder.restoreCallingIdentity(token); |
| 4261 | } |
| 4262 | } |
| 4263 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4264 | /** |
| 4265 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4266 | * @param subId The subscription to use to check the configuration. |
| 4267 | * @param c The callback that will be used to send the result. |
| 4268 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4269 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4270 | public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4271 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4272 | mApp, subId, "unregisterImsRegistrationCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4273 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4274 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4275 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4276 | final long token = Binder.clearCallingIdentity(); |
joonhunshin | 49f0aed | 2022-08-05 08:33:05 +0000 | [diff] [blame] | 4277 | |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4278 | try { |
joonhunshin | 49f0aed | 2022-08-05 08:33:05 +0000 | [diff] [blame] | 4279 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4280 | if (controller != null) { |
| 4281 | ImsManager imsManager = controller.getImsManager(subId); |
| 4282 | if (imsManager != null) { |
| 4283 | imsManager.removeRegistrationCallbackForSubscription(c, subId); |
| 4284 | } else { |
| 4285 | Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId |
| 4286 | + "is inactive, ignoring unregister."); |
| 4287 | // If the ImsManager is not valid, just return, since the callback |
| 4288 | // will already have been removed internally. |
| 4289 | } |
| 4290 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4291 | } finally { |
| 4292 | Binder.restoreCallingIdentity(token); |
| 4293 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4294 | } |
| 4295 | |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 4296 | /** |
| 4297 | * Get the IMS service registration state for the MmTelFeature associated with this sub id. |
| 4298 | */ |
| 4299 | @Override |
| 4300 | public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) { |
| 4301 | enforceReadPrivilegedPermission("getImsMmTelRegistrationState"); |
| 4302 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4303 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4304 | "IMS not available on device."); |
| 4305 | } |
| 4306 | final long token = Binder.clearCallingIdentity(); |
| 4307 | try { |
| 4308 | Phone phone = getPhone(subId); |
| 4309 | if (phone == null) { |
| 4310 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 4311 | + subId + "'"); |
| 4312 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 4313 | } |
| 4314 | phone.getImsRegistrationState(regState -> { |
| 4315 | try { |
| 4316 | consumer.accept((regState == null) |
| 4317 | ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState); |
| 4318 | } catch (RemoteException e) { |
| 4319 | // Ignore if the remote process is no longer available to call back. |
| 4320 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 4321 | } |
| 4322 | }); |
| 4323 | } finally { |
| 4324 | Binder.restoreCallingIdentity(token); |
| 4325 | } |
| 4326 | } |
| 4327 | |
| 4328 | /** |
| 4329 | * Get the transport type for the IMS service registration state. |
| 4330 | */ |
| 4331 | @Override |
| 4332 | public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4333 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4334 | mApp, subId, "getImsMmTelRegistrationTransportType"); |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 4335 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4336 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4337 | "IMS not available on device."); |
| 4338 | } |
| 4339 | final long token = Binder.clearCallingIdentity(); |
| 4340 | try { |
| 4341 | Phone phone = getPhone(subId); |
| 4342 | if (phone == null) { |
| 4343 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 4344 | + subId + "'"); |
| 4345 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 4346 | } |
| 4347 | phone.getImsRegistrationTech(regTech -> { |
| 4348 | // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager |
| 4349 | int regTechConverted = (regTech == null) |
| 4350 | ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech; |
| 4351 | regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get( |
| 4352 | regTechConverted); |
| 4353 | try { |
| 4354 | consumer.accept(regTechConverted); |
| 4355 | } catch (RemoteException e) { |
| 4356 | // Ignore if the remote process is no longer available to call back. |
| 4357 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 4358 | } |
| 4359 | }); |
| 4360 | } finally { |
| 4361 | Binder.restoreCallingIdentity(token); |
| 4362 | } |
| 4363 | } |
| 4364 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4365 | /** |
| 4366 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4367 | * @param subId The subscription to use to check the configuration. |
| 4368 | * @param c The callback that will be used to send the result. |
| 4369 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4370 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4371 | public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) |
| 4372 | throws RemoteException { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4373 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4374 | mApp, subId, "registerMmTelCapabilityCallback"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4375 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4376 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4377 | "IMS not available on device."); |
| 4378 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4379 | final long token = Binder.clearCallingIdentity(); |
| 4380 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4381 | int slotId = getSlotIndexOrException(subId); |
| 4382 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 4383 | ImsManager.getInstance(mApp, slotId).addCapabilitiesCallbackForSubscription(c, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4384 | } catch (ImsException e) { |
| 4385 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4386 | } finally { |
| 4387 | Binder.restoreCallingIdentity(token); |
| 4388 | } |
| 4389 | } |
| 4390 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4391 | /** |
| 4392 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4393 | * @param subId The subscription to use to check the configuration. |
| 4394 | * @param c The callback that will be used to send the result. |
| 4395 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4396 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4397 | public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4398 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4399 | mApp, subId, "unregisterMmTelCapabilityCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4400 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4401 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4402 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4403 | |
| 4404 | final long token = Binder.clearCallingIdentity(); |
| 4405 | try { |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4406 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4407 | .removeCapabilitiesCallbackForSubscription(c, subId); |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4408 | } catch (ImsException e) { |
| 4409 | Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId |
| 4410 | + "is inactive, ignoring unregister."); |
| 4411 | // If the subscription is no longer active, just return, since the callback |
| 4412 | // will already have been removed internally. |
| 4413 | } finally { |
| 4414 | Binder.restoreCallingIdentity(token); |
| 4415 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4416 | } |
| 4417 | |
| 4418 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4419 | public boolean isCapable(int subId, int capability, int regTech) { |
| 4420 | enforceReadPrivilegedPermission("isCapable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4421 | final long token = Binder.clearCallingIdentity(); |
| 4422 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4423 | int slotId = getSlotIndexOrException(subId); |
| 4424 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 4425 | return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech); |
| 4426 | } catch (com.android.ims.ImsException e) { |
| 4427 | Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage()); |
| 4428 | return false; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4429 | } catch (ImsException e) { |
Brad Ebinger | 6b5ac22 | 2019-02-04 14:36:52 -0800 | [diff] [blame] | 4430 | Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false."); |
| 4431 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4432 | } finally { |
| 4433 | Binder.restoreCallingIdentity(token); |
| 4434 | } |
| 4435 | } |
| 4436 | |
| 4437 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4438 | public boolean isAvailable(int subId, int capability, int regTech) { |
| 4439 | enforceReadPrivilegedPermission("isAvailable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4440 | final long token = Binder.clearCallingIdentity(); |
| 4441 | try { |
| 4442 | Phone phone = getPhone(subId); |
| 4443 | if (phone == null) return false; |
| 4444 | return phone.isImsCapabilityAvailable(capability, regTech); |
Daniel Bright | 5e40e4e | 2020-03-11 16:35:39 -0700 | [diff] [blame] | 4445 | } catch (com.android.ims.ImsException e) { |
| 4446 | Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage()); |
| 4447 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4448 | } finally { |
| 4449 | Binder.restoreCallingIdentity(token); |
| 4450 | } |
| 4451 | } |
| 4452 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4453 | /** |
| 4454 | * Determines if the MmTel feature capability is supported by the carrier configuration for this |
| 4455 | * subscription. |
| 4456 | * @param subId The subscription to use to check the configuration. |
| 4457 | * @param callback The callback that will be used to send the result. |
| 4458 | * @param capability The MmTelFeature capability that will be used to send the result. |
| 4459 | * @param transportType The transport type of the MmTelFeature capability. |
| 4460 | */ |
| 4461 | @Override |
| 4462 | public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability, |
| 4463 | int transportType) { |
| 4464 | enforceReadPrivilegedPermission("isMmTelCapabilitySupported"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4465 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4466 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4467 | "IMS not available on device."); |
| 4468 | } |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4469 | final long token = Binder.clearCallingIdentity(); |
| 4470 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4471 | int slotId = getSlotIndex(subId); |
| 4472 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4473 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '" |
| 4474 | + subId + "'"); |
| 4475 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 4476 | } |
| 4477 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 4478 | ImsManager.getInstance(mApp, slotId).isSupported(capability, |
| 4479 | transportType, aBoolean -> { |
| 4480 | try { |
| 4481 | callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0)); |
| 4482 | } catch (RemoteException e) { |
| 4483 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not " |
| 4484 | + "running. Ignore"); |
| 4485 | } |
| 4486 | }); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4487 | } catch (ImsException e) { |
| 4488 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4489 | } finally { |
| 4490 | Binder.restoreCallingIdentity(token); |
| 4491 | } |
| 4492 | } |
| 4493 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4494 | /** |
| 4495 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4496 | * @param subId The subscription to use to check the configuration. |
| 4497 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4498 | @Override |
| 4499 | public boolean isAdvancedCallingSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4500 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4501 | mApp, subId, "isAdvancedCallingSettingEnabled"); |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4502 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4503 | final long token = Binder.clearCallingIdentity(); |
| 4504 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4505 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4506 | // 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] | 4507 | return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4508 | } catch (ImsException e) { |
| 4509 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4510 | } finally { |
| 4511 | Binder.restoreCallingIdentity(token); |
| 4512 | } |
| 4513 | } |
| 4514 | |
| 4515 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4516 | public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4517 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4518 | "setAdvancedCallingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4519 | final long identity = Binder.clearCallingIdentity(); |
| 4520 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4521 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4522 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4523 | // 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] | 4524 | ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4525 | } catch (ImsException e) { |
| 4526 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4527 | } finally { |
| 4528 | Binder.restoreCallingIdentity(identity); |
| 4529 | } |
| 4530 | } |
| 4531 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4532 | /** |
| 4533 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4534 | * @param subId The subscription to use to check the configuration. |
| 4535 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4536 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4537 | public boolean isVtSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4538 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4539 | mApp, subId, "isVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4540 | final long identity = Binder.clearCallingIdentity(); |
| 4541 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4542 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4543 | // 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] | 4544 | return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4545 | } catch (ImsException e) { |
| 4546 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4547 | } finally { |
| 4548 | Binder.restoreCallingIdentity(identity); |
| 4549 | } |
| 4550 | } |
| 4551 | |
| 4552 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4553 | public void setVtSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4554 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4555 | "setVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4556 | final long identity = Binder.clearCallingIdentity(); |
| 4557 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4558 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4559 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4560 | // 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] | 4561 | ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4562 | } catch (ImsException e) { |
| 4563 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4564 | } finally { |
| 4565 | Binder.restoreCallingIdentity(identity); |
| 4566 | } |
| 4567 | } |
| 4568 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4569 | /** |
| 4570 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4571 | * @param subId The subscription to use to check the configuration. |
| 4572 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4573 | @Override |
| 4574 | public boolean isVoWiFiSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4575 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4576 | mApp, subId, "isVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4577 | final long identity = Binder.clearCallingIdentity(); |
| 4578 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4579 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4580 | // 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] | 4581 | return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4582 | } catch (ImsException e) { |
| 4583 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4584 | } finally { |
| 4585 | Binder.restoreCallingIdentity(identity); |
| 4586 | } |
| 4587 | } |
| 4588 | |
| 4589 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4590 | public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4591 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4592 | "setVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4593 | final long identity = Binder.clearCallingIdentity(); |
| 4594 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4595 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4596 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4597 | // 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] | 4598 | ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4599 | } catch (ImsException e) { |
| 4600 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4601 | } finally { |
| 4602 | Binder.restoreCallingIdentity(identity); |
| 4603 | } |
| 4604 | } |
| 4605 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4606 | /** |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 4607 | * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not |
| 4608 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4609 | * @param subId The subscription to use to check the configuration. |
| 4610 | */ |
| 4611 | @Override |
| 4612 | public boolean isCrossSimCallingEnabledByUser(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4613 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 4614 | mApp, subId, "isCrossSimCallingEnabledByUser"); |
| 4615 | final long identity = Binder.clearCallingIdentity(); |
| 4616 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4617 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4618 | // 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] | 4619 | return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser(); |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 4620 | } catch (ImsException e) { |
| 4621 | throw new ServiceSpecificException(e.getCode()); |
| 4622 | } finally { |
| 4623 | Binder.restoreCallingIdentity(identity); |
| 4624 | } |
| 4625 | } |
| 4626 | |
| 4627 | /** |
| 4628 | * Sets the user's setting for whether or not Voice over Cross SIM is enabled. |
| 4629 | * Requires MODIFY_PHONE_STATE permission. |
| 4630 | * @param subId The subscription to use to check the configuration. |
| 4631 | * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled, |
| 4632 | * false otherwise |
| 4633 | */ |
| 4634 | @Override |
| 4635 | public void setCrossSimCallingEnabled(int subId, boolean isEnabled) { |
| 4636 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4637 | "setCrossSimCallingEnabled"); |
| 4638 | final long identity = Binder.clearCallingIdentity(); |
| 4639 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4640 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4641 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4642 | // 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] | 4643 | ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled); |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 4644 | } catch (ImsException e) { |
| 4645 | throw new ServiceSpecificException(e.getCode()); |
| 4646 | } finally { |
| 4647 | Binder.restoreCallingIdentity(identity); |
| 4648 | } |
| 4649 | } |
| 4650 | |
| 4651 | /** |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4652 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4653 | * @param subId The subscription to use to check the configuration. |
| 4654 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4655 | @Override |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4656 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4657 | public boolean isVoWiFiRoamingSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4658 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4659 | mApp, subId, "isVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4660 | final long identity = Binder.clearCallingIdentity(); |
| 4661 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4662 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4663 | // 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] | 4664 | return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4665 | } catch (ImsException e) { |
| 4666 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4667 | } finally { |
| 4668 | Binder.restoreCallingIdentity(identity); |
| 4669 | } |
| 4670 | } |
| 4671 | |
| 4672 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4673 | public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4674 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4675 | "setVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4676 | final long identity = Binder.clearCallingIdentity(); |
| 4677 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4678 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4679 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4680 | // 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] | 4681 | ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4682 | } catch (ImsException e) { |
| 4683 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4684 | } finally { |
| 4685 | Binder.restoreCallingIdentity(identity); |
| 4686 | } |
| 4687 | } |
| 4688 | |
| 4689 | @Override |
| 4690 | public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) { |
| 4691 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4692 | "setVoWiFiNonPersistent"); |
| 4693 | final long identity = Binder.clearCallingIdentity(); |
| 4694 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4695 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4696 | // This setting will be ignored if the ImsService isn't up. |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4697 | ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4698 | } catch (ImsException e) { |
| 4699 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4700 | } finally { |
| 4701 | Binder.restoreCallingIdentity(identity); |
| 4702 | } |
| 4703 | } |
| 4704 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4705 | /** |
| 4706 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4707 | * @param subId The subscription to use to check the configuration. |
| 4708 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4709 | @Override |
| 4710 | public int getVoWiFiModeSetting(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4711 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4712 | mApp, subId, "getVoWiFiModeSetting"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4713 | final long identity = Binder.clearCallingIdentity(); |
| 4714 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4715 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4716 | // 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] | 4717 | return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4718 | } catch (ImsException e) { |
| 4719 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4720 | } finally { |
| 4721 | Binder.restoreCallingIdentity(identity); |
| 4722 | } |
| 4723 | } |
| 4724 | |
| 4725 | @Override |
| 4726 | public void setVoWiFiModeSetting(int subId, int mode) { |
| 4727 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4728 | "setVoWiFiModeSetting"); |
| 4729 | final long identity = Binder.clearCallingIdentity(); |
| 4730 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4731 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4732 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4733 | // 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] | 4734 | ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4735 | } catch (ImsException e) { |
| 4736 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4737 | } finally { |
| 4738 | Binder.restoreCallingIdentity(identity); |
| 4739 | } |
| 4740 | } |
| 4741 | |
| 4742 | @Override |
| 4743 | public int getVoWiFiRoamingModeSetting(int subId) { |
| 4744 | enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting"); |
| 4745 | final long identity = Binder.clearCallingIdentity(); |
| 4746 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4747 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4748 | // 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] | 4749 | return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4750 | } catch (ImsException e) { |
| 4751 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4752 | } finally { |
| 4753 | Binder.restoreCallingIdentity(identity); |
| 4754 | } |
| 4755 | } |
| 4756 | |
| 4757 | @Override |
| 4758 | public void setVoWiFiRoamingModeSetting(int subId, int mode) { |
| 4759 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4760 | "setVoWiFiRoamingModeSetting"); |
| 4761 | final long identity = Binder.clearCallingIdentity(); |
| 4762 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4763 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4764 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4765 | // 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] | 4766 | ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4767 | } catch (ImsException e) { |
| 4768 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4769 | } finally { |
| 4770 | Binder.restoreCallingIdentity(identity); |
| 4771 | } |
| 4772 | } |
| 4773 | |
| 4774 | @Override |
| 4775 | public void setRttCapabilitySetting(int subId, boolean isEnabled) { |
| 4776 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4777 | "setRttCapabilityEnabled"); |
| 4778 | final long identity = Binder.clearCallingIdentity(); |
| 4779 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4780 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4781 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4782 | // 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] | 4783 | ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4784 | } catch (ImsException e) { |
| 4785 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4786 | } finally { |
| 4787 | Binder.restoreCallingIdentity(identity); |
| 4788 | } |
| 4789 | } |
| 4790 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4791 | /** |
| 4792 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4793 | * @param subId The subscription to use to check the configuration. |
| 4794 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4795 | @Override |
| 4796 | public boolean isTtyOverVolteEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4797 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4798 | mApp, subId, "isTtyOverVolteEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4799 | final long identity = Binder.clearCallingIdentity(); |
| 4800 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4801 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4802 | // 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] | 4803 | return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4804 | } catch (ImsException e) { |
| 4805 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4806 | } finally { |
| 4807 | Binder.restoreCallingIdentity(identity); |
| 4808 | } |
| 4809 | } |
| 4810 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4811 | @Override |
| 4812 | public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 4813 | enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4814 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4815 | final long identity = Binder.clearCallingIdentity(); |
| 4816 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4817 | if (!isImsAvailableOnDevice()) { |
| 4818 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4819 | "IMS not available on device."); |
| 4820 | } |
| 4821 | int slotId = getSlotIndexOrException(subId); |
| 4822 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 4823 | ImsManager.getInstance(mApp, slotId) |
| 4824 | .addProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4825 | } catch (ImsException e) { |
| 4826 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4827 | } finally { |
| 4828 | Binder.restoreCallingIdentity(identity); |
| 4829 | } |
| 4830 | } |
| 4831 | |
| 4832 | @Override |
| 4833 | public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 4834 | enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4835 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4836 | final long identity = Binder.clearCallingIdentity(); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4837 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4838 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4839 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4840 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4841 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4842 | .removeProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4843 | } catch (ImsException e) { |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4844 | Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId |
| 4845 | + "is inactive, ignoring unregister."); |
| 4846 | // If the subscription is no longer active, just return, since the callback will already |
| 4847 | // have been removed internally. |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4848 | } finally { |
| 4849 | Binder.restoreCallingIdentity(identity); |
| 4850 | } |
| 4851 | } |
| 4852 | |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4853 | @Override |
| 4854 | public void registerFeatureProvisioningChangedCallback(int subId, |
| 4855 | IFeatureProvisioningCallback callback) { |
| 4856 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4857 | mApp, subId, "registerFeatureProvisioningChangedCallback"); |
| 4858 | |
| 4859 | final long identity = Binder.clearCallingIdentity(); |
| 4860 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4861 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4862 | } |
| 4863 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 4864 | try { |
| 4865 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 4866 | if (controller == null) { |
| 4867 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4868 | "Device does not support IMS"); |
| 4869 | } |
| 4870 | controller.addFeatureProvisioningChangedCallback(subId, callback); |
| 4871 | } finally { |
| 4872 | Binder.restoreCallingIdentity(identity); |
| 4873 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4874 | } |
| 4875 | |
| 4876 | @Override |
| 4877 | public void unregisterFeatureProvisioningChangedCallback(int subId, |
| 4878 | IFeatureProvisioningCallback callback) { |
| 4879 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4880 | mApp, subId, "unregisterFeatureProvisioningChangedCallback"); |
| 4881 | |
| 4882 | final long identity = Binder.clearCallingIdentity(); |
| 4883 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4884 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4885 | } |
| 4886 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 4887 | try { |
| 4888 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 4889 | if (controller == null) { |
| 4890 | loge("unregisterFeatureProvisioningChangedCallback: Device does not support IMS"); |
| 4891 | return; |
| 4892 | } |
| 4893 | controller.removeFeatureProvisioningChangedCallback(subId, callback); |
| 4894 | } finally { |
| 4895 | Binder.restoreCallingIdentity(identity); |
| 4896 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4897 | } |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4898 | |
| 4899 | private void checkModifyPhoneStatePermission(int subId, String message) { |
| 4900 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4901 | message); |
| 4902 | } |
| 4903 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4904 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4905 | public void setRcsProvisioningStatusForCapability(int subId, int capability, int tech, |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4906 | boolean isProvisioned) { |
| 4907 | checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability"); |
| 4908 | |
| 4909 | final long identity = Binder.clearCallingIdentity(); |
| 4910 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 4911 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 4912 | if (controller == null) { |
| 4913 | loge("setRcsProvisioningStatusForCapability: Device does not support IMS"); |
| 4914 | return; |
| 4915 | } |
| 4916 | controller.setRcsProvisioningStatusForCapability( |
| 4917 | subId, capability, tech, isProvisioned); |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4918 | } finally { |
| 4919 | Binder.restoreCallingIdentity(identity); |
| 4920 | } |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4921 | } |
| 4922 | |
| 4923 | |
| 4924 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4925 | public boolean getRcsProvisioningStatusForCapability(int subId, int capability, int tech) { |
| 4926 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4927 | mApp, subId, "getRcsProvisioningStatusForCapability"); |
| 4928 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4929 | final long identity = Binder.clearCallingIdentity(); |
| 4930 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 4931 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 4932 | if (controller == null) { |
| 4933 | loge("getRcsProvisioningStatusForCapability: Device does not support IMS"); |
| 4934 | |
| 4935 | // device does not support IMS, this method will return true always. |
| 4936 | return true; |
| 4937 | } |
| 4938 | return controller.getRcsProvisioningStatusForCapability(subId, capability, tech); |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4939 | } finally { |
| 4940 | Binder.restoreCallingIdentity(identity); |
| 4941 | } |
| 4942 | } |
| 4943 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4944 | @Override |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4945 | public void setImsProvisioningStatusForCapability(int subId, int capability, int tech, |
| 4946 | boolean isProvisioned) { |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4947 | checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4948 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4949 | final long identity = Binder.clearCallingIdentity(); |
| 4950 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 4951 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 4952 | if (controller == null) { |
| 4953 | loge("setImsProvisioningStatusForCapability: Device does not support IMS"); |
| 4954 | return; |
| 4955 | } |
| 4956 | controller.setImsProvisioningStatusForCapability( |
| 4957 | subId, capability, tech, isProvisioned); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4958 | } finally { |
| 4959 | Binder.restoreCallingIdentity(identity); |
| 4960 | } |
| 4961 | } |
| 4962 | |
| 4963 | @Override |
| 4964 | public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) { |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4965 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4966 | mApp, subId, "getProvisioningStatusForCapability"); |
| 4967 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4968 | final long identity = Binder.clearCallingIdentity(); |
| 4969 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 4970 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 4971 | if (controller == null) { |
| 4972 | loge("getImsProvisioningStatusForCapability: Device does not support IMS"); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4973 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 4974 | // device does not support IMS, this method will return true always. |
| 4975 | return true; |
| 4976 | } |
| 4977 | return controller.getImsProvisioningStatusForCapability(subId, capability, tech); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4978 | } finally { |
| 4979 | Binder.restoreCallingIdentity(identity); |
| 4980 | } |
| 4981 | } |
| 4982 | |
| 4983 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4984 | public boolean isProvisioningRequiredForCapability(int subId, int capability, int tech) { |
| 4985 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4986 | mApp, subId, "isProvisioningRequiredForCapability"); |
| 4987 | |
| 4988 | final long identity = Binder.clearCallingIdentity(); |
| 4989 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 4990 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 4991 | if (controller == null) { |
| 4992 | loge("isProvisioningRequiredForCapability: Device does not support IMS"); |
| 4993 | |
| 4994 | // device does not support IMS, this method will return false |
| 4995 | return false; |
| 4996 | } |
| 4997 | return controller.isImsProvisioningRequiredForCapability(subId, capability, tech); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4998 | } finally { |
| 4999 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5000 | } |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5001 | } |
| 5002 | |
| 5003 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5004 | public boolean isRcsProvisioningRequiredForCapability(int subId, int capability, int tech) { |
| 5005 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5006 | mApp, subId, "isProvisioningRequiredForCapability"); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5007 | |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5008 | final long identity = Binder.clearCallingIdentity(); |
| 5009 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5010 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5011 | if (controller == null) { |
| 5012 | loge("isRcsProvisioningRequiredForCapability: Device does not support IMS"); |
| 5013 | |
| 5014 | // device does not support IMS, this method will return false |
| 5015 | return false; |
| 5016 | } |
| 5017 | return controller.isRcsProvisioningRequiredForCapability(subId, capability, tech); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5018 | } finally { |
| 5019 | Binder.restoreCallingIdentity(identity); |
| 5020 | } |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5021 | } |
| 5022 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5023 | @Override |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5024 | public int getImsProvisioningInt(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5025 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5026 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 5027 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5028 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5029 | mApp, subId, "getImsProvisioningInt"); |
| 5030 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5031 | final long identity = Binder.clearCallingIdentity(); |
| 5032 | try { |
| 5033 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5034 | int slotId = getSlotIndex(subId); |
| 5035 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5036 | Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '" |
| 5037 | + subId + "' for key:" + key); |
| 5038 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
| 5039 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5040 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5041 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5042 | if (controller == null) { |
| 5043 | loge("getImsProvisioningInt: Device does not support IMS"); |
| 5044 | |
| 5045 | // device does not support IMS, this method will return CONFIG_RESULT_UNKNOWN. |
| 5046 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
| 5047 | } |
| 5048 | int retVal = controller.getProvisioningValue(subId, key); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5049 | if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) { |
| 5050 | return retVal; |
| 5051 | } |
| 5052 | |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5053 | return ImsManager.getInstance(mApp, slotId).getConfigInt(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5054 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5055 | Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '" |
| 5056 | + subId + "' for key:" + key); |
| 5057 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5058 | } finally { |
| 5059 | Binder.restoreCallingIdentity(identity); |
| 5060 | } |
| 5061 | } |
| 5062 | |
| 5063 | @Override |
| 5064 | public String getImsProvisioningString(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5065 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5066 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 5067 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5068 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5069 | mApp, subId, "getImsProvisioningString"); |
| 5070 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5071 | final long identity = Binder.clearCallingIdentity(); |
| 5072 | try { |
| 5073 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5074 | int slotId = getSlotIndex(subId); |
| 5075 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5076 | Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '" |
| 5077 | + subId + "' for key:" + key); |
| 5078 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC; |
| 5079 | } |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5080 | return ImsManager.getInstance(mApp, slotId).getConfigString(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5081 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5082 | Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '" |
| 5083 | + subId + "' for key:" + key); |
| 5084 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5085 | } finally { |
| 5086 | Binder.restoreCallingIdentity(identity); |
| 5087 | } |
| 5088 | } |
| 5089 | |
| 5090 | @Override |
| 5091 | public int setImsProvisioningInt(int subId, int key, int value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5092 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5093 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 5094 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 5095 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5096 | "setImsProvisioningInt"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5097 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5098 | final long identity = Binder.clearCallingIdentity(); |
| 5099 | try { |
| 5100 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5101 | int slotId = getSlotIndex(subId); |
| 5102 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5103 | Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '" |
| 5104 | + subId + "' for key:" + key); |
| 5105 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 5106 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5107 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5108 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5109 | if (controller == null) { |
| 5110 | loge("setImsProvisioningInt: Device does not support IMS"); |
| 5111 | |
| 5112 | // device does not support IMS, this method will return CONFIG_RESULT_FAILED. |
| 5113 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 5114 | } |
| 5115 | int retVal = controller.setProvisioningValue(subId, key, value); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5116 | if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) { |
| 5117 | return retVal; |
| 5118 | } |
| 5119 | |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5120 | return ImsManager.getInstance(mApp, slotId).setConfig(key, value); |
| 5121 | } catch (com.android.ims.ImsException | RemoteException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5122 | Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5123 | + "' for key:" + key, e); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5124 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5125 | } finally { |
| 5126 | Binder.restoreCallingIdentity(identity); |
| 5127 | } |
| 5128 | } |
| 5129 | |
| 5130 | @Override |
| 5131 | public int setImsProvisioningString(int subId, int key, String value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5132 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5133 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 5134 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 5135 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5136 | "setImsProvisioningString"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5137 | final long identity = Binder.clearCallingIdentity(); |
| 5138 | try { |
| 5139 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5140 | int slotId = getSlotIndex(subId); |
| 5141 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5142 | Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '" |
| 5143 | + subId + "' for key:" + key); |
| 5144 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 5145 | } |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5146 | return ImsManager.getInstance(mApp, slotId).setConfig(key, value); |
| 5147 | } catch (com.android.ims.ImsException | RemoteException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5148 | Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5149 | + "' for key:" + key, e); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5150 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5151 | } finally { |
| 5152 | Binder.restoreCallingIdentity(identity); |
| 5153 | } |
| 5154 | } |
| 5155 | |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5156 | /** |
| 5157 | * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL |
| 5158 | * for the given slot ID or no ImsResolver instance has been created. |
| 5159 | * @param slotId The slot ID that the IMS service is created for. |
| 5160 | * @throws ImsException If there is no ImsService configured for this slot. |
| 5161 | */ |
| 5162 | private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException { |
| 5163 | if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId, |
| 5164 | ImsFeature.FEATURE_MMTEL)) { |
| 5165 | throw new ImsException("This subscription does not support MMTEL over IMS", |
| 5166 | ImsException.CODE_ERROR_UNSUPPORTED_OPERATION); |
| 5167 | } |
| 5168 | } |
| 5169 | |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5170 | private int getSlotIndexOrException(int subId) throws ImsException { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5171 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 5172 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5173 | throw new ImsException("Invalid Subscription Id, subId=" + subId, |
| 5174 | ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5175 | } |
| 5176 | return slotId; |
| 5177 | } |
| 5178 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5179 | private int getSlotIndex(int subId) { |
| 5180 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 5181 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
| 5182 | return SubscriptionManager.INVALID_SIM_SLOT_INDEX; |
| 5183 | } |
| 5184 | return slotId; |
| 5185 | } |
| 5186 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5187 | /** |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 5188 | * Returns the data network type for a subId; does not throw SecurityException. |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5189 | */ |
| 5190 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5191 | public int getNetworkTypeForSubscriber(int subId, String callingPackage, |
| 5192 | String callingFeatureId) { |
Shuo Qian | 13d8915 | 2021-05-10 23:58:11 -0700 | [diff] [blame] | 5193 | try { |
| 5194 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 5195 | } catch (SecurityException se) { |
| 5196 | EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid()); |
| 5197 | throw new SecurityException("Package " + callingPackage + " does not belong to " |
| 5198 | + Binder.getCallingUid()); |
| 5199 | } |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 5200 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 5201 | if (targetSdk > android.os.Build.VERSION_CODES.Q) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5202 | return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 5203 | } else if (targetSdk == android.os.Build.VERSION_CODES.Q |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 5204 | && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5205 | mApp, subId, callingPackage, callingFeatureId, |
| 5206 | "getNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5207 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5208 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 5209 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5210 | final long identity = Binder.clearCallingIdentity(); |
| 5211 | try { |
| 5212 | final Phone phone = getPhone(subId); |
| 5213 | if (phone != null) { |
| 5214 | return phone.getServiceState().getDataNetworkType(); |
| 5215 | } else { |
| 5216 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5217 | } |
| 5218 | } finally { |
| 5219 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5220 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5221 | } |
| 5222 | |
| 5223 | /** |
| 5224 | * Returns the data network type |
| 5225 | */ |
| 5226 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5227 | public int getDataNetworkType(String callingPackage, String callingFeatureId) { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5228 | return getDataNetworkTypeForSubscriber(SubscriptionManager.getDefaultDataSubscriptionId(), |
Zoey Chen | fd61f7f | 2021-04-21 13:42:10 +0800 | [diff] [blame] | 5229 | callingPackage, callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5230 | } |
| 5231 | |
| 5232 | /** |
| 5233 | * Returns the data network type for a subId |
| 5234 | */ |
| 5235 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5236 | public int getDataNetworkTypeForSubscriber(int subId, String callingPackage, |
| 5237 | String callingFeatureId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 5238 | String functionName = "getDataNetworkTypeForSubscriber"; |
| 5239 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 5240 | mApp, functionName)) { |
| 5241 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 5242 | mApp, subId, callingPackage, callingFeatureId, functionName)) { |
| 5243 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5244 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5245 | } |
| 5246 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5247 | final long identity = Binder.clearCallingIdentity(); |
| 5248 | try { |
| 5249 | final Phone phone = getPhone(subId); |
| 5250 | if (phone != null) { |
| 5251 | return phone.getServiceState().getDataNetworkType(); |
| 5252 | } else { |
| 5253 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5254 | } |
| 5255 | } finally { |
| 5256 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5257 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5258 | } |
| 5259 | |
| 5260 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5261 | * Returns the Voice network type for a subId |
| 5262 | */ |
| 5263 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5264 | public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage, |
| 5265 | String callingFeatureId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 5266 | String functionName = "getVoiceNetworkTypeForSubscriber"; |
| 5267 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 5268 | mApp, functionName)) { |
| 5269 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 5270 | mApp, subId, callingPackage, callingFeatureId, functionName)) { |
| 5271 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5272 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 5273 | } |
| 5274 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5275 | final long identity = Binder.clearCallingIdentity(); |
| 5276 | try { |
| 5277 | final Phone phone = getPhone(subId); |
| 5278 | if (phone != null) { |
| 5279 | return phone.getServiceState().getVoiceNetworkType(); |
| 5280 | } else { |
| 5281 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5282 | } |
| 5283 | } finally { |
| 5284 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5285 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5286 | } |
| 5287 | |
| 5288 | /** |
| 5289 | * @return true if a ICC card is present |
| 5290 | */ |
| 5291 | public boolean hasIccCard() { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5292 | // FIXME Make changes to pass defaultSimId of type int |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5293 | return hasIccCardUsingSlotIndex(SubscriptionManager.getSlotIndex( |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5294 | getDefaultSubscription())); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5295 | } |
| 5296 | |
| 5297 | /** |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5298 | * @return true if a ICC card is present for a slotIndex |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5299 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5300 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5301 | public boolean hasIccCardUsingSlotIndex(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5302 | final long identity = Binder.clearCallingIdentity(); |
| 5303 | try { |
| 5304 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5305 | if (phone != null) { |
| 5306 | return phone.getIccCard().hasIccCard(); |
| 5307 | } else { |
| 5308 | return false; |
| 5309 | } |
| 5310 | } finally { |
| 5311 | Binder.restoreCallingIdentity(identity); |
Amit Mahajan | a6fc2a8 | 2015-01-06 11:53:51 -0800 | [diff] [blame] | 5312 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5313 | } |
| 5314 | |
| 5315 | /** |
| 5316 | * Return if the current radio is LTE on CDMA. This |
| 5317 | * is a tri-state return value as for a period of time |
| 5318 | * the mode may be unknown. |
| 5319 | * |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5320 | * @param callingPackage the name of the package making the call. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5321 | * @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] | 5322 | * or {@link Phone#LTE_ON_CDMA_TRUE} |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5323 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5324 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5325 | public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) { |
| 5326 | return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 5327 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5328 | } |
| 5329 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5330 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5331 | public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage, |
| 5332 | String callingFeatureId) { |
Sarah Chin | 790d292 | 2020-01-16 12:17:23 -0800 | [diff] [blame] | 5333 | try { |
| 5334 | enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber"); |
| 5335 | } catch (SecurityException e) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5336 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 5337 | } |
| 5338 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5339 | final long identity = Binder.clearCallingIdentity(); |
| 5340 | try { |
| 5341 | final Phone phone = getPhone(subId); |
| 5342 | if (phone == null) { |
| 5343 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 5344 | } else { |
Nathan Harold | 05ad633 | 2020-07-10 11:54:36 -0700 | [diff] [blame] | 5345 | return TelephonyProperties.lte_on_cdma_device() |
| 5346 | .orElse(PhoneConstants.LTE_ON_CDMA_FALSE); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5347 | } |
| 5348 | } finally { |
| 5349 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5350 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5351 | } |
| 5352 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5353 | /** |
| 5354 | * {@hide} |
| 5355 | * Returns Default subId, 0 in the case of single standby. |
| 5356 | */ |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 5357 | private int getDefaultSubscription() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5358 | return SubscriptionManager.getDefaultSubscriptionId(); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5359 | } |
| 5360 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 5361 | private int getSlotForDefaultSubscription() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5362 | return SubscriptionManager.getPhoneId(getDefaultSubscription()); |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 5363 | } |
| 5364 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 5365 | private int getPreferredVoiceSubscription() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5366 | return SubscriptionManager.getDefaultVoiceSubscriptionId(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5367 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5368 | |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 5369 | private boolean isActiveSubscription(int subId) { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5370 | if (PhoneFactory.isSubscriptionManagerServiceEnabled()) { |
| 5371 | return SubscriptionManagerService.getInstance().isActiveSubId(subId, |
| 5372 | mApp.getOpPackageName(), mApp.getFeatureId()); |
| 5373 | } |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 5374 | return mSubscriptionController.isActiveSubId(subId); |
| 5375 | } |
| 5376 | |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5377 | /** |
| 5378 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 5379 | */ |
| 5380 | public int getWhenToMakeWifiCalls() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5381 | final long identity = Binder.clearCallingIdentity(); |
| 5382 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5383 | return Settings.System.getInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5384 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, |
| 5385 | getWhenToMakeWifiCallsDefaultPreference()); |
| 5386 | } finally { |
| 5387 | Binder.restoreCallingIdentity(identity); |
| 5388 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5389 | } |
| 5390 | |
| 5391 | /** |
| 5392 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 5393 | */ |
| 5394 | public void setWhenToMakeWifiCalls(int preference) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5395 | final long identity = Binder.clearCallingIdentity(); |
| 5396 | try { |
| 5397 | if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5398 | Settings.System.putInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5399 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference); |
| 5400 | } finally { |
| 5401 | Binder.restoreCallingIdentity(identity); |
| 5402 | } |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 5403 | } |
| 5404 | |
Sailesh Nepal | d1e6815 | 2013-12-12 19:08:02 -0800 | [diff] [blame] | 5405 | private static int getWhenToMakeWifiCallsDefaultPreference() { |
Santos Cordon | da120f4 | 2014-08-06 04:44:34 -0700 | [diff] [blame] | 5406 | // TODO: Use a build property to choose this value. |
Evan Charlton | 9829e88 | 2013-12-19 15:30:38 -0800 | [diff] [blame] | 5407 | return TelephonyManager.WifiCallingChoices.ALWAYS_USE; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5408 | } |
Shishir Agrawal | 69f6812 | 2013-12-16 17:25:49 -0800 | [diff] [blame] | 5409 | |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5410 | private Phone getPhoneFromSlotPortIndexOrThrowException(int slotIndex, int portIndex) { |
| 5411 | int phoneId = UiccController.getInstance().getPhoneIdFromSlotPortIndex(slotIndex, |
| 5412 | portIndex); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5413 | if (phoneId == -1) { |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5414 | throw new IllegalArgumentException("Given slot index: " + slotIndex + " port index: " |
| 5415 | + portIndex + " does not correspond to an active phone"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5416 | } |
| 5417 | return PhoneFactory.getPhone(phoneId); |
| 5418 | } |
| 5419 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5420 | @Override |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 5421 | public IccOpenLogicalChannelResponse iccOpenLogicalChannel( |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5422 | @NonNull IccLogicalChannelRequest request) { |
| 5423 | Phone phone = getPhoneFromValidIccLogicalChannelRequest(request, |
| 5424 | /*message=*/ "iccOpenLogicalChannel"); |
| 5425 | |
| 5426 | if (DBG) log("iccOpenLogicalChannel: request=" + request); |
| 5427 | // Verify that the callingPackage in the request belongs to the calling UID |
| 5428 | mAppOps.checkPackage(Binder.getCallingUid(), request.callingPackage); |
| 5429 | |
| 5430 | return iccOpenLogicalChannelWithPermission(phone, request); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5431 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5432 | |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5433 | private Phone getPhoneFromValidIccLogicalChannelRequest( |
| 5434 | @NonNull IccLogicalChannelRequest request, String message) { |
| 5435 | Phone phone; |
| 5436 | if (request.subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) { |
| 5437 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5438 | mApp, request.subId, message); |
| 5439 | phone = getPhoneFromSubId(request.subId); |
| 5440 | } else if (request.slotIndex != SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5441 | enforceModifyPermission(); |
| 5442 | phone = getPhoneFromSlotPortIndexOrThrowException(request.slotIndex, request.portIndex); |
| 5443 | } else { |
| 5444 | throw new IllegalArgumentException("Both subId and slotIndex in request are invalid."); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5445 | } |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5446 | return phone; |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5447 | } |
| 5448 | |
| 5449 | private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone, |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5450 | IccLogicalChannelRequest channelRequest) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5451 | final long identity = Binder.clearCallingIdentity(); |
| 5452 | try { |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5453 | if (TextUtils.equals(ISDR_AID, channelRequest.aid)) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5454 | // Only allows LPA to open logical channel to ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5455 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 5456 | .getContext().getPackageManager()); |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5457 | if (bestComponent == null || !TextUtils.equals(channelRequest.callingPackage, |
| 5458 | bestComponent.packageName)) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5459 | loge("The calling package is not allowed to access ISD-R."); |
| 5460 | throw new SecurityException( |
| 5461 | "The calling package is not allowed to access ISD-R."); |
| 5462 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 5463 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 5464 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5465 | IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest( |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5466 | CMD_OPEN_CHANNEL, channelRequest, phone, null /* workSource */); |
| 5467 | if (DBG) log("iccOpenLogicalChannelWithPermission: response=" + response); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5468 | return response; |
| 5469 | } finally { |
| 5470 | Binder.restoreCallingIdentity(identity); |
| 5471 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5472 | } |
| 5473 | |
| 5474 | @Override |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5475 | public boolean iccCloseLogicalChannel(@NonNull IccLogicalChannelRequest request) { |
| 5476 | Phone phone = getPhoneFromValidIccLogicalChannelRequest(request, |
| 5477 | /*message=*/"iccCloseLogicalChannel"); |
| 5478 | |
| 5479 | if (DBG) log("iccCloseLogicalChannel: request=" + request); |
| 5480 | |
| 5481 | return iccCloseLogicalChannelWithPermission(phone, request); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5482 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5483 | |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5484 | private boolean iccCloseLogicalChannelWithPermission(Phone phone, |
| 5485 | IccLogicalChannelRequest request) { |
Chen Xu | a8f0dff | 2022-02-12 00:34:15 -0800 | [diff] [blame] | 5486 | // before this feature is enabled, this API should only return false if |
| 5487 | // the operation fails instead of throwing runtime exception for |
| 5488 | // backward-compatibility. |
| 5489 | final boolean shouldThrowExceptionOnFailure = CompatChanges.isChangeEnabled( |
| 5490 | ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE, Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5491 | final long identity = Binder.clearCallingIdentity(); |
| 5492 | try { |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5493 | if (request.channel < 0) { |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 5494 | throw new IllegalArgumentException("request.channel is less than 0"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5495 | } |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 5496 | Object result = sendRequest(CMD_CLOSE_CHANNEL, request.channel, phone, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5497 | null /* workSource */); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 5498 | Boolean success = false; |
| 5499 | if (result instanceof RuntimeException) { |
| 5500 | // if there is an exception returned, throw from the binder thread here. |
Chen Xu | a8f0dff | 2022-02-12 00:34:15 -0800 | [diff] [blame] | 5501 | if (shouldThrowExceptionOnFailure) { |
| 5502 | throw (RuntimeException) result; |
| 5503 | } else { |
| 5504 | return false; |
| 5505 | } |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 5506 | } else if (result instanceof Boolean) { |
| 5507 | success = (Boolean) result; |
| 5508 | } else { |
| 5509 | loge("iccCloseLogicalChannelWithPermission: supported return type " + result); |
| 5510 | } |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5511 | if (DBG) log("iccCloseLogicalChannelWithPermission: success=" + success); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5512 | return success; |
| 5513 | } finally { |
| 5514 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5515 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5516 | } |
| 5517 | |
| 5518 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5519 | public String iccTransmitApduLogicalChannel(int subId, int channel, int cla, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5520 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5521 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5522 | mApp, subId, "iccTransmitApduLogicalChannel"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5523 | if (DBG) { |
| 5524 | log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel |
| 5525 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 5526 | + p3 + " data=" + data); |
| 5527 | } |
| 5528 | return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla, |
| 5529 | command, p1, p2, p3, data); |
| 5530 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5531 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5532 | @Override |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5533 | public String iccTransmitApduLogicalChannelByPort(int slotIndex, int portIndex, int channel, |
| 5534 | int cla, int command, int p1, int p2, int p3, String data) { |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5535 | enforceModifyPermission(); |
| 5536 | if (DBG) { |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5537 | log("iccTransmitApduLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex=" |
| 5538 | + portIndex + " chnl=" + channel + " cla=" + cla + " cmd=" + command + " p1=" |
| 5539 | + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5540 | } |
| 5541 | return iccTransmitApduLogicalChannelWithPermission( |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5542 | getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel, cla, |
| 5543 | command, p1, p2, p3, data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5544 | } |
| 5545 | |
| 5546 | private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla, |
| 5547 | int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5548 | final long identity = Binder.clearCallingIdentity(); |
| 5549 | try { |
Hall Liu | 4fd771b | 2019-05-02 09:16:29 -0700 | [diff] [blame] | 5550 | if (channel <= 0) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5551 | return ""; |
| 5552 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5553 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5554 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5555 | new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone, |
| 5556 | null /* workSource */); |
| 5557 | if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5558 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5559 | // Append the returned status code to the end of the response payload. |
| 5560 | String s = Integer.toHexString( |
| 5561 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 5562 | if (response.payload != null) { |
| 5563 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 5564 | } |
| 5565 | return s; |
| 5566 | } finally { |
| 5567 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 5568 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5569 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5570 | |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5571 | @Override |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 5572 | public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla, |
| 5573 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5574 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5575 | mApp, subId, "iccTransmitApduBasicChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5576 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5577 | if (DBG) { |
| 5578 | log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" |
| 5579 | + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
| 5580 | } |
| 5581 | return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage, |
| 5582 | cla, command, p1, p2, p3, data); |
| 5583 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5584 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5585 | @Override |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5586 | public String iccTransmitApduBasicChannelByPort(int slotIndex, int portIndex, |
| 5587 | 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] | 5588 | enforceModifyPermission(); |
| 5589 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 5590 | if (DBG) { |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5591 | log("iccTransmitApduBasicChannelByPort: slotIndex=" + slotIndex + " portIndex=" |
| 5592 | + portIndex + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" |
| 5593 | + p2 + " p3=" + p3 + " data=" + data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5594 | } |
| 5595 | |
| 5596 | return iccTransmitApduBasicChannelWithPermission( |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5597 | getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), callingPackage, |
| 5598 | cla, command, p1, p2, p3, data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5599 | } |
| 5600 | |
| 5601 | // open APDU basic channel assuming the caller has sufficient permissions |
| 5602 | private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage, |
| 5603 | int cla, int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5604 | final long identity = Binder.clearCallingIdentity(); |
| 5605 | try { |
| 5606 | if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3 |
| 5607 | && TextUtils.equals(ISDR_AID, data)) { |
| 5608 | // Only allows LPA to select ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5609 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 5610 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5611 | if (bestComponent == null |
| 5612 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 5613 | loge("The calling package is not allowed to select ISD-R."); |
| 5614 | throw new SecurityException( |
| 5615 | "The calling package is not allowed to select ISD-R."); |
| 5616 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 5617 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 5618 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5619 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5620 | new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone, |
| 5621 | null /* workSource */); |
| 5622 | if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5623 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5624 | // Append the returned status code to the end of the response payload. |
| 5625 | String s = Integer.toHexString( |
| 5626 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 5627 | if (response.payload != null) { |
| 5628 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 5629 | } |
| 5630 | return s; |
| 5631 | } finally { |
| 5632 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 5633 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5634 | } |
| 5635 | |
| 5636 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5637 | 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] | 5638 | String filePath) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5639 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5640 | mApp, subId, "iccExchangeSimIO"); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5641 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5642 | final long identity = Binder.clearCallingIdentity(); |
| 5643 | try { |
| 5644 | if (DBG) { |
| 5645 | log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " |
| 5646 | + p1 + " " + p2 + " " + p3 + ":" + filePath); |
| 5647 | } |
| 5648 | |
| 5649 | IccIoResult response = |
| 5650 | (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO, |
| 5651 | new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath), |
| 5652 | subId); |
| 5653 | |
| 5654 | if (DBG) { |
| 5655 | log("Exchange SIM_IO [R]" + response); |
| 5656 | } |
| 5657 | |
| 5658 | byte[] result = null; |
| 5659 | int length = 2; |
| 5660 | if (response.payload != null) { |
| 5661 | length = 2 + response.payload.length; |
| 5662 | result = new byte[length]; |
| 5663 | System.arraycopy(response.payload, 0, result, 0, response.payload.length); |
| 5664 | } else { |
| 5665 | result = new byte[length]; |
| 5666 | } |
| 5667 | |
| 5668 | result[length - 1] = (byte) response.sw2; |
| 5669 | result[length - 2] = (byte) response.sw1; |
| 5670 | return result; |
| 5671 | } finally { |
| 5672 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5673 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5674 | } |
| 5675 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5676 | /** |
| 5677 | * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM) |
| 5678 | * on a particular subscription |
| 5679 | */ |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5680 | public String[] getForbiddenPlmns(int subId, int appType, String callingPackage, |
| 5681 | String callingFeatureId) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 5682 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5683 | mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 5684 | return null; |
| 5685 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5686 | |
| 5687 | final long identity = Binder.clearCallingIdentity(); |
| 5688 | try { |
| 5689 | if (appType != TelephonyManager.APPTYPE_USIM |
| 5690 | && appType != TelephonyManager.APPTYPE_SIM) { |
| 5691 | loge("getForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 5692 | return null; |
| 5693 | } |
| 5694 | Object response = sendRequest( |
| 5695 | CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId); |
| 5696 | if (response instanceof String[]) { |
| 5697 | return (String[]) response; |
| 5698 | } |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5699 | // Response is an Exception of some kind |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5700 | // which is signalled to the user as a NULL retval |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5701 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5702 | } finally { |
| 5703 | Binder.restoreCallingIdentity(identity); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5704 | } |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5705 | } |
| 5706 | |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5707 | /** |
| 5708 | * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular |
| 5709 | * subscription. |
| 5710 | * |
| 5711 | * @param subId the id of the subscription. |
| 5712 | * @param appType the uicc app type, must be USIM or SIM. |
| 5713 | * @param fplmns the Forbiden plmns list that needed to be written to the SIM. |
| 5714 | * @param callingPackage the op Package name. |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5715 | * @param callingFeatureId the feature in the package. |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5716 | * @return number of fplmns that is successfully written to the SIM. |
| 5717 | */ |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5718 | public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage, |
| 5719 | String callingFeatureId) { |
Jayachandran C | 5b0d75a | 2021-10-21 22:15:27 -0700 | [diff] [blame] | 5720 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5721 | mApp, subId, "setForbiddenPlmns"); |
| 5722 | |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5723 | if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) { |
| 5724 | loge("setForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 5725 | throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM"); |
| 5726 | } |
| 5727 | if (fplmns == null) { |
| 5728 | throw new IllegalArgumentException("Fplmn List provided is null"); |
| 5729 | } |
| 5730 | for (String fplmn : fplmns) { |
| 5731 | if (!CellIdentity.isValidPlmn(fplmn)) { |
| 5732 | throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn); |
| 5733 | } |
| 5734 | } |
| 5735 | final long identity = Binder.clearCallingIdentity(); |
| 5736 | try { |
| 5737 | Object response = sendRequest( |
| 5738 | CMD_SET_FORBIDDEN_PLMNS, |
| 5739 | new Pair<Integer, List<String>>(new Integer(appType), fplmns), |
| 5740 | subId); |
| 5741 | return (int) response; |
| 5742 | } finally { |
| 5743 | Binder.restoreCallingIdentity(identity); |
| 5744 | } |
| 5745 | } |
| 5746 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5747 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5748 | public String sendEnvelopeWithStatus(int subId, String content) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5749 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5750 | mApp, subId, "sendEnvelopeWithStatus"); |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5751 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5752 | final long identity = Binder.clearCallingIdentity(); |
| 5753 | try { |
| 5754 | IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId); |
| 5755 | if (response.payload == null) { |
| 5756 | return ""; |
| 5757 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5758 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5759 | // Append the returned status code to the end of the response payload. |
| 5760 | String s = Integer.toHexString( |
| 5761 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 5762 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 5763 | return s; |
| 5764 | } finally { |
| 5765 | Binder.restoreCallingIdentity(identity); |
| 5766 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5767 | } |
| 5768 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5769 | /** |
| 5770 | * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 5771 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 5772 | * |
| 5773 | * @param itemID the ID of the item to read |
| 5774 | * @return the NV item as a String, or null on error. |
| 5775 | */ |
| 5776 | @Override |
| 5777 | public String nvReadItem(int itemID) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5778 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5779 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5780 | mApp, getDefaultSubscription(), "nvReadItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5781 | |
| 5782 | final long identity = Binder.clearCallingIdentity(); |
| 5783 | try { |
| 5784 | if (DBG) log("nvReadItem: item " + itemID); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5785 | String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5786 | if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"'); |
| 5787 | return value; |
| 5788 | } finally { |
| 5789 | Binder.restoreCallingIdentity(identity); |
| 5790 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5791 | } |
| 5792 | |
| 5793 | /** |
| 5794 | * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 5795 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 5796 | * |
| 5797 | * @param itemID the ID of the item to read |
| 5798 | * @param itemValue the value to write, as a String |
| 5799 | * @return true on success; false on any failure |
| 5800 | */ |
| 5801 | @Override |
| 5802 | public boolean nvWriteItem(int itemID, String itemValue) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5803 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5804 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5805 | mApp, getDefaultSubscription(), "nvWriteItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5806 | |
| 5807 | final long identity = Binder.clearCallingIdentity(); |
| 5808 | try { |
| 5809 | if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"'); |
| 5810 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5811 | new Pair<Integer, String>(itemID, itemValue), workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5812 | if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail")); |
| 5813 | return success; |
| 5814 | } finally { |
| 5815 | Binder.restoreCallingIdentity(identity); |
| 5816 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5817 | } |
| 5818 | |
| 5819 | /** |
| 5820 | * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage. |
| 5821 | * Used for device configuration by some CDMA operators. |
| 5822 | * |
| 5823 | * @param preferredRoamingList byte array containing the new PRL |
| 5824 | * @return true on success; false on any failure |
| 5825 | */ |
| 5826 | @Override |
| 5827 | public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5828 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5829 | mApp, getDefaultSubscription(), "nvWriteCdmaPrl"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5830 | |
| 5831 | final long identity = Binder.clearCallingIdentity(); |
| 5832 | try { |
| 5833 | if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList)); |
| 5834 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList); |
| 5835 | if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail")); |
| 5836 | return success; |
| 5837 | } finally { |
| 5838 | Binder.restoreCallingIdentity(identity); |
| 5839 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5840 | } |
| 5841 | |
| 5842 | /** |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5843 | * 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] | 5844 | * Used for device configuration by some CDMA operators. |
| 5845 | * |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5846 | * @param slotIndex - device slot. |
| 5847 | * |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5848 | * @return true on success; false on any failure |
| 5849 | */ |
| 5850 | @Override |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5851 | public boolean resetModemConfig(int slotIndex) { |
| 5852 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5853 | if (phone != null) { |
| 5854 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5855 | mApp, phone.getSubId(), "resetModemConfig"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5856 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5857 | final long identity = Binder.clearCallingIdentity(); |
| 5858 | try { |
| 5859 | Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null); |
| 5860 | if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 5861 | return success; |
| 5862 | } finally { |
| 5863 | Binder.restoreCallingIdentity(identity); |
| 5864 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5865 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5866 | return false; |
| 5867 | } |
| 5868 | |
| 5869 | /** |
| 5870 | * Generate a radio modem reset. Used for device configuration by some CDMA operators. |
| 5871 | * |
| 5872 | * @param slotIndex - device slot. |
| 5873 | * |
| 5874 | * @return true on success; false on any failure |
| 5875 | */ |
| 5876 | @Override |
| 5877 | public boolean rebootModem(int slotIndex) { |
| 5878 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5879 | if (phone != null) { |
| 5880 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5881 | mApp, phone.getSubId(), "rebootModem"); |
| 5882 | |
| 5883 | final long identity = Binder.clearCallingIdentity(); |
| 5884 | try { |
| 5885 | Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null); |
| 5886 | if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail")); |
| 5887 | return success; |
| 5888 | } finally { |
| 5889 | Binder.restoreCallingIdentity(identity); |
| 5890 | } |
| 5891 | } |
| 5892 | return false; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5893 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5894 | |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5895 | /** |
Grace Jia | aa2eb6b | 2020-01-09 16:26:08 -0800 | [diff] [blame] | 5896 | * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and |
| 5897 | * {@link #disableIms(int)}. |
| 5898 | * @param slotIndex device slot. |
| 5899 | */ |
| 5900 | public void resetIms(int slotIndex) { |
| 5901 | enforceModifyPermission(); |
| 5902 | |
| 5903 | final long identity = Binder.clearCallingIdentity(); |
| 5904 | try { |
| 5905 | if (mImsResolver == null) { |
| 5906 | // may happen if the does not support IMS. |
| 5907 | return; |
| 5908 | } |
Hyunho | a17ac7c | 2022-08-30 12:03:04 +0000 | [diff] [blame] | 5909 | mImsResolver.resetIms(slotIndex); |
Grace Jia | aa2eb6b | 2020-01-09 16:26:08 -0800 | [diff] [blame] | 5910 | } finally { |
| 5911 | Binder.restoreCallingIdentity(identity); |
| 5912 | } |
| 5913 | } |
| 5914 | |
| 5915 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5916 | * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability |
| 5917 | * status updates, if not already enabled. |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5918 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5919 | public void enableIms(int slotId) { |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5920 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5921 | |
| 5922 | final long identity = Binder.clearCallingIdentity(); |
| 5923 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5924 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5925 | // may happen if the device does not support IMS. |
| 5926 | return; |
| 5927 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5928 | mImsResolver.enableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5929 | } finally { |
| 5930 | Binder.restoreCallingIdentity(identity); |
| 5931 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5932 | } |
| 5933 | |
| 5934 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5935 | * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature |
| 5936 | * status updates to disabled. |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5937 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5938 | public void disableIms(int slotId) { |
| 5939 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5940 | |
| 5941 | final long identity = Binder.clearCallingIdentity(); |
| 5942 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5943 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5944 | // may happen if the device does not support IMS. |
| 5945 | return; |
| 5946 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5947 | mImsResolver.disableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5948 | } finally { |
| 5949 | Binder.restoreCallingIdentity(identity); |
| 5950 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5951 | } |
| 5952 | |
| 5953 | /** |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5954 | * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback |
| 5955 | * callback. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5956 | */ |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5957 | @Override |
Brad Ebinger | f6aca00 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 5958 | public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) { |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5959 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5960 | |
| 5961 | final long identity = Binder.clearCallingIdentity(); |
| 5962 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5963 | if (mImsResolver == null) { |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5964 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 5965 | "Device does not support IMS"); |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5966 | } |
Brad Ebinger | f6aca00 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 5967 | mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5968 | } finally { |
| 5969 | Binder.restoreCallingIdentity(identity); |
| 5970 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5971 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5972 | /** |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5973 | * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature. |
| 5974 | */ |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5975 | @Override |
| 5976 | public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) { |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5977 | enforceModifyPermission(); |
| 5978 | |
| 5979 | final long identity = Binder.clearCallingIdentity(); |
| 5980 | try { |
| 5981 | if (mImsResolver == null) return; |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5982 | mImsResolver.unregisterImsFeatureCallback(callback); |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5983 | } finally { |
| 5984 | Binder.restoreCallingIdentity(identity); |
| 5985 | } |
| 5986 | } |
| 5987 | |
| 5988 | /** |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5989 | * Returns the {@link IImsRegistration} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5990 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5991 | */ |
| 5992 | public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException { |
| 5993 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5994 | |
| 5995 | final long identity = Binder.clearCallingIdentity(); |
| 5996 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5997 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5998 | // may happen if the device does not support IMS. |
| 5999 | return null; |
| 6000 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6001 | return mImsResolver.getImsRegistration(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6002 | } finally { |
| 6003 | Binder.restoreCallingIdentity(identity); |
| 6004 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 6005 | } |
| 6006 | |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6007 | /** |
| 6008 | * Returns the {@link IImsConfig} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6009 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6010 | */ |
| 6011 | public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException { |
| 6012 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6013 | |
| 6014 | final long identity = Binder.clearCallingIdentity(); |
| 6015 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6016 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6017 | // may happen if the device does not support IMS. |
| 6018 | return null; |
| 6019 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6020 | return mImsResolver.getImsConfig(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6021 | } finally { |
| 6022 | Binder.restoreCallingIdentity(identity); |
| 6023 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6024 | } |
| 6025 | |
Brad Ebinger | 884c07b | 2018-02-15 16:17:40 -0800 | [diff] [blame] | 6026 | /** |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6027 | * Sets the ImsService Package Name that Telephony will bind to. |
| 6028 | * |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6029 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 6030 | * @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] | 6031 | * ImsService is the device default ImsService. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6032 | * @param featureTypes An integer array of feature types associated with a packageName. |
| 6033 | * @param packageName The name of the package that the current configuration will be replaced |
| 6034 | * with. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6035 | * @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] | 6036 | */ |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6037 | public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService, |
| 6038 | int[] featureTypes, String packageName) { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6039 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 6040 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
Jack Yu | 00ece8c | 2022-11-19 22:29:12 -0800 | [diff] [blame] | 6041 | SubscriptionManager.getSubscriptionId(slotIndex), "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 6042 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6043 | final long identity = Binder.clearCallingIdentity(); |
| 6044 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6045 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6046 | // may happen if the device does not support IMS. |
| 6047 | return false; |
| 6048 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6049 | Map<Integer, String> featureConfig = new HashMap<>(); |
| 6050 | for (int featureType : featureTypes) { |
| 6051 | featureConfig.put(featureType, packageName); |
| 6052 | } |
| 6053 | return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService, |
| 6054 | featureConfig); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6055 | } finally { |
| 6056 | Binder.restoreCallingIdentity(identity); |
| 6057 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6058 | } |
| 6059 | |
| 6060 | /** |
Brad Ebinger | 999d330 | 2020-11-25 14:31:39 -0800 | [diff] [blame] | 6061 | * Clears any carrier ImsService overrides for the slot index specified that were previously |
| 6062 | * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}. |
| 6063 | * |
| 6064 | * This should only be used for testing. |
| 6065 | * |
| 6066 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 6067 | * @return true if clearing the carrier ImsService override succeeded or false if it did not. |
| 6068 | */ |
| 6069 | @Override |
| 6070 | public boolean clearCarrierImsServiceOverride(int slotIndex) { |
Brad Ebinger | 999d330 | 2020-11-25 14:31:39 -0800 | [diff] [blame] | 6071 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 6072 | "clearCarrierImsServiceOverride"); |
| 6073 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
Jack Yu | 00ece8c | 2022-11-19 22:29:12 -0800 | [diff] [blame] | 6074 | SubscriptionManager.getSubscriptionId(slotIndex), "clearCarrierImsServiceOverride"); |
Brad Ebinger | 999d330 | 2020-11-25 14:31:39 -0800 | [diff] [blame] | 6075 | |
| 6076 | final long identity = Binder.clearCallingIdentity(); |
| 6077 | try { |
| 6078 | if (mImsResolver == null) { |
| 6079 | // may happen if the device does not support IMS. |
| 6080 | return false; |
| 6081 | } |
| 6082 | return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex); |
| 6083 | } finally { |
| 6084 | Binder.restoreCallingIdentity(identity); |
| 6085 | } |
| 6086 | } |
| 6087 | |
| 6088 | /** |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6089 | * Return the package name of the currently bound ImsService. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6090 | * |
| 6091 | * @param slotId The slot that the ImsService is associated with. |
| 6092 | * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is |
| 6093 | * the device default. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6094 | * @param featureType The feature associated with the queried configuration. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6095 | * @return the package name of the ImsService configuration. |
| 6096 | */ |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6097 | public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService, |
| 6098 | @ImsFeature.FeatureType int featureType) { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6099 | TelephonyPermissions |
Jack Yu | 00ece8c | 2022-11-19 22:29:12 -0800 | [diff] [blame] | 6100 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(mApp, |
| 6101 | SubscriptionManager.getSubscriptionId(slotId), "getBoundImsServicePackage"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 6102 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6103 | final long identity = Binder.clearCallingIdentity(); |
| 6104 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6105 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6106 | // may happen if the device does not support IMS. |
| 6107 | return ""; |
| 6108 | } |
Brad Ebinger | a80c331 | 2019-12-02 10:59:39 -0800 | [diff] [blame] | 6109 | // TODO: change API to query RCS separately. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6110 | return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService, |
| 6111 | featureType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6112 | } finally { |
| 6113 | Binder.restoreCallingIdentity(identity); |
| 6114 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6115 | } |
| 6116 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6117 | /** |
| 6118 | * Get the MmTelFeature state associated with the requested subscription id. |
| 6119 | * @param subId The subscription that the MmTelFeature is associated with. |
| 6120 | * @param callback A callback with an integer containing the |
| 6121 | * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature. |
| 6122 | */ |
| 6123 | @Override |
| 6124 | public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) { |
| 6125 | enforceReadPrivilegedPermission("getImsMmTelFeatureState"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 6126 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 6127 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 6128 | "IMS not available on device."); |
| 6129 | } |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6130 | final long token = Binder.clearCallingIdentity(); |
| 6131 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 6132 | int slotId = getSlotIndex(subId); |
| 6133 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 6134 | Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '" |
| 6135 | + subId + "'"); |
| 6136 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 6137 | } |
| 6138 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 6139 | ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> { |
| 6140 | try { |
| 6141 | callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger); |
| 6142 | } catch (RemoteException e) { |
| 6143 | Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. " |
| 6144 | + "Ignore"); |
| 6145 | } |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6146 | }); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 6147 | } catch (ImsException e) { |
| 6148 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6149 | } finally { |
| 6150 | Binder.restoreCallingIdentity(token); |
| 6151 | } |
| 6152 | } |
| 6153 | |
Daniel Bright | bb5840b | 2021-01-12 15:48:18 -0800 | [diff] [blame] | 6154 | /** |
| 6155 | * Sets the ims registration state on all valid {@link Phone}s. |
| 6156 | */ |
| 6157 | public void setImsRegistrationState(final boolean registered) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 6158 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6159 | |
| 6160 | final long identity = Binder.clearCallingIdentity(); |
| 6161 | try { |
Daniel Bright | bb5840b | 2021-01-12 15:48:18 -0800 | [diff] [blame] | 6162 | // NOTE: Before S, this method only set the default phone. |
| 6163 | for (final Phone phone : PhoneFactory.getPhones()) { |
| 6164 | if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) { |
| 6165 | phone.setImsRegistrationState(registered); |
| 6166 | } |
| 6167 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6168 | } finally { |
| 6169 | Binder.restoreCallingIdentity(identity); |
| 6170 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 6171 | } |
| 6172 | |
| 6173 | /** |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 6174 | * Set the network selection mode to automatic. |
| 6175 | * |
| 6176 | */ |
| 6177 | @Override |
| 6178 | public void setNetworkSelectionModeAutomatic(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6179 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6180 | mApp, subId, "setNetworkSelectionModeAutomatic"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6181 | |
| 6182 | final long identity = Binder.clearCallingIdentity(); |
| 6183 | try { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 6184 | if (!isActiveSubscription(subId)) { |
| 6185 | return; |
| 6186 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6187 | if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId); |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 6188 | sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId, |
| 6189 | SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6190 | } finally { |
| 6191 | Binder.restoreCallingIdentity(identity); |
| 6192 | } |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 6193 | } |
| 6194 | |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 6195 | /** |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6196 | * Ask the radio to connect to the input network and change selection mode to manual. |
| 6197 | * |
| 6198 | * @param subId the id of the subscription. |
| 6199 | * @param operatorInfo the operator information, included the PLMN, long name and short name of |
| 6200 | * the operator to attach to. |
| 6201 | * @param persistSelection whether the selection will persist until reboot. If true, only allows |
| 6202 | * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume |
| 6203 | * normal network selection next time. |
| 6204 | * @return {@code true} on success; {@code true} on any failure. |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6205 | */ |
| 6206 | @Override |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6207 | public boolean setNetworkSelectionModeManual( |
| 6208 | int subId, OperatorInfo operatorInfo, boolean persistSelection) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6209 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6210 | mApp, subId, "setNetworkSelectionModeManual"); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 6211 | |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 6212 | final long identity = Binder.clearCallingIdentity(); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 6213 | if (!isActiveSubscription(subId)) { |
| 6214 | return false; |
| 6215 | } |
| 6216 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6217 | try { |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6218 | ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6219 | persistSelection); |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6220 | if (DBG) { |
| 6221 | log("setNetworkSelectionModeManual: subId: " + subId |
| 6222 | + " operator: " + operatorInfo); |
| 6223 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6224 | return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId); |
| 6225 | } finally { |
| 6226 | Binder.restoreCallingIdentity(identity); |
| 6227 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6228 | } |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6229 | /** |
| 6230 | * Get the manual network selection |
| 6231 | * |
| 6232 | * @param subId the id of the subscription. |
| 6233 | * |
| 6234 | * @return the previously saved user selected PLMN |
| 6235 | */ |
| 6236 | @Override |
| 6237 | public String getManualNetworkSelectionPlmn(int subId) { |
| 6238 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 6239 | .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6240 | mApp, subId, "getManualNetworkSelectionPlmn"); |
| 6241 | |
| 6242 | final long identity = Binder.clearCallingIdentity(); |
| 6243 | try { |
| 6244 | if (!isActiveSubscription(subId)) { |
shilu | fa1c259 | 2020-03-10 10:59:43 -0700 | [diff] [blame] | 6245 | throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6246 | } |
| 6247 | |
| 6248 | final Phone phone = getPhone(subId); |
| 6249 | if (phone == null) { |
shilu | fa1c259 | 2020-03-10 10:59:43 -0700 | [diff] [blame] | 6250 | throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6251 | } |
| 6252 | OperatorInfo networkSelection = phone.getSavedNetworkSelection(); |
| 6253 | return TextUtils.isEmpty(networkSelection.getOperatorNumeric()) |
| 6254 | ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric(); |
| 6255 | } finally { |
| 6256 | Binder.restoreCallingIdentity(identity); |
| 6257 | } |
| 6258 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6259 | |
| 6260 | /** |
| 6261 | * Scans for available networks. |
| 6262 | */ |
| 6263 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6264 | public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage, |
| 6265 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6266 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6267 | mApp, subId, "getCellNetworkScanResults"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6268 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 6269 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 6270 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 6271 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6272 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6273 | .setCallingPid(Binder.getCallingPid()) |
| 6274 | .setCallingUid(Binder.getCallingUid()) |
| 6275 | .setMethod("getCellNetworkScanResults") |
| 6276 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
Hall Liu | c4a3e42 | 2020-05-26 17:18:03 -0700 | [diff] [blame] | 6277 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 6278 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6279 | .build()); |
| 6280 | switch (locationResult) { |
| 6281 | case DENIED_HARD: |
| 6282 | throw new SecurityException("Not allowed to access scan results -- location"); |
| 6283 | case DENIED_SOFT: |
| 6284 | return null; |
| 6285 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6286 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6287 | long identity = Binder.clearCallingIdentity(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6288 | try { |
| 6289 | if (DBG) log("getCellNetworkScanResults: subId " + subId); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6290 | return (CellNetworkScanResult) sendRequest( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6291 | CMD_PERFORM_NETWORK_SCAN, null, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6292 | } finally { |
| 6293 | Binder.restoreCallingIdentity(identity); |
| 6294 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6295 | } |
| 6296 | |
| 6297 | /** |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6298 | * Get the call forwarding info, given the call forwarding reason. |
| 6299 | */ |
| 6300 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6301 | public void getCallForwarding(int subId, int callForwardingReason, |
| 6302 | ICallForwardingInfoCallback callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6303 | enforceReadPrivilegedPermission("getCallForwarding"); |
| 6304 | long identity = Binder.clearCallingIdentity(); |
| 6305 | try { |
| 6306 | if (DBG) { |
| 6307 | log("getCallForwarding: subId " + subId |
| 6308 | + " callForwardingReason" + callForwardingReason); |
| 6309 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6310 | |
| 6311 | Phone phone = getPhone(subId); |
| 6312 | if (phone == null) { |
| 6313 | try { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 6314 | callback.onError( |
| 6315 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6316 | } catch (RemoteException e) { |
| 6317 | // ignore |
| 6318 | } |
| 6319 | return; |
| 6320 | } |
| 6321 | |
| 6322 | Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create( |
| 6323 | callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() { |
| 6324 | @Override |
| 6325 | public void onCallForwardingInfoAvailable(CallForwardingInfo info) { |
| 6326 | try { |
| 6327 | callback.onCallForwardingInfoAvailable(info); |
| 6328 | } catch (RemoteException e) { |
| 6329 | // ignore |
| 6330 | } |
| 6331 | } |
| 6332 | |
| 6333 | @Override |
| 6334 | public void onError(int error) { |
| 6335 | try { |
| 6336 | callback.onError(error); |
| 6337 | } catch (RemoteException e) { |
| 6338 | // ignore |
| 6339 | } |
| 6340 | } |
| 6341 | }); |
| 6342 | sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6343 | } finally { |
| 6344 | Binder.restoreCallingIdentity(identity); |
| 6345 | } |
| 6346 | } |
| 6347 | |
| 6348 | /** |
| 6349 | * Sets the voice call forwarding info including status (enable/disable), call forwarding |
| 6350 | * reason, the number to forward, and the timeout before the forwarding is attempted. |
| 6351 | */ |
| 6352 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6353 | public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo, |
| 6354 | IIntegerConsumer callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6355 | enforceModifyPermission(); |
| 6356 | long identity = Binder.clearCallingIdentity(); |
| 6357 | try { |
| 6358 | if (DBG) { |
| 6359 | log("setCallForwarding: subId " + subId |
| 6360 | + " callForwardingInfo" + callForwardingInfo); |
| 6361 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6362 | |
| 6363 | Phone phone = getPhone(subId); |
| 6364 | if (phone == null) { |
| 6365 | try { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 6366 | callback.accept( |
| 6367 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6368 | } catch (RemoteException e) { |
| 6369 | // ignore |
| 6370 | } |
| 6371 | return; |
| 6372 | } |
| 6373 | |
| 6374 | Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo, |
| 6375 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 6376 | |
| 6377 | sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6378 | } finally { |
| 6379 | Binder.restoreCallingIdentity(identity); |
| 6380 | } |
| 6381 | } |
| 6382 | |
| 6383 | /** |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6384 | * Get the call waiting status for a subId. |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6385 | */ |
| 6386 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6387 | public void getCallWaitingStatus(int subId, IIntegerConsumer callback) { |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6388 | enforceReadPrivilegedPermission("getCallWaitingStatus"); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6389 | long identity = Binder.clearCallingIdentity(); |
| 6390 | try { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6391 | Phone phone = getPhone(subId); |
| 6392 | if (phone == null) { |
| 6393 | try { |
| 6394 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 6395 | } catch (RemoteException e) { |
| 6396 | // ignore |
| 6397 | } |
| 6398 | return; |
| 6399 | } |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6400 | CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext()); |
| 6401 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 6402 | boolean requireUssd = c.getBoolean( |
| 6403 | CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6404 | |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6405 | if (DBG) log("getCallWaitingStatus: subId " + subId); |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6406 | if (requireUssd) { |
| 6407 | CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(), |
| 6408 | getSubscriptionCarrierId(subId)); |
| 6409 | String newUssdCommand = ""; |
| 6410 | try { |
| 6411 | newUssdCommand = carrierXmlParser.getFeature( |
| 6412 | CarrierXmlParser.FEATURE_CALL_WAITING) |
| 6413 | .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null); |
| 6414 | } catch (NullPointerException e) { |
| 6415 | loge("Failed to generate USSD number" + e); |
| 6416 | } |
| 6417 | ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver( |
| 6418 | mMainThreadHandler, callback, carrierXmlParser, |
| 6419 | CarrierXmlParser.SsEntry.SSAction.QUERY); |
| 6420 | final String ussdCommand = newUssdCommand; |
| 6421 | Executors.newSingleThreadExecutor().execute(() -> { |
| 6422 | handleUssdRequest(subId, ussdCommand, wrappedCallback); |
| 6423 | }); |
| 6424 | } else { |
| 6425 | Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException( |
| 6426 | callback::accept); |
| 6427 | sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null); |
| 6428 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6429 | } finally { |
| 6430 | Binder.restoreCallingIdentity(identity); |
| 6431 | } |
| 6432 | } |
| 6433 | |
| 6434 | /** |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6435 | * Sets whether call waiting is enabled for a given subId. |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6436 | */ |
| 6437 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6438 | public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6439 | enforceModifyPermission(); |
| 6440 | long identity = Binder.clearCallingIdentity(); |
| 6441 | try { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6442 | if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable); |
| 6443 | |
| 6444 | Phone phone = getPhone(subId); |
| 6445 | if (phone == null) { |
| 6446 | try { |
| 6447 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 6448 | } catch (RemoteException e) { |
| 6449 | // ignore |
| 6450 | } |
| 6451 | return; |
| 6452 | } |
| 6453 | |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6454 | CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext()); |
| 6455 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 6456 | boolean requireUssd = c.getBoolean( |
| 6457 | CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6458 | |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6459 | if (DBG) log("getCallWaitingStatus: subId " + subId); |
| 6460 | if (requireUssd) { |
| 6461 | CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(), |
| 6462 | getSubscriptionCarrierId(subId)); |
| 6463 | CarrierXmlParser.SsEntry.SSAction ssAction = |
| 6464 | enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE |
| 6465 | : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE; |
| 6466 | String newUssdCommand = ""; |
| 6467 | try { |
| 6468 | newUssdCommand = carrierXmlParser.getFeature( |
| 6469 | CarrierXmlParser.FEATURE_CALL_WAITING) |
| 6470 | .makeCommand(ssAction, null); |
| 6471 | } catch (NullPointerException e) { |
| 6472 | loge("Failed to generate USSD number" + e); |
| 6473 | } |
| 6474 | ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver( |
| 6475 | mMainThreadHandler, callback, carrierXmlParser, ssAction); |
| 6476 | final String ussdCommand = newUssdCommand; |
| 6477 | Executors.newSingleThreadExecutor().execute(() -> { |
| 6478 | handleUssdRequest(subId, ussdCommand, wrappedCallback); |
| 6479 | }); |
| 6480 | } else { |
| 6481 | Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable, |
| 6482 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 6483 | |
| 6484 | sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null); |
| 6485 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6486 | } finally { |
| 6487 | Binder.restoreCallingIdentity(identity); |
| 6488 | } |
| 6489 | } |
| 6490 | |
| 6491 | /** |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 6492 | * Starts a new network scan and returns the id of this scan. |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6493 | * |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 6494 | * @param subId id of the subscription |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 6495 | * @param renounceFineLocationAccess Set this to true if the caller would not like to receive |
| 6496 | * location related information which will be sent if the caller already possess |
| 6497 | * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 6498 | * @param request contains the radio access networks with bands/channels to scan |
| 6499 | * @param messenger callback messenger for scan results or errors |
| 6500 | * @param binder for the purpose of auto clean when the user thread crashes |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6501 | * @return the id of the requested scan which can be used to stop the scan. |
| 6502 | */ |
| 6503 | @Override |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 6504 | public int requestNetworkScan(int subId, boolean renounceFineLocationAccess, |
| 6505 | NetworkScanRequest request, Messenger messenger, |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6506 | IBinder binder, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6507 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6508 | mApp, subId, "requestNetworkScan"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6509 | LocationAccessPolicy.LocationPermissionResult locationResult = |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 6510 | LocationAccessPolicy.LocationPermissionResult.DENIED_HARD; |
| 6511 | if (!renounceFineLocationAccess) { |
| 6512 | locationResult = LocationAccessPolicy.checkLocationPermission(mApp, |
| 6513 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 6514 | .setCallingPackage(callingPackage) |
| 6515 | .setCallingFeatureId(callingFeatureId) |
| 6516 | .setCallingPid(Binder.getCallingPid()) |
| 6517 | .setCallingUid(Binder.getCallingUid()) |
| 6518 | .setMethod("requestNetworkScan") |
| 6519 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 6520 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 6521 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 6522 | .build()); |
| 6523 | } |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6524 | if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) { |
Nathan Harold | 1c11dba | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 6525 | SecurityException e = checkNetworkRequestForSanitizedLocationAccess( |
| 6526 | request, subId, callingPackage); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6527 | if (e != null) { |
| 6528 | if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) { |
| 6529 | throw e; |
| 6530 | } else { |
Hall Liu | 0e5abaf | 2019-04-04 01:25:30 -0700 | [diff] [blame] | 6531 | loge(e.getMessage()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6532 | return TelephonyScanManager.INVALID_SCAN_ID; |
| 6533 | } |
| 6534 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6535 | } |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6536 | int callingUid = Binder.getCallingUid(); |
| 6537 | int callingPid = Binder.getCallingPid(); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 6538 | final long identity = Binder.clearCallingIdentity(); |
| 6539 | try { |
| 6540 | return mNetworkScanRequestTracker.startNetworkScan( |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 6541 | renounceFineLocationAccess, request, messenger, binder, getPhone(subId), |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6542 | callingUid, callingPid, callingPackage); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 6543 | } finally { |
| 6544 | Binder.restoreCallingIdentity(identity); |
| 6545 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6546 | } |
| 6547 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6548 | private SecurityException checkNetworkRequestForSanitizedLocationAccess( |
Nathan Harold | 1c11dba | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 6549 | NetworkScanRequest request, int subId, String callingPackage) { |
Rambo Wang | 3dee30a | 2022-10-20 16:52:29 +0000 | [diff] [blame] | 6550 | boolean hasCarrierPriv; |
| 6551 | final long identity = Binder.clearCallingIdentity(); |
| 6552 | try { |
| 6553 | hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage) |
| 6554 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 6555 | } finally { |
| 6556 | Binder.restoreCallingIdentity(identity); |
| 6557 | } |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 6558 | boolean hasNetworkScanPermission = |
| 6559 | mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN) |
| 6560 | == PERMISSION_GRANTED; |
| 6561 | |
| 6562 | if (!hasCarrierPriv && !hasNetworkScanPermission) { |
| 6563 | return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed" |
| 6564 | + " for network scans without location access."); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6565 | } |
| 6566 | |
| 6567 | if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) { |
| 6568 | for (RadioAccessSpecifier ras : request.getSpecifiers()) { |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6569 | if (ras.getChannels() != null && ras.getChannels().length > 0) { |
| 6570 | return new SecurityException("Specific channels must not be" |
| 6571 | + " scanned without location access."); |
| 6572 | } |
| 6573 | } |
| 6574 | } |
| 6575 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6576 | return null; |
| 6577 | } |
| 6578 | |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6579 | /** |
| 6580 | * Stops an existing network scan with the given scanId. |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 6581 | * |
| 6582 | * @param subId id of the subscription |
| 6583 | * @param scanId id of the scan that needs to be stopped |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6584 | */ |
| 6585 | @Override |
| 6586 | public void stopNetworkScan(int subId, int scanId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6587 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6588 | mApp, subId, "stopNetworkScan"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6589 | |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6590 | int callingUid = Binder.getCallingUid(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6591 | final long identity = Binder.clearCallingIdentity(); |
| 6592 | try { |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6593 | mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6594 | } finally { |
| 6595 | Binder.restoreCallingIdentity(identity); |
| 6596 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6597 | } |
| 6598 | |
| 6599 | /** |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6600 | * Get the allowed network types bitmask. |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 6601 | * |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6602 | * @return the allowed network types bitmask, defined in RILConstants.java. |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 6603 | */ |
| 6604 | @Override |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6605 | public int getAllowedNetworkTypesBitmask(int subId) { |
Pengquan Meng | a4009cb | 2018-12-20 11:00:24 -0800 | [diff] [blame] | 6606 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 6607 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6608 | mApp, subId, "getAllowedNetworkTypesBitmask"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6609 | |
| 6610 | final long identity = Binder.clearCallingIdentity(); |
| 6611 | try { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6612 | if (DBG) log("getAllowedNetworkTypesBitmask"); |
| 6613 | int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId); |
| 6614 | int networkTypesBitmask = (result != null ? result[0] : -1); |
| 6615 | if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask); |
| 6616 | return networkTypesBitmask; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6617 | } finally { |
| 6618 | Binder.restoreCallingIdentity(identity); |
| 6619 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 6620 | } |
| 6621 | |
| 6622 | /** |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6623 | * Get the allowed network types for certain reason. |
| 6624 | * |
| 6625 | * @param subId the id of the subscription. |
| 6626 | * @param reason the reason the allowed network type change is taking place |
| 6627 | * @return the allowed network types. |
| 6628 | */ |
| 6629 | @Override |
| 6630 | public long getAllowedNetworkTypesForReason(int subId, |
| 6631 | @TelephonyManager.AllowedNetworkTypesReason int reason) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 6632 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 6633 | mApp, subId, "getAllowedNetworkTypesForReason"); |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6634 | final long identity = Binder.clearCallingIdentity(); |
| 6635 | try { |
| 6636 | return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason); |
| 6637 | } finally { |
| 6638 | Binder.restoreCallingIdentity(identity); |
| 6639 | } |
| 6640 | } |
| 6641 | |
| 6642 | /** |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6643 | * Enable/Disable E-UTRA-NR Dual Connectivity |
| 6644 | * @param subId subscription id of the sim card |
| 6645 | * @param nrDualConnectivityState expected NR dual connectivity state |
| 6646 | * This can be passed following states |
| 6647 | * <ol> |
| 6648 | * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE} |
| 6649 | * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE} |
| 6650 | * <li>Disable NR dual connectivity and force secondary cell to be released |
| 6651 | * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE} |
| 6652 | * </ol> |
| 6653 | * @return operation result. |
| 6654 | */ |
| 6655 | @Override |
| 6656 | public int setNrDualConnectivityState(int subId, |
| 6657 | @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) { |
| 6658 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6659 | mApp, subId, "enableNRDualConnectivity"); |
Sooraj Sasindran | 0e4e00a | 2021-03-16 18:02:32 -0700 | [diff] [blame] | 6660 | if (!isRadioInterfaceCapabilitySupported( |
Sooraj Sasindran | dfd595b | 2021-03-11 17:38:13 -0800 | [diff] [blame] | 6661 | TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) { |
| 6662 | return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED; |
| 6663 | } |
| 6664 | |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6665 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 6666 | final long identity = Binder.clearCallingIdentity(); |
| 6667 | try { |
| 6668 | int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY, |
| 6669 | nrDualConnectivityState, subId, |
| 6670 | workSource); |
| 6671 | if (DBG) log("enableNRDualConnectivity result: " + result); |
| 6672 | return result; |
| 6673 | } finally { |
| 6674 | Binder.restoreCallingIdentity(identity); |
| 6675 | } |
| 6676 | } |
| 6677 | |
| 6678 | /** |
| 6679 | * Is E-UTRA-NR Dual Connectivity enabled |
| 6680 | * @return true if dual connectivity is enabled else false |
| 6681 | */ |
| 6682 | @Override |
| 6683 | public boolean isNrDualConnectivityEnabled(int subId) { |
| 6684 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 6685 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6686 | mApp, subId, "isNRDualConnectivityEnabled"); |
Sooraj Sasindran | 0e4e00a | 2021-03-16 18:02:32 -0700 | [diff] [blame] | 6687 | if (!isRadioInterfaceCapabilitySupported( |
Sooraj Sasindran | dfd595b | 2021-03-11 17:38:13 -0800 | [diff] [blame] | 6688 | TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) { |
| 6689 | return false; |
| 6690 | } |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6691 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 6692 | final long identity = Binder.clearCallingIdentity(); |
| 6693 | try { |
| 6694 | boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED, |
| 6695 | null, subId, workSource); |
| 6696 | if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled); |
| 6697 | return isEnabled; |
| 6698 | } finally { |
| 6699 | Binder.restoreCallingIdentity(identity); |
| 6700 | } |
| 6701 | } |
| 6702 | |
| 6703 | /** |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6704 | * Set the allowed network types of the device and |
| 6705 | * provide the reason triggering the allowed network change. |
| 6706 | * |
| 6707 | * @param subId the id of the subscription. |
| 6708 | * @param reason the reason the allowed network type change is taking place |
| 6709 | * @param allowedNetworkTypes the allowed network types. |
| 6710 | * @return true on success; false on any failure. |
| 6711 | */ |
| 6712 | @Override |
| 6713 | public boolean setAllowedNetworkTypesForReason(int subId, |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6714 | @TelephonyManager.AllowedNetworkTypesReason int reason, |
| 6715 | @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) { |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6716 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6717 | mApp, subId, "setAllowedNetworkTypesForReason"); |
Gil Cukierman | 1d3d375 | 2022-10-03 21:31:33 +0000 | [diff] [blame] | 6718 | // If the caller only has carrier privileges, then they should not be able to override |
| 6719 | // any network types which were set for security reasons. |
| 6720 | if (mApp.checkCallingOrSelfPermission(Manifest.permission.MODIFY_PHONE_STATE) |
| 6721 | != PERMISSION_GRANTED |
| 6722 | && (reason == TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_ENABLE_2G |
| 6723 | || reason == TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER_RESTRICTIONS)) { |
| 6724 | throw new SecurityException( |
| 6725 | "setAllowedNetworkTypesForReason cannot be called with carrier privileges for" |
| 6726 | + " reason " |
| 6727 | + reason); |
| 6728 | } |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6729 | if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) { |
SongFerngWang | 7ffc273 | 2021-04-15 19:46:33 +0800 | [diff] [blame] | 6730 | loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason); |
| 6731 | return false; |
| 6732 | } |
| 6733 | if (!SubscriptionManager.isUsableSubscriptionId(subId)) { |
| 6734 | loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId); |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6735 | return false; |
| 6736 | } |
| 6737 | |
Aishwarya Mallampati | 32336e8 | 2023-01-04 23:02:56 +0000 | [diff] [blame] | 6738 | log("setAllowedNetworkTypesForReason: " + reason + " value: " |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 6739 | + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes)); |
| 6740 | |
| 6741 | |
Aishwarya Mallampati | 32336e8 | 2023-01-04 23:02:56 +0000 | [diff] [blame] | 6742 | if (allowedNetworkTypes == getPhoneFromSubId(subId).getAllowedNetworkTypes(reason)) { |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 6743 | log("setAllowedNetworkTypesForReason: " + reason + "does not change value"); |
| 6744 | return true; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6745 | } |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 6746 | |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6747 | final long identity = Binder.clearCallingIdentity(); |
| 6748 | try { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6749 | Boolean success = (Boolean) sendRequest( |
| 6750 | CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON, |
| 6751 | new Pair<Integer, Long>(reason, allowedNetworkTypes), subId); |
| 6752 | |
| 6753 | if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail")); |
| 6754 | return success; |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6755 | } finally { |
| 6756 | Binder.restoreCallingIdentity(identity); |
| 6757 | } |
| 6758 | } |
| 6759 | |
| 6760 | /** |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6761 | * Check whether DUN APN is required for tethering with subId. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6762 | * |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6763 | * @param subId the id of the subscription to require tethering. |
Amit Mahajan | fe58cdf | 2017-07-11 12:01:53 -0700 | [diff] [blame] | 6764 | * @return {@code true} if DUN APN is required for tethering. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6765 | * @hide |
| 6766 | */ |
| 6767 | @Override |
SongFerngWang | f08d812 | 2019-11-15 14:58:44 +0800 | [diff] [blame] | 6768 | public boolean isTetheringApnRequiredForSubscriber(int subId) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6769 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6770 | final long identity = Binder.clearCallingIdentity(); |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6771 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6772 | try { |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6773 | if (phone != null) { |
| 6774 | return phone.hasMatchedTetherApnSetting(); |
| 6775 | } else { |
| 6776 | return false; |
| 6777 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6778 | } finally { |
| 6779 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6780 | } |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6781 | } |
| 6782 | |
| 6783 | /** |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6784 | * Get the user enabled state of Mobile Data. |
| 6785 | * |
| 6786 | * TODO: remove and use isUserDataEnabled. |
| 6787 | * This can't be removed now because some vendor codes |
| 6788 | * calls through ITelephony directly while they should |
| 6789 | * use TelephonyManager. |
| 6790 | * |
| 6791 | * @return true on enabled |
| 6792 | */ |
| 6793 | @Override |
| 6794 | public boolean getDataEnabled(int subId) { |
| 6795 | return isUserDataEnabled(subId); |
| 6796 | } |
| 6797 | |
| 6798 | /** |
| 6799 | * Get whether mobile data is enabled per user setting. |
| 6800 | * |
| 6801 | * There are other factors deciding whether mobile data is actually enabled, but they are |
| 6802 | * not considered here. See {@link #isDataEnabled(int)} for more details. |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6803 | * |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6804 | * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE |
| 6805 | * or carrier privileges. |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 6806 | * |
| 6807 | * @return {@code true} if data is enabled else {@code false} |
| 6808 | */ |
| 6809 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6810 | public boolean isUserDataEnabled(int subId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6811 | String functionName = "isUserDataEnabled"; |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6812 | try { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6813 | try { |
| 6814 | mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE, |
| 6815 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 6816 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6817 | mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName); |
| 6818 | } |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 6819 | } catch (SecurityException e) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6820 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6821 | mApp, subId, functionName); |
| 6822 | |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6823 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6824 | |
| 6825 | final long identity = Binder.clearCallingIdentity(); |
| 6826 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 6827 | int phoneId = SubscriptionManager.getPhoneId(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6828 | if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 6829 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6830 | if (phone != null) { |
| 6831 | boolean retVal = phone.isUserDataEnabled(); |
| 6832 | if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 6833 | return retVal; |
| 6834 | } else { |
| 6835 | if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 6836 | return false; |
| 6837 | } |
| 6838 | } finally { |
| 6839 | Binder.restoreCallingIdentity(identity); |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6840 | } |
| 6841 | } |
| 6842 | |
| 6843 | /** |
Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 6844 | * Checks if the device is capable of mobile data by considering whether whether the |
| 6845 | * user has enabled mobile data, whether the carrier has enabled mobile data, and |
| 6846 | * whether the network policy allows data connections. |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6847 | * |
Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 6848 | * @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] | 6849 | */ |
| 6850 | @Override |
| 6851 | public boolean isDataEnabled(int subId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6852 | String functionName = "isDataEnabled"; |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6853 | try { |
| 6854 | try { |
| 6855 | mApp.enforceCallingOrSelfPermission( |
| 6856 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6857 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 6858 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6859 | try { |
| 6860 | mApp.enforceCallingOrSelfPermission( |
| 6861 | android.Manifest.permission.READ_PHONE_STATE, |
| 6862 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 6863 | } catch (SecurityException e2) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6864 | mApp.enforceCallingOrSelfPermission( |
| 6865 | permission.READ_BASIC_PHONE_STATE, functionName); |
| 6866 | } |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6867 | } |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 6868 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6869 | enforceReadPrivilegedPermission(functionName); |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6870 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6871 | |
| 6872 | final long identity = Binder.clearCallingIdentity(); |
| 6873 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 6874 | int phoneId = SubscriptionManager.getPhoneId(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6875 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6876 | if (phone != null) { |
Sarah Chin | e04784a | 2022-10-31 20:32:34 -0700 | [diff] [blame] | 6877 | boolean retVal = phone.getDataSettingsManager().isDataEnabled(); |
Jack Yu | 4ad64e5 | 2021-12-03 14:23:53 -0800 | [diff] [blame] | 6878 | if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6879 | return retVal; |
| 6880 | } else { |
| 6881 | if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 6882 | return false; |
| 6883 | } |
| 6884 | } finally { |
| 6885 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 6886 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 6887 | } |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6888 | |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6889 | /** |
| 6890 | * Check if data is enabled for a specific reason |
| 6891 | * @param subId Subscription index |
| 6892 | * @param reason the reason the data enable change is taking place |
| 6893 | * @return {@code true} if the overall data is enabled; {@code false} if not. |
| 6894 | */ |
| 6895 | @Override |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6896 | public boolean isDataEnabledForReason(int subId, |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6897 | @TelephonyManager.DataEnabledReason int reason) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6898 | String functionName = "isDataEnabledForReason"; |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6899 | try { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6900 | try { |
| 6901 | mApp.enforceCallingOrSelfPermission( |
| 6902 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 6903 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 6904 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6905 | mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE, |
| 6906 | functionName); |
| 6907 | } |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 6908 | } catch (SecurityException e) { |
Sooraj Sasindran | 0d909a0 | 2021-11-08 12:01:16 -0800 | [diff] [blame] | 6909 | try { |
| 6910 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6911 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 6912 | } catch (SecurityException e2) { |
Sooraj Sasindran | 0d909a0 | 2021-11-08 12:01:16 -0800 | [diff] [blame] | 6913 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6914 | mApp, subId, functionName); |
Sooraj Sasindran | 0d909a0 | 2021-11-08 12:01:16 -0800 | [diff] [blame] | 6915 | } |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6916 | } |
| 6917 | |
| 6918 | |
| 6919 | final long identity = Binder.clearCallingIdentity(); |
| 6920 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 6921 | int phoneId = SubscriptionManager.getPhoneId(subId); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6922 | if (DBG) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6923 | log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6924 | + " reason=" + reason); |
| 6925 | } |
| 6926 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6927 | if (phone != null) { |
| 6928 | boolean retVal; |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 6929 | retVal = phone.getDataSettingsManager().isDataEnabledForReason(reason); |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6930 | if (DBG) log("isDataEnabledForReason: retVal=" + retVal); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6931 | return retVal; |
| 6932 | } else { |
| 6933 | if (DBG) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6934 | loge("isDataEnabledForReason: no phone subId=" |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6935 | + subId + " retVal=false"); |
| 6936 | } |
| 6937 | return false; |
| 6938 | } |
| 6939 | } finally { |
| 6940 | Binder.restoreCallingIdentity(identity); |
| 6941 | } |
| 6942 | } |
| 6943 | |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6944 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6945 | public int getCarrierPrivilegeStatus(int subId) { |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6946 | // No permission needed; this only lets the caller inspect their own status. |
| 6947 | return getCarrierPrivilegeStatusForUidWithPermission(subId, Binder.getCallingUid()); |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6948 | } |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 6949 | |
| 6950 | @Override |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6951 | public int getCarrierPrivilegeStatusForUid(int subId, int uid) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6952 | enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid"); |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6953 | return getCarrierPrivilegeStatusForUidWithPermission(subId, uid); |
| 6954 | } |
| 6955 | |
| 6956 | private int getCarrierPrivilegeStatusForUidWithPermission(int subId, int uid) { |
| 6957 | Phone phone = getPhone(subId); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6958 | if (phone == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 6959 | loge("getCarrierPrivilegeStatusForUid: Invalid subId"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6960 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 6961 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6962 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 6963 | if (cpt == null) { |
| 6964 | loge("getCarrierPrivilegeStatusForUid: No CarrierPrivilegesTracker"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6965 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6966 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6967 | return cpt.getCarrierPrivilegeStatusForUid(uid); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6968 | } |
| 6969 | |
| 6970 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6971 | public int checkCarrierPrivilegesForPackage(int subId, String pkgName) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 6972 | enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage"); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6973 | if (TextUtils.isEmpty(pkgName)) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 6974 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6975 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6976 | Phone phone = getPhone(subId); |
| 6977 | if (phone == null) { |
| 6978 | loge("checkCarrierPrivilegesForPackage: Invalid subId"); |
| 6979 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 6980 | } |
| 6981 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 6982 | if (cpt == null) { |
| 6983 | loge("checkCarrierPrivilegesForPackage: No CarrierPrivilegesTracker"); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 6984 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6985 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6986 | return cpt.getCarrierPrivilegeStatusForPackage(pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6987 | } |
| 6988 | |
| 6989 | @Override |
| 6990 | public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) { |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6991 | enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackageAnyPhone"); |
Rambo Wang | e7209ce | 2022-02-23 13:41:02 -0800 | [diff] [blame] | 6992 | return checkCarrierPrivilegesForPackageAnyPhoneWithPermission(pkgName); |
| 6993 | } |
| 6994 | |
| 6995 | private int checkCarrierPrivilegesForPackageAnyPhoneWithPermission(String pkgName) { |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6996 | if (TextUtils.isEmpty(pkgName)) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 6997 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6998 | } |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6999 | int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7000 | for (int phoneId = 0; phoneId < TelephonyManager.getDefault().getPhoneCount(); phoneId++) { |
| 7001 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 7002 | if (phone == null) { |
| 7003 | continue; |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 7004 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7005 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7006 | if (cpt == null) { |
| 7007 | continue; |
| 7008 | } |
| 7009 | result = cpt.getCarrierPrivilegeStatusForPackage(pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 7010 | if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 7011 | break; |
| 7012 | } |
| 7013 | } |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 7014 | return result; |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 7015 | } |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 7016 | |
| 7017 | @Override |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 7018 | public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 7019 | enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone"); |
Rambo Wang | 8a247eb | 2022-02-08 21:11:18 +0000 | [diff] [blame] | 7020 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 7021 | if (phone == null) { |
| 7022 | return Collections.emptyList(); |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 7023 | } |
Rambo Wang | 8a247eb | 2022-02-08 21:11:18 +0000 | [diff] [blame] | 7024 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7025 | if (cpt == null) { |
| 7026 | return Collections.emptyList(); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 7027 | } |
Rambo Wang | 8a247eb | 2022-02-08 21:11:18 +0000 | [diff] [blame] | 7028 | return cpt.getCarrierPackageNamesForIntent(intent); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 7029 | } |
| 7030 | |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 7031 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7032 | public List<String> getPackagesWithCarrierPrivileges(int phoneId) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 7033 | enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges"); |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7034 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 7035 | if (phone == null) { |
| 7036 | return Collections.emptyList(); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 7037 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7038 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7039 | if (cpt == null) { |
| 7040 | return Collections.emptyList(); |
| 7041 | } |
| 7042 | return new ArrayList<>(cpt.getPackagesWithCarrierPrivileges()); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 7043 | } |
| 7044 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7045 | @Override |
| 7046 | public List<String> getPackagesWithCarrierPrivilegesForAllPhones() { |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 7047 | enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones"); |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7048 | Set<String> privilegedPackages = new ArraySet<>(); |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 7049 | final long identity = Binder.clearCallingIdentity(); |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 7050 | try { |
| 7051 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 7052 | privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i)); |
| 7053 | } |
| 7054 | } finally { |
| 7055 | Binder.restoreCallingIdentity(identity); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7056 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7057 | return new ArrayList<>(privilegedPackages); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7058 | } |
| 7059 | |
Rambo Wang | 6812ffb | 2022-03-15 16:54:17 -0700 | [diff] [blame] | 7060 | @Override |
| 7061 | public @Nullable String getCarrierServicePackageNameForLogicalSlot(int logicalSlotIndex) { |
| 7062 | enforceReadPrivilegedPermission("getCarrierServicePackageNameForLogicalSlot"); |
| 7063 | |
| 7064 | final Phone phone = PhoneFactory.getPhone(logicalSlotIndex); |
| 7065 | if (phone == null) { |
| 7066 | return null; |
| 7067 | } |
| 7068 | final CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7069 | if (cpt == null) { |
| 7070 | return null; |
| 7071 | } |
| 7072 | return cpt.getCarrierServicePackageName(); |
| 7073 | } |
| 7074 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 7075 | private String getIccId(int subId) { |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 7076 | final Phone phone = getPhone(subId); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 7077 | UiccPort port = phone == null ? null : phone.getUiccPort(); |
| 7078 | if (port == null) { |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7079 | return null; |
| 7080 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 7081 | String iccId = port.getIccId(); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7082 | if (TextUtils.isEmpty(iccId)) { |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7083 | return null; |
| 7084 | } |
| 7085 | return iccId; |
| 7086 | } |
| 7087 | |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 7088 | @Override |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 7089 | public void setCallComposerStatus(int subId, int status) { |
| 7090 | enforceModifyPermission(); |
| 7091 | |
| 7092 | final long identity = Binder.clearCallingIdentity(); |
| 7093 | try { |
| 7094 | Phone phone = getPhone(subId); |
| 7095 | if (phone != null) { |
| 7096 | Phone defaultPhone = phone.getImsPhone(); |
| 7097 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 7098 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 7099 | imsPhone.setCallComposerStatus(status); |
Shuo Qian | 284ae75 | 2020-12-22 19:10:14 -0800 | [diff] [blame] | 7100 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| 7101 | .updateImsServiceConfig(); |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 7102 | } |
| 7103 | } |
Shuo Qian | 284ae75 | 2020-12-22 19:10:14 -0800 | [diff] [blame] | 7104 | } catch (ImsException e) { |
| 7105 | throw new ServiceSpecificException(e.getCode()); |
| 7106 | } finally { |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 7107 | Binder.restoreCallingIdentity(identity); |
| 7108 | } |
| 7109 | } |
| 7110 | |
| 7111 | @Override |
| 7112 | public int getCallComposerStatus(int subId) { |
| 7113 | enforceReadPrivilegedPermission("getCallComposerStatus"); |
| 7114 | |
| 7115 | final long identity = Binder.clearCallingIdentity(); |
| 7116 | try { |
| 7117 | Phone phone = getPhone(subId); |
| 7118 | if (phone != null) { |
| 7119 | Phone defaultPhone = phone.getImsPhone(); |
| 7120 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 7121 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 7122 | return imsPhone.getCallComposerStatus(); |
| 7123 | } |
| 7124 | } |
| 7125 | } finally { |
| 7126 | Binder.restoreCallingIdentity(identity); |
| 7127 | } |
| 7128 | return TelephonyManager.CALL_COMPOSER_STATUS_OFF; |
| 7129 | } |
| 7130 | |
| 7131 | @Override |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7132 | public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag, |
| 7133 | String number) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 7134 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7135 | subId, "setLine1NumberForDisplayForSubscriber"); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7136 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7137 | final long identity = Binder.clearCallingIdentity(); |
| 7138 | try { |
| 7139 | final String iccId = getIccId(subId); |
| 7140 | final Phone phone = getPhone(subId); |
| 7141 | if (phone == null) { |
| 7142 | return false; |
| 7143 | } |
| 7144 | final String subscriberId = phone.getSubscriberId(); |
| 7145 | |
| 7146 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 7147 | Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId=" |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7148 | + subscriberId + " to " + number); |
| 7149 | } |
| 7150 | |
| 7151 | if (TextUtils.isEmpty(iccId)) { |
| 7152 | return false; |
| 7153 | } |
| 7154 | |
| 7155 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 7156 | |
| 7157 | final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 7158 | if (alphaTag == null) { |
| 7159 | editor.remove(alphaTagPrefKey); |
| 7160 | } else { |
| 7161 | editor.putString(alphaTagPrefKey, alphaTag); |
| 7162 | } |
| 7163 | |
| 7164 | // Record both the line number and IMSI for this ICCID, since we need to |
| 7165 | // track all merged IMSIs based on line number |
| 7166 | final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 7167 | final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 7168 | if (number == null) { |
| 7169 | editor.remove(numberPrefKey); |
| 7170 | editor.remove(subscriberPrefKey); |
| 7171 | } else { |
| 7172 | editor.putString(numberPrefKey, number); |
| 7173 | editor.putString(subscriberPrefKey, subscriberId); |
| 7174 | } |
| 7175 | |
| 7176 | editor.commit(); |
| 7177 | return true; |
| 7178 | } finally { |
| 7179 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 7180 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7181 | } |
| 7182 | |
| 7183 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7184 | public String getLine1NumberForDisplay(int subId, String callingPackage, |
| 7185 | String callingFeatureId) { |
Makoto Onuki | fee6934 | 2015-06-29 14:44:50 -0700 | [diff] [blame] | 7186 | // This is open to apps with WRITE_SMS. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7187 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7188 | mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) { |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 7189 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission"); |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 7190 | return null; |
| 7191 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7192 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7193 | final long identity = Binder.clearCallingIdentity(); |
| 7194 | try { |
| 7195 | String iccId = getIccId(subId); |
| 7196 | if (iccId != null) { |
| 7197 | String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 7198 | if (DBG_MERGE) { |
| 7199 | log("getLine1NumberForDisplay returning " |
| 7200 | + mTelephonySharedPreferences.getString(numberPrefKey, null)); |
| 7201 | } |
| 7202 | return mTelephonySharedPreferences.getString(numberPrefKey, null); |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 7203 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7204 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null"); |
| 7205 | return null; |
| 7206 | } finally { |
| 7207 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7208 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7209 | } |
| 7210 | |
| 7211 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7212 | public String getLine1AlphaTagForDisplay(int subId, String callingPackage, |
| 7213 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7214 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7215 | mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 7216 | return null; |
| 7217 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7218 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7219 | final long identity = Binder.clearCallingIdentity(); |
| 7220 | try { |
| 7221 | String iccId = getIccId(subId); |
| 7222 | if (iccId != null) { |
| 7223 | String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 7224 | return mTelephonySharedPreferences.getString(alphaTagPrefKey, null); |
| 7225 | } |
| 7226 | return null; |
| 7227 | } finally { |
| 7228 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7229 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7230 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 7231 | |
| 7232 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7233 | public String[] getMergedSubscriberIds(int subId, String callingPackage, |
| 7234 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7235 | // This API isn't public, so no need to provide a valid subscription ID - we're not worried |
| 7236 | // about carrier-privileged callers not having access. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7237 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7238 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7239 | callingFeatureId, "getMergedSubscriberIds")) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7240 | return null; |
| 7241 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7242 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 7243 | // Clear calling identity, when calling TelephonyManager, because callerUid must be |
| 7244 | // the process, where TelephonyManager was instantiated. |
| 7245 | // Otherwise AppOps check will fail. |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7246 | final long identity = Binder.clearCallingIdentity(); |
| 7247 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7248 | final Context context = mApp; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7249 | final TelephonyManager tele = TelephonyManager.from(context); |
| 7250 | final SubscriptionManager sub = SubscriptionManager.from(context); |
| 7251 | |
| 7252 | // Figure out what subscribers are currently active |
| 7253 | final ArraySet<String> activeSubscriberIds = new ArraySet<>(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7254 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 7255 | // Only consider subs which match the current subId |
| 7256 | // This logic can be simplified. See b/131189269 for progress. |
| 7257 | if (isActiveSubscription(subId)) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7258 | activeSubscriberIds.add(tele.getSubscriberId(subId)); |
| 7259 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7260 | |
| 7261 | // First pass, find a number override for an active subscriber |
| 7262 | String mergeNumber = null; |
| 7263 | final Map<String, ?> prefs = mTelephonySharedPreferences.getAll(); |
| 7264 | for (String key : prefs.keySet()) { |
| 7265 | if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) { |
| 7266 | final String subscriberId = (String) prefs.get(key); |
| 7267 | if (activeSubscriberIds.contains(subscriberId)) { |
| 7268 | final String iccId = key.substring( |
| 7269 | PREF_CARRIERS_SUBSCRIBER_PREFIX.length()); |
| 7270 | final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 7271 | mergeNumber = (String) prefs.get(numberKey); |
| 7272 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 7273 | Rlog.d(LOG_TAG, "Found line number " + mergeNumber |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7274 | + " for active subscriber " + subscriberId); |
| 7275 | } |
| 7276 | if (!TextUtils.isEmpty(mergeNumber)) { |
| 7277 | break; |
| 7278 | } |
| 7279 | } |
| 7280 | } |
| 7281 | } |
| 7282 | |
| 7283 | // Shortcut when no active merged subscribers |
| 7284 | if (TextUtils.isEmpty(mergeNumber)) { |
| 7285 | return null; |
| 7286 | } |
| 7287 | |
| 7288 | // Second pass, find all subscribers under that line override |
| 7289 | final ArraySet<String> result = new ArraySet<>(); |
| 7290 | for (String key : prefs.keySet()) { |
| 7291 | if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) { |
| 7292 | final String number = (String) prefs.get(key); |
| 7293 | if (mergeNumber.equals(number)) { |
| 7294 | final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length()); |
| 7295 | final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 7296 | final String subscriberId = (String) prefs.get(subscriberKey); |
| 7297 | if (!TextUtils.isEmpty(subscriberId)) { |
| 7298 | result.add(subscriberId); |
| 7299 | } |
| 7300 | } |
| 7301 | } |
| 7302 | } |
| 7303 | |
| 7304 | final String[] resultArray = result.toArray(new String[result.size()]); |
| 7305 | Arrays.sort(resultArray); |
| 7306 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 7307 | Rlog.d(LOG_TAG, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7308 | "Found subscribers " + Arrays.toString(resultArray) + " after merge"); |
| 7309 | } |
| 7310 | return resultArray; |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7311 | } finally { |
| 7312 | Binder.restoreCallingIdentity(identity); |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7313 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7314 | } |
| 7315 | |
| 7316 | @Override |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 7317 | public String[] getMergedImsisFromGroup(int subId, String callingPackage) { |
| 7318 | enforceReadPrivilegedPermission("getMergedImsisFromGroup"); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7319 | |
| 7320 | final long identity = Binder.clearCallingIdentity(); |
| 7321 | try { |
| 7322 | final TelephonyManager telephonyManager = mApp.getSystemService( |
| 7323 | TelephonyManager.class); |
| 7324 | String subscriberId = telephonyManager.getSubscriberId(subId); |
| 7325 | if (subscriberId == null) { |
| 7326 | if (DBG) { |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 7327 | log("getMergedImsisFromGroup can't find subscriberId for subId " |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7328 | + subId); |
| 7329 | } |
| 7330 | return null; |
| 7331 | } |
| 7332 | |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 7333 | ParcelUuid groupUuid; |
| 7334 | if (PhoneFactory.isSubscriptionManagerServiceEnabled()) { |
| 7335 | final SubscriptionInfo info = SubscriptionManagerService.getInstance() |
| 7336 | .getSubscriptionInfo(subId); |
| 7337 | groupUuid = info.getGroupUuid(); |
| 7338 | } else { |
| 7339 | final SubscriptionInfo info = mSubscriptionController |
| 7340 | .getSubscriptionInfo(subId); |
| 7341 | groupUuid = info.getGroupUuid(); |
| 7342 | } |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7343 | // If it doesn't belong to any group, return just subscriberId of itself. |
| 7344 | if (groupUuid == null) { |
| 7345 | return new String[]{subscriberId}; |
| 7346 | } |
| 7347 | |
| 7348 | // Get all subscriberIds from the group. |
| 7349 | final List<String> mergedSubscriberIds = new ArrayList<>(); |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 7350 | List<SubscriptionInfo> groupInfos; |
| 7351 | if (PhoneFactory.isSubscriptionManagerServiceEnabled()) { |
| 7352 | groupInfos = SubscriptionManagerService.getInstance() |
| 7353 | .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(), |
| 7354 | mApp.getAttributionTag()); |
| 7355 | } else { |
| 7356 | groupInfos = mSubscriptionController |
| 7357 | .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(), |
| 7358 | mApp.getAttributionTag()); |
| 7359 | } |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7360 | for (SubscriptionInfo subInfo : groupInfos) { |
| 7361 | subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId()); |
| 7362 | if (subscriberId != null) { |
| 7363 | mergedSubscriberIds.add(subscriberId); |
| 7364 | } |
| 7365 | } |
| 7366 | |
| 7367 | return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]); |
| 7368 | } finally { |
| 7369 | Binder.restoreCallingIdentity(identity); |
| 7370 | |
| 7371 | } |
| 7372 | } |
| 7373 | |
| 7374 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7375 | public boolean setOperatorBrandOverride(int subId, String brand) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 7376 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7377 | subId, "setOperatorBrandOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7378 | |
| 7379 | final long identity = Binder.clearCallingIdentity(); |
| 7380 | try { |
| 7381 | final Phone phone = getPhone(subId); |
| 7382 | return phone == null ? false : phone.setOperatorBrandOverride(brand); |
| 7383 | } finally { |
| 7384 | Binder.restoreCallingIdentity(identity); |
| 7385 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 7386 | } |
Steven Liu | 4bf01bc | 2014-07-17 11:05:29 -0500 | [diff] [blame] | 7387 | |
| 7388 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7389 | public boolean setRoamingOverride(int subId, List<String> gsmRoamingList, |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 7390 | List<String> gsmNonRoamingList, List<String> cdmaRoamingList, |
| 7391 | List<String> cdmaNonRoamingList) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 7392 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 7393 | mApp, subId, "setRoamingOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7394 | |
| 7395 | final long identity = Binder.clearCallingIdentity(); |
| 7396 | try { |
| 7397 | final Phone phone = getPhone(subId); |
| 7398 | if (phone == null) { |
| 7399 | return false; |
| 7400 | } |
| 7401 | return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList, |
| 7402 | cdmaNonRoamingList); |
| 7403 | } finally { |
| 7404 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7405 | } |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 7406 | } |
| 7407 | |
| 7408 | @Override |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 7409 | @Deprecated |
| 7410 | public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) { |
| 7411 | enforceModifyPermission(); |
| 7412 | |
| 7413 | int returnValue = 0; |
| 7414 | try { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7415 | AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 7416 | if(result.exception == null) { |
| 7417 | if (result.result != null) { |
| 7418 | byte[] responseData = (byte[])(result.result); |
| 7419 | if(responseData.length > oemResp.length) { |
| 7420 | Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " + |
| 7421 | responseData.length + "bytes. Buffer Size is " + |
| 7422 | oemResp.length + "bytes."); |
| 7423 | } |
| 7424 | System.arraycopy(responseData, 0, oemResp, 0, responseData.length); |
| 7425 | returnValue = responseData.length; |
| 7426 | } |
| 7427 | } else { |
| 7428 | CommandException ex = (CommandException) result.exception; |
| 7429 | returnValue = ex.getCommandError().ordinal(); |
| 7430 | if(returnValue > 0) returnValue *= -1; |
| 7431 | } |
| 7432 | } catch (RuntimeException e) { |
| 7433 | Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception"); |
| 7434 | returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal()); |
| 7435 | if(returnValue > 0) returnValue *= -1; |
| 7436 | } |
| 7437 | |
| 7438 | return returnValue; |
| 7439 | } |
| 7440 | |
| 7441 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 7442 | public int getRadioAccessFamily(int phoneId, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7443 | Phone phone = PhoneFactory.getPhone(phoneId); |
Shuo Qian | dee5340 | 2020-05-29 14:08:15 -0700 | [diff] [blame] | 7444 | try { |
| 7445 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 7446 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Shuo Qian | dee5340 | 2020-05-29 14:08:15 -0700 | [diff] [blame] | 7447 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 7448 | } catch (SecurityException e) { |
| 7449 | EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission"); |
| 7450 | throw e; |
| 7451 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7452 | int raf = RadioAccessFamily.RAF_UNKNOWN; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7453 | if (phone == null) { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7454 | return raf; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7455 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7456 | final long identity = Binder.clearCallingIdentity(); |
| 7457 | try { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7458 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 7459 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7460 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 7461 | raf = ProxyController.getInstance().getRadioAccessFamily(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7462 | } finally { |
| 7463 | Binder.restoreCallingIdentity(identity); |
| 7464 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7465 | return raf; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 7466 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7467 | |
| 7468 | @Override |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7469 | public void uploadCallComposerPicture(int subscriptionId, String callingPackage, |
Hall Liu | e31bac6 | 2020-12-23 19:16:10 -0800 | [diff] [blame] | 7470 | String contentType, ParcelFileDescriptor fd, ResultReceiver callback) { |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7471 | try { |
| 7472 | if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0), |
| 7473 | Binder.getCallingUid())) { |
Tyler Gunn | b87925a | 2021-06-10 14:54:27 -0700 | [diff] [blame] | 7474 | throw new SecurityException("Invalid package:" + callingPackage); |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7475 | } |
| 7476 | } catch (PackageManager.NameNotFoundException e) { |
Tyler Gunn | b87925a | 2021-06-10 14:54:27 -0700 | [diff] [blame] | 7477 | throw new SecurityException("Invalid package:" + callingPackage); |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7478 | } |
| 7479 | RoleManager rm = mApp.getSystemService(RoleManager.class); |
| 7480 | List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER); |
| 7481 | if (!dialerRoleHolders.contains(callingPackage)) { |
| 7482 | throw new SecurityException("App must be the dialer role holder to" |
| 7483 | + " upload a call composer pic"); |
| 7484 | } |
| 7485 | |
| 7486 | Executors.newSingleThreadExecutor().execute(() -> { |
| 7487 | ByteArrayOutputStream output = new ByteArrayOutputStream( |
| 7488 | (int) TelephonyManager.getMaximumCallComposerPictureSize()); |
| 7489 | InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd); |
| 7490 | boolean readUntilEnd = false; |
| 7491 | int totalBytesRead = 0; |
| 7492 | byte[] buffer = new byte[16 * 1024]; |
| 7493 | while (true) { |
| 7494 | int numRead; |
| 7495 | try { |
| 7496 | numRead = input.read(buffer); |
| 7497 | } catch (IOException e) { |
| 7498 | try { |
| 7499 | fd.checkError(); |
| 7500 | callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED, |
| 7501 | null); |
| 7502 | } catch (IOException e1) { |
| 7503 | // This means that the other side closed explicitly with an error. If this |
| 7504 | // happens, log and ignore. |
| 7505 | loge("Remote end of call composer picture pipe closed: " + e1); |
| 7506 | } |
| 7507 | break; |
| 7508 | } |
| 7509 | if (numRead == -1) { |
| 7510 | readUntilEnd = true; |
| 7511 | break; |
| 7512 | } |
| 7513 | totalBytesRead += numRead; |
| 7514 | if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) { |
| 7515 | loge("Too many bytes read for call composer picture: " + totalBytesRead); |
| 7516 | try { |
| 7517 | input.close(); |
| 7518 | } catch (IOException e) { |
| 7519 | // ignore |
| 7520 | } |
| 7521 | break; |
| 7522 | } |
| 7523 | output.write(buffer, 0, numRead); |
| 7524 | } |
| 7525 | // Generally, the remote end will close the file descriptors. The only case where we |
| 7526 | // close is above, where the picture size is too big. |
| 7527 | |
| 7528 | try { |
| 7529 | fd.checkError(); |
| 7530 | } catch (IOException e) { |
| 7531 | loge("Remote end for call composer closed with an error: " + e); |
| 7532 | return; |
| 7533 | } |
| 7534 | |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 7535 | if (!readUntilEnd) { |
| 7536 | loge("Did not finish reading entire image; aborting"); |
| 7537 | return; |
| 7538 | } |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7539 | |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 7540 | ImageData imageData = new ImageData(output.toByteArray(), contentType, null); |
| 7541 | CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer( |
| 7542 | new CallComposerPictureTransfer.Factory() {}, |
| 7543 | imageData, |
| 7544 | (result) -> { |
| 7545 | if (result.first != null) { |
| 7546 | ParcelUuid parcelUuid = new ParcelUuid(result.first); |
| 7547 | Bundle outputResult = new Bundle(); |
| 7548 | outputResult.putParcelable( |
| 7549 | TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid); |
| 7550 | callback.send(TelephonyManager.CallComposerException.SUCCESS, |
| 7551 | outputResult); |
| 7552 | } else { |
| 7553 | callback.send(result.second, null); |
| 7554 | } |
| 7555 | } |
| 7556 | ); |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7557 | }); |
| 7558 | } |
| 7559 | |
| 7560 | @Override |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7561 | public void enableVideoCalling(boolean enable) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7562 | final Phone defaultPhone = getDefaultPhone(); |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7563 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7564 | |
| 7565 | final long identity = Binder.clearCallingIdentity(); |
| 7566 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7567 | ImsManager.getInstance(defaultPhone.getContext(), |
| 7568 | defaultPhone.getPhoneId()).setVtSetting(enable); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7569 | } finally { |
| 7570 | Binder.restoreCallingIdentity(identity); |
| 7571 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7572 | } |
| 7573 | |
| 7574 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7575 | public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7576 | final Phone defaultPhone = getDefaultPhone(); |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7577 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 7578 | callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 7579 | return false; |
| 7580 | } |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 7581 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7582 | final long identity = Binder.clearCallingIdentity(); |
| 7583 | try { |
| 7584 | // Check the user preference and the system-level IMS setting. Even if the user has |
| 7585 | // enabled video calling, if IMS is disabled we aren't able to support video calling. |
| 7586 | // In the long run, we may instead need to check if there exists a connection service |
| 7587 | // which can support video calling. |
| 7588 | ImsManager imsManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7589 | ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7590 | return imsManager.isVtEnabledByPlatform() |
| 7591 | && imsManager.isEnhanced4gLteModeSettingEnabledByUser() |
| 7592 | && imsManager.isVtEnabledByUser(); |
| 7593 | } finally { |
| 7594 | Binder.restoreCallingIdentity(identity); |
| 7595 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7596 | } |
Libin.Tang@motorola.com | afe8264 | 2014-12-18 13:27:53 -0600 | [diff] [blame] | 7597 | |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7598 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7599 | public boolean canChangeDtmfToneLength(int subId, String callingPackage, |
| 7600 | String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7601 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7602 | mApp, subId, callingPackage, callingFeatureId, |
| 7603 | "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7604 | return false; |
| 7605 | } |
| 7606 | |
| 7607 | final long identity = Binder.clearCallingIdentity(); |
| 7608 | try { |
| 7609 | CarrierConfigManager configManager = |
| 7610 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7611 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7612 | .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL); |
| 7613 | } finally { |
| 7614 | Binder.restoreCallingIdentity(identity); |
| 7615 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7616 | } |
| 7617 | |
| 7618 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7619 | public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7620 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7621 | mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7622 | return false; |
| 7623 | } |
| 7624 | |
| 7625 | final long identity = Binder.clearCallingIdentity(); |
| 7626 | try { |
| 7627 | CarrierConfigManager configManager = |
| 7628 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7629 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7630 | .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL); |
| 7631 | } finally { |
| 7632 | Binder.restoreCallingIdentity(identity); |
| 7633 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7634 | } |
| 7635 | |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7636 | @Override |
| 7637 | public boolean isTtyModeSupported() { |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 7638 | TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class); |
Wooki Wu | 1f82f7a | 2016-02-15 15:59:58 +0800 | [diff] [blame] | 7639 | return telecomManager.isTtySupported(); |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7640 | } |
| 7641 | |
| 7642 | @Override |
| 7643 | public boolean isHearingAidCompatibilitySupported() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7644 | final long identity = Binder.clearCallingIdentity(); |
| 7645 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7646 | return mApp.getResources().getBoolean(R.bool.hac_enabled); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7647 | } finally { |
| 7648 | Binder.restoreCallingIdentity(identity); |
| 7649 | } |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7650 | } |
| 7651 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 7652 | /** |
| 7653 | * Determines whether the device currently supports RTT (Real-time text). Based both on carrier |
| 7654 | * support for the feature and device firmware support. |
| 7655 | * |
| 7656 | * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise. |
| 7657 | */ |
| 7658 | @Override |
| 7659 | public boolean isRttSupported(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7660 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7661 | final Phone phone = getPhone(subscriptionId); |
| 7662 | if (phone == null) { |
| 7663 | loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId); |
| 7664 | return false; |
| 7665 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7666 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7667 | boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7668 | CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL); |
| 7669 | boolean isDeviceSupported = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7670 | phone.getContext().getResources().getBoolean(R.bool.config_support_rtt); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7671 | return isCarrierSupported && isDeviceSupported; |
| 7672 | } finally { |
| 7673 | Binder.restoreCallingIdentity(identity); |
| 7674 | } |
Hall Liu | 9818758 | 2018-01-22 19:15:32 -0800 | [diff] [blame] | 7675 | } |
| 7676 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 7677 | /** |
Hall Liu | f2daa02 | 2019-07-23 18:39:00 -0700 | [diff] [blame] | 7678 | * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set |
| 7679 | * RTT setting, will return true if the device and carrier both support RTT. |
| 7680 | * 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] | 7681 | */ |
| 7682 | public boolean isRttEnabled(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7683 | final long identity = Binder.clearCallingIdentity(); |
| 7684 | try { |
Hall Liu | 5bab75c | 2019-12-11 23:58:20 +0000 | [diff] [blame] | 7685 | boolean isRttSupported = isRttSupported(subscriptionId); |
| 7686 | boolean isUserRttSettingOn = Settings.Secure.getInt( |
| 7687 | mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0; |
| 7688 | boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId) |
| 7689 | .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL); |
| 7690 | return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7691 | } finally { |
| 7692 | Binder.restoreCallingIdentity(identity); |
| 7693 | } |
Hall Liu | 3ad5f01 | 2018-04-06 16:23:39 -0700 | [diff] [blame] | 7694 | } |
| 7695 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7696 | @Deprecated |
| 7697 | @Override |
| 7698 | public String getDeviceId(String callingPackage) { |
| 7699 | return getDeviceIdWithFeature(callingPackage, null); |
| 7700 | } |
| 7701 | |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7702 | /** |
| 7703 | * Returns the unique device ID of phone, for example, the IMEI for |
| 7704 | * GSM and the MEID for CDMA phones. Return null if device ID is not available. |
| 7705 | * |
| 7706 | * <p>Requires Permission: |
| 7707 | * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} |
| 7708 | */ |
| 7709 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7710 | public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) { |
Shuo Qian | 13d8915 | 2021-05-10 23:58:11 -0700 | [diff] [blame] | 7711 | try { |
| 7712 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 7713 | } catch (SecurityException se) { |
| 7714 | EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid()); |
| 7715 | throw new SecurityException("Package " + callingPackage + " does not belong to " |
| 7716 | + Binder.getCallingUid()); |
| 7717 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7718 | final Phone phone = PhoneFactory.getPhone(0); |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7719 | if (phone == null) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7720 | return null; |
| 7721 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7722 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 7723 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7724 | callingPackage, callingFeatureId, "getDeviceId")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7725 | return null; |
| 7726 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7727 | |
| 7728 | final long identity = Binder.clearCallingIdentity(); |
| 7729 | try { |
| 7730 | return phone.getDeviceId(); |
| 7731 | } finally { |
| 7732 | Binder.restoreCallingIdentity(identity); |
| 7733 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7734 | } |
| 7735 | |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 7736 | /** |
| 7737 | * {@hide} |
| 7738 | * Returns the IMS Registration Status on a particular subid |
| 7739 | * |
| 7740 | * @param subId |
| 7741 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7742 | public boolean isImsRegistered(int subId) { |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 7743 | Phone phone = getPhone(subId); |
| 7744 | if (phone != null) { |
| 7745 | return phone.isImsRegistered(); |
| 7746 | } else { |
| 7747 | return false; |
| 7748 | } |
| 7749 | } |
| 7750 | |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 7751 | @Override |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7752 | public int getSubIdForPhoneAccountHandle( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7753 | PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) { |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7754 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(), |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7755 | callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) { |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7756 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 7757 | } |
| 7758 | final long identity = Binder.clearCallingIdentity(); |
| 7759 | try { |
| 7760 | return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle); |
| 7761 | } finally { |
| 7762 | Binder.restoreCallingIdentity(identity); |
| 7763 | } |
| 7764 | } |
| 7765 | |
| 7766 | @Override |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 7767 | public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) { |
Alireza Forouzan | 4ac4f98 | 2021-03-16 22:18:52 -0700 | [diff] [blame] | 7768 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 7769 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Alireza Forouzan | 4ac4f98 | 2021-03-16 22:18:52 -0700 | [diff] [blame] | 7770 | mApp, |
| 7771 | subscriptionId, |
| 7772 | "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: " + subscriptionId); |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 7773 | final long identity = Binder.clearCallingIdentity(); |
| 7774 | try { |
| 7775 | Phone phone = getPhone(subscriptionId); |
| 7776 | if (phone == null) { |
| 7777 | return null; |
| 7778 | } |
| 7779 | return PhoneUtils.makePstnPhoneAccountHandle(phone); |
| 7780 | } finally { |
| 7781 | Binder.restoreCallingIdentity(identity); |
| 7782 | } |
| 7783 | } |
| 7784 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7785 | /** |
| 7786 | * @return the VoWiFi calling availability. |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 7787 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7788 | public boolean isWifiCallingAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7789 | final long identity = Binder.clearCallingIdentity(); |
| 7790 | try { |
| 7791 | Phone phone = getPhone(subId); |
| 7792 | if (phone != null) { |
| 7793 | return phone.isWifiCallingEnabled(); |
| 7794 | } else { |
| 7795 | return false; |
| 7796 | } |
| 7797 | } finally { |
| 7798 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7799 | } |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 7800 | } |
| 7801 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7802 | /** |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7803 | * @return the VT calling availability. |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 7804 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7805 | public boolean isVideoTelephonyAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7806 | final long identity = Binder.clearCallingIdentity(); |
| 7807 | try { |
| 7808 | Phone phone = getPhone(subId); |
| 7809 | if (phone != null) { |
| 7810 | return phone.isVideoEnabled(); |
| 7811 | } else { |
| 7812 | return false; |
| 7813 | } |
| 7814 | } finally { |
| 7815 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7816 | } |
| 7817 | } |
| 7818 | |
| 7819 | /** |
| 7820 | * @return the IMS registration technology for the MMTEL feature. Valid return values are |
| 7821 | * defined in {@link ImsRegistrationImplBase}. |
| 7822 | */ |
| 7823 | public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7824 | final long identity = Binder.clearCallingIdentity(); |
| 7825 | try { |
| 7826 | Phone phone = getPhone(subId); |
| 7827 | if (phone != null) { |
| 7828 | return phone.getImsRegistrationTech(); |
| 7829 | } else { |
| 7830 | return ImsRegistrationImplBase.REGISTRATION_TECH_NONE; |
| 7831 | } |
| 7832 | } finally { |
| 7833 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7834 | } |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 7835 | } |
| 7836 | |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 7837 | @Override |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 7838 | public void factoryReset(int subId, String callingPackage) { |
paulhu | 5a77360 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 7839 | enforceSettingsPermission(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 7840 | if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) { |
| 7841 | return; |
| 7842 | } |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 7843 | Phone defaultPhone = getDefaultPhone(); |
| 7844 | if (defaultPhone != null) { |
| 7845 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7846 | mApp, getDefaultPhone().getSubId(), "factoryReset"); |
| 7847 | } |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7848 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7849 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7850 | try { |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 7851 | if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction( |
| 7852 | UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7853 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 7854 | getDefaultDataEnabled(), callingPackage); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7855 | setNetworkSelectionModeAutomatic(subId); |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 7856 | Phone phone = getPhone(subId); |
SongFerngWang | fd89b10 | 2021-05-27 22:44:54 +0800 | [diff] [blame] | 7857 | cleanUpAllowedNetworkTypes(phone, subId); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7858 | setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId)); |
Jordan Liu | 857e73a | 2021-03-05 16:24:04 -0800 | [diff] [blame] | 7859 | getPhone(subId).resetCarrierKeysForImsiEncryption(); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7860 | } |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 7861 | // There has been issues when Sms raw table somehow stores orphan |
| 7862 | // fragments. They lead to garbled message when new fragments come |
| 7863 | // in and combined with those stale ones. In case this happens again, |
| 7864 | // user can reset all network settings which will clean up this table. |
| 7865 | cleanUpSmsRawTable(getDefaultPhone().getContext()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 7866 | // Clean up IMS settings as well here. |
| 7867 | int slotId = getSlotIndex(subId); |
| 7868 | if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 7869 | ImsManager.getInstance(mApp, slotId).factoryReset(); |
| 7870 | } |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 7871 | |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 7872 | if (defaultPhone == null) { |
| 7873 | return; |
| 7874 | } |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 7875 | // Erase modem config if erase modem on network setting is enabled. |
| 7876 | String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY, |
| 7877 | RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED); |
| 7878 | if (configValue != null && Boolean.parseBoolean(configValue)) { |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 7879 | sendEraseModemConfig(defaultPhone); |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 7880 | } |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 7881 | |
| 7882 | sendEraseDataInSharedPreferences(defaultPhone); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7883 | } finally { |
| 7884 | Binder.restoreCallingIdentity(identity); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 7885 | } |
| 7886 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7887 | |
SongFerngWang | fd89b10 | 2021-05-27 22:44:54 +0800 | [diff] [blame] | 7888 | @VisibleForTesting |
| 7889 | void cleanUpAllowedNetworkTypes(Phone phone, int subId) { |
| 7890 | if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) { |
| 7891 | return; |
| 7892 | } |
| 7893 | long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType( |
| 7894 | RILConstants.PREFERRED_NETWORK_MODE); |
| 7895 | SubscriptionManager.setSubscriptionProperty(subId, |
| 7896 | SubscriptionManager.ALLOWED_NETWORK_TYPES, |
| 7897 | "user=" + defaultNetworkType); |
| 7898 | phone.loadAllowedNetworksFromSubscriptionDatabase(); |
| 7899 | phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER, |
| 7900 | defaultNetworkType, null); |
| 7901 | } |
| 7902 | |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 7903 | private void cleanUpSmsRawTable(Context context) { |
| 7904 | ContentResolver resolver = context.getContentResolver(); |
| 7905 | Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete"); |
| 7906 | resolver.delete(uri, null, null); |
| 7907 | } |
| 7908 | |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7909 | @Override |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7910 | public String getSimLocaleForSubscriber(int subId) { |
| 7911 | enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId); |
| 7912 | final Phone phone = getPhone(subId); |
| 7913 | if (phone == null) { |
| 7914 | log("getSimLocaleForSubscriber, invalid subId"); |
chen xu | 2bb91e4 | 2019-01-24 14:35:54 -0800 | [diff] [blame] | 7915 | return null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7916 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7917 | final long identity = Binder.clearCallingIdentity(); |
| 7918 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 7919 | SubscriptionInfo info; |
| 7920 | if (PhoneFactory.isSubscriptionManagerServiceEnabled()) { |
| 7921 | info = SubscriptionManagerService.getInstance().getActiveSubscriptionInfo(subId, |
| 7922 | phone.getContext().getOpPackageName(), |
| 7923 | phone.getContext().getAttributionTag()); |
| 7924 | if (info == null) { |
| 7925 | log("getSimLocaleForSubscriber, inactive subId: " + subId); |
| 7926 | return null; |
| 7927 | } |
| 7928 | } else { |
| 7929 | info = mSubscriptionController.getActiveSubscriptionInfo(subId, |
| 7930 | phone.getContext().getOpPackageName(), |
| 7931 | phone.getContext().getAttributionTag()); |
| 7932 | if (info == null) { |
| 7933 | log("getSimLocaleForSubscriber, inactive subId: " + subId); |
| 7934 | return null; |
| 7935 | } |
chen xu | 6291c47 | 2019-02-04 12:55:53 -0800 | [diff] [blame] | 7936 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7937 | // Try and fetch the locale from the carrier properties or from the SIM language |
| 7938 | // preferences (EF-PL and EF-LI)... |
| 7939 | final int mcc = info.getMcc(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7940 | String simLanguage = null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7941 | final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs(); |
| 7942 | if (localeFromDefaultSim != null) { |
| 7943 | if (!localeFromDefaultSim.getCountry().isEmpty()) { |
| 7944 | if (DBG) log("Using locale from subId: " + subId + " locale: " |
| 7945 | + localeFromDefaultSim); |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 7946 | return matchLocaleFromSupportedLocaleList(phone, localeFromDefaultSim); |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7947 | } else { |
| 7948 | simLanguage = localeFromDefaultSim.getLanguage(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7949 | } |
| 7950 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7951 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7952 | // The SIM language preferences only store a language (e.g. fr = French), not an |
| 7953 | // exact locale (e.g. fr_FR = French/France). So, if the locale returned from |
| 7954 | // the SIM and carrier preferences does not include a country we add the country |
| 7955 | // determined from the SIM MCC to provide an exact locale. |
zoey chen | c730df8 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 7956 | final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7957 | if (mccLocale != null) { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7958 | if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale); |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 7959 | return matchLocaleFromSupportedLocaleList(phone, mccLocale); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7960 | } |
| 7961 | |
| 7962 | if (DBG) log("No locale found - returning null"); |
| 7963 | return null; |
| 7964 | } finally { |
| 7965 | Binder.restoreCallingIdentity(identity); |
| 7966 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7967 | } |
| 7968 | |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 7969 | @VisibleForTesting |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 7970 | String matchLocaleFromSupportedLocaleList(Phone phone, @NonNull Locale inputLocale) { |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 7971 | String[] supportedLocale = com.android.internal.app.LocalePicker.getSupportedLocales( |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 7972 | phone.getContext()); |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 7973 | for (String localeTag : supportedLocale) { |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 7974 | if (LocaleList.matchesLanguageAndScript(inputLocale, Locale.forLanguageTag(localeTag)) |
| 7975 | && TextUtils.equals(inputLocale.getCountry(), |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 7976 | Locale.forLanguageTag(localeTag).getCountry())) { |
| 7977 | return localeTag; |
| 7978 | } |
| 7979 | } |
| 7980 | return inputLocale.toLanguageTag(); |
| 7981 | } |
| 7982 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7983 | /** |
| 7984 | * NOTE: this method assumes permission checks are done and caller identity has been cleared. |
| 7985 | */ |
| 7986 | private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 7987 | if (PhoneFactory.isSubscriptionManagerServiceEnabled()) { |
| 7988 | return SubscriptionManagerService.getInstance().getActiveSubscriptionInfoList( |
| 7989 | mApp.getOpPackageName(), mApp.getAttributionTag()); |
| 7990 | } |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7991 | return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(), |
Philip P. Moltmann | 8d34f0c | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7992 | mApp.getAttributionTag()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7993 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7994 | |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 7995 | private ActivityStatsTechSpecificInfo[] mLastModemActivitySpecificInfo = null; |
| 7996 | private ModemActivityInfo mLastModemActivityInfo = null; |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7997 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7998 | /** |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 7999 | * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object |
| 8000 | * representing the state of the modem. |
| 8001 | * |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 8002 | * NOTE: The underlying implementation clears the modem state, so there should only ever be one |
| 8003 | * caller to it. Everyone should call this class to get cumulative data. |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 8004 | * @hide |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 8005 | */ |
| 8006 | @Override |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 8007 | public void requestModemActivityInfo(ResultReceiver result) { |
| 8008 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8009 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8010 | |
| 8011 | final long identity = Binder.clearCallingIdentity(); |
| 8012 | try { |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 8013 | sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8014 | } finally { |
| 8015 | Binder.restoreCallingIdentity(identity); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 8016 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 8017 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8018 | |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 8019 | // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be |
| 8020 | // less than total activity duration. |
| 8021 | private boolean isModemActivityInfoValid(ModemActivityInfo info) { |
| 8022 | if (info == null) { |
| 8023 | return false; |
| 8024 | } |
| 8025 | int activityDurationMs = |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 8026 | (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis()); |
| 8027 | int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum(); |
| 8028 | |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 8029 | return (info.isValid() |
| 8030 | && (info.getSleepTimeMillis() <= activityDurationMs) |
| 8031 | && (info.getIdleTimeMillis() <= activityDurationMs) |
Chen Xu | d78231e | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 8032 | && (info.getReceiveTimeMillis() <= activityDurationMs) |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 8033 | && (totalTxTimeMs <= activityDurationMs)); |
| 8034 | } |
| 8035 | |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8036 | private void updateLastModemActivityInfo(ModemActivityInfo info, int rat, int freq) { |
| 8037 | int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()]; |
| 8038 | int[] txTimeMs = info.getTransmitTimeMillis(rat, freq); |
| 8039 | int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat, freq); |
| 8040 | |
| 8041 | for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) { |
| 8042 | mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl]; |
| 8043 | } |
| 8044 | |
| 8045 | mLastModemActivityInfo.setTransmitTimeMillis(rat, freq, mergedTxTimeMs); |
| 8046 | mLastModemActivityInfo.setReceiveTimeMillis( |
| 8047 | rat, |
| 8048 | freq, |
| 8049 | info.getReceiveTimeMillis(rat, freq) |
| 8050 | + mLastModemActivityInfo.getReceiveTimeMillis(rat, freq)); |
| 8051 | } |
| 8052 | |
| 8053 | private void updateLastModemActivityInfo(ModemActivityInfo info, int rat) { |
| 8054 | int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()]; |
| 8055 | int[] txTimeMs = info.getTransmitTimeMillis(rat); |
| 8056 | int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat); |
| 8057 | |
| 8058 | for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) { |
| 8059 | mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl]; |
| 8060 | } |
| 8061 | mLastModemActivityInfo.setTransmitTimeMillis(rat, mergedTxTimeMs); |
| 8062 | mLastModemActivityInfo.setReceiveTimeMillis( |
| 8063 | rat, |
| 8064 | info.getReceiveTimeMillis(rat) + mLastModemActivityInfo.getReceiveTimeMillis(rat)); |
| 8065 | } |
| 8066 | |
| 8067 | /** |
| 8068 | * Merge this ModemActivityInfo with mLastModemActivitySpecificInfo |
| 8069 | * @param info recent ModemActivityInfo |
| 8070 | */ |
| 8071 | private void mergeModemActivityInfo(ModemActivityInfo info) { |
| 8072 | List<ActivityStatsTechSpecificInfo> merged = new ArrayList<>(); |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 8073 | ActivityStatsTechSpecificInfo deltaSpecificInfo; |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8074 | boolean matched; |
| 8075 | for (int i = 0; i < info.getSpecificInfoLength(); i++) { |
| 8076 | matched = false; |
| 8077 | int rat = info.getSpecificInfoRat(i); |
| 8078 | int freq = info.getSpecificInfoFrequencyRange(i); |
| 8079 | //Check each ActivityStatsTechSpecificInfo in this ModemActivityInfo for new rat returns |
| 8080 | //Add a new ActivityStatsTechSpecificInfo if is a new rat, and merge with the original |
| 8081 | //if it already exists |
| 8082 | for (int j = 0; j < mLastModemActivitySpecificInfo.length; j++) { |
| 8083 | if (rat == mLastModemActivityInfo.getSpecificInfoRat(j) && !matched) { |
| 8084 | //Merged based on frequency range (MMWAVE vs SUB6) for 5G |
| 8085 | if (rat == AccessNetworkConstants.AccessNetworkType.NGRAN) { |
| 8086 | if (freq == mLastModemActivityInfo.getSpecificInfoFrequencyRange(j)) { |
| 8087 | updateLastModemActivityInfo(info, rat, freq); |
| 8088 | matched = true; |
| 8089 | } |
| 8090 | } else { |
| 8091 | updateLastModemActivityInfo(info, rat); |
| 8092 | matched = true; |
| 8093 | } |
| 8094 | } |
| 8095 | } |
| 8096 | |
| 8097 | if (!matched) { |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 8098 | deltaSpecificInfo = |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8099 | new ActivityStatsTechSpecificInfo( |
| 8100 | rat, |
| 8101 | freq, |
| 8102 | info.getTransmitTimeMillis(rat, freq), |
| 8103 | (int) info.getReceiveTimeMillis(rat, freq)); |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 8104 | merged.addAll(Arrays.asList(deltaSpecificInfo)); |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8105 | } |
| 8106 | } |
| 8107 | merged.addAll(Arrays.asList(mLastModemActivitySpecificInfo)); |
| 8108 | mLastModemActivitySpecificInfo = |
| 8109 | new ActivityStatsTechSpecificInfo[merged.size()]; |
| 8110 | merged.toArray(mLastModemActivitySpecificInfo); |
| 8111 | |
| 8112 | mLastModemActivityInfo.setTimestamp(info.getTimestampMillis()); |
| 8113 | mLastModemActivityInfo.setSleepTimeMillis( |
| 8114 | info.getSleepTimeMillis() |
| 8115 | + mLastModemActivityInfo.getSleepTimeMillis()); |
| 8116 | mLastModemActivityInfo.setIdleTimeMillis( |
| 8117 | info.getIdleTimeMillis() |
| 8118 | + mLastModemActivityInfo.getIdleTimeMillis()); |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 8119 | |
| 8120 | mLastModemActivityInfo = |
| 8121 | new ModemActivityInfo( |
| 8122 | mLastModemActivityInfo.getTimestampMillis(), |
| 8123 | mLastModemActivityInfo.getSleepTimeMillis(), |
| 8124 | mLastModemActivityInfo.getIdleTimeMillis(), |
| 8125 | mLastModemActivitySpecificInfo); |
| 8126 | } |
| 8127 | |
| 8128 | private ActivityStatsTechSpecificInfo[] deepCopyModemActivitySpecificInfo( |
| 8129 | ActivityStatsTechSpecificInfo[] info) { |
| 8130 | int infoSize = info.length; |
| 8131 | ActivityStatsTechSpecificInfo[] ret = new ActivityStatsTechSpecificInfo[infoSize]; |
| 8132 | for (int i = 0; i < infoSize; i++) { |
| 8133 | ret[i] = new ActivityStatsTechSpecificInfo( |
| 8134 | info[i].getRat(), info[i].getFrequencyRange(), |
| 8135 | info[i].getTransmitTimeMillis(), |
| 8136 | (int) info[i].getReceiveTimeMillis()); |
| 8137 | } |
| 8138 | return ret; |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8139 | } |
| 8140 | |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8141 | /** |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8142 | * Returns the service state information on specified subscription. |
| 8143 | */ |
| 8144 | @Override |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 8145 | public ServiceState getServiceStateForSubscriber(int subId, |
| 8146 | boolean renounceFineLocationAccess, boolean renounceCoarseLocationAccess, |
| 8147 | String callingPackage, String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8148 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8149 | mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) { |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8150 | return null; |
| 8151 | } |
| 8152 | |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 8153 | boolean hasFinePermission = false; |
| 8154 | boolean hasCoarsePermission = false; |
| 8155 | if (!renounceFineLocationAccess) { |
| 8156 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 8157 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 8158 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 8159 | .setCallingPackage(callingPackage) |
| 8160 | .setCallingFeatureId(callingFeatureId) |
| 8161 | .setCallingPid(Binder.getCallingPid()) |
| 8162 | .setCallingUid(Binder.getCallingUid()) |
| 8163 | .setMethod("getServiceStateForSubscriber") |
| 8164 | .setLogAsInfo(true) |
| 8165 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 8166 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 8167 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 8168 | .build()); |
| 8169 | hasFinePermission = |
| 8170 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 8171 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 8172 | |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 8173 | if (!renounceCoarseLocationAccess) { |
| 8174 | LocationAccessPolicy.LocationPermissionResult coarseLocationResult = |
| 8175 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 8176 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 8177 | .setCallingPackage(callingPackage) |
| 8178 | .setCallingFeatureId(callingFeatureId) |
| 8179 | .setCallingPid(Binder.getCallingPid()) |
| 8180 | .setCallingUid(Binder.getCallingUid()) |
| 8181 | .setMethod("getServiceStateForSubscriber") |
| 8182 | .setLogAsInfo(true) |
| 8183 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 8184 | .setMinSdkVersionForFine(Integer.MAX_VALUE) |
| 8185 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 8186 | .build()); |
| 8187 | hasCoarsePermission = |
| 8188 | coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 8189 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 8190 | |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 8191 | final Phone phone = getPhone(subId); |
| 8192 | if (phone == null) { |
| 8193 | return null; |
| 8194 | } |
| 8195 | |
Jordan Liu | 0f2bc44 | 2020-11-18 16:47:37 -0800 | [diff] [blame] | 8196 | final long identity = Binder.clearCallingIdentity(); |
| 8197 | |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 8198 | boolean isCallingPackageDataService = phone.getDataServicePackages() |
| 8199 | .contains(callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8200 | try { |
Jordan Liu | c437b19 | 2020-08-17 10:59:12 -0700 | [diff] [blame] | 8201 | // isActiveSubId requires READ_PHONE_STATE, which we already check for above |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 8202 | if (PhoneFactory.isSubscriptionManagerServiceEnabled()) { |
| 8203 | SubscriptionInfoInternal subInfo = SubscriptionManagerService.getInstance() |
| 8204 | .getSubscriptionInfoInternal(subId); |
| 8205 | if (subInfo == null || !subInfo.isActive()) { |
| 8206 | Rlog.d(LOG_TAG, "getServiceStateForSubscriber returning null for inactive " |
| 8207 | + "subId=" + subId); |
| 8208 | return null; |
| 8209 | } |
| 8210 | } else { |
| 8211 | if (!mSubscriptionController.isActiveSubId(subId, callingPackage, |
| 8212 | callingFeatureId)) { |
| 8213 | Rlog.d(LOG_TAG, "getServiceStateForSubscriber returning null for inactive " |
| 8214 | + "subId=" + subId); |
| 8215 | return null; |
| 8216 | } |
Jordan Liu | c437b19 | 2020-08-17 10:59:12 -0700 | [diff] [blame] | 8217 | } |
| 8218 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 8219 | ServiceState ss = phone.getServiceState(); |
| 8220 | |
| 8221 | // Scrub out the location info in ServiceState depending on what level of access |
| 8222 | // the caller has. |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 8223 | if (hasFinePermission || isCallingPackageDataService) return ss; |
Malcolm Chen | 5052de6 | 2019-12-30 13:56:38 -0800 | [diff] [blame] | 8224 | if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false); |
| 8225 | return ss.createLocationInfoSanitizedCopy(true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8226 | } finally { |
| 8227 | Binder.restoreCallingIdentity(identity); |
| 8228 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8229 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8230 | |
| 8231 | /** |
| 8232 | * Returns the URI for the per-account voicemail ringtone set in Phone settings. |
| 8233 | * |
| 8234 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 8235 | * voicemail ringtone. |
| 8236 | * @return The URI for the ringtone to play when receiving a voicemail from a specific |
| 8237 | * PhoneAccount. |
| 8238 | */ |
| 8239 | @Override |
| 8240 | public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8241 | final long identity = Binder.clearCallingIdentity(); |
| 8242 | try { |
| 8243 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 8244 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8245 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8246 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8247 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8248 | return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext()); |
| 8249 | } finally { |
| 8250 | Binder.restoreCallingIdentity(identity); |
| 8251 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8252 | } |
| 8253 | |
| 8254 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8255 | * Sets the per-account voicemail ringtone. |
| 8256 | * |
| 8257 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 8258 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 8259 | * |
| 8260 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 8261 | * voicemail ringtone. |
| 8262 | * @param uri The URI for the ringtone to play when receiving a voicemail from a specific |
| 8263 | * PhoneAccount. |
| 8264 | */ |
| 8265 | @Override |
| 8266 | public void setVoicemailRingtoneUri(String callingPackage, |
| 8267 | PhoneAccountHandle phoneAccountHandle, Uri uri) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8268 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8269 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 8270 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 8271 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8272 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8273 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 8274 | "setVoicemailRingtoneUri"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8275 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8276 | |
| 8277 | final long identity = Binder.clearCallingIdentity(); |
| 8278 | try { |
| 8279 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 8280 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8281 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8282 | } |
| 8283 | VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri); |
| 8284 | } finally { |
| 8285 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8286 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8287 | } |
| 8288 | |
| 8289 | /** |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8290 | * Returns whether vibration is set for voicemail notification in Phone settings. |
| 8291 | * |
| 8292 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 8293 | * voicemail vibration setting. |
| 8294 | * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise. |
| 8295 | */ |
| 8296 | @Override |
| 8297 | public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8298 | final long identity = Binder.clearCallingIdentity(); |
| 8299 | try { |
| 8300 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 8301 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8302 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8303 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8304 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8305 | return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext()); |
| 8306 | } finally { |
| 8307 | Binder.restoreCallingIdentity(identity); |
| 8308 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8309 | } |
| 8310 | |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8311 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8312 | * Sets the per-account voicemail vibration. |
| 8313 | * |
| 8314 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 8315 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 8316 | * |
| 8317 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 8318 | * voicemail vibration setting. |
| 8319 | * @param enabled Whether to enable or disable vibration for voicemail notifications from a |
| 8320 | * specific PhoneAccount. |
| 8321 | */ |
| 8322 | @Override |
| 8323 | public void setVoicemailVibrationEnabled(String callingPackage, |
| 8324 | PhoneAccountHandle phoneAccountHandle, boolean enabled) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8325 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8326 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 8327 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 8328 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8329 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8330 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 8331 | "setVoicemailVibrationEnabled"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8332 | } |
| 8333 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8334 | final long identity = Binder.clearCallingIdentity(); |
| 8335 | try { |
| 8336 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 8337 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8338 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8339 | } |
| 8340 | VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled); |
| 8341 | } finally { |
| 8342 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8343 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8344 | } |
| 8345 | |
| 8346 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8347 | * Make sure either called from same process as self (phone) or IPC caller has read privilege. |
| 8348 | * |
| 8349 | * @throws SecurityException if the caller does not have the required permission |
| 8350 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8351 | private void enforceReadPrivilegedPermission(String message) { |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8352 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8353 | message); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8354 | } |
| 8355 | |
| 8356 | /** |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 8357 | * Make sure either called from same process as self (phone) or IPC caller has send SMS |
| 8358 | * permission. |
| 8359 | * |
| 8360 | * @throws SecurityException if the caller does not have the required permission |
| 8361 | */ |
| 8362 | private void enforceSendSmsPermission() { |
| 8363 | mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null); |
| 8364 | } |
| 8365 | |
| 8366 | /** |
Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame] | 8367 | * Make sure either called from same process as self (phone) or IPC caller has interact across |
| 8368 | * users permission. |
| 8369 | * |
| 8370 | * @throws SecurityException if the caller does not have the required permission |
| 8371 | */ |
| 8372 | private void enforceInteractAcrossUsersPermission(String message) { |
| 8373 | mApp.enforceCallingOrSelfPermission(permission.INTERACT_ACROSS_USERS, message); |
| 8374 | } |
| 8375 | |
| 8376 | /** |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 8377 | * Make sure called from the package in charge of visual voicemail. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 8378 | * |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 8379 | * @throws SecurityException if the caller is not the visual voicemail package. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 8380 | */ |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 8381 | private void enforceVisualVoicemailPackage(String callingPackage, int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8382 | final long identity = Binder.clearCallingIdentity(); |
| 8383 | try { |
| 8384 | ComponentName componentName = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8385 | RemoteVvmTaskManager.getRemotePackage(mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8386 | if (componentName == null) { |
| 8387 | throw new SecurityException( |
| 8388 | "Caller not current active visual voicemail package[null]"); |
| 8389 | } |
| 8390 | String vvmPackage = componentName.getPackageName(); |
| 8391 | if (!callingPackage.equals(vvmPackage)) { |
Hui Wang | 7f65755 | 2022-08-16 16:58:25 +0000 | [diff] [blame] | 8392 | throw new SecurityException("Caller not current active visual voicemail package"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8393 | } |
| 8394 | } finally { |
| 8395 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 8396 | } |
| 8397 | } |
| 8398 | |
| 8399 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8400 | * Return the application ID for the app type. |
| 8401 | * |
| 8402 | * @param subId the subscription ID that this request applies to. |
| 8403 | * @param appType the uicc app type. |
| 8404 | * @return Application ID for specificied app type, or null if no uicc. |
| 8405 | */ |
| 8406 | @Override |
| 8407 | public String getAidForAppType(int subId, int appType) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8408 | enforceReadPrivilegedPermission("getAidForAppType"); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8409 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8410 | |
| 8411 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8412 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8413 | if (phone == null) { |
| 8414 | return null; |
| 8415 | } |
| 8416 | String aid = null; |
| 8417 | try { |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 8418 | aid = UiccController.getInstance().getUiccPort(phone.getPhoneId()) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8419 | .getApplicationByType(appType).getAid(); |
| 8420 | } catch (Exception e) { |
| 8421 | Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e); |
| 8422 | } |
| 8423 | return aid; |
| 8424 | } finally { |
| 8425 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8426 | } |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8427 | } |
| 8428 | |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8429 | /** |
| 8430 | * Return the Electronic Serial Number. |
| 8431 | * |
| 8432 | * @param subId the subscription ID that this request applies to. |
| 8433 | * @return ESN or null if error. |
| 8434 | */ |
| 8435 | @Override |
| 8436 | public String getEsn(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8437 | enforceReadPrivilegedPermission("getEsn"); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8438 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8439 | |
| 8440 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8441 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8442 | if (phone == null) { |
| 8443 | return null; |
| 8444 | } |
| 8445 | String esn = null; |
| 8446 | try { |
| 8447 | esn = phone.getEsn(); |
| 8448 | } catch (Exception e) { |
| 8449 | Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e); |
| 8450 | } |
| 8451 | return esn; |
| 8452 | } finally { |
| 8453 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8454 | } |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8455 | } |
| 8456 | |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 8457 | /** |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8458 | * Return the Preferred Roaming List Version. |
| 8459 | * |
| 8460 | * @param subId the subscription ID that this request applies to. |
| 8461 | * @return PRLVersion or null if error. |
| 8462 | */ |
| 8463 | @Override |
| 8464 | public String getCdmaPrlVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8465 | enforceReadPrivilegedPermission("getCdmaPrlVersion"); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8466 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8467 | |
| 8468 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8469 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8470 | if (phone == null) { |
| 8471 | return null; |
| 8472 | } |
| 8473 | String cdmaPrlVersion = null; |
| 8474 | try { |
| 8475 | cdmaPrlVersion = phone.getCdmaPrlVersion(); |
| 8476 | } catch (Exception e) { |
| 8477 | Log.e(LOG_TAG, "Not getting PRLVersion", e); |
| 8478 | } |
| 8479 | return cdmaPrlVersion; |
| 8480 | } finally { |
| 8481 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8482 | } |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8483 | } |
| 8484 | |
| 8485 | /** |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 8486 | * Get snapshot of Telephony histograms |
| 8487 | * @return List of Telephony histograms |
| 8488 | * @hide |
| 8489 | */ |
| 8490 | @Override |
| 8491 | public List<TelephonyHistogram> getTelephonyHistograms() { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8492 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8493 | mApp, getDefaultSubscription(), "getTelephonyHistograms"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8494 | |
| 8495 | final long identity = Binder.clearCallingIdentity(); |
| 8496 | try { |
| 8497 | return RIL.getTelephonyRILTimingHistograms(); |
| 8498 | } finally { |
| 8499 | Binder.restoreCallingIdentity(identity); |
| 8500 | } |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 8501 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8502 | |
| 8503 | /** |
| 8504 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8505 | * Set the allowed carrier list and the excluded carrier list, indicating the priority between |
| 8506 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8507 | * Require system privileges. In the future we may add this to carrier APIs. |
| 8508 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8509 | * @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] | 8510 | */ |
| 8511 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8512 | @TelephonyManager.SetCarrierRestrictionResult |
| 8513 | public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) { |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8514 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8515 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8516 | |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8517 | if (carrierRestrictionRules == null) { |
| 8518 | throw new NullPointerException("carrier restriction cannot be null"); |
Meng Wang | 9b7c4e9 | 2017-02-17 11:41:27 -0800 | [diff] [blame] | 8519 | } |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8520 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8521 | final long identity = Binder.clearCallingIdentity(); |
| 8522 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8523 | return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8524 | workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8525 | } finally { |
| 8526 | Binder.restoreCallingIdentity(identity); |
| 8527 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8528 | } |
| 8529 | |
| 8530 | /** |
| 8531 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8532 | * Get the allowed carrier list and the excluded carrier list, including the priority between |
| 8533 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8534 | * Require system privileges. In the future we may add this to carrier APIs. |
| 8535 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8536 | * @return {@link android.telephony.CarrierRestrictionRules} |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8537 | */ |
| 8538 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8539 | public CarrierRestrictionRules getAllowedCarriers() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8540 | enforceReadPrivilegedPermission("getAllowedCarriers"); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8541 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8542 | |
| 8543 | final long identity = Binder.clearCallingIdentity(); |
| 8544 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8545 | Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource); |
| 8546 | if (response instanceof CarrierRestrictionRules) { |
| 8547 | return (CarrierRestrictionRules) response; |
| 8548 | } |
| 8549 | // Response is an Exception of some kind, |
| 8550 | // which is signalled to the user as a NULL retval |
| 8551 | return null; |
| 8552 | } catch (Exception e) { |
| 8553 | Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e); |
| 8554 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8555 | } finally { |
| 8556 | Binder.restoreCallingIdentity(identity); |
| 8557 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8558 | } |
| 8559 | |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 8560 | /** |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 8561 | * Action set from carrier signalling broadcast receivers to enable/disable radio |
| 8562 | * @param subId the subscription ID that this action applies to. |
| 8563 | * @param enabled control enable or disable radio. |
| 8564 | * {@hide} |
| 8565 | */ |
| 8566 | @Override |
| 8567 | public void carrierActionSetRadioEnabled(int subId, boolean enabled) { |
| 8568 | enforceModifyPermission(); |
| 8569 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8570 | |
| 8571 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 8572 | if (phone == null) { |
| 8573 | loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId); |
| 8574 | return; |
| 8575 | } |
| 8576 | try { |
| 8577 | phone.carrierActionSetRadioEnabled(enabled); |
| 8578 | } catch (Exception e) { |
| 8579 | Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8580 | } finally { |
| 8581 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 8582 | } |
| 8583 | } |
| 8584 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 8585 | /** |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 8586 | * Enable or disable Voice over NR (VoNR) |
| 8587 | * @param subId the subscription ID that this action applies to. |
| 8588 | * @param enabled enable or disable VoNR. |
| 8589 | * @return operation result. |
| 8590 | */ |
| 8591 | @Override |
| 8592 | public int setVoNrEnabled(int subId, boolean enabled) { |
| 8593 | enforceModifyPermission(); |
| 8594 | final Phone phone = getPhone(subId); |
| 8595 | |
| 8596 | final long identity = Binder.clearCallingIdentity(); |
| 8597 | if (phone == null) { |
| 8598 | loge("setVoNrEnabled fails with no phone object for subId: " + subId); |
| 8599 | return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE; |
| 8600 | } |
| 8601 | |
| 8602 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8603 | try { |
| 8604 | int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId, |
| 8605 | workSource); |
| 8606 | if (DBG) log("setVoNrEnabled result: " + result); |
Gary Jian | 8dd305f | 2021-10-14 16:31:35 +0800 | [diff] [blame] | 8607 | |
| 8608 | if (result == TelephonyManager.ENABLE_VONR_SUCCESS) { |
| 8609 | if (DBG) { |
| 8610 | log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled); |
| 8611 | } |
| 8612 | SubscriptionManager.setSubscriptionProperty( |
| 8613 | subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED, |
| 8614 | (enabled ? "1" : "0")); |
| 8615 | } |
| 8616 | |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 8617 | return result; |
| 8618 | } finally { |
| 8619 | Binder.restoreCallingIdentity(identity); |
| 8620 | } |
| 8621 | } |
| 8622 | |
| 8623 | /** |
| 8624 | * Is voice over NR enabled |
| 8625 | * @return true if VoNR is enabled else false |
| 8626 | */ |
| 8627 | @Override |
| 8628 | public boolean isVoNrEnabled(int subId) { |
| 8629 | enforceReadPrivilegedPermission("isVoNrEnabled"); |
| 8630 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8631 | final long identity = Binder.clearCallingIdentity(); |
| 8632 | try { |
| 8633 | boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED, |
| 8634 | null, subId, workSource); |
| 8635 | if (DBG) log("isVoNrEnabled: " + isEnabled); |
| 8636 | return isEnabled; |
| 8637 | } finally { |
| 8638 | Binder.restoreCallingIdentity(identity); |
| 8639 | } |
| 8640 | } |
| 8641 | |
| 8642 | /** |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 8643 | * Action set from carrier signalling broadcast receivers to start/stop reporting the default |
| 8644 | * network status based on which carrier apps could apply actions accordingly, |
| 8645 | * enable/disable default url handler for example. |
| 8646 | * |
| 8647 | * @param subId the subscription ID that this action applies to. |
| 8648 | * @param report control start/stop reporting the default network status. |
| 8649 | * {@hide} |
| 8650 | */ |
| 8651 | @Override |
| 8652 | public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) { |
| 8653 | enforceModifyPermission(); |
| 8654 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8655 | |
| 8656 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 8657 | if (phone == null) { |
| 8658 | loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId); |
| 8659 | return; |
| 8660 | } |
| 8661 | try { |
| 8662 | phone.carrierActionReportDefaultNetworkStatus(report); |
| 8663 | } catch (Exception e) { |
| 8664 | Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8665 | } finally { |
| 8666 | Binder.restoreCallingIdentity(identity); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 8667 | } |
| 8668 | } |
| 8669 | |
| 8670 | /** |
fionaxu | d962228 | 2017-07-17 17:51:30 -0700 | [diff] [blame] | 8671 | * Action set from carrier signalling broadcast receivers to reset all carrier actions |
| 8672 | * @param subId the subscription ID that this action applies to. |
| 8673 | * {@hide} |
| 8674 | */ |
| 8675 | @Override |
| 8676 | public void carrierActionResetAll(int subId) { |
| 8677 | enforceModifyPermission(); |
| 8678 | final Phone phone = getPhone(subId); |
| 8679 | if (phone == null) { |
| 8680 | loge("carrierAction: ResetAll fails with invalid sibId: " + subId); |
| 8681 | return; |
| 8682 | } |
| 8683 | try { |
| 8684 | phone.carrierActionResetAll(); |
| 8685 | } catch (Exception e) { |
| 8686 | Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e); |
| 8687 | } |
| 8688 | } |
| 8689 | |
| 8690 | /** |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 8691 | * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a |
| 8692 | * bug report is being generated. |
| 8693 | */ |
| 8694 | @Override |
Ta-wei Yen | 99282e0 | 2016-06-21 18:19:35 -0700 | [diff] [blame] | 8695 | protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8696 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 8697 | != PackageManager.PERMISSION_GRANTED) { |
dcashman | 22b950d | 2016-06-27 11:39:02 -0700 | [diff] [blame] | 8698 | writer.println("Permission Denial: can't dump Phone from pid=" |
| 8699 | + Binder.getCallingPid() |
| 8700 | + ", uid=" + Binder.getCallingUid() |
| 8701 | + "without permission " |
| 8702 | + android.Manifest.permission.DUMP); |
| 8703 | return; |
| 8704 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8705 | DumpsysHandler.dump(mApp, fd, writer, args); |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 8706 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 8707 | |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 8708 | @Override |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 8709 | public int handleShellCommand(@NonNull ParcelFileDescriptor in, |
| 8710 | @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err, |
| 8711 | @NonNull String[] args) { |
| 8712 | return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec( |
| 8713 | this, in.getFileDescriptor(), out.getFileDescriptor(), |
| 8714 | err.getFileDescriptor(), args); |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 8715 | } |
| 8716 | |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 8717 | /** |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8718 | * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason} |
Greg Kaiser | 17f4175 | 2020-05-05 16:47:47 +0000 | [diff] [blame] | 8719 | * @param subId Subscription index |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 8720 | * @param reason The reason the data enable change is taking place. |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8721 | * @param enabled True if enabling the data, otherwise disabling. |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 8722 | * @param callingPackage The package that changed the data enabled state. |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8723 | * @hide |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 8724 | */ |
| 8725 | @Override |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 8726 | public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 8727 | boolean enabled, String callingPackage) { |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8728 | if (reason == TelephonyManager.DATA_ENABLED_REASON_USER |
| 8729 | || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 8730 | try { |
| 8731 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 8732 | mApp, subId, "setDataEnabledForReason"); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8733 | } catch (SecurityException se) { |
| 8734 | enforceModifyPermission(); |
| 8735 | } |
| 8736 | } else { |
| 8737 | enforceModifyPermission(); |
| 8738 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8739 | |
| 8740 | final long identity = Binder.clearCallingIdentity(); |
| 8741 | try { |
| 8742 | Phone phone = getPhone(subId); |
| 8743 | if (phone != null) { |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8744 | if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 8745 | phone.carrierActionSetMeteredApnsEnabled(enabled); |
| 8746 | } else { |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 8747 | phone.getDataSettingsManager().setDataEnabled( |
| 8748 | reason, enabled, callingPackage); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8749 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8750 | } |
| 8751 | } finally { |
| 8752 | Binder.restoreCallingIdentity(identity); |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 8753 | } |
| 8754 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8755 | |
| 8756 | /** |
| 8757 | * Get Client request stats |
| 8758 | * @return List of Client Request Stats |
| 8759 | * @hide |
| 8760 | */ |
| 8761 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8762 | public List<ClientRequestStats> getClientRequestStats(String callingPackage, |
| 8763 | String callingFeatureId, int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8764 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8765 | mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) { |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8766 | return null; |
| 8767 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8768 | Phone phone = getPhone(subId); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8769 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8770 | final long identity = Binder.clearCallingIdentity(); |
| 8771 | try { |
| 8772 | if (phone != null) { |
| 8773 | return phone.getClientRequestStats(); |
| 8774 | } |
| 8775 | |
| 8776 | return null; |
| 8777 | } finally { |
| 8778 | Binder.restoreCallingIdentity(identity); |
| 8779 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8780 | } |
| 8781 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 8782 | private WorkSource getWorkSource(int uid) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8783 | String packageName = mApp.getPackageManager().getNameForUid(uid); |
Hunter Knepshield | d03383b | 2022-03-29 22:47:54 +0000 | [diff] [blame] | 8784 | if (uid == Process.ROOT_UID && packageName == null) { |
| 8785 | // Downstream WorkSource attribution inside the RIL requires both a UID and package name |
| 8786 | // to be set for wakelock tracking, otherwise RIL requests fail with a runtime |
| 8787 | // exception. ROOT_UID seems not to have a valid package name returned by |
| 8788 | // PackageManager, so just fake it here to avoid issues when running telephony shell |
| 8789 | // commands that plumb through the RIL as root, like so: |
| 8790 | // $ adb root |
| 8791 | // $ adb shell cmd phone ... |
| 8792 | packageName = "root"; |
| 8793 | } |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 8794 | return new WorkSource(uid, packageName); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8795 | } |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8796 | |
| 8797 | /** |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 8798 | * Set SIM card power state. |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8799 | * |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8800 | * @param slotIndex SIM slot id. |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 8801 | * @param state State of SIM (power down, power up, pass through) |
| 8802 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 8803 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 8804 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8805 | * |
| 8806 | **/ |
| 8807 | @Override |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 8808 | public void setSimPowerStateForSlot(int slotIndex, int state) { |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8809 | enforceModifyPermission(); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8810 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8811 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8812 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8813 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8814 | final long identity = Binder.clearCallingIdentity(); |
| 8815 | try { |
| 8816 | if (phone != null) { |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 8817 | phone.setSimPowerState(state, null, workSource); |
| 8818 | } |
| 8819 | } finally { |
| 8820 | Binder.restoreCallingIdentity(identity); |
| 8821 | } |
| 8822 | } |
| 8823 | |
| 8824 | /** |
| 8825 | * Set SIM card power state. |
| 8826 | * |
| 8827 | * @param slotIndex SIM slot id. |
| 8828 | * @param state State of SIM (power down, power up, pass through) |
| 8829 | * @param callback callback to trigger after success or failure |
| 8830 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 8831 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 8832 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
| 8833 | * |
| 8834 | **/ |
| 8835 | @Override |
| 8836 | public void setSimPowerStateForSlotWithCallback(int slotIndex, int state, |
| 8837 | IIntegerConsumer callback) { |
| 8838 | enforceModifyPermission(); |
| 8839 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8840 | |
| 8841 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8842 | |
| 8843 | final long identity = Binder.clearCallingIdentity(); |
| 8844 | try { |
| 8845 | if (phone != null) { |
| 8846 | Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback); |
| 8847 | sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8848 | } |
| 8849 | } finally { |
| 8850 | Binder.restoreCallingIdentity(identity); |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8851 | } |
| 8852 | } |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8853 | |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 8854 | private boolean isUssdApiAllowed(int subId) { |
| 8855 | CarrierConfigManager configManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8856 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 8857 | if (configManager == null) { |
| 8858 | return false; |
| 8859 | } |
| 8860 | PersistableBundle pb = configManager.getConfigForSubId(subId); |
| 8861 | if (pb == null) { |
| 8862 | return false; |
| 8863 | } |
| 8864 | return pb.getBoolean( |
| 8865 | CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL); |
| 8866 | } |
| 8867 | |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8868 | /** |
| 8869 | * Check if phone is in emergency callback mode |
| 8870 | * @return true if phone is in emergency callback mode |
| 8871 | * @param subId sub id |
| 8872 | */ |
goneil | 9c5f487 | 2017-12-05 14:07:56 -0800 | [diff] [blame] | 8873 | @Override |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8874 | public boolean getEmergencyCallbackMode(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8875 | enforceReadPrivilegedPermission("getEmergencyCallbackMode"); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8876 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8877 | |
| 8878 | final long identity = Binder.clearCallingIdentity(); |
| 8879 | try { |
| 8880 | if (phone != null) { |
| 8881 | return phone.isInEcm(); |
| 8882 | } else { |
| 8883 | return false; |
| 8884 | } |
| 8885 | } finally { |
| 8886 | Binder.restoreCallingIdentity(identity); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8887 | } |
| 8888 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 8889 | |
| 8890 | /** |
| 8891 | * Get the current signal strength information for the given subscription. |
| 8892 | * Because this information is not updated when the device is in a low power state |
| 8893 | * it should not be relied-upon to be current. |
| 8894 | * @param subId Subscription index |
| 8895 | * @return the most recent cached signal strength info from the modem |
| 8896 | */ |
| 8897 | @Override |
| 8898 | public SignalStrength getSignalStrength(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8899 | final long identity = Binder.clearCallingIdentity(); |
| 8900 | try { |
| 8901 | Phone p = getPhone(subId); |
| 8902 | if (p == null) { |
| 8903 | return null; |
| 8904 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 8905 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8906 | return p.getSignalStrength(); |
| 8907 | } finally { |
| 8908 | Binder.restoreCallingIdentity(identity); |
| 8909 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 8910 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8911 | |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8912 | /** |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8913 | * Get the current modem radio state for the given slot. |
| 8914 | * @param slotIndex slot index. |
| 8915 | * @param callingPackage the name of the package making the call. |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8916 | * @param callingFeatureId The feature in the package. |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8917 | * @return the current radio power state from the modem |
| 8918 | */ |
| 8919 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8920 | public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8921 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8922 | if (phone != null) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8923 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(), |
| 8924 | callingPackage, callingFeatureId, "getRadioPowerState")) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8925 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 8926 | } |
| 8927 | |
| 8928 | final long identity = Binder.clearCallingIdentity(); |
| 8929 | try { |
| 8930 | return phone.getRadioPowerState(); |
| 8931 | } finally { |
| 8932 | Binder.restoreCallingIdentity(identity); |
| 8933 | } |
| 8934 | } |
| 8935 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 8936 | } |
| 8937 | |
| 8938 | /** |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8939 | * Checks if data roaming is enabled on the subscription with id {@code subId}. |
| 8940 | * |
| 8941 | * <p>Requires one of the following permissions: |
| 8942 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}, |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 8943 | * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE}, |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8944 | * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier |
| 8945 | * privileges. |
| 8946 | * |
| 8947 | * @param subId subscription id |
| 8948 | * @return {@code true} if data roaming is enabled on this subscription, otherwise return |
| 8949 | * {@code false}. |
| 8950 | */ |
| 8951 | @Override |
| 8952 | public boolean isDataRoamingEnabled(int subId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 8953 | String functionName = "isDataRoamingEnabled"; |
Shuo Qian | 093013d | 2020-08-13 15:42:55 -0700 | [diff] [blame] | 8954 | try { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 8955 | try { |
| 8956 | mApp.enforceCallingOrSelfPermission( |
| 8957 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 8958 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 8959 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 8960 | mApp.enforceCallingOrSelfPermission( |
| 8961 | permission.READ_BASIC_PHONE_STATE, functionName); |
| 8962 | } |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 8963 | } catch (SecurityException e) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 8964 | TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 8965 | mApp, subId, functionName); |
Shuo Qian | 093013d | 2020-08-13 15:42:55 -0700 | [diff] [blame] | 8966 | } |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 8967 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8968 | boolean isEnabled = false; |
| 8969 | final long identity = Binder.clearCallingIdentity(); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8970 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8971 | Phone phone = getPhone(subId); |
| 8972 | isEnabled = phone != null ? phone.getDataRoamingEnabled() : false; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8973 | } finally { |
| 8974 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8975 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8976 | return isEnabled; |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8977 | } |
| 8978 | |
| 8979 | |
| 8980 | /** |
| 8981 | * Enables/Disables the data roaming on the subscription with id {@code subId}. |
| 8982 | * |
| 8983 | * <p> Requires permission: |
| 8984 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier |
| 8985 | * privileges. |
| 8986 | * |
| 8987 | * @param subId subscription id |
| 8988 | * @param isEnabled {@code true} means enable, {@code false} means disable. |
| 8989 | */ |
| 8990 | @Override |
| 8991 | public void setDataRoamingEnabled(int subId, boolean isEnabled) { |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 8992 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8993 | mApp, subId, "setDataRoamingEnabled"); |
| 8994 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8995 | final long identity = Binder.clearCallingIdentity(); |
| 8996 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8997 | Phone phone = getPhone(subId); |
| 8998 | if (phone != null) { |
| 8999 | phone.setDataRoamingEnabled(isEnabled); |
| 9000 | } |
| 9001 | } finally { |
| 9002 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9003 | } |
| 9004 | } |
| 9005 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9006 | @Override |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 9007 | public boolean isManualNetworkSelectionAllowed(int subId) { |
tom hsu | c91afc7 | 2020-01-06 23:46:07 +0800 | [diff] [blame] | 9008 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9009 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 9010 | mApp, subId, "isManualNetworkSelectionAllowed"); |
| 9011 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 9012 | boolean isAllowed = true; |
| 9013 | final long identity = Binder.clearCallingIdentity(); |
| 9014 | try { |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 9015 | Phone phone = getPhone(subId); |
| 9016 | if (phone != null) { |
| 9017 | isAllowed = phone.isCspPlmnEnabled(); |
| 9018 | } |
| 9019 | } finally { |
| 9020 | Binder.restoreCallingIdentity(identity); |
| 9021 | } |
| 9022 | return isAllowed; |
| 9023 | } |
| 9024 | |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9025 | private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) { |
| 9026 | UiccProfile profile = port.getUiccProfile(); |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 9027 | if (profile == null) { |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9028 | return false; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9029 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 9030 | Phone phone = PhoneFactory.getPhone(profile.getPhoneId()); |
| 9031 | if (phone == null) { |
| 9032 | return false; |
| 9033 | } |
| 9034 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 9035 | return cpt != null && cpt.getCarrierPrivilegeStatusForPackage(callingPackage) |
| 9036 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9037 | } |
| 9038 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 9039 | @Override |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 9040 | public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) { |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9041 | // Verify that the callingPackage belongs to the calling UID |
Jordan Liu | 4cda455 | 2020-03-23 11:55:07 -0700 | [diff] [blame] | 9042 | mApp.getSystemService(AppOpsManager.class) |
| 9043 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 9044 | |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9045 | boolean hasReadPermission = false; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9046 | boolean isIccIdAccessRestricted = false; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 9047 | try { |
| 9048 | enforceReadPrivilegedPermission("getUiccCardsInfo"); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9049 | hasReadPermission = true; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 9050 | } catch (SecurityException e) { |
| 9051 | // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller |
| 9052 | // has carrier privileges on an active UICC |
Rambo Wang | e7209ce | 2022-02-23 13:41:02 -0800 | [diff] [blame] | 9053 | if (checkCarrierPrivilegesForPackageAnyPhoneWithPermission(callingPackage) |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 9054 | != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9055 | throw new SecurityException("Caller does not have permission."); |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 9056 | } |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 9057 | } |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9058 | // checking compatibility, if calling app's target SDK is T and beyond. |
| 9059 | if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO, |
| 9060 | Binder.getCallingUid())) { |
| 9061 | isIccIdAccessRestricted = true; |
| 9062 | } |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 9063 | final long identity = Binder.clearCallingIdentity(); |
| 9064 | try { |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 9065 | UiccController uiccController = UiccController.getInstance(); |
| 9066 | ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos(); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9067 | if (hasReadPermission) { |
| 9068 | return cardInfos; |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 9069 | } |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9070 | |
| 9071 | // Remove private info if the caller doesn't have access |
| 9072 | ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>(); |
| 9073 | for (UiccCardInfo cardInfo : cardInfos) { |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9074 | //setting the value after compatibility check |
| 9075 | cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9076 | // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo |
| 9077 | // is available |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9078 | UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex()); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9079 | if (card == null) { |
| 9080 | // assume no access if the card is unavailable |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9081 | filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo)); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9082 | continue; |
| 9083 | } |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9084 | Collection<UiccPortInfo> portInfos = cardInfo.getPorts(); |
| 9085 | if (portInfos.isEmpty()) { |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9086 | filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo)); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9087 | continue; |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9088 | } |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9089 | List<UiccPortInfo> uiccPortInfos = new ArrayList<>(); |
| 9090 | for (UiccPortInfo portInfo : portInfos) { |
| 9091 | UiccPort port = uiccController.getUiccPortForSlot( |
| 9092 | cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex()); |
| 9093 | if (port == null) { |
| 9094 | // assume no access if port is null |
| 9095 | uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo)); |
| 9096 | continue; |
| 9097 | } |
| 9098 | if (haveCarrierPrivilegeAccess(port, callingPackage)) { |
| 9099 | uiccPortInfos.add(portInfo); |
| 9100 | } else { |
| 9101 | uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo)); |
| 9102 | } |
| 9103 | } |
| 9104 | filteredInfos.add(new UiccCardInfo( |
| 9105 | cardInfo.isEuicc(), |
| 9106 | cardInfo.getCardId(), |
| 9107 | null, |
| 9108 | cardInfo.getPhysicalSlotIndex(), |
| 9109 | cardInfo.isRemovable(), |
| 9110 | cardInfo.isMultipleEnabledProfilesSupported(), |
| 9111 | uiccPortInfos)); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9112 | } |
| 9113 | return filteredInfos; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 9114 | } finally { |
| 9115 | Binder.restoreCallingIdentity(identity); |
| 9116 | } |
| 9117 | } |
| 9118 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9119 | /** |
| 9120 | * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are |
| 9121 | * generally private and require carrier privileges to view. |
| 9122 | * |
| 9123 | * @hide |
| 9124 | */ |
| 9125 | @NonNull |
| 9126 | public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) { |
| 9127 | List<UiccPortInfo> portinfo = new ArrayList<>(); |
| 9128 | for (UiccPortInfo portinfos : cardInfo.getPorts()) { |
| 9129 | portinfo.add(getUiccPortInfoUnPrivileged(portinfos)); |
| 9130 | } |
| 9131 | return new UiccCardInfo( |
| 9132 | cardInfo.isEuicc(), |
| 9133 | cardInfo.getCardId(), |
| 9134 | null, |
| 9135 | cardInfo.getPhysicalSlotIndex(), |
| 9136 | cardInfo.isRemovable(), |
| 9137 | cardInfo.isMultipleEnabledProfilesSupported(), |
| 9138 | portinfo |
| 9139 | ); |
| 9140 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9141 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9142 | /** |
| 9143 | * @hide |
| 9144 | * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}. |
| 9145 | * These values are generally private and require carrier privileges to view. |
| 9146 | */ |
| 9147 | @NonNull |
| 9148 | public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) { |
| 9149 | return new UiccPortInfo( |
| 9150 | UiccPortInfo.ICCID_REDACTED, |
| 9151 | portInfo.getPortIndex(), |
| 9152 | portInfo.getLogicalSlotIndex(), |
| 9153 | portInfo.isActive() |
| 9154 | ); |
| 9155 | } |
| 9156 | @Override |
| 9157 | public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) { |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9158 | // Verify that the callingPackage belongs to the calling UID |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9159 | mApp.getSystemService(AppOpsManager.class) |
| 9160 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 9161 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9162 | boolean isLogicalSlotAccessRestricted = false; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9163 | |
Aman Gupta | f3c90b3 | 2022-03-17 04:54:16 +0000 | [diff] [blame] | 9164 | // This will make sure caller has the READ_PRIVILEGED_PHONE_STATE. Do not remove this as |
| 9165 | // we are reading iccId which is PII data. |
| 9166 | enforceReadPrivilegedPermission("getUiccSlotsInfo"); |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9167 | |
| 9168 | // checking compatibility, if calling app's target SDK is T and beyond. |
| 9169 | if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO, |
| 9170 | Binder.getCallingUid())) { |
| 9171 | isLogicalSlotAccessRestricted = true; |
| 9172 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9173 | final long identity = Binder.clearCallingIdentity(); |
| 9174 | try { |
| 9175 | UiccSlot[] slots = UiccController.getInstance().getUiccSlots(); |
Muralidhar Reddy | d196bbf | 2022-01-17 17:56:30 +0000 | [diff] [blame] | 9176 | if (slots == null || slots.length == 0) { |
| 9177 | Rlog.i(LOG_TAG, "slots is null or empty."); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9178 | return null; |
| 9179 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9180 | UiccSlotInfo[] infos = new UiccSlotInfo[slots.length]; |
| 9181 | for (int i = 0; i < slots.length; i++) { |
| 9182 | UiccSlot slot = slots[i]; |
| 9183 | if (slot == null) { |
| 9184 | continue; |
| 9185 | } |
| 9186 | |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 9187 | String cardId; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9188 | UiccCard card = slot.getUiccCard(); |
| 9189 | if (card != null) { |
| 9190 | cardId = card.getCardId(); |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 9191 | } else { |
Jordan Liu | 01bd00d | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 9192 | cardId = slot.getEid(); |
| 9193 | if (TextUtils.isEmpty(cardId)) { |
Aman Gupta | f3c90b3 | 2022-03-17 04:54:16 +0000 | [diff] [blame] | 9194 | // If cardId is null, use iccId of default port as cardId. |
| 9195 | cardId = slot.getIccId(TelephonyManager.DEFAULT_PORT_INDEX); |
Jordan Liu | 01bd00d | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 9196 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9197 | } |
| 9198 | |
Jordan Liu | 857451f | 2019-05-09 16:35:35 -0700 | [diff] [blame] | 9199 | if (cardId != null) { |
| 9200 | // if cardId is an ICCID, strip off trailing Fs before exposing to user |
| 9201 | // if cardId is an EID, it's all digits so this is fine |
| 9202 | cardId = IccUtils.stripTrailingFs(cardId); |
| 9203 | } |
| 9204 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9205 | int cardState = 0; |
| 9206 | switch (slot.getCardState()) { |
| 9207 | case CARDSTATE_ABSENT: |
| 9208 | cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT; |
| 9209 | break; |
| 9210 | case CARDSTATE_PRESENT: |
| 9211 | cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT; |
| 9212 | break; |
| 9213 | case CARDSTATE_ERROR: |
| 9214 | cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR; |
| 9215 | break; |
| 9216 | case CARDSTATE_RESTRICTED: |
| 9217 | cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED; |
| 9218 | break; |
| 9219 | default: |
| 9220 | break; |
| 9221 | |
| 9222 | } |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9223 | List<UiccPortInfo> portInfos = new ArrayList<>(); |
| 9224 | int[] portIndexes = slot.getPortList(); |
| 9225 | for (int portIdx : portIndexes) { |
| 9226 | String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx, |
Aman Gupta | f3c90b3 | 2022-03-17 04:54:16 +0000 | [diff] [blame] | 9227 | callingPackage, /* hasReadPermission= */ true)); |
Muralidhar Reddy | fbcff0c | 2022-01-19 13:07:57 +0000 | [diff] [blame] | 9228 | portInfos.add(new UiccPortInfo(iccId, portIdx, |
| 9229 | slot.getPhoneIdFromPortIndex(portIdx), slot.isPortActive(portIdx))); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9230 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9231 | infos[i] = new UiccSlotInfo( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9232 | slot.isEuicc(), |
| 9233 | cardId, |
| 9234 | cardState, |
Jordan Liu | a261958 | 2019-02-14 12:56:40 -0800 | [diff] [blame] | 9235 | slot.isExtendedApduSupported(), |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9236 | slot.isRemovable(), portInfos); |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9237 | //setting the value after compatibility check |
| 9238 | infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9239 | } |
| 9240 | return infos; |
| 9241 | } finally { |
| 9242 | Binder.restoreCallingIdentity(identity); |
Holly Jiuyu Sun | 1d957c5 | 2018-04-04 13:52:42 -0700 | [diff] [blame] | 9243 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9244 | } |
| 9245 | |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9246 | /* Returns null if doesn't have read permission or carrier privilege access. */ |
| 9247 | private String getIccId(UiccSlot slot, int portIndex, String callingPackage, |
| 9248 | boolean hasReadPermission) { |
| 9249 | String iccId = slot.getIccId(portIndex); |
| 9250 | if (hasReadPermission) { // if has read permission |
| 9251 | return iccId; |
| 9252 | } else { |
| 9253 | if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) { |
| 9254 | UiccPort port = slot.getUiccCard().getUiccPort(portIndex); |
| 9255 | // if no read permission, checking carrier privilege access |
| 9256 | if (haveCarrierPrivilegeAccess(port, callingPackage)) { |
| 9257 | return iccId; |
| 9258 | } |
| 9259 | } |
| 9260 | } |
| 9261 | // No read permission or carrier privilege access. |
| 9262 | return UiccPortInfo.ICCID_REDACTED; |
| 9263 | } |
| 9264 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9265 | @Override |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9266 | @Deprecated |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9267 | public boolean switchSlots(int[] physicalSlots) { |
| 9268 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9269 | |
| 9270 | final long identity = Binder.clearCallingIdentity(); |
| 9271 | try { |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9272 | List<UiccSlotMapping> slotMappings = new ArrayList<>(); |
| 9273 | for (int i = 0; i < physicalSlots.length; i++) { |
| 9274 | // Deprecated API, hence MEP is not supported. Adding default portIndex 0. |
| 9275 | slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX, |
| 9276 | physicalSlots[i], i)); |
| 9277 | } |
| 9278 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9279 | } finally { |
| 9280 | Binder.restoreCallingIdentity(identity); |
| 9281 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9282 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 9283 | |
| 9284 | @Override |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9285 | @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 9286 | public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) { |
| 9287 | enforceModifyPermission(); |
| 9288 | |
| 9289 | final long identity = Binder.clearCallingIdentity(); |
| 9290 | try { |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9291 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping); |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9292 | } finally { |
| 9293 | Binder.restoreCallingIdentity(identity); |
| 9294 | } |
| 9295 | } |
| 9296 | |
| 9297 | @Override |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 9298 | public int getCardIdForDefaultEuicc(int subId, String callingPackage) { |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 9299 | final long identity = Binder.clearCallingIdentity(); |
| 9300 | try { |
| 9301 | return UiccController.getInstance().getCardIdForDefaultEuicc(); |
| 9302 | } finally { |
| 9303 | Binder.restoreCallingIdentity(identity); |
| 9304 | } |
| 9305 | } |
| 9306 | |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9307 | /** |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 9308 | * A test API to reload the UICC profile. |
| 9309 | * |
| 9310 | * <p>Requires that the calling app has permission |
| 9311 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 9312 | * @hide |
| 9313 | */ |
| 9314 | @Override |
| 9315 | public void refreshUiccProfile(int subId) { |
| 9316 | enforceModifyPermission(); |
| 9317 | |
| 9318 | final long identity = Binder.clearCallingIdentity(); |
| 9319 | try { |
| 9320 | Phone phone = getPhone(subId); |
| 9321 | if (phone == null) { |
| 9322 | return; |
| 9323 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9324 | UiccPort uiccPort = phone.getUiccPort(); |
| 9325 | if (uiccPort == null) { |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 9326 | return; |
| 9327 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9328 | UiccProfile uiccProfile = uiccPort.getUiccProfile(); |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 9329 | if (uiccProfile == null) { |
| 9330 | return; |
| 9331 | } |
| 9332 | uiccProfile.refresh(); |
| 9333 | } finally { |
| 9334 | Binder.restoreCallingIdentity(identity); |
| 9335 | } |
| 9336 | } |
| 9337 | |
| 9338 | /** |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9339 | * Returns false if the mobile data is disabled by default, otherwise return true. |
| 9340 | */ |
| 9341 | private boolean getDefaultDataEnabled() { |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 9342 | return TelephonyProperties.mobile_data().orElse(true); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9343 | } |
| 9344 | |
| 9345 | /** |
| 9346 | * Returns true if the data roaming is enabled by default, i.e the system property |
| 9347 | * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of |
| 9348 | * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true. |
| 9349 | */ |
| 9350 | private boolean getDefaultDataRoamingEnabled(int subId) { |
| 9351 | final CarrierConfigManager configMgr = (CarrierConfigManager) |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9352 | mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Shuo Qian | 1d84a0e | 2020-07-15 12:36:44 -0700 | [diff] [blame] | 9353 | boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9354 | isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean( |
| 9355 | CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL); |
| 9356 | return isDataRoamingEnabled; |
| 9357 | } |
| 9358 | |
| 9359 | /** |
| 9360 | * Returns the default network type for the given {@code subId}, if the default network type is |
| 9361 | * not set, return {@link Phone#PREFERRED_NT_MODE}. |
| 9362 | */ |
| 9363 | private int getDefaultNetworkType(int subId) { |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 9364 | List<Integer> list = TelephonyProperties.default_network(); |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 9365 | int phoneId = SubscriptionManager.getPhoneId(subId); |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 9366 | if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) { |
| 9367 | return list.get(phoneId); |
| 9368 | } |
| 9369 | return Phone.PREFERRED_NT_MODE; |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9370 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9371 | |
| 9372 | @Override |
| 9373 | public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 9374 | gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) { |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9375 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9376 | |
| 9377 | final long identity = Binder.clearCallingIdentity(); |
| 9378 | try { |
| 9379 | final Phone phone = getPhone(subId); |
| 9380 | if (phone == null) { |
| 9381 | loge("setCarrierTestOverride fails with invalid subId: " + subId); |
| 9382 | return; |
| 9383 | } |
Rambo Wang | 9c9ffdd | 2022-01-13 21:51:44 -0800 | [diff] [blame] | 9384 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 9385 | if (cpt != null) { |
| 9386 | cpt.setTestOverrideCarrierPrivilegeRules(carrierPrivilegeRules); |
| 9387 | } |
| 9388 | // 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] | 9389 | phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn, |
| 9390 | carrierPrivilegeRules, apn); |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 9391 | if (carrierPrivilegeRules == null) { |
| 9392 | mCarrierPrivilegeTestOverrideSubIds.remove(subId); |
| 9393 | } else { |
| 9394 | mCarrierPrivilegeTestOverrideSubIds.add(subId); |
| 9395 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9396 | } finally { |
| 9397 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9398 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9399 | } |
| 9400 | |
| 9401 | @Override |
| 9402 | public int getCarrierIdListVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 9403 | enforceReadPrivilegedPermission("getCarrierIdListVersion"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9404 | |
| 9405 | final long identity = Binder.clearCallingIdentity(); |
| 9406 | try { |
| 9407 | final Phone phone = getPhone(subId); |
| 9408 | if (phone == null) { |
| 9409 | loge("getCarrierIdListVersion fails with invalid subId: " + subId); |
| 9410 | return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION; |
| 9411 | } |
| 9412 | return phone.getCarrierIdListVersion(); |
| 9413 | } finally { |
| 9414 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9415 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9416 | } |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 9417 | |
| 9418 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9419 | public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage, |
| 9420 | String callingFeatureId) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 9421 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9422 | mApp, subId, callingPackage, callingFeatureId, |
| 9423 | "getNumberOfModemsWithSimultaneousDataConnections")) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 9424 | return -1; |
| 9425 | } |
| 9426 | |
| 9427 | final long identity = Binder.clearCallingIdentity(); |
| 9428 | try { |
| 9429 | return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections(); |
| 9430 | } finally { |
| 9431 | Binder.restoreCallingIdentity(identity); |
| 9432 | } |
| 9433 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9434 | |
| 9435 | @Override |
| 9436 | public int getCdmaRoamingMode(int subId) { |
zoey chen | 7e6d4e5 | 2019-12-17 18:18:59 +0800 | [diff] [blame] | 9437 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9438 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9439 | mApp, subId, "getCdmaRoamingMode"); |
| 9440 | |
| 9441 | final long identity = Binder.clearCallingIdentity(); |
| 9442 | try { |
| 9443 | return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId); |
| 9444 | } finally { |
| 9445 | Binder.restoreCallingIdentity(identity); |
| 9446 | } |
| 9447 | } |
| 9448 | |
| 9449 | @Override |
| 9450 | public boolean setCdmaRoamingMode(int subId, int mode) { |
| 9451 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9452 | mApp, subId, "setCdmaRoamingMode"); |
| 9453 | |
| 9454 | final long identity = Binder.clearCallingIdentity(); |
| 9455 | try { |
| 9456 | return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId); |
| 9457 | } finally { |
| 9458 | Binder.restoreCallingIdentity(identity); |
| 9459 | } |
| 9460 | } |
| 9461 | |
| 9462 | @Override |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 9463 | public int getCdmaSubscriptionMode(int subId) { |
| 9464 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9465 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 9466 | mApp, subId, "getCdmaSubscriptionMode"); |
| 9467 | |
| 9468 | final long identity = Binder.clearCallingIdentity(); |
| 9469 | try { |
| 9470 | return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId); |
| 9471 | } finally { |
| 9472 | Binder.restoreCallingIdentity(identity); |
| 9473 | } |
| 9474 | } |
| 9475 | |
| 9476 | @Override |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9477 | public boolean setCdmaSubscriptionMode(int subId, int mode) { |
| 9478 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9479 | mApp, subId, "setCdmaSubscriptionMode"); |
| 9480 | |
| 9481 | final long identity = Binder.clearCallingIdentity(); |
| 9482 | try { |
| 9483 | return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId); |
| 9484 | } finally { |
| 9485 | Binder.restoreCallingIdentity(identity); |
| 9486 | } |
| 9487 | } |
Makoto Onuki | da3bf79 | 2018-09-18 16:06:29 -0700 | [diff] [blame] | 9488 | |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 9489 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 9490 | public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9491 | String callingPackage, String callingFeatureId) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9492 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9493 | mApp, getDefaultSubscription(), callingPackage, callingFeatureId, |
| 9494 | "getEmergencyNumberList")) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9495 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 9496 | } |
| 9497 | final long identity = Binder.clearCallingIdentity(); |
| 9498 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 9499 | Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>(); |
| 9500 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9501 | if (phone.getEmergencyNumberTracker() != null |
| 9502 | && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) { |
| 9503 | emergencyNumberListInternal.put( |
| 9504 | phone.getSubId(), |
| 9505 | phone.getEmergencyNumberTracker().getEmergencyNumberList()); |
| 9506 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9507 | } |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 9508 | return emergencyNumberListInternal; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9509 | } finally { |
| 9510 | Binder.restoreCallingIdentity(identity); |
| 9511 | } |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 9512 | } |
| 9513 | |
| 9514 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 9515 | public boolean isEmergencyNumber(String number, boolean exactMatch) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9516 | final Phone defaultPhone = getDefaultPhone(); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9517 | if (!exactMatch) { |
| 9518 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9519 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 9520 | mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)"); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9521 | } |
| 9522 | final long identity = Binder.clearCallingIdentity(); |
| 9523 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 9524 | for (Phone phone: PhoneFactory.getPhones()) { |
Chinmay Dhodapkar | d521bb1 | 2022-08-16 15:49:54 -0700 | [diff] [blame] | 9525 | //Note: we ignore passed in param exactMatch. We can remove it once |
| 9526 | // TelephonyManager#isPotentialEmergencyNumber is removed completely |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 9527 | if (phone.getEmergencyNumberTracker() != null |
Taesu Lee | e050c00 | 2020-10-13 17:19:35 +0900 | [diff] [blame] | 9528 | && phone.getEmergencyNumberTracker() |
Chinmay Dhodapkar | d521bb1 | 2022-08-16 15:49:54 -0700 | [diff] [blame] | 9529 | .isEmergencyNumber(number)) { |
Taesu Lee | e050c00 | 2020-10-13 17:19:35 +0900 | [diff] [blame] | 9530 | return true; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9531 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9532 | } |
| 9533 | return false; |
| 9534 | } finally { |
| 9535 | Binder.restoreCallingIdentity(identity); |
| 9536 | } |
| 9537 | } |
| 9538 | |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 9539 | /** |
Shuo Qian | ccbaf74 | 2021-02-22 18:32:21 -0800 | [diff] [blame] | 9540 | * Start emergency callback mode for GsmCdmaPhone for testing. |
| 9541 | */ |
| 9542 | @Override |
| 9543 | public void startEmergencyCallbackMode() { |
| 9544 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9545 | "startEmergencyCallbackMode"); |
| 9546 | enforceModifyPermission(); |
| 9547 | final long identity = Binder.clearCallingIdentity(); |
| 9548 | try { |
| 9549 | for (Phone phone : PhoneFactory.getPhones()) { |
| 9550 | Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType()); |
| 9551 | if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM) |
| 9552 | || (phone.getPhoneType() == PHONE_TYPE_CDMA))) { |
| 9553 | GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone; |
| 9554 | gsmCdmaPhone.obtainMessage( |
| 9555 | GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget(); |
| 9556 | Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered"); |
| 9557 | } |
| 9558 | } |
| 9559 | } finally { |
| 9560 | Binder.restoreCallingIdentity(identity); |
| 9561 | } |
| 9562 | } |
| 9563 | |
| 9564 | /** |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 9565 | * Update emergency number list for test mode. |
| 9566 | */ |
| 9567 | @Override |
| 9568 | public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) { |
| 9569 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9570 | "updateEmergencyNumberListTestMode"); |
| 9571 | |
| 9572 | final long identity = Binder.clearCallingIdentity(); |
| 9573 | try { |
| 9574 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9575 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9576 | if (tracker != null) { |
| 9577 | tracker.executeEmergencyNumberTestModeCommand(action, num); |
| 9578 | } |
| 9579 | } |
| 9580 | } finally { |
| 9581 | Binder.restoreCallingIdentity(identity); |
| 9582 | } |
| 9583 | } |
| 9584 | |
| 9585 | /** |
| 9586 | * Get the full emergency number list for test mode. |
| 9587 | */ |
| 9588 | @Override |
| 9589 | public List<String> getEmergencyNumberListTestMode() { |
| 9590 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9591 | "getEmergencyNumberListTestMode"); |
| 9592 | |
| 9593 | final long identity = Binder.clearCallingIdentity(); |
| 9594 | try { |
| 9595 | Set<String> emergencyNumbers = new HashSet<>(); |
| 9596 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9597 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9598 | if (tracker != null) { |
| 9599 | for (EmergencyNumber num : tracker.getEmergencyNumberList()) { |
| 9600 | emergencyNumbers.add(num.getNumber()); |
| 9601 | } |
| 9602 | } |
| 9603 | } |
| 9604 | return new ArrayList<>(emergencyNumbers); |
| 9605 | } finally { |
| 9606 | Binder.restoreCallingIdentity(identity); |
| 9607 | } |
| 9608 | } |
| 9609 | |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 9610 | @Override |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 9611 | public int getEmergencyNumberDbVersion(int subId) { |
| 9612 | enforceReadPrivilegedPermission("getEmergencyNumberDbVersion"); |
| 9613 | |
| 9614 | final long identity = Binder.clearCallingIdentity(); |
| 9615 | try { |
| 9616 | final Phone phone = getPhone(subId); |
| 9617 | if (phone == null) { |
| 9618 | loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId); |
| 9619 | return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION; |
| 9620 | } |
| 9621 | return phone.getEmergencyNumberDbVersion(); |
| 9622 | } finally { |
| 9623 | Binder.restoreCallingIdentity(identity); |
| 9624 | } |
| 9625 | } |
| 9626 | |
| 9627 | @Override |
| 9628 | public void notifyOtaEmergencyNumberDbInstalled() { |
| 9629 | enforceModifyPermission(); |
| 9630 | |
| 9631 | final long identity = Binder.clearCallingIdentity(); |
| 9632 | try { |
| 9633 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9634 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9635 | if (tracker != null) { |
| 9636 | tracker.updateOtaEmergencyNumberDatabase(); |
| 9637 | } |
| 9638 | } |
| 9639 | } finally { |
| 9640 | Binder.restoreCallingIdentity(identity); |
| 9641 | } |
| 9642 | } |
| 9643 | |
| 9644 | @Override |
Shuo Qian | c373f11 | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 9645 | public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) { |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 9646 | enforceActiveEmergencySessionPermission(); |
| 9647 | |
| 9648 | final long identity = Binder.clearCallingIdentity(); |
| 9649 | try { |
| 9650 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9651 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9652 | if (tracker != null) { |
Shuo Qian | c373f11 | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 9653 | tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor); |
| 9654 | } |
| 9655 | } |
| 9656 | } finally { |
| 9657 | Binder.restoreCallingIdentity(identity); |
| 9658 | } |
| 9659 | } |
| 9660 | |
| 9661 | @Override |
| 9662 | public void resetOtaEmergencyNumberDbFilePath() { |
| 9663 | enforceActiveEmergencySessionPermission(); |
| 9664 | |
| 9665 | final long identity = Binder.clearCallingIdentity(); |
| 9666 | try { |
| 9667 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9668 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9669 | if (tracker != null) { |
| 9670 | tracker.resetOtaEmergencyNumberDbFilePath(); |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 9671 | } |
| 9672 | } |
| 9673 | } finally { |
| 9674 | Binder.restoreCallingIdentity(identity); |
| 9675 | } |
| 9676 | } |
| 9677 | |
| 9678 | @Override |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 9679 | public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) { |
| 9680 | enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules"); |
| 9681 | Phone phone = getPhone(subId); |
| 9682 | if (phone == null) { |
| 9683 | return null; |
| 9684 | } |
| 9685 | final long identity = Binder.clearCallingIdentity(); |
| 9686 | try { |
| 9687 | UiccProfile profile = UiccController.getInstance() |
| 9688 | .getUiccProfileForPhone(phone.getPhoneId()); |
| 9689 | if (profile != null) { |
| 9690 | return profile.getCertsFromCarrierPrivilegeAccessRules(); |
| 9691 | } |
| 9692 | } finally { |
| 9693 | Binder.restoreCallingIdentity(identity); |
| 9694 | } |
| 9695 | return null; |
| 9696 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 9697 | |
| 9698 | /** |
| 9699 | * Enable or disable a modem stack. |
| 9700 | */ |
| 9701 | @Override |
| 9702 | public boolean enableModemForSlot(int slotIndex, boolean enable) { |
| 9703 | enforceModifyPermission(); |
| 9704 | |
| 9705 | final long identity = Binder.clearCallingIdentity(); |
| 9706 | try { |
| 9707 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 9708 | if (phone == null) { |
| 9709 | return false; |
| 9710 | } else { |
| 9711 | return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null); |
| 9712 | } |
| 9713 | } finally { |
| 9714 | Binder.restoreCallingIdentity(identity); |
| 9715 | } |
| 9716 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9717 | |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 9718 | /** |
| 9719 | * Whether a modem stack is enabled or not. |
| 9720 | */ |
| 9721 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9722 | public boolean isModemEnabledForSlot(int slotIndex, String callingPackage, |
| 9723 | String callingFeatureId) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 9724 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 9725 | if (phone == null) return false; |
| 9726 | |
| 9727 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9728 | mApp, phone.getSubId(), callingPackage, callingFeatureId, |
| 9729 | "isModemEnabledForSlot")) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 9730 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 9731 | } |
| 9732 | |
| 9733 | final long identity = Binder.clearCallingIdentity(); |
| 9734 | try { |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 9735 | try { |
| 9736 | return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId()); |
| 9737 | } catch (NoSuchElementException ex) { |
| 9738 | return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null); |
| 9739 | } |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 9740 | } finally { |
| 9741 | Binder.restoreCallingIdentity(identity); |
| 9742 | } |
| 9743 | } |
| 9744 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9745 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9746 | public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) { |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9747 | enforceModifyPermission(); |
| 9748 | |
| 9749 | final long identity = Binder.clearCallingIdentity(); |
| 9750 | try { |
| 9751 | mTelephonySharedPreferences.edit() |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9752 | .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted) |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9753 | .commit(); |
| 9754 | } finally { |
| 9755 | Binder.restoreCallingIdentity(identity); |
| 9756 | } |
| 9757 | } |
| 9758 | |
| 9759 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9760 | @TelephonyManager.IsMultiSimSupportedResult |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9761 | public int isMultiSimSupported(String callingPackage, String callingFeatureId) { |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 9762 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9763 | getDefaultPhone().getSubId(), callingPackage, callingFeatureId, |
| 9764 | "isMultiSimSupported")) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9765 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 9766 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9767 | |
| 9768 | final long identity = Binder.clearCallingIdentity(); |
| 9769 | try { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9770 | return isMultiSimSupportedInternal(); |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9771 | } finally { |
| 9772 | Binder.restoreCallingIdentity(identity); |
| 9773 | } |
| 9774 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9775 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9776 | @TelephonyManager.IsMultiSimSupportedResult |
| 9777 | private int isMultiSimSupportedInternal() { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9778 | // If the device has less than 2 SIM cards, indicate that multisim is restricted. |
| 9779 | int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length; |
| 9780 | if (numPhysicalSlots < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9781 | loge("isMultiSimSupportedInternal: requires at least 2 cards"); |
| 9782 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9783 | } |
| 9784 | // Check if the hardware supports multisim functionality. If usage of multisim is not |
| 9785 | // supported by the modem, indicate that it is restricted. |
| 9786 | PhoneCapability staticCapability = |
| 9787 | mPhoneConfigurationManager.getStaticPhoneCapability(); |
| 9788 | if (staticCapability == null) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9789 | loge("isMultiSimSupportedInternal: no static configuration available"); |
| 9790 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9791 | } |
SongFerngWang | 8236caa | 2021-01-17 21:51:44 +0800 | [diff] [blame] | 9792 | if (staticCapability.getLogicalModemList().size() < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9793 | loge("isMultiSimSupportedInternal: maximum number of modem is < 2"); |
| 9794 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9795 | } |
| 9796 | // Check if support of multiple SIMs is restricted by carrier |
| 9797 | if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9798 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9799 | } |
| 9800 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9801 | return TelephonyManager.MULTISIM_ALLOWED; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9802 | } |
| 9803 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9804 | /** |
| 9805 | * Switch configs to enable multi-sim or switch back to single-sim |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 9806 | * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE |
| 9807 | * permission, but the other way around is possible with either MODIFY_PHONE_STATE |
| 9808 | * or carrier privileges |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9809 | * @param numOfSims number of active sims we want to switch to |
| 9810 | */ |
| 9811 | @Override |
| 9812 | public void switchMultiSimConfig(int numOfSims) { |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 9813 | if (numOfSims == 1) { |
| 9814 | enforceModifyPermission(); |
| 9815 | } else { |
| 9816 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9817 | mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig"); |
| 9818 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9819 | final long identity = Binder.clearCallingIdentity(); |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9820 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9821 | try { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9822 | //only proceed if multi-sim is not restricted |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9823 | if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9824 | loge("switchMultiSimConfig not possible. It is restricted or not supported."); |
| 9825 | return; |
| 9826 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9827 | mPhoneConfigurationManager.switchMultiSimConfig(numOfSims); |
| 9828 | } finally { |
| 9829 | Binder.restoreCallingIdentity(identity); |
| 9830 | } |
| 9831 | } |
| 9832 | |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 9833 | @Override |
| 9834 | public boolean isApplicationOnUicc(int subId, int appType) { |
| 9835 | enforceReadPrivilegedPermission("isApplicationOnUicc"); |
| 9836 | Phone phone = getPhone(subId); |
| 9837 | if (phone == null) { |
| 9838 | return false; |
| 9839 | } |
| 9840 | final long identity = Binder.clearCallingIdentity(); |
| 9841 | try { |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9842 | UiccPort uiccPort = phone.getUiccPort(); |
| 9843 | if (uiccPort == null) { |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 9844 | return false; |
| 9845 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9846 | UiccProfile uiccProfile = uiccPort.getUiccProfile(); |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 9847 | if (uiccProfile == null) { |
| 9848 | return false; |
| 9849 | } |
| 9850 | if (TelephonyManager.APPTYPE_SIM <= appType |
| 9851 | && appType <= TelephonyManager.APPTYPE_ISIM) { |
| 9852 | return uiccProfile.isApplicationOnIcc(AppType.values()[appType]); |
| 9853 | } |
| 9854 | return false; |
| 9855 | } finally { |
| 9856 | Binder.restoreCallingIdentity(identity); |
| 9857 | } |
| 9858 | } |
| 9859 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9860 | /** |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 9861 | * Get whether making changes to modem configurations will trigger reboot. |
| 9862 | * Return value defaults to true. |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 9863 | */ |
| 9864 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9865 | public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage, |
| 9866 | String callingFeatureId) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 9867 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9868 | mApp, subId, callingPackage, callingFeatureId, |
| 9869 | "doesSwitchMultiSimConfigTriggerReboot")) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 9870 | return false; |
| 9871 | } |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 9872 | final long identity = Binder.clearCallingIdentity(); |
| 9873 | try { |
| 9874 | return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange(); |
| 9875 | } finally { |
| 9876 | Binder.restoreCallingIdentity(identity); |
| 9877 | } |
| 9878 | } |
| 9879 | |
Nathan Harold | 29f5f05 | 2019-02-15 13:41:57 -0800 | [diff] [blame] | 9880 | private void updateModemStateMetrics() { |
| 9881 | TelephonyMetrics metrics = TelephonyMetrics.getInstance(); |
| 9882 | // TODO: check the state for each modem if the api is ready. |
| 9883 | metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1); |
| 9884 | } |
| 9885 | |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 9886 | @Override |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9887 | public List<UiccSlotMapping> getSlotsMapping(String callingPackage) { |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 9888 | enforceReadPrivilegedPermission("getSlotsMapping"); |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9889 | // Verify that the callingPackage belongs to the calling UID |
| 9890 | mApp.getSystemService(AppOpsManager.class) |
| 9891 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 9892 | final long identity = Binder.clearCallingIdentity(); |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9893 | List<UiccSlotMapping> slotMap = new ArrayList<>(); |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 9894 | try { |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9895 | UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName()); |
| 9896 | if (slotInfos != null) { |
| 9897 | for (int i = 0; i < slotInfos.length; i++) { |
| 9898 | for (UiccPortInfo portInfo : slotInfos[i].getPorts()) { |
| 9899 | if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) { |
| 9900 | slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i, |
| 9901 | portInfo.getLogicalSlotIndex())); |
| 9902 | } |
| 9903 | } |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 9904 | } |
| 9905 | } |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9906 | return slotMap; |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 9907 | } finally { |
| 9908 | Binder.restoreCallingIdentity(identity); |
| 9909 | } |
| 9910 | } |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 9911 | |
| 9912 | /** |
| 9913 | * Get the IRadio HAL Version |
jimsun | f9ec162 | 2022-09-13 21:18:43 +0800 | [diff] [blame] | 9914 | * @deprecated use getHalVersion instead |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 9915 | */ |
jimsun | f9ec162 | 2022-09-13 21:18:43 +0800 | [diff] [blame] | 9916 | @Deprecated |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 9917 | @Override |
| 9918 | public int getRadioHalVersion() { |
jimsun | f9ec162 | 2022-09-13 21:18:43 +0800 | [diff] [blame] | 9919 | return getHalVersion(HAL_SERVICE_RADIO); |
| 9920 | } |
| 9921 | |
| 9922 | /** |
| 9923 | * Get the HAL Version of a specific service |
| 9924 | */ |
| 9925 | @Override |
| 9926 | public int getHalVersion(int service) { |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 9927 | Phone phone = getDefaultPhone(); |
| 9928 | if (phone == null) return -1; |
jimsun | f9ec162 | 2022-09-13 21:18:43 +0800 | [diff] [blame] | 9929 | HalVersion hv = phone.getHalVersion(service); |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 9930 | if (hv.equals(HalVersion.UNKNOWN)) return -1; |
| 9931 | return hv.major * 100 + hv.minor; |
| 9932 | } |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9933 | |
| 9934 | /** |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 9935 | * Get the current calling package name. |
| 9936 | * @return the current calling package name |
| 9937 | */ |
| 9938 | @Override |
| 9939 | public String getCurrentPackageName() { |
| 9940 | return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0]; |
| 9941 | } |
| 9942 | |
| 9943 | /** |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9944 | * Return whether data is enabled for certain APN type. This will tell if framework will accept |
| 9945 | * corresponding network requests on a subId. |
| 9946 | * |
| 9947 | * Data is enabled if: |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9948 | * 1) user data is turned on, or |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9949 | * 2) APN is un-metered for this subscription, or |
| 9950 | * 3) APN type is whitelisted. E.g. MMS is whitelisted if |
Hall Liu | 746e03c | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 9951 | * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled. |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9952 | * |
| 9953 | * @return whether data is allowed for a apn type. |
| 9954 | * |
| 9955 | * @hide |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9956 | */ |
| 9957 | @Override |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9958 | public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) { |
Amit Mahajan | 5d4e192 | 2019-10-07 16:20:43 -0700 | [diff] [blame] | 9959 | enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for " |
| 9960 | + "isDataEnabledForApn"); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9961 | |
| 9962 | // Now that all security checks passes, perform the operation as ourselves. |
| 9963 | final long identity = Binder.clearCallingIdentity(); |
| 9964 | try { |
| 9965 | Phone phone = getPhone(subId); |
| 9966 | if (phone == null) return false; |
| 9967 | |
Jack Yu | 27422a5 | 2022-03-21 10:38:05 -0700 | [diff] [blame] | 9968 | boolean isMetered; |
Jack Yu | 99e8733 | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 9969 | boolean isDataEnabled; |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 9970 | isMetered = phone.getDataNetworkController().getDataConfigManager() |
| 9971 | .isMeteredCapability(DataUtils.apnTypeToNetworkCapability(apnType), |
| 9972 | phone.getServiceState().getDataRoaming()); |
| 9973 | isDataEnabled = phone.getDataSettingsManager().isDataEnabled(apnType); |
Jack Yu | 99e8733 | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 9974 | return !isMetered || isDataEnabled; |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9975 | } finally { |
| 9976 | Binder.restoreCallingIdentity(identity); |
| 9977 | } |
| 9978 | } |
| 9979 | |
| 9980 | @Override |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 9981 | public boolean isApnMetered(@ApnType int apnType, int subId) { |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9982 | enforceReadPrivilegedPermission("isApnMetered"); |
| 9983 | |
| 9984 | // Now that all security checks passes, perform the operation as ourselves. |
| 9985 | final long identity = Binder.clearCallingIdentity(); |
| 9986 | try { |
| 9987 | Phone phone = getPhone(subId); |
| 9988 | if (phone == null) return true; // By default return true. |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 9989 | return phone.getDataNetworkController().getDataConfigManager().isMeteredCapability( |
| 9990 | DataUtils.apnTypeToNetworkCapability(apnType), |
| 9991 | phone.getServiceState().getDataRoaming()); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9992 | } finally { |
| 9993 | Binder.restoreCallingIdentity(identity); |
| 9994 | } |
| 9995 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 9996 | |
| 9997 | @Override |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 9998 | public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers, |
| 9999 | int subscriptionId, IBooleanConsumer resultCallback) { |
| 10000 | enforceModifyPermission(); |
| 10001 | long token = Binder.clearCallingIdentity(); |
| 10002 | try { |
| 10003 | Phone phone = getPhone(subscriptionId); |
| 10004 | if (phone == null) { |
| 10005 | try { |
| 10006 | if (resultCallback != null) { |
| 10007 | resultCallback.accept(false); |
| 10008 | } |
| 10009 | } catch (RemoteException e) { |
| 10010 | // ignore |
| 10011 | } |
| 10012 | return; |
| 10013 | } |
| 10014 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument = |
| 10015 | Pair.create(specifiers, (x) -> { |
| 10016 | try { |
| 10017 | if (resultCallback != null) { |
| 10018 | resultCallback.accept(x); |
| 10019 | } |
| 10020 | } catch (RemoteException e) { |
| 10021 | // ignore |
| 10022 | } |
| 10023 | }); |
| 10024 | sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null); |
| 10025 | } finally { |
| 10026 | Binder.restoreCallingIdentity(token); |
| 10027 | } |
| 10028 | } |
| 10029 | |
| 10030 | @Override |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 10031 | public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) { |
| 10032 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 10033 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 10034 | mApp, subId, "getSystemSelectionChannels"); |
| 10035 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 10036 | final long identity = Binder.clearCallingIdentity(); |
| 10037 | try { |
Sarah Chin | 428d1d6 | 2021-03-13 03:17:40 -0800 | [diff] [blame] | 10038 | Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource); |
| 10039 | if (result instanceof IllegalStateException) { |
| 10040 | throw (IllegalStateException) result; |
| 10041 | } |
| 10042 | List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 10043 | if (DBG) log("getSystemSelectionChannels: " + specifiers); |
| 10044 | return specifiers; |
| 10045 | } finally { |
| 10046 | Binder.restoreCallingIdentity(identity); |
| 10047 | } |
| 10048 | } |
| 10049 | |
| 10050 | @Override |
Jack Yu | 8b766fc | 2022-03-21 09:42:33 -0700 | [diff] [blame] | 10051 | public boolean isMvnoMatched(int slotIndex, int mvnoType, @NonNull String mvnoMatchData) { |
changbetty | ca3d40d | 2020-03-03 16:27:31 +0800 | [diff] [blame] | 10052 | enforceReadPrivilegedPermission("isMvnoMatched"); |
Jack Yu | 8b766fc | 2022-03-21 09:42:33 -0700 | [diff] [blame] | 10053 | return UiccController.getInstance().mvnoMatches(slotIndex, mvnoType, mvnoMatchData); |
changbetty | 7157e9e | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 10054 | } |
| 10055 | |
| 10056 | @Override |
Philip P. Moltmann | d02b737 | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 10057 | public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag, |
| 10058 | IIntegerConsumer pendingSubIdResult) { |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 10059 | if (callingPackage == null) { |
| 10060 | callingPackage = getCurrentPackageName(); |
| 10061 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 10062 | SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp, |
| 10063 | (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE)); |
Philip P. Moltmann | d02b737 | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 10064 | if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag, |
| 10065 | "Sending message")) { |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 10066 | throw new SecurityException("Requires SEND_SMS permission to perform this operation"); |
| 10067 | } |
| 10068 | PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult); |
| 10069 | Intent intent = new Intent(); |
| 10070 | intent.setClass(mApp, PickSmsSubscriptionActivity.class); |
| 10071 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 10072 | // Bring up choose default SMS subscription dialog right now |
| 10073 | intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY, |
| 10074 | PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE); |
| 10075 | mApp.startActivity(intent); |
| 10076 | } |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 10077 | |
| 10078 | @Override |
| 10079 | public String getMmsUAProfUrl(int subId) { |
| 10080 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 10081 | final long identity = Binder.clearCallingIdentity(); |
| 10082 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 10083 | String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString( |
| 10084 | CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING); |
| 10085 | if (!TextUtils.isEmpty(carrierUAProfUrl)) { |
| 10086 | return carrierUAProfUrl; |
| 10087 | } |
Daniel Bright | ebb4eb7 | 2020-02-18 15:16:33 -0800 | [diff] [blame] | 10088 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 10089 | .getString(com.android.internal.R.string.config_mms_user_agent_profile_url); |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 10090 | } finally { |
| 10091 | Binder.restoreCallingIdentity(identity); |
| 10092 | } |
| 10093 | } |
| 10094 | |
| 10095 | @Override |
| 10096 | public String getMmsUserAgent(int subId) { |
| 10097 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 10098 | final long identity = Binder.clearCallingIdentity(); |
| 10099 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 10100 | String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString( |
| 10101 | CarrierConfigManager.KEY_MMS_USER_AGENT_STRING); |
| 10102 | if (!TextUtils.isEmpty(carrierUserAgent)) { |
| 10103 | return carrierUserAgent; |
| 10104 | } |
Daniel Bright | ebb4eb7 | 2020-02-18 15:16:33 -0800 | [diff] [blame] | 10105 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 10106 | .getString(com.android.internal.R.string.config_mms_user_agent); |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 10107 | } finally { |
| 10108 | Binder.restoreCallingIdentity(identity); |
| 10109 | } |
| 10110 | } |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 10111 | |
| 10112 | @Override |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 10113 | public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) { |
| 10114 | enforceReadPrivilegedPermission("isMobileDataPolicyEnabled"); |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 10115 | |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 10116 | final long identity = Binder.clearCallingIdentity(); |
| 10117 | try { |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 10118 | Phone phone = getPhone(subscriptionId); |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 10119 | if (phone == null) return false; |
| 10120 | |
Ling Ma | f188d50 | 2022-09-16 15:22:36 -0700 | [diff] [blame] | 10121 | return phone.getDataSettingsManager().isMobileDataPolicyEnabled(policy); |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 10122 | } finally { |
| 10123 | Binder.restoreCallingIdentity(identity); |
| 10124 | } |
| 10125 | } |
| 10126 | |
| 10127 | @Override |
Hall Liu | c66bb11 | 2021-02-02 12:09:32 -0800 | [diff] [blame] | 10128 | public void setMobileDataPolicyEnabled(int subscriptionId, int policy, |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 10129 | boolean enabled) { |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 10130 | enforceModifyPermission(); |
| 10131 | |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 10132 | final long identity = Binder.clearCallingIdentity(); |
| 10133 | try { |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 10134 | Phone phone = getPhone(subscriptionId); |
| 10135 | if (phone == null) return; |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 10136 | |
Ling Ma | f188d50 | 2022-09-16 15:22:36 -0700 | [diff] [blame] | 10137 | phone.getDataSettingsManager().setMobileDataPolicy(policy, enabled); |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 10138 | } finally { |
| 10139 | Binder.restoreCallingIdentity(identity); |
| 10140 | } |
| 10141 | } |
| 10142 | |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 10143 | /** |
Hall Liu | 746e03c | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 10144 | * Updates whether conference event package handling is enabled. |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 10145 | * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false} |
| 10146 | * otherwise. |
| 10147 | */ |
| 10148 | @Override |
| 10149 | public void setCepEnabled(boolean isCepEnabled) { |
| 10150 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled"); |
| 10151 | |
| 10152 | final long identity = Binder.clearCallingIdentity(); |
| 10153 | try { |
| 10154 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled); |
| 10155 | for (Phone phone : PhoneFactory.getPhones()) { |
| 10156 | Phone defaultPhone = phone.getImsPhone(); |
| 10157 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 10158 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 10159 | ImsPhoneCallTracker imsPhoneCallTracker = |
| 10160 | (ImsPhoneCallTracker) imsPhone.getCallTracker(); |
| 10161 | imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled); |
| 10162 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone " |
| 10163 | + imsPhone.getMsisdn()); |
| 10164 | } |
| 10165 | } |
| 10166 | } finally { |
| 10167 | Binder.restoreCallingIdentity(identity); |
| 10168 | } |
| 10169 | } |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 10170 | |
| 10171 | /** |
| 10172 | * Notify that an RCS autoconfiguration XML file has been received for provisioning. |
| 10173 | * |
| 10174 | * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed. |
| 10175 | * @param isCompressed The XML file is compressed in gzip format and must be decompressed |
| 10176 | * before being read. |
| 10177 | */ |
| 10178 | @Override |
| 10179 | public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean |
| 10180 | isCompressed) { |
| 10181 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 10182 | mApp, subId, "notifyRcsAutoConfigurationReceived"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10183 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10184 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10185 | } |
| 10186 | if (!isImsAvailableOnDevice()) { |
| 10187 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 10188 | "IMS not available on device."); |
| 10189 | } |
| 10190 | |
| 10191 | final long identity = Binder.clearCallingIdentity(); |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 10192 | try { |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10193 | RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed); |
| 10194 | } finally { |
| 10195 | Binder.restoreCallingIdentity(identity); |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 10196 | } |
| 10197 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 10198 | |
| 10199 | @Override |
| 10200 | public boolean isIccLockEnabled(int subId) { |
| 10201 | enforceReadPrivilegedPermission("isIccLockEnabled"); |
| 10202 | |
| 10203 | // Now that all security checks passes, perform the operation as ourselves. |
| 10204 | final long identity = Binder.clearCallingIdentity(); |
| 10205 | try { |
| 10206 | Phone phone = getPhone(subId); |
| 10207 | if (phone != null && phone.getIccCard() != null) { |
| 10208 | return phone.getIccCard().getIccLockEnabled(); |
| 10209 | } else { |
| 10210 | return false; |
| 10211 | } |
| 10212 | } finally { |
| 10213 | Binder.restoreCallingIdentity(identity); |
| 10214 | } |
| 10215 | } |
| 10216 | |
| 10217 | /** |
| 10218 | * Set the ICC pin lock enabled or disabled. |
| 10219 | * |
| 10220 | * @return an integer representing the status of IccLock enabled or disabled in the following |
| 10221 | * three cases: |
| 10222 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock |
| 10223 | * successfully. |
| 10224 | * - Positive number and zero for remaining password attempts. |
| 10225 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
| 10226 | * |
| 10227 | */ |
| 10228 | @Override |
| 10229 | public int setIccLockEnabled(int subId, boolean enabled, String password) { |
| 10230 | enforceModifyPermission(); |
| 10231 | |
| 10232 | Phone phone = getPhone(subId); |
| 10233 | if (phone == null) { |
| 10234 | return 0; |
| 10235 | } |
| 10236 | // Now that all security checks passes, perform the operation as ourselves. |
| 10237 | final long identity = Binder.clearCallingIdentity(); |
| 10238 | try { |
| 10239 | int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED, |
| 10240 | new Pair<Boolean, String>(enabled, password), phone, null); |
| 10241 | return attemptsRemaining; |
| 10242 | |
| 10243 | } catch (Exception e) { |
| 10244 | Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e); |
| 10245 | } finally { |
| 10246 | Binder.restoreCallingIdentity(identity); |
| 10247 | } |
| 10248 | return 0; |
| 10249 | } |
| 10250 | |
| 10251 | /** |
| 10252 | * Change the ICC password used in ICC pin lock. |
| 10253 | * |
| 10254 | * @return an integer representing the status of IccLock changed in the following three cases: |
| 10255 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully. |
| 10256 | * - Positive number and zero for remaining password attempts. |
| 10257 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
| 10258 | * |
| 10259 | */ |
| 10260 | @Override |
| 10261 | public int changeIccLockPassword(int subId, String oldPassword, String newPassword) { |
| 10262 | enforceModifyPermission(); |
| 10263 | |
| 10264 | Phone phone = getPhone(subId); |
| 10265 | if (phone == null) { |
| 10266 | return 0; |
| 10267 | } |
| 10268 | // Now that all security checks passes, perform the operation as ourselves. |
| 10269 | final long identity = Binder.clearCallingIdentity(); |
| 10270 | try { |
| 10271 | int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD, |
| 10272 | new Pair<String, String>(oldPassword, newPassword), phone, null); |
| 10273 | return attemptsRemaining; |
| 10274 | |
| 10275 | } catch (Exception e) { |
| 10276 | Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e); |
| 10277 | } finally { |
| 10278 | Binder.restoreCallingIdentity(identity); |
| 10279 | } |
| 10280 | return 0; |
| 10281 | } |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 10282 | |
| 10283 | /** |
| 10284 | * Request for receiving user activity notification |
| 10285 | */ |
| 10286 | @Override |
| 10287 | public void requestUserActivityNotification() { |
| 10288 | if (!mNotifyUserActivity.get() |
| 10289 | && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) { |
| 10290 | mNotifyUserActivity.set(true); |
| 10291 | } |
| 10292 | } |
| 10293 | |
| 10294 | /** |
| 10295 | * Called when userActivity is signalled in the power manager. |
| 10296 | * This is safe to call from any thread, with any window manager locks held or not. |
| 10297 | */ |
| 10298 | @Override |
| 10299 | public void userActivity() { |
| 10300 | // *************************************** |
| 10301 | // * Inherited from PhoneWindowManager * |
| 10302 | // *************************************** |
| 10303 | // THIS IS CALLED FROM DEEP IN THE POWER MANAGER |
| 10304 | // WITH ITS LOCKS HELD. |
| 10305 | // |
| 10306 | // This code must be VERY careful about the locks |
| 10307 | // it acquires. |
| 10308 | // In fact, the current code acquires way too many, |
| 10309 | // and probably has lurking deadlocks. |
| 10310 | |
| 10311 | if (Binder.getCallingUid() != Process.SYSTEM_UID) { |
| 10312 | throw new SecurityException("Only the OS may call notifyUserActivity()"); |
| 10313 | } |
| 10314 | |
| 10315 | if (mNotifyUserActivity.getAndSet(false)) { |
| 10316 | mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY, |
| 10317 | USER_ACTIVITY_NOTIFICATION_DELAY); |
| 10318 | } |
| 10319 | } |
Malcolm Chen | 4639c56 | 2020-04-13 11:59:40 -0700 | [diff] [blame] | 10320 | |
| 10321 | @Override |
| 10322 | public boolean canConnectTo5GInDsdsMode() { |
| 10323 | return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode); |
| 10324 | } |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 10325 | |
| 10326 | @Override |
| 10327 | public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage, |
| 10328 | String callingFeatureId) { |
| 10329 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 10330 | mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) { |
| 10331 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 10332 | } |
| 10333 | |
| 10334 | Phone phone = getPhone(subId); |
| 10335 | if (phone == null) { |
| 10336 | throw new RuntimeException("phone is not available"); |
| 10337 | } |
| 10338 | // Now that all security checks passes, perform the operation as ourselves. |
| 10339 | final long identity = Binder.clearCallingIdentity(); |
| 10340 | try { |
| 10341 | return phone.getEquivalentHomePlmns(); |
| 10342 | } finally { |
| 10343 | Binder.restoreCallingIdentity(identity); |
| 10344 | } |
| 10345 | } |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 10346 | |
| 10347 | @Override |
| 10348 | public boolean isRadioInterfaceCapabilitySupported( |
Daniel Bright | 95a4c1f | 2021-02-11 09:57:16 -0800 | [diff] [blame] | 10349 | final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) { |
| 10350 | Set<String> radioInterfaceCapabilities = |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 10351 | mRadioInterfaceCapabilities.getCapabilities(); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 10352 | if (radioInterfaceCapabilities == null) { |
| 10353 | throw new RuntimeException("radio interface capabilities are not available"); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 10354 | } |
Daniel Bright | 95a4c1f | 2021-02-11 09:57:16 -0800 | [diff] [blame] | 10355 | return radioInterfaceCapabilities.contains(capability); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 10356 | } |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10357 | |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 10358 | @Override |
| 10359 | public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl, |
| 10360 | UaSecurityProtocolIdentifier securityProtocol, |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10361 | boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) { |
| 10362 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 10363 | Binder.getCallingUid(), "bootstrapAuthenticationRequest", |
| 10364 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 10365 | Manifest.permission.MODIFY_PHONE_STATE); |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 10366 | if (DBG) { |
| 10367 | log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:" |
| 10368 | + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol |
| 10369 | + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback); |
| 10370 | } |
| 10371 | |
| 10372 | if (!SubscriptionManager.isValidSubscriptionId(subId) |
| 10373 | || appType < TelephonyManager.APPTYPE_UNKNOWN |
| 10374 | || appType > TelephonyManager.APPTYPE_ISIM |
| 10375 | || nafUrl == null || securityProtocol == null || callback == null) { |
| 10376 | Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters"); |
| 10377 | if (callback != null) { |
| 10378 | try { |
| 10379 | callback.onAuthenticationFailure( |
| 10380 | 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED); |
| 10381 | } catch (RemoteException exception) { |
| 10382 | log("Fail to notify onAuthenticationFailure due to " + exception); |
| 10383 | } |
| 10384 | return; |
| 10385 | } |
| 10386 | } |
| 10387 | |
| 10388 | final long token = Binder.clearCallingIdentity(); |
| 10389 | try { |
| 10390 | getGbaManager(subId).bootstrapAuthenticationRequest( |
| 10391 | new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(), |
| 10392 | forceBootStrapping, callback)); |
| 10393 | } finally { |
| 10394 | Binder.restoreCallingIdentity(token); |
| 10395 | } |
| 10396 | } |
| 10397 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10398 | /** |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10399 | * Attempts to set the radio power state for all phones for thermal reason. |
| 10400 | * This does not guarantee that the |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10401 | * requested radio power state will actually be set. See {@link |
| 10402 | * PhoneInternalInterface#setRadioPowerForReason} for more details. |
| 10403 | * |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10404 | * @param enable {@code true} if trying to turn radio on. |
| 10405 | * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code |
| 10406 | * false}. |
| 10407 | */ |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10408 | private boolean setRadioPowerForThermal(boolean enable) { |
| 10409 | boolean isPhoneAvailable = false; |
| 10410 | for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) { |
| 10411 | Phone phone = PhoneFactory.getPhone(i); |
| 10412 | if (phone != null) { |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 10413 | phone.setRadioPowerForReason(enable, TelephonyManager.RADIO_POWER_REASON_THERMAL); |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10414 | isPhoneAvailable = true; |
| 10415 | } |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10416 | } |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10417 | |
| 10418 | // return true if successfully informed the phone object about the thermal radio power |
| 10419 | // request. |
| 10420 | return isPhoneAvailable; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10421 | } |
| 10422 | |
| 10423 | private int handleDataThrottlingRequest(int subId, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 10424 | DataThrottlingRequest dataThrottlingRequest, String callingPackage) { |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10425 | boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported( |
| 10426 | TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING); |
| 10427 | if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction() |
| 10428 | != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) { |
| 10429 | throw new IllegalArgumentException("modem does not support data throttling"); |
| 10430 | } |
| 10431 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10432 | // Ensure that radio is on. If not able to power on due to phone being unavailable, return |
| 10433 | // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10434 | if (!setRadioPowerForThermal(true)) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10435 | return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 10436 | } |
| 10437 | |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 10438 | setDataEnabledForReason( |
| 10439 | subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true, callingPackage); |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10440 | |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10441 | if (isDataThrottlingSupported) { |
| 10442 | int thermalMitigationResult = |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10443 | (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId); |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10444 | if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) { |
| 10445 | throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS"); |
| 10446 | } else if (thermalMitigationResult |
| 10447 | == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) { |
Jack Nudelman | 760d096 | 2021-05-20 13:57:30 -0700 | [diff] [blame] | 10448 | log("Modem likely does not support data throttling on secondary carrier. Data " + |
| 10449 | "throttling action = " + dataThrottlingRequest.getDataThrottlingAction()); |
| 10450 | return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10451 | } |
| 10452 | return thermalMitigationResult; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10453 | } |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10454 | |
| 10455 | return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10456 | } |
| 10457 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10458 | private static List<String> getThermalMitigationAllowlist(Context context) { |
| 10459 | if (sThermalMitigationAllowlistedPackages.isEmpty()) { |
| 10460 | for (String pckg : context.getResources() |
| 10461 | .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) { |
| 10462 | sThermalMitigationAllowlistedPackages.add(pckg); |
| 10463 | } |
| 10464 | } |
| 10465 | |
| 10466 | return sThermalMitigationAllowlistedPackages; |
| 10467 | } |
| 10468 | |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 10469 | private boolean isAnyPhoneInEmergencyState() { |
| 10470 | TelecomManager tm = mApp.getSystemService(TelecomManager.class); |
| 10471 | if (tm.isInEmergencyCall()) { |
| 10472 | Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call"); |
| 10473 | return true; |
| 10474 | } |
| 10475 | for (Phone phone : PhoneFactory.getPhones()) { |
| 10476 | if (phone.isInEmergencySmsMode() || phone.isInEcm()) { |
| 10477 | Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = " |
| 10478 | + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = " |
| 10479 | + phone.isInEcm()); |
| 10480 | return true; |
| 10481 | } |
| 10482 | } |
| 10483 | |
| 10484 | return false; |
| 10485 | } |
| 10486 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10487 | /** |
| 10488 | * Used by shell commands to add an authorized package name for thermal mitigation. |
| 10489 | * @param packageName name of package to be allowlisted |
| 10490 | * @param context |
| 10491 | */ |
| 10492 | static void addPackageToThermalMitigationAllowlist(String packageName, Context context) { |
| 10493 | sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context); |
| 10494 | sThermalMitigationAllowlistedPackages.add(packageName); |
| 10495 | } |
| 10496 | |
| 10497 | /** |
| 10498 | * Used by shell commands to remove an authorized package name for thermal mitigation. |
| 10499 | * @param packageName name of package to remove from allowlist |
| 10500 | * @param context |
| 10501 | */ |
| 10502 | static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) { |
| 10503 | sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context); |
| 10504 | sThermalMitigationAllowlistedPackages.remove(packageName); |
| 10505 | } |
| 10506 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10507 | /** |
| 10508 | * Thermal mitigation request to control functionalities at modem. |
| 10509 | * |
| 10510 | * @param subId the id of the subscription. |
| 10511 | * @param thermalMitigationRequest holds all necessary information to be passed down to modem. |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10512 | * @param callingPackage the package name of the calling package. |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10513 | * |
| 10514 | * @return thermalMitigationResult enum as defined in android.telephony.Annotation. |
| 10515 | */ |
| 10516 | @Override |
| 10517 | @ThermalMitigationResult |
| 10518 | public int sendThermalMitigationRequest( |
| 10519 | int subId, |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10520 | ThermalMitigationRequest thermalMitigationRequest, |
| 10521 | String callingPackage) throws IllegalArgumentException { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10522 | enforceModifyPermission(); |
| 10523 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10524 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 10525 | if (!getThermalMitigationAllowlist(getDefaultPhone().getContext()) |
| 10526 | .contains(callingPackage)) { |
| 10527 | throw new SecurityException("Calling package must be configured in the device config. " |
| 10528 | + "calling package: " + callingPackage); |
| 10529 | } |
| 10530 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10531 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 10532 | final long identity = Binder.clearCallingIdentity(); |
| 10533 | |
| 10534 | int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR; |
| 10535 | try { |
| 10536 | int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction(); |
| 10537 | switch (thermalMitigationAction) { |
| 10538 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING: |
| 10539 | thermalMitigationResult = |
| 10540 | handleDataThrottlingRequest(subId, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 10541 | thermalMitigationRequest.getDataThrottlingRequest(), |
| 10542 | callingPackage); |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10543 | break; |
| 10544 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY: |
| 10545 | if (thermalMitigationRequest.getDataThrottlingRequest() != null) { |
| 10546 | throw new IllegalArgumentException("dataThrottlingRequest must be null for " |
| 10547 | + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY"); |
| 10548 | } |
| 10549 | |
| 10550 | // Ensure that radio is on. If not able to power on due to phone being |
| 10551 | // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10552 | if (!setRadioPowerForThermal(true)) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10553 | thermalMitigationResult = |
| 10554 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 10555 | break; |
| 10556 | } |
| 10557 | |
| 10558 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 10559 | false, callingPackage); |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10560 | thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 10561 | break; |
| 10562 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF: |
| 10563 | if (thermalMitigationRequest.getDataThrottlingRequest() != null) { |
| 10564 | throw new IllegalArgumentException("dataThrottlingRequest must be null for" |
| 10565 | + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF"); |
| 10566 | } |
| 10567 | |
| 10568 | TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null); |
| 10569 | if (registry != null) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10570 | Phone phone = getPhone(subId); |
| 10571 | if (phone == null) { |
| 10572 | thermalMitigationResult = |
| 10573 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 10574 | break; |
| 10575 | } |
| 10576 | |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 10577 | TelephonyConnectionService service = |
| 10578 | registry.getTelephonyConnectionService(); |
Jack Nudelman | b30ac30 | 2021-06-17 15:39:58 -0700 | [diff] [blame] | 10579 | if (service != null && service.isEmergencyCallPending()) { |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 10580 | Log.e(LOG_TAG, "An emergency call is pending"); |
| 10581 | thermalMitigationResult = |
| 10582 | TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE; |
| 10583 | break; |
| 10584 | } else if (isAnyPhoneInEmergencyState()) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10585 | thermalMitigationResult = |
| 10586 | TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE; |
| 10587 | break; |
| 10588 | } |
| 10589 | } else { |
| 10590 | thermalMitigationResult = |
| 10591 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 10592 | break; |
| 10593 | } |
| 10594 | |
| 10595 | // Turn radio off. If not able to power off due to phone being unavailable, |
| 10596 | // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10597 | if (!setRadioPowerForThermal(false)) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10598 | thermalMitigationResult = |
| 10599 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 10600 | break; |
| 10601 | } |
| 10602 | thermalMitigationResult = |
| 10603 | TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 10604 | break; |
| 10605 | default: |
| 10606 | throw new IllegalArgumentException("the requested thermalMitigationAction does " |
| 10607 | + "not exist. Requested action: " + thermalMitigationAction); |
| 10608 | } |
| 10609 | } catch (IllegalArgumentException e) { |
| 10610 | throw e; |
| 10611 | } catch (Exception e) { |
| 10612 | Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e); |
| 10613 | thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 10614 | } finally { |
| 10615 | Binder.restoreCallingIdentity(identity); |
| 10616 | } |
| 10617 | |
| 10618 | if (DBG) { |
| 10619 | log("thermalMitigationRequest returning with thermalMitigationResult: " |
| 10620 | + thermalMitigationResult); |
| 10621 | } |
| 10622 | |
| 10623 | return thermalMitigationResult; |
| 10624 | } |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 10625 | |
| 10626 | /** |
| 10627 | * Set the GbaService Package Name that Telephony will bind to. |
| 10628 | * |
| 10629 | * @param subId The sim that the GbaService is associated with. |
| 10630 | * @param packageName The name of the package to be replaced with. |
| 10631 | * @return true if setting the GbaService to bind to succeeded, false if it did not. |
| 10632 | */ |
| 10633 | @Override |
| 10634 | public boolean setBoundGbaServiceOverride(int subId, String packageName) { |
| 10635 | enforceModifyPermission(); |
| 10636 | |
| 10637 | final long identity = Binder.clearCallingIdentity(); |
| 10638 | try { |
| 10639 | return getGbaManager(subId).overrideServicePackage(packageName); |
| 10640 | } finally { |
| 10641 | Binder.restoreCallingIdentity(identity); |
| 10642 | } |
| 10643 | } |
| 10644 | |
| 10645 | /** |
| 10646 | * Return the package name of the currently bound GbaService. |
| 10647 | * |
| 10648 | * @param subId The sim that the GbaService is associated with. |
| 10649 | * @return the package name of the GbaService configuration, null if GBA is not supported. |
| 10650 | */ |
| 10651 | @Override |
| 10652 | public String getBoundGbaService(int subId) { |
| 10653 | enforceReadPrivilegedPermission("getBoundGbaServicePackage"); |
| 10654 | |
| 10655 | final long identity = Binder.clearCallingIdentity(); |
| 10656 | try { |
| 10657 | return getGbaManager(subId).getServicePackage(); |
| 10658 | } finally { |
| 10659 | Binder.restoreCallingIdentity(identity); |
| 10660 | } |
| 10661 | } |
| 10662 | |
| 10663 | /** |
| 10664 | * Set the release time for telephony to unbind GbaService. |
| 10665 | * |
| 10666 | * @param subId The sim that the GbaService is associated with. |
| 10667 | * @param interval The release time to unbind GbaService by millisecond. |
| 10668 | * @return true if setting the GbaService to bind to succeeded, false if it did not. |
| 10669 | */ |
| 10670 | @Override |
| 10671 | public boolean setGbaReleaseTimeOverride(int subId, int interval) { |
| 10672 | enforceModifyPermission(); |
| 10673 | |
| 10674 | final long identity = Binder.clearCallingIdentity(); |
| 10675 | try { |
| 10676 | return getGbaManager(subId).overrideReleaseTime(interval); |
| 10677 | } finally { |
| 10678 | Binder.restoreCallingIdentity(identity); |
| 10679 | } |
| 10680 | } |
| 10681 | |
| 10682 | /** |
| 10683 | * Return the release time for telephony to unbind GbaService. |
| 10684 | * |
| 10685 | * @param subId The sim that the GbaService is associated with. |
| 10686 | * @return The release time to unbind GbaService by millisecond. |
| 10687 | */ |
| 10688 | @Override |
| 10689 | public int getGbaReleaseTime(int subId) { |
| 10690 | enforceReadPrivilegedPermission("getGbaReleaseTime"); |
| 10691 | |
| 10692 | final long identity = Binder.clearCallingIdentity(); |
| 10693 | try { |
| 10694 | return getGbaManager(subId).getReleaseTime(); |
| 10695 | } finally { |
| 10696 | Binder.restoreCallingIdentity(identity); |
| 10697 | } |
| 10698 | } |
| 10699 | |
| 10700 | private GbaManager getGbaManager(int subId) { |
| 10701 | GbaManager instance = GbaManager.getInstance(subId); |
| 10702 | if (instance == null) { |
| 10703 | String packageName = mApp.getResources().getString(R.string.config_gba_package); |
| 10704 | int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time); |
| 10705 | instance = GbaManager.make(mApp, subId, packageName, releaseTime); |
| 10706 | } |
| 10707 | return instance; |
| 10708 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10709 | |
| 10710 | /** |
| 10711 | * indicate whether the device and the carrier can support |
| 10712 | * RCS VoLTE single registration. |
| 10713 | */ |
| 10714 | @Override |
| 10715 | public boolean isRcsVolteSingleRegistrationCapable(int subId) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10716 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 10717 | Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable", |
| 10718 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 10719 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10720 | |
| 10721 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10722 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10723 | } |
| 10724 | |
| 10725 | final long identity = Binder.clearCallingIdentity(); |
| 10726 | try { |
| 10727 | RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance(); |
| 10728 | if (rpm != null) { |
Hui Wang | 67af90e | 2021-06-04 16:57:15 -0700 | [diff] [blame] | 10729 | Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId); |
| 10730 | if (isCapable != null) { |
| 10731 | return isCapable; |
| 10732 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10733 | } |
Hui Wang | 67af90e | 2021-06-04 16:57:15 -0700 | [diff] [blame] | 10734 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE, |
| 10735 | "service is temporarily unavailable."); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10736 | } finally { |
| 10737 | Binder.restoreCallingIdentity(identity); |
| 10738 | } |
| 10739 | } |
| 10740 | |
| 10741 | /** |
| 10742 | * Register RCS provisioning callback. |
| 10743 | */ |
| 10744 | @Override |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10745 | public void registerRcsProvisioningCallback(int subId, |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10746 | IRcsConfigCallback callback) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10747 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10748 | Binder.getCallingUid(), "registerRcsProvisioningCallback", |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10749 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 10750 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10751 | |
| 10752 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10753 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10754 | } |
| 10755 | if (!isImsAvailableOnDevice()) { |
| 10756 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 10757 | "IMS not available on device."); |
| 10758 | } |
| 10759 | |
| 10760 | final long identity = Binder.clearCallingIdentity(); |
| 10761 | try { |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 10762 | if (!RcsProvisioningMonitor.getInstance() |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10763 | .registerRcsProvisioningCallback(subId, callback)) { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 10764 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION, |
| 10765 | "Active subscription not found."); |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 10766 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10767 | } finally { |
| 10768 | Binder.restoreCallingIdentity(identity); |
| 10769 | } |
| 10770 | } |
| 10771 | |
| 10772 | /** |
| 10773 | * Unregister RCS provisioning callback. |
| 10774 | */ |
| 10775 | @Override |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10776 | public void unregisterRcsProvisioningCallback(int subId, |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10777 | IRcsConfigCallback callback) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10778 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10779 | Binder.getCallingUid(), "unregisterRcsProvisioningCallback", |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10780 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 10781 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10782 | |
| 10783 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10784 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10785 | } |
| 10786 | if (!isImsAvailableOnDevice()) { |
| 10787 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 10788 | "IMS not available on device."); |
| 10789 | } |
| 10790 | |
| 10791 | final long identity = Binder.clearCallingIdentity(); |
| 10792 | try { |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 10793 | RcsProvisioningMonitor.getInstance() |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10794 | .unregisterRcsProvisioningCallback(subId, callback); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10795 | } finally { |
| 10796 | Binder.restoreCallingIdentity(identity); |
| 10797 | } |
| 10798 | } |
| 10799 | |
| 10800 | /** |
| 10801 | * trigger RCS reconfiguration. |
| 10802 | */ |
| 10803 | public void triggerRcsReconfiguration(int subId) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10804 | TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(), |
| 10805 | "triggerRcsReconfiguration", |
| 10806 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10807 | |
| 10808 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10809 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10810 | } |
| 10811 | if (!isImsAvailableOnDevice()) { |
| 10812 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 10813 | "IMS not available on device."); |
| 10814 | } |
| 10815 | |
| 10816 | final long identity = Binder.clearCallingIdentity(); |
| 10817 | try { |
| 10818 | RcsProvisioningMonitor.getInstance().requestReconfig(subId); |
| 10819 | } finally { |
| 10820 | Binder.restoreCallingIdentity(identity); |
| 10821 | } |
| 10822 | } |
| 10823 | |
| 10824 | /** |
| 10825 | * Provide the client configuration parameters of the RCS application. |
| 10826 | */ |
| 10827 | public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10828 | TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(), |
| 10829 | "setRcsClientConfiguration", |
| 10830 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10831 | |
| 10832 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10833 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10834 | } |
| 10835 | if (!isImsAvailableOnDevice()) { |
| 10836 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 10837 | "IMS not available on device."); |
| 10838 | } |
| 10839 | |
| 10840 | final long identity = Binder.clearCallingIdentity(); |
| 10841 | |
| 10842 | try { |
| 10843 | IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS); |
| 10844 | if (configBinder == null) { |
| 10845 | Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration"); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 10846 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION, |
| 10847 | "could not find the requested subscription"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10848 | } else { |
| 10849 | configBinder.setRcsClientConfiguration(rcc); |
| 10850 | } |
joonhunshin | 3e15424 | 2021-09-17 06:33:39 +0000 | [diff] [blame] | 10851 | |
| 10852 | RcsStats.getInstance().onRcsClientProvisioningStats(subId, |
| 10853 | RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10854 | } catch (RemoteException e) { |
| 10855 | Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage()); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 10856 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE, |
| 10857 | "service is temporarily unavailable."); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10858 | } finally { |
| 10859 | Binder.restoreCallingIdentity(identity); |
| 10860 | } |
| 10861 | } |
| 10862 | |
| 10863 | /** |
Hui Wang | baaee6a | 2021-02-19 20:45:36 -0800 | [diff] [blame] | 10864 | * Enables or disables the test mode for RCS VoLTE single registration. |
| 10865 | */ |
| 10866 | @Override |
| 10867 | public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) { |
| 10868 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10869 | "setRcsSingleRegistrationTestModeEnabled"); |
| 10870 | |
| 10871 | RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled); |
| 10872 | } |
| 10873 | |
| 10874 | /** |
| 10875 | * Gets the test mode for RCS VoLTE single registration. |
| 10876 | */ |
| 10877 | @Override |
| 10878 | public boolean getRcsSingleRegistrationTestModeEnabled() { |
| 10879 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10880 | "getRcsSingleRegistrationTestModeEnabled"); |
| 10881 | |
| 10882 | return RcsProvisioningMonitor.getInstance().getTestModeEnabled(); |
| 10883 | } |
| 10884 | |
| 10885 | /** |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10886 | * Overrides the config of RCS VoLTE single registration enabled for the device. |
| 10887 | */ |
| 10888 | @Override |
| 10889 | public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) { |
| 10890 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10891 | "setDeviceSingleRegistrationEnabledOverride"); |
| 10892 | enforceModifyPermission(); |
| 10893 | |
| 10894 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 10895 | : Boolean.parseBoolean(enabledStr); |
| 10896 | RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled); |
Brad Ebinger | 49a72b4 | 2021-01-29 00:55:24 +0000 | [diff] [blame] | 10897 | mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10898 | } |
| 10899 | |
| 10900 | /** |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 10901 | * Sends a device to device communication message. Only usable via shell. |
| 10902 | * @param message message to send. |
| 10903 | * @param value message value. |
| 10904 | */ |
| 10905 | @Override |
| 10906 | public void sendDeviceToDeviceMessage(int message, int value) { |
| 10907 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
Tyler Gunn | babbda0 | 2021-02-10 11:05:02 -0800 | [diff] [blame] | 10908 | "sendDeviceToDeviceMessage"); |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 10909 | enforceModifyPermission(); |
| 10910 | |
| 10911 | final long identity = Binder.clearCallingIdentity(); |
| 10912 | try { |
| 10913 | TelephonyConnectionService service = |
| 10914 | TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService(); |
| 10915 | if (service == null) { |
| 10916 | Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call."); |
| 10917 | return; |
| 10918 | } |
| 10919 | service.sendTestDeviceToDeviceMessage(message, value); |
| 10920 | } finally { |
| 10921 | Binder.restoreCallingIdentity(identity); |
| 10922 | } |
| 10923 | } |
| 10924 | |
Tyler Gunn | babbda0 | 2021-02-10 11:05:02 -0800 | [diff] [blame] | 10925 | /** |
| 10926 | * Sets the specified device to device transport active. |
| 10927 | * @param transport The transport to set active. |
| 10928 | */ |
| 10929 | @Override |
| 10930 | public void setActiveDeviceToDeviceTransport(@NonNull String transport) { |
| 10931 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10932 | "setActiveDeviceToDeviceTransport"); |
| 10933 | enforceModifyPermission(); |
| 10934 | |
| 10935 | final long identity = Binder.clearCallingIdentity(); |
| 10936 | try { |
| 10937 | TelephonyConnectionService service = |
| 10938 | TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService(); |
| 10939 | if (service == null) { |
| 10940 | Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call."); |
| 10941 | return; |
| 10942 | } |
| 10943 | service.setActiveDeviceToDeviceTransport(transport); |
| 10944 | } finally { |
| 10945 | Binder.restoreCallingIdentity(identity); |
| 10946 | } |
| 10947 | } |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 10948 | |
Tyler Gunn | d433926 | 2021-05-03 14:46:49 -0700 | [diff] [blame] | 10949 | @Override |
| 10950 | public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) { |
| 10951 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10952 | "setDeviceToDeviceForceEnabled"); |
| 10953 | |
| 10954 | final long identity = Binder.clearCallingIdentity(); |
| 10955 | try { |
| 10956 | Arrays.stream(PhoneFactory.getPhones()).forEach( |
| 10957 | p -> { |
| 10958 | Phone thePhone = p.getImsPhone(); |
| 10959 | if (thePhone != null && thePhone instanceof ImsPhone) { |
| 10960 | ImsPhone imsPhone = (ImsPhone) thePhone; |
| 10961 | CallTracker tracker = imsPhone.getCallTracker(); |
| 10962 | if (tracker != null && tracker instanceof ImsPhoneCallTracker) { |
| 10963 | ImsPhoneCallTracker imsPhoneCallTracker = |
| 10964 | (ImsPhoneCallTracker) tracker; |
| 10965 | imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled); |
| 10966 | } |
| 10967 | } |
| 10968 | } |
| 10969 | ); |
| 10970 | } finally { |
| 10971 | Binder.restoreCallingIdentity(identity); |
| 10972 | } |
| 10973 | } |
| 10974 | |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 10975 | /** |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10976 | * Gets the config of RCS VoLTE single registration enabled for the device. |
| 10977 | */ |
| 10978 | @Override |
| 10979 | public boolean getDeviceSingleRegistrationEnabled() { |
| 10980 | enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled"); |
| 10981 | return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled(); |
| 10982 | } |
| 10983 | |
| 10984 | /** |
| 10985 | * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription. |
| 10986 | */ |
| 10987 | @Override |
| 10988 | public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) { |
| 10989 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10990 | "setCarrierSingleRegistrationEnabledOverride"); |
| 10991 | enforceModifyPermission(); |
| 10992 | |
| 10993 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 10994 | : Boolean.parseBoolean(enabledStr); |
| 10995 | return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled( |
| 10996 | subId, enabled); |
| 10997 | } |
| 10998 | |
| 10999 | /** |
| 11000 | * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription. |
| 11001 | */ |
| 11002 | @Override |
| 11003 | public boolean getCarrierSingleRegistrationEnabled(int subId) { |
| 11004 | enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled"); |
| 11005 | return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId); |
| 11006 | } |
Chiachang Wang | d6d3477 | 2020-12-22 11:38:27 +0800 | [diff] [blame] | 11007 | |
| 11008 | /** |
Hui Wang | b647abe | 2021-02-26 09:33:38 -0800 | [diff] [blame] | 11009 | * Overrides the ims feature validation result |
| 11010 | */ |
| 11011 | @Override |
| 11012 | public boolean setImsFeatureValidationOverride(int subId, String enabledStr) { |
| 11013 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11014 | "setImsFeatureValidationOverride"); |
| 11015 | |
| 11016 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 11017 | : Boolean.parseBoolean(enabledStr); |
| 11018 | return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation( |
| 11019 | subId, enabled); |
| 11020 | } |
| 11021 | |
| 11022 | /** |
| 11023 | * Gets the ims feature validation override value |
| 11024 | */ |
| 11025 | @Override |
| 11026 | public boolean getImsFeatureValidationOverride(int subId) { |
| 11027 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11028 | "getImsFeatureValidationOverride"); |
| 11029 | return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId); |
| 11030 | } |
| 11031 | |
| 11032 | /** |
Chiachang Wang | d6d3477 | 2020-12-22 11:38:27 +0800 | [diff] [blame] | 11033 | * Get the mobile provisioning url that is used to launch a browser to allow users to manage |
| 11034 | * their mobile plan. |
| 11035 | */ |
| 11036 | @Override |
| 11037 | public String getMobileProvisioningUrl() { |
| 11038 | enforceReadPrivilegedPermission("getMobileProvisioningUrl"); |
| 11039 | final long identity = Binder.clearCallingIdentity(); |
| 11040 | try { |
| 11041 | return getDefaultPhone().getMobileProvisioningUrl(); |
| 11042 | } finally { |
| 11043 | Binder.restoreCallingIdentity(identity); |
| 11044 | } |
| 11045 | } |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11046 | |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 11047 | /** |
calvinpan | e4a8a1d | 2021-01-25 13:51:18 +0800 | [diff] [blame] | 11048 | * Get the EAB contact from the EAB database. |
| 11049 | */ |
| 11050 | @Override |
| 11051 | public String getContactFromEab(String contact) { |
| 11052 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab"); |
| 11053 | enforceModifyPermission(); |
| 11054 | final long identity = Binder.clearCallingIdentity(); |
| 11055 | try { |
| 11056 | return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact); |
| 11057 | } finally { |
| 11058 | Binder.restoreCallingIdentity(identity); |
| 11059 | } |
| 11060 | } |
| 11061 | |
| 11062 | /** |
Calvin Pan | a143432 | 2021-07-01 19:27:01 +0800 | [diff] [blame] | 11063 | * Get the EAB capability from the EAB database. |
| 11064 | */ |
| 11065 | @Override |
| 11066 | public String getCapabilityFromEab(String contact) { |
| 11067 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab"); |
| 11068 | enforceModifyPermission(); |
| 11069 | final long identity = Binder.clearCallingIdentity(); |
| 11070 | try { |
| 11071 | return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact); |
| 11072 | } finally { |
| 11073 | Binder.restoreCallingIdentity(identity); |
| 11074 | } |
| 11075 | } |
| 11076 | |
| 11077 | /** |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 11078 | * Remove the EAB contacts from the EAB database. |
| 11079 | */ |
| 11080 | @Override |
| 11081 | public int removeContactFromEab(int subId, String contacts) { |
| 11082 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab"); |
| 11083 | enforceModifyPermission(); |
| 11084 | final long identity = Binder.clearCallingIdentity(); |
| 11085 | try { |
| 11086 | return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext()); |
| 11087 | } finally { |
| 11088 | Binder.restoreCallingIdentity(identity); |
| 11089 | } |
| 11090 | } |
| 11091 | |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11092 | @Override |
James.cf Lin | 4b784aa | 2021-01-31 03:25:15 +0800 | [diff] [blame] | 11093 | public boolean getDeviceUceEnabled() { |
| 11094 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled"); |
| 11095 | final long identity = Binder.clearCallingIdentity(); |
| 11096 | try { |
| 11097 | return mApp.getDeviceUceEnabled(); |
| 11098 | } finally { |
| 11099 | Binder.restoreCallingIdentity(identity); |
| 11100 | } |
| 11101 | } |
| 11102 | |
| 11103 | @Override |
| 11104 | public void setDeviceUceEnabled(boolean isEnabled) { |
| 11105 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled"); |
| 11106 | final long identity = Binder.clearCallingIdentity(); |
| 11107 | try { |
| 11108 | mApp.setDeviceUceEnabled(isEnabled); |
| 11109 | } finally { |
| 11110 | Binder.restoreCallingIdentity(identity); |
| 11111 | } |
| 11112 | } |
| 11113 | |
Brad Ebinger | 14d467f | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 11114 | /** |
| 11115 | * Add new feature tags to the Set used to calculate the capabilities in PUBLISH. |
| 11116 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 11117 | */ |
| 11118 | // Used for SHELL command only right now. |
| 11119 | @Override |
| 11120 | public RcsContactUceCapability addUceRegistrationOverrideShell(int subId, |
| 11121 | List<String> featureTags) { |
| 11122 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11123 | "addUceRegistrationOverrideShell"); |
| 11124 | final long identity = Binder.clearCallingIdentity(); |
| 11125 | try { |
| 11126 | return mApp.imsRcsController.addUceRegistrationOverrideShell(subId, |
| 11127 | new ArraySet<>(featureTags)); |
| 11128 | } catch (ImsException e) { |
| 11129 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 11130 | } finally { |
| 11131 | Binder.restoreCallingIdentity(identity); |
| 11132 | } |
| 11133 | } |
| 11134 | |
| 11135 | /** |
| 11136 | * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH. |
| 11137 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 11138 | */ |
| 11139 | // Used for SHELL command only right now. |
| 11140 | @Override |
| 11141 | public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId, |
| 11142 | List<String> featureTags) { |
| 11143 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11144 | "removeUceRegistrationOverrideShell"); |
| 11145 | final long identity = Binder.clearCallingIdentity(); |
| 11146 | try { |
| 11147 | return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId, |
| 11148 | new ArraySet<>(featureTags)); |
| 11149 | } catch (ImsException e) { |
| 11150 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 11151 | } finally { |
| 11152 | Binder.restoreCallingIdentity(identity); |
| 11153 | } |
| 11154 | } |
| 11155 | |
| 11156 | /** |
| 11157 | * Clear all overrides in the Set used to calculate the capabilities in PUBLISH. |
| 11158 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 11159 | */ |
| 11160 | // Used for SHELL command only right now. |
| 11161 | @Override |
| 11162 | public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) { |
| 11163 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11164 | "clearUceRegistrationOverrideShell"); |
| 11165 | final long identity = Binder.clearCallingIdentity(); |
| 11166 | try { |
| 11167 | return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId); |
| 11168 | } catch (ImsException e) { |
| 11169 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 11170 | } finally { |
| 11171 | Binder.restoreCallingIdentity(identity); |
| 11172 | } |
| 11173 | } |
| 11174 | |
| 11175 | /** |
| 11176 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 11177 | */ |
| 11178 | // Used for SHELL command only right now. |
| 11179 | @Override |
| 11180 | public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) { |
| 11181 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11182 | "getLatestRcsContactUceCapabilityShell"); |
| 11183 | final long identity = Binder.clearCallingIdentity(); |
| 11184 | try { |
| 11185 | return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId); |
| 11186 | } catch (ImsException e) { |
| 11187 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 11188 | } finally { |
| 11189 | Binder.restoreCallingIdentity(identity); |
| 11190 | } |
| 11191 | } |
| 11192 | |
| 11193 | /** |
| 11194 | * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the |
| 11195 | * device does not have an active PUBLISH. |
| 11196 | */ |
| 11197 | // Used for SHELL command only right now. |
| 11198 | @Override |
| 11199 | public String getLastUcePidfXmlShell(int subId) { |
| 11200 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml"); |
| 11201 | final long identity = Binder.clearCallingIdentity(); |
| 11202 | try { |
| 11203 | return mApp.imsRcsController.getLastUcePidfXmlShell(subId); |
| 11204 | } catch (ImsException e) { |
| 11205 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 11206 | } finally { |
| 11207 | Binder.restoreCallingIdentity(identity); |
| 11208 | } |
| 11209 | } |
| 11210 | |
James.cf Lin | e8713a4 | 2021-04-29 16:04:26 +0800 | [diff] [blame] | 11211 | /** |
| 11212 | * Remove UCE requests cannot be sent to the network status. |
| 11213 | */ |
| 11214 | // Used for SHELL command only right now. |
| 11215 | @Override |
| 11216 | public boolean removeUceRequestDisallowedStatus(int subId) { |
| 11217 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus"); |
| 11218 | final long identity = Binder.clearCallingIdentity(); |
| 11219 | try { |
| 11220 | return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId); |
| 11221 | } catch (ImsException e) { |
| 11222 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 11223 | } finally { |
| 11224 | Binder.restoreCallingIdentity(identity); |
| 11225 | } |
| 11226 | } |
| 11227 | |
James.cf Lin | 18bb900 | 2021-05-25 01:37:38 +0800 | [diff] [blame] | 11228 | /** |
| 11229 | * Remove UCE requests cannot be sent to the network status. |
| 11230 | */ |
| 11231 | // Used for SHELL command only. |
| 11232 | @Override |
| 11233 | public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) { |
| 11234 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout"); |
| 11235 | final long identity = Binder.clearCallingIdentity(); |
| 11236 | try { |
| 11237 | return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs); |
| 11238 | } catch (ImsException e) { |
| 11239 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 11240 | } finally { |
| 11241 | Binder.restoreCallingIdentity(identity); |
| 11242 | } |
| 11243 | } |
Brad Ebinger | 14d467f | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 11244 | |
James.cf Lin | 4b784aa | 2021-01-31 03:25:15 +0800 | [diff] [blame] | 11245 | @Override |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11246 | public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request, |
| 11247 | String callingPackage) { |
| 11248 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 11249 | mApp, subId, "setSignalStrengthUpdateRequest"); |
| 11250 | |
| 11251 | final int callingUid = Binder.getCallingUid(); |
| 11252 | // Verify that tha callingPackage belongs to the calling UID |
| 11253 | mApp.getSystemService(AppOpsManager.class) |
| 11254 | .checkPackage(callingUid, callingPackage); |
| 11255 | |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 11256 | validateSignalStrengthUpdateRequest(mApp, request, callingUid); |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11257 | |
| 11258 | final long identity = Binder.clearCallingIdentity(); |
| 11259 | try { |
| 11260 | Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST, |
| 11261 | new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId); |
| 11262 | |
| 11263 | if (result instanceof IllegalStateException) { |
| 11264 | throw (IllegalStateException) result; |
| 11265 | } |
| 11266 | } finally { |
| 11267 | Binder.restoreCallingIdentity(identity); |
| 11268 | } |
| 11269 | } |
| 11270 | |
| 11271 | @Override |
| 11272 | public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request, |
| 11273 | String callingPackage) { |
| 11274 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 11275 | mApp, subId, "clearSignalStrengthUpdateRequest"); |
| 11276 | |
| 11277 | final int callingUid = Binder.getCallingUid(); |
| 11278 | // Verify that tha callingPackage belongs to the calling UID |
| 11279 | mApp.getSystemService(AppOpsManager.class) |
| 11280 | .checkPackage(callingUid, callingPackage); |
| 11281 | |
| 11282 | final long identity = Binder.clearCallingIdentity(); |
| 11283 | try { |
| 11284 | Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST, |
| 11285 | new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId); |
| 11286 | |
| 11287 | if (result instanceof IllegalStateException) { |
| 11288 | throw (IllegalStateException) result; |
| 11289 | } |
| 11290 | } finally { |
| 11291 | Binder.restoreCallingIdentity(identity); |
| 11292 | } |
| 11293 | } |
| 11294 | |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 11295 | private static void validateSignalStrengthUpdateRequest(Context context, |
| 11296 | SignalStrengthUpdateRequest request, int callingUid) { |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11297 | if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) { |
| 11298 | // phone/system process do not have further restriction on request |
| 11299 | return; |
| 11300 | } |
| 11301 | |
| 11302 | // Applications has restrictions on how to use the request: |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 11303 | // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11304 | if (request.isSystemThresholdReportingRequestedWhileIdle()) { |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 11305 | context.enforceCallingOrSelfPermission( |
| 11306 | android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH, |
| 11307 | "validateSignalStrengthUpdateRequest"); |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11308 | } |
| 11309 | |
| 11310 | for (SignalThresholdInfo info : request.getSignalThresholdInfos()) { |
Nagendra Prasad Nagarle Basavaraju | fee544c | 2022-12-07 16:34:52 +0000 | [diff] [blame] | 11311 | // Only system caller can set mHysteresisMs/mIsEnabled. |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11312 | if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11313 | || info.isEnabled()) { |
| 11314 | throw new IllegalArgumentException( |
| 11315 | "Only system can set hide fields in SignalThresholdInfo"); |
| 11316 | } |
| 11317 | |
| 11318 | // Thresholds length for each RAN need in range. This has been validated in |
| 11319 | // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method |
| 11320 | // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds |
| 11321 | final int[] thresholds = info.getThresholds(); |
| 11322 | Objects.requireNonNull(thresholds); |
| 11323 | if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed() |
| 11324 | || thresholds.length |
| 11325 | > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) { |
| 11326 | throw new IllegalArgumentException( |
| 11327 | "thresholds length is out of range: " + thresholds.length); |
| 11328 | } |
| 11329 | } |
| 11330 | } |
SongFerngWang | 8236caa | 2021-01-17 21:51:44 +0800 | [diff] [blame] | 11331 | |
| 11332 | /** |
| 11333 | * Gets the current phone capability. |
| 11334 | * |
| 11335 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 11336 | * @return the PhoneCapability which describes the data connection capability of modem. |
| 11337 | * It's used to evaluate possible phone config change, for example from single |
| 11338 | * SIM device to multi-SIM device. |
| 11339 | */ |
| 11340 | @Override |
| 11341 | public PhoneCapability getPhoneCapability() { |
| 11342 | enforceReadPrivilegedPermission("getPhoneCapability"); |
| 11343 | final long identity = Binder.clearCallingIdentity(); |
| 11344 | try { |
| 11345 | return mPhoneConfigurationManager.getCurrentPhoneCapability(); |
| 11346 | } finally { |
| 11347 | Binder.restoreCallingIdentity(identity); |
| 11348 | } |
| 11349 | } |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 11350 | |
| 11351 | /** |
| 11352 | * Prepare TelephonyManager for an unattended reboot. The reboot is |
| 11353 | * required to be done shortly after the API is invoked. |
| 11354 | */ |
| 11355 | @Override |
| 11356 | @TelephonyManager.PrepareUnattendedRebootResult |
| 11357 | public int prepareForUnattendedReboot() { |
Rafael Higuera Silva | d963064 | 2021-09-20 15:32:01 +0000 | [diff] [blame] | 11358 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 11359 | enforceRebootPermission(); |
| 11360 | |
| 11361 | final long identity = Binder.clearCallingIdentity(); |
| 11362 | try { |
Rafael Higuera Silva | d963064 | 2021-09-20 15:32:01 +0000 | [diff] [blame] | 11363 | return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 11364 | } finally { |
| 11365 | Binder.restoreCallingIdentity(identity); |
| 11366 | } |
| 11367 | } |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 11368 | |
| 11369 | /** |
| 11370 | * Request to get the current slicing configuration including URSP rules and |
| 11371 | * NSSAIs (configured, allowed and rejected). |
| 11372 | * |
| 11373 | * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission. |
| 11374 | */ |
| 11375 | @Override |
| 11376 | public void getSlicingConfig(ResultReceiver callback) { |
Hongbo Zeng | 1b2063d | 2022-02-21 01:33:03 +0000 | [diff] [blame] | 11377 | TelephonyPermissions |
| 11378 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 11379 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, "getSlicingConfig"); |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 11380 | |
| 11381 | final long identity = Binder.clearCallingIdentity(); |
| 11382 | try { |
| 11383 | Phone phone = getDefaultPhone(); |
| 11384 | sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null); |
| 11385 | } finally { |
| 11386 | Binder.restoreCallingIdentity(identity); |
| 11387 | } |
| 11388 | } |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 11389 | |
| 11390 | /** |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 11391 | * Check whether the given premium capability is available for purchase from the carrier. |
| 11392 | * |
| 11393 | * @param capability The premium capability to check. |
| 11394 | * @param subId The subId to check the premium capability for. |
| 11395 | * |
| 11396 | * @return Whether the given premium capability is available to purchase. |
| 11397 | */ |
| 11398 | @Override |
| 11399 | public boolean isPremiumCapabilityAvailableForPurchase(int capability, int subId) { |
| 11400 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 11401 | mApp, "isPremiumCapabilityAvailableForPurchase")) { |
| 11402 | log("Premium capability " |
| 11403 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 11404 | + " is not available for purchase due to missing permissions."); |
| 11405 | throw new SecurityException("isPremiumCapabilityAvailableForPurchase requires " |
| 11406 | + "permission READ_BASIC_PHONE_STATE."); |
| 11407 | } |
| 11408 | |
| 11409 | Phone phone = getPhone(subId); |
Thomas Nguyen | 7216ed6 | 2022-11-29 16:45:31 -0800 | [diff] [blame] | 11410 | if (phone == null) { |
| 11411 | loge("isPremiumCapabilityAvailableForPurchase: phone is null, subId=" + subId); |
| 11412 | return false; |
| 11413 | } |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 11414 | final long identity = Binder.clearCallingIdentity(); |
| 11415 | try { |
Sarah Chin | 46355ba | 2022-11-01 23:51:16 -0700 | [diff] [blame] | 11416 | return SlicePurchaseController.getInstance(phone) |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 11417 | .isPremiumCapabilityAvailableForPurchase(capability); |
| 11418 | } finally { |
| 11419 | Binder.restoreCallingIdentity(identity); |
| 11420 | } |
| 11421 | } |
| 11422 | |
| 11423 | /** |
| 11424 | * Purchase the given premium capability from the carrier. |
| 11425 | * |
| 11426 | * @param capability The premium capability to purchase. |
| 11427 | * @param callback The result of the purchase request. |
| 11428 | * @param subId The subId to purchase the premium capability for. |
| 11429 | */ |
| 11430 | @Override |
| 11431 | public void purchasePremiumCapability(int capability, IIntegerConsumer callback, int subId) { |
| 11432 | log("purchasePremiumCapability: capability=" |
| 11433 | + TelephonyManager.convertPremiumCapabilityToString(capability) + ", caller=" |
| 11434 | + getCurrentPackageName()); |
| 11435 | |
| 11436 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 11437 | mApp, "purchasePremiumCapability")) { |
| 11438 | log("purchasePremiumCapability " |
| 11439 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 11440 | + " failed due to missing permissions."); |
| 11441 | throw new SecurityException("purchasePremiumCapability requires permission " |
| 11442 | + "READ_BASIC_PHONE_STATE."); |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame^] | 11443 | } else if (!TelephonyPermissions.checkInternetPermissionNoThrow( |
| 11444 | mApp, "purchasePremiumCapability")) { |
| 11445 | log("purchasePremiumCapability " |
| 11446 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 11447 | + " failed due to missing permissions."); |
| 11448 | throw new SecurityException("purchasePremiumCapability requires permission INTERNET."); |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 11449 | } |
| 11450 | |
| 11451 | Phone phone = getPhone(subId); |
Sarah Chin | 1969411 | 2022-12-06 15:41:37 -0800 | [diff] [blame] | 11452 | if (phone == null) { |
| 11453 | try { |
| 11454 | int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_REQUEST_FAILED; |
| 11455 | callback.accept(result); |
| 11456 | loge("purchasePremiumCapability: phone is null, subId=" + subId); |
| 11457 | } catch (RemoteException e) { |
| 11458 | String logStr = "Purchase premium capability " |
| 11459 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 11460 | + " failed due to RemoteException handling null phone: " + e; |
| 11461 | if (DBG) log(logStr); |
| 11462 | AnomalyReporter.reportAnomaly( |
| 11463 | UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr); |
| 11464 | } |
| 11465 | return; |
| 11466 | } |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame^] | 11467 | |
| 11468 | String callingProcess; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 11469 | try { |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame^] | 11470 | callingProcess = mApp.getPackageManager().getApplicationInfo( |
| 11471 | getCurrentPackageName(), 0).processName; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 11472 | } catch (PackageManager.NameNotFoundException e) { |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame^] | 11473 | callingProcess = getCurrentPackageName(); |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 11474 | } |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame^] | 11475 | |
| 11476 | boolean isVisible = false; |
| 11477 | ActivityManager am = mApp.getSystemService(ActivityManager.class); |
| 11478 | if (am != null) { |
| 11479 | List<ActivityManager.RunningAppProcessInfo> processes = am.getRunningAppProcesses(); |
| 11480 | if (processes != null) { |
| 11481 | for (ActivityManager.RunningAppProcessInfo process : processes) { |
| 11482 | log("purchasePremiumCapability: process " + process.processName |
| 11483 | + "has importance " + process.importance); |
| 11484 | if (process.processName.equals(callingProcess) && process.importance |
| 11485 | <= ActivityManager.RunningAppProcessInfo.IMPORTANCE_VISIBLE) { |
| 11486 | isVisible = true; |
| 11487 | break; |
| 11488 | } |
| 11489 | } |
| 11490 | } |
| 11491 | } |
| 11492 | |
| 11493 | if (!isVisible) { |
| 11494 | try { |
| 11495 | int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_NOT_FOREGROUND; |
| 11496 | callback.accept(result); |
| 11497 | loge("purchasePremiumCapability: " + callingProcess + " is not in the foreground."); |
| 11498 | } catch (RemoteException e) { |
| 11499 | String logStr = "Purchase premium capability " |
| 11500 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 11501 | + " failed due to RemoteException handling background application: " + e; |
| 11502 | if (DBG) log(logStr); |
| 11503 | AnomalyReporter.reportAnomaly( |
| 11504 | UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr); |
| 11505 | } |
| 11506 | return; |
| 11507 | } |
| 11508 | |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 11509 | sendRequestAsync(CMD_PURCHASE_PREMIUM_CAPABILITY, |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame^] | 11510 | new PurchasePremiumCapabilityArgument(capability, callingProcess, callback), phone, |
| 11511 | null); |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 11512 | } |
| 11513 | |
| 11514 | /** |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 11515 | * Register an IMS connection state callback |
| 11516 | */ |
| 11517 | @Override |
Hunsuk Choi | 89bd22c | 2021-11-01 13:04:54 +0000 | [diff] [blame] | 11518 | public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb, |
| 11519 | String callingPackage) { |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 11520 | if (feature == ImsFeature.FEATURE_MMTEL) { |
| 11521 | // ImsMmTelManager |
| 11522 | // The following also checks READ_PRIVILEGED_PHONE_STATE. |
| 11523 | TelephonyPermissions |
| 11524 | .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 11525 | mApp, subId, "registerImsStateCallback"); |
| 11526 | } else if (feature == ImsFeature.FEATURE_RCS) { |
| 11527 | // ImsRcsManager or SipDelegateManager |
| 11528 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 11529 | Binder.getCallingUid(), "registerImsStateCallback", |
| 11530 | Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
| 11531 | Manifest.permission.READ_PRECISE_PHONE_STATE, |
| 11532 | Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE, |
| 11533 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
| 11534 | } |
| 11535 | |
| 11536 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 11537 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 11538 | "IMS not available on device."); |
| 11539 | } |
| 11540 | |
| 11541 | if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) { |
| 11542 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 11543 | } |
| 11544 | |
| 11545 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 11546 | if (controller == null) { |
| 11547 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 11548 | "IMS not available on device."); |
| 11549 | } |
| 11550 | |
Hunsuk Choi | 89bd22c | 2021-11-01 13:04:54 +0000 | [diff] [blame] | 11551 | if (callingPackage == null) { |
| 11552 | callingPackage = getCurrentPackageName(); |
| 11553 | } |
| 11554 | |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 11555 | final long token = Binder.clearCallingIdentity(); |
| 11556 | try { |
| 11557 | int slotId = getSlotIndexOrException(subId); |
Hunsuk Choi | 89bd22c | 2021-11-01 13:04:54 +0000 | [diff] [blame] | 11558 | controller.registerImsStateCallback(subId, feature, cb, callingPackage); |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 11559 | } catch (ImsException e) { |
| 11560 | throw new ServiceSpecificException(e.getCode()); |
| 11561 | } finally { |
| 11562 | Binder.restoreCallingIdentity(token); |
| 11563 | } |
| 11564 | } |
| 11565 | |
| 11566 | /** |
| 11567 | * Unregister an IMS connection state callback |
| 11568 | */ |
| 11569 | @Override |
| 11570 | public void unregisterImsStateCallback(IImsStateCallback cb) { |
| 11571 | final long token = Binder.clearCallingIdentity(); |
| 11572 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 11573 | if (controller == null) { |
| 11574 | return; |
| 11575 | } |
| 11576 | try { |
| 11577 | controller.unregisterImsStateCallback(cb); |
| 11578 | } finally { |
| 11579 | Binder.restoreCallingIdentity(token); |
| 11580 | } |
| 11581 | } |
Sooraj Sasindran | fae41b3 | 2021-10-26 02:10:05 -0700 | [diff] [blame] | 11582 | |
| 11583 | /** |
| 11584 | * @return {@CellIdentity} last known cell identity {@CellIdentity}. |
| 11585 | * |
| 11586 | * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and |
| 11587 | * com.android.phone.permission.ACCESS_LAST_KNOWN_CELL_ID, otherwise throws |
| 11588 | * SecurityException. |
| 11589 | * If there is current registered network this value will be same as the registered cell |
| 11590 | * identity. If the device goes out of service the previous cell identity is cached and |
| 11591 | * will be returned. If the cache age of the Cell identity is more than 24 hours |
| 11592 | * it will be cleared and null will be returned. |
| 11593 | * |
| 11594 | */ |
| 11595 | @Override |
| 11596 | public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage, |
| 11597 | String callingFeatureId) { |
| 11598 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 11599 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 11600 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 11601 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 11602 | .setCallingPackage(callingPackage) |
| 11603 | .setCallingFeatureId(callingFeatureId) |
| 11604 | .setCallingPid(Binder.getCallingPid()) |
| 11605 | .setCallingUid(Binder.getCallingUid()) |
| 11606 | .setMethod("getLastKnownCellIdentity") |
| 11607 | .setLogAsInfo(true) |
| 11608 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 11609 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 11610 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 11611 | .build()); |
| 11612 | |
| 11613 | boolean hasFinePermission = |
| 11614 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 11615 | if (!hasFinePermission |
| 11616 | || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) { |
| 11617 | throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION " |
Rambo Wang | 918993a | 2022-04-27 09:08:36 -0700 | [diff] [blame] | 11618 | + "and ACCESS_LAST_KNOWN_CELL_ID permission."); |
Sooraj Sasindran | fae41b3 | 2021-10-26 02:10:05 -0700 | [diff] [blame] | 11619 | } |
| 11620 | |
| 11621 | final long identity = Binder.clearCallingIdentity(); |
| 11622 | try { |
| 11623 | Phone phone = getPhone(subId); |
| 11624 | if (phone == null) return null; |
| 11625 | ServiceStateTracker sst = phone.getServiceStateTracker(); |
| 11626 | if (sst == null) return null; |
| 11627 | return sst.getLastKnownCellIdentity(); |
| 11628 | } finally { |
| 11629 | Binder.restoreCallingIdentity(identity); |
| 11630 | } |
| 11631 | } |
Jack Yu | 4c0a550 | 2021-12-03 23:58:26 -0800 | [diff] [blame] | 11632 | |
jimsun | 3b9ccac | 2021-10-26 15:01:23 +0800 | [diff] [blame] | 11633 | /** |
| 11634 | * Sets the modem service class Name that Telephony will bind to. |
| 11635 | * |
| 11636 | * @param serviceName The class name of the modem service. |
| 11637 | * @return true if the operation is succeed, otherwise false. |
| 11638 | */ |
| 11639 | public boolean setModemService(String serviceName) { |
| 11640 | Log.d(LOG_TAG, "setModemService - " + serviceName); |
| 11641 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService"); |
| 11642 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 11643 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 11644 | "setModemService"); |
| 11645 | return mPhoneConfigurationManager.setModemService(serviceName); |
| 11646 | } |
| 11647 | |
| 11648 | /** |
| 11649 | * Return the class name of the currently bounded modem service. |
| 11650 | * |
| 11651 | * @return the class name of the modem service. |
| 11652 | */ |
| 11653 | public String getModemService() { |
| 11654 | String result; |
| 11655 | Log.d(LOG_TAG, "getModemService"); |
| 11656 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService"); |
| 11657 | TelephonyPermissions |
| 11658 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 11659 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 11660 | "getModemService"); |
| 11661 | result = mPhoneConfigurationManager.getModemService(); |
| 11662 | Log.d(LOG_TAG, "result = " + result); |
| 11663 | return result; |
| 11664 | } |
Hunter Knepshield | 2b076fa | 2022-01-19 02:26:22 -0800 | [diff] [blame] | 11665 | |
| 11666 | @Override |
| 11667 | public void setVoiceServiceStateOverride(int subId, boolean hasService, String callingPackage) { |
| 11668 | // Only telecom (and shell, for CTS purposes) is allowed to call this method. |
| 11669 | mApp.enforceCallingOrSelfPermission( |
| 11670 | permission.BIND_TELECOM_CONNECTION_SERVICE, "setVoiceServiceStateOverride"); |
| 11671 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 11672 | |
| 11673 | final long identity = Binder.clearCallingIdentity(); |
| 11674 | try { |
| 11675 | Phone phone = getPhone(subId); |
| 11676 | if (phone == null) return; |
| 11677 | phone.setVoiceServiceStateOverride(hasService); |
| 11678 | } finally { |
| 11679 | Binder.restoreCallingIdentity(identity); |
| 11680 | } |
| 11681 | } |
Muralidhar Reddy | 4e5a801 | 2022-05-11 14:49:00 +0000 | [diff] [blame] | 11682 | |
| 11683 | /** |
| 11684 | * set removable eSIM as default eUICC. |
| 11685 | * |
| 11686 | * @hide |
| 11687 | */ |
| 11688 | @Override |
| 11689 | public void setRemovableEsimAsDefaultEuicc(boolean isDefault, String callingPackage) { |
| 11690 | enforceModifyPermission(); |
| 11691 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 11692 | |
| 11693 | final long identity = Binder.clearCallingIdentity(); |
| 11694 | try { |
| 11695 | UiccController.getInstance().setRemovableEsimAsDefaultEuicc(isDefault); |
| 11696 | } finally { |
| 11697 | Binder.restoreCallingIdentity(identity); |
| 11698 | } |
| 11699 | } |
| 11700 | |
| 11701 | /** |
| 11702 | * Returns whether the removable eSIM is default eUICC or not. |
| 11703 | * |
| 11704 | * @hide |
| 11705 | */ |
| 11706 | @Override |
| 11707 | public boolean isRemovableEsimDefaultEuicc(String callingPackage) { |
| 11708 | enforceReadPrivilegedPermission("isRemovableEsimDefaultEuicc"); |
| 11709 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 11710 | |
| 11711 | final long identity = Binder.clearCallingIdentity(); |
| 11712 | try { |
| 11713 | return UiccController.getInstance().isRemovableEsimDefaultEuicc(); |
| 11714 | } finally { |
| 11715 | Binder.restoreCallingIdentity(identity); |
| 11716 | } |
| 11717 | } |
| 11718 | |
Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame] | 11719 | /** |
| 11720 | * Get the component name of the default app to direct respond-via-message intent for the |
| 11721 | * user associated with this subscription, update the cache if there is no respond-via-message |
| 11722 | * application currently configured for this user. |
| 11723 | * @return component name of the app and class to direct Respond Via Message intent to, or |
| 11724 | * {@code null} if the functionality is not supported. |
| 11725 | * @hide |
| 11726 | */ |
| 11727 | @Override |
| 11728 | public @Nullable ComponentName getDefaultRespondViaMessageApplication(int subId, |
| 11729 | boolean updateIfNeeded) { |
| 11730 | enforceInteractAcrossUsersPermission("getDefaultRespondViaMessageApplication"); |
Muralidhar Reddy | 4e5a801 | 2022-05-11 14:49:00 +0000 | [diff] [blame] | 11731 | |
Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame] | 11732 | Context context = getPhone(subId).getContext(); |
| 11733 | UserHandle userHandle = null; |
| 11734 | final long identity = Binder.clearCallingIdentity(); |
| 11735 | try { |
| 11736 | userHandle = TelephonyUtils.getSubscriptionUserHandle(context, subId); |
| 11737 | } finally { |
| 11738 | Binder.restoreCallingIdentity(identity); |
| 11739 | } |
| 11740 | return SmsApplication.getDefaultRespondViaMessageApplicationAsUser(context, |
| 11741 | updateIfNeeded, userHandle); |
| 11742 | } |
Jack Yu | f5badd9 | 2022-12-08 00:50:53 -0800 | [diff] [blame] | 11743 | |
| 11744 | /** |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 11745 | * Set whether the device is able to connect with null ciphering or integrity |
| 11746 | * algorithms. This is a global setting and will apply to all active subscriptions |
| 11747 | * and all new subscriptions after this. |
| 11748 | * |
| 11749 | * @param enabled when true, null cipher and integrity algorithms are allowed. |
| 11750 | * @hide |
| 11751 | */ |
| 11752 | @Override |
| 11753 | @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 11754 | public void setNullCipherAndIntegrityEnabled(boolean enabled) { |
| 11755 | enforceModifyPermission(); |
| 11756 | checkForNullCipherAndIntegritySupport(); |
| 11757 | |
| 11758 | // Persist the state of our preference. Each GsmCdmaPhone instance is responsible |
| 11759 | // for listening to these preference changes and applying them immediately. |
| 11760 | SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 11761 | editor.putBoolean(Phone.PREF_NULL_CIPHER_AND_INTEGRITY_ENABLED, enabled); |
| 11762 | editor.apply(); |
| 11763 | |
| 11764 | for (Phone phone: PhoneFactory.getPhones()) { |
| 11765 | phone.handleNullCipherEnabledChange(); |
| 11766 | } |
| 11767 | } |
| 11768 | |
| 11769 | |
| 11770 | /** |
| 11771 | * Get whether the device is able to connect with null ciphering or integrity |
| 11772 | * algorithms. Note that this retrieves the phone-global preference and not |
| 11773 | * the state of the radio. |
| 11774 | * |
| 11775 | * @throws SecurityException if {@link permission#MODIFY_PHONE_STATE} is not satisfied |
| 11776 | * @throws UnsupportedOperationException if the device does not support the minimum HAL |
| 11777 | * version for this feature. |
| 11778 | * @hide |
| 11779 | */ |
| 11780 | @Override |
| 11781 | @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) |
| 11782 | public boolean isNullCipherAndIntegrityPreferenceEnabled() { |
| 11783 | enforceReadPermission(); |
| 11784 | checkForNullCipherAndIntegritySupport(); |
| 11785 | return getDefaultPhone().getNullCipherAndIntegrityEnabledPreference(); |
| 11786 | } |
| 11787 | |
| 11788 | private void checkForNullCipherAndIntegritySupport() { |
| 11789 | if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_NULL_CIPHER_AND_INTEGRITY_VERSION) { |
| 11790 | throw new UnsupportedOperationException( |
| 11791 | "Null cipher and integrity operations require HAL 2.1 or above"); |
| 11792 | } |
Gil Cukierman | 92cc7db | 2023-01-06 19:25:53 +0000 | [diff] [blame] | 11793 | if (!getDefaultPhone().isNullCipherAndIntegritySupported()) { |
| 11794 | throw new UnsupportedOperationException( |
| 11795 | "Null cipher and integrity operations unsupported by modem"); |
| 11796 | } |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 11797 | } |
| 11798 | |
| 11799 | /** |
Jack Yu | f5badd9 | 2022-12-08 00:50:53 -0800 | [diff] [blame] | 11800 | * Get the SIM state for the slot index. |
| 11801 | * For Remote-SIMs, this method returns {@link IccCardConstants.State#UNKNOWN} |
| 11802 | * |
| 11803 | * @return SIM state as the ordinal of {@link IccCardConstants.State} |
| 11804 | */ |
| 11805 | @Override |
| 11806 | @SimState |
| 11807 | public int getSimStateForSlotIndex(int slotIndex) { |
| 11808 | IccCardConstants.State simState; |
| 11809 | if (slotIndex < 0) { |
| 11810 | simState = IccCardConstants.State.UNKNOWN; |
| 11811 | } else { |
| 11812 | Phone phone = null; |
| 11813 | try { |
| 11814 | phone = PhoneFactory.getPhone(slotIndex); |
| 11815 | } catch (IllegalStateException e) { |
| 11816 | // ignore |
| 11817 | } |
| 11818 | if (phone == null) { |
| 11819 | simState = IccCardConstants.State.UNKNOWN; |
| 11820 | } else { |
| 11821 | IccCard icc = phone.getIccCard(); |
| 11822 | if (icc == null) { |
| 11823 | simState = IccCardConstants.State.UNKNOWN; |
| 11824 | } else { |
| 11825 | simState = icc.getState(); |
| 11826 | } |
| 11827 | } |
| 11828 | } |
| 11829 | return simState.ordinal(); |
| 11830 | } |
Hui Wang | 9b5793a | 2022-12-05 14:38:06 -0600 | [diff] [blame] | 11831 | |
| 11832 | /** |
| 11833 | * Get current cell broadcast ranges. |
| 11834 | */ |
| 11835 | @Override |
| 11836 | @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS) |
| 11837 | public List<CellBroadcastIdRange> getCellBroadcastIdRanges(int subId) { |
| 11838 | mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS, |
| 11839 | "getCellBroadcastIdRanges"); |
| 11840 | final long identity = Binder.clearCallingIdentity(); |
| 11841 | try { |
| 11842 | return getPhone(subId).getCellBroadcastIdRanges(); |
| 11843 | } finally { |
| 11844 | Binder.restoreCallingIdentity(identity); |
| 11845 | } |
| 11846 | } |
| 11847 | |
| 11848 | /** |
| 11849 | * Set reception of cell broadcast messages with the list of the given ranges |
| 11850 | * |
| 11851 | * @param ranges the list of {@link CellBroadcastIdRange} to be enabled |
| 11852 | */ |
| 11853 | @Override |
| 11854 | @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS) |
| 11855 | public void setCellBroadcastIdRanges(int subId, @NonNull List<CellBroadcastIdRange> ranges, |
| 11856 | @Nullable IIntegerConsumer callback) { |
| 11857 | mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS, |
| 11858 | "setCellBroadcastIdRanges"); |
| 11859 | final long identity = Binder.clearCallingIdentity(); |
| 11860 | try { |
| 11861 | Phone phone = getPhoneFromSubId(subId); |
| 11862 | if (DBG) { |
| 11863 | log("setCellBroadcastIdRanges for subId :" + subId + ", phone:" + phone); |
| 11864 | } |
| 11865 | phone.setCellBroadcastIdRanges(ranges, result -> { |
| 11866 | if (callback != null) { |
| 11867 | try { |
| 11868 | callback.accept(result); |
| 11869 | } catch (RemoteException e) { |
| 11870 | Log.w(LOG_TAG, "setCellBroadcastIdRanges: callback not available."); |
| 11871 | } |
| 11872 | } |
| 11873 | }); |
| 11874 | } finally { |
| 11875 | Binder.restoreCallingIdentity(identity); |
| 11876 | } |
| 11877 | } |
Hunsuk Choi | 42cc62a | 2022-10-16 06:03:40 +0000 | [diff] [blame] | 11878 | |
| 11879 | /** |
| 11880 | * Returns whether the device supports the domain selection service. |
| 11881 | * |
| 11882 | * @return {@code true} if the device supports the domain selection service. |
| 11883 | */ |
| 11884 | @Override |
| 11885 | public boolean isDomainSelectionSupported() { |
| 11886 | mApp.enforceCallingOrSelfPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
| 11887 | "isDomainSelectionSupported"); |
| 11888 | |
| 11889 | final long identity = Binder.clearCallingIdentity(); |
| 11890 | try { |
| 11891 | return DomainSelectionResolver.getInstance().isDomainSelectionSupported(); |
| 11892 | } finally { |
| 11893 | Binder.restoreCallingIdentity(identity); |
| 11894 | } |
| 11895 | } |
arunvoddu | d5c6ce0 | 2022-12-11 06:03:12 +0000 | [diff] [blame] | 11896 | |
| 11897 | /** |
| 11898 | * Check whether the caller (or self, if not processing an IPC) can read device identifiers. |
| 11899 | * |
| 11900 | * <p>This method behaves in one of the following ways: |
| 11901 | * <ul> |
| 11902 | * <li>return true : if the calling package has the appop permission {@link |
| 11903 | * Manifest.permission#USE_ICC_AUTH_WITH_DEVICE_IDENTIFIER} in the manifest </> |
| 11904 | * <li>return true : if any one subscription has the READ_PRIVILEGED_PHONE_STATE |
| 11905 | * permission, the calling package passes a DevicePolicyManager Device Owner / Profile |
| 11906 | * Owner device identifier access check, or the calling package has carrier privileges</> |
| 11907 | * <li>throw SecurityException: if the caller does not meet any of the requirements. |
| 11908 | * </ul> |
| 11909 | */ |
| 11910 | private static boolean checkCallingOrSelfReadDeviceIdentifiersForAnySub(Context context, |
| 11911 | String callingPackage, @Nullable String callingFeatureId, String message) { |
| 11912 | for (Phone phone : PhoneFactory.getPhones()) { |
| 11913 | if (TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(context, |
| 11914 | phone.getSubId(), callingPackage, callingFeatureId, message)) { |
| 11915 | return true; |
| 11916 | } |
| 11917 | } |
| 11918 | return false; |
| 11919 | } |
| 11920 | } |