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; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 34 | import android.app.AppOpsManager; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 35 | import android.app.PendingIntent; |
Tyler Gunn | 64144d9 | 2022-03-17 14:16:41 -0700 | [diff] [blame] | 36 | import android.app.PropertyInvalidatedCache; |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 37 | import android.app.compat.CompatChanges; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 38 | import android.app.role.RoleManager; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 39 | import android.compat.annotation.ChangeId; |
| 40 | import android.compat.annotation.EnabledSince; |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 41 | import android.content.ComponentName; |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 42 | import android.content.ContentResolver; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 43 | import android.content.Context; |
| 44 | import android.content.Intent; |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 45 | import android.content.SharedPreferences; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 46 | import android.content.pm.ComponentInfo; |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 47 | import android.content.pm.PackageManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 48 | import android.net.Uri; |
| 49 | import android.os.AsyncResult; |
| 50 | import android.os.Binder; |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 51 | import android.os.Build; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 52 | import android.os.Bundle; |
| 53 | import android.os.Handler; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 54 | import android.os.IBinder; |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 55 | import android.os.LocaleList; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 56 | import android.os.Looper; |
| 57 | import android.os.Message; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 58 | import android.os.Messenger; |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 59 | import android.os.ParcelFileDescriptor; |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 60 | import android.os.ParcelUuid; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 61 | import android.os.PersistableBundle; |
Shuo Qian | cd19c46 | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 62 | import android.os.Process; |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 63 | import android.os.RemoteException; |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 64 | import android.os.ResultReceiver; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 65 | import android.os.ServiceSpecificException; |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 66 | import android.os.SystemClock; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 67 | import android.os.UserHandle; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 68 | import android.os.UserManager; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 69 | import android.os.WorkSource; |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 70 | import android.preference.PreferenceManager; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 71 | import android.provider.DeviceConfig; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 72 | import android.provider.Settings; |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 73 | import android.provider.Telephony; |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 74 | import android.sysprop.TelephonyProperties; |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 75 | import android.telecom.PhoneAccount; |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 76 | import android.telecom.PhoneAccountHandle; |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 77 | import android.telecom.TelecomManager; |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 78 | import android.telephony.AccessNetworkConstants; |
| 79 | import android.telephony.ActivityStatsTechSpecificInfo; |
Chen Xu | 227e06f | 2019-09-26 22:48:11 -0700 | [diff] [blame] | 80 | import android.telephony.Annotation.ApnType; |
Jack Yu | 0eda684 | 2022-04-18 00:34:46 -0700 | [diff] [blame] | 81 | import android.telephony.Annotation.DataActivityType; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 82 | import android.telephony.Annotation.ThermalMitigationResult; |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 83 | import android.telephony.AnomalyReporter; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 84 | import android.telephony.CallForwardingInfo; |
Junda Liu | 12f7d80 | 2015-05-01 12:06:44 -0700 | [diff] [blame] | 85 | import android.telephony.CarrierConfigManager; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 86 | import android.telephony.CarrierRestrictionRules; |
Hui Wang | 9b5793a | 2022-12-05 14:38:06 -0600 | [diff] [blame] | 87 | import android.telephony.CellBroadcastIdRange; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 88 | import android.telephony.CellIdentity; |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 89 | import android.telephony.CellIdentityCdma; |
| 90 | import android.telephony.CellIdentityGsm; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 91 | import android.telephony.CellInfo; |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 92 | import android.telephony.CellInfoGsm; |
| 93 | import android.telephony.CellInfoWcdma; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 94 | import android.telephony.ClientRequestStats; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 95 | import android.telephony.DataThrottlingRequest; |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 96 | import android.telephony.IBootstrapAuthenticationCallback; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 97 | import android.telephony.ICellInfoCallback; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 98 | import android.telephony.IccOpenLogicalChannelResponse; |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 99 | import android.telephony.LocationAccessPolicy; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 100 | import android.telephony.ModemActivityInfo; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 101 | import android.telephony.NeighboringCellInfo; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 102 | import android.telephony.NetworkScanRequest; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 103 | import android.telephony.PhoneCapability; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 104 | import android.telephony.PhoneNumberRange; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 105 | import android.telephony.RadioAccessFamily; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 106 | import android.telephony.RadioAccessSpecifier; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 107 | import android.telephony.ServiceState; |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 108 | import android.telephony.SignalStrength; |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 109 | import android.telephony.SignalStrengthUpdateRequest; |
| 110 | import android.telephony.SignalThresholdInfo; |
Wink Saville | 0f3b5fc | 2014-11-11 08:40:49 -0800 | [diff] [blame] | 111 | import android.telephony.SubscriptionInfo; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 112 | import android.telephony.SubscriptionManager; |
Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 113 | import android.telephony.TelephonyFrameworkInitializer; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 114 | import android.telephony.TelephonyHistogram; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 115 | import android.telephony.TelephonyManager; |
Jack Yu | f5badd9 | 2022-12-08 00:50:53 -0800 | [diff] [blame] | 116 | import android.telephony.TelephonyManager.SimState; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 117 | import android.telephony.TelephonyScanManager; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 118 | import android.telephony.ThermalMitigationRequest; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 119 | import android.telephony.UiccCardInfo; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 120 | import android.telephony.UiccPortInfo; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 121 | import android.telephony.UiccSlotInfo; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 122 | import android.telephony.UiccSlotMapping; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 123 | import android.telephony.UssdResponse; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 124 | import android.telephony.VisualVoicemailSmsFilterSettings; |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 125 | import android.telephony.data.NetworkSlicingConfig; |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 126 | import android.telephony.emergency.EmergencyNumber; |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 127 | import android.telephony.gba.GbaAuthRequest; |
| 128 | import android.telephony.gba.UaSecurityProtocolIdentifier; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 129 | import android.telephony.ims.ImsException; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 130 | import android.telephony.ims.ProvisioningManager; |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 131 | import android.telephony.ims.RcsClientConfiguration; |
Brad Ebinger | 14d467f | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 132 | import android.telephony.ims.RcsContactUceCapability; |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 133 | import android.telephony.ims.RegistrationManager; |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 134 | import android.telephony.ims.aidl.IFeatureProvisioningCallback; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 135 | import android.telephony.ims.aidl.IImsCapabilityCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 136 | import android.telephony.ims.aidl.IImsConfig; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 137 | import android.telephony.ims.aidl.IImsConfigCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 138 | import android.telephony.ims.aidl.IImsRegistration; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 139 | import android.telephony.ims.aidl.IImsRegistrationCallback; |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 140 | import android.telephony.ims.aidl.IRcsConfigCallback; |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 141 | import android.telephony.ims.feature.ImsFeature; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 142 | import android.telephony.ims.stub.ImsConfigImplBase; |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 143 | import android.telephony.ims.stub.ImsRegistrationImplBase; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 144 | import android.text.TextUtils; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 145 | import android.util.ArraySet; |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 146 | import android.util.EventLog; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 147 | import android.util.Log; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 148 | import android.util.Pair; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 149 | |
Andrew Lee | 312e817 | 2014-10-23 17:01:36 -0700 | [diff] [blame] | 150 | import com.android.ims.ImsManager; |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 151 | import com.android.ims.internal.IImsServiceFeatureCallback; |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 152 | import com.android.ims.rcs.uce.eab.EabUtil; |
SongFerngWang | fd89b10 | 2021-05-27 22:44:54 +0800 | [diff] [blame] | 153 | import com.android.internal.annotations.VisibleForTesting; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 154 | import com.android.internal.telephony.CallForwardInfo; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 155 | import com.android.internal.telephony.CallManager; |
Tyler Gunn | 52dcf77 | 2017-04-26 11:30:31 -0700 | [diff] [blame] | 156 | import com.android.internal.telephony.CallStateException; |
Tyler Gunn | d433926 | 2021-05-03 14:46:49 -0700 | [diff] [blame] | 157 | import com.android.internal.telephony.CallTracker; |
Rambo Wang | 9c9ffdd | 2022-01-13 21:51:44 -0800 | [diff] [blame] | 158 | import com.android.internal.telephony.CarrierPrivilegesTracker; |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 159 | import com.android.internal.telephony.CarrierResolver; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 160 | import com.android.internal.telephony.CellNetworkScanResult; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 161 | import com.android.internal.telephony.CommandException; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 162 | import com.android.internal.telephony.CommandsInterface; |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 163 | import com.android.internal.telephony.GbaManager; |
Shuo Qian | ccbaf74 | 2021-02-22 18:32:21 -0800 | [diff] [blame] | 164 | import com.android.internal.telephony.GsmCdmaPhone; |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 165 | import com.android.internal.telephony.HalVersion; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 166 | import com.android.internal.telephony.IBooleanConsumer; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 167 | import com.android.internal.telephony.ICallForwardingInfoCallback; |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 168 | import com.android.internal.telephony.IImsStateCallback; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 169 | import com.android.internal.telephony.IIntegerConsumer; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 170 | import com.android.internal.telephony.INumberVerificationCallback; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 171 | import com.android.internal.telephony.ITelephony; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 172 | import com.android.internal.telephony.IccCard; |
Jack Yu | f5badd9 | 2022-12-08 00:50:53 -0800 | [diff] [blame] | 173 | import com.android.internal.telephony.IccCardConstants; |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 174 | import com.android.internal.telephony.IccLogicalChannelRequest; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 175 | import com.android.internal.telephony.LocaleTracker; |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 176 | import com.android.internal.telephony.NetworkScanRequestTracker; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 177 | import com.android.internal.telephony.OperatorInfo; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 178 | import com.android.internal.telephony.Phone; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 179 | import com.android.internal.telephony.PhoneConfigurationManager; |
Nathan Harold | a667c15 | 2016-12-14 11:27:20 -0800 | [diff] [blame] | 180 | import com.android.internal.telephony.PhoneConstantConversions; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 181 | import com.android.internal.telephony.PhoneConstants; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 182 | import com.android.internal.telephony.PhoneFactory; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 183 | import com.android.internal.telephony.ProxyController; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 184 | import com.android.internal.telephony.RIL; |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 185 | import com.android.internal.telephony.RILConstants; |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 186 | import com.android.internal.telephony.RadioInterfaceCapabilityController; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 187 | import com.android.internal.telephony.ServiceStateTracker; |
Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame] | 188 | import com.android.internal.telephony.SmsApplication; |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 189 | import com.android.internal.telephony.SmsController; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 190 | import com.android.internal.telephony.SmsPermissions; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 191 | import com.android.internal.telephony.SubscriptionController; |
Peter Wang | 59571be | 2020-01-27 12:35:15 +0800 | [diff] [blame] | 192 | import com.android.internal.telephony.TelephonyIntents; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 193 | import com.android.internal.telephony.TelephonyPermissions; |
Jack Yu | 27422a5 | 2022-03-21 10:38:05 -0700 | [diff] [blame] | 194 | import com.android.internal.telephony.data.DataUtils; |
Hunsuk Choi | 42cc62a | 2022-10-16 06:03:40 +0000 | [diff] [blame] | 195 | import com.android.internal.telephony.domainselection.DomainSelectionResolver; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 196 | import com.android.internal.telephony.emergency.EmergencyNumberTracker; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 197 | import com.android.internal.telephony.euicc.EuiccConnector; |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 198 | import com.android.internal.telephony.ims.ImsResolver; |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 199 | import com.android.internal.telephony.imsphone.ImsPhone; |
| 200 | import com.android.internal.telephony.imsphone.ImsPhoneCallTracker; |
joonhunshin | 3e15424 | 2021-09-17 06:33:39 +0000 | [diff] [blame] | 201 | import com.android.internal.telephony.metrics.RcsStats; |
Pengquan Meng | 6c2dc9f | 2019-02-06 11:12:53 -0800 | [diff] [blame] | 202 | import com.android.internal.telephony.metrics.TelephonyMetrics; |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 203 | import com.android.internal.telephony.subscription.SubscriptionInfoInternal; |
| 204 | import com.android.internal.telephony.subscription.SubscriptionManagerService; |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 205 | import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 206 | import com.android.internal.telephony.uicc.IccIoResult; |
| 207 | import com.android.internal.telephony.uicc.IccUtils; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 208 | import com.android.internal.telephony.uicc.SIMRecords; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 209 | import com.android.internal.telephony.uicc.UiccCard; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 210 | import com.android.internal.telephony.uicc.UiccCardApplication; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 211 | import com.android.internal.telephony.uicc.UiccController; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 212 | import com.android.internal.telephony.uicc.UiccPort; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 213 | import com.android.internal.telephony.uicc.UiccProfile; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 214 | import com.android.internal.telephony.uicc.UiccSlot; |
zoey chen | c730df8 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 215 | import com.android.internal.telephony.util.LocaleUtils; |
Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame] | 216 | import com.android.internal.telephony.util.TelephonyUtils; |
fionaxu | 7ed723d | 2017-05-30 18:58:54 -0700 | [diff] [blame] | 217 | import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 218 | import com.android.internal.util.FunctionalUtils; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 219 | import com.android.internal.util.HexDump; |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 220 | import com.android.phone.callcomposer.CallComposerPictureManager; |
| 221 | import com.android.phone.callcomposer.CallComposerPictureTransfer; |
| 222 | import com.android.phone.callcomposer.ImageData; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 223 | import com.android.phone.settings.PickSmsSubscriptionActivity; |
Sarah Chin | 46355ba | 2022-11-01 23:51:16 -0700 | [diff] [blame] | 224 | import com.android.phone.slice.SlicePurchaseController; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 225 | import com.android.phone.vvm.PhoneAccountHandleConverter; |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 226 | import com.android.phone.vvm.RemoteVvmTaskManager; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 227 | import com.android.phone.vvm.VisualVoicemailSettingsUtil; |
Ta-wei Yen | c890531 | 2017-03-28 11:14:45 -0700 | [diff] [blame] | 228 | import com.android.phone.vvm.VisualVoicemailSmsFilterConfig; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 229 | import com.android.services.telephony.TelecomAccountRegistry; |
| 230 | import com.android.services.telephony.TelephonyConnectionService; |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 231 | import com.android.telephony.Rlog; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 232 | |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 233 | import java.io.ByteArrayOutputStream; |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 234 | import java.io.FileDescriptor; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 235 | import java.io.IOException; |
| 236 | import java.io.InputStream; |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 237 | import java.io.PrintWriter; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 238 | import java.util.ArrayList; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 239 | import java.util.Arrays; |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 240 | import java.util.Collection; |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 241 | import java.util.Collections; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 242 | import java.util.HashMap; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 243 | import java.util.HashSet; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 244 | import java.util.List; |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 245 | import java.util.Locale; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 246 | import java.util.Map; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 247 | import java.util.NoSuchElementException; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 248 | import java.util.Objects; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 249 | import java.util.Set; |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 250 | import java.util.UUID; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 251 | import java.util.concurrent.Executors; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 252 | import java.util.concurrent.atomic.AtomicBoolean; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 253 | import java.util.function.Consumer; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 254 | |
| 255 | /** |
| 256 | * Implementation of the ITelephony interface. |
| 257 | */ |
Santos Cordon | 117fee7 | 2014-05-16 17:56:12 -0700 | [diff] [blame] | 258 | public class PhoneInterfaceManager extends ITelephony.Stub { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 259 | private static final String LOG_TAG = "PhoneInterfaceManager"; |
| 260 | private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2); |
| 261 | private static final boolean DBG_LOC = false; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 262 | private static final boolean DBG_MERGE = false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 263 | |
| 264 | // Message codes used with mMainThreadHandler |
| 265 | private static final int CMD_HANDLE_PIN_MMI = 1; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 266 | private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7; |
| 267 | private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 268 | private static final int CMD_OPEN_CHANNEL = 9; |
| 269 | private static final int EVENT_OPEN_CHANNEL_DONE = 10; |
| 270 | private static final int CMD_CLOSE_CHANNEL = 11; |
| 271 | private static final int EVENT_CLOSE_CHANNEL_DONE = 12; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 272 | private static final int CMD_NV_READ_ITEM = 13; |
| 273 | private static final int EVENT_NV_READ_ITEM_DONE = 14; |
| 274 | private static final int CMD_NV_WRITE_ITEM = 15; |
| 275 | private static final int EVENT_NV_WRITE_ITEM_DONE = 16; |
| 276 | private static final int CMD_NV_WRITE_CDMA_PRL = 17; |
| 277 | private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 278 | private static final int CMD_RESET_MODEM_CONFIG = 19; |
| 279 | private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 280 | private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21; |
| 281 | private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22; |
Sailesh Nepal | 35b5945 | 2014-03-06 09:26:56 -0800 | [diff] [blame] | 282 | private static final int CMD_SEND_ENVELOPE = 25; |
| 283 | private static final int EVENT_SEND_ENVELOPE_DONE = 26; |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 284 | private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27; |
| 285 | private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28; |
Derek Tan | 6b088ee | 2014-09-05 14:15:18 -0700 | [diff] [blame] | 286 | private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29; |
| 287 | private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30; |
| 288 | private static final int CMD_EXCHANGE_SIM_IO = 31; |
| 289 | private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 290 | private static final int CMD_SET_VOICEMAIL_NUMBER = 33; |
| 291 | private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 292 | private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35; |
| 293 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 294 | private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37; |
| 295 | private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 296 | private static final int CMD_PERFORM_NETWORK_SCAN = 39; |
| 297 | private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40; |
| 298 | private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41; |
| 299 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 300 | private static final int CMD_SET_ALLOWED_CARRIERS = 43; |
| 301 | private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44; |
| 302 | private static final int CMD_GET_ALLOWED_CARRIERS = 45; |
| 303 | private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 304 | private static final int CMD_HANDLE_USSD_REQUEST = 47; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 305 | private static final int CMD_GET_FORBIDDEN_PLMNS = 48; |
| 306 | private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 307 | private static final int CMD_SWITCH_SLOTS = 50; |
| 308 | private static final int EVENT_SWITCH_SLOTS_DONE = 51; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 309 | private static final int CMD_GET_NETWORK_SELECTION_MODE = 52; |
| 310 | private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53; |
| 311 | private static final int CMD_GET_CDMA_ROAMING_MODE = 54; |
| 312 | private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55; |
| 313 | private static final int CMD_SET_CDMA_ROAMING_MODE = 56; |
| 314 | private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57; |
| 315 | private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58; |
| 316 | private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 317 | private static final int CMD_GET_ALL_CELL_INFO = 60; |
| 318 | private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61; |
| 319 | private static final int CMD_GET_CELL_LOCATION = 62; |
| 320 | private static final int EVENT_GET_CELL_LOCATION_DONE = 63; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 321 | private static final int CMD_MODEM_REBOOT = 64; |
| 322 | private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 323 | private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66; |
| 324 | private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 325 | private static final int CMD_REQUEST_ENABLE_MODEM = 68; |
| 326 | private static final int EVENT_ENABLE_MODEM_DONE = 69; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 327 | private static final int CMD_GET_MODEM_STATUS = 70; |
| 328 | private static final int EVENT_GET_MODEM_STATUS_DONE = 71; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 329 | private static final int CMD_SET_FORBIDDEN_PLMNS = 72; |
| 330 | private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 331 | private static final int CMD_ERASE_MODEM_CONFIG = 74; |
| 332 | private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75; |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 333 | private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76; |
| 334 | private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77; |
| 335 | private static final int CMD_SET_ICC_LOCK_ENABLED = 78; |
| 336 | private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 337 | private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80; |
| 338 | private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 339 | private static final int MSG_NOTIFY_USER_ACTIVITY = 82; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 340 | private static final int CMD_GET_CALL_FORWARDING = 83; |
| 341 | private static final int EVENT_GET_CALL_FORWARDING_DONE = 84; |
| 342 | private static final int CMD_SET_CALL_FORWARDING = 85; |
| 343 | private static final int EVENT_SET_CALL_FORWARDING_DONE = 86; |
| 344 | private static final int CMD_GET_CALL_WAITING = 87; |
| 345 | private static final int EVENT_GET_CALL_WAITING_DONE = 88; |
| 346 | private static final int CMD_SET_CALL_WAITING = 89; |
| 347 | private static final int EVENT_SET_CALL_WAITING_DONE = 90; |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 348 | private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91; |
| 349 | private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92; |
| 350 | private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93; |
| 351 | private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 352 | private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95; |
| 353 | private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 354 | private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97; |
| 355 | private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 356 | private static final int CMD_SET_DATA_THROTTLING = 99; |
| 357 | private static final int EVENT_SET_DATA_THROTTLING_DONE = 100; |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 358 | private static final int CMD_SET_SIM_POWER = 101; |
| 359 | private static final int EVENT_SET_SIM_POWER_DONE = 102; |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 360 | private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103; |
| 361 | private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104; |
| 362 | private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105; |
| 363 | private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 364 | private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107; |
| 365 | 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] | 366 | private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 367 | private static final int CMD_GET_SLICING_CONFIG = 110; |
| 368 | private static final int EVENT_GET_SLICING_CONFIG_DONE = 111; |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 369 | private static final int CMD_ERASE_DATA_SHARED_PREFERENCES = 112; |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 370 | private static final int CMD_ENABLE_VONR = 113; |
| 371 | private static final int EVENT_ENABLE_VONR_DONE = 114; |
| 372 | private static final int CMD_IS_VONR_ENABLED = 115; |
| 373 | private static final int EVENT_IS_VONR_ENABLED_DONE = 116; |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 374 | private static final int CMD_PURCHASE_PREMIUM_CAPABILITY = 117; |
| 375 | private static final int EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE = 118; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 376 | |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 377 | // Parameters of select command. |
| 378 | private static final int SELECT_COMMAND = 0xA4; |
| 379 | private static final int SELECT_P1 = 0x04; |
| 380 | private static final int SELECT_P2 = 0; |
| 381 | private static final int SELECT_P3 = 0x10; |
| 382 | |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 383 | // Toggling null cipher and integrity support was added in IRadioNetwork 2.1 |
| 384 | private static final int MIN_NULL_CIPHER_AND_INTEGRITY_VERSION = 201; |
| 385 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 386 | /** The singleton instance. */ |
| 387 | private static PhoneInterfaceManager sInstance; |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 388 | private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 389 | |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 390 | private PhoneGlobals mApp; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 391 | private CallManager mCM; |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 392 | private ImsResolver mImsResolver; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 393 | private UserManager mUserManager; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 394 | private AppOpsManager mAppOps; |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 395 | private PackageManager mPm; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 396 | private MainThreadHandler mMainThreadHandler; |
Jack Yu | e37dd26 | 2022-12-16 11:53:37 -0800 | [diff] [blame^] | 397 | private final SubscriptionController mSubscriptionController; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 398 | private SharedPreferences mTelephonySharedPreferences; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 399 | private PhoneConfigurationManager mPhoneConfigurationManager; |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 400 | private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities; |
Gil Cukierman | 6dac5eb | 2022-09-19 16:09:04 +0000 | [diff] [blame] | 401 | private final Telephony2gUpdater mTelephony2gUpdater; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 402 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 403 | /** User Activity */ |
| 404 | private AtomicBoolean mNotifyUserActivity; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 405 | private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200; |
| 406 | |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 407 | private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>(); |
| 408 | |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 409 | private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_"; |
| 410 | private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_"; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 411 | private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_"; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 412 | private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_"; |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 413 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 414 | // String to store multi SIM allowed |
| 415 | private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted"; |
| 416 | |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 417 | // The AID of ISD-R. |
| 418 | private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100"; |
| 419 | |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 420 | private NetworkScanRequestTracker mNetworkScanRequestTracker; |
| 421 | |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 422 | private static final int TYPE_ALLOCATION_CODE_LENGTH = 8; |
| 423 | private static final int MANUFACTURER_CODE_LENGTH = 8; |
| 424 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 425 | private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1; |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 426 | 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] | 427 | |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 428 | private static final String PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID = |
| 429 | "24bf97a6-e8a6-44d8-a6a4-255d7548733c"; |
| 430 | |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 431 | /** |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 432 | * Experiment flag to enable erase modem config on reset network, default value is false |
| 433 | */ |
| 434 | public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED = |
| 435 | "reset_network_erase_modem_config_enabled"; |
| 436 | |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 437 | 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] | 438 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 439 | /** |
| 440 | * With support for MEP(multiple enabled profile) in Android T, a SIM card can have more than |
| 441 | * one ICCID active at the same time. |
| 442 | * Apps should use below API signatures if targeting SDK is T and beyond. |
| 443 | * |
| 444 | * @hide |
| 445 | */ |
| 446 | @ChangeId |
| 447 | @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU) |
| 448 | public static final long GET_API_SIGNATURES_FROM_UICC_PORT_INFO = 202110963L; |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 449 | |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 450 | /** |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 451 | * Apps targeting on Android T and beyond will get exception whenever icc close channel |
| 452 | * operation fails. |
| 453 | */ |
| 454 | @ChangeId |
| 455 | @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU) |
| 456 | public static final long ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE = 208739934L; |
| 457 | |
| 458 | /** |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 459 | * A request object to use for transmitting data to an ICC. |
| 460 | */ |
| 461 | private static final class IccAPDUArgument { |
| 462 | public int channel, cla, command, p1, p2, p3; |
| 463 | public String data; |
| 464 | |
| 465 | public IccAPDUArgument(int channel, int cla, int command, |
| 466 | int p1, int p2, int p3, String data) { |
| 467 | this.channel = channel; |
| 468 | this.cla = cla; |
| 469 | this.command = command; |
| 470 | this.p1 = p1; |
| 471 | this.p2 = p2; |
| 472 | this.p3 = p3; |
| 473 | this.data = data; |
| 474 | } |
| 475 | } |
| 476 | |
| 477 | /** |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 478 | * A request object to use for transmitting data to an ICC. |
| 479 | */ |
| 480 | private static final class ManualNetworkSelectionArgument { |
| 481 | public OperatorInfo operatorInfo; |
| 482 | public boolean persistSelection; |
| 483 | |
| 484 | public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) { |
| 485 | this.operatorInfo = operatorInfo; |
| 486 | this.persistSelection = persistSelection; |
| 487 | } |
| 488 | } |
| 489 | |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 490 | private static final class PurchasePremiumCapabilityArgument { |
| 491 | public @TelephonyManager.PremiumCapability int capability; |
| 492 | public @NonNull String appName; |
| 493 | public @NonNull IIntegerConsumer callback; |
| 494 | |
| 495 | PurchasePremiumCapabilityArgument(@TelephonyManager.PremiumCapability int capability, |
| 496 | @NonNull String appName, @NonNull IIntegerConsumer callback) { |
| 497 | this.capability = capability; |
| 498 | this.appName = appName; |
| 499 | this.callback = callback; |
| 500 | } |
| 501 | } |
| 502 | |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 503 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 504 | * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the |
| 505 | * request after sending. The main thread will notify the request when it is complete. |
| 506 | */ |
| 507 | private static final class MainThreadRequest { |
| 508 | /** The argument to use for the request */ |
| 509 | public Object argument; |
| 510 | /** The result of the request that is run on the main thread */ |
| 511 | public Object result; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 512 | // The subscriber id that this request applies to. Defaults to |
| 513 | // SubscriptionManager.INVALID_SUBSCRIPTION_ID |
| 514 | public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 515 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 516 | // In cases where subId is unavailable, the caller needs to specify the phone. |
| 517 | public Phone phone; |
| 518 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 519 | public WorkSource workSource; |
| 520 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 521 | public MainThreadRequest(Object argument) { |
| 522 | this.argument = argument; |
| 523 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 524 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 525 | MainThreadRequest(Object argument, Phone phone, WorkSource workSource) { |
| 526 | this.argument = argument; |
| 527 | if (phone != null) { |
| 528 | this.phone = phone; |
| 529 | } |
| 530 | this.workSource = workSource; |
| 531 | } |
| 532 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 533 | MainThreadRequest(Object argument, Integer subId, WorkSource workSource) { |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 534 | this.argument = argument; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 535 | if (subId != null) { |
| 536 | this.subId = subId; |
| 537 | } |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 538 | this.workSource = workSource; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 539 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 540 | } |
| 541 | |
Sailesh Nepal | cc0375f | 2013-11-13 09:15:18 -0800 | [diff] [blame] | 542 | private static final class IncomingThirdPartyCallArgs { |
| 543 | public final ComponentName component; |
| 544 | public final String callId; |
| 545 | public final String callerDisplayName; |
| 546 | |
| 547 | public IncomingThirdPartyCallArgs(ComponentName component, String callId, |
| 548 | String callerDisplayName) { |
| 549 | this.component = component; |
| 550 | this.callId = callId; |
| 551 | this.callerDisplayName = callerDisplayName; |
| 552 | } |
| 553 | } |
| 554 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 555 | /** |
| 556 | * A handler that processes messages on the main thread in the phone process. Since many |
| 557 | * of the Phone calls are not thread safe this is needed to shuttle the requests from the |
| 558 | * inbound binder threads to the main thread in the phone process. The Binder thread |
| 559 | * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting |
| 560 | * on, which will be notified when the operation completes and will contain the result of the |
| 561 | * request. |
| 562 | * |
| 563 | * <p>If a MainThreadRequest object is provided in the msg.obj field, |
| 564 | * note that request.result must be set to something non-null for the calling thread to |
| 565 | * unblock. |
| 566 | */ |
| 567 | private final class MainThreadHandler extends Handler { |
| 568 | @Override |
| 569 | public void handleMessage(Message msg) { |
| 570 | MainThreadRequest request; |
| 571 | Message onCompleted; |
| 572 | AsyncResult ar; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 573 | UiccPort uiccPort; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 574 | IccAPDUArgument iccArgument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 575 | final Phone defaultPhone = getDefaultPhone(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 576 | |
| 577 | switch (msg.what) { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 578 | case CMD_HANDLE_USSD_REQUEST: { |
| 579 | request = (MainThreadRequest) msg.obj; |
| 580 | final Phone phone = getPhoneFromRequest(request); |
| 581 | Pair<String, ResultReceiver> ussdObject = (Pair) request.argument; |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 582 | String ussdRequest = ussdObject.first; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 583 | ResultReceiver wrappedCallback = ussdObject.second; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 584 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 585 | if (!isUssdApiAllowed(request.subId)) { |
| 586 | // Carrier does not support use of this API, return failure. |
| 587 | Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis."); |
| 588 | UssdResponse response = new UssdResponse(ussdRequest, null); |
| 589 | Bundle returnData = new Bundle(); |
| 590 | returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response); |
| 591 | wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 592 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 593 | request.result = true; |
| 594 | notifyRequester(request); |
| 595 | return; |
| 596 | } |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 597 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 598 | try { |
| 599 | request.result = phone != null |
| 600 | ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false; |
| 601 | } catch (CallStateException cse) { |
| 602 | request.result = false; |
| 603 | } |
| 604 | // Wake up the requesting thread |
| 605 | notifyRequester(request); |
| 606 | break; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 607 | } |
| 608 | |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 609 | case CMD_HANDLE_PIN_MMI: { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 610 | request = (MainThreadRequest) msg.obj; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 611 | final Phone phone = getPhoneFromRequest(request); |
| 612 | request.result = phone != null ? |
| 613 | getPhoneFromRequest(request).handlePinMmi((String) request.argument) |
| 614 | : false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 615 | // Wake up the requesting thread |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 616 | notifyRequester(request); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 617 | break; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 618 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 619 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 620 | case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 621 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 622 | iccArgument = (IccAPDUArgument) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 623 | uiccPort = getUiccPortFromRequest(request); |
| 624 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 625 | loge("iccTransmitApduLogicalChannel: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 626 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 627 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 628 | } else { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 629 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE, |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 630 | request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 631 | uiccPort.iccTransmitApduLogicalChannel( |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 632 | iccArgument.channel, iccArgument.cla, iccArgument.command, |
| 633 | iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data, |
| 634 | onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 635 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 636 | break; |
| 637 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 638 | case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 639 | ar = (AsyncResult) msg.obj; |
| 640 | request = (MainThreadRequest) ar.userObj; |
| 641 | if (ar.exception == null && ar.result != null) { |
| 642 | request.result = ar.result; |
| 643 | } else { |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 644 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 645 | if (ar.result == null) { |
| 646 | loge("iccTransmitApduLogicalChannel: Empty response"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 647 | } else if (ar.exception instanceof CommandException) { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 648 | loge("iccTransmitApduLogicalChannel: CommandException: " + |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 649 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 650 | } else { |
| 651 | loge("iccTransmitApduLogicalChannel: Unknown exception"); |
| 652 | } |
| 653 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 654 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 655 | break; |
| 656 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 657 | case CMD_TRANSMIT_APDU_BASIC_CHANNEL: |
| 658 | request = (MainThreadRequest) msg.obj; |
| 659 | iccArgument = (IccAPDUArgument) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 660 | uiccPort = getUiccPortFromRequest(request); |
| 661 | if (uiccPort == null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 662 | loge("iccTransmitApduBasicChannel: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 663 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 664 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 665 | } else { |
| 666 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE, |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 667 | request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 668 | uiccPort.iccTransmitApduBasicChannel( |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 669 | iccArgument.cla, iccArgument.command, iccArgument.p1, |
| 670 | iccArgument.p2, |
| 671 | iccArgument.p3, iccArgument.data, onCompleted); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 672 | } |
| 673 | break; |
| 674 | |
| 675 | case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE: |
| 676 | ar = (AsyncResult) msg.obj; |
| 677 | request = (MainThreadRequest) ar.userObj; |
| 678 | if (ar.exception == null && ar.result != null) { |
| 679 | request.result = ar.result; |
| 680 | } else { |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 681 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 682 | if (ar.result == null) { |
| 683 | loge("iccTransmitApduBasicChannel: Empty response"); |
| 684 | } else if (ar.exception instanceof CommandException) { |
| 685 | loge("iccTransmitApduBasicChannel: CommandException: " + |
| 686 | ar.exception); |
| 687 | } else { |
| 688 | loge("iccTransmitApduBasicChannel: Unknown exception"); |
| 689 | } |
| 690 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 691 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 692 | break; |
| 693 | |
| 694 | case CMD_EXCHANGE_SIM_IO: |
| 695 | request = (MainThreadRequest) msg.obj; |
| 696 | iccArgument = (IccAPDUArgument) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 697 | uiccPort = getUiccPortFromRequest(request); |
| 698 | if (uiccPort == null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 699 | loge("iccExchangeSimIO: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 700 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 701 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 702 | } else { |
| 703 | onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE, |
| 704 | request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 705 | uiccPort.iccExchangeSimIO(iccArgument.cla, /* fileID */ |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 706 | iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3, |
| 707 | iccArgument.data, onCompleted); |
| 708 | } |
| 709 | break; |
| 710 | |
| 711 | case EVENT_EXCHANGE_SIM_IO_DONE: |
| 712 | ar = (AsyncResult) msg.obj; |
| 713 | request = (MainThreadRequest) ar.userObj; |
| 714 | if (ar.exception == null && ar.result != null) { |
| 715 | request.result = ar.result; |
| 716 | } else { |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 717 | request.result = new IccIoResult(0x6f, 0, (byte[]) null); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 718 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 719 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 720 | break; |
| 721 | |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 722 | case CMD_SEND_ENVELOPE: |
| 723 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 724 | uiccPort = getUiccPortFromRequest(request); |
| 725 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 726 | loge("sendEnvelopeWithStatus: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 727 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 728 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 729 | } else { |
| 730 | onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 731 | uiccPort.sendEnvelopeWithStatus((String) request.argument, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 732 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 733 | break; |
| 734 | |
| 735 | case EVENT_SEND_ENVELOPE_DONE: |
| 736 | ar = (AsyncResult) msg.obj; |
| 737 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 738 | if (ar.exception == null && ar.result != null) { |
| 739 | request.result = ar.result; |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 740 | } else { |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 741 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 742 | if (ar.result == null) { |
| 743 | loge("sendEnvelopeWithStatus: Empty response"); |
| 744 | } else if (ar.exception instanceof CommandException) { |
| 745 | loge("sendEnvelopeWithStatus: CommandException: " + |
| 746 | ar.exception); |
| 747 | } else { |
| 748 | loge("sendEnvelopeWithStatus: exception:" + ar.exception); |
| 749 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 750 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 751 | notifyRequester(request); |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 752 | break; |
| 753 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 754 | case CMD_OPEN_CHANNEL: |
| 755 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 756 | uiccPort = getUiccPortFromRequest(request); |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 757 | IccLogicalChannelRequest openChannelRequest = |
| 758 | (IccLogicalChannelRequest) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 759 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 760 | loge("iccOpenLogicalChannel: No UICC"); |
Shishir Agrawal | fc0492a | 2016-02-17 11:15:33 -0800 | [diff] [blame] | 761 | request.result = new IccOpenLogicalChannelResponse(-1, |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 762 | IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 763 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 764 | } else { |
| 765 | onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request); |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 766 | uiccPort.iccOpenLogicalChannel(openChannelRequest.aid, |
| 767 | openChannelRequest.p2, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 768 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 769 | break; |
| 770 | |
| 771 | case EVENT_OPEN_CHANNEL_DONE: |
| 772 | ar = (AsyncResult) msg.obj; |
| 773 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 774 | IccOpenLogicalChannelResponse openChannelResp; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 775 | if (ar.exception == null && ar.result != null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 776 | int[] result = (int[]) ar.result; |
| 777 | int channelId = result[0]; |
| 778 | byte[] selectResponse = null; |
| 779 | if (result.length > 1) { |
| 780 | selectResponse = new byte[result.length - 1]; |
| 781 | for (int i = 1; i < result.length; ++i) { |
| 782 | selectResponse[i - 1] = (byte) result[i]; |
| 783 | } |
| 784 | } |
| 785 | openChannelResp = new IccOpenLogicalChannelResponse(channelId, |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 786 | IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse); |
Rambo Wang | 3b77c4c | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 787 | |
| 788 | uiccPort = getUiccPortFromRequest(request); |
Rambo Wang | e53e07d | 2022-05-10 13:01:13 -0700 | [diff] [blame] | 789 | if (uiccPort == null) { |
| 790 | loge("EVENT_OPEN_CHANNEL_DONE: UiccPort is null"); |
| 791 | } else { |
| 792 | IccLogicalChannelRequest channelRequest = |
| 793 | (IccLogicalChannelRequest) request.argument; |
| 794 | channelRequest.channel = channelId; |
| 795 | uiccPort.onLogicalChannelOpened(channelRequest); |
| 796 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 797 | } else { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 798 | if (ar.result == null) { |
| 799 | loge("iccOpenLogicalChannel: Empty response"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 800 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 801 | if (ar.exception != null) { |
| 802 | loge("iccOpenLogicalChannel: Exception: " + ar.exception); |
| 803 | } |
| 804 | |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 805 | int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 806 | if (ar.exception instanceof CommandException) { |
| 807 | CommandException.Error error = |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 808 | ((CommandException) (ar.exception)).getCommandError(); |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 809 | if (error == CommandException.Error.MISSING_RESOURCE) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 810 | errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 811 | } else if (error == CommandException.Error.NO_SUCH_ELEMENT) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 812 | errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 813 | } |
| 814 | } |
| 815 | openChannelResp = new IccOpenLogicalChannelResponse( |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 816 | IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 817 | } |
Shishir Agrawal | 82c8a46 | 2014-07-31 18:13:17 -0700 | [diff] [blame] | 818 | request.result = openChannelResp; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 819 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 820 | break; |
| 821 | |
| 822 | case CMD_CLOSE_CHANNEL: |
| 823 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 824 | uiccPort = getUiccPortFromRequest(request); |
| 825 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 826 | loge("iccCloseLogicalChannel: No UICC"); |
Chen Xu | a8f0dff | 2022-02-12 00:34:15 -0800 | [diff] [blame] | 827 | request.result = new IllegalArgumentException( |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 828 | "iccCloseLogicalChannel: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 829 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 830 | } else { |
| 831 | onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 832 | uiccPort.iccCloseLogicalChannel((Integer) request.argument, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 833 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 834 | break; |
| 835 | |
| 836 | case EVENT_CLOSE_CHANNEL_DONE: |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 837 | ar = (AsyncResult) msg.obj; |
| 838 | request = (MainThreadRequest) ar.userObj; |
| 839 | if (ar.exception == null) { |
| 840 | request.result = true; |
Rambo Wang | 3b77c4c | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 841 | uiccPort = getUiccPortFromRequest(request); |
Rambo Wang | e53e07d | 2022-05-10 13:01:13 -0700 | [diff] [blame] | 842 | if (uiccPort == null) { |
| 843 | loge("EVENT_CLOSE_CHANNEL_DONE: UiccPort is null"); |
| 844 | } else { |
| 845 | final int channelId = (Integer) request.argument; |
| 846 | uiccPort.onLogicalChannelClosed(channelId); |
| 847 | } |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 848 | } else { |
| 849 | request.result = false; |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 850 | Exception exception = null; |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 851 | if (ar.exception instanceof CommandException) { |
| 852 | loge("iccCloseLogicalChannel: CommandException: " + ar.exception); |
| 853 | CommandException.Error error = |
| 854 | ((CommandException) (ar.exception)).getCommandError(); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 855 | if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 856 | // should only throw exceptions from the binder threads. |
| 857 | exception = new IllegalArgumentException( |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 858 | "iccCloseLogicalChannel: invalid argument "); |
| 859 | } |
| 860 | } else { |
| 861 | loge("iccCloseLogicalChannel: Unknown exception"); |
| 862 | } |
Chen Xu | a8f0dff | 2022-02-12 00:34:15 -0800 | [diff] [blame] | 863 | request.result = (exception != null) ? exception : |
| 864 | new IllegalStateException( |
| 865 | "exception from modem to close iccLogical Channel"); |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 866 | } |
| 867 | notifyRequester(request); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 868 | break; |
| 869 | |
| 870 | case CMD_NV_READ_ITEM: |
| 871 | request = (MainThreadRequest) msg.obj; |
| 872 | onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 873 | defaultPhone.nvReadItem((Integer) request.argument, onCompleted, |
| 874 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 875 | break; |
| 876 | |
| 877 | case EVENT_NV_READ_ITEM_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 878 | ar = (AsyncResult) msg.obj; |
| 879 | request = (MainThreadRequest) ar.userObj; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 880 | if (ar.exception == null && ar.result != null) { |
| 881 | request.result = ar.result; // String |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 882 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 883 | request.result = ""; |
| 884 | if (ar.result == null) { |
| 885 | loge("nvReadItem: Empty response"); |
| 886 | } else if (ar.exception instanceof CommandException) { |
| 887 | loge("nvReadItem: CommandException: " + |
| 888 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 889 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 890 | loge("nvReadItem: Unknown exception"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 891 | } |
| 892 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 893 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 894 | break; |
| 895 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 896 | case CMD_NV_WRITE_ITEM: |
| 897 | request = (MainThreadRequest) msg.obj; |
| 898 | onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request); |
| 899 | Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 900 | defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 901 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 902 | break; |
| 903 | |
| 904 | case EVENT_NV_WRITE_ITEM_DONE: |
| 905 | handleNullReturnEvent(msg, "nvWriteItem"); |
| 906 | break; |
| 907 | |
| 908 | case CMD_NV_WRITE_CDMA_PRL: |
| 909 | request = (MainThreadRequest) msg.obj; |
| 910 | onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 911 | defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 912 | break; |
| 913 | |
| 914 | case EVENT_NV_WRITE_CDMA_PRL_DONE: |
| 915 | handleNullReturnEvent(msg, "nvWriteCdmaPrl"); |
| 916 | break; |
| 917 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 918 | case CMD_RESET_MODEM_CONFIG: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 919 | request = (MainThreadRequest) msg.obj; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 920 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 921 | defaultPhone.resetModemConfig(onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 922 | break; |
| 923 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 924 | case EVENT_RESET_MODEM_CONFIG_DONE: |
| 925 | handleNullReturnEvent(msg, "resetModemConfig"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 926 | break; |
| 927 | |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 928 | case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: { |
| 929 | request = (MainThreadRequest) msg.obj; |
| 930 | onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE, |
| 931 | request); |
| 932 | Phone phone = getPhoneFromRequest(request); |
| 933 | if (phone != null) { |
| 934 | phone.isNrDualConnectivityEnabled(onCompleted, request.workSource); |
| 935 | } else { |
| 936 | loge("isNRDualConnectivityEnabled: No phone object"); |
| 937 | request.result = false; |
| 938 | notifyRequester(request); |
| 939 | } |
| 940 | break; |
| 941 | } |
| 942 | |
| 943 | case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE: |
| 944 | ar = (AsyncResult) msg.obj; |
| 945 | request = (MainThreadRequest) ar.userObj; |
| 946 | if (ar.exception == null && ar.result != null) { |
| 947 | request.result = ar.result; |
| 948 | } else { |
| 949 | // request.result must be set to something non-null |
| 950 | // for the calling thread to unblock |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 951 | if (ar.result != null) { |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 952 | request.result = ar.result; |
| 953 | } else { |
| 954 | request.result = false; |
| 955 | } |
| 956 | if (ar.result == null) { |
| 957 | loge("isNRDualConnectivityEnabled: Empty response"); |
| 958 | } else if (ar.exception instanceof CommandException) { |
| 959 | loge("isNRDualConnectivityEnabled: CommandException: " |
| 960 | + ar.exception); |
| 961 | } else { |
| 962 | loge("isNRDualConnectivityEnabled: Unknown exception"); |
| 963 | } |
| 964 | } |
| 965 | notifyRequester(request); |
| 966 | break; |
| 967 | |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 968 | case CMD_IS_VONR_ENABLED: { |
| 969 | request = (MainThreadRequest) msg.obj; |
| 970 | onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE, |
| 971 | request); |
| 972 | Phone phone = getPhoneFromRequest(request); |
| 973 | if (phone != null) { |
| 974 | phone.isVoNrEnabled(onCompleted, request.workSource); |
| 975 | } else { |
| 976 | loge("isVoNrEnabled: No phone object"); |
| 977 | request.result = false; |
| 978 | notifyRequester(request); |
| 979 | } |
| 980 | break; |
| 981 | } |
| 982 | |
| 983 | case EVENT_IS_VONR_ENABLED_DONE: |
| 984 | ar = (AsyncResult) msg.obj; |
| 985 | request = (MainThreadRequest) ar.userObj; |
| 986 | if (ar.exception == null && ar.result != null) { |
| 987 | request.result = ar.result; |
| 988 | } else { |
| 989 | // request.result must be set to something non-null |
| 990 | // for the calling thread to unblock |
| 991 | if (ar.result != null) { |
| 992 | request.result = ar.result; |
| 993 | } else { |
| 994 | request.result = false; |
| 995 | } |
| 996 | if (ar.result == null) { |
| 997 | loge("isVoNrEnabled: Empty response"); |
| 998 | } else if (ar.exception instanceof CommandException) { |
| 999 | loge("isVoNrEnabled: CommandException: " |
| 1000 | + ar.exception); |
| 1001 | } else { |
| 1002 | loge("isVoNrEnabled: Unknown exception"); |
| 1003 | } |
| 1004 | } |
| 1005 | notifyRequester(request); |
| 1006 | break; |
| 1007 | |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 1008 | case CMD_ENABLE_NR_DUAL_CONNECTIVITY: { |
| 1009 | request = (MainThreadRequest) msg.obj; |
| 1010 | onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request); |
| 1011 | Phone phone = getPhoneFromRequest(request); |
| 1012 | if (phone != null) { |
| 1013 | phone.setNrDualConnectivityState((int) request.argument, onCompleted, |
| 1014 | request.workSource); |
| 1015 | } else { |
| 1016 | loge("enableNrDualConnectivity: No phone object"); |
| 1017 | request.result = |
| 1018 | TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE; |
| 1019 | notifyRequester(request); |
| 1020 | } |
| 1021 | break; |
| 1022 | } |
| 1023 | |
| 1024 | case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: { |
| 1025 | ar = (AsyncResult) msg.obj; |
| 1026 | request = (MainThreadRequest) ar.userObj; |
| 1027 | if (ar.exception == null) { |
| 1028 | request.result = |
| 1029 | TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS; |
| 1030 | } else { |
| 1031 | request.result = |
| 1032 | TelephonyManager |
| 1033 | .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR; |
| 1034 | if (ar.exception instanceof CommandException) { |
| 1035 | CommandException.Error error = |
| 1036 | ((CommandException) (ar.exception)).getCommandError(); |
| 1037 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1038 | request.result = |
| 1039 | TelephonyManager |
| 1040 | .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE; |
Sooraj Sasindran | 2965416 | 2021-03-03 23:00:01 +0000 | [diff] [blame] | 1041 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1042 | request.result = |
| 1043 | TelephonyManager |
| 1044 | .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED; |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 1045 | } |
| 1046 | loge("enableNrDualConnectivity" + ": CommandException: " |
| 1047 | + ar.exception); |
| 1048 | } else { |
| 1049 | loge("enableNrDualConnectivity" + ": Unknown exception"); |
| 1050 | } |
| 1051 | } |
| 1052 | notifyRequester(request); |
| 1053 | break; |
| 1054 | } |
| 1055 | |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 1056 | case CMD_ENABLE_VONR: { |
| 1057 | request = (MainThreadRequest) msg.obj; |
| 1058 | onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request); |
| 1059 | Phone phone = getPhoneFromRequest(request); |
| 1060 | if (phone != null) { |
| 1061 | phone.setVoNrEnabled((boolean) request.argument, onCompleted, |
| 1062 | request.workSource); |
| 1063 | } else { |
| 1064 | loge("setVoNrEnabled: No phone object"); |
| 1065 | request.result = |
| 1066 | TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE; |
| 1067 | notifyRequester(request); |
| 1068 | } |
| 1069 | break; |
| 1070 | } |
| 1071 | |
| 1072 | case EVENT_ENABLE_VONR_DONE: { |
| 1073 | ar = (AsyncResult) msg.obj; |
| 1074 | request = (MainThreadRequest) ar.userObj; |
| 1075 | if (ar.exception == null) { |
| 1076 | request.result = TelephonyManager.ENABLE_VONR_SUCCESS; |
| 1077 | } else { |
| 1078 | request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR; |
| 1079 | if (ar.exception instanceof CommandException) { |
| 1080 | CommandException.Error error = |
| 1081 | ((CommandException) (ar.exception)).getCommandError(); |
| 1082 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1083 | request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE; |
| 1084 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1085 | request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED; |
| 1086 | } else { |
| 1087 | request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR; |
| 1088 | } |
| 1089 | loge("setVoNrEnabled" + ": CommandException: " |
| 1090 | + ar.exception); |
| 1091 | } else { |
| 1092 | loge("setVoNrEnabled" + ": Unknown exception"); |
| 1093 | } |
| 1094 | } |
| 1095 | notifyRequester(request); |
| 1096 | break; |
| 1097 | } |
| 1098 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1099 | case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1100 | request = (MainThreadRequest) msg.obj; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1101 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE, |
| 1102 | request); |
| 1103 | getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1104 | break; |
| 1105 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1106 | case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1107 | ar = (AsyncResult) msg.obj; |
| 1108 | request = (MainThreadRequest) ar.userObj; |
| 1109 | if (ar.exception == null && ar.result != null) { |
| 1110 | request.result = ar.result; // Integer |
| 1111 | } else { |
Nazish Tabassum | e8ba43a | 2020-07-28 14:49:25 +0530 | [diff] [blame] | 1112 | // request.result must be set to something non-null |
| 1113 | // for the calling thread to unblock |
| 1114 | request.result = new int[]{-1}; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1115 | if (ar.result == null) { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1116 | loge("getAllowedNetworkTypesBitmask: Empty response"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1117 | } else if (ar.exception instanceof CommandException) { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1118 | loge("getAllowedNetworkTypesBitmask: CommandException: " |
| 1119 | + ar.exception); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1120 | } else { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1121 | loge("getAllowedNetworkTypesBitmask: Unknown exception"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1122 | } |
| 1123 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1124 | notifyRequester(request); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1125 | break; |
| 1126 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1127 | case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1128 | request = (MainThreadRequest) msg.obj; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1129 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE, |
| 1130 | request); |
| 1131 | Pair<Integer, Long> reasonWithNetworkTypes = |
| 1132 | (Pair<Integer, Long>) request.argument; |
| 1133 | getPhoneFromRequest(request).setAllowedNetworkTypes( |
| 1134 | reasonWithNetworkTypes.first, |
| 1135 | reasonWithNetworkTypes.second, |
| 1136 | onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1137 | break; |
| 1138 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1139 | case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE: |
| 1140 | handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1141 | break; |
| 1142 | |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 1143 | case CMD_INVOKE_OEM_RIL_REQUEST_RAW: |
| 1144 | request = (MainThreadRequest)msg.obj; |
| 1145 | onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1146 | defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 1147 | break; |
| 1148 | |
| 1149 | case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE: |
| 1150 | ar = (AsyncResult)msg.obj; |
| 1151 | request = (MainThreadRequest)ar.userObj; |
| 1152 | request.result = ar; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1153 | notifyRequester(request); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 1154 | break; |
| 1155 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1156 | case CMD_SET_VOICEMAIL_NUMBER: |
| 1157 | request = (MainThreadRequest) msg.obj; |
| 1158 | onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request); |
| 1159 | Pair<String, String> tagNum = (Pair<String, String>) request.argument; |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1160 | getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second, |
| 1161 | onCompleted); |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1162 | break; |
| 1163 | |
| 1164 | case EVENT_SET_VOICEMAIL_NUMBER_DONE: |
| 1165 | handleNullReturnEvent(msg, "setVoicemailNumber"); |
| 1166 | break; |
| 1167 | |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 1168 | case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC: |
| 1169 | request = (MainThreadRequest) msg.obj; |
| 1170 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE, |
| 1171 | request); |
| 1172 | getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted); |
| 1173 | break; |
| 1174 | |
| 1175 | case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE: |
| 1176 | handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic"); |
| 1177 | break; |
| 1178 | |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1179 | case CMD_PERFORM_NETWORK_SCAN: |
| 1180 | request = (MainThreadRequest) msg.obj; |
| 1181 | onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request); |
| 1182 | getPhoneFromRequest(request).getAvailableNetworks(onCompleted); |
| 1183 | break; |
| 1184 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1185 | case CMD_GET_CALL_FORWARDING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1186 | request = (MainThreadRequest) msg.obj; |
| 1187 | onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1188 | Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args = |
| 1189 | (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>) |
| 1190 | request.argument; |
| 1191 | int callForwardingReason = args.first; |
| 1192 | request.phone.getCallForwardingOption(callForwardingReason, onCompleted); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1193 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1194 | } |
| 1195 | case EVENT_GET_CALL_FORWARDING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1196 | ar = (AsyncResult) msg.obj; |
| 1197 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1198 | TelephonyManager.CallForwardingInfoCallback callback = |
| 1199 | ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>) |
| 1200 | request.argument).second; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1201 | if (ar.exception == null && ar.result != null) { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1202 | CallForwardingInfo callForwardingInfo = null; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1203 | CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result; |
| 1204 | for (CallForwardInfo callForwardInfo : callForwardInfos) { |
| 1205 | // Service Class is a bit mask per 3gpp 27.007. Search for |
| 1206 | // any service for voice call. |
| 1207 | if ((callForwardInfo.serviceClass |
| 1208 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0) { |
Yuchen Dong | 69cc141 | 2021-09-27 20:27:01 +0800 | [diff] [blame] | 1209 | callForwardingInfo = new CallForwardingInfo( |
| 1210 | callForwardInfo.status |
| 1211 | == CommandsInterface.CF_ACTION_ENABLE, |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1212 | callForwardInfo.reason, |
| 1213 | callForwardInfo.number, |
| 1214 | callForwardInfo.timeSeconds); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1215 | break; |
| 1216 | } |
| 1217 | } |
| 1218 | // Didn't find a call forward info for voice call. |
| 1219 | if (callForwardingInfo == null) { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1220 | callForwardingInfo = new CallForwardingInfo(false /* enabled */, |
| 1221 | 0 /* reason */, null /* number */, 0 /* timeout */); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1222 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1223 | callback.onCallForwardingInfoAvailable(callForwardingInfo); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1224 | } else { |
| 1225 | if (ar.result == null) { |
| 1226 | loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response"); |
| 1227 | } |
| 1228 | if (ar.exception != null) { |
| 1229 | loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception); |
| 1230 | } |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1231 | int errorCode = TelephonyManager |
| 1232 | .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1233 | if (ar.exception instanceof CommandException) { |
| 1234 | CommandException.Error error = |
| 1235 | ((CommandException) (ar.exception)).getCommandError(); |
| 1236 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1237 | errorCode = TelephonyManager |
| 1238 | .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1239 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1240 | errorCode = TelephonyManager |
| 1241 | .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1242 | } |
| 1243 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1244 | callback.onError(errorCode); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1245 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1246 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1247 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1248 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1249 | case CMD_SET_CALL_FORWARDING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1250 | request = (MainThreadRequest) msg.obj; |
| 1251 | onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1252 | request = (MainThreadRequest) msg.obj; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1253 | CallForwardingInfo callForwardingInfoToSet = |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1254 | ((Pair<CallForwardingInfo, Consumer<Integer>>) |
| 1255 | request.argument).first; |
| 1256 | request.phone.setCallForwardingOption( |
| 1257 | callForwardingInfoToSet.isEnabled() |
Calvin Pan | 258f1f7 | 2021-07-28 21:46:56 +0800 | [diff] [blame] | 1258 | ? CommandsInterface.CF_ACTION_REGISTRATION |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1259 | : CommandsInterface.CF_ACTION_DISABLE, |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1260 | callForwardingInfoToSet.getReason(), |
| 1261 | callForwardingInfoToSet.getNumber(), |
| 1262 | callForwardingInfoToSet.getTimeoutSeconds(), onCompleted); |
| 1263 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1264 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1265 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1266 | case EVENT_SET_CALL_FORWARDING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1267 | ar = (AsyncResult) msg.obj; |
| 1268 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1269 | Consumer<Integer> callback = |
| 1270 | ((Pair<CallForwardingInfo, Consumer<Integer>>) |
| 1271 | request.argument).second; |
| 1272 | if (ar.exception != null) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1273 | loge("setCallForwarding exception: " + ar.exception); |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1274 | int errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1275 | .RESULT_ERROR_UNKNOWN; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1276 | if (ar.exception instanceof CommandException) { |
| 1277 | CommandException.Error error = |
| 1278 | ((CommandException) (ar.exception)).getCommandError(); |
| 1279 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1280 | errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1281 | .RESULT_ERROR_FDN_CHECK_FAILURE; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1282 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1283 | errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1284 | .RESULT_ERROR_NOT_SUPPORTED; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1285 | } |
| 1286 | } |
| 1287 | callback.accept(errorCode); |
| 1288 | } else { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1289 | callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1290 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1291 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1292 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1293 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1294 | case CMD_GET_CALL_WAITING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1295 | request = (MainThreadRequest) msg.obj; |
| 1296 | onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request); |
| 1297 | getPhoneFromRequest(request).getCallWaiting(onCompleted); |
| 1298 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1299 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1300 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1301 | case EVENT_GET_CALL_WAITING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1302 | ar = (AsyncResult) msg.obj; |
| 1303 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1304 | Consumer<Integer> callback = (Consumer<Integer>) request.argument; |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1305 | int callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1306 | if (ar.exception == null && ar.result != null) { |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1307 | int[] callForwardResults = (int[]) ar.result; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1308 | // Service Class is a bit mask per 3gpp 27.007. |
| 1309 | // Search for any service for voice call. |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1310 | if (callForwardResults.length > 1 |
| 1311 | && ((callForwardResults[1] |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1312 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) { |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1313 | callWaitingStatus = callForwardResults[0] == 0 |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1314 | ? TelephonyManager.CALL_WAITING_STATUS_DISABLED |
| 1315 | : TelephonyManager.CALL_WAITING_STATUS_ENABLED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1316 | } else { |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1317 | callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1318 | } |
| 1319 | } else { |
| 1320 | if (ar.result == null) { |
| 1321 | loge("EVENT_GET_CALL_WAITING_DONE: Empty response"); |
| 1322 | } |
| 1323 | if (ar.exception != null) { |
| 1324 | loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception); |
| 1325 | } |
| 1326 | if (ar.exception instanceof CommandException) { |
| 1327 | CommandException.Error error = |
| 1328 | ((CommandException) (ar.exception)).getCommandError(); |
| 1329 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1330 | callWaitingStatus = |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1331 | TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED; |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1332 | } else if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
| 1333 | callWaitingStatus = |
| 1334 | TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1335 | } |
| 1336 | } |
| 1337 | } |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1338 | callback.accept(callWaitingStatus); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1339 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1340 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1341 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1342 | case CMD_SET_CALL_WAITING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1343 | request = (MainThreadRequest) msg.obj; |
| 1344 | onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1345 | boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first; |
| 1346 | getPhoneFromRequest(request).setCallWaiting(enable, onCompleted); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1347 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1348 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1349 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1350 | case EVENT_SET_CALL_WAITING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1351 | ar = (AsyncResult) msg.obj; |
| 1352 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1353 | boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first; |
| 1354 | Consumer<Integer> callback = |
| 1355 | ((Pair<Boolean, Consumer<Integer>>) request.argument).second; |
| 1356 | if (ar.exception != null) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1357 | loge("setCallWaiting exception: " + ar.exception); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1358 | if (ar.exception instanceof CommandException) { |
| 1359 | CommandException.Error error = |
| 1360 | ((CommandException) (ar.exception)).getCommandError(); |
| 1361 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1362 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED); |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1363 | } else if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
| 1364 | callback.accept( |
| 1365 | TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1366 | } else { |
| 1367 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 1368 | } |
| 1369 | } else { |
| 1370 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 1371 | } |
| 1372 | } else { |
| 1373 | callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED |
| 1374 | : TelephonyManager.CALL_WAITING_STATUS_DISABLED); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1375 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1376 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1377 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1378 | case EVENT_PERFORM_NETWORK_SCAN_DONE: |
| 1379 | ar = (AsyncResult) msg.obj; |
| 1380 | request = (MainThreadRequest) ar.userObj; |
| 1381 | CellNetworkScanResult cellScanResult; |
| 1382 | if (ar.exception == null && ar.result != null) { |
| 1383 | cellScanResult = new CellNetworkScanResult( |
| 1384 | CellNetworkScanResult.STATUS_SUCCESS, |
| 1385 | (List<OperatorInfo>) ar.result); |
| 1386 | } else { |
| 1387 | if (ar.result == null) { |
| 1388 | loge("getCellNetworkScanResults: Empty response"); |
| 1389 | } |
| 1390 | if (ar.exception != null) { |
| 1391 | loge("getCellNetworkScanResults: Exception: " + ar.exception); |
| 1392 | } |
| 1393 | int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR; |
| 1394 | if (ar.exception instanceof CommandException) { |
| 1395 | CommandException.Error error = |
| 1396 | ((CommandException) (ar.exception)).getCommandError(); |
| 1397 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1398 | errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE; |
| 1399 | } else if (error == CommandException.Error.GENERIC_FAILURE) { |
| 1400 | errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE; |
| 1401 | } |
| 1402 | } |
| 1403 | cellScanResult = new CellNetworkScanResult(errorCode, null); |
| 1404 | } |
| 1405 | request.result = cellScanResult; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1406 | notifyRequester(request); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1407 | break; |
| 1408 | |
| 1409 | case CMD_SET_NETWORK_SELECTION_MODE_MANUAL: |
| 1410 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1411 | ManualNetworkSelectionArgument selArg = |
| 1412 | (ManualNetworkSelectionArgument) request.argument; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1413 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE, |
| 1414 | request); |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1415 | getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo, |
| 1416 | selArg.persistSelection, onCompleted); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1417 | break; |
| 1418 | |
| 1419 | case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE: |
Pengquan Meng | e3d01e2 | 2018-09-20 15:25:35 -0700 | [diff] [blame] | 1420 | ar = (AsyncResult) msg.obj; |
| 1421 | request = (MainThreadRequest) ar.userObj; |
| 1422 | if (ar.exception == null) { |
| 1423 | request.result = true; |
| 1424 | } else { |
| 1425 | request.result = false; |
| 1426 | loge("setNetworkSelectionModeManual " + ar.exception); |
| 1427 | } |
| 1428 | notifyRequester(request); |
| 1429 | mApp.onNetworkSelectionChanged(request.subId); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1430 | break; |
| 1431 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1432 | case CMD_GET_MODEM_ACTIVITY_INFO: |
| 1433 | request = (MainThreadRequest) msg.obj; |
| 1434 | onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1435 | if (defaultPhone != null) { |
| 1436 | defaultPhone.getModemActivityInfo(onCompleted, request.workSource); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1437 | } else { |
| 1438 | ResultReceiver result = (ResultReceiver) request.argument; |
| 1439 | Bundle bundle = new Bundle(); |
| 1440 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 1441 | new ModemActivityInfo(0, 0, 0, |
| 1442 | new int[ModemActivityInfo.getNumTxPowerLevels()], 0)); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1443 | result.send(0, bundle); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1444 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1445 | break; |
| 1446 | |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1447 | case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: { |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1448 | ar = (AsyncResult) msg.obj; |
| 1449 | request = (MainThreadRequest) ar.userObj; |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1450 | ResultReceiver result = (ResultReceiver) request.argument; |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1451 | int error = 0; |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 1452 | ModemActivityInfo ret = null; |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1453 | if (mLastModemActivityInfo == null) { |
| 1454 | mLastModemActivitySpecificInfo = new ActivityStatsTechSpecificInfo[1]; |
| 1455 | mLastModemActivitySpecificInfo[0] = |
| 1456 | new ActivityStatsTechSpecificInfo( |
| 1457 | 0, |
| 1458 | 0, |
| 1459 | new int[ModemActivityInfo.getNumTxPowerLevels()], |
| 1460 | 0); |
| 1461 | mLastModemActivityInfo = |
| 1462 | new ModemActivityInfo(0, 0, 0, mLastModemActivitySpecificInfo); |
| 1463 | } |
| 1464 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1465 | if (ar.exception == null && ar.result != null) { |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1466 | // Update the last modem activity info and the result of the request. |
| 1467 | ModemActivityInfo info = (ModemActivityInfo) ar.result; |
| 1468 | if (isModemActivityInfoValid(info)) { |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1469 | mergeModemActivityInfo(info); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1470 | } |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 1471 | // This is needed to decouple ret from mLastModemActivityInfo |
| 1472 | // We don't want to return mLastModemActivityInfo which is updated |
| 1473 | // inside mergeModemActivityInfo() |
| 1474 | ret = new ModemActivityInfo( |
| 1475 | mLastModemActivityInfo.getTimestampMillis(), |
| 1476 | mLastModemActivityInfo.getSleepTimeMillis(), |
| 1477 | mLastModemActivityInfo.getIdleTimeMillis(), |
| 1478 | deepCopyModemActivitySpecificInfo(mLastModemActivitySpecificInfo)); |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1479 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1480 | } else { |
| 1481 | if (ar.result == null) { |
| 1482 | loge("queryModemActivityInfo: Empty response"); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1483 | error = TelephonyManager.ModemActivityInfoException |
| 1484 | .ERROR_INVALID_INFO_RECEIVED; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1485 | } else if (ar.exception instanceof CommandException) { |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1486 | loge("queryModemActivityInfo: CommandException: " + ar.exception); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1487 | error = TelephonyManager.ModemActivityInfoException |
| 1488 | .ERROR_MODEM_RESPONSE_ERROR; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1489 | } else { |
| 1490 | loge("queryModemActivityInfo: Unknown exception"); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1491 | error = TelephonyManager.ModemActivityInfoException |
| 1492 | .ERROR_UNKNOWN; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1493 | } |
| 1494 | } |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1495 | Bundle bundle = new Bundle(); |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 1496 | if (ret != null) { |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1497 | bundle.putParcelable( |
| 1498 | TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 1499 | ret); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1500 | } else { |
| 1501 | bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error); |
| 1502 | } |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1503 | result.send(0, bundle); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1504 | notifyRequester(request); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1505 | break; |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1506 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1507 | |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1508 | case CMD_SET_ALLOWED_CARRIERS: |
| 1509 | request = (MainThreadRequest) msg.obj; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1510 | CarrierRestrictionRules argument = |
| 1511 | (CarrierRestrictionRules) request.argument; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1512 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request); |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1513 | defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1514 | break; |
| 1515 | |
| 1516 | case EVENT_SET_ALLOWED_CARRIERS_DONE: |
| 1517 | ar = (AsyncResult) msg.obj; |
| 1518 | request = (MainThreadRequest) ar.userObj; |
| 1519 | if (ar.exception == null && ar.result != null) { |
| 1520 | request.result = ar.result; |
| 1521 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1522 | request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR; |
| 1523 | if (ar.exception instanceof CommandException) { |
| 1524 | loge("setAllowedCarriers: CommandException: " + ar.exception); |
| 1525 | CommandException.Error error = |
| 1526 | ((CommandException) (ar.exception)).getCommandError(); |
| 1527 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1528 | request.result = |
| 1529 | TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED; |
| 1530 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1531 | } else { |
| 1532 | loge("setAllowedCarriers: Unknown exception"); |
| 1533 | } |
| 1534 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1535 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1536 | break; |
| 1537 | |
| 1538 | case CMD_GET_ALLOWED_CARRIERS: |
| 1539 | request = (MainThreadRequest) msg.obj; |
| 1540 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1541 | defaultPhone.getAllowedCarriers(onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1542 | break; |
| 1543 | |
| 1544 | case EVENT_GET_ALLOWED_CARRIERS_DONE: |
| 1545 | ar = (AsyncResult) msg.obj; |
| 1546 | request = (MainThreadRequest) ar.userObj; |
| 1547 | if (ar.exception == null && ar.result != null) { |
| 1548 | request.result = ar.result; |
| 1549 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1550 | request.result = new IllegalStateException( |
| 1551 | "Failed to get carrier restrictions"); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1552 | if (ar.result == null) { |
| 1553 | loge("getAllowedCarriers: Empty response"); |
| 1554 | } else if (ar.exception instanceof CommandException) { |
| 1555 | loge("getAllowedCarriers: CommandException: " + |
| 1556 | ar.exception); |
| 1557 | } else { |
| 1558 | loge("getAllowedCarriers: Unknown exception"); |
| 1559 | } |
| 1560 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1561 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1562 | break; |
| 1563 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1564 | case EVENT_GET_FORBIDDEN_PLMNS_DONE: |
| 1565 | ar = (AsyncResult) msg.obj; |
| 1566 | request = (MainThreadRequest) ar.userObj; |
| 1567 | if (ar.exception == null && ar.result != null) { |
| 1568 | request.result = ar.result; |
| 1569 | } else { |
| 1570 | request.result = new IllegalArgumentException( |
| 1571 | "Failed to retrieve Forbidden Plmns"); |
| 1572 | if (ar.result == null) { |
| 1573 | loge("getForbiddenPlmns: Empty response"); |
| 1574 | } else { |
| 1575 | loge("getForbiddenPlmns: Unknown exception"); |
| 1576 | } |
| 1577 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1578 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1579 | break; |
| 1580 | |
| 1581 | case CMD_GET_FORBIDDEN_PLMNS: |
| 1582 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1583 | uiccPort = getUiccPortFromRequest(request); |
| 1584 | if (uiccPort == null) { |
| 1585 | loge("getForbiddenPlmns() UiccPort is null"); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1586 | request.result = new IllegalArgumentException( |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1587 | "getForbiddenPlmns() UiccPort is null"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1588 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1589 | break; |
| 1590 | } |
| 1591 | Integer appType = (Integer) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1592 | UiccCardApplication uiccApp = uiccPort.getApplicationByType(appType); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1593 | if (uiccApp == null) { |
| 1594 | loge("getForbiddenPlmns() no app with specified type -- " |
| 1595 | + appType); |
| 1596 | request.result = new IllegalArgumentException("Failed to get UICC App"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1597 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1598 | break; |
| 1599 | } else { |
| 1600 | if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid() |
| 1601 | + " specified type -- " + appType); |
| 1602 | } |
| 1603 | onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request); |
| 1604 | ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns( |
| 1605 | onCompleted); |
| 1606 | break; |
| 1607 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1608 | case CMD_SWITCH_SLOTS: |
| 1609 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 1610 | List<UiccSlotMapping> slotMapping = (List<UiccSlotMapping>) request.argument; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1611 | onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 1612 | UiccController.getInstance().switchSlots(slotMapping, onCompleted); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1613 | break; |
| 1614 | |
| 1615 | case EVENT_SWITCH_SLOTS_DONE: |
| 1616 | ar = (AsyncResult) msg.obj; |
| 1617 | request = (MainThreadRequest) ar.userObj; |
| 1618 | request.result = (ar.exception == null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1619 | notifyRequester(request); |
| 1620 | break; |
| 1621 | case CMD_GET_NETWORK_SELECTION_MODE: |
| 1622 | request = (MainThreadRequest) msg.obj; |
| 1623 | onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request); |
| 1624 | getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted); |
| 1625 | break; |
| 1626 | |
| 1627 | case EVENT_GET_NETWORK_SELECTION_MODE_DONE: |
| 1628 | ar = (AsyncResult) msg.obj; |
| 1629 | request = (MainThreadRequest) ar.userObj; |
| 1630 | if (ar.exception != null) { |
| 1631 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 1632 | } else { |
| 1633 | int mode = ((int[]) ar.result)[0]; |
| 1634 | if (mode == 0) { |
| 1635 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO; |
| 1636 | } else { |
| 1637 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL; |
| 1638 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1639 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1640 | notifyRequester(request); |
| 1641 | break; |
| 1642 | case CMD_GET_CDMA_ROAMING_MODE: |
| 1643 | request = (MainThreadRequest) msg.obj; |
| 1644 | onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request); |
| 1645 | getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted); |
| 1646 | break; |
| 1647 | case EVENT_GET_CDMA_ROAMING_MODE_DONE: |
| 1648 | ar = (AsyncResult) msg.obj; |
| 1649 | request = (MainThreadRequest) ar.userObj; |
| 1650 | if (ar.exception != null) { |
| 1651 | request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT; |
| 1652 | } else { |
| 1653 | request.result = ((int[]) ar.result)[0]; |
| 1654 | } |
| 1655 | notifyRequester(request); |
| 1656 | break; |
| 1657 | case CMD_SET_CDMA_ROAMING_MODE: |
| 1658 | request = (MainThreadRequest) msg.obj; |
| 1659 | onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request); |
| 1660 | int mode = (int) request.argument; |
| 1661 | getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted); |
| 1662 | break; |
| 1663 | case EVENT_SET_CDMA_ROAMING_MODE_DONE: |
| 1664 | ar = (AsyncResult) msg.obj; |
| 1665 | request = (MainThreadRequest) ar.userObj; |
| 1666 | request.result = ar.exception == null; |
| 1667 | notifyRequester(request); |
| 1668 | break; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 1669 | case CMD_GET_CDMA_SUBSCRIPTION_MODE: |
| 1670 | request = (MainThreadRequest) msg.obj; |
| 1671 | onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1672 | getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted); |
| 1673 | break; |
| 1674 | case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1675 | ar = (AsyncResult) msg.obj; |
| 1676 | request = (MainThreadRequest) ar.userObj; |
| 1677 | if (ar.exception != null) { |
| 1678 | request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM; |
| 1679 | } else { |
| 1680 | request.result = ((int[]) ar.result)[0]; |
| 1681 | } |
| 1682 | notifyRequester(request); |
| 1683 | break; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1684 | case CMD_SET_CDMA_SUBSCRIPTION_MODE: |
| 1685 | request = (MainThreadRequest) msg.obj; |
| 1686 | onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1687 | int subscriptionMode = (int) request.argument; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 1688 | getPhoneFromRequest(request).setCdmaSubscriptionMode( |
| 1689 | subscriptionMode, onCompleted); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1690 | break; |
| 1691 | case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1692 | ar = (AsyncResult) msg.obj; |
| 1693 | request = (MainThreadRequest) ar.userObj; |
| 1694 | request.result = ar.exception == null; |
| 1695 | notifyRequester(request); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1696 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1697 | case CMD_GET_ALL_CELL_INFO: |
| 1698 | request = (MainThreadRequest) msg.obj; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1699 | onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1700 | request.phone.requestCellInfoUpdate(request.workSource, onCompleted); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1701 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1702 | case EVENT_GET_ALL_CELL_INFO_DONE: |
| 1703 | ar = (AsyncResult) msg.obj; |
| 1704 | request = (MainThreadRequest) ar.userObj; |
Nathan Harold | 8d0f174 | 2018-10-02 12:14:47 -0700 | [diff] [blame] | 1705 | // If a timeout occurs, the response will be null |
| 1706 | request.result = (ar.exception == null && ar.result != null) |
| 1707 | ? ar.result : new ArrayList<CellInfo>(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1708 | synchronized (request) { |
| 1709 | request.notifyAll(); |
| 1710 | } |
| 1711 | break; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1712 | case CMD_REQUEST_CELL_INFO_UPDATE: |
| 1713 | request = (MainThreadRequest) msg.obj; |
| 1714 | request.phone.requestCellInfoUpdate(request.workSource, |
| 1715 | obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request)); |
| 1716 | break; |
| 1717 | case EVENT_REQUEST_CELL_INFO_UPDATE_DONE: |
| 1718 | ar = (AsyncResult) msg.obj; |
| 1719 | request = (MainThreadRequest) ar.userObj; |
| 1720 | ICellInfoCallback cb = (ICellInfoCallback) request.argument; |
| 1721 | try { |
| 1722 | if (ar.exception != null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1723 | Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception); |
Meng Wang | d8921f4 | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1724 | cb.onError( |
| 1725 | TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR, |
| 1726 | ar.exception.getClass().getName(), |
| 1727 | ar.exception.toString()); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1728 | } else if (ar.result == null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1729 | Log.w(LOG_TAG, "Timeout Waiting for CellInfo!"); |
Meng Wang | d8921f4 | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1730 | cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1731 | } else { |
| 1732 | // use the result as returned |
| 1733 | cb.onCellInfo((List<CellInfo>) ar.result); |
| 1734 | } |
| 1735 | } catch (RemoteException re) { |
| 1736 | Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException"); |
| 1737 | } |
| 1738 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1739 | case CMD_GET_CELL_LOCATION: { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1740 | request = (MainThreadRequest) msg.obj; |
| 1741 | WorkSource ws = (WorkSource) request.argument; |
| 1742 | Phone phone = getPhoneFromRequest(request); |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1743 | phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request)); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1744 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1745 | } |
| 1746 | case EVENT_GET_CELL_LOCATION_DONE: { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1747 | ar = (AsyncResult) msg.obj; |
| 1748 | request = (MainThreadRequest) ar.userObj; |
| 1749 | if (ar.exception == null) { |
| 1750 | request.result = ar.result; |
| 1751 | } else { |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1752 | Phone phone = getPhoneFromRequest(request); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1753 | request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1754 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1755 | } |
| 1756 | |
| 1757 | synchronized (request) { |
| 1758 | request.notifyAll(); |
| 1759 | } |
| 1760 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1761 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1762 | case CMD_MODEM_REBOOT: |
| 1763 | request = (MainThreadRequest) msg.obj; |
| 1764 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1765 | defaultPhone.rebootModem(onCompleted); |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1766 | break; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1767 | case EVENT_CMD_MODEM_REBOOT_DONE: |
| 1768 | handleNullReturnEvent(msg, "rebootModem"); |
| 1769 | break; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1770 | case CMD_REQUEST_ENABLE_MODEM: |
| 1771 | request = (MainThreadRequest) msg.obj; |
| 1772 | boolean enable = (boolean) request.argument; |
| 1773 | onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1774 | onCompleted.arg1 = enable ? 1 : 0; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1775 | PhoneConfigurationManager.getInstance() |
| 1776 | .enablePhone(request.phone, enable, onCompleted); |
| 1777 | break; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1778 | case EVENT_ENABLE_MODEM_DONE: { |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1779 | ar = (AsyncResult) msg.obj; |
| 1780 | request = (MainThreadRequest) ar.userObj; |
| 1781 | request.result = (ar.exception == null); |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1782 | int phoneId = request.phone.getPhoneId(); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1783 | //update the cache as modem status has changed |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1784 | if ((boolean) request.result) { |
| 1785 | mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1); |
| 1786 | updateModemStateMetrics(); |
| 1787 | } else { |
| 1788 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1789 | + ar.exception); |
| 1790 | } |
| 1791 | notifyRequester(request); |
| 1792 | break; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1793 | } |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1794 | case CMD_GET_MODEM_STATUS: |
| 1795 | request = (MainThreadRequest) msg.obj; |
| 1796 | onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request); |
| 1797 | PhoneConfigurationManager.getInstance() |
| 1798 | .getPhoneStatusFromModem(request.phone, onCompleted); |
| 1799 | break; |
| 1800 | case EVENT_GET_MODEM_STATUS_DONE: |
| 1801 | ar = (AsyncResult) msg.obj; |
| 1802 | request = (MainThreadRequest) ar.userObj; |
| 1803 | int id = request.phone.getPhoneId(); |
| 1804 | if (ar.exception == null && ar.result != null) { |
| 1805 | request.result = ar.result; |
| 1806 | //update the cache as modem status has changed |
| 1807 | mPhoneConfigurationManager.addToPhoneStatusCache(id, |
| 1808 | (boolean) request.result); |
| 1809 | } else { |
| 1810 | // Return true if modem status cannot be retrieved. For most cases, |
| 1811 | // modem status is on. And for older version modems, GET_MODEM_STATUS |
| 1812 | // and disable modem are not supported. Modem is always on. |
| 1813 | // TODO: this should be fixed in R to support a third |
| 1814 | // status UNKNOWN b/131631629 |
| 1815 | request.result = true; |
| 1816 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1817 | + ar.exception); |
| 1818 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1819 | notifyRequester(request); |
| 1820 | break; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 1821 | case CMD_SET_SYSTEM_SELECTION_CHANNELS: { |
| 1822 | request = (MainThreadRequest) msg.obj; |
| 1823 | onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request); |
| 1824 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 1825 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 1826 | request.phone.setSystemSelectionChannels(args.first, onCompleted); |
| 1827 | break; |
| 1828 | } |
| 1829 | case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: { |
| 1830 | ar = (AsyncResult) msg.obj; |
| 1831 | request = (MainThreadRequest) ar.userObj; |
| 1832 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 1833 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 1834 | args.second.accept(ar.exception == null); |
| 1835 | notifyRequester(request); |
| 1836 | break; |
| 1837 | } |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1838 | case CMD_GET_SYSTEM_SELECTION_CHANNELS: { |
| 1839 | request = (MainThreadRequest) msg.obj; |
| 1840 | onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request); |
| 1841 | Phone phone = getPhoneFromRequest(request); |
| 1842 | if (phone != null) { |
| 1843 | phone.getSystemSelectionChannels(onCompleted); |
| 1844 | } else { |
| 1845 | loge("getSystemSelectionChannels: No phone object"); |
| 1846 | request.result = new ArrayList<RadioAccessSpecifier>(); |
| 1847 | notifyRequester(request); |
| 1848 | } |
| 1849 | break; |
| 1850 | } |
| 1851 | case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE: |
| 1852 | ar = (AsyncResult) msg.obj; |
| 1853 | request = (MainThreadRequest) ar.userObj; |
| 1854 | if (ar.exception == null && ar.result != null) { |
| 1855 | request.result = ar.result; |
| 1856 | } else { |
Sarah Chin | 428d1d6 | 2021-03-13 03:17:40 -0800 | [diff] [blame] | 1857 | request.result = new IllegalStateException( |
| 1858 | "Failed to retrieve system selecton channels"); |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1859 | if (ar.result == null) { |
| 1860 | loge("getSystemSelectionChannels: Empty response"); |
| 1861 | } else { |
| 1862 | loge("getSystemSelectionChannels: Unknown exception"); |
| 1863 | } |
| 1864 | } |
| 1865 | notifyRequester(request); |
| 1866 | break; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1867 | case EVENT_SET_FORBIDDEN_PLMNS_DONE: |
| 1868 | ar = (AsyncResult) msg.obj; |
| 1869 | request = (MainThreadRequest) ar.userObj; |
| 1870 | if (ar.exception == null && ar.result != null) { |
| 1871 | request.result = ar.result; |
| 1872 | } else { |
| 1873 | request.result = -1; |
| 1874 | loge("Failed to set Forbidden Plmns"); |
| 1875 | if (ar.result == null) { |
| 1876 | loge("setForbidenPlmns: Empty response"); |
| 1877 | } else if (ar.exception != null) { |
| 1878 | loge("setForbiddenPlmns: Exception: " + ar.exception); |
| 1879 | request.result = -1; |
| 1880 | } else { |
| 1881 | loge("setForbiddenPlmns: Unknown exception"); |
| 1882 | } |
| 1883 | } |
| 1884 | notifyRequester(request); |
| 1885 | break; |
| 1886 | case CMD_SET_FORBIDDEN_PLMNS: |
| 1887 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1888 | uiccPort = getUiccPortFromRequest(request); |
| 1889 | if (uiccPort == null) { |
| 1890 | loge("setForbiddenPlmns: UiccPort is null"); |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1891 | request.result = -1; |
| 1892 | notifyRequester(request); |
| 1893 | break; |
| 1894 | } |
| 1895 | Pair<Integer, List<String>> setFplmnsArgs = |
| 1896 | (Pair<Integer, List<String>>) request.argument; |
| 1897 | appType = setFplmnsArgs.first; |
| 1898 | List<String> fplmns = setFplmnsArgs.second; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1899 | uiccApp = uiccPort.getApplicationByType(appType); |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1900 | if (uiccApp == null) { |
| 1901 | loge("setForbiddenPlmns: no app with specified type -- " + appType); |
| 1902 | request.result = -1; |
| 1903 | loge("Failed to get UICC App"); |
| 1904 | notifyRequester(request); |
| 1905 | } else { |
| 1906 | onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request); |
| 1907 | ((SIMRecords) uiccApp.getIccRecords()) |
| 1908 | .setForbiddenPlmns(onCompleted, fplmns); |
| 1909 | } |
yinchengzhao | 4d163c0 | 2019-12-12 15:21:47 -0800 | [diff] [blame] | 1910 | break; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 1911 | case CMD_ERASE_MODEM_CONFIG: |
| 1912 | request = (MainThreadRequest) msg.obj; |
| 1913 | onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request); |
| 1914 | defaultPhone.eraseModemConfig(onCompleted); |
| 1915 | break; |
| 1916 | case EVENT_ERASE_MODEM_CONFIG_DONE: |
| 1917 | handleNullReturnEvent(msg, "eraseModemConfig"); |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1918 | break; |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1919 | |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 1920 | case CMD_ERASE_DATA_SHARED_PREFERENCES: |
| 1921 | request = (MainThreadRequest) msg.obj; |
| 1922 | request.result = defaultPhone.eraseDataInSharedPreferences(); |
| 1923 | notifyRequester(request); |
| 1924 | break; |
| 1925 | |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1926 | case CMD_CHANGE_ICC_LOCK_PASSWORD: |
| 1927 | request = (MainThreadRequest) msg.obj; |
| 1928 | onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request); |
| 1929 | Pair<String, String> changed = (Pair<String, String>) request.argument; |
| 1930 | getPhoneFromRequest(request).getIccCard().changeIccLockPassword( |
| 1931 | changed.first, changed.second, onCompleted); |
| 1932 | break; |
| 1933 | case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE: |
| 1934 | ar = (AsyncResult) msg.obj; |
| 1935 | request = (MainThreadRequest) ar.userObj; |
| 1936 | if (ar.exception == null) { |
| 1937 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1938 | // If the operation is successful, update the PIN storage |
| 1939 | Pair<String, String> passwords = (Pair<String, String>) request.argument; |
| 1940 | int phoneId = getPhoneFromRequest(request).getPhoneId(); |
Jon Spivack | 9c3bc76 | 2021-10-06 20:53:09 +0000 | [diff] [blame] | 1941 | UiccController.getInstance().getPinStorage() |
| 1942 | .storePin(passwords.second, phoneId); |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1943 | } else { |
| 1944 | request.result = msg.arg1; |
| 1945 | } |
| 1946 | notifyRequester(request); |
| 1947 | break; |
| 1948 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1949 | case CMD_SET_ICC_LOCK_ENABLED: { |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1950 | request = (MainThreadRequest) msg.obj; |
| 1951 | onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request); |
| 1952 | Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument; |
| 1953 | getPhoneFromRequest(request).getIccCard().setIccLockEnabled( |
| 1954 | enabled.first, enabled.second, onCompleted); |
| 1955 | break; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1956 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1957 | case EVENT_SET_ICC_LOCK_ENABLED_DONE: |
| 1958 | ar = (AsyncResult) msg.obj; |
| 1959 | request = (MainThreadRequest) ar.userObj; |
| 1960 | if (ar.exception == null) { |
| 1961 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1962 | // If the operation is successful, update the PIN storage |
| 1963 | Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument; |
| 1964 | int phoneId = getPhoneFromRequest(request).getPhoneId(); |
| 1965 | if (enabled.first) { |
Jon Spivack | 9c3bc76 | 2021-10-06 20:53:09 +0000 | [diff] [blame] | 1966 | UiccController.getInstance().getPinStorage() |
| 1967 | .storePin(enabled.second, phoneId); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1968 | } else { |
| 1969 | UiccController.getInstance().getPinStorage().clearPin(phoneId); |
| 1970 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1971 | } else { |
| 1972 | request.result = msg.arg1; |
| 1973 | } |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1974 | |
| 1975 | |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1976 | notifyRequester(request); |
| 1977 | break; |
| 1978 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 1979 | case MSG_NOTIFY_USER_ACTIVITY: |
| 1980 | removeMessages(MSG_NOTIFY_USER_ACTIVITY); |
Peter Wang | 59571be | 2020-01-27 12:35:15 +0800 | [diff] [blame] | 1981 | Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION); |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 1982 | intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY); |
| 1983 | getDefaultPhone().getContext().sendBroadcastAsUser( |
| 1984 | intent, UserHandle.ALL, permission.USER_ACTIVITY); |
| 1985 | break; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 1986 | |
| 1987 | case CMD_SET_DATA_THROTTLING: { |
| 1988 | request = (MainThreadRequest) msg.obj; |
| 1989 | onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request); |
| 1990 | DataThrottlingRequest dataThrottlingRequest = |
| 1991 | (DataThrottlingRequest) request.argument; |
| 1992 | Phone phone = getPhoneFromRequest(request); |
| 1993 | if (phone != null) { |
| 1994 | phone.setDataThrottling(onCompleted, |
| 1995 | request.workSource, dataThrottlingRequest.getDataThrottlingAction(), |
| 1996 | dataThrottlingRequest.getCompletionDurationMillis()); |
| 1997 | } else { |
| 1998 | loge("setDataThrottling: No phone object"); |
| 1999 | request.result = |
| 2000 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 2001 | notifyRequester(request); |
| 2002 | } |
| 2003 | |
| 2004 | break; |
| 2005 | } |
| 2006 | case EVENT_SET_DATA_THROTTLING_DONE: |
| 2007 | ar = (AsyncResult) msg.obj; |
| 2008 | request = (MainThreadRequest) ar.userObj; |
| 2009 | |
| 2010 | if (ar.exception == null) { |
| 2011 | request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 2012 | } else if (ar.exception instanceof CommandException) { |
| 2013 | loge("setDataThrottling: CommandException: " + ar.exception); |
| 2014 | CommandException.Error error = |
| 2015 | ((CommandException) (ar.exception)).getCommandError(); |
| 2016 | |
| 2017 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 2018 | request.result = TelephonyManager |
| 2019 | .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 2020 | } else if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 2021 | request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS; |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 2022 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 2023 | request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 2024 | } else { |
| 2025 | request.result = |
| 2026 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 2027 | } |
| 2028 | } else { |
| 2029 | request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 2030 | } |
| 2031 | Log.w(LOG_TAG, "DataThrottlingResult = " + request.result); |
| 2032 | notifyRequester(request); |
| 2033 | break; |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 2034 | |
| 2035 | case CMD_SET_SIM_POWER: { |
| 2036 | request = (MainThreadRequest) msg.obj; |
| 2037 | onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request); |
| 2038 | request = (MainThreadRequest) msg.obj; |
| 2039 | int stateToSet = |
| 2040 | ((Pair<Integer, IIntegerConsumer>) |
| 2041 | request.argument).first; |
| 2042 | request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource); |
| 2043 | break; |
| 2044 | } |
| 2045 | case EVENT_SET_SIM_POWER_DONE: { |
| 2046 | ar = (AsyncResult) msg.obj; |
| 2047 | request = (MainThreadRequest) ar.userObj; |
| 2048 | IIntegerConsumer callback = |
| 2049 | ((Pair<Integer, IIntegerConsumer>) request.argument).second; |
| 2050 | if (ar.exception != null) { |
| 2051 | loge("setSimPower exception: " + ar.exception); |
| 2052 | int errorCode = TelephonyManager.CallForwardingInfoCallback |
| 2053 | .RESULT_ERROR_UNKNOWN; |
| 2054 | if (ar.exception instanceof CommandException) { |
| 2055 | CommandException.Error error = |
| 2056 | ((CommandException) (ar.exception)).getCommandError(); |
| 2057 | if (error == CommandException.Error.SIM_ERR) { |
| 2058 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR; |
| 2059 | } else if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 2060 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE; |
| 2061 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 2062 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED; |
| 2063 | } else { |
| 2064 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR; |
| 2065 | } |
| 2066 | } |
| 2067 | try { |
| 2068 | callback.accept(errorCode); |
| 2069 | } catch (RemoteException e) { |
| 2070 | // Ignore if the remote process is no longer available to call back. |
| 2071 | Log.w(LOG_TAG, "setSimPower: callback not available."); |
| 2072 | } |
| 2073 | } else { |
| 2074 | try { |
| 2075 | callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS); |
| 2076 | } catch (RemoteException e) { |
| 2077 | // Ignore if the remote process is no longer available to call back. |
| 2078 | Log.w(LOG_TAG, "setSimPower: callback not available."); |
| 2079 | } |
| 2080 | } |
| 2081 | break; |
| 2082 | } |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 2083 | case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: { |
| 2084 | request = (MainThreadRequest) msg.obj; |
| 2085 | |
| 2086 | final Phone phone = getPhoneFromRequest(request); |
| 2087 | if (phone == null || phone.getServiceStateTracker() == null) { |
| 2088 | request.result = new IllegalStateException("Phone or SST is null"); |
| 2089 | notifyRequester(request); |
| 2090 | break; |
| 2091 | } |
| 2092 | |
| 2093 | Pair<Integer, SignalStrengthUpdateRequest> pair = |
| 2094 | (Pair<Integer, SignalStrengthUpdateRequest>) request.argument; |
| 2095 | onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE, |
| 2096 | request); |
Rambo Wang | 6568f17 | 2021-02-03 16:56:47 -0800 | [diff] [blame] | 2097 | phone.getSignalStrengthController().setSignalStrengthUpdateRequest( |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 2098 | request.subId, pair.first /*callingUid*/, |
| 2099 | pair.second /*request*/, onCompleted); |
| 2100 | break; |
| 2101 | } |
| 2102 | case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: { |
| 2103 | ar = (AsyncResult) msg.obj; |
| 2104 | request = (MainThreadRequest) ar.userObj; |
| 2105 | // request.result will be the exception of ar if present, true otherwise. |
| 2106 | // Be cautious not to leave result null which will wait() forever |
| 2107 | request.result = ar.exception != null ? ar.exception : true; |
| 2108 | notifyRequester(request); |
| 2109 | break; |
| 2110 | } |
| 2111 | case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: { |
| 2112 | request = (MainThreadRequest) msg.obj; |
| 2113 | |
| 2114 | Phone phone = getPhoneFromRequest(request); |
| 2115 | if (phone == null || phone.getServiceStateTracker() == null) { |
| 2116 | request.result = new IllegalStateException("Phone or SST is null"); |
| 2117 | notifyRequester(request); |
| 2118 | break; |
| 2119 | } |
| 2120 | |
| 2121 | Pair<Integer, SignalStrengthUpdateRequest> pair = |
| 2122 | (Pair<Integer, SignalStrengthUpdateRequest>) request.argument; |
| 2123 | onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE, |
| 2124 | request); |
Rambo Wang | 6568f17 | 2021-02-03 16:56:47 -0800 | [diff] [blame] | 2125 | phone.getSignalStrengthController().clearSignalStrengthUpdateRequest( |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 2126 | request.subId, pair.first /*callingUid*/, |
| 2127 | pair.second /*request*/, onCompleted); |
| 2128 | break; |
| 2129 | } |
| 2130 | case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: { |
| 2131 | ar = (AsyncResult) msg.obj; |
| 2132 | request = (MainThreadRequest) ar.userObj; |
| 2133 | request.result = ar.exception != null ? ar.exception : true; |
| 2134 | notifyRequester(request); |
| 2135 | break; |
| 2136 | } |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 2137 | |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2138 | case CMD_GET_SLICING_CONFIG: { |
| 2139 | request = (MainThreadRequest) msg.obj; |
| 2140 | onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request); |
| 2141 | request.phone.getSlicingConfig(onCompleted); |
| 2142 | break; |
| 2143 | } |
| 2144 | case EVENT_GET_SLICING_CONFIG_DONE: { |
| 2145 | ar = (AsyncResult) msg.obj; |
| 2146 | request = (MainThreadRequest) ar.userObj; |
| 2147 | ResultReceiver result = (ResultReceiver) request.argument; |
| 2148 | |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2149 | NetworkSlicingConfig slicingConfig = null; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2150 | Bundle bundle = new Bundle(); |
| 2151 | int resultCode = 0; |
| 2152 | if (ar.exception != null) { |
| 2153 | Log.e(LOG_TAG, "Exception retrieving slicing configuration=" |
| 2154 | + ar.exception); |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2155 | resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2156 | } else if (ar.result == null) { |
| 2157 | Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!"); |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2158 | resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2159 | } else { |
| 2160 | // use the result as returned |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2161 | resultCode = TelephonyManager.NetworkSlicingException.SUCCESS; |
| 2162 | slicingConfig = (NetworkSlicingConfig) ar.result; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2163 | } |
| 2164 | |
| 2165 | if (slicingConfig == null) { |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2166 | slicingConfig = new NetworkSlicingConfig(); |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2167 | } |
| 2168 | bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig); |
| 2169 | result.send(resultCode, bundle); |
| 2170 | notifyRequester(request); |
| 2171 | break; |
| 2172 | } |
| 2173 | |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2174 | case CMD_PURCHASE_PREMIUM_CAPABILITY: { |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2175 | request = (MainThreadRequest) msg.obj; |
| 2176 | onCompleted = obtainMessage(EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE, request); |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2177 | PurchasePremiumCapabilityArgument arg = |
| 2178 | (PurchasePremiumCapabilityArgument) request.argument; |
Sarah Chin | 46355ba | 2022-11-01 23:51:16 -0700 | [diff] [blame] | 2179 | SlicePurchaseController.getInstance(request.phone).purchasePremiumCapability( |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2180 | arg.capability, arg.appName, onCompleted); |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2181 | break; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2182 | } |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2183 | |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2184 | case EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE: { |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2185 | ar = (AsyncResult) msg.obj; |
| 2186 | request = (MainThreadRequest) ar.userObj; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2187 | PurchasePremiumCapabilityArgument arg = |
| 2188 | (PurchasePremiumCapabilityArgument) request.argument; |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2189 | try { |
| 2190 | int result = (int) ar.result; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2191 | arg.callback.accept(result); |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2192 | log("purchasePremiumCapability: capability=" |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2193 | + TelephonyManager.convertPremiumCapabilityToString(arg.capability) |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2194 | + ", result= " |
| 2195 | + TelephonyManager.convertPurchaseResultToString(result)); |
| 2196 | } catch (RemoteException e) { |
| 2197 | String logStr = "Purchase premium capability " |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2198 | + TelephonyManager.convertPremiumCapabilityToString(arg.capability) |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2199 | + " failed: " + e; |
| 2200 | if (DBG) log(logStr); |
| 2201 | AnomalyReporter.reportAnomaly( |
| 2202 | UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr); |
| 2203 | } |
| 2204 | break; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2205 | } |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2206 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2207 | case CMD_PREPARE_UNATTENDED_REBOOT: |
| 2208 | request = (MainThreadRequest) msg.obj; |
| 2209 | request.result = |
Rafael Higuera Silva | d963064 | 2021-09-20 15:32:01 +0000 | [diff] [blame] | 2210 | UiccController.getInstance().getPinStorage() |
| 2211 | .prepareUnattendedReboot(request.workSource); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2212 | notifyRequester(request); |
| 2213 | break; |
| 2214 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2215 | default: |
| 2216 | Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what); |
| 2217 | break; |
| 2218 | } |
| 2219 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2220 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 2221 | private void notifyRequester(MainThreadRequest request) { |
| 2222 | synchronized (request) { |
| 2223 | request.notifyAll(); |
| 2224 | } |
| 2225 | } |
| 2226 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2227 | private void handleNullReturnEvent(Message msg, String command) { |
| 2228 | AsyncResult ar = (AsyncResult) msg.obj; |
| 2229 | MainThreadRequest request = (MainThreadRequest) ar.userObj; |
| 2230 | if (ar.exception == null) { |
| 2231 | request.result = true; |
| 2232 | } else { |
| 2233 | request.result = false; |
| 2234 | if (ar.exception instanceof CommandException) { |
| 2235 | loge(command + ": CommandException: " + ar.exception); |
| 2236 | } else { |
| 2237 | loge(command + ": Unknown exception"); |
| 2238 | } |
| 2239 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 2240 | notifyRequester(request); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2241 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2242 | } |
| 2243 | |
| 2244 | /** |
| 2245 | * Posts the specified command to be executed on the main thread, |
| 2246 | * waits for the request to complete, and returns the result. |
| 2247 | * @see #sendRequestAsync |
| 2248 | */ |
| 2249 | private Object sendRequest(int command, Object argument) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2250 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, |
| 2251 | null, -1 /*timeoutInMs*/); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 2252 | } |
| 2253 | |
| 2254 | /** |
| 2255 | * Posts the specified command to be executed on the main thread, |
| 2256 | * waits for the request to complete, and returns the result. |
| 2257 | * @see #sendRequestAsync |
| 2258 | */ |
| 2259 | private Object sendRequest(int command, Object argument, WorkSource workSource) { |
| 2260 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2261 | null, workSource, -1 /*timeoutInMs*/); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2262 | } |
| 2263 | |
| 2264 | /** |
| 2265 | * Posts the specified command to be executed on the main thread, |
| 2266 | * waits for the request to complete, and returns the result. |
| 2267 | * @see #sendRequestAsync |
| 2268 | */ |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2269 | private Object sendRequest(int command, Object argument, Integer subId) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2270 | return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/); |
| 2271 | } |
| 2272 | |
| 2273 | /** |
| 2274 | * Posts the specified command to be executed on the main thread, |
| 2275 | * waits for the request to complete for at most {@code timeoutInMs}, and returns the result |
| 2276 | * if not timeout or null otherwise. |
| 2277 | * @see #sendRequestAsync |
| 2278 | */ |
| 2279 | private @Nullable Object sendRequest(int command, Object argument, Integer subId, |
| 2280 | long timeoutInMs) { |
| 2281 | return sendRequest(command, argument, subId, null, null, timeoutInMs); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 2282 | } |
| 2283 | |
| 2284 | /** |
| 2285 | * Posts the specified command to be executed on the main thread, |
| 2286 | * waits for the request to complete, and returns the result. |
| 2287 | * @see #sendRequestAsync |
| 2288 | */ |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2289 | private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2290 | return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2291 | } |
| 2292 | |
| 2293 | /** |
| 2294 | * Posts the specified command to be executed on the main thread, |
| 2295 | * waits for the request to complete, and returns the result. |
| 2296 | * @see #sendRequestAsync |
| 2297 | */ |
| 2298 | private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2299 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, |
| 2300 | workSource, -1 /*timeoutInMs*/); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2301 | } |
| 2302 | |
| 2303 | /** |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2304 | * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is |
| 2305 | * negative, waits for the request to complete, and returns the result. Otherwise, wait for |
| 2306 | * maximum of {@code timeoutInMs} milliseconds, interrupt and return null. |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2307 | * @see #sendRequestAsync |
| 2308 | */ |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2309 | private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone, |
| 2310 | WorkSource workSource, long timeoutInMs) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2311 | if (Looper.myLooper() == mMainThreadHandler.getLooper()) { |
| 2312 | throw new RuntimeException("This method will deadlock if called from the main thread."); |
| 2313 | } |
| 2314 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2315 | MainThreadRequest request = null; |
| 2316 | if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) { |
| 2317 | throw new IllegalArgumentException("subId and phone cannot both be specified!"); |
| 2318 | } else if (phone != null) { |
| 2319 | request = new MainThreadRequest(argument, phone, workSource); |
| 2320 | } else { |
| 2321 | request = new MainThreadRequest(argument, subId, workSource); |
| 2322 | } |
| 2323 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2324 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 2325 | msg.sendToTarget(); |
| 2326 | |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2327 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2328 | synchronized (request) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2329 | if (timeoutInMs >= 0) { |
| 2330 | // Wait for at least timeoutInMs before returning null request result |
| 2331 | long now = SystemClock.elapsedRealtime(); |
| 2332 | long deadline = now + timeoutInMs; |
Grace Jia | 8a0a1e8 | 2021-05-23 22:59:52 -0700 | [diff] [blame] | 2333 | while (request.result == null && now < deadline) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2334 | try { |
| 2335 | request.wait(deadline - now); |
| 2336 | } catch (InterruptedException e) { |
| 2337 | // Do nothing, go back and check if request is completed or timeout |
| 2338 | } finally { |
| 2339 | now = SystemClock.elapsedRealtime(); |
| 2340 | } |
| 2341 | } |
| 2342 | } else { |
| 2343 | // Wait for the request to complete |
| 2344 | while (request.result == null) { |
| 2345 | try { |
| 2346 | request.wait(); |
| 2347 | } catch (InterruptedException e) { |
| 2348 | // Do nothing, go back and wait until the request is complete |
| 2349 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2350 | } |
| 2351 | } |
| 2352 | } |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2353 | if (request.result == null) { |
| 2354 | Log.wtf(LOG_TAG, |
| 2355 | "sendRequest: Blocking command timed out. Something has gone terribly wrong."); |
| 2356 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2357 | return request.result; |
| 2358 | } |
| 2359 | |
| 2360 | /** |
| 2361 | * Asynchronous ("fire and forget") version of sendRequest(): |
| 2362 | * Posts the specified command to be executed on the main thread, and |
| 2363 | * returns immediately. |
| 2364 | * @see #sendRequest |
| 2365 | */ |
| 2366 | private void sendRequestAsync(int command) { |
| 2367 | mMainThreadHandler.sendEmptyMessage(command); |
| 2368 | } |
| 2369 | |
| 2370 | /** |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2371 | * Same as {@link #sendRequestAsync(int)} except it takes an argument. |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2372 | * @see {@link #sendRequest(int)} |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2373 | */ |
| 2374 | private void sendRequestAsync(int command, Object argument) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2375 | sendRequestAsync(command, argument, null, null); |
| 2376 | } |
| 2377 | |
| 2378 | /** |
| 2379 | * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource. |
| 2380 | * @see {@link #sendRequest(int,Object)} |
| 2381 | */ |
| 2382 | private void sendRequestAsync( |
| 2383 | int command, Object argument, Phone phone, WorkSource workSource) { |
| 2384 | MainThreadRequest request = new MainThreadRequest(argument, phone, workSource); |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2385 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 2386 | msg.sendToTarget(); |
| 2387 | } |
| 2388 | |
| 2389 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2390 | * Initialize the singleton PhoneInterfaceManager instance. |
| 2391 | * This is only done once, at startup, from PhoneApp.onCreate(). |
| 2392 | */ |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2393 | /* package */ static PhoneInterfaceManager init(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2394 | synchronized (PhoneInterfaceManager.class) { |
| 2395 | if (sInstance == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2396 | sInstance = new PhoneInterfaceManager(app); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2397 | } else { |
| 2398 | Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance); |
| 2399 | } |
| 2400 | return sInstance; |
| 2401 | } |
| 2402 | } |
| 2403 | |
| 2404 | /** Private constructor; @see init() */ |
Jordan Liu | 1979a04 | 2020-03-20 21:39:35 +0000 | [diff] [blame] | 2405 | private PhoneInterfaceManager(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2406 | mApp = app; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2407 | mCM = PhoneGlobals.getInstance().mCM; |
Brad Ebinger | d1947d8 | 2021-05-17 20:54:49 +0000 | [diff] [blame] | 2408 | mImsResolver = ImsResolver.getInstance(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 2409 | mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2410 | mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 2411 | mPm = app.getSystemService(PackageManager.class); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2412 | mMainThreadHandler = new MainThreadHandler(); |
Jack Yu | e37dd26 | 2022-12-16 11:53:37 -0800 | [diff] [blame^] | 2413 | if (!PhoneFactory.isSubscriptionManagerServiceEnabled()) { |
| 2414 | mSubscriptionController = SubscriptionController.getInstance(); |
| 2415 | } else { |
| 2416 | mSubscriptionController = null; |
| 2417 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2418 | mTelephonySharedPreferences = |
| 2419 | PreferenceManager.getDefaultSharedPreferences(mApp); |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 2420 | mNetworkScanRequestTracker = new NetworkScanRequestTracker(); |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 2421 | mPhoneConfigurationManager = PhoneConfigurationManager.getInstance(); |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 2422 | mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance(); |
Peter Wang | a3cf4ac | 2020-01-27 09:39:46 +0800 | [diff] [blame] | 2423 | mNotifyUserActivity = new AtomicBoolean(false); |
Tyler Gunn | 64144d9 | 2022-03-17 14:16:41 -0700 | [diff] [blame] | 2424 | PropertyInvalidatedCache.invalidateCache(TelephonyManager.CACHE_KEY_PHONE_ACCOUNT_TO_SUBID); |
Gil Cukierman | 6dac5eb | 2022-09-19 16:09:04 +0000 | [diff] [blame] | 2425 | mTelephony2gUpdater = new Telephony2gUpdater( |
| 2426 | Executors.newSingleThreadExecutor(), mApp); |
| 2427 | mTelephony2gUpdater.init(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2428 | publish(); |
| 2429 | } |
| 2430 | |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 2431 | @VisibleForTesting |
| 2432 | public SharedPreferences getSharedPreferences() { |
| 2433 | return mTelephonySharedPreferences; |
| 2434 | } |
| 2435 | |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2436 | private Phone getDefaultPhone() { |
| 2437 | Phone thePhone = getPhone(getDefaultSubscription()); |
| 2438 | return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone(); |
| 2439 | } |
| 2440 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2441 | private void publish() { |
| 2442 | if (DBG) log("publish: " + this); |
| 2443 | |
Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 2444 | TelephonyFrameworkInitializer |
| 2445 | .getTelephonyServiceManager() |
| 2446 | .getTelephonyServiceRegisterer() |
| 2447 | .register(this); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2448 | } |
| 2449 | |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 2450 | private Phone getPhoneFromRequest(MainThreadRequest request) { |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 2451 | if (request.phone != null) { |
| 2452 | return request.phone; |
| 2453 | } else { |
| 2454 | return getPhoneFromSubId(request.subId); |
| 2455 | } |
| 2456 | } |
| 2457 | |
| 2458 | private Phone getPhoneFromSubId(int subId) { |
| 2459 | return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) |
| 2460 | ? getDefaultPhone() : getPhone(subId); |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 2461 | } |
| 2462 | |
Rambo Wang | e53e07d | 2022-05-10 13:01:13 -0700 | [diff] [blame] | 2463 | @Nullable |
| 2464 | private UiccPort getUiccPortFromRequest(@NonNull MainThreadRequest request) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2465 | Phone phone = getPhoneFromRequest(request); |
| 2466 | return phone == null ? null : |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 2467 | UiccController.getInstance().getUiccPort(phone.getPhoneId()); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2468 | } |
| 2469 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2470 | // returns phone associated with the subId. |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2471 | private Phone getPhone(int subId) { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 2472 | return PhoneFactory.getPhone(SubscriptionManager.getPhoneId(subId)); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2473 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2474 | |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 2475 | private void sendEraseModemConfig(@NonNull Phone phone) { |
| 2476 | Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null); |
| 2477 | if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 2478 | } |
| 2479 | |
| 2480 | private void sendEraseDataInSharedPreferences(@NonNull Phone phone) { |
| 2481 | Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null); |
| 2482 | if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail")); |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 2483 | } |
| 2484 | |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 2485 | private boolean isImsAvailableOnDevice() { |
| 2486 | PackageManager pm = getDefaultPhone().getContext().getPackageManager(); |
| 2487 | if (pm == null) { |
| 2488 | // For some reason package manger is not available.. This will fail internally anyway, |
| 2489 | // so do not throw error and allow. |
| 2490 | return true; |
| 2491 | } |
| 2492 | return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0); |
| 2493 | } |
| 2494 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2495 | public void dial(String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2496 | dialForSubscriber(getPreferredVoiceSubscription(), number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2497 | } |
| 2498 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2499 | public void dialForSubscriber(int subId, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2500 | if (DBG) log("dial: " + number); |
| 2501 | // No permission check needed here: This is just a wrapper around the |
| 2502 | // ACTION_DIAL intent, which is available to any app since it puts up |
| 2503 | // the UI before it does anything. |
| 2504 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2505 | final long identity = Binder.clearCallingIdentity(); |
| 2506 | try { |
| 2507 | String url = createTelUrl(number); |
| 2508 | if (url == null) { |
| 2509 | return; |
| 2510 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2511 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2512 | // PENDING: should we just silently fail if phone is offhook or ringing? |
| 2513 | PhoneConstants.State state = mCM.getState(subId); |
| 2514 | if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) { |
| 2515 | Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url)); |
| 2516 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2517 | mApp.startActivity(intent); |
| 2518 | } |
| 2519 | } finally { |
| 2520 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2521 | } |
| 2522 | } |
| 2523 | |
| 2524 | public void call(String callingPackage, String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2525 | callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2526 | } |
| 2527 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2528 | public void callForSubscriber(int subId, String callingPackage, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2529 | if (DBG) log("call: " + number); |
| 2530 | |
| 2531 | // This is just a wrapper around the ACTION_CALL intent, but we still |
| 2532 | // need to do a permission check since we're calling startActivity() |
| 2533 | // from the context of the phone app. |
| 2534 | enforceCallPermission(); |
| 2535 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 2536 | if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage) |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2537 | != AppOpsManager.MODE_ALLOWED) { |
| 2538 | return; |
| 2539 | } |
| 2540 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2541 | final long identity = Binder.clearCallingIdentity(); |
| 2542 | try { |
| 2543 | String url = createTelUrl(number); |
| 2544 | if (url == null) { |
| 2545 | return; |
| 2546 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2547 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2548 | boolean isValid = false; |
| 2549 | final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged(); |
| 2550 | if (slist != null) { |
| 2551 | for (SubscriptionInfo subInfoRecord : slist) { |
| 2552 | if (subInfoRecord.getSubscriptionId() == subId) { |
| 2553 | isValid = true; |
| 2554 | break; |
| 2555 | } |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 2556 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 2557 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2558 | if (!isValid) { |
| 2559 | return; |
| 2560 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 2561 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2562 | Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url)); |
| 2563 | intent.putExtra(SUBSCRIPTION_KEY, subId); |
| 2564 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2565 | mApp.startActivity(intent); |
| 2566 | } finally { |
| 2567 | Binder.restoreCallingIdentity(identity); |
| 2568 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2569 | } |
| 2570 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2571 | public boolean supplyPinForSubscriber(int subId, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2572 | int [] resultArray = supplyPinReportResultForSubscriber(subId, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2573 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 2574 | } |
| 2575 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2576 | public boolean supplyPukForSubscriber(int subId, String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2577 | int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2578 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 2579 | } |
| 2580 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2581 | public int[] supplyPinReportResultForSubscriber(int subId, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2582 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2583 | |
| 2584 | final long identity = Binder.clearCallingIdentity(); |
| 2585 | try { |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2586 | Phone phone = getPhone(subId); |
| 2587 | final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2588 | checkSimPin.start(); |
| 2589 | return checkSimPin.unlockSim(null, pin); |
| 2590 | } finally { |
| 2591 | Binder.restoreCallingIdentity(identity); |
| 2592 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2593 | } |
| 2594 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2595 | public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2596 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2597 | |
| 2598 | final long identity = Binder.clearCallingIdentity(); |
| 2599 | try { |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2600 | Phone phone = getPhone(subId); |
| 2601 | final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2602 | checkSimPuk.start(); |
| 2603 | return checkSimPuk.unlockSim(puk, pin); |
| 2604 | } finally { |
| 2605 | Binder.restoreCallingIdentity(identity); |
| 2606 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2607 | } |
| 2608 | |
| 2609 | /** |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2610 | * Helper thread to turn async call to SimCard#supplyPin into |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2611 | * a synchronous one. |
| 2612 | */ |
| 2613 | private static class UnlockSim extends Thread { |
| 2614 | |
| 2615 | private final IccCard mSimCard; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2616 | private final int mPhoneId; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2617 | |
| 2618 | private boolean mDone = false; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2619 | private int mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 2620 | private int mRetryCount = -1; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2621 | |
| 2622 | // For replies from SimCard interface |
| 2623 | private Handler mHandler; |
| 2624 | |
| 2625 | // For async handler to identify request type |
| 2626 | private static final int SUPPLY_PIN_COMPLETE = 100; |
| 2627 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2628 | UnlockSim(int phoneId, IccCard simCard) { |
| 2629 | mPhoneId = phoneId; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2630 | mSimCard = simCard; |
| 2631 | } |
| 2632 | |
| 2633 | @Override |
| 2634 | public void run() { |
| 2635 | Looper.prepare(); |
| 2636 | synchronized (UnlockSim.this) { |
| 2637 | mHandler = new Handler() { |
| 2638 | @Override |
| 2639 | public void handleMessage(Message msg) { |
| 2640 | AsyncResult ar = (AsyncResult) msg.obj; |
| 2641 | switch (msg.what) { |
| 2642 | case SUPPLY_PIN_COMPLETE: |
| 2643 | Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE"); |
| 2644 | synchronized (UnlockSim.this) { |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2645 | mRetryCount = msg.arg1; |
| 2646 | if (ar.exception != null) { |
| 2647 | if (ar.exception instanceof CommandException && |
| 2648 | ((CommandException)(ar.exception)).getCommandError() |
| 2649 | == CommandException.Error.PASSWORD_INCORRECT) { |
| 2650 | mResult = PhoneConstants.PIN_PASSWORD_INCORRECT; |
vivi.li | b5e9ada | 2019-09-12 16:04:24 +0800 | [diff] [blame] | 2651 | } //When UiccCardApp dispose,handle message and return exception |
| 2652 | else if (ar.exception instanceof CommandException && |
| 2653 | ((CommandException) (ar.exception)).getCommandError() |
| 2654 | == CommandException.Error.ABORTED) { |
| 2655 | mResult = PhoneConstants.PIN_OPERATION_ABORTED; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2656 | } else { |
| 2657 | mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 2658 | } |
| 2659 | } else { |
| 2660 | mResult = PhoneConstants.PIN_RESULT_SUCCESS; |
| 2661 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2662 | mDone = true; |
| 2663 | UnlockSim.this.notifyAll(); |
| 2664 | } |
| 2665 | break; |
| 2666 | } |
| 2667 | } |
| 2668 | }; |
| 2669 | UnlockSim.this.notifyAll(); |
| 2670 | } |
| 2671 | Looper.loop(); |
| 2672 | } |
| 2673 | |
| 2674 | /* |
| 2675 | * Use PIN or PUK to unlock SIM card |
| 2676 | * |
| 2677 | * If PUK is null, unlock SIM card with PIN |
| 2678 | * |
| 2679 | * If PUK is not null, unlock SIM card with PUK and set PIN code |
| 2680 | */ |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2681 | synchronized int[] unlockSim(String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2682 | |
| 2683 | while (mHandler == null) { |
| 2684 | try { |
| 2685 | wait(); |
| 2686 | } catch (InterruptedException e) { |
| 2687 | Thread.currentThread().interrupt(); |
| 2688 | } |
| 2689 | } |
| 2690 | Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE); |
| 2691 | |
| 2692 | if (puk == null) { |
| 2693 | mSimCard.supplyPin(pin, callback); |
| 2694 | } else { |
| 2695 | mSimCard.supplyPuk(puk, pin, callback); |
| 2696 | } |
| 2697 | |
| 2698 | while (!mDone) { |
| 2699 | try { |
| 2700 | Log.d(LOG_TAG, "wait for done"); |
| 2701 | wait(); |
| 2702 | } catch (InterruptedException e) { |
| 2703 | // Restore the interrupted status |
| 2704 | Thread.currentThread().interrupt(); |
| 2705 | } |
| 2706 | } |
| 2707 | Log.d(LOG_TAG, "done"); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2708 | int[] resultArray = new int[2]; |
| 2709 | resultArray[0] = mResult; |
| 2710 | resultArray[1] = mRetryCount; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2711 | |
| 2712 | if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) { |
Jon Spivack | 9c3bc76 | 2021-10-06 20:53:09 +0000 | [diff] [blame] | 2713 | UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2714 | } |
| 2715 | |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2716 | return resultArray; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2717 | } |
| 2718 | } |
| 2719 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2720 | /** |
| 2721 | * This method has been removed due to privacy and stability concerns. |
| 2722 | */ |
| 2723 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2724 | public void updateServiceLocation() { |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2725 | Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()"); |
| 2726 | return; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2727 | } |
| 2728 | |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2729 | @Override |
| 2730 | public void updateServiceLocationWithPackageName(String callingPackage) { |
| 2731 | mApp.getSystemService(AppOpsManager.class) |
| 2732 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 2733 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 2734 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2735 | if (targetSdk > android.os.Build.VERSION_CODES.R) { |
| 2736 | // Callers targeting S have no business invoking this method. |
| 2737 | return; |
| 2738 | } |
| 2739 | |
| 2740 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2741 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2742 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2743 | .setCallingPackage(callingPackage) |
| 2744 | .setCallingFeatureId(null) |
| 2745 | .setCallingPid(Binder.getCallingPid()) |
| 2746 | .setCallingUid(Binder.getCallingUid()) |
| 2747 | .setMethod("updateServiceLocation") |
| 2748 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
| 2749 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2750 | .build()); |
| 2751 | // Apps that lack location permission have no business calling this method; |
| 2752 | // however, because no permission was declared in the public API, denials must |
| 2753 | // all be "soft". |
| 2754 | switch (locationResult) { |
| 2755 | case DENIED_HARD: /* fall through */ |
| 2756 | case DENIED_SOFT: |
| 2757 | return; |
| 2758 | } |
| 2759 | |
| 2760 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2761 | final long identity = Binder.clearCallingIdentity(); |
| 2762 | try { |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2763 | final Phone phone = getPhone(getDefaultSubscription()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2764 | if (phone != null) { |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2765 | phone.updateServiceLocation(workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2766 | } |
| 2767 | } finally { |
| 2768 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2769 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2770 | } |
| 2771 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2772 | @Deprecated |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2773 | @Override |
| 2774 | public boolean isRadioOn(String callingPackage) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2775 | return isRadioOnWithFeature(callingPackage, null); |
| 2776 | } |
| 2777 | |
| 2778 | |
| 2779 | @Override |
| 2780 | public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) { |
| 2781 | return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage, |
| 2782 | callingFeatureId); |
| 2783 | } |
| 2784 | |
| 2785 | @Deprecated |
| 2786 | @Override |
| 2787 | public boolean isRadioOnForSubscriber(int subId, String callingPackage) { |
| 2788 | return isRadioOnForSubscriberWithFeature(subId, callingPackage, null); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2789 | } |
| 2790 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2791 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2792 | public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage, |
| 2793 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2794 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2795 | mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2796 | return false; |
| 2797 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2798 | |
| 2799 | final long identity = Binder.clearCallingIdentity(); |
| 2800 | try { |
| 2801 | return isRadioOnForSubscriber(subId); |
| 2802 | } finally { |
| 2803 | Binder.restoreCallingIdentity(identity); |
| 2804 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2805 | } |
| 2806 | |
| 2807 | private boolean isRadioOnForSubscriber(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2808 | final long identity = Binder.clearCallingIdentity(); |
| 2809 | try { |
| 2810 | final Phone phone = getPhone(subId); |
| 2811 | if (phone != null) { |
| 2812 | return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF; |
| 2813 | } else { |
| 2814 | return false; |
| 2815 | } |
| 2816 | } finally { |
| 2817 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2818 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2819 | } |
| 2820 | |
| 2821 | public void toggleRadioOnOff() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2822 | toggleRadioOnOffForSubscriber(getDefaultSubscription()); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2823 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2824 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2825 | public void toggleRadioOnOffForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2826 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2827 | |
| 2828 | final long identity = Binder.clearCallingIdentity(); |
| 2829 | try { |
| 2830 | final Phone phone = getPhone(subId); |
| 2831 | if (phone != null) { |
| 2832 | phone.setRadioPower(!isRadioOnForSubscriber(subId)); |
| 2833 | } |
| 2834 | } finally { |
| 2835 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2836 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2837 | } |
| 2838 | |
| 2839 | public boolean setRadio(boolean turnOn) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2840 | return setRadioForSubscriber(getDefaultSubscription(), turnOn); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2841 | } |
| 2842 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2843 | public boolean setRadioForSubscriber(int subId, boolean turnOn) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2844 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2845 | |
| 2846 | final long identity = Binder.clearCallingIdentity(); |
| 2847 | try { |
| 2848 | final Phone phone = getPhone(subId); |
| 2849 | if (phone == null) { |
| 2850 | return false; |
| 2851 | } |
| 2852 | if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) { |
| 2853 | toggleRadioOnOffForSubscriber(subId); |
| 2854 | } |
| 2855 | return true; |
| 2856 | } finally { |
| 2857 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2858 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2859 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2860 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2861 | public boolean needMobileRadioShutdown() { |
Shuo Qian | fa7b6b3 | 2019-12-10 10:40:38 -0800 | [diff] [blame] | 2862 | enforceReadPrivilegedPermission("needMobileRadioShutdown"); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2863 | /* |
| 2864 | * If any of the Radios are available, it will need to be |
| 2865 | * shutdown. So return true if any Radio is available. |
| 2866 | */ |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2867 | final long identity = Binder.clearCallingIdentity(); |
| 2868 | try { |
| 2869 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 2870 | Phone phone = PhoneFactory.getPhone(i); |
| 2871 | if (phone != null && phone.isRadioAvailable()) return true; |
| 2872 | } |
| 2873 | logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown."); |
| 2874 | return false; |
| 2875 | } finally { |
| 2876 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2877 | } |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2878 | } |
| 2879 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2880 | @Override |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2881 | public void shutdownMobileRadios() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2882 | enforceModifyPermission(); |
| 2883 | |
| 2884 | final long identity = Binder.clearCallingIdentity(); |
| 2885 | try { |
| 2886 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 2887 | logv("Shutting down Phone " + i); |
| 2888 | shutdownRadioUsingPhoneId(i); |
| 2889 | } |
| 2890 | } finally { |
| 2891 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2892 | } |
| 2893 | } |
| 2894 | |
| 2895 | private void shutdownRadioUsingPhoneId(int phoneId) { |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2896 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 2897 | if (phone != null && phone.isRadioAvailable()) { |
| 2898 | phone.shutdownRadio(); |
| 2899 | } |
| 2900 | } |
| 2901 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2902 | public boolean setRadioPower(boolean turnOn) { |
Jack Yu | b4e1616 | 2017-05-15 12:48:40 -0700 | [diff] [blame] | 2903 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2904 | |
| 2905 | final long identity = Binder.clearCallingIdentity(); |
| 2906 | try { |
| 2907 | final Phone defaultPhone = PhoneFactory.getDefaultPhone(); |
| 2908 | if (defaultPhone != null) { |
| 2909 | defaultPhone.setRadioPower(turnOn); |
| 2910 | return true; |
| 2911 | } else { |
| 2912 | loge("There's no default phone."); |
| 2913 | return false; |
| 2914 | } |
| 2915 | } finally { |
| 2916 | Binder.restoreCallingIdentity(identity); |
Wei Liu | 9ae2a06 | 2016-08-08 11:09:34 -0700 | [diff] [blame] | 2917 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2918 | } |
| 2919 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2920 | public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2921 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2922 | |
| 2923 | final long identity = Binder.clearCallingIdentity(); |
| 2924 | try { |
| 2925 | final Phone phone = getPhone(subId); |
| 2926 | if (phone != null) { |
| 2927 | phone.setRadioPower(turnOn); |
| 2928 | return true; |
| 2929 | } else { |
| 2930 | return false; |
| 2931 | } |
| 2932 | } finally { |
| 2933 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2934 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2935 | } |
| 2936 | |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 2937 | /** |
| 2938 | * Vote on powering off the radio for a reason. The radio will be turned on only when there is |
| 2939 | * no reason to power it off. When any of the voters want to power it off, it will be turned |
| 2940 | * off. In case of emergency, the radio will be turned on even if there are some reasons for |
| 2941 | * powering it off, and these radio off votes will be cleared. |
| 2942 | * Multiple apps can vote for the same reason and the last vote will take effect. Each app is |
| 2943 | * responsible for its vote. A powering-off vote of a reason will be maintained until it is |
| 2944 | * cleared by calling {@link clearRadioPowerOffForReason} for that reason, or an emergency call |
| 2945 | * is made, or the device is rebooted. When an app comes backup from a crash, it needs to make |
| 2946 | * sure if its vote is as expected. An app can use the API {@link getRadioPowerOffReasons} to |
| 2947 | * check its vote. |
| 2948 | * |
| 2949 | * @param subId The subscription ID. |
| 2950 | * @param reason The reason for powering off radio. |
| 2951 | * @return true on success and false on failure. |
| 2952 | */ |
| 2953 | public boolean requestRadioPowerOffForReason(int subId, |
| 2954 | @TelephonyManager.RadioPowerReason int reason) { |
| 2955 | enforceModifyPermission(); |
| 2956 | |
| 2957 | final long identity = Binder.clearCallingIdentity(); |
| 2958 | try { |
| 2959 | final Phone phone = getPhone(subId); |
| 2960 | if (phone != null) { |
| 2961 | phone.setRadioPowerForReason(false, reason); |
| 2962 | return true; |
| 2963 | } else { |
| 2964 | return false; |
| 2965 | } |
| 2966 | } finally { |
| 2967 | Binder.restoreCallingIdentity(identity); |
| 2968 | } |
| 2969 | } |
| 2970 | |
| 2971 | /** |
| 2972 | * Remove the vote on powering off the radio for a reason, as requested by |
| 2973 | * {@link requestRadioPowerOffForReason}. |
| 2974 | * |
| 2975 | * @param subId The subscription ID. |
| 2976 | * @param reason The reason for powering off radio. |
| 2977 | * @return true on success and false on failure. |
| 2978 | */ |
| 2979 | public boolean clearRadioPowerOffForReason(int subId, |
| 2980 | @TelephonyManager.RadioPowerReason int reason) { |
| 2981 | enforceModifyPermission(); |
| 2982 | |
| 2983 | final long identity = Binder.clearCallingIdentity(); |
| 2984 | try { |
| 2985 | final Phone phone = getPhone(subId); |
| 2986 | if (phone != null) { |
| 2987 | phone.setRadioPowerForReason(true, reason); |
| 2988 | return true; |
| 2989 | } else { |
| 2990 | return false; |
| 2991 | } |
| 2992 | } finally { |
| 2993 | Binder.restoreCallingIdentity(identity); |
| 2994 | } |
| 2995 | } |
| 2996 | |
| 2997 | /** |
| 2998 | * Get reasons for powering off radio, as requested by {@link requestRadioPowerOffForReason}. |
| 2999 | * |
| 3000 | * @param subId The subscription ID. |
| 3001 | * @param callingPackage The package making the call. |
| 3002 | * @param callingFeatureId The feature in the package. |
| 3003 | * @return List of reasons for powering off radio. |
| 3004 | */ |
| 3005 | public List getRadioPowerOffReasons(int subId, String callingPackage, String callingFeatureId) { |
| 3006 | enforceReadPrivilegedPermission("getRadioPowerOffReasons"); |
| 3007 | |
| 3008 | final long identity = Binder.clearCallingIdentity(); |
| 3009 | List result = new ArrayList(); |
| 3010 | try { |
| 3011 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, |
| 3012 | callingPackage, callingFeatureId, "getRadioPowerOffReasons")) { |
| 3013 | return result; |
| 3014 | } |
| 3015 | |
| 3016 | final Phone phone = getPhone(subId); |
| 3017 | if (phone != null) { |
| 3018 | result.addAll(phone.getRadioPowerOffReasons()); |
| 3019 | } |
| 3020 | } finally { |
| 3021 | Binder.restoreCallingIdentity(identity); |
| 3022 | } |
| 3023 | return result; |
| 3024 | } |
| 3025 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3026 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3027 | @Override |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 3028 | public boolean enableDataConnectivity(String callingPackage) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3029 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3030 | |
| 3031 | final long identity = Binder.clearCallingIdentity(); |
| 3032 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3033 | int subId = SubscriptionManager.getDefaultDataSubscriptionId(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3034 | final Phone phone = getPhone(subId); |
| 3035 | if (phone != null) { |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 3036 | phone.getDataSettingsManager().setDataEnabled( |
| 3037 | TelephonyManager.DATA_ENABLED_REASON_USER, true, callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3038 | return true; |
| 3039 | } else { |
| 3040 | return false; |
| 3041 | } |
| 3042 | } finally { |
| 3043 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3044 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3045 | } |
| 3046 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3047 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3048 | @Override |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 3049 | public boolean disableDataConnectivity(String callingPackage) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3050 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3051 | |
| 3052 | final long identity = Binder.clearCallingIdentity(); |
| 3053 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3054 | int subId = SubscriptionManager.getDefaultDataSubscriptionId(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3055 | final Phone phone = getPhone(subId); |
| 3056 | if (phone != null) { |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 3057 | phone.getDataSettingsManager().setDataEnabled( |
| 3058 | TelephonyManager.DATA_ENABLED_REASON_USER, false, callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3059 | return true; |
| 3060 | } else { |
| 3061 | return false; |
| 3062 | } |
| 3063 | } finally { |
| 3064 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3065 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3066 | } |
| 3067 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3068 | @Override |
Jack Yu | acf8a13 | 2017-05-01 17:00:48 -0700 | [diff] [blame] | 3069 | public boolean isDataConnectivityPossible(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3070 | final long identity = Binder.clearCallingIdentity(); |
| 3071 | try { |
| 3072 | final Phone phone = getPhone(subId); |
| 3073 | if (phone != null) { |
Jack Yu | 59824e1 | 2022-03-23 01:42:44 -0700 | [diff] [blame] | 3074 | return phone.isDataAllowed(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3075 | } else { |
| 3076 | return false; |
| 3077 | } |
| 3078 | } finally { |
| 3079 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3080 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3081 | } |
| 3082 | |
| 3083 | public boolean handlePinMmi(String dialString) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 3084 | return handlePinMmiForSubscriber(getDefaultSubscription(), dialString); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3085 | } |
| 3086 | |
pkanwar | ae03a6b | 2016-11-06 20:37:09 -0800 | [diff] [blame] | 3087 | public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3088 | enforceCallPermission(); |
| 3089 | |
| 3090 | final long identity = Binder.clearCallingIdentity(); |
| 3091 | try { |
| 3092 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3093 | return; |
| 3094 | } |
| 3095 | Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback); |
| 3096 | sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId); |
| 3097 | } finally { |
| 3098 | Binder.restoreCallingIdentity(identity); |
| 3099 | } |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 3100 | }; |
| 3101 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3102 | public boolean handlePinMmiForSubscriber(int subId, String dialString) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3103 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3104 | |
| 3105 | final long identity = Binder.clearCallingIdentity(); |
| 3106 | try { |
| 3107 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3108 | return false; |
| 3109 | } |
| 3110 | return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId); |
| 3111 | } finally { |
| 3112 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3113 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3114 | } |
| 3115 | |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 3116 | /** |
| 3117 | * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage |
| 3118 | * tag on getCallState Binder call. |
| 3119 | */ |
| 3120 | @Deprecated |
| 3121 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3122 | public int getCallState() { |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 3123 | if (CompatChanges.isChangeEnabled( |
| 3124 | TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION, |
| 3125 | Binder.getCallingUid())) { |
| 3126 | // Do not allow this API to be called on API version 31+, it should only be |
| 3127 | // called on old apps using this Binder call directly. |
| 3128 | throw new SecurityException("This method can only be used for applications " |
| 3129 | + "targeting API version 30 or less."); |
| 3130 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3131 | final long identity = Binder.clearCallingIdentity(); |
| 3132 | try { |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 3133 | Phone phone = getPhone(getDefaultSubscription()); |
| 3134 | return phone == null ? TelephonyManager.CALL_STATE_IDLE : |
| 3135 | PhoneConstantConversions.convertCallState(phone.getState()); |
| 3136 | } finally { |
| 3137 | Binder.restoreCallingIdentity(identity); |
| 3138 | } |
| 3139 | } |
| 3140 | |
| 3141 | @Override |
| 3142 | public int getCallStateForSubscription(int subId, String callingPackage, String featureId) { |
| 3143 | if (CompatChanges.isChangeEnabled( |
| 3144 | TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION, |
| 3145 | Binder.getCallingUid())) { |
| 3146 | // Check READ_PHONE_STATE for API version 31+ |
| 3147 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage, |
| 3148 | featureId, "getCallStateForSubscription")) { |
| 3149 | throw new SecurityException("getCallState requires READ_PHONE_STATE for apps " |
| 3150 | + "targeting API level 31+."); |
| 3151 | } |
| 3152 | } |
| 3153 | final long identity = Binder.clearCallingIdentity(); |
| 3154 | try { |
| 3155 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3156 | return phone == null ? TelephonyManager.CALL_STATE_IDLE : |
| 3157 | PhoneConstantConversions.convertCallState(phone.getState()); |
| 3158 | } finally { |
| 3159 | Binder.restoreCallingIdentity(identity); |
| 3160 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3161 | } |
| 3162 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3163 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 3164 | public int getDataState() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3165 | return getDataStateForSubId(SubscriptionManager.getDefaultDataSubscriptionId()); |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 3166 | } |
| 3167 | |
| 3168 | @Override |
| 3169 | public int getDataStateForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3170 | final long identity = Binder.clearCallingIdentity(); |
| 3171 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 3172 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3173 | if (phone != null) { |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 3174 | return phone.getDataNetworkController().getInternetDataNetworkState(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3175 | } else { |
| 3176 | return PhoneConstantConversions.convertDataState( |
| 3177 | PhoneConstants.DataState.DISCONNECTED); |
| 3178 | } |
| 3179 | } finally { |
| 3180 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3181 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3182 | } |
| 3183 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3184 | @Override |
Jack Yu | 0eda684 | 2022-04-18 00:34:46 -0700 | [diff] [blame] | 3185 | public @DataActivityType int getDataActivity() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3186 | return getDataActivityForSubId(SubscriptionManager.getDefaultDataSubscriptionId()); |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 3187 | } |
| 3188 | |
| 3189 | @Override |
Jack Yu | 0eda684 | 2022-04-18 00:34:46 -0700 | [diff] [blame] | 3190 | public @DataActivityType int getDataActivityForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3191 | final long identity = Binder.clearCallingIdentity(); |
| 3192 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 3193 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3194 | if (phone != null) { |
Jack Yu | 0eda684 | 2022-04-18 00:34:46 -0700 | [diff] [blame] | 3195 | return phone.getDataActivityState(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3196 | } else { |
| 3197 | return TelephonyManager.DATA_ACTIVITY_NONE; |
| 3198 | } |
| 3199 | } finally { |
| 3200 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3201 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3202 | } |
| 3203 | |
| 3204 | @Override |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 3205 | public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3206 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 3207 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3208 | |
| 3209 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 3210 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 3211 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 3212 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3213 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3214 | .setCallingPid(Binder.getCallingPid()) |
| 3215 | .setCallingUid(Binder.getCallingUid()) |
| 3216 | .setMethod("getCellLocation") |
Hall Liu | 773ba02 | 2020-01-24 18:07:12 -0800 | [diff] [blame] | 3217 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3218 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 3219 | .build()); |
| 3220 | switch (locationResult) { |
| 3221 | case DENIED_HARD: |
| 3222 | throw new SecurityException("Not allowed to access cell location"); |
| 3223 | case DENIED_SOFT: |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 3224 | return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
| 3225 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3226 | } |
| 3227 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 3228 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3229 | final long identity = Binder.clearCallingIdentity(); |
| 3230 | try { |
| 3231 | if (DBG_LOC) log("getCellLocation: is active user"); |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3232 | int subId = SubscriptionManager.getDefaultDataSubscriptionId(); |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 3233 | return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3234 | } finally { |
| 3235 | Binder.restoreCallingIdentity(identity); |
| 3236 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 3237 | } |
| 3238 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3239 | @Override |
Jack Yu | eb1e7fe | 2020-02-22 19:38:58 -0800 | [diff] [blame] | 3240 | public String getNetworkCountryIsoForPhone(int phoneId) { |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3241 | // Reporting the correct network country is ambiguous when IWLAN could conflict with |
| 3242 | // registered cell info, so return a NULL country instead. |
| 3243 | final long identity = Binder.clearCallingIdentity(); |
| 3244 | try { |
Malcolm Chen | 3732c2b | 2018-07-18 20:15:24 -0700 | [diff] [blame] | 3245 | if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) { |
| 3246 | // Get default phone in this case. |
| 3247 | phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX; |
| 3248 | } |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3249 | final int subId = SubscriptionManager.getSubscriptionId(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3250 | Phone phone = PhoneFactory.getPhone(phoneId); |
Nathan Harold | 532f51c | 2020-04-21 19:31:10 -0700 | [diff] [blame] | 3251 | if (phone == null) return ""; |
| 3252 | ServiceStateTracker sst = phone.getServiceStateTracker(); |
| 3253 | if (sst == null) return ""; |
| 3254 | LocaleTracker lt = sst.getLocaleTracker(); |
| 3255 | if (lt == null) return ""; |
Shuo Qian | 9418a92 | 2021-03-09 11:21:16 -0800 | [diff] [blame] | 3256 | return lt.getCurrentCountry(); |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3257 | } finally { |
| 3258 | Binder.restoreCallingIdentity(identity); |
| 3259 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3260 | } |
| 3261 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 3262 | /** |
| 3263 | * This method was removed due to potential issues caused by performing partial |
| 3264 | * updates of service state, and lack of a credible use case. |
| 3265 | * |
| 3266 | * This has the ability to break the telephony implementation by disabling notification of |
| 3267 | * changes in device connectivity. DO NOT USE THIS! |
| 3268 | */ |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3269 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3270 | public void enableLocationUpdates() { |
| 3271 | mApp.enforceCallingOrSelfPermission( |
| 3272 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3273 | } |
| 3274 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 3275 | /** |
| 3276 | * This method was removed due to potential issues caused by performing partial |
| 3277 | * updates of service state, and lack of a credible use case. |
| 3278 | * |
| 3279 | * This has the ability to break the telephony implementation by disabling notification of |
| 3280 | * changes in device connectivity. DO NOT USE THIS! |
| 3281 | */ |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3282 | @Override |
| 3283 | public void disableLocationUpdates() { |
| 3284 | mApp.enforceCallingOrSelfPermission( |
| 3285 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3286 | } |
| 3287 | |
| 3288 | @Override |
| 3289 | @SuppressWarnings("unchecked") |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3290 | public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage, |
| 3291 | String callingFeatureId) { |
Nathan Harold | b55f63b | 2021-07-27 11:27:38 -0700 | [diff] [blame] | 3292 | try { |
| 3293 | mApp.getSystemService(AppOpsManager.class) |
| 3294 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 3295 | } catch (SecurityException e) { |
| 3296 | EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid()); |
| 3297 | throw e; |
| 3298 | } |
| 3299 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3300 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | dbea45a | 2018-08-30 14:35:07 -0700 | [diff] [blame] | 3301 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 3302 | throw new SecurityException( |
| 3303 | "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels."); |
| 3304 | } |
Nathan Harold | b4d5561 | 2018-07-20 13:13:08 -0700 | [diff] [blame] | 3305 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 3306 | if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(), |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3307 | callingPackage) != AppOpsManager.MODE_ALLOWED) { |
| 3308 | return null; |
| 3309 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 3310 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 3311 | if (DBG_LOC) log("getNeighboringCellInfo: is active user"); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3312 | |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3313 | List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId); |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 3314 | if (info == null) return null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3315 | |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 3316 | List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>(); |
| 3317 | for (CellInfo ci : info) { |
| 3318 | if (ci instanceof CellInfoGsm) { |
| 3319 | neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci)); |
| 3320 | } else if (ci instanceof CellInfoWcdma) { |
| 3321 | neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci)); |
| 3322 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3323 | } |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 3324 | return (neighbors.size()) > 0 ? neighbors : null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3325 | } |
| 3326 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3327 | private List<CellInfo> getCachedCellInfo() { |
| 3328 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 3329 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3330 | List<CellInfo> info = phone.getAllCellInfo(); |
| 3331 | if (info != null) cellInfos.addAll(info); |
| 3332 | } |
| 3333 | return cellInfos; |
| 3334 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3335 | |
| 3336 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3337 | public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3338 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 3339 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3340 | |
| 3341 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 3342 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 3343 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 3344 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3345 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3346 | .setCallingPid(Binder.getCallingPid()) |
| 3347 | .setCallingUid(Binder.getCallingUid()) |
| 3348 | .setMethod("getAllCellInfo") |
Nathan Harold | 5ae50b5 | 2019-02-20 15:46:36 -0800 | [diff] [blame] | 3349 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3350 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 3351 | .build()); |
| 3352 | switch (locationResult) { |
| 3353 | case DENIED_HARD: |
| 3354 | throw new SecurityException("Not allowed to access cell info"); |
| 3355 | case DENIED_SOFT: |
| 3356 | return new ArrayList<>(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3357 | } |
| 3358 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3359 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3360 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 3361 | return getCachedCellInfo(); |
| 3362 | } |
| 3363 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 3364 | if (DBG_LOC) log("getAllCellInfo: is active user"); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 3365 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3366 | final long identity = Binder.clearCallingIdentity(); |
| 3367 | try { |
| 3368 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 3369 | for (Phone phone : PhoneFactory.getPhones()) { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 3370 | final List<CellInfo> info = (List<CellInfo>) sendRequest( |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 3371 | CMD_GET_ALL_CELL_INFO, null, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3372 | if (info != null) cellInfos.addAll(info); |
| 3373 | } |
| 3374 | return cellInfos; |
| 3375 | } finally { |
| 3376 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3377 | } |
| 3378 | } |
| 3379 | |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 3380 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3381 | public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage, |
| 3382 | String callingFeatureId) { |
| 3383 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, |
| 3384 | getWorkSource(Binder.getCallingUid())); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3385 | } |
| 3386 | |
| 3387 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3388 | public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb, |
| 3389 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3390 | enforceModifyPermission(); |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3391 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3392 | } |
| 3393 | |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3394 | private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb, |
| 3395 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3396 | mApp.getSystemService(AppOpsManager.class) |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3397 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3398 | |
| 3399 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 3400 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 3401 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 3402 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3403 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3404 | .setCallingPid(Binder.getCallingPid()) |
| 3405 | .setCallingUid(Binder.getCallingUid()) |
| 3406 | .setMethod("requestCellInfoUpdate") |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 3407 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
| 3408 | .setMinSdkVersionForFine(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3409 | .build()); |
| 3410 | switch (locationResult) { |
| 3411 | case DENIED_HARD: |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3412 | if (TelephonyPermissions |
| 3413 | .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) { |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 3414 | // Safetynet logging for b/154934934 |
| 3415 | EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid()); |
| 3416 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3417 | throw new SecurityException("Not allowed to access cell info"); |
| 3418 | case DENIED_SOFT: |
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 | } |
Nathan Harold | 5320c42 | 2019-05-09 10:26:08 -0700 | [diff] [blame] | 3424 | try { |
| 3425 | cb.onCellInfo(new ArrayList<CellInfo>()); |
| 3426 | } catch (RemoteException re) { |
| 3427 | // Drop without consequences |
| 3428 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3429 | return; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3430 | } |
| 3431 | |
Nathan Harold | a939a96 | 2019-05-09 10:13:47 -0700 | [diff] [blame] | 3432 | |
| 3433 | final Phone phone = getPhoneFromSubId(subId); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3434 | if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
| 3435 | |
| 3436 | sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource); |
| 3437 | } |
| 3438 | |
| 3439 | @Override |
Aishwarya Mallampati | 0603fb1 | 2022-08-24 21:16:56 +0000 | [diff] [blame] | 3440 | public void setCellInfoListRate(int rateInMillis, int subId) { |
Jack Yu | a8d8cb8 | 2017-01-16 10:15:34 -0800 | [diff] [blame] | 3441 | enforceModifyPermission(); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 3442 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3443 | |
| 3444 | final long identity = Binder.clearCallingIdentity(); |
| 3445 | try { |
Aishwarya Mallampati | 0603fb1 | 2022-08-24 21:16:56 +0000 | [diff] [blame] | 3446 | Phone phone = getPhone(subId); |
| 3447 | if (phone == null) { |
| 3448 | getDefaultPhone().setCellInfoListRate(rateInMillis, workSource); |
| 3449 | } else { |
| 3450 | phone.setCellInfoListRate(rateInMillis, workSource); |
| 3451 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3452 | } finally { |
| 3453 | Binder.restoreCallingIdentity(identity); |
| 3454 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3455 | } |
| 3456 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3457 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3458 | public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3459 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3460 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3461 | return null; |
| 3462 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3463 | int subId = phone.getSubId(); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3464 | enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot"); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 3465 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3466 | callingPackage, callingFeatureId, "getImeiForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3467 | return null; |
| 3468 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3469 | |
| 3470 | final long identity = Binder.clearCallingIdentity(); |
| 3471 | try { |
| 3472 | return phone.getImei(); |
| 3473 | } finally { |
| 3474 | Binder.restoreCallingIdentity(identity); |
| 3475 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3476 | } |
| 3477 | |
| 3478 | @Override |
arunvoddu | d5c6ce0 | 2022-12-11 06:03:12 +0000 | [diff] [blame] | 3479 | public String getPrimaryImei(String callingPackage, String callingFeatureId) { |
| 3480 | enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getPrimaryImei"); |
| 3481 | if (!checkCallingOrSelfReadDeviceIdentifiersForAnySub(mApp, callingPackage, |
| 3482 | callingFeatureId, "getPrimaryImei")) { |
| 3483 | throw new SecurityException("Caller does not have permission"); |
| 3484 | } |
| 3485 | final long identity = Binder.clearCallingIdentity(); |
| 3486 | try { |
| 3487 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3488 | if (phone.getImeiType() == Phone.IMEI_TYPE_PRIMARY) { |
| 3489 | return phone.getImei(); |
| 3490 | } |
| 3491 | } |
| 3492 | throw new UnsupportedOperationException("Operation not supported"); |
| 3493 | } finally { |
| 3494 | Binder.restoreCallingIdentity(identity); |
| 3495 | } |
| 3496 | } |
| 3497 | |
| 3498 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3499 | public String getTypeAllocationCodeForSlot(int slotIndex) { |
| 3500 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3501 | String tac = null; |
| 3502 | if (phone != null) { |
| 3503 | String imei = phone.getImei(); |
Vala Zadeh | ab00555 | 2021-09-21 15:54:29 -0700 | [diff] [blame] | 3504 | try { |
| 3505 | tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH); |
| 3506 | } catch (IndexOutOfBoundsException e) { |
| 3507 | Log.e(LOG_TAG, "IMEI length shorter than upper index."); |
| 3508 | return null; |
| 3509 | } |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3510 | } |
| 3511 | return tac; |
| 3512 | } |
| 3513 | |
| 3514 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3515 | public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Shuo Qian | 13d8915 | 2021-05-10 23:58:11 -0700 | [diff] [blame] | 3516 | try { |
| 3517 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 3518 | } catch (SecurityException se) { |
| 3519 | EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid()); |
| 3520 | throw new SecurityException("Package " + callingPackage + " does not belong to " |
| 3521 | + Binder.getCallingUid()); |
| 3522 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3523 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3524 | if (phone == null) { |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 3525 | return null; |
| 3526 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3527 | |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3528 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 3529 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3530 | callingPackage, callingFeatureId, "getMeidForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3531 | return null; |
| 3532 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3533 | |
| 3534 | final long identity = Binder.clearCallingIdentity(); |
| 3535 | try { |
| 3536 | return phone.getMeid(); |
| 3537 | } finally { |
| 3538 | Binder.restoreCallingIdentity(identity); |
| 3539 | } |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 3540 | } |
| 3541 | |
| 3542 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3543 | public String getManufacturerCodeForSlot(int slotIndex) { |
| 3544 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3545 | String manufacturerCode = null; |
| 3546 | if (phone != null) { |
| 3547 | String meid = phone.getMeid(); |
Vala Zadeh | ab00555 | 2021-09-21 15:54:29 -0700 | [diff] [blame] | 3548 | try { |
| 3549 | manufacturerCode = |
| 3550 | meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH); |
| 3551 | } catch (IndexOutOfBoundsException e) { |
| 3552 | Log.e(LOG_TAG, "MEID length shorter than upper index."); |
| 3553 | return null; |
| 3554 | } |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3555 | } |
| 3556 | return manufacturerCode; |
| 3557 | } |
| 3558 | |
| 3559 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3560 | public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage, |
| 3561 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3562 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3563 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3564 | return null; |
| 3565 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3566 | int subId = phone.getSubId(); |
| 3567 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3568 | mApp, subId, callingPackage, callingFeatureId, |
| 3569 | "getDeviceSoftwareVersionForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3570 | return null; |
| 3571 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3572 | |
| 3573 | final long identity = Binder.clearCallingIdentity(); |
| 3574 | try { |
| 3575 | return phone.getDeviceSvn(); |
| 3576 | } finally { |
| 3577 | Binder.restoreCallingIdentity(identity); |
| 3578 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3579 | } |
| 3580 | |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3581 | @Override |
| 3582 | public int getSubscriptionCarrierId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3583 | final long identity = Binder.clearCallingIdentity(); |
| 3584 | try { |
| 3585 | final Phone phone = getPhone(subId); |
| 3586 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId(); |
| 3587 | } finally { |
| 3588 | Binder.restoreCallingIdentity(identity); |
| 3589 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3590 | } |
| 3591 | |
| 3592 | @Override |
| 3593 | public String getSubscriptionCarrierName(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3594 | final long identity = Binder.clearCallingIdentity(); |
| 3595 | try { |
| 3596 | final Phone phone = getPhone(subId); |
| 3597 | return phone == null ? null : phone.getCarrierName(); |
| 3598 | } finally { |
| 3599 | Binder.restoreCallingIdentity(identity); |
| 3600 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3601 | } |
| 3602 | |
calvinpan | ffe225e | 2018-11-01 19:43:06 +0800 | [diff] [blame] | 3603 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3604 | public int getSubscriptionSpecificCarrierId(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3605 | final long identity = Binder.clearCallingIdentity(); |
| 3606 | try { |
| 3607 | final Phone phone = getPhone(subId); |
| 3608 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3609 | : phone.getSpecificCarrierId(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3610 | } finally { |
| 3611 | Binder.restoreCallingIdentity(identity); |
| 3612 | } |
| 3613 | } |
| 3614 | |
| 3615 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3616 | public String getSubscriptionSpecificCarrierName(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3617 | final long identity = Binder.clearCallingIdentity(); |
| 3618 | try { |
| 3619 | final Phone phone = getPhone(subId); |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3620 | return phone == null ? null : phone.getSpecificCarrierName(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3621 | } finally { |
| 3622 | Binder.restoreCallingIdentity(identity); |
| 3623 | } |
| 3624 | } |
| 3625 | |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 3626 | @Override |
chen xu | 864e11c | 2018-12-06 22:10:03 -0800 | [diff] [blame] | 3627 | public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) { |
| 3628 | if (!isSubscriptionMccMnc) { |
| 3629 | enforceReadPrivilegedPermission("getCarrierIdFromMccMnc"); |
| 3630 | } |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 3631 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3632 | if (phone == null) { |
| 3633 | return TelephonyManager.UNKNOWN_CARRIER_ID; |
| 3634 | } |
| 3635 | final long identity = Binder.clearCallingIdentity(); |
| 3636 | try { |
| 3637 | return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc); |
| 3638 | } finally { |
| 3639 | Binder.restoreCallingIdentity(identity); |
| 3640 | } |
| 3641 | } |
| 3642 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3643 | // |
| 3644 | // Internal helper methods. |
| 3645 | // |
| 3646 | |
Sanket Padawe | ee13a9b | 2016-03-08 17:30:28 -0800 | [diff] [blame] | 3647 | /** |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3648 | * Make sure the caller is the calling package itself |
| 3649 | * |
| 3650 | * @throws SecurityException if the caller is not the calling package |
| 3651 | */ |
| 3652 | private void enforceCallingPackage(String callingPackage, int callingUid, String message) { |
| 3653 | int packageUid = -1; |
Grace Jia | dbefca0 | 2021-04-26 15:13:31 -0700 | [diff] [blame] | 3654 | PackageManager pm = mApp.getBaseContext().createContextAsUser( |
| 3655 | UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager(); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3656 | try { |
Grace Jia | dbefca0 | 2021-04-26 15:13:31 -0700 | [diff] [blame] | 3657 | packageUid = pm.getPackageUid(callingPackage, 0); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3658 | } catch (PackageManager.NameNotFoundException e) { |
| 3659 | // packageUid is -1 |
| 3660 | } |
| 3661 | if (packageUid != callingUid) { |
| 3662 | throw new SecurityException(message + ": Package " + callingPackage |
| 3663 | + " does not belong to " + callingUid); |
| 3664 | } |
| 3665 | } |
| 3666 | |
| 3667 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3668 | * Make sure the caller has the MODIFY_PHONE_STATE permission. |
| 3669 | * |
| 3670 | * @throws SecurityException if the caller does not have the required permission |
| 3671 | */ |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 3672 | @VisibleForTesting |
| 3673 | public void enforceModifyPermission() { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3674 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null); |
| 3675 | } |
| 3676 | |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 3677 | /** |
| 3678 | * Make sure the caller has the MODIFY_PHONE_STATE permission. |
| 3679 | * |
| 3680 | * @throws SecurityException if the caller does not have the required permission |
| 3681 | */ |
| 3682 | @VisibleForTesting |
| 3683 | public void enforceReadPermission() { |
| 3684 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, null); |
| 3685 | } |
| 3686 | |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 3687 | private void enforceActiveEmergencySessionPermission() { |
| 3688 | mApp.enforceCallingOrSelfPermission( |
| 3689 | android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null); |
| 3690 | } |
| 3691 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3692 | /** |
| 3693 | * Make sure the caller has the CALL_PHONE permission. |
| 3694 | * |
| 3695 | * @throws SecurityException if the caller does not have the required permission |
| 3696 | */ |
| 3697 | private void enforceCallPermission() { |
| 3698 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null); |
| 3699 | } |
| 3700 | |
paulhu | 5a77360 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 3701 | private void enforceSettingsPermission() { |
| 3702 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 3703 | } |
| 3704 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 3705 | private void enforceRebootPermission() { |
| 3706 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null); |
| 3707 | } |
| 3708 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3709 | private String createTelUrl(String number) { |
| 3710 | if (TextUtils.isEmpty(number)) { |
| 3711 | return null; |
| 3712 | } |
| 3713 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3714 | return "tel:" + number; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3715 | } |
| 3716 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3717 | private static void log(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3718 | Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 3719 | } |
| 3720 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3721 | private static void logv(String msg) { |
| 3722 | Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 3723 | } |
| 3724 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3725 | private static void loge(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3726 | Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 3727 | } |
| 3728 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3729 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3730 | public int getActivePhoneType() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3731 | return getActivePhoneTypeForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3732 | } |
| 3733 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3734 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3735 | public int getActivePhoneTypeForSlot(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3736 | final long identity = Binder.clearCallingIdentity(); |
| 3737 | try { |
| 3738 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3739 | if (phone == null) { |
| 3740 | return PhoneConstants.PHONE_TYPE_NONE; |
| 3741 | } else { |
| 3742 | return phone.getPhoneType(); |
| 3743 | } |
| 3744 | } finally { |
| 3745 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3746 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3747 | } |
| 3748 | |
| 3749 | /** |
| 3750 | * Returns the CDMA ERI icon index to display |
| 3751 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3752 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3753 | public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) { |
| 3754 | return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage, |
| 3755 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3756 | } |
| 3757 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3758 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3759 | public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage, |
| 3760 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3761 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3762 | mApp, subId, callingPackage, callingFeatureId, |
| 3763 | "getCdmaEriIconIndexForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3764 | return -1; |
| 3765 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3766 | |
| 3767 | final long identity = Binder.clearCallingIdentity(); |
| 3768 | try { |
| 3769 | final Phone phone = getPhone(subId); |
| 3770 | if (phone != null) { |
| 3771 | return phone.getCdmaEriIconIndex(); |
| 3772 | } else { |
| 3773 | return -1; |
| 3774 | } |
| 3775 | } finally { |
| 3776 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3777 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3778 | } |
| 3779 | |
| 3780 | /** |
| 3781 | * Returns the CDMA ERI icon mode, |
| 3782 | * 0 - ON |
| 3783 | * 1 - FLASHING |
| 3784 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3785 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3786 | public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) { |
| 3787 | return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 3788 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3789 | } |
| 3790 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3791 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3792 | public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage, |
| 3793 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3794 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3795 | mApp, subId, callingPackage, callingFeatureId, |
| 3796 | "getCdmaEriIconModeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3797 | return -1; |
| 3798 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3799 | |
| 3800 | final long identity = Binder.clearCallingIdentity(); |
| 3801 | try { |
| 3802 | final Phone phone = getPhone(subId); |
| 3803 | if (phone != null) { |
| 3804 | return phone.getCdmaEriIconMode(); |
| 3805 | } else { |
| 3806 | return -1; |
| 3807 | } |
| 3808 | } finally { |
| 3809 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3810 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3811 | } |
| 3812 | |
| 3813 | /** |
| 3814 | * Returns the CDMA ERI text, |
| 3815 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3816 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3817 | public String getCdmaEriText(String callingPackage, String callingFeatureId) { |
| 3818 | return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage, |
| 3819 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3820 | } |
| 3821 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3822 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3823 | public String getCdmaEriTextForSubscriber(int subId, String callingPackage, |
| 3824 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3825 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3826 | mApp, subId, callingPackage, callingFeatureId, |
| 3827 | "getCdmaEriIconTextForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3828 | return null; |
| 3829 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3830 | |
| 3831 | final long identity = Binder.clearCallingIdentity(); |
| 3832 | try { |
| 3833 | final Phone phone = getPhone(subId); |
| 3834 | if (phone != null) { |
| 3835 | return phone.getCdmaEriText(); |
| 3836 | } else { |
| 3837 | return null; |
| 3838 | } |
| 3839 | } finally { |
| 3840 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3841 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3842 | } |
| 3843 | |
| 3844 | /** |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3845 | * Returns the CDMA MDN. |
| 3846 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3847 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3848 | public String getCdmaMdn(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3849 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3850 | mApp, subId, "getCdmaMdn"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3851 | |
| 3852 | final long identity = Binder.clearCallingIdentity(); |
| 3853 | try { |
| 3854 | final Phone phone = getPhone(subId); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3855 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3856 | return phone.getLine1Number(); |
| 3857 | } else { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3858 | loge("getCdmaMdn: no phone found. Invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3859 | return null; |
| 3860 | } |
| 3861 | } finally { |
| 3862 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3863 | } |
| 3864 | } |
| 3865 | |
| 3866 | /** |
| 3867 | * Returns the CDMA MIN. |
| 3868 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3869 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3870 | public String getCdmaMin(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3871 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3872 | mApp, subId, "getCdmaMin"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3873 | |
| 3874 | final long identity = Binder.clearCallingIdentity(); |
| 3875 | try { |
| 3876 | final Phone phone = getPhone(subId); |
| 3877 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
| 3878 | return phone.getCdmaMin(); |
| 3879 | } else { |
| 3880 | return null; |
| 3881 | } |
| 3882 | } finally { |
| 3883 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3884 | } |
| 3885 | } |
| 3886 | |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3887 | @Override |
| 3888 | public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis, |
| 3889 | INumberVerificationCallback callback, String callingPackage) { |
| 3890 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 3891 | != PERMISSION_GRANTED) { |
| 3892 | throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission"); |
| 3893 | } |
| 3894 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 3895 | |
| 3896 | String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp); |
| 3897 | if (!TextUtils.equals(callingPackage, authorizedPackage)) { |
Hall Liu | b9d8feb | 2021-01-13 10:28:04 -0800 | [diff] [blame] | 3898 | throw new SecurityException("Calling package must be configured in the device config: " |
| 3899 | + "calling package: " + callingPackage |
| 3900 | + ", configured package: " + authorizedPackage); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3901 | } |
| 3902 | |
| 3903 | if (range == null) { |
| 3904 | throw new NullPointerException("Range must be non-null"); |
| 3905 | } |
| 3906 | |
| 3907 | timeoutMillis = Math.min(timeoutMillis, |
Hall Liu | bd069e3 | 2019-02-28 18:56:30 -0800 | [diff] [blame] | 3908 | TelephonyManager.getMaxNumberVerificationTimeoutMillis()); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3909 | |
| 3910 | NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis); |
| 3911 | } |
| 3912 | |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3913 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3914 | * Returns true if CDMA provisioning needs to run. |
| 3915 | */ |
| 3916 | public boolean needsOtaServiceProvisioning() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3917 | final long identity = Binder.clearCallingIdentity(); |
| 3918 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3919 | return getDefaultPhone().needsOtaServiceProvisioning(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3920 | } finally { |
| 3921 | Binder.restoreCallingIdentity(identity); |
| 3922 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3923 | } |
| 3924 | |
| 3925 | /** |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3926 | * Sets the voice mail number of a given subId. |
| 3927 | */ |
| 3928 | @Override |
| 3929 | public boolean setVoiceMailNumber(int subId, String alphaTag, String number) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 3930 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 3931 | mApp, subId, "setVoiceMailNumber"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3932 | |
| 3933 | final long identity = Binder.clearCallingIdentity(); |
| 3934 | try { |
| 3935 | Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER, |
| 3936 | new Pair<String, String>(alphaTag, number), new Integer(subId)); |
| 3937 | return success; |
| 3938 | } finally { |
| 3939 | Binder.restoreCallingIdentity(identity); |
| 3940 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3941 | } |
| 3942 | |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3943 | @Override |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3944 | public Bundle getVisualVoicemailSettings(String callingPackage, int subId) { |
| 3945 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 3946 | TelecomManager tm = mApp.getSystemService(TelecomManager.class); |
| 3947 | String systemDialer = tm.getSystemDialerPackage(); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3948 | if (!TextUtils.equals(callingPackage, systemDialer)) { |
| 3949 | throw new SecurityException("caller must be system dialer"); |
| 3950 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3951 | |
| 3952 | final long identity = Binder.clearCallingIdentity(); |
| 3953 | try { |
| 3954 | PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId); |
| 3955 | if (phoneAccountHandle == null) { |
| 3956 | return null; |
| 3957 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3958 | return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3959 | } finally { |
| 3960 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3961 | } |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3962 | } |
| 3963 | |
| 3964 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3965 | public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId, |
| 3966 | int subId) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3967 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3968 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3969 | mApp, subId, callingPackage, callingFeatureId, |
| 3970 | "getVisualVoicemailPackageName")) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3971 | return null; |
| 3972 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3973 | |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 3974 | final long identity = Binder.clearCallingIdentity(); |
| 3975 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3976 | return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName(); |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 3977 | } finally { |
| 3978 | Binder.restoreCallingIdentity(identity); |
| 3979 | } |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3980 | } |
| 3981 | |
| 3982 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3983 | public void enableVisualVoicemailSmsFilter(String callingPackage, int subId, |
| 3984 | VisualVoicemailSmsFilterSettings settings) { |
| 3985 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3986 | |
| 3987 | final long identity = Binder.clearCallingIdentity(); |
| 3988 | try { |
| 3989 | VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3990 | mApp, callingPackage, subId, settings); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3991 | } finally { |
| 3992 | Binder.restoreCallingIdentity(identity); |
| 3993 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3994 | } |
| 3995 | |
| 3996 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3997 | public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) { |
| 3998 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3999 | |
| 4000 | final long identity = Binder.clearCallingIdentity(); |
| 4001 | try { |
| 4002 | VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4003 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4004 | } finally { |
| 4005 | Binder.restoreCallingIdentity(identity); |
| 4006 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 4007 | } |
| 4008 | |
| 4009 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 4010 | public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings( |
| 4011 | String callingPackage, int subId) { |
| 4012 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4013 | |
| 4014 | final long identity = Binder.clearCallingIdentity(); |
| 4015 | try { |
| 4016 | return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4017 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4018 | } finally { |
| 4019 | Binder.restoreCallingIdentity(identity); |
| 4020 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 4021 | } |
| 4022 | |
| 4023 | @Override |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 4024 | public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4025 | enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4026 | |
| 4027 | final long identity = Binder.clearCallingIdentity(); |
| 4028 | try { |
| 4029 | return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4030 | mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4031 | } finally { |
| 4032 | Binder.restoreCallingIdentity(identity); |
| 4033 | } |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 4034 | } |
| 4035 | |
| 4036 | @Override |
Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 4037 | public void sendVisualVoicemailSmsForSubscriber(String callingPackage, |
| 4038 | String callingAttributionTag, int subId, String number, int port, String text, |
| 4039 | PendingIntent sentIntent) { |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 4040 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 4041 | enforceVisualVoicemailPackage(callingPackage, subId); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 4042 | enforceSendSmsPermission(); |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 4043 | SmsController smsController = PhoneFactory.getSmsController(); |
Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 4044 | smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag, |
| 4045 | subId, number, port, text, sentIntent); |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 4046 | } |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 4047 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 4048 | /** |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4049 | * Sets the voice activation state of a given subId. |
| 4050 | */ |
| 4051 | @Override |
| 4052 | public void setVoiceActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4053 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4054 | mApp, subId, "setVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4055 | |
| 4056 | final long identity = Binder.clearCallingIdentity(); |
| 4057 | try { |
| 4058 | final Phone phone = getPhone(subId); |
| 4059 | if (phone != null) { |
| 4060 | phone.setVoiceActivationState(activationState); |
| 4061 | } else { |
| 4062 | loge("setVoiceActivationState fails with invalid subId: " + subId); |
| 4063 | } |
| 4064 | } finally { |
| 4065 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4066 | } |
| 4067 | } |
| 4068 | |
| 4069 | /** |
| 4070 | * Sets the data activation state of a given subId. |
| 4071 | */ |
| 4072 | @Override |
| 4073 | public void setDataActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4074 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4075 | mApp, subId, "setDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4076 | |
| 4077 | final long identity = Binder.clearCallingIdentity(); |
| 4078 | try { |
| 4079 | final Phone phone = getPhone(subId); |
| 4080 | if (phone != null) { |
| 4081 | phone.setDataActivationState(activationState); |
| 4082 | } else { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 4083 | loge("setDataActivationState fails with invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4084 | } |
| 4085 | } finally { |
| 4086 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4087 | } |
| 4088 | } |
| 4089 | |
| 4090 | /** |
| 4091 | * Returns the voice activation state of a given subId. |
| 4092 | */ |
| 4093 | @Override |
| 4094 | public int getVoiceActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4095 | enforceReadPrivilegedPermission("getVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4096 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4097 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4098 | final long identity = Binder.clearCallingIdentity(); |
| 4099 | try { |
| 4100 | if (phone != null) { |
| 4101 | return phone.getVoiceActivationState(); |
| 4102 | } else { |
| 4103 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 4104 | } |
| 4105 | } finally { |
| 4106 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4107 | } |
| 4108 | } |
| 4109 | |
| 4110 | /** |
| 4111 | * Returns the data activation state of a given subId. |
| 4112 | */ |
| 4113 | @Override |
| 4114 | public int getDataActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4115 | enforceReadPrivilegedPermission("getDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4116 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4117 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4118 | final long identity = Binder.clearCallingIdentity(); |
| 4119 | try { |
| 4120 | if (phone != null) { |
| 4121 | return phone.getDataActivationState(); |
| 4122 | } else { |
| 4123 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 4124 | } |
| 4125 | } finally { |
| 4126 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4127 | } |
| 4128 | } |
| 4129 | |
| 4130 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4131 | * Returns the unread count of voicemails for a subId |
| 4132 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4133 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4134 | public int getVoiceMessageCountForSubscriber(int subId, String callingPackage, |
| 4135 | String callingFeatureId) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 4136 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4137 | mApp, subId, callingPackage, callingFeatureId, |
| 4138 | "getVoiceMessageCountForSubscriber")) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 4139 | return 0; |
| 4140 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4141 | final long identity = Binder.clearCallingIdentity(); |
| 4142 | try { |
| 4143 | final Phone phone = getPhone(subId); |
| 4144 | if (phone != null) { |
| 4145 | return phone.getVoiceMessageCount(); |
| 4146 | } else { |
| 4147 | return 0; |
| 4148 | } |
| 4149 | } finally { |
| 4150 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4151 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4152 | } |
| 4153 | |
| 4154 | /** |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 4155 | * returns true, if the device is in a state where both voice and data |
| 4156 | * are supported simultaneously. This can change based on location or network condition. |
| 4157 | */ |
| 4158 | @Override |
| 4159 | public boolean isConcurrentVoiceAndDataAllowed(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4160 | final long identity = Binder.clearCallingIdentity(); |
| 4161 | try { |
| 4162 | final Phone phone = getPhone(subId); |
| 4163 | return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed()); |
| 4164 | } finally { |
| 4165 | Binder.restoreCallingIdentity(identity); |
| 4166 | } |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 4167 | } |
| 4168 | |
| 4169 | /** |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4170 | * Send the dialer code if called from the current default dialer or the caller has |
| 4171 | * carrier privilege. |
| 4172 | * @param inputCode The dialer code to send |
| 4173 | */ |
| 4174 | @Override |
| 4175 | public void sendDialerSpecialCode(String callingPackage, String inputCode) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4176 | final Phone defaultPhone = getDefaultPhone(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4177 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 4178 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 4179 | String defaultDialer = tm.getDefaultDialerPackage(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4180 | if (!TextUtils.equals(callingPackage, defaultDialer)) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 4181 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4182 | getDefaultSubscription(), "sendDialerSpecialCode"); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4183 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4184 | |
| 4185 | final long identity = Binder.clearCallingIdentity(); |
| 4186 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4187 | defaultPhone.sendDialerSpecialCode(inputCode); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4188 | } finally { |
| 4189 | Binder.restoreCallingIdentity(identity); |
| 4190 | } |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4191 | } |
| 4192 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 4193 | @Override |
| 4194 | public int getNetworkSelectionMode(int subId) { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 4195 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4196 | .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 4197 | mApp, subId, "getNetworkSelectionMode"); |
| 4198 | final long identity = Binder.clearCallingIdentity(); |
| 4199 | try { |
| 4200 | if (!isActiveSubscription(subId)) { |
| 4201 | return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 4202 | } |
| 4203 | return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId); |
| 4204 | } finally { |
| 4205 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 4206 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 4207 | } |
| 4208 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4209 | @Override |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 4210 | public boolean isInEmergencySmsMode() { |
| 4211 | enforceReadPrivilegedPermission("isInEmergencySmsMode"); |
| 4212 | final long identity = Binder.clearCallingIdentity(); |
| 4213 | try { |
| 4214 | for (Phone phone : PhoneFactory.getPhones()) { |
| 4215 | if (phone.isInEmergencySmsMode()) { |
| 4216 | return true; |
| 4217 | } |
| 4218 | } |
| 4219 | } finally { |
| 4220 | Binder.restoreCallingIdentity(identity); |
| 4221 | } |
| 4222 | return false; |
| 4223 | } |
| 4224 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4225 | /** |
| 4226 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4227 | * @param subId The subscription to use to check the configuration. |
| 4228 | * @param c The callback that will be used to send the result. |
| 4229 | */ |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 4230 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4231 | public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c) |
| 4232 | throws RemoteException { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4233 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4234 | mApp, subId, "registerImsRegistrationCallback"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4235 | |
| 4236 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4237 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4238 | "IMS not available on device."); |
| 4239 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4240 | final long token = Binder.clearCallingIdentity(); |
| 4241 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4242 | int slotId = getSlotIndexOrException(subId); |
| 4243 | verifyImsMmTelConfiguredOrThrow(slotId); |
joonhunshin | 49f0aed | 2022-08-05 08:33:05 +0000 | [diff] [blame] | 4244 | |
| 4245 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4246 | if (controller != null) { |
| 4247 | ImsManager imsManager = controller.getImsManager(subId); |
| 4248 | if (imsManager != null) { |
| 4249 | imsManager.addRegistrationCallbackForSubscription(c, subId); |
| 4250 | } else { |
| 4251 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE); |
| 4252 | } |
| 4253 | } else { |
| 4254 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION); |
| 4255 | } |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4256 | } catch (ImsException e) { |
| 4257 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4258 | } finally { |
| 4259 | Binder.restoreCallingIdentity(token); |
| 4260 | } |
| 4261 | } |
| 4262 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4263 | /** |
| 4264 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4265 | * @param subId The subscription to use to check the configuration. |
| 4266 | * @param c The callback that will be used to send the result. |
| 4267 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4268 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4269 | public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4270 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4271 | mApp, subId, "unregisterImsRegistrationCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4272 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4273 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4274 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4275 | final long token = Binder.clearCallingIdentity(); |
joonhunshin | 49f0aed | 2022-08-05 08:33:05 +0000 | [diff] [blame] | 4276 | |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4277 | try { |
joonhunshin | 49f0aed | 2022-08-05 08:33:05 +0000 | [diff] [blame] | 4278 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4279 | if (controller != null) { |
| 4280 | ImsManager imsManager = controller.getImsManager(subId); |
| 4281 | if (imsManager != null) { |
| 4282 | imsManager.removeRegistrationCallbackForSubscription(c, subId); |
| 4283 | } else { |
| 4284 | Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId |
| 4285 | + "is inactive, ignoring unregister."); |
| 4286 | // If the ImsManager is not valid, just return, since the callback |
| 4287 | // will already have been removed internally. |
| 4288 | } |
| 4289 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4290 | } finally { |
| 4291 | Binder.restoreCallingIdentity(token); |
| 4292 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4293 | } |
| 4294 | |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 4295 | /** |
| 4296 | * Get the IMS service registration state for the MmTelFeature associated with this sub id. |
| 4297 | */ |
| 4298 | @Override |
| 4299 | public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) { |
| 4300 | enforceReadPrivilegedPermission("getImsMmTelRegistrationState"); |
| 4301 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4302 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4303 | "IMS not available on device."); |
| 4304 | } |
| 4305 | final long token = Binder.clearCallingIdentity(); |
| 4306 | try { |
| 4307 | Phone phone = getPhone(subId); |
| 4308 | if (phone == null) { |
| 4309 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 4310 | + subId + "'"); |
| 4311 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 4312 | } |
| 4313 | phone.getImsRegistrationState(regState -> { |
| 4314 | try { |
| 4315 | consumer.accept((regState == null) |
| 4316 | ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState); |
| 4317 | } catch (RemoteException e) { |
| 4318 | // Ignore if the remote process is no longer available to call back. |
| 4319 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 4320 | } |
| 4321 | }); |
| 4322 | } finally { |
| 4323 | Binder.restoreCallingIdentity(token); |
| 4324 | } |
| 4325 | } |
| 4326 | |
| 4327 | /** |
| 4328 | * Get the transport type for the IMS service registration state. |
| 4329 | */ |
| 4330 | @Override |
| 4331 | public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4332 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4333 | mApp, subId, "getImsMmTelRegistrationTransportType"); |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 4334 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4335 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4336 | "IMS not available on device."); |
| 4337 | } |
| 4338 | final long token = Binder.clearCallingIdentity(); |
| 4339 | try { |
| 4340 | Phone phone = getPhone(subId); |
| 4341 | if (phone == null) { |
| 4342 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 4343 | + subId + "'"); |
| 4344 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 4345 | } |
| 4346 | phone.getImsRegistrationTech(regTech -> { |
| 4347 | // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager |
| 4348 | int regTechConverted = (regTech == null) |
| 4349 | ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech; |
| 4350 | regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get( |
| 4351 | regTechConverted); |
| 4352 | try { |
| 4353 | consumer.accept(regTechConverted); |
| 4354 | } catch (RemoteException e) { |
| 4355 | // Ignore if the remote process is no longer available to call back. |
| 4356 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 4357 | } |
| 4358 | }); |
| 4359 | } finally { |
| 4360 | Binder.restoreCallingIdentity(token); |
| 4361 | } |
| 4362 | } |
| 4363 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4364 | /** |
| 4365 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4366 | * @param subId The subscription to use to check the configuration. |
| 4367 | * @param c The callback that will be used to send the result. |
| 4368 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4369 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4370 | public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) |
| 4371 | throws RemoteException { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4372 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4373 | mApp, subId, "registerMmTelCapabilityCallback"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4374 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4375 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4376 | "IMS not available on device."); |
| 4377 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4378 | final long token = Binder.clearCallingIdentity(); |
| 4379 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4380 | int slotId = getSlotIndexOrException(subId); |
| 4381 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 4382 | ImsManager.getInstance(mApp, slotId).addCapabilitiesCallbackForSubscription(c, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4383 | } catch (ImsException e) { |
| 4384 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4385 | } finally { |
| 4386 | Binder.restoreCallingIdentity(token); |
| 4387 | } |
| 4388 | } |
| 4389 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4390 | /** |
| 4391 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4392 | * @param subId The subscription to use to check the configuration. |
| 4393 | * @param c The callback that will be used to send the result. |
| 4394 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4395 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4396 | public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4397 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4398 | mApp, subId, "unregisterMmTelCapabilityCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4399 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4400 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4401 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4402 | |
| 4403 | final long token = Binder.clearCallingIdentity(); |
| 4404 | try { |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4405 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4406 | .removeCapabilitiesCallbackForSubscription(c, subId); |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4407 | } catch (ImsException e) { |
| 4408 | Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId |
| 4409 | + "is inactive, ignoring unregister."); |
| 4410 | // If the subscription is no longer active, just return, since the callback |
| 4411 | // will already have been removed internally. |
| 4412 | } finally { |
| 4413 | Binder.restoreCallingIdentity(token); |
| 4414 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4415 | } |
| 4416 | |
| 4417 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4418 | public boolean isCapable(int subId, int capability, int regTech) { |
| 4419 | enforceReadPrivilegedPermission("isCapable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4420 | final long token = Binder.clearCallingIdentity(); |
| 4421 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4422 | int slotId = getSlotIndexOrException(subId); |
| 4423 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 4424 | return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech); |
| 4425 | } catch (com.android.ims.ImsException e) { |
| 4426 | Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage()); |
| 4427 | return false; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4428 | } catch (ImsException e) { |
Brad Ebinger | 6b5ac22 | 2019-02-04 14:36:52 -0800 | [diff] [blame] | 4429 | Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false."); |
| 4430 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4431 | } finally { |
| 4432 | Binder.restoreCallingIdentity(token); |
| 4433 | } |
| 4434 | } |
| 4435 | |
| 4436 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4437 | public boolean isAvailable(int subId, int capability, int regTech) { |
| 4438 | enforceReadPrivilegedPermission("isAvailable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4439 | final long token = Binder.clearCallingIdentity(); |
| 4440 | try { |
| 4441 | Phone phone = getPhone(subId); |
| 4442 | if (phone == null) return false; |
| 4443 | return phone.isImsCapabilityAvailable(capability, regTech); |
Daniel Bright | 5e40e4e | 2020-03-11 16:35:39 -0700 | [diff] [blame] | 4444 | } catch (com.android.ims.ImsException e) { |
| 4445 | Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage()); |
| 4446 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4447 | } finally { |
| 4448 | Binder.restoreCallingIdentity(token); |
| 4449 | } |
| 4450 | } |
| 4451 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4452 | /** |
| 4453 | * Determines if the MmTel feature capability is supported by the carrier configuration for this |
| 4454 | * subscription. |
| 4455 | * @param subId The subscription to use to check the configuration. |
| 4456 | * @param callback The callback that will be used to send the result. |
| 4457 | * @param capability The MmTelFeature capability that will be used to send the result. |
| 4458 | * @param transportType The transport type of the MmTelFeature capability. |
| 4459 | */ |
| 4460 | @Override |
| 4461 | public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability, |
| 4462 | int transportType) { |
| 4463 | enforceReadPrivilegedPermission("isMmTelCapabilitySupported"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4464 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4465 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4466 | "IMS not available on device."); |
| 4467 | } |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4468 | final long token = Binder.clearCallingIdentity(); |
| 4469 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4470 | int slotId = getSlotIndex(subId); |
| 4471 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4472 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '" |
| 4473 | + subId + "'"); |
| 4474 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 4475 | } |
| 4476 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 4477 | ImsManager.getInstance(mApp, slotId).isSupported(capability, |
| 4478 | transportType, aBoolean -> { |
| 4479 | try { |
| 4480 | callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0)); |
| 4481 | } catch (RemoteException e) { |
| 4482 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not " |
| 4483 | + "running. Ignore"); |
| 4484 | } |
| 4485 | }); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4486 | } catch (ImsException e) { |
| 4487 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4488 | } finally { |
| 4489 | Binder.restoreCallingIdentity(token); |
| 4490 | } |
| 4491 | } |
| 4492 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4493 | /** |
| 4494 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4495 | * @param subId The subscription to use to check the configuration. |
| 4496 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4497 | @Override |
| 4498 | public boolean isAdvancedCallingSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4499 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4500 | mApp, subId, "isAdvancedCallingSettingEnabled"); |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4501 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4502 | final long token = Binder.clearCallingIdentity(); |
| 4503 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4504 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4505 | // 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] | 4506 | return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4507 | } catch (ImsException e) { |
| 4508 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4509 | } finally { |
| 4510 | Binder.restoreCallingIdentity(token); |
| 4511 | } |
| 4512 | } |
| 4513 | |
| 4514 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4515 | public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4516 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4517 | "setAdvancedCallingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4518 | final long identity = Binder.clearCallingIdentity(); |
| 4519 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4520 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4521 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4522 | // 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] | 4523 | ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4524 | } catch (ImsException e) { |
| 4525 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4526 | } finally { |
| 4527 | Binder.restoreCallingIdentity(identity); |
| 4528 | } |
| 4529 | } |
| 4530 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4531 | /** |
| 4532 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4533 | * @param subId The subscription to use to check the configuration. |
| 4534 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4535 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4536 | public boolean isVtSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4537 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4538 | mApp, subId, "isVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4539 | final long identity = Binder.clearCallingIdentity(); |
| 4540 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4541 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4542 | // 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] | 4543 | return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4544 | } catch (ImsException e) { |
| 4545 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4546 | } finally { |
| 4547 | Binder.restoreCallingIdentity(identity); |
| 4548 | } |
| 4549 | } |
| 4550 | |
| 4551 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4552 | public void setVtSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4553 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4554 | "setVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4555 | final long identity = Binder.clearCallingIdentity(); |
| 4556 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4557 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4558 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4559 | // 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] | 4560 | ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4561 | } catch (ImsException e) { |
| 4562 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4563 | } finally { |
| 4564 | Binder.restoreCallingIdentity(identity); |
| 4565 | } |
| 4566 | } |
| 4567 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4568 | /** |
| 4569 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4570 | * @param subId The subscription to use to check the configuration. |
| 4571 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4572 | @Override |
| 4573 | public boolean isVoWiFiSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4574 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4575 | mApp, subId, "isVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4576 | final long identity = Binder.clearCallingIdentity(); |
| 4577 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4578 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4579 | // 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] | 4580 | return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4581 | } catch (ImsException e) { |
| 4582 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4583 | } finally { |
| 4584 | Binder.restoreCallingIdentity(identity); |
| 4585 | } |
| 4586 | } |
| 4587 | |
| 4588 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4589 | public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4590 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4591 | "setVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4592 | final long identity = Binder.clearCallingIdentity(); |
| 4593 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4594 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4595 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4596 | // 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] | 4597 | ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4598 | } catch (ImsException e) { |
| 4599 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4600 | } finally { |
| 4601 | Binder.restoreCallingIdentity(identity); |
| 4602 | } |
| 4603 | } |
| 4604 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4605 | /** |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 4606 | * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not |
| 4607 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4608 | * @param subId The subscription to use to check the configuration. |
| 4609 | */ |
| 4610 | @Override |
| 4611 | public boolean isCrossSimCallingEnabledByUser(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4612 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 4613 | mApp, subId, "isCrossSimCallingEnabledByUser"); |
| 4614 | final long identity = Binder.clearCallingIdentity(); |
| 4615 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4616 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4617 | // 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] | 4618 | return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser(); |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 4619 | } catch (ImsException e) { |
| 4620 | throw new ServiceSpecificException(e.getCode()); |
| 4621 | } finally { |
| 4622 | Binder.restoreCallingIdentity(identity); |
| 4623 | } |
| 4624 | } |
| 4625 | |
| 4626 | /** |
| 4627 | * Sets the user's setting for whether or not Voice over Cross SIM is enabled. |
| 4628 | * Requires MODIFY_PHONE_STATE permission. |
| 4629 | * @param subId The subscription to use to check the configuration. |
| 4630 | * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled, |
| 4631 | * false otherwise |
| 4632 | */ |
| 4633 | @Override |
| 4634 | public void setCrossSimCallingEnabled(int subId, boolean isEnabled) { |
| 4635 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4636 | "setCrossSimCallingEnabled"); |
| 4637 | final long identity = Binder.clearCallingIdentity(); |
| 4638 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4639 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4640 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4641 | // 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] | 4642 | ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled); |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 4643 | } catch (ImsException e) { |
| 4644 | throw new ServiceSpecificException(e.getCode()); |
| 4645 | } finally { |
| 4646 | Binder.restoreCallingIdentity(identity); |
| 4647 | } |
| 4648 | } |
| 4649 | |
| 4650 | /** |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4651 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4652 | * @param subId The subscription to use to check the configuration. |
| 4653 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4654 | @Override |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4655 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4656 | public boolean isVoWiFiRoamingSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4657 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4658 | mApp, subId, "isVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4659 | final long identity = Binder.clearCallingIdentity(); |
| 4660 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4661 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4662 | // 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] | 4663 | return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4664 | } catch (ImsException e) { |
| 4665 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4666 | } finally { |
| 4667 | Binder.restoreCallingIdentity(identity); |
| 4668 | } |
| 4669 | } |
| 4670 | |
| 4671 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4672 | public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4673 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4674 | "setVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4675 | final long identity = Binder.clearCallingIdentity(); |
| 4676 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4677 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4678 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4679 | // 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] | 4680 | ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4681 | } catch (ImsException e) { |
| 4682 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4683 | } finally { |
| 4684 | Binder.restoreCallingIdentity(identity); |
| 4685 | } |
| 4686 | } |
| 4687 | |
| 4688 | @Override |
| 4689 | public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) { |
| 4690 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4691 | "setVoWiFiNonPersistent"); |
| 4692 | final long identity = Binder.clearCallingIdentity(); |
| 4693 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4694 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4695 | // This setting will be ignored if the ImsService isn't up. |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4696 | ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4697 | } catch (ImsException e) { |
| 4698 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4699 | } finally { |
| 4700 | Binder.restoreCallingIdentity(identity); |
| 4701 | } |
| 4702 | } |
| 4703 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4704 | /** |
| 4705 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4706 | * @param subId The subscription to use to check the configuration. |
| 4707 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4708 | @Override |
| 4709 | public int getVoWiFiModeSetting(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4710 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4711 | mApp, subId, "getVoWiFiModeSetting"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4712 | final long identity = Binder.clearCallingIdentity(); |
| 4713 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4714 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4715 | // 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] | 4716 | return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4717 | } catch (ImsException e) { |
| 4718 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4719 | } finally { |
| 4720 | Binder.restoreCallingIdentity(identity); |
| 4721 | } |
| 4722 | } |
| 4723 | |
| 4724 | @Override |
| 4725 | public void setVoWiFiModeSetting(int subId, int mode) { |
| 4726 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4727 | "setVoWiFiModeSetting"); |
| 4728 | final long identity = Binder.clearCallingIdentity(); |
| 4729 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4730 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4731 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4732 | // 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] | 4733 | ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4734 | } catch (ImsException e) { |
| 4735 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4736 | } finally { |
| 4737 | Binder.restoreCallingIdentity(identity); |
| 4738 | } |
| 4739 | } |
| 4740 | |
| 4741 | @Override |
| 4742 | public int getVoWiFiRoamingModeSetting(int subId) { |
| 4743 | enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting"); |
| 4744 | final long identity = Binder.clearCallingIdentity(); |
| 4745 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4746 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4747 | // 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] | 4748 | return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4749 | } catch (ImsException e) { |
| 4750 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4751 | } finally { |
| 4752 | Binder.restoreCallingIdentity(identity); |
| 4753 | } |
| 4754 | } |
| 4755 | |
| 4756 | @Override |
| 4757 | public void setVoWiFiRoamingModeSetting(int subId, int mode) { |
| 4758 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4759 | "setVoWiFiRoamingModeSetting"); |
| 4760 | final long identity = Binder.clearCallingIdentity(); |
| 4761 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4762 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4763 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4764 | // 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] | 4765 | ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4766 | } catch (ImsException e) { |
| 4767 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4768 | } finally { |
| 4769 | Binder.restoreCallingIdentity(identity); |
| 4770 | } |
| 4771 | } |
| 4772 | |
| 4773 | @Override |
| 4774 | public void setRttCapabilitySetting(int subId, boolean isEnabled) { |
| 4775 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4776 | "setRttCapabilityEnabled"); |
| 4777 | final long identity = Binder.clearCallingIdentity(); |
| 4778 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4779 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4780 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4781 | // 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] | 4782 | ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4783 | } catch (ImsException e) { |
| 4784 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4785 | } finally { |
| 4786 | Binder.restoreCallingIdentity(identity); |
| 4787 | } |
| 4788 | } |
| 4789 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4790 | /** |
| 4791 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4792 | * @param subId The subscription to use to check the configuration. |
| 4793 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4794 | @Override |
| 4795 | public boolean isTtyOverVolteEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4796 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4797 | mApp, subId, "isTtyOverVolteEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4798 | final long identity = Binder.clearCallingIdentity(); |
| 4799 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4800 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4801 | // 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] | 4802 | return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4803 | } catch (ImsException e) { |
| 4804 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4805 | } finally { |
| 4806 | Binder.restoreCallingIdentity(identity); |
| 4807 | } |
| 4808 | } |
| 4809 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4810 | @Override |
| 4811 | public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 4812 | enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4813 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4814 | final long identity = Binder.clearCallingIdentity(); |
| 4815 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4816 | if (!isImsAvailableOnDevice()) { |
| 4817 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4818 | "IMS not available on device."); |
| 4819 | } |
| 4820 | int slotId = getSlotIndexOrException(subId); |
| 4821 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 4822 | ImsManager.getInstance(mApp, slotId) |
| 4823 | .addProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4824 | } catch (ImsException e) { |
| 4825 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4826 | } finally { |
| 4827 | Binder.restoreCallingIdentity(identity); |
| 4828 | } |
| 4829 | } |
| 4830 | |
| 4831 | @Override |
| 4832 | public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 4833 | enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4834 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4835 | final long identity = Binder.clearCallingIdentity(); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4836 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4837 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4838 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4839 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4840 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4841 | .removeProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4842 | } catch (ImsException e) { |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4843 | Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId |
| 4844 | + "is inactive, ignoring unregister."); |
| 4845 | // If the subscription is no longer active, just return, since the callback will already |
| 4846 | // have been removed internally. |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4847 | } finally { |
| 4848 | Binder.restoreCallingIdentity(identity); |
| 4849 | } |
| 4850 | } |
| 4851 | |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4852 | @Override |
| 4853 | public void registerFeatureProvisioningChangedCallback(int subId, |
| 4854 | IFeatureProvisioningCallback callback) { |
| 4855 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4856 | mApp, subId, "registerFeatureProvisioningChangedCallback"); |
| 4857 | |
| 4858 | final long identity = Binder.clearCallingIdentity(); |
| 4859 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4860 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4861 | } |
| 4862 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 4863 | try { |
| 4864 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 4865 | if (controller == null) { |
| 4866 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4867 | "Device does not support IMS"); |
| 4868 | } |
| 4869 | controller.addFeatureProvisioningChangedCallback(subId, callback); |
| 4870 | } finally { |
| 4871 | Binder.restoreCallingIdentity(identity); |
| 4872 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4873 | } |
| 4874 | |
| 4875 | @Override |
| 4876 | public void unregisterFeatureProvisioningChangedCallback(int subId, |
| 4877 | IFeatureProvisioningCallback callback) { |
| 4878 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4879 | mApp, subId, "unregisterFeatureProvisioningChangedCallback"); |
| 4880 | |
| 4881 | final long identity = Binder.clearCallingIdentity(); |
| 4882 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4883 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4884 | } |
| 4885 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 4886 | try { |
| 4887 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 4888 | if (controller == null) { |
| 4889 | loge("unregisterFeatureProvisioningChangedCallback: Device does not support IMS"); |
| 4890 | return; |
| 4891 | } |
| 4892 | controller.removeFeatureProvisioningChangedCallback(subId, callback); |
| 4893 | } finally { |
| 4894 | Binder.restoreCallingIdentity(identity); |
| 4895 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4896 | } |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4897 | |
| 4898 | private void checkModifyPhoneStatePermission(int subId, String message) { |
| 4899 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4900 | message); |
| 4901 | } |
| 4902 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4903 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4904 | public void setRcsProvisioningStatusForCapability(int subId, int capability, int tech, |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4905 | boolean isProvisioned) { |
| 4906 | checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability"); |
| 4907 | |
| 4908 | final long identity = Binder.clearCallingIdentity(); |
| 4909 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 4910 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 4911 | if (controller == null) { |
| 4912 | loge("setRcsProvisioningStatusForCapability: Device does not support IMS"); |
| 4913 | return; |
| 4914 | } |
| 4915 | controller.setRcsProvisioningStatusForCapability( |
| 4916 | subId, capability, tech, isProvisioned); |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4917 | } finally { |
| 4918 | Binder.restoreCallingIdentity(identity); |
| 4919 | } |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4920 | } |
| 4921 | |
| 4922 | |
| 4923 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4924 | public boolean getRcsProvisioningStatusForCapability(int subId, int capability, int tech) { |
| 4925 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4926 | mApp, subId, "getRcsProvisioningStatusForCapability"); |
| 4927 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4928 | final long identity = Binder.clearCallingIdentity(); |
| 4929 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 4930 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 4931 | if (controller == null) { |
| 4932 | loge("getRcsProvisioningStatusForCapability: Device does not support IMS"); |
| 4933 | |
| 4934 | // device does not support IMS, this method will return true always. |
| 4935 | return true; |
| 4936 | } |
| 4937 | return controller.getRcsProvisioningStatusForCapability(subId, capability, tech); |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4938 | } finally { |
| 4939 | Binder.restoreCallingIdentity(identity); |
| 4940 | } |
| 4941 | } |
| 4942 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4943 | @Override |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4944 | public void setImsProvisioningStatusForCapability(int subId, int capability, int tech, |
| 4945 | boolean isProvisioned) { |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4946 | checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4947 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4948 | final long identity = Binder.clearCallingIdentity(); |
| 4949 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 4950 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 4951 | if (controller == null) { |
| 4952 | loge("setImsProvisioningStatusForCapability: Device does not support IMS"); |
| 4953 | return; |
| 4954 | } |
| 4955 | controller.setImsProvisioningStatusForCapability( |
| 4956 | subId, capability, tech, isProvisioned); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4957 | } finally { |
| 4958 | Binder.restoreCallingIdentity(identity); |
| 4959 | } |
| 4960 | } |
| 4961 | |
| 4962 | @Override |
| 4963 | public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) { |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4964 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4965 | mApp, subId, "getProvisioningStatusForCapability"); |
| 4966 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4967 | final long identity = Binder.clearCallingIdentity(); |
| 4968 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 4969 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 4970 | if (controller == null) { |
| 4971 | loge("getImsProvisioningStatusForCapability: Device does not support IMS"); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4972 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 4973 | // device does not support IMS, this method will return true always. |
| 4974 | return true; |
| 4975 | } |
| 4976 | return controller.getImsProvisioningStatusForCapability(subId, capability, tech); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4977 | } finally { |
| 4978 | Binder.restoreCallingIdentity(identity); |
| 4979 | } |
| 4980 | } |
| 4981 | |
| 4982 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4983 | public boolean isProvisioningRequiredForCapability(int subId, int capability, int tech) { |
| 4984 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4985 | mApp, subId, "isProvisioningRequiredForCapability"); |
| 4986 | |
| 4987 | final long identity = Binder.clearCallingIdentity(); |
| 4988 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 4989 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 4990 | if (controller == null) { |
| 4991 | loge("isProvisioningRequiredForCapability: Device does not support IMS"); |
| 4992 | |
| 4993 | // device does not support IMS, this method will return false |
| 4994 | return false; |
| 4995 | } |
| 4996 | return controller.isImsProvisioningRequiredForCapability(subId, capability, tech); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4997 | } finally { |
| 4998 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4999 | } |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5000 | } |
| 5001 | |
| 5002 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5003 | public boolean isRcsProvisioningRequiredForCapability(int subId, int capability, int tech) { |
| 5004 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5005 | mApp, subId, "isProvisioningRequiredForCapability"); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5006 | |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5007 | final long identity = Binder.clearCallingIdentity(); |
| 5008 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5009 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5010 | if (controller == null) { |
| 5011 | loge("isRcsProvisioningRequiredForCapability: Device does not support IMS"); |
| 5012 | |
| 5013 | // device does not support IMS, this method will return false |
| 5014 | return false; |
| 5015 | } |
| 5016 | return controller.isRcsProvisioningRequiredForCapability(subId, capability, tech); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5017 | } finally { |
| 5018 | Binder.restoreCallingIdentity(identity); |
| 5019 | } |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5020 | } |
| 5021 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5022 | @Override |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5023 | public int getImsProvisioningInt(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5024 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5025 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 5026 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5027 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5028 | mApp, subId, "getImsProvisioningInt"); |
| 5029 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5030 | final long identity = Binder.clearCallingIdentity(); |
| 5031 | try { |
| 5032 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5033 | int slotId = getSlotIndex(subId); |
| 5034 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5035 | Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '" |
| 5036 | + subId + "' for key:" + key); |
| 5037 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
| 5038 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5039 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5040 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5041 | if (controller == null) { |
| 5042 | loge("getImsProvisioningInt: Device does not support IMS"); |
| 5043 | |
| 5044 | // device does not support IMS, this method will return CONFIG_RESULT_UNKNOWN. |
| 5045 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
| 5046 | } |
| 5047 | int retVal = controller.getProvisioningValue(subId, key); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5048 | if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) { |
| 5049 | return retVal; |
| 5050 | } |
| 5051 | |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5052 | return ImsManager.getInstance(mApp, slotId).getConfigInt(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5053 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5054 | Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '" |
| 5055 | + subId + "' for key:" + key); |
| 5056 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5057 | } finally { |
| 5058 | Binder.restoreCallingIdentity(identity); |
| 5059 | } |
| 5060 | } |
| 5061 | |
| 5062 | @Override |
| 5063 | public String getImsProvisioningString(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5064 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5065 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 5066 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5067 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5068 | mApp, subId, "getImsProvisioningString"); |
| 5069 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5070 | final long identity = Binder.clearCallingIdentity(); |
| 5071 | try { |
| 5072 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5073 | int slotId = getSlotIndex(subId); |
| 5074 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5075 | Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '" |
| 5076 | + subId + "' for key:" + key); |
| 5077 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC; |
| 5078 | } |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5079 | return ImsManager.getInstance(mApp, slotId).getConfigString(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5080 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5081 | Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '" |
| 5082 | + subId + "' for key:" + key); |
| 5083 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5084 | } finally { |
| 5085 | Binder.restoreCallingIdentity(identity); |
| 5086 | } |
| 5087 | } |
| 5088 | |
| 5089 | @Override |
| 5090 | public int setImsProvisioningInt(int subId, int key, int value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5091 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5092 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 5093 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 5094 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5095 | "setImsProvisioningInt"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5096 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5097 | final long identity = Binder.clearCallingIdentity(); |
| 5098 | try { |
| 5099 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5100 | int slotId = getSlotIndex(subId); |
| 5101 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5102 | Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '" |
| 5103 | + subId + "' for key:" + key); |
| 5104 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 5105 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5106 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5107 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5108 | if (controller == null) { |
| 5109 | loge("setImsProvisioningInt: Device does not support IMS"); |
| 5110 | |
| 5111 | // device does not support IMS, this method will return CONFIG_RESULT_FAILED. |
| 5112 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 5113 | } |
| 5114 | int retVal = controller.setProvisioningValue(subId, key, value); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5115 | if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) { |
| 5116 | return retVal; |
| 5117 | } |
| 5118 | |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5119 | return ImsManager.getInstance(mApp, slotId).setConfig(key, value); |
| 5120 | } catch (com.android.ims.ImsException | RemoteException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5121 | Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5122 | + "' for key:" + key, e); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5123 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5124 | } finally { |
| 5125 | Binder.restoreCallingIdentity(identity); |
| 5126 | } |
| 5127 | } |
| 5128 | |
| 5129 | @Override |
| 5130 | public int setImsProvisioningString(int subId, int key, String value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5131 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5132 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 5133 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 5134 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5135 | "setImsProvisioningString"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5136 | final long identity = Binder.clearCallingIdentity(); |
| 5137 | try { |
| 5138 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5139 | int slotId = getSlotIndex(subId); |
| 5140 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5141 | Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '" |
| 5142 | + subId + "' for key:" + key); |
| 5143 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 5144 | } |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5145 | return ImsManager.getInstance(mApp, slotId).setConfig(key, value); |
| 5146 | } catch (com.android.ims.ImsException | RemoteException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5147 | Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5148 | + "' for key:" + key, e); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5149 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5150 | } finally { |
| 5151 | Binder.restoreCallingIdentity(identity); |
| 5152 | } |
| 5153 | } |
| 5154 | |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5155 | /** |
| 5156 | * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL |
| 5157 | * for the given slot ID or no ImsResolver instance has been created. |
| 5158 | * @param slotId The slot ID that the IMS service is created for. |
| 5159 | * @throws ImsException If there is no ImsService configured for this slot. |
| 5160 | */ |
| 5161 | private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException { |
| 5162 | if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId, |
| 5163 | ImsFeature.FEATURE_MMTEL)) { |
| 5164 | throw new ImsException("This subscription does not support MMTEL over IMS", |
| 5165 | ImsException.CODE_ERROR_UNSUPPORTED_OPERATION); |
| 5166 | } |
| 5167 | } |
| 5168 | |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5169 | private int getSlotIndexOrException(int subId) throws ImsException { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5170 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 5171 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5172 | throw new ImsException("Invalid Subscription Id, subId=" + subId, |
| 5173 | ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5174 | } |
| 5175 | return slotId; |
| 5176 | } |
| 5177 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5178 | private int getSlotIndex(int subId) { |
| 5179 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 5180 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
| 5181 | return SubscriptionManager.INVALID_SIM_SLOT_INDEX; |
| 5182 | } |
| 5183 | return slotId; |
| 5184 | } |
| 5185 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5186 | /** |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 5187 | * Returns the data network type for a subId; does not throw SecurityException. |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5188 | */ |
| 5189 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5190 | public int getNetworkTypeForSubscriber(int subId, String callingPackage, |
| 5191 | String callingFeatureId) { |
Shuo Qian | 13d8915 | 2021-05-10 23:58:11 -0700 | [diff] [blame] | 5192 | try { |
| 5193 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 5194 | } catch (SecurityException se) { |
| 5195 | EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid()); |
| 5196 | throw new SecurityException("Package " + callingPackage + " does not belong to " |
| 5197 | + Binder.getCallingUid()); |
| 5198 | } |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 5199 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 5200 | if (targetSdk > android.os.Build.VERSION_CODES.Q) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5201 | return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 5202 | } else if (targetSdk == android.os.Build.VERSION_CODES.Q |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 5203 | && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5204 | mApp, subId, callingPackage, callingFeatureId, |
| 5205 | "getNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5206 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5207 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 5208 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5209 | final long identity = Binder.clearCallingIdentity(); |
| 5210 | try { |
| 5211 | final Phone phone = getPhone(subId); |
| 5212 | if (phone != null) { |
| 5213 | return phone.getServiceState().getDataNetworkType(); |
| 5214 | } else { |
| 5215 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5216 | } |
| 5217 | } finally { |
| 5218 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5219 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5220 | } |
| 5221 | |
| 5222 | /** |
| 5223 | * Returns the data network type |
| 5224 | */ |
| 5225 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5226 | public int getDataNetworkType(String callingPackage, String callingFeatureId) { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5227 | return getDataNetworkTypeForSubscriber(SubscriptionManager.getDefaultDataSubscriptionId(), |
Zoey Chen | fd61f7f | 2021-04-21 13:42:10 +0800 | [diff] [blame] | 5228 | callingPackage, callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5229 | } |
| 5230 | |
| 5231 | /** |
| 5232 | * Returns the data network type for a subId |
| 5233 | */ |
| 5234 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5235 | public int getDataNetworkTypeForSubscriber(int subId, String callingPackage, |
| 5236 | String callingFeatureId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 5237 | String functionName = "getDataNetworkTypeForSubscriber"; |
| 5238 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 5239 | mApp, functionName)) { |
| 5240 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 5241 | mApp, subId, callingPackage, callingFeatureId, functionName)) { |
| 5242 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5243 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5244 | } |
| 5245 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5246 | final long identity = Binder.clearCallingIdentity(); |
| 5247 | try { |
| 5248 | final Phone phone = getPhone(subId); |
| 5249 | if (phone != null) { |
| 5250 | return phone.getServiceState().getDataNetworkType(); |
| 5251 | } else { |
| 5252 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5253 | } |
| 5254 | } finally { |
| 5255 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5256 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5257 | } |
| 5258 | |
| 5259 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5260 | * Returns the Voice network type for a subId |
| 5261 | */ |
| 5262 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5263 | public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage, |
| 5264 | String callingFeatureId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 5265 | String functionName = "getVoiceNetworkTypeForSubscriber"; |
| 5266 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 5267 | mApp, functionName)) { |
| 5268 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 5269 | mApp, subId, callingPackage, callingFeatureId, functionName)) { |
| 5270 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5271 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 5272 | } |
| 5273 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5274 | final long identity = Binder.clearCallingIdentity(); |
| 5275 | try { |
| 5276 | final Phone phone = getPhone(subId); |
| 5277 | if (phone != null) { |
| 5278 | return phone.getServiceState().getVoiceNetworkType(); |
| 5279 | } else { |
| 5280 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5281 | } |
| 5282 | } finally { |
| 5283 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5284 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5285 | } |
| 5286 | |
| 5287 | /** |
| 5288 | * @return true if a ICC card is present |
| 5289 | */ |
| 5290 | public boolean hasIccCard() { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5291 | // FIXME Make changes to pass defaultSimId of type int |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5292 | return hasIccCardUsingSlotIndex(SubscriptionManager.getSlotIndex( |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5293 | getDefaultSubscription())); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5294 | } |
| 5295 | |
| 5296 | /** |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5297 | * @return true if a ICC card is present for a slotIndex |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5298 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5299 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5300 | public boolean hasIccCardUsingSlotIndex(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5301 | final long identity = Binder.clearCallingIdentity(); |
| 5302 | try { |
| 5303 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5304 | if (phone != null) { |
| 5305 | return phone.getIccCard().hasIccCard(); |
| 5306 | } else { |
| 5307 | return false; |
| 5308 | } |
| 5309 | } finally { |
| 5310 | Binder.restoreCallingIdentity(identity); |
Amit Mahajan | a6fc2a8 | 2015-01-06 11:53:51 -0800 | [diff] [blame] | 5311 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5312 | } |
| 5313 | |
| 5314 | /** |
| 5315 | * Return if the current radio is LTE on CDMA. This |
| 5316 | * is a tri-state return value as for a period of time |
| 5317 | * the mode may be unknown. |
| 5318 | * |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5319 | * @param callingPackage the name of the package making the call. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5320 | * @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] | 5321 | * or {@link Phone#LTE_ON_CDMA_TRUE} |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5322 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5323 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5324 | public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) { |
| 5325 | return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 5326 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5327 | } |
| 5328 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5329 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5330 | public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage, |
| 5331 | String callingFeatureId) { |
Sarah Chin | 790d292 | 2020-01-16 12:17:23 -0800 | [diff] [blame] | 5332 | try { |
| 5333 | enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber"); |
| 5334 | } catch (SecurityException e) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5335 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 5336 | } |
| 5337 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5338 | final long identity = Binder.clearCallingIdentity(); |
| 5339 | try { |
| 5340 | final Phone phone = getPhone(subId); |
| 5341 | if (phone == null) { |
| 5342 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 5343 | } else { |
Nathan Harold | 05ad633 | 2020-07-10 11:54:36 -0700 | [diff] [blame] | 5344 | return TelephonyProperties.lte_on_cdma_device() |
| 5345 | .orElse(PhoneConstants.LTE_ON_CDMA_FALSE); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5346 | } |
| 5347 | } finally { |
| 5348 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5349 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5350 | } |
| 5351 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5352 | /** |
| 5353 | * {@hide} |
| 5354 | * Returns Default subId, 0 in the case of single standby. |
| 5355 | */ |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 5356 | private int getDefaultSubscription() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5357 | return SubscriptionManager.getDefaultSubscriptionId(); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5358 | } |
| 5359 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 5360 | private int getSlotForDefaultSubscription() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5361 | return SubscriptionManager.getPhoneId(getDefaultSubscription()); |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 5362 | } |
| 5363 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 5364 | private int getPreferredVoiceSubscription() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5365 | return SubscriptionManager.getDefaultVoiceSubscriptionId(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5366 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5367 | |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 5368 | private boolean isActiveSubscription(int subId) { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5369 | if (PhoneFactory.isSubscriptionManagerServiceEnabled()) { |
| 5370 | return SubscriptionManagerService.getInstance().isActiveSubId(subId, |
| 5371 | mApp.getOpPackageName(), mApp.getFeatureId()); |
| 5372 | } |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 5373 | return mSubscriptionController.isActiveSubId(subId); |
| 5374 | } |
| 5375 | |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5376 | /** |
| 5377 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 5378 | */ |
| 5379 | public int getWhenToMakeWifiCalls() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5380 | final long identity = Binder.clearCallingIdentity(); |
| 5381 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5382 | return Settings.System.getInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5383 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, |
| 5384 | getWhenToMakeWifiCallsDefaultPreference()); |
| 5385 | } finally { |
| 5386 | Binder.restoreCallingIdentity(identity); |
| 5387 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5388 | } |
| 5389 | |
| 5390 | /** |
| 5391 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 5392 | */ |
| 5393 | public void setWhenToMakeWifiCalls(int preference) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5394 | final long identity = Binder.clearCallingIdentity(); |
| 5395 | try { |
| 5396 | if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5397 | Settings.System.putInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5398 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference); |
| 5399 | } finally { |
| 5400 | Binder.restoreCallingIdentity(identity); |
| 5401 | } |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 5402 | } |
| 5403 | |
Sailesh Nepal | d1e6815 | 2013-12-12 19:08:02 -0800 | [diff] [blame] | 5404 | private static int getWhenToMakeWifiCallsDefaultPreference() { |
Santos Cordon | da120f4 | 2014-08-06 04:44:34 -0700 | [diff] [blame] | 5405 | // TODO: Use a build property to choose this value. |
Evan Charlton | 9829e88 | 2013-12-19 15:30:38 -0800 | [diff] [blame] | 5406 | return TelephonyManager.WifiCallingChoices.ALWAYS_USE; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5407 | } |
Shishir Agrawal | 69f6812 | 2013-12-16 17:25:49 -0800 | [diff] [blame] | 5408 | |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5409 | private Phone getPhoneFromSlotPortIndexOrThrowException(int slotIndex, int portIndex) { |
| 5410 | int phoneId = UiccController.getInstance().getPhoneIdFromSlotPortIndex(slotIndex, |
| 5411 | portIndex); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5412 | if (phoneId == -1) { |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5413 | throw new IllegalArgumentException("Given slot index: " + slotIndex + " port index: " |
| 5414 | + portIndex + " does not correspond to an active phone"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5415 | } |
| 5416 | return PhoneFactory.getPhone(phoneId); |
| 5417 | } |
| 5418 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5419 | @Override |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 5420 | public IccOpenLogicalChannelResponse iccOpenLogicalChannel( |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5421 | @NonNull IccLogicalChannelRequest request) { |
| 5422 | Phone phone = getPhoneFromValidIccLogicalChannelRequest(request, |
| 5423 | /*message=*/ "iccOpenLogicalChannel"); |
| 5424 | |
| 5425 | if (DBG) log("iccOpenLogicalChannel: request=" + request); |
| 5426 | // Verify that the callingPackage in the request belongs to the calling UID |
| 5427 | mAppOps.checkPackage(Binder.getCallingUid(), request.callingPackage); |
| 5428 | |
| 5429 | return iccOpenLogicalChannelWithPermission(phone, request); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5430 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5431 | |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5432 | private Phone getPhoneFromValidIccLogicalChannelRequest( |
| 5433 | @NonNull IccLogicalChannelRequest request, String message) { |
| 5434 | Phone phone; |
| 5435 | if (request.subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) { |
| 5436 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5437 | mApp, request.subId, message); |
| 5438 | phone = getPhoneFromSubId(request.subId); |
| 5439 | } else if (request.slotIndex != SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5440 | enforceModifyPermission(); |
| 5441 | phone = getPhoneFromSlotPortIndexOrThrowException(request.slotIndex, request.portIndex); |
| 5442 | } else { |
| 5443 | throw new IllegalArgumentException("Both subId and slotIndex in request are invalid."); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5444 | } |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5445 | return phone; |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5446 | } |
| 5447 | |
| 5448 | private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone, |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5449 | IccLogicalChannelRequest channelRequest) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5450 | final long identity = Binder.clearCallingIdentity(); |
| 5451 | try { |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5452 | if (TextUtils.equals(ISDR_AID, channelRequest.aid)) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5453 | // Only allows LPA to open logical channel to ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5454 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 5455 | .getContext().getPackageManager()); |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5456 | if (bestComponent == null || !TextUtils.equals(channelRequest.callingPackage, |
| 5457 | bestComponent.packageName)) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5458 | loge("The calling package is not allowed to access ISD-R."); |
| 5459 | throw new SecurityException( |
| 5460 | "The calling package is not allowed to access ISD-R."); |
| 5461 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 5462 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 5463 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5464 | IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest( |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5465 | CMD_OPEN_CHANNEL, channelRequest, phone, null /* workSource */); |
| 5466 | if (DBG) log("iccOpenLogicalChannelWithPermission: response=" + response); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5467 | return response; |
| 5468 | } finally { |
| 5469 | Binder.restoreCallingIdentity(identity); |
| 5470 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5471 | } |
| 5472 | |
| 5473 | @Override |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5474 | public boolean iccCloseLogicalChannel(@NonNull IccLogicalChannelRequest request) { |
| 5475 | Phone phone = getPhoneFromValidIccLogicalChannelRequest(request, |
| 5476 | /*message=*/"iccCloseLogicalChannel"); |
| 5477 | |
| 5478 | if (DBG) log("iccCloseLogicalChannel: request=" + request); |
| 5479 | |
| 5480 | return iccCloseLogicalChannelWithPermission(phone, request); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5481 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5482 | |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5483 | private boolean iccCloseLogicalChannelWithPermission(Phone phone, |
| 5484 | IccLogicalChannelRequest request) { |
Chen Xu | a8f0dff | 2022-02-12 00:34:15 -0800 | [diff] [blame] | 5485 | // before this feature is enabled, this API should only return false if |
| 5486 | // the operation fails instead of throwing runtime exception for |
| 5487 | // backward-compatibility. |
| 5488 | final boolean shouldThrowExceptionOnFailure = CompatChanges.isChangeEnabled( |
| 5489 | ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE, Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5490 | final long identity = Binder.clearCallingIdentity(); |
| 5491 | try { |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5492 | if (request.channel < 0) { |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 5493 | throw new IllegalArgumentException("request.channel is less than 0"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5494 | } |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 5495 | Object result = sendRequest(CMD_CLOSE_CHANNEL, request.channel, phone, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5496 | null /* workSource */); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 5497 | Boolean success = false; |
| 5498 | if (result instanceof RuntimeException) { |
| 5499 | // if there is an exception returned, throw from the binder thread here. |
Chen Xu | a8f0dff | 2022-02-12 00:34:15 -0800 | [diff] [blame] | 5500 | if (shouldThrowExceptionOnFailure) { |
| 5501 | throw (RuntimeException) result; |
| 5502 | } else { |
| 5503 | return false; |
| 5504 | } |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 5505 | } else if (result instanceof Boolean) { |
| 5506 | success = (Boolean) result; |
| 5507 | } else { |
| 5508 | loge("iccCloseLogicalChannelWithPermission: supported return type " + result); |
| 5509 | } |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5510 | if (DBG) log("iccCloseLogicalChannelWithPermission: success=" + success); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5511 | return success; |
| 5512 | } finally { |
| 5513 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5514 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5515 | } |
| 5516 | |
| 5517 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5518 | public String iccTransmitApduLogicalChannel(int subId, int channel, int cla, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5519 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5520 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5521 | mApp, subId, "iccTransmitApduLogicalChannel"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5522 | if (DBG) { |
| 5523 | log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel |
| 5524 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 5525 | + p3 + " data=" + data); |
| 5526 | } |
| 5527 | return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla, |
| 5528 | command, p1, p2, p3, data); |
| 5529 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5530 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5531 | @Override |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5532 | public String iccTransmitApduLogicalChannelByPort(int slotIndex, int portIndex, int channel, |
| 5533 | int cla, int command, int p1, int p2, int p3, String data) { |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5534 | enforceModifyPermission(); |
| 5535 | if (DBG) { |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5536 | log("iccTransmitApduLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex=" |
| 5537 | + portIndex + " chnl=" + channel + " cla=" + cla + " cmd=" + command + " p1=" |
| 5538 | + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5539 | } |
| 5540 | return iccTransmitApduLogicalChannelWithPermission( |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5541 | getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel, cla, |
| 5542 | command, p1, p2, p3, data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5543 | } |
| 5544 | |
| 5545 | private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla, |
| 5546 | int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5547 | final long identity = Binder.clearCallingIdentity(); |
| 5548 | try { |
Hall Liu | 4fd771b | 2019-05-02 09:16:29 -0700 | [diff] [blame] | 5549 | if (channel <= 0) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5550 | return ""; |
| 5551 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5552 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5553 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5554 | new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone, |
| 5555 | null /* workSource */); |
| 5556 | if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5557 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5558 | // Append the returned status code to the end of the response payload. |
| 5559 | String s = Integer.toHexString( |
| 5560 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 5561 | if (response.payload != null) { |
| 5562 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 5563 | } |
| 5564 | return s; |
| 5565 | } finally { |
| 5566 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 5567 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5568 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5569 | |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5570 | @Override |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 5571 | public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla, |
| 5572 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5573 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5574 | mApp, subId, "iccTransmitApduBasicChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5575 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5576 | if (DBG) { |
| 5577 | log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" |
| 5578 | + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
| 5579 | } |
| 5580 | return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage, |
| 5581 | cla, command, p1, p2, p3, data); |
| 5582 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5583 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5584 | @Override |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5585 | public String iccTransmitApduBasicChannelByPort(int slotIndex, int portIndex, |
| 5586 | 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] | 5587 | enforceModifyPermission(); |
| 5588 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 5589 | if (DBG) { |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5590 | log("iccTransmitApduBasicChannelByPort: slotIndex=" + slotIndex + " portIndex=" |
| 5591 | + portIndex + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" |
| 5592 | + p2 + " p3=" + p3 + " data=" + data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5593 | } |
| 5594 | |
| 5595 | return iccTransmitApduBasicChannelWithPermission( |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5596 | getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), callingPackage, |
| 5597 | cla, command, p1, p2, p3, data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5598 | } |
| 5599 | |
| 5600 | // open APDU basic channel assuming the caller has sufficient permissions |
| 5601 | private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage, |
| 5602 | int cla, int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5603 | final long identity = Binder.clearCallingIdentity(); |
| 5604 | try { |
| 5605 | if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3 |
| 5606 | && TextUtils.equals(ISDR_AID, data)) { |
| 5607 | // Only allows LPA to select ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5608 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 5609 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5610 | if (bestComponent == null |
| 5611 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 5612 | loge("The calling package is not allowed to select ISD-R."); |
| 5613 | throw new SecurityException( |
| 5614 | "The calling package is not allowed to select ISD-R."); |
| 5615 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 5616 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 5617 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5618 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5619 | new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone, |
| 5620 | null /* workSource */); |
| 5621 | if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5622 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5623 | // Append the returned status code to the end of the response payload. |
| 5624 | String s = Integer.toHexString( |
| 5625 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 5626 | if (response.payload != null) { |
| 5627 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 5628 | } |
| 5629 | return s; |
| 5630 | } finally { |
| 5631 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 5632 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5633 | } |
| 5634 | |
| 5635 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5636 | 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] | 5637 | String filePath) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5638 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5639 | mApp, subId, "iccExchangeSimIO"); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5640 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5641 | final long identity = Binder.clearCallingIdentity(); |
| 5642 | try { |
| 5643 | if (DBG) { |
| 5644 | log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " |
| 5645 | + p1 + " " + p2 + " " + p3 + ":" + filePath); |
| 5646 | } |
| 5647 | |
| 5648 | IccIoResult response = |
| 5649 | (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO, |
| 5650 | new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath), |
| 5651 | subId); |
| 5652 | |
| 5653 | if (DBG) { |
| 5654 | log("Exchange SIM_IO [R]" + response); |
| 5655 | } |
| 5656 | |
| 5657 | byte[] result = null; |
| 5658 | int length = 2; |
| 5659 | if (response.payload != null) { |
| 5660 | length = 2 + response.payload.length; |
| 5661 | result = new byte[length]; |
| 5662 | System.arraycopy(response.payload, 0, result, 0, response.payload.length); |
| 5663 | } else { |
| 5664 | result = new byte[length]; |
| 5665 | } |
| 5666 | |
| 5667 | result[length - 1] = (byte) response.sw2; |
| 5668 | result[length - 2] = (byte) response.sw1; |
| 5669 | return result; |
| 5670 | } finally { |
| 5671 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5672 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5673 | } |
| 5674 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5675 | /** |
| 5676 | * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM) |
| 5677 | * on a particular subscription |
| 5678 | */ |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5679 | public String[] getForbiddenPlmns(int subId, int appType, String callingPackage, |
| 5680 | String callingFeatureId) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 5681 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5682 | mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 5683 | return null; |
| 5684 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5685 | |
| 5686 | final long identity = Binder.clearCallingIdentity(); |
| 5687 | try { |
| 5688 | if (appType != TelephonyManager.APPTYPE_USIM |
| 5689 | && appType != TelephonyManager.APPTYPE_SIM) { |
| 5690 | loge("getForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 5691 | return null; |
| 5692 | } |
| 5693 | Object response = sendRequest( |
| 5694 | CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId); |
| 5695 | if (response instanceof String[]) { |
| 5696 | return (String[]) response; |
| 5697 | } |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5698 | // Response is an Exception of some kind |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5699 | // which is signalled to the user as a NULL retval |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5700 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5701 | } finally { |
| 5702 | Binder.restoreCallingIdentity(identity); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5703 | } |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5704 | } |
| 5705 | |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5706 | /** |
| 5707 | * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular |
| 5708 | * subscription. |
| 5709 | * |
| 5710 | * @param subId the id of the subscription. |
| 5711 | * @param appType the uicc app type, must be USIM or SIM. |
| 5712 | * @param fplmns the Forbiden plmns list that needed to be written to the SIM. |
| 5713 | * @param callingPackage the op Package name. |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5714 | * @param callingFeatureId the feature in the package. |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5715 | * @return number of fplmns that is successfully written to the SIM. |
| 5716 | */ |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5717 | public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage, |
| 5718 | String callingFeatureId) { |
Jayachandran C | 5b0d75a | 2021-10-21 22:15:27 -0700 | [diff] [blame] | 5719 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5720 | mApp, subId, "setForbiddenPlmns"); |
| 5721 | |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5722 | if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) { |
| 5723 | loge("setForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 5724 | throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM"); |
| 5725 | } |
| 5726 | if (fplmns == null) { |
| 5727 | throw new IllegalArgumentException("Fplmn List provided is null"); |
| 5728 | } |
| 5729 | for (String fplmn : fplmns) { |
| 5730 | if (!CellIdentity.isValidPlmn(fplmn)) { |
| 5731 | throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn); |
| 5732 | } |
| 5733 | } |
| 5734 | final long identity = Binder.clearCallingIdentity(); |
| 5735 | try { |
| 5736 | Object response = sendRequest( |
| 5737 | CMD_SET_FORBIDDEN_PLMNS, |
| 5738 | new Pair<Integer, List<String>>(new Integer(appType), fplmns), |
| 5739 | subId); |
| 5740 | return (int) response; |
| 5741 | } finally { |
| 5742 | Binder.restoreCallingIdentity(identity); |
| 5743 | } |
| 5744 | } |
| 5745 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5746 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5747 | public String sendEnvelopeWithStatus(int subId, String content) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5748 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5749 | mApp, subId, "sendEnvelopeWithStatus"); |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5750 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5751 | final long identity = Binder.clearCallingIdentity(); |
| 5752 | try { |
| 5753 | IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId); |
| 5754 | if (response.payload == null) { |
| 5755 | return ""; |
| 5756 | } |
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 | // Append the returned status code to the end of the response payload. |
| 5759 | String s = Integer.toHexString( |
| 5760 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 5761 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 5762 | return s; |
| 5763 | } finally { |
| 5764 | Binder.restoreCallingIdentity(identity); |
| 5765 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5766 | } |
| 5767 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5768 | /** |
| 5769 | * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 5770 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 5771 | * |
| 5772 | * @param itemID the ID of the item to read |
| 5773 | * @return the NV item as a String, or null on error. |
| 5774 | */ |
| 5775 | @Override |
| 5776 | public String nvReadItem(int itemID) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5777 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5778 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5779 | mApp, getDefaultSubscription(), "nvReadItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5780 | |
| 5781 | final long identity = Binder.clearCallingIdentity(); |
| 5782 | try { |
| 5783 | if (DBG) log("nvReadItem: item " + itemID); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5784 | String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5785 | if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"'); |
| 5786 | return value; |
| 5787 | } finally { |
| 5788 | Binder.restoreCallingIdentity(identity); |
| 5789 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5790 | } |
| 5791 | |
| 5792 | /** |
| 5793 | * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 5794 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 5795 | * |
| 5796 | * @param itemID the ID of the item to read |
| 5797 | * @param itemValue the value to write, as a String |
| 5798 | * @return true on success; false on any failure |
| 5799 | */ |
| 5800 | @Override |
| 5801 | public boolean nvWriteItem(int itemID, String itemValue) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5802 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5803 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5804 | mApp, getDefaultSubscription(), "nvWriteItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5805 | |
| 5806 | final long identity = Binder.clearCallingIdentity(); |
| 5807 | try { |
| 5808 | if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"'); |
| 5809 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5810 | new Pair<Integer, String>(itemID, itemValue), workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5811 | if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail")); |
| 5812 | return success; |
| 5813 | } finally { |
| 5814 | Binder.restoreCallingIdentity(identity); |
| 5815 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5816 | } |
| 5817 | |
| 5818 | /** |
| 5819 | * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage. |
| 5820 | * Used for device configuration by some CDMA operators. |
| 5821 | * |
| 5822 | * @param preferredRoamingList byte array containing the new PRL |
| 5823 | * @return true on success; false on any failure |
| 5824 | */ |
| 5825 | @Override |
| 5826 | public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5827 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5828 | mApp, getDefaultSubscription(), "nvWriteCdmaPrl"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5829 | |
| 5830 | final long identity = Binder.clearCallingIdentity(); |
| 5831 | try { |
| 5832 | if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList)); |
| 5833 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList); |
| 5834 | if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail")); |
| 5835 | return success; |
| 5836 | } finally { |
| 5837 | Binder.restoreCallingIdentity(identity); |
| 5838 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5839 | } |
| 5840 | |
| 5841 | /** |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5842 | * 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] | 5843 | * Used for device configuration by some CDMA operators. |
| 5844 | * |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5845 | * @param slotIndex - device slot. |
| 5846 | * |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5847 | * @return true on success; false on any failure |
| 5848 | */ |
| 5849 | @Override |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5850 | public boolean resetModemConfig(int slotIndex) { |
| 5851 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5852 | if (phone != null) { |
| 5853 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5854 | mApp, phone.getSubId(), "resetModemConfig"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5855 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5856 | final long identity = Binder.clearCallingIdentity(); |
| 5857 | try { |
| 5858 | Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null); |
| 5859 | if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 5860 | return success; |
| 5861 | } finally { |
| 5862 | Binder.restoreCallingIdentity(identity); |
| 5863 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5864 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5865 | return false; |
| 5866 | } |
| 5867 | |
| 5868 | /** |
| 5869 | * Generate a radio modem reset. Used for device configuration by some CDMA operators. |
| 5870 | * |
| 5871 | * @param slotIndex - device slot. |
| 5872 | * |
| 5873 | * @return true on success; false on any failure |
| 5874 | */ |
| 5875 | @Override |
| 5876 | public boolean rebootModem(int slotIndex) { |
| 5877 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5878 | if (phone != null) { |
| 5879 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5880 | mApp, phone.getSubId(), "rebootModem"); |
| 5881 | |
| 5882 | final long identity = Binder.clearCallingIdentity(); |
| 5883 | try { |
| 5884 | Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null); |
| 5885 | if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail")); |
| 5886 | return success; |
| 5887 | } finally { |
| 5888 | Binder.restoreCallingIdentity(identity); |
| 5889 | } |
| 5890 | } |
| 5891 | return false; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5892 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5893 | |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5894 | /** |
Grace Jia | aa2eb6b | 2020-01-09 16:26:08 -0800 | [diff] [blame] | 5895 | * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and |
| 5896 | * {@link #disableIms(int)}. |
| 5897 | * @param slotIndex device slot. |
| 5898 | */ |
| 5899 | public void resetIms(int slotIndex) { |
| 5900 | enforceModifyPermission(); |
| 5901 | |
| 5902 | final long identity = Binder.clearCallingIdentity(); |
| 5903 | try { |
| 5904 | if (mImsResolver == null) { |
| 5905 | // may happen if the does not support IMS. |
| 5906 | return; |
| 5907 | } |
Hyunho | a17ac7c | 2022-08-30 12:03:04 +0000 | [diff] [blame] | 5908 | mImsResolver.resetIms(slotIndex); |
Grace Jia | aa2eb6b | 2020-01-09 16:26:08 -0800 | [diff] [blame] | 5909 | } finally { |
| 5910 | Binder.restoreCallingIdentity(identity); |
| 5911 | } |
| 5912 | } |
| 5913 | |
| 5914 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5915 | * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability |
| 5916 | * status updates, if not already enabled. |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5917 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5918 | public void enableIms(int slotId) { |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5919 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5920 | |
| 5921 | final long identity = Binder.clearCallingIdentity(); |
| 5922 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5923 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5924 | // may happen if the device does not support IMS. |
| 5925 | return; |
| 5926 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5927 | mImsResolver.enableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5928 | } finally { |
| 5929 | Binder.restoreCallingIdentity(identity); |
| 5930 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5931 | } |
| 5932 | |
| 5933 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5934 | * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature |
| 5935 | * status updates to disabled. |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5936 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5937 | public void disableIms(int slotId) { |
| 5938 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5939 | |
| 5940 | final long identity = Binder.clearCallingIdentity(); |
| 5941 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5942 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5943 | // may happen if the device does not support IMS. |
| 5944 | return; |
| 5945 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5946 | mImsResolver.disableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5947 | } finally { |
| 5948 | Binder.restoreCallingIdentity(identity); |
| 5949 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5950 | } |
| 5951 | |
| 5952 | /** |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5953 | * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback |
| 5954 | * callback. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5955 | */ |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5956 | @Override |
Brad Ebinger | f6aca00 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 5957 | public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) { |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5958 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5959 | |
| 5960 | final long identity = Binder.clearCallingIdentity(); |
| 5961 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5962 | if (mImsResolver == null) { |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5963 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 5964 | "Device does not support IMS"); |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5965 | } |
Brad Ebinger | f6aca00 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 5966 | mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5967 | } finally { |
| 5968 | Binder.restoreCallingIdentity(identity); |
| 5969 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5970 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5971 | /** |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5972 | * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature. |
| 5973 | */ |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5974 | @Override |
| 5975 | public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) { |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5976 | enforceModifyPermission(); |
| 5977 | |
| 5978 | final long identity = Binder.clearCallingIdentity(); |
| 5979 | try { |
| 5980 | if (mImsResolver == null) return; |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5981 | mImsResolver.unregisterImsFeatureCallback(callback); |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5982 | } finally { |
| 5983 | Binder.restoreCallingIdentity(identity); |
| 5984 | } |
| 5985 | } |
| 5986 | |
| 5987 | /** |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5988 | * Returns the {@link IImsRegistration} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5989 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5990 | */ |
| 5991 | public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException { |
| 5992 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5993 | |
| 5994 | final long identity = Binder.clearCallingIdentity(); |
| 5995 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5996 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5997 | // may happen if the device does not support IMS. |
| 5998 | return null; |
| 5999 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6000 | return mImsResolver.getImsRegistration(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6001 | } finally { |
| 6002 | Binder.restoreCallingIdentity(identity); |
| 6003 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 6004 | } |
| 6005 | |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6006 | /** |
| 6007 | * Returns the {@link IImsConfig} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6008 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6009 | */ |
| 6010 | public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException { |
| 6011 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6012 | |
| 6013 | final long identity = Binder.clearCallingIdentity(); |
| 6014 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6015 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6016 | // may happen if the device does not support IMS. |
| 6017 | return null; |
| 6018 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6019 | return mImsResolver.getImsConfig(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6020 | } finally { |
| 6021 | Binder.restoreCallingIdentity(identity); |
| 6022 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6023 | } |
| 6024 | |
Brad Ebinger | 884c07b | 2018-02-15 16:17:40 -0800 | [diff] [blame] | 6025 | /** |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6026 | * Sets the ImsService Package Name that Telephony will bind to. |
| 6027 | * |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6028 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 6029 | * @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] | 6030 | * ImsService is the device default ImsService. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6031 | * @param featureTypes An integer array of feature types associated with a packageName. |
| 6032 | * @param packageName The name of the package that the current configuration will be replaced |
| 6033 | * with. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6034 | * @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] | 6035 | */ |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6036 | public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService, |
| 6037 | int[] featureTypes, String packageName) { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6038 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 6039 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
Jack Yu | 00ece8c | 2022-11-19 22:29:12 -0800 | [diff] [blame] | 6040 | SubscriptionManager.getSubscriptionId(slotIndex), "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 6041 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6042 | final long identity = Binder.clearCallingIdentity(); |
| 6043 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6044 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6045 | // may happen if the device does not support IMS. |
| 6046 | return false; |
| 6047 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6048 | Map<Integer, String> featureConfig = new HashMap<>(); |
| 6049 | for (int featureType : featureTypes) { |
| 6050 | featureConfig.put(featureType, packageName); |
| 6051 | } |
| 6052 | return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService, |
| 6053 | featureConfig); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6054 | } finally { |
| 6055 | Binder.restoreCallingIdentity(identity); |
| 6056 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6057 | } |
| 6058 | |
| 6059 | /** |
Brad Ebinger | 999d330 | 2020-11-25 14:31:39 -0800 | [diff] [blame] | 6060 | * Clears any carrier ImsService overrides for the slot index specified that were previously |
| 6061 | * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}. |
| 6062 | * |
| 6063 | * This should only be used for testing. |
| 6064 | * |
| 6065 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 6066 | * @return true if clearing the carrier ImsService override succeeded or false if it did not. |
| 6067 | */ |
| 6068 | @Override |
| 6069 | public boolean clearCarrierImsServiceOverride(int slotIndex) { |
Brad Ebinger | 999d330 | 2020-11-25 14:31:39 -0800 | [diff] [blame] | 6070 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 6071 | "clearCarrierImsServiceOverride"); |
| 6072 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
Jack Yu | 00ece8c | 2022-11-19 22:29:12 -0800 | [diff] [blame] | 6073 | SubscriptionManager.getSubscriptionId(slotIndex), "clearCarrierImsServiceOverride"); |
Brad Ebinger | 999d330 | 2020-11-25 14:31:39 -0800 | [diff] [blame] | 6074 | |
| 6075 | final long identity = Binder.clearCallingIdentity(); |
| 6076 | try { |
| 6077 | if (mImsResolver == null) { |
| 6078 | // may happen if the device does not support IMS. |
| 6079 | return false; |
| 6080 | } |
| 6081 | return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex); |
| 6082 | } finally { |
| 6083 | Binder.restoreCallingIdentity(identity); |
| 6084 | } |
| 6085 | } |
| 6086 | |
| 6087 | /** |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6088 | * Return the package name of the currently bound ImsService. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6089 | * |
| 6090 | * @param slotId The slot that the ImsService is associated with. |
| 6091 | * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is |
| 6092 | * the device default. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6093 | * @param featureType The feature associated with the queried configuration. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6094 | * @return the package name of the ImsService configuration. |
| 6095 | */ |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6096 | public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService, |
| 6097 | @ImsFeature.FeatureType int featureType) { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6098 | TelephonyPermissions |
Jack Yu | 00ece8c | 2022-11-19 22:29:12 -0800 | [diff] [blame] | 6099 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(mApp, |
| 6100 | SubscriptionManager.getSubscriptionId(slotId), "getBoundImsServicePackage"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 6101 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6102 | final long identity = Binder.clearCallingIdentity(); |
| 6103 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6104 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6105 | // may happen if the device does not support IMS. |
| 6106 | return ""; |
| 6107 | } |
Brad Ebinger | a80c331 | 2019-12-02 10:59:39 -0800 | [diff] [blame] | 6108 | // TODO: change API to query RCS separately. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6109 | return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService, |
| 6110 | featureType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6111 | } finally { |
| 6112 | Binder.restoreCallingIdentity(identity); |
| 6113 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6114 | } |
| 6115 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6116 | /** |
| 6117 | * Get the MmTelFeature state associated with the requested subscription id. |
| 6118 | * @param subId The subscription that the MmTelFeature is associated with. |
| 6119 | * @param callback A callback with an integer containing the |
| 6120 | * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature. |
| 6121 | */ |
| 6122 | @Override |
| 6123 | public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) { |
| 6124 | enforceReadPrivilegedPermission("getImsMmTelFeatureState"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 6125 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 6126 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 6127 | "IMS not available on device."); |
| 6128 | } |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6129 | final long token = Binder.clearCallingIdentity(); |
| 6130 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 6131 | int slotId = getSlotIndex(subId); |
| 6132 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 6133 | Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '" |
| 6134 | + subId + "'"); |
| 6135 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 6136 | } |
| 6137 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 6138 | ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> { |
| 6139 | try { |
| 6140 | callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger); |
| 6141 | } catch (RemoteException e) { |
| 6142 | Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. " |
| 6143 | + "Ignore"); |
| 6144 | } |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6145 | }); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 6146 | } catch (ImsException e) { |
| 6147 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6148 | } finally { |
| 6149 | Binder.restoreCallingIdentity(token); |
| 6150 | } |
| 6151 | } |
| 6152 | |
Daniel Bright | bb5840b | 2021-01-12 15:48:18 -0800 | [diff] [blame] | 6153 | /** |
| 6154 | * Sets the ims registration state on all valid {@link Phone}s. |
| 6155 | */ |
| 6156 | public void setImsRegistrationState(final boolean registered) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 6157 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6158 | |
| 6159 | final long identity = Binder.clearCallingIdentity(); |
| 6160 | try { |
Daniel Bright | bb5840b | 2021-01-12 15:48:18 -0800 | [diff] [blame] | 6161 | // NOTE: Before S, this method only set the default phone. |
| 6162 | for (final Phone phone : PhoneFactory.getPhones()) { |
| 6163 | if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) { |
| 6164 | phone.setImsRegistrationState(registered); |
| 6165 | } |
| 6166 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6167 | } finally { |
| 6168 | Binder.restoreCallingIdentity(identity); |
| 6169 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 6170 | } |
| 6171 | |
| 6172 | /** |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 6173 | * Set the network selection mode to automatic. |
| 6174 | * |
| 6175 | */ |
| 6176 | @Override |
| 6177 | public void setNetworkSelectionModeAutomatic(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6178 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6179 | mApp, subId, "setNetworkSelectionModeAutomatic"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6180 | |
| 6181 | final long identity = Binder.clearCallingIdentity(); |
| 6182 | try { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 6183 | if (!isActiveSubscription(subId)) { |
| 6184 | return; |
| 6185 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6186 | if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId); |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 6187 | sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId, |
| 6188 | SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6189 | } finally { |
| 6190 | Binder.restoreCallingIdentity(identity); |
| 6191 | } |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 6192 | } |
| 6193 | |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 6194 | /** |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6195 | * Ask the radio to connect to the input network and change selection mode to manual. |
| 6196 | * |
| 6197 | * @param subId the id of the subscription. |
| 6198 | * @param operatorInfo the operator information, included the PLMN, long name and short name of |
| 6199 | * the operator to attach to. |
| 6200 | * @param persistSelection whether the selection will persist until reboot. If true, only allows |
| 6201 | * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume |
| 6202 | * normal network selection next time. |
| 6203 | * @return {@code true} on success; {@code true} on any failure. |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6204 | */ |
| 6205 | @Override |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6206 | public boolean setNetworkSelectionModeManual( |
| 6207 | int subId, OperatorInfo operatorInfo, boolean persistSelection) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6208 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6209 | mApp, subId, "setNetworkSelectionModeManual"); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 6210 | |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 6211 | final long identity = Binder.clearCallingIdentity(); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 6212 | if (!isActiveSubscription(subId)) { |
| 6213 | return false; |
| 6214 | } |
| 6215 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6216 | try { |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6217 | ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6218 | persistSelection); |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6219 | if (DBG) { |
| 6220 | log("setNetworkSelectionModeManual: subId: " + subId |
| 6221 | + " operator: " + operatorInfo); |
| 6222 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6223 | return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId); |
| 6224 | } finally { |
| 6225 | Binder.restoreCallingIdentity(identity); |
| 6226 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6227 | } |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6228 | /** |
| 6229 | * Get the manual network selection |
| 6230 | * |
| 6231 | * @param subId the id of the subscription. |
| 6232 | * |
| 6233 | * @return the previously saved user selected PLMN |
| 6234 | */ |
| 6235 | @Override |
| 6236 | public String getManualNetworkSelectionPlmn(int subId) { |
| 6237 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 6238 | .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6239 | mApp, subId, "getManualNetworkSelectionPlmn"); |
| 6240 | |
| 6241 | final long identity = Binder.clearCallingIdentity(); |
| 6242 | try { |
| 6243 | if (!isActiveSubscription(subId)) { |
shilu | fa1c259 | 2020-03-10 10:59:43 -0700 | [diff] [blame] | 6244 | throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6245 | } |
| 6246 | |
| 6247 | final Phone phone = getPhone(subId); |
| 6248 | if (phone == null) { |
shilu | fa1c259 | 2020-03-10 10:59:43 -0700 | [diff] [blame] | 6249 | throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6250 | } |
| 6251 | OperatorInfo networkSelection = phone.getSavedNetworkSelection(); |
| 6252 | return TextUtils.isEmpty(networkSelection.getOperatorNumeric()) |
| 6253 | ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric(); |
| 6254 | } finally { |
| 6255 | Binder.restoreCallingIdentity(identity); |
| 6256 | } |
| 6257 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6258 | |
| 6259 | /** |
| 6260 | * Scans for available networks. |
| 6261 | */ |
| 6262 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6263 | public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage, |
| 6264 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6265 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6266 | mApp, subId, "getCellNetworkScanResults"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6267 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 6268 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 6269 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 6270 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6271 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6272 | .setCallingPid(Binder.getCallingPid()) |
| 6273 | .setCallingUid(Binder.getCallingUid()) |
| 6274 | .setMethod("getCellNetworkScanResults") |
| 6275 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
Hall Liu | c4a3e42 | 2020-05-26 17:18:03 -0700 | [diff] [blame] | 6276 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 6277 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6278 | .build()); |
| 6279 | switch (locationResult) { |
| 6280 | case DENIED_HARD: |
| 6281 | throw new SecurityException("Not allowed to access scan results -- location"); |
| 6282 | case DENIED_SOFT: |
| 6283 | return null; |
| 6284 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6285 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6286 | long identity = Binder.clearCallingIdentity(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6287 | try { |
| 6288 | if (DBG) log("getCellNetworkScanResults: subId " + subId); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6289 | return (CellNetworkScanResult) sendRequest( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6290 | CMD_PERFORM_NETWORK_SCAN, null, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6291 | } finally { |
| 6292 | Binder.restoreCallingIdentity(identity); |
| 6293 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6294 | } |
| 6295 | |
| 6296 | /** |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6297 | * Get the call forwarding info, given the call forwarding reason. |
| 6298 | */ |
| 6299 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6300 | public void getCallForwarding(int subId, int callForwardingReason, |
| 6301 | ICallForwardingInfoCallback callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6302 | enforceReadPrivilegedPermission("getCallForwarding"); |
| 6303 | long identity = Binder.clearCallingIdentity(); |
| 6304 | try { |
| 6305 | if (DBG) { |
| 6306 | log("getCallForwarding: subId " + subId |
| 6307 | + " callForwardingReason" + callForwardingReason); |
| 6308 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6309 | |
| 6310 | Phone phone = getPhone(subId); |
| 6311 | if (phone == null) { |
| 6312 | try { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 6313 | callback.onError( |
| 6314 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6315 | } catch (RemoteException e) { |
| 6316 | // ignore |
| 6317 | } |
| 6318 | return; |
| 6319 | } |
| 6320 | |
| 6321 | Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create( |
| 6322 | callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() { |
| 6323 | @Override |
| 6324 | public void onCallForwardingInfoAvailable(CallForwardingInfo info) { |
| 6325 | try { |
| 6326 | callback.onCallForwardingInfoAvailable(info); |
| 6327 | } catch (RemoteException e) { |
| 6328 | // ignore |
| 6329 | } |
| 6330 | } |
| 6331 | |
| 6332 | @Override |
| 6333 | public void onError(int error) { |
| 6334 | try { |
| 6335 | callback.onError(error); |
| 6336 | } catch (RemoteException e) { |
| 6337 | // ignore |
| 6338 | } |
| 6339 | } |
| 6340 | }); |
| 6341 | sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6342 | } finally { |
| 6343 | Binder.restoreCallingIdentity(identity); |
| 6344 | } |
| 6345 | } |
| 6346 | |
| 6347 | /** |
| 6348 | * Sets the voice call forwarding info including status (enable/disable), call forwarding |
| 6349 | * reason, the number to forward, and the timeout before the forwarding is attempted. |
| 6350 | */ |
| 6351 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6352 | public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo, |
| 6353 | IIntegerConsumer callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6354 | enforceModifyPermission(); |
| 6355 | long identity = Binder.clearCallingIdentity(); |
| 6356 | try { |
| 6357 | if (DBG) { |
| 6358 | log("setCallForwarding: subId " + subId |
| 6359 | + " callForwardingInfo" + callForwardingInfo); |
| 6360 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6361 | |
| 6362 | Phone phone = getPhone(subId); |
| 6363 | if (phone == null) { |
| 6364 | try { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 6365 | callback.accept( |
| 6366 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6367 | } catch (RemoteException e) { |
| 6368 | // ignore |
| 6369 | } |
| 6370 | return; |
| 6371 | } |
| 6372 | |
| 6373 | Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo, |
| 6374 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 6375 | |
| 6376 | sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6377 | } finally { |
| 6378 | Binder.restoreCallingIdentity(identity); |
| 6379 | } |
| 6380 | } |
| 6381 | |
| 6382 | /** |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6383 | * Get the call waiting status for a subId. |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6384 | */ |
| 6385 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6386 | public void getCallWaitingStatus(int subId, IIntegerConsumer callback) { |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6387 | enforceReadPrivilegedPermission("getCallWaitingStatus"); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6388 | long identity = Binder.clearCallingIdentity(); |
| 6389 | try { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6390 | Phone phone = getPhone(subId); |
| 6391 | if (phone == null) { |
| 6392 | try { |
| 6393 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 6394 | } catch (RemoteException e) { |
| 6395 | // ignore |
| 6396 | } |
| 6397 | return; |
| 6398 | } |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6399 | CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext()); |
| 6400 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 6401 | boolean requireUssd = c.getBoolean( |
| 6402 | CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6403 | |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6404 | if (DBG) log("getCallWaitingStatus: subId " + subId); |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6405 | if (requireUssd) { |
| 6406 | CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(), |
| 6407 | getSubscriptionCarrierId(subId)); |
| 6408 | String newUssdCommand = ""; |
| 6409 | try { |
| 6410 | newUssdCommand = carrierXmlParser.getFeature( |
| 6411 | CarrierXmlParser.FEATURE_CALL_WAITING) |
| 6412 | .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null); |
| 6413 | } catch (NullPointerException e) { |
| 6414 | loge("Failed to generate USSD number" + e); |
| 6415 | } |
| 6416 | ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver( |
| 6417 | mMainThreadHandler, callback, carrierXmlParser, |
| 6418 | CarrierXmlParser.SsEntry.SSAction.QUERY); |
| 6419 | final String ussdCommand = newUssdCommand; |
| 6420 | Executors.newSingleThreadExecutor().execute(() -> { |
| 6421 | handleUssdRequest(subId, ussdCommand, wrappedCallback); |
| 6422 | }); |
| 6423 | } else { |
| 6424 | Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException( |
| 6425 | callback::accept); |
| 6426 | sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null); |
| 6427 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6428 | } finally { |
| 6429 | Binder.restoreCallingIdentity(identity); |
| 6430 | } |
| 6431 | } |
| 6432 | |
| 6433 | /** |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6434 | * Sets whether call waiting is enabled for a given subId. |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6435 | */ |
| 6436 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6437 | public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6438 | enforceModifyPermission(); |
| 6439 | long identity = Binder.clearCallingIdentity(); |
| 6440 | try { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6441 | if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable); |
| 6442 | |
| 6443 | Phone phone = getPhone(subId); |
| 6444 | if (phone == null) { |
| 6445 | try { |
| 6446 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 6447 | } catch (RemoteException e) { |
| 6448 | // ignore |
| 6449 | } |
| 6450 | return; |
| 6451 | } |
| 6452 | |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6453 | CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext()); |
| 6454 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 6455 | boolean requireUssd = c.getBoolean( |
| 6456 | CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6457 | |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6458 | if (DBG) log("getCallWaitingStatus: subId " + subId); |
| 6459 | if (requireUssd) { |
| 6460 | CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(), |
| 6461 | getSubscriptionCarrierId(subId)); |
| 6462 | CarrierXmlParser.SsEntry.SSAction ssAction = |
| 6463 | enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE |
| 6464 | : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE; |
| 6465 | String newUssdCommand = ""; |
| 6466 | try { |
| 6467 | newUssdCommand = carrierXmlParser.getFeature( |
| 6468 | CarrierXmlParser.FEATURE_CALL_WAITING) |
| 6469 | .makeCommand(ssAction, null); |
| 6470 | } catch (NullPointerException e) { |
| 6471 | loge("Failed to generate USSD number" + e); |
| 6472 | } |
| 6473 | ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver( |
| 6474 | mMainThreadHandler, callback, carrierXmlParser, ssAction); |
| 6475 | final String ussdCommand = newUssdCommand; |
| 6476 | Executors.newSingleThreadExecutor().execute(() -> { |
| 6477 | handleUssdRequest(subId, ussdCommand, wrappedCallback); |
| 6478 | }); |
| 6479 | } else { |
| 6480 | Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable, |
| 6481 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 6482 | |
| 6483 | sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null); |
| 6484 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6485 | } finally { |
| 6486 | Binder.restoreCallingIdentity(identity); |
| 6487 | } |
| 6488 | } |
| 6489 | |
| 6490 | /** |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 6491 | * Starts a new network scan and returns the id of this scan. |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6492 | * |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 6493 | * @param subId id of the subscription |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 6494 | * @param renounceFineLocationAccess Set this to true if the caller would not like to receive |
| 6495 | * location related information which will be sent if the caller already possess |
| 6496 | * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 6497 | * @param request contains the radio access networks with bands/channels to scan |
| 6498 | * @param messenger callback messenger for scan results or errors |
| 6499 | * @param binder for the purpose of auto clean when the user thread crashes |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6500 | * @return the id of the requested scan which can be used to stop the scan. |
| 6501 | */ |
| 6502 | @Override |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 6503 | public int requestNetworkScan(int subId, boolean renounceFineLocationAccess, |
| 6504 | NetworkScanRequest request, Messenger messenger, |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6505 | IBinder binder, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6506 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6507 | mApp, subId, "requestNetworkScan"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6508 | LocationAccessPolicy.LocationPermissionResult locationResult = |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 6509 | LocationAccessPolicy.LocationPermissionResult.DENIED_HARD; |
| 6510 | if (!renounceFineLocationAccess) { |
| 6511 | locationResult = LocationAccessPolicy.checkLocationPermission(mApp, |
| 6512 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 6513 | .setCallingPackage(callingPackage) |
| 6514 | .setCallingFeatureId(callingFeatureId) |
| 6515 | .setCallingPid(Binder.getCallingPid()) |
| 6516 | .setCallingUid(Binder.getCallingUid()) |
| 6517 | .setMethod("requestNetworkScan") |
| 6518 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 6519 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 6520 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 6521 | .build()); |
| 6522 | } |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6523 | if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) { |
Nathan Harold | 1c11dba | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 6524 | SecurityException e = checkNetworkRequestForSanitizedLocationAccess( |
| 6525 | request, subId, callingPackage); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6526 | if (e != null) { |
| 6527 | if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) { |
| 6528 | throw e; |
| 6529 | } else { |
Hall Liu | 0e5abaf | 2019-04-04 01:25:30 -0700 | [diff] [blame] | 6530 | loge(e.getMessage()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6531 | return TelephonyScanManager.INVALID_SCAN_ID; |
| 6532 | } |
| 6533 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6534 | } |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6535 | int callingUid = Binder.getCallingUid(); |
| 6536 | int callingPid = Binder.getCallingPid(); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 6537 | final long identity = Binder.clearCallingIdentity(); |
| 6538 | try { |
| 6539 | return mNetworkScanRequestTracker.startNetworkScan( |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 6540 | renounceFineLocationAccess, request, messenger, binder, getPhone(subId), |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6541 | callingUid, callingPid, callingPackage); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 6542 | } finally { |
| 6543 | Binder.restoreCallingIdentity(identity); |
| 6544 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6545 | } |
| 6546 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6547 | private SecurityException checkNetworkRequestForSanitizedLocationAccess( |
Nathan Harold | 1c11dba | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 6548 | NetworkScanRequest request, int subId, String callingPackage) { |
Rambo Wang | 3dee30a | 2022-10-20 16:52:29 +0000 | [diff] [blame] | 6549 | boolean hasCarrierPriv; |
| 6550 | final long identity = Binder.clearCallingIdentity(); |
| 6551 | try { |
| 6552 | hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage) |
| 6553 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 6554 | } finally { |
| 6555 | Binder.restoreCallingIdentity(identity); |
| 6556 | } |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 6557 | boolean hasNetworkScanPermission = |
| 6558 | mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN) |
| 6559 | == PERMISSION_GRANTED; |
| 6560 | |
| 6561 | if (!hasCarrierPriv && !hasNetworkScanPermission) { |
| 6562 | return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed" |
| 6563 | + " for network scans without location access."); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6564 | } |
| 6565 | |
| 6566 | if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) { |
| 6567 | for (RadioAccessSpecifier ras : request.getSpecifiers()) { |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6568 | if (ras.getChannels() != null && ras.getChannels().length > 0) { |
| 6569 | return new SecurityException("Specific channels must not be" |
| 6570 | + " scanned without location access."); |
| 6571 | } |
| 6572 | } |
| 6573 | } |
| 6574 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6575 | return null; |
| 6576 | } |
| 6577 | |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6578 | /** |
| 6579 | * Stops an existing network scan with the given scanId. |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 6580 | * |
| 6581 | * @param subId id of the subscription |
| 6582 | * @param scanId id of the scan that needs to be stopped |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6583 | */ |
| 6584 | @Override |
| 6585 | public void stopNetworkScan(int subId, int scanId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6586 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6587 | mApp, subId, "stopNetworkScan"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6588 | |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6589 | int callingUid = Binder.getCallingUid(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6590 | final long identity = Binder.clearCallingIdentity(); |
| 6591 | try { |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6592 | mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6593 | } finally { |
| 6594 | Binder.restoreCallingIdentity(identity); |
| 6595 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6596 | } |
| 6597 | |
| 6598 | /** |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6599 | * Get the allowed network types bitmask. |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 6600 | * |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6601 | * @return the allowed network types bitmask, defined in RILConstants.java. |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 6602 | */ |
| 6603 | @Override |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6604 | public int getAllowedNetworkTypesBitmask(int subId) { |
Pengquan Meng | a4009cb | 2018-12-20 11:00:24 -0800 | [diff] [blame] | 6605 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 6606 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6607 | mApp, subId, "getAllowedNetworkTypesBitmask"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6608 | |
| 6609 | final long identity = Binder.clearCallingIdentity(); |
| 6610 | try { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6611 | if (DBG) log("getAllowedNetworkTypesBitmask"); |
| 6612 | int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId); |
| 6613 | int networkTypesBitmask = (result != null ? result[0] : -1); |
| 6614 | if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask); |
| 6615 | return networkTypesBitmask; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6616 | } finally { |
| 6617 | Binder.restoreCallingIdentity(identity); |
| 6618 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 6619 | } |
| 6620 | |
| 6621 | /** |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6622 | * Get the allowed network types for certain reason. |
| 6623 | * |
| 6624 | * @param subId the id of the subscription. |
| 6625 | * @param reason the reason the allowed network type change is taking place |
| 6626 | * @return the allowed network types. |
| 6627 | */ |
| 6628 | @Override |
| 6629 | public long getAllowedNetworkTypesForReason(int subId, |
| 6630 | @TelephonyManager.AllowedNetworkTypesReason int reason) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 6631 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 6632 | mApp, subId, "getAllowedNetworkTypesForReason"); |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6633 | final long identity = Binder.clearCallingIdentity(); |
| 6634 | try { |
| 6635 | return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason); |
| 6636 | } finally { |
| 6637 | Binder.restoreCallingIdentity(identity); |
| 6638 | } |
| 6639 | } |
| 6640 | |
| 6641 | /** |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6642 | * Enable/Disable E-UTRA-NR Dual Connectivity |
| 6643 | * @param subId subscription id of the sim card |
| 6644 | * @param nrDualConnectivityState expected NR dual connectivity state |
| 6645 | * This can be passed following states |
| 6646 | * <ol> |
| 6647 | * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE} |
| 6648 | * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE} |
| 6649 | * <li>Disable NR dual connectivity and force secondary cell to be released |
| 6650 | * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE} |
| 6651 | * </ol> |
| 6652 | * @return operation result. |
| 6653 | */ |
| 6654 | @Override |
| 6655 | public int setNrDualConnectivityState(int subId, |
| 6656 | @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) { |
| 6657 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6658 | mApp, subId, "enableNRDualConnectivity"); |
Sooraj Sasindran | 0e4e00a | 2021-03-16 18:02:32 -0700 | [diff] [blame] | 6659 | if (!isRadioInterfaceCapabilitySupported( |
Sooraj Sasindran | dfd595b | 2021-03-11 17:38:13 -0800 | [diff] [blame] | 6660 | TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) { |
| 6661 | return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED; |
| 6662 | } |
| 6663 | |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6664 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 6665 | final long identity = Binder.clearCallingIdentity(); |
| 6666 | try { |
| 6667 | int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY, |
| 6668 | nrDualConnectivityState, subId, |
| 6669 | workSource); |
| 6670 | if (DBG) log("enableNRDualConnectivity result: " + result); |
| 6671 | return result; |
| 6672 | } finally { |
| 6673 | Binder.restoreCallingIdentity(identity); |
| 6674 | } |
| 6675 | } |
| 6676 | |
| 6677 | /** |
| 6678 | * Is E-UTRA-NR Dual Connectivity enabled |
| 6679 | * @return true if dual connectivity is enabled else false |
| 6680 | */ |
| 6681 | @Override |
| 6682 | public boolean isNrDualConnectivityEnabled(int subId) { |
| 6683 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 6684 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6685 | mApp, subId, "isNRDualConnectivityEnabled"); |
Sooraj Sasindran | 0e4e00a | 2021-03-16 18:02:32 -0700 | [diff] [blame] | 6686 | if (!isRadioInterfaceCapabilitySupported( |
Sooraj Sasindran | dfd595b | 2021-03-11 17:38:13 -0800 | [diff] [blame] | 6687 | TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) { |
| 6688 | return false; |
| 6689 | } |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6690 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 6691 | final long identity = Binder.clearCallingIdentity(); |
| 6692 | try { |
| 6693 | boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED, |
| 6694 | null, subId, workSource); |
| 6695 | if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled); |
| 6696 | return isEnabled; |
| 6697 | } finally { |
| 6698 | Binder.restoreCallingIdentity(identity); |
| 6699 | } |
| 6700 | } |
| 6701 | |
| 6702 | /** |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6703 | * Set the allowed network types of the device and |
| 6704 | * provide the reason triggering the allowed network change. |
| 6705 | * |
| 6706 | * @param subId the id of the subscription. |
| 6707 | * @param reason the reason the allowed network type change is taking place |
| 6708 | * @param allowedNetworkTypes the allowed network types. |
| 6709 | * @return true on success; false on any failure. |
| 6710 | */ |
| 6711 | @Override |
| 6712 | public boolean setAllowedNetworkTypesForReason(int subId, |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6713 | @TelephonyManager.AllowedNetworkTypesReason int reason, |
| 6714 | @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) { |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6715 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6716 | mApp, subId, "setAllowedNetworkTypesForReason"); |
Gil Cukierman | 1d3d375 | 2022-10-03 21:31:33 +0000 | [diff] [blame] | 6717 | // If the caller only has carrier privileges, then they should not be able to override |
| 6718 | // any network types which were set for security reasons. |
| 6719 | if (mApp.checkCallingOrSelfPermission(Manifest.permission.MODIFY_PHONE_STATE) |
| 6720 | != PERMISSION_GRANTED |
| 6721 | && (reason == TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_ENABLE_2G |
| 6722 | || reason == TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER_RESTRICTIONS)) { |
| 6723 | throw new SecurityException( |
| 6724 | "setAllowedNetworkTypesForReason cannot be called with carrier privileges for" |
| 6725 | + " reason " |
| 6726 | + reason); |
| 6727 | } |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6728 | if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) { |
SongFerngWang | 7ffc273 | 2021-04-15 19:46:33 +0800 | [diff] [blame] | 6729 | loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason); |
| 6730 | return false; |
| 6731 | } |
| 6732 | if (!SubscriptionManager.isUsableSubscriptionId(subId)) { |
| 6733 | loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId); |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6734 | return false; |
| 6735 | } |
| 6736 | |
Jack Yu | e37dd26 | 2022-12-16 11:53:37 -0800 | [diff] [blame^] | 6737 | log("setAllowedNetworkTypesForReason: subId=" + subId + ", reason=" + reason + " value: " |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 6738 | + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes)); |
| 6739 | |
Jack Yu | e37dd26 | 2022-12-16 11:53:37 -0800 | [diff] [blame^] | 6740 | Phone phone = getPhone(subId); |
| 6741 | if (phone == null) { |
| 6742 | return false; |
| 6743 | } |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 6744 | |
Jack Yu | e37dd26 | 2022-12-16 11:53:37 -0800 | [diff] [blame^] | 6745 | if (allowedNetworkTypes == phone.getAllowedNetworkTypes(reason)) { |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 6746 | log("setAllowedNetworkTypesForReason: " + reason + "does not change value"); |
| 6747 | return true; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6748 | } |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 6749 | |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6750 | final long identity = Binder.clearCallingIdentity(); |
| 6751 | try { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6752 | Boolean success = (Boolean) sendRequest( |
| 6753 | CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON, |
| 6754 | new Pair<Integer, Long>(reason, allowedNetworkTypes), subId); |
| 6755 | |
| 6756 | if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail")); |
| 6757 | return success; |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6758 | } finally { |
| 6759 | Binder.restoreCallingIdentity(identity); |
| 6760 | } |
| 6761 | } |
| 6762 | |
| 6763 | /** |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6764 | * Check whether DUN APN is required for tethering with subId. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6765 | * |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6766 | * @param subId the id of the subscription to require tethering. |
Amit Mahajan | fe58cdf | 2017-07-11 12:01:53 -0700 | [diff] [blame] | 6767 | * @return {@code true} if DUN APN is required for tethering. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6768 | * @hide |
| 6769 | */ |
| 6770 | @Override |
SongFerngWang | f08d812 | 2019-11-15 14:58:44 +0800 | [diff] [blame] | 6771 | public boolean isTetheringApnRequiredForSubscriber(int subId) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6772 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6773 | final long identity = Binder.clearCallingIdentity(); |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6774 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6775 | try { |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6776 | if (phone != null) { |
| 6777 | return phone.hasMatchedTetherApnSetting(); |
| 6778 | } else { |
| 6779 | return false; |
| 6780 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6781 | } finally { |
| 6782 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6783 | } |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6784 | } |
| 6785 | |
| 6786 | /** |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6787 | * Get the user enabled state of Mobile Data. |
| 6788 | * |
| 6789 | * TODO: remove and use isUserDataEnabled. |
| 6790 | * This can't be removed now because some vendor codes |
| 6791 | * calls through ITelephony directly while they should |
| 6792 | * use TelephonyManager. |
| 6793 | * |
| 6794 | * @return true on enabled |
| 6795 | */ |
| 6796 | @Override |
| 6797 | public boolean getDataEnabled(int subId) { |
| 6798 | return isUserDataEnabled(subId); |
| 6799 | } |
| 6800 | |
| 6801 | /** |
| 6802 | * Get whether mobile data is enabled per user setting. |
| 6803 | * |
| 6804 | * There are other factors deciding whether mobile data is actually enabled, but they are |
| 6805 | * not considered here. See {@link #isDataEnabled(int)} for more details. |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6806 | * |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6807 | * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE |
| 6808 | * or carrier privileges. |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 6809 | * |
| 6810 | * @return {@code true} if data is enabled else {@code false} |
| 6811 | */ |
| 6812 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6813 | public boolean isUserDataEnabled(int subId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6814 | String functionName = "isUserDataEnabled"; |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6815 | try { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6816 | try { |
| 6817 | mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE, |
| 6818 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 6819 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6820 | mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName); |
| 6821 | } |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 6822 | } catch (SecurityException e) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6823 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6824 | mApp, subId, functionName); |
| 6825 | |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6826 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6827 | |
| 6828 | final long identity = Binder.clearCallingIdentity(); |
| 6829 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 6830 | int phoneId = SubscriptionManager.getPhoneId(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6831 | if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 6832 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6833 | if (phone != null) { |
| 6834 | boolean retVal = phone.isUserDataEnabled(); |
| 6835 | if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 6836 | return retVal; |
| 6837 | } else { |
| 6838 | if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 6839 | return false; |
| 6840 | } |
| 6841 | } finally { |
| 6842 | Binder.restoreCallingIdentity(identity); |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6843 | } |
| 6844 | } |
| 6845 | |
| 6846 | /** |
Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 6847 | * Checks if the device is capable of mobile data by considering whether whether the |
| 6848 | * user has enabled mobile data, whether the carrier has enabled mobile data, and |
| 6849 | * whether the network policy allows data connections. |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6850 | * |
Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 6851 | * @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] | 6852 | */ |
| 6853 | @Override |
| 6854 | public boolean isDataEnabled(int subId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6855 | String functionName = "isDataEnabled"; |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6856 | try { |
| 6857 | try { |
| 6858 | mApp.enforceCallingOrSelfPermission( |
| 6859 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6860 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 6861 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6862 | try { |
| 6863 | mApp.enforceCallingOrSelfPermission( |
| 6864 | android.Manifest.permission.READ_PHONE_STATE, |
| 6865 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 6866 | } catch (SecurityException e2) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6867 | mApp.enforceCallingOrSelfPermission( |
| 6868 | permission.READ_BASIC_PHONE_STATE, functionName); |
| 6869 | } |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6870 | } |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 6871 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6872 | enforceReadPrivilegedPermission(functionName); |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6873 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6874 | |
| 6875 | final long identity = Binder.clearCallingIdentity(); |
| 6876 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 6877 | int phoneId = SubscriptionManager.getPhoneId(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6878 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6879 | if (phone != null) { |
Sarah Chin | e04784a | 2022-10-31 20:32:34 -0700 | [diff] [blame] | 6880 | boolean retVal = phone.getDataSettingsManager().isDataEnabled(); |
Jack Yu | 4ad64e5 | 2021-12-03 14:23:53 -0800 | [diff] [blame] | 6881 | if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6882 | return retVal; |
| 6883 | } else { |
| 6884 | if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 6885 | return false; |
| 6886 | } |
| 6887 | } finally { |
| 6888 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 6889 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 6890 | } |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6891 | |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6892 | /** |
| 6893 | * Check if data is enabled for a specific reason |
| 6894 | * @param subId Subscription index |
| 6895 | * @param reason the reason the data enable change is taking place |
| 6896 | * @return {@code true} if the overall data is enabled; {@code false} if not. |
| 6897 | */ |
| 6898 | @Override |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6899 | public boolean isDataEnabledForReason(int subId, |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6900 | @TelephonyManager.DataEnabledReason int reason) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6901 | String functionName = "isDataEnabledForReason"; |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6902 | try { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6903 | try { |
| 6904 | mApp.enforceCallingOrSelfPermission( |
| 6905 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 6906 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 6907 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6908 | mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE, |
| 6909 | functionName); |
| 6910 | } |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 6911 | } catch (SecurityException e) { |
Sooraj Sasindran | 0d909a0 | 2021-11-08 12:01:16 -0800 | [diff] [blame] | 6912 | try { |
| 6913 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6914 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 6915 | } catch (SecurityException e2) { |
Sooraj Sasindran | 0d909a0 | 2021-11-08 12:01:16 -0800 | [diff] [blame] | 6916 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6917 | mApp, subId, functionName); |
Sooraj Sasindran | 0d909a0 | 2021-11-08 12:01:16 -0800 | [diff] [blame] | 6918 | } |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6919 | } |
| 6920 | |
| 6921 | |
| 6922 | final long identity = Binder.clearCallingIdentity(); |
| 6923 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 6924 | int phoneId = SubscriptionManager.getPhoneId(subId); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6925 | if (DBG) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6926 | log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6927 | + " reason=" + reason); |
| 6928 | } |
| 6929 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6930 | if (phone != null) { |
| 6931 | boolean retVal; |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 6932 | retVal = phone.getDataSettingsManager().isDataEnabledForReason(reason); |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6933 | if (DBG) log("isDataEnabledForReason: retVal=" + retVal); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6934 | return retVal; |
| 6935 | } else { |
| 6936 | if (DBG) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6937 | loge("isDataEnabledForReason: no phone subId=" |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6938 | + subId + " retVal=false"); |
| 6939 | } |
| 6940 | return false; |
| 6941 | } |
| 6942 | } finally { |
| 6943 | Binder.restoreCallingIdentity(identity); |
| 6944 | } |
| 6945 | } |
| 6946 | |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6947 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6948 | public int getCarrierPrivilegeStatus(int subId) { |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6949 | // No permission needed; this only lets the caller inspect their own status. |
| 6950 | return getCarrierPrivilegeStatusForUidWithPermission(subId, Binder.getCallingUid()); |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6951 | } |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 6952 | |
| 6953 | @Override |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6954 | public int getCarrierPrivilegeStatusForUid(int subId, int uid) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6955 | enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid"); |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6956 | return getCarrierPrivilegeStatusForUidWithPermission(subId, uid); |
| 6957 | } |
| 6958 | |
| 6959 | private int getCarrierPrivilegeStatusForUidWithPermission(int subId, int uid) { |
| 6960 | Phone phone = getPhone(subId); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6961 | if (phone == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 6962 | loge("getCarrierPrivilegeStatusForUid: Invalid subId"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6963 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 6964 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6965 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 6966 | if (cpt == null) { |
| 6967 | loge("getCarrierPrivilegeStatusForUid: No CarrierPrivilegesTracker"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6968 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6969 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6970 | return cpt.getCarrierPrivilegeStatusForUid(uid); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6971 | } |
| 6972 | |
| 6973 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6974 | public int checkCarrierPrivilegesForPackage(int subId, String pkgName) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 6975 | enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage"); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6976 | if (TextUtils.isEmpty(pkgName)) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 6977 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6978 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6979 | Phone phone = getPhone(subId); |
| 6980 | if (phone == null) { |
| 6981 | loge("checkCarrierPrivilegesForPackage: Invalid subId"); |
| 6982 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 6983 | } |
| 6984 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 6985 | if (cpt == null) { |
| 6986 | loge("checkCarrierPrivilegesForPackage: No CarrierPrivilegesTracker"); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 6987 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6988 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6989 | return cpt.getCarrierPrivilegeStatusForPackage(pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6990 | } |
| 6991 | |
| 6992 | @Override |
| 6993 | public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) { |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6994 | enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackageAnyPhone"); |
Rambo Wang | e7209ce | 2022-02-23 13:41:02 -0800 | [diff] [blame] | 6995 | return checkCarrierPrivilegesForPackageAnyPhoneWithPermission(pkgName); |
| 6996 | } |
| 6997 | |
| 6998 | private int checkCarrierPrivilegesForPackageAnyPhoneWithPermission(String pkgName) { |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6999 | if (TextUtils.isEmpty(pkgName)) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 7000 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7001 | } |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 7002 | int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7003 | for (int phoneId = 0; phoneId < TelephonyManager.getDefault().getPhoneCount(); phoneId++) { |
| 7004 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 7005 | if (phone == null) { |
| 7006 | continue; |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 7007 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7008 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7009 | if (cpt == null) { |
| 7010 | continue; |
| 7011 | } |
| 7012 | result = cpt.getCarrierPrivilegeStatusForPackage(pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 7013 | if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 7014 | break; |
| 7015 | } |
| 7016 | } |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 7017 | return result; |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 7018 | } |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 7019 | |
| 7020 | @Override |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 7021 | public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 7022 | enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone"); |
Rambo Wang | 8a247eb | 2022-02-08 21:11:18 +0000 | [diff] [blame] | 7023 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 7024 | if (phone == null) { |
| 7025 | return Collections.emptyList(); |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 7026 | } |
Rambo Wang | 8a247eb | 2022-02-08 21:11:18 +0000 | [diff] [blame] | 7027 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7028 | if (cpt == null) { |
| 7029 | return Collections.emptyList(); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 7030 | } |
Rambo Wang | 8a247eb | 2022-02-08 21:11:18 +0000 | [diff] [blame] | 7031 | return cpt.getCarrierPackageNamesForIntent(intent); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 7032 | } |
| 7033 | |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 7034 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7035 | public List<String> getPackagesWithCarrierPrivileges(int phoneId) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 7036 | enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges"); |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7037 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 7038 | if (phone == null) { |
| 7039 | return Collections.emptyList(); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 7040 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7041 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7042 | if (cpt == null) { |
| 7043 | return Collections.emptyList(); |
| 7044 | } |
| 7045 | return new ArrayList<>(cpt.getPackagesWithCarrierPrivileges()); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 7046 | } |
| 7047 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7048 | @Override |
| 7049 | public List<String> getPackagesWithCarrierPrivilegesForAllPhones() { |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 7050 | enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones"); |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7051 | Set<String> privilegedPackages = new ArraySet<>(); |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 7052 | final long identity = Binder.clearCallingIdentity(); |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 7053 | try { |
| 7054 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 7055 | privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i)); |
| 7056 | } |
| 7057 | } finally { |
| 7058 | Binder.restoreCallingIdentity(identity); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7059 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7060 | return new ArrayList<>(privilegedPackages); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7061 | } |
| 7062 | |
Rambo Wang | 6812ffb | 2022-03-15 16:54:17 -0700 | [diff] [blame] | 7063 | @Override |
| 7064 | public @Nullable String getCarrierServicePackageNameForLogicalSlot(int logicalSlotIndex) { |
| 7065 | enforceReadPrivilegedPermission("getCarrierServicePackageNameForLogicalSlot"); |
| 7066 | |
| 7067 | final Phone phone = PhoneFactory.getPhone(logicalSlotIndex); |
| 7068 | if (phone == null) { |
| 7069 | return null; |
| 7070 | } |
| 7071 | final CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7072 | if (cpt == null) { |
| 7073 | return null; |
| 7074 | } |
| 7075 | return cpt.getCarrierServicePackageName(); |
| 7076 | } |
| 7077 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 7078 | private String getIccId(int subId) { |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 7079 | final Phone phone = getPhone(subId); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 7080 | UiccPort port = phone == null ? null : phone.getUiccPort(); |
| 7081 | if (port == null) { |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7082 | return null; |
| 7083 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 7084 | String iccId = port.getIccId(); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7085 | if (TextUtils.isEmpty(iccId)) { |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7086 | return null; |
| 7087 | } |
| 7088 | return iccId; |
| 7089 | } |
| 7090 | |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 7091 | @Override |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 7092 | public void setCallComposerStatus(int subId, int status) { |
| 7093 | enforceModifyPermission(); |
| 7094 | |
| 7095 | final long identity = Binder.clearCallingIdentity(); |
| 7096 | try { |
| 7097 | Phone phone = getPhone(subId); |
| 7098 | if (phone != null) { |
| 7099 | Phone defaultPhone = phone.getImsPhone(); |
| 7100 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 7101 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 7102 | imsPhone.setCallComposerStatus(status); |
Shuo Qian | 284ae75 | 2020-12-22 19:10:14 -0800 | [diff] [blame] | 7103 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| 7104 | .updateImsServiceConfig(); |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 7105 | } |
| 7106 | } |
Shuo Qian | 284ae75 | 2020-12-22 19:10:14 -0800 | [diff] [blame] | 7107 | } catch (ImsException e) { |
| 7108 | throw new ServiceSpecificException(e.getCode()); |
| 7109 | } finally { |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 7110 | Binder.restoreCallingIdentity(identity); |
| 7111 | } |
| 7112 | } |
| 7113 | |
| 7114 | @Override |
| 7115 | public int getCallComposerStatus(int subId) { |
| 7116 | enforceReadPrivilegedPermission("getCallComposerStatus"); |
| 7117 | |
| 7118 | final long identity = Binder.clearCallingIdentity(); |
| 7119 | try { |
| 7120 | Phone phone = getPhone(subId); |
| 7121 | if (phone != null) { |
| 7122 | Phone defaultPhone = phone.getImsPhone(); |
| 7123 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 7124 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 7125 | return imsPhone.getCallComposerStatus(); |
| 7126 | } |
| 7127 | } |
| 7128 | } finally { |
| 7129 | Binder.restoreCallingIdentity(identity); |
| 7130 | } |
| 7131 | return TelephonyManager.CALL_COMPOSER_STATUS_OFF; |
| 7132 | } |
| 7133 | |
| 7134 | @Override |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7135 | public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag, |
| 7136 | String number) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 7137 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7138 | subId, "setLine1NumberForDisplayForSubscriber"); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7139 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7140 | final long identity = Binder.clearCallingIdentity(); |
| 7141 | try { |
| 7142 | final String iccId = getIccId(subId); |
| 7143 | final Phone phone = getPhone(subId); |
| 7144 | if (phone == null) { |
| 7145 | return false; |
| 7146 | } |
| 7147 | final String subscriberId = phone.getSubscriberId(); |
| 7148 | |
| 7149 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 7150 | Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId=" |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7151 | + subscriberId + " to " + number); |
| 7152 | } |
| 7153 | |
| 7154 | if (TextUtils.isEmpty(iccId)) { |
| 7155 | return false; |
| 7156 | } |
| 7157 | |
| 7158 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 7159 | |
| 7160 | final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 7161 | if (alphaTag == null) { |
| 7162 | editor.remove(alphaTagPrefKey); |
| 7163 | } else { |
| 7164 | editor.putString(alphaTagPrefKey, alphaTag); |
| 7165 | } |
| 7166 | |
| 7167 | // Record both the line number and IMSI for this ICCID, since we need to |
| 7168 | // track all merged IMSIs based on line number |
| 7169 | final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 7170 | final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 7171 | if (number == null) { |
| 7172 | editor.remove(numberPrefKey); |
| 7173 | editor.remove(subscriberPrefKey); |
| 7174 | } else { |
| 7175 | editor.putString(numberPrefKey, number); |
| 7176 | editor.putString(subscriberPrefKey, subscriberId); |
| 7177 | } |
| 7178 | |
| 7179 | editor.commit(); |
| 7180 | return true; |
| 7181 | } finally { |
| 7182 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 7183 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7184 | } |
| 7185 | |
| 7186 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7187 | public String getLine1NumberForDisplay(int subId, String callingPackage, |
| 7188 | String callingFeatureId) { |
Makoto Onuki | fee6934 | 2015-06-29 14:44:50 -0700 | [diff] [blame] | 7189 | // This is open to apps with WRITE_SMS. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7190 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7191 | mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) { |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 7192 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission"); |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 7193 | return null; |
| 7194 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7195 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7196 | final long identity = Binder.clearCallingIdentity(); |
| 7197 | try { |
| 7198 | String iccId = getIccId(subId); |
| 7199 | if (iccId != null) { |
| 7200 | String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 7201 | if (DBG_MERGE) { |
| 7202 | log("getLine1NumberForDisplay returning " |
| 7203 | + mTelephonySharedPreferences.getString(numberPrefKey, null)); |
| 7204 | } |
| 7205 | return mTelephonySharedPreferences.getString(numberPrefKey, null); |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 7206 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7207 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null"); |
| 7208 | return null; |
| 7209 | } finally { |
| 7210 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7211 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7212 | } |
| 7213 | |
| 7214 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7215 | public String getLine1AlphaTagForDisplay(int subId, String callingPackage, |
| 7216 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7217 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7218 | mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 7219 | return null; |
| 7220 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7221 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7222 | final long identity = Binder.clearCallingIdentity(); |
| 7223 | try { |
| 7224 | String iccId = getIccId(subId); |
| 7225 | if (iccId != null) { |
| 7226 | String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 7227 | return mTelephonySharedPreferences.getString(alphaTagPrefKey, null); |
| 7228 | } |
| 7229 | return null; |
| 7230 | } finally { |
| 7231 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7232 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7233 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 7234 | |
| 7235 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7236 | public String[] getMergedSubscriberIds(int subId, String callingPackage, |
| 7237 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7238 | // This API isn't public, so no need to provide a valid subscription ID - we're not worried |
| 7239 | // about carrier-privileged callers not having access. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7240 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7241 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7242 | callingFeatureId, "getMergedSubscriberIds")) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7243 | return null; |
| 7244 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7245 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 7246 | // Clear calling identity, when calling TelephonyManager, because callerUid must be |
| 7247 | // the process, where TelephonyManager was instantiated. |
| 7248 | // Otherwise AppOps check will fail. |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7249 | final long identity = Binder.clearCallingIdentity(); |
| 7250 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7251 | final Context context = mApp; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7252 | final TelephonyManager tele = TelephonyManager.from(context); |
| 7253 | final SubscriptionManager sub = SubscriptionManager.from(context); |
| 7254 | |
| 7255 | // Figure out what subscribers are currently active |
| 7256 | final ArraySet<String> activeSubscriberIds = new ArraySet<>(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7257 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 7258 | // Only consider subs which match the current subId |
| 7259 | // This logic can be simplified. See b/131189269 for progress. |
| 7260 | if (isActiveSubscription(subId)) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7261 | activeSubscriberIds.add(tele.getSubscriberId(subId)); |
| 7262 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7263 | |
| 7264 | // First pass, find a number override for an active subscriber |
| 7265 | String mergeNumber = null; |
| 7266 | final Map<String, ?> prefs = mTelephonySharedPreferences.getAll(); |
| 7267 | for (String key : prefs.keySet()) { |
| 7268 | if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) { |
| 7269 | final String subscriberId = (String) prefs.get(key); |
| 7270 | if (activeSubscriberIds.contains(subscriberId)) { |
| 7271 | final String iccId = key.substring( |
| 7272 | PREF_CARRIERS_SUBSCRIBER_PREFIX.length()); |
| 7273 | final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 7274 | mergeNumber = (String) prefs.get(numberKey); |
| 7275 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 7276 | Rlog.d(LOG_TAG, "Found line number " + mergeNumber |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7277 | + " for active subscriber " + subscriberId); |
| 7278 | } |
| 7279 | if (!TextUtils.isEmpty(mergeNumber)) { |
| 7280 | break; |
| 7281 | } |
| 7282 | } |
| 7283 | } |
| 7284 | } |
| 7285 | |
| 7286 | // Shortcut when no active merged subscribers |
| 7287 | if (TextUtils.isEmpty(mergeNumber)) { |
| 7288 | return null; |
| 7289 | } |
| 7290 | |
| 7291 | // Second pass, find all subscribers under that line override |
| 7292 | final ArraySet<String> result = new ArraySet<>(); |
| 7293 | for (String key : prefs.keySet()) { |
| 7294 | if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) { |
| 7295 | final String number = (String) prefs.get(key); |
| 7296 | if (mergeNumber.equals(number)) { |
| 7297 | final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length()); |
| 7298 | final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 7299 | final String subscriberId = (String) prefs.get(subscriberKey); |
| 7300 | if (!TextUtils.isEmpty(subscriberId)) { |
| 7301 | result.add(subscriberId); |
| 7302 | } |
| 7303 | } |
| 7304 | } |
| 7305 | } |
| 7306 | |
| 7307 | final String[] resultArray = result.toArray(new String[result.size()]); |
| 7308 | Arrays.sort(resultArray); |
| 7309 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 7310 | Rlog.d(LOG_TAG, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7311 | "Found subscribers " + Arrays.toString(resultArray) + " after merge"); |
| 7312 | } |
| 7313 | return resultArray; |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7314 | } finally { |
| 7315 | Binder.restoreCallingIdentity(identity); |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7316 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7317 | } |
| 7318 | |
| 7319 | @Override |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 7320 | public String[] getMergedImsisFromGroup(int subId, String callingPackage) { |
| 7321 | enforceReadPrivilegedPermission("getMergedImsisFromGroup"); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7322 | |
| 7323 | final long identity = Binder.clearCallingIdentity(); |
| 7324 | try { |
| 7325 | final TelephonyManager telephonyManager = mApp.getSystemService( |
| 7326 | TelephonyManager.class); |
| 7327 | String subscriberId = telephonyManager.getSubscriberId(subId); |
| 7328 | if (subscriberId == null) { |
| 7329 | if (DBG) { |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 7330 | log("getMergedImsisFromGroup can't find subscriberId for subId " |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7331 | + subId); |
| 7332 | } |
| 7333 | return null; |
| 7334 | } |
| 7335 | |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 7336 | ParcelUuid groupUuid; |
| 7337 | if (PhoneFactory.isSubscriptionManagerServiceEnabled()) { |
| 7338 | final SubscriptionInfo info = SubscriptionManagerService.getInstance() |
| 7339 | .getSubscriptionInfo(subId); |
| 7340 | groupUuid = info.getGroupUuid(); |
| 7341 | } else { |
| 7342 | final SubscriptionInfo info = mSubscriptionController |
| 7343 | .getSubscriptionInfo(subId); |
| 7344 | groupUuid = info.getGroupUuid(); |
| 7345 | } |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7346 | // If it doesn't belong to any group, return just subscriberId of itself. |
| 7347 | if (groupUuid == null) { |
| 7348 | return new String[]{subscriberId}; |
| 7349 | } |
| 7350 | |
| 7351 | // Get all subscriberIds from the group. |
| 7352 | final List<String> mergedSubscriberIds = new ArrayList<>(); |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 7353 | List<SubscriptionInfo> groupInfos; |
| 7354 | if (PhoneFactory.isSubscriptionManagerServiceEnabled()) { |
| 7355 | groupInfos = SubscriptionManagerService.getInstance() |
| 7356 | .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(), |
| 7357 | mApp.getAttributionTag()); |
| 7358 | } else { |
| 7359 | groupInfos = mSubscriptionController |
| 7360 | .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(), |
| 7361 | mApp.getAttributionTag()); |
| 7362 | } |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7363 | for (SubscriptionInfo subInfo : groupInfos) { |
| 7364 | subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId()); |
| 7365 | if (subscriberId != null) { |
| 7366 | mergedSubscriberIds.add(subscriberId); |
| 7367 | } |
| 7368 | } |
| 7369 | |
| 7370 | return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]); |
| 7371 | } finally { |
| 7372 | Binder.restoreCallingIdentity(identity); |
| 7373 | |
| 7374 | } |
| 7375 | } |
| 7376 | |
| 7377 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7378 | public boolean setOperatorBrandOverride(int subId, String brand) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 7379 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7380 | subId, "setOperatorBrandOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7381 | |
| 7382 | final long identity = Binder.clearCallingIdentity(); |
| 7383 | try { |
| 7384 | final Phone phone = getPhone(subId); |
| 7385 | return phone == null ? false : phone.setOperatorBrandOverride(brand); |
| 7386 | } finally { |
| 7387 | Binder.restoreCallingIdentity(identity); |
| 7388 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 7389 | } |
Steven Liu | 4bf01bc | 2014-07-17 11:05:29 -0500 | [diff] [blame] | 7390 | |
| 7391 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7392 | public boolean setRoamingOverride(int subId, List<String> gsmRoamingList, |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 7393 | List<String> gsmNonRoamingList, List<String> cdmaRoamingList, |
| 7394 | List<String> cdmaNonRoamingList) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 7395 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 7396 | mApp, subId, "setRoamingOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7397 | |
| 7398 | final long identity = Binder.clearCallingIdentity(); |
| 7399 | try { |
| 7400 | final Phone phone = getPhone(subId); |
| 7401 | if (phone == null) { |
| 7402 | return false; |
| 7403 | } |
| 7404 | return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList, |
| 7405 | cdmaNonRoamingList); |
| 7406 | } finally { |
| 7407 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7408 | } |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 7409 | } |
| 7410 | |
| 7411 | @Override |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 7412 | @Deprecated |
| 7413 | public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) { |
| 7414 | enforceModifyPermission(); |
| 7415 | |
| 7416 | int returnValue = 0; |
| 7417 | try { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7418 | AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 7419 | if(result.exception == null) { |
| 7420 | if (result.result != null) { |
| 7421 | byte[] responseData = (byte[])(result.result); |
| 7422 | if(responseData.length > oemResp.length) { |
| 7423 | Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " + |
| 7424 | responseData.length + "bytes. Buffer Size is " + |
| 7425 | oemResp.length + "bytes."); |
| 7426 | } |
| 7427 | System.arraycopy(responseData, 0, oemResp, 0, responseData.length); |
| 7428 | returnValue = responseData.length; |
| 7429 | } |
| 7430 | } else { |
| 7431 | CommandException ex = (CommandException) result.exception; |
| 7432 | returnValue = ex.getCommandError().ordinal(); |
| 7433 | if(returnValue > 0) returnValue *= -1; |
| 7434 | } |
| 7435 | } catch (RuntimeException e) { |
| 7436 | Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception"); |
| 7437 | returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal()); |
| 7438 | if(returnValue > 0) returnValue *= -1; |
| 7439 | } |
| 7440 | |
| 7441 | return returnValue; |
| 7442 | } |
| 7443 | |
| 7444 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 7445 | public int getRadioAccessFamily(int phoneId, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7446 | Phone phone = PhoneFactory.getPhone(phoneId); |
Shuo Qian | dee5340 | 2020-05-29 14:08:15 -0700 | [diff] [blame] | 7447 | try { |
| 7448 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 7449 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Shuo Qian | dee5340 | 2020-05-29 14:08:15 -0700 | [diff] [blame] | 7450 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 7451 | } catch (SecurityException e) { |
| 7452 | EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission"); |
| 7453 | throw e; |
| 7454 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7455 | int raf = RadioAccessFamily.RAF_UNKNOWN; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7456 | if (phone == null) { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7457 | return raf; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7458 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7459 | final long identity = Binder.clearCallingIdentity(); |
| 7460 | try { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7461 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 7462 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7463 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 7464 | raf = ProxyController.getInstance().getRadioAccessFamily(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7465 | } finally { |
| 7466 | Binder.restoreCallingIdentity(identity); |
| 7467 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7468 | return raf; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 7469 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7470 | |
| 7471 | @Override |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7472 | public void uploadCallComposerPicture(int subscriptionId, String callingPackage, |
Hall Liu | e31bac6 | 2020-12-23 19:16:10 -0800 | [diff] [blame] | 7473 | String contentType, ParcelFileDescriptor fd, ResultReceiver callback) { |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7474 | try { |
| 7475 | if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0), |
| 7476 | Binder.getCallingUid())) { |
Tyler Gunn | b87925a | 2021-06-10 14:54:27 -0700 | [diff] [blame] | 7477 | throw new SecurityException("Invalid package:" + callingPackage); |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7478 | } |
| 7479 | } catch (PackageManager.NameNotFoundException e) { |
Tyler Gunn | b87925a | 2021-06-10 14:54:27 -0700 | [diff] [blame] | 7480 | throw new SecurityException("Invalid package:" + callingPackage); |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7481 | } |
| 7482 | RoleManager rm = mApp.getSystemService(RoleManager.class); |
| 7483 | List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER); |
| 7484 | if (!dialerRoleHolders.contains(callingPackage)) { |
| 7485 | throw new SecurityException("App must be the dialer role holder to" |
| 7486 | + " upload a call composer pic"); |
| 7487 | } |
| 7488 | |
| 7489 | Executors.newSingleThreadExecutor().execute(() -> { |
| 7490 | ByteArrayOutputStream output = new ByteArrayOutputStream( |
| 7491 | (int) TelephonyManager.getMaximumCallComposerPictureSize()); |
| 7492 | InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd); |
| 7493 | boolean readUntilEnd = false; |
| 7494 | int totalBytesRead = 0; |
| 7495 | byte[] buffer = new byte[16 * 1024]; |
| 7496 | while (true) { |
| 7497 | int numRead; |
| 7498 | try { |
| 7499 | numRead = input.read(buffer); |
| 7500 | } catch (IOException e) { |
| 7501 | try { |
| 7502 | fd.checkError(); |
| 7503 | callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED, |
| 7504 | null); |
| 7505 | } catch (IOException e1) { |
| 7506 | // This means that the other side closed explicitly with an error. If this |
| 7507 | // happens, log and ignore. |
| 7508 | loge("Remote end of call composer picture pipe closed: " + e1); |
| 7509 | } |
| 7510 | break; |
| 7511 | } |
| 7512 | if (numRead == -1) { |
| 7513 | readUntilEnd = true; |
| 7514 | break; |
| 7515 | } |
| 7516 | totalBytesRead += numRead; |
| 7517 | if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) { |
| 7518 | loge("Too many bytes read for call composer picture: " + totalBytesRead); |
| 7519 | try { |
| 7520 | input.close(); |
| 7521 | } catch (IOException e) { |
| 7522 | // ignore |
| 7523 | } |
| 7524 | break; |
| 7525 | } |
| 7526 | output.write(buffer, 0, numRead); |
| 7527 | } |
| 7528 | // Generally, the remote end will close the file descriptors. The only case where we |
| 7529 | // close is above, where the picture size is too big. |
| 7530 | |
| 7531 | try { |
| 7532 | fd.checkError(); |
| 7533 | } catch (IOException e) { |
| 7534 | loge("Remote end for call composer closed with an error: " + e); |
| 7535 | return; |
| 7536 | } |
| 7537 | |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 7538 | if (!readUntilEnd) { |
| 7539 | loge("Did not finish reading entire image; aborting"); |
| 7540 | return; |
| 7541 | } |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7542 | |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 7543 | ImageData imageData = new ImageData(output.toByteArray(), contentType, null); |
| 7544 | CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer( |
| 7545 | new CallComposerPictureTransfer.Factory() {}, |
| 7546 | imageData, |
| 7547 | (result) -> { |
| 7548 | if (result.first != null) { |
| 7549 | ParcelUuid parcelUuid = new ParcelUuid(result.first); |
| 7550 | Bundle outputResult = new Bundle(); |
| 7551 | outputResult.putParcelable( |
| 7552 | TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid); |
| 7553 | callback.send(TelephonyManager.CallComposerException.SUCCESS, |
| 7554 | outputResult); |
| 7555 | } else { |
| 7556 | callback.send(result.second, null); |
| 7557 | } |
| 7558 | } |
| 7559 | ); |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7560 | }); |
| 7561 | } |
| 7562 | |
| 7563 | @Override |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7564 | public void enableVideoCalling(boolean enable) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7565 | final Phone defaultPhone = getDefaultPhone(); |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7566 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7567 | |
| 7568 | final long identity = Binder.clearCallingIdentity(); |
| 7569 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7570 | ImsManager.getInstance(defaultPhone.getContext(), |
| 7571 | defaultPhone.getPhoneId()).setVtSetting(enable); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7572 | } finally { |
| 7573 | Binder.restoreCallingIdentity(identity); |
| 7574 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7575 | } |
| 7576 | |
| 7577 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7578 | public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7579 | final Phone defaultPhone = getDefaultPhone(); |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7580 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 7581 | callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 7582 | return false; |
| 7583 | } |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 7584 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7585 | final long identity = Binder.clearCallingIdentity(); |
| 7586 | try { |
| 7587 | // Check the user preference and the system-level IMS setting. Even if the user has |
| 7588 | // enabled video calling, if IMS is disabled we aren't able to support video calling. |
| 7589 | // In the long run, we may instead need to check if there exists a connection service |
| 7590 | // which can support video calling. |
| 7591 | ImsManager imsManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7592 | ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7593 | return imsManager.isVtEnabledByPlatform() |
| 7594 | && imsManager.isEnhanced4gLteModeSettingEnabledByUser() |
| 7595 | && imsManager.isVtEnabledByUser(); |
| 7596 | } finally { |
| 7597 | Binder.restoreCallingIdentity(identity); |
| 7598 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7599 | } |
Libin.Tang@motorola.com | afe8264 | 2014-12-18 13:27:53 -0600 | [diff] [blame] | 7600 | |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7601 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7602 | public boolean canChangeDtmfToneLength(int subId, String callingPackage, |
| 7603 | String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7604 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7605 | mApp, subId, callingPackage, callingFeatureId, |
| 7606 | "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7607 | return false; |
| 7608 | } |
| 7609 | |
| 7610 | final long identity = Binder.clearCallingIdentity(); |
| 7611 | try { |
| 7612 | CarrierConfigManager configManager = |
| 7613 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7614 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7615 | .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL); |
| 7616 | } finally { |
| 7617 | Binder.restoreCallingIdentity(identity); |
| 7618 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7619 | } |
| 7620 | |
| 7621 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7622 | public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7623 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7624 | mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7625 | return false; |
| 7626 | } |
| 7627 | |
| 7628 | final long identity = Binder.clearCallingIdentity(); |
| 7629 | try { |
| 7630 | CarrierConfigManager configManager = |
| 7631 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7632 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7633 | .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL); |
| 7634 | } finally { |
| 7635 | Binder.restoreCallingIdentity(identity); |
| 7636 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7637 | } |
| 7638 | |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7639 | @Override |
| 7640 | public boolean isTtyModeSupported() { |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 7641 | TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class); |
Wooki Wu | 1f82f7a | 2016-02-15 15:59:58 +0800 | [diff] [blame] | 7642 | return telecomManager.isTtySupported(); |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7643 | } |
| 7644 | |
| 7645 | @Override |
| 7646 | public boolean isHearingAidCompatibilitySupported() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7647 | final long identity = Binder.clearCallingIdentity(); |
| 7648 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7649 | return mApp.getResources().getBoolean(R.bool.hac_enabled); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7650 | } finally { |
| 7651 | Binder.restoreCallingIdentity(identity); |
| 7652 | } |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7653 | } |
| 7654 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 7655 | /** |
| 7656 | * Determines whether the device currently supports RTT (Real-time text). Based both on carrier |
| 7657 | * support for the feature and device firmware support. |
| 7658 | * |
| 7659 | * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise. |
| 7660 | */ |
| 7661 | @Override |
| 7662 | public boolean isRttSupported(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7663 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7664 | final Phone phone = getPhone(subscriptionId); |
| 7665 | if (phone == null) { |
| 7666 | loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId); |
| 7667 | return false; |
| 7668 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7669 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7670 | boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7671 | CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL); |
| 7672 | boolean isDeviceSupported = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7673 | phone.getContext().getResources().getBoolean(R.bool.config_support_rtt); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7674 | return isCarrierSupported && isDeviceSupported; |
| 7675 | } finally { |
| 7676 | Binder.restoreCallingIdentity(identity); |
| 7677 | } |
Hall Liu | 9818758 | 2018-01-22 19:15:32 -0800 | [diff] [blame] | 7678 | } |
| 7679 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 7680 | /** |
Hall Liu | f2daa02 | 2019-07-23 18:39:00 -0700 | [diff] [blame] | 7681 | * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set |
| 7682 | * RTT setting, will return true if the device and carrier both support RTT. |
| 7683 | * 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] | 7684 | */ |
| 7685 | public boolean isRttEnabled(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7686 | final long identity = Binder.clearCallingIdentity(); |
| 7687 | try { |
Hall Liu | 5bab75c | 2019-12-11 23:58:20 +0000 | [diff] [blame] | 7688 | boolean isRttSupported = isRttSupported(subscriptionId); |
| 7689 | boolean isUserRttSettingOn = Settings.Secure.getInt( |
| 7690 | mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0; |
| 7691 | boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId) |
| 7692 | .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL); |
| 7693 | return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7694 | } finally { |
| 7695 | Binder.restoreCallingIdentity(identity); |
| 7696 | } |
Hall Liu | 3ad5f01 | 2018-04-06 16:23:39 -0700 | [diff] [blame] | 7697 | } |
| 7698 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7699 | @Deprecated |
| 7700 | @Override |
| 7701 | public String getDeviceId(String callingPackage) { |
| 7702 | return getDeviceIdWithFeature(callingPackage, null); |
| 7703 | } |
| 7704 | |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7705 | /** |
| 7706 | * Returns the unique device ID of phone, for example, the IMEI for |
| 7707 | * GSM and the MEID for CDMA phones. Return null if device ID is not available. |
| 7708 | * |
| 7709 | * <p>Requires Permission: |
| 7710 | * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} |
| 7711 | */ |
| 7712 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7713 | public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) { |
Shuo Qian | 13d8915 | 2021-05-10 23:58:11 -0700 | [diff] [blame] | 7714 | try { |
| 7715 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 7716 | } catch (SecurityException se) { |
| 7717 | EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid()); |
| 7718 | throw new SecurityException("Package " + callingPackage + " does not belong to " |
| 7719 | + Binder.getCallingUid()); |
| 7720 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7721 | final Phone phone = PhoneFactory.getPhone(0); |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7722 | if (phone == null) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7723 | return null; |
| 7724 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7725 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 7726 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7727 | callingPackage, callingFeatureId, "getDeviceId")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7728 | return null; |
| 7729 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7730 | |
| 7731 | final long identity = Binder.clearCallingIdentity(); |
| 7732 | try { |
| 7733 | return phone.getDeviceId(); |
| 7734 | } finally { |
| 7735 | Binder.restoreCallingIdentity(identity); |
| 7736 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7737 | } |
| 7738 | |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 7739 | /** |
| 7740 | * {@hide} |
| 7741 | * Returns the IMS Registration Status on a particular subid |
| 7742 | * |
| 7743 | * @param subId |
| 7744 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7745 | public boolean isImsRegistered(int subId) { |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 7746 | Phone phone = getPhone(subId); |
| 7747 | if (phone != null) { |
| 7748 | return phone.isImsRegistered(); |
| 7749 | } else { |
| 7750 | return false; |
| 7751 | } |
| 7752 | } |
| 7753 | |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 7754 | @Override |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7755 | public int getSubIdForPhoneAccountHandle( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7756 | PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) { |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7757 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(), |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7758 | callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) { |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7759 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 7760 | } |
| 7761 | final long identity = Binder.clearCallingIdentity(); |
| 7762 | try { |
| 7763 | return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle); |
| 7764 | } finally { |
| 7765 | Binder.restoreCallingIdentity(identity); |
| 7766 | } |
| 7767 | } |
| 7768 | |
| 7769 | @Override |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 7770 | public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) { |
Alireza Forouzan | 4ac4f98 | 2021-03-16 22:18:52 -0700 | [diff] [blame] | 7771 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 7772 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Alireza Forouzan | 4ac4f98 | 2021-03-16 22:18:52 -0700 | [diff] [blame] | 7773 | mApp, |
| 7774 | subscriptionId, |
| 7775 | "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: " + subscriptionId); |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 7776 | final long identity = Binder.clearCallingIdentity(); |
| 7777 | try { |
| 7778 | Phone phone = getPhone(subscriptionId); |
| 7779 | if (phone == null) { |
| 7780 | return null; |
| 7781 | } |
| 7782 | return PhoneUtils.makePstnPhoneAccountHandle(phone); |
| 7783 | } finally { |
| 7784 | Binder.restoreCallingIdentity(identity); |
| 7785 | } |
| 7786 | } |
| 7787 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7788 | /** |
| 7789 | * @return the VoWiFi calling availability. |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 7790 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7791 | public boolean isWifiCallingAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7792 | final long identity = Binder.clearCallingIdentity(); |
| 7793 | try { |
| 7794 | Phone phone = getPhone(subId); |
| 7795 | if (phone != null) { |
| 7796 | return phone.isWifiCallingEnabled(); |
| 7797 | } else { |
| 7798 | return false; |
| 7799 | } |
| 7800 | } finally { |
| 7801 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7802 | } |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 7803 | } |
| 7804 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7805 | /** |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7806 | * @return the VT calling availability. |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 7807 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7808 | public boolean isVideoTelephonyAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7809 | final long identity = Binder.clearCallingIdentity(); |
| 7810 | try { |
| 7811 | Phone phone = getPhone(subId); |
| 7812 | if (phone != null) { |
| 7813 | return phone.isVideoEnabled(); |
| 7814 | } else { |
| 7815 | return false; |
| 7816 | } |
| 7817 | } finally { |
| 7818 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7819 | } |
| 7820 | } |
| 7821 | |
| 7822 | /** |
| 7823 | * @return the IMS registration technology for the MMTEL feature. Valid return values are |
| 7824 | * defined in {@link ImsRegistrationImplBase}. |
| 7825 | */ |
| 7826 | public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7827 | final long identity = Binder.clearCallingIdentity(); |
| 7828 | try { |
| 7829 | Phone phone = getPhone(subId); |
| 7830 | if (phone != null) { |
| 7831 | return phone.getImsRegistrationTech(); |
| 7832 | } else { |
| 7833 | return ImsRegistrationImplBase.REGISTRATION_TECH_NONE; |
| 7834 | } |
| 7835 | } finally { |
| 7836 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7837 | } |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 7838 | } |
| 7839 | |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 7840 | @Override |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 7841 | public void factoryReset(int subId, String callingPackage) { |
paulhu | 5a77360 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 7842 | enforceSettingsPermission(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 7843 | if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) { |
| 7844 | return; |
| 7845 | } |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 7846 | Phone defaultPhone = getDefaultPhone(); |
| 7847 | if (defaultPhone != null) { |
| 7848 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7849 | mApp, getDefaultPhone().getSubId(), "factoryReset"); |
| 7850 | } |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7851 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7852 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7853 | try { |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 7854 | if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction( |
| 7855 | UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7856 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 7857 | getDefaultDataEnabled(), callingPackage); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7858 | setNetworkSelectionModeAutomatic(subId); |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 7859 | Phone phone = getPhone(subId); |
SongFerngWang | fd89b10 | 2021-05-27 22:44:54 +0800 | [diff] [blame] | 7860 | cleanUpAllowedNetworkTypes(phone, subId); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7861 | setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId)); |
Jordan Liu | 857e73a | 2021-03-05 16:24:04 -0800 | [diff] [blame] | 7862 | getPhone(subId).resetCarrierKeysForImsiEncryption(); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7863 | } |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 7864 | // There has been issues when Sms raw table somehow stores orphan |
| 7865 | // fragments. They lead to garbled message when new fragments come |
| 7866 | // in and combined with those stale ones. In case this happens again, |
| 7867 | // user can reset all network settings which will clean up this table. |
| 7868 | cleanUpSmsRawTable(getDefaultPhone().getContext()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 7869 | // Clean up IMS settings as well here. |
| 7870 | int slotId = getSlotIndex(subId); |
| 7871 | if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 7872 | ImsManager.getInstance(mApp, slotId).factoryReset(); |
| 7873 | } |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 7874 | |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 7875 | if (defaultPhone == null) { |
| 7876 | return; |
| 7877 | } |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 7878 | // Erase modem config if erase modem on network setting is enabled. |
| 7879 | String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY, |
| 7880 | RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED); |
| 7881 | if (configValue != null && Boolean.parseBoolean(configValue)) { |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 7882 | sendEraseModemConfig(defaultPhone); |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 7883 | } |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 7884 | |
| 7885 | sendEraseDataInSharedPreferences(defaultPhone); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7886 | } finally { |
| 7887 | Binder.restoreCallingIdentity(identity); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 7888 | } |
| 7889 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7890 | |
SongFerngWang | fd89b10 | 2021-05-27 22:44:54 +0800 | [diff] [blame] | 7891 | @VisibleForTesting |
| 7892 | void cleanUpAllowedNetworkTypes(Phone phone, int subId) { |
| 7893 | if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) { |
| 7894 | return; |
| 7895 | } |
| 7896 | long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType( |
| 7897 | RILConstants.PREFERRED_NETWORK_MODE); |
| 7898 | SubscriptionManager.setSubscriptionProperty(subId, |
| 7899 | SubscriptionManager.ALLOWED_NETWORK_TYPES, |
| 7900 | "user=" + defaultNetworkType); |
| 7901 | phone.loadAllowedNetworksFromSubscriptionDatabase(); |
| 7902 | phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER, |
| 7903 | defaultNetworkType, null); |
| 7904 | } |
| 7905 | |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 7906 | private void cleanUpSmsRawTable(Context context) { |
| 7907 | ContentResolver resolver = context.getContentResolver(); |
| 7908 | Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete"); |
| 7909 | resolver.delete(uri, null, null); |
| 7910 | } |
| 7911 | |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7912 | @Override |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7913 | public String getSimLocaleForSubscriber(int subId) { |
| 7914 | enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId); |
| 7915 | final Phone phone = getPhone(subId); |
| 7916 | if (phone == null) { |
| 7917 | log("getSimLocaleForSubscriber, invalid subId"); |
chen xu | 2bb91e4 | 2019-01-24 14:35:54 -0800 | [diff] [blame] | 7918 | return null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7919 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7920 | final long identity = Binder.clearCallingIdentity(); |
| 7921 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 7922 | SubscriptionInfo info; |
| 7923 | if (PhoneFactory.isSubscriptionManagerServiceEnabled()) { |
| 7924 | info = SubscriptionManagerService.getInstance().getActiveSubscriptionInfo(subId, |
| 7925 | phone.getContext().getOpPackageName(), |
| 7926 | phone.getContext().getAttributionTag()); |
| 7927 | if (info == null) { |
| 7928 | log("getSimLocaleForSubscriber, inactive subId: " + subId); |
| 7929 | return null; |
| 7930 | } |
| 7931 | } else { |
| 7932 | info = mSubscriptionController.getActiveSubscriptionInfo(subId, |
| 7933 | phone.getContext().getOpPackageName(), |
| 7934 | phone.getContext().getAttributionTag()); |
| 7935 | if (info == null) { |
| 7936 | log("getSimLocaleForSubscriber, inactive subId: " + subId); |
| 7937 | return null; |
| 7938 | } |
chen xu | 6291c47 | 2019-02-04 12:55:53 -0800 | [diff] [blame] | 7939 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7940 | // Try and fetch the locale from the carrier properties or from the SIM language |
| 7941 | // preferences (EF-PL and EF-LI)... |
| 7942 | final int mcc = info.getMcc(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7943 | String simLanguage = null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7944 | final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs(); |
| 7945 | if (localeFromDefaultSim != null) { |
| 7946 | if (!localeFromDefaultSim.getCountry().isEmpty()) { |
| 7947 | if (DBG) log("Using locale from subId: " + subId + " locale: " |
| 7948 | + localeFromDefaultSim); |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 7949 | return matchLocaleFromSupportedLocaleList(phone, localeFromDefaultSim); |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7950 | } else { |
| 7951 | simLanguage = localeFromDefaultSim.getLanguage(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7952 | } |
| 7953 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7954 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7955 | // The SIM language preferences only store a language (e.g. fr = French), not an |
| 7956 | // exact locale (e.g. fr_FR = French/France). So, if the locale returned from |
| 7957 | // the SIM and carrier preferences does not include a country we add the country |
| 7958 | // determined from the SIM MCC to provide an exact locale. |
zoey chen | c730df8 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 7959 | final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7960 | if (mccLocale != null) { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7961 | if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale); |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 7962 | return matchLocaleFromSupportedLocaleList(phone, mccLocale); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7963 | } |
| 7964 | |
| 7965 | if (DBG) log("No locale found - returning null"); |
| 7966 | return null; |
| 7967 | } finally { |
| 7968 | Binder.restoreCallingIdentity(identity); |
| 7969 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7970 | } |
| 7971 | |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 7972 | @VisibleForTesting |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 7973 | String matchLocaleFromSupportedLocaleList(Phone phone, @NonNull Locale inputLocale) { |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 7974 | String[] supportedLocale = com.android.internal.app.LocalePicker.getSupportedLocales( |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 7975 | phone.getContext()); |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 7976 | for (String localeTag : supportedLocale) { |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 7977 | if (LocaleList.matchesLanguageAndScript(inputLocale, Locale.forLanguageTag(localeTag)) |
| 7978 | && TextUtils.equals(inputLocale.getCountry(), |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 7979 | Locale.forLanguageTag(localeTag).getCountry())) { |
| 7980 | return localeTag; |
| 7981 | } |
| 7982 | } |
| 7983 | return inputLocale.toLanguageTag(); |
| 7984 | } |
| 7985 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7986 | /** |
| 7987 | * NOTE: this method assumes permission checks are done and caller identity has been cleared. |
| 7988 | */ |
| 7989 | private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 7990 | if (PhoneFactory.isSubscriptionManagerServiceEnabled()) { |
| 7991 | return SubscriptionManagerService.getInstance().getActiveSubscriptionInfoList( |
| 7992 | mApp.getOpPackageName(), mApp.getAttributionTag()); |
| 7993 | } |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7994 | return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(), |
Philip P. Moltmann | 8d34f0c | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7995 | mApp.getAttributionTag()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7996 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7997 | |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 7998 | private ActivityStatsTechSpecificInfo[] mLastModemActivitySpecificInfo = null; |
| 7999 | private ModemActivityInfo mLastModemActivityInfo = null; |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 8000 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 8001 | /** |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 8002 | * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object |
| 8003 | * representing the state of the modem. |
| 8004 | * |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 8005 | * NOTE: The underlying implementation clears the modem state, so there should only ever be one |
| 8006 | * caller to it. Everyone should call this class to get cumulative data. |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 8007 | * @hide |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 8008 | */ |
| 8009 | @Override |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 8010 | public void requestModemActivityInfo(ResultReceiver result) { |
| 8011 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8012 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8013 | |
| 8014 | final long identity = Binder.clearCallingIdentity(); |
| 8015 | try { |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 8016 | sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8017 | } finally { |
| 8018 | Binder.restoreCallingIdentity(identity); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 8019 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 8020 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8021 | |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 8022 | // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be |
| 8023 | // less than total activity duration. |
| 8024 | private boolean isModemActivityInfoValid(ModemActivityInfo info) { |
| 8025 | if (info == null) { |
| 8026 | return false; |
| 8027 | } |
| 8028 | int activityDurationMs = |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 8029 | (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis()); |
| 8030 | int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum(); |
| 8031 | |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 8032 | return (info.isValid() |
| 8033 | && (info.getSleepTimeMillis() <= activityDurationMs) |
| 8034 | && (info.getIdleTimeMillis() <= activityDurationMs) |
Chen Xu | d78231e | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 8035 | && (info.getReceiveTimeMillis() <= activityDurationMs) |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 8036 | && (totalTxTimeMs <= activityDurationMs)); |
| 8037 | } |
| 8038 | |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8039 | private void updateLastModemActivityInfo(ModemActivityInfo info, int rat, int freq) { |
| 8040 | int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()]; |
| 8041 | int[] txTimeMs = info.getTransmitTimeMillis(rat, freq); |
| 8042 | int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat, freq); |
| 8043 | |
| 8044 | for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) { |
| 8045 | mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl]; |
| 8046 | } |
| 8047 | |
| 8048 | mLastModemActivityInfo.setTransmitTimeMillis(rat, freq, mergedTxTimeMs); |
| 8049 | mLastModemActivityInfo.setReceiveTimeMillis( |
| 8050 | rat, |
| 8051 | freq, |
| 8052 | info.getReceiveTimeMillis(rat, freq) |
| 8053 | + mLastModemActivityInfo.getReceiveTimeMillis(rat, freq)); |
| 8054 | } |
| 8055 | |
| 8056 | private void updateLastModemActivityInfo(ModemActivityInfo info, int rat) { |
| 8057 | int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()]; |
| 8058 | int[] txTimeMs = info.getTransmitTimeMillis(rat); |
| 8059 | int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat); |
| 8060 | |
| 8061 | for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) { |
| 8062 | mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl]; |
| 8063 | } |
| 8064 | mLastModemActivityInfo.setTransmitTimeMillis(rat, mergedTxTimeMs); |
| 8065 | mLastModemActivityInfo.setReceiveTimeMillis( |
| 8066 | rat, |
| 8067 | info.getReceiveTimeMillis(rat) + mLastModemActivityInfo.getReceiveTimeMillis(rat)); |
| 8068 | } |
| 8069 | |
| 8070 | /** |
| 8071 | * Merge this ModemActivityInfo with mLastModemActivitySpecificInfo |
| 8072 | * @param info recent ModemActivityInfo |
| 8073 | */ |
| 8074 | private void mergeModemActivityInfo(ModemActivityInfo info) { |
| 8075 | List<ActivityStatsTechSpecificInfo> merged = new ArrayList<>(); |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 8076 | ActivityStatsTechSpecificInfo deltaSpecificInfo; |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8077 | boolean matched; |
| 8078 | for (int i = 0; i < info.getSpecificInfoLength(); i++) { |
| 8079 | matched = false; |
| 8080 | int rat = info.getSpecificInfoRat(i); |
| 8081 | int freq = info.getSpecificInfoFrequencyRange(i); |
| 8082 | //Check each ActivityStatsTechSpecificInfo in this ModemActivityInfo for new rat returns |
| 8083 | //Add a new ActivityStatsTechSpecificInfo if is a new rat, and merge with the original |
| 8084 | //if it already exists |
| 8085 | for (int j = 0; j < mLastModemActivitySpecificInfo.length; j++) { |
| 8086 | if (rat == mLastModemActivityInfo.getSpecificInfoRat(j) && !matched) { |
| 8087 | //Merged based on frequency range (MMWAVE vs SUB6) for 5G |
| 8088 | if (rat == AccessNetworkConstants.AccessNetworkType.NGRAN) { |
| 8089 | if (freq == mLastModemActivityInfo.getSpecificInfoFrequencyRange(j)) { |
| 8090 | updateLastModemActivityInfo(info, rat, freq); |
| 8091 | matched = true; |
| 8092 | } |
| 8093 | } else { |
| 8094 | updateLastModemActivityInfo(info, rat); |
| 8095 | matched = true; |
| 8096 | } |
| 8097 | } |
| 8098 | } |
| 8099 | |
| 8100 | if (!matched) { |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 8101 | deltaSpecificInfo = |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8102 | new ActivityStatsTechSpecificInfo( |
| 8103 | rat, |
| 8104 | freq, |
| 8105 | info.getTransmitTimeMillis(rat, freq), |
| 8106 | (int) info.getReceiveTimeMillis(rat, freq)); |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 8107 | merged.addAll(Arrays.asList(deltaSpecificInfo)); |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8108 | } |
| 8109 | } |
| 8110 | merged.addAll(Arrays.asList(mLastModemActivitySpecificInfo)); |
| 8111 | mLastModemActivitySpecificInfo = |
| 8112 | new ActivityStatsTechSpecificInfo[merged.size()]; |
| 8113 | merged.toArray(mLastModemActivitySpecificInfo); |
| 8114 | |
| 8115 | mLastModemActivityInfo.setTimestamp(info.getTimestampMillis()); |
| 8116 | mLastModemActivityInfo.setSleepTimeMillis( |
| 8117 | info.getSleepTimeMillis() |
| 8118 | + mLastModemActivityInfo.getSleepTimeMillis()); |
| 8119 | mLastModemActivityInfo.setIdleTimeMillis( |
| 8120 | info.getIdleTimeMillis() |
| 8121 | + mLastModemActivityInfo.getIdleTimeMillis()); |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 8122 | |
| 8123 | mLastModemActivityInfo = |
| 8124 | new ModemActivityInfo( |
| 8125 | mLastModemActivityInfo.getTimestampMillis(), |
| 8126 | mLastModemActivityInfo.getSleepTimeMillis(), |
| 8127 | mLastModemActivityInfo.getIdleTimeMillis(), |
| 8128 | mLastModemActivitySpecificInfo); |
| 8129 | } |
| 8130 | |
| 8131 | private ActivityStatsTechSpecificInfo[] deepCopyModemActivitySpecificInfo( |
| 8132 | ActivityStatsTechSpecificInfo[] info) { |
| 8133 | int infoSize = info.length; |
| 8134 | ActivityStatsTechSpecificInfo[] ret = new ActivityStatsTechSpecificInfo[infoSize]; |
| 8135 | for (int i = 0; i < infoSize; i++) { |
| 8136 | ret[i] = new ActivityStatsTechSpecificInfo( |
| 8137 | info[i].getRat(), info[i].getFrequencyRange(), |
| 8138 | info[i].getTransmitTimeMillis(), |
| 8139 | (int) info[i].getReceiveTimeMillis()); |
| 8140 | } |
| 8141 | return ret; |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8142 | } |
| 8143 | |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8144 | /** |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8145 | * Returns the service state information on specified subscription. |
| 8146 | */ |
| 8147 | @Override |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 8148 | public ServiceState getServiceStateForSubscriber(int subId, |
| 8149 | boolean renounceFineLocationAccess, boolean renounceCoarseLocationAccess, |
| 8150 | String callingPackage, String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8151 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8152 | mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) { |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8153 | return null; |
| 8154 | } |
| 8155 | |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 8156 | boolean hasFinePermission = false; |
| 8157 | boolean hasCoarsePermission = false; |
| 8158 | if (!renounceFineLocationAccess) { |
| 8159 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 8160 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 8161 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 8162 | .setCallingPackage(callingPackage) |
| 8163 | .setCallingFeatureId(callingFeatureId) |
| 8164 | .setCallingPid(Binder.getCallingPid()) |
| 8165 | .setCallingUid(Binder.getCallingUid()) |
| 8166 | .setMethod("getServiceStateForSubscriber") |
| 8167 | .setLogAsInfo(true) |
| 8168 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 8169 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 8170 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 8171 | .build()); |
| 8172 | hasFinePermission = |
| 8173 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 8174 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 8175 | |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 8176 | if (!renounceCoarseLocationAccess) { |
| 8177 | LocationAccessPolicy.LocationPermissionResult coarseLocationResult = |
| 8178 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 8179 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 8180 | .setCallingPackage(callingPackage) |
| 8181 | .setCallingFeatureId(callingFeatureId) |
| 8182 | .setCallingPid(Binder.getCallingPid()) |
| 8183 | .setCallingUid(Binder.getCallingUid()) |
| 8184 | .setMethod("getServiceStateForSubscriber") |
| 8185 | .setLogAsInfo(true) |
| 8186 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 8187 | .setMinSdkVersionForFine(Integer.MAX_VALUE) |
| 8188 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 8189 | .build()); |
| 8190 | hasCoarsePermission = |
| 8191 | coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 8192 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 8193 | |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 8194 | final Phone phone = getPhone(subId); |
| 8195 | if (phone == null) { |
| 8196 | return null; |
| 8197 | } |
| 8198 | |
Jordan Liu | 0f2bc44 | 2020-11-18 16:47:37 -0800 | [diff] [blame] | 8199 | final long identity = Binder.clearCallingIdentity(); |
| 8200 | |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 8201 | boolean isCallingPackageDataService = phone.getDataServicePackages() |
| 8202 | .contains(callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8203 | try { |
Jordan Liu | c437b19 | 2020-08-17 10:59:12 -0700 | [diff] [blame] | 8204 | // isActiveSubId requires READ_PHONE_STATE, which we already check for above |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 8205 | if (PhoneFactory.isSubscriptionManagerServiceEnabled()) { |
| 8206 | SubscriptionInfoInternal subInfo = SubscriptionManagerService.getInstance() |
| 8207 | .getSubscriptionInfoInternal(subId); |
| 8208 | if (subInfo == null || !subInfo.isActive()) { |
| 8209 | Rlog.d(LOG_TAG, "getServiceStateForSubscriber returning null for inactive " |
| 8210 | + "subId=" + subId); |
| 8211 | return null; |
| 8212 | } |
| 8213 | } else { |
| 8214 | if (!mSubscriptionController.isActiveSubId(subId, callingPackage, |
| 8215 | callingFeatureId)) { |
| 8216 | Rlog.d(LOG_TAG, "getServiceStateForSubscriber returning null for inactive " |
| 8217 | + "subId=" + subId); |
| 8218 | return null; |
| 8219 | } |
Jordan Liu | c437b19 | 2020-08-17 10:59:12 -0700 | [diff] [blame] | 8220 | } |
| 8221 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 8222 | ServiceState ss = phone.getServiceState(); |
| 8223 | |
| 8224 | // Scrub out the location info in ServiceState depending on what level of access |
| 8225 | // the caller has. |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 8226 | if (hasFinePermission || isCallingPackageDataService) return ss; |
Malcolm Chen | 5052de6 | 2019-12-30 13:56:38 -0800 | [diff] [blame] | 8227 | if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false); |
| 8228 | return ss.createLocationInfoSanitizedCopy(true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8229 | } finally { |
| 8230 | Binder.restoreCallingIdentity(identity); |
| 8231 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8232 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8233 | |
| 8234 | /** |
| 8235 | * Returns the URI for the per-account voicemail ringtone set in Phone settings. |
| 8236 | * |
| 8237 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 8238 | * voicemail ringtone. |
| 8239 | * @return The URI for the ringtone to play when receiving a voicemail from a specific |
| 8240 | * PhoneAccount. |
| 8241 | */ |
| 8242 | @Override |
| 8243 | public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8244 | final long identity = Binder.clearCallingIdentity(); |
| 8245 | try { |
| 8246 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 8247 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8248 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8249 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8250 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8251 | return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext()); |
| 8252 | } finally { |
| 8253 | Binder.restoreCallingIdentity(identity); |
| 8254 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8255 | } |
| 8256 | |
| 8257 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8258 | * Sets the per-account voicemail ringtone. |
| 8259 | * |
| 8260 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 8261 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 8262 | * |
| 8263 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 8264 | * voicemail ringtone. |
| 8265 | * @param uri The URI for the ringtone to play when receiving a voicemail from a specific |
| 8266 | * PhoneAccount. |
| 8267 | */ |
| 8268 | @Override |
| 8269 | public void setVoicemailRingtoneUri(String callingPackage, |
| 8270 | PhoneAccountHandle phoneAccountHandle, Uri uri) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8271 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8272 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 8273 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 8274 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8275 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8276 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 8277 | "setVoicemailRingtoneUri"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8278 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8279 | |
| 8280 | final long identity = Binder.clearCallingIdentity(); |
| 8281 | try { |
| 8282 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 8283 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8284 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8285 | } |
| 8286 | VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri); |
| 8287 | } finally { |
| 8288 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8289 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8290 | } |
| 8291 | |
| 8292 | /** |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8293 | * Returns whether vibration is set for voicemail notification in Phone settings. |
| 8294 | * |
| 8295 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 8296 | * voicemail vibration setting. |
| 8297 | * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise. |
| 8298 | */ |
| 8299 | @Override |
| 8300 | public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8301 | final long identity = Binder.clearCallingIdentity(); |
| 8302 | try { |
| 8303 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 8304 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8305 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8306 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8307 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8308 | return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext()); |
| 8309 | } finally { |
| 8310 | Binder.restoreCallingIdentity(identity); |
| 8311 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8312 | } |
| 8313 | |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8314 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8315 | * Sets the per-account voicemail vibration. |
| 8316 | * |
| 8317 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 8318 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 8319 | * |
| 8320 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 8321 | * voicemail vibration setting. |
| 8322 | * @param enabled Whether to enable or disable vibration for voicemail notifications from a |
| 8323 | * specific PhoneAccount. |
| 8324 | */ |
| 8325 | @Override |
| 8326 | public void setVoicemailVibrationEnabled(String callingPackage, |
| 8327 | PhoneAccountHandle phoneAccountHandle, boolean enabled) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8328 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8329 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 8330 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 8331 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8332 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8333 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 8334 | "setVoicemailVibrationEnabled"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8335 | } |
| 8336 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8337 | final long identity = Binder.clearCallingIdentity(); |
| 8338 | try { |
| 8339 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 8340 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8341 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8342 | } |
| 8343 | VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled); |
| 8344 | } finally { |
| 8345 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8346 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8347 | } |
| 8348 | |
| 8349 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8350 | * Make sure either called from same process as self (phone) or IPC caller has read privilege. |
| 8351 | * |
| 8352 | * @throws SecurityException if the caller does not have the required permission |
| 8353 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8354 | private void enforceReadPrivilegedPermission(String message) { |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8355 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8356 | message); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8357 | } |
| 8358 | |
| 8359 | /** |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 8360 | * Make sure either called from same process as self (phone) or IPC caller has send SMS |
| 8361 | * permission. |
| 8362 | * |
| 8363 | * @throws SecurityException if the caller does not have the required permission |
| 8364 | */ |
| 8365 | private void enforceSendSmsPermission() { |
| 8366 | mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null); |
| 8367 | } |
| 8368 | |
| 8369 | /** |
Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame] | 8370 | * Make sure either called from same process as self (phone) or IPC caller has interact across |
| 8371 | * users permission. |
| 8372 | * |
| 8373 | * @throws SecurityException if the caller does not have the required permission |
| 8374 | */ |
| 8375 | private void enforceInteractAcrossUsersPermission(String message) { |
| 8376 | mApp.enforceCallingOrSelfPermission(permission.INTERACT_ACROSS_USERS, message); |
| 8377 | } |
| 8378 | |
| 8379 | /** |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 8380 | * Make sure called from the package in charge of visual voicemail. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 8381 | * |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 8382 | * @throws SecurityException if the caller is not the visual voicemail package. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 8383 | */ |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 8384 | private void enforceVisualVoicemailPackage(String callingPackage, int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8385 | final long identity = Binder.clearCallingIdentity(); |
| 8386 | try { |
| 8387 | ComponentName componentName = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8388 | RemoteVvmTaskManager.getRemotePackage(mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8389 | if (componentName == null) { |
| 8390 | throw new SecurityException( |
| 8391 | "Caller not current active visual voicemail package[null]"); |
| 8392 | } |
| 8393 | String vvmPackage = componentName.getPackageName(); |
| 8394 | if (!callingPackage.equals(vvmPackage)) { |
Hui Wang | 7f65755 | 2022-08-16 16:58:25 +0000 | [diff] [blame] | 8395 | throw new SecurityException("Caller not current active visual voicemail package"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8396 | } |
| 8397 | } finally { |
| 8398 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 8399 | } |
| 8400 | } |
| 8401 | |
| 8402 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8403 | * Return the application ID for the app type. |
| 8404 | * |
| 8405 | * @param subId the subscription ID that this request applies to. |
| 8406 | * @param appType the uicc app type. |
| 8407 | * @return Application ID for specificied app type, or null if no uicc. |
| 8408 | */ |
| 8409 | @Override |
| 8410 | public String getAidForAppType(int subId, int appType) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8411 | enforceReadPrivilegedPermission("getAidForAppType"); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8412 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8413 | |
| 8414 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8415 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8416 | if (phone == null) { |
| 8417 | return null; |
| 8418 | } |
| 8419 | String aid = null; |
| 8420 | try { |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 8421 | aid = UiccController.getInstance().getUiccPort(phone.getPhoneId()) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8422 | .getApplicationByType(appType).getAid(); |
| 8423 | } catch (Exception e) { |
| 8424 | Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e); |
| 8425 | } |
| 8426 | return aid; |
| 8427 | } finally { |
| 8428 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8429 | } |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8430 | } |
| 8431 | |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8432 | /** |
| 8433 | * Return the Electronic Serial Number. |
| 8434 | * |
| 8435 | * @param subId the subscription ID that this request applies to. |
| 8436 | * @return ESN or null if error. |
| 8437 | */ |
| 8438 | @Override |
| 8439 | public String getEsn(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8440 | enforceReadPrivilegedPermission("getEsn"); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8441 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8442 | |
| 8443 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8444 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8445 | if (phone == null) { |
| 8446 | return null; |
| 8447 | } |
| 8448 | String esn = null; |
| 8449 | try { |
| 8450 | esn = phone.getEsn(); |
| 8451 | } catch (Exception e) { |
| 8452 | Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e); |
| 8453 | } |
| 8454 | return esn; |
| 8455 | } finally { |
| 8456 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8457 | } |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8458 | } |
| 8459 | |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 8460 | /** |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8461 | * Return the Preferred Roaming List Version. |
| 8462 | * |
| 8463 | * @param subId the subscription ID that this request applies to. |
| 8464 | * @return PRLVersion or null if error. |
| 8465 | */ |
| 8466 | @Override |
| 8467 | public String getCdmaPrlVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8468 | enforceReadPrivilegedPermission("getCdmaPrlVersion"); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8469 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8470 | |
| 8471 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8472 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8473 | if (phone == null) { |
| 8474 | return null; |
| 8475 | } |
| 8476 | String cdmaPrlVersion = null; |
| 8477 | try { |
| 8478 | cdmaPrlVersion = phone.getCdmaPrlVersion(); |
| 8479 | } catch (Exception e) { |
| 8480 | Log.e(LOG_TAG, "Not getting PRLVersion", e); |
| 8481 | } |
| 8482 | return cdmaPrlVersion; |
| 8483 | } finally { |
| 8484 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8485 | } |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8486 | } |
| 8487 | |
| 8488 | /** |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 8489 | * Get snapshot of Telephony histograms |
| 8490 | * @return List of Telephony histograms |
| 8491 | * @hide |
| 8492 | */ |
| 8493 | @Override |
| 8494 | public List<TelephonyHistogram> getTelephonyHistograms() { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8495 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8496 | mApp, getDefaultSubscription(), "getTelephonyHistograms"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8497 | |
| 8498 | final long identity = Binder.clearCallingIdentity(); |
| 8499 | try { |
| 8500 | return RIL.getTelephonyRILTimingHistograms(); |
| 8501 | } finally { |
| 8502 | Binder.restoreCallingIdentity(identity); |
| 8503 | } |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 8504 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8505 | |
| 8506 | /** |
| 8507 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8508 | * Set the allowed carrier list and the excluded carrier list, indicating the priority between |
| 8509 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8510 | * Require system privileges. In the future we may add this to carrier APIs. |
| 8511 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8512 | * @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] | 8513 | */ |
| 8514 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8515 | @TelephonyManager.SetCarrierRestrictionResult |
| 8516 | public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) { |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8517 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8518 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8519 | |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8520 | if (carrierRestrictionRules == null) { |
| 8521 | throw new NullPointerException("carrier restriction cannot be null"); |
Meng Wang | 9b7c4e9 | 2017-02-17 11:41:27 -0800 | [diff] [blame] | 8522 | } |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8523 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8524 | final long identity = Binder.clearCallingIdentity(); |
| 8525 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8526 | return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8527 | workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8528 | } finally { |
| 8529 | Binder.restoreCallingIdentity(identity); |
| 8530 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8531 | } |
| 8532 | |
| 8533 | /** |
| 8534 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8535 | * Get the allowed carrier list and the excluded carrier list, including the priority between |
| 8536 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8537 | * Require system privileges. In the future we may add this to carrier APIs. |
| 8538 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8539 | * @return {@link android.telephony.CarrierRestrictionRules} |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8540 | */ |
| 8541 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8542 | public CarrierRestrictionRules getAllowedCarriers() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8543 | enforceReadPrivilegedPermission("getAllowedCarriers"); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8544 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8545 | |
| 8546 | final long identity = Binder.clearCallingIdentity(); |
| 8547 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8548 | Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource); |
| 8549 | if (response instanceof CarrierRestrictionRules) { |
| 8550 | return (CarrierRestrictionRules) response; |
| 8551 | } |
| 8552 | // Response is an Exception of some kind, |
| 8553 | // which is signalled to the user as a NULL retval |
| 8554 | return null; |
| 8555 | } catch (Exception e) { |
| 8556 | Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e); |
| 8557 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8558 | } finally { |
| 8559 | Binder.restoreCallingIdentity(identity); |
| 8560 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8561 | } |
| 8562 | |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 8563 | /** |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 8564 | * Action set from carrier signalling broadcast receivers to enable/disable radio |
| 8565 | * @param subId the subscription ID that this action applies to. |
| 8566 | * @param enabled control enable or disable radio. |
| 8567 | * {@hide} |
| 8568 | */ |
| 8569 | @Override |
| 8570 | public void carrierActionSetRadioEnabled(int subId, boolean enabled) { |
| 8571 | enforceModifyPermission(); |
| 8572 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8573 | |
| 8574 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 8575 | if (phone == null) { |
| 8576 | loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId); |
| 8577 | return; |
| 8578 | } |
| 8579 | try { |
| 8580 | phone.carrierActionSetRadioEnabled(enabled); |
| 8581 | } catch (Exception e) { |
| 8582 | Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8583 | } finally { |
| 8584 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 8585 | } |
| 8586 | } |
| 8587 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 8588 | /** |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 8589 | * Enable or disable Voice over NR (VoNR) |
| 8590 | * @param subId the subscription ID that this action applies to. |
| 8591 | * @param enabled enable or disable VoNR. |
| 8592 | * @return operation result. |
| 8593 | */ |
| 8594 | @Override |
| 8595 | public int setVoNrEnabled(int subId, boolean enabled) { |
| 8596 | enforceModifyPermission(); |
| 8597 | final Phone phone = getPhone(subId); |
| 8598 | |
| 8599 | final long identity = Binder.clearCallingIdentity(); |
| 8600 | if (phone == null) { |
| 8601 | loge("setVoNrEnabled fails with no phone object for subId: " + subId); |
| 8602 | return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE; |
| 8603 | } |
| 8604 | |
| 8605 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8606 | try { |
| 8607 | int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId, |
| 8608 | workSource); |
| 8609 | if (DBG) log("setVoNrEnabled result: " + result); |
Gary Jian | 8dd305f | 2021-10-14 16:31:35 +0800 | [diff] [blame] | 8610 | |
| 8611 | if (result == TelephonyManager.ENABLE_VONR_SUCCESS) { |
| 8612 | if (DBG) { |
| 8613 | log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled); |
| 8614 | } |
| 8615 | SubscriptionManager.setSubscriptionProperty( |
| 8616 | subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED, |
| 8617 | (enabled ? "1" : "0")); |
| 8618 | } |
| 8619 | |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 8620 | return result; |
| 8621 | } finally { |
| 8622 | Binder.restoreCallingIdentity(identity); |
| 8623 | } |
| 8624 | } |
| 8625 | |
| 8626 | /** |
| 8627 | * Is voice over NR enabled |
| 8628 | * @return true if VoNR is enabled else false |
| 8629 | */ |
| 8630 | @Override |
| 8631 | public boolean isVoNrEnabled(int subId) { |
| 8632 | enforceReadPrivilegedPermission("isVoNrEnabled"); |
| 8633 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8634 | final long identity = Binder.clearCallingIdentity(); |
| 8635 | try { |
| 8636 | boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED, |
| 8637 | null, subId, workSource); |
| 8638 | if (DBG) log("isVoNrEnabled: " + isEnabled); |
| 8639 | return isEnabled; |
| 8640 | } finally { |
| 8641 | Binder.restoreCallingIdentity(identity); |
| 8642 | } |
| 8643 | } |
| 8644 | |
| 8645 | /** |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 8646 | * Action set from carrier signalling broadcast receivers to start/stop reporting the default |
| 8647 | * network status based on which carrier apps could apply actions accordingly, |
| 8648 | * enable/disable default url handler for example. |
| 8649 | * |
| 8650 | * @param subId the subscription ID that this action applies to. |
| 8651 | * @param report control start/stop reporting the default network status. |
| 8652 | * {@hide} |
| 8653 | */ |
| 8654 | @Override |
| 8655 | public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) { |
| 8656 | enforceModifyPermission(); |
| 8657 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8658 | |
| 8659 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 8660 | if (phone == null) { |
| 8661 | loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId); |
| 8662 | return; |
| 8663 | } |
| 8664 | try { |
| 8665 | phone.carrierActionReportDefaultNetworkStatus(report); |
| 8666 | } catch (Exception e) { |
| 8667 | Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8668 | } finally { |
| 8669 | Binder.restoreCallingIdentity(identity); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 8670 | } |
| 8671 | } |
| 8672 | |
| 8673 | /** |
fionaxu | d962228 | 2017-07-17 17:51:30 -0700 | [diff] [blame] | 8674 | * Action set from carrier signalling broadcast receivers to reset all carrier actions |
| 8675 | * @param subId the subscription ID that this action applies to. |
| 8676 | * {@hide} |
| 8677 | */ |
| 8678 | @Override |
| 8679 | public void carrierActionResetAll(int subId) { |
| 8680 | enforceModifyPermission(); |
| 8681 | final Phone phone = getPhone(subId); |
| 8682 | if (phone == null) { |
| 8683 | loge("carrierAction: ResetAll fails with invalid sibId: " + subId); |
| 8684 | return; |
| 8685 | } |
| 8686 | try { |
| 8687 | phone.carrierActionResetAll(); |
| 8688 | } catch (Exception e) { |
| 8689 | Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e); |
| 8690 | } |
| 8691 | } |
| 8692 | |
| 8693 | /** |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 8694 | * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a |
| 8695 | * bug report is being generated. |
| 8696 | */ |
| 8697 | @Override |
Ta-wei Yen | 99282e0 | 2016-06-21 18:19:35 -0700 | [diff] [blame] | 8698 | protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8699 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 8700 | != PackageManager.PERMISSION_GRANTED) { |
dcashman | 22b950d | 2016-06-27 11:39:02 -0700 | [diff] [blame] | 8701 | writer.println("Permission Denial: can't dump Phone from pid=" |
| 8702 | + Binder.getCallingPid() |
| 8703 | + ", uid=" + Binder.getCallingUid() |
| 8704 | + "without permission " |
| 8705 | + android.Manifest.permission.DUMP); |
| 8706 | return; |
| 8707 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8708 | DumpsysHandler.dump(mApp, fd, writer, args); |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 8709 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 8710 | |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 8711 | @Override |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 8712 | public int handleShellCommand(@NonNull ParcelFileDescriptor in, |
| 8713 | @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err, |
| 8714 | @NonNull String[] args) { |
| 8715 | return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec( |
| 8716 | this, in.getFileDescriptor(), out.getFileDescriptor(), |
| 8717 | err.getFileDescriptor(), args); |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 8718 | } |
| 8719 | |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 8720 | /** |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8721 | * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason} |
Greg Kaiser | 17f4175 | 2020-05-05 16:47:47 +0000 | [diff] [blame] | 8722 | * @param subId Subscription index |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 8723 | * @param reason The reason the data enable change is taking place. |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8724 | * @param enabled True if enabling the data, otherwise disabling. |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 8725 | * @param callingPackage The package that changed the data enabled state. |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8726 | * @hide |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 8727 | */ |
| 8728 | @Override |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 8729 | public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 8730 | boolean enabled, String callingPackage) { |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8731 | if (reason == TelephonyManager.DATA_ENABLED_REASON_USER |
| 8732 | || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 8733 | try { |
| 8734 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 8735 | mApp, subId, "setDataEnabledForReason"); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8736 | } catch (SecurityException se) { |
| 8737 | enforceModifyPermission(); |
| 8738 | } |
| 8739 | } else { |
| 8740 | enforceModifyPermission(); |
| 8741 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8742 | |
| 8743 | final long identity = Binder.clearCallingIdentity(); |
| 8744 | try { |
| 8745 | Phone phone = getPhone(subId); |
| 8746 | if (phone != null) { |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8747 | if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 8748 | phone.carrierActionSetMeteredApnsEnabled(enabled); |
| 8749 | } else { |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 8750 | phone.getDataSettingsManager().setDataEnabled( |
| 8751 | reason, enabled, callingPackage); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8752 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8753 | } |
| 8754 | } finally { |
| 8755 | Binder.restoreCallingIdentity(identity); |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 8756 | } |
| 8757 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8758 | |
| 8759 | /** |
| 8760 | * Get Client request stats |
| 8761 | * @return List of Client Request Stats |
| 8762 | * @hide |
| 8763 | */ |
| 8764 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8765 | public List<ClientRequestStats> getClientRequestStats(String callingPackage, |
| 8766 | String callingFeatureId, int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8767 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8768 | mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) { |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8769 | return null; |
| 8770 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8771 | Phone phone = getPhone(subId); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8772 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8773 | final long identity = Binder.clearCallingIdentity(); |
| 8774 | try { |
| 8775 | if (phone != null) { |
| 8776 | return phone.getClientRequestStats(); |
| 8777 | } |
| 8778 | |
| 8779 | return null; |
| 8780 | } finally { |
| 8781 | Binder.restoreCallingIdentity(identity); |
| 8782 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8783 | } |
| 8784 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 8785 | private WorkSource getWorkSource(int uid) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8786 | String packageName = mApp.getPackageManager().getNameForUid(uid); |
Hunter Knepshield | d03383b | 2022-03-29 22:47:54 +0000 | [diff] [blame] | 8787 | if (uid == Process.ROOT_UID && packageName == null) { |
| 8788 | // Downstream WorkSource attribution inside the RIL requires both a UID and package name |
| 8789 | // to be set for wakelock tracking, otherwise RIL requests fail with a runtime |
| 8790 | // exception. ROOT_UID seems not to have a valid package name returned by |
| 8791 | // PackageManager, so just fake it here to avoid issues when running telephony shell |
| 8792 | // commands that plumb through the RIL as root, like so: |
| 8793 | // $ adb root |
| 8794 | // $ adb shell cmd phone ... |
| 8795 | packageName = "root"; |
| 8796 | } |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 8797 | return new WorkSource(uid, packageName); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8798 | } |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8799 | |
| 8800 | /** |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 8801 | * Set SIM card power state. |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8802 | * |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8803 | * @param slotIndex SIM slot id. |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 8804 | * @param state State of SIM (power down, power up, pass through) |
| 8805 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 8806 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 8807 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8808 | * |
| 8809 | **/ |
| 8810 | @Override |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 8811 | public void setSimPowerStateForSlot(int slotIndex, int state) { |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8812 | enforceModifyPermission(); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8813 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8814 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8815 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8816 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8817 | final long identity = Binder.clearCallingIdentity(); |
| 8818 | try { |
| 8819 | if (phone != null) { |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 8820 | phone.setSimPowerState(state, null, workSource); |
| 8821 | } |
| 8822 | } finally { |
| 8823 | Binder.restoreCallingIdentity(identity); |
| 8824 | } |
| 8825 | } |
| 8826 | |
| 8827 | /** |
| 8828 | * Set SIM card power state. |
| 8829 | * |
| 8830 | * @param slotIndex SIM slot id. |
| 8831 | * @param state State of SIM (power down, power up, pass through) |
| 8832 | * @param callback callback to trigger after success or failure |
| 8833 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 8834 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 8835 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
| 8836 | * |
| 8837 | **/ |
| 8838 | @Override |
| 8839 | public void setSimPowerStateForSlotWithCallback(int slotIndex, int state, |
| 8840 | IIntegerConsumer callback) { |
| 8841 | enforceModifyPermission(); |
| 8842 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8843 | |
| 8844 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8845 | |
| 8846 | final long identity = Binder.clearCallingIdentity(); |
| 8847 | try { |
| 8848 | if (phone != null) { |
| 8849 | Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback); |
| 8850 | sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8851 | } |
| 8852 | } finally { |
| 8853 | Binder.restoreCallingIdentity(identity); |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8854 | } |
| 8855 | } |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8856 | |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 8857 | private boolean isUssdApiAllowed(int subId) { |
| 8858 | CarrierConfigManager configManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8859 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 8860 | if (configManager == null) { |
| 8861 | return false; |
| 8862 | } |
| 8863 | PersistableBundle pb = configManager.getConfigForSubId(subId); |
| 8864 | if (pb == null) { |
| 8865 | return false; |
| 8866 | } |
| 8867 | return pb.getBoolean( |
| 8868 | CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL); |
| 8869 | } |
| 8870 | |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8871 | /** |
| 8872 | * Check if phone is in emergency callback mode |
| 8873 | * @return true if phone is in emergency callback mode |
| 8874 | * @param subId sub id |
| 8875 | */ |
goneil | 9c5f487 | 2017-12-05 14:07:56 -0800 | [diff] [blame] | 8876 | @Override |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8877 | public boolean getEmergencyCallbackMode(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8878 | enforceReadPrivilegedPermission("getEmergencyCallbackMode"); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8879 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8880 | |
| 8881 | final long identity = Binder.clearCallingIdentity(); |
| 8882 | try { |
| 8883 | if (phone != null) { |
| 8884 | return phone.isInEcm(); |
| 8885 | } else { |
| 8886 | return false; |
| 8887 | } |
| 8888 | } finally { |
| 8889 | Binder.restoreCallingIdentity(identity); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8890 | } |
| 8891 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 8892 | |
| 8893 | /** |
| 8894 | * Get the current signal strength information for the given subscription. |
| 8895 | * Because this information is not updated when the device is in a low power state |
| 8896 | * it should not be relied-upon to be current. |
| 8897 | * @param subId Subscription index |
| 8898 | * @return the most recent cached signal strength info from the modem |
| 8899 | */ |
| 8900 | @Override |
| 8901 | public SignalStrength getSignalStrength(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8902 | final long identity = Binder.clearCallingIdentity(); |
| 8903 | try { |
| 8904 | Phone p = getPhone(subId); |
| 8905 | if (p == null) { |
| 8906 | return null; |
| 8907 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 8908 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8909 | return p.getSignalStrength(); |
| 8910 | } finally { |
| 8911 | Binder.restoreCallingIdentity(identity); |
| 8912 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 8913 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8914 | |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8915 | /** |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8916 | * Get the current modem radio state for the given slot. |
| 8917 | * @param slotIndex slot index. |
| 8918 | * @param callingPackage the name of the package making the call. |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8919 | * @param callingFeatureId The feature in the package. |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8920 | * @return the current radio power state from the modem |
| 8921 | */ |
| 8922 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8923 | public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8924 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8925 | if (phone != null) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8926 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(), |
| 8927 | callingPackage, callingFeatureId, "getRadioPowerState")) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8928 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 8929 | } |
| 8930 | |
| 8931 | final long identity = Binder.clearCallingIdentity(); |
| 8932 | try { |
| 8933 | return phone.getRadioPowerState(); |
| 8934 | } finally { |
| 8935 | Binder.restoreCallingIdentity(identity); |
| 8936 | } |
| 8937 | } |
| 8938 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 8939 | } |
| 8940 | |
| 8941 | /** |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8942 | * Checks if data roaming is enabled on the subscription with id {@code subId}. |
| 8943 | * |
| 8944 | * <p>Requires one of the following permissions: |
| 8945 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}, |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 8946 | * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE}, |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8947 | * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier |
| 8948 | * privileges. |
| 8949 | * |
| 8950 | * @param subId subscription id |
| 8951 | * @return {@code true} if data roaming is enabled on this subscription, otherwise return |
| 8952 | * {@code false}. |
| 8953 | */ |
| 8954 | @Override |
| 8955 | public boolean isDataRoamingEnabled(int subId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 8956 | String functionName = "isDataRoamingEnabled"; |
Shuo Qian | 093013d | 2020-08-13 15:42:55 -0700 | [diff] [blame] | 8957 | try { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 8958 | try { |
| 8959 | mApp.enforceCallingOrSelfPermission( |
| 8960 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 8961 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 8962 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 8963 | mApp.enforceCallingOrSelfPermission( |
| 8964 | permission.READ_BASIC_PHONE_STATE, functionName); |
| 8965 | } |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 8966 | } catch (SecurityException e) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 8967 | TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 8968 | mApp, subId, functionName); |
Shuo Qian | 093013d | 2020-08-13 15:42:55 -0700 | [diff] [blame] | 8969 | } |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 8970 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8971 | boolean isEnabled = false; |
| 8972 | final long identity = Binder.clearCallingIdentity(); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8973 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8974 | Phone phone = getPhone(subId); |
| 8975 | isEnabled = phone != null ? phone.getDataRoamingEnabled() : false; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8976 | } finally { |
| 8977 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8978 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8979 | return isEnabled; |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8980 | } |
| 8981 | |
| 8982 | |
| 8983 | /** |
| 8984 | * Enables/Disables the data roaming on the subscription with id {@code subId}. |
| 8985 | * |
| 8986 | * <p> Requires permission: |
| 8987 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier |
| 8988 | * privileges. |
| 8989 | * |
| 8990 | * @param subId subscription id |
| 8991 | * @param isEnabled {@code true} means enable, {@code false} means disable. |
| 8992 | */ |
| 8993 | @Override |
| 8994 | public void setDataRoamingEnabled(int subId, boolean isEnabled) { |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 8995 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8996 | mApp, subId, "setDataRoamingEnabled"); |
| 8997 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8998 | final long identity = Binder.clearCallingIdentity(); |
| 8999 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9000 | Phone phone = getPhone(subId); |
| 9001 | if (phone != null) { |
| 9002 | phone.setDataRoamingEnabled(isEnabled); |
| 9003 | } |
| 9004 | } finally { |
| 9005 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9006 | } |
| 9007 | } |
| 9008 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9009 | @Override |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 9010 | public boolean isManualNetworkSelectionAllowed(int subId) { |
tom hsu | c91afc7 | 2020-01-06 23:46:07 +0800 | [diff] [blame] | 9011 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9012 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 9013 | mApp, subId, "isManualNetworkSelectionAllowed"); |
| 9014 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 9015 | boolean isAllowed = true; |
| 9016 | final long identity = Binder.clearCallingIdentity(); |
| 9017 | try { |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 9018 | Phone phone = getPhone(subId); |
| 9019 | if (phone != null) { |
| 9020 | isAllowed = phone.isCspPlmnEnabled(); |
| 9021 | } |
| 9022 | } finally { |
| 9023 | Binder.restoreCallingIdentity(identity); |
| 9024 | } |
| 9025 | return isAllowed; |
| 9026 | } |
| 9027 | |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9028 | private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) { |
| 9029 | UiccProfile profile = port.getUiccProfile(); |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 9030 | if (profile == null) { |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9031 | return false; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9032 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 9033 | Phone phone = PhoneFactory.getPhone(profile.getPhoneId()); |
| 9034 | if (phone == null) { |
| 9035 | return false; |
| 9036 | } |
| 9037 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 9038 | return cpt != null && cpt.getCarrierPrivilegeStatusForPackage(callingPackage) |
| 9039 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9040 | } |
| 9041 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 9042 | @Override |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 9043 | public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) { |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9044 | // Verify that the callingPackage belongs to the calling UID |
Jordan Liu | 4cda455 | 2020-03-23 11:55:07 -0700 | [diff] [blame] | 9045 | mApp.getSystemService(AppOpsManager.class) |
| 9046 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 9047 | |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9048 | boolean hasReadPermission = false; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9049 | boolean isIccIdAccessRestricted = false; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 9050 | try { |
| 9051 | enforceReadPrivilegedPermission("getUiccCardsInfo"); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9052 | hasReadPermission = true; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 9053 | } catch (SecurityException e) { |
| 9054 | // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller |
| 9055 | // has carrier privileges on an active UICC |
Rambo Wang | e7209ce | 2022-02-23 13:41:02 -0800 | [diff] [blame] | 9056 | if (checkCarrierPrivilegesForPackageAnyPhoneWithPermission(callingPackage) |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 9057 | != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9058 | throw new SecurityException("Caller does not have permission."); |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 9059 | } |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 9060 | } |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9061 | // checking compatibility, if calling app's target SDK is T and beyond. |
| 9062 | if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO, |
| 9063 | Binder.getCallingUid())) { |
| 9064 | isIccIdAccessRestricted = true; |
| 9065 | } |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 9066 | final long identity = Binder.clearCallingIdentity(); |
| 9067 | try { |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 9068 | UiccController uiccController = UiccController.getInstance(); |
| 9069 | ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos(); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9070 | if (hasReadPermission) { |
| 9071 | return cardInfos; |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 9072 | } |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9073 | |
| 9074 | // Remove private info if the caller doesn't have access |
| 9075 | ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>(); |
| 9076 | for (UiccCardInfo cardInfo : cardInfos) { |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9077 | //setting the value after compatibility check |
| 9078 | cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9079 | // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo |
| 9080 | // is available |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9081 | UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex()); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9082 | if (card == null) { |
| 9083 | // assume no access if the card is unavailable |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9084 | filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo)); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9085 | continue; |
| 9086 | } |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9087 | Collection<UiccPortInfo> portInfos = cardInfo.getPorts(); |
| 9088 | if (portInfos.isEmpty()) { |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9089 | filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo)); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9090 | continue; |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9091 | } |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9092 | List<UiccPortInfo> uiccPortInfos = new ArrayList<>(); |
| 9093 | for (UiccPortInfo portInfo : portInfos) { |
| 9094 | UiccPort port = uiccController.getUiccPortForSlot( |
| 9095 | cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex()); |
| 9096 | if (port == null) { |
| 9097 | // assume no access if port is null |
| 9098 | uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo)); |
| 9099 | continue; |
| 9100 | } |
| 9101 | if (haveCarrierPrivilegeAccess(port, callingPackage)) { |
| 9102 | uiccPortInfos.add(portInfo); |
| 9103 | } else { |
| 9104 | uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo)); |
| 9105 | } |
| 9106 | } |
| 9107 | filteredInfos.add(new UiccCardInfo( |
| 9108 | cardInfo.isEuicc(), |
| 9109 | cardInfo.getCardId(), |
| 9110 | null, |
| 9111 | cardInfo.getPhysicalSlotIndex(), |
| 9112 | cardInfo.isRemovable(), |
| 9113 | cardInfo.isMultipleEnabledProfilesSupported(), |
| 9114 | uiccPortInfos)); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9115 | } |
| 9116 | return filteredInfos; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 9117 | } finally { |
| 9118 | Binder.restoreCallingIdentity(identity); |
| 9119 | } |
| 9120 | } |
| 9121 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9122 | /** |
| 9123 | * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are |
| 9124 | * generally private and require carrier privileges to view. |
| 9125 | * |
| 9126 | * @hide |
| 9127 | */ |
| 9128 | @NonNull |
| 9129 | public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) { |
| 9130 | List<UiccPortInfo> portinfo = new ArrayList<>(); |
| 9131 | for (UiccPortInfo portinfos : cardInfo.getPorts()) { |
| 9132 | portinfo.add(getUiccPortInfoUnPrivileged(portinfos)); |
| 9133 | } |
| 9134 | return new UiccCardInfo( |
| 9135 | cardInfo.isEuicc(), |
| 9136 | cardInfo.getCardId(), |
| 9137 | null, |
| 9138 | cardInfo.getPhysicalSlotIndex(), |
| 9139 | cardInfo.isRemovable(), |
| 9140 | cardInfo.isMultipleEnabledProfilesSupported(), |
| 9141 | portinfo |
| 9142 | ); |
| 9143 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9144 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9145 | /** |
| 9146 | * @hide |
| 9147 | * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}. |
| 9148 | * These values are generally private and require carrier privileges to view. |
| 9149 | */ |
| 9150 | @NonNull |
| 9151 | public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) { |
| 9152 | return new UiccPortInfo( |
| 9153 | UiccPortInfo.ICCID_REDACTED, |
| 9154 | portInfo.getPortIndex(), |
| 9155 | portInfo.getLogicalSlotIndex(), |
| 9156 | portInfo.isActive() |
| 9157 | ); |
| 9158 | } |
| 9159 | @Override |
| 9160 | public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) { |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9161 | // Verify that the callingPackage belongs to the calling UID |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9162 | mApp.getSystemService(AppOpsManager.class) |
| 9163 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 9164 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9165 | boolean isLogicalSlotAccessRestricted = false; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9166 | |
Aman Gupta | f3c90b3 | 2022-03-17 04:54:16 +0000 | [diff] [blame] | 9167 | // This will make sure caller has the READ_PRIVILEGED_PHONE_STATE. Do not remove this as |
| 9168 | // we are reading iccId which is PII data. |
| 9169 | enforceReadPrivilegedPermission("getUiccSlotsInfo"); |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9170 | |
| 9171 | // checking compatibility, if calling app's target SDK is T and beyond. |
| 9172 | if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO, |
| 9173 | Binder.getCallingUid())) { |
| 9174 | isLogicalSlotAccessRestricted = true; |
| 9175 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9176 | final long identity = Binder.clearCallingIdentity(); |
| 9177 | try { |
| 9178 | UiccSlot[] slots = UiccController.getInstance().getUiccSlots(); |
Muralidhar Reddy | d196bbf | 2022-01-17 17:56:30 +0000 | [diff] [blame] | 9179 | if (slots == null || slots.length == 0) { |
| 9180 | Rlog.i(LOG_TAG, "slots is null or empty."); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9181 | return null; |
| 9182 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9183 | UiccSlotInfo[] infos = new UiccSlotInfo[slots.length]; |
| 9184 | for (int i = 0; i < slots.length; i++) { |
| 9185 | UiccSlot slot = slots[i]; |
| 9186 | if (slot == null) { |
| 9187 | continue; |
| 9188 | } |
| 9189 | |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 9190 | String cardId; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9191 | UiccCard card = slot.getUiccCard(); |
| 9192 | if (card != null) { |
| 9193 | cardId = card.getCardId(); |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 9194 | } else { |
Jordan Liu | 01bd00d | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 9195 | cardId = slot.getEid(); |
| 9196 | if (TextUtils.isEmpty(cardId)) { |
Aman Gupta | f3c90b3 | 2022-03-17 04:54:16 +0000 | [diff] [blame] | 9197 | // If cardId is null, use iccId of default port as cardId. |
| 9198 | cardId = slot.getIccId(TelephonyManager.DEFAULT_PORT_INDEX); |
Jordan Liu | 01bd00d | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 9199 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9200 | } |
| 9201 | |
Jordan Liu | 857451f | 2019-05-09 16:35:35 -0700 | [diff] [blame] | 9202 | if (cardId != null) { |
| 9203 | // if cardId is an ICCID, strip off trailing Fs before exposing to user |
| 9204 | // if cardId is an EID, it's all digits so this is fine |
| 9205 | cardId = IccUtils.stripTrailingFs(cardId); |
| 9206 | } |
| 9207 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9208 | int cardState = 0; |
| 9209 | switch (slot.getCardState()) { |
| 9210 | case CARDSTATE_ABSENT: |
| 9211 | cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT; |
| 9212 | break; |
| 9213 | case CARDSTATE_PRESENT: |
| 9214 | cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT; |
| 9215 | break; |
| 9216 | case CARDSTATE_ERROR: |
| 9217 | cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR; |
| 9218 | break; |
| 9219 | case CARDSTATE_RESTRICTED: |
| 9220 | cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED; |
| 9221 | break; |
| 9222 | default: |
| 9223 | break; |
| 9224 | |
| 9225 | } |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9226 | List<UiccPortInfo> portInfos = new ArrayList<>(); |
| 9227 | int[] portIndexes = slot.getPortList(); |
| 9228 | for (int portIdx : portIndexes) { |
| 9229 | String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx, |
Aman Gupta | f3c90b3 | 2022-03-17 04:54:16 +0000 | [diff] [blame] | 9230 | callingPackage, /* hasReadPermission= */ true)); |
Muralidhar Reddy | fbcff0c | 2022-01-19 13:07:57 +0000 | [diff] [blame] | 9231 | portInfos.add(new UiccPortInfo(iccId, portIdx, |
| 9232 | slot.getPhoneIdFromPortIndex(portIdx), slot.isPortActive(portIdx))); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9233 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9234 | infos[i] = new UiccSlotInfo( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9235 | slot.isEuicc(), |
| 9236 | cardId, |
| 9237 | cardState, |
Jordan Liu | a261958 | 2019-02-14 12:56:40 -0800 | [diff] [blame] | 9238 | slot.isExtendedApduSupported(), |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9239 | slot.isRemovable(), portInfos); |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9240 | //setting the value after compatibility check |
| 9241 | infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9242 | } |
| 9243 | return infos; |
| 9244 | } finally { |
| 9245 | Binder.restoreCallingIdentity(identity); |
Holly Jiuyu Sun | 1d957c5 | 2018-04-04 13:52:42 -0700 | [diff] [blame] | 9246 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9247 | } |
| 9248 | |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9249 | /* Returns null if doesn't have read permission or carrier privilege access. */ |
| 9250 | private String getIccId(UiccSlot slot, int portIndex, String callingPackage, |
| 9251 | boolean hasReadPermission) { |
| 9252 | String iccId = slot.getIccId(portIndex); |
| 9253 | if (hasReadPermission) { // if has read permission |
| 9254 | return iccId; |
| 9255 | } else { |
| 9256 | if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) { |
| 9257 | UiccPort port = slot.getUiccCard().getUiccPort(portIndex); |
| 9258 | // if no read permission, checking carrier privilege access |
| 9259 | if (haveCarrierPrivilegeAccess(port, callingPackage)) { |
| 9260 | return iccId; |
| 9261 | } |
| 9262 | } |
| 9263 | } |
| 9264 | // No read permission or carrier privilege access. |
| 9265 | return UiccPortInfo.ICCID_REDACTED; |
| 9266 | } |
| 9267 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9268 | @Override |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9269 | @Deprecated |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9270 | public boolean switchSlots(int[] physicalSlots) { |
| 9271 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9272 | |
| 9273 | final long identity = Binder.clearCallingIdentity(); |
| 9274 | try { |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9275 | List<UiccSlotMapping> slotMappings = new ArrayList<>(); |
| 9276 | for (int i = 0; i < physicalSlots.length; i++) { |
| 9277 | // Deprecated API, hence MEP is not supported. Adding default portIndex 0. |
| 9278 | slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX, |
| 9279 | physicalSlots[i], i)); |
| 9280 | } |
| 9281 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9282 | } finally { |
| 9283 | Binder.restoreCallingIdentity(identity); |
| 9284 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9285 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 9286 | |
| 9287 | @Override |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9288 | @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 9289 | public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) { |
| 9290 | enforceModifyPermission(); |
| 9291 | |
| 9292 | final long identity = Binder.clearCallingIdentity(); |
| 9293 | try { |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9294 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping); |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9295 | } finally { |
| 9296 | Binder.restoreCallingIdentity(identity); |
| 9297 | } |
| 9298 | } |
| 9299 | |
| 9300 | @Override |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 9301 | public int getCardIdForDefaultEuicc(int subId, String callingPackage) { |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 9302 | final long identity = Binder.clearCallingIdentity(); |
| 9303 | try { |
| 9304 | return UiccController.getInstance().getCardIdForDefaultEuicc(); |
| 9305 | } finally { |
| 9306 | Binder.restoreCallingIdentity(identity); |
| 9307 | } |
| 9308 | } |
| 9309 | |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9310 | /** |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 9311 | * A test API to reload the UICC profile. |
| 9312 | * |
| 9313 | * <p>Requires that the calling app has permission |
| 9314 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 9315 | * @hide |
| 9316 | */ |
| 9317 | @Override |
| 9318 | public void refreshUiccProfile(int subId) { |
| 9319 | enforceModifyPermission(); |
| 9320 | |
| 9321 | final long identity = Binder.clearCallingIdentity(); |
| 9322 | try { |
| 9323 | Phone phone = getPhone(subId); |
| 9324 | if (phone == null) { |
| 9325 | return; |
| 9326 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9327 | UiccPort uiccPort = phone.getUiccPort(); |
| 9328 | if (uiccPort == null) { |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 9329 | return; |
| 9330 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9331 | UiccProfile uiccProfile = uiccPort.getUiccProfile(); |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 9332 | if (uiccProfile == null) { |
| 9333 | return; |
| 9334 | } |
| 9335 | uiccProfile.refresh(); |
| 9336 | } finally { |
| 9337 | Binder.restoreCallingIdentity(identity); |
| 9338 | } |
| 9339 | } |
| 9340 | |
| 9341 | /** |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9342 | * Returns false if the mobile data is disabled by default, otherwise return true. |
| 9343 | */ |
| 9344 | private boolean getDefaultDataEnabled() { |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 9345 | return TelephonyProperties.mobile_data().orElse(true); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9346 | } |
| 9347 | |
| 9348 | /** |
| 9349 | * Returns true if the data roaming is enabled by default, i.e the system property |
| 9350 | * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of |
| 9351 | * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true. |
| 9352 | */ |
| 9353 | private boolean getDefaultDataRoamingEnabled(int subId) { |
| 9354 | final CarrierConfigManager configMgr = (CarrierConfigManager) |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9355 | mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Shuo Qian | 1d84a0e | 2020-07-15 12:36:44 -0700 | [diff] [blame] | 9356 | boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9357 | isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean( |
| 9358 | CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL); |
| 9359 | return isDataRoamingEnabled; |
| 9360 | } |
| 9361 | |
| 9362 | /** |
| 9363 | * Returns the default network type for the given {@code subId}, if the default network type is |
| 9364 | * not set, return {@link Phone#PREFERRED_NT_MODE}. |
| 9365 | */ |
| 9366 | private int getDefaultNetworkType(int subId) { |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 9367 | List<Integer> list = TelephonyProperties.default_network(); |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 9368 | int phoneId = SubscriptionManager.getPhoneId(subId); |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 9369 | if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) { |
| 9370 | return list.get(phoneId); |
| 9371 | } |
| 9372 | return Phone.PREFERRED_NT_MODE; |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9373 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9374 | |
| 9375 | @Override |
| 9376 | public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 9377 | gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) { |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9378 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9379 | |
| 9380 | final long identity = Binder.clearCallingIdentity(); |
| 9381 | try { |
| 9382 | final Phone phone = getPhone(subId); |
| 9383 | if (phone == null) { |
| 9384 | loge("setCarrierTestOverride fails with invalid subId: " + subId); |
| 9385 | return; |
| 9386 | } |
Rambo Wang | 9c9ffdd | 2022-01-13 21:51:44 -0800 | [diff] [blame] | 9387 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 9388 | if (cpt != null) { |
| 9389 | cpt.setTestOverrideCarrierPrivilegeRules(carrierPrivilegeRules); |
| 9390 | } |
| 9391 | // 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] | 9392 | phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn, |
| 9393 | carrierPrivilegeRules, apn); |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 9394 | if (carrierPrivilegeRules == null) { |
| 9395 | mCarrierPrivilegeTestOverrideSubIds.remove(subId); |
| 9396 | } else { |
| 9397 | mCarrierPrivilegeTestOverrideSubIds.add(subId); |
| 9398 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9399 | } finally { |
| 9400 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9401 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9402 | } |
| 9403 | |
| 9404 | @Override |
| 9405 | public int getCarrierIdListVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 9406 | enforceReadPrivilegedPermission("getCarrierIdListVersion"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9407 | |
| 9408 | final long identity = Binder.clearCallingIdentity(); |
| 9409 | try { |
| 9410 | final Phone phone = getPhone(subId); |
| 9411 | if (phone == null) { |
| 9412 | loge("getCarrierIdListVersion fails with invalid subId: " + subId); |
| 9413 | return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION; |
| 9414 | } |
| 9415 | return phone.getCarrierIdListVersion(); |
| 9416 | } finally { |
| 9417 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9418 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9419 | } |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 9420 | |
| 9421 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9422 | public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage, |
| 9423 | String callingFeatureId) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 9424 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9425 | mApp, subId, callingPackage, callingFeatureId, |
| 9426 | "getNumberOfModemsWithSimultaneousDataConnections")) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 9427 | return -1; |
| 9428 | } |
| 9429 | |
| 9430 | final long identity = Binder.clearCallingIdentity(); |
| 9431 | try { |
| 9432 | return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections(); |
| 9433 | } finally { |
| 9434 | Binder.restoreCallingIdentity(identity); |
| 9435 | } |
| 9436 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9437 | |
| 9438 | @Override |
| 9439 | public int getCdmaRoamingMode(int subId) { |
zoey chen | 7e6d4e5 | 2019-12-17 18:18:59 +0800 | [diff] [blame] | 9440 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9441 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9442 | mApp, subId, "getCdmaRoamingMode"); |
| 9443 | |
| 9444 | final long identity = Binder.clearCallingIdentity(); |
| 9445 | try { |
| 9446 | return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId); |
| 9447 | } finally { |
| 9448 | Binder.restoreCallingIdentity(identity); |
| 9449 | } |
| 9450 | } |
| 9451 | |
| 9452 | @Override |
| 9453 | public boolean setCdmaRoamingMode(int subId, int mode) { |
| 9454 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9455 | mApp, subId, "setCdmaRoamingMode"); |
| 9456 | |
| 9457 | final long identity = Binder.clearCallingIdentity(); |
| 9458 | try { |
| 9459 | return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId); |
| 9460 | } finally { |
| 9461 | Binder.restoreCallingIdentity(identity); |
| 9462 | } |
| 9463 | } |
| 9464 | |
| 9465 | @Override |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 9466 | public int getCdmaSubscriptionMode(int subId) { |
| 9467 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9468 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 9469 | mApp, subId, "getCdmaSubscriptionMode"); |
| 9470 | |
| 9471 | final long identity = Binder.clearCallingIdentity(); |
| 9472 | try { |
| 9473 | return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId); |
| 9474 | } finally { |
| 9475 | Binder.restoreCallingIdentity(identity); |
| 9476 | } |
| 9477 | } |
| 9478 | |
| 9479 | @Override |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9480 | public boolean setCdmaSubscriptionMode(int subId, int mode) { |
| 9481 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9482 | mApp, subId, "setCdmaSubscriptionMode"); |
| 9483 | |
| 9484 | final long identity = Binder.clearCallingIdentity(); |
| 9485 | try { |
| 9486 | return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId); |
| 9487 | } finally { |
| 9488 | Binder.restoreCallingIdentity(identity); |
| 9489 | } |
| 9490 | } |
Makoto Onuki | da3bf79 | 2018-09-18 16:06:29 -0700 | [diff] [blame] | 9491 | |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 9492 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 9493 | public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9494 | String callingPackage, String callingFeatureId) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9495 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9496 | mApp, getDefaultSubscription(), callingPackage, callingFeatureId, |
| 9497 | "getEmergencyNumberList")) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9498 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 9499 | } |
| 9500 | final long identity = Binder.clearCallingIdentity(); |
| 9501 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 9502 | Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>(); |
| 9503 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9504 | if (phone.getEmergencyNumberTracker() != null |
| 9505 | && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) { |
| 9506 | emergencyNumberListInternal.put( |
| 9507 | phone.getSubId(), |
| 9508 | phone.getEmergencyNumberTracker().getEmergencyNumberList()); |
| 9509 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9510 | } |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 9511 | return emergencyNumberListInternal; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9512 | } finally { |
| 9513 | Binder.restoreCallingIdentity(identity); |
| 9514 | } |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 9515 | } |
| 9516 | |
| 9517 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 9518 | public boolean isEmergencyNumber(String number, boolean exactMatch) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9519 | final Phone defaultPhone = getDefaultPhone(); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9520 | if (!exactMatch) { |
| 9521 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9522 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 9523 | mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)"); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9524 | } |
| 9525 | final long identity = Binder.clearCallingIdentity(); |
| 9526 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 9527 | for (Phone phone: PhoneFactory.getPhones()) { |
Chinmay Dhodapkar | d521bb1 | 2022-08-16 15:49:54 -0700 | [diff] [blame] | 9528 | //Note: we ignore passed in param exactMatch. We can remove it once |
| 9529 | // TelephonyManager#isPotentialEmergencyNumber is removed completely |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 9530 | if (phone.getEmergencyNumberTracker() != null |
Taesu Lee | e050c00 | 2020-10-13 17:19:35 +0900 | [diff] [blame] | 9531 | && phone.getEmergencyNumberTracker() |
Chinmay Dhodapkar | d521bb1 | 2022-08-16 15:49:54 -0700 | [diff] [blame] | 9532 | .isEmergencyNumber(number)) { |
Taesu Lee | e050c00 | 2020-10-13 17:19:35 +0900 | [diff] [blame] | 9533 | return true; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9534 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9535 | } |
| 9536 | return false; |
| 9537 | } finally { |
| 9538 | Binder.restoreCallingIdentity(identity); |
| 9539 | } |
| 9540 | } |
| 9541 | |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 9542 | /** |
Shuo Qian | ccbaf74 | 2021-02-22 18:32:21 -0800 | [diff] [blame] | 9543 | * Start emergency callback mode for GsmCdmaPhone for testing. |
| 9544 | */ |
| 9545 | @Override |
| 9546 | public void startEmergencyCallbackMode() { |
| 9547 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9548 | "startEmergencyCallbackMode"); |
| 9549 | enforceModifyPermission(); |
| 9550 | final long identity = Binder.clearCallingIdentity(); |
| 9551 | try { |
| 9552 | for (Phone phone : PhoneFactory.getPhones()) { |
| 9553 | Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType()); |
| 9554 | if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM) |
| 9555 | || (phone.getPhoneType() == PHONE_TYPE_CDMA))) { |
| 9556 | GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone; |
| 9557 | gsmCdmaPhone.obtainMessage( |
| 9558 | GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget(); |
| 9559 | Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered"); |
| 9560 | } |
| 9561 | } |
| 9562 | } finally { |
| 9563 | Binder.restoreCallingIdentity(identity); |
| 9564 | } |
| 9565 | } |
| 9566 | |
| 9567 | /** |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 9568 | * Update emergency number list for test mode. |
| 9569 | */ |
| 9570 | @Override |
| 9571 | public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) { |
| 9572 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9573 | "updateEmergencyNumberListTestMode"); |
| 9574 | |
| 9575 | final long identity = Binder.clearCallingIdentity(); |
| 9576 | try { |
| 9577 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9578 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9579 | if (tracker != null) { |
| 9580 | tracker.executeEmergencyNumberTestModeCommand(action, num); |
| 9581 | } |
| 9582 | } |
| 9583 | } finally { |
| 9584 | Binder.restoreCallingIdentity(identity); |
| 9585 | } |
| 9586 | } |
| 9587 | |
| 9588 | /** |
| 9589 | * Get the full emergency number list for test mode. |
| 9590 | */ |
| 9591 | @Override |
| 9592 | public List<String> getEmergencyNumberListTestMode() { |
| 9593 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9594 | "getEmergencyNumberListTestMode"); |
| 9595 | |
| 9596 | final long identity = Binder.clearCallingIdentity(); |
| 9597 | try { |
| 9598 | Set<String> emergencyNumbers = new HashSet<>(); |
| 9599 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9600 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9601 | if (tracker != null) { |
| 9602 | for (EmergencyNumber num : tracker.getEmergencyNumberList()) { |
| 9603 | emergencyNumbers.add(num.getNumber()); |
| 9604 | } |
| 9605 | } |
| 9606 | } |
| 9607 | return new ArrayList<>(emergencyNumbers); |
| 9608 | } finally { |
| 9609 | Binder.restoreCallingIdentity(identity); |
| 9610 | } |
| 9611 | } |
| 9612 | |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 9613 | @Override |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 9614 | public int getEmergencyNumberDbVersion(int subId) { |
| 9615 | enforceReadPrivilegedPermission("getEmergencyNumberDbVersion"); |
| 9616 | |
| 9617 | final long identity = Binder.clearCallingIdentity(); |
| 9618 | try { |
| 9619 | final Phone phone = getPhone(subId); |
| 9620 | if (phone == null) { |
| 9621 | loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId); |
| 9622 | return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION; |
| 9623 | } |
| 9624 | return phone.getEmergencyNumberDbVersion(); |
| 9625 | } finally { |
| 9626 | Binder.restoreCallingIdentity(identity); |
| 9627 | } |
| 9628 | } |
| 9629 | |
| 9630 | @Override |
| 9631 | public void notifyOtaEmergencyNumberDbInstalled() { |
| 9632 | enforceModifyPermission(); |
| 9633 | |
| 9634 | final long identity = Binder.clearCallingIdentity(); |
| 9635 | try { |
| 9636 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9637 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9638 | if (tracker != null) { |
| 9639 | tracker.updateOtaEmergencyNumberDatabase(); |
| 9640 | } |
| 9641 | } |
| 9642 | } finally { |
| 9643 | Binder.restoreCallingIdentity(identity); |
| 9644 | } |
| 9645 | } |
| 9646 | |
| 9647 | @Override |
Shuo Qian | c373f11 | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 9648 | public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) { |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 9649 | enforceActiveEmergencySessionPermission(); |
| 9650 | |
| 9651 | final long identity = Binder.clearCallingIdentity(); |
| 9652 | try { |
| 9653 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9654 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9655 | if (tracker != null) { |
Shuo Qian | c373f11 | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 9656 | tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor); |
| 9657 | } |
| 9658 | } |
| 9659 | } finally { |
| 9660 | Binder.restoreCallingIdentity(identity); |
| 9661 | } |
| 9662 | } |
| 9663 | |
| 9664 | @Override |
| 9665 | public void resetOtaEmergencyNumberDbFilePath() { |
| 9666 | enforceActiveEmergencySessionPermission(); |
| 9667 | |
| 9668 | final long identity = Binder.clearCallingIdentity(); |
| 9669 | try { |
| 9670 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9671 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9672 | if (tracker != null) { |
| 9673 | tracker.resetOtaEmergencyNumberDbFilePath(); |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 9674 | } |
| 9675 | } |
| 9676 | } finally { |
| 9677 | Binder.restoreCallingIdentity(identity); |
| 9678 | } |
| 9679 | } |
| 9680 | |
| 9681 | @Override |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 9682 | public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) { |
| 9683 | enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules"); |
| 9684 | Phone phone = getPhone(subId); |
| 9685 | if (phone == null) { |
| 9686 | return null; |
| 9687 | } |
| 9688 | final long identity = Binder.clearCallingIdentity(); |
| 9689 | try { |
| 9690 | UiccProfile profile = UiccController.getInstance() |
| 9691 | .getUiccProfileForPhone(phone.getPhoneId()); |
| 9692 | if (profile != null) { |
| 9693 | return profile.getCertsFromCarrierPrivilegeAccessRules(); |
| 9694 | } |
| 9695 | } finally { |
| 9696 | Binder.restoreCallingIdentity(identity); |
| 9697 | } |
| 9698 | return null; |
| 9699 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 9700 | |
| 9701 | /** |
| 9702 | * Enable or disable a modem stack. |
| 9703 | */ |
| 9704 | @Override |
| 9705 | public boolean enableModemForSlot(int slotIndex, boolean enable) { |
| 9706 | enforceModifyPermission(); |
| 9707 | |
| 9708 | final long identity = Binder.clearCallingIdentity(); |
| 9709 | try { |
| 9710 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 9711 | if (phone == null) { |
| 9712 | return false; |
| 9713 | } else { |
| 9714 | return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null); |
| 9715 | } |
| 9716 | } finally { |
| 9717 | Binder.restoreCallingIdentity(identity); |
| 9718 | } |
| 9719 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9720 | |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 9721 | /** |
| 9722 | * Whether a modem stack is enabled or not. |
| 9723 | */ |
| 9724 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9725 | public boolean isModemEnabledForSlot(int slotIndex, String callingPackage, |
| 9726 | String callingFeatureId) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 9727 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 9728 | if (phone == null) return false; |
| 9729 | |
| 9730 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9731 | mApp, phone.getSubId(), callingPackage, callingFeatureId, |
| 9732 | "isModemEnabledForSlot")) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 9733 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 9734 | } |
| 9735 | |
| 9736 | final long identity = Binder.clearCallingIdentity(); |
| 9737 | try { |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 9738 | try { |
| 9739 | return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId()); |
| 9740 | } catch (NoSuchElementException ex) { |
| 9741 | return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null); |
| 9742 | } |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 9743 | } finally { |
| 9744 | Binder.restoreCallingIdentity(identity); |
| 9745 | } |
| 9746 | } |
| 9747 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9748 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9749 | public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) { |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9750 | enforceModifyPermission(); |
| 9751 | |
| 9752 | final long identity = Binder.clearCallingIdentity(); |
| 9753 | try { |
| 9754 | mTelephonySharedPreferences.edit() |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9755 | .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted) |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9756 | .commit(); |
| 9757 | } finally { |
| 9758 | Binder.restoreCallingIdentity(identity); |
| 9759 | } |
| 9760 | } |
| 9761 | |
| 9762 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9763 | @TelephonyManager.IsMultiSimSupportedResult |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9764 | public int isMultiSimSupported(String callingPackage, String callingFeatureId) { |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 9765 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9766 | getDefaultPhone().getSubId(), callingPackage, callingFeatureId, |
| 9767 | "isMultiSimSupported")) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9768 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 9769 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9770 | |
| 9771 | final long identity = Binder.clearCallingIdentity(); |
| 9772 | try { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9773 | return isMultiSimSupportedInternal(); |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9774 | } finally { |
| 9775 | Binder.restoreCallingIdentity(identity); |
| 9776 | } |
| 9777 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9778 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9779 | @TelephonyManager.IsMultiSimSupportedResult |
| 9780 | private int isMultiSimSupportedInternal() { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9781 | // If the device has less than 2 SIM cards, indicate that multisim is restricted. |
| 9782 | int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length; |
| 9783 | if (numPhysicalSlots < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9784 | loge("isMultiSimSupportedInternal: requires at least 2 cards"); |
| 9785 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9786 | } |
| 9787 | // Check if the hardware supports multisim functionality. If usage of multisim is not |
| 9788 | // supported by the modem, indicate that it is restricted. |
| 9789 | PhoneCapability staticCapability = |
| 9790 | mPhoneConfigurationManager.getStaticPhoneCapability(); |
| 9791 | if (staticCapability == null) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9792 | loge("isMultiSimSupportedInternal: no static configuration available"); |
| 9793 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9794 | } |
SongFerngWang | 8236caa | 2021-01-17 21:51:44 +0800 | [diff] [blame] | 9795 | if (staticCapability.getLogicalModemList().size() < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9796 | loge("isMultiSimSupportedInternal: maximum number of modem is < 2"); |
| 9797 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9798 | } |
| 9799 | // Check if support of multiple SIMs is restricted by carrier |
| 9800 | if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9801 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9802 | } |
| 9803 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9804 | return TelephonyManager.MULTISIM_ALLOWED; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9805 | } |
| 9806 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9807 | /** |
| 9808 | * Switch configs to enable multi-sim or switch back to single-sim |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 9809 | * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE |
| 9810 | * permission, but the other way around is possible with either MODIFY_PHONE_STATE |
| 9811 | * or carrier privileges |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9812 | * @param numOfSims number of active sims we want to switch to |
| 9813 | */ |
| 9814 | @Override |
| 9815 | public void switchMultiSimConfig(int numOfSims) { |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 9816 | if (numOfSims == 1) { |
| 9817 | enforceModifyPermission(); |
| 9818 | } else { |
| 9819 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9820 | mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig"); |
| 9821 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9822 | final long identity = Binder.clearCallingIdentity(); |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9823 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9824 | try { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9825 | //only proceed if multi-sim is not restricted |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9826 | if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9827 | loge("switchMultiSimConfig not possible. It is restricted or not supported."); |
| 9828 | return; |
| 9829 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9830 | mPhoneConfigurationManager.switchMultiSimConfig(numOfSims); |
| 9831 | } finally { |
| 9832 | Binder.restoreCallingIdentity(identity); |
| 9833 | } |
| 9834 | } |
| 9835 | |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 9836 | @Override |
| 9837 | public boolean isApplicationOnUicc(int subId, int appType) { |
| 9838 | enforceReadPrivilegedPermission("isApplicationOnUicc"); |
| 9839 | Phone phone = getPhone(subId); |
| 9840 | if (phone == null) { |
| 9841 | return false; |
| 9842 | } |
| 9843 | final long identity = Binder.clearCallingIdentity(); |
| 9844 | try { |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9845 | UiccPort uiccPort = phone.getUiccPort(); |
| 9846 | if (uiccPort == null) { |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 9847 | return false; |
| 9848 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9849 | UiccProfile uiccProfile = uiccPort.getUiccProfile(); |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 9850 | if (uiccProfile == null) { |
| 9851 | return false; |
| 9852 | } |
| 9853 | if (TelephonyManager.APPTYPE_SIM <= appType |
| 9854 | && appType <= TelephonyManager.APPTYPE_ISIM) { |
| 9855 | return uiccProfile.isApplicationOnIcc(AppType.values()[appType]); |
| 9856 | } |
| 9857 | return false; |
| 9858 | } finally { |
| 9859 | Binder.restoreCallingIdentity(identity); |
| 9860 | } |
| 9861 | } |
| 9862 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9863 | /** |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 9864 | * Get whether making changes to modem configurations will trigger reboot. |
| 9865 | * Return value defaults to true. |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 9866 | */ |
| 9867 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9868 | public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage, |
| 9869 | String callingFeatureId) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 9870 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9871 | mApp, subId, callingPackage, callingFeatureId, |
| 9872 | "doesSwitchMultiSimConfigTriggerReboot")) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 9873 | return false; |
| 9874 | } |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 9875 | final long identity = Binder.clearCallingIdentity(); |
| 9876 | try { |
| 9877 | return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange(); |
| 9878 | } finally { |
| 9879 | Binder.restoreCallingIdentity(identity); |
| 9880 | } |
| 9881 | } |
| 9882 | |
Nathan Harold | 29f5f05 | 2019-02-15 13:41:57 -0800 | [diff] [blame] | 9883 | private void updateModemStateMetrics() { |
| 9884 | TelephonyMetrics metrics = TelephonyMetrics.getInstance(); |
| 9885 | // TODO: check the state for each modem if the api is ready. |
| 9886 | metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1); |
| 9887 | } |
| 9888 | |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 9889 | @Override |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9890 | public List<UiccSlotMapping> getSlotsMapping(String callingPackage) { |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 9891 | enforceReadPrivilegedPermission("getSlotsMapping"); |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9892 | // Verify that the callingPackage belongs to the calling UID |
| 9893 | mApp.getSystemService(AppOpsManager.class) |
| 9894 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 9895 | final long identity = Binder.clearCallingIdentity(); |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9896 | List<UiccSlotMapping> slotMap = new ArrayList<>(); |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 9897 | try { |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9898 | UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName()); |
| 9899 | if (slotInfos != null) { |
| 9900 | for (int i = 0; i < slotInfos.length; i++) { |
| 9901 | for (UiccPortInfo portInfo : slotInfos[i].getPorts()) { |
| 9902 | if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) { |
| 9903 | slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i, |
| 9904 | portInfo.getLogicalSlotIndex())); |
| 9905 | } |
| 9906 | } |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 9907 | } |
| 9908 | } |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9909 | return slotMap; |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 9910 | } finally { |
| 9911 | Binder.restoreCallingIdentity(identity); |
| 9912 | } |
| 9913 | } |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 9914 | |
| 9915 | /** |
| 9916 | * Get the IRadio HAL Version |
jimsun | f9ec162 | 2022-09-13 21:18:43 +0800 | [diff] [blame] | 9917 | * @deprecated use getHalVersion instead |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 9918 | */ |
jimsun | f9ec162 | 2022-09-13 21:18:43 +0800 | [diff] [blame] | 9919 | @Deprecated |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 9920 | @Override |
| 9921 | public int getRadioHalVersion() { |
jimsun | f9ec162 | 2022-09-13 21:18:43 +0800 | [diff] [blame] | 9922 | return getHalVersion(HAL_SERVICE_RADIO); |
| 9923 | } |
| 9924 | |
| 9925 | /** |
| 9926 | * Get the HAL Version of a specific service |
| 9927 | */ |
| 9928 | @Override |
| 9929 | public int getHalVersion(int service) { |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 9930 | Phone phone = getDefaultPhone(); |
| 9931 | if (phone == null) return -1; |
jimsun | f9ec162 | 2022-09-13 21:18:43 +0800 | [diff] [blame] | 9932 | HalVersion hv = phone.getHalVersion(service); |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 9933 | if (hv.equals(HalVersion.UNKNOWN)) return -1; |
| 9934 | return hv.major * 100 + hv.minor; |
| 9935 | } |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9936 | |
| 9937 | /** |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 9938 | * Get the current calling package name. |
| 9939 | * @return the current calling package name |
| 9940 | */ |
| 9941 | @Override |
| 9942 | public String getCurrentPackageName() { |
| 9943 | return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0]; |
| 9944 | } |
| 9945 | |
| 9946 | /** |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9947 | * Return whether data is enabled for certain APN type. This will tell if framework will accept |
| 9948 | * corresponding network requests on a subId. |
| 9949 | * |
| 9950 | * Data is enabled if: |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9951 | * 1) user data is turned on, or |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9952 | * 2) APN is un-metered for this subscription, or |
| 9953 | * 3) APN type is whitelisted. E.g. MMS is whitelisted if |
Hall Liu | 746e03c | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 9954 | * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled. |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9955 | * |
| 9956 | * @return whether data is allowed for a apn type. |
| 9957 | * |
| 9958 | * @hide |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9959 | */ |
| 9960 | @Override |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9961 | public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) { |
Amit Mahajan | 5d4e192 | 2019-10-07 16:20:43 -0700 | [diff] [blame] | 9962 | enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for " |
| 9963 | + "isDataEnabledForApn"); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9964 | |
| 9965 | // Now that all security checks passes, perform the operation as ourselves. |
| 9966 | final long identity = Binder.clearCallingIdentity(); |
| 9967 | try { |
| 9968 | Phone phone = getPhone(subId); |
| 9969 | if (phone == null) return false; |
| 9970 | |
Jack Yu | 27422a5 | 2022-03-21 10:38:05 -0700 | [diff] [blame] | 9971 | boolean isMetered; |
Jack Yu | 99e8733 | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 9972 | boolean isDataEnabled; |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 9973 | isMetered = phone.getDataNetworkController().getDataConfigManager() |
| 9974 | .isMeteredCapability(DataUtils.apnTypeToNetworkCapability(apnType), |
| 9975 | phone.getServiceState().getDataRoaming()); |
| 9976 | isDataEnabled = phone.getDataSettingsManager().isDataEnabled(apnType); |
Jack Yu | 99e8733 | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 9977 | return !isMetered || isDataEnabled; |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9978 | } finally { |
| 9979 | Binder.restoreCallingIdentity(identity); |
| 9980 | } |
| 9981 | } |
| 9982 | |
| 9983 | @Override |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 9984 | public boolean isApnMetered(@ApnType int apnType, int subId) { |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9985 | enforceReadPrivilegedPermission("isApnMetered"); |
| 9986 | |
| 9987 | // Now that all security checks passes, perform the operation as ourselves. |
| 9988 | final long identity = Binder.clearCallingIdentity(); |
| 9989 | try { |
| 9990 | Phone phone = getPhone(subId); |
| 9991 | if (phone == null) return true; // By default return true. |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 9992 | return phone.getDataNetworkController().getDataConfigManager().isMeteredCapability( |
| 9993 | DataUtils.apnTypeToNetworkCapability(apnType), |
| 9994 | phone.getServiceState().getDataRoaming()); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9995 | } finally { |
| 9996 | Binder.restoreCallingIdentity(identity); |
| 9997 | } |
| 9998 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 9999 | |
| 10000 | @Override |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 10001 | public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers, |
| 10002 | int subscriptionId, IBooleanConsumer resultCallback) { |
| 10003 | enforceModifyPermission(); |
| 10004 | long token = Binder.clearCallingIdentity(); |
| 10005 | try { |
| 10006 | Phone phone = getPhone(subscriptionId); |
| 10007 | if (phone == null) { |
| 10008 | try { |
| 10009 | if (resultCallback != null) { |
| 10010 | resultCallback.accept(false); |
| 10011 | } |
| 10012 | } catch (RemoteException e) { |
| 10013 | // ignore |
| 10014 | } |
| 10015 | return; |
| 10016 | } |
| 10017 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument = |
| 10018 | Pair.create(specifiers, (x) -> { |
| 10019 | try { |
| 10020 | if (resultCallback != null) { |
| 10021 | resultCallback.accept(x); |
| 10022 | } |
| 10023 | } catch (RemoteException e) { |
| 10024 | // ignore |
| 10025 | } |
| 10026 | }); |
| 10027 | sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null); |
| 10028 | } finally { |
| 10029 | Binder.restoreCallingIdentity(token); |
| 10030 | } |
| 10031 | } |
| 10032 | |
| 10033 | @Override |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 10034 | public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) { |
| 10035 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 10036 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 10037 | mApp, subId, "getSystemSelectionChannels"); |
| 10038 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 10039 | final long identity = Binder.clearCallingIdentity(); |
| 10040 | try { |
Sarah Chin | 428d1d6 | 2021-03-13 03:17:40 -0800 | [diff] [blame] | 10041 | Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource); |
| 10042 | if (result instanceof IllegalStateException) { |
| 10043 | throw (IllegalStateException) result; |
| 10044 | } |
| 10045 | List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 10046 | if (DBG) log("getSystemSelectionChannels: " + specifiers); |
| 10047 | return specifiers; |
| 10048 | } finally { |
| 10049 | Binder.restoreCallingIdentity(identity); |
| 10050 | } |
| 10051 | } |
| 10052 | |
| 10053 | @Override |
Jack Yu | 8b766fc | 2022-03-21 09:42:33 -0700 | [diff] [blame] | 10054 | public boolean isMvnoMatched(int slotIndex, int mvnoType, @NonNull String mvnoMatchData) { |
changbetty | ca3d40d | 2020-03-03 16:27:31 +0800 | [diff] [blame] | 10055 | enforceReadPrivilegedPermission("isMvnoMatched"); |
Jack Yu | 8b766fc | 2022-03-21 09:42:33 -0700 | [diff] [blame] | 10056 | return UiccController.getInstance().mvnoMatches(slotIndex, mvnoType, mvnoMatchData); |
changbetty | 7157e9e | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 10057 | } |
| 10058 | |
| 10059 | @Override |
Philip P. Moltmann | d02b737 | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 10060 | public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag, |
| 10061 | IIntegerConsumer pendingSubIdResult) { |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 10062 | if (callingPackage == null) { |
| 10063 | callingPackage = getCurrentPackageName(); |
| 10064 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 10065 | SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp, |
| 10066 | (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE)); |
Philip P. Moltmann | d02b737 | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 10067 | if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag, |
| 10068 | "Sending message")) { |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 10069 | throw new SecurityException("Requires SEND_SMS permission to perform this operation"); |
| 10070 | } |
| 10071 | PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult); |
| 10072 | Intent intent = new Intent(); |
| 10073 | intent.setClass(mApp, PickSmsSubscriptionActivity.class); |
| 10074 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 10075 | // Bring up choose default SMS subscription dialog right now |
| 10076 | intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY, |
| 10077 | PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE); |
| 10078 | mApp.startActivity(intent); |
| 10079 | } |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 10080 | |
| 10081 | @Override |
| 10082 | public String getMmsUAProfUrl(int subId) { |
| 10083 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 10084 | final long identity = Binder.clearCallingIdentity(); |
| 10085 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 10086 | String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString( |
| 10087 | CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING); |
| 10088 | if (!TextUtils.isEmpty(carrierUAProfUrl)) { |
| 10089 | return carrierUAProfUrl; |
| 10090 | } |
Daniel Bright | ebb4eb7 | 2020-02-18 15:16:33 -0800 | [diff] [blame] | 10091 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 10092 | .getString(com.android.internal.R.string.config_mms_user_agent_profile_url); |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 10093 | } finally { |
| 10094 | Binder.restoreCallingIdentity(identity); |
| 10095 | } |
| 10096 | } |
| 10097 | |
| 10098 | @Override |
| 10099 | public String getMmsUserAgent(int subId) { |
| 10100 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 10101 | final long identity = Binder.clearCallingIdentity(); |
| 10102 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 10103 | String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString( |
| 10104 | CarrierConfigManager.KEY_MMS_USER_AGENT_STRING); |
| 10105 | if (!TextUtils.isEmpty(carrierUserAgent)) { |
| 10106 | return carrierUserAgent; |
| 10107 | } |
Daniel Bright | ebb4eb7 | 2020-02-18 15:16:33 -0800 | [diff] [blame] | 10108 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 10109 | .getString(com.android.internal.R.string.config_mms_user_agent); |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 10110 | } finally { |
| 10111 | Binder.restoreCallingIdentity(identity); |
| 10112 | } |
| 10113 | } |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 10114 | |
| 10115 | @Override |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 10116 | public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) { |
| 10117 | enforceReadPrivilegedPermission("isMobileDataPolicyEnabled"); |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 10118 | |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 10119 | final long identity = Binder.clearCallingIdentity(); |
| 10120 | try { |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 10121 | Phone phone = getPhone(subscriptionId); |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 10122 | if (phone == null) return false; |
| 10123 | |
Ling Ma | f188d50 | 2022-09-16 15:22:36 -0700 | [diff] [blame] | 10124 | return phone.getDataSettingsManager().isMobileDataPolicyEnabled(policy); |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 10125 | } finally { |
| 10126 | Binder.restoreCallingIdentity(identity); |
| 10127 | } |
| 10128 | } |
| 10129 | |
| 10130 | @Override |
Hall Liu | c66bb11 | 2021-02-02 12:09:32 -0800 | [diff] [blame] | 10131 | public void setMobileDataPolicyEnabled(int subscriptionId, int policy, |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 10132 | boolean enabled) { |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 10133 | enforceModifyPermission(); |
| 10134 | |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 10135 | final long identity = Binder.clearCallingIdentity(); |
| 10136 | try { |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 10137 | Phone phone = getPhone(subscriptionId); |
| 10138 | if (phone == null) return; |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 10139 | |
Ling Ma | f188d50 | 2022-09-16 15:22:36 -0700 | [diff] [blame] | 10140 | phone.getDataSettingsManager().setMobileDataPolicy(policy, enabled); |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 10141 | } finally { |
| 10142 | Binder.restoreCallingIdentity(identity); |
| 10143 | } |
| 10144 | } |
| 10145 | |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 10146 | /** |
Hall Liu | 746e03c | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 10147 | * Updates whether conference event package handling is enabled. |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 10148 | * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false} |
| 10149 | * otherwise. |
| 10150 | */ |
| 10151 | @Override |
| 10152 | public void setCepEnabled(boolean isCepEnabled) { |
| 10153 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled"); |
| 10154 | |
| 10155 | final long identity = Binder.clearCallingIdentity(); |
| 10156 | try { |
| 10157 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled); |
| 10158 | for (Phone phone : PhoneFactory.getPhones()) { |
| 10159 | Phone defaultPhone = phone.getImsPhone(); |
| 10160 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 10161 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 10162 | ImsPhoneCallTracker imsPhoneCallTracker = |
| 10163 | (ImsPhoneCallTracker) imsPhone.getCallTracker(); |
| 10164 | imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled); |
| 10165 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone " |
| 10166 | + imsPhone.getMsisdn()); |
| 10167 | } |
| 10168 | } |
| 10169 | } finally { |
| 10170 | Binder.restoreCallingIdentity(identity); |
| 10171 | } |
| 10172 | } |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 10173 | |
| 10174 | /** |
| 10175 | * Notify that an RCS autoconfiguration XML file has been received for provisioning. |
| 10176 | * |
| 10177 | * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed. |
| 10178 | * @param isCompressed The XML file is compressed in gzip format and must be decompressed |
| 10179 | * before being read. |
| 10180 | */ |
| 10181 | @Override |
| 10182 | public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean |
| 10183 | isCompressed) { |
| 10184 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 10185 | mApp, subId, "notifyRcsAutoConfigurationReceived"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10186 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10187 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10188 | } |
| 10189 | if (!isImsAvailableOnDevice()) { |
| 10190 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 10191 | "IMS not available on device."); |
| 10192 | } |
| 10193 | |
| 10194 | final long identity = Binder.clearCallingIdentity(); |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 10195 | try { |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10196 | RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed); |
| 10197 | } finally { |
| 10198 | Binder.restoreCallingIdentity(identity); |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 10199 | } |
| 10200 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 10201 | |
| 10202 | @Override |
| 10203 | public boolean isIccLockEnabled(int subId) { |
| 10204 | enforceReadPrivilegedPermission("isIccLockEnabled"); |
| 10205 | |
| 10206 | // Now that all security checks passes, perform the operation as ourselves. |
| 10207 | final long identity = Binder.clearCallingIdentity(); |
| 10208 | try { |
| 10209 | Phone phone = getPhone(subId); |
| 10210 | if (phone != null && phone.getIccCard() != null) { |
| 10211 | return phone.getIccCard().getIccLockEnabled(); |
| 10212 | } else { |
| 10213 | return false; |
| 10214 | } |
| 10215 | } finally { |
| 10216 | Binder.restoreCallingIdentity(identity); |
| 10217 | } |
| 10218 | } |
| 10219 | |
| 10220 | /** |
| 10221 | * Set the ICC pin lock enabled or disabled. |
| 10222 | * |
| 10223 | * @return an integer representing the status of IccLock enabled or disabled in the following |
| 10224 | * three cases: |
| 10225 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock |
| 10226 | * successfully. |
| 10227 | * - Positive number and zero for remaining password attempts. |
| 10228 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
| 10229 | * |
| 10230 | */ |
| 10231 | @Override |
| 10232 | public int setIccLockEnabled(int subId, boolean enabled, String password) { |
| 10233 | enforceModifyPermission(); |
| 10234 | |
| 10235 | Phone phone = getPhone(subId); |
| 10236 | if (phone == null) { |
| 10237 | return 0; |
| 10238 | } |
| 10239 | // Now that all security checks passes, perform the operation as ourselves. |
| 10240 | final long identity = Binder.clearCallingIdentity(); |
| 10241 | try { |
| 10242 | int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED, |
| 10243 | new Pair<Boolean, String>(enabled, password), phone, null); |
| 10244 | return attemptsRemaining; |
| 10245 | |
| 10246 | } catch (Exception e) { |
| 10247 | Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e); |
| 10248 | } finally { |
| 10249 | Binder.restoreCallingIdentity(identity); |
| 10250 | } |
| 10251 | return 0; |
| 10252 | } |
| 10253 | |
| 10254 | /** |
| 10255 | * Change the ICC password used in ICC pin lock. |
| 10256 | * |
| 10257 | * @return an integer representing the status of IccLock changed in the following three cases: |
| 10258 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully. |
| 10259 | * - Positive number and zero for remaining password attempts. |
| 10260 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
| 10261 | * |
| 10262 | */ |
| 10263 | @Override |
| 10264 | public int changeIccLockPassword(int subId, String oldPassword, String newPassword) { |
| 10265 | enforceModifyPermission(); |
| 10266 | |
| 10267 | Phone phone = getPhone(subId); |
| 10268 | if (phone == null) { |
| 10269 | return 0; |
| 10270 | } |
| 10271 | // Now that all security checks passes, perform the operation as ourselves. |
| 10272 | final long identity = Binder.clearCallingIdentity(); |
| 10273 | try { |
| 10274 | int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD, |
| 10275 | new Pair<String, String>(oldPassword, newPassword), phone, null); |
| 10276 | return attemptsRemaining; |
| 10277 | |
| 10278 | } catch (Exception e) { |
| 10279 | Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e); |
| 10280 | } finally { |
| 10281 | Binder.restoreCallingIdentity(identity); |
| 10282 | } |
| 10283 | return 0; |
| 10284 | } |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 10285 | |
| 10286 | /** |
| 10287 | * Request for receiving user activity notification |
| 10288 | */ |
| 10289 | @Override |
| 10290 | public void requestUserActivityNotification() { |
| 10291 | if (!mNotifyUserActivity.get() |
| 10292 | && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) { |
| 10293 | mNotifyUserActivity.set(true); |
| 10294 | } |
| 10295 | } |
| 10296 | |
| 10297 | /** |
| 10298 | * Called when userActivity is signalled in the power manager. |
| 10299 | * This is safe to call from any thread, with any window manager locks held or not. |
| 10300 | */ |
| 10301 | @Override |
| 10302 | public void userActivity() { |
| 10303 | // *************************************** |
| 10304 | // * Inherited from PhoneWindowManager * |
| 10305 | // *************************************** |
| 10306 | // THIS IS CALLED FROM DEEP IN THE POWER MANAGER |
| 10307 | // WITH ITS LOCKS HELD. |
| 10308 | // |
| 10309 | // This code must be VERY careful about the locks |
| 10310 | // it acquires. |
| 10311 | // In fact, the current code acquires way too many, |
| 10312 | // and probably has lurking deadlocks. |
| 10313 | |
| 10314 | if (Binder.getCallingUid() != Process.SYSTEM_UID) { |
| 10315 | throw new SecurityException("Only the OS may call notifyUserActivity()"); |
| 10316 | } |
| 10317 | |
| 10318 | if (mNotifyUserActivity.getAndSet(false)) { |
| 10319 | mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY, |
| 10320 | USER_ACTIVITY_NOTIFICATION_DELAY); |
| 10321 | } |
| 10322 | } |
Malcolm Chen | 4639c56 | 2020-04-13 11:59:40 -0700 | [diff] [blame] | 10323 | |
| 10324 | @Override |
| 10325 | public boolean canConnectTo5GInDsdsMode() { |
| 10326 | return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode); |
| 10327 | } |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 10328 | |
| 10329 | @Override |
| 10330 | public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage, |
| 10331 | String callingFeatureId) { |
| 10332 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 10333 | mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) { |
| 10334 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 10335 | } |
| 10336 | |
| 10337 | Phone phone = getPhone(subId); |
| 10338 | if (phone == null) { |
| 10339 | throw new RuntimeException("phone is not available"); |
| 10340 | } |
| 10341 | // Now that all security checks passes, perform the operation as ourselves. |
| 10342 | final long identity = Binder.clearCallingIdentity(); |
| 10343 | try { |
| 10344 | return phone.getEquivalentHomePlmns(); |
| 10345 | } finally { |
| 10346 | Binder.restoreCallingIdentity(identity); |
| 10347 | } |
| 10348 | } |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 10349 | |
| 10350 | @Override |
| 10351 | public boolean isRadioInterfaceCapabilitySupported( |
Daniel Bright | 95a4c1f | 2021-02-11 09:57:16 -0800 | [diff] [blame] | 10352 | final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) { |
| 10353 | Set<String> radioInterfaceCapabilities = |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 10354 | mRadioInterfaceCapabilities.getCapabilities(); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 10355 | if (radioInterfaceCapabilities == null) { |
| 10356 | throw new RuntimeException("radio interface capabilities are not available"); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 10357 | } |
Daniel Bright | 95a4c1f | 2021-02-11 09:57:16 -0800 | [diff] [blame] | 10358 | return radioInterfaceCapabilities.contains(capability); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 10359 | } |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10360 | |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 10361 | @Override |
| 10362 | public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl, |
| 10363 | UaSecurityProtocolIdentifier securityProtocol, |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10364 | boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) { |
| 10365 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 10366 | Binder.getCallingUid(), "bootstrapAuthenticationRequest", |
| 10367 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 10368 | Manifest.permission.MODIFY_PHONE_STATE); |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 10369 | if (DBG) { |
| 10370 | log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:" |
| 10371 | + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol |
| 10372 | + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback); |
| 10373 | } |
| 10374 | |
| 10375 | if (!SubscriptionManager.isValidSubscriptionId(subId) |
| 10376 | || appType < TelephonyManager.APPTYPE_UNKNOWN |
| 10377 | || appType > TelephonyManager.APPTYPE_ISIM |
| 10378 | || nafUrl == null || securityProtocol == null || callback == null) { |
| 10379 | Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters"); |
| 10380 | if (callback != null) { |
| 10381 | try { |
| 10382 | callback.onAuthenticationFailure( |
| 10383 | 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED); |
| 10384 | } catch (RemoteException exception) { |
| 10385 | log("Fail to notify onAuthenticationFailure due to " + exception); |
| 10386 | } |
| 10387 | return; |
| 10388 | } |
| 10389 | } |
| 10390 | |
| 10391 | final long token = Binder.clearCallingIdentity(); |
| 10392 | try { |
| 10393 | getGbaManager(subId).bootstrapAuthenticationRequest( |
| 10394 | new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(), |
| 10395 | forceBootStrapping, callback)); |
| 10396 | } finally { |
| 10397 | Binder.restoreCallingIdentity(token); |
| 10398 | } |
| 10399 | } |
| 10400 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10401 | /** |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10402 | * Attempts to set the radio power state for all phones for thermal reason. |
| 10403 | * This does not guarantee that the |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10404 | * requested radio power state will actually be set. See {@link |
| 10405 | * PhoneInternalInterface#setRadioPowerForReason} for more details. |
| 10406 | * |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10407 | * @param enable {@code true} if trying to turn radio on. |
| 10408 | * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code |
| 10409 | * false}. |
| 10410 | */ |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10411 | private boolean setRadioPowerForThermal(boolean enable) { |
| 10412 | boolean isPhoneAvailable = false; |
| 10413 | for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) { |
| 10414 | Phone phone = PhoneFactory.getPhone(i); |
| 10415 | if (phone != null) { |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 10416 | phone.setRadioPowerForReason(enable, TelephonyManager.RADIO_POWER_REASON_THERMAL); |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10417 | isPhoneAvailable = true; |
| 10418 | } |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10419 | } |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10420 | |
| 10421 | // return true if successfully informed the phone object about the thermal radio power |
| 10422 | // request. |
| 10423 | return isPhoneAvailable; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10424 | } |
| 10425 | |
| 10426 | private int handleDataThrottlingRequest(int subId, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 10427 | DataThrottlingRequest dataThrottlingRequest, String callingPackage) { |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10428 | boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported( |
| 10429 | TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING); |
| 10430 | if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction() |
| 10431 | != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) { |
| 10432 | throw new IllegalArgumentException("modem does not support data throttling"); |
| 10433 | } |
| 10434 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10435 | // Ensure that radio is on. If not able to power on due to phone being unavailable, return |
| 10436 | // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10437 | if (!setRadioPowerForThermal(true)) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10438 | return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 10439 | } |
| 10440 | |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 10441 | setDataEnabledForReason( |
| 10442 | subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true, callingPackage); |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10443 | |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10444 | if (isDataThrottlingSupported) { |
| 10445 | int thermalMitigationResult = |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10446 | (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId); |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10447 | if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) { |
| 10448 | throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS"); |
| 10449 | } else if (thermalMitigationResult |
| 10450 | == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) { |
Jack Nudelman | 760d096 | 2021-05-20 13:57:30 -0700 | [diff] [blame] | 10451 | log("Modem likely does not support data throttling on secondary carrier. Data " + |
| 10452 | "throttling action = " + dataThrottlingRequest.getDataThrottlingAction()); |
| 10453 | return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10454 | } |
| 10455 | return thermalMitigationResult; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10456 | } |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10457 | |
| 10458 | return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10459 | } |
| 10460 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10461 | private static List<String> getThermalMitigationAllowlist(Context context) { |
| 10462 | if (sThermalMitigationAllowlistedPackages.isEmpty()) { |
| 10463 | for (String pckg : context.getResources() |
| 10464 | .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) { |
| 10465 | sThermalMitigationAllowlistedPackages.add(pckg); |
| 10466 | } |
| 10467 | } |
| 10468 | |
| 10469 | return sThermalMitigationAllowlistedPackages; |
| 10470 | } |
| 10471 | |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 10472 | private boolean isAnyPhoneInEmergencyState() { |
| 10473 | TelecomManager tm = mApp.getSystemService(TelecomManager.class); |
| 10474 | if (tm.isInEmergencyCall()) { |
| 10475 | Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call"); |
| 10476 | return true; |
| 10477 | } |
| 10478 | for (Phone phone : PhoneFactory.getPhones()) { |
| 10479 | if (phone.isInEmergencySmsMode() || phone.isInEcm()) { |
| 10480 | Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = " |
| 10481 | + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = " |
| 10482 | + phone.isInEcm()); |
| 10483 | return true; |
| 10484 | } |
| 10485 | } |
| 10486 | |
| 10487 | return false; |
| 10488 | } |
| 10489 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10490 | /** |
| 10491 | * Used by shell commands to add an authorized package name for thermal mitigation. |
| 10492 | * @param packageName name of package to be allowlisted |
| 10493 | * @param context |
| 10494 | */ |
| 10495 | static void addPackageToThermalMitigationAllowlist(String packageName, Context context) { |
| 10496 | sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context); |
| 10497 | sThermalMitigationAllowlistedPackages.add(packageName); |
| 10498 | } |
| 10499 | |
| 10500 | /** |
| 10501 | * Used by shell commands to remove an authorized package name for thermal mitigation. |
| 10502 | * @param packageName name of package to remove from allowlist |
| 10503 | * @param context |
| 10504 | */ |
| 10505 | static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) { |
| 10506 | sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context); |
| 10507 | sThermalMitigationAllowlistedPackages.remove(packageName); |
| 10508 | } |
| 10509 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10510 | /** |
| 10511 | * Thermal mitigation request to control functionalities at modem. |
| 10512 | * |
| 10513 | * @param subId the id of the subscription. |
| 10514 | * @param thermalMitigationRequest holds all necessary information to be passed down to modem. |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10515 | * @param callingPackage the package name of the calling package. |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10516 | * |
| 10517 | * @return thermalMitigationResult enum as defined in android.telephony.Annotation. |
| 10518 | */ |
| 10519 | @Override |
| 10520 | @ThermalMitigationResult |
| 10521 | public int sendThermalMitigationRequest( |
| 10522 | int subId, |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10523 | ThermalMitigationRequest thermalMitigationRequest, |
| 10524 | String callingPackage) throws IllegalArgumentException { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10525 | enforceModifyPermission(); |
| 10526 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10527 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 10528 | if (!getThermalMitigationAllowlist(getDefaultPhone().getContext()) |
| 10529 | .contains(callingPackage)) { |
| 10530 | throw new SecurityException("Calling package must be configured in the device config. " |
| 10531 | + "calling package: " + callingPackage); |
| 10532 | } |
| 10533 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10534 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 10535 | final long identity = Binder.clearCallingIdentity(); |
| 10536 | |
| 10537 | int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR; |
| 10538 | try { |
| 10539 | int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction(); |
| 10540 | switch (thermalMitigationAction) { |
| 10541 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING: |
| 10542 | thermalMitigationResult = |
| 10543 | handleDataThrottlingRequest(subId, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 10544 | thermalMitigationRequest.getDataThrottlingRequest(), |
| 10545 | callingPackage); |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10546 | break; |
| 10547 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY: |
| 10548 | if (thermalMitigationRequest.getDataThrottlingRequest() != null) { |
| 10549 | throw new IllegalArgumentException("dataThrottlingRequest must be null for " |
| 10550 | + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY"); |
| 10551 | } |
| 10552 | |
| 10553 | // Ensure that radio is on. If not able to power on due to phone being |
| 10554 | // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10555 | if (!setRadioPowerForThermal(true)) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10556 | thermalMitigationResult = |
| 10557 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 10558 | break; |
| 10559 | } |
| 10560 | |
| 10561 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 10562 | false, callingPackage); |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10563 | thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 10564 | break; |
| 10565 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF: |
| 10566 | if (thermalMitigationRequest.getDataThrottlingRequest() != null) { |
| 10567 | throw new IllegalArgumentException("dataThrottlingRequest must be null for" |
| 10568 | + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF"); |
| 10569 | } |
| 10570 | |
| 10571 | TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null); |
| 10572 | if (registry != null) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10573 | Phone phone = getPhone(subId); |
| 10574 | if (phone == null) { |
| 10575 | thermalMitigationResult = |
| 10576 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 10577 | break; |
| 10578 | } |
| 10579 | |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 10580 | TelephonyConnectionService service = |
| 10581 | registry.getTelephonyConnectionService(); |
Jack Nudelman | b30ac30 | 2021-06-17 15:39:58 -0700 | [diff] [blame] | 10582 | if (service != null && service.isEmergencyCallPending()) { |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 10583 | Log.e(LOG_TAG, "An emergency call is pending"); |
| 10584 | thermalMitigationResult = |
| 10585 | TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE; |
| 10586 | break; |
| 10587 | } else if (isAnyPhoneInEmergencyState()) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10588 | thermalMitigationResult = |
| 10589 | TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE; |
| 10590 | break; |
| 10591 | } |
| 10592 | } else { |
| 10593 | thermalMitigationResult = |
| 10594 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 10595 | break; |
| 10596 | } |
| 10597 | |
| 10598 | // Turn radio off. If not able to power off due to phone being unavailable, |
| 10599 | // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10600 | if (!setRadioPowerForThermal(false)) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10601 | thermalMitigationResult = |
| 10602 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 10603 | break; |
| 10604 | } |
| 10605 | thermalMitigationResult = |
| 10606 | TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 10607 | break; |
| 10608 | default: |
| 10609 | throw new IllegalArgumentException("the requested thermalMitigationAction does " |
| 10610 | + "not exist. Requested action: " + thermalMitigationAction); |
| 10611 | } |
| 10612 | } catch (IllegalArgumentException e) { |
| 10613 | throw e; |
| 10614 | } catch (Exception e) { |
| 10615 | Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e); |
| 10616 | thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 10617 | } finally { |
| 10618 | Binder.restoreCallingIdentity(identity); |
| 10619 | } |
| 10620 | |
| 10621 | if (DBG) { |
| 10622 | log("thermalMitigationRequest returning with thermalMitigationResult: " |
| 10623 | + thermalMitigationResult); |
| 10624 | } |
| 10625 | |
| 10626 | return thermalMitigationResult; |
| 10627 | } |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 10628 | |
| 10629 | /** |
| 10630 | * Set the GbaService Package Name that Telephony will bind to. |
| 10631 | * |
| 10632 | * @param subId The sim that the GbaService is associated with. |
| 10633 | * @param packageName The name of the package to be replaced with. |
| 10634 | * @return true if setting the GbaService to bind to succeeded, false if it did not. |
| 10635 | */ |
| 10636 | @Override |
| 10637 | public boolean setBoundGbaServiceOverride(int subId, String packageName) { |
| 10638 | enforceModifyPermission(); |
| 10639 | |
| 10640 | final long identity = Binder.clearCallingIdentity(); |
| 10641 | try { |
| 10642 | return getGbaManager(subId).overrideServicePackage(packageName); |
| 10643 | } finally { |
| 10644 | Binder.restoreCallingIdentity(identity); |
| 10645 | } |
| 10646 | } |
| 10647 | |
| 10648 | /** |
| 10649 | * Return the package name of the currently bound GbaService. |
| 10650 | * |
| 10651 | * @param subId The sim that the GbaService is associated with. |
| 10652 | * @return the package name of the GbaService configuration, null if GBA is not supported. |
| 10653 | */ |
| 10654 | @Override |
| 10655 | public String getBoundGbaService(int subId) { |
| 10656 | enforceReadPrivilegedPermission("getBoundGbaServicePackage"); |
| 10657 | |
| 10658 | final long identity = Binder.clearCallingIdentity(); |
| 10659 | try { |
| 10660 | return getGbaManager(subId).getServicePackage(); |
| 10661 | } finally { |
| 10662 | Binder.restoreCallingIdentity(identity); |
| 10663 | } |
| 10664 | } |
| 10665 | |
| 10666 | /** |
| 10667 | * Set the release time for telephony to unbind GbaService. |
| 10668 | * |
| 10669 | * @param subId The sim that the GbaService is associated with. |
| 10670 | * @param interval The release time to unbind GbaService by millisecond. |
| 10671 | * @return true if setting the GbaService to bind to succeeded, false if it did not. |
| 10672 | */ |
| 10673 | @Override |
| 10674 | public boolean setGbaReleaseTimeOverride(int subId, int interval) { |
| 10675 | enforceModifyPermission(); |
| 10676 | |
| 10677 | final long identity = Binder.clearCallingIdentity(); |
| 10678 | try { |
| 10679 | return getGbaManager(subId).overrideReleaseTime(interval); |
| 10680 | } finally { |
| 10681 | Binder.restoreCallingIdentity(identity); |
| 10682 | } |
| 10683 | } |
| 10684 | |
| 10685 | /** |
| 10686 | * Return the release time for telephony to unbind GbaService. |
| 10687 | * |
| 10688 | * @param subId The sim that the GbaService is associated with. |
| 10689 | * @return The release time to unbind GbaService by millisecond. |
| 10690 | */ |
| 10691 | @Override |
| 10692 | public int getGbaReleaseTime(int subId) { |
| 10693 | enforceReadPrivilegedPermission("getGbaReleaseTime"); |
| 10694 | |
| 10695 | final long identity = Binder.clearCallingIdentity(); |
| 10696 | try { |
| 10697 | return getGbaManager(subId).getReleaseTime(); |
| 10698 | } finally { |
| 10699 | Binder.restoreCallingIdentity(identity); |
| 10700 | } |
| 10701 | } |
| 10702 | |
| 10703 | private GbaManager getGbaManager(int subId) { |
| 10704 | GbaManager instance = GbaManager.getInstance(subId); |
| 10705 | if (instance == null) { |
| 10706 | String packageName = mApp.getResources().getString(R.string.config_gba_package); |
| 10707 | int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time); |
| 10708 | instance = GbaManager.make(mApp, subId, packageName, releaseTime); |
| 10709 | } |
| 10710 | return instance; |
| 10711 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10712 | |
| 10713 | /** |
| 10714 | * indicate whether the device and the carrier can support |
| 10715 | * RCS VoLTE single registration. |
| 10716 | */ |
| 10717 | @Override |
| 10718 | public boolean isRcsVolteSingleRegistrationCapable(int subId) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10719 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 10720 | Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable", |
| 10721 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 10722 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10723 | |
| 10724 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10725 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10726 | } |
| 10727 | |
| 10728 | final long identity = Binder.clearCallingIdentity(); |
| 10729 | try { |
| 10730 | RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance(); |
| 10731 | if (rpm != null) { |
Hui Wang | 67af90e | 2021-06-04 16:57:15 -0700 | [diff] [blame] | 10732 | Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId); |
| 10733 | if (isCapable != null) { |
| 10734 | return isCapable; |
| 10735 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10736 | } |
Hui Wang | 67af90e | 2021-06-04 16:57:15 -0700 | [diff] [blame] | 10737 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE, |
| 10738 | "service is temporarily unavailable."); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10739 | } finally { |
| 10740 | Binder.restoreCallingIdentity(identity); |
| 10741 | } |
| 10742 | } |
| 10743 | |
| 10744 | /** |
| 10745 | * Register RCS provisioning callback. |
| 10746 | */ |
| 10747 | @Override |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10748 | public void registerRcsProvisioningCallback(int subId, |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10749 | IRcsConfigCallback callback) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10750 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10751 | Binder.getCallingUid(), "registerRcsProvisioningCallback", |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10752 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 10753 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10754 | |
| 10755 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10756 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10757 | } |
| 10758 | if (!isImsAvailableOnDevice()) { |
| 10759 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 10760 | "IMS not available on device."); |
| 10761 | } |
| 10762 | |
| 10763 | final long identity = Binder.clearCallingIdentity(); |
| 10764 | try { |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 10765 | if (!RcsProvisioningMonitor.getInstance() |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10766 | .registerRcsProvisioningCallback(subId, callback)) { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 10767 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION, |
| 10768 | "Active subscription not found."); |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 10769 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10770 | } finally { |
| 10771 | Binder.restoreCallingIdentity(identity); |
| 10772 | } |
| 10773 | } |
| 10774 | |
| 10775 | /** |
| 10776 | * Unregister RCS provisioning callback. |
| 10777 | */ |
| 10778 | @Override |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10779 | public void unregisterRcsProvisioningCallback(int subId, |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10780 | IRcsConfigCallback callback) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10781 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10782 | Binder.getCallingUid(), "unregisterRcsProvisioningCallback", |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10783 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 10784 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10785 | |
| 10786 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10787 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10788 | } |
| 10789 | if (!isImsAvailableOnDevice()) { |
| 10790 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 10791 | "IMS not available on device."); |
| 10792 | } |
| 10793 | |
| 10794 | final long identity = Binder.clearCallingIdentity(); |
| 10795 | try { |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 10796 | RcsProvisioningMonitor.getInstance() |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10797 | .unregisterRcsProvisioningCallback(subId, callback); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10798 | } finally { |
| 10799 | Binder.restoreCallingIdentity(identity); |
| 10800 | } |
| 10801 | } |
| 10802 | |
| 10803 | /** |
| 10804 | * trigger RCS reconfiguration. |
| 10805 | */ |
| 10806 | public void triggerRcsReconfiguration(int subId) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10807 | TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(), |
| 10808 | "triggerRcsReconfiguration", |
| 10809 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10810 | |
| 10811 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10812 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10813 | } |
| 10814 | if (!isImsAvailableOnDevice()) { |
| 10815 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 10816 | "IMS not available on device."); |
| 10817 | } |
| 10818 | |
| 10819 | final long identity = Binder.clearCallingIdentity(); |
| 10820 | try { |
| 10821 | RcsProvisioningMonitor.getInstance().requestReconfig(subId); |
| 10822 | } finally { |
| 10823 | Binder.restoreCallingIdentity(identity); |
| 10824 | } |
| 10825 | } |
| 10826 | |
| 10827 | /** |
| 10828 | * Provide the client configuration parameters of the RCS application. |
| 10829 | */ |
| 10830 | public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10831 | TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(), |
| 10832 | "setRcsClientConfiguration", |
| 10833 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10834 | |
| 10835 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10836 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10837 | } |
| 10838 | if (!isImsAvailableOnDevice()) { |
| 10839 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 10840 | "IMS not available on device."); |
| 10841 | } |
| 10842 | |
| 10843 | final long identity = Binder.clearCallingIdentity(); |
| 10844 | |
| 10845 | try { |
| 10846 | IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS); |
| 10847 | if (configBinder == null) { |
| 10848 | Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration"); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 10849 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION, |
| 10850 | "could not find the requested subscription"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10851 | } else { |
| 10852 | configBinder.setRcsClientConfiguration(rcc); |
| 10853 | } |
joonhunshin | 3e15424 | 2021-09-17 06:33:39 +0000 | [diff] [blame] | 10854 | |
| 10855 | RcsStats.getInstance().onRcsClientProvisioningStats(subId, |
| 10856 | RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10857 | } catch (RemoteException e) { |
| 10858 | Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage()); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 10859 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE, |
| 10860 | "service is temporarily unavailable."); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10861 | } finally { |
| 10862 | Binder.restoreCallingIdentity(identity); |
| 10863 | } |
| 10864 | } |
| 10865 | |
| 10866 | /** |
Hui Wang | baaee6a | 2021-02-19 20:45:36 -0800 | [diff] [blame] | 10867 | * Enables or disables the test mode for RCS VoLTE single registration. |
| 10868 | */ |
| 10869 | @Override |
| 10870 | public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) { |
| 10871 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10872 | "setRcsSingleRegistrationTestModeEnabled"); |
| 10873 | |
| 10874 | RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled); |
| 10875 | } |
| 10876 | |
| 10877 | /** |
| 10878 | * Gets the test mode for RCS VoLTE single registration. |
| 10879 | */ |
| 10880 | @Override |
| 10881 | public boolean getRcsSingleRegistrationTestModeEnabled() { |
| 10882 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10883 | "getRcsSingleRegistrationTestModeEnabled"); |
| 10884 | |
| 10885 | return RcsProvisioningMonitor.getInstance().getTestModeEnabled(); |
| 10886 | } |
| 10887 | |
| 10888 | /** |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10889 | * Overrides the config of RCS VoLTE single registration enabled for the device. |
| 10890 | */ |
| 10891 | @Override |
| 10892 | public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) { |
| 10893 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10894 | "setDeviceSingleRegistrationEnabledOverride"); |
| 10895 | enforceModifyPermission(); |
| 10896 | |
| 10897 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 10898 | : Boolean.parseBoolean(enabledStr); |
| 10899 | RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled); |
Brad Ebinger | 49a72b4 | 2021-01-29 00:55:24 +0000 | [diff] [blame] | 10900 | mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10901 | } |
| 10902 | |
| 10903 | /** |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 10904 | * Sends a device to device communication message. Only usable via shell. |
| 10905 | * @param message message to send. |
| 10906 | * @param value message value. |
| 10907 | */ |
| 10908 | @Override |
| 10909 | public void sendDeviceToDeviceMessage(int message, int value) { |
| 10910 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
Tyler Gunn | babbda0 | 2021-02-10 11:05:02 -0800 | [diff] [blame] | 10911 | "sendDeviceToDeviceMessage"); |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 10912 | enforceModifyPermission(); |
| 10913 | |
| 10914 | final long identity = Binder.clearCallingIdentity(); |
| 10915 | try { |
| 10916 | TelephonyConnectionService service = |
| 10917 | TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService(); |
| 10918 | if (service == null) { |
| 10919 | Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call."); |
| 10920 | return; |
| 10921 | } |
| 10922 | service.sendTestDeviceToDeviceMessage(message, value); |
| 10923 | } finally { |
| 10924 | Binder.restoreCallingIdentity(identity); |
| 10925 | } |
| 10926 | } |
| 10927 | |
Tyler Gunn | babbda0 | 2021-02-10 11:05:02 -0800 | [diff] [blame] | 10928 | /** |
| 10929 | * Sets the specified device to device transport active. |
| 10930 | * @param transport The transport to set active. |
| 10931 | */ |
| 10932 | @Override |
| 10933 | public void setActiveDeviceToDeviceTransport(@NonNull String transport) { |
| 10934 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10935 | "setActiveDeviceToDeviceTransport"); |
| 10936 | enforceModifyPermission(); |
| 10937 | |
| 10938 | final long identity = Binder.clearCallingIdentity(); |
| 10939 | try { |
| 10940 | TelephonyConnectionService service = |
| 10941 | TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService(); |
| 10942 | if (service == null) { |
| 10943 | Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call."); |
| 10944 | return; |
| 10945 | } |
| 10946 | service.setActiveDeviceToDeviceTransport(transport); |
| 10947 | } finally { |
| 10948 | Binder.restoreCallingIdentity(identity); |
| 10949 | } |
| 10950 | } |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 10951 | |
Tyler Gunn | d433926 | 2021-05-03 14:46:49 -0700 | [diff] [blame] | 10952 | @Override |
| 10953 | public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) { |
| 10954 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10955 | "setDeviceToDeviceForceEnabled"); |
| 10956 | |
| 10957 | final long identity = Binder.clearCallingIdentity(); |
| 10958 | try { |
| 10959 | Arrays.stream(PhoneFactory.getPhones()).forEach( |
| 10960 | p -> { |
| 10961 | Phone thePhone = p.getImsPhone(); |
| 10962 | if (thePhone != null && thePhone instanceof ImsPhone) { |
| 10963 | ImsPhone imsPhone = (ImsPhone) thePhone; |
| 10964 | CallTracker tracker = imsPhone.getCallTracker(); |
| 10965 | if (tracker != null && tracker instanceof ImsPhoneCallTracker) { |
| 10966 | ImsPhoneCallTracker imsPhoneCallTracker = |
| 10967 | (ImsPhoneCallTracker) tracker; |
| 10968 | imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled); |
| 10969 | } |
| 10970 | } |
| 10971 | } |
| 10972 | ); |
| 10973 | } finally { |
| 10974 | Binder.restoreCallingIdentity(identity); |
| 10975 | } |
| 10976 | } |
| 10977 | |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 10978 | /** |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10979 | * Gets the config of RCS VoLTE single registration enabled for the device. |
| 10980 | */ |
| 10981 | @Override |
| 10982 | public boolean getDeviceSingleRegistrationEnabled() { |
| 10983 | enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled"); |
| 10984 | return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled(); |
| 10985 | } |
| 10986 | |
| 10987 | /** |
| 10988 | * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription. |
| 10989 | */ |
| 10990 | @Override |
| 10991 | public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) { |
| 10992 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10993 | "setCarrierSingleRegistrationEnabledOverride"); |
| 10994 | enforceModifyPermission(); |
| 10995 | |
| 10996 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 10997 | : Boolean.parseBoolean(enabledStr); |
| 10998 | return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled( |
| 10999 | subId, enabled); |
| 11000 | } |
| 11001 | |
| 11002 | /** |
| 11003 | * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription. |
| 11004 | */ |
| 11005 | @Override |
| 11006 | public boolean getCarrierSingleRegistrationEnabled(int subId) { |
| 11007 | enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled"); |
| 11008 | return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId); |
| 11009 | } |
Chiachang Wang | d6d3477 | 2020-12-22 11:38:27 +0800 | [diff] [blame] | 11010 | |
| 11011 | /** |
Hui Wang | b647abe | 2021-02-26 09:33:38 -0800 | [diff] [blame] | 11012 | * Overrides the ims feature validation result |
| 11013 | */ |
| 11014 | @Override |
| 11015 | public boolean setImsFeatureValidationOverride(int subId, String enabledStr) { |
| 11016 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11017 | "setImsFeatureValidationOverride"); |
| 11018 | |
| 11019 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 11020 | : Boolean.parseBoolean(enabledStr); |
| 11021 | return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation( |
| 11022 | subId, enabled); |
| 11023 | } |
| 11024 | |
| 11025 | /** |
| 11026 | * Gets the ims feature validation override value |
| 11027 | */ |
| 11028 | @Override |
| 11029 | public boolean getImsFeatureValidationOverride(int subId) { |
| 11030 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11031 | "getImsFeatureValidationOverride"); |
| 11032 | return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId); |
| 11033 | } |
| 11034 | |
| 11035 | /** |
Chiachang Wang | d6d3477 | 2020-12-22 11:38:27 +0800 | [diff] [blame] | 11036 | * Get the mobile provisioning url that is used to launch a browser to allow users to manage |
| 11037 | * their mobile plan. |
| 11038 | */ |
| 11039 | @Override |
| 11040 | public String getMobileProvisioningUrl() { |
| 11041 | enforceReadPrivilegedPermission("getMobileProvisioningUrl"); |
| 11042 | final long identity = Binder.clearCallingIdentity(); |
| 11043 | try { |
| 11044 | return getDefaultPhone().getMobileProvisioningUrl(); |
| 11045 | } finally { |
| 11046 | Binder.restoreCallingIdentity(identity); |
| 11047 | } |
| 11048 | } |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11049 | |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 11050 | /** |
calvinpan | e4a8a1d | 2021-01-25 13:51:18 +0800 | [diff] [blame] | 11051 | * Get the EAB contact from the EAB database. |
| 11052 | */ |
| 11053 | @Override |
| 11054 | public String getContactFromEab(String contact) { |
| 11055 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab"); |
| 11056 | enforceModifyPermission(); |
| 11057 | final long identity = Binder.clearCallingIdentity(); |
| 11058 | try { |
| 11059 | return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact); |
| 11060 | } finally { |
| 11061 | Binder.restoreCallingIdentity(identity); |
| 11062 | } |
| 11063 | } |
| 11064 | |
| 11065 | /** |
Calvin Pan | a143432 | 2021-07-01 19:27:01 +0800 | [diff] [blame] | 11066 | * Get the EAB capability from the EAB database. |
| 11067 | */ |
| 11068 | @Override |
| 11069 | public String getCapabilityFromEab(String contact) { |
| 11070 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab"); |
| 11071 | enforceModifyPermission(); |
| 11072 | final long identity = Binder.clearCallingIdentity(); |
| 11073 | try { |
| 11074 | return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact); |
| 11075 | } finally { |
| 11076 | Binder.restoreCallingIdentity(identity); |
| 11077 | } |
| 11078 | } |
| 11079 | |
| 11080 | /** |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 11081 | * Remove the EAB contacts from the EAB database. |
| 11082 | */ |
| 11083 | @Override |
| 11084 | public int removeContactFromEab(int subId, String contacts) { |
| 11085 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab"); |
| 11086 | enforceModifyPermission(); |
| 11087 | final long identity = Binder.clearCallingIdentity(); |
| 11088 | try { |
| 11089 | return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext()); |
| 11090 | } finally { |
| 11091 | Binder.restoreCallingIdentity(identity); |
| 11092 | } |
| 11093 | } |
| 11094 | |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11095 | @Override |
James.cf Lin | 4b784aa | 2021-01-31 03:25:15 +0800 | [diff] [blame] | 11096 | public boolean getDeviceUceEnabled() { |
| 11097 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled"); |
| 11098 | final long identity = Binder.clearCallingIdentity(); |
| 11099 | try { |
| 11100 | return mApp.getDeviceUceEnabled(); |
| 11101 | } finally { |
| 11102 | Binder.restoreCallingIdentity(identity); |
| 11103 | } |
| 11104 | } |
| 11105 | |
| 11106 | @Override |
| 11107 | public void setDeviceUceEnabled(boolean isEnabled) { |
| 11108 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled"); |
| 11109 | final long identity = Binder.clearCallingIdentity(); |
| 11110 | try { |
| 11111 | mApp.setDeviceUceEnabled(isEnabled); |
| 11112 | } finally { |
| 11113 | Binder.restoreCallingIdentity(identity); |
| 11114 | } |
| 11115 | } |
| 11116 | |
Brad Ebinger | 14d467f | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 11117 | /** |
| 11118 | * Add new feature tags to the Set used to calculate the capabilities in PUBLISH. |
| 11119 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 11120 | */ |
| 11121 | // Used for SHELL command only right now. |
| 11122 | @Override |
| 11123 | public RcsContactUceCapability addUceRegistrationOverrideShell(int subId, |
| 11124 | List<String> featureTags) { |
| 11125 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11126 | "addUceRegistrationOverrideShell"); |
| 11127 | final long identity = Binder.clearCallingIdentity(); |
| 11128 | try { |
| 11129 | return mApp.imsRcsController.addUceRegistrationOverrideShell(subId, |
| 11130 | new ArraySet<>(featureTags)); |
| 11131 | } catch (ImsException e) { |
| 11132 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 11133 | } finally { |
| 11134 | Binder.restoreCallingIdentity(identity); |
| 11135 | } |
| 11136 | } |
| 11137 | |
| 11138 | /** |
| 11139 | * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH. |
| 11140 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 11141 | */ |
| 11142 | // Used for SHELL command only right now. |
| 11143 | @Override |
| 11144 | public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId, |
| 11145 | List<String> featureTags) { |
| 11146 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11147 | "removeUceRegistrationOverrideShell"); |
| 11148 | final long identity = Binder.clearCallingIdentity(); |
| 11149 | try { |
| 11150 | return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId, |
| 11151 | new ArraySet<>(featureTags)); |
| 11152 | } catch (ImsException e) { |
| 11153 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 11154 | } finally { |
| 11155 | Binder.restoreCallingIdentity(identity); |
| 11156 | } |
| 11157 | } |
| 11158 | |
| 11159 | /** |
| 11160 | * Clear all overrides in the Set used to calculate the capabilities in PUBLISH. |
| 11161 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 11162 | */ |
| 11163 | // Used for SHELL command only right now. |
| 11164 | @Override |
| 11165 | public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) { |
| 11166 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11167 | "clearUceRegistrationOverrideShell"); |
| 11168 | final long identity = Binder.clearCallingIdentity(); |
| 11169 | try { |
| 11170 | return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId); |
| 11171 | } catch (ImsException e) { |
| 11172 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 11173 | } finally { |
| 11174 | Binder.restoreCallingIdentity(identity); |
| 11175 | } |
| 11176 | } |
| 11177 | |
| 11178 | /** |
| 11179 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 11180 | */ |
| 11181 | // Used for SHELL command only right now. |
| 11182 | @Override |
| 11183 | public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) { |
| 11184 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11185 | "getLatestRcsContactUceCapabilityShell"); |
| 11186 | final long identity = Binder.clearCallingIdentity(); |
| 11187 | try { |
| 11188 | return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId); |
| 11189 | } catch (ImsException e) { |
| 11190 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 11191 | } finally { |
| 11192 | Binder.restoreCallingIdentity(identity); |
| 11193 | } |
| 11194 | } |
| 11195 | |
| 11196 | /** |
| 11197 | * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the |
| 11198 | * device does not have an active PUBLISH. |
| 11199 | */ |
| 11200 | // Used for SHELL command only right now. |
| 11201 | @Override |
| 11202 | public String getLastUcePidfXmlShell(int subId) { |
| 11203 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml"); |
| 11204 | final long identity = Binder.clearCallingIdentity(); |
| 11205 | try { |
| 11206 | return mApp.imsRcsController.getLastUcePidfXmlShell(subId); |
| 11207 | } catch (ImsException e) { |
| 11208 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 11209 | } finally { |
| 11210 | Binder.restoreCallingIdentity(identity); |
| 11211 | } |
| 11212 | } |
| 11213 | |
James.cf Lin | e8713a4 | 2021-04-29 16:04:26 +0800 | [diff] [blame] | 11214 | /** |
| 11215 | * Remove UCE requests cannot be sent to the network status. |
| 11216 | */ |
| 11217 | // Used for SHELL command only right now. |
| 11218 | @Override |
| 11219 | public boolean removeUceRequestDisallowedStatus(int subId) { |
| 11220 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus"); |
| 11221 | final long identity = Binder.clearCallingIdentity(); |
| 11222 | try { |
| 11223 | return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId); |
| 11224 | } catch (ImsException e) { |
| 11225 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 11226 | } finally { |
| 11227 | Binder.restoreCallingIdentity(identity); |
| 11228 | } |
| 11229 | } |
| 11230 | |
James.cf Lin | 18bb900 | 2021-05-25 01:37:38 +0800 | [diff] [blame] | 11231 | /** |
| 11232 | * Remove UCE requests cannot be sent to the network status. |
| 11233 | */ |
| 11234 | // Used for SHELL command only. |
| 11235 | @Override |
| 11236 | public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) { |
| 11237 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout"); |
| 11238 | final long identity = Binder.clearCallingIdentity(); |
| 11239 | try { |
| 11240 | return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs); |
| 11241 | } catch (ImsException e) { |
| 11242 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 11243 | } finally { |
| 11244 | Binder.restoreCallingIdentity(identity); |
| 11245 | } |
| 11246 | } |
Brad Ebinger | 14d467f | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 11247 | |
James.cf Lin | 4b784aa | 2021-01-31 03:25:15 +0800 | [diff] [blame] | 11248 | @Override |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11249 | public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request, |
| 11250 | String callingPackage) { |
| 11251 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 11252 | mApp, subId, "setSignalStrengthUpdateRequest"); |
| 11253 | |
| 11254 | final int callingUid = Binder.getCallingUid(); |
| 11255 | // Verify that tha callingPackage belongs to the calling UID |
| 11256 | mApp.getSystemService(AppOpsManager.class) |
| 11257 | .checkPackage(callingUid, callingPackage); |
| 11258 | |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 11259 | validateSignalStrengthUpdateRequest(mApp, request, callingUid); |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11260 | |
| 11261 | final long identity = Binder.clearCallingIdentity(); |
| 11262 | try { |
| 11263 | Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST, |
| 11264 | new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId); |
| 11265 | |
| 11266 | if (result instanceof IllegalStateException) { |
| 11267 | throw (IllegalStateException) result; |
| 11268 | } |
| 11269 | } finally { |
| 11270 | Binder.restoreCallingIdentity(identity); |
| 11271 | } |
| 11272 | } |
| 11273 | |
| 11274 | @Override |
| 11275 | public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request, |
| 11276 | String callingPackage) { |
| 11277 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 11278 | mApp, subId, "clearSignalStrengthUpdateRequest"); |
| 11279 | |
| 11280 | final int callingUid = Binder.getCallingUid(); |
| 11281 | // Verify that tha callingPackage belongs to the calling UID |
| 11282 | mApp.getSystemService(AppOpsManager.class) |
| 11283 | .checkPackage(callingUid, callingPackage); |
| 11284 | |
| 11285 | final long identity = Binder.clearCallingIdentity(); |
| 11286 | try { |
| 11287 | Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST, |
| 11288 | new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId); |
| 11289 | |
| 11290 | if (result instanceof IllegalStateException) { |
| 11291 | throw (IllegalStateException) result; |
| 11292 | } |
| 11293 | } finally { |
| 11294 | Binder.restoreCallingIdentity(identity); |
| 11295 | } |
| 11296 | } |
| 11297 | |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 11298 | private static void validateSignalStrengthUpdateRequest(Context context, |
| 11299 | SignalStrengthUpdateRequest request, int callingUid) { |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11300 | if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) { |
| 11301 | // phone/system process do not have further restriction on request |
| 11302 | return; |
| 11303 | } |
| 11304 | |
| 11305 | // Applications has restrictions on how to use the request: |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 11306 | // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11307 | if (request.isSystemThresholdReportingRequestedWhileIdle()) { |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 11308 | context.enforceCallingOrSelfPermission( |
| 11309 | android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH, |
| 11310 | "validateSignalStrengthUpdateRequest"); |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11311 | } |
| 11312 | |
| 11313 | for (SignalThresholdInfo info : request.getSignalThresholdInfos()) { |
Nagendra Prasad Nagarle Basavaraju | fee544c | 2022-12-07 16:34:52 +0000 | [diff] [blame] | 11314 | // Only system caller can set mHysteresisMs/mIsEnabled. |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11315 | if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11316 | || info.isEnabled()) { |
| 11317 | throw new IllegalArgumentException( |
| 11318 | "Only system can set hide fields in SignalThresholdInfo"); |
| 11319 | } |
| 11320 | |
| 11321 | // Thresholds length for each RAN need in range. This has been validated in |
| 11322 | // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method |
| 11323 | // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds |
| 11324 | final int[] thresholds = info.getThresholds(); |
| 11325 | Objects.requireNonNull(thresholds); |
| 11326 | if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed() |
| 11327 | || thresholds.length |
| 11328 | > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) { |
| 11329 | throw new IllegalArgumentException( |
| 11330 | "thresholds length is out of range: " + thresholds.length); |
| 11331 | } |
| 11332 | } |
| 11333 | } |
SongFerngWang | 8236caa | 2021-01-17 21:51:44 +0800 | [diff] [blame] | 11334 | |
| 11335 | /** |
| 11336 | * Gets the current phone capability. |
| 11337 | * |
| 11338 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 11339 | * @return the PhoneCapability which describes the data connection capability of modem. |
| 11340 | * It's used to evaluate possible phone config change, for example from single |
| 11341 | * SIM device to multi-SIM device. |
| 11342 | */ |
| 11343 | @Override |
| 11344 | public PhoneCapability getPhoneCapability() { |
| 11345 | enforceReadPrivilegedPermission("getPhoneCapability"); |
| 11346 | final long identity = Binder.clearCallingIdentity(); |
| 11347 | try { |
| 11348 | return mPhoneConfigurationManager.getCurrentPhoneCapability(); |
| 11349 | } finally { |
| 11350 | Binder.restoreCallingIdentity(identity); |
| 11351 | } |
| 11352 | } |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 11353 | |
| 11354 | /** |
| 11355 | * Prepare TelephonyManager for an unattended reboot. The reboot is |
| 11356 | * required to be done shortly after the API is invoked. |
| 11357 | */ |
| 11358 | @Override |
| 11359 | @TelephonyManager.PrepareUnattendedRebootResult |
| 11360 | public int prepareForUnattendedReboot() { |
Rafael Higuera Silva | d963064 | 2021-09-20 15:32:01 +0000 | [diff] [blame] | 11361 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 11362 | enforceRebootPermission(); |
| 11363 | |
| 11364 | final long identity = Binder.clearCallingIdentity(); |
| 11365 | try { |
Rafael Higuera Silva | d963064 | 2021-09-20 15:32:01 +0000 | [diff] [blame] | 11366 | return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 11367 | } finally { |
| 11368 | Binder.restoreCallingIdentity(identity); |
| 11369 | } |
| 11370 | } |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 11371 | |
| 11372 | /** |
| 11373 | * Request to get the current slicing configuration including URSP rules and |
| 11374 | * NSSAIs (configured, allowed and rejected). |
| 11375 | * |
| 11376 | * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission. |
| 11377 | */ |
| 11378 | @Override |
| 11379 | public void getSlicingConfig(ResultReceiver callback) { |
Hongbo Zeng | 1b2063d | 2022-02-21 01:33:03 +0000 | [diff] [blame] | 11380 | TelephonyPermissions |
| 11381 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 11382 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, "getSlicingConfig"); |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 11383 | |
| 11384 | final long identity = Binder.clearCallingIdentity(); |
| 11385 | try { |
| 11386 | Phone phone = getDefaultPhone(); |
| 11387 | sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null); |
| 11388 | } finally { |
| 11389 | Binder.restoreCallingIdentity(identity); |
| 11390 | } |
| 11391 | } |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 11392 | |
| 11393 | /** |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 11394 | * Check whether the given premium capability is available for purchase from the carrier. |
| 11395 | * |
| 11396 | * @param capability The premium capability to check. |
| 11397 | * @param subId The subId to check the premium capability for. |
| 11398 | * |
| 11399 | * @return Whether the given premium capability is available to purchase. |
| 11400 | */ |
| 11401 | @Override |
| 11402 | public boolean isPremiumCapabilityAvailableForPurchase(int capability, int subId) { |
| 11403 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 11404 | mApp, "isPremiumCapabilityAvailableForPurchase")) { |
| 11405 | log("Premium capability " |
| 11406 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 11407 | + " is not available for purchase due to missing permissions."); |
| 11408 | throw new SecurityException("isPremiumCapabilityAvailableForPurchase requires " |
| 11409 | + "permission READ_BASIC_PHONE_STATE."); |
| 11410 | } |
| 11411 | |
| 11412 | Phone phone = getPhone(subId); |
Thomas Nguyen | 7216ed6 | 2022-11-29 16:45:31 -0800 | [diff] [blame] | 11413 | if (phone == null) { |
| 11414 | loge("isPremiumCapabilityAvailableForPurchase: phone is null, subId=" + subId); |
| 11415 | return false; |
| 11416 | } |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 11417 | final long identity = Binder.clearCallingIdentity(); |
| 11418 | try { |
Sarah Chin | 46355ba | 2022-11-01 23:51:16 -0700 | [diff] [blame] | 11419 | return SlicePurchaseController.getInstance(phone) |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 11420 | .isPremiumCapabilityAvailableForPurchase(capability); |
| 11421 | } finally { |
| 11422 | Binder.restoreCallingIdentity(identity); |
| 11423 | } |
| 11424 | } |
| 11425 | |
| 11426 | /** |
| 11427 | * Purchase the given premium capability from the carrier. |
| 11428 | * |
| 11429 | * @param capability The premium capability to purchase. |
| 11430 | * @param callback The result of the purchase request. |
| 11431 | * @param subId The subId to purchase the premium capability for. |
| 11432 | */ |
| 11433 | @Override |
| 11434 | public void purchasePremiumCapability(int capability, IIntegerConsumer callback, int subId) { |
| 11435 | log("purchasePremiumCapability: capability=" |
| 11436 | + TelephonyManager.convertPremiumCapabilityToString(capability) + ", caller=" |
| 11437 | + getCurrentPackageName()); |
| 11438 | |
| 11439 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 11440 | mApp, "purchasePremiumCapability")) { |
| 11441 | log("purchasePremiumCapability " |
| 11442 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 11443 | + " failed due to missing permissions."); |
| 11444 | throw new SecurityException("purchasePremiumCapability requires permission " |
| 11445 | + "READ_BASIC_PHONE_STATE."); |
| 11446 | } |
| 11447 | |
| 11448 | Phone phone = getPhone(subId); |
Sarah Chin | 1969411 | 2022-12-06 15:41:37 -0800 | [diff] [blame] | 11449 | if (phone == null) { |
| 11450 | try { |
| 11451 | int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_REQUEST_FAILED; |
| 11452 | callback.accept(result); |
| 11453 | loge("purchasePremiumCapability: phone is null, subId=" + subId); |
| 11454 | } catch (RemoteException e) { |
| 11455 | String logStr = "Purchase premium capability " |
| 11456 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 11457 | + " failed due to RemoteException handling null phone: " + e; |
| 11458 | if (DBG) log(logStr); |
| 11459 | AnomalyReporter.reportAnomaly( |
| 11460 | UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr); |
| 11461 | } |
| 11462 | return; |
| 11463 | } |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 11464 | String appName; |
| 11465 | try { |
| 11466 | appName = mApp.getPackageManager().getApplicationLabel(mApp.getPackageManager() |
| 11467 | .getApplicationInfo(getCurrentPackageName(), 0)).toString(); |
| 11468 | } catch (PackageManager.NameNotFoundException e) { |
| 11469 | appName = "An application"; |
| 11470 | } |
| 11471 | sendRequestAsync(CMD_PURCHASE_PREMIUM_CAPABILITY, |
| 11472 | new PurchasePremiumCapabilityArgument(capability, appName, callback), phone, null); |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 11473 | } |
| 11474 | |
| 11475 | /** |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 11476 | * Register an IMS connection state callback |
| 11477 | */ |
| 11478 | @Override |
Hunsuk Choi | 89bd22c | 2021-11-01 13:04:54 +0000 | [diff] [blame] | 11479 | public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb, |
| 11480 | String callingPackage) { |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 11481 | if (feature == ImsFeature.FEATURE_MMTEL) { |
| 11482 | // ImsMmTelManager |
| 11483 | // The following also checks READ_PRIVILEGED_PHONE_STATE. |
| 11484 | TelephonyPermissions |
| 11485 | .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 11486 | mApp, subId, "registerImsStateCallback"); |
| 11487 | } else if (feature == ImsFeature.FEATURE_RCS) { |
| 11488 | // ImsRcsManager or SipDelegateManager |
| 11489 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 11490 | Binder.getCallingUid(), "registerImsStateCallback", |
| 11491 | Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
| 11492 | Manifest.permission.READ_PRECISE_PHONE_STATE, |
| 11493 | Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE, |
| 11494 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
| 11495 | } |
| 11496 | |
| 11497 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 11498 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 11499 | "IMS not available on device."); |
| 11500 | } |
| 11501 | |
| 11502 | if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) { |
| 11503 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 11504 | } |
| 11505 | |
| 11506 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 11507 | if (controller == null) { |
| 11508 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 11509 | "IMS not available on device."); |
| 11510 | } |
| 11511 | |
Hunsuk Choi | 89bd22c | 2021-11-01 13:04:54 +0000 | [diff] [blame] | 11512 | if (callingPackage == null) { |
| 11513 | callingPackage = getCurrentPackageName(); |
| 11514 | } |
| 11515 | |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 11516 | final long token = Binder.clearCallingIdentity(); |
| 11517 | try { |
| 11518 | int slotId = getSlotIndexOrException(subId); |
Hunsuk Choi | 89bd22c | 2021-11-01 13:04:54 +0000 | [diff] [blame] | 11519 | controller.registerImsStateCallback(subId, feature, cb, callingPackage); |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 11520 | } catch (ImsException e) { |
| 11521 | throw new ServiceSpecificException(e.getCode()); |
| 11522 | } finally { |
| 11523 | Binder.restoreCallingIdentity(token); |
| 11524 | } |
| 11525 | } |
| 11526 | |
| 11527 | /** |
| 11528 | * Unregister an IMS connection state callback |
| 11529 | */ |
| 11530 | @Override |
| 11531 | public void unregisterImsStateCallback(IImsStateCallback cb) { |
| 11532 | final long token = Binder.clearCallingIdentity(); |
| 11533 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 11534 | if (controller == null) { |
| 11535 | return; |
| 11536 | } |
| 11537 | try { |
| 11538 | controller.unregisterImsStateCallback(cb); |
| 11539 | } finally { |
| 11540 | Binder.restoreCallingIdentity(token); |
| 11541 | } |
| 11542 | } |
Sooraj Sasindran | fae41b3 | 2021-10-26 02:10:05 -0700 | [diff] [blame] | 11543 | |
| 11544 | /** |
| 11545 | * @return {@CellIdentity} last known cell identity {@CellIdentity}. |
| 11546 | * |
| 11547 | * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and |
| 11548 | * com.android.phone.permission.ACCESS_LAST_KNOWN_CELL_ID, otherwise throws |
| 11549 | * SecurityException. |
| 11550 | * If there is current registered network this value will be same as the registered cell |
| 11551 | * identity. If the device goes out of service the previous cell identity is cached and |
| 11552 | * will be returned. If the cache age of the Cell identity is more than 24 hours |
| 11553 | * it will be cleared and null will be returned. |
| 11554 | * |
| 11555 | */ |
| 11556 | @Override |
| 11557 | public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage, |
| 11558 | String callingFeatureId) { |
| 11559 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 11560 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 11561 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 11562 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 11563 | .setCallingPackage(callingPackage) |
| 11564 | .setCallingFeatureId(callingFeatureId) |
| 11565 | .setCallingPid(Binder.getCallingPid()) |
| 11566 | .setCallingUid(Binder.getCallingUid()) |
| 11567 | .setMethod("getLastKnownCellIdentity") |
| 11568 | .setLogAsInfo(true) |
| 11569 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 11570 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 11571 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 11572 | .build()); |
| 11573 | |
| 11574 | boolean hasFinePermission = |
| 11575 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 11576 | if (!hasFinePermission |
| 11577 | || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) { |
| 11578 | throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION " |
Rambo Wang | 918993a | 2022-04-27 09:08:36 -0700 | [diff] [blame] | 11579 | + "and ACCESS_LAST_KNOWN_CELL_ID permission."); |
Sooraj Sasindran | fae41b3 | 2021-10-26 02:10:05 -0700 | [diff] [blame] | 11580 | } |
| 11581 | |
| 11582 | final long identity = Binder.clearCallingIdentity(); |
| 11583 | try { |
| 11584 | Phone phone = getPhone(subId); |
| 11585 | if (phone == null) return null; |
| 11586 | ServiceStateTracker sst = phone.getServiceStateTracker(); |
| 11587 | if (sst == null) return null; |
| 11588 | return sst.getLastKnownCellIdentity(); |
| 11589 | } finally { |
| 11590 | Binder.restoreCallingIdentity(identity); |
| 11591 | } |
| 11592 | } |
Jack Yu | 4c0a550 | 2021-12-03 23:58:26 -0800 | [diff] [blame] | 11593 | |
jimsun | 3b9ccac | 2021-10-26 15:01:23 +0800 | [diff] [blame] | 11594 | /** |
| 11595 | * Sets the modem service class Name that Telephony will bind to. |
| 11596 | * |
| 11597 | * @param serviceName The class name of the modem service. |
| 11598 | * @return true if the operation is succeed, otherwise false. |
| 11599 | */ |
| 11600 | public boolean setModemService(String serviceName) { |
| 11601 | Log.d(LOG_TAG, "setModemService - " + serviceName); |
| 11602 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService"); |
| 11603 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 11604 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 11605 | "setModemService"); |
| 11606 | return mPhoneConfigurationManager.setModemService(serviceName); |
| 11607 | } |
| 11608 | |
| 11609 | /** |
| 11610 | * Return the class name of the currently bounded modem service. |
| 11611 | * |
| 11612 | * @return the class name of the modem service. |
| 11613 | */ |
| 11614 | public String getModemService() { |
| 11615 | String result; |
| 11616 | Log.d(LOG_TAG, "getModemService"); |
| 11617 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService"); |
| 11618 | TelephonyPermissions |
| 11619 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 11620 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 11621 | "getModemService"); |
| 11622 | result = mPhoneConfigurationManager.getModemService(); |
| 11623 | Log.d(LOG_TAG, "result = " + result); |
| 11624 | return result; |
| 11625 | } |
Hunter Knepshield | 2b076fa | 2022-01-19 02:26:22 -0800 | [diff] [blame] | 11626 | |
| 11627 | @Override |
| 11628 | public void setVoiceServiceStateOverride(int subId, boolean hasService, String callingPackage) { |
| 11629 | // Only telecom (and shell, for CTS purposes) is allowed to call this method. |
| 11630 | mApp.enforceCallingOrSelfPermission( |
| 11631 | permission.BIND_TELECOM_CONNECTION_SERVICE, "setVoiceServiceStateOverride"); |
| 11632 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 11633 | |
| 11634 | final long identity = Binder.clearCallingIdentity(); |
| 11635 | try { |
| 11636 | Phone phone = getPhone(subId); |
| 11637 | if (phone == null) return; |
| 11638 | phone.setVoiceServiceStateOverride(hasService); |
| 11639 | } finally { |
| 11640 | Binder.restoreCallingIdentity(identity); |
| 11641 | } |
| 11642 | } |
Muralidhar Reddy | 4e5a801 | 2022-05-11 14:49:00 +0000 | [diff] [blame] | 11643 | |
| 11644 | /** |
| 11645 | * set removable eSIM as default eUICC. |
| 11646 | * |
| 11647 | * @hide |
| 11648 | */ |
| 11649 | @Override |
| 11650 | public void setRemovableEsimAsDefaultEuicc(boolean isDefault, String callingPackage) { |
| 11651 | enforceModifyPermission(); |
| 11652 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 11653 | |
| 11654 | final long identity = Binder.clearCallingIdentity(); |
| 11655 | try { |
| 11656 | UiccController.getInstance().setRemovableEsimAsDefaultEuicc(isDefault); |
| 11657 | } finally { |
| 11658 | Binder.restoreCallingIdentity(identity); |
| 11659 | } |
| 11660 | } |
| 11661 | |
| 11662 | /** |
| 11663 | * Returns whether the removable eSIM is default eUICC or not. |
| 11664 | * |
| 11665 | * @hide |
| 11666 | */ |
| 11667 | @Override |
| 11668 | public boolean isRemovableEsimDefaultEuicc(String callingPackage) { |
| 11669 | enforceReadPrivilegedPermission("isRemovableEsimDefaultEuicc"); |
| 11670 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 11671 | |
| 11672 | final long identity = Binder.clearCallingIdentity(); |
| 11673 | try { |
| 11674 | return UiccController.getInstance().isRemovableEsimDefaultEuicc(); |
| 11675 | } finally { |
| 11676 | Binder.restoreCallingIdentity(identity); |
| 11677 | } |
| 11678 | } |
| 11679 | |
Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame] | 11680 | /** |
| 11681 | * Get the component name of the default app to direct respond-via-message intent for the |
| 11682 | * user associated with this subscription, update the cache if there is no respond-via-message |
| 11683 | * application currently configured for this user. |
| 11684 | * @return component name of the app and class to direct Respond Via Message intent to, or |
| 11685 | * {@code null} if the functionality is not supported. |
| 11686 | * @hide |
| 11687 | */ |
| 11688 | @Override |
| 11689 | public @Nullable ComponentName getDefaultRespondViaMessageApplication(int subId, |
| 11690 | boolean updateIfNeeded) { |
| 11691 | enforceInteractAcrossUsersPermission("getDefaultRespondViaMessageApplication"); |
Muralidhar Reddy | 4e5a801 | 2022-05-11 14:49:00 +0000 | [diff] [blame] | 11692 | |
Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame] | 11693 | Context context = getPhone(subId).getContext(); |
| 11694 | UserHandle userHandle = null; |
| 11695 | final long identity = Binder.clearCallingIdentity(); |
| 11696 | try { |
| 11697 | userHandle = TelephonyUtils.getSubscriptionUserHandle(context, subId); |
| 11698 | } finally { |
| 11699 | Binder.restoreCallingIdentity(identity); |
| 11700 | } |
| 11701 | return SmsApplication.getDefaultRespondViaMessageApplicationAsUser(context, |
| 11702 | updateIfNeeded, userHandle); |
| 11703 | } |
Jack Yu | f5badd9 | 2022-12-08 00:50:53 -0800 | [diff] [blame] | 11704 | |
| 11705 | /** |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 11706 | * Set whether the device is able to connect with null ciphering or integrity |
| 11707 | * algorithms. This is a global setting and will apply to all active subscriptions |
| 11708 | * and all new subscriptions after this. |
| 11709 | * |
| 11710 | * @param enabled when true, null cipher and integrity algorithms are allowed. |
| 11711 | * @hide |
| 11712 | */ |
| 11713 | @Override |
| 11714 | @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 11715 | public void setNullCipherAndIntegrityEnabled(boolean enabled) { |
| 11716 | enforceModifyPermission(); |
| 11717 | checkForNullCipherAndIntegritySupport(); |
| 11718 | |
| 11719 | // Persist the state of our preference. Each GsmCdmaPhone instance is responsible |
| 11720 | // for listening to these preference changes and applying them immediately. |
| 11721 | SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 11722 | editor.putBoolean(Phone.PREF_NULL_CIPHER_AND_INTEGRITY_ENABLED, enabled); |
| 11723 | editor.apply(); |
| 11724 | |
| 11725 | for (Phone phone: PhoneFactory.getPhones()) { |
| 11726 | phone.handleNullCipherEnabledChange(); |
| 11727 | } |
| 11728 | } |
| 11729 | |
| 11730 | |
| 11731 | /** |
| 11732 | * Get whether the device is able to connect with null ciphering or integrity |
| 11733 | * algorithms. Note that this retrieves the phone-global preference and not |
| 11734 | * the state of the radio. |
| 11735 | * |
| 11736 | * @throws SecurityException if {@link permission#MODIFY_PHONE_STATE} is not satisfied |
| 11737 | * @throws UnsupportedOperationException if the device does not support the minimum HAL |
| 11738 | * version for this feature. |
| 11739 | * @hide |
| 11740 | */ |
| 11741 | @Override |
| 11742 | @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) |
| 11743 | public boolean isNullCipherAndIntegrityPreferenceEnabled() { |
| 11744 | enforceReadPermission(); |
| 11745 | checkForNullCipherAndIntegritySupport(); |
| 11746 | return getDefaultPhone().getNullCipherAndIntegrityEnabledPreference(); |
| 11747 | } |
| 11748 | |
| 11749 | private void checkForNullCipherAndIntegritySupport() { |
| 11750 | if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_NULL_CIPHER_AND_INTEGRITY_VERSION) { |
| 11751 | throw new UnsupportedOperationException( |
| 11752 | "Null cipher and integrity operations require HAL 2.1 or above"); |
| 11753 | } |
| 11754 | } |
| 11755 | |
| 11756 | /** |
Jack Yu | f5badd9 | 2022-12-08 00:50:53 -0800 | [diff] [blame] | 11757 | * Get the SIM state for the slot index. |
| 11758 | * For Remote-SIMs, this method returns {@link IccCardConstants.State#UNKNOWN} |
| 11759 | * |
| 11760 | * @return SIM state as the ordinal of {@link IccCardConstants.State} |
| 11761 | */ |
| 11762 | @Override |
| 11763 | @SimState |
| 11764 | public int getSimStateForSlotIndex(int slotIndex) { |
| 11765 | IccCardConstants.State simState; |
| 11766 | if (slotIndex < 0) { |
| 11767 | simState = IccCardConstants.State.UNKNOWN; |
| 11768 | } else { |
| 11769 | Phone phone = null; |
| 11770 | try { |
| 11771 | phone = PhoneFactory.getPhone(slotIndex); |
| 11772 | } catch (IllegalStateException e) { |
| 11773 | // ignore |
| 11774 | } |
| 11775 | if (phone == null) { |
| 11776 | simState = IccCardConstants.State.UNKNOWN; |
| 11777 | } else { |
| 11778 | IccCard icc = phone.getIccCard(); |
| 11779 | if (icc == null) { |
| 11780 | simState = IccCardConstants.State.UNKNOWN; |
| 11781 | } else { |
| 11782 | simState = icc.getState(); |
| 11783 | } |
| 11784 | } |
| 11785 | } |
| 11786 | return simState.ordinal(); |
| 11787 | } |
Hui Wang | 9b5793a | 2022-12-05 14:38:06 -0600 | [diff] [blame] | 11788 | |
| 11789 | /** |
| 11790 | * Get current cell broadcast ranges. |
| 11791 | */ |
| 11792 | @Override |
| 11793 | @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS) |
| 11794 | public List<CellBroadcastIdRange> getCellBroadcastIdRanges(int subId) { |
| 11795 | mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS, |
| 11796 | "getCellBroadcastIdRanges"); |
| 11797 | final long identity = Binder.clearCallingIdentity(); |
| 11798 | try { |
| 11799 | return getPhone(subId).getCellBroadcastIdRanges(); |
| 11800 | } finally { |
| 11801 | Binder.restoreCallingIdentity(identity); |
| 11802 | } |
| 11803 | } |
| 11804 | |
| 11805 | /** |
| 11806 | * Set reception of cell broadcast messages with the list of the given ranges |
| 11807 | * |
| 11808 | * @param ranges the list of {@link CellBroadcastIdRange} to be enabled |
| 11809 | */ |
| 11810 | @Override |
| 11811 | @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS) |
| 11812 | public void setCellBroadcastIdRanges(int subId, @NonNull List<CellBroadcastIdRange> ranges, |
| 11813 | @Nullable IIntegerConsumer callback) { |
| 11814 | mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS, |
| 11815 | "setCellBroadcastIdRanges"); |
| 11816 | final long identity = Binder.clearCallingIdentity(); |
| 11817 | try { |
| 11818 | Phone phone = getPhoneFromSubId(subId); |
| 11819 | if (DBG) { |
| 11820 | log("setCellBroadcastIdRanges for subId :" + subId + ", phone:" + phone); |
| 11821 | } |
| 11822 | phone.setCellBroadcastIdRanges(ranges, result -> { |
| 11823 | if (callback != null) { |
| 11824 | try { |
| 11825 | callback.accept(result); |
| 11826 | } catch (RemoteException e) { |
| 11827 | Log.w(LOG_TAG, "setCellBroadcastIdRanges: callback not available."); |
| 11828 | } |
| 11829 | } |
| 11830 | }); |
| 11831 | } finally { |
| 11832 | Binder.restoreCallingIdentity(identity); |
| 11833 | } |
| 11834 | } |
Hunsuk Choi | 42cc62a | 2022-10-16 06:03:40 +0000 | [diff] [blame] | 11835 | |
| 11836 | /** |
| 11837 | * Returns whether the device supports the domain selection service. |
| 11838 | * |
| 11839 | * @return {@code true} if the device supports the domain selection service. |
| 11840 | */ |
| 11841 | @Override |
| 11842 | public boolean isDomainSelectionSupported() { |
| 11843 | mApp.enforceCallingOrSelfPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
| 11844 | "isDomainSelectionSupported"); |
| 11845 | |
| 11846 | final long identity = Binder.clearCallingIdentity(); |
| 11847 | try { |
| 11848 | return DomainSelectionResolver.getInstance().isDomainSelectionSupported(); |
| 11849 | } finally { |
| 11850 | Binder.restoreCallingIdentity(identity); |
| 11851 | } |
| 11852 | } |
arunvoddu | d5c6ce0 | 2022-12-11 06:03:12 +0000 | [diff] [blame] | 11853 | |
| 11854 | /** |
| 11855 | * Check whether the caller (or self, if not processing an IPC) can read device identifiers. |
| 11856 | * |
| 11857 | * <p>This method behaves in one of the following ways: |
| 11858 | * <ul> |
| 11859 | * <li>return true : if the calling package has the appop permission {@link |
| 11860 | * Manifest.permission#USE_ICC_AUTH_WITH_DEVICE_IDENTIFIER} in the manifest </> |
| 11861 | * <li>return true : if any one subscription has the READ_PRIVILEGED_PHONE_STATE |
| 11862 | * permission, the calling package passes a DevicePolicyManager Device Owner / Profile |
| 11863 | * Owner device identifier access check, or the calling package has carrier privileges</> |
| 11864 | * <li>throw SecurityException: if the caller does not meet any of the requirements. |
| 11865 | * </ul> |
| 11866 | */ |
| 11867 | private static boolean checkCallingOrSelfReadDeviceIdentifiersForAnySub(Context context, |
| 11868 | String callingPackage, @Nullable String callingFeatureId, String message) { |
| 11869 | for (Phone phone : PhoneFactory.getPhones()) { |
| 11870 | if (TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(context, |
| 11871 | phone.getSubId(), callingPackage, callingFeatureId, message)) { |
| 11872 | return true; |
| 11873 | } |
| 11874 | } |
| 11875 | return false; |
| 11876 | } |
| 11877 | } |