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; |
Jack Yu | e37dd26 | 2022-12-16 11:53:37 -0800 | [diff] [blame] | 398 | private final 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 | |
Gary Jian | 76280a4 | 2022-12-07 16:18:33 +0800 | [diff] [blame] | 440 | private static final int MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS = 50; |
| 441 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 442 | /** |
| 443 | * With support for MEP(multiple enabled profile) in Android T, a SIM card can have more than |
| 444 | * one ICCID active at the same time. |
| 445 | * Apps should use below API signatures if targeting SDK is T and beyond. |
| 446 | * |
| 447 | * @hide |
| 448 | */ |
| 449 | @ChangeId |
| 450 | @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU) |
| 451 | public static final long GET_API_SIGNATURES_FROM_UICC_PORT_INFO = 202110963L; |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 452 | |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 453 | /** |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 454 | * Apps targeting on Android T and beyond will get exception whenever icc close channel |
| 455 | * operation fails. |
| 456 | */ |
| 457 | @ChangeId |
| 458 | @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU) |
| 459 | public static final long ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE = 208739934L; |
| 460 | |
| 461 | /** |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 462 | * A request object to use for transmitting data to an ICC. |
| 463 | */ |
| 464 | private static final class IccAPDUArgument { |
| 465 | public int channel, cla, command, p1, p2, p3; |
| 466 | public String data; |
| 467 | |
| 468 | public IccAPDUArgument(int channel, int cla, int command, |
| 469 | int p1, int p2, int p3, String data) { |
| 470 | this.channel = channel; |
| 471 | this.cla = cla; |
| 472 | this.command = command; |
| 473 | this.p1 = p1; |
| 474 | this.p2 = p2; |
| 475 | this.p3 = p3; |
| 476 | this.data = data; |
| 477 | } |
| 478 | } |
| 479 | |
| 480 | /** |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 481 | * A request object to use for transmitting data to an ICC. |
| 482 | */ |
| 483 | private static final class ManualNetworkSelectionArgument { |
| 484 | public OperatorInfo operatorInfo; |
| 485 | public boolean persistSelection; |
| 486 | |
| 487 | public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) { |
| 488 | this.operatorInfo = operatorInfo; |
| 489 | this.persistSelection = persistSelection; |
| 490 | } |
| 491 | } |
| 492 | |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 493 | private static final class PurchasePremiumCapabilityArgument { |
| 494 | public @TelephonyManager.PremiumCapability int capability; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 495 | public @NonNull IIntegerConsumer callback; |
| 496 | |
| 497 | PurchasePremiumCapabilityArgument(@TelephonyManager.PremiumCapability int capability, |
Sarah Chin | b8218c2 | 2023-01-04 13:35:29 -0800 | [diff] [blame] | 498 | @NonNull IIntegerConsumer callback) { |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 499 | this.capability = capability; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 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); |
Gary Jian | 76280a4 | 2022-12-07 16:18:33 +0800 | [diff] [blame] | 1471 | } else { |
| 1472 | loge("queryModemActivityInfo: invalid response"); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1473 | } |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 1474 | // This is needed to decouple ret from mLastModemActivityInfo |
| 1475 | // We don't want to return mLastModemActivityInfo which is updated |
| 1476 | // inside mergeModemActivityInfo() |
| 1477 | ret = new ModemActivityInfo( |
| 1478 | mLastModemActivityInfo.getTimestampMillis(), |
| 1479 | mLastModemActivityInfo.getSleepTimeMillis(), |
| 1480 | mLastModemActivityInfo.getIdleTimeMillis(), |
| 1481 | deepCopyModemActivitySpecificInfo(mLastModemActivitySpecificInfo)); |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1482 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1483 | } else { |
| 1484 | if (ar.result == null) { |
| 1485 | loge("queryModemActivityInfo: Empty response"); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1486 | error = TelephonyManager.ModemActivityInfoException |
| 1487 | .ERROR_INVALID_INFO_RECEIVED; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1488 | } else if (ar.exception instanceof CommandException) { |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1489 | loge("queryModemActivityInfo: CommandException: " + ar.exception); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1490 | error = TelephonyManager.ModemActivityInfoException |
| 1491 | .ERROR_MODEM_RESPONSE_ERROR; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1492 | } else { |
| 1493 | loge("queryModemActivityInfo: Unknown exception"); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1494 | error = TelephonyManager.ModemActivityInfoException |
| 1495 | .ERROR_UNKNOWN; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1496 | } |
| 1497 | } |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1498 | Bundle bundle = new Bundle(); |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 1499 | if (ret != null) { |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1500 | bundle.putParcelable( |
| 1501 | TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 1502 | ret); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1503 | } else { |
| 1504 | bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error); |
| 1505 | } |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1506 | result.send(0, bundle); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1507 | notifyRequester(request); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1508 | break; |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1509 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1510 | |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1511 | case CMD_SET_ALLOWED_CARRIERS: |
| 1512 | request = (MainThreadRequest) msg.obj; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1513 | CarrierRestrictionRules argument = |
| 1514 | (CarrierRestrictionRules) request.argument; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1515 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request); |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1516 | defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1517 | break; |
| 1518 | |
| 1519 | case EVENT_SET_ALLOWED_CARRIERS_DONE: |
| 1520 | ar = (AsyncResult) msg.obj; |
| 1521 | request = (MainThreadRequest) ar.userObj; |
| 1522 | if (ar.exception == null && ar.result != null) { |
| 1523 | request.result = ar.result; |
| 1524 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1525 | request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR; |
| 1526 | if (ar.exception instanceof CommandException) { |
| 1527 | loge("setAllowedCarriers: CommandException: " + ar.exception); |
| 1528 | CommandException.Error error = |
| 1529 | ((CommandException) (ar.exception)).getCommandError(); |
| 1530 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1531 | request.result = |
| 1532 | TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED; |
| 1533 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1534 | } else { |
| 1535 | loge("setAllowedCarriers: Unknown exception"); |
| 1536 | } |
| 1537 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1538 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1539 | break; |
| 1540 | |
| 1541 | case CMD_GET_ALLOWED_CARRIERS: |
| 1542 | request = (MainThreadRequest) msg.obj; |
| 1543 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1544 | defaultPhone.getAllowedCarriers(onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1545 | break; |
| 1546 | |
| 1547 | case EVENT_GET_ALLOWED_CARRIERS_DONE: |
| 1548 | ar = (AsyncResult) msg.obj; |
| 1549 | request = (MainThreadRequest) ar.userObj; |
| 1550 | if (ar.exception == null && ar.result != null) { |
| 1551 | request.result = ar.result; |
| 1552 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1553 | request.result = new IllegalStateException( |
| 1554 | "Failed to get carrier restrictions"); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1555 | if (ar.result == null) { |
| 1556 | loge("getAllowedCarriers: Empty response"); |
| 1557 | } else if (ar.exception instanceof CommandException) { |
| 1558 | loge("getAllowedCarriers: CommandException: " + |
| 1559 | ar.exception); |
| 1560 | } else { |
| 1561 | loge("getAllowedCarriers: Unknown exception"); |
| 1562 | } |
| 1563 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1564 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1565 | break; |
| 1566 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1567 | case EVENT_GET_FORBIDDEN_PLMNS_DONE: |
| 1568 | ar = (AsyncResult) msg.obj; |
| 1569 | request = (MainThreadRequest) ar.userObj; |
| 1570 | if (ar.exception == null && ar.result != null) { |
| 1571 | request.result = ar.result; |
| 1572 | } else { |
| 1573 | request.result = new IllegalArgumentException( |
| 1574 | "Failed to retrieve Forbidden Plmns"); |
| 1575 | if (ar.result == null) { |
| 1576 | loge("getForbiddenPlmns: Empty response"); |
| 1577 | } else { |
| 1578 | loge("getForbiddenPlmns: Unknown exception"); |
| 1579 | } |
| 1580 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1581 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1582 | break; |
| 1583 | |
| 1584 | case CMD_GET_FORBIDDEN_PLMNS: |
| 1585 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1586 | uiccPort = getUiccPortFromRequest(request); |
| 1587 | if (uiccPort == null) { |
| 1588 | loge("getForbiddenPlmns() UiccPort is null"); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1589 | request.result = new IllegalArgumentException( |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1590 | "getForbiddenPlmns() UiccPort is null"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1591 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1592 | break; |
| 1593 | } |
| 1594 | Integer appType = (Integer) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1595 | UiccCardApplication uiccApp = uiccPort.getApplicationByType(appType); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1596 | if (uiccApp == null) { |
| 1597 | loge("getForbiddenPlmns() no app with specified type -- " |
| 1598 | + appType); |
| 1599 | request.result = new IllegalArgumentException("Failed to get UICC App"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1600 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1601 | break; |
| 1602 | } else { |
| 1603 | if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid() |
| 1604 | + " specified type -- " + appType); |
| 1605 | } |
| 1606 | onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request); |
| 1607 | ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns( |
| 1608 | onCompleted); |
| 1609 | break; |
| 1610 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1611 | case CMD_SWITCH_SLOTS: |
| 1612 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 1613 | List<UiccSlotMapping> slotMapping = (List<UiccSlotMapping>) request.argument; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1614 | onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 1615 | UiccController.getInstance().switchSlots(slotMapping, onCompleted); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1616 | break; |
| 1617 | |
| 1618 | case EVENT_SWITCH_SLOTS_DONE: |
| 1619 | ar = (AsyncResult) msg.obj; |
| 1620 | request = (MainThreadRequest) ar.userObj; |
| 1621 | request.result = (ar.exception == null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1622 | notifyRequester(request); |
| 1623 | break; |
| 1624 | case CMD_GET_NETWORK_SELECTION_MODE: |
| 1625 | request = (MainThreadRequest) msg.obj; |
| 1626 | onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request); |
| 1627 | getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted); |
| 1628 | break; |
| 1629 | |
| 1630 | case EVENT_GET_NETWORK_SELECTION_MODE_DONE: |
| 1631 | ar = (AsyncResult) msg.obj; |
| 1632 | request = (MainThreadRequest) ar.userObj; |
| 1633 | if (ar.exception != null) { |
| 1634 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 1635 | } else { |
| 1636 | int mode = ((int[]) ar.result)[0]; |
| 1637 | if (mode == 0) { |
| 1638 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO; |
| 1639 | } else { |
| 1640 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL; |
| 1641 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1642 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1643 | notifyRequester(request); |
| 1644 | break; |
| 1645 | case CMD_GET_CDMA_ROAMING_MODE: |
| 1646 | request = (MainThreadRequest) msg.obj; |
| 1647 | onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request); |
| 1648 | getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted); |
| 1649 | break; |
| 1650 | case EVENT_GET_CDMA_ROAMING_MODE_DONE: |
| 1651 | ar = (AsyncResult) msg.obj; |
| 1652 | request = (MainThreadRequest) ar.userObj; |
| 1653 | if (ar.exception != null) { |
| 1654 | request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT; |
| 1655 | } else { |
| 1656 | request.result = ((int[]) ar.result)[0]; |
| 1657 | } |
| 1658 | notifyRequester(request); |
| 1659 | break; |
| 1660 | case CMD_SET_CDMA_ROAMING_MODE: |
| 1661 | request = (MainThreadRequest) msg.obj; |
| 1662 | onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request); |
| 1663 | int mode = (int) request.argument; |
| 1664 | getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted); |
| 1665 | break; |
| 1666 | case EVENT_SET_CDMA_ROAMING_MODE_DONE: |
| 1667 | ar = (AsyncResult) msg.obj; |
| 1668 | request = (MainThreadRequest) ar.userObj; |
| 1669 | request.result = ar.exception == null; |
| 1670 | notifyRequester(request); |
| 1671 | break; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 1672 | case CMD_GET_CDMA_SUBSCRIPTION_MODE: |
| 1673 | request = (MainThreadRequest) msg.obj; |
| 1674 | onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1675 | getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted); |
| 1676 | break; |
| 1677 | case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1678 | ar = (AsyncResult) msg.obj; |
| 1679 | request = (MainThreadRequest) ar.userObj; |
| 1680 | if (ar.exception != null) { |
| 1681 | request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM; |
| 1682 | } else { |
| 1683 | request.result = ((int[]) ar.result)[0]; |
| 1684 | } |
| 1685 | notifyRequester(request); |
| 1686 | break; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1687 | case CMD_SET_CDMA_SUBSCRIPTION_MODE: |
| 1688 | request = (MainThreadRequest) msg.obj; |
| 1689 | onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1690 | int subscriptionMode = (int) request.argument; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 1691 | getPhoneFromRequest(request).setCdmaSubscriptionMode( |
| 1692 | subscriptionMode, onCompleted); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1693 | break; |
| 1694 | case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1695 | ar = (AsyncResult) msg.obj; |
| 1696 | request = (MainThreadRequest) ar.userObj; |
| 1697 | request.result = ar.exception == null; |
| 1698 | notifyRequester(request); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1699 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1700 | case CMD_GET_ALL_CELL_INFO: |
| 1701 | request = (MainThreadRequest) msg.obj; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1702 | onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1703 | request.phone.requestCellInfoUpdate(request.workSource, onCompleted); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1704 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1705 | case EVENT_GET_ALL_CELL_INFO_DONE: |
| 1706 | ar = (AsyncResult) msg.obj; |
| 1707 | request = (MainThreadRequest) ar.userObj; |
Nathan Harold | 8d0f174 | 2018-10-02 12:14:47 -0700 | [diff] [blame] | 1708 | // If a timeout occurs, the response will be null |
| 1709 | request.result = (ar.exception == null && ar.result != null) |
| 1710 | ? ar.result : new ArrayList<CellInfo>(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1711 | synchronized (request) { |
| 1712 | request.notifyAll(); |
| 1713 | } |
| 1714 | break; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1715 | case CMD_REQUEST_CELL_INFO_UPDATE: |
| 1716 | request = (MainThreadRequest) msg.obj; |
| 1717 | request.phone.requestCellInfoUpdate(request.workSource, |
| 1718 | obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request)); |
| 1719 | break; |
| 1720 | case EVENT_REQUEST_CELL_INFO_UPDATE_DONE: |
| 1721 | ar = (AsyncResult) msg.obj; |
| 1722 | request = (MainThreadRequest) ar.userObj; |
| 1723 | ICellInfoCallback cb = (ICellInfoCallback) request.argument; |
| 1724 | try { |
| 1725 | if (ar.exception != null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1726 | Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception); |
Meng Wang | d8921f4 | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1727 | cb.onError( |
| 1728 | TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR, |
| 1729 | ar.exception.getClass().getName(), |
| 1730 | ar.exception.toString()); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1731 | } else if (ar.result == null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1732 | Log.w(LOG_TAG, "Timeout Waiting for CellInfo!"); |
Meng Wang | d8921f4 | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1733 | cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1734 | } else { |
| 1735 | // use the result as returned |
| 1736 | cb.onCellInfo((List<CellInfo>) ar.result); |
| 1737 | } |
| 1738 | } catch (RemoteException re) { |
| 1739 | Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException"); |
| 1740 | } |
| 1741 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1742 | case CMD_GET_CELL_LOCATION: { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1743 | request = (MainThreadRequest) msg.obj; |
| 1744 | WorkSource ws = (WorkSource) request.argument; |
| 1745 | Phone phone = getPhoneFromRequest(request); |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1746 | phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request)); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1747 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1748 | } |
| 1749 | case EVENT_GET_CELL_LOCATION_DONE: { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1750 | ar = (AsyncResult) msg.obj; |
| 1751 | request = (MainThreadRequest) ar.userObj; |
| 1752 | if (ar.exception == null) { |
| 1753 | request.result = ar.result; |
| 1754 | } else { |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1755 | Phone phone = getPhoneFromRequest(request); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1756 | request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1757 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1758 | } |
| 1759 | |
| 1760 | synchronized (request) { |
| 1761 | request.notifyAll(); |
| 1762 | } |
| 1763 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1764 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1765 | case CMD_MODEM_REBOOT: |
| 1766 | request = (MainThreadRequest) msg.obj; |
| 1767 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1768 | defaultPhone.rebootModem(onCompleted); |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1769 | break; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1770 | case EVENT_CMD_MODEM_REBOOT_DONE: |
| 1771 | handleNullReturnEvent(msg, "rebootModem"); |
| 1772 | break; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1773 | case CMD_REQUEST_ENABLE_MODEM: |
| 1774 | request = (MainThreadRequest) msg.obj; |
| 1775 | boolean enable = (boolean) request.argument; |
| 1776 | onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1777 | onCompleted.arg1 = enable ? 1 : 0; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1778 | PhoneConfigurationManager.getInstance() |
| 1779 | .enablePhone(request.phone, enable, onCompleted); |
| 1780 | break; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1781 | case EVENT_ENABLE_MODEM_DONE: { |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1782 | ar = (AsyncResult) msg.obj; |
| 1783 | request = (MainThreadRequest) ar.userObj; |
| 1784 | request.result = (ar.exception == null); |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1785 | int phoneId = request.phone.getPhoneId(); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1786 | //update the cache as modem status has changed |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1787 | if ((boolean) request.result) { |
| 1788 | mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1); |
| 1789 | updateModemStateMetrics(); |
| 1790 | } else { |
| 1791 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1792 | + ar.exception); |
| 1793 | } |
| 1794 | notifyRequester(request); |
| 1795 | break; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1796 | } |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1797 | case CMD_GET_MODEM_STATUS: |
| 1798 | request = (MainThreadRequest) msg.obj; |
| 1799 | onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request); |
| 1800 | PhoneConfigurationManager.getInstance() |
| 1801 | .getPhoneStatusFromModem(request.phone, onCompleted); |
| 1802 | break; |
| 1803 | case EVENT_GET_MODEM_STATUS_DONE: |
| 1804 | ar = (AsyncResult) msg.obj; |
| 1805 | request = (MainThreadRequest) ar.userObj; |
| 1806 | int id = request.phone.getPhoneId(); |
| 1807 | if (ar.exception == null && ar.result != null) { |
| 1808 | request.result = ar.result; |
| 1809 | //update the cache as modem status has changed |
| 1810 | mPhoneConfigurationManager.addToPhoneStatusCache(id, |
| 1811 | (boolean) request.result); |
| 1812 | } else { |
| 1813 | // Return true if modem status cannot be retrieved. For most cases, |
| 1814 | // modem status is on. And for older version modems, GET_MODEM_STATUS |
| 1815 | // and disable modem are not supported. Modem is always on. |
| 1816 | // TODO: this should be fixed in R to support a third |
| 1817 | // status UNKNOWN b/131631629 |
| 1818 | request.result = true; |
| 1819 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1820 | + ar.exception); |
| 1821 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1822 | notifyRequester(request); |
| 1823 | break; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 1824 | case CMD_SET_SYSTEM_SELECTION_CHANNELS: { |
| 1825 | request = (MainThreadRequest) msg.obj; |
| 1826 | onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request); |
| 1827 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 1828 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 1829 | request.phone.setSystemSelectionChannels(args.first, onCompleted); |
| 1830 | break; |
| 1831 | } |
| 1832 | case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: { |
| 1833 | ar = (AsyncResult) msg.obj; |
| 1834 | request = (MainThreadRequest) ar.userObj; |
| 1835 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 1836 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 1837 | args.second.accept(ar.exception == null); |
| 1838 | notifyRequester(request); |
| 1839 | break; |
| 1840 | } |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1841 | case CMD_GET_SYSTEM_SELECTION_CHANNELS: { |
| 1842 | request = (MainThreadRequest) msg.obj; |
| 1843 | onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request); |
| 1844 | Phone phone = getPhoneFromRequest(request); |
| 1845 | if (phone != null) { |
| 1846 | phone.getSystemSelectionChannels(onCompleted); |
| 1847 | } else { |
| 1848 | loge("getSystemSelectionChannels: No phone object"); |
| 1849 | request.result = new ArrayList<RadioAccessSpecifier>(); |
| 1850 | notifyRequester(request); |
| 1851 | } |
| 1852 | break; |
| 1853 | } |
| 1854 | case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE: |
| 1855 | ar = (AsyncResult) msg.obj; |
| 1856 | request = (MainThreadRequest) ar.userObj; |
| 1857 | if (ar.exception == null && ar.result != null) { |
| 1858 | request.result = ar.result; |
| 1859 | } else { |
Sarah Chin | 428d1d6 | 2021-03-13 03:17:40 -0800 | [diff] [blame] | 1860 | request.result = new IllegalStateException( |
| 1861 | "Failed to retrieve system selecton channels"); |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1862 | if (ar.result == null) { |
| 1863 | loge("getSystemSelectionChannels: Empty response"); |
| 1864 | } else { |
| 1865 | loge("getSystemSelectionChannels: Unknown exception"); |
| 1866 | } |
| 1867 | } |
| 1868 | notifyRequester(request); |
| 1869 | break; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1870 | case EVENT_SET_FORBIDDEN_PLMNS_DONE: |
| 1871 | ar = (AsyncResult) msg.obj; |
| 1872 | request = (MainThreadRequest) ar.userObj; |
| 1873 | if (ar.exception == null && ar.result != null) { |
| 1874 | request.result = ar.result; |
| 1875 | } else { |
| 1876 | request.result = -1; |
| 1877 | loge("Failed to set Forbidden Plmns"); |
| 1878 | if (ar.result == null) { |
| 1879 | loge("setForbidenPlmns: Empty response"); |
| 1880 | } else if (ar.exception != null) { |
| 1881 | loge("setForbiddenPlmns: Exception: " + ar.exception); |
| 1882 | request.result = -1; |
| 1883 | } else { |
| 1884 | loge("setForbiddenPlmns: Unknown exception"); |
| 1885 | } |
| 1886 | } |
| 1887 | notifyRequester(request); |
| 1888 | break; |
| 1889 | case CMD_SET_FORBIDDEN_PLMNS: |
| 1890 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1891 | uiccPort = getUiccPortFromRequest(request); |
| 1892 | if (uiccPort == null) { |
| 1893 | loge("setForbiddenPlmns: UiccPort is null"); |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1894 | request.result = -1; |
| 1895 | notifyRequester(request); |
| 1896 | break; |
| 1897 | } |
| 1898 | Pair<Integer, List<String>> setFplmnsArgs = |
| 1899 | (Pair<Integer, List<String>>) request.argument; |
| 1900 | appType = setFplmnsArgs.first; |
| 1901 | List<String> fplmns = setFplmnsArgs.second; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1902 | uiccApp = uiccPort.getApplicationByType(appType); |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1903 | if (uiccApp == null) { |
| 1904 | loge("setForbiddenPlmns: no app with specified type -- " + appType); |
| 1905 | request.result = -1; |
| 1906 | loge("Failed to get UICC App"); |
| 1907 | notifyRequester(request); |
| 1908 | } else { |
| 1909 | onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request); |
| 1910 | ((SIMRecords) uiccApp.getIccRecords()) |
| 1911 | .setForbiddenPlmns(onCompleted, fplmns); |
| 1912 | } |
yinchengzhao | 4d163c0 | 2019-12-12 15:21:47 -0800 | [diff] [blame] | 1913 | break; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 1914 | case CMD_ERASE_MODEM_CONFIG: |
| 1915 | request = (MainThreadRequest) msg.obj; |
| 1916 | onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request); |
| 1917 | defaultPhone.eraseModemConfig(onCompleted); |
| 1918 | break; |
| 1919 | case EVENT_ERASE_MODEM_CONFIG_DONE: |
| 1920 | handleNullReturnEvent(msg, "eraseModemConfig"); |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1921 | break; |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1922 | |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 1923 | case CMD_ERASE_DATA_SHARED_PREFERENCES: |
| 1924 | request = (MainThreadRequest) msg.obj; |
| 1925 | request.result = defaultPhone.eraseDataInSharedPreferences(); |
| 1926 | notifyRequester(request); |
| 1927 | break; |
| 1928 | |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1929 | case CMD_CHANGE_ICC_LOCK_PASSWORD: |
| 1930 | request = (MainThreadRequest) msg.obj; |
| 1931 | onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request); |
| 1932 | Pair<String, String> changed = (Pair<String, String>) request.argument; |
| 1933 | getPhoneFromRequest(request).getIccCard().changeIccLockPassword( |
| 1934 | changed.first, changed.second, onCompleted); |
| 1935 | break; |
| 1936 | case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE: |
| 1937 | ar = (AsyncResult) msg.obj; |
| 1938 | request = (MainThreadRequest) ar.userObj; |
| 1939 | if (ar.exception == null) { |
| 1940 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1941 | // If the operation is successful, update the PIN storage |
| 1942 | Pair<String, String> passwords = (Pair<String, String>) request.argument; |
| 1943 | int phoneId = getPhoneFromRequest(request).getPhoneId(); |
Jon Spivack | 9c3bc76 | 2021-10-06 20:53:09 +0000 | [diff] [blame] | 1944 | UiccController.getInstance().getPinStorage() |
| 1945 | .storePin(passwords.second, phoneId); |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1946 | } else { |
| 1947 | request.result = msg.arg1; |
| 1948 | } |
| 1949 | notifyRequester(request); |
| 1950 | break; |
| 1951 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1952 | case CMD_SET_ICC_LOCK_ENABLED: { |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1953 | request = (MainThreadRequest) msg.obj; |
| 1954 | onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request); |
| 1955 | Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument; |
| 1956 | getPhoneFromRequest(request).getIccCard().setIccLockEnabled( |
| 1957 | enabled.first, enabled.second, onCompleted); |
| 1958 | break; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1959 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1960 | case EVENT_SET_ICC_LOCK_ENABLED_DONE: |
| 1961 | ar = (AsyncResult) msg.obj; |
| 1962 | request = (MainThreadRequest) ar.userObj; |
| 1963 | if (ar.exception == null) { |
| 1964 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1965 | // If the operation is successful, update the PIN storage |
| 1966 | Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument; |
| 1967 | int phoneId = getPhoneFromRequest(request).getPhoneId(); |
| 1968 | if (enabled.first) { |
Jon Spivack | 9c3bc76 | 2021-10-06 20:53:09 +0000 | [diff] [blame] | 1969 | UiccController.getInstance().getPinStorage() |
| 1970 | .storePin(enabled.second, phoneId); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1971 | } else { |
| 1972 | UiccController.getInstance().getPinStorage().clearPin(phoneId); |
| 1973 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1974 | } else { |
| 1975 | request.result = msg.arg1; |
| 1976 | } |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1977 | |
| 1978 | |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1979 | notifyRequester(request); |
| 1980 | break; |
| 1981 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 1982 | case MSG_NOTIFY_USER_ACTIVITY: |
| 1983 | removeMessages(MSG_NOTIFY_USER_ACTIVITY); |
Peter Wang | 59571be | 2020-01-27 12:35:15 +0800 | [diff] [blame] | 1984 | Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION); |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 1985 | intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY); |
| 1986 | getDefaultPhone().getContext().sendBroadcastAsUser( |
| 1987 | intent, UserHandle.ALL, permission.USER_ACTIVITY); |
| 1988 | break; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 1989 | |
| 1990 | case CMD_SET_DATA_THROTTLING: { |
| 1991 | request = (MainThreadRequest) msg.obj; |
| 1992 | onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request); |
| 1993 | DataThrottlingRequest dataThrottlingRequest = |
| 1994 | (DataThrottlingRequest) request.argument; |
| 1995 | Phone phone = getPhoneFromRequest(request); |
| 1996 | if (phone != null) { |
| 1997 | phone.setDataThrottling(onCompleted, |
| 1998 | request.workSource, dataThrottlingRequest.getDataThrottlingAction(), |
| 1999 | dataThrottlingRequest.getCompletionDurationMillis()); |
| 2000 | } else { |
| 2001 | loge("setDataThrottling: No phone object"); |
| 2002 | request.result = |
| 2003 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 2004 | notifyRequester(request); |
| 2005 | } |
| 2006 | |
| 2007 | break; |
| 2008 | } |
| 2009 | case EVENT_SET_DATA_THROTTLING_DONE: |
| 2010 | ar = (AsyncResult) msg.obj; |
| 2011 | request = (MainThreadRequest) ar.userObj; |
| 2012 | |
| 2013 | if (ar.exception == null) { |
| 2014 | request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 2015 | } else if (ar.exception instanceof CommandException) { |
| 2016 | loge("setDataThrottling: CommandException: " + ar.exception); |
| 2017 | CommandException.Error error = |
| 2018 | ((CommandException) (ar.exception)).getCommandError(); |
| 2019 | |
| 2020 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 2021 | request.result = TelephonyManager |
| 2022 | .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 2023 | } else if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 2024 | request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS; |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 2025 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 2026 | request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 2027 | } else { |
| 2028 | request.result = |
| 2029 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 2030 | } |
| 2031 | } else { |
| 2032 | request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 2033 | } |
| 2034 | Log.w(LOG_TAG, "DataThrottlingResult = " + request.result); |
| 2035 | notifyRequester(request); |
| 2036 | break; |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 2037 | |
| 2038 | case CMD_SET_SIM_POWER: { |
| 2039 | request = (MainThreadRequest) msg.obj; |
| 2040 | onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request); |
| 2041 | request = (MainThreadRequest) msg.obj; |
| 2042 | int stateToSet = |
| 2043 | ((Pair<Integer, IIntegerConsumer>) |
| 2044 | request.argument).first; |
| 2045 | request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource); |
| 2046 | break; |
| 2047 | } |
| 2048 | case EVENT_SET_SIM_POWER_DONE: { |
| 2049 | ar = (AsyncResult) msg.obj; |
| 2050 | request = (MainThreadRequest) ar.userObj; |
| 2051 | IIntegerConsumer callback = |
| 2052 | ((Pair<Integer, IIntegerConsumer>) request.argument).second; |
| 2053 | if (ar.exception != null) { |
| 2054 | loge("setSimPower exception: " + ar.exception); |
| 2055 | int errorCode = TelephonyManager.CallForwardingInfoCallback |
| 2056 | .RESULT_ERROR_UNKNOWN; |
| 2057 | if (ar.exception instanceof CommandException) { |
| 2058 | CommandException.Error error = |
| 2059 | ((CommandException) (ar.exception)).getCommandError(); |
| 2060 | if (error == CommandException.Error.SIM_ERR) { |
| 2061 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR; |
| 2062 | } else if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 2063 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE; |
| 2064 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 2065 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED; |
| 2066 | } else { |
| 2067 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR; |
| 2068 | } |
| 2069 | } |
| 2070 | try { |
| 2071 | callback.accept(errorCode); |
| 2072 | } catch (RemoteException e) { |
| 2073 | // Ignore if the remote process is no longer available to call back. |
| 2074 | Log.w(LOG_TAG, "setSimPower: callback not available."); |
| 2075 | } |
| 2076 | } else { |
| 2077 | try { |
| 2078 | callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS); |
| 2079 | } catch (RemoteException e) { |
| 2080 | // Ignore if the remote process is no longer available to call back. |
| 2081 | Log.w(LOG_TAG, "setSimPower: callback not available."); |
| 2082 | } |
| 2083 | } |
| 2084 | break; |
| 2085 | } |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 2086 | case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: { |
| 2087 | request = (MainThreadRequest) msg.obj; |
| 2088 | |
| 2089 | final Phone phone = getPhoneFromRequest(request); |
| 2090 | if (phone == null || phone.getServiceStateTracker() == null) { |
| 2091 | request.result = new IllegalStateException("Phone or SST is null"); |
| 2092 | notifyRequester(request); |
| 2093 | break; |
| 2094 | } |
| 2095 | |
| 2096 | Pair<Integer, SignalStrengthUpdateRequest> pair = |
| 2097 | (Pair<Integer, SignalStrengthUpdateRequest>) request.argument; |
| 2098 | onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE, |
| 2099 | request); |
Rambo Wang | 6568f17 | 2021-02-03 16:56:47 -0800 | [diff] [blame] | 2100 | phone.getSignalStrengthController().setSignalStrengthUpdateRequest( |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 2101 | request.subId, pair.first /*callingUid*/, |
| 2102 | pair.second /*request*/, onCompleted); |
| 2103 | break; |
| 2104 | } |
| 2105 | case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: { |
| 2106 | ar = (AsyncResult) msg.obj; |
| 2107 | request = (MainThreadRequest) ar.userObj; |
| 2108 | // request.result will be the exception of ar if present, true otherwise. |
| 2109 | // Be cautious not to leave result null which will wait() forever |
| 2110 | request.result = ar.exception != null ? ar.exception : true; |
| 2111 | notifyRequester(request); |
| 2112 | break; |
| 2113 | } |
| 2114 | case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: { |
| 2115 | request = (MainThreadRequest) msg.obj; |
| 2116 | |
| 2117 | Phone phone = getPhoneFromRequest(request); |
| 2118 | if (phone == null || phone.getServiceStateTracker() == null) { |
| 2119 | request.result = new IllegalStateException("Phone or SST is null"); |
| 2120 | notifyRequester(request); |
| 2121 | break; |
| 2122 | } |
| 2123 | |
| 2124 | Pair<Integer, SignalStrengthUpdateRequest> pair = |
| 2125 | (Pair<Integer, SignalStrengthUpdateRequest>) request.argument; |
| 2126 | onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE, |
| 2127 | request); |
Rambo Wang | 6568f17 | 2021-02-03 16:56:47 -0800 | [diff] [blame] | 2128 | phone.getSignalStrengthController().clearSignalStrengthUpdateRequest( |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 2129 | request.subId, pair.first /*callingUid*/, |
| 2130 | pair.second /*request*/, onCompleted); |
| 2131 | break; |
| 2132 | } |
| 2133 | case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: { |
| 2134 | ar = (AsyncResult) msg.obj; |
| 2135 | request = (MainThreadRequest) ar.userObj; |
| 2136 | request.result = ar.exception != null ? ar.exception : true; |
| 2137 | notifyRequester(request); |
| 2138 | break; |
| 2139 | } |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 2140 | |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2141 | case CMD_GET_SLICING_CONFIG: { |
| 2142 | request = (MainThreadRequest) msg.obj; |
| 2143 | onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request); |
| 2144 | request.phone.getSlicingConfig(onCompleted); |
| 2145 | break; |
| 2146 | } |
| 2147 | case EVENT_GET_SLICING_CONFIG_DONE: { |
| 2148 | ar = (AsyncResult) msg.obj; |
| 2149 | request = (MainThreadRequest) ar.userObj; |
| 2150 | ResultReceiver result = (ResultReceiver) request.argument; |
| 2151 | |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2152 | NetworkSlicingConfig slicingConfig = null; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2153 | Bundle bundle = new Bundle(); |
| 2154 | int resultCode = 0; |
| 2155 | if (ar.exception != null) { |
| 2156 | Log.e(LOG_TAG, "Exception retrieving slicing configuration=" |
| 2157 | + ar.exception); |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2158 | resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2159 | } else if (ar.result == null) { |
| 2160 | Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!"); |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2161 | resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2162 | } else { |
| 2163 | // use the result as returned |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2164 | resultCode = TelephonyManager.NetworkSlicingException.SUCCESS; |
| 2165 | slicingConfig = (NetworkSlicingConfig) ar.result; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2166 | } |
| 2167 | |
| 2168 | if (slicingConfig == null) { |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2169 | slicingConfig = new NetworkSlicingConfig(); |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2170 | } |
| 2171 | bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig); |
| 2172 | result.send(resultCode, bundle); |
| 2173 | notifyRequester(request); |
| 2174 | break; |
| 2175 | } |
| 2176 | |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2177 | case CMD_PURCHASE_PREMIUM_CAPABILITY: { |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2178 | request = (MainThreadRequest) msg.obj; |
| 2179 | onCompleted = obtainMessage(EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE, request); |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2180 | PurchasePremiumCapabilityArgument arg = |
| 2181 | (PurchasePremiumCapabilityArgument) request.argument; |
Sarah Chin | 46355ba | 2022-11-01 23:51:16 -0700 | [diff] [blame] | 2182 | SlicePurchaseController.getInstance(request.phone).purchasePremiumCapability( |
Sarah Chin | b8218c2 | 2023-01-04 13:35:29 -0800 | [diff] [blame] | 2183 | arg.capability, onCompleted); |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2184 | break; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2185 | } |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2186 | |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2187 | case EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE: { |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2188 | ar = (AsyncResult) msg.obj; |
| 2189 | request = (MainThreadRequest) ar.userObj; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2190 | PurchasePremiumCapabilityArgument arg = |
| 2191 | (PurchasePremiumCapabilityArgument) request.argument; |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2192 | try { |
| 2193 | int result = (int) ar.result; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2194 | arg.callback.accept(result); |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2195 | log("purchasePremiumCapability: capability=" |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2196 | + TelephonyManager.convertPremiumCapabilityToString(arg.capability) |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2197 | + ", result= " |
| 2198 | + TelephonyManager.convertPurchaseResultToString(result)); |
| 2199 | } catch (RemoteException e) { |
| 2200 | String logStr = "Purchase premium capability " |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2201 | + TelephonyManager.convertPremiumCapabilityToString(arg.capability) |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2202 | + " failed: " + e; |
| 2203 | if (DBG) log(logStr); |
| 2204 | AnomalyReporter.reportAnomaly( |
| 2205 | UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr); |
| 2206 | } |
| 2207 | break; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2208 | } |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2209 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2210 | case CMD_PREPARE_UNATTENDED_REBOOT: |
| 2211 | request = (MainThreadRequest) msg.obj; |
| 2212 | request.result = |
Rafael Higuera Silva | d963064 | 2021-09-20 15:32:01 +0000 | [diff] [blame] | 2213 | UiccController.getInstance().getPinStorage() |
| 2214 | .prepareUnattendedReboot(request.workSource); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2215 | notifyRequester(request); |
| 2216 | break; |
| 2217 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2218 | default: |
| 2219 | Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what); |
| 2220 | break; |
| 2221 | } |
| 2222 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2223 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 2224 | private void notifyRequester(MainThreadRequest request) { |
| 2225 | synchronized (request) { |
| 2226 | request.notifyAll(); |
| 2227 | } |
| 2228 | } |
| 2229 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2230 | private void handleNullReturnEvent(Message msg, String command) { |
| 2231 | AsyncResult ar = (AsyncResult) msg.obj; |
| 2232 | MainThreadRequest request = (MainThreadRequest) ar.userObj; |
| 2233 | if (ar.exception == null) { |
| 2234 | request.result = true; |
| 2235 | } else { |
| 2236 | request.result = false; |
| 2237 | if (ar.exception instanceof CommandException) { |
| 2238 | loge(command + ": CommandException: " + ar.exception); |
| 2239 | } else { |
| 2240 | loge(command + ": Unknown exception"); |
| 2241 | } |
| 2242 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 2243 | notifyRequester(request); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2244 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2245 | } |
| 2246 | |
| 2247 | /** |
| 2248 | * Posts the specified command to be executed on the main thread, |
| 2249 | * waits for the request to complete, and returns the result. |
| 2250 | * @see #sendRequestAsync |
| 2251 | */ |
| 2252 | private Object sendRequest(int command, Object argument) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2253 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, |
| 2254 | null, -1 /*timeoutInMs*/); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 2255 | } |
| 2256 | |
| 2257 | /** |
| 2258 | * Posts the specified command to be executed on the main thread, |
| 2259 | * waits for the request to complete, and returns the result. |
| 2260 | * @see #sendRequestAsync |
| 2261 | */ |
| 2262 | private Object sendRequest(int command, Object argument, WorkSource workSource) { |
| 2263 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2264 | null, workSource, -1 /*timeoutInMs*/); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2265 | } |
| 2266 | |
| 2267 | /** |
| 2268 | * Posts the specified command to be executed on the main thread, |
| 2269 | * waits for the request to complete, and returns the result. |
| 2270 | * @see #sendRequestAsync |
| 2271 | */ |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2272 | private Object sendRequest(int command, Object argument, Integer subId) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2273 | return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/); |
| 2274 | } |
| 2275 | |
| 2276 | /** |
| 2277 | * Posts the specified command to be executed on the main thread, |
| 2278 | * waits for the request to complete for at most {@code timeoutInMs}, and returns the result |
| 2279 | * if not timeout or null otherwise. |
| 2280 | * @see #sendRequestAsync |
| 2281 | */ |
| 2282 | private @Nullable Object sendRequest(int command, Object argument, Integer subId, |
| 2283 | long timeoutInMs) { |
| 2284 | return sendRequest(command, argument, subId, null, null, timeoutInMs); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 2285 | } |
| 2286 | |
| 2287 | /** |
| 2288 | * Posts the specified command to be executed on the main thread, |
| 2289 | * waits for the request to complete, and returns the result. |
| 2290 | * @see #sendRequestAsync |
| 2291 | */ |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2292 | private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2293 | return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2294 | } |
| 2295 | |
| 2296 | /** |
| 2297 | * Posts the specified command to be executed on the main thread, |
| 2298 | * waits for the request to complete, and returns the result. |
| 2299 | * @see #sendRequestAsync |
| 2300 | */ |
| 2301 | private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2302 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, |
| 2303 | workSource, -1 /*timeoutInMs*/); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2304 | } |
| 2305 | |
| 2306 | /** |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2307 | * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is |
| 2308 | * negative, waits for the request to complete, and returns the result. Otherwise, wait for |
| 2309 | * maximum of {@code timeoutInMs} milliseconds, interrupt and return null. |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2310 | * @see #sendRequestAsync |
| 2311 | */ |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2312 | private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone, |
| 2313 | WorkSource workSource, long timeoutInMs) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2314 | if (Looper.myLooper() == mMainThreadHandler.getLooper()) { |
| 2315 | throw new RuntimeException("This method will deadlock if called from the main thread."); |
| 2316 | } |
| 2317 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2318 | MainThreadRequest request = null; |
| 2319 | if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) { |
| 2320 | throw new IllegalArgumentException("subId and phone cannot both be specified!"); |
| 2321 | } else if (phone != null) { |
| 2322 | request = new MainThreadRequest(argument, phone, workSource); |
| 2323 | } else { |
| 2324 | request = new MainThreadRequest(argument, subId, workSource); |
| 2325 | } |
| 2326 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2327 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 2328 | msg.sendToTarget(); |
| 2329 | |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2330 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2331 | synchronized (request) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2332 | if (timeoutInMs >= 0) { |
| 2333 | // Wait for at least timeoutInMs before returning null request result |
| 2334 | long now = SystemClock.elapsedRealtime(); |
| 2335 | long deadline = now + timeoutInMs; |
Grace Jia | 8a0a1e8 | 2021-05-23 22:59:52 -0700 | [diff] [blame] | 2336 | while (request.result == null && now < deadline) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2337 | try { |
| 2338 | request.wait(deadline - now); |
| 2339 | } catch (InterruptedException e) { |
| 2340 | // Do nothing, go back and check if request is completed or timeout |
| 2341 | } finally { |
| 2342 | now = SystemClock.elapsedRealtime(); |
| 2343 | } |
| 2344 | } |
| 2345 | } else { |
| 2346 | // Wait for the request to complete |
| 2347 | while (request.result == null) { |
| 2348 | try { |
| 2349 | request.wait(); |
| 2350 | } catch (InterruptedException e) { |
| 2351 | // Do nothing, go back and wait until the request is complete |
| 2352 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2353 | } |
| 2354 | } |
| 2355 | } |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2356 | if (request.result == null) { |
| 2357 | Log.wtf(LOG_TAG, |
| 2358 | "sendRequest: Blocking command timed out. Something has gone terribly wrong."); |
| 2359 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2360 | return request.result; |
| 2361 | } |
| 2362 | |
| 2363 | /** |
| 2364 | * Asynchronous ("fire and forget") version of sendRequest(): |
| 2365 | * Posts the specified command to be executed on the main thread, and |
| 2366 | * returns immediately. |
| 2367 | * @see #sendRequest |
| 2368 | */ |
| 2369 | private void sendRequestAsync(int command) { |
| 2370 | mMainThreadHandler.sendEmptyMessage(command); |
| 2371 | } |
| 2372 | |
| 2373 | /** |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2374 | * Same as {@link #sendRequestAsync(int)} except it takes an argument. |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2375 | * @see {@link #sendRequest(int)} |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2376 | */ |
| 2377 | private void sendRequestAsync(int command, Object argument) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2378 | sendRequestAsync(command, argument, null, null); |
| 2379 | } |
| 2380 | |
| 2381 | /** |
| 2382 | * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource. |
| 2383 | * @see {@link #sendRequest(int,Object)} |
| 2384 | */ |
| 2385 | private void sendRequestAsync( |
| 2386 | int command, Object argument, Phone phone, WorkSource workSource) { |
| 2387 | MainThreadRequest request = new MainThreadRequest(argument, phone, workSource); |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2388 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 2389 | msg.sendToTarget(); |
| 2390 | } |
| 2391 | |
| 2392 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2393 | * Initialize the singleton PhoneInterfaceManager instance. |
| 2394 | * This is only done once, at startup, from PhoneApp.onCreate(). |
| 2395 | */ |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2396 | /* package */ static PhoneInterfaceManager init(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2397 | synchronized (PhoneInterfaceManager.class) { |
| 2398 | if (sInstance == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2399 | sInstance = new PhoneInterfaceManager(app); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2400 | } else { |
| 2401 | Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance); |
| 2402 | } |
| 2403 | return sInstance; |
| 2404 | } |
| 2405 | } |
| 2406 | |
| 2407 | /** Private constructor; @see init() */ |
Jordan Liu | 1979a04 | 2020-03-20 21:39:35 +0000 | [diff] [blame] | 2408 | private PhoneInterfaceManager(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2409 | mApp = app; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2410 | mCM = PhoneGlobals.getInstance().mCM; |
Brad Ebinger | d1947d8 | 2021-05-17 20:54:49 +0000 | [diff] [blame] | 2411 | mImsResolver = ImsResolver.getInstance(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 2412 | mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2413 | mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 2414 | mPm = app.getSystemService(PackageManager.class); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2415 | mMainThreadHandler = new MainThreadHandler(); |
Jack Yu | e37dd26 | 2022-12-16 11:53:37 -0800 | [diff] [blame] | 2416 | if (!PhoneFactory.isSubscriptionManagerServiceEnabled()) { |
| 2417 | mSubscriptionController = SubscriptionController.getInstance(); |
| 2418 | } else { |
| 2419 | mSubscriptionController = null; |
| 2420 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2421 | mTelephonySharedPreferences = |
| 2422 | PreferenceManager.getDefaultSharedPreferences(mApp); |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 2423 | mNetworkScanRequestTracker = new NetworkScanRequestTracker(); |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 2424 | mPhoneConfigurationManager = PhoneConfigurationManager.getInstance(); |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 2425 | mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance(); |
Peter Wang | a3cf4ac | 2020-01-27 09:39:46 +0800 | [diff] [blame] | 2426 | mNotifyUserActivity = new AtomicBoolean(false); |
Tyler Gunn | 64144d9 | 2022-03-17 14:16:41 -0700 | [diff] [blame] | 2427 | PropertyInvalidatedCache.invalidateCache(TelephonyManager.CACHE_KEY_PHONE_ACCOUNT_TO_SUBID); |
Gil Cukierman | 6dac5eb | 2022-09-19 16:09:04 +0000 | [diff] [blame] | 2428 | mTelephony2gUpdater = new Telephony2gUpdater( |
| 2429 | Executors.newSingleThreadExecutor(), mApp); |
| 2430 | mTelephony2gUpdater.init(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2431 | publish(); |
| 2432 | } |
| 2433 | |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 2434 | @VisibleForTesting |
| 2435 | public SharedPreferences getSharedPreferences() { |
| 2436 | return mTelephonySharedPreferences; |
| 2437 | } |
| 2438 | |
Gil Cukierman | 92cc7db | 2023-01-06 19:25:53 +0000 | [diff] [blame] | 2439 | /** |
| 2440 | * Get the default phone for this device. |
| 2441 | */ |
| 2442 | @VisibleForTesting |
| 2443 | public Phone getDefaultPhone() { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2444 | Phone thePhone = getPhone(getDefaultSubscription()); |
| 2445 | return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone(); |
| 2446 | } |
| 2447 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2448 | private void publish() { |
| 2449 | if (DBG) log("publish: " + this); |
| 2450 | |
Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 2451 | TelephonyFrameworkInitializer |
| 2452 | .getTelephonyServiceManager() |
| 2453 | .getTelephonyServiceRegisterer() |
| 2454 | .register(this); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2455 | } |
| 2456 | |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 2457 | private Phone getPhoneFromRequest(MainThreadRequest request) { |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 2458 | if (request.phone != null) { |
| 2459 | return request.phone; |
| 2460 | } else { |
| 2461 | return getPhoneFromSubId(request.subId); |
| 2462 | } |
| 2463 | } |
| 2464 | |
| 2465 | private Phone getPhoneFromSubId(int subId) { |
| 2466 | return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) |
| 2467 | ? getDefaultPhone() : getPhone(subId); |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 2468 | } |
| 2469 | |
Rambo Wang | e53e07d | 2022-05-10 13:01:13 -0700 | [diff] [blame] | 2470 | @Nullable |
| 2471 | private UiccPort getUiccPortFromRequest(@NonNull MainThreadRequest request) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2472 | Phone phone = getPhoneFromRequest(request); |
| 2473 | return phone == null ? null : |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 2474 | UiccController.getInstance().getUiccPort(phone.getPhoneId()); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2475 | } |
| 2476 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2477 | // returns phone associated with the subId. |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2478 | private Phone getPhone(int subId) { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 2479 | return PhoneFactory.getPhone(SubscriptionManager.getPhoneId(subId)); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2480 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2481 | |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 2482 | private void sendEraseModemConfig(@NonNull Phone phone) { |
| 2483 | Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null); |
| 2484 | if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 2485 | } |
| 2486 | |
| 2487 | private void sendEraseDataInSharedPreferences(@NonNull Phone phone) { |
| 2488 | Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null); |
| 2489 | if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail")); |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 2490 | } |
| 2491 | |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 2492 | private boolean isImsAvailableOnDevice() { |
| 2493 | PackageManager pm = getDefaultPhone().getContext().getPackageManager(); |
| 2494 | if (pm == null) { |
| 2495 | // For some reason package manger is not available.. This will fail internally anyway, |
| 2496 | // so do not throw error and allow. |
| 2497 | return true; |
| 2498 | } |
| 2499 | return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0); |
| 2500 | } |
| 2501 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2502 | public void dial(String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2503 | dialForSubscriber(getPreferredVoiceSubscription(), number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2504 | } |
| 2505 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2506 | public void dialForSubscriber(int subId, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2507 | if (DBG) log("dial: " + number); |
| 2508 | // No permission check needed here: This is just a wrapper around the |
| 2509 | // ACTION_DIAL intent, which is available to any app since it puts up |
| 2510 | // the UI before it does anything. |
| 2511 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2512 | final long identity = Binder.clearCallingIdentity(); |
| 2513 | try { |
| 2514 | String url = createTelUrl(number); |
| 2515 | if (url == null) { |
| 2516 | return; |
| 2517 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2518 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2519 | // PENDING: should we just silently fail if phone is offhook or ringing? |
| 2520 | PhoneConstants.State state = mCM.getState(subId); |
| 2521 | if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) { |
| 2522 | Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url)); |
| 2523 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2524 | mApp.startActivity(intent); |
| 2525 | } |
| 2526 | } finally { |
| 2527 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2528 | } |
| 2529 | } |
| 2530 | |
| 2531 | public void call(String callingPackage, String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2532 | callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2533 | } |
| 2534 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2535 | public void callForSubscriber(int subId, String callingPackage, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2536 | if (DBG) log("call: " + number); |
| 2537 | |
| 2538 | // This is just a wrapper around the ACTION_CALL intent, but we still |
| 2539 | // need to do a permission check since we're calling startActivity() |
| 2540 | // from the context of the phone app. |
| 2541 | enforceCallPermission(); |
| 2542 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 2543 | if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage) |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2544 | != AppOpsManager.MODE_ALLOWED) { |
| 2545 | return; |
| 2546 | } |
| 2547 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2548 | final long identity = Binder.clearCallingIdentity(); |
| 2549 | try { |
| 2550 | String url = createTelUrl(number); |
| 2551 | if (url == null) { |
| 2552 | return; |
| 2553 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2554 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2555 | boolean isValid = false; |
| 2556 | final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged(); |
| 2557 | if (slist != null) { |
| 2558 | for (SubscriptionInfo subInfoRecord : slist) { |
| 2559 | if (subInfoRecord.getSubscriptionId() == subId) { |
| 2560 | isValid = true; |
| 2561 | break; |
| 2562 | } |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 2563 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 2564 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2565 | if (!isValid) { |
| 2566 | return; |
| 2567 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 2568 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2569 | Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url)); |
| 2570 | intent.putExtra(SUBSCRIPTION_KEY, subId); |
| 2571 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2572 | mApp.startActivity(intent); |
| 2573 | } finally { |
| 2574 | Binder.restoreCallingIdentity(identity); |
| 2575 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2576 | } |
| 2577 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2578 | public boolean supplyPinForSubscriber(int subId, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2579 | int [] resultArray = supplyPinReportResultForSubscriber(subId, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2580 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 2581 | } |
| 2582 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2583 | public boolean supplyPukForSubscriber(int subId, String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2584 | int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2585 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 2586 | } |
| 2587 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2588 | public int[] supplyPinReportResultForSubscriber(int subId, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2589 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2590 | |
| 2591 | final long identity = Binder.clearCallingIdentity(); |
| 2592 | try { |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2593 | Phone phone = getPhone(subId); |
| 2594 | final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2595 | checkSimPin.start(); |
| 2596 | return checkSimPin.unlockSim(null, pin); |
| 2597 | } finally { |
| 2598 | Binder.restoreCallingIdentity(identity); |
| 2599 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2600 | } |
| 2601 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2602 | public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2603 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2604 | |
| 2605 | final long identity = Binder.clearCallingIdentity(); |
| 2606 | try { |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2607 | Phone phone = getPhone(subId); |
| 2608 | final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2609 | checkSimPuk.start(); |
| 2610 | return checkSimPuk.unlockSim(puk, pin); |
| 2611 | } finally { |
| 2612 | Binder.restoreCallingIdentity(identity); |
| 2613 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2614 | } |
| 2615 | |
| 2616 | /** |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2617 | * Helper thread to turn async call to SimCard#supplyPin into |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2618 | * a synchronous one. |
| 2619 | */ |
| 2620 | private static class UnlockSim extends Thread { |
| 2621 | |
| 2622 | private final IccCard mSimCard; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2623 | private final int mPhoneId; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2624 | |
| 2625 | private boolean mDone = false; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2626 | private int mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 2627 | private int mRetryCount = -1; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2628 | |
| 2629 | // For replies from SimCard interface |
| 2630 | private Handler mHandler; |
| 2631 | |
| 2632 | // For async handler to identify request type |
| 2633 | private static final int SUPPLY_PIN_COMPLETE = 100; |
| 2634 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2635 | UnlockSim(int phoneId, IccCard simCard) { |
| 2636 | mPhoneId = phoneId; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2637 | mSimCard = simCard; |
| 2638 | } |
| 2639 | |
| 2640 | @Override |
| 2641 | public void run() { |
| 2642 | Looper.prepare(); |
| 2643 | synchronized (UnlockSim.this) { |
| 2644 | mHandler = new Handler() { |
| 2645 | @Override |
| 2646 | public void handleMessage(Message msg) { |
| 2647 | AsyncResult ar = (AsyncResult) msg.obj; |
| 2648 | switch (msg.what) { |
| 2649 | case SUPPLY_PIN_COMPLETE: |
| 2650 | Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE"); |
| 2651 | synchronized (UnlockSim.this) { |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2652 | mRetryCount = msg.arg1; |
| 2653 | if (ar.exception != null) { |
| 2654 | if (ar.exception instanceof CommandException && |
| 2655 | ((CommandException)(ar.exception)).getCommandError() |
| 2656 | == CommandException.Error.PASSWORD_INCORRECT) { |
| 2657 | mResult = PhoneConstants.PIN_PASSWORD_INCORRECT; |
vivi.li | b5e9ada | 2019-09-12 16:04:24 +0800 | [diff] [blame] | 2658 | } //When UiccCardApp dispose,handle message and return exception |
| 2659 | else if (ar.exception instanceof CommandException && |
| 2660 | ((CommandException) (ar.exception)).getCommandError() |
| 2661 | == CommandException.Error.ABORTED) { |
| 2662 | mResult = PhoneConstants.PIN_OPERATION_ABORTED; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2663 | } else { |
| 2664 | mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 2665 | } |
| 2666 | } else { |
| 2667 | mResult = PhoneConstants.PIN_RESULT_SUCCESS; |
| 2668 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2669 | mDone = true; |
| 2670 | UnlockSim.this.notifyAll(); |
| 2671 | } |
| 2672 | break; |
| 2673 | } |
| 2674 | } |
| 2675 | }; |
| 2676 | UnlockSim.this.notifyAll(); |
| 2677 | } |
| 2678 | Looper.loop(); |
| 2679 | } |
| 2680 | |
| 2681 | /* |
| 2682 | * Use PIN or PUK to unlock SIM card |
| 2683 | * |
| 2684 | * If PUK is null, unlock SIM card with PIN |
| 2685 | * |
| 2686 | * If PUK is not null, unlock SIM card with PUK and set PIN code |
| 2687 | */ |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2688 | synchronized int[] unlockSim(String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2689 | |
| 2690 | while (mHandler == null) { |
| 2691 | try { |
| 2692 | wait(); |
| 2693 | } catch (InterruptedException e) { |
| 2694 | Thread.currentThread().interrupt(); |
| 2695 | } |
| 2696 | } |
| 2697 | Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE); |
| 2698 | |
| 2699 | if (puk == null) { |
| 2700 | mSimCard.supplyPin(pin, callback); |
| 2701 | } else { |
| 2702 | mSimCard.supplyPuk(puk, pin, callback); |
| 2703 | } |
| 2704 | |
| 2705 | while (!mDone) { |
| 2706 | try { |
| 2707 | Log.d(LOG_TAG, "wait for done"); |
| 2708 | wait(); |
| 2709 | } catch (InterruptedException e) { |
| 2710 | // Restore the interrupted status |
| 2711 | Thread.currentThread().interrupt(); |
| 2712 | } |
| 2713 | } |
| 2714 | Log.d(LOG_TAG, "done"); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2715 | int[] resultArray = new int[2]; |
| 2716 | resultArray[0] = mResult; |
| 2717 | resultArray[1] = mRetryCount; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2718 | |
| 2719 | if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) { |
Jon Spivack | 9c3bc76 | 2021-10-06 20:53:09 +0000 | [diff] [blame] | 2720 | UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2721 | } |
| 2722 | |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2723 | return resultArray; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2724 | } |
| 2725 | } |
| 2726 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2727 | /** |
| 2728 | * This method has been removed due to privacy and stability concerns. |
| 2729 | */ |
| 2730 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2731 | public void updateServiceLocation() { |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2732 | Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()"); |
| 2733 | return; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2734 | } |
| 2735 | |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2736 | @Override |
| 2737 | public void updateServiceLocationWithPackageName(String callingPackage) { |
| 2738 | mApp.getSystemService(AppOpsManager.class) |
| 2739 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 2740 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 2741 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2742 | if (targetSdk > android.os.Build.VERSION_CODES.R) { |
| 2743 | // Callers targeting S have no business invoking this method. |
| 2744 | return; |
| 2745 | } |
| 2746 | |
| 2747 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2748 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2749 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2750 | .setCallingPackage(callingPackage) |
| 2751 | .setCallingFeatureId(null) |
| 2752 | .setCallingPid(Binder.getCallingPid()) |
| 2753 | .setCallingUid(Binder.getCallingUid()) |
| 2754 | .setMethod("updateServiceLocation") |
| 2755 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
| 2756 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2757 | .build()); |
| 2758 | // Apps that lack location permission have no business calling this method; |
| 2759 | // however, because no permission was declared in the public API, denials must |
| 2760 | // all be "soft". |
| 2761 | switch (locationResult) { |
| 2762 | case DENIED_HARD: /* fall through */ |
| 2763 | case DENIED_SOFT: |
| 2764 | return; |
| 2765 | } |
| 2766 | |
| 2767 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2768 | final long identity = Binder.clearCallingIdentity(); |
| 2769 | try { |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2770 | final Phone phone = getPhone(getDefaultSubscription()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2771 | if (phone != null) { |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2772 | phone.updateServiceLocation(workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2773 | } |
| 2774 | } finally { |
| 2775 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2776 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2777 | } |
| 2778 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2779 | @Deprecated |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2780 | @Override |
| 2781 | public boolean isRadioOn(String callingPackage) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2782 | return isRadioOnWithFeature(callingPackage, null); |
| 2783 | } |
| 2784 | |
| 2785 | |
| 2786 | @Override |
| 2787 | public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) { |
| 2788 | return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage, |
| 2789 | callingFeatureId); |
| 2790 | } |
| 2791 | |
| 2792 | @Deprecated |
| 2793 | @Override |
| 2794 | public boolean isRadioOnForSubscriber(int subId, String callingPackage) { |
| 2795 | return isRadioOnForSubscriberWithFeature(subId, callingPackage, null); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2796 | } |
| 2797 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2798 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2799 | public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage, |
| 2800 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2801 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2802 | mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2803 | return false; |
| 2804 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2805 | |
| 2806 | final long identity = Binder.clearCallingIdentity(); |
| 2807 | try { |
| 2808 | return isRadioOnForSubscriber(subId); |
| 2809 | } finally { |
| 2810 | Binder.restoreCallingIdentity(identity); |
| 2811 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2812 | } |
| 2813 | |
| 2814 | private boolean isRadioOnForSubscriber(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2815 | final long identity = Binder.clearCallingIdentity(); |
| 2816 | try { |
| 2817 | final Phone phone = getPhone(subId); |
| 2818 | if (phone != null) { |
| 2819 | return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF; |
| 2820 | } else { |
| 2821 | return false; |
| 2822 | } |
| 2823 | } finally { |
| 2824 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2825 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2826 | } |
| 2827 | |
| 2828 | public void toggleRadioOnOff() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2829 | toggleRadioOnOffForSubscriber(getDefaultSubscription()); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2830 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2831 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2832 | public void toggleRadioOnOffForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2833 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2834 | |
| 2835 | final long identity = Binder.clearCallingIdentity(); |
| 2836 | try { |
| 2837 | final Phone phone = getPhone(subId); |
| 2838 | if (phone != null) { |
| 2839 | phone.setRadioPower(!isRadioOnForSubscriber(subId)); |
| 2840 | } |
| 2841 | } finally { |
| 2842 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2843 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2844 | } |
| 2845 | |
| 2846 | public boolean setRadio(boolean turnOn) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2847 | return setRadioForSubscriber(getDefaultSubscription(), turnOn); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2848 | } |
| 2849 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2850 | public boolean setRadioForSubscriber(int subId, boolean turnOn) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2851 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2852 | |
| 2853 | final long identity = Binder.clearCallingIdentity(); |
| 2854 | try { |
| 2855 | final Phone phone = getPhone(subId); |
| 2856 | if (phone == null) { |
| 2857 | return false; |
| 2858 | } |
| 2859 | if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) { |
| 2860 | toggleRadioOnOffForSubscriber(subId); |
| 2861 | } |
| 2862 | return true; |
| 2863 | } finally { |
| 2864 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2865 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2866 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2867 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2868 | public boolean needMobileRadioShutdown() { |
Shuo Qian | fa7b6b3 | 2019-12-10 10:40:38 -0800 | [diff] [blame] | 2869 | enforceReadPrivilegedPermission("needMobileRadioShutdown"); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2870 | /* |
| 2871 | * If any of the Radios are available, it will need to be |
| 2872 | * shutdown. So return true if any Radio is available. |
| 2873 | */ |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2874 | final long identity = Binder.clearCallingIdentity(); |
| 2875 | try { |
| 2876 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 2877 | Phone phone = PhoneFactory.getPhone(i); |
| 2878 | if (phone != null && phone.isRadioAvailable()) return true; |
| 2879 | } |
| 2880 | logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown."); |
| 2881 | return false; |
| 2882 | } finally { |
| 2883 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2884 | } |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2885 | } |
| 2886 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2887 | @Override |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2888 | public void shutdownMobileRadios() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2889 | enforceModifyPermission(); |
| 2890 | |
| 2891 | final long identity = Binder.clearCallingIdentity(); |
| 2892 | try { |
| 2893 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 2894 | logv("Shutting down Phone " + i); |
| 2895 | shutdownRadioUsingPhoneId(i); |
| 2896 | } |
| 2897 | } finally { |
| 2898 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2899 | } |
| 2900 | } |
| 2901 | |
| 2902 | private void shutdownRadioUsingPhoneId(int phoneId) { |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2903 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 2904 | if (phone != null && phone.isRadioAvailable()) { |
| 2905 | phone.shutdownRadio(); |
| 2906 | } |
| 2907 | } |
| 2908 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2909 | public boolean setRadioPower(boolean turnOn) { |
Jack Yu | b4e1616 | 2017-05-15 12:48:40 -0700 | [diff] [blame] | 2910 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2911 | |
| 2912 | final long identity = Binder.clearCallingIdentity(); |
| 2913 | try { |
| 2914 | final Phone defaultPhone = PhoneFactory.getDefaultPhone(); |
| 2915 | if (defaultPhone != null) { |
| 2916 | defaultPhone.setRadioPower(turnOn); |
| 2917 | return true; |
| 2918 | } else { |
| 2919 | loge("There's no default phone."); |
| 2920 | return false; |
| 2921 | } |
| 2922 | } finally { |
| 2923 | Binder.restoreCallingIdentity(identity); |
Wei Liu | 9ae2a06 | 2016-08-08 11:09:34 -0700 | [diff] [blame] | 2924 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2925 | } |
| 2926 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2927 | public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2928 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2929 | |
| 2930 | final long identity = Binder.clearCallingIdentity(); |
| 2931 | try { |
| 2932 | final Phone phone = getPhone(subId); |
| 2933 | if (phone != null) { |
| 2934 | phone.setRadioPower(turnOn); |
| 2935 | return true; |
| 2936 | } else { |
| 2937 | return false; |
| 2938 | } |
| 2939 | } finally { |
| 2940 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2941 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2942 | } |
| 2943 | |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 2944 | /** |
| 2945 | * Vote on powering off the radio for a reason. The radio will be turned on only when there is |
| 2946 | * no reason to power it off. When any of the voters want to power it off, it will be turned |
| 2947 | * off. In case of emergency, the radio will be turned on even if there are some reasons for |
| 2948 | * powering it off, and these radio off votes will be cleared. |
| 2949 | * Multiple apps can vote for the same reason and the last vote will take effect. Each app is |
| 2950 | * responsible for its vote. A powering-off vote of a reason will be maintained until it is |
| 2951 | * cleared by calling {@link clearRadioPowerOffForReason} for that reason, or an emergency call |
| 2952 | * is made, or the device is rebooted. When an app comes backup from a crash, it needs to make |
| 2953 | * sure if its vote is as expected. An app can use the API {@link getRadioPowerOffReasons} to |
| 2954 | * check its vote. |
| 2955 | * |
| 2956 | * @param subId The subscription ID. |
| 2957 | * @param reason The reason for powering off radio. |
| 2958 | * @return true on success and false on failure. |
| 2959 | */ |
| 2960 | public boolean requestRadioPowerOffForReason(int subId, |
| 2961 | @TelephonyManager.RadioPowerReason int reason) { |
| 2962 | enforceModifyPermission(); |
| 2963 | |
| 2964 | final long identity = Binder.clearCallingIdentity(); |
| 2965 | try { |
| 2966 | final Phone phone = getPhone(subId); |
| 2967 | if (phone != null) { |
| 2968 | phone.setRadioPowerForReason(false, reason); |
| 2969 | return true; |
| 2970 | } else { |
| 2971 | return false; |
| 2972 | } |
| 2973 | } finally { |
| 2974 | Binder.restoreCallingIdentity(identity); |
| 2975 | } |
| 2976 | } |
| 2977 | |
| 2978 | /** |
| 2979 | * Remove the vote on powering off the radio for a reason, as requested by |
| 2980 | * {@link requestRadioPowerOffForReason}. |
| 2981 | * |
| 2982 | * @param subId The subscription ID. |
| 2983 | * @param reason The reason for powering off radio. |
| 2984 | * @return true on success and false on failure. |
| 2985 | */ |
| 2986 | public boolean clearRadioPowerOffForReason(int subId, |
| 2987 | @TelephonyManager.RadioPowerReason int reason) { |
| 2988 | enforceModifyPermission(); |
| 2989 | |
| 2990 | final long identity = Binder.clearCallingIdentity(); |
| 2991 | try { |
| 2992 | final Phone phone = getPhone(subId); |
| 2993 | if (phone != null) { |
| 2994 | phone.setRadioPowerForReason(true, reason); |
| 2995 | return true; |
| 2996 | } else { |
| 2997 | return false; |
| 2998 | } |
| 2999 | } finally { |
| 3000 | Binder.restoreCallingIdentity(identity); |
| 3001 | } |
| 3002 | } |
| 3003 | |
| 3004 | /** |
| 3005 | * Get reasons for powering off radio, as requested by {@link requestRadioPowerOffForReason}. |
| 3006 | * |
| 3007 | * @param subId The subscription ID. |
| 3008 | * @param callingPackage The package making the call. |
| 3009 | * @param callingFeatureId The feature in the package. |
| 3010 | * @return List of reasons for powering off radio. |
| 3011 | */ |
| 3012 | public List getRadioPowerOffReasons(int subId, String callingPackage, String callingFeatureId) { |
| 3013 | enforceReadPrivilegedPermission("getRadioPowerOffReasons"); |
| 3014 | |
| 3015 | final long identity = Binder.clearCallingIdentity(); |
| 3016 | List result = new ArrayList(); |
| 3017 | try { |
| 3018 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, |
| 3019 | callingPackage, callingFeatureId, "getRadioPowerOffReasons")) { |
| 3020 | return result; |
| 3021 | } |
| 3022 | |
| 3023 | final Phone phone = getPhone(subId); |
| 3024 | if (phone != null) { |
| 3025 | result.addAll(phone.getRadioPowerOffReasons()); |
| 3026 | } |
| 3027 | } finally { |
| 3028 | Binder.restoreCallingIdentity(identity); |
| 3029 | } |
| 3030 | return result; |
| 3031 | } |
| 3032 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3033 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3034 | @Override |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 3035 | public boolean enableDataConnectivity(String callingPackage) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3036 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3037 | |
| 3038 | final long identity = Binder.clearCallingIdentity(); |
| 3039 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3040 | int subId = SubscriptionManager.getDefaultDataSubscriptionId(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3041 | final Phone phone = getPhone(subId); |
| 3042 | if (phone != null) { |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 3043 | phone.getDataSettingsManager().setDataEnabled( |
| 3044 | TelephonyManager.DATA_ENABLED_REASON_USER, true, callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3045 | return true; |
| 3046 | } else { |
| 3047 | return false; |
| 3048 | } |
| 3049 | } finally { |
| 3050 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3051 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3052 | } |
| 3053 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3054 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3055 | @Override |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 3056 | public boolean disableDataConnectivity(String callingPackage) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3057 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3058 | |
| 3059 | final long identity = Binder.clearCallingIdentity(); |
| 3060 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3061 | int subId = SubscriptionManager.getDefaultDataSubscriptionId(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3062 | final Phone phone = getPhone(subId); |
| 3063 | if (phone != null) { |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 3064 | phone.getDataSettingsManager().setDataEnabled( |
| 3065 | TelephonyManager.DATA_ENABLED_REASON_USER, false, callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3066 | return true; |
| 3067 | } else { |
| 3068 | return false; |
| 3069 | } |
| 3070 | } finally { |
| 3071 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3072 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3073 | } |
| 3074 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3075 | @Override |
Jack Yu | acf8a13 | 2017-05-01 17:00:48 -0700 | [diff] [blame] | 3076 | public boolean isDataConnectivityPossible(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3077 | final long identity = Binder.clearCallingIdentity(); |
| 3078 | try { |
| 3079 | final Phone phone = getPhone(subId); |
| 3080 | if (phone != null) { |
Jack Yu | 59824e1 | 2022-03-23 01:42:44 -0700 | [diff] [blame] | 3081 | return phone.isDataAllowed(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3082 | } else { |
| 3083 | return false; |
| 3084 | } |
| 3085 | } finally { |
| 3086 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3087 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3088 | } |
| 3089 | |
| 3090 | public boolean handlePinMmi(String dialString) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 3091 | return handlePinMmiForSubscriber(getDefaultSubscription(), dialString); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3092 | } |
| 3093 | |
pkanwar | ae03a6b | 2016-11-06 20:37:09 -0800 | [diff] [blame] | 3094 | public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3095 | enforceCallPermission(); |
| 3096 | |
| 3097 | final long identity = Binder.clearCallingIdentity(); |
| 3098 | try { |
| 3099 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3100 | return; |
| 3101 | } |
| 3102 | Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback); |
| 3103 | sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId); |
| 3104 | } finally { |
| 3105 | Binder.restoreCallingIdentity(identity); |
| 3106 | } |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 3107 | }; |
| 3108 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3109 | public boolean handlePinMmiForSubscriber(int subId, String dialString) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3110 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3111 | |
| 3112 | final long identity = Binder.clearCallingIdentity(); |
| 3113 | try { |
| 3114 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3115 | return false; |
| 3116 | } |
| 3117 | return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId); |
| 3118 | } finally { |
| 3119 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3120 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3121 | } |
| 3122 | |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 3123 | /** |
| 3124 | * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage |
| 3125 | * tag on getCallState Binder call. |
| 3126 | */ |
| 3127 | @Deprecated |
| 3128 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3129 | public int getCallState() { |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 3130 | if (CompatChanges.isChangeEnabled( |
| 3131 | TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION, |
| 3132 | Binder.getCallingUid())) { |
| 3133 | // Do not allow this API to be called on API version 31+, it should only be |
| 3134 | // called on old apps using this Binder call directly. |
| 3135 | throw new SecurityException("This method can only be used for applications " |
| 3136 | + "targeting API version 30 or less."); |
| 3137 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3138 | final long identity = Binder.clearCallingIdentity(); |
| 3139 | try { |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 3140 | Phone phone = getPhone(getDefaultSubscription()); |
| 3141 | return phone == null ? TelephonyManager.CALL_STATE_IDLE : |
| 3142 | PhoneConstantConversions.convertCallState(phone.getState()); |
| 3143 | } finally { |
| 3144 | Binder.restoreCallingIdentity(identity); |
| 3145 | } |
| 3146 | } |
| 3147 | |
| 3148 | @Override |
| 3149 | public int getCallStateForSubscription(int subId, String callingPackage, String featureId) { |
| 3150 | if (CompatChanges.isChangeEnabled( |
| 3151 | TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION, |
| 3152 | Binder.getCallingUid())) { |
| 3153 | // Check READ_PHONE_STATE for API version 31+ |
| 3154 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage, |
| 3155 | featureId, "getCallStateForSubscription")) { |
| 3156 | throw new SecurityException("getCallState requires READ_PHONE_STATE for apps " |
| 3157 | + "targeting API level 31+."); |
| 3158 | } |
| 3159 | } |
| 3160 | final long identity = Binder.clearCallingIdentity(); |
| 3161 | try { |
| 3162 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3163 | return phone == null ? TelephonyManager.CALL_STATE_IDLE : |
| 3164 | PhoneConstantConversions.convertCallState(phone.getState()); |
| 3165 | } finally { |
| 3166 | Binder.restoreCallingIdentity(identity); |
| 3167 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3168 | } |
| 3169 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3170 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 3171 | public int getDataState() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3172 | return getDataStateForSubId(SubscriptionManager.getDefaultDataSubscriptionId()); |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 3173 | } |
| 3174 | |
| 3175 | @Override |
| 3176 | public int getDataStateForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3177 | final long identity = Binder.clearCallingIdentity(); |
| 3178 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 3179 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3180 | if (phone != null) { |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 3181 | return phone.getDataNetworkController().getInternetDataNetworkState(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3182 | } else { |
| 3183 | return PhoneConstantConversions.convertDataState( |
| 3184 | PhoneConstants.DataState.DISCONNECTED); |
| 3185 | } |
| 3186 | } finally { |
| 3187 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3188 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3189 | } |
| 3190 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3191 | @Override |
Jack Yu | 0eda684 | 2022-04-18 00:34:46 -0700 | [diff] [blame] | 3192 | public @DataActivityType int getDataActivity() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3193 | return getDataActivityForSubId(SubscriptionManager.getDefaultDataSubscriptionId()); |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 3194 | } |
| 3195 | |
| 3196 | @Override |
Jack Yu | 0eda684 | 2022-04-18 00:34:46 -0700 | [diff] [blame] | 3197 | public @DataActivityType int getDataActivityForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3198 | final long identity = Binder.clearCallingIdentity(); |
| 3199 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 3200 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3201 | if (phone != null) { |
Jack Yu | 0eda684 | 2022-04-18 00:34:46 -0700 | [diff] [blame] | 3202 | return phone.getDataActivityState(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3203 | } else { |
| 3204 | return TelephonyManager.DATA_ACTIVITY_NONE; |
| 3205 | } |
| 3206 | } finally { |
| 3207 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3208 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3209 | } |
| 3210 | |
| 3211 | @Override |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 3212 | public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3213 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 3214 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3215 | |
| 3216 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 3217 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 3218 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 3219 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3220 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3221 | .setCallingPid(Binder.getCallingPid()) |
| 3222 | .setCallingUid(Binder.getCallingUid()) |
| 3223 | .setMethod("getCellLocation") |
Hall Liu | 773ba02 | 2020-01-24 18:07:12 -0800 | [diff] [blame] | 3224 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3225 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 3226 | .build()); |
| 3227 | switch (locationResult) { |
| 3228 | case DENIED_HARD: |
| 3229 | throw new SecurityException("Not allowed to access cell location"); |
| 3230 | case DENIED_SOFT: |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 3231 | return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
| 3232 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3233 | } |
| 3234 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 3235 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3236 | final long identity = Binder.clearCallingIdentity(); |
| 3237 | try { |
| 3238 | if (DBG_LOC) log("getCellLocation: is active user"); |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3239 | int subId = SubscriptionManager.getDefaultDataSubscriptionId(); |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 3240 | return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3241 | } finally { |
| 3242 | Binder.restoreCallingIdentity(identity); |
| 3243 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 3244 | } |
| 3245 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3246 | @Override |
Jack Yu | eb1e7fe | 2020-02-22 19:38:58 -0800 | [diff] [blame] | 3247 | public String getNetworkCountryIsoForPhone(int phoneId) { |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3248 | // Reporting the correct network country is ambiguous when IWLAN could conflict with |
| 3249 | // registered cell info, so return a NULL country instead. |
| 3250 | final long identity = Binder.clearCallingIdentity(); |
| 3251 | try { |
Malcolm Chen | 3732c2b | 2018-07-18 20:15:24 -0700 | [diff] [blame] | 3252 | if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) { |
| 3253 | // Get default phone in this case. |
| 3254 | phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX; |
| 3255 | } |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3256 | final int subId = SubscriptionManager.getSubscriptionId(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3257 | Phone phone = PhoneFactory.getPhone(phoneId); |
Nathan Harold | 532f51c | 2020-04-21 19:31:10 -0700 | [diff] [blame] | 3258 | if (phone == null) return ""; |
| 3259 | ServiceStateTracker sst = phone.getServiceStateTracker(); |
| 3260 | if (sst == null) return ""; |
| 3261 | LocaleTracker lt = sst.getLocaleTracker(); |
| 3262 | if (lt == null) return ""; |
Shuo Qian | 9418a92 | 2021-03-09 11:21:16 -0800 | [diff] [blame] | 3263 | return lt.getCurrentCountry(); |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3264 | } finally { |
| 3265 | Binder.restoreCallingIdentity(identity); |
| 3266 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3267 | } |
| 3268 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 3269 | /** |
| 3270 | * This method was removed due to potential issues caused by performing partial |
| 3271 | * updates of service state, and lack of a credible use case. |
| 3272 | * |
| 3273 | * This has the ability to break the telephony implementation by disabling notification of |
| 3274 | * changes in device connectivity. DO NOT USE THIS! |
| 3275 | */ |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3276 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3277 | public void enableLocationUpdates() { |
| 3278 | mApp.enforceCallingOrSelfPermission( |
| 3279 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3280 | } |
| 3281 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 3282 | /** |
| 3283 | * This method was removed due to potential issues caused by performing partial |
| 3284 | * updates of service state, and lack of a credible use case. |
| 3285 | * |
| 3286 | * This has the ability to break the telephony implementation by disabling notification of |
| 3287 | * changes in device connectivity. DO NOT USE THIS! |
| 3288 | */ |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3289 | @Override |
| 3290 | public void disableLocationUpdates() { |
| 3291 | mApp.enforceCallingOrSelfPermission( |
| 3292 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3293 | } |
| 3294 | |
| 3295 | @Override |
| 3296 | @SuppressWarnings("unchecked") |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3297 | public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage, |
| 3298 | String callingFeatureId) { |
Nathan Harold | b55f63b | 2021-07-27 11:27:38 -0700 | [diff] [blame] | 3299 | try { |
| 3300 | mApp.getSystemService(AppOpsManager.class) |
| 3301 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 3302 | } catch (SecurityException e) { |
| 3303 | EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid()); |
| 3304 | throw e; |
| 3305 | } |
| 3306 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3307 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | dbea45a | 2018-08-30 14:35:07 -0700 | [diff] [blame] | 3308 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 3309 | throw new SecurityException( |
| 3310 | "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels."); |
| 3311 | } |
Nathan Harold | b4d5561 | 2018-07-20 13:13:08 -0700 | [diff] [blame] | 3312 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 3313 | if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(), |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3314 | callingPackage) != AppOpsManager.MODE_ALLOWED) { |
| 3315 | return null; |
| 3316 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 3317 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 3318 | if (DBG_LOC) log("getNeighboringCellInfo: is active user"); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3319 | |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3320 | List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId); |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 3321 | if (info == null) return null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3322 | |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 3323 | List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>(); |
| 3324 | for (CellInfo ci : info) { |
| 3325 | if (ci instanceof CellInfoGsm) { |
| 3326 | neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci)); |
| 3327 | } else if (ci instanceof CellInfoWcdma) { |
| 3328 | neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci)); |
| 3329 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3330 | } |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 3331 | return (neighbors.size()) > 0 ? neighbors : null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3332 | } |
| 3333 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3334 | private List<CellInfo> getCachedCellInfo() { |
| 3335 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 3336 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3337 | List<CellInfo> info = phone.getAllCellInfo(); |
| 3338 | if (info != null) cellInfos.addAll(info); |
| 3339 | } |
| 3340 | return cellInfos; |
| 3341 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3342 | |
| 3343 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3344 | public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3345 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 3346 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3347 | |
| 3348 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 3349 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 3350 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 3351 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3352 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3353 | .setCallingPid(Binder.getCallingPid()) |
| 3354 | .setCallingUid(Binder.getCallingUid()) |
| 3355 | .setMethod("getAllCellInfo") |
Nathan Harold | 5ae50b5 | 2019-02-20 15:46:36 -0800 | [diff] [blame] | 3356 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3357 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 3358 | .build()); |
| 3359 | switch (locationResult) { |
| 3360 | case DENIED_HARD: |
| 3361 | throw new SecurityException("Not allowed to access cell info"); |
| 3362 | case DENIED_SOFT: |
| 3363 | return new ArrayList<>(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3364 | } |
| 3365 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3366 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3367 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 3368 | return getCachedCellInfo(); |
| 3369 | } |
| 3370 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 3371 | if (DBG_LOC) log("getAllCellInfo: is active user"); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 3372 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3373 | final long identity = Binder.clearCallingIdentity(); |
| 3374 | try { |
| 3375 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 3376 | for (Phone phone : PhoneFactory.getPhones()) { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 3377 | final List<CellInfo> info = (List<CellInfo>) sendRequest( |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 3378 | CMD_GET_ALL_CELL_INFO, null, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3379 | if (info != null) cellInfos.addAll(info); |
| 3380 | } |
| 3381 | return cellInfos; |
| 3382 | } finally { |
| 3383 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3384 | } |
| 3385 | } |
| 3386 | |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 3387 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3388 | public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage, |
| 3389 | String callingFeatureId) { |
| 3390 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, |
| 3391 | getWorkSource(Binder.getCallingUid())); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3392 | } |
| 3393 | |
| 3394 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3395 | public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb, |
| 3396 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3397 | enforceModifyPermission(); |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3398 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3399 | } |
| 3400 | |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3401 | private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb, |
| 3402 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3403 | mApp.getSystemService(AppOpsManager.class) |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3404 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3405 | |
| 3406 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 3407 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 3408 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 3409 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3410 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3411 | .setCallingPid(Binder.getCallingPid()) |
| 3412 | .setCallingUid(Binder.getCallingUid()) |
| 3413 | .setMethod("requestCellInfoUpdate") |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 3414 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
| 3415 | .setMinSdkVersionForFine(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3416 | .build()); |
| 3417 | switch (locationResult) { |
| 3418 | case DENIED_HARD: |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3419 | if (TelephonyPermissions |
| 3420 | .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) { |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 3421 | // Safetynet logging for b/154934934 |
| 3422 | EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid()); |
| 3423 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3424 | throw new SecurityException("Not allowed to access cell info"); |
| 3425 | case DENIED_SOFT: |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3426 | if (TelephonyPermissions |
| 3427 | .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) { |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 3428 | // Safetynet logging for b/154934934 |
| 3429 | EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid()); |
| 3430 | } |
Nathan Harold | 5320c42 | 2019-05-09 10:26:08 -0700 | [diff] [blame] | 3431 | try { |
| 3432 | cb.onCellInfo(new ArrayList<CellInfo>()); |
| 3433 | } catch (RemoteException re) { |
| 3434 | // Drop without consequences |
| 3435 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3436 | return; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3437 | } |
| 3438 | |
Nathan Harold | a939a96 | 2019-05-09 10:13:47 -0700 | [diff] [blame] | 3439 | |
| 3440 | final Phone phone = getPhoneFromSubId(subId); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3441 | if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
| 3442 | |
| 3443 | sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource); |
| 3444 | } |
| 3445 | |
| 3446 | @Override |
Aishwarya Mallampati | 0603fb1 | 2022-08-24 21:16:56 +0000 | [diff] [blame] | 3447 | public void setCellInfoListRate(int rateInMillis, int subId) { |
Jack Yu | a8d8cb8 | 2017-01-16 10:15:34 -0800 | [diff] [blame] | 3448 | enforceModifyPermission(); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 3449 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3450 | |
| 3451 | final long identity = Binder.clearCallingIdentity(); |
| 3452 | try { |
Aishwarya Mallampati | 0603fb1 | 2022-08-24 21:16:56 +0000 | [diff] [blame] | 3453 | Phone phone = getPhone(subId); |
| 3454 | if (phone == null) { |
| 3455 | getDefaultPhone().setCellInfoListRate(rateInMillis, workSource); |
| 3456 | } else { |
| 3457 | phone.setCellInfoListRate(rateInMillis, workSource); |
| 3458 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3459 | } finally { |
| 3460 | Binder.restoreCallingIdentity(identity); |
| 3461 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3462 | } |
| 3463 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3464 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3465 | public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3466 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3467 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3468 | return null; |
| 3469 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3470 | int subId = phone.getSubId(); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3471 | enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot"); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 3472 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3473 | callingPackage, callingFeatureId, "getImeiForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3474 | return null; |
| 3475 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3476 | |
| 3477 | final long identity = Binder.clearCallingIdentity(); |
| 3478 | try { |
| 3479 | return phone.getImei(); |
| 3480 | } finally { |
| 3481 | Binder.restoreCallingIdentity(identity); |
| 3482 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3483 | } |
| 3484 | |
| 3485 | @Override |
arunvoddu | d5c6ce0 | 2022-12-11 06:03:12 +0000 | [diff] [blame] | 3486 | public String getPrimaryImei(String callingPackage, String callingFeatureId) { |
| 3487 | enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getPrimaryImei"); |
| 3488 | if (!checkCallingOrSelfReadDeviceIdentifiersForAnySub(mApp, callingPackage, |
| 3489 | callingFeatureId, "getPrimaryImei")) { |
| 3490 | throw new SecurityException("Caller does not have permission"); |
| 3491 | } |
| 3492 | final long identity = Binder.clearCallingIdentity(); |
| 3493 | try { |
| 3494 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3495 | if (phone.getImeiType() == Phone.IMEI_TYPE_PRIMARY) { |
| 3496 | return phone.getImei(); |
| 3497 | } |
| 3498 | } |
| 3499 | throw new UnsupportedOperationException("Operation not supported"); |
| 3500 | } finally { |
| 3501 | Binder.restoreCallingIdentity(identity); |
| 3502 | } |
| 3503 | } |
| 3504 | |
| 3505 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3506 | public String getTypeAllocationCodeForSlot(int slotIndex) { |
| 3507 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3508 | String tac = null; |
| 3509 | if (phone != null) { |
| 3510 | String imei = phone.getImei(); |
Vala Zadeh | ab00555 | 2021-09-21 15:54:29 -0700 | [diff] [blame] | 3511 | try { |
| 3512 | tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH); |
| 3513 | } catch (IndexOutOfBoundsException e) { |
| 3514 | Log.e(LOG_TAG, "IMEI length shorter than upper index."); |
| 3515 | return null; |
| 3516 | } |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3517 | } |
| 3518 | return tac; |
| 3519 | } |
| 3520 | |
| 3521 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3522 | public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Shuo Qian | 13d8915 | 2021-05-10 23:58:11 -0700 | [diff] [blame] | 3523 | try { |
| 3524 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 3525 | } catch (SecurityException se) { |
| 3526 | EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid()); |
| 3527 | throw new SecurityException("Package " + callingPackage + " does not belong to " |
| 3528 | + Binder.getCallingUid()); |
| 3529 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3530 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3531 | if (phone == null) { |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 3532 | return null; |
| 3533 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3534 | |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3535 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 3536 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3537 | callingPackage, callingFeatureId, "getMeidForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3538 | return null; |
| 3539 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3540 | |
| 3541 | final long identity = Binder.clearCallingIdentity(); |
| 3542 | try { |
| 3543 | return phone.getMeid(); |
| 3544 | } finally { |
| 3545 | Binder.restoreCallingIdentity(identity); |
| 3546 | } |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 3547 | } |
| 3548 | |
| 3549 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3550 | public String getManufacturerCodeForSlot(int slotIndex) { |
| 3551 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3552 | String manufacturerCode = null; |
| 3553 | if (phone != null) { |
| 3554 | String meid = phone.getMeid(); |
Vala Zadeh | ab00555 | 2021-09-21 15:54:29 -0700 | [diff] [blame] | 3555 | try { |
| 3556 | manufacturerCode = |
| 3557 | meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH); |
| 3558 | } catch (IndexOutOfBoundsException e) { |
| 3559 | Log.e(LOG_TAG, "MEID length shorter than upper index."); |
| 3560 | return null; |
| 3561 | } |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3562 | } |
| 3563 | return manufacturerCode; |
| 3564 | } |
| 3565 | |
| 3566 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3567 | public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage, |
| 3568 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3569 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3570 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3571 | return null; |
| 3572 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3573 | int subId = phone.getSubId(); |
| 3574 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3575 | mApp, subId, callingPackage, callingFeatureId, |
| 3576 | "getDeviceSoftwareVersionForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3577 | return null; |
| 3578 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3579 | |
| 3580 | final long identity = Binder.clearCallingIdentity(); |
| 3581 | try { |
| 3582 | return phone.getDeviceSvn(); |
| 3583 | } finally { |
| 3584 | Binder.restoreCallingIdentity(identity); |
| 3585 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3586 | } |
| 3587 | |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3588 | @Override |
| 3589 | public int getSubscriptionCarrierId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3590 | final long identity = Binder.clearCallingIdentity(); |
| 3591 | try { |
| 3592 | final Phone phone = getPhone(subId); |
| 3593 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId(); |
| 3594 | } finally { |
| 3595 | Binder.restoreCallingIdentity(identity); |
| 3596 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3597 | } |
| 3598 | |
| 3599 | @Override |
| 3600 | public String getSubscriptionCarrierName(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3601 | final long identity = Binder.clearCallingIdentity(); |
| 3602 | try { |
| 3603 | final Phone phone = getPhone(subId); |
| 3604 | return phone == null ? null : phone.getCarrierName(); |
| 3605 | } finally { |
| 3606 | Binder.restoreCallingIdentity(identity); |
| 3607 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3608 | } |
| 3609 | |
calvinpan | ffe225e | 2018-11-01 19:43:06 +0800 | [diff] [blame] | 3610 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3611 | public int getSubscriptionSpecificCarrierId(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3612 | final long identity = Binder.clearCallingIdentity(); |
| 3613 | try { |
| 3614 | final Phone phone = getPhone(subId); |
| 3615 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3616 | : phone.getSpecificCarrierId(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3617 | } finally { |
| 3618 | Binder.restoreCallingIdentity(identity); |
| 3619 | } |
| 3620 | } |
| 3621 | |
| 3622 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3623 | public String getSubscriptionSpecificCarrierName(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3624 | final long identity = Binder.clearCallingIdentity(); |
| 3625 | try { |
| 3626 | final Phone phone = getPhone(subId); |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3627 | return phone == null ? null : phone.getSpecificCarrierName(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3628 | } finally { |
| 3629 | Binder.restoreCallingIdentity(identity); |
| 3630 | } |
| 3631 | } |
| 3632 | |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 3633 | @Override |
chen xu | 864e11c | 2018-12-06 22:10:03 -0800 | [diff] [blame] | 3634 | public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) { |
| 3635 | if (!isSubscriptionMccMnc) { |
| 3636 | enforceReadPrivilegedPermission("getCarrierIdFromMccMnc"); |
| 3637 | } |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 3638 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3639 | if (phone == null) { |
| 3640 | return TelephonyManager.UNKNOWN_CARRIER_ID; |
| 3641 | } |
| 3642 | final long identity = Binder.clearCallingIdentity(); |
| 3643 | try { |
| 3644 | return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc); |
| 3645 | } finally { |
| 3646 | Binder.restoreCallingIdentity(identity); |
| 3647 | } |
| 3648 | } |
| 3649 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3650 | // |
| 3651 | // Internal helper methods. |
| 3652 | // |
| 3653 | |
Sanket Padawe | ee13a9b | 2016-03-08 17:30:28 -0800 | [diff] [blame] | 3654 | /** |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3655 | * Make sure the caller is the calling package itself |
| 3656 | * |
| 3657 | * @throws SecurityException if the caller is not the calling package |
| 3658 | */ |
| 3659 | private void enforceCallingPackage(String callingPackage, int callingUid, String message) { |
| 3660 | int packageUid = -1; |
Grace Jia | dbefca0 | 2021-04-26 15:13:31 -0700 | [diff] [blame] | 3661 | PackageManager pm = mApp.getBaseContext().createContextAsUser( |
| 3662 | UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager(); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3663 | try { |
Grace Jia | dbefca0 | 2021-04-26 15:13:31 -0700 | [diff] [blame] | 3664 | packageUid = pm.getPackageUid(callingPackage, 0); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3665 | } catch (PackageManager.NameNotFoundException e) { |
| 3666 | // packageUid is -1 |
| 3667 | } |
| 3668 | if (packageUid != callingUid) { |
| 3669 | throw new SecurityException(message + ": Package " + callingPackage |
| 3670 | + " does not belong to " + callingUid); |
| 3671 | } |
| 3672 | } |
| 3673 | |
| 3674 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3675 | * Make sure the caller has the MODIFY_PHONE_STATE permission. |
| 3676 | * |
| 3677 | * @throws SecurityException if the caller does not have the required permission |
| 3678 | */ |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 3679 | @VisibleForTesting |
| 3680 | public void enforceModifyPermission() { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3681 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null); |
| 3682 | } |
| 3683 | |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 3684 | /** |
| 3685 | * Make sure the caller has the MODIFY_PHONE_STATE permission. |
| 3686 | * |
| 3687 | * @throws SecurityException if the caller does not have the required permission |
| 3688 | */ |
| 3689 | @VisibleForTesting |
| 3690 | public void enforceReadPermission() { |
| 3691 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, null); |
| 3692 | } |
| 3693 | |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 3694 | private void enforceActiveEmergencySessionPermission() { |
| 3695 | mApp.enforceCallingOrSelfPermission( |
| 3696 | android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null); |
| 3697 | } |
| 3698 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3699 | /** |
| 3700 | * Make sure the caller has the CALL_PHONE permission. |
| 3701 | * |
| 3702 | * @throws SecurityException if the caller does not have the required permission |
| 3703 | */ |
| 3704 | private void enforceCallPermission() { |
| 3705 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null); |
| 3706 | } |
| 3707 | |
paulhu | 5a77360 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 3708 | private void enforceSettingsPermission() { |
| 3709 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 3710 | } |
| 3711 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 3712 | private void enforceRebootPermission() { |
| 3713 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null); |
| 3714 | } |
| 3715 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3716 | private String createTelUrl(String number) { |
| 3717 | if (TextUtils.isEmpty(number)) { |
| 3718 | return null; |
| 3719 | } |
| 3720 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3721 | return "tel:" + number; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3722 | } |
| 3723 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3724 | private static void log(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3725 | Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 3726 | } |
| 3727 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3728 | private static void logv(String msg) { |
| 3729 | Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 3730 | } |
| 3731 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3732 | private static void loge(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3733 | Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 3734 | } |
| 3735 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3736 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3737 | public int getActivePhoneType() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3738 | return getActivePhoneTypeForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3739 | } |
| 3740 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3741 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3742 | public int getActivePhoneTypeForSlot(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3743 | final long identity = Binder.clearCallingIdentity(); |
| 3744 | try { |
| 3745 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3746 | if (phone == null) { |
| 3747 | return PhoneConstants.PHONE_TYPE_NONE; |
| 3748 | } else { |
| 3749 | return phone.getPhoneType(); |
| 3750 | } |
| 3751 | } finally { |
| 3752 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3753 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3754 | } |
| 3755 | |
| 3756 | /** |
| 3757 | * Returns the CDMA ERI icon index to display |
| 3758 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3759 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3760 | public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) { |
| 3761 | return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage, |
| 3762 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3763 | } |
| 3764 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3765 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3766 | public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage, |
| 3767 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3768 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3769 | mApp, subId, callingPackage, callingFeatureId, |
| 3770 | "getCdmaEriIconIndexForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3771 | return -1; |
| 3772 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3773 | |
| 3774 | final long identity = Binder.clearCallingIdentity(); |
| 3775 | try { |
| 3776 | final Phone phone = getPhone(subId); |
| 3777 | if (phone != null) { |
| 3778 | return phone.getCdmaEriIconIndex(); |
| 3779 | } else { |
| 3780 | return -1; |
| 3781 | } |
| 3782 | } finally { |
| 3783 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3784 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3785 | } |
| 3786 | |
| 3787 | /** |
| 3788 | * Returns the CDMA ERI icon mode, |
| 3789 | * 0 - ON |
| 3790 | * 1 - FLASHING |
| 3791 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3792 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3793 | public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) { |
| 3794 | return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 3795 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3796 | } |
| 3797 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3798 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3799 | public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage, |
| 3800 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3801 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3802 | mApp, subId, callingPackage, callingFeatureId, |
| 3803 | "getCdmaEriIconModeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3804 | return -1; |
| 3805 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3806 | |
| 3807 | final long identity = Binder.clearCallingIdentity(); |
| 3808 | try { |
| 3809 | final Phone phone = getPhone(subId); |
| 3810 | if (phone != null) { |
| 3811 | return phone.getCdmaEriIconMode(); |
| 3812 | } else { |
| 3813 | return -1; |
| 3814 | } |
| 3815 | } finally { |
| 3816 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3817 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3818 | } |
| 3819 | |
| 3820 | /** |
| 3821 | * Returns the CDMA ERI text, |
| 3822 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3823 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3824 | public String getCdmaEriText(String callingPackage, String callingFeatureId) { |
| 3825 | return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage, |
| 3826 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3827 | } |
| 3828 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3829 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3830 | public String getCdmaEriTextForSubscriber(int subId, String callingPackage, |
| 3831 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3832 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3833 | mApp, subId, callingPackage, callingFeatureId, |
| 3834 | "getCdmaEriIconTextForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3835 | return null; |
| 3836 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3837 | |
| 3838 | final long identity = Binder.clearCallingIdentity(); |
| 3839 | try { |
| 3840 | final Phone phone = getPhone(subId); |
| 3841 | if (phone != null) { |
| 3842 | return phone.getCdmaEriText(); |
| 3843 | } else { |
| 3844 | return null; |
| 3845 | } |
| 3846 | } finally { |
| 3847 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3848 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3849 | } |
| 3850 | |
| 3851 | /** |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3852 | * Returns the CDMA MDN. |
| 3853 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3854 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3855 | public String getCdmaMdn(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3856 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3857 | mApp, subId, "getCdmaMdn"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3858 | |
| 3859 | final long identity = Binder.clearCallingIdentity(); |
| 3860 | try { |
| 3861 | final Phone phone = getPhone(subId); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3862 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3863 | return phone.getLine1Number(); |
| 3864 | } else { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3865 | loge("getCdmaMdn: no phone found. Invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3866 | return null; |
| 3867 | } |
| 3868 | } finally { |
| 3869 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3870 | } |
| 3871 | } |
| 3872 | |
| 3873 | /** |
| 3874 | * Returns the CDMA MIN. |
| 3875 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3876 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3877 | public String getCdmaMin(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3878 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3879 | mApp, subId, "getCdmaMin"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3880 | |
| 3881 | final long identity = Binder.clearCallingIdentity(); |
| 3882 | try { |
| 3883 | final Phone phone = getPhone(subId); |
| 3884 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
| 3885 | return phone.getCdmaMin(); |
| 3886 | } else { |
| 3887 | return null; |
| 3888 | } |
| 3889 | } finally { |
| 3890 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3891 | } |
| 3892 | } |
| 3893 | |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3894 | @Override |
| 3895 | public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis, |
| 3896 | INumberVerificationCallback callback, String callingPackage) { |
| 3897 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 3898 | != PERMISSION_GRANTED) { |
| 3899 | throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission"); |
| 3900 | } |
| 3901 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 3902 | |
| 3903 | String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp); |
| 3904 | if (!TextUtils.equals(callingPackage, authorizedPackage)) { |
Hall Liu | b9d8feb | 2021-01-13 10:28:04 -0800 | [diff] [blame] | 3905 | throw new SecurityException("Calling package must be configured in the device config: " |
| 3906 | + "calling package: " + callingPackage |
| 3907 | + ", configured package: " + authorizedPackage); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3908 | } |
| 3909 | |
| 3910 | if (range == null) { |
| 3911 | throw new NullPointerException("Range must be non-null"); |
| 3912 | } |
| 3913 | |
| 3914 | timeoutMillis = Math.min(timeoutMillis, |
Hall Liu | bd069e3 | 2019-02-28 18:56:30 -0800 | [diff] [blame] | 3915 | TelephonyManager.getMaxNumberVerificationTimeoutMillis()); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3916 | |
| 3917 | NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis); |
| 3918 | } |
| 3919 | |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3920 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3921 | * Returns true if CDMA provisioning needs to run. |
| 3922 | */ |
| 3923 | public boolean needsOtaServiceProvisioning() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3924 | final long identity = Binder.clearCallingIdentity(); |
| 3925 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3926 | return getDefaultPhone().needsOtaServiceProvisioning(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3927 | } finally { |
| 3928 | Binder.restoreCallingIdentity(identity); |
| 3929 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3930 | } |
| 3931 | |
| 3932 | /** |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3933 | * Sets the voice mail number of a given subId. |
| 3934 | */ |
| 3935 | @Override |
| 3936 | public boolean setVoiceMailNumber(int subId, String alphaTag, String number) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 3937 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 3938 | mApp, subId, "setVoiceMailNumber"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3939 | |
| 3940 | final long identity = Binder.clearCallingIdentity(); |
| 3941 | try { |
| 3942 | Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER, |
| 3943 | new Pair<String, String>(alphaTag, number), new Integer(subId)); |
| 3944 | return success; |
| 3945 | } finally { |
| 3946 | Binder.restoreCallingIdentity(identity); |
| 3947 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3948 | } |
| 3949 | |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3950 | @Override |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3951 | public Bundle getVisualVoicemailSettings(String callingPackage, int subId) { |
| 3952 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 3953 | TelecomManager tm = mApp.getSystemService(TelecomManager.class); |
| 3954 | String systemDialer = tm.getSystemDialerPackage(); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3955 | if (!TextUtils.equals(callingPackage, systemDialer)) { |
| 3956 | throw new SecurityException("caller must be system dialer"); |
| 3957 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3958 | |
| 3959 | final long identity = Binder.clearCallingIdentity(); |
| 3960 | try { |
| 3961 | PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId); |
| 3962 | if (phoneAccountHandle == null) { |
| 3963 | return null; |
| 3964 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3965 | return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3966 | } finally { |
| 3967 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3968 | } |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3969 | } |
| 3970 | |
| 3971 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3972 | public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId, |
| 3973 | int subId) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3974 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3975 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3976 | mApp, subId, callingPackage, callingFeatureId, |
| 3977 | "getVisualVoicemailPackageName")) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3978 | return null; |
| 3979 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3980 | |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 3981 | final long identity = Binder.clearCallingIdentity(); |
| 3982 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3983 | return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName(); |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 3984 | } finally { |
| 3985 | Binder.restoreCallingIdentity(identity); |
| 3986 | } |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3987 | } |
| 3988 | |
| 3989 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3990 | public void enableVisualVoicemailSmsFilter(String callingPackage, int subId, |
| 3991 | VisualVoicemailSmsFilterSettings settings) { |
| 3992 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3993 | |
| 3994 | final long identity = Binder.clearCallingIdentity(); |
| 3995 | try { |
| 3996 | VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3997 | mApp, callingPackage, subId, settings); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3998 | } finally { |
| 3999 | Binder.restoreCallingIdentity(identity); |
| 4000 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 4001 | } |
| 4002 | |
| 4003 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 4004 | public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) { |
| 4005 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4006 | |
| 4007 | final long identity = Binder.clearCallingIdentity(); |
| 4008 | try { |
| 4009 | VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4010 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4011 | } finally { |
| 4012 | Binder.restoreCallingIdentity(identity); |
| 4013 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 4014 | } |
| 4015 | |
| 4016 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 4017 | public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings( |
| 4018 | String callingPackage, int subId) { |
| 4019 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4020 | |
| 4021 | final long identity = Binder.clearCallingIdentity(); |
| 4022 | try { |
| 4023 | return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4024 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4025 | } finally { |
| 4026 | Binder.restoreCallingIdentity(identity); |
| 4027 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 4028 | } |
| 4029 | |
| 4030 | @Override |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 4031 | public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4032 | enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4033 | |
| 4034 | final long identity = Binder.clearCallingIdentity(); |
| 4035 | try { |
| 4036 | return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4037 | mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4038 | } finally { |
| 4039 | Binder.restoreCallingIdentity(identity); |
| 4040 | } |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 4041 | } |
| 4042 | |
| 4043 | @Override |
Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 4044 | public void sendVisualVoicemailSmsForSubscriber(String callingPackage, |
| 4045 | String callingAttributionTag, int subId, String number, int port, String text, |
| 4046 | PendingIntent sentIntent) { |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 4047 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 4048 | enforceVisualVoicemailPackage(callingPackage, subId); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 4049 | enforceSendSmsPermission(); |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 4050 | SmsController smsController = PhoneFactory.getSmsController(); |
Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 4051 | smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag, |
| 4052 | subId, number, port, text, sentIntent); |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 4053 | } |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 4054 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 4055 | /** |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4056 | * Sets the voice activation state of a given subId. |
| 4057 | */ |
| 4058 | @Override |
| 4059 | public void setVoiceActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4060 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4061 | mApp, subId, "setVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4062 | |
| 4063 | final long identity = Binder.clearCallingIdentity(); |
| 4064 | try { |
| 4065 | final Phone phone = getPhone(subId); |
| 4066 | if (phone != null) { |
| 4067 | phone.setVoiceActivationState(activationState); |
| 4068 | } else { |
| 4069 | loge("setVoiceActivationState fails with invalid subId: " + subId); |
| 4070 | } |
| 4071 | } finally { |
| 4072 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4073 | } |
| 4074 | } |
| 4075 | |
| 4076 | /** |
| 4077 | * Sets the data activation state of a given subId. |
| 4078 | */ |
| 4079 | @Override |
| 4080 | public void setDataActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4081 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4082 | mApp, subId, "setDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4083 | |
| 4084 | final long identity = Binder.clearCallingIdentity(); |
| 4085 | try { |
| 4086 | final Phone phone = getPhone(subId); |
| 4087 | if (phone != null) { |
| 4088 | phone.setDataActivationState(activationState); |
| 4089 | } else { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 4090 | loge("setDataActivationState fails with invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4091 | } |
| 4092 | } finally { |
| 4093 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4094 | } |
| 4095 | } |
| 4096 | |
| 4097 | /** |
| 4098 | * Returns the voice activation state of a given subId. |
| 4099 | */ |
| 4100 | @Override |
| 4101 | public int getVoiceActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4102 | enforceReadPrivilegedPermission("getVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4103 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4104 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4105 | final long identity = Binder.clearCallingIdentity(); |
| 4106 | try { |
| 4107 | if (phone != null) { |
| 4108 | return phone.getVoiceActivationState(); |
| 4109 | } else { |
| 4110 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 4111 | } |
| 4112 | } finally { |
| 4113 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4114 | } |
| 4115 | } |
| 4116 | |
| 4117 | /** |
| 4118 | * Returns the data activation state of a given subId. |
| 4119 | */ |
| 4120 | @Override |
| 4121 | public int getDataActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4122 | enforceReadPrivilegedPermission("getDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4123 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4124 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4125 | final long identity = Binder.clearCallingIdentity(); |
| 4126 | try { |
| 4127 | if (phone != null) { |
| 4128 | return phone.getDataActivationState(); |
| 4129 | } else { |
| 4130 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 4131 | } |
| 4132 | } finally { |
| 4133 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4134 | } |
| 4135 | } |
| 4136 | |
| 4137 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4138 | * Returns the unread count of voicemails for a subId |
| 4139 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4140 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4141 | public int getVoiceMessageCountForSubscriber(int subId, String callingPackage, |
| 4142 | String callingFeatureId) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 4143 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4144 | mApp, subId, callingPackage, callingFeatureId, |
| 4145 | "getVoiceMessageCountForSubscriber")) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 4146 | return 0; |
| 4147 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4148 | final long identity = Binder.clearCallingIdentity(); |
| 4149 | try { |
| 4150 | final Phone phone = getPhone(subId); |
| 4151 | if (phone != null) { |
| 4152 | return phone.getVoiceMessageCount(); |
| 4153 | } else { |
| 4154 | return 0; |
| 4155 | } |
| 4156 | } finally { |
| 4157 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4158 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4159 | } |
| 4160 | |
| 4161 | /** |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 4162 | * returns true, if the device is in a state where both voice and data |
| 4163 | * are supported simultaneously. This can change based on location or network condition. |
| 4164 | */ |
| 4165 | @Override |
| 4166 | public boolean isConcurrentVoiceAndDataAllowed(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4167 | final long identity = Binder.clearCallingIdentity(); |
| 4168 | try { |
| 4169 | final Phone phone = getPhone(subId); |
| 4170 | return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed()); |
| 4171 | } finally { |
| 4172 | Binder.restoreCallingIdentity(identity); |
| 4173 | } |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 4174 | } |
| 4175 | |
| 4176 | /** |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4177 | * Send the dialer code if called from the current default dialer or the caller has |
| 4178 | * carrier privilege. |
| 4179 | * @param inputCode The dialer code to send |
| 4180 | */ |
| 4181 | @Override |
| 4182 | public void sendDialerSpecialCode(String callingPackage, String inputCode) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4183 | final Phone defaultPhone = getDefaultPhone(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4184 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 4185 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 4186 | String defaultDialer = tm.getDefaultDialerPackage(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4187 | if (!TextUtils.equals(callingPackage, defaultDialer)) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 4188 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4189 | getDefaultSubscription(), "sendDialerSpecialCode"); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4190 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4191 | |
| 4192 | final long identity = Binder.clearCallingIdentity(); |
| 4193 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4194 | defaultPhone.sendDialerSpecialCode(inputCode); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4195 | } finally { |
| 4196 | Binder.restoreCallingIdentity(identity); |
| 4197 | } |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4198 | } |
| 4199 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 4200 | @Override |
| 4201 | public int getNetworkSelectionMode(int subId) { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 4202 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4203 | .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 4204 | mApp, subId, "getNetworkSelectionMode"); |
| 4205 | final long identity = Binder.clearCallingIdentity(); |
| 4206 | try { |
| 4207 | if (!isActiveSubscription(subId)) { |
| 4208 | return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 4209 | } |
| 4210 | return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId); |
| 4211 | } finally { |
| 4212 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 4213 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 4214 | } |
| 4215 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4216 | @Override |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 4217 | public boolean isInEmergencySmsMode() { |
| 4218 | enforceReadPrivilegedPermission("isInEmergencySmsMode"); |
| 4219 | final long identity = Binder.clearCallingIdentity(); |
| 4220 | try { |
| 4221 | for (Phone phone : PhoneFactory.getPhones()) { |
| 4222 | if (phone.isInEmergencySmsMode()) { |
| 4223 | return true; |
| 4224 | } |
| 4225 | } |
| 4226 | } finally { |
| 4227 | Binder.restoreCallingIdentity(identity); |
| 4228 | } |
| 4229 | return false; |
| 4230 | } |
| 4231 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4232 | /** |
| 4233 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4234 | * @param subId The subscription to use to check the configuration. |
| 4235 | * @param c The callback that will be used to send the result. |
| 4236 | */ |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 4237 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4238 | public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c) |
| 4239 | throws RemoteException { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4240 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4241 | mApp, subId, "registerImsRegistrationCallback"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4242 | |
| 4243 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4244 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4245 | "IMS not available on device."); |
| 4246 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4247 | final long token = Binder.clearCallingIdentity(); |
| 4248 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4249 | int slotId = getSlotIndexOrException(subId); |
| 4250 | verifyImsMmTelConfiguredOrThrow(slotId); |
joonhunshin | 49f0aed | 2022-08-05 08:33:05 +0000 | [diff] [blame] | 4251 | |
| 4252 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4253 | if (controller != null) { |
| 4254 | ImsManager imsManager = controller.getImsManager(subId); |
| 4255 | if (imsManager != null) { |
| 4256 | imsManager.addRegistrationCallbackForSubscription(c, subId); |
| 4257 | } else { |
| 4258 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE); |
| 4259 | } |
| 4260 | } else { |
| 4261 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION); |
| 4262 | } |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4263 | } catch (ImsException e) { |
| 4264 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4265 | } finally { |
| 4266 | Binder.restoreCallingIdentity(token); |
| 4267 | } |
| 4268 | } |
| 4269 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4270 | /** |
| 4271 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4272 | * @param subId The subscription to use to check the configuration. |
| 4273 | * @param c The callback that will be used to send the result. |
| 4274 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4275 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4276 | public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4277 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4278 | mApp, subId, "unregisterImsRegistrationCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4279 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4280 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4281 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4282 | final long token = Binder.clearCallingIdentity(); |
joonhunshin | 49f0aed | 2022-08-05 08:33:05 +0000 | [diff] [blame] | 4283 | |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4284 | try { |
joonhunshin | 49f0aed | 2022-08-05 08:33:05 +0000 | [diff] [blame] | 4285 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4286 | if (controller != null) { |
| 4287 | ImsManager imsManager = controller.getImsManager(subId); |
| 4288 | if (imsManager != null) { |
| 4289 | imsManager.removeRegistrationCallbackForSubscription(c, subId); |
| 4290 | } else { |
| 4291 | Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId |
| 4292 | + "is inactive, ignoring unregister."); |
| 4293 | // If the ImsManager is not valid, just return, since the callback |
| 4294 | // will already have been removed internally. |
| 4295 | } |
| 4296 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4297 | } finally { |
| 4298 | Binder.restoreCallingIdentity(token); |
| 4299 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4300 | } |
| 4301 | |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 4302 | /** |
| 4303 | * Get the IMS service registration state for the MmTelFeature associated with this sub id. |
| 4304 | */ |
| 4305 | @Override |
| 4306 | public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) { |
| 4307 | enforceReadPrivilegedPermission("getImsMmTelRegistrationState"); |
| 4308 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4309 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4310 | "IMS not available on device."); |
| 4311 | } |
| 4312 | final long token = Binder.clearCallingIdentity(); |
| 4313 | try { |
| 4314 | Phone phone = getPhone(subId); |
| 4315 | if (phone == null) { |
| 4316 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 4317 | + subId + "'"); |
| 4318 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 4319 | } |
| 4320 | phone.getImsRegistrationState(regState -> { |
| 4321 | try { |
| 4322 | consumer.accept((regState == null) |
| 4323 | ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState); |
| 4324 | } catch (RemoteException e) { |
| 4325 | // Ignore if the remote process is no longer available to call back. |
| 4326 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 4327 | } |
| 4328 | }); |
| 4329 | } finally { |
| 4330 | Binder.restoreCallingIdentity(token); |
| 4331 | } |
| 4332 | } |
| 4333 | |
| 4334 | /** |
| 4335 | * Get the transport type for the IMS service registration state. |
| 4336 | */ |
| 4337 | @Override |
| 4338 | public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4339 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4340 | mApp, subId, "getImsMmTelRegistrationTransportType"); |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 4341 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4342 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4343 | "IMS not available on device."); |
| 4344 | } |
| 4345 | final long token = Binder.clearCallingIdentity(); |
| 4346 | try { |
| 4347 | Phone phone = getPhone(subId); |
| 4348 | if (phone == null) { |
| 4349 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 4350 | + subId + "'"); |
| 4351 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 4352 | } |
| 4353 | phone.getImsRegistrationTech(regTech -> { |
| 4354 | // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager |
| 4355 | int regTechConverted = (regTech == null) |
| 4356 | ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech; |
| 4357 | regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get( |
| 4358 | regTechConverted); |
| 4359 | try { |
| 4360 | consumer.accept(regTechConverted); |
| 4361 | } catch (RemoteException e) { |
| 4362 | // Ignore if the remote process is no longer available to call back. |
| 4363 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 4364 | } |
| 4365 | }); |
| 4366 | } finally { |
| 4367 | Binder.restoreCallingIdentity(token); |
| 4368 | } |
| 4369 | } |
| 4370 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4371 | /** |
| 4372 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4373 | * @param subId The subscription to use to check the configuration. |
| 4374 | * @param c The callback that will be used to send the result. |
| 4375 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4376 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4377 | public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) |
| 4378 | throws RemoteException { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4379 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4380 | mApp, subId, "registerMmTelCapabilityCallback"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4381 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4382 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4383 | "IMS not available on device."); |
| 4384 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4385 | final long token = Binder.clearCallingIdentity(); |
| 4386 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4387 | int slotId = getSlotIndexOrException(subId); |
| 4388 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 4389 | ImsManager.getInstance(mApp, slotId).addCapabilitiesCallbackForSubscription(c, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4390 | } catch (ImsException e) { |
| 4391 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4392 | } finally { |
| 4393 | Binder.restoreCallingIdentity(token); |
| 4394 | } |
| 4395 | } |
| 4396 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4397 | /** |
| 4398 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4399 | * @param subId The subscription to use to check the configuration. |
| 4400 | * @param c The callback that will be used to send the result. |
| 4401 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4402 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4403 | public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4404 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4405 | mApp, subId, "unregisterMmTelCapabilityCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4406 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4407 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4408 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4409 | |
| 4410 | final long token = Binder.clearCallingIdentity(); |
| 4411 | try { |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4412 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4413 | .removeCapabilitiesCallbackForSubscription(c, subId); |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4414 | } catch (ImsException e) { |
| 4415 | Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId |
| 4416 | + "is inactive, ignoring unregister."); |
| 4417 | // If the subscription is no longer active, just return, since the callback |
| 4418 | // will already have been removed internally. |
| 4419 | } finally { |
| 4420 | Binder.restoreCallingIdentity(token); |
| 4421 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4422 | } |
| 4423 | |
| 4424 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4425 | public boolean isCapable(int subId, int capability, int regTech) { |
| 4426 | enforceReadPrivilegedPermission("isCapable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4427 | final long token = Binder.clearCallingIdentity(); |
| 4428 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4429 | int slotId = getSlotIndexOrException(subId); |
| 4430 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 4431 | return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech); |
| 4432 | } catch (com.android.ims.ImsException e) { |
| 4433 | Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage()); |
| 4434 | return false; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4435 | } catch (ImsException e) { |
Brad Ebinger | 6b5ac22 | 2019-02-04 14:36:52 -0800 | [diff] [blame] | 4436 | Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false."); |
| 4437 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4438 | } finally { |
| 4439 | Binder.restoreCallingIdentity(token); |
| 4440 | } |
| 4441 | } |
| 4442 | |
| 4443 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4444 | public boolean isAvailable(int subId, int capability, int regTech) { |
| 4445 | enforceReadPrivilegedPermission("isAvailable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4446 | final long token = Binder.clearCallingIdentity(); |
| 4447 | try { |
| 4448 | Phone phone = getPhone(subId); |
| 4449 | if (phone == null) return false; |
| 4450 | return phone.isImsCapabilityAvailable(capability, regTech); |
Daniel Bright | 5e40e4e | 2020-03-11 16:35:39 -0700 | [diff] [blame] | 4451 | } catch (com.android.ims.ImsException e) { |
| 4452 | Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage()); |
| 4453 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4454 | } finally { |
| 4455 | Binder.restoreCallingIdentity(token); |
| 4456 | } |
| 4457 | } |
| 4458 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4459 | /** |
| 4460 | * Determines if the MmTel feature capability is supported by the carrier configuration for this |
| 4461 | * subscription. |
| 4462 | * @param subId The subscription to use to check the configuration. |
| 4463 | * @param callback The callback that will be used to send the result. |
| 4464 | * @param capability The MmTelFeature capability that will be used to send the result. |
| 4465 | * @param transportType The transport type of the MmTelFeature capability. |
| 4466 | */ |
| 4467 | @Override |
| 4468 | public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability, |
| 4469 | int transportType) { |
| 4470 | enforceReadPrivilegedPermission("isMmTelCapabilitySupported"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4471 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4472 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4473 | "IMS not available on device."); |
| 4474 | } |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4475 | final long token = Binder.clearCallingIdentity(); |
| 4476 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4477 | int slotId = getSlotIndex(subId); |
| 4478 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4479 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '" |
| 4480 | + subId + "'"); |
| 4481 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 4482 | } |
| 4483 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 4484 | ImsManager.getInstance(mApp, slotId).isSupported(capability, |
| 4485 | transportType, aBoolean -> { |
| 4486 | try { |
| 4487 | callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0)); |
| 4488 | } catch (RemoteException e) { |
| 4489 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not " |
| 4490 | + "running. Ignore"); |
| 4491 | } |
| 4492 | }); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4493 | } catch (ImsException e) { |
| 4494 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4495 | } finally { |
| 4496 | Binder.restoreCallingIdentity(token); |
| 4497 | } |
| 4498 | } |
| 4499 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4500 | /** |
| 4501 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4502 | * @param subId The subscription to use to check the configuration. |
| 4503 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4504 | @Override |
| 4505 | public boolean isAdvancedCallingSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4506 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4507 | mApp, subId, "isAdvancedCallingSettingEnabled"); |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4508 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4509 | final long token = Binder.clearCallingIdentity(); |
| 4510 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4511 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4512 | // 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] | 4513 | return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4514 | } catch (ImsException e) { |
| 4515 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4516 | } finally { |
| 4517 | Binder.restoreCallingIdentity(token); |
| 4518 | } |
| 4519 | } |
| 4520 | |
| 4521 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4522 | public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4523 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4524 | "setAdvancedCallingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4525 | final long identity = Binder.clearCallingIdentity(); |
| 4526 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4527 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4528 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4529 | // 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] | 4530 | ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4531 | } catch (ImsException e) { |
| 4532 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4533 | } finally { |
| 4534 | Binder.restoreCallingIdentity(identity); |
| 4535 | } |
| 4536 | } |
| 4537 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4538 | /** |
| 4539 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4540 | * @param subId The subscription to use to check the configuration. |
| 4541 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4542 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4543 | public boolean isVtSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4544 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4545 | mApp, subId, "isVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4546 | final long identity = Binder.clearCallingIdentity(); |
| 4547 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4548 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4549 | // 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] | 4550 | return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4551 | } catch (ImsException e) { |
| 4552 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4553 | } finally { |
| 4554 | Binder.restoreCallingIdentity(identity); |
| 4555 | } |
| 4556 | } |
| 4557 | |
| 4558 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4559 | public void setVtSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4560 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4561 | "setVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4562 | final long identity = Binder.clearCallingIdentity(); |
| 4563 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4564 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4565 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4566 | // 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] | 4567 | ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4568 | } catch (ImsException e) { |
| 4569 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4570 | } finally { |
| 4571 | Binder.restoreCallingIdentity(identity); |
| 4572 | } |
| 4573 | } |
| 4574 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4575 | /** |
| 4576 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4577 | * @param subId The subscription to use to check the configuration. |
| 4578 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4579 | @Override |
| 4580 | public boolean isVoWiFiSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4581 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4582 | mApp, subId, "isVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4583 | final long identity = Binder.clearCallingIdentity(); |
| 4584 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4585 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4586 | // 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] | 4587 | return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4588 | } catch (ImsException e) { |
| 4589 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4590 | } finally { |
| 4591 | Binder.restoreCallingIdentity(identity); |
| 4592 | } |
| 4593 | } |
| 4594 | |
| 4595 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4596 | public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4597 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4598 | "setVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4599 | final long identity = Binder.clearCallingIdentity(); |
| 4600 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4601 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4602 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4603 | // 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] | 4604 | ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4605 | } catch (ImsException e) { |
| 4606 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4607 | } finally { |
| 4608 | Binder.restoreCallingIdentity(identity); |
| 4609 | } |
| 4610 | } |
| 4611 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4612 | /** |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 4613 | * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not |
| 4614 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4615 | * @param subId The subscription to use to check the configuration. |
| 4616 | */ |
| 4617 | @Override |
| 4618 | public boolean isCrossSimCallingEnabledByUser(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4619 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 4620 | mApp, subId, "isCrossSimCallingEnabledByUser"); |
| 4621 | final long identity = Binder.clearCallingIdentity(); |
| 4622 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4623 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4624 | // 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] | 4625 | return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser(); |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 4626 | } catch (ImsException e) { |
| 4627 | throw new ServiceSpecificException(e.getCode()); |
| 4628 | } finally { |
| 4629 | Binder.restoreCallingIdentity(identity); |
| 4630 | } |
| 4631 | } |
| 4632 | |
| 4633 | /** |
| 4634 | * Sets the user's setting for whether or not Voice over Cross SIM is enabled. |
| 4635 | * Requires MODIFY_PHONE_STATE permission. |
| 4636 | * @param subId The subscription to use to check the configuration. |
| 4637 | * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled, |
| 4638 | * false otherwise |
| 4639 | */ |
| 4640 | @Override |
| 4641 | public void setCrossSimCallingEnabled(int subId, boolean isEnabled) { |
| 4642 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4643 | "setCrossSimCallingEnabled"); |
| 4644 | final long identity = Binder.clearCallingIdentity(); |
| 4645 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4646 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4647 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4648 | // 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] | 4649 | ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled); |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 4650 | } catch (ImsException e) { |
| 4651 | throw new ServiceSpecificException(e.getCode()); |
| 4652 | } finally { |
| 4653 | Binder.restoreCallingIdentity(identity); |
| 4654 | } |
| 4655 | } |
| 4656 | |
| 4657 | /** |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4658 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4659 | * @param subId The subscription to use to check the configuration. |
| 4660 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4661 | @Override |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4662 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4663 | public boolean isVoWiFiRoamingSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4664 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4665 | mApp, subId, "isVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4666 | final long identity = Binder.clearCallingIdentity(); |
| 4667 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4668 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4669 | // 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] | 4670 | return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4671 | } catch (ImsException e) { |
| 4672 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4673 | } finally { |
| 4674 | Binder.restoreCallingIdentity(identity); |
| 4675 | } |
| 4676 | } |
| 4677 | |
| 4678 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4679 | public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4680 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4681 | "setVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4682 | final long identity = Binder.clearCallingIdentity(); |
| 4683 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4684 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4685 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4686 | // 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] | 4687 | ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4688 | } catch (ImsException e) { |
| 4689 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4690 | } finally { |
| 4691 | Binder.restoreCallingIdentity(identity); |
| 4692 | } |
| 4693 | } |
| 4694 | |
| 4695 | @Override |
| 4696 | public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) { |
| 4697 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4698 | "setVoWiFiNonPersistent"); |
| 4699 | final long identity = Binder.clearCallingIdentity(); |
| 4700 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4701 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4702 | // This setting will be ignored if the ImsService isn't up. |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4703 | ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4704 | } catch (ImsException e) { |
| 4705 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4706 | } finally { |
| 4707 | Binder.restoreCallingIdentity(identity); |
| 4708 | } |
| 4709 | } |
| 4710 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4711 | /** |
| 4712 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4713 | * @param subId The subscription to use to check the configuration. |
| 4714 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4715 | @Override |
| 4716 | public int getVoWiFiModeSetting(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4717 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4718 | mApp, subId, "getVoWiFiModeSetting"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4719 | final long identity = Binder.clearCallingIdentity(); |
| 4720 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4721 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4722 | // 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] | 4723 | return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4724 | } catch (ImsException e) { |
| 4725 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4726 | } finally { |
| 4727 | Binder.restoreCallingIdentity(identity); |
| 4728 | } |
| 4729 | } |
| 4730 | |
| 4731 | @Override |
| 4732 | public void setVoWiFiModeSetting(int subId, int mode) { |
| 4733 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4734 | "setVoWiFiModeSetting"); |
| 4735 | final long identity = Binder.clearCallingIdentity(); |
| 4736 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4737 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4738 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4739 | // 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] | 4740 | ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4741 | } catch (ImsException e) { |
| 4742 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4743 | } finally { |
| 4744 | Binder.restoreCallingIdentity(identity); |
| 4745 | } |
| 4746 | } |
| 4747 | |
| 4748 | @Override |
| 4749 | public int getVoWiFiRoamingModeSetting(int subId) { |
| 4750 | enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting"); |
| 4751 | final long identity = Binder.clearCallingIdentity(); |
| 4752 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4753 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4754 | // 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] | 4755 | return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4756 | } catch (ImsException e) { |
| 4757 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4758 | } finally { |
| 4759 | Binder.restoreCallingIdentity(identity); |
| 4760 | } |
| 4761 | } |
| 4762 | |
| 4763 | @Override |
| 4764 | public void setVoWiFiRoamingModeSetting(int subId, int mode) { |
| 4765 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4766 | "setVoWiFiRoamingModeSetting"); |
| 4767 | final long identity = Binder.clearCallingIdentity(); |
| 4768 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4769 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4770 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4771 | // 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] | 4772 | ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4773 | } catch (ImsException e) { |
| 4774 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4775 | } finally { |
| 4776 | Binder.restoreCallingIdentity(identity); |
| 4777 | } |
| 4778 | } |
| 4779 | |
| 4780 | @Override |
| 4781 | public void setRttCapabilitySetting(int subId, boolean isEnabled) { |
| 4782 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4783 | "setRttCapabilityEnabled"); |
| 4784 | final long identity = Binder.clearCallingIdentity(); |
| 4785 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4786 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4787 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4788 | // 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] | 4789 | ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4790 | } catch (ImsException e) { |
| 4791 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4792 | } finally { |
| 4793 | Binder.restoreCallingIdentity(identity); |
| 4794 | } |
| 4795 | } |
| 4796 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4797 | /** |
| 4798 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4799 | * @param subId The subscription to use to check the configuration. |
| 4800 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4801 | @Override |
| 4802 | public boolean isTtyOverVolteEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4803 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4804 | mApp, subId, "isTtyOverVolteEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4805 | final long identity = Binder.clearCallingIdentity(); |
| 4806 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4807 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4808 | // 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] | 4809 | return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4810 | } catch (ImsException e) { |
| 4811 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4812 | } finally { |
| 4813 | Binder.restoreCallingIdentity(identity); |
| 4814 | } |
| 4815 | } |
| 4816 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4817 | @Override |
| 4818 | public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 4819 | enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4820 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4821 | final long identity = Binder.clearCallingIdentity(); |
| 4822 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4823 | if (!isImsAvailableOnDevice()) { |
| 4824 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4825 | "IMS not available on device."); |
| 4826 | } |
| 4827 | int slotId = getSlotIndexOrException(subId); |
| 4828 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 4829 | ImsManager.getInstance(mApp, slotId) |
| 4830 | .addProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4831 | } catch (ImsException e) { |
| 4832 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4833 | } finally { |
| 4834 | Binder.restoreCallingIdentity(identity); |
| 4835 | } |
| 4836 | } |
| 4837 | |
| 4838 | @Override |
| 4839 | public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 4840 | enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4841 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4842 | final long identity = Binder.clearCallingIdentity(); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4843 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4844 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4845 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4846 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4847 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4848 | .removeProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4849 | } catch (ImsException e) { |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4850 | Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId |
| 4851 | + "is inactive, ignoring unregister."); |
| 4852 | // If the subscription is no longer active, just return, since the callback will already |
| 4853 | // have been removed internally. |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4854 | } finally { |
| 4855 | Binder.restoreCallingIdentity(identity); |
| 4856 | } |
| 4857 | } |
| 4858 | |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4859 | @Override |
| 4860 | public void registerFeatureProvisioningChangedCallback(int subId, |
| 4861 | IFeatureProvisioningCallback callback) { |
| 4862 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4863 | mApp, subId, "registerFeatureProvisioningChangedCallback"); |
| 4864 | |
| 4865 | final long identity = Binder.clearCallingIdentity(); |
| 4866 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4867 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4868 | } |
| 4869 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 4870 | try { |
| 4871 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 4872 | if (controller == null) { |
| 4873 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4874 | "Device does not support IMS"); |
| 4875 | } |
| 4876 | controller.addFeatureProvisioningChangedCallback(subId, callback); |
| 4877 | } finally { |
| 4878 | Binder.restoreCallingIdentity(identity); |
| 4879 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4880 | } |
| 4881 | |
| 4882 | @Override |
| 4883 | public void unregisterFeatureProvisioningChangedCallback(int subId, |
| 4884 | IFeatureProvisioningCallback callback) { |
| 4885 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4886 | mApp, subId, "unregisterFeatureProvisioningChangedCallback"); |
| 4887 | |
| 4888 | final long identity = Binder.clearCallingIdentity(); |
| 4889 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4890 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4891 | } |
| 4892 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 4893 | try { |
| 4894 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 4895 | if (controller == null) { |
| 4896 | loge("unregisterFeatureProvisioningChangedCallback: Device does not support IMS"); |
| 4897 | return; |
| 4898 | } |
| 4899 | controller.removeFeatureProvisioningChangedCallback(subId, callback); |
| 4900 | } finally { |
| 4901 | Binder.restoreCallingIdentity(identity); |
| 4902 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4903 | } |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4904 | |
| 4905 | private void checkModifyPhoneStatePermission(int subId, String message) { |
| 4906 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4907 | message); |
| 4908 | } |
| 4909 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4910 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4911 | public void setRcsProvisioningStatusForCapability(int subId, int capability, int tech, |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4912 | boolean isProvisioned) { |
| 4913 | checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability"); |
| 4914 | |
| 4915 | final long identity = Binder.clearCallingIdentity(); |
| 4916 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 4917 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 4918 | if (controller == null) { |
| 4919 | loge("setRcsProvisioningStatusForCapability: Device does not support IMS"); |
| 4920 | return; |
| 4921 | } |
| 4922 | controller.setRcsProvisioningStatusForCapability( |
| 4923 | subId, capability, tech, isProvisioned); |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4924 | } finally { |
| 4925 | Binder.restoreCallingIdentity(identity); |
| 4926 | } |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4927 | } |
| 4928 | |
| 4929 | |
| 4930 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4931 | public boolean getRcsProvisioningStatusForCapability(int subId, int capability, int tech) { |
| 4932 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4933 | mApp, subId, "getRcsProvisioningStatusForCapability"); |
| 4934 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4935 | final long identity = Binder.clearCallingIdentity(); |
| 4936 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 4937 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 4938 | if (controller == null) { |
| 4939 | loge("getRcsProvisioningStatusForCapability: Device does not support IMS"); |
| 4940 | |
| 4941 | // device does not support IMS, this method will return true always. |
| 4942 | return true; |
| 4943 | } |
| 4944 | return controller.getRcsProvisioningStatusForCapability(subId, capability, tech); |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4945 | } finally { |
| 4946 | Binder.restoreCallingIdentity(identity); |
| 4947 | } |
| 4948 | } |
| 4949 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4950 | @Override |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4951 | public void setImsProvisioningStatusForCapability(int subId, int capability, int tech, |
| 4952 | boolean isProvisioned) { |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4953 | checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4954 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4955 | final long identity = Binder.clearCallingIdentity(); |
| 4956 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 4957 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 4958 | if (controller == null) { |
| 4959 | loge("setImsProvisioningStatusForCapability: Device does not support IMS"); |
| 4960 | return; |
| 4961 | } |
| 4962 | controller.setImsProvisioningStatusForCapability( |
| 4963 | subId, capability, tech, isProvisioned); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4964 | } finally { |
| 4965 | Binder.restoreCallingIdentity(identity); |
| 4966 | } |
| 4967 | } |
| 4968 | |
| 4969 | @Override |
| 4970 | public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) { |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4971 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4972 | mApp, subId, "getProvisioningStatusForCapability"); |
| 4973 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4974 | final long identity = Binder.clearCallingIdentity(); |
| 4975 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 4976 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 4977 | if (controller == null) { |
| 4978 | loge("getImsProvisioningStatusForCapability: Device does not support IMS"); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4979 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 4980 | // device does not support IMS, this method will return true always. |
| 4981 | return true; |
| 4982 | } |
| 4983 | return controller.getImsProvisioningStatusForCapability(subId, capability, tech); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4984 | } finally { |
| 4985 | Binder.restoreCallingIdentity(identity); |
| 4986 | } |
| 4987 | } |
| 4988 | |
| 4989 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4990 | public boolean isProvisioningRequiredForCapability(int subId, int capability, int tech) { |
| 4991 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4992 | mApp, subId, "isProvisioningRequiredForCapability"); |
| 4993 | |
| 4994 | final long identity = Binder.clearCallingIdentity(); |
| 4995 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 4996 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 4997 | if (controller == null) { |
| 4998 | loge("isProvisioningRequiredForCapability: Device does not support IMS"); |
| 4999 | |
| 5000 | // device does not support IMS, this method will return false |
| 5001 | return false; |
| 5002 | } |
| 5003 | return controller.isImsProvisioningRequiredForCapability(subId, capability, tech); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5004 | } finally { |
| 5005 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5006 | } |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5007 | } |
| 5008 | |
| 5009 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5010 | public boolean isRcsProvisioningRequiredForCapability(int subId, int capability, int tech) { |
| 5011 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5012 | mApp, subId, "isProvisioningRequiredForCapability"); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5013 | |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5014 | final long identity = Binder.clearCallingIdentity(); |
| 5015 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5016 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5017 | if (controller == null) { |
| 5018 | loge("isRcsProvisioningRequiredForCapability: Device does not support IMS"); |
| 5019 | |
| 5020 | // device does not support IMS, this method will return false |
| 5021 | return false; |
| 5022 | } |
| 5023 | return controller.isRcsProvisioningRequiredForCapability(subId, capability, tech); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5024 | } finally { |
| 5025 | Binder.restoreCallingIdentity(identity); |
| 5026 | } |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5027 | } |
| 5028 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5029 | @Override |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5030 | public int getImsProvisioningInt(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5031 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5032 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 5033 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5034 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5035 | mApp, subId, "getImsProvisioningInt"); |
| 5036 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5037 | final long identity = Binder.clearCallingIdentity(); |
| 5038 | try { |
| 5039 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5040 | int slotId = getSlotIndex(subId); |
| 5041 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5042 | Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '" |
| 5043 | + subId + "' for key:" + key); |
| 5044 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
| 5045 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5046 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5047 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5048 | if (controller == null) { |
| 5049 | loge("getImsProvisioningInt: Device does not support IMS"); |
| 5050 | |
| 5051 | // device does not support IMS, this method will return CONFIG_RESULT_UNKNOWN. |
| 5052 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
| 5053 | } |
| 5054 | int retVal = controller.getProvisioningValue(subId, key); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5055 | if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) { |
| 5056 | return retVal; |
| 5057 | } |
| 5058 | |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5059 | return ImsManager.getInstance(mApp, slotId).getConfigInt(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5060 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5061 | Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '" |
| 5062 | + subId + "' for key:" + key); |
| 5063 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5064 | } finally { |
| 5065 | Binder.restoreCallingIdentity(identity); |
| 5066 | } |
| 5067 | } |
| 5068 | |
| 5069 | @Override |
| 5070 | public String getImsProvisioningString(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5071 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5072 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 5073 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5074 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5075 | mApp, subId, "getImsProvisioningString"); |
| 5076 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5077 | final long identity = Binder.clearCallingIdentity(); |
| 5078 | try { |
| 5079 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5080 | int slotId = getSlotIndex(subId); |
| 5081 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5082 | Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '" |
| 5083 | + subId + "' for key:" + key); |
| 5084 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC; |
| 5085 | } |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5086 | return ImsManager.getInstance(mApp, slotId).getConfigString(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5087 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5088 | Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '" |
| 5089 | + subId + "' for key:" + key); |
| 5090 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5091 | } finally { |
| 5092 | Binder.restoreCallingIdentity(identity); |
| 5093 | } |
| 5094 | } |
| 5095 | |
| 5096 | @Override |
| 5097 | public int setImsProvisioningInt(int subId, int key, int value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5098 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5099 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 5100 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 5101 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5102 | "setImsProvisioningInt"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5103 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5104 | final long identity = Binder.clearCallingIdentity(); |
| 5105 | try { |
| 5106 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5107 | int slotId = getSlotIndex(subId); |
| 5108 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5109 | Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '" |
| 5110 | + subId + "' for key:" + key); |
| 5111 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 5112 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5113 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5114 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5115 | if (controller == null) { |
| 5116 | loge("setImsProvisioningInt: Device does not support IMS"); |
| 5117 | |
| 5118 | // device does not support IMS, this method will return CONFIG_RESULT_FAILED. |
| 5119 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 5120 | } |
| 5121 | int retVal = controller.setProvisioningValue(subId, key, value); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5122 | if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) { |
| 5123 | return retVal; |
| 5124 | } |
| 5125 | |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5126 | return ImsManager.getInstance(mApp, slotId).setConfig(key, value); |
| 5127 | } catch (com.android.ims.ImsException | RemoteException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5128 | Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5129 | + "' for key:" + key, e); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5130 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5131 | } finally { |
| 5132 | Binder.restoreCallingIdentity(identity); |
| 5133 | } |
| 5134 | } |
| 5135 | |
| 5136 | @Override |
| 5137 | public int setImsProvisioningString(int subId, int key, String value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5138 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5139 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 5140 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 5141 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5142 | "setImsProvisioningString"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5143 | final long identity = Binder.clearCallingIdentity(); |
| 5144 | try { |
| 5145 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5146 | int slotId = getSlotIndex(subId); |
| 5147 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5148 | Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '" |
| 5149 | + subId + "' for key:" + key); |
| 5150 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 5151 | } |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5152 | return ImsManager.getInstance(mApp, slotId).setConfig(key, value); |
| 5153 | } catch (com.android.ims.ImsException | RemoteException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5154 | Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5155 | + "' for key:" + key, e); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5156 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5157 | } finally { |
| 5158 | Binder.restoreCallingIdentity(identity); |
| 5159 | } |
| 5160 | } |
| 5161 | |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5162 | /** |
| 5163 | * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL |
| 5164 | * for the given slot ID or no ImsResolver instance has been created. |
| 5165 | * @param slotId The slot ID that the IMS service is created for. |
| 5166 | * @throws ImsException If there is no ImsService configured for this slot. |
| 5167 | */ |
| 5168 | private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException { |
| 5169 | if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId, |
| 5170 | ImsFeature.FEATURE_MMTEL)) { |
| 5171 | throw new ImsException("This subscription does not support MMTEL over IMS", |
| 5172 | ImsException.CODE_ERROR_UNSUPPORTED_OPERATION); |
| 5173 | } |
| 5174 | } |
| 5175 | |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5176 | private int getSlotIndexOrException(int subId) throws ImsException { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5177 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 5178 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5179 | throw new ImsException("Invalid Subscription Id, subId=" + subId, |
| 5180 | ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5181 | } |
| 5182 | return slotId; |
| 5183 | } |
| 5184 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5185 | private int getSlotIndex(int subId) { |
| 5186 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 5187 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
| 5188 | return SubscriptionManager.INVALID_SIM_SLOT_INDEX; |
| 5189 | } |
| 5190 | return slotId; |
| 5191 | } |
| 5192 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5193 | /** |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 5194 | * Returns the data network type for a subId; does not throw SecurityException. |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5195 | */ |
| 5196 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5197 | public int getNetworkTypeForSubscriber(int subId, String callingPackage, |
| 5198 | String callingFeatureId) { |
Shuo Qian | 13d8915 | 2021-05-10 23:58:11 -0700 | [diff] [blame] | 5199 | try { |
| 5200 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 5201 | } catch (SecurityException se) { |
| 5202 | EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid()); |
| 5203 | throw new SecurityException("Package " + callingPackage + " does not belong to " |
| 5204 | + Binder.getCallingUid()); |
| 5205 | } |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 5206 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 5207 | if (targetSdk > android.os.Build.VERSION_CODES.Q) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5208 | return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 5209 | } else if (targetSdk == android.os.Build.VERSION_CODES.Q |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 5210 | && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5211 | mApp, subId, callingPackage, callingFeatureId, |
| 5212 | "getNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5213 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5214 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 5215 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5216 | final long identity = Binder.clearCallingIdentity(); |
| 5217 | try { |
| 5218 | final Phone phone = getPhone(subId); |
| 5219 | if (phone != null) { |
| 5220 | return phone.getServiceState().getDataNetworkType(); |
| 5221 | } else { |
| 5222 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5223 | } |
| 5224 | } finally { |
| 5225 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5226 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5227 | } |
| 5228 | |
| 5229 | /** |
| 5230 | * Returns the data network type |
| 5231 | */ |
| 5232 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5233 | public int getDataNetworkType(String callingPackage, String callingFeatureId) { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5234 | return getDataNetworkTypeForSubscriber(SubscriptionManager.getDefaultDataSubscriptionId(), |
Zoey Chen | fd61f7f | 2021-04-21 13:42:10 +0800 | [diff] [blame] | 5235 | callingPackage, callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5236 | } |
| 5237 | |
| 5238 | /** |
| 5239 | * Returns the data network type for a subId |
| 5240 | */ |
| 5241 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5242 | public int getDataNetworkTypeForSubscriber(int subId, String callingPackage, |
| 5243 | String callingFeatureId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 5244 | String functionName = "getDataNetworkTypeForSubscriber"; |
| 5245 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 5246 | mApp, functionName)) { |
| 5247 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 5248 | mApp, subId, callingPackage, callingFeatureId, functionName)) { |
| 5249 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5250 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5251 | } |
| 5252 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5253 | final long identity = Binder.clearCallingIdentity(); |
| 5254 | try { |
| 5255 | final Phone phone = getPhone(subId); |
| 5256 | if (phone != null) { |
| 5257 | return phone.getServiceState().getDataNetworkType(); |
| 5258 | } else { |
| 5259 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5260 | } |
| 5261 | } finally { |
| 5262 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5263 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5264 | } |
| 5265 | |
| 5266 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5267 | * Returns the Voice network type for a subId |
| 5268 | */ |
| 5269 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5270 | public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage, |
| 5271 | String callingFeatureId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 5272 | String functionName = "getVoiceNetworkTypeForSubscriber"; |
| 5273 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 5274 | mApp, functionName)) { |
| 5275 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 5276 | mApp, subId, callingPackage, callingFeatureId, functionName)) { |
| 5277 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5278 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 5279 | } |
| 5280 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5281 | final long identity = Binder.clearCallingIdentity(); |
| 5282 | try { |
| 5283 | final Phone phone = getPhone(subId); |
| 5284 | if (phone != null) { |
| 5285 | return phone.getServiceState().getVoiceNetworkType(); |
| 5286 | } else { |
| 5287 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5288 | } |
| 5289 | } finally { |
| 5290 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5291 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5292 | } |
| 5293 | |
| 5294 | /** |
| 5295 | * @return true if a ICC card is present |
| 5296 | */ |
| 5297 | public boolean hasIccCard() { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5298 | // FIXME Make changes to pass defaultSimId of type int |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5299 | return hasIccCardUsingSlotIndex(SubscriptionManager.getSlotIndex( |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5300 | getDefaultSubscription())); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5301 | } |
| 5302 | |
| 5303 | /** |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5304 | * @return true if a ICC card is present for a slotIndex |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5305 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5306 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5307 | public boolean hasIccCardUsingSlotIndex(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5308 | final long identity = Binder.clearCallingIdentity(); |
| 5309 | try { |
| 5310 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5311 | if (phone != null) { |
| 5312 | return phone.getIccCard().hasIccCard(); |
| 5313 | } else { |
| 5314 | return false; |
| 5315 | } |
| 5316 | } finally { |
| 5317 | Binder.restoreCallingIdentity(identity); |
Amit Mahajan | a6fc2a8 | 2015-01-06 11:53:51 -0800 | [diff] [blame] | 5318 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5319 | } |
| 5320 | |
| 5321 | /** |
| 5322 | * Return if the current radio is LTE on CDMA. This |
| 5323 | * is a tri-state return value as for a period of time |
| 5324 | * the mode may be unknown. |
| 5325 | * |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5326 | * @param callingPackage the name of the package making the call. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5327 | * @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] | 5328 | * or {@link Phone#LTE_ON_CDMA_TRUE} |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5329 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5330 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5331 | public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) { |
| 5332 | return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 5333 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5334 | } |
| 5335 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5336 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5337 | public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage, |
| 5338 | String callingFeatureId) { |
Sarah Chin | 790d292 | 2020-01-16 12:17:23 -0800 | [diff] [blame] | 5339 | try { |
| 5340 | enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber"); |
| 5341 | } catch (SecurityException e) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5342 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 5343 | } |
| 5344 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5345 | final long identity = Binder.clearCallingIdentity(); |
| 5346 | try { |
| 5347 | final Phone phone = getPhone(subId); |
| 5348 | if (phone == null) { |
| 5349 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 5350 | } else { |
Nathan Harold | 05ad633 | 2020-07-10 11:54:36 -0700 | [diff] [blame] | 5351 | return TelephonyProperties.lte_on_cdma_device() |
| 5352 | .orElse(PhoneConstants.LTE_ON_CDMA_FALSE); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5353 | } |
| 5354 | } finally { |
| 5355 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5356 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5357 | } |
| 5358 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5359 | /** |
| 5360 | * {@hide} |
| 5361 | * Returns Default subId, 0 in the case of single standby. |
| 5362 | */ |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 5363 | private int getDefaultSubscription() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5364 | return SubscriptionManager.getDefaultSubscriptionId(); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5365 | } |
| 5366 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 5367 | private int getSlotForDefaultSubscription() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5368 | return SubscriptionManager.getPhoneId(getDefaultSubscription()); |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 5369 | } |
| 5370 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 5371 | private int getPreferredVoiceSubscription() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5372 | return SubscriptionManager.getDefaultVoiceSubscriptionId(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5373 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5374 | |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 5375 | private boolean isActiveSubscription(int subId) { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5376 | if (PhoneFactory.isSubscriptionManagerServiceEnabled()) { |
| 5377 | return SubscriptionManagerService.getInstance().isActiveSubId(subId, |
| 5378 | mApp.getOpPackageName(), mApp.getFeatureId()); |
| 5379 | } |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 5380 | return mSubscriptionController.isActiveSubId(subId); |
| 5381 | } |
| 5382 | |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5383 | /** |
| 5384 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 5385 | */ |
| 5386 | public int getWhenToMakeWifiCalls() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5387 | final long identity = Binder.clearCallingIdentity(); |
| 5388 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5389 | return Settings.System.getInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5390 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, |
| 5391 | getWhenToMakeWifiCallsDefaultPreference()); |
| 5392 | } finally { |
| 5393 | Binder.restoreCallingIdentity(identity); |
| 5394 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5395 | } |
| 5396 | |
| 5397 | /** |
| 5398 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 5399 | */ |
| 5400 | public void setWhenToMakeWifiCalls(int preference) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5401 | final long identity = Binder.clearCallingIdentity(); |
| 5402 | try { |
| 5403 | if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5404 | Settings.System.putInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5405 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference); |
| 5406 | } finally { |
| 5407 | Binder.restoreCallingIdentity(identity); |
| 5408 | } |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 5409 | } |
| 5410 | |
Sailesh Nepal | d1e6815 | 2013-12-12 19:08:02 -0800 | [diff] [blame] | 5411 | private static int getWhenToMakeWifiCallsDefaultPreference() { |
Santos Cordon | da120f4 | 2014-08-06 04:44:34 -0700 | [diff] [blame] | 5412 | // TODO: Use a build property to choose this value. |
Evan Charlton | 9829e88 | 2013-12-19 15:30:38 -0800 | [diff] [blame] | 5413 | return TelephonyManager.WifiCallingChoices.ALWAYS_USE; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5414 | } |
Shishir Agrawal | 69f6812 | 2013-12-16 17:25:49 -0800 | [diff] [blame] | 5415 | |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5416 | private Phone getPhoneFromSlotPortIndexOrThrowException(int slotIndex, int portIndex) { |
| 5417 | int phoneId = UiccController.getInstance().getPhoneIdFromSlotPortIndex(slotIndex, |
| 5418 | portIndex); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5419 | if (phoneId == -1) { |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5420 | throw new IllegalArgumentException("Given slot index: " + slotIndex + " port index: " |
| 5421 | + portIndex + " does not correspond to an active phone"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5422 | } |
| 5423 | return PhoneFactory.getPhone(phoneId); |
| 5424 | } |
| 5425 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5426 | @Override |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 5427 | public IccOpenLogicalChannelResponse iccOpenLogicalChannel( |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5428 | @NonNull IccLogicalChannelRequest request) { |
| 5429 | Phone phone = getPhoneFromValidIccLogicalChannelRequest(request, |
| 5430 | /*message=*/ "iccOpenLogicalChannel"); |
| 5431 | |
| 5432 | if (DBG) log("iccOpenLogicalChannel: request=" + request); |
| 5433 | // Verify that the callingPackage in the request belongs to the calling UID |
| 5434 | mAppOps.checkPackage(Binder.getCallingUid(), request.callingPackage); |
| 5435 | |
| 5436 | return iccOpenLogicalChannelWithPermission(phone, request); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5437 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5438 | |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5439 | private Phone getPhoneFromValidIccLogicalChannelRequest( |
| 5440 | @NonNull IccLogicalChannelRequest request, String message) { |
| 5441 | Phone phone; |
| 5442 | if (request.subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) { |
| 5443 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5444 | mApp, request.subId, message); |
| 5445 | phone = getPhoneFromSubId(request.subId); |
| 5446 | } else if (request.slotIndex != SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5447 | enforceModifyPermission(); |
| 5448 | phone = getPhoneFromSlotPortIndexOrThrowException(request.slotIndex, request.portIndex); |
| 5449 | } else { |
| 5450 | throw new IllegalArgumentException("Both subId and slotIndex in request are invalid."); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5451 | } |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5452 | return phone; |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5453 | } |
| 5454 | |
| 5455 | private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone, |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5456 | IccLogicalChannelRequest channelRequest) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5457 | final long identity = Binder.clearCallingIdentity(); |
| 5458 | try { |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5459 | if (TextUtils.equals(ISDR_AID, channelRequest.aid)) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5460 | // Only allows LPA to open logical channel to ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5461 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 5462 | .getContext().getPackageManager()); |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5463 | if (bestComponent == null || !TextUtils.equals(channelRequest.callingPackage, |
| 5464 | bestComponent.packageName)) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5465 | loge("The calling package is not allowed to access ISD-R."); |
| 5466 | throw new SecurityException( |
| 5467 | "The calling package is not allowed to access ISD-R."); |
| 5468 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 5469 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 5470 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5471 | IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest( |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5472 | CMD_OPEN_CHANNEL, channelRequest, phone, null /* workSource */); |
| 5473 | if (DBG) log("iccOpenLogicalChannelWithPermission: response=" + response); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5474 | return response; |
| 5475 | } finally { |
| 5476 | Binder.restoreCallingIdentity(identity); |
| 5477 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5478 | } |
| 5479 | |
| 5480 | @Override |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5481 | public boolean iccCloseLogicalChannel(@NonNull IccLogicalChannelRequest request) { |
| 5482 | Phone phone = getPhoneFromValidIccLogicalChannelRequest(request, |
| 5483 | /*message=*/"iccCloseLogicalChannel"); |
| 5484 | |
| 5485 | if (DBG) log("iccCloseLogicalChannel: request=" + request); |
| 5486 | |
| 5487 | return iccCloseLogicalChannelWithPermission(phone, request); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5488 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5489 | |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5490 | private boolean iccCloseLogicalChannelWithPermission(Phone phone, |
| 5491 | IccLogicalChannelRequest request) { |
Chen Xu | a8f0dff | 2022-02-12 00:34:15 -0800 | [diff] [blame] | 5492 | // before this feature is enabled, this API should only return false if |
| 5493 | // the operation fails instead of throwing runtime exception for |
| 5494 | // backward-compatibility. |
| 5495 | final boolean shouldThrowExceptionOnFailure = CompatChanges.isChangeEnabled( |
| 5496 | ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE, Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5497 | final long identity = Binder.clearCallingIdentity(); |
| 5498 | try { |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5499 | if (request.channel < 0) { |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 5500 | throw new IllegalArgumentException("request.channel is less than 0"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5501 | } |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 5502 | Object result = sendRequest(CMD_CLOSE_CHANNEL, request.channel, phone, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5503 | null /* workSource */); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 5504 | Boolean success = false; |
| 5505 | if (result instanceof RuntimeException) { |
| 5506 | // if there is an exception returned, throw from the binder thread here. |
Chen Xu | a8f0dff | 2022-02-12 00:34:15 -0800 | [diff] [blame] | 5507 | if (shouldThrowExceptionOnFailure) { |
| 5508 | throw (RuntimeException) result; |
| 5509 | } else { |
| 5510 | return false; |
| 5511 | } |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 5512 | } else if (result instanceof Boolean) { |
| 5513 | success = (Boolean) result; |
| 5514 | } else { |
| 5515 | loge("iccCloseLogicalChannelWithPermission: supported return type " + result); |
| 5516 | } |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5517 | if (DBG) log("iccCloseLogicalChannelWithPermission: success=" + success); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5518 | return success; |
| 5519 | } finally { |
| 5520 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5521 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5522 | } |
| 5523 | |
| 5524 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5525 | public String iccTransmitApduLogicalChannel(int subId, int channel, int cla, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5526 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5527 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5528 | mApp, subId, "iccTransmitApduLogicalChannel"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5529 | if (DBG) { |
| 5530 | log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel |
| 5531 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 5532 | + p3 + " data=" + data); |
| 5533 | } |
| 5534 | return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla, |
| 5535 | command, p1, p2, p3, data); |
| 5536 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5537 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5538 | @Override |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5539 | public String iccTransmitApduLogicalChannelByPort(int slotIndex, int portIndex, int channel, |
| 5540 | int cla, int command, int p1, int p2, int p3, String data) { |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5541 | enforceModifyPermission(); |
| 5542 | if (DBG) { |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5543 | log("iccTransmitApduLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex=" |
| 5544 | + portIndex + " chnl=" + channel + " cla=" + cla + " cmd=" + command + " p1=" |
| 5545 | + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5546 | } |
| 5547 | return iccTransmitApduLogicalChannelWithPermission( |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5548 | getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel, cla, |
| 5549 | command, p1, p2, p3, data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5550 | } |
| 5551 | |
| 5552 | private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla, |
| 5553 | int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5554 | final long identity = Binder.clearCallingIdentity(); |
| 5555 | try { |
Hall Liu | 4fd771b | 2019-05-02 09:16:29 -0700 | [diff] [blame] | 5556 | if (channel <= 0) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5557 | return ""; |
| 5558 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5559 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5560 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5561 | new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone, |
| 5562 | null /* workSource */); |
| 5563 | if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5564 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5565 | // Append the returned status code to the end of the response payload. |
| 5566 | String s = Integer.toHexString( |
| 5567 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 5568 | if (response.payload != null) { |
| 5569 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 5570 | } |
| 5571 | return s; |
| 5572 | } finally { |
| 5573 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 5574 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5575 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5576 | |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5577 | @Override |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 5578 | public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla, |
| 5579 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5580 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5581 | mApp, subId, "iccTransmitApduBasicChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5582 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5583 | if (DBG) { |
| 5584 | log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" |
| 5585 | + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
| 5586 | } |
| 5587 | return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage, |
| 5588 | cla, command, p1, p2, p3, data); |
| 5589 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5590 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5591 | @Override |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5592 | public String iccTransmitApduBasicChannelByPort(int slotIndex, int portIndex, |
| 5593 | 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] | 5594 | enforceModifyPermission(); |
| 5595 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 5596 | if (DBG) { |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5597 | log("iccTransmitApduBasicChannelByPort: slotIndex=" + slotIndex + " portIndex=" |
| 5598 | + portIndex + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" |
| 5599 | + p2 + " p3=" + p3 + " data=" + data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5600 | } |
| 5601 | |
| 5602 | return iccTransmitApduBasicChannelWithPermission( |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5603 | getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), callingPackage, |
| 5604 | cla, command, p1, p2, p3, data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5605 | } |
| 5606 | |
| 5607 | // open APDU basic channel assuming the caller has sufficient permissions |
| 5608 | private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage, |
| 5609 | int cla, int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5610 | final long identity = Binder.clearCallingIdentity(); |
| 5611 | try { |
| 5612 | if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3 |
| 5613 | && TextUtils.equals(ISDR_AID, data)) { |
| 5614 | // Only allows LPA to select ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5615 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 5616 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5617 | if (bestComponent == null |
| 5618 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 5619 | loge("The calling package is not allowed to select ISD-R."); |
| 5620 | throw new SecurityException( |
| 5621 | "The calling package is not allowed to select ISD-R."); |
| 5622 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 5623 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 5624 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5625 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5626 | new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone, |
| 5627 | null /* workSource */); |
| 5628 | if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5629 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5630 | // Append the returned status code to the end of the response payload. |
| 5631 | String s = Integer.toHexString( |
| 5632 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 5633 | if (response.payload != null) { |
| 5634 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 5635 | } |
| 5636 | return s; |
| 5637 | } finally { |
| 5638 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 5639 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5640 | } |
| 5641 | |
| 5642 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5643 | 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] | 5644 | String filePath) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5645 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5646 | mApp, subId, "iccExchangeSimIO"); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5647 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5648 | final long identity = Binder.clearCallingIdentity(); |
| 5649 | try { |
| 5650 | if (DBG) { |
| 5651 | log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " |
| 5652 | + p1 + " " + p2 + " " + p3 + ":" + filePath); |
| 5653 | } |
| 5654 | |
| 5655 | IccIoResult response = |
| 5656 | (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO, |
| 5657 | new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath), |
| 5658 | subId); |
| 5659 | |
| 5660 | if (DBG) { |
| 5661 | log("Exchange SIM_IO [R]" + response); |
| 5662 | } |
| 5663 | |
| 5664 | byte[] result = null; |
| 5665 | int length = 2; |
| 5666 | if (response.payload != null) { |
| 5667 | length = 2 + response.payload.length; |
| 5668 | result = new byte[length]; |
| 5669 | System.arraycopy(response.payload, 0, result, 0, response.payload.length); |
| 5670 | } else { |
| 5671 | result = new byte[length]; |
| 5672 | } |
| 5673 | |
| 5674 | result[length - 1] = (byte) response.sw2; |
| 5675 | result[length - 2] = (byte) response.sw1; |
| 5676 | return result; |
| 5677 | } finally { |
| 5678 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5679 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5680 | } |
| 5681 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5682 | /** |
| 5683 | * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM) |
| 5684 | * on a particular subscription |
| 5685 | */ |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5686 | public String[] getForbiddenPlmns(int subId, int appType, String callingPackage, |
| 5687 | String callingFeatureId) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 5688 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5689 | mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 5690 | return null; |
| 5691 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5692 | |
| 5693 | final long identity = Binder.clearCallingIdentity(); |
| 5694 | try { |
| 5695 | if (appType != TelephonyManager.APPTYPE_USIM |
| 5696 | && appType != TelephonyManager.APPTYPE_SIM) { |
| 5697 | loge("getForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 5698 | return null; |
| 5699 | } |
| 5700 | Object response = sendRequest( |
| 5701 | CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId); |
| 5702 | if (response instanceof String[]) { |
| 5703 | return (String[]) response; |
| 5704 | } |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5705 | // Response is an Exception of some kind |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5706 | // which is signalled to the user as a NULL retval |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5707 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5708 | } finally { |
| 5709 | Binder.restoreCallingIdentity(identity); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5710 | } |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5711 | } |
| 5712 | |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5713 | /** |
| 5714 | * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular |
| 5715 | * subscription. |
| 5716 | * |
| 5717 | * @param subId the id of the subscription. |
| 5718 | * @param appType the uicc app type, must be USIM or SIM. |
| 5719 | * @param fplmns the Forbiden plmns list that needed to be written to the SIM. |
| 5720 | * @param callingPackage the op Package name. |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5721 | * @param callingFeatureId the feature in the package. |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5722 | * @return number of fplmns that is successfully written to the SIM. |
| 5723 | */ |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5724 | public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage, |
| 5725 | String callingFeatureId) { |
Jayachandran C | 5b0d75a | 2021-10-21 22:15:27 -0700 | [diff] [blame] | 5726 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5727 | mApp, subId, "setForbiddenPlmns"); |
| 5728 | |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5729 | if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) { |
| 5730 | loge("setForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 5731 | throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM"); |
| 5732 | } |
| 5733 | if (fplmns == null) { |
| 5734 | throw new IllegalArgumentException("Fplmn List provided is null"); |
| 5735 | } |
| 5736 | for (String fplmn : fplmns) { |
| 5737 | if (!CellIdentity.isValidPlmn(fplmn)) { |
| 5738 | throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn); |
| 5739 | } |
| 5740 | } |
| 5741 | final long identity = Binder.clearCallingIdentity(); |
| 5742 | try { |
| 5743 | Object response = sendRequest( |
| 5744 | CMD_SET_FORBIDDEN_PLMNS, |
| 5745 | new Pair<Integer, List<String>>(new Integer(appType), fplmns), |
| 5746 | subId); |
| 5747 | return (int) response; |
| 5748 | } finally { |
| 5749 | Binder.restoreCallingIdentity(identity); |
| 5750 | } |
| 5751 | } |
| 5752 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5753 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5754 | public String sendEnvelopeWithStatus(int subId, String content) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5755 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5756 | mApp, subId, "sendEnvelopeWithStatus"); |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5757 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5758 | final long identity = Binder.clearCallingIdentity(); |
| 5759 | try { |
| 5760 | IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId); |
| 5761 | if (response.payload == null) { |
| 5762 | return ""; |
| 5763 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5764 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5765 | // Append the returned status code to the end of the response payload. |
| 5766 | String s = Integer.toHexString( |
| 5767 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 5768 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 5769 | return s; |
| 5770 | } finally { |
| 5771 | Binder.restoreCallingIdentity(identity); |
| 5772 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5773 | } |
| 5774 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5775 | /** |
| 5776 | * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 5777 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 5778 | * |
| 5779 | * @param itemID the ID of the item to read |
| 5780 | * @return the NV item as a String, or null on error. |
| 5781 | */ |
| 5782 | @Override |
| 5783 | public String nvReadItem(int itemID) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5784 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5785 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5786 | mApp, getDefaultSubscription(), "nvReadItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5787 | |
| 5788 | final long identity = Binder.clearCallingIdentity(); |
| 5789 | try { |
| 5790 | if (DBG) log("nvReadItem: item " + itemID); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5791 | String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5792 | if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"'); |
| 5793 | return value; |
| 5794 | } finally { |
| 5795 | Binder.restoreCallingIdentity(identity); |
| 5796 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5797 | } |
| 5798 | |
| 5799 | /** |
| 5800 | * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 5801 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 5802 | * |
| 5803 | * @param itemID the ID of the item to read |
| 5804 | * @param itemValue the value to write, as a String |
| 5805 | * @return true on success; false on any failure |
| 5806 | */ |
| 5807 | @Override |
| 5808 | public boolean nvWriteItem(int itemID, String itemValue) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5809 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5810 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5811 | mApp, getDefaultSubscription(), "nvWriteItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5812 | |
| 5813 | final long identity = Binder.clearCallingIdentity(); |
| 5814 | try { |
| 5815 | if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"'); |
| 5816 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5817 | new Pair<Integer, String>(itemID, itemValue), workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5818 | if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail")); |
| 5819 | return success; |
| 5820 | } finally { |
| 5821 | Binder.restoreCallingIdentity(identity); |
| 5822 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5823 | } |
| 5824 | |
| 5825 | /** |
| 5826 | * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage. |
| 5827 | * Used for device configuration by some CDMA operators. |
| 5828 | * |
| 5829 | * @param preferredRoamingList byte array containing the new PRL |
| 5830 | * @return true on success; false on any failure |
| 5831 | */ |
| 5832 | @Override |
| 5833 | public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5834 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5835 | mApp, getDefaultSubscription(), "nvWriteCdmaPrl"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5836 | |
| 5837 | final long identity = Binder.clearCallingIdentity(); |
| 5838 | try { |
| 5839 | if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList)); |
| 5840 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList); |
| 5841 | if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail")); |
| 5842 | return success; |
| 5843 | } finally { |
| 5844 | Binder.restoreCallingIdentity(identity); |
| 5845 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5846 | } |
| 5847 | |
| 5848 | /** |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5849 | * 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] | 5850 | * Used for device configuration by some CDMA operators. |
| 5851 | * |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5852 | * @param slotIndex - device slot. |
| 5853 | * |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5854 | * @return true on success; false on any failure |
| 5855 | */ |
| 5856 | @Override |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5857 | public boolean resetModemConfig(int slotIndex) { |
| 5858 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5859 | if (phone != null) { |
| 5860 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5861 | mApp, phone.getSubId(), "resetModemConfig"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5862 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5863 | final long identity = Binder.clearCallingIdentity(); |
| 5864 | try { |
| 5865 | Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null); |
| 5866 | if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 5867 | return success; |
| 5868 | } finally { |
| 5869 | Binder.restoreCallingIdentity(identity); |
| 5870 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5871 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5872 | return false; |
| 5873 | } |
| 5874 | |
| 5875 | /** |
| 5876 | * Generate a radio modem reset. Used for device configuration by some CDMA operators. |
| 5877 | * |
| 5878 | * @param slotIndex - device slot. |
| 5879 | * |
| 5880 | * @return true on success; false on any failure |
| 5881 | */ |
| 5882 | @Override |
| 5883 | public boolean rebootModem(int slotIndex) { |
| 5884 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5885 | if (phone != null) { |
| 5886 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5887 | mApp, phone.getSubId(), "rebootModem"); |
| 5888 | |
| 5889 | final long identity = Binder.clearCallingIdentity(); |
| 5890 | try { |
| 5891 | Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null); |
| 5892 | if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail")); |
| 5893 | return success; |
| 5894 | } finally { |
| 5895 | Binder.restoreCallingIdentity(identity); |
| 5896 | } |
| 5897 | } |
| 5898 | return false; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5899 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5900 | |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5901 | /** |
Grace Jia | aa2eb6b | 2020-01-09 16:26:08 -0800 | [diff] [blame] | 5902 | * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and |
| 5903 | * {@link #disableIms(int)}. |
| 5904 | * @param slotIndex device slot. |
| 5905 | */ |
| 5906 | public void resetIms(int slotIndex) { |
| 5907 | enforceModifyPermission(); |
| 5908 | |
| 5909 | final long identity = Binder.clearCallingIdentity(); |
| 5910 | try { |
| 5911 | if (mImsResolver == null) { |
| 5912 | // may happen if the does not support IMS. |
| 5913 | return; |
| 5914 | } |
Hyunho | a17ac7c | 2022-08-30 12:03:04 +0000 | [diff] [blame] | 5915 | mImsResolver.resetIms(slotIndex); |
Grace Jia | aa2eb6b | 2020-01-09 16:26:08 -0800 | [diff] [blame] | 5916 | } finally { |
| 5917 | Binder.restoreCallingIdentity(identity); |
| 5918 | } |
| 5919 | } |
| 5920 | |
| 5921 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5922 | * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability |
| 5923 | * status updates, if not already enabled. |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5924 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5925 | public void enableIms(int slotId) { |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5926 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5927 | |
| 5928 | final long identity = Binder.clearCallingIdentity(); |
| 5929 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5930 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5931 | // may happen if the device does not support IMS. |
| 5932 | return; |
| 5933 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5934 | mImsResolver.enableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5935 | } finally { |
| 5936 | Binder.restoreCallingIdentity(identity); |
| 5937 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5938 | } |
| 5939 | |
| 5940 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5941 | * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature |
| 5942 | * status updates to disabled. |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5943 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5944 | public void disableIms(int slotId) { |
| 5945 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5946 | |
| 5947 | final long identity = Binder.clearCallingIdentity(); |
| 5948 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5949 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5950 | // may happen if the device does not support IMS. |
| 5951 | return; |
| 5952 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5953 | mImsResolver.disableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5954 | } finally { |
| 5955 | Binder.restoreCallingIdentity(identity); |
| 5956 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5957 | } |
| 5958 | |
| 5959 | /** |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5960 | * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback |
| 5961 | * callback. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5962 | */ |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5963 | @Override |
Brad Ebinger | f6aca00 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 5964 | public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) { |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5965 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5966 | |
| 5967 | final long identity = Binder.clearCallingIdentity(); |
| 5968 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5969 | if (mImsResolver == null) { |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5970 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 5971 | "Device does not support IMS"); |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5972 | } |
Brad Ebinger | f6aca00 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 5973 | mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5974 | } finally { |
| 5975 | Binder.restoreCallingIdentity(identity); |
| 5976 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5977 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5978 | /** |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5979 | * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature. |
| 5980 | */ |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5981 | @Override |
| 5982 | public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) { |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5983 | enforceModifyPermission(); |
| 5984 | |
| 5985 | final long identity = Binder.clearCallingIdentity(); |
| 5986 | try { |
| 5987 | if (mImsResolver == null) return; |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5988 | mImsResolver.unregisterImsFeatureCallback(callback); |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5989 | } finally { |
| 5990 | Binder.restoreCallingIdentity(identity); |
| 5991 | } |
| 5992 | } |
| 5993 | |
| 5994 | /** |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5995 | * Returns the {@link IImsRegistration} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5996 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5997 | */ |
| 5998 | public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException { |
| 5999 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6000 | |
| 6001 | final long identity = Binder.clearCallingIdentity(); |
| 6002 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6003 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6004 | // may happen if the device does not support IMS. |
| 6005 | return null; |
| 6006 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6007 | return mImsResolver.getImsRegistration(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6008 | } finally { |
| 6009 | Binder.restoreCallingIdentity(identity); |
| 6010 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 6011 | } |
| 6012 | |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6013 | /** |
| 6014 | * Returns the {@link IImsConfig} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6015 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6016 | */ |
| 6017 | public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException { |
| 6018 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6019 | |
| 6020 | final long identity = Binder.clearCallingIdentity(); |
| 6021 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6022 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6023 | // may happen if the device does not support IMS. |
| 6024 | return null; |
| 6025 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6026 | return mImsResolver.getImsConfig(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6027 | } finally { |
| 6028 | Binder.restoreCallingIdentity(identity); |
| 6029 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6030 | } |
| 6031 | |
Brad Ebinger | 884c07b | 2018-02-15 16:17:40 -0800 | [diff] [blame] | 6032 | /** |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6033 | * Sets the ImsService Package Name that Telephony will bind to. |
| 6034 | * |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6035 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 6036 | * @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] | 6037 | * ImsService is the device default ImsService. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6038 | * @param featureTypes An integer array of feature types associated with a packageName. |
| 6039 | * @param packageName The name of the package that the current configuration will be replaced |
| 6040 | * with. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6041 | * @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] | 6042 | */ |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6043 | public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService, |
| 6044 | int[] featureTypes, String packageName) { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6045 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 6046 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
Jack Yu | 00ece8c | 2022-11-19 22:29:12 -0800 | [diff] [blame] | 6047 | SubscriptionManager.getSubscriptionId(slotIndex), "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 6048 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6049 | final long identity = Binder.clearCallingIdentity(); |
| 6050 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6051 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6052 | // may happen if the device does not support IMS. |
| 6053 | return false; |
| 6054 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6055 | Map<Integer, String> featureConfig = new HashMap<>(); |
| 6056 | for (int featureType : featureTypes) { |
| 6057 | featureConfig.put(featureType, packageName); |
| 6058 | } |
| 6059 | return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService, |
| 6060 | featureConfig); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6061 | } finally { |
| 6062 | Binder.restoreCallingIdentity(identity); |
| 6063 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6064 | } |
| 6065 | |
| 6066 | /** |
Brad Ebinger | 999d330 | 2020-11-25 14:31:39 -0800 | [diff] [blame] | 6067 | * Clears any carrier ImsService overrides for the slot index specified that were previously |
| 6068 | * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}. |
| 6069 | * |
| 6070 | * This should only be used for testing. |
| 6071 | * |
| 6072 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 6073 | * @return true if clearing the carrier ImsService override succeeded or false if it did not. |
| 6074 | */ |
| 6075 | @Override |
| 6076 | public boolean clearCarrierImsServiceOverride(int slotIndex) { |
Brad Ebinger | 999d330 | 2020-11-25 14:31:39 -0800 | [diff] [blame] | 6077 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 6078 | "clearCarrierImsServiceOverride"); |
| 6079 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
Jack Yu | 00ece8c | 2022-11-19 22:29:12 -0800 | [diff] [blame] | 6080 | SubscriptionManager.getSubscriptionId(slotIndex), "clearCarrierImsServiceOverride"); |
Brad Ebinger | 999d330 | 2020-11-25 14:31:39 -0800 | [diff] [blame] | 6081 | |
| 6082 | final long identity = Binder.clearCallingIdentity(); |
| 6083 | try { |
| 6084 | if (mImsResolver == null) { |
| 6085 | // may happen if the device does not support IMS. |
| 6086 | return false; |
| 6087 | } |
| 6088 | return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex); |
| 6089 | } finally { |
| 6090 | Binder.restoreCallingIdentity(identity); |
| 6091 | } |
| 6092 | } |
| 6093 | |
| 6094 | /** |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6095 | * Return the package name of the currently bound ImsService. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6096 | * |
| 6097 | * @param slotId The slot that the ImsService is associated with. |
| 6098 | * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is |
| 6099 | * the device default. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6100 | * @param featureType The feature associated with the queried configuration. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6101 | * @return the package name of the ImsService configuration. |
| 6102 | */ |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6103 | public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService, |
| 6104 | @ImsFeature.FeatureType int featureType) { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6105 | TelephonyPermissions |
Jack Yu | 00ece8c | 2022-11-19 22:29:12 -0800 | [diff] [blame] | 6106 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(mApp, |
| 6107 | SubscriptionManager.getSubscriptionId(slotId), "getBoundImsServicePackage"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 6108 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6109 | final long identity = Binder.clearCallingIdentity(); |
| 6110 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6111 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6112 | // may happen if the device does not support IMS. |
| 6113 | return ""; |
| 6114 | } |
Brad Ebinger | a80c331 | 2019-12-02 10:59:39 -0800 | [diff] [blame] | 6115 | // TODO: change API to query RCS separately. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6116 | return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService, |
| 6117 | featureType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6118 | } finally { |
| 6119 | Binder.restoreCallingIdentity(identity); |
| 6120 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6121 | } |
| 6122 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6123 | /** |
| 6124 | * Get the MmTelFeature state associated with the requested subscription id. |
| 6125 | * @param subId The subscription that the MmTelFeature is associated with. |
| 6126 | * @param callback A callback with an integer containing the |
| 6127 | * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature. |
| 6128 | */ |
| 6129 | @Override |
| 6130 | public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) { |
| 6131 | enforceReadPrivilegedPermission("getImsMmTelFeatureState"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 6132 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 6133 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 6134 | "IMS not available on device."); |
| 6135 | } |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6136 | final long token = Binder.clearCallingIdentity(); |
| 6137 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 6138 | int slotId = getSlotIndex(subId); |
| 6139 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 6140 | Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '" |
| 6141 | + subId + "'"); |
| 6142 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 6143 | } |
| 6144 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 6145 | ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> { |
| 6146 | try { |
| 6147 | callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger); |
| 6148 | } catch (RemoteException e) { |
| 6149 | Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. " |
| 6150 | + "Ignore"); |
| 6151 | } |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6152 | }); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 6153 | } catch (ImsException e) { |
| 6154 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6155 | } finally { |
| 6156 | Binder.restoreCallingIdentity(token); |
| 6157 | } |
| 6158 | } |
| 6159 | |
Daniel Bright | bb5840b | 2021-01-12 15:48:18 -0800 | [diff] [blame] | 6160 | /** |
| 6161 | * Sets the ims registration state on all valid {@link Phone}s. |
| 6162 | */ |
| 6163 | public void setImsRegistrationState(final boolean registered) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 6164 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6165 | |
| 6166 | final long identity = Binder.clearCallingIdentity(); |
| 6167 | try { |
Daniel Bright | bb5840b | 2021-01-12 15:48:18 -0800 | [diff] [blame] | 6168 | // NOTE: Before S, this method only set the default phone. |
| 6169 | for (final Phone phone : PhoneFactory.getPhones()) { |
| 6170 | if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) { |
| 6171 | phone.setImsRegistrationState(registered); |
| 6172 | } |
| 6173 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6174 | } finally { |
| 6175 | Binder.restoreCallingIdentity(identity); |
| 6176 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 6177 | } |
| 6178 | |
| 6179 | /** |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 6180 | * Set the network selection mode to automatic. |
| 6181 | * |
| 6182 | */ |
| 6183 | @Override |
| 6184 | public void setNetworkSelectionModeAutomatic(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6185 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6186 | mApp, subId, "setNetworkSelectionModeAutomatic"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6187 | |
| 6188 | final long identity = Binder.clearCallingIdentity(); |
| 6189 | try { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 6190 | if (!isActiveSubscription(subId)) { |
| 6191 | return; |
| 6192 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6193 | if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId); |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 6194 | sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId, |
| 6195 | SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6196 | } finally { |
| 6197 | Binder.restoreCallingIdentity(identity); |
| 6198 | } |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 6199 | } |
| 6200 | |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 6201 | /** |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6202 | * Ask the radio to connect to the input network and change selection mode to manual. |
| 6203 | * |
| 6204 | * @param subId the id of the subscription. |
| 6205 | * @param operatorInfo the operator information, included the PLMN, long name and short name of |
| 6206 | * the operator to attach to. |
| 6207 | * @param persistSelection whether the selection will persist until reboot. If true, only allows |
| 6208 | * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume |
| 6209 | * normal network selection next time. |
| 6210 | * @return {@code true} on success; {@code true} on any failure. |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6211 | */ |
| 6212 | @Override |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6213 | public boolean setNetworkSelectionModeManual( |
| 6214 | int subId, OperatorInfo operatorInfo, boolean persistSelection) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6215 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6216 | mApp, subId, "setNetworkSelectionModeManual"); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 6217 | |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 6218 | final long identity = Binder.clearCallingIdentity(); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 6219 | if (!isActiveSubscription(subId)) { |
| 6220 | return false; |
| 6221 | } |
| 6222 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6223 | try { |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6224 | ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6225 | persistSelection); |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6226 | if (DBG) { |
| 6227 | log("setNetworkSelectionModeManual: subId: " + subId |
| 6228 | + " operator: " + operatorInfo); |
| 6229 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6230 | return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId); |
| 6231 | } finally { |
| 6232 | Binder.restoreCallingIdentity(identity); |
| 6233 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6234 | } |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6235 | /** |
| 6236 | * Get the manual network selection |
| 6237 | * |
| 6238 | * @param subId the id of the subscription. |
| 6239 | * |
| 6240 | * @return the previously saved user selected PLMN |
| 6241 | */ |
| 6242 | @Override |
| 6243 | public String getManualNetworkSelectionPlmn(int subId) { |
| 6244 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 6245 | .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6246 | mApp, subId, "getManualNetworkSelectionPlmn"); |
| 6247 | |
| 6248 | final long identity = Binder.clearCallingIdentity(); |
| 6249 | try { |
| 6250 | if (!isActiveSubscription(subId)) { |
shilu | fa1c259 | 2020-03-10 10:59:43 -0700 | [diff] [blame] | 6251 | throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6252 | } |
| 6253 | |
| 6254 | final Phone phone = getPhone(subId); |
| 6255 | if (phone == null) { |
shilu | fa1c259 | 2020-03-10 10:59:43 -0700 | [diff] [blame] | 6256 | throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6257 | } |
| 6258 | OperatorInfo networkSelection = phone.getSavedNetworkSelection(); |
| 6259 | return TextUtils.isEmpty(networkSelection.getOperatorNumeric()) |
| 6260 | ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric(); |
| 6261 | } finally { |
| 6262 | Binder.restoreCallingIdentity(identity); |
| 6263 | } |
| 6264 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6265 | |
| 6266 | /** |
| 6267 | * Scans for available networks. |
| 6268 | */ |
| 6269 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6270 | public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage, |
| 6271 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6272 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6273 | mApp, subId, "getCellNetworkScanResults"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6274 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 6275 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 6276 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 6277 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6278 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6279 | .setCallingPid(Binder.getCallingPid()) |
| 6280 | .setCallingUid(Binder.getCallingUid()) |
| 6281 | .setMethod("getCellNetworkScanResults") |
| 6282 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
Hall Liu | c4a3e42 | 2020-05-26 17:18:03 -0700 | [diff] [blame] | 6283 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 6284 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6285 | .build()); |
| 6286 | switch (locationResult) { |
| 6287 | case DENIED_HARD: |
| 6288 | throw new SecurityException("Not allowed to access scan results -- location"); |
| 6289 | case DENIED_SOFT: |
| 6290 | return null; |
| 6291 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6292 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6293 | long identity = Binder.clearCallingIdentity(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6294 | try { |
| 6295 | if (DBG) log("getCellNetworkScanResults: subId " + subId); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6296 | return (CellNetworkScanResult) sendRequest( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6297 | CMD_PERFORM_NETWORK_SCAN, null, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6298 | } finally { |
| 6299 | Binder.restoreCallingIdentity(identity); |
| 6300 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6301 | } |
| 6302 | |
| 6303 | /** |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6304 | * Get the call forwarding info, given the call forwarding reason. |
| 6305 | */ |
| 6306 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6307 | public void getCallForwarding(int subId, int callForwardingReason, |
| 6308 | ICallForwardingInfoCallback callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6309 | enforceReadPrivilegedPermission("getCallForwarding"); |
| 6310 | long identity = Binder.clearCallingIdentity(); |
| 6311 | try { |
| 6312 | if (DBG) { |
| 6313 | log("getCallForwarding: subId " + subId |
| 6314 | + " callForwardingReason" + callForwardingReason); |
| 6315 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6316 | |
| 6317 | Phone phone = getPhone(subId); |
| 6318 | if (phone == null) { |
| 6319 | try { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 6320 | callback.onError( |
| 6321 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6322 | } catch (RemoteException e) { |
| 6323 | // ignore |
| 6324 | } |
| 6325 | return; |
| 6326 | } |
| 6327 | |
| 6328 | Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create( |
| 6329 | callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() { |
| 6330 | @Override |
| 6331 | public void onCallForwardingInfoAvailable(CallForwardingInfo info) { |
| 6332 | try { |
| 6333 | callback.onCallForwardingInfoAvailable(info); |
| 6334 | } catch (RemoteException e) { |
| 6335 | // ignore |
| 6336 | } |
| 6337 | } |
| 6338 | |
| 6339 | @Override |
| 6340 | public void onError(int error) { |
| 6341 | try { |
| 6342 | callback.onError(error); |
| 6343 | } catch (RemoteException e) { |
| 6344 | // ignore |
| 6345 | } |
| 6346 | } |
| 6347 | }); |
| 6348 | sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6349 | } finally { |
| 6350 | Binder.restoreCallingIdentity(identity); |
| 6351 | } |
| 6352 | } |
| 6353 | |
| 6354 | /** |
| 6355 | * Sets the voice call forwarding info including status (enable/disable), call forwarding |
| 6356 | * reason, the number to forward, and the timeout before the forwarding is attempted. |
| 6357 | */ |
| 6358 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6359 | public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo, |
| 6360 | IIntegerConsumer callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6361 | enforceModifyPermission(); |
| 6362 | long identity = Binder.clearCallingIdentity(); |
| 6363 | try { |
| 6364 | if (DBG) { |
| 6365 | log("setCallForwarding: subId " + subId |
| 6366 | + " callForwardingInfo" + callForwardingInfo); |
| 6367 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6368 | |
| 6369 | Phone phone = getPhone(subId); |
| 6370 | if (phone == null) { |
| 6371 | try { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 6372 | callback.accept( |
| 6373 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6374 | } catch (RemoteException e) { |
| 6375 | // ignore |
| 6376 | } |
| 6377 | return; |
| 6378 | } |
| 6379 | |
| 6380 | Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo, |
| 6381 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 6382 | |
| 6383 | sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6384 | } finally { |
| 6385 | Binder.restoreCallingIdentity(identity); |
| 6386 | } |
| 6387 | } |
| 6388 | |
| 6389 | /** |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6390 | * Get the call waiting status for a subId. |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6391 | */ |
| 6392 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6393 | public void getCallWaitingStatus(int subId, IIntegerConsumer callback) { |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6394 | enforceReadPrivilegedPermission("getCallWaitingStatus"); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6395 | long identity = Binder.clearCallingIdentity(); |
| 6396 | try { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6397 | Phone phone = getPhone(subId); |
| 6398 | if (phone == null) { |
| 6399 | try { |
| 6400 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 6401 | } catch (RemoteException e) { |
| 6402 | // ignore |
| 6403 | } |
| 6404 | return; |
| 6405 | } |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6406 | CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext()); |
| 6407 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 6408 | boolean requireUssd = c.getBoolean( |
| 6409 | CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6410 | |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6411 | if (DBG) log("getCallWaitingStatus: subId " + subId); |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6412 | if (requireUssd) { |
| 6413 | CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(), |
| 6414 | getSubscriptionCarrierId(subId)); |
| 6415 | String newUssdCommand = ""; |
| 6416 | try { |
| 6417 | newUssdCommand = carrierXmlParser.getFeature( |
| 6418 | CarrierXmlParser.FEATURE_CALL_WAITING) |
| 6419 | .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null); |
| 6420 | } catch (NullPointerException e) { |
| 6421 | loge("Failed to generate USSD number" + e); |
| 6422 | } |
| 6423 | ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver( |
| 6424 | mMainThreadHandler, callback, carrierXmlParser, |
| 6425 | CarrierXmlParser.SsEntry.SSAction.QUERY); |
| 6426 | final String ussdCommand = newUssdCommand; |
| 6427 | Executors.newSingleThreadExecutor().execute(() -> { |
| 6428 | handleUssdRequest(subId, ussdCommand, wrappedCallback); |
| 6429 | }); |
| 6430 | } else { |
| 6431 | Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException( |
| 6432 | callback::accept); |
| 6433 | sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null); |
| 6434 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6435 | } finally { |
| 6436 | Binder.restoreCallingIdentity(identity); |
| 6437 | } |
| 6438 | } |
| 6439 | |
| 6440 | /** |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6441 | * Sets whether call waiting is enabled for a given subId. |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6442 | */ |
| 6443 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6444 | public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6445 | enforceModifyPermission(); |
| 6446 | long identity = Binder.clearCallingIdentity(); |
| 6447 | try { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6448 | if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable); |
| 6449 | |
| 6450 | Phone phone = getPhone(subId); |
| 6451 | if (phone == null) { |
| 6452 | try { |
| 6453 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 6454 | } catch (RemoteException e) { |
| 6455 | // ignore |
| 6456 | } |
| 6457 | return; |
| 6458 | } |
| 6459 | |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6460 | CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext()); |
| 6461 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 6462 | boolean requireUssd = c.getBoolean( |
| 6463 | CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6464 | |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6465 | if (DBG) log("getCallWaitingStatus: subId " + subId); |
| 6466 | if (requireUssd) { |
| 6467 | CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(), |
| 6468 | getSubscriptionCarrierId(subId)); |
| 6469 | CarrierXmlParser.SsEntry.SSAction ssAction = |
| 6470 | enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE |
| 6471 | : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE; |
| 6472 | String newUssdCommand = ""; |
| 6473 | try { |
| 6474 | newUssdCommand = carrierXmlParser.getFeature( |
| 6475 | CarrierXmlParser.FEATURE_CALL_WAITING) |
| 6476 | .makeCommand(ssAction, null); |
| 6477 | } catch (NullPointerException e) { |
| 6478 | loge("Failed to generate USSD number" + e); |
| 6479 | } |
| 6480 | ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver( |
| 6481 | mMainThreadHandler, callback, carrierXmlParser, ssAction); |
| 6482 | final String ussdCommand = newUssdCommand; |
| 6483 | Executors.newSingleThreadExecutor().execute(() -> { |
| 6484 | handleUssdRequest(subId, ussdCommand, wrappedCallback); |
| 6485 | }); |
| 6486 | } else { |
| 6487 | Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable, |
| 6488 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 6489 | |
| 6490 | sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null); |
| 6491 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6492 | } finally { |
| 6493 | Binder.restoreCallingIdentity(identity); |
| 6494 | } |
| 6495 | } |
| 6496 | |
| 6497 | /** |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 6498 | * Starts a new network scan and returns the id of this scan. |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6499 | * |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 6500 | * @param subId id of the subscription |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 6501 | * @param renounceFineLocationAccess Set this to true if the caller would not like to receive |
| 6502 | * location related information which will be sent if the caller already possess |
| 6503 | * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 6504 | * @param request contains the radio access networks with bands/channels to scan |
| 6505 | * @param messenger callback messenger for scan results or errors |
| 6506 | * @param binder for the purpose of auto clean when the user thread crashes |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6507 | * @return the id of the requested scan which can be used to stop the scan. |
| 6508 | */ |
| 6509 | @Override |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 6510 | public int requestNetworkScan(int subId, boolean renounceFineLocationAccess, |
| 6511 | NetworkScanRequest request, Messenger messenger, |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6512 | IBinder binder, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6513 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6514 | mApp, subId, "requestNetworkScan"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6515 | LocationAccessPolicy.LocationPermissionResult locationResult = |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 6516 | LocationAccessPolicy.LocationPermissionResult.DENIED_HARD; |
| 6517 | if (!renounceFineLocationAccess) { |
| 6518 | locationResult = LocationAccessPolicy.checkLocationPermission(mApp, |
| 6519 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 6520 | .setCallingPackage(callingPackage) |
| 6521 | .setCallingFeatureId(callingFeatureId) |
| 6522 | .setCallingPid(Binder.getCallingPid()) |
| 6523 | .setCallingUid(Binder.getCallingUid()) |
| 6524 | .setMethod("requestNetworkScan") |
| 6525 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 6526 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 6527 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 6528 | .build()); |
| 6529 | } |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6530 | if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) { |
Nathan Harold | 1c11dba | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 6531 | SecurityException e = checkNetworkRequestForSanitizedLocationAccess( |
| 6532 | request, subId, callingPackage); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6533 | if (e != null) { |
| 6534 | if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) { |
| 6535 | throw e; |
| 6536 | } else { |
Hall Liu | 0e5abaf | 2019-04-04 01:25:30 -0700 | [diff] [blame] | 6537 | loge(e.getMessage()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6538 | return TelephonyScanManager.INVALID_SCAN_ID; |
| 6539 | } |
| 6540 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6541 | } |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6542 | int callingUid = Binder.getCallingUid(); |
| 6543 | int callingPid = Binder.getCallingPid(); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 6544 | final long identity = Binder.clearCallingIdentity(); |
| 6545 | try { |
| 6546 | return mNetworkScanRequestTracker.startNetworkScan( |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 6547 | renounceFineLocationAccess, request, messenger, binder, getPhone(subId), |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6548 | callingUid, callingPid, callingPackage); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 6549 | } finally { |
| 6550 | Binder.restoreCallingIdentity(identity); |
| 6551 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6552 | } |
| 6553 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6554 | private SecurityException checkNetworkRequestForSanitizedLocationAccess( |
Nathan Harold | 1c11dba | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 6555 | NetworkScanRequest request, int subId, String callingPackage) { |
Rambo Wang | 3dee30a | 2022-10-20 16:52:29 +0000 | [diff] [blame] | 6556 | boolean hasCarrierPriv; |
| 6557 | final long identity = Binder.clearCallingIdentity(); |
| 6558 | try { |
| 6559 | hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage) |
| 6560 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 6561 | } finally { |
| 6562 | Binder.restoreCallingIdentity(identity); |
| 6563 | } |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 6564 | boolean hasNetworkScanPermission = |
| 6565 | mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN) |
| 6566 | == PERMISSION_GRANTED; |
| 6567 | |
| 6568 | if (!hasCarrierPriv && !hasNetworkScanPermission) { |
| 6569 | return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed" |
| 6570 | + " for network scans without location access."); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6571 | } |
| 6572 | |
| 6573 | if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) { |
| 6574 | for (RadioAccessSpecifier ras : request.getSpecifiers()) { |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6575 | if (ras.getChannels() != null && ras.getChannels().length > 0) { |
| 6576 | return new SecurityException("Specific channels must not be" |
| 6577 | + " scanned without location access."); |
| 6578 | } |
| 6579 | } |
| 6580 | } |
| 6581 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6582 | return null; |
| 6583 | } |
| 6584 | |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6585 | /** |
| 6586 | * Stops an existing network scan with the given scanId. |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 6587 | * |
| 6588 | * @param subId id of the subscription |
| 6589 | * @param scanId id of the scan that needs to be stopped |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6590 | */ |
| 6591 | @Override |
| 6592 | public void stopNetworkScan(int subId, int scanId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6593 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6594 | mApp, subId, "stopNetworkScan"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6595 | |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6596 | int callingUid = Binder.getCallingUid(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6597 | final long identity = Binder.clearCallingIdentity(); |
| 6598 | try { |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6599 | mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6600 | } finally { |
| 6601 | Binder.restoreCallingIdentity(identity); |
| 6602 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6603 | } |
| 6604 | |
| 6605 | /** |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6606 | * Get the allowed network types bitmask. |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 6607 | * |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6608 | * @return the allowed network types bitmask, defined in RILConstants.java. |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 6609 | */ |
| 6610 | @Override |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6611 | public int getAllowedNetworkTypesBitmask(int subId) { |
Pengquan Meng | a4009cb | 2018-12-20 11:00:24 -0800 | [diff] [blame] | 6612 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 6613 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6614 | mApp, subId, "getAllowedNetworkTypesBitmask"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6615 | |
| 6616 | final long identity = Binder.clearCallingIdentity(); |
| 6617 | try { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6618 | if (DBG) log("getAllowedNetworkTypesBitmask"); |
| 6619 | int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId); |
| 6620 | int networkTypesBitmask = (result != null ? result[0] : -1); |
| 6621 | if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask); |
| 6622 | return networkTypesBitmask; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6623 | } finally { |
| 6624 | Binder.restoreCallingIdentity(identity); |
| 6625 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 6626 | } |
| 6627 | |
| 6628 | /** |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6629 | * Get the allowed network types for certain reason. |
| 6630 | * |
| 6631 | * @param subId the id of the subscription. |
| 6632 | * @param reason the reason the allowed network type change is taking place |
| 6633 | * @return the allowed network types. |
| 6634 | */ |
| 6635 | @Override |
| 6636 | public long getAllowedNetworkTypesForReason(int subId, |
| 6637 | @TelephonyManager.AllowedNetworkTypesReason int reason) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 6638 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 6639 | mApp, subId, "getAllowedNetworkTypesForReason"); |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6640 | final long identity = Binder.clearCallingIdentity(); |
| 6641 | try { |
| 6642 | return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason); |
| 6643 | } finally { |
| 6644 | Binder.restoreCallingIdentity(identity); |
| 6645 | } |
| 6646 | } |
| 6647 | |
| 6648 | /** |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6649 | * Enable/Disable E-UTRA-NR Dual Connectivity |
| 6650 | * @param subId subscription id of the sim card |
| 6651 | * @param nrDualConnectivityState expected NR dual connectivity state |
| 6652 | * This can be passed following states |
| 6653 | * <ol> |
| 6654 | * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE} |
| 6655 | * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE} |
| 6656 | * <li>Disable NR dual connectivity and force secondary cell to be released |
| 6657 | * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE} |
| 6658 | * </ol> |
| 6659 | * @return operation result. |
| 6660 | */ |
| 6661 | @Override |
| 6662 | public int setNrDualConnectivityState(int subId, |
| 6663 | @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) { |
| 6664 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6665 | mApp, subId, "enableNRDualConnectivity"); |
Sooraj Sasindran | 0e4e00a | 2021-03-16 18:02:32 -0700 | [diff] [blame] | 6666 | if (!isRadioInterfaceCapabilitySupported( |
Sooraj Sasindran | dfd595b | 2021-03-11 17:38:13 -0800 | [diff] [blame] | 6667 | TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) { |
| 6668 | return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED; |
| 6669 | } |
| 6670 | |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6671 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 6672 | final long identity = Binder.clearCallingIdentity(); |
| 6673 | try { |
| 6674 | int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY, |
| 6675 | nrDualConnectivityState, subId, |
| 6676 | workSource); |
| 6677 | if (DBG) log("enableNRDualConnectivity result: " + result); |
| 6678 | return result; |
| 6679 | } finally { |
| 6680 | Binder.restoreCallingIdentity(identity); |
| 6681 | } |
| 6682 | } |
| 6683 | |
| 6684 | /** |
| 6685 | * Is E-UTRA-NR Dual Connectivity enabled |
| 6686 | * @return true if dual connectivity is enabled else false |
| 6687 | */ |
| 6688 | @Override |
| 6689 | public boolean isNrDualConnectivityEnabled(int subId) { |
| 6690 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 6691 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6692 | mApp, subId, "isNRDualConnectivityEnabled"); |
Sooraj Sasindran | 0e4e00a | 2021-03-16 18:02:32 -0700 | [diff] [blame] | 6693 | if (!isRadioInterfaceCapabilitySupported( |
Sooraj Sasindran | dfd595b | 2021-03-11 17:38:13 -0800 | [diff] [blame] | 6694 | TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) { |
| 6695 | return false; |
| 6696 | } |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6697 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 6698 | final long identity = Binder.clearCallingIdentity(); |
| 6699 | try { |
| 6700 | boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED, |
| 6701 | null, subId, workSource); |
| 6702 | if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled); |
| 6703 | return isEnabled; |
| 6704 | } finally { |
| 6705 | Binder.restoreCallingIdentity(identity); |
| 6706 | } |
| 6707 | } |
| 6708 | |
| 6709 | /** |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6710 | * Set the allowed network types of the device and |
| 6711 | * provide the reason triggering the allowed network change. |
| 6712 | * |
| 6713 | * @param subId the id of the subscription. |
| 6714 | * @param reason the reason the allowed network type change is taking place |
| 6715 | * @param allowedNetworkTypes the allowed network types. |
| 6716 | * @return true on success; false on any failure. |
| 6717 | */ |
| 6718 | @Override |
| 6719 | public boolean setAllowedNetworkTypesForReason(int subId, |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6720 | @TelephonyManager.AllowedNetworkTypesReason int reason, |
| 6721 | @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) { |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6722 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6723 | mApp, subId, "setAllowedNetworkTypesForReason"); |
Gil Cukierman | 1d3d375 | 2022-10-03 21:31:33 +0000 | [diff] [blame] | 6724 | // If the caller only has carrier privileges, then they should not be able to override |
| 6725 | // any network types which were set for security reasons. |
| 6726 | if (mApp.checkCallingOrSelfPermission(Manifest.permission.MODIFY_PHONE_STATE) |
| 6727 | != PERMISSION_GRANTED |
| 6728 | && (reason == TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_ENABLE_2G |
| 6729 | || reason == TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER_RESTRICTIONS)) { |
| 6730 | throw new SecurityException( |
| 6731 | "setAllowedNetworkTypesForReason cannot be called with carrier privileges for" |
| 6732 | + " reason " |
| 6733 | + reason); |
| 6734 | } |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6735 | if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) { |
SongFerngWang | 7ffc273 | 2021-04-15 19:46:33 +0800 | [diff] [blame] | 6736 | loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason); |
| 6737 | return false; |
| 6738 | } |
| 6739 | if (!SubscriptionManager.isUsableSubscriptionId(subId)) { |
| 6740 | loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId); |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6741 | return false; |
| 6742 | } |
| 6743 | |
Jack Yu | e37dd26 | 2022-12-16 11:53:37 -0800 | [diff] [blame] | 6744 | log("setAllowedNetworkTypesForReason: subId=" + subId + ", reason=" + reason + " value: " |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 6745 | + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes)); |
| 6746 | |
Jack Yu | e37dd26 | 2022-12-16 11:53:37 -0800 | [diff] [blame] | 6747 | Phone phone = getPhone(subId); |
| 6748 | if (phone == null) { |
| 6749 | return false; |
| 6750 | } |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 6751 | |
Jack Yu | e37dd26 | 2022-12-16 11:53:37 -0800 | [diff] [blame] | 6752 | if (allowedNetworkTypes == phone.getAllowedNetworkTypes(reason)) { |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 6753 | log("setAllowedNetworkTypesForReason: " + reason + "does not change value"); |
| 6754 | return true; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6755 | } |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 6756 | |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6757 | final long identity = Binder.clearCallingIdentity(); |
| 6758 | try { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6759 | Boolean success = (Boolean) sendRequest( |
| 6760 | CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON, |
| 6761 | new Pair<Integer, Long>(reason, allowedNetworkTypes), subId); |
| 6762 | |
| 6763 | if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail")); |
| 6764 | return success; |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6765 | } finally { |
| 6766 | Binder.restoreCallingIdentity(identity); |
| 6767 | } |
| 6768 | } |
| 6769 | |
| 6770 | /** |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6771 | * Check whether DUN APN is required for tethering with subId. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6772 | * |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6773 | * @param subId the id of the subscription to require tethering. |
Amit Mahajan | fe58cdf | 2017-07-11 12:01:53 -0700 | [diff] [blame] | 6774 | * @return {@code true} if DUN APN is required for tethering. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6775 | * @hide |
| 6776 | */ |
| 6777 | @Override |
SongFerngWang | f08d812 | 2019-11-15 14:58:44 +0800 | [diff] [blame] | 6778 | public boolean isTetheringApnRequiredForSubscriber(int subId) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6779 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6780 | final long identity = Binder.clearCallingIdentity(); |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6781 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6782 | try { |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6783 | if (phone != null) { |
| 6784 | return phone.hasMatchedTetherApnSetting(); |
| 6785 | } else { |
| 6786 | return false; |
| 6787 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6788 | } finally { |
| 6789 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6790 | } |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6791 | } |
| 6792 | |
| 6793 | /** |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6794 | * Get the user enabled state of Mobile Data. |
| 6795 | * |
| 6796 | * TODO: remove and use isUserDataEnabled. |
| 6797 | * This can't be removed now because some vendor codes |
| 6798 | * calls through ITelephony directly while they should |
| 6799 | * use TelephonyManager. |
| 6800 | * |
| 6801 | * @return true on enabled |
| 6802 | */ |
| 6803 | @Override |
| 6804 | public boolean getDataEnabled(int subId) { |
| 6805 | return isUserDataEnabled(subId); |
| 6806 | } |
| 6807 | |
| 6808 | /** |
| 6809 | * Get whether mobile data is enabled per user setting. |
| 6810 | * |
| 6811 | * There are other factors deciding whether mobile data is actually enabled, but they are |
| 6812 | * not considered here. See {@link #isDataEnabled(int)} for more details. |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6813 | * |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6814 | * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE |
| 6815 | * or carrier privileges. |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 6816 | * |
| 6817 | * @return {@code true} if data is enabled else {@code false} |
| 6818 | */ |
| 6819 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6820 | public boolean isUserDataEnabled(int subId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6821 | String functionName = "isUserDataEnabled"; |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6822 | try { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6823 | try { |
| 6824 | mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE, |
| 6825 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 6826 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6827 | mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName); |
| 6828 | } |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 6829 | } catch (SecurityException e) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6830 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6831 | mApp, subId, functionName); |
| 6832 | |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6833 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6834 | |
| 6835 | final long identity = Binder.clearCallingIdentity(); |
| 6836 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 6837 | int phoneId = SubscriptionManager.getPhoneId(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6838 | if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 6839 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6840 | if (phone != null) { |
| 6841 | boolean retVal = phone.isUserDataEnabled(); |
| 6842 | if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 6843 | return retVal; |
| 6844 | } else { |
| 6845 | if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 6846 | return false; |
| 6847 | } |
| 6848 | } finally { |
| 6849 | Binder.restoreCallingIdentity(identity); |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6850 | } |
| 6851 | } |
| 6852 | |
| 6853 | /** |
Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 6854 | * Checks if the device is capable of mobile data by considering whether whether the |
| 6855 | * user has enabled mobile data, whether the carrier has enabled mobile data, and |
| 6856 | * whether the network policy allows data connections. |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6857 | * |
Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 6858 | * @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] | 6859 | */ |
| 6860 | @Override |
| 6861 | public boolean isDataEnabled(int subId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6862 | String functionName = "isDataEnabled"; |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6863 | try { |
| 6864 | try { |
| 6865 | mApp.enforceCallingOrSelfPermission( |
| 6866 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6867 | functionName); |
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 | try { |
| 6870 | mApp.enforceCallingOrSelfPermission( |
| 6871 | android.Manifest.permission.READ_PHONE_STATE, |
| 6872 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 6873 | } catch (SecurityException e2) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6874 | mApp.enforceCallingOrSelfPermission( |
| 6875 | permission.READ_BASIC_PHONE_STATE, functionName); |
| 6876 | } |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6877 | } |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 6878 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6879 | enforceReadPrivilegedPermission(functionName); |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6880 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6881 | |
| 6882 | final long identity = Binder.clearCallingIdentity(); |
| 6883 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 6884 | int phoneId = SubscriptionManager.getPhoneId(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6885 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6886 | if (phone != null) { |
Sarah Chin | e04784a | 2022-10-31 20:32:34 -0700 | [diff] [blame] | 6887 | boolean retVal = phone.getDataSettingsManager().isDataEnabled(); |
Jack Yu | 4ad64e5 | 2021-12-03 14:23:53 -0800 | [diff] [blame] | 6888 | if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6889 | return retVal; |
| 6890 | } else { |
| 6891 | if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 6892 | return false; |
| 6893 | } |
| 6894 | } finally { |
| 6895 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 6896 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 6897 | } |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6898 | |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6899 | /** |
| 6900 | * Check if data is enabled for a specific reason |
| 6901 | * @param subId Subscription index |
| 6902 | * @param reason the reason the data enable change is taking place |
| 6903 | * @return {@code true} if the overall data is enabled; {@code false} if not. |
| 6904 | */ |
| 6905 | @Override |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6906 | public boolean isDataEnabledForReason(int subId, |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6907 | @TelephonyManager.DataEnabledReason int reason) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6908 | String functionName = "isDataEnabledForReason"; |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6909 | try { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6910 | try { |
| 6911 | mApp.enforceCallingOrSelfPermission( |
| 6912 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 6913 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 6914 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6915 | mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE, |
| 6916 | functionName); |
| 6917 | } |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 6918 | } catch (SecurityException e) { |
Sooraj Sasindran | 0d909a0 | 2021-11-08 12:01:16 -0800 | [diff] [blame] | 6919 | try { |
| 6920 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6921 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 6922 | } catch (SecurityException e2) { |
Sooraj Sasindran | 0d909a0 | 2021-11-08 12:01:16 -0800 | [diff] [blame] | 6923 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6924 | mApp, subId, functionName); |
Sooraj Sasindran | 0d909a0 | 2021-11-08 12:01:16 -0800 | [diff] [blame] | 6925 | } |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6926 | } |
| 6927 | |
| 6928 | |
| 6929 | final long identity = Binder.clearCallingIdentity(); |
| 6930 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 6931 | int phoneId = SubscriptionManager.getPhoneId(subId); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6932 | if (DBG) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6933 | log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6934 | + " reason=" + reason); |
| 6935 | } |
| 6936 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6937 | if (phone != null) { |
| 6938 | boolean retVal; |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 6939 | retVal = phone.getDataSettingsManager().isDataEnabledForReason(reason); |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6940 | if (DBG) log("isDataEnabledForReason: retVal=" + retVal); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6941 | return retVal; |
| 6942 | } else { |
| 6943 | if (DBG) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6944 | loge("isDataEnabledForReason: no phone subId=" |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6945 | + subId + " retVal=false"); |
| 6946 | } |
| 6947 | return false; |
| 6948 | } |
| 6949 | } finally { |
| 6950 | Binder.restoreCallingIdentity(identity); |
| 6951 | } |
| 6952 | } |
| 6953 | |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6954 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6955 | public int getCarrierPrivilegeStatus(int subId) { |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6956 | // No permission needed; this only lets the caller inspect their own status. |
| 6957 | return getCarrierPrivilegeStatusForUidWithPermission(subId, Binder.getCallingUid()); |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6958 | } |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 6959 | |
| 6960 | @Override |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6961 | public int getCarrierPrivilegeStatusForUid(int subId, int uid) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6962 | enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid"); |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6963 | return getCarrierPrivilegeStatusForUidWithPermission(subId, uid); |
| 6964 | } |
| 6965 | |
| 6966 | private int getCarrierPrivilegeStatusForUidWithPermission(int subId, int uid) { |
| 6967 | Phone phone = getPhone(subId); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6968 | if (phone == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 6969 | loge("getCarrierPrivilegeStatusForUid: Invalid subId"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6970 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 6971 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6972 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 6973 | if (cpt == null) { |
| 6974 | loge("getCarrierPrivilegeStatusForUid: No CarrierPrivilegesTracker"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6975 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6976 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6977 | return cpt.getCarrierPrivilegeStatusForUid(uid); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6978 | } |
| 6979 | |
| 6980 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6981 | public int checkCarrierPrivilegesForPackage(int subId, String pkgName) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 6982 | enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage"); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6983 | if (TextUtils.isEmpty(pkgName)) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 6984 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6985 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6986 | Phone phone = getPhone(subId); |
| 6987 | if (phone == null) { |
| 6988 | loge("checkCarrierPrivilegesForPackage: Invalid subId"); |
| 6989 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 6990 | } |
| 6991 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 6992 | if (cpt == null) { |
| 6993 | loge("checkCarrierPrivilegesForPackage: No CarrierPrivilegesTracker"); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 6994 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6995 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6996 | return cpt.getCarrierPrivilegeStatusForPackage(pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6997 | } |
| 6998 | |
| 6999 | @Override |
| 7000 | public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) { |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7001 | enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackageAnyPhone"); |
Rambo Wang | e7209ce | 2022-02-23 13:41:02 -0800 | [diff] [blame] | 7002 | return checkCarrierPrivilegesForPackageAnyPhoneWithPermission(pkgName); |
| 7003 | } |
| 7004 | |
| 7005 | private int checkCarrierPrivilegesForPackageAnyPhoneWithPermission(String pkgName) { |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7006 | if (TextUtils.isEmpty(pkgName)) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 7007 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7008 | } |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 7009 | int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7010 | for (int phoneId = 0; phoneId < TelephonyManager.getDefault().getPhoneCount(); phoneId++) { |
| 7011 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 7012 | if (phone == null) { |
| 7013 | continue; |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 7014 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7015 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7016 | if (cpt == null) { |
| 7017 | continue; |
| 7018 | } |
| 7019 | result = cpt.getCarrierPrivilegeStatusForPackage(pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 7020 | if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 7021 | break; |
| 7022 | } |
| 7023 | } |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 7024 | return result; |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 7025 | } |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 7026 | |
| 7027 | @Override |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 7028 | public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 7029 | enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone"); |
Rambo Wang | 8a247eb | 2022-02-08 21:11:18 +0000 | [diff] [blame] | 7030 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 7031 | if (phone == null) { |
| 7032 | return Collections.emptyList(); |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 7033 | } |
Rambo Wang | 8a247eb | 2022-02-08 21:11:18 +0000 | [diff] [blame] | 7034 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7035 | if (cpt == null) { |
| 7036 | return Collections.emptyList(); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 7037 | } |
Rambo Wang | 8a247eb | 2022-02-08 21:11:18 +0000 | [diff] [blame] | 7038 | return cpt.getCarrierPackageNamesForIntent(intent); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 7039 | } |
| 7040 | |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 7041 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7042 | public List<String> getPackagesWithCarrierPrivileges(int phoneId) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 7043 | enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges"); |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7044 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 7045 | if (phone == null) { |
| 7046 | return Collections.emptyList(); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 7047 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7048 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7049 | if (cpt == null) { |
| 7050 | return Collections.emptyList(); |
| 7051 | } |
| 7052 | return new ArrayList<>(cpt.getPackagesWithCarrierPrivileges()); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 7053 | } |
| 7054 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7055 | @Override |
| 7056 | public List<String> getPackagesWithCarrierPrivilegesForAllPhones() { |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 7057 | enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones"); |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7058 | Set<String> privilegedPackages = new ArraySet<>(); |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 7059 | final long identity = Binder.clearCallingIdentity(); |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 7060 | try { |
| 7061 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 7062 | privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i)); |
| 7063 | } |
| 7064 | } finally { |
| 7065 | Binder.restoreCallingIdentity(identity); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7066 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7067 | return new ArrayList<>(privilegedPackages); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7068 | } |
| 7069 | |
Rambo Wang | 6812ffb | 2022-03-15 16:54:17 -0700 | [diff] [blame] | 7070 | @Override |
| 7071 | public @Nullable String getCarrierServicePackageNameForLogicalSlot(int logicalSlotIndex) { |
| 7072 | enforceReadPrivilegedPermission("getCarrierServicePackageNameForLogicalSlot"); |
| 7073 | |
| 7074 | final Phone phone = PhoneFactory.getPhone(logicalSlotIndex); |
| 7075 | if (phone == null) { |
| 7076 | return null; |
| 7077 | } |
| 7078 | final CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7079 | if (cpt == null) { |
| 7080 | return null; |
| 7081 | } |
| 7082 | return cpt.getCarrierServicePackageName(); |
| 7083 | } |
| 7084 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 7085 | private String getIccId(int subId) { |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 7086 | final Phone phone = getPhone(subId); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 7087 | UiccPort port = phone == null ? null : phone.getUiccPort(); |
| 7088 | if (port == null) { |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7089 | return null; |
| 7090 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 7091 | String iccId = port.getIccId(); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7092 | if (TextUtils.isEmpty(iccId)) { |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7093 | return null; |
| 7094 | } |
| 7095 | return iccId; |
| 7096 | } |
| 7097 | |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 7098 | @Override |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 7099 | public void setCallComposerStatus(int subId, int status) { |
| 7100 | enforceModifyPermission(); |
| 7101 | |
| 7102 | final long identity = Binder.clearCallingIdentity(); |
| 7103 | try { |
| 7104 | Phone phone = getPhone(subId); |
| 7105 | if (phone != null) { |
| 7106 | Phone defaultPhone = phone.getImsPhone(); |
| 7107 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 7108 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 7109 | imsPhone.setCallComposerStatus(status); |
Shuo Qian | 284ae75 | 2020-12-22 19:10:14 -0800 | [diff] [blame] | 7110 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| 7111 | .updateImsServiceConfig(); |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 7112 | } |
| 7113 | } |
Shuo Qian | 284ae75 | 2020-12-22 19:10:14 -0800 | [diff] [blame] | 7114 | } catch (ImsException e) { |
| 7115 | throw new ServiceSpecificException(e.getCode()); |
| 7116 | } finally { |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 7117 | Binder.restoreCallingIdentity(identity); |
| 7118 | } |
| 7119 | } |
| 7120 | |
| 7121 | @Override |
| 7122 | public int getCallComposerStatus(int subId) { |
| 7123 | enforceReadPrivilegedPermission("getCallComposerStatus"); |
| 7124 | |
| 7125 | final long identity = Binder.clearCallingIdentity(); |
| 7126 | try { |
| 7127 | Phone phone = getPhone(subId); |
| 7128 | if (phone != null) { |
| 7129 | Phone defaultPhone = phone.getImsPhone(); |
| 7130 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 7131 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 7132 | return imsPhone.getCallComposerStatus(); |
| 7133 | } |
| 7134 | } |
| 7135 | } finally { |
| 7136 | Binder.restoreCallingIdentity(identity); |
| 7137 | } |
| 7138 | return TelephonyManager.CALL_COMPOSER_STATUS_OFF; |
| 7139 | } |
| 7140 | |
| 7141 | @Override |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7142 | public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag, |
| 7143 | String number) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 7144 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7145 | subId, "setLine1NumberForDisplayForSubscriber"); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7146 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7147 | final long identity = Binder.clearCallingIdentity(); |
| 7148 | try { |
| 7149 | final String iccId = getIccId(subId); |
| 7150 | final Phone phone = getPhone(subId); |
| 7151 | if (phone == null) { |
| 7152 | return false; |
| 7153 | } |
| 7154 | final String subscriberId = phone.getSubscriberId(); |
| 7155 | |
| 7156 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 7157 | Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId=" |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7158 | + subscriberId + " to " + number); |
| 7159 | } |
| 7160 | |
| 7161 | if (TextUtils.isEmpty(iccId)) { |
| 7162 | return false; |
| 7163 | } |
| 7164 | |
| 7165 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 7166 | |
| 7167 | final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 7168 | if (alphaTag == null) { |
| 7169 | editor.remove(alphaTagPrefKey); |
| 7170 | } else { |
| 7171 | editor.putString(alphaTagPrefKey, alphaTag); |
| 7172 | } |
| 7173 | |
| 7174 | // Record both the line number and IMSI for this ICCID, since we need to |
| 7175 | // track all merged IMSIs based on line number |
| 7176 | final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 7177 | final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 7178 | if (number == null) { |
| 7179 | editor.remove(numberPrefKey); |
| 7180 | editor.remove(subscriberPrefKey); |
| 7181 | } else { |
| 7182 | editor.putString(numberPrefKey, number); |
| 7183 | editor.putString(subscriberPrefKey, subscriberId); |
| 7184 | } |
| 7185 | |
| 7186 | editor.commit(); |
| 7187 | return true; |
| 7188 | } finally { |
| 7189 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 7190 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7191 | } |
| 7192 | |
| 7193 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7194 | public String getLine1NumberForDisplay(int subId, String callingPackage, |
| 7195 | String callingFeatureId) { |
Makoto Onuki | fee6934 | 2015-06-29 14:44:50 -0700 | [diff] [blame] | 7196 | // This is open to apps with WRITE_SMS. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7197 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7198 | mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) { |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 7199 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission"); |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 7200 | return null; |
| 7201 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7202 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7203 | final long identity = Binder.clearCallingIdentity(); |
| 7204 | try { |
| 7205 | String iccId = getIccId(subId); |
| 7206 | if (iccId != null) { |
| 7207 | String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 7208 | if (DBG_MERGE) { |
| 7209 | log("getLine1NumberForDisplay returning " |
| 7210 | + mTelephonySharedPreferences.getString(numberPrefKey, null)); |
| 7211 | } |
| 7212 | return mTelephonySharedPreferences.getString(numberPrefKey, null); |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 7213 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7214 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null"); |
| 7215 | return null; |
| 7216 | } finally { |
| 7217 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7218 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7219 | } |
| 7220 | |
| 7221 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7222 | public String getLine1AlphaTagForDisplay(int subId, String callingPackage, |
| 7223 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7224 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7225 | mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 7226 | return null; |
| 7227 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7228 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7229 | final long identity = Binder.clearCallingIdentity(); |
| 7230 | try { |
| 7231 | String iccId = getIccId(subId); |
| 7232 | if (iccId != null) { |
| 7233 | String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 7234 | return mTelephonySharedPreferences.getString(alphaTagPrefKey, null); |
| 7235 | } |
| 7236 | return null; |
| 7237 | } finally { |
| 7238 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7239 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7240 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 7241 | |
| 7242 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7243 | public String[] getMergedSubscriberIds(int subId, String callingPackage, |
| 7244 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7245 | // This API isn't public, so no need to provide a valid subscription ID - we're not worried |
| 7246 | // about carrier-privileged callers not having access. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7247 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7248 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7249 | callingFeatureId, "getMergedSubscriberIds")) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7250 | return null; |
| 7251 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7252 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 7253 | // Clear calling identity, when calling TelephonyManager, because callerUid must be |
| 7254 | // the process, where TelephonyManager was instantiated. |
| 7255 | // Otherwise AppOps check will fail. |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7256 | final long identity = Binder.clearCallingIdentity(); |
| 7257 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7258 | final Context context = mApp; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7259 | final TelephonyManager tele = TelephonyManager.from(context); |
| 7260 | final SubscriptionManager sub = SubscriptionManager.from(context); |
| 7261 | |
| 7262 | // Figure out what subscribers are currently active |
| 7263 | final ArraySet<String> activeSubscriberIds = new ArraySet<>(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7264 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 7265 | // Only consider subs which match the current subId |
| 7266 | // This logic can be simplified. See b/131189269 for progress. |
| 7267 | if (isActiveSubscription(subId)) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7268 | activeSubscriberIds.add(tele.getSubscriberId(subId)); |
| 7269 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7270 | |
| 7271 | // First pass, find a number override for an active subscriber |
| 7272 | String mergeNumber = null; |
| 7273 | final Map<String, ?> prefs = mTelephonySharedPreferences.getAll(); |
| 7274 | for (String key : prefs.keySet()) { |
| 7275 | if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) { |
| 7276 | final String subscriberId = (String) prefs.get(key); |
| 7277 | if (activeSubscriberIds.contains(subscriberId)) { |
| 7278 | final String iccId = key.substring( |
| 7279 | PREF_CARRIERS_SUBSCRIBER_PREFIX.length()); |
| 7280 | final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 7281 | mergeNumber = (String) prefs.get(numberKey); |
| 7282 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 7283 | Rlog.d(LOG_TAG, "Found line number " + mergeNumber |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7284 | + " for active subscriber " + subscriberId); |
| 7285 | } |
| 7286 | if (!TextUtils.isEmpty(mergeNumber)) { |
| 7287 | break; |
| 7288 | } |
| 7289 | } |
| 7290 | } |
| 7291 | } |
| 7292 | |
| 7293 | // Shortcut when no active merged subscribers |
| 7294 | if (TextUtils.isEmpty(mergeNumber)) { |
| 7295 | return null; |
| 7296 | } |
| 7297 | |
| 7298 | // Second pass, find all subscribers under that line override |
| 7299 | final ArraySet<String> result = new ArraySet<>(); |
| 7300 | for (String key : prefs.keySet()) { |
| 7301 | if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) { |
| 7302 | final String number = (String) prefs.get(key); |
| 7303 | if (mergeNumber.equals(number)) { |
| 7304 | final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length()); |
| 7305 | final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 7306 | final String subscriberId = (String) prefs.get(subscriberKey); |
| 7307 | if (!TextUtils.isEmpty(subscriberId)) { |
| 7308 | result.add(subscriberId); |
| 7309 | } |
| 7310 | } |
| 7311 | } |
| 7312 | } |
| 7313 | |
| 7314 | final String[] resultArray = result.toArray(new String[result.size()]); |
| 7315 | Arrays.sort(resultArray); |
| 7316 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 7317 | Rlog.d(LOG_TAG, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7318 | "Found subscribers " + Arrays.toString(resultArray) + " after merge"); |
| 7319 | } |
| 7320 | return resultArray; |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7321 | } finally { |
| 7322 | Binder.restoreCallingIdentity(identity); |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7323 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7324 | } |
| 7325 | |
| 7326 | @Override |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 7327 | public String[] getMergedImsisFromGroup(int subId, String callingPackage) { |
| 7328 | enforceReadPrivilegedPermission("getMergedImsisFromGroup"); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7329 | |
| 7330 | final long identity = Binder.clearCallingIdentity(); |
| 7331 | try { |
| 7332 | final TelephonyManager telephonyManager = mApp.getSystemService( |
| 7333 | TelephonyManager.class); |
| 7334 | String subscriberId = telephonyManager.getSubscriberId(subId); |
| 7335 | if (subscriberId == null) { |
| 7336 | if (DBG) { |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 7337 | log("getMergedImsisFromGroup can't find subscriberId for subId " |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7338 | + subId); |
| 7339 | } |
| 7340 | return null; |
| 7341 | } |
| 7342 | |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 7343 | ParcelUuid groupUuid; |
| 7344 | if (PhoneFactory.isSubscriptionManagerServiceEnabled()) { |
| 7345 | final SubscriptionInfo info = SubscriptionManagerService.getInstance() |
| 7346 | .getSubscriptionInfo(subId); |
| 7347 | groupUuid = info.getGroupUuid(); |
| 7348 | } else { |
| 7349 | final SubscriptionInfo info = mSubscriptionController |
| 7350 | .getSubscriptionInfo(subId); |
| 7351 | groupUuid = info.getGroupUuid(); |
| 7352 | } |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7353 | // If it doesn't belong to any group, return just subscriberId of itself. |
| 7354 | if (groupUuid == null) { |
| 7355 | return new String[]{subscriberId}; |
| 7356 | } |
| 7357 | |
| 7358 | // Get all subscriberIds from the group. |
| 7359 | final List<String> mergedSubscriberIds = new ArrayList<>(); |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 7360 | List<SubscriptionInfo> groupInfos; |
| 7361 | if (PhoneFactory.isSubscriptionManagerServiceEnabled()) { |
| 7362 | groupInfos = SubscriptionManagerService.getInstance() |
| 7363 | .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(), |
| 7364 | mApp.getAttributionTag()); |
| 7365 | } else { |
| 7366 | groupInfos = mSubscriptionController |
| 7367 | .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(), |
| 7368 | mApp.getAttributionTag()); |
| 7369 | } |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7370 | for (SubscriptionInfo subInfo : groupInfos) { |
| 7371 | subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId()); |
| 7372 | if (subscriberId != null) { |
| 7373 | mergedSubscriberIds.add(subscriberId); |
| 7374 | } |
| 7375 | } |
| 7376 | |
| 7377 | return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]); |
| 7378 | } finally { |
| 7379 | Binder.restoreCallingIdentity(identity); |
| 7380 | |
| 7381 | } |
| 7382 | } |
| 7383 | |
| 7384 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7385 | public boolean setOperatorBrandOverride(int subId, String brand) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 7386 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7387 | subId, "setOperatorBrandOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7388 | |
| 7389 | final long identity = Binder.clearCallingIdentity(); |
| 7390 | try { |
| 7391 | final Phone phone = getPhone(subId); |
| 7392 | return phone == null ? false : phone.setOperatorBrandOverride(brand); |
| 7393 | } finally { |
| 7394 | Binder.restoreCallingIdentity(identity); |
| 7395 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 7396 | } |
Steven Liu | 4bf01bc | 2014-07-17 11:05:29 -0500 | [diff] [blame] | 7397 | |
| 7398 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7399 | public boolean setRoamingOverride(int subId, List<String> gsmRoamingList, |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 7400 | List<String> gsmNonRoamingList, List<String> cdmaRoamingList, |
| 7401 | List<String> cdmaNonRoamingList) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 7402 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 7403 | mApp, subId, "setRoamingOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7404 | |
| 7405 | final long identity = Binder.clearCallingIdentity(); |
| 7406 | try { |
| 7407 | final Phone phone = getPhone(subId); |
| 7408 | if (phone == null) { |
| 7409 | return false; |
| 7410 | } |
| 7411 | return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList, |
| 7412 | cdmaNonRoamingList); |
| 7413 | } finally { |
| 7414 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7415 | } |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 7416 | } |
| 7417 | |
| 7418 | @Override |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 7419 | @Deprecated |
| 7420 | public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) { |
| 7421 | enforceModifyPermission(); |
| 7422 | |
| 7423 | int returnValue = 0; |
| 7424 | try { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7425 | AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 7426 | if(result.exception == null) { |
| 7427 | if (result.result != null) { |
| 7428 | byte[] responseData = (byte[])(result.result); |
| 7429 | if(responseData.length > oemResp.length) { |
| 7430 | Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " + |
| 7431 | responseData.length + "bytes. Buffer Size is " + |
| 7432 | oemResp.length + "bytes."); |
| 7433 | } |
| 7434 | System.arraycopy(responseData, 0, oemResp, 0, responseData.length); |
| 7435 | returnValue = responseData.length; |
| 7436 | } |
| 7437 | } else { |
| 7438 | CommandException ex = (CommandException) result.exception; |
| 7439 | returnValue = ex.getCommandError().ordinal(); |
| 7440 | if(returnValue > 0) returnValue *= -1; |
| 7441 | } |
| 7442 | } catch (RuntimeException e) { |
| 7443 | Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception"); |
| 7444 | returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal()); |
| 7445 | if(returnValue > 0) returnValue *= -1; |
| 7446 | } |
| 7447 | |
| 7448 | return returnValue; |
| 7449 | } |
| 7450 | |
| 7451 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 7452 | public int getRadioAccessFamily(int phoneId, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7453 | Phone phone = PhoneFactory.getPhone(phoneId); |
Shuo Qian | dee5340 | 2020-05-29 14:08:15 -0700 | [diff] [blame] | 7454 | try { |
| 7455 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 7456 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Shuo Qian | dee5340 | 2020-05-29 14:08:15 -0700 | [diff] [blame] | 7457 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 7458 | } catch (SecurityException e) { |
| 7459 | EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission"); |
| 7460 | throw e; |
| 7461 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7462 | int raf = RadioAccessFamily.RAF_UNKNOWN; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7463 | if (phone == null) { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7464 | return raf; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7465 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7466 | final long identity = Binder.clearCallingIdentity(); |
| 7467 | try { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7468 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 7469 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7470 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 7471 | raf = ProxyController.getInstance().getRadioAccessFamily(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7472 | } finally { |
| 7473 | Binder.restoreCallingIdentity(identity); |
| 7474 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7475 | return raf; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 7476 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7477 | |
| 7478 | @Override |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7479 | public void uploadCallComposerPicture(int subscriptionId, String callingPackage, |
Hall Liu | e31bac6 | 2020-12-23 19:16:10 -0800 | [diff] [blame] | 7480 | String contentType, ParcelFileDescriptor fd, ResultReceiver callback) { |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7481 | try { |
| 7482 | if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0), |
| 7483 | Binder.getCallingUid())) { |
Tyler Gunn | b87925a | 2021-06-10 14:54:27 -0700 | [diff] [blame] | 7484 | throw new SecurityException("Invalid package:" + callingPackage); |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7485 | } |
| 7486 | } catch (PackageManager.NameNotFoundException e) { |
Tyler Gunn | b87925a | 2021-06-10 14:54:27 -0700 | [diff] [blame] | 7487 | throw new SecurityException("Invalid package:" + callingPackage); |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7488 | } |
| 7489 | RoleManager rm = mApp.getSystemService(RoleManager.class); |
| 7490 | List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER); |
| 7491 | if (!dialerRoleHolders.contains(callingPackage)) { |
| 7492 | throw new SecurityException("App must be the dialer role holder to" |
| 7493 | + " upload a call composer pic"); |
| 7494 | } |
| 7495 | |
| 7496 | Executors.newSingleThreadExecutor().execute(() -> { |
| 7497 | ByteArrayOutputStream output = new ByteArrayOutputStream( |
| 7498 | (int) TelephonyManager.getMaximumCallComposerPictureSize()); |
| 7499 | InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd); |
| 7500 | boolean readUntilEnd = false; |
| 7501 | int totalBytesRead = 0; |
| 7502 | byte[] buffer = new byte[16 * 1024]; |
| 7503 | while (true) { |
| 7504 | int numRead; |
| 7505 | try { |
| 7506 | numRead = input.read(buffer); |
| 7507 | } catch (IOException e) { |
| 7508 | try { |
| 7509 | fd.checkError(); |
| 7510 | callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED, |
| 7511 | null); |
| 7512 | } catch (IOException e1) { |
| 7513 | // This means that the other side closed explicitly with an error. If this |
| 7514 | // happens, log and ignore. |
| 7515 | loge("Remote end of call composer picture pipe closed: " + e1); |
| 7516 | } |
| 7517 | break; |
| 7518 | } |
| 7519 | if (numRead == -1) { |
| 7520 | readUntilEnd = true; |
| 7521 | break; |
| 7522 | } |
| 7523 | totalBytesRead += numRead; |
| 7524 | if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) { |
| 7525 | loge("Too many bytes read for call composer picture: " + totalBytesRead); |
| 7526 | try { |
| 7527 | input.close(); |
| 7528 | } catch (IOException e) { |
| 7529 | // ignore |
| 7530 | } |
| 7531 | break; |
| 7532 | } |
| 7533 | output.write(buffer, 0, numRead); |
| 7534 | } |
| 7535 | // Generally, the remote end will close the file descriptors. The only case where we |
| 7536 | // close is above, where the picture size is too big. |
| 7537 | |
| 7538 | try { |
| 7539 | fd.checkError(); |
| 7540 | } catch (IOException e) { |
| 7541 | loge("Remote end for call composer closed with an error: " + e); |
| 7542 | return; |
| 7543 | } |
| 7544 | |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 7545 | if (!readUntilEnd) { |
| 7546 | loge("Did not finish reading entire image; aborting"); |
| 7547 | return; |
| 7548 | } |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7549 | |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 7550 | ImageData imageData = new ImageData(output.toByteArray(), contentType, null); |
| 7551 | CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer( |
| 7552 | new CallComposerPictureTransfer.Factory() {}, |
| 7553 | imageData, |
| 7554 | (result) -> { |
| 7555 | if (result.first != null) { |
| 7556 | ParcelUuid parcelUuid = new ParcelUuid(result.first); |
| 7557 | Bundle outputResult = new Bundle(); |
| 7558 | outputResult.putParcelable( |
| 7559 | TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid); |
| 7560 | callback.send(TelephonyManager.CallComposerException.SUCCESS, |
| 7561 | outputResult); |
| 7562 | } else { |
| 7563 | callback.send(result.second, null); |
| 7564 | } |
| 7565 | } |
| 7566 | ); |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7567 | }); |
| 7568 | } |
| 7569 | |
| 7570 | @Override |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7571 | public void enableVideoCalling(boolean enable) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7572 | final Phone defaultPhone = getDefaultPhone(); |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7573 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7574 | |
| 7575 | final long identity = Binder.clearCallingIdentity(); |
| 7576 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7577 | ImsManager.getInstance(defaultPhone.getContext(), |
| 7578 | defaultPhone.getPhoneId()).setVtSetting(enable); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7579 | } finally { |
| 7580 | Binder.restoreCallingIdentity(identity); |
| 7581 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7582 | } |
| 7583 | |
| 7584 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7585 | public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7586 | final Phone defaultPhone = getDefaultPhone(); |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7587 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 7588 | callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 7589 | return false; |
| 7590 | } |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 7591 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7592 | final long identity = Binder.clearCallingIdentity(); |
| 7593 | try { |
| 7594 | // Check the user preference and the system-level IMS setting. Even if the user has |
| 7595 | // enabled video calling, if IMS is disabled we aren't able to support video calling. |
| 7596 | // In the long run, we may instead need to check if there exists a connection service |
| 7597 | // which can support video calling. |
| 7598 | ImsManager imsManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7599 | ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7600 | return imsManager.isVtEnabledByPlatform() |
| 7601 | && imsManager.isEnhanced4gLteModeSettingEnabledByUser() |
| 7602 | && imsManager.isVtEnabledByUser(); |
| 7603 | } finally { |
| 7604 | Binder.restoreCallingIdentity(identity); |
| 7605 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7606 | } |
Libin.Tang@motorola.com | afe8264 | 2014-12-18 13:27:53 -0600 | [diff] [blame] | 7607 | |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7608 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7609 | public boolean canChangeDtmfToneLength(int subId, String callingPackage, |
| 7610 | String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7611 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7612 | mApp, subId, callingPackage, callingFeatureId, |
| 7613 | "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7614 | return false; |
| 7615 | } |
| 7616 | |
| 7617 | final long identity = Binder.clearCallingIdentity(); |
| 7618 | try { |
| 7619 | CarrierConfigManager configManager = |
| 7620 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7621 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7622 | .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL); |
| 7623 | } finally { |
| 7624 | Binder.restoreCallingIdentity(identity); |
| 7625 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7626 | } |
| 7627 | |
| 7628 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7629 | public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7630 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7631 | mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7632 | return false; |
| 7633 | } |
| 7634 | |
| 7635 | final long identity = Binder.clearCallingIdentity(); |
| 7636 | try { |
| 7637 | CarrierConfigManager configManager = |
| 7638 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7639 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7640 | .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL); |
| 7641 | } finally { |
| 7642 | Binder.restoreCallingIdentity(identity); |
| 7643 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7644 | } |
| 7645 | |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7646 | @Override |
| 7647 | public boolean isTtyModeSupported() { |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 7648 | TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class); |
Wooki Wu | 1f82f7a | 2016-02-15 15:59:58 +0800 | [diff] [blame] | 7649 | return telecomManager.isTtySupported(); |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7650 | } |
| 7651 | |
| 7652 | @Override |
| 7653 | public boolean isHearingAidCompatibilitySupported() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7654 | final long identity = Binder.clearCallingIdentity(); |
| 7655 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7656 | return mApp.getResources().getBoolean(R.bool.hac_enabled); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7657 | } finally { |
| 7658 | Binder.restoreCallingIdentity(identity); |
| 7659 | } |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7660 | } |
| 7661 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 7662 | /** |
| 7663 | * Determines whether the device currently supports RTT (Real-time text). Based both on carrier |
| 7664 | * support for the feature and device firmware support. |
| 7665 | * |
| 7666 | * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise. |
| 7667 | */ |
| 7668 | @Override |
| 7669 | public boolean isRttSupported(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7670 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7671 | final Phone phone = getPhone(subscriptionId); |
| 7672 | if (phone == null) { |
| 7673 | loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId); |
| 7674 | return false; |
| 7675 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7676 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7677 | boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7678 | CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL); |
| 7679 | boolean isDeviceSupported = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7680 | phone.getContext().getResources().getBoolean(R.bool.config_support_rtt); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7681 | return isCarrierSupported && isDeviceSupported; |
| 7682 | } finally { |
| 7683 | Binder.restoreCallingIdentity(identity); |
| 7684 | } |
Hall Liu | 9818758 | 2018-01-22 19:15:32 -0800 | [diff] [blame] | 7685 | } |
| 7686 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 7687 | /** |
Hall Liu | f2daa02 | 2019-07-23 18:39:00 -0700 | [diff] [blame] | 7688 | * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set |
| 7689 | * RTT setting, will return true if the device and carrier both support RTT. |
| 7690 | * 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] | 7691 | */ |
| 7692 | public boolean isRttEnabled(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7693 | final long identity = Binder.clearCallingIdentity(); |
| 7694 | try { |
Hall Liu | 5bab75c | 2019-12-11 23:58:20 +0000 | [diff] [blame] | 7695 | boolean isRttSupported = isRttSupported(subscriptionId); |
| 7696 | boolean isUserRttSettingOn = Settings.Secure.getInt( |
| 7697 | mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0; |
| 7698 | boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId) |
| 7699 | .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL); |
| 7700 | return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7701 | } finally { |
| 7702 | Binder.restoreCallingIdentity(identity); |
| 7703 | } |
Hall Liu | 3ad5f01 | 2018-04-06 16:23:39 -0700 | [diff] [blame] | 7704 | } |
| 7705 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7706 | @Deprecated |
| 7707 | @Override |
| 7708 | public String getDeviceId(String callingPackage) { |
| 7709 | return getDeviceIdWithFeature(callingPackage, null); |
| 7710 | } |
| 7711 | |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7712 | /** |
| 7713 | * Returns the unique device ID of phone, for example, the IMEI for |
| 7714 | * GSM and the MEID for CDMA phones. Return null if device ID is not available. |
| 7715 | * |
| 7716 | * <p>Requires Permission: |
| 7717 | * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} |
| 7718 | */ |
| 7719 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7720 | public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) { |
Shuo Qian | 13d8915 | 2021-05-10 23:58:11 -0700 | [diff] [blame] | 7721 | try { |
| 7722 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 7723 | } catch (SecurityException se) { |
| 7724 | EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid()); |
| 7725 | throw new SecurityException("Package " + callingPackage + " does not belong to " |
| 7726 | + Binder.getCallingUid()); |
| 7727 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7728 | final Phone phone = PhoneFactory.getPhone(0); |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7729 | if (phone == null) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7730 | return null; |
| 7731 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7732 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 7733 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7734 | callingPackage, callingFeatureId, "getDeviceId")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7735 | return null; |
| 7736 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7737 | |
| 7738 | final long identity = Binder.clearCallingIdentity(); |
| 7739 | try { |
| 7740 | return phone.getDeviceId(); |
| 7741 | } finally { |
| 7742 | Binder.restoreCallingIdentity(identity); |
| 7743 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7744 | } |
| 7745 | |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 7746 | /** |
| 7747 | * {@hide} |
| 7748 | * Returns the IMS Registration Status on a particular subid |
| 7749 | * |
| 7750 | * @param subId |
| 7751 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7752 | public boolean isImsRegistered(int subId) { |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 7753 | Phone phone = getPhone(subId); |
| 7754 | if (phone != null) { |
| 7755 | return phone.isImsRegistered(); |
| 7756 | } else { |
| 7757 | return false; |
| 7758 | } |
| 7759 | } |
| 7760 | |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 7761 | @Override |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7762 | public int getSubIdForPhoneAccountHandle( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7763 | PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) { |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7764 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(), |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7765 | callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) { |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7766 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 7767 | } |
| 7768 | final long identity = Binder.clearCallingIdentity(); |
| 7769 | try { |
| 7770 | return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle); |
| 7771 | } finally { |
| 7772 | Binder.restoreCallingIdentity(identity); |
| 7773 | } |
| 7774 | } |
| 7775 | |
| 7776 | @Override |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 7777 | public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) { |
Alireza Forouzan | 4ac4f98 | 2021-03-16 22:18:52 -0700 | [diff] [blame] | 7778 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 7779 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Alireza Forouzan | 4ac4f98 | 2021-03-16 22:18:52 -0700 | [diff] [blame] | 7780 | mApp, |
| 7781 | subscriptionId, |
| 7782 | "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: " + subscriptionId); |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 7783 | final long identity = Binder.clearCallingIdentity(); |
| 7784 | try { |
| 7785 | Phone phone = getPhone(subscriptionId); |
| 7786 | if (phone == null) { |
| 7787 | return null; |
| 7788 | } |
| 7789 | return PhoneUtils.makePstnPhoneAccountHandle(phone); |
| 7790 | } finally { |
| 7791 | Binder.restoreCallingIdentity(identity); |
| 7792 | } |
| 7793 | } |
| 7794 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7795 | /** |
| 7796 | * @return the VoWiFi calling availability. |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 7797 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7798 | public boolean isWifiCallingAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7799 | final long identity = Binder.clearCallingIdentity(); |
| 7800 | try { |
| 7801 | Phone phone = getPhone(subId); |
| 7802 | if (phone != null) { |
| 7803 | return phone.isWifiCallingEnabled(); |
| 7804 | } else { |
| 7805 | return false; |
| 7806 | } |
| 7807 | } finally { |
| 7808 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7809 | } |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 7810 | } |
| 7811 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7812 | /** |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7813 | * @return the VT calling availability. |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 7814 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7815 | public boolean isVideoTelephonyAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7816 | final long identity = Binder.clearCallingIdentity(); |
| 7817 | try { |
| 7818 | Phone phone = getPhone(subId); |
| 7819 | if (phone != null) { |
| 7820 | return phone.isVideoEnabled(); |
| 7821 | } else { |
| 7822 | return false; |
| 7823 | } |
| 7824 | } finally { |
| 7825 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7826 | } |
| 7827 | } |
| 7828 | |
| 7829 | /** |
| 7830 | * @return the IMS registration technology for the MMTEL feature. Valid return values are |
| 7831 | * defined in {@link ImsRegistrationImplBase}. |
| 7832 | */ |
| 7833 | public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7834 | final long identity = Binder.clearCallingIdentity(); |
| 7835 | try { |
| 7836 | Phone phone = getPhone(subId); |
| 7837 | if (phone != null) { |
| 7838 | return phone.getImsRegistrationTech(); |
| 7839 | } else { |
| 7840 | return ImsRegistrationImplBase.REGISTRATION_TECH_NONE; |
| 7841 | } |
| 7842 | } finally { |
| 7843 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7844 | } |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 7845 | } |
| 7846 | |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 7847 | @Override |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 7848 | public void factoryReset(int subId, String callingPackage) { |
paulhu | 5a77360 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 7849 | enforceSettingsPermission(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 7850 | if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) { |
| 7851 | return; |
| 7852 | } |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 7853 | Phone defaultPhone = getDefaultPhone(); |
| 7854 | if (defaultPhone != null) { |
| 7855 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7856 | mApp, getDefaultPhone().getSubId(), "factoryReset"); |
| 7857 | } |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7858 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7859 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7860 | try { |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 7861 | if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction( |
| 7862 | UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7863 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 7864 | getDefaultDataEnabled(), callingPackage); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7865 | setNetworkSelectionModeAutomatic(subId); |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 7866 | Phone phone = getPhone(subId); |
SongFerngWang | fd89b10 | 2021-05-27 22:44:54 +0800 | [diff] [blame] | 7867 | cleanUpAllowedNetworkTypes(phone, subId); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7868 | setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId)); |
Jordan Liu | 857e73a | 2021-03-05 16:24:04 -0800 | [diff] [blame] | 7869 | getPhone(subId).resetCarrierKeysForImsiEncryption(); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7870 | } |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 7871 | // There has been issues when Sms raw table somehow stores orphan |
| 7872 | // fragments. They lead to garbled message when new fragments come |
| 7873 | // in and combined with those stale ones. In case this happens again, |
| 7874 | // user can reset all network settings which will clean up this table. |
| 7875 | cleanUpSmsRawTable(getDefaultPhone().getContext()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 7876 | // Clean up IMS settings as well here. |
| 7877 | int slotId = getSlotIndex(subId); |
| 7878 | if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 7879 | ImsManager.getInstance(mApp, slotId).factoryReset(); |
| 7880 | } |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 7881 | |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 7882 | if (defaultPhone == null) { |
| 7883 | return; |
| 7884 | } |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 7885 | // Erase modem config if erase modem on network setting is enabled. |
| 7886 | String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY, |
| 7887 | RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED); |
| 7888 | if (configValue != null && Boolean.parseBoolean(configValue)) { |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 7889 | sendEraseModemConfig(defaultPhone); |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 7890 | } |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 7891 | |
| 7892 | sendEraseDataInSharedPreferences(defaultPhone); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7893 | } finally { |
| 7894 | Binder.restoreCallingIdentity(identity); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 7895 | } |
| 7896 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7897 | |
SongFerngWang | fd89b10 | 2021-05-27 22:44:54 +0800 | [diff] [blame] | 7898 | @VisibleForTesting |
| 7899 | void cleanUpAllowedNetworkTypes(Phone phone, int subId) { |
| 7900 | if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) { |
| 7901 | return; |
| 7902 | } |
| 7903 | long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType( |
| 7904 | RILConstants.PREFERRED_NETWORK_MODE); |
| 7905 | SubscriptionManager.setSubscriptionProperty(subId, |
| 7906 | SubscriptionManager.ALLOWED_NETWORK_TYPES, |
| 7907 | "user=" + defaultNetworkType); |
| 7908 | phone.loadAllowedNetworksFromSubscriptionDatabase(); |
| 7909 | phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER, |
| 7910 | defaultNetworkType, null); |
| 7911 | } |
| 7912 | |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 7913 | private void cleanUpSmsRawTable(Context context) { |
| 7914 | ContentResolver resolver = context.getContentResolver(); |
| 7915 | Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete"); |
| 7916 | resolver.delete(uri, null, null); |
| 7917 | } |
| 7918 | |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7919 | @Override |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7920 | public String getSimLocaleForSubscriber(int subId) { |
| 7921 | enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId); |
| 7922 | final Phone phone = getPhone(subId); |
| 7923 | if (phone == null) { |
| 7924 | log("getSimLocaleForSubscriber, invalid subId"); |
chen xu | 2bb91e4 | 2019-01-24 14:35:54 -0800 | [diff] [blame] | 7925 | return null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7926 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7927 | final long identity = Binder.clearCallingIdentity(); |
| 7928 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 7929 | SubscriptionInfo info; |
| 7930 | if (PhoneFactory.isSubscriptionManagerServiceEnabled()) { |
| 7931 | info = SubscriptionManagerService.getInstance().getActiveSubscriptionInfo(subId, |
| 7932 | phone.getContext().getOpPackageName(), |
| 7933 | phone.getContext().getAttributionTag()); |
| 7934 | if (info == null) { |
| 7935 | log("getSimLocaleForSubscriber, inactive subId: " + subId); |
| 7936 | return null; |
| 7937 | } |
| 7938 | } else { |
| 7939 | info = mSubscriptionController.getActiveSubscriptionInfo(subId, |
| 7940 | phone.getContext().getOpPackageName(), |
| 7941 | phone.getContext().getAttributionTag()); |
| 7942 | if (info == null) { |
| 7943 | log("getSimLocaleForSubscriber, inactive subId: " + subId); |
| 7944 | return null; |
| 7945 | } |
chen xu | 6291c47 | 2019-02-04 12:55:53 -0800 | [diff] [blame] | 7946 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7947 | // Try and fetch the locale from the carrier properties or from the SIM language |
| 7948 | // preferences (EF-PL and EF-LI)... |
| 7949 | final int mcc = info.getMcc(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7950 | String simLanguage = null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7951 | final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs(); |
| 7952 | if (localeFromDefaultSim != null) { |
| 7953 | if (!localeFromDefaultSim.getCountry().isEmpty()) { |
| 7954 | if (DBG) log("Using locale from subId: " + subId + " locale: " |
| 7955 | + localeFromDefaultSim); |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 7956 | return matchLocaleFromSupportedLocaleList(phone, localeFromDefaultSim); |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7957 | } else { |
| 7958 | simLanguage = localeFromDefaultSim.getLanguage(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7959 | } |
| 7960 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7961 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7962 | // The SIM language preferences only store a language (e.g. fr = French), not an |
| 7963 | // exact locale (e.g. fr_FR = French/France). So, if the locale returned from |
| 7964 | // the SIM and carrier preferences does not include a country we add the country |
| 7965 | // determined from the SIM MCC to provide an exact locale. |
zoey chen | c730df8 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 7966 | final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7967 | if (mccLocale != null) { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7968 | if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale); |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 7969 | return matchLocaleFromSupportedLocaleList(phone, mccLocale); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7970 | } |
| 7971 | |
| 7972 | if (DBG) log("No locale found - returning null"); |
| 7973 | return null; |
| 7974 | } finally { |
| 7975 | Binder.restoreCallingIdentity(identity); |
| 7976 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7977 | } |
| 7978 | |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 7979 | @VisibleForTesting |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 7980 | String matchLocaleFromSupportedLocaleList(Phone phone, @NonNull Locale inputLocale) { |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 7981 | String[] supportedLocale = com.android.internal.app.LocalePicker.getSupportedLocales( |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 7982 | phone.getContext()); |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 7983 | for (String localeTag : supportedLocale) { |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 7984 | if (LocaleList.matchesLanguageAndScript(inputLocale, Locale.forLanguageTag(localeTag)) |
| 7985 | && TextUtils.equals(inputLocale.getCountry(), |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 7986 | Locale.forLanguageTag(localeTag).getCountry())) { |
| 7987 | return localeTag; |
| 7988 | } |
| 7989 | } |
| 7990 | return inputLocale.toLanguageTag(); |
| 7991 | } |
| 7992 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7993 | /** |
| 7994 | * NOTE: this method assumes permission checks are done and caller identity has been cleared. |
| 7995 | */ |
| 7996 | private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 7997 | if (PhoneFactory.isSubscriptionManagerServiceEnabled()) { |
| 7998 | return SubscriptionManagerService.getInstance().getActiveSubscriptionInfoList( |
| 7999 | mApp.getOpPackageName(), mApp.getAttributionTag()); |
| 8000 | } |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8001 | return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(), |
Philip P. Moltmann | 8d34f0c | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 8002 | mApp.getAttributionTag()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 8003 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 8004 | |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8005 | private ActivityStatsTechSpecificInfo[] mLastModemActivitySpecificInfo = null; |
| 8006 | private ModemActivityInfo mLastModemActivityInfo = null; |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 8007 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 8008 | /** |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 8009 | * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object |
| 8010 | * representing the state of the modem. |
| 8011 | * |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 8012 | * NOTE: The underlying implementation clears the modem state, so there should only ever be one |
| 8013 | * caller to it. Everyone should call this class to get cumulative data. |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 8014 | * @hide |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 8015 | */ |
| 8016 | @Override |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 8017 | public void requestModemActivityInfo(ResultReceiver result) { |
| 8018 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8019 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8020 | |
| 8021 | final long identity = Binder.clearCallingIdentity(); |
| 8022 | try { |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 8023 | sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8024 | } finally { |
| 8025 | Binder.restoreCallingIdentity(identity); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 8026 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 8027 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8028 | |
Gary Jian | 76280a4 | 2022-12-07 16:18:33 +0800 | [diff] [blame] | 8029 | // Checks that ModemActivityInfo is valid. Sleep time and Idle time should be |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 8030 | // less than total activity duration. |
| 8031 | private boolean isModemActivityInfoValid(ModemActivityInfo info) { |
| 8032 | if (info == null) { |
| 8033 | return false; |
| 8034 | } |
| 8035 | int activityDurationMs = |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 8036 | (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis()); |
Gary Jian | 76280a4 | 2022-12-07 16:18:33 +0800 | [diff] [blame] | 8037 | activityDurationMs += MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS; |
| 8038 | |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 8039 | int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum(); |
| 8040 | |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 8041 | return (info.isValid() |
| 8042 | && (info.getSleepTimeMillis() <= activityDurationMs) |
Gary Jian | 76280a4 | 2022-12-07 16:18:33 +0800 | [diff] [blame] | 8043 | && (info.getIdleTimeMillis() <= activityDurationMs)); |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 8044 | } |
| 8045 | |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8046 | private void updateLastModemActivityInfo(ModemActivityInfo info, int rat, int freq) { |
| 8047 | int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()]; |
| 8048 | int[] txTimeMs = info.getTransmitTimeMillis(rat, freq); |
| 8049 | int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat, freq); |
| 8050 | |
| 8051 | for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) { |
| 8052 | mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl]; |
| 8053 | } |
| 8054 | |
| 8055 | mLastModemActivityInfo.setTransmitTimeMillis(rat, freq, mergedTxTimeMs); |
| 8056 | mLastModemActivityInfo.setReceiveTimeMillis( |
| 8057 | rat, |
| 8058 | freq, |
| 8059 | info.getReceiveTimeMillis(rat, freq) |
| 8060 | + mLastModemActivityInfo.getReceiveTimeMillis(rat, freq)); |
| 8061 | } |
| 8062 | |
| 8063 | private void updateLastModemActivityInfo(ModemActivityInfo info, int rat) { |
| 8064 | int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()]; |
| 8065 | int[] txTimeMs = info.getTransmitTimeMillis(rat); |
| 8066 | int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat); |
| 8067 | |
| 8068 | for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) { |
| 8069 | mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl]; |
| 8070 | } |
| 8071 | mLastModemActivityInfo.setTransmitTimeMillis(rat, mergedTxTimeMs); |
| 8072 | mLastModemActivityInfo.setReceiveTimeMillis( |
| 8073 | rat, |
| 8074 | info.getReceiveTimeMillis(rat) + mLastModemActivityInfo.getReceiveTimeMillis(rat)); |
| 8075 | } |
| 8076 | |
| 8077 | /** |
| 8078 | * Merge this ModemActivityInfo with mLastModemActivitySpecificInfo |
| 8079 | * @param info recent ModemActivityInfo |
| 8080 | */ |
| 8081 | private void mergeModemActivityInfo(ModemActivityInfo info) { |
| 8082 | List<ActivityStatsTechSpecificInfo> merged = new ArrayList<>(); |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 8083 | ActivityStatsTechSpecificInfo deltaSpecificInfo; |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8084 | boolean matched; |
| 8085 | for (int i = 0; i < info.getSpecificInfoLength(); i++) { |
| 8086 | matched = false; |
| 8087 | int rat = info.getSpecificInfoRat(i); |
| 8088 | int freq = info.getSpecificInfoFrequencyRange(i); |
| 8089 | //Check each ActivityStatsTechSpecificInfo in this ModemActivityInfo for new rat returns |
| 8090 | //Add a new ActivityStatsTechSpecificInfo if is a new rat, and merge with the original |
| 8091 | //if it already exists |
| 8092 | for (int j = 0; j < mLastModemActivitySpecificInfo.length; j++) { |
| 8093 | if (rat == mLastModemActivityInfo.getSpecificInfoRat(j) && !matched) { |
| 8094 | //Merged based on frequency range (MMWAVE vs SUB6) for 5G |
| 8095 | if (rat == AccessNetworkConstants.AccessNetworkType.NGRAN) { |
| 8096 | if (freq == mLastModemActivityInfo.getSpecificInfoFrequencyRange(j)) { |
| 8097 | updateLastModemActivityInfo(info, rat, freq); |
| 8098 | matched = true; |
| 8099 | } |
| 8100 | } else { |
| 8101 | updateLastModemActivityInfo(info, rat); |
| 8102 | matched = true; |
| 8103 | } |
| 8104 | } |
| 8105 | } |
| 8106 | |
| 8107 | if (!matched) { |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 8108 | deltaSpecificInfo = |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8109 | new ActivityStatsTechSpecificInfo( |
| 8110 | rat, |
| 8111 | freq, |
| 8112 | info.getTransmitTimeMillis(rat, freq), |
| 8113 | (int) info.getReceiveTimeMillis(rat, freq)); |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 8114 | merged.addAll(Arrays.asList(deltaSpecificInfo)); |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8115 | } |
| 8116 | } |
| 8117 | merged.addAll(Arrays.asList(mLastModemActivitySpecificInfo)); |
| 8118 | mLastModemActivitySpecificInfo = |
| 8119 | new ActivityStatsTechSpecificInfo[merged.size()]; |
| 8120 | merged.toArray(mLastModemActivitySpecificInfo); |
| 8121 | |
| 8122 | mLastModemActivityInfo.setTimestamp(info.getTimestampMillis()); |
| 8123 | mLastModemActivityInfo.setSleepTimeMillis( |
| 8124 | info.getSleepTimeMillis() |
| 8125 | + mLastModemActivityInfo.getSleepTimeMillis()); |
| 8126 | mLastModemActivityInfo.setIdleTimeMillis( |
| 8127 | info.getIdleTimeMillis() |
| 8128 | + mLastModemActivityInfo.getIdleTimeMillis()); |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 8129 | |
| 8130 | mLastModemActivityInfo = |
| 8131 | new ModemActivityInfo( |
| 8132 | mLastModemActivityInfo.getTimestampMillis(), |
| 8133 | mLastModemActivityInfo.getSleepTimeMillis(), |
| 8134 | mLastModemActivityInfo.getIdleTimeMillis(), |
| 8135 | mLastModemActivitySpecificInfo); |
| 8136 | } |
| 8137 | |
| 8138 | private ActivityStatsTechSpecificInfo[] deepCopyModemActivitySpecificInfo( |
| 8139 | ActivityStatsTechSpecificInfo[] info) { |
| 8140 | int infoSize = info.length; |
| 8141 | ActivityStatsTechSpecificInfo[] ret = new ActivityStatsTechSpecificInfo[infoSize]; |
| 8142 | for (int i = 0; i < infoSize; i++) { |
| 8143 | ret[i] = new ActivityStatsTechSpecificInfo( |
| 8144 | info[i].getRat(), info[i].getFrequencyRange(), |
| 8145 | info[i].getTransmitTimeMillis(), |
| 8146 | (int) info[i].getReceiveTimeMillis()); |
| 8147 | } |
| 8148 | return ret; |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8149 | } |
| 8150 | |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8151 | /** |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8152 | * Returns the service state information on specified subscription. |
| 8153 | */ |
| 8154 | @Override |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 8155 | public ServiceState getServiceStateForSubscriber(int subId, |
| 8156 | boolean renounceFineLocationAccess, boolean renounceCoarseLocationAccess, |
| 8157 | String callingPackage, String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8158 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8159 | mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) { |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8160 | return null; |
| 8161 | } |
| 8162 | |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 8163 | boolean hasFinePermission = false; |
| 8164 | boolean hasCoarsePermission = false; |
| 8165 | if (!renounceFineLocationAccess) { |
| 8166 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 8167 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 8168 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 8169 | .setCallingPackage(callingPackage) |
| 8170 | .setCallingFeatureId(callingFeatureId) |
| 8171 | .setCallingPid(Binder.getCallingPid()) |
| 8172 | .setCallingUid(Binder.getCallingUid()) |
| 8173 | .setMethod("getServiceStateForSubscriber") |
| 8174 | .setLogAsInfo(true) |
| 8175 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 8176 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 8177 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 8178 | .build()); |
| 8179 | hasFinePermission = |
| 8180 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 8181 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 8182 | |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 8183 | if (!renounceCoarseLocationAccess) { |
| 8184 | LocationAccessPolicy.LocationPermissionResult coarseLocationResult = |
| 8185 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 8186 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 8187 | .setCallingPackage(callingPackage) |
| 8188 | .setCallingFeatureId(callingFeatureId) |
| 8189 | .setCallingPid(Binder.getCallingPid()) |
| 8190 | .setCallingUid(Binder.getCallingUid()) |
| 8191 | .setMethod("getServiceStateForSubscriber") |
| 8192 | .setLogAsInfo(true) |
| 8193 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 8194 | .setMinSdkVersionForFine(Integer.MAX_VALUE) |
| 8195 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 8196 | .build()); |
| 8197 | hasCoarsePermission = |
| 8198 | coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 8199 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 8200 | |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 8201 | final Phone phone = getPhone(subId); |
| 8202 | if (phone == null) { |
| 8203 | return null; |
| 8204 | } |
| 8205 | |
Jordan Liu | 0f2bc44 | 2020-11-18 16:47:37 -0800 | [diff] [blame] | 8206 | final long identity = Binder.clearCallingIdentity(); |
| 8207 | |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 8208 | boolean isCallingPackageDataService = phone.getDataServicePackages() |
| 8209 | .contains(callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8210 | try { |
Jordan Liu | c437b19 | 2020-08-17 10:59:12 -0700 | [diff] [blame] | 8211 | // isActiveSubId requires READ_PHONE_STATE, which we already check for above |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 8212 | if (PhoneFactory.isSubscriptionManagerServiceEnabled()) { |
| 8213 | SubscriptionInfoInternal subInfo = SubscriptionManagerService.getInstance() |
| 8214 | .getSubscriptionInfoInternal(subId); |
| 8215 | if (subInfo == null || !subInfo.isActive()) { |
| 8216 | Rlog.d(LOG_TAG, "getServiceStateForSubscriber returning null for inactive " |
| 8217 | + "subId=" + subId); |
| 8218 | return null; |
| 8219 | } |
| 8220 | } else { |
| 8221 | if (!mSubscriptionController.isActiveSubId(subId, callingPackage, |
| 8222 | callingFeatureId)) { |
| 8223 | Rlog.d(LOG_TAG, "getServiceStateForSubscriber returning null for inactive " |
| 8224 | + "subId=" + subId); |
| 8225 | return null; |
| 8226 | } |
Jordan Liu | c437b19 | 2020-08-17 10:59:12 -0700 | [diff] [blame] | 8227 | } |
| 8228 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 8229 | ServiceState ss = phone.getServiceState(); |
| 8230 | |
| 8231 | // Scrub out the location info in ServiceState depending on what level of access |
| 8232 | // the caller has. |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 8233 | if (hasFinePermission || isCallingPackageDataService) return ss; |
Malcolm Chen | 5052de6 | 2019-12-30 13:56:38 -0800 | [diff] [blame] | 8234 | if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false); |
| 8235 | return ss.createLocationInfoSanitizedCopy(true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8236 | } finally { |
| 8237 | Binder.restoreCallingIdentity(identity); |
| 8238 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8239 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8240 | |
| 8241 | /** |
| 8242 | * Returns the URI for the per-account voicemail ringtone set in Phone settings. |
| 8243 | * |
| 8244 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 8245 | * voicemail ringtone. |
| 8246 | * @return The URI for the ringtone to play when receiving a voicemail from a specific |
| 8247 | * PhoneAccount. |
| 8248 | */ |
| 8249 | @Override |
| 8250 | public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8251 | final long identity = Binder.clearCallingIdentity(); |
| 8252 | try { |
| 8253 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 8254 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8255 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8256 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8257 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8258 | return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext()); |
| 8259 | } finally { |
| 8260 | Binder.restoreCallingIdentity(identity); |
| 8261 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8262 | } |
| 8263 | |
| 8264 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8265 | * Sets the per-account voicemail ringtone. |
| 8266 | * |
| 8267 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 8268 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 8269 | * |
| 8270 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 8271 | * voicemail ringtone. |
| 8272 | * @param uri The URI for the ringtone to play when receiving a voicemail from a specific |
| 8273 | * PhoneAccount. |
| 8274 | */ |
| 8275 | @Override |
| 8276 | public void setVoicemailRingtoneUri(String callingPackage, |
| 8277 | PhoneAccountHandle phoneAccountHandle, Uri uri) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8278 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8279 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 8280 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 8281 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8282 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8283 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 8284 | "setVoicemailRingtoneUri"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8285 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8286 | |
| 8287 | final long identity = Binder.clearCallingIdentity(); |
| 8288 | try { |
| 8289 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 8290 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8291 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8292 | } |
| 8293 | VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri); |
| 8294 | } finally { |
| 8295 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8296 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8297 | } |
| 8298 | |
| 8299 | /** |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8300 | * Returns whether vibration is set for voicemail notification in Phone settings. |
| 8301 | * |
| 8302 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 8303 | * voicemail vibration setting. |
| 8304 | * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise. |
| 8305 | */ |
| 8306 | @Override |
| 8307 | public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8308 | final long identity = Binder.clearCallingIdentity(); |
| 8309 | try { |
| 8310 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 8311 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8312 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8313 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8314 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8315 | return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext()); |
| 8316 | } finally { |
| 8317 | Binder.restoreCallingIdentity(identity); |
| 8318 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8319 | } |
| 8320 | |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8321 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8322 | * Sets the per-account voicemail vibration. |
| 8323 | * |
| 8324 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 8325 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 8326 | * |
| 8327 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 8328 | * voicemail vibration setting. |
| 8329 | * @param enabled Whether to enable or disable vibration for voicemail notifications from a |
| 8330 | * specific PhoneAccount. |
| 8331 | */ |
| 8332 | @Override |
| 8333 | public void setVoicemailVibrationEnabled(String callingPackage, |
| 8334 | PhoneAccountHandle phoneAccountHandle, boolean enabled) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8335 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8336 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 8337 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 8338 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8339 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8340 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 8341 | "setVoicemailVibrationEnabled"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8342 | } |
| 8343 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8344 | final long identity = Binder.clearCallingIdentity(); |
| 8345 | try { |
| 8346 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 8347 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8348 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8349 | } |
| 8350 | VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled); |
| 8351 | } finally { |
| 8352 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8353 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8354 | } |
| 8355 | |
| 8356 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8357 | * Make sure either called from same process as self (phone) or IPC caller has read privilege. |
| 8358 | * |
| 8359 | * @throws SecurityException if the caller does not have the required permission |
| 8360 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8361 | private void enforceReadPrivilegedPermission(String message) { |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8362 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8363 | message); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8364 | } |
| 8365 | |
| 8366 | /** |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 8367 | * Make sure either called from same process as self (phone) or IPC caller has send SMS |
| 8368 | * permission. |
| 8369 | * |
| 8370 | * @throws SecurityException if the caller does not have the required permission |
| 8371 | */ |
| 8372 | private void enforceSendSmsPermission() { |
| 8373 | mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null); |
| 8374 | } |
| 8375 | |
| 8376 | /** |
Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame] | 8377 | * Make sure either called from same process as self (phone) or IPC caller has interact across |
| 8378 | * users permission. |
| 8379 | * |
| 8380 | * @throws SecurityException if the caller does not have the required permission |
| 8381 | */ |
| 8382 | private void enforceInteractAcrossUsersPermission(String message) { |
| 8383 | mApp.enforceCallingOrSelfPermission(permission.INTERACT_ACROSS_USERS, message); |
| 8384 | } |
| 8385 | |
| 8386 | /** |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 8387 | * Make sure called from the package in charge of visual voicemail. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 8388 | * |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 8389 | * @throws SecurityException if the caller is not the visual voicemail package. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 8390 | */ |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 8391 | private void enforceVisualVoicemailPackage(String callingPackage, int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8392 | final long identity = Binder.clearCallingIdentity(); |
| 8393 | try { |
| 8394 | ComponentName componentName = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8395 | RemoteVvmTaskManager.getRemotePackage(mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8396 | if (componentName == null) { |
| 8397 | throw new SecurityException( |
| 8398 | "Caller not current active visual voicemail package[null]"); |
| 8399 | } |
| 8400 | String vvmPackage = componentName.getPackageName(); |
| 8401 | if (!callingPackage.equals(vvmPackage)) { |
Hui Wang | 7f65755 | 2022-08-16 16:58:25 +0000 | [diff] [blame] | 8402 | throw new SecurityException("Caller not current active visual voicemail package"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8403 | } |
| 8404 | } finally { |
| 8405 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 8406 | } |
| 8407 | } |
| 8408 | |
| 8409 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8410 | * Return the application ID for the app type. |
| 8411 | * |
| 8412 | * @param subId the subscription ID that this request applies to. |
| 8413 | * @param appType the uicc app type. |
| 8414 | * @return Application ID for specificied app type, or null if no uicc. |
| 8415 | */ |
| 8416 | @Override |
| 8417 | public String getAidForAppType(int subId, int appType) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8418 | enforceReadPrivilegedPermission("getAidForAppType"); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8419 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8420 | |
| 8421 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8422 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8423 | if (phone == null) { |
| 8424 | return null; |
| 8425 | } |
| 8426 | String aid = null; |
| 8427 | try { |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 8428 | aid = UiccController.getInstance().getUiccPort(phone.getPhoneId()) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8429 | .getApplicationByType(appType).getAid(); |
| 8430 | } catch (Exception e) { |
| 8431 | Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e); |
| 8432 | } |
| 8433 | return aid; |
| 8434 | } finally { |
| 8435 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8436 | } |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8437 | } |
| 8438 | |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8439 | /** |
| 8440 | * Return the Electronic Serial Number. |
| 8441 | * |
| 8442 | * @param subId the subscription ID that this request applies to. |
| 8443 | * @return ESN or null if error. |
| 8444 | */ |
| 8445 | @Override |
| 8446 | public String getEsn(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8447 | enforceReadPrivilegedPermission("getEsn"); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8448 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8449 | |
| 8450 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8451 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8452 | if (phone == null) { |
| 8453 | return null; |
| 8454 | } |
| 8455 | String esn = null; |
| 8456 | try { |
| 8457 | esn = phone.getEsn(); |
| 8458 | } catch (Exception e) { |
| 8459 | Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e); |
| 8460 | } |
| 8461 | return esn; |
| 8462 | } finally { |
| 8463 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8464 | } |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8465 | } |
| 8466 | |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 8467 | /** |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8468 | * Return the Preferred Roaming List Version. |
| 8469 | * |
| 8470 | * @param subId the subscription ID that this request applies to. |
| 8471 | * @return PRLVersion or null if error. |
| 8472 | */ |
| 8473 | @Override |
| 8474 | public String getCdmaPrlVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8475 | enforceReadPrivilegedPermission("getCdmaPrlVersion"); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8476 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8477 | |
| 8478 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8479 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8480 | if (phone == null) { |
| 8481 | return null; |
| 8482 | } |
| 8483 | String cdmaPrlVersion = null; |
| 8484 | try { |
| 8485 | cdmaPrlVersion = phone.getCdmaPrlVersion(); |
| 8486 | } catch (Exception e) { |
| 8487 | Log.e(LOG_TAG, "Not getting PRLVersion", e); |
| 8488 | } |
| 8489 | return cdmaPrlVersion; |
| 8490 | } finally { |
| 8491 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8492 | } |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8493 | } |
| 8494 | |
| 8495 | /** |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 8496 | * Get snapshot of Telephony histograms |
| 8497 | * @return List of Telephony histograms |
| 8498 | * @hide |
| 8499 | */ |
| 8500 | @Override |
| 8501 | public List<TelephonyHistogram> getTelephonyHistograms() { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8502 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8503 | mApp, getDefaultSubscription(), "getTelephonyHistograms"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8504 | |
| 8505 | final long identity = Binder.clearCallingIdentity(); |
| 8506 | try { |
| 8507 | return RIL.getTelephonyRILTimingHistograms(); |
| 8508 | } finally { |
| 8509 | Binder.restoreCallingIdentity(identity); |
| 8510 | } |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 8511 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8512 | |
| 8513 | /** |
| 8514 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8515 | * Set the allowed carrier list and the excluded carrier list, indicating the priority between |
| 8516 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8517 | * Require system privileges. In the future we may add this to carrier APIs. |
| 8518 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8519 | * @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] | 8520 | */ |
| 8521 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8522 | @TelephonyManager.SetCarrierRestrictionResult |
| 8523 | public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) { |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8524 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8525 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8526 | |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8527 | if (carrierRestrictionRules == null) { |
| 8528 | throw new NullPointerException("carrier restriction cannot be null"); |
Meng Wang | 9b7c4e9 | 2017-02-17 11:41:27 -0800 | [diff] [blame] | 8529 | } |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8530 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8531 | final long identity = Binder.clearCallingIdentity(); |
| 8532 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8533 | return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8534 | workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8535 | } finally { |
| 8536 | Binder.restoreCallingIdentity(identity); |
| 8537 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8538 | } |
| 8539 | |
| 8540 | /** |
| 8541 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8542 | * Get the allowed carrier list and the excluded carrier list, including the priority between |
| 8543 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8544 | * Require system privileges. In the future we may add this to carrier APIs. |
| 8545 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8546 | * @return {@link android.telephony.CarrierRestrictionRules} |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8547 | */ |
| 8548 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8549 | public CarrierRestrictionRules getAllowedCarriers() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8550 | enforceReadPrivilegedPermission("getAllowedCarriers"); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8551 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8552 | |
| 8553 | final long identity = Binder.clearCallingIdentity(); |
| 8554 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8555 | Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource); |
| 8556 | if (response instanceof CarrierRestrictionRules) { |
| 8557 | return (CarrierRestrictionRules) response; |
| 8558 | } |
| 8559 | // Response is an Exception of some kind, |
| 8560 | // which is signalled to the user as a NULL retval |
| 8561 | return null; |
| 8562 | } catch (Exception e) { |
| 8563 | Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e); |
| 8564 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8565 | } finally { |
| 8566 | Binder.restoreCallingIdentity(identity); |
| 8567 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8568 | } |
| 8569 | |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 8570 | /** |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 8571 | * Action set from carrier signalling broadcast receivers to enable/disable radio |
| 8572 | * @param subId the subscription ID that this action applies to. |
| 8573 | * @param enabled control enable or disable radio. |
| 8574 | * {@hide} |
| 8575 | */ |
| 8576 | @Override |
| 8577 | public void carrierActionSetRadioEnabled(int subId, boolean enabled) { |
| 8578 | enforceModifyPermission(); |
| 8579 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8580 | |
| 8581 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 8582 | if (phone == null) { |
| 8583 | loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId); |
| 8584 | return; |
| 8585 | } |
| 8586 | try { |
| 8587 | phone.carrierActionSetRadioEnabled(enabled); |
| 8588 | } catch (Exception e) { |
| 8589 | Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8590 | } finally { |
| 8591 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 8592 | } |
| 8593 | } |
| 8594 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 8595 | /** |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 8596 | * Enable or disable Voice over NR (VoNR) |
| 8597 | * @param subId the subscription ID that this action applies to. |
| 8598 | * @param enabled enable or disable VoNR. |
| 8599 | * @return operation result. |
| 8600 | */ |
| 8601 | @Override |
| 8602 | public int setVoNrEnabled(int subId, boolean enabled) { |
| 8603 | enforceModifyPermission(); |
| 8604 | final Phone phone = getPhone(subId); |
| 8605 | |
| 8606 | final long identity = Binder.clearCallingIdentity(); |
| 8607 | if (phone == null) { |
| 8608 | loge("setVoNrEnabled fails with no phone object for subId: " + subId); |
| 8609 | return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE; |
| 8610 | } |
| 8611 | |
| 8612 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8613 | try { |
| 8614 | int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId, |
| 8615 | workSource); |
| 8616 | if (DBG) log("setVoNrEnabled result: " + result); |
Gary Jian | 8dd305f | 2021-10-14 16:31:35 +0800 | [diff] [blame] | 8617 | |
| 8618 | if (result == TelephonyManager.ENABLE_VONR_SUCCESS) { |
| 8619 | if (DBG) { |
| 8620 | log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled); |
| 8621 | } |
| 8622 | SubscriptionManager.setSubscriptionProperty( |
| 8623 | subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED, |
| 8624 | (enabled ? "1" : "0")); |
| 8625 | } |
| 8626 | |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 8627 | return result; |
| 8628 | } finally { |
| 8629 | Binder.restoreCallingIdentity(identity); |
| 8630 | } |
| 8631 | } |
| 8632 | |
| 8633 | /** |
| 8634 | * Is voice over NR enabled |
| 8635 | * @return true if VoNR is enabled else false |
| 8636 | */ |
| 8637 | @Override |
| 8638 | public boolean isVoNrEnabled(int subId) { |
| 8639 | enforceReadPrivilegedPermission("isVoNrEnabled"); |
| 8640 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8641 | final long identity = Binder.clearCallingIdentity(); |
| 8642 | try { |
| 8643 | boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED, |
| 8644 | null, subId, workSource); |
| 8645 | if (DBG) log("isVoNrEnabled: " + isEnabled); |
| 8646 | return isEnabled; |
| 8647 | } finally { |
| 8648 | Binder.restoreCallingIdentity(identity); |
| 8649 | } |
| 8650 | } |
| 8651 | |
| 8652 | /** |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 8653 | * Action set from carrier signalling broadcast receivers to start/stop reporting the default |
| 8654 | * network status based on which carrier apps could apply actions accordingly, |
| 8655 | * enable/disable default url handler for example. |
| 8656 | * |
| 8657 | * @param subId the subscription ID that this action applies to. |
| 8658 | * @param report control start/stop reporting the default network status. |
| 8659 | * {@hide} |
| 8660 | */ |
| 8661 | @Override |
| 8662 | public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) { |
| 8663 | enforceModifyPermission(); |
| 8664 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8665 | |
| 8666 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 8667 | if (phone == null) { |
| 8668 | loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId); |
| 8669 | return; |
| 8670 | } |
| 8671 | try { |
| 8672 | phone.carrierActionReportDefaultNetworkStatus(report); |
| 8673 | } catch (Exception e) { |
| 8674 | Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8675 | } finally { |
| 8676 | Binder.restoreCallingIdentity(identity); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 8677 | } |
| 8678 | } |
| 8679 | |
| 8680 | /** |
fionaxu | d962228 | 2017-07-17 17:51:30 -0700 | [diff] [blame] | 8681 | * Action set from carrier signalling broadcast receivers to reset all carrier actions |
| 8682 | * @param subId the subscription ID that this action applies to. |
| 8683 | * {@hide} |
| 8684 | */ |
| 8685 | @Override |
| 8686 | public void carrierActionResetAll(int subId) { |
| 8687 | enforceModifyPermission(); |
| 8688 | final Phone phone = getPhone(subId); |
| 8689 | if (phone == null) { |
| 8690 | loge("carrierAction: ResetAll fails with invalid sibId: " + subId); |
| 8691 | return; |
| 8692 | } |
| 8693 | try { |
| 8694 | phone.carrierActionResetAll(); |
| 8695 | } catch (Exception e) { |
| 8696 | Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e); |
| 8697 | } |
| 8698 | } |
| 8699 | |
| 8700 | /** |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 8701 | * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a |
| 8702 | * bug report is being generated. |
| 8703 | */ |
| 8704 | @Override |
Ta-wei Yen | 99282e0 | 2016-06-21 18:19:35 -0700 | [diff] [blame] | 8705 | protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8706 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 8707 | != PackageManager.PERMISSION_GRANTED) { |
dcashman | 22b950d | 2016-06-27 11:39:02 -0700 | [diff] [blame] | 8708 | writer.println("Permission Denial: can't dump Phone from pid=" |
| 8709 | + Binder.getCallingPid() |
| 8710 | + ", uid=" + Binder.getCallingUid() |
| 8711 | + "without permission " |
| 8712 | + android.Manifest.permission.DUMP); |
| 8713 | return; |
| 8714 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8715 | DumpsysHandler.dump(mApp, fd, writer, args); |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 8716 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 8717 | |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 8718 | @Override |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 8719 | public int handleShellCommand(@NonNull ParcelFileDescriptor in, |
| 8720 | @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err, |
| 8721 | @NonNull String[] args) { |
| 8722 | return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec( |
| 8723 | this, in.getFileDescriptor(), out.getFileDescriptor(), |
| 8724 | err.getFileDescriptor(), args); |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 8725 | } |
| 8726 | |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 8727 | /** |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8728 | * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason} |
Greg Kaiser | 17f4175 | 2020-05-05 16:47:47 +0000 | [diff] [blame] | 8729 | * @param subId Subscription index |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 8730 | * @param reason The reason the data enable change is taking place. |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8731 | * @param enabled True if enabling the data, otherwise disabling. |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 8732 | * @param callingPackage The package that changed the data enabled state. |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8733 | * @hide |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 8734 | */ |
| 8735 | @Override |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 8736 | public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 8737 | boolean enabled, String callingPackage) { |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8738 | if (reason == TelephonyManager.DATA_ENABLED_REASON_USER |
| 8739 | || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 8740 | try { |
| 8741 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 8742 | mApp, subId, "setDataEnabledForReason"); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8743 | } catch (SecurityException se) { |
| 8744 | enforceModifyPermission(); |
| 8745 | } |
| 8746 | } else { |
| 8747 | enforceModifyPermission(); |
| 8748 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8749 | |
| 8750 | final long identity = Binder.clearCallingIdentity(); |
| 8751 | try { |
| 8752 | Phone phone = getPhone(subId); |
| 8753 | if (phone != null) { |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8754 | if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 8755 | phone.carrierActionSetMeteredApnsEnabled(enabled); |
| 8756 | } else { |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 8757 | phone.getDataSettingsManager().setDataEnabled( |
| 8758 | reason, enabled, callingPackage); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8759 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8760 | } |
| 8761 | } finally { |
| 8762 | Binder.restoreCallingIdentity(identity); |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 8763 | } |
| 8764 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8765 | |
| 8766 | /** |
| 8767 | * Get Client request stats |
| 8768 | * @return List of Client Request Stats |
| 8769 | * @hide |
| 8770 | */ |
| 8771 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8772 | public List<ClientRequestStats> getClientRequestStats(String callingPackage, |
| 8773 | String callingFeatureId, int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8774 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8775 | mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) { |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8776 | return null; |
| 8777 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8778 | Phone phone = getPhone(subId); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8779 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8780 | final long identity = Binder.clearCallingIdentity(); |
| 8781 | try { |
| 8782 | if (phone != null) { |
| 8783 | return phone.getClientRequestStats(); |
| 8784 | } |
| 8785 | |
| 8786 | return null; |
| 8787 | } finally { |
| 8788 | Binder.restoreCallingIdentity(identity); |
| 8789 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8790 | } |
| 8791 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 8792 | private WorkSource getWorkSource(int uid) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8793 | String packageName = mApp.getPackageManager().getNameForUid(uid); |
Hunter Knepshield | d03383b | 2022-03-29 22:47:54 +0000 | [diff] [blame] | 8794 | if (uid == Process.ROOT_UID && packageName == null) { |
| 8795 | // Downstream WorkSource attribution inside the RIL requires both a UID and package name |
| 8796 | // to be set for wakelock tracking, otherwise RIL requests fail with a runtime |
| 8797 | // exception. ROOT_UID seems not to have a valid package name returned by |
| 8798 | // PackageManager, so just fake it here to avoid issues when running telephony shell |
| 8799 | // commands that plumb through the RIL as root, like so: |
| 8800 | // $ adb root |
| 8801 | // $ adb shell cmd phone ... |
| 8802 | packageName = "root"; |
| 8803 | } |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 8804 | return new WorkSource(uid, packageName); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8805 | } |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8806 | |
| 8807 | /** |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 8808 | * Set SIM card power state. |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8809 | * |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8810 | * @param slotIndex SIM slot id. |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 8811 | * @param state State of SIM (power down, power up, pass through) |
| 8812 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 8813 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 8814 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8815 | * |
| 8816 | **/ |
| 8817 | @Override |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 8818 | public void setSimPowerStateForSlot(int slotIndex, int state) { |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8819 | enforceModifyPermission(); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8820 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8821 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8822 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8823 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8824 | final long identity = Binder.clearCallingIdentity(); |
| 8825 | try { |
| 8826 | if (phone != null) { |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 8827 | phone.setSimPowerState(state, null, workSource); |
| 8828 | } |
| 8829 | } finally { |
| 8830 | Binder.restoreCallingIdentity(identity); |
| 8831 | } |
| 8832 | } |
| 8833 | |
| 8834 | /** |
| 8835 | * Set SIM card power state. |
| 8836 | * |
| 8837 | * @param slotIndex SIM slot id. |
| 8838 | * @param state State of SIM (power down, power up, pass through) |
| 8839 | * @param callback callback to trigger after success or failure |
| 8840 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 8841 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 8842 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
| 8843 | * |
| 8844 | **/ |
| 8845 | @Override |
| 8846 | public void setSimPowerStateForSlotWithCallback(int slotIndex, int state, |
| 8847 | IIntegerConsumer callback) { |
| 8848 | enforceModifyPermission(); |
| 8849 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8850 | |
| 8851 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8852 | |
| 8853 | final long identity = Binder.clearCallingIdentity(); |
| 8854 | try { |
| 8855 | if (phone != null) { |
| 8856 | Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback); |
| 8857 | sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8858 | } |
| 8859 | } finally { |
| 8860 | Binder.restoreCallingIdentity(identity); |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8861 | } |
| 8862 | } |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8863 | |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 8864 | private boolean isUssdApiAllowed(int subId) { |
| 8865 | CarrierConfigManager configManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8866 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 8867 | if (configManager == null) { |
| 8868 | return false; |
| 8869 | } |
| 8870 | PersistableBundle pb = configManager.getConfigForSubId(subId); |
| 8871 | if (pb == null) { |
| 8872 | return false; |
| 8873 | } |
| 8874 | return pb.getBoolean( |
| 8875 | CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL); |
| 8876 | } |
| 8877 | |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8878 | /** |
| 8879 | * Check if phone is in emergency callback mode |
| 8880 | * @return true if phone is in emergency callback mode |
| 8881 | * @param subId sub id |
| 8882 | */ |
goneil | 9c5f487 | 2017-12-05 14:07:56 -0800 | [diff] [blame] | 8883 | @Override |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8884 | public boolean getEmergencyCallbackMode(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8885 | enforceReadPrivilegedPermission("getEmergencyCallbackMode"); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8886 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8887 | |
| 8888 | final long identity = Binder.clearCallingIdentity(); |
| 8889 | try { |
| 8890 | if (phone != null) { |
| 8891 | return phone.isInEcm(); |
| 8892 | } else { |
| 8893 | return false; |
| 8894 | } |
| 8895 | } finally { |
| 8896 | Binder.restoreCallingIdentity(identity); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8897 | } |
| 8898 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 8899 | |
| 8900 | /** |
| 8901 | * Get the current signal strength information for the given subscription. |
| 8902 | * Because this information is not updated when the device is in a low power state |
| 8903 | * it should not be relied-upon to be current. |
| 8904 | * @param subId Subscription index |
| 8905 | * @return the most recent cached signal strength info from the modem |
| 8906 | */ |
| 8907 | @Override |
| 8908 | public SignalStrength getSignalStrength(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8909 | final long identity = Binder.clearCallingIdentity(); |
| 8910 | try { |
| 8911 | Phone p = getPhone(subId); |
| 8912 | if (p == null) { |
| 8913 | return null; |
| 8914 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 8915 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8916 | return p.getSignalStrength(); |
| 8917 | } finally { |
| 8918 | Binder.restoreCallingIdentity(identity); |
| 8919 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 8920 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8921 | |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8922 | /** |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8923 | * Get the current modem radio state for the given slot. |
| 8924 | * @param slotIndex slot index. |
| 8925 | * @param callingPackage the name of the package making the call. |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8926 | * @param callingFeatureId The feature in the package. |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8927 | * @return the current radio power state from the modem |
| 8928 | */ |
| 8929 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8930 | public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8931 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8932 | if (phone != null) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8933 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(), |
| 8934 | callingPackage, callingFeatureId, "getRadioPowerState")) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8935 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 8936 | } |
| 8937 | |
| 8938 | final long identity = Binder.clearCallingIdentity(); |
| 8939 | try { |
| 8940 | return phone.getRadioPowerState(); |
| 8941 | } finally { |
| 8942 | Binder.restoreCallingIdentity(identity); |
| 8943 | } |
| 8944 | } |
| 8945 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 8946 | } |
| 8947 | |
| 8948 | /** |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8949 | * Checks if data roaming is enabled on the subscription with id {@code subId}. |
| 8950 | * |
| 8951 | * <p>Requires one of the following permissions: |
| 8952 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}, |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 8953 | * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE}, |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8954 | * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier |
| 8955 | * privileges. |
| 8956 | * |
| 8957 | * @param subId subscription id |
| 8958 | * @return {@code true} if data roaming is enabled on this subscription, otherwise return |
| 8959 | * {@code false}. |
| 8960 | */ |
| 8961 | @Override |
| 8962 | public boolean isDataRoamingEnabled(int subId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 8963 | String functionName = "isDataRoamingEnabled"; |
Shuo Qian | 093013d | 2020-08-13 15:42:55 -0700 | [diff] [blame] | 8964 | try { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 8965 | try { |
| 8966 | mApp.enforceCallingOrSelfPermission( |
| 8967 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 8968 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 8969 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 8970 | mApp.enforceCallingOrSelfPermission( |
| 8971 | permission.READ_BASIC_PHONE_STATE, functionName); |
| 8972 | } |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 8973 | } catch (SecurityException e) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 8974 | TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 8975 | mApp, subId, functionName); |
Shuo Qian | 093013d | 2020-08-13 15:42:55 -0700 | [diff] [blame] | 8976 | } |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 8977 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8978 | boolean isEnabled = false; |
| 8979 | final long identity = Binder.clearCallingIdentity(); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8980 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8981 | Phone phone = getPhone(subId); |
| 8982 | isEnabled = phone != null ? phone.getDataRoamingEnabled() : false; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8983 | } finally { |
| 8984 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8985 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8986 | return isEnabled; |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8987 | } |
| 8988 | |
| 8989 | |
| 8990 | /** |
| 8991 | * Enables/Disables the data roaming on the subscription with id {@code subId}. |
| 8992 | * |
| 8993 | * <p> Requires permission: |
| 8994 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier |
| 8995 | * privileges. |
| 8996 | * |
| 8997 | * @param subId subscription id |
| 8998 | * @param isEnabled {@code true} means enable, {@code false} means disable. |
| 8999 | */ |
| 9000 | @Override |
| 9001 | public void setDataRoamingEnabled(int subId, boolean isEnabled) { |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 9002 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9003 | mApp, subId, "setDataRoamingEnabled"); |
| 9004 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9005 | final long identity = Binder.clearCallingIdentity(); |
| 9006 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9007 | Phone phone = getPhone(subId); |
| 9008 | if (phone != null) { |
| 9009 | phone.setDataRoamingEnabled(isEnabled); |
| 9010 | } |
| 9011 | } finally { |
| 9012 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9013 | } |
| 9014 | } |
| 9015 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9016 | @Override |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 9017 | public boolean isManualNetworkSelectionAllowed(int subId) { |
tom hsu | c91afc7 | 2020-01-06 23:46:07 +0800 | [diff] [blame] | 9018 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9019 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 9020 | mApp, subId, "isManualNetworkSelectionAllowed"); |
| 9021 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 9022 | boolean isAllowed = true; |
| 9023 | final long identity = Binder.clearCallingIdentity(); |
| 9024 | try { |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 9025 | Phone phone = getPhone(subId); |
| 9026 | if (phone != null) { |
| 9027 | isAllowed = phone.isCspPlmnEnabled(); |
| 9028 | } |
| 9029 | } finally { |
| 9030 | Binder.restoreCallingIdentity(identity); |
| 9031 | } |
| 9032 | return isAllowed; |
| 9033 | } |
| 9034 | |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9035 | private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) { |
| 9036 | UiccProfile profile = port.getUiccProfile(); |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 9037 | if (profile == null) { |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9038 | return false; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9039 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 9040 | Phone phone = PhoneFactory.getPhone(profile.getPhoneId()); |
| 9041 | if (phone == null) { |
| 9042 | return false; |
| 9043 | } |
| 9044 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 9045 | return cpt != null && cpt.getCarrierPrivilegeStatusForPackage(callingPackage) |
| 9046 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9047 | } |
| 9048 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 9049 | @Override |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 9050 | public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) { |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9051 | // Verify that the callingPackage belongs to the calling UID |
Jordan Liu | 4cda455 | 2020-03-23 11:55:07 -0700 | [diff] [blame] | 9052 | mApp.getSystemService(AppOpsManager.class) |
| 9053 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 9054 | |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9055 | boolean hasReadPermission = false; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9056 | boolean isIccIdAccessRestricted = false; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 9057 | try { |
| 9058 | enforceReadPrivilegedPermission("getUiccCardsInfo"); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9059 | hasReadPermission = true; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 9060 | } catch (SecurityException e) { |
| 9061 | // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller |
| 9062 | // has carrier privileges on an active UICC |
Rambo Wang | e7209ce | 2022-02-23 13:41:02 -0800 | [diff] [blame] | 9063 | if (checkCarrierPrivilegesForPackageAnyPhoneWithPermission(callingPackage) |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 9064 | != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9065 | throw new SecurityException("Caller does not have permission."); |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 9066 | } |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 9067 | } |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9068 | // checking compatibility, if calling app's target SDK is T and beyond. |
| 9069 | if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO, |
| 9070 | Binder.getCallingUid())) { |
| 9071 | isIccIdAccessRestricted = true; |
| 9072 | } |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 9073 | final long identity = Binder.clearCallingIdentity(); |
| 9074 | try { |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 9075 | UiccController uiccController = UiccController.getInstance(); |
| 9076 | ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos(); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9077 | if (hasReadPermission) { |
| 9078 | return cardInfos; |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 9079 | } |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9080 | |
| 9081 | // Remove private info if the caller doesn't have access |
| 9082 | ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>(); |
| 9083 | for (UiccCardInfo cardInfo : cardInfos) { |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9084 | //setting the value after compatibility check |
| 9085 | cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9086 | // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo |
| 9087 | // is available |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9088 | UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex()); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9089 | if (card == null) { |
| 9090 | // assume no access if the card is unavailable |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9091 | filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo)); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9092 | continue; |
| 9093 | } |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9094 | Collection<UiccPortInfo> portInfos = cardInfo.getPorts(); |
| 9095 | if (portInfos.isEmpty()) { |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9096 | filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo)); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9097 | continue; |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9098 | } |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9099 | List<UiccPortInfo> uiccPortInfos = new ArrayList<>(); |
| 9100 | for (UiccPortInfo portInfo : portInfos) { |
| 9101 | UiccPort port = uiccController.getUiccPortForSlot( |
| 9102 | cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex()); |
| 9103 | if (port == null) { |
| 9104 | // assume no access if port is null |
| 9105 | uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo)); |
| 9106 | continue; |
| 9107 | } |
| 9108 | if (haveCarrierPrivilegeAccess(port, callingPackage)) { |
| 9109 | uiccPortInfos.add(portInfo); |
| 9110 | } else { |
| 9111 | uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo)); |
| 9112 | } |
| 9113 | } |
| 9114 | filteredInfos.add(new UiccCardInfo( |
| 9115 | cardInfo.isEuicc(), |
| 9116 | cardInfo.getCardId(), |
| 9117 | null, |
| 9118 | cardInfo.getPhysicalSlotIndex(), |
| 9119 | cardInfo.isRemovable(), |
| 9120 | cardInfo.isMultipleEnabledProfilesSupported(), |
| 9121 | uiccPortInfos)); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9122 | } |
| 9123 | return filteredInfos; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 9124 | } finally { |
| 9125 | Binder.restoreCallingIdentity(identity); |
| 9126 | } |
| 9127 | } |
| 9128 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9129 | /** |
| 9130 | * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are |
| 9131 | * generally private and require carrier privileges to view. |
| 9132 | * |
| 9133 | * @hide |
| 9134 | */ |
| 9135 | @NonNull |
| 9136 | public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) { |
| 9137 | List<UiccPortInfo> portinfo = new ArrayList<>(); |
| 9138 | for (UiccPortInfo portinfos : cardInfo.getPorts()) { |
| 9139 | portinfo.add(getUiccPortInfoUnPrivileged(portinfos)); |
| 9140 | } |
| 9141 | return new UiccCardInfo( |
| 9142 | cardInfo.isEuicc(), |
| 9143 | cardInfo.getCardId(), |
| 9144 | null, |
| 9145 | cardInfo.getPhysicalSlotIndex(), |
| 9146 | cardInfo.isRemovable(), |
| 9147 | cardInfo.isMultipleEnabledProfilesSupported(), |
| 9148 | portinfo |
| 9149 | ); |
| 9150 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9151 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9152 | /** |
| 9153 | * @hide |
| 9154 | * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}. |
| 9155 | * These values are generally private and require carrier privileges to view. |
| 9156 | */ |
| 9157 | @NonNull |
| 9158 | public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) { |
| 9159 | return new UiccPortInfo( |
| 9160 | UiccPortInfo.ICCID_REDACTED, |
| 9161 | portInfo.getPortIndex(), |
| 9162 | portInfo.getLogicalSlotIndex(), |
| 9163 | portInfo.isActive() |
| 9164 | ); |
| 9165 | } |
| 9166 | @Override |
| 9167 | public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) { |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9168 | // Verify that the callingPackage belongs to the calling UID |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9169 | mApp.getSystemService(AppOpsManager.class) |
| 9170 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 9171 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9172 | boolean isLogicalSlotAccessRestricted = false; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9173 | |
Aman Gupta | f3c90b3 | 2022-03-17 04:54:16 +0000 | [diff] [blame] | 9174 | // This will make sure caller has the READ_PRIVILEGED_PHONE_STATE. Do not remove this as |
| 9175 | // we are reading iccId which is PII data. |
| 9176 | enforceReadPrivilegedPermission("getUiccSlotsInfo"); |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9177 | |
| 9178 | // checking compatibility, if calling app's target SDK is T and beyond. |
| 9179 | if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO, |
| 9180 | Binder.getCallingUid())) { |
| 9181 | isLogicalSlotAccessRestricted = true; |
| 9182 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9183 | final long identity = Binder.clearCallingIdentity(); |
| 9184 | try { |
| 9185 | UiccSlot[] slots = UiccController.getInstance().getUiccSlots(); |
Muralidhar Reddy | d196bbf | 2022-01-17 17:56:30 +0000 | [diff] [blame] | 9186 | if (slots == null || slots.length == 0) { |
| 9187 | Rlog.i(LOG_TAG, "slots is null or empty."); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9188 | return null; |
| 9189 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9190 | UiccSlotInfo[] infos = new UiccSlotInfo[slots.length]; |
| 9191 | for (int i = 0; i < slots.length; i++) { |
| 9192 | UiccSlot slot = slots[i]; |
| 9193 | if (slot == null) { |
| 9194 | continue; |
| 9195 | } |
| 9196 | |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 9197 | String cardId; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9198 | UiccCard card = slot.getUiccCard(); |
| 9199 | if (card != null) { |
| 9200 | cardId = card.getCardId(); |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 9201 | } else { |
Jordan Liu | 01bd00d | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 9202 | cardId = slot.getEid(); |
| 9203 | if (TextUtils.isEmpty(cardId)) { |
Aman Gupta | f3c90b3 | 2022-03-17 04:54:16 +0000 | [diff] [blame] | 9204 | // If cardId is null, use iccId of default port as cardId. |
| 9205 | cardId = slot.getIccId(TelephonyManager.DEFAULT_PORT_INDEX); |
Jordan Liu | 01bd00d | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 9206 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9207 | } |
| 9208 | |
Jordan Liu | 857451f | 2019-05-09 16:35:35 -0700 | [diff] [blame] | 9209 | if (cardId != null) { |
| 9210 | // if cardId is an ICCID, strip off trailing Fs before exposing to user |
| 9211 | // if cardId is an EID, it's all digits so this is fine |
| 9212 | cardId = IccUtils.stripTrailingFs(cardId); |
| 9213 | } |
| 9214 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9215 | int cardState = 0; |
| 9216 | switch (slot.getCardState()) { |
| 9217 | case CARDSTATE_ABSENT: |
| 9218 | cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT; |
| 9219 | break; |
| 9220 | case CARDSTATE_PRESENT: |
| 9221 | cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT; |
| 9222 | break; |
| 9223 | case CARDSTATE_ERROR: |
| 9224 | cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR; |
| 9225 | break; |
| 9226 | case CARDSTATE_RESTRICTED: |
| 9227 | cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED; |
| 9228 | break; |
| 9229 | default: |
| 9230 | break; |
| 9231 | |
| 9232 | } |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9233 | List<UiccPortInfo> portInfos = new ArrayList<>(); |
| 9234 | int[] portIndexes = slot.getPortList(); |
| 9235 | for (int portIdx : portIndexes) { |
| 9236 | String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx, |
Aman Gupta | f3c90b3 | 2022-03-17 04:54:16 +0000 | [diff] [blame] | 9237 | callingPackage, /* hasReadPermission= */ true)); |
Muralidhar Reddy | fbcff0c | 2022-01-19 13:07:57 +0000 | [diff] [blame] | 9238 | portInfos.add(new UiccPortInfo(iccId, portIdx, |
| 9239 | slot.getPhoneIdFromPortIndex(portIdx), slot.isPortActive(portIdx))); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9240 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9241 | infos[i] = new UiccSlotInfo( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9242 | slot.isEuicc(), |
| 9243 | cardId, |
| 9244 | cardState, |
Jordan Liu | a261958 | 2019-02-14 12:56:40 -0800 | [diff] [blame] | 9245 | slot.isExtendedApduSupported(), |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9246 | slot.isRemovable(), portInfos); |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9247 | //setting the value after compatibility check |
| 9248 | infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9249 | } |
| 9250 | return infos; |
| 9251 | } finally { |
| 9252 | Binder.restoreCallingIdentity(identity); |
Holly Jiuyu Sun | 1d957c5 | 2018-04-04 13:52:42 -0700 | [diff] [blame] | 9253 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9254 | } |
| 9255 | |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9256 | /* Returns null if doesn't have read permission or carrier privilege access. */ |
| 9257 | private String getIccId(UiccSlot slot, int portIndex, String callingPackage, |
| 9258 | boolean hasReadPermission) { |
| 9259 | String iccId = slot.getIccId(portIndex); |
| 9260 | if (hasReadPermission) { // if has read permission |
| 9261 | return iccId; |
| 9262 | } else { |
| 9263 | if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) { |
| 9264 | UiccPort port = slot.getUiccCard().getUiccPort(portIndex); |
| 9265 | // if no read permission, checking carrier privilege access |
| 9266 | if (haveCarrierPrivilegeAccess(port, callingPackage)) { |
| 9267 | return iccId; |
| 9268 | } |
| 9269 | } |
| 9270 | } |
| 9271 | // No read permission or carrier privilege access. |
| 9272 | return UiccPortInfo.ICCID_REDACTED; |
| 9273 | } |
| 9274 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9275 | @Override |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9276 | @Deprecated |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9277 | public boolean switchSlots(int[] physicalSlots) { |
| 9278 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9279 | |
| 9280 | final long identity = Binder.clearCallingIdentity(); |
| 9281 | try { |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9282 | List<UiccSlotMapping> slotMappings = new ArrayList<>(); |
| 9283 | for (int i = 0; i < physicalSlots.length; i++) { |
| 9284 | // Deprecated API, hence MEP is not supported. Adding default portIndex 0. |
| 9285 | slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX, |
| 9286 | physicalSlots[i], i)); |
| 9287 | } |
| 9288 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9289 | } finally { |
| 9290 | Binder.restoreCallingIdentity(identity); |
| 9291 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9292 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 9293 | |
| 9294 | @Override |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9295 | @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 9296 | public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) { |
| 9297 | enforceModifyPermission(); |
| 9298 | |
| 9299 | final long identity = Binder.clearCallingIdentity(); |
| 9300 | try { |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9301 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping); |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9302 | } finally { |
| 9303 | Binder.restoreCallingIdentity(identity); |
| 9304 | } |
| 9305 | } |
| 9306 | |
| 9307 | @Override |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 9308 | public int getCardIdForDefaultEuicc(int subId, String callingPackage) { |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 9309 | final long identity = Binder.clearCallingIdentity(); |
| 9310 | try { |
| 9311 | return UiccController.getInstance().getCardIdForDefaultEuicc(); |
| 9312 | } finally { |
| 9313 | Binder.restoreCallingIdentity(identity); |
| 9314 | } |
| 9315 | } |
| 9316 | |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9317 | /** |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 9318 | * A test API to reload the UICC profile. |
| 9319 | * |
| 9320 | * <p>Requires that the calling app has permission |
| 9321 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 9322 | * @hide |
| 9323 | */ |
| 9324 | @Override |
| 9325 | public void refreshUiccProfile(int subId) { |
| 9326 | enforceModifyPermission(); |
| 9327 | |
| 9328 | final long identity = Binder.clearCallingIdentity(); |
| 9329 | try { |
| 9330 | Phone phone = getPhone(subId); |
| 9331 | if (phone == null) { |
| 9332 | return; |
| 9333 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9334 | UiccPort uiccPort = phone.getUiccPort(); |
| 9335 | if (uiccPort == null) { |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 9336 | return; |
| 9337 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9338 | UiccProfile uiccProfile = uiccPort.getUiccProfile(); |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 9339 | if (uiccProfile == null) { |
| 9340 | return; |
| 9341 | } |
| 9342 | uiccProfile.refresh(); |
| 9343 | } finally { |
| 9344 | Binder.restoreCallingIdentity(identity); |
| 9345 | } |
| 9346 | } |
| 9347 | |
| 9348 | /** |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9349 | * Returns false if the mobile data is disabled by default, otherwise return true. |
| 9350 | */ |
| 9351 | private boolean getDefaultDataEnabled() { |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 9352 | return TelephonyProperties.mobile_data().orElse(true); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9353 | } |
| 9354 | |
| 9355 | /** |
| 9356 | * Returns true if the data roaming is enabled by default, i.e the system property |
| 9357 | * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of |
| 9358 | * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true. |
| 9359 | */ |
| 9360 | private boolean getDefaultDataRoamingEnabled(int subId) { |
| 9361 | final CarrierConfigManager configMgr = (CarrierConfigManager) |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9362 | mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Shuo Qian | 1d84a0e | 2020-07-15 12:36:44 -0700 | [diff] [blame] | 9363 | boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9364 | isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean( |
| 9365 | CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL); |
| 9366 | return isDataRoamingEnabled; |
| 9367 | } |
| 9368 | |
| 9369 | /** |
| 9370 | * Returns the default network type for the given {@code subId}, if the default network type is |
| 9371 | * not set, return {@link Phone#PREFERRED_NT_MODE}. |
| 9372 | */ |
| 9373 | private int getDefaultNetworkType(int subId) { |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 9374 | List<Integer> list = TelephonyProperties.default_network(); |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 9375 | int phoneId = SubscriptionManager.getPhoneId(subId); |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 9376 | if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) { |
| 9377 | return list.get(phoneId); |
| 9378 | } |
| 9379 | return Phone.PREFERRED_NT_MODE; |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9380 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9381 | |
| 9382 | @Override |
| 9383 | public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 9384 | gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) { |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9385 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9386 | |
| 9387 | final long identity = Binder.clearCallingIdentity(); |
| 9388 | try { |
| 9389 | final Phone phone = getPhone(subId); |
| 9390 | if (phone == null) { |
| 9391 | loge("setCarrierTestOverride fails with invalid subId: " + subId); |
| 9392 | return; |
| 9393 | } |
Rambo Wang | 9c9ffdd | 2022-01-13 21:51:44 -0800 | [diff] [blame] | 9394 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 9395 | if (cpt != null) { |
| 9396 | cpt.setTestOverrideCarrierPrivilegeRules(carrierPrivilegeRules); |
| 9397 | } |
| 9398 | // 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] | 9399 | phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn, |
| 9400 | carrierPrivilegeRules, apn); |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 9401 | if (carrierPrivilegeRules == null) { |
| 9402 | mCarrierPrivilegeTestOverrideSubIds.remove(subId); |
| 9403 | } else { |
| 9404 | mCarrierPrivilegeTestOverrideSubIds.add(subId); |
| 9405 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9406 | } finally { |
| 9407 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9408 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9409 | } |
| 9410 | |
| 9411 | @Override |
| 9412 | public int getCarrierIdListVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 9413 | enforceReadPrivilegedPermission("getCarrierIdListVersion"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9414 | |
| 9415 | final long identity = Binder.clearCallingIdentity(); |
| 9416 | try { |
| 9417 | final Phone phone = getPhone(subId); |
| 9418 | if (phone == null) { |
| 9419 | loge("getCarrierIdListVersion fails with invalid subId: " + subId); |
| 9420 | return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION; |
| 9421 | } |
| 9422 | return phone.getCarrierIdListVersion(); |
| 9423 | } finally { |
| 9424 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9425 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9426 | } |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 9427 | |
| 9428 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9429 | public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage, |
| 9430 | String callingFeatureId) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 9431 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9432 | mApp, subId, callingPackage, callingFeatureId, |
| 9433 | "getNumberOfModemsWithSimultaneousDataConnections")) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 9434 | return -1; |
| 9435 | } |
| 9436 | |
| 9437 | final long identity = Binder.clearCallingIdentity(); |
| 9438 | try { |
| 9439 | return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections(); |
| 9440 | } finally { |
| 9441 | Binder.restoreCallingIdentity(identity); |
| 9442 | } |
| 9443 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9444 | |
| 9445 | @Override |
| 9446 | public int getCdmaRoamingMode(int subId) { |
zoey chen | 7e6d4e5 | 2019-12-17 18:18:59 +0800 | [diff] [blame] | 9447 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9448 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9449 | mApp, subId, "getCdmaRoamingMode"); |
| 9450 | |
| 9451 | final long identity = Binder.clearCallingIdentity(); |
| 9452 | try { |
| 9453 | return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId); |
| 9454 | } finally { |
| 9455 | Binder.restoreCallingIdentity(identity); |
| 9456 | } |
| 9457 | } |
| 9458 | |
| 9459 | @Override |
| 9460 | public boolean setCdmaRoamingMode(int subId, int mode) { |
| 9461 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9462 | mApp, subId, "setCdmaRoamingMode"); |
| 9463 | |
| 9464 | final long identity = Binder.clearCallingIdentity(); |
| 9465 | try { |
| 9466 | return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId); |
| 9467 | } finally { |
| 9468 | Binder.restoreCallingIdentity(identity); |
| 9469 | } |
| 9470 | } |
| 9471 | |
| 9472 | @Override |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 9473 | public int getCdmaSubscriptionMode(int subId) { |
| 9474 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9475 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 9476 | mApp, subId, "getCdmaSubscriptionMode"); |
| 9477 | |
| 9478 | final long identity = Binder.clearCallingIdentity(); |
| 9479 | try { |
| 9480 | return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId); |
| 9481 | } finally { |
| 9482 | Binder.restoreCallingIdentity(identity); |
| 9483 | } |
| 9484 | } |
| 9485 | |
| 9486 | @Override |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9487 | public boolean setCdmaSubscriptionMode(int subId, int mode) { |
| 9488 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9489 | mApp, subId, "setCdmaSubscriptionMode"); |
| 9490 | |
| 9491 | final long identity = Binder.clearCallingIdentity(); |
| 9492 | try { |
| 9493 | return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId); |
| 9494 | } finally { |
| 9495 | Binder.restoreCallingIdentity(identity); |
| 9496 | } |
| 9497 | } |
Makoto Onuki | da3bf79 | 2018-09-18 16:06:29 -0700 | [diff] [blame] | 9498 | |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 9499 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 9500 | public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9501 | String callingPackage, String callingFeatureId) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9502 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9503 | mApp, getDefaultSubscription(), callingPackage, callingFeatureId, |
| 9504 | "getEmergencyNumberList")) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9505 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 9506 | } |
| 9507 | final long identity = Binder.clearCallingIdentity(); |
| 9508 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 9509 | Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>(); |
| 9510 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9511 | if (phone.getEmergencyNumberTracker() != null |
| 9512 | && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) { |
| 9513 | emergencyNumberListInternal.put( |
| 9514 | phone.getSubId(), |
| 9515 | phone.getEmergencyNumberTracker().getEmergencyNumberList()); |
| 9516 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9517 | } |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 9518 | return emergencyNumberListInternal; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9519 | } finally { |
| 9520 | Binder.restoreCallingIdentity(identity); |
| 9521 | } |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 9522 | } |
| 9523 | |
| 9524 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 9525 | public boolean isEmergencyNumber(String number, boolean exactMatch) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9526 | final Phone defaultPhone = getDefaultPhone(); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9527 | if (!exactMatch) { |
| 9528 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9529 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 9530 | mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)"); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9531 | } |
| 9532 | final long identity = Binder.clearCallingIdentity(); |
| 9533 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 9534 | for (Phone phone: PhoneFactory.getPhones()) { |
Chinmay Dhodapkar | d521bb1 | 2022-08-16 15:49:54 -0700 | [diff] [blame] | 9535 | //Note: we ignore passed in param exactMatch. We can remove it once |
| 9536 | // TelephonyManager#isPotentialEmergencyNumber is removed completely |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 9537 | if (phone.getEmergencyNumberTracker() != null |
Taesu Lee | e050c00 | 2020-10-13 17:19:35 +0900 | [diff] [blame] | 9538 | && phone.getEmergencyNumberTracker() |
Chinmay Dhodapkar | d521bb1 | 2022-08-16 15:49:54 -0700 | [diff] [blame] | 9539 | .isEmergencyNumber(number)) { |
Taesu Lee | e050c00 | 2020-10-13 17:19:35 +0900 | [diff] [blame] | 9540 | return true; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9541 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9542 | } |
| 9543 | return false; |
| 9544 | } finally { |
| 9545 | Binder.restoreCallingIdentity(identity); |
| 9546 | } |
| 9547 | } |
| 9548 | |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 9549 | /** |
Shuo Qian | ccbaf74 | 2021-02-22 18:32:21 -0800 | [diff] [blame] | 9550 | * Start emergency callback mode for GsmCdmaPhone for testing. |
| 9551 | */ |
| 9552 | @Override |
| 9553 | public void startEmergencyCallbackMode() { |
| 9554 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9555 | "startEmergencyCallbackMode"); |
| 9556 | enforceModifyPermission(); |
| 9557 | final long identity = Binder.clearCallingIdentity(); |
| 9558 | try { |
| 9559 | for (Phone phone : PhoneFactory.getPhones()) { |
| 9560 | Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType()); |
| 9561 | if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM) |
| 9562 | || (phone.getPhoneType() == PHONE_TYPE_CDMA))) { |
| 9563 | GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone; |
| 9564 | gsmCdmaPhone.obtainMessage( |
| 9565 | GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget(); |
| 9566 | Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered"); |
| 9567 | } |
| 9568 | } |
| 9569 | } finally { |
| 9570 | Binder.restoreCallingIdentity(identity); |
| 9571 | } |
| 9572 | } |
| 9573 | |
| 9574 | /** |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 9575 | * Update emergency number list for test mode. |
| 9576 | */ |
| 9577 | @Override |
| 9578 | public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) { |
| 9579 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9580 | "updateEmergencyNumberListTestMode"); |
| 9581 | |
| 9582 | final long identity = Binder.clearCallingIdentity(); |
| 9583 | try { |
| 9584 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9585 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9586 | if (tracker != null) { |
| 9587 | tracker.executeEmergencyNumberTestModeCommand(action, num); |
| 9588 | } |
| 9589 | } |
| 9590 | } finally { |
| 9591 | Binder.restoreCallingIdentity(identity); |
| 9592 | } |
| 9593 | } |
| 9594 | |
| 9595 | /** |
| 9596 | * Get the full emergency number list for test mode. |
| 9597 | */ |
| 9598 | @Override |
| 9599 | public List<String> getEmergencyNumberListTestMode() { |
| 9600 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9601 | "getEmergencyNumberListTestMode"); |
| 9602 | |
| 9603 | final long identity = Binder.clearCallingIdentity(); |
| 9604 | try { |
| 9605 | Set<String> emergencyNumbers = new HashSet<>(); |
| 9606 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9607 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9608 | if (tracker != null) { |
| 9609 | for (EmergencyNumber num : tracker.getEmergencyNumberList()) { |
| 9610 | emergencyNumbers.add(num.getNumber()); |
| 9611 | } |
| 9612 | } |
| 9613 | } |
| 9614 | return new ArrayList<>(emergencyNumbers); |
| 9615 | } finally { |
| 9616 | Binder.restoreCallingIdentity(identity); |
| 9617 | } |
| 9618 | } |
| 9619 | |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 9620 | @Override |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 9621 | public int getEmergencyNumberDbVersion(int subId) { |
| 9622 | enforceReadPrivilegedPermission("getEmergencyNumberDbVersion"); |
| 9623 | |
| 9624 | final long identity = Binder.clearCallingIdentity(); |
| 9625 | try { |
| 9626 | final Phone phone = getPhone(subId); |
| 9627 | if (phone == null) { |
| 9628 | loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId); |
| 9629 | return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION; |
| 9630 | } |
| 9631 | return phone.getEmergencyNumberDbVersion(); |
| 9632 | } finally { |
| 9633 | Binder.restoreCallingIdentity(identity); |
| 9634 | } |
| 9635 | } |
| 9636 | |
| 9637 | @Override |
| 9638 | public void notifyOtaEmergencyNumberDbInstalled() { |
| 9639 | enforceModifyPermission(); |
| 9640 | |
| 9641 | final long identity = Binder.clearCallingIdentity(); |
| 9642 | try { |
| 9643 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9644 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9645 | if (tracker != null) { |
| 9646 | tracker.updateOtaEmergencyNumberDatabase(); |
| 9647 | } |
| 9648 | } |
| 9649 | } finally { |
| 9650 | Binder.restoreCallingIdentity(identity); |
| 9651 | } |
| 9652 | } |
| 9653 | |
| 9654 | @Override |
Shuo Qian | c373f11 | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 9655 | public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) { |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 9656 | enforceActiveEmergencySessionPermission(); |
| 9657 | |
| 9658 | final long identity = Binder.clearCallingIdentity(); |
| 9659 | try { |
| 9660 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9661 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9662 | if (tracker != null) { |
Shuo Qian | c373f11 | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 9663 | tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor); |
| 9664 | } |
| 9665 | } |
| 9666 | } finally { |
| 9667 | Binder.restoreCallingIdentity(identity); |
| 9668 | } |
| 9669 | } |
| 9670 | |
| 9671 | @Override |
| 9672 | public void resetOtaEmergencyNumberDbFilePath() { |
| 9673 | enforceActiveEmergencySessionPermission(); |
| 9674 | |
| 9675 | final long identity = Binder.clearCallingIdentity(); |
| 9676 | try { |
| 9677 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9678 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9679 | if (tracker != null) { |
| 9680 | tracker.resetOtaEmergencyNumberDbFilePath(); |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 9681 | } |
| 9682 | } |
| 9683 | } finally { |
| 9684 | Binder.restoreCallingIdentity(identity); |
| 9685 | } |
| 9686 | } |
| 9687 | |
| 9688 | @Override |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 9689 | public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) { |
| 9690 | enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules"); |
| 9691 | Phone phone = getPhone(subId); |
| 9692 | if (phone == null) { |
| 9693 | return null; |
| 9694 | } |
| 9695 | final long identity = Binder.clearCallingIdentity(); |
| 9696 | try { |
| 9697 | UiccProfile profile = UiccController.getInstance() |
| 9698 | .getUiccProfileForPhone(phone.getPhoneId()); |
| 9699 | if (profile != null) { |
| 9700 | return profile.getCertsFromCarrierPrivilegeAccessRules(); |
| 9701 | } |
| 9702 | } finally { |
| 9703 | Binder.restoreCallingIdentity(identity); |
| 9704 | } |
| 9705 | return null; |
| 9706 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 9707 | |
| 9708 | /** |
| 9709 | * Enable or disable a modem stack. |
| 9710 | */ |
| 9711 | @Override |
| 9712 | public boolean enableModemForSlot(int slotIndex, boolean enable) { |
| 9713 | enforceModifyPermission(); |
| 9714 | |
| 9715 | final long identity = Binder.clearCallingIdentity(); |
| 9716 | try { |
| 9717 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 9718 | if (phone == null) { |
| 9719 | return false; |
| 9720 | } else { |
| 9721 | return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null); |
| 9722 | } |
| 9723 | } finally { |
| 9724 | Binder.restoreCallingIdentity(identity); |
| 9725 | } |
| 9726 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9727 | |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 9728 | /** |
| 9729 | * Whether a modem stack is enabled or not. |
| 9730 | */ |
| 9731 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9732 | public boolean isModemEnabledForSlot(int slotIndex, String callingPackage, |
| 9733 | String callingFeatureId) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 9734 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 9735 | if (phone == null) return false; |
| 9736 | |
| 9737 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9738 | mApp, phone.getSubId(), callingPackage, callingFeatureId, |
| 9739 | "isModemEnabledForSlot")) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 9740 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 9741 | } |
| 9742 | |
| 9743 | final long identity = Binder.clearCallingIdentity(); |
| 9744 | try { |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 9745 | try { |
| 9746 | return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId()); |
| 9747 | } catch (NoSuchElementException ex) { |
| 9748 | return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null); |
| 9749 | } |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 9750 | } finally { |
| 9751 | Binder.restoreCallingIdentity(identity); |
| 9752 | } |
| 9753 | } |
| 9754 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9755 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9756 | public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) { |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9757 | enforceModifyPermission(); |
| 9758 | |
| 9759 | final long identity = Binder.clearCallingIdentity(); |
| 9760 | try { |
| 9761 | mTelephonySharedPreferences.edit() |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9762 | .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted) |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9763 | .commit(); |
| 9764 | } finally { |
| 9765 | Binder.restoreCallingIdentity(identity); |
| 9766 | } |
| 9767 | } |
| 9768 | |
| 9769 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9770 | @TelephonyManager.IsMultiSimSupportedResult |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9771 | public int isMultiSimSupported(String callingPackage, String callingFeatureId) { |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 9772 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9773 | getDefaultPhone().getSubId(), callingPackage, callingFeatureId, |
| 9774 | "isMultiSimSupported")) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9775 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 9776 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9777 | |
| 9778 | final long identity = Binder.clearCallingIdentity(); |
| 9779 | try { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9780 | return isMultiSimSupportedInternal(); |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9781 | } finally { |
| 9782 | Binder.restoreCallingIdentity(identity); |
| 9783 | } |
| 9784 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9785 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9786 | @TelephonyManager.IsMultiSimSupportedResult |
| 9787 | private int isMultiSimSupportedInternal() { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9788 | // If the device has less than 2 SIM cards, indicate that multisim is restricted. |
| 9789 | int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length; |
| 9790 | if (numPhysicalSlots < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9791 | loge("isMultiSimSupportedInternal: requires at least 2 cards"); |
| 9792 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9793 | } |
| 9794 | // Check if the hardware supports multisim functionality. If usage of multisim is not |
| 9795 | // supported by the modem, indicate that it is restricted. |
| 9796 | PhoneCapability staticCapability = |
| 9797 | mPhoneConfigurationManager.getStaticPhoneCapability(); |
| 9798 | if (staticCapability == null) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9799 | loge("isMultiSimSupportedInternal: no static configuration available"); |
| 9800 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9801 | } |
SongFerngWang | 8236caa | 2021-01-17 21:51:44 +0800 | [diff] [blame] | 9802 | if (staticCapability.getLogicalModemList().size() < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9803 | loge("isMultiSimSupportedInternal: maximum number of modem is < 2"); |
| 9804 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9805 | } |
| 9806 | // Check if support of multiple SIMs is restricted by carrier |
| 9807 | if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9808 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9809 | } |
| 9810 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9811 | return TelephonyManager.MULTISIM_ALLOWED; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9812 | } |
| 9813 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9814 | /** |
| 9815 | * Switch configs to enable multi-sim or switch back to single-sim |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 9816 | * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE |
| 9817 | * permission, but the other way around is possible with either MODIFY_PHONE_STATE |
| 9818 | * or carrier privileges |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9819 | * @param numOfSims number of active sims we want to switch to |
| 9820 | */ |
| 9821 | @Override |
| 9822 | public void switchMultiSimConfig(int numOfSims) { |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 9823 | if (numOfSims == 1) { |
| 9824 | enforceModifyPermission(); |
| 9825 | } else { |
| 9826 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9827 | mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig"); |
| 9828 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9829 | final long identity = Binder.clearCallingIdentity(); |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9830 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9831 | try { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9832 | //only proceed if multi-sim is not restricted |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9833 | if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9834 | loge("switchMultiSimConfig not possible. It is restricted or not supported."); |
| 9835 | return; |
| 9836 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9837 | mPhoneConfigurationManager.switchMultiSimConfig(numOfSims); |
| 9838 | } finally { |
| 9839 | Binder.restoreCallingIdentity(identity); |
| 9840 | } |
| 9841 | } |
| 9842 | |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 9843 | @Override |
| 9844 | public boolean isApplicationOnUicc(int subId, int appType) { |
| 9845 | enforceReadPrivilegedPermission("isApplicationOnUicc"); |
| 9846 | Phone phone = getPhone(subId); |
| 9847 | if (phone == null) { |
| 9848 | return false; |
| 9849 | } |
| 9850 | final long identity = Binder.clearCallingIdentity(); |
| 9851 | try { |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9852 | UiccPort uiccPort = phone.getUiccPort(); |
| 9853 | if (uiccPort == null) { |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 9854 | return false; |
| 9855 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9856 | UiccProfile uiccProfile = uiccPort.getUiccProfile(); |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 9857 | if (uiccProfile == null) { |
| 9858 | return false; |
| 9859 | } |
| 9860 | if (TelephonyManager.APPTYPE_SIM <= appType |
| 9861 | && appType <= TelephonyManager.APPTYPE_ISIM) { |
| 9862 | return uiccProfile.isApplicationOnIcc(AppType.values()[appType]); |
| 9863 | } |
| 9864 | return false; |
| 9865 | } finally { |
| 9866 | Binder.restoreCallingIdentity(identity); |
| 9867 | } |
| 9868 | } |
| 9869 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9870 | /** |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 9871 | * Get whether making changes to modem configurations will trigger reboot. |
| 9872 | * Return value defaults to true. |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 9873 | */ |
| 9874 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9875 | public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage, |
| 9876 | String callingFeatureId) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 9877 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9878 | mApp, subId, callingPackage, callingFeatureId, |
| 9879 | "doesSwitchMultiSimConfigTriggerReboot")) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 9880 | return false; |
| 9881 | } |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 9882 | final long identity = Binder.clearCallingIdentity(); |
| 9883 | try { |
| 9884 | return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange(); |
| 9885 | } finally { |
| 9886 | Binder.restoreCallingIdentity(identity); |
| 9887 | } |
| 9888 | } |
| 9889 | |
Nathan Harold | 29f5f05 | 2019-02-15 13:41:57 -0800 | [diff] [blame] | 9890 | private void updateModemStateMetrics() { |
| 9891 | TelephonyMetrics metrics = TelephonyMetrics.getInstance(); |
| 9892 | // TODO: check the state for each modem if the api is ready. |
| 9893 | metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1); |
| 9894 | } |
| 9895 | |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 9896 | @Override |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9897 | public List<UiccSlotMapping> getSlotsMapping(String callingPackage) { |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 9898 | enforceReadPrivilegedPermission("getSlotsMapping"); |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9899 | // Verify that the callingPackage belongs to the calling UID |
| 9900 | mApp.getSystemService(AppOpsManager.class) |
| 9901 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 9902 | final long identity = Binder.clearCallingIdentity(); |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9903 | List<UiccSlotMapping> slotMap = new ArrayList<>(); |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 9904 | try { |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9905 | UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName()); |
| 9906 | if (slotInfos != null) { |
| 9907 | for (int i = 0; i < slotInfos.length; i++) { |
| 9908 | for (UiccPortInfo portInfo : slotInfos[i].getPorts()) { |
| 9909 | if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) { |
| 9910 | slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i, |
| 9911 | portInfo.getLogicalSlotIndex())); |
| 9912 | } |
| 9913 | } |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 9914 | } |
| 9915 | } |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9916 | return slotMap; |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 9917 | } finally { |
| 9918 | Binder.restoreCallingIdentity(identity); |
| 9919 | } |
| 9920 | } |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 9921 | |
| 9922 | /** |
| 9923 | * Get the IRadio HAL Version |
jimsun | f9ec162 | 2022-09-13 21:18:43 +0800 | [diff] [blame] | 9924 | * @deprecated use getHalVersion instead |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 9925 | */ |
jimsun | f9ec162 | 2022-09-13 21:18:43 +0800 | [diff] [blame] | 9926 | @Deprecated |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 9927 | @Override |
| 9928 | public int getRadioHalVersion() { |
jimsun | f9ec162 | 2022-09-13 21:18:43 +0800 | [diff] [blame] | 9929 | return getHalVersion(HAL_SERVICE_RADIO); |
| 9930 | } |
| 9931 | |
| 9932 | /** |
| 9933 | * Get the HAL Version of a specific service |
| 9934 | */ |
| 9935 | @Override |
| 9936 | public int getHalVersion(int service) { |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 9937 | Phone phone = getDefaultPhone(); |
| 9938 | if (phone == null) return -1; |
jimsun | f9ec162 | 2022-09-13 21:18:43 +0800 | [diff] [blame] | 9939 | HalVersion hv = phone.getHalVersion(service); |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 9940 | if (hv.equals(HalVersion.UNKNOWN)) return -1; |
| 9941 | return hv.major * 100 + hv.minor; |
| 9942 | } |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9943 | |
| 9944 | /** |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 9945 | * Get the current calling package name. |
| 9946 | * @return the current calling package name |
| 9947 | */ |
| 9948 | @Override |
| 9949 | public String getCurrentPackageName() { |
| 9950 | return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0]; |
| 9951 | } |
| 9952 | |
| 9953 | /** |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9954 | * Return whether data is enabled for certain APN type. This will tell if framework will accept |
| 9955 | * corresponding network requests on a subId. |
| 9956 | * |
| 9957 | * Data is enabled if: |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9958 | * 1) user data is turned on, or |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9959 | * 2) APN is un-metered for this subscription, or |
| 9960 | * 3) APN type is whitelisted. E.g. MMS is whitelisted if |
Hall Liu | 746e03c | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 9961 | * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled. |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9962 | * |
| 9963 | * @return whether data is allowed for a apn type. |
| 9964 | * |
| 9965 | * @hide |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9966 | */ |
| 9967 | @Override |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9968 | public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) { |
Amit Mahajan | 5d4e192 | 2019-10-07 16:20:43 -0700 | [diff] [blame] | 9969 | enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for " |
| 9970 | + "isDataEnabledForApn"); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9971 | |
| 9972 | // Now that all security checks passes, perform the operation as ourselves. |
| 9973 | final long identity = Binder.clearCallingIdentity(); |
| 9974 | try { |
| 9975 | Phone phone = getPhone(subId); |
| 9976 | if (phone == null) return false; |
| 9977 | |
Jack Yu | 27422a5 | 2022-03-21 10:38:05 -0700 | [diff] [blame] | 9978 | boolean isMetered; |
Jack Yu | 99e8733 | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 9979 | boolean isDataEnabled; |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 9980 | isMetered = phone.getDataNetworkController().getDataConfigManager() |
| 9981 | .isMeteredCapability(DataUtils.apnTypeToNetworkCapability(apnType), |
| 9982 | phone.getServiceState().getDataRoaming()); |
| 9983 | isDataEnabled = phone.getDataSettingsManager().isDataEnabled(apnType); |
Jack Yu | 99e8733 | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 9984 | return !isMetered || isDataEnabled; |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9985 | } finally { |
| 9986 | Binder.restoreCallingIdentity(identity); |
| 9987 | } |
| 9988 | } |
| 9989 | |
| 9990 | @Override |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 9991 | public boolean isApnMetered(@ApnType int apnType, int subId) { |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9992 | enforceReadPrivilegedPermission("isApnMetered"); |
| 9993 | |
| 9994 | // Now that all security checks passes, perform the operation as ourselves. |
| 9995 | final long identity = Binder.clearCallingIdentity(); |
| 9996 | try { |
| 9997 | Phone phone = getPhone(subId); |
| 9998 | if (phone == null) return true; // By default return true. |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 9999 | return phone.getDataNetworkController().getDataConfigManager().isMeteredCapability( |
| 10000 | DataUtils.apnTypeToNetworkCapability(apnType), |
| 10001 | phone.getServiceState().getDataRoaming()); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 10002 | } finally { |
| 10003 | Binder.restoreCallingIdentity(identity); |
| 10004 | } |
| 10005 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 10006 | |
| 10007 | @Override |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 10008 | public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers, |
| 10009 | int subscriptionId, IBooleanConsumer resultCallback) { |
| 10010 | enforceModifyPermission(); |
| 10011 | long token = Binder.clearCallingIdentity(); |
| 10012 | try { |
| 10013 | Phone phone = getPhone(subscriptionId); |
| 10014 | if (phone == null) { |
| 10015 | try { |
| 10016 | if (resultCallback != null) { |
| 10017 | resultCallback.accept(false); |
| 10018 | } |
| 10019 | } catch (RemoteException e) { |
| 10020 | // ignore |
| 10021 | } |
| 10022 | return; |
| 10023 | } |
| 10024 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument = |
| 10025 | Pair.create(specifiers, (x) -> { |
| 10026 | try { |
| 10027 | if (resultCallback != null) { |
| 10028 | resultCallback.accept(x); |
| 10029 | } |
| 10030 | } catch (RemoteException e) { |
| 10031 | // ignore |
| 10032 | } |
| 10033 | }); |
| 10034 | sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null); |
| 10035 | } finally { |
| 10036 | Binder.restoreCallingIdentity(token); |
| 10037 | } |
| 10038 | } |
| 10039 | |
| 10040 | @Override |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 10041 | public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) { |
| 10042 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 10043 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 10044 | mApp, subId, "getSystemSelectionChannels"); |
| 10045 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 10046 | final long identity = Binder.clearCallingIdentity(); |
| 10047 | try { |
Sarah Chin | 428d1d6 | 2021-03-13 03:17:40 -0800 | [diff] [blame] | 10048 | Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource); |
| 10049 | if (result instanceof IllegalStateException) { |
| 10050 | throw (IllegalStateException) result; |
| 10051 | } |
| 10052 | List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 10053 | if (DBG) log("getSystemSelectionChannels: " + specifiers); |
| 10054 | return specifiers; |
| 10055 | } finally { |
| 10056 | Binder.restoreCallingIdentity(identity); |
| 10057 | } |
| 10058 | } |
| 10059 | |
| 10060 | @Override |
Jack Yu | 8b766fc | 2022-03-21 09:42:33 -0700 | [diff] [blame] | 10061 | public boolean isMvnoMatched(int slotIndex, int mvnoType, @NonNull String mvnoMatchData) { |
changbetty | ca3d40d | 2020-03-03 16:27:31 +0800 | [diff] [blame] | 10062 | enforceReadPrivilegedPermission("isMvnoMatched"); |
Jack Yu | 8b766fc | 2022-03-21 09:42:33 -0700 | [diff] [blame] | 10063 | return UiccController.getInstance().mvnoMatches(slotIndex, mvnoType, mvnoMatchData); |
changbetty | 7157e9e | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 10064 | } |
| 10065 | |
| 10066 | @Override |
Philip P. Moltmann | d02b737 | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 10067 | public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag, |
| 10068 | IIntegerConsumer pendingSubIdResult) { |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 10069 | if (callingPackage == null) { |
| 10070 | callingPackage = getCurrentPackageName(); |
| 10071 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 10072 | SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp, |
| 10073 | (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE)); |
Philip P. Moltmann | d02b737 | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 10074 | if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag, |
| 10075 | "Sending message")) { |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 10076 | throw new SecurityException("Requires SEND_SMS permission to perform this operation"); |
| 10077 | } |
| 10078 | PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult); |
| 10079 | Intent intent = new Intent(); |
| 10080 | intent.setClass(mApp, PickSmsSubscriptionActivity.class); |
| 10081 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 10082 | // Bring up choose default SMS subscription dialog right now |
| 10083 | intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY, |
| 10084 | PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE); |
| 10085 | mApp.startActivity(intent); |
| 10086 | } |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 10087 | |
| 10088 | @Override |
| 10089 | public String getMmsUAProfUrl(int subId) { |
| 10090 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 10091 | final long identity = Binder.clearCallingIdentity(); |
| 10092 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 10093 | String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString( |
| 10094 | CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING); |
| 10095 | if (!TextUtils.isEmpty(carrierUAProfUrl)) { |
| 10096 | return carrierUAProfUrl; |
| 10097 | } |
Daniel Bright | ebb4eb7 | 2020-02-18 15:16:33 -0800 | [diff] [blame] | 10098 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 10099 | .getString(com.android.internal.R.string.config_mms_user_agent_profile_url); |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 10100 | } finally { |
| 10101 | Binder.restoreCallingIdentity(identity); |
| 10102 | } |
| 10103 | } |
| 10104 | |
| 10105 | @Override |
| 10106 | public String getMmsUserAgent(int subId) { |
| 10107 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 10108 | final long identity = Binder.clearCallingIdentity(); |
| 10109 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 10110 | String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString( |
| 10111 | CarrierConfigManager.KEY_MMS_USER_AGENT_STRING); |
| 10112 | if (!TextUtils.isEmpty(carrierUserAgent)) { |
| 10113 | return carrierUserAgent; |
| 10114 | } |
Daniel Bright | ebb4eb7 | 2020-02-18 15:16:33 -0800 | [diff] [blame] | 10115 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 10116 | .getString(com.android.internal.R.string.config_mms_user_agent); |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 10117 | } finally { |
| 10118 | Binder.restoreCallingIdentity(identity); |
| 10119 | } |
| 10120 | } |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 10121 | |
| 10122 | @Override |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 10123 | public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) { |
| 10124 | enforceReadPrivilegedPermission("isMobileDataPolicyEnabled"); |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 10125 | |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 10126 | final long identity = Binder.clearCallingIdentity(); |
| 10127 | try { |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 10128 | Phone phone = getPhone(subscriptionId); |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 10129 | if (phone == null) return false; |
| 10130 | |
Ling Ma | f188d50 | 2022-09-16 15:22:36 -0700 | [diff] [blame] | 10131 | return phone.getDataSettingsManager().isMobileDataPolicyEnabled(policy); |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 10132 | } finally { |
| 10133 | Binder.restoreCallingIdentity(identity); |
| 10134 | } |
| 10135 | } |
| 10136 | |
| 10137 | @Override |
Hall Liu | c66bb11 | 2021-02-02 12:09:32 -0800 | [diff] [blame] | 10138 | public void setMobileDataPolicyEnabled(int subscriptionId, int policy, |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 10139 | boolean enabled) { |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 10140 | enforceModifyPermission(); |
| 10141 | |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 10142 | final long identity = Binder.clearCallingIdentity(); |
| 10143 | try { |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 10144 | Phone phone = getPhone(subscriptionId); |
| 10145 | if (phone == null) return; |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 10146 | |
Ling Ma | f188d50 | 2022-09-16 15:22:36 -0700 | [diff] [blame] | 10147 | phone.getDataSettingsManager().setMobileDataPolicy(policy, enabled); |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 10148 | } finally { |
| 10149 | Binder.restoreCallingIdentity(identity); |
| 10150 | } |
| 10151 | } |
| 10152 | |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 10153 | /** |
Hall Liu | 746e03c | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 10154 | * Updates whether conference event package handling is enabled. |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 10155 | * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false} |
| 10156 | * otherwise. |
| 10157 | */ |
| 10158 | @Override |
| 10159 | public void setCepEnabled(boolean isCepEnabled) { |
| 10160 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled"); |
| 10161 | |
| 10162 | final long identity = Binder.clearCallingIdentity(); |
| 10163 | try { |
| 10164 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled); |
| 10165 | for (Phone phone : PhoneFactory.getPhones()) { |
| 10166 | Phone defaultPhone = phone.getImsPhone(); |
| 10167 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 10168 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 10169 | ImsPhoneCallTracker imsPhoneCallTracker = |
| 10170 | (ImsPhoneCallTracker) imsPhone.getCallTracker(); |
| 10171 | imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled); |
| 10172 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone " |
| 10173 | + imsPhone.getMsisdn()); |
| 10174 | } |
| 10175 | } |
| 10176 | } finally { |
| 10177 | Binder.restoreCallingIdentity(identity); |
| 10178 | } |
| 10179 | } |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 10180 | |
| 10181 | /** |
| 10182 | * Notify that an RCS autoconfiguration XML file has been received for provisioning. |
| 10183 | * |
| 10184 | * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed. |
| 10185 | * @param isCompressed The XML file is compressed in gzip format and must be decompressed |
| 10186 | * before being read. |
| 10187 | */ |
| 10188 | @Override |
| 10189 | public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean |
| 10190 | isCompressed) { |
| 10191 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 10192 | mApp, subId, "notifyRcsAutoConfigurationReceived"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10193 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10194 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10195 | } |
| 10196 | if (!isImsAvailableOnDevice()) { |
joonhunshin | 46b49a3 | 2022-12-21 05:33:23 +0000 | [diff] [blame^] | 10197 | // ProvisioningManager can not handle ServiceSpecificException. |
| 10198 | // Throw the IllegalStateException and annotate ProvisioningManager. |
| 10199 | throw new IllegalStateException("IMS not available on device."); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10200 | } |
| 10201 | |
| 10202 | final long identity = Binder.clearCallingIdentity(); |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 10203 | try { |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10204 | RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed); |
| 10205 | } finally { |
| 10206 | Binder.restoreCallingIdentity(identity); |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 10207 | } |
| 10208 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 10209 | |
| 10210 | @Override |
| 10211 | public boolean isIccLockEnabled(int subId) { |
| 10212 | enforceReadPrivilegedPermission("isIccLockEnabled"); |
| 10213 | |
| 10214 | // Now that all security checks passes, perform the operation as ourselves. |
| 10215 | final long identity = Binder.clearCallingIdentity(); |
| 10216 | try { |
| 10217 | Phone phone = getPhone(subId); |
| 10218 | if (phone != null && phone.getIccCard() != null) { |
| 10219 | return phone.getIccCard().getIccLockEnabled(); |
| 10220 | } else { |
| 10221 | return false; |
| 10222 | } |
| 10223 | } finally { |
| 10224 | Binder.restoreCallingIdentity(identity); |
| 10225 | } |
| 10226 | } |
| 10227 | |
| 10228 | /** |
| 10229 | * Set the ICC pin lock enabled or disabled. |
| 10230 | * |
| 10231 | * @return an integer representing the status of IccLock enabled or disabled in the following |
| 10232 | * three cases: |
| 10233 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock |
| 10234 | * successfully. |
| 10235 | * - Positive number and zero for remaining password attempts. |
| 10236 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
| 10237 | * |
| 10238 | */ |
| 10239 | @Override |
| 10240 | public int setIccLockEnabled(int subId, boolean enabled, String password) { |
| 10241 | enforceModifyPermission(); |
| 10242 | |
| 10243 | Phone phone = getPhone(subId); |
| 10244 | if (phone == null) { |
| 10245 | return 0; |
| 10246 | } |
| 10247 | // Now that all security checks passes, perform the operation as ourselves. |
| 10248 | final long identity = Binder.clearCallingIdentity(); |
| 10249 | try { |
| 10250 | int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED, |
| 10251 | new Pair<Boolean, String>(enabled, password), phone, null); |
| 10252 | return attemptsRemaining; |
| 10253 | |
| 10254 | } catch (Exception e) { |
| 10255 | Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e); |
| 10256 | } finally { |
| 10257 | Binder.restoreCallingIdentity(identity); |
| 10258 | } |
| 10259 | return 0; |
| 10260 | } |
| 10261 | |
| 10262 | /** |
| 10263 | * Change the ICC password used in ICC pin lock. |
| 10264 | * |
| 10265 | * @return an integer representing the status of IccLock changed in the following three cases: |
| 10266 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully. |
| 10267 | * - Positive number and zero for remaining password attempts. |
| 10268 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
| 10269 | * |
| 10270 | */ |
| 10271 | @Override |
| 10272 | public int changeIccLockPassword(int subId, String oldPassword, String newPassword) { |
| 10273 | enforceModifyPermission(); |
| 10274 | |
| 10275 | Phone phone = getPhone(subId); |
| 10276 | if (phone == null) { |
| 10277 | return 0; |
| 10278 | } |
| 10279 | // Now that all security checks passes, perform the operation as ourselves. |
| 10280 | final long identity = Binder.clearCallingIdentity(); |
| 10281 | try { |
| 10282 | int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD, |
| 10283 | new Pair<String, String>(oldPassword, newPassword), phone, null); |
| 10284 | return attemptsRemaining; |
| 10285 | |
| 10286 | } catch (Exception e) { |
| 10287 | Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e); |
| 10288 | } finally { |
| 10289 | Binder.restoreCallingIdentity(identity); |
| 10290 | } |
| 10291 | return 0; |
| 10292 | } |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 10293 | |
| 10294 | /** |
| 10295 | * Request for receiving user activity notification |
| 10296 | */ |
| 10297 | @Override |
| 10298 | public void requestUserActivityNotification() { |
| 10299 | if (!mNotifyUserActivity.get() |
| 10300 | && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) { |
| 10301 | mNotifyUserActivity.set(true); |
| 10302 | } |
| 10303 | } |
| 10304 | |
| 10305 | /** |
| 10306 | * Called when userActivity is signalled in the power manager. |
| 10307 | * This is safe to call from any thread, with any window manager locks held or not. |
| 10308 | */ |
| 10309 | @Override |
| 10310 | public void userActivity() { |
| 10311 | // *************************************** |
| 10312 | // * Inherited from PhoneWindowManager * |
| 10313 | // *************************************** |
| 10314 | // THIS IS CALLED FROM DEEP IN THE POWER MANAGER |
| 10315 | // WITH ITS LOCKS HELD. |
| 10316 | // |
| 10317 | // This code must be VERY careful about the locks |
| 10318 | // it acquires. |
| 10319 | // In fact, the current code acquires way too many, |
| 10320 | // and probably has lurking deadlocks. |
| 10321 | |
| 10322 | if (Binder.getCallingUid() != Process.SYSTEM_UID) { |
| 10323 | throw new SecurityException("Only the OS may call notifyUserActivity()"); |
| 10324 | } |
| 10325 | |
| 10326 | if (mNotifyUserActivity.getAndSet(false)) { |
| 10327 | mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY, |
| 10328 | USER_ACTIVITY_NOTIFICATION_DELAY); |
| 10329 | } |
| 10330 | } |
Malcolm Chen | 4639c56 | 2020-04-13 11:59:40 -0700 | [diff] [blame] | 10331 | |
| 10332 | @Override |
| 10333 | public boolean canConnectTo5GInDsdsMode() { |
| 10334 | return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode); |
| 10335 | } |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 10336 | |
| 10337 | @Override |
| 10338 | public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage, |
| 10339 | String callingFeatureId) { |
| 10340 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 10341 | mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) { |
| 10342 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 10343 | } |
| 10344 | |
| 10345 | Phone phone = getPhone(subId); |
| 10346 | if (phone == null) { |
| 10347 | throw new RuntimeException("phone is not available"); |
| 10348 | } |
| 10349 | // Now that all security checks passes, perform the operation as ourselves. |
| 10350 | final long identity = Binder.clearCallingIdentity(); |
| 10351 | try { |
| 10352 | return phone.getEquivalentHomePlmns(); |
| 10353 | } finally { |
| 10354 | Binder.restoreCallingIdentity(identity); |
| 10355 | } |
| 10356 | } |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 10357 | |
| 10358 | @Override |
| 10359 | public boolean isRadioInterfaceCapabilitySupported( |
Daniel Bright | 95a4c1f | 2021-02-11 09:57:16 -0800 | [diff] [blame] | 10360 | final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) { |
| 10361 | Set<String> radioInterfaceCapabilities = |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 10362 | mRadioInterfaceCapabilities.getCapabilities(); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 10363 | if (radioInterfaceCapabilities == null) { |
| 10364 | throw new RuntimeException("radio interface capabilities are not available"); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 10365 | } |
Daniel Bright | 95a4c1f | 2021-02-11 09:57:16 -0800 | [diff] [blame] | 10366 | return radioInterfaceCapabilities.contains(capability); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 10367 | } |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10368 | |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 10369 | @Override |
| 10370 | public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl, |
| 10371 | UaSecurityProtocolIdentifier securityProtocol, |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10372 | boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) { |
| 10373 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 10374 | Binder.getCallingUid(), "bootstrapAuthenticationRequest", |
| 10375 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 10376 | Manifest.permission.MODIFY_PHONE_STATE); |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 10377 | if (DBG) { |
| 10378 | log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:" |
| 10379 | + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol |
| 10380 | + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback); |
| 10381 | } |
| 10382 | |
| 10383 | if (!SubscriptionManager.isValidSubscriptionId(subId) |
| 10384 | || appType < TelephonyManager.APPTYPE_UNKNOWN |
| 10385 | || appType > TelephonyManager.APPTYPE_ISIM |
| 10386 | || nafUrl == null || securityProtocol == null || callback == null) { |
| 10387 | Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters"); |
| 10388 | if (callback != null) { |
| 10389 | try { |
| 10390 | callback.onAuthenticationFailure( |
| 10391 | 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED); |
| 10392 | } catch (RemoteException exception) { |
| 10393 | log("Fail to notify onAuthenticationFailure due to " + exception); |
| 10394 | } |
| 10395 | return; |
| 10396 | } |
| 10397 | } |
| 10398 | |
| 10399 | final long token = Binder.clearCallingIdentity(); |
| 10400 | try { |
| 10401 | getGbaManager(subId).bootstrapAuthenticationRequest( |
| 10402 | new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(), |
| 10403 | forceBootStrapping, callback)); |
| 10404 | } finally { |
| 10405 | Binder.restoreCallingIdentity(token); |
| 10406 | } |
| 10407 | } |
| 10408 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10409 | /** |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10410 | * Attempts to set the radio power state for all phones for thermal reason. |
| 10411 | * This does not guarantee that the |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10412 | * requested radio power state will actually be set. See {@link |
| 10413 | * PhoneInternalInterface#setRadioPowerForReason} for more details. |
| 10414 | * |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10415 | * @param enable {@code true} if trying to turn radio on. |
| 10416 | * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code |
| 10417 | * false}. |
| 10418 | */ |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10419 | private boolean setRadioPowerForThermal(boolean enable) { |
| 10420 | boolean isPhoneAvailable = false; |
| 10421 | for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) { |
| 10422 | Phone phone = PhoneFactory.getPhone(i); |
| 10423 | if (phone != null) { |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 10424 | phone.setRadioPowerForReason(enable, TelephonyManager.RADIO_POWER_REASON_THERMAL); |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10425 | isPhoneAvailable = true; |
| 10426 | } |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10427 | } |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10428 | |
| 10429 | // return true if successfully informed the phone object about the thermal radio power |
| 10430 | // request. |
| 10431 | return isPhoneAvailable; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10432 | } |
| 10433 | |
| 10434 | private int handleDataThrottlingRequest(int subId, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 10435 | DataThrottlingRequest dataThrottlingRequest, String callingPackage) { |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10436 | boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported( |
| 10437 | TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING); |
| 10438 | if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction() |
| 10439 | != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) { |
| 10440 | throw new IllegalArgumentException("modem does not support data throttling"); |
| 10441 | } |
| 10442 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10443 | // Ensure that radio is on. If not able to power on due to phone being unavailable, return |
| 10444 | // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10445 | if (!setRadioPowerForThermal(true)) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10446 | return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 10447 | } |
| 10448 | |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 10449 | setDataEnabledForReason( |
| 10450 | subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true, callingPackage); |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10451 | |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10452 | if (isDataThrottlingSupported) { |
| 10453 | int thermalMitigationResult = |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10454 | (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId); |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10455 | if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) { |
| 10456 | throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS"); |
| 10457 | } else if (thermalMitigationResult |
| 10458 | == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) { |
Jack Nudelman | 760d096 | 2021-05-20 13:57:30 -0700 | [diff] [blame] | 10459 | log("Modem likely does not support data throttling on secondary carrier. Data " + |
| 10460 | "throttling action = " + dataThrottlingRequest.getDataThrottlingAction()); |
| 10461 | return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10462 | } |
| 10463 | return thermalMitigationResult; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10464 | } |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10465 | |
| 10466 | return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10467 | } |
| 10468 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10469 | private static List<String> getThermalMitigationAllowlist(Context context) { |
| 10470 | if (sThermalMitigationAllowlistedPackages.isEmpty()) { |
| 10471 | for (String pckg : context.getResources() |
| 10472 | .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) { |
| 10473 | sThermalMitigationAllowlistedPackages.add(pckg); |
| 10474 | } |
| 10475 | } |
| 10476 | |
| 10477 | return sThermalMitigationAllowlistedPackages; |
| 10478 | } |
| 10479 | |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 10480 | private boolean isAnyPhoneInEmergencyState() { |
| 10481 | TelecomManager tm = mApp.getSystemService(TelecomManager.class); |
| 10482 | if (tm.isInEmergencyCall()) { |
| 10483 | Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call"); |
| 10484 | return true; |
| 10485 | } |
| 10486 | for (Phone phone : PhoneFactory.getPhones()) { |
| 10487 | if (phone.isInEmergencySmsMode() || phone.isInEcm()) { |
| 10488 | Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = " |
| 10489 | + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = " |
| 10490 | + phone.isInEcm()); |
| 10491 | return true; |
| 10492 | } |
| 10493 | } |
| 10494 | |
| 10495 | return false; |
| 10496 | } |
| 10497 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10498 | /** |
| 10499 | * Used by shell commands to add an authorized package name for thermal mitigation. |
| 10500 | * @param packageName name of package to be allowlisted |
| 10501 | * @param context |
| 10502 | */ |
| 10503 | static void addPackageToThermalMitigationAllowlist(String packageName, Context context) { |
| 10504 | sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context); |
| 10505 | sThermalMitigationAllowlistedPackages.add(packageName); |
| 10506 | } |
| 10507 | |
| 10508 | /** |
| 10509 | * Used by shell commands to remove an authorized package name for thermal mitigation. |
| 10510 | * @param packageName name of package to remove from allowlist |
| 10511 | * @param context |
| 10512 | */ |
| 10513 | static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) { |
| 10514 | sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context); |
| 10515 | sThermalMitigationAllowlistedPackages.remove(packageName); |
| 10516 | } |
| 10517 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10518 | /** |
| 10519 | * Thermal mitigation request to control functionalities at modem. |
| 10520 | * |
| 10521 | * @param subId the id of the subscription. |
| 10522 | * @param thermalMitigationRequest holds all necessary information to be passed down to modem. |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10523 | * @param callingPackage the package name of the calling package. |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10524 | * |
| 10525 | * @return thermalMitigationResult enum as defined in android.telephony.Annotation. |
| 10526 | */ |
| 10527 | @Override |
| 10528 | @ThermalMitigationResult |
| 10529 | public int sendThermalMitigationRequest( |
| 10530 | int subId, |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10531 | ThermalMitigationRequest thermalMitigationRequest, |
| 10532 | String callingPackage) throws IllegalArgumentException { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10533 | enforceModifyPermission(); |
| 10534 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10535 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 10536 | if (!getThermalMitigationAllowlist(getDefaultPhone().getContext()) |
| 10537 | .contains(callingPackage)) { |
| 10538 | throw new SecurityException("Calling package must be configured in the device config. " |
| 10539 | + "calling package: " + callingPackage); |
| 10540 | } |
| 10541 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10542 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 10543 | final long identity = Binder.clearCallingIdentity(); |
| 10544 | |
| 10545 | int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR; |
| 10546 | try { |
| 10547 | int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction(); |
| 10548 | switch (thermalMitigationAction) { |
| 10549 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING: |
| 10550 | thermalMitigationResult = |
| 10551 | handleDataThrottlingRequest(subId, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 10552 | thermalMitigationRequest.getDataThrottlingRequest(), |
| 10553 | callingPackage); |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10554 | break; |
| 10555 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY: |
| 10556 | if (thermalMitigationRequest.getDataThrottlingRequest() != null) { |
| 10557 | throw new IllegalArgumentException("dataThrottlingRequest must be null for " |
| 10558 | + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY"); |
| 10559 | } |
| 10560 | |
| 10561 | // Ensure that radio is on. If not able to power on due to phone being |
| 10562 | // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10563 | if (!setRadioPowerForThermal(true)) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10564 | thermalMitigationResult = |
| 10565 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 10566 | break; |
| 10567 | } |
| 10568 | |
| 10569 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 10570 | false, callingPackage); |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10571 | thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 10572 | break; |
| 10573 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF: |
| 10574 | if (thermalMitigationRequest.getDataThrottlingRequest() != null) { |
| 10575 | throw new IllegalArgumentException("dataThrottlingRequest must be null for" |
| 10576 | + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF"); |
| 10577 | } |
| 10578 | |
| 10579 | TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null); |
| 10580 | if (registry != null) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10581 | Phone phone = getPhone(subId); |
| 10582 | if (phone == null) { |
| 10583 | thermalMitigationResult = |
| 10584 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 10585 | break; |
| 10586 | } |
| 10587 | |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 10588 | TelephonyConnectionService service = |
| 10589 | registry.getTelephonyConnectionService(); |
Jack Nudelman | b30ac30 | 2021-06-17 15:39:58 -0700 | [diff] [blame] | 10590 | if (service != null && service.isEmergencyCallPending()) { |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 10591 | Log.e(LOG_TAG, "An emergency call is pending"); |
| 10592 | thermalMitigationResult = |
| 10593 | TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE; |
| 10594 | break; |
| 10595 | } else if (isAnyPhoneInEmergencyState()) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10596 | thermalMitigationResult = |
| 10597 | TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE; |
| 10598 | break; |
| 10599 | } |
| 10600 | } else { |
| 10601 | thermalMitigationResult = |
| 10602 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 10603 | break; |
| 10604 | } |
| 10605 | |
| 10606 | // Turn radio off. If not able to power off due to phone being unavailable, |
| 10607 | // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10608 | if (!setRadioPowerForThermal(false)) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10609 | thermalMitigationResult = |
| 10610 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 10611 | break; |
| 10612 | } |
| 10613 | thermalMitigationResult = |
| 10614 | TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 10615 | break; |
| 10616 | default: |
| 10617 | throw new IllegalArgumentException("the requested thermalMitigationAction does " |
| 10618 | + "not exist. Requested action: " + thermalMitigationAction); |
| 10619 | } |
| 10620 | } catch (IllegalArgumentException e) { |
| 10621 | throw e; |
| 10622 | } catch (Exception e) { |
| 10623 | Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e); |
| 10624 | thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 10625 | } finally { |
| 10626 | Binder.restoreCallingIdentity(identity); |
| 10627 | } |
| 10628 | |
| 10629 | if (DBG) { |
| 10630 | log("thermalMitigationRequest returning with thermalMitigationResult: " |
| 10631 | + thermalMitigationResult); |
| 10632 | } |
| 10633 | |
| 10634 | return thermalMitigationResult; |
| 10635 | } |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 10636 | |
| 10637 | /** |
| 10638 | * Set the GbaService Package Name that Telephony will bind to. |
| 10639 | * |
| 10640 | * @param subId The sim that the GbaService is associated with. |
| 10641 | * @param packageName The name of the package to be replaced with. |
| 10642 | * @return true if setting the GbaService to bind to succeeded, false if it did not. |
| 10643 | */ |
| 10644 | @Override |
| 10645 | public boolean setBoundGbaServiceOverride(int subId, String packageName) { |
| 10646 | enforceModifyPermission(); |
| 10647 | |
| 10648 | final long identity = Binder.clearCallingIdentity(); |
| 10649 | try { |
| 10650 | return getGbaManager(subId).overrideServicePackage(packageName); |
| 10651 | } finally { |
| 10652 | Binder.restoreCallingIdentity(identity); |
| 10653 | } |
| 10654 | } |
| 10655 | |
| 10656 | /** |
| 10657 | * Return the package name of the currently bound GbaService. |
| 10658 | * |
| 10659 | * @param subId The sim that the GbaService is associated with. |
| 10660 | * @return the package name of the GbaService configuration, null if GBA is not supported. |
| 10661 | */ |
| 10662 | @Override |
| 10663 | public String getBoundGbaService(int subId) { |
| 10664 | enforceReadPrivilegedPermission("getBoundGbaServicePackage"); |
| 10665 | |
| 10666 | final long identity = Binder.clearCallingIdentity(); |
| 10667 | try { |
| 10668 | return getGbaManager(subId).getServicePackage(); |
| 10669 | } finally { |
| 10670 | Binder.restoreCallingIdentity(identity); |
| 10671 | } |
| 10672 | } |
| 10673 | |
| 10674 | /** |
| 10675 | * Set the release time for telephony to unbind GbaService. |
| 10676 | * |
| 10677 | * @param subId The sim that the GbaService is associated with. |
| 10678 | * @param interval The release time to unbind GbaService by millisecond. |
| 10679 | * @return true if setting the GbaService to bind to succeeded, false if it did not. |
| 10680 | */ |
| 10681 | @Override |
| 10682 | public boolean setGbaReleaseTimeOverride(int subId, int interval) { |
| 10683 | enforceModifyPermission(); |
| 10684 | |
| 10685 | final long identity = Binder.clearCallingIdentity(); |
| 10686 | try { |
| 10687 | return getGbaManager(subId).overrideReleaseTime(interval); |
| 10688 | } finally { |
| 10689 | Binder.restoreCallingIdentity(identity); |
| 10690 | } |
| 10691 | } |
| 10692 | |
| 10693 | /** |
| 10694 | * Return the release time for telephony to unbind GbaService. |
| 10695 | * |
| 10696 | * @param subId The sim that the GbaService is associated with. |
| 10697 | * @return The release time to unbind GbaService by millisecond. |
| 10698 | */ |
| 10699 | @Override |
| 10700 | public int getGbaReleaseTime(int subId) { |
| 10701 | enforceReadPrivilegedPermission("getGbaReleaseTime"); |
| 10702 | |
| 10703 | final long identity = Binder.clearCallingIdentity(); |
| 10704 | try { |
| 10705 | return getGbaManager(subId).getReleaseTime(); |
| 10706 | } finally { |
| 10707 | Binder.restoreCallingIdentity(identity); |
| 10708 | } |
| 10709 | } |
| 10710 | |
| 10711 | private GbaManager getGbaManager(int subId) { |
| 10712 | GbaManager instance = GbaManager.getInstance(subId); |
| 10713 | if (instance == null) { |
| 10714 | String packageName = mApp.getResources().getString(R.string.config_gba_package); |
| 10715 | int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time); |
| 10716 | instance = GbaManager.make(mApp, subId, packageName, releaseTime); |
| 10717 | } |
| 10718 | return instance; |
| 10719 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10720 | |
| 10721 | /** |
| 10722 | * indicate whether the device and the carrier can support |
| 10723 | * RCS VoLTE single registration. |
| 10724 | */ |
| 10725 | @Override |
| 10726 | public boolean isRcsVolteSingleRegistrationCapable(int subId) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10727 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 10728 | Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable", |
| 10729 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 10730 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10731 | |
| 10732 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10733 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10734 | } |
| 10735 | |
| 10736 | final long identity = Binder.clearCallingIdentity(); |
| 10737 | try { |
| 10738 | RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance(); |
| 10739 | if (rpm != null) { |
Hui Wang | 67af90e | 2021-06-04 16:57:15 -0700 | [diff] [blame] | 10740 | Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId); |
| 10741 | if (isCapable != null) { |
| 10742 | return isCapable; |
| 10743 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10744 | } |
Hui Wang | 67af90e | 2021-06-04 16:57:15 -0700 | [diff] [blame] | 10745 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE, |
| 10746 | "service is temporarily unavailable."); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10747 | } finally { |
| 10748 | Binder.restoreCallingIdentity(identity); |
| 10749 | } |
| 10750 | } |
| 10751 | |
| 10752 | /** |
| 10753 | * Register RCS provisioning callback. |
| 10754 | */ |
| 10755 | @Override |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10756 | public void registerRcsProvisioningCallback(int subId, |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10757 | IRcsConfigCallback callback) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10758 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10759 | Binder.getCallingUid(), "registerRcsProvisioningCallback", |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10760 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 10761 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10762 | |
| 10763 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10764 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10765 | } |
| 10766 | if (!isImsAvailableOnDevice()) { |
| 10767 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 10768 | "IMS not available on device."); |
| 10769 | } |
| 10770 | |
| 10771 | final long identity = Binder.clearCallingIdentity(); |
| 10772 | try { |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 10773 | if (!RcsProvisioningMonitor.getInstance() |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10774 | .registerRcsProvisioningCallback(subId, callback)) { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 10775 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION, |
| 10776 | "Active subscription not found."); |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 10777 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10778 | } finally { |
| 10779 | Binder.restoreCallingIdentity(identity); |
| 10780 | } |
| 10781 | } |
| 10782 | |
| 10783 | /** |
| 10784 | * Unregister RCS provisioning callback. |
| 10785 | */ |
| 10786 | @Override |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10787 | public void unregisterRcsProvisioningCallback(int subId, |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10788 | IRcsConfigCallback callback) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10789 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10790 | Binder.getCallingUid(), "unregisterRcsProvisioningCallback", |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10791 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 10792 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10793 | |
| 10794 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10795 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10796 | } |
| 10797 | if (!isImsAvailableOnDevice()) { |
joonhunshin | 46b49a3 | 2022-12-21 05:33:23 +0000 | [diff] [blame^] | 10798 | // operation failed silently |
| 10799 | Rlog.w(LOG_TAG, "IMS not available on device."); |
| 10800 | return; |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10801 | } |
| 10802 | |
| 10803 | final long identity = Binder.clearCallingIdentity(); |
| 10804 | try { |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 10805 | RcsProvisioningMonitor.getInstance() |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10806 | .unregisterRcsProvisioningCallback(subId, callback); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10807 | } finally { |
| 10808 | Binder.restoreCallingIdentity(identity); |
| 10809 | } |
| 10810 | } |
| 10811 | |
| 10812 | /** |
| 10813 | * trigger RCS reconfiguration. |
| 10814 | */ |
| 10815 | public void triggerRcsReconfiguration(int subId) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10816 | TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(), |
| 10817 | "triggerRcsReconfiguration", |
| 10818 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10819 | |
| 10820 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10821 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10822 | } |
| 10823 | if (!isImsAvailableOnDevice()) { |
joonhunshin | 46b49a3 | 2022-12-21 05:33:23 +0000 | [diff] [blame^] | 10824 | // ProvisioningManager can not handle ServiceSpecificException. |
| 10825 | // Throw the IllegalStateException and annotate ProvisioningManager. |
| 10826 | throw new IllegalStateException("IMS not available on device."); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10827 | } |
| 10828 | |
| 10829 | final long identity = Binder.clearCallingIdentity(); |
| 10830 | try { |
| 10831 | RcsProvisioningMonitor.getInstance().requestReconfig(subId); |
| 10832 | } finally { |
| 10833 | Binder.restoreCallingIdentity(identity); |
| 10834 | } |
| 10835 | } |
| 10836 | |
| 10837 | /** |
| 10838 | * Provide the client configuration parameters of the RCS application. |
| 10839 | */ |
| 10840 | public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10841 | TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(), |
| 10842 | "setRcsClientConfiguration", |
| 10843 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10844 | |
| 10845 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10846 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10847 | } |
| 10848 | if (!isImsAvailableOnDevice()) { |
| 10849 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 10850 | "IMS not available on device."); |
| 10851 | } |
| 10852 | |
| 10853 | final long identity = Binder.clearCallingIdentity(); |
| 10854 | |
| 10855 | try { |
| 10856 | IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS); |
| 10857 | if (configBinder == null) { |
| 10858 | Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration"); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 10859 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION, |
| 10860 | "could not find the requested subscription"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10861 | } else { |
| 10862 | configBinder.setRcsClientConfiguration(rcc); |
| 10863 | } |
joonhunshin | 3e15424 | 2021-09-17 06:33:39 +0000 | [diff] [blame] | 10864 | |
| 10865 | RcsStats.getInstance().onRcsClientProvisioningStats(subId, |
| 10866 | RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10867 | } catch (RemoteException e) { |
| 10868 | Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage()); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 10869 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE, |
| 10870 | "service is temporarily unavailable."); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10871 | } finally { |
| 10872 | Binder.restoreCallingIdentity(identity); |
| 10873 | } |
| 10874 | } |
| 10875 | |
| 10876 | /** |
Hui Wang | baaee6a | 2021-02-19 20:45:36 -0800 | [diff] [blame] | 10877 | * Enables or disables the test mode for RCS VoLTE single registration. |
| 10878 | */ |
| 10879 | @Override |
| 10880 | public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) { |
| 10881 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10882 | "setRcsSingleRegistrationTestModeEnabled"); |
| 10883 | |
| 10884 | RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled); |
| 10885 | } |
| 10886 | |
| 10887 | /** |
| 10888 | * Gets the test mode for RCS VoLTE single registration. |
| 10889 | */ |
| 10890 | @Override |
| 10891 | public boolean getRcsSingleRegistrationTestModeEnabled() { |
| 10892 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10893 | "getRcsSingleRegistrationTestModeEnabled"); |
| 10894 | |
| 10895 | return RcsProvisioningMonitor.getInstance().getTestModeEnabled(); |
| 10896 | } |
| 10897 | |
| 10898 | /** |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10899 | * Overrides the config of RCS VoLTE single registration enabled for the device. |
| 10900 | */ |
| 10901 | @Override |
| 10902 | public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) { |
| 10903 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10904 | "setDeviceSingleRegistrationEnabledOverride"); |
| 10905 | enforceModifyPermission(); |
| 10906 | |
| 10907 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 10908 | : Boolean.parseBoolean(enabledStr); |
| 10909 | RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled); |
Brad Ebinger | 49a72b4 | 2021-01-29 00:55:24 +0000 | [diff] [blame] | 10910 | mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10911 | } |
| 10912 | |
| 10913 | /** |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 10914 | * Sends a device to device communication message. Only usable via shell. |
| 10915 | * @param message message to send. |
| 10916 | * @param value message value. |
| 10917 | */ |
| 10918 | @Override |
| 10919 | public void sendDeviceToDeviceMessage(int message, int value) { |
| 10920 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
Tyler Gunn | babbda0 | 2021-02-10 11:05:02 -0800 | [diff] [blame] | 10921 | "sendDeviceToDeviceMessage"); |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 10922 | enforceModifyPermission(); |
| 10923 | |
| 10924 | final long identity = Binder.clearCallingIdentity(); |
| 10925 | try { |
| 10926 | TelephonyConnectionService service = |
| 10927 | TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService(); |
| 10928 | if (service == null) { |
| 10929 | Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call."); |
| 10930 | return; |
| 10931 | } |
| 10932 | service.sendTestDeviceToDeviceMessage(message, value); |
| 10933 | } finally { |
| 10934 | Binder.restoreCallingIdentity(identity); |
| 10935 | } |
| 10936 | } |
| 10937 | |
Tyler Gunn | babbda0 | 2021-02-10 11:05:02 -0800 | [diff] [blame] | 10938 | /** |
| 10939 | * Sets the specified device to device transport active. |
| 10940 | * @param transport The transport to set active. |
| 10941 | */ |
| 10942 | @Override |
| 10943 | public void setActiveDeviceToDeviceTransport(@NonNull String transport) { |
| 10944 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10945 | "setActiveDeviceToDeviceTransport"); |
| 10946 | enforceModifyPermission(); |
| 10947 | |
| 10948 | final long identity = Binder.clearCallingIdentity(); |
| 10949 | try { |
| 10950 | TelephonyConnectionService service = |
| 10951 | TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService(); |
| 10952 | if (service == null) { |
| 10953 | Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call."); |
| 10954 | return; |
| 10955 | } |
| 10956 | service.setActiveDeviceToDeviceTransport(transport); |
| 10957 | } finally { |
| 10958 | Binder.restoreCallingIdentity(identity); |
| 10959 | } |
| 10960 | } |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 10961 | |
Tyler Gunn | d433926 | 2021-05-03 14:46:49 -0700 | [diff] [blame] | 10962 | @Override |
| 10963 | public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) { |
| 10964 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10965 | "setDeviceToDeviceForceEnabled"); |
| 10966 | |
| 10967 | final long identity = Binder.clearCallingIdentity(); |
| 10968 | try { |
| 10969 | Arrays.stream(PhoneFactory.getPhones()).forEach( |
| 10970 | p -> { |
| 10971 | Phone thePhone = p.getImsPhone(); |
| 10972 | if (thePhone != null && thePhone instanceof ImsPhone) { |
| 10973 | ImsPhone imsPhone = (ImsPhone) thePhone; |
| 10974 | CallTracker tracker = imsPhone.getCallTracker(); |
| 10975 | if (tracker != null && tracker instanceof ImsPhoneCallTracker) { |
| 10976 | ImsPhoneCallTracker imsPhoneCallTracker = |
| 10977 | (ImsPhoneCallTracker) tracker; |
| 10978 | imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled); |
| 10979 | } |
| 10980 | } |
| 10981 | } |
| 10982 | ); |
| 10983 | } finally { |
| 10984 | Binder.restoreCallingIdentity(identity); |
| 10985 | } |
| 10986 | } |
| 10987 | |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 10988 | /** |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10989 | * Gets the config of RCS VoLTE single registration enabled for the device. |
| 10990 | */ |
| 10991 | @Override |
| 10992 | public boolean getDeviceSingleRegistrationEnabled() { |
| 10993 | enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled"); |
| 10994 | return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled(); |
| 10995 | } |
| 10996 | |
| 10997 | /** |
| 10998 | * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription. |
| 10999 | */ |
| 11000 | @Override |
| 11001 | public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) { |
| 11002 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11003 | "setCarrierSingleRegistrationEnabledOverride"); |
| 11004 | enforceModifyPermission(); |
| 11005 | |
| 11006 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 11007 | : Boolean.parseBoolean(enabledStr); |
| 11008 | return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled( |
| 11009 | subId, enabled); |
| 11010 | } |
| 11011 | |
| 11012 | /** |
| 11013 | * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription. |
| 11014 | */ |
| 11015 | @Override |
| 11016 | public boolean getCarrierSingleRegistrationEnabled(int subId) { |
| 11017 | enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled"); |
| 11018 | return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId); |
| 11019 | } |
Chiachang Wang | d6d3477 | 2020-12-22 11:38:27 +0800 | [diff] [blame] | 11020 | |
| 11021 | /** |
Hui Wang | b647abe | 2021-02-26 09:33:38 -0800 | [diff] [blame] | 11022 | * Overrides the ims feature validation result |
| 11023 | */ |
| 11024 | @Override |
| 11025 | public boolean setImsFeatureValidationOverride(int subId, String enabledStr) { |
| 11026 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11027 | "setImsFeatureValidationOverride"); |
| 11028 | |
| 11029 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 11030 | : Boolean.parseBoolean(enabledStr); |
| 11031 | return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation( |
| 11032 | subId, enabled); |
| 11033 | } |
| 11034 | |
| 11035 | /** |
| 11036 | * Gets the ims feature validation override value |
| 11037 | */ |
| 11038 | @Override |
| 11039 | public boolean getImsFeatureValidationOverride(int subId) { |
| 11040 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11041 | "getImsFeatureValidationOverride"); |
| 11042 | return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId); |
| 11043 | } |
| 11044 | |
| 11045 | /** |
Chiachang Wang | d6d3477 | 2020-12-22 11:38:27 +0800 | [diff] [blame] | 11046 | * Get the mobile provisioning url that is used to launch a browser to allow users to manage |
| 11047 | * their mobile plan. |
| 11048 | */ |
| 11049 | @Override |
| 11050 | public String getMobileProvisioningUrl() { |
| 11051 | enforceReadPrivilegedPermission("getMobileProvisioningUrl"); |
| 11052 | final long identity = Binder.clearCallingIdentity(); |
| 11053 | try { |
| 11054 | return getDefaultPhone().getMobileProvisioningUrl(); |
| 11055 | } finally { |
| 11056 | Binder.restoreCallingIdentity(identity); |
| 11057 | } |
| 11058 | } |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11059 | |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 11060 | /** |
calvinpan | e4a8a1d | 2021-01-25 13:51:18 +0800 | [diff] [blame] | 11061 | * Get the EAB contact from the EAB database. |
| 11062 | */ |
| 11063 | @Override |
| 11064 | public String getContactFromEab(String contact) { |
| 11065 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab"); |
| 11066 | enforceModifyPermission(); |
| 11067 | final long identity = Binder.clearCallingIdentity(); |
| 11068 | try { |
| 11069 | return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact); |
| 11070 | } finally { |
| 11071 | Binder.restoreCallingIdentity(identity); |
| 11072 | } |
| 11073 | } |
| 11074 | |
| 11075 | /** |
Calvin Pan | a143432 | 2021-07-01 19:27:01 +0800 | [diff] [blame] | 11076 | * Get the EAB capability from the EAB database. |
| 11077 | */ |
| 11078 | @Override |
| 11079 | public String getCapabilityFromEab(String contact) { |
| 11080 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab"); |
| 11081 | enforceModifyPermission(); |
| 11082 | final long identity = Binder.clearCallingIdentity(); |
| 11083 | try { |
| 11084 | return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact); |
| 11085 | } finally { |
| 11086 | Binder.restoreCallingIdentity(identity); |
| 11087 | } |
| 11088 | } |
| 11089 | |
| 11090 | /** |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 11091 | * Remove the EAB contacts from the EAB database. |
| 11092 | */ |
| 11093 | @Override |
| 11094 | public int removeContactFromEab(int subId, String contacts) { |
| 11095 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab"); |
| 11096 | enforceModifyPermission(); |
| 11097 | final long identity = Binder.clearCallingIdentity(); |
| 11098 | try { |
| 11099 | return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext()); |
| 11100 | } finally { |
| 11101 | Binder.restoreCallingIdentity(identity); |
| 11102 | } |
| 11103 | } |
| 11104 | |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11105 | @Override |
James.cf Lin | 4b784aa | 2021-01-31 03:25:15 +0800 | [diff] [blame] | 11106 | public boolean getDeviceUceEnabled() { |
| 11107 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled"); |
| 11108 | final long identity = Binder.clearCallingIdentity(); |
| 11109 | try { |
| 11110 | return mApp.getDeviceUceEnabled(); |
| 11111 | } finally { |
| 11112 | Binder.restoreCallingIdentity(identity); |
| 11113 | } |
| 11114 | } |
| 11115 | |
| 11116 | @Override |
| 11117 | public void setDeviceUceEnabled(boolean isEnabled) { |
| 11118 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled"); |
| 11119 | final long identity = Binder.clearCallingIdentity(); |
| 11120 | try { |
| 11121 | mApp.setDeviceUceEnabled(isEnabled); |
| 11122 | } finally { |
| 11123 | Binder.restoreCallingIdentity(identity); |
| 11124 | } |
| 11125 | } |
| 11126 | |
Brad Ebinger | 14d467f | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 11127 | /** |
| 11128 | * Add new feature tags to the Set used to calculate the capabilities in PUBLISH. |
| 11129 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 11130 | */ |
| 11131 | // Used for SHELL command only right now. |
| 11132 | @Override |
| 11133 | public RcsContactUceCapability addUceRegistrationOverrideShell(int subId, |
| 11134 | List<String> featureTags) { |
| 11135 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11136 | "addUceRegistrationOverrideShell"); |
| 11137 | final long identity = Binder.clearCallingIdentity(); |
| 11138 | try { |
| 11139 | return mApp.imsRcsController.addUceRegistrationOverrideShell(subId, |
| 11140 | new ArraySet<>(featureTags)); |
| 11141 | } catch (ImsException e) { |
| 11142 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 11143 | } finally { |
| 11144 | Binder.restoreCallingIdentity(identity); |
| 11145 | } |
| 11146 | } |
| 11147 | |
| 11148 | /** |
| 11149 | * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH. |
| 11150 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 11151 | */ |
| 11152 | // Used for SHELL command only right now. |
| 11153 | @Override |
| 11154 | public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId, |
| 11155 | List<String> featureTags) { |
| 11156 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11157 | "removeUceRegistrationOverrideShell"); |
| 11158 | final long identity = Binder.clearCallingIdentity(); |
| 11159 | try { |
| 11160 | return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId, |
| 11161 | new ArraySet<>(featureTags)); |
| 11162 | } catch (ImsException e) { |
| 11163 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 11164 | } finally { |
| 11165 | Binder.restoreCallingIdentity(identity); |
| 11166 | } |
| 11167 | } |
| 11168 | |
| 11169 | /** |
| 11170 | * Clear all overrides in the Set used to calculate the capabilities in PUBLISH. |
| 11171 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 11172 | */ |
| 11173 | // Used for SHELL command only right now. |
| 11174 | @Override |
| 11175 | public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) { |
| 11176 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11177 | "clearUceRegistrationOverrideShell"); |
| 11178 | final long identity = Binder.clearCallingIdentity(); |
| 11179 | try { |
| 11180 | return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId); |
| 11181 | } catch (ImsException e) { |
| 11182 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 11183 | } finally { |
| 11184 | Binder.restoreCallingIdentity(identity); |
| 11185 | } |
| 11186 | } |
| 11187 | |
| 11188 | /** |
| 11189 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 11190 | */ |
| 11191 | // Used for SHELL command only right now. |
| 11192 | @Override |
| 11193 | public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) { |
| 11194 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11195 | "getLatestRcsContactUceCapabilityShell"); |
| 11196 | final long identity = Binder.clearCallingIdentity(); |
| 11197 | try { |
| 11198 | return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId); |
| 11199 | } catch (ImsException e) { |
| 11200 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 11201 | } finally { |
| 11202 | Binder.restoreCallingIdentity(identity); |
| 11203 | } |
| 11204 | } |
| 11205 | |
| 11206 | /** |
| 11207 | * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the |
| 11208 | * device does not have an active PUBLISH. |
| 11209 | */ |
| 11210 | // Used for SHELL command only right now. |
| 11211 | @Override |
| 11212 | public String getLastUcePidfXmlShell(int subId) { |
| 11213 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml"); |
| 11214 | final long identity = Binder.clearCallingIdentity(); |
| 11215 | try { |
| 11216 | return mApp.imsRcsController.getLastUcePidfXmlShell(subId); |
| 11217 | } catch (ImsException e) { |
| 11218 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 11219 | } finally { |
| 11220 | Binder.restoreCallingIdentity(identity); |
| 11221 | } |
| 11222 | } |
| 11223 | |
James.cf Lin | e8713a4 | 2021-04-29 16:04:26 +0800 | [diff] [blame] | 11224 | /** |
| 11225 | * Remove UCE requests cannot be sent to the network status. |
| 11226 | */ |
| 11227 | // Used for SHELL command only right now. |
| 11228 | @Override |
| 11229 | public boolean removeUceRequestDisallowedStatus(int subId) { |
| 11230 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus"); |
| 11231 | final long identity = Binder.clearCallingIdentity(); |
| 11232 | try { |
| 11233 | return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId); |
| 11234 | } catch (ImsException e) { |
| 11235 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 11236 | } finally { |
| 11237 | Binder.restoreCallingIdentity(identity); |
| 11238 | } |
| 11239 | } |
| 11240 | |
James.cf Lin | 18bb900 | 2021-05-25 01:37:38 +0800 | [diff] [blame] | 11241 | /** |
| 11242 | * Remove UCE requests cannot be sent to the network status. |
| 11243 | */ |
| 11244 | // Used for SHELL command only. |
| 11245 | @Override |
| 11246 | public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) { |
| 11247 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout"); |
| 11248 | final long identity = Binder.clearCallingIdentity(); |
| 11249 | try { |
| 11250 | return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs); |
| 11251 | } catch (ImsException e) { |
| 11252 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 11253 | } finally { |
| 11254 | Binder.restoreCallingIdentity(identity); |
| 11255 | } |
| 11256 | } |
Brad Ebinger | 14d467f | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 11257 | |
James.cf Lin | 4b784aa | 2021-01-31 03:25:15 +0800 | [diff] [blame] | 11258 | @Override |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11259 | public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request, |
| 11260 | String callingPackage) { |
| 11261 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 11262 | mApp, subId, "setSignalStrengthUpdateRequest"); |
| 11263 | |
| 11264 | final int callingUid = Binder.getCallingUid(); |
| 11265 | // Verify that tha callingPackage belongs to the calling UID |
| 11266 | mApp.getSystemService(AppOpsManager.class) |
| 11267 | .checkPackage(callingUid, callingPackage); |
| 11268 | |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 11269 | validateSignalStrengthUpdateRequest(mApp, request, callingUid); |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11270 | |
| 11271 | final long identity = Binder.clearCallingIdentity(); |
| 11272 | try { |
| 11273 | Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST, |
| 11274 | new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId); |
| 11275 | |
| 11276 | if (result instanceof IllegalStateException) { |
| 11277 | throw (IllegalStateException) result; |
| 11278 | } |
| 11279 | } finally { |
| 11280 | Binder.restoreCallingIdentity(identity); |
| 11281 | } |
| 11282 | } |
| 11283 | |
| 11284 | @Override |
| 11285 | public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request, |
| 11286 | String callingPackage) { |
| 11287 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 11288 | mApp, subId, "clearSignalStrengthUpdateRequest"); |
| 11289 | |
| 11290 | final int callingUid = Binder.getCallingUid(); |
| 11291 | // Verify that tha callingPackage belongs to the calling UID |
| 11292 | mApp.getSystemService(AppOpsManager.class) |
| 11293 | .checkPackage(callingUid, callingPackage); |
| 11294 | |
| 11295 | final long identity = Binder.clearCallingIdentity(); |
| 11296 | try { |
| 11297 | Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST, |
| 11298 | new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId); |
| 11299 | |
| 11300 | if (result instanceof IllegalStateException) { |
| 11301 | throw (IllegalStateException) result; |
| 11302 | } |
| 11303 | } finally { |
| 11304 | Binder.restoreCallingIdentity(identity); |
| 11305 | } |
| 11306 | } |
| 11307 | |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 11308 | private static void validateSignalStrengthUpdateRequest(Context context, |
| 11309 | SignalStrengthUpdateRequest request, int callingUid) { |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11310 | if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) { |
| 11311 | // phone/system process do not have further restriction on request |
| 11312 | return; |
| 11313 | } |
| 11314 | |
| 11315 | // Applications has restrictions on how to use the request: |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 11316 | // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11317 | if (request.isSystemThresholdReportingRequestedWhileIdle()) { |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 11318 | context.enforceCallingOrSelfPermission( |
| 11319 | android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH, |
| 11320 | "validateSignalStrengthUpdateRequest"); |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11321 | } |
| 11322 | |
| 11323 | for (SignalThresholdInfo info : request.getSignalThresholdInfos()) { |
Nagendra Prasad Nagarle Basavaraju | fee544c | 2022-12-07 16:34:52 +0000 | [diff] [blame] | 11324 | // Only system caller can set mHysteresisMs/mIsEnabled. |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11325 | if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11326 | || info.isEnabled()) { |
| 11327 | throw new IllegalArgumentException( |
| 11328 | "Only system can set hide fields in SignalThresholdInfo"); |
| 11329 | } |
| 11330 | |
| 11331 | // Thresholds length for each RAN need in range. This has been validated in |
| 11332 | // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method |
| 11333 | // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds |
| 11334 | final int[] thresholds = info.getThresholds(); |
| 11335 | Objects.requireNonNull(thresholds); |
| 11336 | if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed() |
| 11337 | || thresholds.length |
| 11338 | > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) { |
| 11339 | throw new IllegalArgumentException( |
| 11340 | "thresholds length is out of range: " + thresholds.length); |
| 11341 | } |
| 11342 | } |
| 11343 | } |
SongFerngWang | 8236caa | 2021-01-17 21:51:44 +0800 | [diff] [blame] | 11344 | |
| 11345 | /** |
| 11346 | * Gets the current phone capability. |
| 11347 | * |
| 11348 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 11349 | * @return the PhoneCapability which describes the data connection capability of modem. |
| 11350 | * It's used to evaluate possible phone config change, for example from single |
| 11351 | * SIM device to multi-SIM device. |
| 11352 | */ |
| 11353 | @Override |
| 11354 | public PhoneCapability getPhoneCapability() { |
| 11355 | enforceReadPrivilegedPermission("getPhoneCapability"); |
| 11356 | final long identity = Binder.clearCallingIdentity(); |
| 11357 | try { |
| 11358 | return mPhoneConfigurationManager.getCurrentPhoneCapability(); |
| 11359 | } finally { |
| 11360 | Binder.restoreCallingIdentity(identity); |
| 11361 | } |
| 11362 | } |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 11363 | |
| 11364 | /** |
| 11365 | * Prepare TelephonyManager for an unattended reboot. The reboot is |
| 11366 | * required to be done shortly after the API is invoked. |
| 11367 | */ |
| 11368 | @Override |
| 11369 | @TelephonyManager.PrepareUnattendedRebootResult |
| 11370 | public int prepareForUnattendedReboot() { |
Rafael Higuera Silva | d963064 | 2021-09-20 15:32:01 +0000 | [diff] [blame] | 11371 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 11372 | enforceRebootPermission(); |
| 11373 | |
| 11374 | final long identity = Binder.clearCallingIdentity(); |
| 11375 | try { |
Rafael Higuera Silva | d963064 | 2021-09-20 15:32:01 +0000 | [diff] [blame] | 11376 | return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 11377 | } finally { |
| 11378 | Binder.restoreCallingIdentity(identity); |
| 11379 | } |
| 11380 | } |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 11381 | |
| 11382 | /** |
| 11383 | * Request to get the current slicing configuration including URSP rules and |
| 11384 | * NSSAIs (configured, allowed and rejected). |
| 11385 | * |
| 11386 | * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission. |
| 11387 | */ |
| 11388 | @Override |
| 11389 | public void getSlicingConfig(ResultReceiver callback) { |
Hongbo Zeng | 1b2063d | 2022-02-21 01:33:03 +0000 | [diff] [blame] | 11390 | TelephonyPermissions |
| 11391 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 11392 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, "getSlicingConfig"); |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 11393 | |
| 11394 | final long identity = Binder.clearCallingIdentity(); |
| 11395 | try { |
| 11396 | Phone phone = getDefaultPhone(); |
| 11397 | sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null); |
| 11398 | } finally { |
| 11399 | Binder.restoreCallingIdentity(identity); |
| 11400 | } |
| 11401 | } |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 11402 | |
| 11403 | /** |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 11404 | * Check whether the given premium capability is available for purchase from the carrier. |
| 11405 | * |
| 11406 | * @param capability The premium capability to check. |
| 11407 | * @param subId The subId to check the premium capability for. |
| 11408 | * |
| 11409 | * @return Whether the given premium capability is available to purchase. |
| 11410 | */ |
| 11411 | @Override |
| 11412 | public boolean isPremiumCapabilityAvailableForPurchase(int capability, int subId) { |
| 11413 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 11414 | mApp, "isPremiumCapabilityAvailableForPurchase")) { |
| 11415 | log("Premium capability " |
| 11416 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 11417 | + " is not available for purchase due to missing permissions."); |
| 11418 | throw new SecurityException("isPremiumCapabilityAvailableForPurchase requires " |
| 11419 | + "permission READ_BASIC_PHONE_STATE."); |
| 11420 | } |
| 11421 | |
| 11422 | Phone phone = getPhone(subId); |
Thomas Nguyen | 7216ed6 | 2022-11-29 16:45:31 -0800 | [diff] [blame] | 11423 | if (phone == null) { |
| 11424 | loge("isPremiumCapabilityAvailableForPurchase: phone is null, subId=" + subId); |
| 11425 | return false; |
| 11426 | } |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 11427 | final long identity = Binder.clearCallingIdentity(); |
| 11428 | try { |
Sarah Chin | 46355ba | 2022-11-01 23:51:16 -0700 | [diff] [blame] | 11429 | return SlicePurchaseController.getInstance(phone) |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 11430 | .isPremiumCapabilityAvailableForPurchase(capability); |
| 11431 | } finally { |
| 11432 | Binder.restoreCallingIdentity(identity); |
| 11433 | } |
| 11434 | } |
| 11435 | |
| 11436 | /** |
| 11437 | * Purchase the given premium capability from the carrier. |
| 11438 | * |
| 11439 | * @param capability The premium capability to purchase. |
| 11440 | * @param callback The result of the purchase request. |
| 11441 | * @param subId The subId to purchase the premium capability for. |
| 11442 | */ |
| 11443 | @Override |
| 11444 | public void purchasePremiumCapability(int capability, IIntegerConsumer callback, int subId) { |
| 11445 | log("purchasePremiumCapability: capability=" |
| 11446 | + TelephonyManager.convertPremiumCapabilityToString(capability) + ", caller=" |
| 11447 | + getCurrentPackageName()); |
| 11448 | |
| 11449 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 11450 | mApp, "purchasePremiumCapability")) { |
| 11451 | log("purchasePremiumCapability " |
| 11452 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 11453 | + " failed due to missing permissions."); |
| 11454 | throw new SecurityException("purchasePremiumCapability requires permission " |
| 11455 | + "READ_BASIC_PHONE_STATE."); |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 11456 | } else if (!TelephonyPermissions.checkInternetPermissionNoThrow( |
| 11457 | mApp, "purchasePremiumCapability")) { |
| 11458 | log("purchasePremiumCapability " |
| 11459 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 11460 | + " failed due to missing permissions."); |
| 11461 | throw new SecurityException("purchasePremiumCapability requires permission INTERNET."); |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 11462 | } |
| 11463 | |
| 11464 | Phone phone = getPhone(subId); |
Sarah Chin | 1969411 | 2022-12-06 15:41:37 -0800 | [diff] [blame] | 11465 | if (phone == null) { |
| 11466 | try { |
| 11467 | int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_REQUEST_FAILED; |
| 11468 | callback.accept(result); |
| 11469 | loge("purchasePremiumCapability: phone is null, subId=" + subId); |
| 11470 | } catch (RemoteException e) { |
| 11471 | String logStr = "Purchase premium capability " |
| 11472 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 11473 | + " failed due to RemoteException handling null phone: " + e; |
| 11474 | if (DBG) log(logStr); |
| 11475 | AnomalyReporter.reportAnomaly( |
| 11476 | UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr); |
| 11477 | } |
| 11478 | return; |
| 11479 | } |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 11480 | |
| 11481 | String callingProcess; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 11482 | try { |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 11483 | callingProcess = mApp.getPackageManager().getApplicationInfo( |
| 11484 | getCurrentPackageName(), 0).processName; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 11485 | } catch (PackageManager.NameNotFoundException e) { |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 11486 | callingProcess = getCurrentPackageName(); |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 11487 | } |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 11488 | |
| 11489 | boolean isVisible = false; |
| 11490 | ActivityManager am = mApp.getSystemService(ActivityManager.class); |
| 11491 | if (am != null) { |
| 11492 | List<ActivityManager.RunningAppProcessInfo> processes = am.getRunningAppProcesses(); |
| 11493 | if (processes != null) { |
| 11494 | for (ActivityManager.RunningAppProcessInfo process : processes) { |
| 11495 | log("purchasePremiumCapability: process " + process.processName |
| 11496 | + "has importance " + process.importance); |
| 11497 | if (process.processName.equals(callingProcess) && process.importance |
| 11498 | <= ActivityManager.RunningAppProcessInfo.IMPORTANCE_VISIBLE) { |
| 11499 | isVisible = true; |
| 11500 | break; |
| 11501 | } |
| 11502 | } |
| 11503 | } |
| 11504 | } |
| 11505 | |
| 11506 | if (!isVisible) { |
| 11507 | try { |
| 11508 | int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_NOT_FOREGROUND; |
| 11509 | callback.accept(result); |
| 11510 | loge("purchasePremiumCapability: " + callingProcess + " is not in the foreground."); |
| 11511 | } catch (RemoteException e) { |
| 11512 | String logStr = "Purchase premium capability " |
| 11513 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 11514 | + " failed due to RemoteException handling background application: " + e; |
| 11515 | if (DBG) log(logStr); |
| 11516 | AnomalyReporter.reportAnomaly( |
| 11517 | UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr); |
| 11518 | } |
| 11519 | return; |
| 11520 | } |
| 11521 | |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 11522 | sendRequestAsync(CMD_PURCHASE_PREMIUM_CAPABILITY, |
Sarah Chin | b8218c2 | 2023-01-04 13:35:29 -0800 | [diff] [blame] | 11523 | new PurchasePremiumCapabilityArgument(capability, callback), phone, null); |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 11524 | } |
| 11525 | |
| 11526 | /** |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 11527 | * Register an IMS connection state callback |
| 11528 | */ |
| 11529 | @Override |
Hunsuk Choi | 89bd22c | 2021-11-01 13:04:54 +0000 | [diff] [blame] | 11530 | public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb, |
| 11531 | String callingPackage) { |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 11532 | if (feature == ImsFeature.FEATURE_MMTEL) { |
| 11533 | // ImsMmTelManager |
| 11534 | // The following also checks READ_PRIVILEGED_PHONE_STATE. |
| 11535 | TelephonyPermissions |
| 11536 | .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 11537 | mApp, subId, "registerImsStateCallback"); |
| 11538 | } else if (feature == ImsFeature.FEATURE_RCS) { |
| 11539 | // ImsRcsManager or SipDelegateManager |
| 11540 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 11541 | Binder.getCallingUid(), "registerImsStateCallback", |
| 11542 | Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
| 11543 | Manifest.permission.READ_PRECISE_PHONE_STATE, |
| 11544 | Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE, |
| 11545 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
| 11546 | } |
| 11547 | |
| 11548 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 11549 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 11550 | "IMS not available on device."); |
| 11551 | } |
| 11552 | |
| 11553 | if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) { |
| 11554 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 11555 | } |
| 11556 | |
| 11557 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 11558 | if (controller == null) { |
| 11559 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 11560 | "IMS not available on device."); |
| 11561 | } |
| 11562 | |
Hunsuk Choi | 89bd22c | 2021-11-01 13:04:54 +0000 | [diff] [blame] | 11563 | if (callingPackage == null) { |
| 11564 | callingPackage = getCurrentPackageName(); |
| 11565 | } |
| 11566 | |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 11567 | final long token = Binder.clearCallingIdentity(); |
| 11568 | try { |
| 11569 | int slotId = getSlotIndexOrException(subId); |
Hunsuk Choi | 89bd22c | 2021-11-01 13:04:54 +0000 | [diff] [blame] | 11570 | controller.registerImsStateCallback(subId, feature, cb, callingPackage); |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 11571 | } catch (ImsException e) { |
| 11572 | throw new ServiceSpecificException(e.getCode()); |
| 11573 | } finally { |
| 11574 | Binder.restoreCallingIdentity(token); |
| 11575 | } |
| 11576 | } |
| 11577 | |
| 11578 | /** |
| 11579 | * Unregister an IMS connection state callback |
| 11580 | */ |
| 11581 | @Override |
| 11582 | public void unregisterImsStateCallback(IImsStateCallback cb) { |
| 11583 | final long token = Binder.clearCallingIdentity(); |
| 11584 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 11585 | if (controller == null) { |
| 11586 | return; |
| 11587 | } |
| 11588 | try { |
| 11589 | controller.unregisterImsStateCallback(cb); |
| 11590 | } finally { |
| 11591 | Binder.restoreCallingIdentity(token); |
| 11592 | } |
| 11593 | } |
Sooraj Sasindran | fae41b3 | 2021-10-26 02:10:05 -0700 | [diff] [blame] | 11594 | |
| 11595 | /** |
| 11596 | * @return {@CellIdentity} last known cell identity {@CellIdentity}. |
| 11597 | * |
| 11598 | * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and |
| 11599 | * com.android.phone.permission.ACCESS_LAST_KNOWN_CELL_ID, otherwise throws |
| 11600 | * SecurityException. |
| 11601 | * If there is current registered network this value will be same as the registered cell |
| 11602 | * identity. If the device goes out of service the previous cell identity is cached and |
| 11603 | * will be returned. If the cache age of the Cell identity is more than 24 hours |
| 11604 | * it will be cleared and null will be returned. |
| 11605 | * |
| 11606 | */ |
| 11607 | @Override |
| 11608 | public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage, |
| 11609 | String callingFeatureId) { |
| 11610 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 11611 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 11612 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 11613 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 11614 | .setCallingPackage(callingPackage) |
| 11615 | .setCallingFeatureId(callingFeatureId) |
| 11616 | .setCallingPid(Binder.getCallingPid()) |
| 11617 | .setCallingUid(Binder.getCallingUid()) |
| 11618 | .setMethod("getLastKnownCellIdentity") |
| 11619 | .setLogAsInfo(true) |
| 11620 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 11621 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 11622 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 11623 | .build()); |
| 11624 | |
| 11625 | boolean hasFinePermission = |
| 11626 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 11627 | if (!hasFinePermission |
| 11628 | || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) { |
| 11629 | throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION " |
Rambo Wang | 918993a | 2022-04-27 09:08:36 -0700 | [diff] [blame] | 11630 | + "and ACCESS_LAST_KNOWN_CELL_ID permission."); |
Sooraj Sasindran | fae41b3 | 2021-10-26 02:10:05 -0700 | [diff] [blame] | 11631 | } |
| 11632 | |
| 11633 | final long identity = Binder.clearCallingIdentity(); |
| 11634 | try { |
| 11635 | Phone phone = getPhone(subId); |
| 11636 | if (phone == null) return null; |
| 11637 | ServiceStateTracker sst = phone.getServiceStateTracker(); |
| 11638 | if (sst == null) return null; |
| 11639 | return sst.getLastKnownCellIdentity(); |
| 11640 | } finally { |
| 11641 | Binder.restoreCallingIdentity(identity); |
| 11642 | } |
| 11643 | } |
Jack Yu | 4c0a550 | 2021-12-03 23:58:26 -0800 | [diff] [blame] | 11644 | |
jimsun | 3b9ccac | 2021-10-26 15:01:23 +0800 | [diff] [blame] | 11645 | /** |
| 11646 | * Sets the modem service class Name that Telephony will bind to. |
| 11647 | * |
| 11648 | * @param serviceName The class name of the modem service. |
| 11649 | * @return true if the operation is succeed, otherwise false. |
| 11650 | */ |
| 11651 | public boolean setModemService(String serviceName) { |
| 11652 | Log.d(LOG_TAG, "setModemService - " + serviceName); |
| 11653 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService"); |
| 11654 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 11655 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 11656 | "setModemService"); |
| 11657 | return mPhoneConfigurationManager.setModemService(serviceName); |
| 11658 | } |
| 11659 | |
| 11660 | /** |
| 11661 | * Return the class name of the currently bounded modem service. |
| 11662 | * |
| 11663 | * @return the class name of the modem service. |
| 11664 | */ |
| 11665 | public String getModemService() { |
| 11666 | String result; |
| 11667 | Log.d(LOG_TAG, "getModemService"); |
| 11668 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService"); |
| 11669 | TelephonyPermissions |
| 11670 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 11671 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 11672 | "getModemService"); |
| 11673 | result = mPhoneConfigurationManager.getModemService(); |
| 11674 | Log.d(LOG_TAG, "result = " + result); |
| 11675 | return result; |
| 11676 | } |
Hunter Knepshield | 2b076fa | 2022-01-19 02:26:22 -0800 | [diff] [blame] | 11677 | |
| 11678 | @Override |
| 11679 | public void setVoiceServiceStateOverride(int subId, boolean hasService, String callingPackage) { |
| 11680 | // Only telecom (and shell, for CTS purposes) is allowed to call this method. |
| 11681 | mApp.enforceCallingOrSelfPermission( |
| 11682 | permission.BIND_TELECOM_CONNECTION_SERVICE, "setVoiceServiceStateOverride"); |
| 11683 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 11684 | |
| 11685 | final long identity = Binder.clearCallingIdentity(); |
| 11686 | try { |
| 11687 | Phone phone = getPhone(subId); |
| 11688 | if (phone == null) return; |
| 11689 | phone.setVoiceServiceStateOverride(hasService); |
| 11690 | } finally { |
| 11691 | Binder.restoreCallingIdentity(identity); |
| 11692 | } |
| 11693 | } |
Muralidhar Reddy | 4e5a801 | 2022-05-11 14:49:00 +0000 | [diff] [blame] | 11694 | |
| 11695 | /** |
| 11696 | * set removable eSIM as default eUICC. |
| 11697 | * |
| 11698 | * @hide |
| 11699 | */ |
| 11700 | @Override |
| 11701 | public void setRemovableEsimAsDefaultEuicc(boolean isDefault, String callingPackage) { |
| 11702 | enforceModifyPermission(); |
| 11703 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 11704 | |
| 11705 | final long identity = Binder.clearCallingIdentity(); |
| 11706 | try { |
| 11707 | UiccController.getInstance().setRemovableEsimAsDefaultEuicc(isDefault); |
| 11708 | } finally { |
| 11709 | Binder.restoreCallingIdentity(identity); |
| 11710 | } |
| 11711 | } |
| 11712 | |
| 11713 | /** |
| 11714 | * Returns whether the removable eSIM is default eUICC or not. |
| 11715 | * |
| 11716 | * @hide |
| 11717 | */ |
| 11718 | @Override |
| 11719 | public boolean isRemovableEsimDefaultEuicc(String callingPackage) { |
| 11720 | enforceReadPrivilegedPermission("isRemovableEsimDefaultEuicc"); |
| 11721 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 11722 | |
| 11723 | final long identity = Binder.clearCallingIdentity(); |
| 11724 | try { |
| 11725 | return UiccController.getInstance().isRemovableEsimDefaultEuicc(); |
| 11726 | } finally { |
| 11727 | Binder.restoreCallingIdentity(identity); |
| 11728 | } |
| 11729 | } |
| 11730 | |
Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame] | 11731 | /** |
| 11732 | * Get the component name of the default app to direct respond-via-message intent for the |
| 11733 | * user associated with this subscription, update the cache if there is no respond-via-message |
| 11734 | * application currently configured for this user. |
| 11735 | * @return component name of the app and class to direct Respond Via Message intent to, or |
| 11736 | * {@code null} if the functionality is not supported. |
| 11737 | * @hide |
| 11738 | */ |
| 11739 | @Override |
| 11740 | public @Nullable ComponentName getDefaultRespondViaMessageApplication(int subId, |
| 11741 | boolean updateIfNeeded) { |
| 11742 | enforceInteractAcrossUsersPermission("getDefaultRespondViaMessageApplication"); |
Muralidhar Reddy | 4e5a801 | 2022-05-11 14:49:00 +0000 | [diff] [blame] | 11743 | |
Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame] | 11744 | Context context = getPhone(subId).getContext(); |
| 11745 | UserHandle userHandle = null; |
| 11746 | final long identity = Binder.clearCallingIdentity(); |
| 11747 | try { |
| 11748 | userHandle = TelephonyUtils.getSubscriptionUserHandle(context, subId); |
| 11749 | } finally { |
| 11750 | Binder.restoreCallingIdentity(identity); |
| 11751 | } |
| 11752 | return SmsApplication.getDefaultRespondViaMessageApplicationAsUser(context, |
| 11753 | updateIfNeeded, userHandle); |
| 11754 | } |
Jack Yu | f5badd9 | 2022-12-08 00:50:53 -0800 | [diff] [blame] | 11755 | |
| 11756 | /** |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 11757 | * Set whether the device is able to connect with null ciphering or integrity |
| 11758 | * algorithms. This is a global setting and will apply to all active subscriptions |
| 11759 | * and all new subscriptions after this. |
| 11760 | * |
| 11761 | * @param enabled when true, null cipher and integrity algorithms are allowed. |
| 11762 | * @hide |
| 11763 | */ |
| 11764 | @Override |
| 11765 | @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 11766 | public void setNullCipherAndIntegrityEnabled(boolean enabled) { |
| 11767 | enforceModifyPermission(); |
| 11768 | checkForNullCipherAndIntegritySupport(); |
| 11769 | |
| 11770 | // Persist the state of our preference. Each GsmCdmaPhone instance is responsible |
| 11771 | // for listening to these preference changes and applying them immediately. |
| 11772 | SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 11773 | editor.putBoolean(Phone.PREF_NULL_CIPHER_AND_INTEGRITY_ENABLED, enabled); |
| 11774 | editor.apply(); |
| 11775 | |
| 11776 | for (Phone phone: PhoneFactory.getPhones()) { |
| 11777 | phone.handleNullCipherEnabledChange(); |
| 11778 | } |
| 11779 | } |
| 11780 | |
| 11781 | |
| 11782 | /** |
| 11783 | * Get whether the device is able to connect with null ciphering or integrity |
| 11784 | * algorithms. Note that this retrieves the phone-global preference and not |
| 11785 | * the state of the radio. |
| 11786 | * |
| 11787 | * @throws SecurityException if {@link permission#MODIFY_PHONE_STATE} is not satisfied |
| 11788 | * @throws UnsupportedOperationException if the device does not support the minimum HAL |
| 11789 | * version for this feature. |
| 11790 | * @hide |
| 11791 | */ |
| 11792 | @Override |
| 11793 | @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) |
| 11794 | public boolean isNullCipherAndIntegrityPreferenceEnabled() { |
| 11795 | enforceReadPermission(); |
| 11796 | checkForNullCipherAndIntegritySupport(); |
| 11797 | return getDefaultPhone().getNullCipherAndIntegrityEnabledPreference(); |
| 11798 | } |
| 11799 | |
| 11800 | private void checkForNullCipherAndIntegritySupport() { |
| 11801 | if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_NULL_CIPHER_AND_INTEGRITY_VERSION) { |
| 11802 | throw new UnsupportedOperationException( |
| 11803 | "Null cipher and integrity operations require HAL 2.1 or above"); |
| 11804 | } |
Gil Cukierman | 92cc7db | 2023-01-06 19:25:53 +0000 | [diff] [blame] | 11805 | if (!getDefaultPhone().isNullCipherAndIntegritySupported()) { |
| 11806 | throw new UnsupportedOperationException( |
| 11807 | "Null cipher and integrity operations unsupported by modem"); |
| 11808 | } |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 11809 | } |
| 11810 | |
| 11811 | /** |
Jack Yu | f5badd9 | 2022-12-08 00:50:53 -0800 | [diff] [blame] | 11812 | * Get the SIM state for the slot index. |
| 11813 | * For Remote-SIMs, this method returns {@link IccCardConstants.State#UNKNOWN} |
| 11814 | * |
| 11815 | * @return SIM state as the ordinal of {@link IccCardConstants.State} |
| 11816 | */ |
| 11817 | @Override |
| 11818 | @SimState |
| 11819 | public int getSimStateForSlotIndex(int slotIndex) { |
| 11820 | IccCardConstants.State simState; |
| 11821 | if (slotIndex < 0) { |
| 11822 | simState = IccCardConstants.State.UNKNOWN; |
| 11823 | } else { |
| 11824 | Phone phone = null; |
| 11825 | try { |
| 11826 | phone = PhoneFactory.getPhone(slotIndex); |
| 11827 | } catch (IllegalStateException e) { |
| 11828 | // ignore |
| 11829 | } |
| 11830 | if (phone == null) { |
| 11831 | simState = IccCardConstants.State.UNKNOWN; |
| 11832 | } else { |
| 11833 | IccCard icc = phone.getIccCard(); |
| 11834 | if (icc == null) { |
| 11835 | simState = IccCardConstants.State.UNKNOWN; |
| 11836 | } else { |
| 11837 | simState = icc.getState(); |
| 11838 | } |
| 11839 | } |
| 11840 | } |
| 11841 | return simState.ordinal(); |
| 11842 | } |
Hui Wang | 9b5793a | 2022-12-05 14:38:06 -0600 | [diff] [blame] | 11843 | |
| 11844 | /** |
| 11845 | * Get current cell broadcast ranges. |
| 11846 | */ |
| 11847 | @Override |
| 11848 | @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS) |
| 11849 | public List<CellBroadcastIdRange> getCellBroadcastIdRanges(int subId) { |
| 11850 | mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS, |
| 11851 | "getCellBroadcastIdRanges"); |
| 11852 | final long identity = Binder.clearCallingIdentity(); |
| 11853 | try { |
| 11854 | return getPhone(subId).getCellBroadcastIdRanges(); |
| 11855 | } finally { |
| 11856 | Binder.restoreCallingIdentity(identity); |
| 11857 | } |
| 11858 | } |
| 11859 | |
| 11860 | /** |
| 11861 | * Set reception of cell broadcast messages with the list of the given ranges |
| 11862 | * |
| 11863 | * @param ranges the list of {@link CellBroadcastIdRange} to be enabled |
| 11864 | */ |
| 11865 | @Override |
| 11866 | @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS) |
| 11867 | public void setCellBroadcastIdRanges(int subId, @NonNull List<CellBroadcastIdRange> ranges, |
| 11868 | @Nullable IIntegerConsumer callback) { |
| 11869 | mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS, |
| 11870 | "setCellBroadcastIdRanges"); |
| 11871 | final long identity = Binder.clearCallingIdentity(); |
| 11872 | try { |
| 11873 | Phone phone = getPhoneFromSubId(subId); |
| 11874 | if (DBG) { |
| 11875 | log("setCellBroadcastIdRanges for subId :" + subId + ", phone:" + phone); |
| 11876 | } |
| 11877 | phone.setCellBroadcastIdRanges(ranges, result -> { |
| 11878 | if (callback != null) { |
| 11879 | try { |
| 11880 | callback.accept(result); |
| 11881 | } catch (RemoteException e) { |
| 11882 | Log.w(LOG_TAG, "setCellBroadcastIdRanges: callback not available."); |
| 11883 | } |
| 11884 | } |
| 11885 | }); |
| 11886 | } finally { |
| 11887 | Binder.restoreCallingIdentity(identity); |
| 11888 | } |
| 11889 | } |
Hunsuk Choi | 42cc62a | 2022-10-16 06:03:40 +0000 | [diff] [blame] | 11890 | |
| 11891 | /** |
| 11892 | * Returns whether the device supports the domain selection service. |
| 11893 | * |
| 11894 | * @return {@code true} if the device supports the domain selection service. |
| 11895 | */ |
| 11896 | @Override |
| 11897 | public boolean isDomainSelectionSupported() { |
| 11898 | mApp.enforceCallingOrSelfPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
| 11899 | "isDomainSelectionSupported"); |
| 11900 | |
| 11901 | final long identity = Binder.clearCallingIdentity(); |
| 11902 | try { |
| 11903 | return DomainSelectionResolver.getInstance().isDomainSelectionSupported(); |
| 11904 | } finally { |
| 11905 | Binder.restoreCallingIdentity(identity); |
| 11906 | } |
| 11907 | } |
arunvoddu | d5c6ce0 | 2022-12-11 06:03:12 +0000 | [diff] [blame] | 11908 | |
| 11909 | /** |
| 11910 | * Check whether the caller (or self, if not processing an IPC) can read device identifiers. |
| 11911 | * |
| 11912 | * <p>This method behaves in one of the following ways: |
| 11913 | * <ul> |
| 11914 | * <li>return true : if the calling package has the appop permission {@link |
| 11915 | * Manifest.permission#USE_ICC_AUTH_WITH_DEVICE_IDENTIFIER} in the manifest </> |
| 11916 | * <li>return true : if any one subscription has the READ_PRIVILEGED_PHONE_STATE |
| 11917 | * permission, the calling package passes a DevicePolicyManager Device Owner / Profile |
| 11918 | * Owner device identifier access check, or the calling package has carrier privileges</> |
| 11919 | * <li>throw SecurityException: if the caller does not meet any of the requirements. |
| 11920 | * </ul> |
| 11921 | */ |
| 11922 | private static boolean checkCallingOrSelfReadDeviceIdentifiersForAnySub(Context context, |
| 11923 | String callingPackage, @Nullable String callingFeatureId, String message) { |
| 11924 | for (Phone phone : PhoneFactory.getPhones()) { |
| 11925 | if (TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(context, |
| 11926 | phone.getSubId(), callingPackage, callingFeatureId, message)) { |
| 11927 | return true; |
| 11928 | } |
| 11929 | } |
| 11930 | return false; |
| 11931 | } |
| 11932 | } |