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; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 397 | private 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(); |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 2413 | mSubscriptionController = SubscriptionController.getInstance(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2414 | mTelephonySharedPreferences = |
| 2415 | PreferenceManager.getDefaultSharedPreferences(mApp); |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 2416 | mNetworkScanRequestTracker = new NetworkScanRequestTracker(); |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 2417 | mPhoneConfigurationManager = PhoneConfigurationManager.getInstance(); |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 2418 | mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance(); |
Peter Wang | a3cf4ac | 2020-01-27 09:39:46 +0800 | [diff] [blame] | 2419 | mNotifyUserActivity = new AtomicBoolean(false); |
Tyler Gunn | 64144d9 | 2022-03-17 14:16:41 -0700 | [diff] [blame] | 2420 | PropertyInvalidatedCache.invalidateCache(TelephonyManager.CACHE_KEY_PHONE_ACCOUNT_TO_SUBID); |
Gil Cukierman | 6dac5eb | 2022-09-19 16:09:04 +0000 | [diff] [blame] | 2421 | mTelephony2gUpdater = new Telephony2gUpdater( |
| 2422 | Executors.newSingleThreadExecutor(), mApp); |
| 2423 | mTelephony2gUpdater.init(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2424 | publish(); |
| 2425 | } |
| 2426 | |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 2427 | @VisibleForTesting |
| 2428 | public SharedPreferences getSharedPreferences() { |
| 2429 | return mTelephonySharedPreferences; |
| 2430 | } |
| 2431 | |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2432 | private Phone getDefaultPhone() { |
| 2433 | Phone thePhone = getPhone(getDefaultSubscription()); |
| 2434 | return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone(); |
| 2435 | } |
| 2436 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2437 | private void publish() { |
| 2438 | if (DBG) log("publish: " + this); |
| 2439 | |
Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 2440 | TelephonyFrameworkInitializer |
| 2441 | .getTelephonyServiceManager() |
| 2442 | .getTelephonyServiceRegisterer() |
| 2443 | .register(this); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2444 | } |
| 2445 | |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 2446 | private Phone getPhoneFromRequest(MainThreadRequest request) { |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 2447 | if (request.phone != null) { |
| 2448 | return request.phone; |
| 2449 | } else { |
| 2450 | return getPhoneFromSubId(request.subId); |
| 2451 | } |
| 2452 | } |
| 2453 | |
| 2454 | private Phone getPhoneFromSubId(int subId) { |
| 2455 | return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) |
| 2456 | ? getDefaultPhone() : getPhone(subId); |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 2457 | } |
| 2458 | |
Rambo Wang | e53e07d | 2022-05-10 13:01:13 -0700 | [diff] [blame] | 2459 | @Nullable |
| 2460 | private UiccPort getUiccPortFromRequest(@NonNull MainThreadRequest request) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2461 | Phone phone = getPhoneFromRequest(request); |
| 2462 | return phone == null ? null : |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 2463 | UiccController.getInstance().getUiccPort(phone.getPhoneId()); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2464 | } |
| 2465 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2466 | // returns phone associated with the subId. |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2467 | private Phone getPhone(int subId) { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 2468 | return PhoneFactory.getPhone(SubscriptionManager.getPhoneId(subId)); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2469 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2470 | |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 2471 | private void sendEraseModemConfig(@NonNull Phone phone) { |
| 2472 | Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null); |
| 2473 | if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 2474 | } |
| 2475 | |
| 2476 | private void sendEraseDataInSharedPreferences(@NonNull Phone phone) { |
| 2477 | Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null); |
| 2478 | if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail")); |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 2479 | } |
| 2480 | |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 2481 | private boolean isImsAvailableOnDevice() { |
| 2482 | PackageManager pm = getDefaultPhone().getContext().getPackageManager(); |
| 2483 | if (pm == null) { |
| 2484 | // For some reason package manger is not available.. This will fail internally anyway, |
| 2485 | // so do not throw error and allow. |
| 2486 | return true; |
| 2487 | } |
| 2488 | return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0); |
| 2489 | } |
| 2490 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2491 | public void dial(String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2492 | dialForSubscriber(getPreferredVoiceSubscription(), number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2493 | } |
| 2494 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2495 | public void dialForSubscriber(int subId, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2496 | if (DBG) log("dial: " + number); |
| 2497 | // No permission check needed here: This is just a wrapper around the |
| 2498 | // ACTION_DIAL intent, which is available to any app since it puts up |
| 2499 | // the UI before it does anything. |
| 2500 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2501 | final long identity = Binder.clearCallingIdentity(); |
| 2502 | try { |
| 2503 | String url = createTelUrl(number); |
| 2504 | if (url == null) { |
| 2505 | return; |
| 2506 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2507 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2508 | // PENDING: should we just silently fail if phone is offhook or ringing? |
| 2509 | PhoneConstants.State state = mCM.getState(subId); |
| 2510 | if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) { |
| 2511 | Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url)); |
| 2512 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2513 | mApp.startActivity(intent); |
| 2514 | } |
| 2515 | } finally { |
| 2516 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2517 | } |
| 2518 | } |
| 2519 | |
| 2520 | public void call(String callingPackage, String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2521 | callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2522 | } |
| 2523 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2524 | public void callForSubscriber(int subId, String callingPackage, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2525 | if (DBG) log("call: " + number); |
| 2526 | |
| 2527 | // This is just a wrapper around the ACTION_CALL intent, but we still |
| 2528 | // need to do a permission check since we're calling startActivity() |
| 2529 | // from the context of the phone app. |
| 2530 | enforceCallPermission(); |
| 2531 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 2532 | if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage) |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2533 | != AppOpsManager.MODE_ALLOWED) { |
| 2534 | return; |
| 2535 | } |
| 2536 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2537 | final long identity = Binder.clearCallingIdentity(); |
| 2538 | try { |
| 2539 | String url = createTelUrl(number); |
| 2540 | if (url == null) { |
| 2541 | return; |
| 2542 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2543 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2544 | boolean isValid = false; |
| 2545 | final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged(); |
| 2546 | if (slist != null) { |
| 2547 | for (SubscriptionInfo subInfoRecord : slist) { |
| 2548 | if (subInfoRecord.getSubscriptionId() == subId) { |
| 2549 | isValid = true; |
| 2550 | break; |
| 2551 | } |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 2552 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 2553 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2554 | if (!isValid) { |
| 2555 | return; |
| 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 | Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url)); |
| 2559 | intent.putExtra(SUBSCRIPTION_KEY, subId); |
| 2560 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2561 | mApp.startActivity(intent); |
| 2562 | } finally { |
| 2563 | Binder.restoreCallingIdentity(identity); |
| 2564 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2565 | } |
| 2566 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2567 | public boolean supplyPinForSubscriber(int subId, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2568 | int [] resultArray = supplyPinReportResultForSubscriber(subId, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2569 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 2570 | } |
| 2571 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2572 | public boolean supplyPukForSubscriber(int subId, String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2573 | int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2574 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 2575 | } |
| 2576 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2577 | public int[] supplyPinReportResultForSubscriber(int subId, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2578 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2579 | |
| 2580 | final long identity = Binder.clearCallingIdentity(); |
| 2581 | try { |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2582 | Phone phone = getPhone(subId); |
| 2583 | final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2584 | checkSimPin.start(); |
| 2585 | return checkSimPin.unlockSim(null, pin); |
| 2586 | } finally { |
| 2587 | Binder.restoreCallingIdentity(identity); |
| 2588 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2589 | } |
| 2590 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2591 | public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2592 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2593 | |
| 2594 | final long identity = Binder.clearCallingIdentity(); |
| 2595 | try { |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2596 | Phone phone = getPhone(subId); |
| 2597 | final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2598 | checkSimPuk.start(); |
| 2599 | return checkSimPuk.unlockSim(puk, pin); |
| 2600 | } finally { |
| 2601 | Binder.restoreCallingIdentity(identity); |
| 2602 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2603 | } |
| 2604 | |
| 2605 | /** |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2606 | * Helper thread to turn async call to SimCard#supplyPin into |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2607 | * a synchronous one. |
| 2608 | */ |
| 2609 | private static class UnlockSim extends Thread { |
| 2610 | |
| 2611 | private final IccCard mSimCard; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2612 | private final int mPhoneId; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2613 | |
| 2614 | private boolean mDone = false; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2615 | private int mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 2616 | private int mRetryCount = -1; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2617 | |
| 2618 | // For replies from SimCard interface |
| 2619 | private Handler mHandler; |
| 2620 | |
| 2621 | // For async handler to identify request type |
| 2622 | private static final int SUPPLY_PIN_COMPLETE = 100; |
| 2623 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2624 | UnlockSim(int phoneId, IccCard simCard) { |
| 2625 | mPhoneId = phoneId; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2626 | mSimCard = simCard; |
| 2627 | } |
| 2628 | |
| 2629 | @Override |
| 2630 | public void run() { |
| 2631 | Looper.prepare(); |
| 2632 | synchronized (UnlockSim.this) { |
| 2633 | mHandler = new Handler() { |
| 2634 | @Override |
| 2635 | public void handleMessage(Message msg) { |
| 2636 | AsyncResult ar = (AsyncResult) msg.obj; |
| 2637 | switch (msg.what) { |
| 2638 | case SUPPLY_PIN_COMPLETE: |
| 2639 | Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE"); |
| 2640 | synchronized (UnlockSim.this) { |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2641 | mRetryCount = msg.arg1; |
| 2642 | if (ar.exception != null) { |
| 2643 | if (ar.exception instanceof CommandException && |
| 2644 | ((CommandException)(ar.exception)).getCommandError() |
| 2645 | == CommandException.Error.PASSWORD_INCORRECT) { |
| 2646 | mResult = PhoneConstants.PIN_PASSWORD_INCORRECT; |
vivi.li | b5e9ada | 2019-09-12 16:04:24 +0800 | [diff] [blame] | 2647 | } //When UiccCardApp dispose,handle message and return exception |
| 2648 | else if (ar.exception instanceof CommandException && |
| 2649 | ((CommandException) (ar.exception)).getCommandError() |
| 2650 | == CommandException.Error.ABORTED) { |
| 2651 | mResult = PhoneConstants.PIN_OPERATION_ABORTED; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2652 | } else { |
| 2653 | mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 2654 | } |
| 2655 | } else { |
| 2656 | mResult = PhoneConstants.PIN_RESULT_SUCCESS; |
| 2657 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2658 | mDone = true; |
| 2659 | UnlockSim.this.notifyAll(); |
| 2660 | } |
| 2661 | break; |
| 2662 | } |
| 2663 | } |
| 2664 | }; |
| 2665 | UnlockSim.this.notifyAll(); |
| 2666 | } |
| 2667 | Looper.loop(); |
| 2668 | } |
| 2669 | |
| 2670 | /* |
| 2671 | * Use PIN or PUK to unlock SIM card |
| 2672 | * |
| 2673 | * If PUK is null, unlock SIM card with PIN |
| 2674 | * |
| 2675 | * If PUK is not null, unlock SIM card with PUK and set PIN code |
| 2676 | */ |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2677 | synchronized int[] unlockSim(String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2678 | |
| 2679 | while (mHandler == null) { |
| 2680 | try { |
| 2681 | wait(); |
| 2682 | } catch (InterruptedException e) { |
| 2683 | Thread.currentThread().interrupt(); |
| 2684 | } |
| 2685 | } |
| 2686 | Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE); |
| 2687 | |
| 2688 | if (puk == null) { |
| 2689 | mSimCard.supplyPin(pin, callback); |
| 2690 | } else { |
| 2691 | mSimCard.supplyPuk(puk, pin, callback); |
| 2692 | } |
| 2693 | |
| 2694 | while (!mDone) { |
| 2695 | try { |
| 2696 | Log.d(LOG_TAG, "wait for done"); |
| 2697 | wait(); |
| 2698 | } catch (InterruptedException e) { |
| 2699 | // Restore the interrupted status |
| 2700 | Thread.currentThread().interrupt(); |
| 2701 | } |
| 2702 | } |
| 2703 | Log.d(LOG_TAG, "done"); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2704 | int[] resultArray = new int[2]; |
| 2705 | resultArray[0] = mResult; |
| 2706 | resultArray[1] = mRetryCount; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2707 | |
| 2708 | if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) { |
Jon Spivack | 9c3bc76 | 2021-10-06 20:53:09 +0000 | [diff] [blame] | 2709 | UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2710 | } |
| 2711 | |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2712 | return resultArray; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2713 | } |
| 2714 | } |
| 2715 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2716 | /** |
| 2717 | * This method has been removed due to privacy and stability concerns. |
| 2718 | */ |
| 2719 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2720 | public void updateServiceLocation() { |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2721 | Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()"); |
| 2722 | return; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2723 | } |
| 2724 | |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2725 | @Override |
| 2726 | public void updateServiceLocationWithPackageName(String callingPackage) { |
| 2727 | mApp.getSystemService(AppOpsManager.class) |
| 2728 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 2729 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 2730 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2731 | if (targetSdk > android.os.Build.VERSION_CODES.R) { |
| 2732 | // Callers targeting S have no business invoking this method. |
| 2733 | return; |
| 2734 | } |
| 2735 | |
| 2736 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2737 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2738 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2739 | .setCallingPackage(callingPackage) |
| 2740 | .setCallingFeatureId(null) |
| 2741 | .setCallingPid(Binder.getCallingPid()) |
| 2742 | .setCallingUid(Binder.getCallingUid()) |
| 2743 | .setMethod("updateServiceLocation") |
| 2744 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
| 2745 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2746 | .build()); |
| 2747 | // Apps that lack location permission have no business calling this method; |
| 2748 | // however, because no permission was declared in the public API, denials must |
| 2749 | // all be "soft". |
| 2750 | switch (locationResult) { |
| 2751 | case DENIED_HARD: /* fall through */ |
| 2752 | case DENIED_SOFT: |
| 2753 | return; |
| 2754 | } |
| 2755 | |
| 2756 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2757 | final long identity = Binder.clearCallingIdentity(); |
| 2758 | try { |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2759 | final Phone phone = getPhone(getDefaultSubscription()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2760 | if (phone != null) { |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2761 | phone.updateServiceLocation(workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2762 | } |
| 2763 | } finally { |
| 2764 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2765 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2766 | } |
| 2767 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2768 | @Deprecated |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2769 | @Override |
| 2770 | public boolean isRadioOn(String callingPackage) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2771 | return isRadioOnWithFeature(callingPackage, null); |
| 2772 | } |
| 2773 | |
| 2774 | |
| 2775 | @Override |
| 2776 | public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) { |
| 2777 | return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage, |
| 2778 | callingFeatureId); |
| 2779 | } |
| 2780 | |
| 2781 | @Deprecated |
| 2782 | @Override |
| 2783 | public boolean isRadioOnForSubscriber(int subId, String callingPackage) { |
| 2784 | return isRadioOnForSubscriberWithFeature(subId, callingPackage, null); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2785 | } |
| 2786 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2787 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2788 | public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage, |
| 2789 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2790 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2791 | mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2792 | return false; |
| 2793 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2794 | |
| 2795 | final long identity = Binder.clearCallingIdentity(); |
| 2796 | try { |
| 2797 | return isRadioOnForSubscriber(subId); |
| 2798 | } finally { |
| 2799 | Binder.restoreCallingIdentity(identity); |
| 2800 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2801 | } |
| 2802 | |
| 2803 | private boolean isRadioOnForSubscriber(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2804 | final long identity = Binder.clearCallingIdentity(); |
| 2805 | try { |
| 2806 | final Phone phone = getPhone(subId); |
| 2807 | if (phone != null) { |
| 2808 | return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF; |
| 2809 | } else { |
| 2810 | return false; |
| 2811 | } |
| 2812 | } finally { |
| 2813 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2814 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2815 | } |
| 2816 | |
| 2817 | public void toggleRadioOnOff() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2818 | toggleRadioOnOffForSubscriber(getDefaultSubscription()); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2819 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2820 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2821 | public void toggleRadioOnOffForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2822 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2823 | |
| 2824 | final long identity = Binder.clearCallingIdentity(); |
| 2825 | try { |
| 2826 | final Phone phone = getPhone(subId); |
| 2827 | if (phone != null) { |
| 2828 | phone.setRadioPower(!isRadioOnForSubscriber(subId)); |
| 2829 | } |
| 2830 | } finally { |
| 2831 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2832 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2833 | } |
| 2834 | |
| 2835 | public boolean setRadio(boolean turnOn) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2836 | return setRadioForSubscriber(getDefaultSubscription(), turnOn); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2837 | } |
| 2838 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2839 | public boolean setRadioForSubscriber(int subId, boolean turnOn) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2840 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2841 | |
| 2842 | final long identity = Binder.clearCallingIdentity(); |
| 2843 | try { |
| 2844 | final Phone phone = getPhone(subId); |
| 2845 | if (phone == null) { |
| 2846 | return false; |
| 2847 | } |
| 2848 | if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) { |
| 2849 | toggleRadioOnOffForSubscriber(subId); |
| 2850 | } |
| 2851 | return true; |
| 2852 | } finally { |
| 2853 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2854 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2855 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2856 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2857 | public boolean needMobileRadioShutdown() { |
Shuo Qian | fa7b6b3 | 2019-12-10 10:40:38 -0800 | [diff] [blame] | 2858 | enforceReadPrivilegedPermission("needMobileRadioShutdown"); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2859 | /* |
| 2860 | * If any of the Radios are available, it will need to be |
| 2861 | * shutdown. So return true if any Radio is available. |
| 2862 | */ |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2863 | final long identity = Binder.clearCallingIdentity(); |
| 2864 | try { |
| 2865 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 2866 | Phone phone = PhoneFactory.getPhone(i); |
| 2867 | if (phone != null && phone.isRadioAvailable()) return true; |
| 2868 | } |
| 2869 | logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown."); |
| 2870 | return false; |
| 2871 | } finally { |
| 2872 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2873 | } |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2874 | } |
| 2875 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2876 | @Override |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2877 | public void shutdownMobileRadios() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2878 | enforceModifyPermission(); |
| 2879 | |
| 2880 | final long identity = Binder.clearCallingIdentity(); |
| 2881 | try { |
| 2882 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 2883 | logv("Shutting down Phone " + i); |
| 2884 | shutdownRadioUsingPhoneId(i); |
| 2885 | } |
| 2886 | } finally { |
| 2887 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2888 | } |
| 2889 | } |
| 2890 | |
| 2891 | private void shutdownRadioUsingPhoneId(int phoneId) { |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2892 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 2893 | if (phone != null && phone.isRadioAvailable()) { |
| 2894 | phone.shutdownRadio(); |
| 2895 | } |
| 2896 | } |
| 2897 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2898 | public boolean setRadioPower(boolean turnOn) { |
Jack Yu | b4e1616 | 2017-05-15 12:48:40 -0700 | [diff] [blame] | 2899 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2900 | |
| 2901 | final long identity = Binder.clearCallingIdentity(); |
| 2902 | try { |
| 2903 | final Phone defaultPhone = PhoneFactory.getDefaultPhone(); |
| 2904 | if (defaultPhone != null) { |
| 2905 | defaultPhone.setRadioPower(turnOn); |
| 2906 | return true; |
| 2907 | } else { |
| 2908 | loge("There's no default phone."); |
| 2909 | return false; |
| 2910 | } |
| 2911 | } finally { |
| 2912 | Binder.restoreCallingIdentity(identity); |
Wei Liu | 9ae2a06 | 2016-08-08 11:09:34 -0700 | [diff] [blame] | 2913 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2914 | } |
| 2915 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2916 | public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2917 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2918 | |
| 2919 | final long identity = Binder.clearCallingIdentity(); |
| 2920 | try { |
| 2921 | final Phone phone = getPhone(subId); |
| 2922 | if (phone != null) { |
| 2923 | phone.setRadioPower(turnOn); |
| 2924 | return true; |
| 2925 | } else { |
| 2926 | return false; |
| 2927 | } |
| 2928 | } finally { |
| 2929 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2930 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2931 | } |
| 2932 | |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 2933 | /** |
| 2934 | * Vote on powering off the radio for a reason. The radio will be turned on only when there is |
| 2935 | * no reason to power it off. When any of the voters want to power it off, it will be turned |
| 2936 | * off. In case of emergency, the radio will be turned on even if there are some reasons for |
| 2937 | * powering it off, and these radio off votes will be cleared. |
| 2938 | * Multiple apps can vote for the same reason and the last vote will take effect. Each app is |
| 2939 | * responsible for its vote. A powering-off vote of a reason will be maintained until it is |
| 2940 | * cleared by calling {@link clearRadioPowerOffForReason} for that reason, or an emergency call |
| 2941 | * is made, or the device is rebooted. When an app comes backup from a crash, it needs to make |
| 2942 | * sure if its vote is as expected. An app can use the API {@link getRadioPowerOffReasons} to |
| 2943 | * check its vote. |
| 2944 | * |
| 2945 | * @param subId The subscription ID. |
| 2946 | * @param reason The reason for powering off radio. |
| 2947 | * @return true on success and false on failure. |
| 2948 | */ |
| 2949 | public boolean requestRadioPowerOffForReason(int subId, |
| 2950 | @TelephonyManager.RadioPowerReason int reason) { |
| 2951 | enforceModifyPermission(); |
| 2952 | |
| 2953 | final long identity = Binder.clearCallingIdentity(); |
| 2954 | try { |
| 2955 | final Phone phone = getPhone(subId); |
| 2956 | if (phone != null) { |
| 2957 | phone.setRadioPowerForReason(false, reason); |
| 2958 | return true; |
| 2959 | } else { |
| 2960 | return false; |
| 2961 | } |
| 2962 | } finally { |
| 2963 | Binder.restoreCallingIdentity(identity); |
| 2964 | } |
| 2965 | } |
| 2966 | |
| 2967 | /** |
| 2968 | * Remove the vote on powering off the radio for a reason, as requested by |
| 2969 | * {@link requestRadioPowerOffForReason}. |
| 2970 | * |
| 2971 | * @param subId The subscription ID. |
| 2972 | * @param reason The reason for powering off radio. |
| 2973 | * @return true on success and false on failure. |
| 2974 | */ |
| 2975 | public boolean clearRadioPowerOffForReason(int subId, |
| 2976 | @TelephonyManager.RadioPowerReason int reason) { |
| 2977 | enforceModifyPermission(); |
| 2978 | |
| 2979 | final long identity = Binder.clearCallingIdentity(); |
| 2980 | try { |
| 2981 | final Phone phone = getPhone(subId); |
| 2982 | if (phone != null) { |
| 2983 | phone.setRadioPowerForReason(true, reason); |
| 2984 | return true; |
| 2985 | } else { |
| 2986 | return false; |
| 2987 | } |
| 2988 | } finally { |
| 2989 | Binder.restoreCallingIdentity(identity); |
| 2990 | } |
| 2991 | } |
| 2992 | |
| 2993 | /** |
| 2994 | * Get reasons for powering off radio, as requested by {@link requestRadioPowerOffForReason}. |
| 2995 | * |
| 2996 | * @param subId The subscription ID. |
| 2997 | * @param callingPackage The package making the call. |
| 2998 | * @param callingFeatureId The feature in the package. |
| 2999 | * @return List of reasons for powering off radio. |
| 3000 | */ |
| 3001 | public List getRadioPowerOffReasons(int subId, String callingPackage, String callingFeatureId) { |
| 3002 | enforceReadPrivilegedPermission("getRadioPowerOffReasons"); |
| 3003 | |
| 3004 | final long identity = Binder.clearCallingIdentity(); |
| 3005 | List result = new ArrayList(); |
| 3006 | try { |
| 3007 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, |
| 3008 | callingPackage, callingFeatureId, "getRadioPowerOffReasons")) { |
| 3009 | return result; |
| 3010 | } |
| 3011 | |
| 3012 | final Phone phone = getPhone(subId); |
| 3013 | if (phone != null) { |
| 3014 | result.addAll(phone.getRadioPowerOffReasons()); |
| 3015 | } |
| 3016 | } finally { |
| 3017 | Binder.restoreCallingIdentity(identity); |
| 3018 | } |
| 3019 | return result; |
| 3020 | } |
| 3021 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3022 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3023 | @Override |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 3024 | public boolean enableDataConnectivity(String callingPackage) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3025 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3026 | |
| 3027 | final long identity = Binder.clearCallingIdentity(); |
| 3028 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3029 | int subId = SubscriptionManager.getDefaultDataSubscriptionId(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3030 | final Phone phone = getPhone(subId); |
| 3031 | if (phone != null) { |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 3032 | phone.getDataSettingsManager().setDataEnabled( |
| 3033 | TelephonyManager.DATA_ENABLED_REASON_USER, true, callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3034 | return true; |
| 3035 | } else { |
| 3036 | return false; |
| 3037 | } |
| 3038 | } finally { |
| 3039 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3040 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3041 | } |
| 3042 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3043 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3044 | @Override |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 3045 | public boolean disableDataConnectivity(String callingPackage) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3046 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3047 | |
| 3048 | final long identity = Binder.clearCallingIdentity(); |
| 3049 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3050 | int subId = SubscriptionManager.getDefaultDataSubscriptionId(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3051 | final Phone phone = getPhone(subId); |
| 3052 | if (phone != null) { |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 3053 | phone.getDataSettingsManager().setDataEnabled( |
| 3054 | TelephonyManager.DATA_ENABLED_REASON_USER, false, callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3055 | return true; |
| 3056 | } else { |
| 3057 | return false; |
| 3058 | } |
| 3059 | } finally { |
| 3060 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3061 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3062 | } |
| 3063 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3064 | @Override |
Jack Yu | acf8a13 | 2017-05-01 17:00:48 -0700 | [diff] [blame] | 3065 | public boolean isDataConnectivityPossible(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3066 | final long identity = Binder.clearCallingIdentity(); |
| 3067 | try { |
| 3068 | final Phone phone = getPhone(subId); |
| 3069 | if (phone != null) { |
Jack Yu | 59824e1 | 2022-03-23 01:42:44 -0700 | [diff] [blame] | 3070 | return phone.isDataAllowed(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3071 | } else { |
| 3072 | return false; |
| 3073 | } |
| 3074 | } finally { |
| 3075 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3076 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3077 | } |
| 3078 | |
| 3079 | public boolean handlePinMmi(String dialString) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 3080 | return handlePinMmiForSubscriber(getDefaultSubscription(), dialString); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3081 | } |
| 3082 | |
pkanwar | ae03a6b | 2016-11-06 20:37:09 -0800 | [diff] [blame] | 3083 | public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3084 | enforceCallPermission(); |
| 3085 | |
| 3086 | final long identity = Binder.clearCallingIdentity(); |
| 3087 | try { |
| 3088 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3089 | return; |
| 3090 | } |
| 3091 | Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback); |
| 3092 | sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId); |
| 3093 | } finally { |
| 3094 | Binder.restoreCallingIdentity(identity); |
| 3095 | } |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 3096 | }; |
| 3097 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3098 | public boolean handlePinMmiForSubscriber(int subId, String dialString) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3099 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3100 | |
| 3101 | final long identity = Binder.clearCallingIdentity(); |
| 3102 | try { |
| 3103 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3104 | return false; |
| 3105 | } |
| 3106 | return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId); |
| 3107 | } finally { |
| 3108 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3109 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3110 | } |
| 3111 | |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 3112 | /** |
| 3113 | * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage |
| 3114 | * tag on getCallState Binder call. |
| 3115 | */ |
| 3116 | @Deprecated |
| 3117 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3118 | public int getCallState() { |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 3119 | if (CompatChanges.isChangeEnabled( |
| 3120 | TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION, |
| 3121 | Binder.getCallingUid())) { |
| 3122 | // Do not allow this API to be called on API version 31+, it should only be |
| 3123 | // called on old apps using this Binder call directly. |
| 3124 | throw new SecurityException("This method can only be used for applications " |
| 3125 | + "targeting API version 30 or less."); |
| 3126 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3127 | final long identity = Binder.clearCallingIdentity(); |
| 3128 | try { |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 3129 | Phone phone = getPhone(getDefaultSubscription()); |
| 3130 | return phone == null ? TelephonyManager.CALL_STATE_IDLE : |
| 3131 | PhoneConstantConversions.convertCallState(phone.getState()); |
| 3132 | } finally { |
| 3133 | Binder.restoreCallingIdentity(identity); |
| 3134 | } |
| 3135 | } |
| 3136 | |
| 3137 | @Override |
| 3138 | public int getCallStateForSubscription(int subId, String callingPackage, String featureId) { |
| 3139 | if (CompatChanges.isChangeEnabled( |
| 3140 | TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION, |
| 3141 | Binder.getCallingUid())) { |
| 3142 | // Check READ_PHONE_STATE for API version 31+ |
| 3143 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage, |
| 3144 | featureId, "getCallStateForSubscription")) { |
| 3145 | throw new SecurityException("getCallState requires READ_PHONE_STATE for apps " |
| 3146 | + "targeting API level 31+."); |
| 3147 | } |
| 3148 | } |
| 3149 | final long identity = Binder.clearCallingIdentity(); |
| 3150 | try { |
| 3151 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3152 | return phone == null ? TelephonyManager.CALL_STATE_IDLE : |
| 3153 | PhoneConstantConversions.convertCallState(phone.getState()); |
| 3154 | } finally { |
| 3155 | Binder.restoreCallingIdentity(identity); |
| 3156 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3157 | } |
| 3158 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3159 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 3160 | public int getDataState() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3161 | return getDataStateForSubId(SubscriptionManager.getDefaultDataSubscriptionId()); |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 3162 | } |
| 3163 | |
| 3164 | @Override |
| 3165 | public int getDataStateForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3166 | final long identity = Binder.clearCallingIdentity(); |
| 3167 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 3168 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3169 | if (phone != null) { |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 3170 | return phone.getDataNetworkController().getInternetDataNetworkState(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3171 | } else { |
| 3172 | return PhoneConstantConversions.convertDataState( |
| 3173 | PhoneConstants.DataState.DISCONNECTED); |
| 3174 | } |
| 3175 | } finally { |
| 3176 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3177 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3178 | } |
| 3179 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3180 | @Override |
Jack Yu | 0eda684 | 2022-04-18 00:34:46 -0700 | [diff] [blame] | 3181 | public @DataActivityType int getDataActivity() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3182 | return getDataActivityForSubId(SubscriptionManager.getDefaultDataSubscriptionId()); |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 3183 | } |
| 3184 | |
| 3185 | @Override |
Jack Yu | 0eda684 | 2022-04-18 00:34:46 -0700 | [diff] [blame] | 3186 | public @DataActivityType int getDataActivityForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3187 | final long identity = Binder.clearCallingIdentity(); |
| 3188 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 3189 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3190 | if (phone != null) { |
Jack Yu | 0eda684 | 2022-04-18 00:34:46 -0700 | [diff] [blame] | 3191 | return phone.getDataActivityState(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3192 | } else { |
| 3193 | return TelephonyManager.DATA_ACTIVITY_NONE; |
| 3194 | } |
| 3195 | } finally { |
| 3196 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3197 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3198 | } |
| 3199 | |
| 3200 | @Override |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 3201 | public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3202 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 3203 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3204 | |
| 3205 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 3206 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 3207 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 3208 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3209 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3210 | .setCallingPid(Binder.getCallingPid()) |
| 3211 | .setCallingUid(Binder.getCallingUid()) |
| 3212 | .setMethod("getCellLocation") |
Hall Liu | 773ba02 | 2020-01-24 18:07:12 -0800 | [diff] [blame] | 3213 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3214 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 3215 | .build()); |
| 3216 | switch (locationResult) { |
| 3217 | case DENIED_HARD: |
| 3218 | throw new SecurityException("Not allowed to access cell location"); |
| 3219 | case DENIED_SOFT: |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 3220 | return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
| 3221 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3222 | } |
| 3223 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 3224 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3225 | final long identity = Binder.clearCallingIdentity(); |
| 3226 | try { |
| 3227 | if (DBG_LOC) log("getCellLocation: is active user"); |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3228 | int subId = SubscriptionManager.getDefaultDataSubscriptionId(); |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 3229 | return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3230 | } finally { |
| 3231 | Binder.restoreCallingIdentity(identity); |
| 3232 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 3233 | } |
| 3234 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3235 | @Override |
Jack Yu | eb1e7fe | 2020-02-22 19:38:58 -0800 | [diff] [blame] | 3236 | public String getNetworkCountryIsoForPhone(int phoneId) { |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3237 | // Reporting the correct network country is ambiguous when IWLAN could conflict with |
| 3238 | // registered cell info, so return a NULL country instead. |
| 3239 | final long identity = Binder.clearCallingIdentity(); |
| 3240 | try { |
Malcolm Chen | 3732c2b | 2018-07-18 20:15:24 -0700 | [diff] [blame] | 3241 | if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) { |
| 3242 | // Get default phone in this case. |
| 3243 | phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX; |
| 3244 | } |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3245 | final int subId = SubscriptionManager.getSubscriptionId(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3246 | Phone phone = PhoneFactory.getPhone(phoneId); |
Nathan Harold | 532f51c | 2020-04-21 19:31:10 -0700 | [diff] [blame] | 3247 | if (phone == null) return ""; |
| 3248 | ServiceStateTracker sst = phone.getServiceStateTracker(); |
| 3249 | if (sst == null) return ""; |
| 3250 | LocaleTracker lt = sst.getLocaleTracker(); |
| 3251 | if (lt == null) return ""; |
Shuo Qian | 9418a92 | 2021-03-09 11:21:16 -0800 | [diff] [blame] | 3252 | return lt.getCurrentCountry(); |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3253 | } finally { |
| 3254 | Binder.restoreCallingIdentity(identity); |
| 3255 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3256 | } |
| 3257 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 3258 | /** |
| 3259 | * This method was removed due to potential issues caused by performing partial |
| 3260 | * updates of service state, and lack of a credible use case. |
| 3261 | * |
| 3262 | * This has the ability to break the telephony implementation by disabling notification of |
| 3263 | * changes in device connectivity. DO NOT USE THIS! |
| 3264 | */ |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3265 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3266 | public void enableLocationUpdates() { |
| 3267 | mApp.enforceCallingOrSelfPermission( |
| 3268 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3269 | } |
| 3270 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 3271 | /** |
| 3272 | * This method was removed due to potential issues caused by performing partial |
| 3273 | * updates of service state, and lack of a credible use case. |
| 3274 | * |
| 3275 | * This has the ability to break the telephony implementation by disabling notification of |
| 3276 | * changes in device connectivity. DO NOT USE THIS! |
| 3277 | */ |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3278 | @Override |
| 3279 | public void disableLocationUpdates() { |
| 3280 | mApp.enforceCallingOrSelfPermission( |
| 3281 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3282 | } |
| 3283 | |
| 3284 | @Override |
| 3285 | @SuppressWarnings("unchecked") |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3286 | public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage, |
| 3287 | String callingFeatureId) { |
Nathan Harold | b55f63b | 2021-07-27 11:27:38 -0700 | [diff] [blame] | 3288 | try { |
| 3289 | mApp.getSystemService(AppOpsManager.class) |
| 3290 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 3291 | } catch (SecurityException e) { |
| 3292 | EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid()); |
| 3293 | throw e; |
| 3294 | } |
| 3295 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3296 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | dbea45a | 2018-08-30 14:35:07 -0700 | [diff] [blame] | 3297 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 3298 | throw new SecurityException( |
| 3299 | "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels."); |
| 3300 | } |
Nathan Harold | b4d5561 | 2018-07-20 13:13:08 -0700 | [diff] [blame] | 3301 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 3302 | if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(), |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3303 | callingPackage) != AppOpsManager.MODE_ALLOWED) { |
| 3304 | return null; |
| 3305 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 3306 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 3307 | if (DBG_LOC) log("getNeighboringCellInfo: is active user"); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3308 | |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3309 | List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId); |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 3310 | if (info == null) return null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3311 | |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 3312 | List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>(); |
| 3313 | for (CellInfo ci : info) { |
| 3314 | if (ci instanceof CellInfoGsm) { |
| 3315 | neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci)); |
| 3316 | } else if (ci instanceof CellInfoWcdma) { |
| 3317 | neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci)); |
| 3318 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3319 | } |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 3320 | return (neighbors.size()) > 0 ? neighbors : null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3321 | } |
| 3322 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3323 | private List<CellInfo> getCachedCellInfo() { |
| 3324 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 3325 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3326 | List<CellInfo> info = phone.getAllCellInfo(); |
| 3327 | if (info != null) cellInfos.addAll(info); |
| 3328 | } |
| 3329 | return cellInfos; |
| 3330 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3331 | |
| 3332 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3333 | public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3334 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 3335 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3336 | |
| 3337 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 3338 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 3339 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 3340 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3341 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3342 | .setCallingPid(Binder.getCallingPid()) |
| 3343 | .setCallingUid(Binder.getCallingUid()) |
| 3344 | .setMethod("getAllCellInfo") |
Nathan Harold | 5ae50b5 | 2019-02-20 15:46:36 -0800 | [diff] [blame] | 3345 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3346 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 3347 | .build()); |
| 3348 | switch (locationResult) { |
| 3349 | case DENIED_HARD: |
| 3350 | throw new SecurityException("Not allowed to access cell info"); |
| 3351 | case DENIED_SOFT: |
| 3352 | return new ArrayList<>(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3353 | } |
| 3354 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3355 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3356 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 3357 | return getCachedCellInfo(); |
| 3358 | } |
| 3359 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 3360 | if (DBG_LOC) log("getAllCellInfo: is active user"); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 3361 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3362 | final long identity = Binder.clearCallingIdentity(); |
| 3363 | try { |
| 3364 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 3365 | for (Phone phone : PhoneFactory.getPhones()) { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 3366 | final List<CellInfo> info = (List<CellInfo>) sendRequest( |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 3367 | CMD_GET_ALL_CELL_INFO, null, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3368 | if (info != null) cellInfos.addAll(info); |
| 3369 | } |
| 3370 | return cellInfos; |
| 3371 | } finally { |
| 3372 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3373 | } |
| 3374 | } |
| 3375 | |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 3376 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3377 | public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage, |
| 3378 | String callingFeatureId) { |
| 3379 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, |
| 3380 | getWorkSource(Binder.getCallingUid())); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3381 | } |
| 3382 | |
| 3383 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3384 | public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb, |
| 3385 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3386 | enforceModifyPermission(); |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3387 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3388 | } |
| 3389 | |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3390 | private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb, |
| 3391 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3392 | mApp.getSystemService(AppOpsManager.class) |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3393 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3394 | |
| 3395 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 3396 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 3397 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 3398 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3399 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3400 | .setCallingPid(Binder.getCallingPid()) |
| 3401 | .setCallingUid(Binder.getCallingUid()) |
| 3402 | .setMethod("requestCellInfoUpdate") |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 3403 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
| 3404 | .setMinSdkVersionForFine(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3405 | .build()); |
| 3406 | switch (locationResult) { |
| 3407 | case DENIED_HARD: |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3408 | if (TelephonyPermissions |
| 3409 | .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) { |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 3410 | // Safetynet logging for b/154934934 |
| 3411 | EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid()); |
| 3412 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3413 | throw new SecurityException("Not allowed to access cell info"); |
| 3414 | case DENIED_SOFT: |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3415 | if (TelephonyPermissions |
| 3416 | .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) { |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 3417 | // Safetynet logging for b/154934934 |
| 3418 | EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid()); |
| 3419 | } |
Nathan Harold | 5320c42 | 2019-05-09 10:26:08 -0700 | [diff] [blame] | 3420 | try { |
| 3421 | cb.onCellInfo(new ArrayList<CellInfo>()); |
| 3422 | } catch (RemoteException re) { |
| 3423 | // Drop without consequences |
| 3424 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3425 | return; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3426 | } |
| 3427 | |
Nathan Harold | a939a96 | 2019-05-09 10:13:47 -0700 | [diff] [blame] | 3428 | |
| 3429 | final Phone phone = getPhoneFromSubId(subId); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3430 | if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
| 3431 | |
| 3432 | sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource); |
| 3433 | } |
| 3434 | |
| 3435 | @Override |
Aishwarya Mallampati | 0603fb1 | 2022-08-24 21:16:56 +0000 | [diff] [blame] | 3436 | public void setCellInfoListRate(int rateInMillis, int subId) { |
Jack Yu | a8d8cb8 | 2017-01-16 10:15:34 -0800 | [diff] [blame] | 3437 | enforceModifyPermission(); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 3438 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3439 | |
| 3440 | final long identity = Binder.clearCallingIdentity(); |
| 3441 | try { |
Aishwarya Mallampati | 0603fb1 | 2022-08-24 21:16:56 +0000 | [diff] [blame] | 3442 | Phone phone = getPhone(subId); |
| 3443 | if (phone == null) { |
| 3444 | getDefaultPhone().setCellInfoListRate(rateInMillis, workSource); |
| 3445 | } else { |
| 3446 | phone.setCellInfoListRate(rateInMillis, workSource); |
| 3447 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3448 | } finally { |
| 3449 | Binder.restoreCallingIdentity(identity); |
| 3450 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3451 | } |
| 3452 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3453 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3454 | public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3455 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3456 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3457 | return null; |
| 3458 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3459 | int subId = phone.getSubId(); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3460 | enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot"); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 3461 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3462 | callingPackage, callingFeatureId, "getImeiForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3463 | return null; |
| 3464 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3465 | |
| 3466 | final long identity = Binder.clearCallingIdentity(); |
| 3467 | try { |
| 3468 | return phone.getImei(); |
| 3469 | } finally { |
| 3470 | Binder.restoreCallingIdentity(identity); |
| 3471 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3472 | } |
| 3473 | |
| 3474 | @Override |
arunvoddu | d5c6ce0 | 2022-12-11 06:03:12 +0000 | [diff] [blame^] | 3475 | public String getPrimaryImei(String callingPackage, String callingFeatureId) { |
| 3476 | enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getPrimaryImei"); |
| 3477 | if (!checkCallingOrSelfReadDeviceIdentifiersForAnySub(mApp, callingPackage, |
| 3478 | callingFeatureId, "getPrimaryImei")) { |
| 3479 | throw new SecurityException("Caller does not have permission"); |
| 3480 | } |
| 3481 | final long identity = Binder.clearCallingIdentity(); |
| 3482 | try { |
| 3483 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3484 | if (phone.getImeiType() == Phone.IMEI_TYPE_PRIMARY) { |
| 3485 | return phone.getImei(); |
| 3486 | } |
| 3487 | } |
| 3488 | throw new UnsupportedOperationException("Operation not supported"); |
| 3489 | } finally { |
| 3490 | Binder.restoreCallingIdentity(identity); |
| 3491 | } |
| 3492 | } |
| 3493 | |
| 3494 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3495 | public String getTypeAllocationCodeForSlot(int slotIndex) { |
| 3496 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3497 | String tac = null; |
| 3498 | if (phone != null) { |
| 3499 | String imei = phone.getImei(); |
Vala Zadeh | ab00555 | 2021-09-21 15:54:29 -0700 | [diff] [blame] | 3500 | try { |
| 3501 | tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH); |
| 3502 | } catch (IndexOutOfBoundsException e) { |
| 3503 | Log.e(LOG_TAG, "IMEI length shorter than upper index."); |
| 3504 | return null; |
| 3505 | } |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3506 | } |
| 3507 | return tac; |
| 3508 | } |
| 3509 | |
| 3510 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3511 | public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Shuo Qian | 13d8915 | 2021-05-10 23:58:11 -0700 | [diff] [blame] | 3512 | try { |
| 3513 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 3514 | } catch (SecurityException se) { |
| 3515 | EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid()); |
| 3516 | throw new SecurityException("Package " + callingPackage + " does not belong to " |
| 3517 | + Binder.getCallingUid()); |
| 3518 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3519 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3520 | if (phone == null) { |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 3521 | return null; |
| 3522 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3523 | |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3524 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 3525 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3526 | callingPackage, callingFeatureId, "getMeidForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3527 | return null; |
| 3528 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3529 | |
| 3530 | final long identity = Binder.clearCallingIdentity(); |
| 3531 | try { |
| 3532 | return phone.getMeid(); |
| 3533 | } finally { |
| 3534 | Binder.restoreCallingIdentity(identity); |
| 3535 | } |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 3536 | } |
| 3537 | |
| 3538 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3539 | public String getManufacturerCodeForSlot(int slotIndex) { |
| 3540 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3541 | String manufacturerCode = null; |
| 3542 | if (phone != null) { |
| 3543 | String meid = phone.getMeid(); |
Vala Zadeh | ab00555 | 2021-09-21 15:54:29 -0700 | [diff] [blame] | 3544 | try { |
| 3545 | manufacturerCode = |
| 3546 | meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH); |
| 3547 | } catch (IndexOutOfBoundsException e) { |
| 3548 | Log.e(LOG_TAG, "MEID length shorter than upper index."); |
| 3549 | return null; |
| 3550 | } |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3551 | } |
| 3552 | return manufacturerCode; |
| 3553 | } |
| 3554 | |
| 3555 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3556 | public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage, |
| 3557 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3558 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3559 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3560 | return null; |
| 3561 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3562 | int subId = phone.getSubId(); |
| 3563 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3564 | mApp, subId, callingPackage, callingFeatureId, |
| 3565 | "getDeviceSoftwareVersionForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3566 | return null; |
| 3567 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3568 | |
| 3569 | final long identity = Binder.clearCallingIdentity(); |
| 3570 | try { |
| 3571 | return phone.getDeviceSvn(); |
| 3572 | } finally { |
| 3573 | Binder.restoreCallingIdentity(identity); |
| 3574 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3575 | } |
| 3576 | |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3577 | @Override |
| 3578 | public int getSubscriptionCarrierId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3579 | final long identity = Binder.clearCallingIdentity(); |
| 3580 | try { |
| 3581 | final Phone phone = getPhone(subId); |
| 3582 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId(); |
| 3583 | } finally { |
| 3584 | Binder.restoreCallingIdentity(identity); |
| 3585 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3586 | } |
| 3587 | |
| 3588 | @Override |
| 3589 | public String getSubscriptionCarrierName(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3590 | final long identity = Binder.clearCallingIdentity(); |
| 3591 | try { |
| 3592 | final Phone phone = getPhone(subId); |
| 3593 | return phone == null ? null : phone.getCarrierName(); |
| 3594 | } finally { |
| 3595 | Binder.restoreCallingIdentity(identity); |
| 3596 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3597 | } |
| 3598 | |
calvinpan | ffe225e | 2018-11-01 19:43:06 +0800 | [diff] [blame] | 3599 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3600 | public int getSubscriptionSpecificCarrierId(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3601 | final long identity = Binder.clearCallingIdentity(); |
| 3602 | try { |
| 3603 | final Phone phone = getPhone(subId); |
| 3604 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3605 | : phone.getSpecificCarrierId(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3606 | } finally { |
| 3607 | Binder.restoreCallingIdentity(identity); |
| 3608 | } |
| 3609 | } |
| 3610 | |
| 3611 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3612 | public String getSubscriptionSpecificCarrierName(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3613 | final long identity = Binder.clearCallingIdentity(); |
| 3614 | try { |
| 3615 | final Phone phone = getPhone(subId); |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3616 | return phone == null ? null : phone.getSpecificCarrierName(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3617 | } finally { |
| 3618 | Binder.restoreCallingIdentity(identity); |
| 3619 | } |
| 3620 | } |
| 3621 | |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 3622 | @Override |
chen xu | 864e11c | 2018-12-06 22:10:03 -0800 | [diff] [blame] | 3623 | public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) { |
| 3624 | if (!isSubscriptionMccMnc) { |
| 3625 | enforceReadPrivilegedPermission("getCarrierIdFromMccMnc"); |
| 3626 | } |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 3627 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3628 | if (phone == null) { |
| 3629 | return TelephonyManager.UNKNOWN_CARRIER_ID; |
| 3630 | } |
| 3631 | final long identity = Binder.clearCallingIdentity(); |
| 3632 | try { |
| 3633 | return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc); |
| 3634 | } finally { |
| 3635 | Binder.restoreCallingIdentity(identity); |
| 3636 | } |
| 3637 | } |
| 3638 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3639 | // |
| 3640 | // Internal helper methods. |
| 3641 | // |
| 3642 | |
Sanket Padawe | ee13a9b | 2016-03-08 17:30:28 -0800 | [diff] [blame] | 3643 | /** |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3644 | * Make sure the caller is the calling package itself |
| 3645 | * |
| 3646 | * @throws SecurityException if the caller is not the calling package |
| 3647 | */ |
| 3648 | private void enforceCallingPackage(String callingPackage, int callingUid, String message) { |
| 3649 | int packageUid = -1; |
Grace Jia | dbefca0 | 2021-04-26 15:13:31 -0700 | [diff] [blame] | 3650 | PackageManager pm = mApp.getBaseContext().createContextAsUser( |
| 3651 | UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager(); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3652 | try { |
Grace Jia | dbefca0 | 2021-04-26 15:13:31 -0700 | [diff] [blame] | 3653 | packageUid = pm.getPackageUid(callingPackage, 0); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3654 | } catch (PackageManager.NameNotFoundException e) { |
| 3655 | // packageUid is -1 |
| 3656 | } |
| 3657 | if (packageUid != callingUid) { |
| 3658 | throw new SecurityException(message + ": Package " + callingPackage |
| 3659 | + " does not belong to " + callingUid); |
| 3660 | } |
| 3661 | } |
| 3662 | |
| 3663 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3664 | * Make sure the caller has the MODIFY_PHONE_STATE permission. |
| 3665 | * |
| 3666 | * @throws SecurityException if the caller does not have the required permission |
| 3667 | */ |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 3668 | @VisibleForTesting |
| 3669 | public void enforceModifyPermission() { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3670 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null); |
| 3671 | } |
| 3672 | |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 3673 | /** |
| 3674 | * Make sure the caller has the MODIFY_PHONE_STATE permission. |
| 3675 | * |
| 3676 | * @throws SecurityException if the caller does not have the required permission |
| 3677 | */ |
| 3678 | @VisibleForTesting |
| 3679 | public void enforceReadPermission() { |
| 3680 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, null); |
| 3681 | } |
| 3682 | |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 3683 | private void enforceActiveEmergencySessionPermission() { |
| 3684 | mApp.enforceCallingOrSelfPermission( |
| 3685 | android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null); |
| 3686 | } |
| 3687 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3688 | /** |
| 3689 | * Make sure the caller has the CALL_PHONE permission. |
| 3690 | * |
| 3691 | * @throws SecurityException if the caller does not have the required permission |
| 3692 | */ |
| 3693 | private void enforceCallPermission() { |
| 3694 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null); |
| 3695 | } |
| 3696 | |
paulhu | 5a77360 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 3697 | private void enforceSettingsPermission() { |
| 3698 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 3699 | } |
| 3700 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 3701 | private void enforceRebootPermission() { |
| 3702 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null); |
| 3703 | } |
| 3704 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3705 | private String createTelUrl(String number) { |
| 3706 | if (TextUtils.isEmpty(number)) { |
| 3707 | return null; |
| 3708 | } |
| 3709 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3710 | return "tel:" + number; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3711 | } |
| 3712 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3713 | private static void log(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3714 | Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 3715 | } |
| 3716 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3717 | private static void logv(String msg) { |
| 3718 | Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 3719 | } |
| 3720 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3721 | private static void loge(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3722 | Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 3723 | } |
| 3724 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3725 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3726 | public int getActivePhoneType() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3727 | return getActivePhoneTypeForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3728 | } |
| 3729 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3730 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3731 | public int getActivePhoneTypeForSlot(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3732 | final long identity = Binder.clearCallingIdentity(); |
| 3733 | try { |
| 3734 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3735 | if (phone == null) { |
| 3736 | return PhoneConstants.PHONE_TYPE_NONE; |
| 3737 | } else { |
| 3738 | return phone.getPhoneType(); |
| 3739 | } |
| 3740 | } finally { |
| 3741 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3742 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3743 | } |
| 3744 | |
| 3745 | /** |
| 3746 | * Returns the CDMA ERI icon index to display |
| 3747 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3748 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3749 | public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) { |
| 3750 | return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage, |
| 3751 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3752 | } |
| 3753 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3754 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3755 | public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage, |
| 3756 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3757 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3758 | mApp, subId, callingPackage, callingFeatureId, |
| 3759 | "getCdmaEriIconIndexForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3760 | return -1; |
| 3761 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3762 | |
| 3763 | final long identity = Binder.clearCallingIdentity(); |
| 3764 | try { |
| 3765 | final Phone phone = getPhone(subId); |
| 3766 | if (phone != null) { |
| 3767 | return phone.getCdmaEriIconIndex(); |
| 3768 | } else { |
| 3769 | return -1; |
| 3770 | } |
| 3771 | } finally { |
| 3772 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3773 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3774 | } |
| 3775 | |
| 3776 | /** |
| 3777 | * Returns the CDMA ERI icon mode, |
| 3778 | * 0 - ON |
| 3779 | * 1 - FLASHING |
| 3780 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3781 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3782 | public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) { |
| 3783 | return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 3784 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3785 | } |
| 3786 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3787 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3788 | public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage, |
| 3789 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3790 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3791 | mApp, subId, callingPackage, callingFeatureId, |
| 3792 | "getCdmaEriIconModeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3793 | return -1; |
| 3794 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3795 | |
| 3796 | final long identity = Binder.clearCallingIdentity(); |
| 3797 | try { |
| 3798 | final Phone phone = getPhone(subId); |
| 3799 | if (phone != null) { |
| 3800 | return phone.getCdmaEriIconMode(); |
| 3801 | } else { |
| 3802 | return -1; |
| 3803 | } |
| 3804 | } finally { |
| 3805 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3806 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3807 | } |
| 3808 | |
| 3809 | /** |
| 3810 | * Returns the CDMA ERI text, |
| 3811 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3812 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3813 | public String getCdmaEriText(String callingPackage, String callingFeatureId) { |
| 3814 | return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage, |
| 3815 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3816 | } |
| 3817 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3818 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3819 | public String getCdmaEriTextForSubscriber(int subId, String callingPackage, |
| 3820 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3821 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3822 | mApp, subId, callingPackage, callingFeatureId, |
| 3823 | "getCdmaEriIconTextForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3824 | return null; |
| 3825 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3826 | |
| 3827 | final long identity = Binder.clearCallingIdentity(); |
| 3828 | try { |
| 3829 | final Phone phone = getPhone(subId); |
| 3830 | if (phone != null) { |
| 3831 | return phone.getCdmaEriText(); |
| 3832 | } else { |
| 3833 | return null; |
| 3834 | } |
| 3835 | } finally { |
| 3836 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3837 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3838 | } |
| 3839 | |
| 3840 | /** |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3841 | * Returns the CDMA MDN. |
| 3842 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3843 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3844 | public String getCdmaMdn(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3845 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3846 | mApp, subId, "getCdmaMdn"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3847 | |
| 3848 | final long identity = Binder.clearCallingIdentity(); |
| 3849 | try { |
| 3850 | final Phone phone = getPhone(subId); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3851 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3852 | return phone.getLine1Number(); |
| 3853 | } else { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3854 | loge("getCdmaMdn: no phone found. Invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3855 | return null; |
| 3856 | } |
| 3857 | } finally { |
| 3858 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3859 | } |
| 3860 | } |
| 3861 | |
| 3862 | /** |
| 3863 | * Returns the CDMA MIN. |
| 3864 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3865 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3866 | public String getCdmaMin(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3867 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3868 | mApp, subId, "getCdmaMin"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3869 | |
| 3870 | final long identity = Binder.clearCallingIdentity(); |
| 3871 | try { |
| 3872 | final Phone phone = getPhone(subId); |
| 3873 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
| 3874 | return phone.getCdmaMin(); |
| 3875 | } else { |
| 3876 | return null; |
| 3877 | } |
| 3878 | } finally { |
| 3879 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3880 | } |
| 3881 | } |
| 3882 | |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3883 | @Override |
| 3884 | public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis, |
| 3885 | INumberVerificationCallback callback, String callingPackage) { |
| 3886 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 3887 | != PERMISSION_GRANTED) { |
| 3888 | throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission"); |
| 3889 | } |
| 3890 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 3891 | |
| 3892 | String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp); |
| 3893 | if (!TextUtils.equals(callingPackage, authorizedPackage)) { |
Hall Liu | b9d8feb | 2021-01-13 10:28:04 -0800 | [diff] [blame] | 3894 | throw new SecurityException("Calling package must be configured in the device config: " |
| 3895 | + "calling package: " + callingPackage |
| 3896 | + ", configured package: " + authorizedPackage); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3897 | } |
| 3898 | |
| 3899 | if (range == null) { |
| 3900 | throw new NullPointerException("Range must be non-null"); |
| 3901 | } |
| 3902 | |
| 3903 | timeoutMillis = Math.min(timeoutMillis, |
Hall Liu | bd069e3 | 2019-02-28 18:56:30 -0800 | [diff] [blame] | 3904 | TelephonyManager.getMaxNumberVerificationTimeoutMillis()); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3905 | |
| 3906 | NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis); |
| 3907 | } |
| 3908 | |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3909 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3910 | * Returns true if CDMA provisioning needs to run. |
| 3911 | */ |
| 3912 | public boolean needsOtaServiceProvisioning() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3913 | final long identity = Binder.clearCallingIdentity(); |
| 3914 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3915 | return getDefaultPhone().needsOtaServiceProvisioning(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3916 | } finally { |
| 3917 | Binder.restoreCallingIdentity(identity); |
| 3918 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3919 | } |
| 3920 | |
| 3921 | /** |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3922 | * Sets the voice mail number of a given subId. |
| 3923 | */ |
| 3924 | @Override |
| 3925 | public boolean setVoiceMailNumber(int subId, String alphaTag, String number) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 3926 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 3927 | mApp, subId, "setVoiceMailNumber"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3928 | |
| 3929 | final long identity = Binder.clearCallingIdentity(); |
| 3930 | try { |
| 3931 | Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER, |
| 3932 | new Pair<String, String>(alphaTag, number), new Integer(subId)); |
| 3933 | return success; |
| 3934 | } finally { |
| 3935 | Binder.restoreCallingIdentity(identity); |
| 3936 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3937 | } |
| 3938 | |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3939 | @Override |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3940 | public Bundle getVisualVoicemailSettings(String callingPackage, int subId) { |
| 3941 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 3942 | TelecomManager tm = mApp.getSystemService(TelecomManager.class); |
| 3943 | String systemDialer = tm.getSystemDialerPackage(); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3944 | if (!TextUtils.equals(callingPackage, systemDialer)) { |
| 3945 | throw new SecurityException("caller must be system dialer"); |
| 3946 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3947 | |
| 3948 | final long identity = Binder.clearCallingIdentity(); |
| 3949 | try { |
| 3950 | PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId); |
| 3951 | if (phoneAccountHandle == null) { |
| 3952 | return null; |
| 3953 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3954 | return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3955 | } finally { |
| 3956 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3957 | } |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3958 | } |
| 3959 | |
| 3960 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3961 | public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId, |
| 3962 | int subId) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3963 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3964 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3965 | mApp, subId, callingPackage, callingFeatureId, |
| 3966 | "getVisualVoicemailPackageName")) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3967 | return null; |
| 3968 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3969 | |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 3970 | final long identity = Binder.clearCallingIdentity(); |
| 3971 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3972 | return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName(); |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 3973 | } finally { |
| 3974 | Binder.restoreCallingIdentity(identity); |
| 3975 | } |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3976 | } |
| 3977 | |
| 3978 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3979 | public void enableVisualVoicemailSmsFilter(String callingPackage, int subId, |
| 3980 | VisualVoicemailSmsFilterSettings settings) { |
| 3981 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3982 | |
| 3983 | final long identity = Binder.clearCallingIdentity(); |
| 3984 | try { |
| 3985 | VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3986 | mApp, callingPackage, subId, settings); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3987 | } finally { |
| 3988 | Binder.restoreCallingIdentity(identity); |
| 3989 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3990 | } |
| 3991 | |
| 3992 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3993 | public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) { |
| 3994 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3995 | |
| 3996 | final long identity = Binder.clearCallingIdentity(); |
| 3997 | try { |
| 3998 | VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3999 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4000 | } finally { |
| 4001 | Binder.restoreCallingIdentity(identity); |
| 4002 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 4003 | } |
| 4004 | |
| 4005 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 4006 | public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings( |
| 4007 | String callingPackage, int subId) { |
| 4008 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4009 | |
| 4010 | final long identity = Binder.clearCallingIdentity(); |
| 4011 | try { |
| 4012 | return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4013 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4014 | } finally { |
| 4015 | Binder.restoreCallingIdentity(identity); |
| 4016 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 4017 | } |
| 4018 | |
| 4019 | @Override |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 4020 | public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4021 | enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4022 | |
| 4023 | final long identity = Binder.clearCallingIdentity(); |
| 4024 | try { |
| 4025 | return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4026 | mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4027 | } finally { |
| 4028 | Binder.restoreCallingIdentity(identity); |
| 4029 | } |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 4030 | } |
| 4031 | |
| 4032 | @Override |
Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 4033 | public void sendVisualVoicemailSmsForSubscriber(String callingPackage, |
| 4034 | String callingAttributionTag, int subId, String number, int port, String text, |
| 4035 | PendingIntent sentIntent) { |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 4036 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 4037 | enforceVisualVoicemailPackage(callingPackage, subId); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 4038 | enforceSendSmsPermission(); |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 4039 | SmsController smsController = PhoneFactory.getSmsController(); |
Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 4040 | smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag, |
| 4041 | subId, number, port, text, sentIntent); |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 4042 | } |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 4043 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 4044 | /** |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4045 | * Sets the voice activation state of a given subId. |
| 4046 | */ |
| 4047 | @Override |
| 4048 | public void setVoiceActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4049 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4050 | mApp, subId, "setVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4051 | |
| 4052 | final long identity = Binder.clearCallingIdentity(); |
| 4053 | try { |
| 4054 | final Phone phone = getPhone(subId); |
| 4055 | if (phone != null) { |
| 4056 | phone.setVoiceActivationState(activationState); |
| 4057 | } else { |
| 4058 | loge("setVoiceActivationState fails with invalid subId: " + subId); |
| 4059 | } |
| 4060 | } finally { |
| 4061 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4062 | } |
| 4063 | } |
| 4064 | |
| 4065 | /** |
| 4066 | * Sets the data activation state of a given subId. |
| 4067 | */ |
| 4068 | @Override |
| 4069 | public void setDataActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4070 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4071 | mApp, subId, "setDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4072 | |
| 4073 | final long identity = Binder.clearCallingIdentity(); |
| 4074 | try { |
| 4075 | final Phone phone = getPhone(subId); |
| 4076 | if (phone != null) { |
| 4077 | phone.setDataActivationState(activationState); |
| 4078 | } else { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 4079 | loge("setDataActivationState fails with invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4080 | } |
| 4081 | } finally { |
| 4082 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4083 | } |
| 4084 | } |
| 4085 | |
| 4086 | /** |
| 4087 | * Returns the voice activation state of a given subId. |
| 4088 | */ |
| 4089 | @Override |
| 4090 | public int getVoiceActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4091 | enforceReadPrivilegedPermission("getVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4092 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4093 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4094 | final long identity = Binder.clearCallingIdentity(); |
| 4095 | try { |
| 4096 | if (phone != null) { |
| 4097 | return phone.getVoiceActivationState(); |
| 4098 | } else { |
| 4099 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 4100 | } |
| 4101 | } finally { |
| 4102 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4103 | } |
| 4104 | } |
| 4105 | |
| 4106 | /** |
| 4107 | * Returns the data activation state of a given subId. |
| 4108 | */ |
| 4109 | @Override |
| 4110 | public int getDataActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4111 | enforceReadPrivilegedPermission("getDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4112 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4113 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4114 | final long identity = Binder.clearCallingIdentity(); |
| 4115 | try { |
| 4116 | if (phone != null) { |
| 4117 | return phone.getDataActivationState(); |
| 4118 | } else { |
| 4119 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 4120 | } |
| 4121 | } finally { |
| 4122 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4123 | } |
| 4124 | } |
| 4125 | |
| 4126 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4127 | * Returns the unread count of voicemails for a subId |
| 4128 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4129 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4130 | public int getVoiceMessageCountForSubscriber(int subId, String callingPackage, |
| 4131 | String callingFeatureId) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 4132 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4133 | mApp, subId, callingPackage, callingFeatureId, |
| 4134 | "getVoiceMessageCountForSubscriber")) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 4135 | return 0; |
| 4136 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4137 | final long identity = Binder.clearCallingIdentity(); |
| 4138 | try { |
| 4139 | final Phone phone = getPhone(subId); |
| 4140 | if (phone != null) { |
| 4141 | return phone.getVoiceMessageCount(); |
| 4142 | } else { |
| 4143 | return 0; |
| 4144 | } |
| 4145 | } finally { |
| 4146 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4147 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4148 | } |
| 4149 | |
| 4150 | /** |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 4151 | * returns true, if the device is in a state where both voice and data |
| 4152 | * are supported simultaneously. This can change based on location or network condition. |
| 4153 | */ |
| 4154 | @Override |
| 4155 | public boolean isConcurrentVoiceAndDataAllowed(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4156 | final long identity = Binder.clearCallingIdentity(); |
| 4157 | try { |
| 4158 | final Phone phone = getPhone(subId); |
| 4159 | return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed()); |
| 4160 | } finally { |
| 4161 | Binder.restoreCallingIdentity(identity); |
| 4162 | } |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 4163 | } |
| 4164 | |
| 4165 | /** |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4166 | * Send the dialer code if called from the current default dialer or the caller has |
| 4167 | * carrier privilege. |
| 4168 | * @param inputCode The dialer code to send |
| 4169 | */ |
| 4170 | @Override |
| 4171 | public void sendDialerSpecialCode(String callingPackage, String inputCode) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4172 | final Phone defaultPhone = getDefaultPhone(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4173 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 4174 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 4175 | String defaultDialer = tm.getDefaultDialerPackage(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4176 | if (!TextUtils.equals(callingPackage, defaultDialer)) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 4177 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4178 | getDefaultSubscription(), "sendDialerSpecialCode"); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4179 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4180 | |
| 4181 | final long identity = Binder.clearCallingIdentity(); |
| 4182 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4183 | defaultPhone.sendDialerSpecialCode(inputCode); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4184 | } finally { |
| 4185 | Binder.restoreCallingIdentity(identity); |
| 4186 | } |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4187 | } |
| 4188 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 4189 | @Override |
| 4190 | public int getNetworkSelectionMode(int subId) { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 4191 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4192 | .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 4193 | mApp, subId, "getNetworkSelectionMode"); |
| 4194 | final long identity = Binder.clearCallingIdentity(); |
| 4195 | try { |
| 4196 | if (!isActiveSubscription(subId)) { |
| 4197 | return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 4198 | } |
| 4199 | return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId); |
| 4200 | } finally { |
| 4201 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 4202 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 4203 | } |
| 4204 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4205 | @Override |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 4206 | public boolean isInEmergencySmsMode() { |
| 4207 | enforceReadPrivilegedPermission("isInEmergencySmsMode"); |
| 4208 | final long identity = Binder.clearCallingIdentity(); |
| 4209 | try { |
| 4210 | for (Phone phone : PhoneFactory.getPhones()) { |
| 4211 | if (phone.isInEmergencySmsMode()) { |
| 4212 | return true; |
| 4213 | } |
| 4214 | } |
| 4215 | } finally { |
| 4216 | Binder.restoreCallingIdentity(identity); |
| 4217 | } |
| 4218 | return false; |
| 4219 | } |
| 4220 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4221 | /** |
| 4222 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4223 | * @param subId The subscription to use to check the configuration. |
| 4224 | * @param c The callback that will be used to send the result. |
| 4225 | */ |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 4226 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4227 | public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c) |
| 4228 | throws RemoteException { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4229 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4230 | mApp, subId, "registerImsRegistrationCallback"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4231 | |
| 4232 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4233 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4234 | "IMS not available on device."); |
| 4235 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4236 | final long token = Binder.clearCallingIdentity(); |
| 4237 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4238 | int slotId = getSlotIndexOrException(subId); |
| 4239 | verifyImsMmTelConfiguredOrThrow(slotId); |
joonhunshin | 49f0aed | 2022-08-05 08:33:05 +0000 | [diff] [blame] | 4240 | |
| 4241 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4242 | if (controller != null) { |
| 4243 | ImsManager imsManager = controller.getImsManager(subId); |
| 4244 | if (imsManager != null) { |
| 4245 | imsManager.addRegistrationCallbackForSubscription(c, subId); |
| 4246 | } else { |
| 4247 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE); |
| 4248 | } |
| 4249 | } else { |
| 4250 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION); |
| 4251 | } |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4252 | } catch (ImsException e) { |
| 4253 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4254 | } finally { |
| 4255 | Binder.restoreCallingIdentity(token); |
| 4256 | } |
| 4257 | } |
| 4258 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4259 | /** |
| 4260 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4261 | * @param subId The subscription to use to check the configuration. |
| 4262 | * @param c The callback that will be used to send the result. |
| 4263 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4264 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4265 | public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4266 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4267 | mApp, subId, "unregisterImsRegistrationCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4268 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4269 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4270 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4271 | final long token = Binder.clearCallingIdentity(); |
joonhunshin | 49f0aed | 2022-08-05 08:33:05 +0000 | [diff] [blame] | 4272 | |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4273 | try { |
joonhunshin | 49f0aed | 2022-08-05 08:33:05 +0000 | [diff] [blame] | 4274 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4275 | if (controller != null) { |
| 4276 | ImsManager imsManager = controller.getImsManager(subId); |
| 4277 | if (imsManager != null) { |
| 4278 | imsManager.removeRegistrationCallbackForSubscription(c, subId); |
| 4279 | } else { |
| 4280 | Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId |
| 4281 | + "is inactive, ignoring unregister."); |
| 4282 | // If the ImsManager is not valid, just return, since the callback |
| 4283 | // will already have been removed internally. |
| 4284 | } |
| 4285 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4286 | } finally { |
| 4287 | Binder.restoreCallingIdentity(token); |
| 4288 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4289 | } |
| 4290 | |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 4291 | /** |
| 4292 | * Get the IMS service registration state for the MmTelFeature associated with this sub id. |
| 4293 | */ |
| 4294 | @Override |
| 4295 | public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) { |
| 4296 | enforceReadPrivilegedPermission("getImsMmTelRegistrationState"); |
| 4297 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4298 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4299 | "IMS not available on device."); |
| 4300 | } |
| 4301 | final long token = Binder.clearCallingIdentity(); |
| 4302 | try { |
| 4303 | Phone phone = getPhone(subId); |
| 4304 | if (phone == null) { |
| 4305 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 4306 | + subId + "'"); |
| 4307 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 4308 | } |
| 4309 | phone.getImsRegistrationState(regState -> { |
| 4310 | try { |
| 4311 | consumer.accept((regState == null) |
| 4312 | ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState); |
| 4313 | } catch (RemoteException e) { |
| 4314 | // Ignore if the remote process is no longer available to call back. |
| 4315 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 4316 | } |
| 4317 | }); |
| 4318 | } finally { |
| 4319 | Binder.restoreCallingIdentity(token); |
| 4320 | } |
| 4321 | } |
| 4322 | |
| 4323 | /** |
| 4324 | * Get the transport type for the IMS service registration state. |
| 4325 | */ |
| 4326 | @Override |
| 4327 | public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4328 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4329 | mApp, subId, "getImsMmTelRegistrationTransportType"); |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 4330 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4331 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4332 | "IMS not available on device."); |
| 4333 | } |
| 4334 | final long token = Binder.clearCallingIdentity(); |
| 4335 | try { |
| 4336 | Phone phone = getPhone(subId); |
| 4337 | if (phone == null) { |
| 4338 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 4339 | + subId + "'"); |
| 4340 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 4341 | } |
| 4342 | phone.getImsRegistrationTech(regTech -> { |
| 4343 | // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager |
| 4344 | int regTechConverted = (regTech == null) |
| 4345 | ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech; |
| 4346 | regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get( |
| 4347 | regTechConverted); |
| 4348 | try { |
| 4349 | consumer.accept(regTechConverted); |
| 4350 | } catch (RemoteException e) { |
| 4351 | // Ignore if the remote process is no longer available to call back. |
| 4352 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 4353 | } |
| 4354 | }); |
| 4355 | } finally { |
| 4356 | Binder.restoreCallingIdentity(token); |
| 4357 | } |
| 4358 | } |
| 4359 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4360 | /** |
| 4361 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4362 | * @param subId The subscription to use to check the configuration. |
| 4363 | * @param c The callback that will be used to send the result. |
| 4364 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4365 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4366 | public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) |
| 4367 | throws RemoteException { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4368 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4369 | mApp, subId, "registerMmTelCapabilityCallback"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4370 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4371 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4372 | "IMS not available on device."); |
| 4373 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4374 | final long token = Binder.clearCallingIdentity(); |
| 4375 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4376 | int slotId = getSlotIndexOrException(subId); |
| 4377 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 4378 | ImsManager.getInstance(mApp, slotId).addCapabilitiesCallbackForSubscription(c, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4379 | } catch (ImsException e) { |
| 4380 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4381 | } finally { |
| 4382 | Binder.restoreCallingIdentity(token); |
| 4383 | } |
| 4384 | } |
| 4385 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4386 | /** |
| 4387 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4388 | * @param subId The subscription to use to check the configuration. |
| 4389 | * @param c The callback that will be used to send the result. |
| 4390 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4391 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4392 | public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4393 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4394 | mApp, subId, "unregisterMmTelCapabilityCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4395 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4396 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4397 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4398 | |
| 4399 | final long token = Binder.clearCallingIdentity(); |
| 4400 | try { |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4401 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4402 | .removeCapabilitiesCallbackForSubscription(c, subId); |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4403 | } catch (ImsException e) { |
| 4404 | Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId |
| 4405 | + "is inactive, ignoring unregister."); |
| 4406 | // If the subscription is no longer active, just return, since the callback |
| 4407 | // will already have been removed internally. |
| 4408 | } finally { |
| 4409 | Binder.restoreCallingIdentity(token); |
| 4410 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4411 | } |
| 4412 | |
| 4413 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4414 | public boolean isCapable(int subId, int capability, int regTech) { |
| 4415 | enforceReadPrivilegedPermission("isCapable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4416 | final long token = Binder.clearCallingIdentity(); |
| 4417 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4418 | int slotId = getSlotIndexOrException(subId); |
| 4419 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 4420 | return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech); |
| 4421 | } catch (com.android.ims.ImsException e) { |
| 4422 | Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage()); |
| 4423 | return false; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4424 | } catch (ImsException e) { |
Brad Ebinger | 6b5ac22 | 2019-02-04 14:36:52 -0800 | [diff] [blame] | 4425 | Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false."); |
| 4426 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4427 | } finally { |
| 4428 | Binder.restoreCallingIdentity(token); |
| 4429 | } |
| 4430 | } |
| 4431 | |
| 4432 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4433 | public boolean isAvailable(int subId, int capability, int regTech) { |
| 4434 | enforceReadPrivilegedPermission("isAvailable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4435 | final long token = Binder.clearCallingIdentity(); |
| 4436 | try { |
| 4437 | Phone phone = getPhone(subId); |
| 4438 | if (phone == null) return false; |
| 4439 | return phone.isImsCapabilityAvailable(capability, regTech); |
Daniel Bright | 5e40e4e | 2020-03-11 16:35:39 -0700 | [diff] [blame] | 4440 | } catch (com.android.ims.ImsException e) { |
| 4441 | Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage()); |
| 4442 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4443 | } finally { |
| 4444 | Binder.restoreCallingIdentity(token); |
| 4445 | } |
| 4446 | } |
| 4447 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4448 | /** |
| 4449 | * Determines if the MmTel feature capability is supported by the carrier configuration for this |
| 4450 | * subscription. |
| 4451 | * @param subId The subscription to use to check the configuration. |
| 4452 | * @param callback The callback that will be used to send the result. |
| 4453 | * @param capability The MmTelFeature capability that will be used to send the result. |
| 4454 | * @param transportType The transport type of the MmTelFeature capability. |
| 4455 | */ |
| 4456 | @Override |
| 4457 | public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability, |
| 4458 | int transportType) { |
| 4459 | enforceReadPrivilegedPermission("isMmTelCapabilitySupported"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4460 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4461 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4462 | "IMS not available on device."); |
| 4463 | } |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4464 | final long token = Binder.clearCallingIdentity(); |
| 4465 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4466 | int slotId = getSlotIndex(subId); |
| 4467 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4468 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '" |
| 4469 | + subId + "'"); |
| 4470 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 4471 | } |
| 4472 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 4473 | ImsManager.getInstance(mApp, slotId).isSupported(capability, |
| 4474 | transportType, aBoolean -> { |
| 4475 | try { |
| 4476 | callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0)); |
| 4477 | } catch (RemoteException e) { |
| 4478 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not " |
| 4479 | + "running. Ignore"); |
| 4480 | } |
| 4481 | }); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4482 | } catch (ImsException e) { |
| 4483 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4484 | } finally { |
| 4485 | Binder.restoreCallingIdentity(token); |
| 4486 | } |
| 4487 | } |
| 4488 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4489 | /** |
| 4490 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4491 | * @param subId The subscription to use to check the configuration. |
| 4492 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4493 | @Override |
| 4494 | public boolean isAdvancedCallingSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4495 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4496 | mApp, subId, "isAdvancedCallingSettingEnabled"); |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4497 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4498 | final long token = Binder.clearCallingIdentity(); |
| 4499 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4500 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4501 | // 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] | 4502 | return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4503 | } catch (ImsException e) { |
| 4504 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4505 | } finally { |
| 4506 | Binder.restoreCallingIdentity(token); |
| 4507 | } |
| 4508 | } |
| 4509 | |
| 4510 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4511 | public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4512 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4513 | "setAdvancedCallingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4514 | final long identity = Binder.clearCallingIdentity(); |
| 4515 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4516 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4517 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4518 | // 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] | 4519 | ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4520 | } catch (ImsException e) { |
| 4521 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4522 | } finally { |
| 4523 | Binder.restoreCallingIdentity(identity); |
| 4524 | } |
| 4525 | } |
| 4526 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4527 | /** |
| 4528 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4529 | * @param subId The subscription to use to check the configuration. |
| 4530 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4531 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4532 | public boolean isVtSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4533 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4534 | mApp, subId, "isVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4535 | final long identity = Binder.clearCallingIdentity(); |
| 4536 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4537 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4538 | // 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] | 4539 | return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4540 | } catch (ImsException e) { |
| 4541 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4542 | } finally { |
| 4543 | Binder.restoreCallingIdentity(identity); |
| 4544 | } |
| 4545 | } |
| 4546 | |
| 4547 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4548 | public void setVtSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4549 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4550 | "setVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4551 | final long identity = Binder.clearCallingIdentity(); |
| 4552 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4553 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4554 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4555 | // 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] | 4556 | ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4557 | } catch (ImsException e) { |
| 4558 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4559 | } finally { |
| 4560 | Binder.restoreCallingIdentity(identity); |
| 4561 | } |
| 4562 | } |
| 4563 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4564 | /** |
| 4565 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4566 | * @param subId The subscription to use to check the configuration. |
| 4567 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4568 | @Override |
| 4569 | public boolean isVoWiFiSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4570 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4571 | mApp, subId, "isVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4572 | final long identity = Binder.clearCallingIdentity(); |
| 4573 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4574 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4575 | // 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] | 4576 | return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4577 | } catch (ImsException e) { |
| 4578 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4579 | } finally { |
| 4580 | Binder.restoreCallingIdentity(identity); |
| 4581 | } |
| 4582 | } |
| 4583 | |
| 4584 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4585 | public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4586 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4587 | "setVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4588 | final long identity = Binder.clearCallingIdentity(); |
| 4589 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4590 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4591 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4592 | // 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] | 4593 | ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4594 | } catch (ImsException e) { |
| 4595 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4596 | } finally { |
| 4597 | Binder.restoreCallingIdentity(identity); |
| 4598 | } |
| 4599 | } |
| 4600 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4601 | /** |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 4602 | * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not |
| 4603 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4604 | * @param subId The subscription to use to check the configuration. |
| 4605 | */ |
| 4606 | @Override |
| 4607 | public boolean isCrossSimCallingEnabledByUser(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4608 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 4609 | mApp, subId, "isCrossSimCallingEnabledByUser"); |
| 4610 | final long identity = Binder.clearCallingIdentity(); |
| 4611 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4612 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4613 | // 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] | 4614 | return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser(); |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 4615 | } catch (ImsException e) { |
| 4616 | throw new ServiceSpecificException(e.getCode()); |
| 4617 | } finally { |
| 4618 | Binder.restoreCallingIdentity(identity); |
| 4619 | } |
| 4620 | } |
| 4621 | |
| 4622 | /** |
| 4623 | * Sets the user's setting for whether or not Voice over Cross SIM is enabled. |
| 4624 | * Requires MODIFY_PHONE_STATE permission. |
| 4625 | * @param subId The subscription to use to check the configuration. |
| 4626 | * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled, |
| 4627 | * false otherwise |
| 4628 | */ |
| 4629 | @Override |
| 4630 | public void setCrossSimCallingEnabled(int subId, boolean isEnabled) { |
| 4631 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4632 | "setCrossSimCallingEnabled"); |
| 4633 | final long identity = Binder.clearCallingIdentity(); |
| 4634 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4635 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4636 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4637 | // 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] | 4638 | ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled); |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 4639 | } catch (ImsException e) { |
| 4640 | throw new ServiceSpecificException(e.getCode()); |
| 4641 | } finally { |
| 4642 | Binder.restoreCallingIdentity(identity); |
| 4643 | } |
| 4644 | } |
| 4645 | |
| 4646 | /** |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4647 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4648 | * @param subId The subscription to use to check the configuration. |
| 4649 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4650 | @Override |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4651 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4652 | public boolean isVoWiFiRoamingSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4653 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4654 | mApp, subId, "isVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4655 | final long identity = Binder.clearCallingIdentity(); |
| 4656 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4657 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4658 | // 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] | 4659 | return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4660 | } catch (ImsException e) { |
| 4661 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4662 | } finally { |
| 4663 | Binder.restoreCallingIdentity(identity); |
| 4664 | } |
| 4665 | } |
| 4666 | |
| 4667 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4668 | public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4669 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4670 | "setVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4671 | final long identity = Binder.clearCallingIdentity(); |
| 4672 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4673 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4674 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4675 | // 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] | 4676 | ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4677 | } catch (ImsException e) { |
| 4678 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4679 | } finally { |
| 4680 | Binder.restoreCallingIdentity(identity); |
| 4681 | } |
| 4682 | } |
| 4683 | |
| 4684 | @Override |
| 4685 | public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) { |
| 4686 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4687 | "setVoWiFiNonPersistent"); |
| 4688 | final long identity = Binder.clearCallingIdentity(); |
| 4689 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4690 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4691 | // This setting will be ignored if the ImsService isn't up. |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4692 | ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4693 | } catch (ImsException e) { |
| 4694 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4695 | } finally { |
| 4696 | Binder.restoreCallingIdentity(identity); |
| 4697 | } |
| 4698 | } |
| 4699 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4700 | /** |
| 4701 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4702 | * @param subId The subscription to use to check the configuration. |
| 4703 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4704 | @Override |
| 4705 | public int getVoWiFiModeSetting(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4706 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4707 | mApp, subId, "getVoWiFiModeSetting"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4708 | final long identity = Binder.clearCallingIdentity(); |
| 4709 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4710 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4711 | // 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] | 4712 | return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4713 | } catch (ImsException e) { |
| 4714 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4715 | } finally { |
| 4716 | Binder.restoreCallingIdentity(identity); |
| 4717 | } |
| 4718 | } |
| 4719 | |
| 4720 | @Override |
| 4721 | public void setVoWiFiModeSetting(int subId, int mode) { |
| 4722 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4723 | "setVoWiFiModeSetting"); |
| 4724 | final long identity = Binder.clearCallingIdentity(); |
| 4725 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4726 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4727 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4728 | // 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] | 4729 | ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4730 | } catch (ImsException e) { |
| 4731 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4732 | } finally { |
| 4733 | Binder.restoreCallingIdentity(identity); |
| 4734 | } |
| 4735 | } |
| 4736 | |
| 4737 | @Override |
| 4738 | public int getVoWiFiRoamingModeSetting(int subId) { |
| 4739 | enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting"); |
| 4740 | final long identity = Binder.clearCallingIdentity(); |
| 4741 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4742 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4743 | // 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] | 4744 | return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4745 | } catch (ImsException e) { |
| 4746 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4747 | } finally { |
| 4748 | Binder.restoreCallingIdentity(identity); |
| 4749 | } |
| 4750 | } |
| 4751 | |
| 4752 | @Override |
| 4753 | public void setVoWiFiRoamingModeSetting(int subId, int mode) { |
| 4754 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4755 | "setVoWiFiRoamingModeSetting"); |
| 4756 | final long identity = Binder.clearCallingIdentity(); |
| 4757 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4758 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4759 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4760 | // 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] | 4761 | ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4762 | } catch (ImsException e) { |
| 4763 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4764 | } finally { |
| 4765 | Binder.restoreCallingIdentity(identity); |
| 4766 | } |
| 4767 | } |
| 4768 | |
| 4769 | @Override |
| 4770 | public void setRttCapabilitySetting(int subId, boolean isEnabled) { |
| 4771 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4772 | "setRttCapabilityEnabled"); |
| 4773 | final long identity = Binder.clearCallingIdentity(); |
| 4774 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4775 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4776 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4777 | // 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] | 4778 | ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4779 | } catch (ImsException e) { |
| 4780 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4781 | } finally { |
| 4782 | Binder.restoreCallingIdentity(identity); |
| 4783 | } |
| 4784 | } |
| 4785 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4786 | /** |
| 4787 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4788 | * @param subId The subscription to use to check the configuration. |
| 4789 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4790 | @Override |
| 4791 | public boolean isTtyOverVolteEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4792 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4793 | mApp, subId, "isTtyOverVolteEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4794 | final long identity = Binder.clearCallingIdentity(); |
| 4795 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4796 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4797 | // 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] | 4798 | return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4799 | } catch (ImsException e) { |
| 4800 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4801 | } finally { |
| 4802 | Binder.restoreCallingIdentity(identity); |
| 4803 | } |
| 4804 | } |
| 4805 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4806 | @Override |
| 4807 | public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 4808 | enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4809 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4810 | final long identity = Binder.clearCallingIdentity(); |
| 4811 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4812 | if (!isImsAvailableOnDevice()) { |
| 4813 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4814 | "IMS not available on device."); |
| 4815 | } |
| 4816 | int slotId = getSlotIndexOrException(subId); |
| 4817 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 4818 | ImsManager.getInstance(mApp, slotId) |
| 4819 | .addProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4820 | } catch (ImsException e) { |
| 4821 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4822 | } finally { |
| 4823 | Binder.restoreCallingIdentity(identity); |
| 4824 | } |
| 4825 | } |
| 4826 | |
| 4827 | @Override |
| 4828 | public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 4829 | enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4830 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4831 | final long identity = Binder.clearCallingIdentity(); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4832 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4833 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4834 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4835 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4836 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4837 | .removeProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4838 | } catch (ImsException e) { |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4839 | Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId |
| 4840 | + "is inactive, ignoring unregister."); |
| 4841 | // If the subscription is no longer active, just return, since the callback will already |
| 4842 | // have been removed internally. |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4843 | } finally { |
| 4844 | Binder.restoreCallingIdentity(identity); |
| 4845 | } |
| 4846 | } |
| 4847 | |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4848 | @Override |
| 4849 | public void registerFeatureProvisioningChangedCallback(int subId, |
| 4850 | IFeatureProvisioningCallback callback) { |
| 4851 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4852 | mApp, subId, "registerFeatureProvisioningChangedCallback"); |
| 4853 | |
| 4854 | final long identity = Binder.clearCallingIdentity(); |
| 4855 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4856 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4857 | } |
| 4858 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 4859 | try { |
| 4860 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 4861 | if (controller == null) { |
| 4862 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4863 | "Device does not support IMS"); |
| 4864 | } |
| 4865 | controller.addFeatureProvisioningChangedCallback(subId, callback); |
| 4866 | } finally { |
| 4867 | Binder.restoreCallingIdentity(identity); |
| 4868 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4869 | } |
| 4870 | |
| 4871 | @Override |
| 4872 | public void unregisterFeatureProvisioningChangedCallback(int subId, |
| 4873 | IFeatureProvisioningCallback callback) { |
| 4874 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4875 | mApp, subId, "unregisterFeatureProvisioningChangedCallback"); |
| 4876 | |
| 4877 | final long identity = Binder.clearCallingIdentity(); |
| 4878 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4879 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4880 | } |
| 4881 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 4882 | try { |
| 4883 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 4884 | if (controller == null) { |
| 4885 | loge("unregisterFeatureProvisioningChangedCallback: Device does not support IMS"); |
| 4886 | return; |
| 4887 | } |
| 4888 | controller.removeFeatureProvisioningChangedCallback(subId, callback); |
| 4889 | } finally { |
| 4890 | Binder.restoreCallingIdentity(identity); |
| 4891 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4892 | } |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4893 | |
| 4894 | private void checkModifyPhoneStatePermission(int subId, String message) { |
| 4895 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4896 | message); |
| 4897 | } |
| 4898 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4899 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4900 | public void setRcsProvisioningStatusForCapability(int subId, int capability, int tech, |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4901 | boolean isProvisioned) { |
| 4902 | checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability"); |
| 4903 | |
| 4904 | final long identity = Binder.clearCallingIdentity(); |
| 4905 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 4906 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 4907 | if (controller == null) { |
| 4908 | loge("setRcsProvisioningStatusForCapability: Device does not support IMS"); |
| 4909 | return; |
| 4910 | } |
| 4911 | controller.setRcsProvisioningStatusForCapability( |
| 4912 | subId, capability, tech, isProvisioned); |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4913 | } finally { |
| 4914 | Binder.restoreCallingIdentity(identity); |
| 4915 | } |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4916 | } |
| 4917 | |
| 4918 | |
| 4919 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4920 | public boolean getRcsProvisioningStatusForCapability(int subId, int capability, int tech) { |
| 4921 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4922 | mApp, subId, "getRcsProvisioningStatusForCapability"); |
| 4923 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4924 | final long identity = Binder.clearCallingIdentity(); |
| 4925 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 4926 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 4927 | if (controller == null) { |
| 4928 | loge("getRcsProvisioningStatusForCapability: Device does not support IMS"); |
| 4929 | |
| 4930 | // device does not support IMS, this method will return true always. |
| 4931 | return true; |
| 4932 | } |
| 4933 | return controller.getRcsProvisioningStatusForCapability(subId, capability, tech); |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4934 | } finally { |
| 4935 | Binder.restoreCallingIdentity(identity); |
| 4936 | } |
| 4937 | } |
| 4938 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4939 | @Override |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4940 | public void setImsProvisioningStatusForCapability(int subId, int capability, int tech, |
| 4941 | boolean isProvisioned) { |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4942 | checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4943 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4944 | final long identity = Binder.clearCallingIdentity(); |
| 4945 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 4946 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 4947 | if (controller == null) { |
| 4948 | loge("setImsProvisioningStatusForCapability: Device does not support IMS"); |
| 4949 | return; |
| 4950 | } |
| 4951 | controller.setImsProvisioningStatusForCapability( |
| 4952 | subId, capability, tech, isProvisioned); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4953 | } finally { |
| 4954 | Binder.restoreCallingIdentity(identity); |
| 4955 | } |
| 4956 | } |
| 4957 | |
| 4958 | @Override |
| 4959 | public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) { |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4960 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4961 | mApp, subId, "getProvisioningStatusForCapability"); |
| 4962 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4963 | final long identity = Binder.clearCallingIdentity(); |
| 4964 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 4965 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 4966 | if (controller == null) { |
| 4967 | loge("getImsProvisioningStatusForCapability: Device does not support IMS"); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4968 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 4969 | // device does not support IMS, this method will return true always. |
| 4970 | return true; |
| 4971 | } |
| 4972 | return controller.getImsProvisioningStatusForCapability(subId, capability, tech); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4973 | } finally { |
| 4974 | Binder.restoreCallingIdentity(identity); |
| 4975 | } |
| 4976 | } |
| 4977 | |
| 4978 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4979 | public boolean isProvisioningRequiredForCapability(int subId, int capability, int tech) { |
| 4980 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4981 | mApp, subId, "isProvisioningRequiredForCapability"); |
| 4982 | |
| 4983 | final long identity = Binder.clearCallingIdentity(); |
| 4984 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 4985 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 4986 | if (controller == null) { |
| 4987 | loge("isProvisioningRequiredForCapability: Device does not support IMS"); |
| 4988 | |
| 4989 | // device does not support IMS, this method will return false |
| 4990 | return false; |
| 4991 | } |
| 4992 | return controller.isImsProvisioningRequiredForCapability(subId, capability, tech); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4993 | } finally { |
| 4994 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4995 | } |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4996 | } |
| 4997 | |
| 4998 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4999 | public boolean isRcsProvisioningRequiredForCapability(int subId, int capability, int tech) { |
| 5000 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5001 | mApp, subId, "isProvisioningRequiredForCapability"); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5002 | |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5003 | final long identity = Binder.clearCallingIdentity(); |
| 5004 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5005 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5006 | if (controller == null) { |
| 5007 | loge("isRcsProvisioningRequiredForCapability: Device does not support IMS"); |
| 5008 | |
| 5009 | // device does not support IMS, this method will return false |
| 5010 | return false; |
| 5011 | } |
| 5012 | return controller.isRcsProvisioningRequiredForCapability(subId, capability, tech); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5013 | } finally { |
| 5014 | Binder.restoreCallingIdentity(identity); |
| 5015 | } |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5016 | } |
| 5017 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5018 | @Override |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5019 | public int getImsProvisioningInt(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5020 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5021 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 5022 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5023 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5024 | mApp, subId, "getImsProvisioningInt"); |
| 5025 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5026 | final long identity = Binder.clearCallingIdentity(); |
| 5027 | try { |
| 5028 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5029 | int slotId = getSlotIndex(subId); |
| 5030 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5031 | Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '" |
| 5032 | + subId + "' for key:" + key); |
| 5033 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
| 5034 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5035 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5036 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5037 | if (controller == null) { |
| 5038 | loge("getImsProvisioningInt: Device does not support IMS"); |
| 5039 | |
| 5040 | // device does not support IMS, this method will return CONFIG_RESULT_UNKNOWN. |
| 5041 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
| 5042 | } |
| 5043 | int retVal = controller.getProvisioningValue(subId, key); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5044 | if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) { |
| 5045 | return retVal; |
| 5046 | } |
| 5047 | |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5048 | return ImsManager.getInstance(mApp, slotId).getConfigInt(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5049 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5050 | Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '" |
| 5051 | + subId + "' for key:" + key); |
| 5052 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5053 | } finally { |
| 5054 | Binder.restoreCallingIdentity(identity); |
| 5055 | } |
| 5056 | } |
| 5057 | |
| 5058 | @Override |
| 5059 | public String getImsProvisioningString(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5060 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5061 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 5062 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5063 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5064 | mApp, subId, "getImsProvisioningString"); |
| 5065 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5066 | final long identity = Binder.clearCallingIdentity(); |
| 5067 | try { |
| 5068 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5069 | int slotId = getSlotIndex(subId); |
| 5070 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5071 | Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '" |
| 5072 | + subId + "' for key:" + key); |
| 5073 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC; |
| 5074 | } |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5075 | return ImsManager.getInstance(mApp, slotId).getConfigString(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5076 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5077 | Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '" |
| 5078 | + subId + "' for key:" + key); |
| 5079 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5080 | } finally { |
| 5081 | Binder.restoreCallingIdentity(identity); |
| 5082 | } |
| 5083 | } |
| 5084 | |
| 5085 | @Override |
| 5086 | public int setImsProvisioningInt(int subId, int key, int value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5087 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5088 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 5089 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 5090 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5091 | "setImsProvisioningInt"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5092 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5093 | final long identity = Binder.clearCallingIdentity(); |
| 5094 | try { |
| 5095 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5096 | int slotId = getSlotIndex(subId); |
| 5097 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5098 | Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '" |
| 5099 | + subId + "' for key:" + key); |
| 5100 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 5101 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5102 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5103 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5104 | if (controller == null) { |
| 5105 | loge("setImsProvisioningInt: Device does not support IMS"); |
| 5106 | |
| 5107 | // device does not support IMS, this method will return CONFIG_RESULT_FAILED. |
| 5108 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 5109 | } |
| 5110 | int retVal = controller.setProvisioningValue(subId, key, value); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5111 | if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) { |
| 5112 | return retVal; |
| 5113 | } |
| 5114 | |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5115 | return ImsManager.getInstance(mApp, slotId).setConfig(key, value); |
| 5116 | } catch (com.android.ims.ImsException | RemoteException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5117 | Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5118 | + "' for key:" + key, e); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5119 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5120 | } finally { |
| 5121 | Binder.restoreCallingIdentity(identity); |
| 5122 | } |
| 5123 | } |
| 5124 | |
| 5125 | @Override |
| 5126 | public int setImsProvisioningString(int subId, int key, String value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5127 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5128 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 5129 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 5130 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5131 | "setImsProvisioningString"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5132 | final long identity = Binder.clearCallingIdentity(); |
| 5133 | try { |
| 5134 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5135 | int slotId = getSlotIndex(subId); |
| 5136 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5137 | Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '" |
| 5138 | + subId + "' for key:" + key); |
| 5139 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 5140 | } |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5141 | return ImsManager.getInstance(mApp, slotId).setConfig(key, value); |
| 5142 | } catch (com.android.ims.ImsException | RemoteException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5143 | Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5144 | + "' for key:" + key, e); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5145 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5146 | } finally { |
| 5147 | Binder.restoreCallingIdentity(identity); |
| 5148 | } |
| 5149 | } |
| 5150 | |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5151 | /** |
| 5152 | * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL |
| 5153 | * for the given slot ID or no ImsResolver instance has been created. |
| 5154 | * @param slotId The slot ID that the IMS service is created for. |
| 5155 | * @throws ImsException If there is no ImsService configured for this slot. |
| 5156 | */ |
| 5157 | private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException { |
| 5158 | if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId, |
| 5159 | ImsFeature.FEATURE_MMTEL)) { |
| 5160 | throw new ImsException("This subscription does not support MMTEL over IMS", |
| 5161 | ImsException.CODE_ERROR_UNSUPPORTED_OPERATION); |
| 5162 | } |
| 5163 | } |
| 5164 | |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5165 | private int getSlotIndexOrException(int subId) throws ImsException { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5166 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 5167 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5168 | throw new ImsException("Invalid Subscription Id, subId=" + subId, |
| 5169 | ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5170 | } |
| 5171 | return slotId; |
| 5172 | } |
| 5173 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5174 | private int getSlotIndex(int subId) { |
| 5175 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 5176 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
| 5177 | return SubscriptionManager.INVALID_SIM_SLOT_INDEX; |
| 5178 | } |
| 5179 | return slotId; |
| 5180 | } |
| 5181 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5182 | /** |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 5183 | * Returns the data network type for a subId; does not throw SecurityException. |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5184 | */ |
| 5185 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5186 | public int getNetworkTypeForSubscriber(int subId, String callingPackage, |
| 5187 | String callingFeatureId) { |
Shuo Qian | 13d8915 | 2021-05-10 23:58:11 -0700 | [diff] [blame] | 5188 | try { |
| 5189 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 5190 | } catch (SecurityException se) { |
| 5191 | EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid()); |
| 5192 | throw new SecurityException("Package " + callingPackage + " does not belong to " |
| 5193 | + Binder.getCallingUid()); |
| 5194 | } |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 5195 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 5196 | if (targetSdk > android.os.Build.VERSION_CODES.Q) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5197 | return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 5198 | } else if (targetSdk == android.os.Build.VERSION_CODES.Q |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 5199 | && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5200 | mApp, subId, callingPackage, callingFeatureId, |
| 5201 | "getNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5202 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5203 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 5204 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5205 | final long identity = Binder.clearCallingIdentity(); |
| 5206 | try { |
| 5207 | final Phone phone = getPhone(subId); |
| 5208 | if (phone != null) { |
| 5209 | return phone.getServiceState().getDataNetworkType(); |
| 5210 | } else { |
| 5211 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5212 | } |
| 5213 | } finally { |
| 5214 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5215 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5216 | } |
| 5217 | |
| 5218 | /** |
| 5219 | * Returns the data network type |
| 5220 | */ |
| 5221 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5222 | public int getDataNetworkType(String callingPackage, String callingFeatureId) { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5223 | return getDataNetworkTypeForSubscriber(SubscriptionManager.getDefaultDataSubscriptionId(), |
Zoey Chen | fd61f7f | 2021-04-21 13:42:10 +0800 | [diff] [blame] | 5224 | callingPackage, callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5225 | } |
| 5226 | |
| 5227 | /** |
| 5228 | * Returns the data network type for a subId |
| 5229 | */ |
| 5230 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5231 | public int getDataNetworkTypeForSubscriber(int subId, String callingPackage, |
| 5232 | String callingFeatureId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 5233 | String functionName = "getDataNetworkTypeForSubscriber"; |
| 5234 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 5235 | mApp, functionName)) { |
| 5236 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 5237 | mApp, subId, callingPackage, callingFeatureId, functionName)) { |
| 5238 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5239 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5240 | } |
| 5241 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5242 | final long identity = Binder.clearCallingIdentity(); |
| 5243 | try { |
| 5244 | final Phone phone = getPhone(subId); |
| 5245 | if (phone != null) { |
| 5246 | return phone.getServiceState().getDataNetworkType(); |
| 5247 | } else { |
| 5248 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5249 | } |
| 5250 | } finally { |
| 5251 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5252 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5253 | } |
| 5254 | |
| 5255 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5256 | * Returns the Voice network type for a subId |
| 5257 | */ |
| 5258 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5259 | public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage, |
| 5260 | String callingFeatureId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 5261 | String functionName = "getVoiceNetworkTypeForSubscriber"; |
| 5262 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 5263 | mApp, functionName)) { |
| 5264 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 5265 | mApp, subId, callingPackage, callingFeatureId, functionName)) { |
| 5266 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5267 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 5268 | } |
| 5269 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5270 | final long identity = Binder.clearCallingIdentity(); |
| 5271 | try { |
| 5272 | final Phone phone = getPhone(subId); |
| 5273 | if (phone != null) { |
| 5274 | return phone.getServiceState().getVoiceNetworkType(); |
| 5275 | } else { |
| 5276 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5277 | } |
| 5278 | } finally { |
| 5279 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5280 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5281 | } |
| 5282 | |
| 5283 | /** |
| 5284 | * @return true if a ICC card is present |
| 5285 | */ |
| 5286 | public boolean hasIccCard() { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5287 | // FIXME Make changes to pass defaultSimId of type int |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5288 | return hasIccCardUsingSlotIndex(SubscriptionManager.getSlotIndex( |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5289 | getDefaultSubscription())); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5290 | } |
| 5291 | |
| 5292 | /** |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5293 | * @return true if a ICC card is present for a slotIndex |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5294 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5295 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5296 | public boolean hasIccCardUsingSlotIndex(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5297 | final long identity = Binder.clearCallingIdentity(); |
| 5298 | try { |
| 5299 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5300 | if (phone != null) { |
| 5301 | return phone.getIccCard().hasIccCard(); |
| 5302 | } else { |
| 5303 | return false; |
| 5304 | } |
| 5305 | } finally { |
| 5306 | Binder.restoreCallingIdentity(identity); |
Amit Mahajan | a6fc2a8 | 2015-01-06 11:53:51 -0800 | [diff] [blame] | 5307 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5308 | } |
| 5309 | |
| 5310 | /** |
| 5311 | * Return if the current radio is LTE on CDMA. This |
| 5312 | * is a tri-state return value as for a period of time |
| 5313 | * the mode may be unknown. |
| 5314 | * |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5315 | * @param callingPackage the name of the package making the call. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5316 | * @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] | 5317 | * or {@link Phone#LTE_ON_CDMA_TRUE} |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5318 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5319 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5320 | public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) { |
| 5321 | return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 5322 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5323 | } |
| 5324 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5325 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5326 | public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage, |
| 5327 | String callingFeatureId) { |
Sarah Chin | 790d292 | 2020-01-16 12:17:23 -0800 | [diff] [blame] | 5328 | try { |
| 5329 | enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber"); |
| 5330 | } catch (SecurityException e) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5331 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 5332 | } |
| 5333 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5334 | final long identity = Binder.clearCallingIdentity(); |
| 5335 | try { |
| 5336 | final Phone phone = getPhone(subId); |
| 5337 | if (phone == null) { |
| 5338 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 5339 | } else { |
Nathan Harold | 05ad633 | 2020-07-10 11:54:36 -0700 | [diff] [blame] | 5340 | return TelephonyProperties.lte_on_cdma_device() |
| 5341 | .orElse(PhoneConstants.LTE_ON_CDMA_FALSE); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5342 | } |
| 5343 | } finally { |
| 5344 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5345 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5346 | } |
| 5347 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5348 | /** |
| 5349 | * {@hide} |
| 5350 | * Returns Default subId, 0 in the case of single standby. |
| 5351 | */ |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 5352 | private int getDefaultSubscription() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5353 | return SubscriptionManager.getDefaultSubscriptionId(); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5354 | } |
| 5355 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 5356 | private int getSlotForDefaultSubscription() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5357 | return SubscriptionManager.getPhoneId(getDefaultSubscription()); |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 5358 | } |
| 5359 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 5360 | private int getPreferredVoiceSubscription() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5361 | return SubscriptionManager.getDefaultVoiceSubscriptionId(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5362 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5363 | |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 5364 | private boolean isActiveSubscription(int subId) { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5365 | if (PhoneFactory.isSubscriptionManagerServiceEnabled()) { |
| 5366 | return SubscriptionManagerService.getInstance().isActiveSubId(subId, |
| 5367 | mApp.getOpPackageName(), mApp.getFeatureId()); |
| 5368 | } |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 5369 | return mSubscriptionController.isActiveSubId(subId); |
| 5370 | } |
| 5371 | |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5372 | /** |
| 5373 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 5374 | */ |
| 5375 | public int getWhenToMakeWifiCalls() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5376 | final long identity = Binder.clearCallingIdentity(); |
| 5377 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5378 | return Settings.System.getInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5379 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, |
| 5380 | getWhenToMakeWifiCallsDefaultPreference()); |
| 5381 | } finally { |
| 5382 | Binder.restoreCallingIdentity(identity); |
| 5383 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5384 | } |
| 5385 | |
| 5386 | /** |
| 5387 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 5388 | */ |
| 5389 | public void setWhenToMakeWifiCalls(int preference) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5390 | final long identity = Binder.clearCallingIdentity(); |
| 5391 | try { |
| 5392 | if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5393 | Settings.System.putInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5394 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference); |
| 5395 | } finally { |
| 5396 | Binder.restoreCallingIdentity(identity); |
| 5397 | } |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 5398 | } |
| 5399 | |
Sailesh Nepal | d1e6815 | 2013-12-12 19:08:02 -0800 | [diff] [blame] | 5400 | private static int getWhenToMakeWifiCallsDefaultPreference() { |
Santos Cordon | da120f4 | 2014-08-06 04:44:34 -0700 | [diff] [blame] | 5401 | // TODO: Use a build property to choose this value. |
Evan Charlton | 9829e88 | 2013-12-19 15:30:38 -0800 | [diff] [blame] | 5402 | return TelephonyManager.WifiCallingChoices.ALWAYS_USE; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5403 | } |
Shishir Agrawal | 69f6812 | 2013-12-16 17:25:49 -0800 | [diff] [blame] | 5404 | |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5405 | private Phone getPhoneFromSlotPortIndexOrThrowException(int slotIndex, int portIndex) { |
| 5406 | int phoneId = UiccController.getInstance().getPhoneIdFromSlotPortIndex(slotIndex, |
| 5407 | portIndex); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5408 | if (phoneId == -1) { |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5409 | throw new IllegalArgumentException("Given slot index: " + slotIndex + " port index: " |
| 5410 | + portIndex + " does not correspond to an active phone"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5411 | } |
| 5412 | return PhoneFactory.getPhone(phoneId); |
| 5413 | } |
| 5414 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5415 | @Override |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 5416 | public IccOpenLogicalChannelResponse iccOpenLogicalChannel( |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5417 | @NonNull IccLogicalChannelRequest request) { |
| 5418 | Phone phone = getPhoneFromValidIccLogicalChannelRequest(request, |
| 5419 | /*message=*/ "iccOpenLogicalChannel"); |
| 5420 | |
| 5421 | if (DBG) log("iccOpenLogicalChannel: request=" + request); |
| 5422 | // Verify that the callingPackage in the request belongs to the calling UID |
| 5423 | mAppOps.checkPackage(Binder.getCallingUid(), request.callingPackage); |
| 5424 | |
| 5425 | return iccOpenLogicalChannelWithPermission(phone, request); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5426 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5427 | |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5428 | private Phone getPhoneFromValidIccLogicalChannelRequest( |
| 5429 | @NonNull IccLogicalChannelRequest request, String message) { |
| 5430 | Phone phone; |
| 5431 | if (request.subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) { |
| 5432 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5433 | mApp, request.subId, message); |
| 5434 | phone = getPhoneFromSubId(request.subId); |
| 5435 | } else if (request.slotIndex != SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5436 | enforceModifyPermission(); |
| 5437 | phone = getPhoneFromSlotPortIndexOrThrowException(request.slotIndex, request.portIndex); |
| 5438 | } else { |
| 5439 | throw new IllegalArgumentException("Both subId and slotIndex in request are invalid."); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5440 | } |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5441 | return phone; |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5442 | } |
| 5443 | |
| 5444 | private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone, |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5445 | IccLogicalChannelRequest channelRequest) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5446 | final long identity = Binder.clearCallingIdentity(); |
| 5447 | try { |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5448 | if (TextUtils.equals(ISDR_AID, channelRequest.aid)) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5449 | // Only allows LPA to open logical channel to ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5450 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 5451 | .getContext().getPackageManager()); |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5452 | if (bestComponent == null || !TextUtils.equals(channelRequest.callingPackage, |
| 5453 | bestComponent.packageName)) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5454 | loge("The calling package is not allowed to access ISD-R."); |
| 5455 | throw new SecurityException( |
| 5456 | "The calling package is not allowed to access ISD-R."); |
| 5457 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 5458 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 5459 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5460 | IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest( |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5461 | CMD_OPEN_CHANNEL, channelRequest, phone, null /* workSource */); |
| 5462 | if (DBG) log("iccOpenLogicalChannelWithPermission: response=" + response); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5463 | return response; |
| 5464 | } finally { |
| 5465 | Binder.restoreCallingIdentity(identity); |
| 5466 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5467 | } |
| 5468 | |
| 5469 | @Override |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5470 | public boolean iccCloseLogicalChannel(@NonNull IccLogicalChannelRequest request) { |
| 5471 | Phone phone = getPhoneFromValidIccLogicalChannelRequest(request, |
| 5472 | /*message=*/"iccCloseLogicalChannel"); |
| 5473 | |
| 5474 | if (DBG) log("iccCloseLogicalChannel: request=" + request); |
| 5475 | |
| 5476 | return iccCloseLogicalChannelWithPermission(phone, request); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5477 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5478 | |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5479 | private boolean iccCloseLogicalChannelWithPermission(Phone phone, |
| 5480 | IccLogicalChannelRequest request) { |
Chen Xu | a8f0dff | 2022-02-12 00:34:15 -0800 | [diff] [blame] | 5481 | // before this feature is enabled, this API should only return false if |
| 5482 | // the operation fails instead of throwing runtime exception for |
| 5483 | // backward-compatibility. |
| 5484 | final boolean shouldThrowExceptionOnFailure = CompatChanges.isChangeEnabled( |
| 5485 | ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE, Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5486 | final long identity = Binder.clearCallingIdentity(); |
| 5487 | try { |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5488 | if (request.channel < 0) { |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 5489 | throw new IllegalArgumentException("request.channel is less than 0"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5490 | } |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 5491 | Object result = sendRequest(CMD_CLOSE_CHANNEL, request.channel, phone, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5492 | null /* workSource */); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 5493 | Boolean success = false; |
| 5494 | if (result instanceof RuntimeException) { |
| 5495 | // if there is an exception returned, throw from the binder thread here. |
Chen Xu | a8f0dff | 2022-02-12 00:34:15 -0800 | [diff] [blame] | 5496 | if (shouldThrowExceptionOnFailure) { |
| 5497 | throw (RuntimeException) result; |
| 5498 | } else { |
| 5499 | return false; |
| 5500 | } |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 5501 | } else if (result instanceof Boolean) { |
| 5502 | success = (Boolean) result; |
| 5503 | } else { |
| 5504 | loge("iccCloseLogicalChannelWithPermission: supported return type " + result); |
| 5505 | } |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5506 | if (DBG) log("iccCloseLogicalChannelWithPermission: success=" + success); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5507 | return success; |
| 5508 | } finally { |
| 5509 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5510 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5511 | } |
| 5512 | |
| 5513 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5514 | public String iccTransmitApduLogicalChannel(int subId, int channel, int cla, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5515 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5516 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5517 | mApp, subId, "iccTransmitApduLogicalChannel"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5518 | if (DBG) { |
| 5519 | log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel |
| 5520 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 5521 | + p3 + " data=" + data); |
| 5522 | } |
| 5523 | return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla, |
| 5524 | command, p1, p2, p3, data); |
| 5525 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5526 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5527 | @Override |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5528 | public String iccTransmitApduLogicalChannelByPort(int slotIndex, int portIndex, int channel, |
| 5529 | int cla, int command, int p1, int p2, int p3, String data) { |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5530 | enforceModifyPermission(); |
| 5531 | if (DBG) { |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5532 | log("iccTransmitApduLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex=" |
| 5533 | + portIndex + " chnl=" + channel + " cla=" + cla + " cmd=" + command + " p1=" |
| 5534 | + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5535 | } |
| 5536 | return iccTransmitApduLogicalChannelWithPermission( |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5537 | getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel, cla, |
| 5538 | command, p1, p2, p3, data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5539 | } |
| 5540 | |
| 5541 | private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla, |
| 5542 | int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5543 | final long identity = Binder.clearCallingIdentity(); |
| 5544 | try { |
Hall Liu | 4fd771b | 2019-05-02 09:16:29 -0700 | [diff] [blame] | 5545 | if (channel <= 0) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5546 | return ""; |
| 5547 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5548 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5549 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5550 | new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone, |
| 5551 | null /* workSource */); |
| 5552 | if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5553 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5554 | // Append the returned status code to the end of the response payload. |
| 5555 | String s = Integer.toHexString( |
| 5556 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 5557 | if (response.payload != null) { |
| 5558 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 5559 | } |
| 5560 | return s; |
| 5561 | } finally { |
| 5562 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 5563 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5564 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5565 | |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5566 | @Override |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 5567 | public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla, |
| 5568 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5569 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5570 | mApp, subId, "iccTransmitApduBasicChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5571 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5572 | if (DBG) { |
| 5573 | log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" |
| 5574 | + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
| 5575 | } |
| 5576 | return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage, |
| 5577 | cla, command, p1, p2, p3, data); |
| 5578 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5579 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5580 | @Override |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5581 | public String iccTransmitApduBasicChannelByPort(int slotIndex, int portIndex, |
| 5582 | 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] | 5583 | enforceModifyPermission(); |
| 5584 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 5585 | if (DBG) { |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5586 | log("iccTransmitApduBasicChannelByPort: slotIndex=" + slotIndex + " portIndex=" |
| 5587 | + portIndex + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" |
| 5588 | + p2 + " p3=" + p3 + " data=" + data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5589 | } |
| 5590 | |
| 5591 | return iccTransmitApduBasicChannelWithPermission( |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5592 | getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), callingPackage, |
| 5593 | cla, command, p1, p2, p3, data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5594 | } |
| 5595 | |
| 5596 | // open APDU basic channel assuming the caller has sufficient permissions |
| 5597 | private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage, |
| 5598 | int cla, int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5599 | final long identity = Binder.clearCallingIdentity(); |
| 5600 | try { |
| 5601 | if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3 |
| 5602 | && TextUtils.equals(ISDR_AID, data)) { |
| 5603 | // Only allows LPA to select ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5604 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 5605 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5606 | if (bestComponent == null |
| 5607 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 5608 | loge("The calling package is not allowed to select ISD-R."); |
| 5609 | throw new SecurityException( |
| 5610 | "The calling package is not allowed to select ISD-R."); |
| 5611 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 5612 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 5613 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5614 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5615 | new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone, |
| 5616 | null /* workSource */); |
| 5617 | if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5618 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5619 | // Append the returned status code to the end of the response payload. |
| 5620 | String s = Integer.toHexString( |
| 5621 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 5622 | if (response.payload != null) { |
| 5623 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 5624 | } |
| 5625 | return s; |
| 5626 | } finally { |
| 5627 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 5628 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5629 | } |
| 5630 | |
| 5631 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5632 | 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] | 5633 | String filePath) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5634 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5635 | mApp, subId, "iccExchangeSimIO"); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5636 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5637 | final long identity = Binder.clearCallingIdentity(); |
| 5638 | try { |
| 5639 | if (DBG) { |
| 5640 | log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " |
| 5641 | + p1 + " " + p2 + " " + p3 + ":" + filePath); |
| 5642 | } |
| 5643 | |
| 5644 | IccIoResult response = |
| 5645 | (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO, |
| 5646 | new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath), |
| 5647 | subId); |
| 5648 | |
| 5649 | if (DBG) { |
| 5650 | log("Exchange SIM_IO [R]" + response); |
| 5651 | } |
| 5652 | |
| 5653 | byte[] result = null; |
| 5654 | int length = 2; |
| 5655 | if (response.payload != null) { |
| 5656 | length = 2 + response.payload.length; |
| 5657 | result = new byte[length]; |
| 5658 | System.arraycopy(response.payload, 0, result, 0, response.payload.length); |
| 5659 | } else { |
| 5660 | result = new byte[length]; |
| 5661 | } |
| 5662 | |
| 5663 | result[length - 1] = (byte) response.sw2; |
| 5664 | result[length - 2] = (byte) response.sw1; |
| 5665 | return result; |
| 5666 | } finally { |
| 5667 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5668 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5669 | } |
| 5670 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5671 | /** |
| 5672 | * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM) |
| 5673 | * on a particular subscription |
| 5674 | */ |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5675 | public String[] getForbiddenPlmns(int subId, int appType, String callingPackage, |
| 5676 | String callingFeatureId) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 5677 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5678 | mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 5679 | return null; |
| 5680 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5681 | |
| 5682 | final long identity = Binder.clearCallingIdentity(); |
| 5683 | try { |
| 5684 | if (appType != TelephonyManager.APPTYPE_USIM |
| 5685 | && appType != TelephonyManager.APPTYPE_SIM) { |
| 5686 | loge("getForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 5687 | return null; |
| 5688 | } |
| 5689 | Object response = sendRequest( |
| 5690 | CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId); |
| 5691 | if (response instanceof String[]) { |
| 5692 | return (String[]) response; |
| 5693 | } |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5694 | // Response is an Exception of some kind |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5695 | // which is signalled to the user as a NULL retval |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5696 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5697 | } finally { |
| 5698 | Binder.restoreCallingIdentity(identity); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5699 | } |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5700 | } |
| 5701 | |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5702 | /** |
| 5703 | * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular |
| 5704 | * subscription. |
| 5705 | * |
| 5706 | * @param subId the id of the subscription. |
| 5707 | * @param appType the uicc app type, must be USIM or SIM. |
| 5708 | * @param fplmns the Forbiden plmns list that needed to be written to the SIM. |
| 5709 | * @param callingPackage the op Package name. |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5710 | * @param callingFeatureId the feature in the package. |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5711 | * @return number of fplmns that is successfully written to the SIM. |
| 5712 | */ |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5713 | public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage, |
| 5714 | String callingFeatureId) { |
Jayachandran C | 5b0d75a | 2021-10-21 22:15:27 -0700 | [diff] [blame] | 5715 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5716 | mApp, subId, "setForbiddenPlmns"); |
| 5717 | |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5718 | if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) { |
| 5719 | loge("setForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 5720 | throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM"); |
| 5721 | } |
| 5722 | if (fplmns == null) { |
| 5723 | throw new IllegalArgumentException("Fplmn List provided is null"); |
| 5724 | } |
| 5725 | for (String fplmn : fplmns) { |
| 5726 | if (!CellIdentity.isValidPlmn(fplmn)) { |
| 5727 | throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn); |
| 5728 | } |
| 5729 | } |
| 5730 | final long identity = Binder.clearCallingIdentity(); |
| 5731 | try { |
| 5732 | Object response = sendRequest( |
| 5733 | CMD_SET_FORBIDDEN_PLMNS, |
| 5734 | new Pair<Integer, List<String>>(new Integer(appType), fplmns), |
| 5735 | subId); |
| 5736 | return (int) response; |
| 5737 | } finally { |
| 5738 | Binder.restoreCallingIdentity(identity); |
| 5739 | } |
| 5740 | } |
| 5741 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5742 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5743 | public String sendEnvelopeWithStatus(int subId, String content) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5744 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5745 | mApp, subId, "sendEnvelopeWithStatus"); |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5746 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5747 | final long identity = Binder.clearCallingIdentity(); |
| 5748 | try { |
| 5749 | IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId); |
| 5750 | if (response.payload == null) { |
| 5751 | return ""; |
| 5752 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5753 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5754 | // Append the returned status code to the end of the response payload. |
| 5755 | String s = Integer.toHexString( |
| 5756 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 5757 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 5758 | return s; |
| 5759 | } finally { |
| 5760 | Binder.restoreCallingIdentity(identity); |
| 5761 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5762 | } |
| 5763 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5764 | /** |
| 5765 | * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 5766 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 5767 | * |
| 5768 | * @param itemID the ID of the item to read |
| 5769 | * @return the NV item as a String, or null on error. |
| 5770 | */ |
| 5771 | @Override |
| 5772 | public String nvReadItem(int itemID) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5773 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5774 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5775 | mApp, getDefaultSubscription(), "nvReadItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5776 | |
| 5777 | final long identity = Binder.clearCallingIdentity(); |
| 5778 | try { |
| 5779 | if (DBG) log("nvReadItem: item " + itemID); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5780 | String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5781 | if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"'); |
| 5782 | return value; |
| 5783 | } finally { |
| 5784 | Binder.restoreCallingIdentity(identity); |
| 5785 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5786 | } |
| 5787 | |
| 5788 | /** |
| 5789 | * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 5790 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 5791 | * |
| 5792 | * @param itemID the ID of the item to read |
| 5793 | * @param itemValue the value to write, as a String |
| 5794 | * @return true on success; false on any failure |
| 5795 | */ |
| 5796 | @Override |
| 5797 | public boolean nvWriteItem(int itemID, String itemValue) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5798 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5799 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5800 | mApp, getDefaultSubscription(), "nvWriteItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5801 | |
| 5802 | final long identity = Binder.clearCallingIdentity(); |
| 5803 | try { |
| 5804 | if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"'); |
| 5805 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5806 | new Pair<Integer, String>(itemID, itemValue), workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5807 | if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail")); |
| 5808 | return success; |
| 5809 | } finally { |
| 5810 | Binder.restoreCallingIdentity(identity); |
| 5811 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5812 | } |
| 5813 | |
| 5814 | /** |
| 5815 | * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage. |
| 5816 | * Used for device configuration by some CDMA operators. |
| 5817 | * |
| 5818 | * @param preferredRoamingList byte array containing the new PRL |
| 5819 | * @return true on success; false on any failure |
| 5820 | */ |
| 5821 | @Override |
| 5822 | public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5823 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5824 | mApp, getDefaultSubscription(), "nvWriteCdmaPrl"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5825 | |
| 5826 | final long identity = Binder.clearCallingIdentity(); |
| 5827 | try { |
| 5828 | if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList)); |
| 5829 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList); |
| 5830 | if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail")); |
| 5831 | return success; |
| 5832 | } finally { |
| 5833 | Binder.restoreCallingIdentity(identity); |
| 5834 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5835 | } |
| 5836 | |
| 5837 | /** |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5838 | * 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] | 5839 | * Used for device configuration by some CDMA operators. |
| 5840 | * |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5841 | * @param slotIndex - device slot. |
| 5842 | * |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5843 | * @return true on success; false on any failure |
| 5844 | */ |
| 5845 | @Override |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5846 | public boolean resetModemConfig(int slotIndex) { |
| 5847 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5848 | if (phone != null) { |
| 5849 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5850 | mApp, phone.getSubId(), "resetModemConfig"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5851 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5852 | final long identity = Binder.clearCallingIdentity(); |
| 5853 | try { |
| 5854 | Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null); |
| 5855 | if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 5856 | return success; |
| 5857 | } finally { |
| 5858 | Binder.restoreCallingIdentity(identity); |
| 5859 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5860 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5861 | return false; |
| 5862 | } |
| 5863 | |
| 5864 | /** |
| 5865 | * Generate a radio modem reset. Used for device configuration by some CDMA operators. |
| 5866 | * |
| 5867 | * @param slotIndex - device slot. |
| 5868 | * |
| 5869 | * @return true on success; false on any failure |
| 5870 | */ |
| 5871 | @Override |
| 5872 | public boolean rebootModem(int slotIndex) { |
| 5873 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5874 | if (phone != null) { |
| 5875 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5876 | mApp, phone.getSubId(), "rebootModem"); |
| 5877 | |
| 5878 | final long identity = Binder.clearCallingIdentity(); |
| 5879 | try { |
| 5880 | Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null); |
| 5881 | if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail")); |
| 5882 | return success; |
| 5883 | } finally { |
| 5884 | Binder.restoreCallingIdentity(identity); |
| 5885 | } |
| 5886 | } |
| 5887 | return false; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5888 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5889 | |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5890 | /** |
Grace Jia | aa2eb6b | 2020-01-09 16:26:08 -0800 | [diff] [blame] | 5891 | * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and |
| 5892 | * {@link #disableIms(int)}. |
| 5893 | * @param slotIndex device slot. |
| 5894 | */ |
| 5895 | public void resetIms(int slotIndex) { |
| 5896 | enforceModifyPermission(); |
| 5897 | |
| 5898 | final long identity = Binder.clearCallingIdentity(); |
| 5899 | try { |
| 5900 | if (mImsResolver == null) { |
| 5901 | // may happen if the does not support IMS. |
| 5902 | return; |
| 5903 | } |
Hyunho | a17ac7c | 2022-08-30 12:03:04 +0000 | [diff] [blame] | 5904 | mImsResolver.resetIms(slotIndex); |
Grace Jia | aa2eb6b | 2020-01-09 16:26:08 -0800 | [diff] [blame] | 5905 | } finally { |
| 5906 | Binder.restoreCallingIdentity(identity); |
| 5907 | } |
| 5908 | } |
| 5909 | |
| 5910 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5911 | * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability |
| 5912 | * status updates, if not already enabled. |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5913 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5914 | public void enableIms(int slotId) { |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5915 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5916 | |
| 5917 | final long identity = Binder.clearCallingIdentity(); |
| 5918 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5919 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5920 | // may happen if the device does not support IMS. |
| 5921 | return; |
| 5922 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5923 | mImsResolver.enableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5924 | } finally { |
| 5925 | Binder.restoreCallingIdentity(identity); |
| 5926 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5927 | } |
| 5928 | |
| 5929 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5930 | * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature |
| 5931 | * status updates to disabled. |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5932 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5933 | public void disableIms(int slotId) { |
| 5934 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5935 | |
| 5936 | final long identity = Binder.clearCallingIdentity(); |
| 5937 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5938 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5939 | // may happen if the device does not support IMS. |
| 5940 | return; |
| 5941 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5942 | mImsResolver.disableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5943 | } finally { |
| 5944 | Binder.restoreCallingIdentity(identity); |
| 5945 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5946 | } |
| 5947 | |
| 5948 | /** |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5949 | * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback |
| 5950 | * callback. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5951 | */ |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5952 | @Override |
Brad Ebinger | f6aca00 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 5953 | public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) { |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5954 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5955 | |
| 5956 | final long identity = Binder.clearCallingIdentity(); |
| 5957 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5958 | if (mImsResolver == null) { |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5959 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 5960 | "Device does not support IMS"); |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5961 | } |
Brad Ebinger | f6aca00 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 5962 | mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5963 | } finally { |
| 5964 | Binder.restoreCallingIdentity(identity); |
| 5965 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5966 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5967 | /** |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5968 | * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature. |
| 5969 | */ |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5970 | @Override |
| 5971 | public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) { |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5972 | enforceModifyPermission(); |
| 5973 | |
| 5974 | final long identity = Binder.clearCallingIdentity(); |
| 5975 | try { |
| 5976 | if (mImsResolver == null) return; |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5977 | mImsResolver.unregisterImsFeatureCallback(callback); |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5978 | } finally { |
| 5979 | Binder.restoreCallingIdentity(identity); |
| 5980 | } |
| 5981 | } |
| 5982 | |
| 5983 | /** |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5984 | * Returns the {@link IImsRegistration} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5985 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5986 | */ |
| 5987 | public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException { |
| 5988 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5989 | |
| 5990 | final long identity = Binder.clearCallingIdentity(); |
| 5991 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5992 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5993 | // may happen if the device does not support IMS. |
| 5994 | return null; |
| 5995 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5996 | return mImsResolver.getImsRegistration(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5997 | } finally { |
| 5998 | Binder.restoreCallingIdentity(identity); |
| 5999 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 6000 | } |
| 6001 | |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6002 | /** |
| 6003 | * Returns the {@link IImsConfig} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6004 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6005 | */ |
| 6006 | public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException { |
| 6007 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6008 | |
| 6009 | final long identity = Binder.clearCallingIdentity(); |
| 6010 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6011 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6012 | // may happen if the device does not support IMS. |
| 6013 | return null; |
| 6014 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6015 | return mImsResolver.getImsConfig(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6016 | } finally { |
| 6017 | Binder.restoreCallingIdentity(identity); |
| 6018 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6019 | } |
| 6020 | |
Brad Ebinger | 884c07b | 2018-02-15 16:17:40 -0800 | [diff] [blame] | 6021 | /** |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6022 | * Sets the ImsService Package Name that Telephony will bind to. |
| 6023 | * |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6024 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 6025 | * @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] | 6026 | * ImsService is the device default ImsService. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6027 | * @param featureTypes An integer array of feature types associated with a packageName. |
| 6028 | * @param packageName The name of the package that the current configuration will be replaced |
| 6029 | * with. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6030 | * @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] | 6031 | */ |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6032 | public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService, |
| 6033 | int[] featureTypes, String packageName) { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6034 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 6035 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
Jack Yu | 00ece8c | 2022-11-19 22:29:12 -0800 | [diff] [blame] | 6036 | SubscriptionManager.getSubscriptionId(slotIndex), "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 6037 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6038 | final long identity = Binder.clearCallingIdentity(); |
| 6039 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6040 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6041 | // may happen if the device does not support IMS. |
| 6042 | return false; |
| 6043 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6044 | Map<Integer, String> featureConfig = new HashMap<>(); |
| 6045 | for (int featureType : featureTypes) { |
| 6046 | featureConfig.put(featureType, packageName); |
| 6047 | } |
| 6048 | return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService, |
| 6049 | featureConfig); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6050 | } finally { |
| 6051 | Binder.restoreCallingIdentity(identity); |
| 6052 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6053 | } |
| 6054 | |
| 6055 | /** |
Brad Ebinger | 999d330 | 2020-11-25 14:31:39 -0800 | [diff] [blame] | 6056 | * Clears any carrier ImsService overrides for the slot index specified that were previously |
| 6057 | * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}. |
| 6058 | * |
| 6059 | * This should only be used for testing. |
| 6060 | * |
| 6061 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 6062 | * @return true if clearing the carrier ImsService override succeeded or false if it did not. |
| 6063 | */ |
| 6064 | @Override |
| 6065 | public boolean clearCarrierImsServiceOverride(int slotIndex) { |
Brad Ebinger | 999d330 | 2020-11-25 14:31:39 -0800 | [diff] [blame] | 6066 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 6067 | "clearCarrierImsServiceOverride"); |
| 6068 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
Jack Yu | 00ece8c | 2022-11-19 22:29:12 -0800 | [diff] [blame] | 6069 | SubscriptionManager.getSubscriptionId(slotIndex), "clearCarrierImsServiceOverride"); |
Brad Ebinger | 999d330 | 2020-11-25 14:31:39 -0800 | [diff] [blame] | 6070 | |
| 6071 | final long identity = Binder.clearCallingIdentity(); |
| 6072 | try { |
| 6073 | if (mImsResolver == null) { |
| 6074 | // may happen if the device does not support IMS. |
| 6075 | return false; |
| 6076 | } |
| 6077 | return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex); |
| 6078 | } finally { |
| 6079 | Binder.restoreCallingIdentity(identity); |
| 6080 | } |
| 6081 | } |
| 6082 | |
| 6083 | /** |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6084 | * Return the package name of the currently bound ImsService. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6085 | * |
| 6086 | * @param slotId The slot that the ImsService is associated with. |
| 6087 | * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is |
| 6088 | * the device default. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6089 | * @param featureType The feature associated with the queried configuration. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6090 | * @return the package name of the ImsService configuration. |
| 6091 | */ |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6092 | public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService, |
| 6093 | @ImsFeature.FeatureType int featureType) { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6094 | TelephonyPermissions |
Jack Yu | 00ece8c | 2022-11-19 22:29:12 -0800 | [diff] [blame] | 6095 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(mApp, |
| 6096 | SubscriptionManager.getSubscriptionId(slotId), "getBoundImsServicePackage"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 6097 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6098 | final long identity = Binder.clearCallingIdentity(); |
| 6099 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6100 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6101 | // may happen if the device does not support IMS. |
| 6102 | return ""; |
| 6103 | } |
Brad Ebinger | a80c331 | 2019-12-02 10:59:39 -0800 | [diff] [blame] | 6104 | // TODO: change API to query RCS separately. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6105 | return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService, |
| 6106 | featureType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6107 | } finally { |
| 6108 | Binder.restoreCallingIdentity(identity); |
| 6109 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6110 | } |
| 6111 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6112 | /** |
| 6113 | * Get the MmTelFeature state associated with the requested subscription id. |
| 6114 | * @param subId The subscription that the MmTelFeature is associated with. |
| 6115 | * @param callback A callback with an integer containing the |
| 6116 | * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature. |
| 6117 | */ |
| 6118 | @Override |
| 6119 | public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) { |
| 6120 | enforceReadPrivilegedPermission("getImsMmTelFeatureState"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 6121 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 6122 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 6123 | "IMS not available on device."); |
| 6124 | } |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6125 | final long token = Binder.clearCallingIdentity(); |
| 6126 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 6127 | int slotId = getSlotIndex(subId); |
| 6128 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 6129 | Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '" |
| 6130 | + subId + "'"); |
| 6131 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 6132 | } |
| 6133 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 6134 | ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> { |
| 6135 | try { |
| 6136 | callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger); |
| 6137 | } catch (RemoteException e) { |
| 6138 | Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. " |
| 6139 | + "Ignore"); |
| 6140 | } |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6141 | }); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 6142 | } catch (ImsException e) { |
| 6143 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6144 | } finally { |
| 6145 | Binder.restoreCallingIdentity(token); |
| 6146 | } |
| 6147 | } |
| 6148 | |
Daniel Bright | bb5840b | 2021-01-12 15:48:18 -0800 | [diff] [blame] | 6149 | /** |
| 6150 | * Sets the ims registration state on all valid {@link Phone}s. |
| 6151 | */ |
| 6152 | public void setImsRegistrationState(final boolean registered) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 6153 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6154 | |
| 6155 | final long identity = Binder.clearCallingIdentity(); |
| 6156 | try { |
Daniel Bright | bb5840b | 2021-01-12 15:48:18 -0800 | [diff] [blame] | 6157 | // NOTE: Before S, this method only set the default phone. |
| 6158 | for (final Phone phone : PhoneFactory.getPhones()) { |
| 6159 | if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) { |
| 6160 | phone.setImsRegistrationState(registered); |
| 6161 | } |
| 6162 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6163 | } finally { |
| 6164 | Binder.restoreCallingIdentity(identity); |
| 6165 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 6166 | } |
| 6167 | |
| 6168 | /** |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 6169 | * Set the network selection mode to automatic. |
| 6170 | * |
| 6171 | */ |
| 6172 | @Override |
| 6173 | public void setNetworkSelectionModeAutomatic(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6174 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6175 | mApp, subId, "setNetworkSelectionModeAutomatic"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6176 | |
| 6177 | final long identity = Binder.clearCallingIdentity(); |
| 6178 | try { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 6179 | if (!isActiveSubscription(subId)) { |
| 6180 | return; |
| 6181 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6182 | if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId); |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 6183 | sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId, |
| 6184 | SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6185 | } finally { |
| 6186 | Binder.restoreCallingIdentity(identity); |
| 6187 | } |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 6188 | } |
| 6189 | |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 6190 | /** |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6191 | * Ask the radio to connect to the input network and change selection mode to manual. |
| 6192 | * |
| 6193 | * @param subId the id of the subscription. |
| 6194 | * @param operatorInfo the operator information, included the PLMN, long name and short name of |
| 6195 | * the operator to attach to. |
| 6196 | * @param persistSelection whether the selection will persist until reboot. If true, only allows |
| 6197 | * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume |
| 6198 | * normal network selection next time. |
| 6199 | * @return {@code true} on success; {@code true} on any failure. |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6200 | */ |
| 6201 | @Override |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6202 | public boolean setNetworkSelectionModeManual( |
| 6203 | int subId, OperatorInfo operatorInfo, boolean persistSelection) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6204 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6205 | mApp, subId, "setNetworkSelectionModeManual"); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 6206 | |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 6207 | final long identity = Binder.clearCallingIdentity(); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 6208 | if (!isActiveSubscription(subId)) { |
| 6209 | return false; |
| 6210 | } |
| 6211 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6212 | try { |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6213 | ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6214 | persistSelection); |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6215 | if (DBG) { |
| 6216 | log("setNetworkSelectionModeManual: subId: " + subId |
| 6217 | + " operator: " + operatorInfo); |
| 6218 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6219 | return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId); |
| 6220 | } finally { |
| 6221 | Binder.restoreCallingIdentity(identity); |
| 6222 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6223 | } |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6224 | /** |
| 6225 | * Get the manual network selection |
| 6226 | * |
| 6227 | * @param subId the id of the subscription. |
| 6228 | * |
| 6229 | * @return the previously saved user selected PLMN |
| 6230 | */ |
| 6231 | @Override |
| 6232 | public String getManualNetworkSelectionPlmn(int subId) { |
| 6233 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 6234 | .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6235 | mApp, subId, "getManualNetworkSelectionPlmn"); |
| 6236 | |
| 6237 | final long identity = Binder.clearCallingIdentity(); |
| 6238 | try { |
| 6239 | if (!isActiveSubscription(subId)) { |
shilu | fa1c259 | 2020-03-10 10:59:43 -0700 | [diff] [blame] | 6240 | throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6241 | } |
| 6242 | |
| 6243 | final Phone phone = getPhone(subId); |
| 6244 | if (phone == null) { |
shilu | fa1c259 | 2020-03-10 10:59:43 -0700 | [diff] [blame] | 6245 | throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6246 | } |
| 6247 | OperatorInfo networkSelection = phone.getSavedNetworkSelection(); |
| 6248 | return TextUtils.isEmpty(networkSelection.getOperatorNumeric()) |
| 6249 | ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric(); |
| 6250 | } finally { |
| 6251 | Binder.restoreCallingIdentity(identity); |
| 6252 | } |
| 6253 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6254 | |
| 6255 | /** |
| 6256 | * Scans for available networks. |
| 6257 | */ |
| 6258 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6259 | public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage, |
| 6260 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6261 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6262 | mApp, subId, "getCellNetworkScanResults"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6263 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 6264 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 6265 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 6266 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6267 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6268 | .setCallingPid(Binder.getCallingPid()) |
| 6269 | .setCallingUid(Binder.getCallingUid()) |
| 6270 | .setMethod("getCellNetworkScanResults") |
| 6271 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
Hall Liu | c4a3e42 | 2020-05-26 17:18:03 -0700 | [diff] [blame] | 6272 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 6273 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6274 | .build()); |
| 6275 | switch (locationResult) { |
| 6276 | case DENIED_HARD: |
| 6277 | throw new SecurityException("Not allowed to access scan results -- location"); |
| 6278 | case DENIED_SOFT: |
| 6279 | return null; |
| 6280 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6281 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6282 | long identity = Binder.clearCallingIdentity(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6283 | try { |
| 6284 | if (DBG) log("getCellNetworkScanResults: subId " + subId); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6285 | return (CellNetworkScanResult) sendRequest( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6286 | CMD_PERFORM_NETWORK_SCAN, null, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6287 | } finally { |
| 6288 | Binder.restoreCallingIdentity(identity); |
| 6289 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6290 | } |
| 6291 | |
| 6292 | /** |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6293 | * Get the call forwarding info, given the call forwarding reason. |
| 6294 | */ |
| 6295 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6296 | public void getCallForwarding(int subId, int callForwardingReason, |
| 6297 | ICallForwardingInfoCallback callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6298 | enforceReadPrivilegedPermission("getCallForwarding"); |
| 6299 | long identity = Binder.clearCallingIdentity(); |
| 6300 | try { |
| 6301 | if (DBG) { |
| 6302 | log("getCallForwarding: subId " + subId |
| 6303 | + " callForwardingReason" + callForwardingReason); |
| 6304 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6305 | |
| 6306 | Phone phone = getPhone(subId); |
| 6307 | if (phone == null) { |
| 6308 | try { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 6309 | callback.onError( |
| 6310 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6311 | } catch (RemoteException e) { |
| 6312 | // ignore |
| 6313 | } |
| 6314 | return; |
| 6315 | } |
| 6316 | |
| 6317 | Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create( |
| 6318 | callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() { |
| 6319 | @Override |
| 6320 | public void onCallForwardingInfoAvailable(CallForwardingInfo info) { |
| 6321 | try { |
| 6322 | callback.onCallForwardingInfoAvailable(info); |
| 6323 | } catch (RemoteException e) { |
| 6324 | // ignore |
| 6325 | } |
| 6326 | } |
| 6327 | |
| 6328 | @Override |
| 6329 | public void onError(int error) { |
| 6330 | try { |
| 6331 | callback.onError(error); |
| 6332 | } catch (RemoteException e) { |
| 6333 | // ignore |
| 6334 | } |
| 6335 | } |
| 6336 | }); |
| 6337 | sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6338 | } finally { |
| 6339 | Binder.restoreCallingIdentity(identity); |
| 6340 | } |
| 6341 | } |
| 6342 | |
| 6343 | /** |
| 6344 | * Sets the voice call forwarding info including status (enable/disable), call forwarding |
| 6345 | * reason, the number to forward, and the timeout before the forwarding is attempted. |
| 6346 | */ |
| 6347 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6348 | public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo, |
| 6349 | IIntegerConsumer callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6350 | enforceModifyPermission(); |
| 6351 | long identity = Binder.clearCallingIdentity(); |
| 6352 | try { |
| 6353 | if (DBG) { |
| 6354 | log("setCallForwarding: subId " + subId |
| 6355 | + " callForwardingInfo" + callForwardingInfo); |
| 6356 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6357 | |
| 6358 | Phone phone = getPhone(subId); |
| 6359 | if (phone == null) { |
| 6360 | try { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 6361 | callback.accept( |
| 6362 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6363 | } catch (RemoteException e) { |
| 6364 | // ignore |
| 6365 | } |
| 6366 | return; |
| 6367 | } |
| 6368 | |
| 6369 | Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo, |
| 6370 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 6371 | |
| 6372 | sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6373 | } finally { |
| 6374 | Binder.restoreCallingIdentity(identity); |
| 6375 | } |
| 6376 | } |
| 6377 | |
| 6378 | /** |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6379 | * Get the call waiting status for a subId. |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6380 | */ |
| 6381 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6382 | public void getCallWaitingStatus(int subId, IIntegerConsumer callback) { |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6383 | enforceReadPrivilegedPermission("getCallWaitingStatus"); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6384 | long identity = Binder.clearCallingIdentity(); |
| 6385 | try { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6386 | Phone phone = getPhone(subId); |
| 6387 | if (phone == null) { |
| 6388 | try { |
| 6389 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 6390 | } catch (RemoteException e) { |
| 6391 | // ignore |
| 6392 | } |
| 6393 | return; |
| 6394 | } |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6395 | CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext()); |
| 6396 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 6397 | boolean requireUssd = c.getBoolean( |
| 6398 | CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6399 | |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6400 | if (DBG) log("getCallWaitingStatus: subId " + subId); |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6401 | if (requireUssd) { |
| 6402 | CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(), |
| 6403 | getSubscriptionCarrierId(subId)); |
| 6404 | String newUssdCommand = ""; |
| 6405 | try { |
| 6406 | newUssdCommand = carrierXmlParser.getFeature( |
| 6407 | CarrierXmlParser.FEATURE_CALL_WAITING) |
| 6408 | .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null); |
| 6409 | } catch (NullPointerException e) { |
| 6410 | loge("Failed to generate USSD number" + e); |
| 6411 | } |
| 6412 | ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver( |
| 6413 | mMainThreadHandler, callback, carrierXmlParser, |
| 6414 | CarrierXmlParser.SsEntry.SSAction.QUERY); |
| 6415 | final String ussdCommand = newUssdCommand; |
| 6416 | Executors.newSingleThreadExecutor().execute(() -> { |
| 6417 | handleUssdRequest(subId, ussdCommand, wrappedCallback); |
| 6418 | }); |
| 6419 | } else { |
| 6420 | Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException( |
| 6421 | callback::accept); |
| 6422 | sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null); |
| 6423 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6424 | } finally { |
| 6425 | Binder.restoreCallingIdentity(identity); |
| 6426 | } |
| 6427 | } |
| 6428 | |
| 6429 | /** |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6430 | * Sets whether call waiting is enabled for a given subId. |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6431 | */ |
| 6432 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6433 | public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6434 | enforceModifyPermission(); |
| 6435 | long identity = Binder.clearCallingIdentity(); |
| 6436 | try { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6437 | if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable); |
| 6438 | |
| 6439 | Phone phone = getPhone(subId); |
| 6440 | if (phone == null) { |
| 6441 | try { |
| 6442 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 6443 | } catch (RemoteException e) { |
| 6444 | // ignore |
| 6445 | } |
| 6446 | return; |
| 6447 | } |
| 6448 | |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6449 | CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext()); |
| 6450 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 6451 | boolean requireUssd = c.getBoolean( |
| 6452 | CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6453 | |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6454 | if (DBG) log("getCallWaitingStatus: subId " + subId); |
| 6455 | if (requireUssd) { |
| 6456 | CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(), |
| 6457 | getSubscriptionCarrierId(subId)); |
| 6458 | CarrierXmlParser.SsEntry.SSAction ssAction = |
| 6459 | enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE |
| 6460 | : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE; |
| 6461 | String newUssdCommand = ""; |
| 6462 | try { |
| 6463 | newUssdCommand = carrierXmlParser.getFeature( |
| 6464 | CarrierXmlParser.FEATURE_CALL_WAITING) |
| 6465 | .makeCommand(ssAction, null); |
| 6466 | } catch (NullPointerException e) { |
| 6467 | loge("Failed to generate USSD number" + e); |
| 6468 | } |
| 6469 | ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver( |
| 6470 | mMainThreadHandler, callback, carrierXmlParser, ssAction); |
| 6471 | final String ussdCommand = newUssdCommand; |
| 6472 | Executors.newSingleThreadExecutor().execute(() -> { |
| 6473 | handleUssdRequest(subId, ussdCommand, wrappedCallback); |
| 6474 | }); |
| 6475 | } else { |
| 6476 | Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable, |
| 6477 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 6478 | |
| 6479 | sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null); |
| 6480 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6481 | } finally { |
| 6482 | Binder.restoreCallingIdentity(identity); |
| 6483 | } |
| 6484 | } |
| 6485 | |
| 6486 | /** |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 6487 | * Starts a new network scan and returns the id of this scan. |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6488 | * |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 6489 | * @param subId id of the subscription |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 6490 | * @param renounceFineLocationAccess Set this to true if the caller would not like to receive |
| 6491 | * location related information which will be sent if the caller already possess |
| 6492 | * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 6493 | * @param request contains the radio access networks with bands/channels to scan |
| 6494 | * @param messenger callback messenger for scan results or errors |
| 6495 | * @param binder for the purpose of auto clean when the user thread crashes |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6496 | * @return the id of the requested scan which can be used to stop the scan. |
| 6497 | */ |
| 6498 | @Override |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 6499 | public int requestNetworkScan(int subId, boolean renounceFineLocationAccess, |
| 6500 | NetworkScanRequest request, Messenger messenger, |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6501 | IBinder binder, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6502 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6503 | mApp, subId, "requestNetworkScan"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6504 | LocationAccessPolicy.LocationPermissionResult locationResult = |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 6505 | LocationAccessPolicy.LocationPermissionResult.DENIED_HARD; |
| 6506 | if (!renounceFineLocationAccess) { |
| 6507 | locationResult = LocationAccessPolicy.checkLocationPermission(mApp, |
| 6508 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 6509 | .setCallingPackage(callingPackage) |
| 6510 | .setCallingFeatureId(callingFeatureId) |
| 6511 | .setCallingPid(Binder.getCallingPid()) |
| 6512 | .setCallingUid(Binder.getCallingUid()) |
| 6513 | .setMethod("requestNetworkScan") |
| 6514 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 6515 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 6516 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 6517 | .build()); |
| 6518 | } |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6519 | if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) { |
Nathan Harold | 1c11dba | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 6520 | SecurityException e = checkNetworkRequestForSanitizedLocationAccess( |
| 6521 | request, subId, callingPackage); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6522 | if (e != null) { |
| 6523 | if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) { |
| 6524 | throw e; |
| 6525 | } else { |
Hall Liu | 0e5abaf | 2019-04-04 01:25:30 -0700 | [diff] [blame] | 6526 | loge(e.getMessage()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6527 | return TelephonyScanManager.INVALID_SCAN_ID; |
| 6528 | } |
| 6529 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6530 | } |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6531 | int callingUid = Binder.getCallingUid(); |
| 6532 | int callingPid = Binder.getCallingPid(); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 6533 | final long identity = Binder.clearCallingIdentity(); |
| 6534 | try { |
| 6535 | return mNetworkScanRequestTracker.startNetworkScan( |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 6536 | renounceFineLocationAccess, request, messenger, binder, getPhone(subId), |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6537 | callingUid, callingPid, callingPackage); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 6538 | } finally { |
| 6539 | Binder.restoreCallingIdentity(identity); |
| 6540 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6541 | } |
| 6542 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6543 | private SecurityException checkNetworkRequestForSanitizedLocationAccess( |
Nathan Harold | 1c11dba | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 6544 | NetworkScanRequest request, int subId, String callingPackage) { |
Rambo Wang | 3dee30a | 2022-10-20 16:52:29 +0000 | [diff] [blame] | 6545 | boolean hasCarrierPriv; |
| 6546 | final long identity = Binder.clearCallingIdentity(); |
| 6547 | try { |
| 6548 | hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage) |
| 6549 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 6550 | } finally { |
| 6551 | Binder.restoreCallingIdentity(identity); |
| 6552 | } |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 6553 | boolean hasNetworkScanPermission = |
| 6554 | mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN) |
| 6555 | == PERMISSION_GRANTED; |
| 6556 | |
| 6557 | if (!hasCarrierPriv && !hasNetworkScanPermission) { |
| 6558 | return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed" |
| 6559 | + " for network scans without location access."); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6560 | } |
| 6561 | |
| 6562 | if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) { |
| 6563 | for (RadioAccessSpecifier ras : request.getSpecifiers()) { |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6564 | if (ras.getChannels() != null && ras.getChannels().length > 0) { |
| 6565 | return new SecurityException("Specific channels must not be" |
| 6566 | + " scanned without location access."); |
| 6567 | } |
| 6568 | } |
| 6569 | } |
| 6570 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6571 | return null; |
| 6572 | } |
| 6573 | |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6574 | /** |
| 6575 | * Stops an existing network scan with the given scanId. |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 6576 | * |
| 6577 | * @param subId id of the subscription |
| 6578 | * @param scanId id of the scan that needs to be stopped |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6579 | */ |
| 6580 | @Override |
| 6581 | public void stopNetworkScan(int subId, int scanId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6582 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6583 | mApp, subId, "stopNetworkScan"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6584 | |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6585 | int callingUid = Binder.getCallingUid(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6586 | final long identity = Binder.clearCallingIdentity(); |
| 6587 | try { |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6588 | mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6589 | } finally { |
| 6590 | Binder.restoreCallingIdentity(identity); |
| 6591 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6592 | } |
| 6593 | |
| 6594 | /** |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6595 | * Get the allowed network types bitmask. |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 6596 | * |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6597 | * @return the allowed network types bitmask, defined in RILConstants.java. |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 6598 | */ |
| 6599 | @Override |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6600 | public int getAllowedNetworkTypesBitmask(int subId) { |
Pengquan Meng | a4009cb | 2018-12-20 11:00:24 -0800 | [diff] [blame] | 6601 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 6602 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6603 | mApp, subId, "getAllowedNetworkTypesBitmask"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6604 | |
| 6605 | final long identity = Binder.clearCallingIdentity(); |
| 6606 | try { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6607 | if (DBG) log("getAllowedNetworkTypesBitmask"); |
| 6608 | int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId); |
| 6609 | int networkTypesBitmask = (result != null ? result[0] : -1); |
| 6610 | if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask); |
| 6611 | return networkTypesBitmask; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6612 | } finally { |
| 6613 | Binder.restoreCallingIdentity(identity); |
| 6614 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 6615 | } |
| 6616 | |
| 6617 | /** |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6618 | * Get the allowed network types for certain reason. |
| 6619 | * |
| 6620 | * @param subId the id of the subscription. |
| 6621 | * @param reason the reason the allowed network type change is taking place |
| 6622 | * @return the allowed network types. |
| 6623 | */ |
| 6624 | @Override |
| 6625 | public long getAllowedNetworkTypesForReason(int subId, |
| 6626 | @TelephonyManager.AllowedNetworkTypesReason int reason) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 6627 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 6628 | mApp, subId, "getAllowedNetworkTypesForReason"); |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6629 | final long identity = Binder.clearCallingIdentity(); |
| 6630 | try { |
| 6631 | return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason); |
| 6632 | } finally { |
| 6633 | Binder.restoreCallingIdentity(identity); |
| 6634 | } |
| 6635 | } |
| 6636 | |
| 6637 | /** |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6638 | * Enable/Disable E-UTRA-NR Dual Connectivity |
| 6639 | * @param subId subscription id of the sim card |
| 6640 | * @param nrDualConnectivityState expected NR dual connectivity state |
| 6641 | * This can be passed following states |
| 6642 | * <ol> |
| 6643 | * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE} |
| 6644 | * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE} |
| 6645 | * <li>Disable NR dual connectivity and force secondary cell to be released |
| 6646 | * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE} |
| 6647 | * </ol> |
| 6648 | * @return operation result. |
| 6649 | */ |
| 6650 | @Override |
| 6651 | public int setNrDualConnectivityState(int subId, |
| 6652 | @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) { |
| 6653 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6654 | mApp, subId, "enableNRDualConnectivity"); |
Sooraj Sasindran | 0e4e00a | 2021-03-16 18:02:32 -0700 | [diff] [blame] | 6655 | if (!isRadioInterfaceCapabilitySupported( |
Sooraj Sasindran | dfd595b | 2021-03-11 17:38:13 -0800 | [diff] [blame] | 6656 | TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) { |
| 6657 | return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED; |
| 6658 | } |
| 6659 | |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6660 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 6661 | final long identity = Binder.clearCallingIdentity(); |
| 6662 | try { |
| 6663 | int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY, |
| 6664 | nrDualConnectivityState, subId, |
| 6665 | workSource); |
| 6666 | if (DBG) log("enableNRDualConnectivity result: " + result); |
| 6667 | return result; |
| 6668 | } finally { |
| 6669 | Binder.restoreCallingIdentity(identity); |
| 6670 | } |
| 6671 | } |
| 6672 | |
| 6673 | /** |
| 6674 | * Is E-UTRA-NR Dual Connectivity enabled |
| 6675 | * @return true if dual connectivity is enabled else false |
| 6676 | */ |
| 6677 | @Override |
| 6678 | public boolean isNrDualConnectivityEnabled(int subId) { |
| 6679 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 6680 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6681 | mApp, subId, "isNRDualConnectivityEnabled"); |
Sooraj Sasindran | 0e4e00a | 2021-03-16 18:02:32 -0700 | [diff] [blame] | 6682 | if (!isRadioInterfaceCapabilitySupported( |
Sooraj Sasindran | dfd595b | 2021-03-11 17:38:13 -0800 | [diff] [blame] | 6683 | TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) { |
| 6684 | return false; |
| 6685 | } |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6686 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 6687 | final long identity = Binder.clearCallingIdentity(); |
| 6688 | try { |
| 6689 | boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED, |
| 6690 | null, subId, workSource); |
| 6691 | if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled); |
| 6692 | return isEnabled; |
| 6693 | } finally { |
| 6694 | Binder.restoreCallingIdentity(identity); |
| 6695 | } |
| 6696 | } |
| 6697 | |
| 6698 | /** |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6699 | * Set the allowed network types of the device and |
| 6700 | * provide the reason triggering the allowed network change. |
| 6701 | * |
| 6702 | * @param subId the id of the subscription. |
| 6703 | * @param reason the reason the allowed network type change is taking place |
| 6704 | * @param allowedNetworkTypes the allowed network types. |
| 6705 | * @return true on success; false on any failure. |
| 6706 | */ |
| 6707 | @Override |
| 6708 | public boolean setAllowedNetworkTypesForReason(int subId, |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6709 | @TelephonyManager.AllowedNetworkTypesReason int reason, |
| 6710 | @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) { |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6711 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6712 | mApp, subId, "setAllowedNetworkTypesForReason"); |
Gil Cukierman | 1d3d375 | 2022-10-03 21:31:33 +0000 | [diff] [blame] | 6713 | // If the caller only has carrier privileges, then they should not be able to override |
| 6714 | // any network types which were set for security reasons. |
| 6715 | if (mApp.checkCallingOrSelfPermission(Manifest.permission.MODIFY_PHONE_STATE) |
| 6716 | != PERMISSION_GRANTED |
| 6717 | && (reason == TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_ENABLE_2G |
| 6718 | || reason == TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER_RESTRICTIONS)) { |
| 6719 | throw new SecurityException( |
| 6720 | "setAllowedNetworkTypesForReason cannot be called with carrier privileges for" |
| 6721 | + " reason " |
| 6722 | + reason); |
| 6723 | } |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6724 | if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) { |
SongFerngWang | 7ffc273 | 2021-04-15 19:46:33 +0800 | [diff] [blame] | 6725 | loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason); |
| 6726 | return false; |
| 6727 | } |
| 6728 | if (!SubscriptionManager.isUsableSubscriptionId(subId)) { |
| 6729 | loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId); |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6730 | return false; |
| 6731 | } |
| 6732 | |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 6733 | log("setAllowedNetworkTypesForReason: " + reason + " value: " |
| 6734 | + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes)); |
| 6735 | |
| 6736 | |
| 6737 | if (allowedNetworkTypes == getPhoneFromSubId(subId).getAllowedNetworkTypes(reason)) { |
| 6738 | log("setAllowedNetworkTypesForReason: " + reason + "does not change value"); |
| 6739 | return true; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6740 | } |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 6741 | |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6742 | final long identity = Binder.clearCallingIdentity(); |
| 6743 | try { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6744 | Boolean success = (Boolean) sendRequest( |
| 6745 | CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON, |
| 6746 | new Pair<Integer, Long>(reason, allowedNetworkTypes), subId); |
| 6747 | |
| 6748 | if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail")); |
| 6749 | return success; |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6750 | } finally { |
| 6751 | Binder.restoreCallingIdentity(identity); |
| 6752 | } |
| 6753 | } |
| 6754 | |
| 6755 | /** |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6756 | * Check whether DUN APN is required for tethering with subId. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6757 | * |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6758 | * @param subId the id of the subscription to require tethering. |
Amit Mahajan | fe58cdf | 2017-07-11 12:01:53 -0700 | [diff] [blame] | 6759 | * @return {@code true} if DUN APN is required for tethering. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6760 | * @hide |
| 6761 | */ |
| 6762 | @Override |
SongFerngWang | f08d812 | 2019-11-15 14:58:44 +0800 | [diff] [blame] | 6763 | public boolean isTetheringApnRequiredForSubscriber(int subId) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6764 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6765 | final long identity = Binder.clearCallingIdentity(); |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6766 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6767 | try { |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6768 | if (phone != null) { |
| 6769 | return phone.hasMatchedTetherApnSetting(); |
| 6770 | } else { |
| 6771 | return false; |
| 6772 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6773 | } finally { |
| 6774 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6775 | } |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6776 | } |
| 6777 | |
| 6778 | /** |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6779 | * Get the user enabled state of Mobile Data. |
| 6780 | * |
| 6781 | * TODO: remove and use isUserDataEnabled. |
| 6782 | * This can't be removed now because some vendor codes |
| 6783 | * calls through ITelephony directly while they should |
| 6784 | * use TelephonyManager. |
| 6785 | * |
| 6786 | * @return true on enabled |
| 6787 | */ |
| 6788 | @Override |
| 6789 | public boolean getDataEnabled(int subId) { |
| 6790 | return isUserDataEnabled(subId); |
| 6791 | } |
| 6792 | |
| 6793 | /** |
| 6794 | * Get whether mobile data is enabled per user setting. |
| 6795 | * |
| 6796 | * There are other factors deciding whether mobile data is actually enabled, but they are |
| 6797 | * not considered here. See {@link #isDataEnabled(int)} for more details. |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6798 | * |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6799 | * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE |
| 6800 | * or carrier privileges. |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 6801 | * |
| 6802 | * @return {@code true} if data is enabled else {@code false} |
| 6803 | */ |
| 6804 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6805 | public boolean isUserDataEnabled(int subId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6806 | String functionName = "isUserDataEnabled"; |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6807 | try { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6808 | try { |
| 6809 | mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE, |
| 6810 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 6811 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6812 | mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName); |
| 6813 | } |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 6814 | } catch (SecurityException e) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6815 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6816 | mApp, subId, functionName); |
| 6817 | |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6818 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6819 | |
| 6820 | final long identity = Binder.clearCallingIdentity(); |
| 6821 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 6822 | int phoneId = SubscriptionManager.getPhoneId(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6823 | if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 6824 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6825 | if (phone != null) { |
| 6826 | boolean retVal = phone.isUserDataEnabled(); |
| 6827 | if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 6828 | return retVal; |
| 6829 | } else { |
| 6830 | if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 6831 | return false; |
| 6832 | } |
| 6833 | } finally { |
| 6834 | Binder.restoreCallingIdentity(identity); |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6835 | } |
| 6836 | } |
| 6837 | |
| 6838 | /** |
Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 6839 | * Checks if the device is capable of mobile data by considering whether whether the |
| 6840 | * user has enabled mobile data, whether the carrier has enabled mobile data, and |
| 6841 | * whether the network policy allows data connections. |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6842 | * |
Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 6843 | * @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] | 6844 | */ |
| 6845 | @Override |
| 6846 | public boolean isDataEnabled(int subId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6847 | String functionName = "isDataEnabled"; |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6848 | try { |
| 6849 | try { |
| 6850 | mApp.enforceCallingOrSelfPermission( |
| 6851 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6852 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 6853 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6854 | try { |
| 6855 | mApp.enforceCallingOrSelfPermission( |
| 6856 | android.Manifest.permission.READ_PHONE_STATE, |
| 6857 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 6858 | } catch (SecurityException e2) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6859 | mApp.enforceCallingOrSelfPermission( |
| 6860 | permission.READ_BASIC_PHONE_STATE, functionName); |
| 6861 | } |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6862 | } |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 6863 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6864 | enforceReadPrivilegedPermission(functionName); |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6865 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6866 | |
| 6867 | final long identity = Binder.clearCallingIdentity(); |
| 6868 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 6869 | int phoneId = SubscriptionManager.getPhoneId(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6870 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6871 | if (phone != null) { |
Sarah Chin | e04784a | 2022-10-31 20:32:34 -0700 | [diff] [blame] | 6872 | boolean retVal = phone.getDataSettingsManager().isDataEnabled(); |
Jack Yu | 4ad64e5 | 2021-12-03 14:23:53 -0800 | [diff] [blame] | 6873 | if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6874 | return retVal; |
| 6875 | } else { |
| 6876 | if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 6877 | return false; |
| 6878 | } |
| 6879 | } finally { |
| 6880 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 6881 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 6882 | } |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6883 | |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6884 | /** |
| 6885 | * Check if data is enabled for a specific reason |
| 6886 | * @param subId Subscription index |
| 6887 | * @param reason the reason the data enable change is taking place |
| 6888 | * @return {@code true} if the overall data is enabled; {@code false} if not. |
| 6889 | */ |
| 6890 | @Override |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6891 | public boolean isDataEnabledForReason(int subId, |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6892 | @TelephonyManager.DataEnabledReason int reason) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6893 | String functionName = "isDataEnabledForReason"; |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6894 | try { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6895 | try { |
| 6896 | mApp.enforceCallingOrSelfPermission( |
| 6897 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 6898 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 6899 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6900 | mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE, |
| 6901 | functionName); |
| 6902 | } |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 6903 | } catch (SecurityException e) { |
Sooraj Sasindran | 0d909a0 | 2021-11-08 12:01:16 -0800 | [diff] [blame] | 6904 | try { |
| 6905 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6906 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 6907 | } catch (SecurityException e2) { |
Sooraj Sasindran | 0d909a0 | 2021-11-08 12:01:16 -0800 | [diff] [blame] | 6908 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6909 | mApp, subId, functionName); |
Sooraj Sasindran | 0d909a0 | 2021-11-08 12:01:16 -0800 | [diff] [blame] | 6910 | } |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6911 | } |
| 6912 | |
| 6913 | |
| 6914 | final long identity = Binder.clearCallingIdentity(); |
| 6915 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 6916 | int phoneId = SubscriptionManager.getPhoneId(subId); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6917 | if (DBG) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6918 | log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6919 | + " reason=" + reason); |
| 6920 | } |
| 6921 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6922 | if (phone != null) { |
| 6923 | boolean retVal; |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 6924 | retVal = phone.getDataSettingsManager().isDataEnabledForReason(reason); |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6925 | if (DBG) log("isDataEnabledForReason: retVal=" + retVal); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6926 | return retVal; |
| 6927 | } else { |
| 6928 | if (DBG) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6929 | loge("isDataEnabledForReason: no phone subId=" |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6930 | + subId + " retVal=false"); |
| 6931 | } |
| 6932 | return false; |
| 6933 | } |
| 6934 | } finally { |
| 6935 | Binder.restoreCallingIdentity(identity); |
| 6936 | } |
| 6937 | } |
| 6938 | |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6939 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6940 | public int getCarrierPrivilegeStatus(int subId) { |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6941 | // No permission needed; this only lets the caller inspect their own status. |
| 6942 | return getCarrierPrivilegeStatusForUidWithPermission(subId, Binder.getCallingUid()); |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6943 | } |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 6944 | |
| 6945 | @Override |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6946 | public int getCarrierPrivilegeStatusForUid(int subId, int uid) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6947 | enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid"); |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6948 | return getCarrierPrivilegeStatusForUidWithPermission(subId, uid); |
| 6949 | } |
| 6950 | |
| 6951 | private int getCarrierPrivilegeStatusForUidWithPermission(int subId, int uid) { |
| 6952 | Phone phone = getPhone(subId); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6953 | if (phone == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 6954 | loge("getCarrierPrivilegeStatusForUid: Invalid subId"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6955 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 6956 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6957 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 6958 | if (cpt == null) { |
| 6959 | loge("getCarrierPrivilegeStatusForUid: No CarrierPrivilegesTracker"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6960 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6961 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6962 | return cpt.getCarrierPrivilegeStatusForUid(uid); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6963 | } |
| 6964 | |
| 6965 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6966 | public int checkCarrierPrivilegesForPackage(int subId, String pkgName) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 6967 | enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage"); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6968 | if (TextUtils.isEmpty(pkgName)) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 6969 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6970 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6971 | Phone phone = getPhone(subId); |
| 6972 | if (phone == null) { |
| 6973 | loge("checkCarrierPrivilegesForPackage: Invalid subId"); |
| 6974 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 6975 | } |
| 6976 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 6977 | if (cpt == null) { |
| 6978 | loge("checkCarrierPrivilegesForPackage: No CarrierPrivilegesTracker"); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 6979 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6980 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6981 | return cpt.getCarrierPrivilegeStatusForPackage(pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6982 | } |
| 6983 | |
| 6984 | @Override |
| 6985 | public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) { |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6986 | enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackageAnyPhone"); |
Rambo Wang | e7209ce | 2022-02-23 13:41:02 -0800 | [diff] [blame] | 6987 | return checkCarrierPrivilegesForPackageAnyPhoneWithPermission(pkgName); |
| 6988 | } |
| 6989 | |
| 6990 | private int checkCarrierPrivilegesForPackageAnyPhoneWithPermission(String pkgName) { |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6991 | if (TextUtils.isEmpty(pkgName)) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 6992 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6993 | } |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6994 | int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6995 | for (int phoneId = 0; phoneId < TelephonyManager.getDefault().getPhoneCount(); phoneId++) { |
| 6996 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6997 | if (phone == null) { |
| 6998 | continue; |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6999 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7000 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7001 | if (cpt == null) { |
| 7002 | continue; |
| 7003 | } |
| 7004 | result = cpt.getCarrierPrivilegeStatusForPackage(pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 7005 | if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 7006 | break; |
| 7007 | } |
| 7008 | } |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 7009 | return result; |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 7010 | } |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 7011 | |
| 7012 | @Override |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 7013 | public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 7014 | enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone"); |
Rambo Wang | 8a247eb | 2022-02-08 21:11:18 +0000 | [diff] [blame] | 7015 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 7016 | if (phone == null) { |
| 7017 | return Collections.emptyList(); |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 7018 | } |
Rambo Wang | 8a247eb | 2022-02-08 21:11:18 +0000 | [diff] [blame] | 7019 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7020 | if (cpt == null) { |
| 7021 | return Collections.emptyList(); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 7022 | } |
Rambo Wang | 8a247eb | 2022-02-08 21:11:18 +0000 | [diff] [blame] | 7023 | return cpt.getCarrierPackageNamesForIntent(intent); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 7024 | } |
| 7025 | |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 7026 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7027 | public List<String> getPackagesWithCarrierPrivileges(int phoneId) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 7028 | enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges"); |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7029 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 7030 | if (phone == null) { |
| 7031 | return Collections.emptyList(); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 7032 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7033 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7034 | if (cpt == null) { |
| 7035 | return Collections.emptyList(); |
| 7036 | } |
| 7037 | return new ArrayList<>(cpt.getPackagesWithCarrierPrivileges()); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 7038 | } |
| 7039 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7040 | @Override |
| 7041 | public List<String> getPackagesWithCarrierPrivilegesForAllPhones() { |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 7042 | enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones"); |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7043 | Set<String> privilegedPackages = new ArraySet<>(); |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 7044 | final long identity = Binder.clearCallingIdentity(); |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 7045 | try { |
| 7046 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 7047 | privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i)); |
| 7048 | } |
| 7049 | } finally { |
| 7050 | Binder.restoreCallingIdentity(identity); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7051 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7052 | return new ArrayList<>(privilegedPackages); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7053 | } |
| 7054 | |
Rambo Wang | 6812ffb | 2022-03-15 16:54:17 -0700 | [diff] [blame] | 7055 | @Override |
| 7056 | public @Nullable String getCarrierServicePackageNameForLogicalSlot(int logicalSlotIndex) { |
| 7057 | enforceReadPrivilegedPermission("getCarrierServicePackageNameForLogicalSlot"); |
| 7058 | |
| 7059 | final Phone phone = PhoneFactory.getPhone(logicalSlotIndex); |
| 7060 | if (phone == null) { |
| 7061 | return null; |
| 7062 | } |
| 7063 | final CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7064 | if (cpt == null) { |
| 7065 | return null; |
| 7066 | } |
| 7067 | return cpt.getCarrierServicePackageName(); |
| 7068 | } |
| 7069 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 7070 | private String getIccId(int subId) { |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 7071 | final Phone phone = getPhone(subId); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 7072 | UiccPort port = phone == null ? null : phone.getUiccPort(); |
| 7073 | if (port == null) { |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7074 | return null; |
| 7075 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 7076 | String iccId = port.getIccId(); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7077 | if (TextUtils.isEmpty(iccId)) { |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7078 | return null; |
| 7079 | } |
| 7080 | return iccId; |
| 7081 | } |
| 7082 | |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 7083 | @Override |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 7084 | public void setCallComposerStatus(int subId, int status) { |
| 7085 | enforceModifyPermission(); |
| 7086 | |
| 7087 | final long identity = Binder.clearCallingIdentity(); |
| 7088 | try { |
| 7089 | Phone phone = getPhone(subId); |
| 7090 | if (phone != null) { |
| 7091 | Phone defaultPhone = phone.getImsPhone(); |
| 7092 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 7093 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 7094 | imsPhone.setCallComposerStatus(status); |
Shuo Qian | 284ae75 | 2020-12-22 19:10:14 -0800 | [diff] [blame] | 7095 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| 7096 | .updateImsServiceConfig(); |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 7097 | } |
| 7098 | } |
Shuo Qian | 284ae75 | 2020-12-22 19:10:14 -0800 | [diff] [blame] | 7099 | } catch (ImsException e) { |
| 7100 | throw new ServiceSpecificException(e.getCode()); |
| 7101 | } finally { |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 7102 | Binder.restoreCallingIdentity(identity); |
| 7103 | } |
| 7104 | } |
| 7105 | |
| 7106 | @Override |
| 7107 | public int getCallComposerStatus(int subId) { |
| 7108 | enforceReadPrivilegedPermission("getCallComposerStatus"); |
| 7109 | |
| 7110 | final long identity = Binder.clearCallingIdentity(); |
| 7111 | try { |
| 7112 | Phone phone = getPhone(subId); |
| 7113 | if (phone != null) { |
| 7114 | Phone defaultPhone = phone.getImsPhone(); |
| 7115 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 7116 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 7117 | return imsPhone.getCallComposerStatus(); |
| 7118 | } |
| 7119 | } |
| 7120 | } finally { |
| 7121 | Binder.restoreCallingIdentity(identity); |
| 7122 | } |
| 7123 | return TelephonyManager.CALL_COMPOSER_STATUS_OFF; |
| 7124 | } |
| 7125 | |
| 7126 | @Override |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7127 | public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag, |
| 7128 | String number) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 7129 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7130 | subId, "setLine1NumberForDisplayForSubscriber"); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7131 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7132 | final long identity = Binder.clearCallingIdentity(); |
| 7133 | try { |
| 7134 | final String iccId = getIccId(subId); |
| 7135 | final Phone phone = getPhone(subId); |
| 7136 | if (phone == null) { |
| 7137 | return false; |
| 7138 | } |
| 7139 | final String subscriberId = phone.getSubscriberId(); |
| 7140 | |
| 7141 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 7142 | Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId=" |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7143 | + subscriberId + " to " + number); |
| 7144 | } |
| 7145 | |
| 7146 | if (TextUtils.isEmpty(iccId)) { |
| 7147 | return false; |
| 7148 | } |
| 7149 | |
| 7150 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 7151 | |
| 7152 | final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 7153 | if (alphaTag == null) { |
| 7154 | editor.remove(alphaTagPrefKey); |
| 7155 | } else { |
| 7156 | editor.putString(alphaTagPrefKey, alphaTag); |
| 7157 | } |
| 7158 | |
| 7159 | // Record both the line number and IMSI for this ICCID, since we need to |
| 7160 | // track all merged IMSIs based on line number |
| 7161 | final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 7162 | final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 7163 | if (number == null) { |
| 7164 | editor.remove(numberPrefKey); |
| 7165 | editor.remove(subscriberPrefKey); |
| 7166 | } else { |
| 7167 | editor.putString(numberPrefKey, number); |
| 7168 | editor.putString(subscriberPrefKey, subscriberId); |
| 7169 | } |
| 7170 | |
| 7171 | editor.commit(); |
| 7172 | return true; |
| 7173 | } finally { |
| 7174 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 7175 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7176 | } |
| 7177 | |
| 7178 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7179 | public String getLine1NumberForDisplay(int subId, String callingPackage, |
| 7180 | String callingFeatureId) { |
Makoto Onuki | fee6934 | 2015-06-29 14:44:50 -0700 | [diff] [blame] | 7181 | // This is open to apps with WRITE_SMS. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7182 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7183 | mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) { |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 7184 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission"); |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 7185 | return null; |
| 7186 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7187 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7188 | final long identity = Binder.clearCallingIdentity(); |
| 7189 | try { |
| 7190 | String iccId = getIccId(subId); |
| 7191 | if (iccId != null) { |
| 7192 | String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 7193 | if (DBG_MERGE) { |
| 7194 | log("getLine1NumberForDisplay returning " |
| 7195 | + mTelephonySharedPreferences.getString(numberPrefKey, null)); |
| 7196 | } |
| 7197 | return mTelephonySharedPreferences.getString(numberPrefKey, null); |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 7198 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7199 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null"); |
| 7200 | return null; |
| 7201 | } finally { |
| 7202 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7203 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7204 | } |
| 7205 | |
| 7206 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7207 | public String getLine1AlphaTagForDisplay(int subId, String callingPackage, |
| 7208 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7209 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7210 | mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 7211 | return null; |
| 7212 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7213 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7214 | final long identity = Binder.clearCallingIdentity(); |
| 7215 | try { |
| 7216 | String iccId = getIccId(subId); |
| 7217 | if (iccId != null) { |
| 7218 | String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 7219 | return mTelephonySharedPreferences.getString(alphaTagPrefKey, null); |
| 7220 | } |
| 7221 | return null; |
| 7222 | } finally { |
| 7223 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7224 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7225 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 7226 | |
| 7227 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7228 | public String[] getMergedSubscriberIds(int subId, String callingPackage, |
| 7229 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7230 | // This API isn't public, so no need to provide a valid subscription ID - we're not worried |
| 7231 | // about carrier-privileged callers not having access. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7232 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7233 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7234 | callingFeatureId, "getMergedSubscriberIds")) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7235 | return null; |
| 7236 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7237 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 7238 | // Clear calling identity, when calling TelephonyManager, because callerUid must be |
| 7239 | // the process, where TelephonyManager was instantiated. |
| 7240 | // Otherwise AppOps check will fail. |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7241 | final long identity = Binder.clearCallingIdentity(); |
| 7242 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7243 | final Context context = mApp; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7244 | final TelephonyManager tele = TelephonyManager.from(context); |
| 7245 | final SubscriptionManager sub = SubscriptionManager.from(context); |
| 7246 | |
| 7247 | // Figure out what subscribers are currently active |
| 7248 | final ArraySet<String> activeSubscriberIds = new ArraySet<>(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7249 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 7250 | // Only consider subs which match the current subId |
| 7251 | // This logic can be simplified. See b/131189269 for progress. |
| 7252 | if (isActiveSubscription(subId)) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7253 | activeSubscriberIds.add(tele.getSubscriberId(subId)); |
| 7254 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7255 | |
| 7256 | // First pass, find a number override for an active subscriber |
| 7257 | String mergeNumber = null; |
| 7258 | final Map<String, ?> prefs = mTelephonySharedPreferences.getAll(); |
| 7259 | for (String key : prefs.keySet()) { |
| 7260 | if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) { |
| 7261 | final String subscriberId = (String) prefs.get(key); |
| 7262 | if (activeSubscriberIds.contains(subscriberId)) { |
| 7263 | final String iccId = key.substring( |
| 7264 | PREF_CARRIERS_SUBSCRIBER_PREFIX.length()); |
| 7265 | final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 7266 | mergeNumber = (String) prefs.get(numberKey); |
| 7267 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 7268 | Rlog.d(LOG_TAG, "Found line number " + mergeNumber |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7269 | + " for active subscriber " + subscriberId); |
| 7270 | } |
| 7271 | if (!TextUtils.isEmpty(mergeNumber)) { |
| 7272 | break; |
| 7273 | } |
| 7274 | } |
| 7275 | } |
| 7276 | } |
| 7277 | |
| 7278 | // Shortcut when no active merged subscribers |
| 7279 | if (TextUtils.isEmpty(mergeNumber)) { |
| 7280 | return null; |
| 7281 | } |
| 7282 | |
| 7283 | // Second pass, find all subscribers under that line override |
| 7284 | final ArraySet<String> result = new ArraySet<>(); |
| 7285 | for (String key : prefs.keySet()) { |
| 7286 | if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) { |
| 7287 | final String number = (String) prefs.get(key); |
| 7288 | if (mergeNumber.equals(number)) { |
| 7289 | final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length()); |
| 7290 | final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 7291 | final String subscriberId = (String) prefs.get(subscriberKey); |
| 7292 | if (!TextUtils.isEmpty(subscriberId)) { |
| 7293 | result.add(subscriberId); |
| 7294 | } |
| 7295 | } |
| 7296 | } |
| 7297 | } |
| 7298 | |
| 7299 | final String[] resultArray = result.toArray(new String[result.size()]); |
| 7300 | Arrays.sort(resultArray); |
| 7301 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 7302 | Rlog.d(LOG_TAG, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7303 | "Found subscribers " + Arrays.toString(resultArray) + " after merge"); |
| 7304 | } |
| 7305 | return resultArray; |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7306 | } finally { |
| 7307 | Binder.restoreCallingIdentity(identity); |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7308 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7309 | } |
| 7310 | |
| 7311 | @Override |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 7312 | public String[] getMergedImsisFromGroup(int subId, String callingPackage) { |
| 7313 | enforceReadPrivilegedPermission("getMergedImsisFromGroup"); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7314 | |
| 7315 | final long identity = Binder.clearCallingIdentity(); |
| 7316 | try { |
| 7317 | final TelephonyManager telephonyManager = mApp.getSystemService( |
| 7318 | TelephonyManager.class); |
| 7319 | String subscriberId = telephonyManager.getSubscriberId(subId); |
| 7320 | if (subscriberId == null) { |
| 7321 | if (DBG) { |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 7322 | log("getMergedImsisFromGroup can't find subscriberId for subId " |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7323 | + subId); |
| 7324 | } |
| 7325 | return null; |
| 7326 | } |
| 7327 | |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 7328 | ParcelUuid groupUuid; |
| 7329 | if (PhoneFactory.isSubscriptionManagerServiceEnabled()) { |
| 7330 | final SubscriptionInfo info = SubscriptionManagerService.getInstance() |
| 7331 | .getSubscriptionInfo(subId); |
| 7332 | groupUuid = info.getGroupUuid(); |
| 7333 | } else { |
| 7334 | final SubscriptionInfo info = mSubscriptionController |
| 7335 | .getSubscriptionInfo(subId); |
| 7336 | groupUuid = info.getGroupUuid(); |
| 7337 | } |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7338 | // If it doesn't belong to any group, return just subscriberId of itself. |
| 7339 | if (groupUuid == null) { |
| 7340 | return new String[]{subscriberId}; |
| 7341 | } |
| 7342 | |
| 7343 | // Get all subscriberIds from the group. |
| 7344 | final List<String> mergedSubscriberIds = new ArrayList<>(); |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 7345 | List<SubscriptionInfo> groupInfos; |
| 7346 | if (PhoneFactory.isSubscriptionManagerServiceEnabled()) { |
| 7347 | groupInfos = SubscriptionManagerService.getInstance() |
| 7348 | .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(), |
| 7349 | mApp.getAttributionTag()); |
| 7350 | } else { |
| 7351 | groupInfos = mSubscriptionController |
| 7352 | .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(), |
| 7353 | mApp.getAttributionTag()); |
| 7354 | } |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7355 | for (SubscriptionInfo subInfo : groupInfos) { |
| 7356 | subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId()); |
| 7357 | if (subscriberId != null) { |
| 7358 | mergedSubscriberIds.add(subscriberId); |
| 7359 | } |
| 7360 | } |
| 7361 | |
| 7362 | return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]); |
| 7363 | } finally { |
| 7364 | Binder.restoreCallingIdentity(identity); |
| 7365 | |
| 7366 | } |
| 7367 | } |
| 7368 | |
| 7369 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7370 | public boolean setOperatorBrandOverride(int subId, String brand) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 7371 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7372 | subId, "setOperatorBrandOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7373 | |
| 7374 | final long identity = Binder.clearCallingIdentity(); |
| 7375 | try { |
| 7376 | final Phone phone = getPhone(subId); |
| 7377 | return phone == null ? false : phone.setOperatorBrandOverride(brand); |
| 7378 | } finally { |
| 7379 | Binder.restoreCallingIdentity(identity); |
| 7380 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 7381 | } |
Steven Liu | 4bf01bc | 2014-07-17 11:05:29 -0500 | [diff] [blame] | 7382 | |
| 7383 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7384 | public boolean setRoamingOverride(int subId, List<String> gsmRoamingList, |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 7385 | List<String> gsmNonRoamingList, List<String> cdmaRoamingList, |
| 7386 | List<String> cdmaNonRoamingList) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 7387 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 7388 | mApp, subId, "setRoamingOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7389 | |
| 7390 | final long identity = Binder.clearCallingIdentity(); |
| 7391 | try { |
| 7392 | final Phone phone = getPhone(subId); |
| 7393 | if (phone == null) { |
| 7394 | return false; |
| 7395 | } |
| 7396 | return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList, |
| 7397 | cdmaNonRoamingList); |
| 7398 | } finally { |
| 7399 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7400 | } |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 7401 | } |
| 7402 | |
| 7403 | @Override |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 7404 | @Deprecated |
| 7405 | public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) { |
| 7406 | enforceModifyPermission(); |
| 7407 | |
| 7408 | int returnValue = 0; |
| 7409 | try { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7410 | AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 7411 | if(result.exception == null) { |
| 7412 | if (result.result != null) { |
| 7413 | byte[] responseData = (byte[])(result.result); |
| 7414 | if(responseData.length > oemResp.length) { |
| 7415 | Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " + |
| 7416 | responseData.length + "bytes. Buffer Size is " + |
| 7417 | oemResp.length + "bytes."); |
| 7418 | } |
| 7419 | System.arraycopy(responseData, 0, oemResp, 0, responseData.length); |
| 7420 | returnValue = responseData.length; |
| 7421 | } |
| 7422 | } else { |
| 7423 | CommandException ex = (CommandException) result.exception; |
| 7424 | returnValue = ex.getCommandError().ordinal(); |
| 7425 | if(returnValue > 0) returnValue *= -1; |
| 7426 | } |
| 7427 | } catch (RuntimeException e) { |
| 7428 | Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception"); |
| 7429 | returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal()); |
| 7430 | if(returnValue > 0) returnValue *= -1; |
| 7431 | } |
| 7432 | |
| 7433 | return returnValue; |
| 7434 | } |
| 7435 | |
| 7436 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 7437 | public int getRadioAccessFamily(int phoneId, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7438 | Phone phone = PhoneFactory.getPhone(phoneId); |
Shuo Qian | dee5340 | 2020-05-29 14:08:15 -0700 | [diff] [blame] | 7439 | try { |
| 7440 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 7441 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Shuo Qian | dee5340 | 2020-05-29 14:08:15 -0700 | [diff] [blame] | 7442 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 7443 | } catch (SecurityException e) { |
| 7444 | EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission"); |
| 7445 | throw e; |
| 7446 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7447 | int raf = RadioAccessFamily.RAF_UNKNOWN; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7448 | if (phone == null) { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7449 | return raf; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7450 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7451 | final long identity = Binder.clearCallingIdentity(); |
| 7452 | try { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7453 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 7454 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7455 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 7456 | raf = ProxyController.getInstance().getRadioAccessFamily(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7457 | } finally { |
| 7458 | Binder.restoreCallingIdentity(identity); |
| 7459 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7460 | return raf; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 7461 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7462 | |
| 7463 | @Override |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7464 | public void uploadCallComposerPicture(int subscriptionId, String callingPackage, |
Hall Liu | e31bac6 | 2020-12-23 19:16:10 -0800 | [diff] [blame] | 7465 | String contentType, ParcelFileDescriptor fd, ResultReceiver callback) { |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7466 | try { |
| 7467 | if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0), |
| 7468 | Binder.getCallingUid())) { |
Tyler Gunn | b87925a | 2021-06-10 14:54:27 -0700 | [diff] [blame] | 7469 | throw new SecurityException("Invalid package:" + callingPackage); |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7470 | } |
| 7471 | } catch (PackageManager.NameNotFoundException e) { |
Tyler Gunn | b87925a | 2021-06-10 14:54:27 -0700 | [diff] [blame] | 7472 | throw new SecurityException("Invalid package:" + callingPackage); |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7473 | } |
| 7474 | RoleManager rm = mApp.getSystemService(RoleManager.class); |
| 7475 | List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER); |
| 7476 | if (!dialerRoleHolders.contains(callingPackage)) { |
| 7477 | throw new SecurityException("App must be the dialer role holder to" |
| 7478 | + " upload a call composer pic"); |
| 7479 | } |
| 7480 | |
| 7481 | Executors.newSingleThreadExecutor().execute(() -> { |
| 7482 | ByteArrayOutputStream output = new ByteArrayOutputStream( |
| 7483 | (int) TelephonyManager.getMaximumCallComposerPictureSize()); |
| 7484 | InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd); |
| 7485 | boolean readUntilEnd = false; |
| 7486 | int totalBytesRead = 0; |
| 7487 | byte[] buffer = new byte[16 * 1024]; |
| 7488 | while (true) { |
| 7489 | int numRead; |
| 7490 | try { |
| 7491 | numRead = input.read(buffer); |
| 7492 | } catch (IOException e) { |
| 7493 | try { |
| 7494 | fd.checkError(); |
| 7495 | callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED, |
| 7496 | null); |
| 7497 | } catch (IOException e1) { |
| 7498 | // This means that the other side closed explicitly with an error. If this |
| 7499 | // happens, log and ignore. |
| 7500 | loge("Remote end of call composer picture pipe closed: " + e1); |
| 7501 | } |
| 7502 | break; |
| 7503 | } |
| 7504 | if (numRead == -1) { |
| 7505 | readUntilEnd = true; |
| 7506 | break; |
| 7507 | } |
| 7508 | totalBytesRead += numRead; |
| 7509 | if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) { |
| 7510 | loge("Too many bytes read for call composer picture: " + totalBytesRead); |
| 7511 | try { |
| 7512 | input.close(); |
| 7513 | } catch (IOException e) { |
| 7514 | // ignore |
| 7515 | } |
| 7516 | break; |
| 7517 | } |
| 7518 | output.write(buffer, 0, numRead); |
| 7519 | } |
| 7520 | // Generally, the remote end will close the file descriptors. The only case where we |
| 7521 | // close is above, where the picture size is too big. |
| 7522 | |
| 7523 | try { |
| 7524 | fd.checkError(); |
| 7525 | } catch (IOException e) { |
| 7526 | loge("Remote end for call composer closed with an error: " + e); |
| 7527 | return; |
| 7528 | } |
| 7529 | |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 7530 | if (!readUntilEnd) { |
| 7531 | loge("Did not finish reading entire image; aborting"); |
| 7532 | return; |
| 7533 | } |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7534 | |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 7535 | ImageData imageData = new ImageData(output.toByteArray(), contentType, null); |
| 7536 | CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer( |
| 7537 | new CallComposerPictureTransfer.Factory() {}, |
| 7538 | imageData, |
| 7539 | (result) -> { |
| 7540 | if (result.first != null) { |
| 7541 | ParcelUuid parcelUuid = new ParcelUuid(result.first); |
| 7542 | Bundle outputResult = new Bundle(); |
| 7543 | outputResult.putParcelable( |
| 7544 | TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid); |
| 7545 | callback.send(TelephonyManager.CallComposerException.SUCCESS, |
| 7546 | outputResult); |
| 7547 | } else { |
| 7548 | callback.send(result.second, null); |
| 7549 | } |
| 7550 | } |
| 7551 | ); |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7552 | }); |
| 7553 | } |
| 7554 | |
| 7555 | @Override |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7556 | public void enableVideoCalling(boolean enable) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7557 | final Phone defaultPhone = getDefaultPhone(); |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7558 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7559 | |
| 7560 | final long identity = Binder.clearCallingIdentity(); |
| 7561 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7562 | ImsManager.getInstance(defaultPhone.getContext(), |
| 7563 | defaultPhone.getPhoneId()).setVtSetting(enable); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7564 | } finally { |
| 7565 | Binder.restoreCallingIdentity(identity); |
| 7566 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7567 | } |
| 7568 | |
| 7569 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7570 | public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7571 | final Phone defaultPhone = getDefaultPhone(); |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7572 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 7573 | callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 7574 | return false; |
| 7575 | } |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 7576 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7577 | final long identity = Binder.clearCallingIdentity(); |
| 7578 | try { |
| 7579 | // Check the user preference and the system-level IMS setting. Even if the user has |
| 7580 | // enabled video calling, if IMS is disabled we aren't able to support video calling. |
| 7581 | // In the long run, we may instead need to check if there exists a connection service |
| 7582 | // which can support video calling. |
| 7583 | ImsManager imsManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7584 | ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7585 | return imsManager.isVtEnabledByPlatform() |
| 7586 | && imsManager.isEnhanced4gLteModeSettingEnabledByUser() |
| 7587 | && imsManager.isVtEnabledByUser(); |
| 7588 | } finally { |
| 7589 | Binder.restoreCallingIdentity(identity); |
| 7590 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7591 | } |
Libin.Tang@motorola.com | afe8264 | 2014-12-18 13:27:53 -0600 | [diff] [blame] | 7592 | |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7593 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7594 | public boolean canChangeDtmfToneLength(int subId, String callingPackage, |
| 7595 | String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7596 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7597 | mApp, subId, callingPackage, callingFeatureId, |
| 7598 | "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7599 | return false; |
| 7600 | } |
| 7601 | |
| 7602 | final long identity = Binder.clearCallingIdentity(); |
| 7603 | try { |
| 7604 | CarrierConfigManager configManager = |
| 7605 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7606 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7607 | .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL); |
| 7608 | } finally { |
| 7609 | Binder.restoreCallingIdentity(identity); |
| 7610 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7611 | } |
| 7612 | |
| 7613 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7614 | public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7615 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7616 | mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7617 | return false; |
| 7618 | } |
| 7619 | |
| 7620 | final long identity = Binder.clearCallingIdentity(); |
| 7621 | try { |
| 7622 | CarrierConfigManager configManager = |
| 7623 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7624 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7625 | .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL); |
| 7626 | } finally { |
| 7627 | Binder.restoreCallingIdentity(identity); |
| 7628 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7629 | } |
| 7630 | |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7631 | @Override |
| 7632 | public boolean isTtyModeSupported() { |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 7633 | TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class); |
Wooki Wu | 1f82f7a | 2016-02-15 15:59:58 +0800 | [diff] [blame] | 7634 | return telecomManager.isTtySupported(); |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7635 | } |
| 7636 | |
| 7637 | @Override |
| 7638 | public boolean isHearingAidCompatibilitySupported() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7639 | final long identity = Binder.clearCallingIdentity(); |
| 7640 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7641 | return mApp.getResources().getBoolean(R.bool.hac_enabled); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7642 | } finally { |
| 7643 | Binder.restoreCallingIdentity(identity); |
| 7644 | } |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7645 | } |
| 7646 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 7647 | /** |
| 7648 | * Determines whether the device currently supports RTT (Real-time text). Based both on carrier |
| 7649 | * support for the feature and device firmware support. |
| 7650 | * |
| 7651 | * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise. |
| 7652 | */ |
| 7653 | @Override |
| 7654 | public boolean isRttSupported(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7655 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7656 | final Phone phone = getPhone(subscriptionId); |
| 7657 | if (phone == null) { |
| 7658 | loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId); |
| 7659 | return false; |
| 7660 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7661 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7662 | boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7663 | CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL); |
| 7664 | boolean isDeviceSupported = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7665 | phone.getContext().getResources().getBoolean(R.bool.config_support_rtt); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7666 | return isCarrierSupported && isDeviceSupported; |
| 7667 | } finally { |
| 7668 | Binder.restoreCallingIdentity(identity); |
| 7669 | } |
Hall Liu | 9818758 | 2018-01-22 19:15:32 -0800 | [diff] [blame] | 7670 | } |
| 7671 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 7672 | /** |
Hall Liu | f2daa02 | 2019-07-23 18:39:00 -0700 | [diff] [blame] | 7673 | * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set |
| 7674 | * RTT setting, will return true if the device and carrier both support RTT. |
| 7675 | * 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] | 7676 | */ |
| 7677 | public boolean isRttEnabled(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7678 | final long identity = Binder.clearCallingIdentity(); |
| 7679 | try { |
Hall Liu | 5bab75c | 2019-12-11 23:58:20 +0000 | [diff] [blame] | 7680 | boolean isRttSupported = isRttSupported(subscriptionId); |
| 7681 | boolean isUserRttSettingOn = Settings.Secure.getInt( |
| 7682 | mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0; |
| 7683 | boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId) |
| 7684 | .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL); |
| 7685 | return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7686 | } finally { |
| 7687 | Binder.restoreCallingIdentity(identity); |
| 7688 | } |
Hall Liu | 3ad5f01 | 2018-04-06 16:23:39 -0700 | [diff] [blame] | 7689 | } |
| 7690 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7691 | @Deprecated |
| 7692 | @Override |
| 7693 | public String getDeviceId(String callingPackage) { |
| 7694 | return getDeviceIdWithFeature(callingPackage, null); |
| 7695 | } |
| 7696 | |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7697 | /** |
| 7698 | * Returns the unique device ID of phone, for example, the IMEI for |
| 7699 | * GSM and the MEID for CDMA phones. Return null if device ID is not available. |
| 7700 | * |
| 7701 | * <p>Requires Permission: |
| 7702 | * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} |
| 7703 | */ |
| 7704 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7705 | public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) { |
Shuo Qian | 13d8915 | 2021-05-10 23:58:11 -0700 | [diff] [blame] | 7706 | try { |
| 7707 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 7708 | } catch (SecurityException se) { |
| 7709 | EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid()); |
| 7710 | throw new SecurityException("Package " + callingPackage + " does not belong to " |
| 7711 | + Binder.getCallingUid()); |
| 7712 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7713 | final Phone phone = PhoneFactory.getPhone(0); |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7714 | if (phone == null) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7715 | return null; |
| 7716 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7717 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 7718 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7719 | callingPackage, callingFeatureId, "getDeviceId")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7720 | return null; |
| 7721 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7722 | |
| 7723 | final long identity = Binder.clearCallingIdentity(); |
| 7724 | try { |
| 7725 | return phone.getDeviceId(); |
| 7726 | } finally { |
| 7727 | Binder.restoreCallingIdentity(identity); |
| 7728 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7729 | } |
| 7730 | |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 7731 | /** |
| 7732 | * {@hide} |
| 7733 | * Returns the IMS Registration Status on a particular subid |
| 7734 | * |
| 7735 | * @param subId |
| 7736 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7737 | public boolean isImsRegistered(int subId) { |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 7738 | Phone phone = getPhone(subId); |
| 7739 | if (phone != null) { |
| 7740 | return phone.isImsRegistered(); |
| 7741 | } else { |
| 7742 | return false; |
| 7743 | } |
| 7744 | } |
| 7745 | |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 7746 | @Override |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7747 | public int getSubIdForPhoneAccountHandle( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7748 | PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) { |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7749 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(), |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7750 | callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) { |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7751 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 7752 | } |
| 7753 | final long identity = Binder.clearCallingIdentity(); |
| 7754 | try { |
| 7755 | return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle); |
| 7756 | } finally { |
| 7757 | Binder.restoreCallingIdentity(identity); |
| 7758 | } |
| 7759 | } |
| 7760 | |
| 7761 | @Override |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 7762 | public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) { |
Alireza Forouzan | 4ac4f98 | 2021-03-16 22:18:52 -0700 | [diff] [blame] | 7763 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 7764 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Alireza Forouzan | 4ac4f98 | 2021-03-16 22:18:52 -0700 | [diff] [blame] | 7765 | mApp, |
| 7766 | subscriptionId, |
| 7767 | "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: " + subscriptionId); |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 7768 | final long identity = Binder.clearCallingIdentity(); |
| 7769 | try { |
| 7770 | Phone phone = getPhone(subscriptionId); |
| 7771 | if (phone == null) { |
| 7772 | return null; |
| 7773 | } |
| 7774 | return PhoneUtils.makePstnPhoneAccountHandle(phone); |
| 7775 | } finally { |
| 7776 | Binder.restoreCallingIdentity(identity); |
| 7777 | } |
| 7778 | } |
| 7779 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7780 | /** |
| 7781 | * @return the VoWiFi calling availability. |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 7782 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7783 | public boolean isWifiCallingAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7784 | final long identity = Binder.clearCallingIdentity(); |
| 7785 | try { |
| 7786 | Phone phone = getPhone(subId); |
| 7787 | if (phone != null) { |
| 7788 | return phone.isWifiCallingEnabled(); |
| 7789 | } else { |
| 7790 | return false; |
| 7791 | } |
| 7792 | } finally { |
| 7793 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7794 | } |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 7795 | } |
| 7796 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7797 | /** |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7798 | * @return the VT calling availability. |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 7799 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7800 | public boolean isVideoTelephonyAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7801 | final long identity = Binder.clearCallingIdentity(); |
| 7802 | try { |
| 7803 | Phone phone = getPhone(subId); |
| 7804 | if (phone != null) { |
| 7805 | return phone.isVideoEnabled(); |
| 7806 | } else { |
| 7807 | return false; |
| 7808 | } |
| 7809 | } finally { |
| 7810 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7811 | } |
| 7812 | } |
| 7813 | |
| 7814 | /** |
| 7815 | * @return the IMS registration technology for the MMTEL feature. Valid return values are |
| 7816 | * defined in {@link ImsRegistrationImplBase}. |
| 7817 | */ |
| 7818 | public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7819 | final long identity = Binder.clearCallingIdentity(); |
| 7820 | try { |
| 7821 | Phone phone = getPhone(subId); |
| 7822 | if (phone != null) { |
| 7823 | return phone.getImsRegistrationTech(); |
| 7824 | } else { |
| 7825 | return ImsRegistrationImplBase.REGISTRATION_TECH_NONE; |
| 7826 | } |
| 7827 | } finally { |
| 7828 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7829 | } |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 7830 | } |
| 7831 | |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 7832 | @Override |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 7833 | public void factoryReset(int subId, String callingPackage) { |
paulhu | 5a77360 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 7834 | enforceSettingsPermission(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 7835 | if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) { |
| 7836 | return; |
| 7837 | } |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 7838 | Phone defaultPhone = getDefaultPhone(); |
| 7839 | if (defaultPhone != null) { |
| 7840 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7841 | mApp, getDefaultPhone().getSubId(), "factoryReset"); |
| 7842 | } |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7843 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7844 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7845 | try { |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 7846 | if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction( |
| 7847 | UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7848 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 7849 | getDefaultDataEnabled(), callingPackage); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7850 | setNetworkSelectionModeAutomatic(subId); |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 7851 | Phone phone = getPhone(subId); |
SongFerngWang | fd89b10 | 2021-05-27 22:44:54 +0800 | [diff] [blame] | 7852 | cleanUpAllowedNetworkTypes(phone, subId); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7853 | setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId)); |
Jordan Liu | 857e73a | 2021-03-05 16:24:04 -0800 | [diff] [blame] | 7854 | getPhone(subId).resetCarrierKeysForImsiEncryption(); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7855 | } |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 7856 | // There has been issues when Sms raw table somehow stores orphan |
| 7857 | // fragments. They lead to garbled message when new fragments come |
| 7858 | // in and combined with those stale ones. In case this happens again, |
| 7859 | // user can reset all network settings which will clean up this table. |
| 7860 | cleanUpSmsRawTable(getDefaultPhone().getContext()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 7861 | // Clean up IMS settings as well here. |
| 7862 | int slotId = getSlotIndex(subId); |
| 7863 | if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 7864 | ImsManager.getInstance(mApp, slotId).factoryReset(); |
| 7865 | } |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 7866 | |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 7867 | if (defaultPhone == null) { |
| 7868 | return; |
| 7869 | } |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 7870 | // Erase modem config if erase modem on network setting is enabled. |
| 7871 | String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY, |
| 7872 | RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED); |
| 7873 | if (configValue != null && Boolean.parseBoolean(configValue)) { |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 7874 | sendEraseModemConfig(defaultPhone); |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 7875 | } |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 7876 | |
| 7877 | sendEraseDataInSharedPreferences(defaultPhone); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7878 | } finally { |
| 7879 | Binder.restoreCallingIdentity(identity); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 7880 | } |
| 7881 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7882 | |
SongFerngWang | fd89b10 | 2021-05-27 22:44:54 +0800 | [diff] [blame] | 7883 | @VisibleForTesting |
| 7884 | void cleanUpAllowedNetworkTypes(Phone phone, int subId) { |
| 7885 | if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) { |
| 7886 | return; |
| 7887 | } |
| 7888 | long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType( |
| 7889 | RILConstants.PREFERRED_NETWORK_MODE); |
| 7890 | SubscriptionManager.setSubscriptionProperty(subId, |
| 7891 | SubscriptionManager.ALLOWED_NETWORK_TYPES, |
| 7892 | "user=" + defaultNetworkType); |
| 7893 | phone.loadAllowedNetworksFromSubscriptionDatabase(); |
| 7894 | phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER, |
| 7895 | defaultNetworkType, null); |
| 7896 | } |
| 7897 | |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 7898 | private void cleanUpSmsRawTable(Context context) { |
| 7899 | ContentResolver resolver = context.getContentResolver(); |
| 7900 | Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete"); |
| 7901 | resolver.delete(uri, null, null); |
| 7902 | } |
| 7903 | |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7904 | @Override |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7905 | public String getSimLocaleForSubscriber(int subId) { |
| 7906 | enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId); |
| 7907 | final Phone phone = getPhone(subId); |
| 7908 | if (phone == null) { |
| 7909 | log("getSimLocaleForSubscriber, invalid subId"); |
chen xu | 2bb91e4 | 2019-01-24 14:35:54 -0800 | [diff] [blame] | 7910 | return null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7911 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7912 | final long identity = Binder.clearCallingIdentity(); |
| 7913 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 7914 | SubscriptionInfo info; |
| 7915 | if (PhoneFactory.isSubscriptionManagerServiceEnabled()) { |
| 7916 | info = SubscriptionManagerService.getInstance().getActiveSubscriptionInfo(subId, |
| 7917 | phone.getContext().getOpPackageName(), |
| 7918 | phone.getContext().getAttributionTag()); |
| 7919 | if (info == null) { |
| 7920 | log("getSimLocaleForSubscriber, inactive subId: " + subId); |
| 7921 | return null; |
| 7922 | } |
| 7923 | } else { |
| 7924 | info = mSubscriptionController.getActiveSubscriptionInfo(subId, |
| 7925 | phone.getContext().getOpPackageName(), |
| 7926 | phone.getContext().getAttributionTag()); |
| 7927 | if (info == null) { |
| 7928 | log("getSimLocaleForSubscriber, inactive subId: " + subId); |
| 7929 | return null; |
| 7930 | } |
chen xu | 6291c47 | 2019-02-04 12:55:53 -0800 | [diff] [blame] | 7931 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7932 | // Try and fetch the locale from the carrier properties or from the SIM language |
| 7933 | // preferences (EF-PL and EF-LI)... |
| 7934 | final int mcc = info.getMcc(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7935 | String simLanguage = null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7936 | final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs(); |
| 7937 | if (localeFromDefaultSim != null) { |
| 7938 | if (!localeFromDefaultSim.getCountry().isEmpty()) { |
| 7939 | if (DBG) log("Using locale from subId: " + subId + " locale: " |
| 7940 | + localeFromDefaultSim); |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 7941 | return matchLocaleFromSupportedLocaleList(phone, localeFromDefaultSim); |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7942 | } else { |
| 7943 | simLanguage = localeFromDefaultSim.getLanguage(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7944 | } |
| 7945 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7946 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7947 | // The SIM language preferences only store a language (e.g. fr = French), not an |
| 7948 | // exact locale (e.g. fr_FR = French/France). So, if the locale returned from |
| 7949 | // the SIM and carrier preferences does not include a country we add the country |
| 7950 | // determined from the SIM MCC to provide an exact locale. |
zoey chen | c730df8 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 7951 | final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7952 | if (mccLocale != null) { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7953 | if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale); |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 7954 | return matchLocaleFromSupportedLocaleList(phone, mccLocale); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7955 | } |
| 7956 | |
| 7957 | if (DBG) log("No locale found - returning null"); |
| 7958 | return null; |
| 7959 | } finally { |
| 7960 | Binder.restoreCallingIdentity(identity); |
| 7961 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7962 | } |
| 7963 | |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 7964 | @VisibleForTesting |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 7965 | String matchLocaleFromSupportedLocaleList(Phone phone, @NonNull Locale inputLocale) { |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 7966 | String[] supportedLocale = com.android.internal.app.LocalePicker.getSupportedLocales( |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 7967 | phone.getContext()); |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 7968 | for (String localeTag : supportedLocale) { |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 7969 | if (LocaleList.matchesLanguageAndScript(inputLocale, Locale.forLanguageTag(localeTag)) |
| 7970 | && TextUtils.equals(inputLocale.getCountry(), |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 7971 | Locale.forLanguageTag(localeTag).getCountry())) { |
| 7972 | return localeTag; |
| 7973 | } |
| 7974 | } |
| 7975 | return inputLocale.toLanguageTag(); |
| 7976 | } |
| 7977 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7978 | /** |
| 7979 | * NOTE: this method assumes permission checks are done and caller identity has been cleared. |
| 7980 | */ |
| 7981 | private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 7982 | if (PhoneFactory.isSubscriptionManagerServiceEnabled()) { |
| 7983 | return SubscriptionManagerService.getInstance().getActiveSubscriptionInfoList( |
| 7984 | mApp.getOpPackageName(), mApp.getAttributionTag()); |
| 7985 | } |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7986 | return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(), |
Philip P. Moltmann | 8d34f0c | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7987 | mApp.getAttributionTag()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7988 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7989 | |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 7990 | private ActivityStatsTechSpecificInfo[] mLastModemActivitySpecificInfo = null; |
| 7991 | private ModemActivityInfo mLastModemActivityInfo = null; |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7992 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7993 | /** |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 7994 | * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object |
| 7995 | * representing the state of the modem. |
| 7996 | * |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7997 | * NOTE: The underlying implementation clears the modem state, so there should only ever be one |
| 7998 | * caller to it. Everyone should call this class to get cumulative data. |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 7999 | * @hide |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 8000 | */ |
| 8001 | @Override |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 8002 | public void requestModemActivityInfo(ResultReceiver result) { |
| 8003 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8004 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8005 | |
| 8006 | final long identity = Binder.clearCallingIdentity(); |
| 8007 | try { |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 8008 | sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8009 | } finally { |
| 8010 | Binder.restoreCallingIdentity(identity); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 8011 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 8012 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8013 | |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 8014 | // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be |
| 8015 | // less than total activity duration. |
| 8016 | private boolean isModemActivityInfoValid(ModemActivityInfo info) { |
| 8017 | if (info == null) { |
| 8018 | return false; |
| 8019 | } |
| 8020 | int activityDurationMs = |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 8021 | (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis()); |
| 8022 | int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum(); |
| 8023 | |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 8024 | return (info.isValid() |
| 8025 | && (info.getSleepTimeMillis() <= activityDurationMs) |
| 8026 | && (info.getIdleTimeMillis() <= activityDurationMs) |
Chen Xu | d78231e | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 8027 | && (info.getReceiveTimeMillis() <= activityDurationMs) |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 8028 | && (totalTxTimeMs <= activityDurationMs)); |
| 8029 | } |
| 8030 | |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8031 | private void updateLastModemActivityInfo(ModemActivityInfo info, int rat, int freq) { |
| 8032 | int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()]; |
| 8033 | int[] txTimeMs = info.getTransmitTimeMillis(rat, freq); |
| 8034 | int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat, freq); |
| 8035 | |
| 8036 | for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) { |
| 8037 | mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl]; |
| 8038 | } |
| 8039 | |
| 8040 | mLastModemActivityInfo.setTransmitTimeMillis(rat, freq, mergedTxTimeMs); |
| 8041 | mLastModemActivityInfo.setReceiveTimeMillis( |
| 8042 | rat, |
| 8043 | freq, |
| 8044 | info.getReceiveTimeMillis(rat, freq) |
| 8045 | + mLastModemActivityInfo.getReceiveTimeMillis(rat, freq)); |
| 8046 | } |
| 8047 | |
| 8048 | private void updateLastModemActivityInfo(ModemActivityInfo info, int rat) { |
| 8049 | int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()]; |
| 8050 | int[] txTimeMs = info.getTransmitTimeMillis(rat); |
| 8051 | int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat); |
| 8052 | |
| 8053 | for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) { |
| 8054 | mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl]; |
| 8055 | } |
| 8056 | mLastModemActivityInfo.setTransmitTimeMillis(rat, mergedTxTimeMs); |
| 8057 | mLastModemActivityInfo.setReceiveTimeMillis( |
| 8058 | rat, |
| 8059 | info.getReceiveTimeMillis(rat) + mLastModemActivityInfo.getReceiveTimeMillis(rat)); |
| 8060 | } |
| 8061 | |
| 8062 | /** |
| 8063 | * Merge this ModemActivityInfo with mLastModemActivitySpecificInfo |
| 8064 | * @param info recent ModemActivityInfo |
| 8065 | */ |
| 8066 | private void mergeModemActivityInfo(ModemActivityInfo info) { |
| 8067 | List<ActivityStatsTechSpecificInfo> merged = new ArrayList<>(); |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 8068 | ActivityStatsTechSpecificInfo deltaSpecificInfo; |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8069 | boolean matched; |
| 8070 | for (int i = 0; i < info.getSpecificInfoLength(); i++) { |
| 8071 | matched = false; |
| 8072 | int rat = info.getSpecificInfoRat(i); |
| 8073 | int freq = info.getSpecificInfoFrequencyRange(i); |
| 8074 | //Check each ActivityStatsTechSpecificInfo in this ModemActivityInfo for new rat returns |
| 8075 | //Add a new ActivityStatsTechSpecificInfo if is a new rat, and merge with the original |
| 8076 | //if it already exists |
| 8077 | for (int j = 0; j < mLastModemActivitySpecificInfo.length; j++) { |
| 8078 | if (rat == mLastModemActivityInfo.getSpecificInfoRat(j) && !matched) { |
| 8079 | //Merged based on frequency range (MMWAVE vs SUB6) for 5G |
| 8080 | if (rat == AccessNetworkConstants.AccessNetworkType.NGRAN) { |
| 8081 | if (freq == mLastModemActivityInfo.getSpecificInfoFrequencyRange(j)) { |
| 8082 | updateLastModemActivityInfo(info, rat, freq); |
| 8083 | matched = true; |
| 8084 | } |
| 8085 | } else { |
| 8086 | updateLastModemActivityInfo(info, rat); |
| 8087 | matched = true; |
| 8088 | } |
| 8089 | } |
| 8090 | } |
| 8091 | |
| 8092 | if (!matched) { |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 8093 | deltaSpecificInfo = |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8094 | new ActivityStatsTechSpecificInfo( |
| 8095 | rat, |
| 8096 | freq, |
| 8097 | info.getTransmitTimeMillis(rat, freq), |
| 8098 | (int) info.getReceiveTimeMillis(rat, freq)); |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 8099 | merged.addAll(Arrays.asList(deltaSpecificInfo)); |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8100 | } |
| 8101 | } |
| 8102 | merged.addAll(Arrays.asList(mLastModemActivitySpecificInfo)); |
| 8103 | mLastModemActivitySpecificInfo = |
| 8104 | new ActivityStatsTechSpecificInfo[merged.size()]; |
| 8105 | merged.toArray(mLastModemActivitySpecificInfo); |
| 8106 | |
| 8107 | mLastModemActivityInfo.setTimestamp(info.getTimestampMillis()); |
| 8108 | mLastModemActivityInfo.setSleepTimeMillis( |
| 8109 | info.getSleepTimeMillis() |
| 8110 | + mLastModemActivityInfo.getSleepTimeMillis()); |
| 8111 | mLastModemActivityInfo.setIdleTimeMillis( |
| 8112 | info.getIdleTimeMillis() |
| 8113 | + mLastModemActivityInfo.getIdleTimeMillis()); |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 8114 | |
| 8115 | mLastModemActivityInfo = |
| 8116 | new ModemActivityInfo( |
| 8117 | mLastModemActivityInfo.getTimestampMillis(), |
| 8118 | mLastModemActivityInfo.getSleepTimeMillis(), |
| 8119 | mLastModemActivityInfo.getIdleTimeMillis(), |
| 8120 | mLastModemActivitySpecificInfo); |
| 8121 | } |
| 8122 | |
| 8123 | private ActivityStatsTechSpecificInfo[] deepCopyModemActivitySpecificInfo( |
| 8124 | ActivityStatsTechSpecificInfo[] info) { |
| 8125 | int infoSize = info.length; |
| 8126 | ActivityStatsTechSpecificInfo[] ret = new ActivityStatsTechSpecificInfo[infoSize]; |
| 8127 | for (int i = 0; i < infoSize; i++) { |
| 8128 | ret[i] = new ActivityStatsTechSpecificInfo( |
| 8129 | info[i].getRat(), info[i].getFrequencyRange(), |
| 8130 | info[i].getTransmitTimeMillis(), |
| 8131 | (int) info[i].getReceiveTimeMillis()); |
| 8132 | } |
| 8133 | return ret; |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8134 | } |
| 8135 | |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8136 | /** |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8137 | * Returns the service state information on specified subscription. |
| 8138 | */ |
| 8139 | @Override |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 8140 | public ServiceState getServiceStateForSubscriber(int subId, |
| 8141 | boolean renounceFineLocationAccess, boolean renounceCoarseLocationAccess, |
| 8142 | String callingPackage, String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8143 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8144 | mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) { |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8145 | return null; |
| 8146 | } |
| 8147 | |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 8148 | boolean hasFinePermission = false; |
| 8149 | boolean hasCoarsePermission = false; |
| 8150 | if (!renounceFineLocationAccess) { |
| 8151 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 8152 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 8153 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 8154 | .setCallingPackage(callingPackage) |
| 8155 | .setCallingFeatureId(callingFeatureId) |
| 8156 | .setCallingPid(Binder.getCallingPid()) |
| 8157 | .setCallingUid(Binder.getCallingUid()) |
| 8158 | .setMethod("getServiceStateForSubscriber") |
| 8159 | .setLogAsInfo(true) |
| 8160 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 8161 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 8162 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 8163 | .build()); |
| 8164 | hasFinePermission = |
| 8165 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 8166 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 8167 | |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 8168 | if (!renounceCoarseLocationAccess) { |
| 8169 | LocationAccessPolicy.LocationPermissionResult coarseLocationResult = |
| 8170 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 8171 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 8172 | .setCallingPackage(callingPackage) |
| 8173 | .setCallingFeatureId(callingFeatureId) |
| 8174 | .setCallingPid(Binder.getCallingPid()) |
| 8175 | .setCallingUid(Binder.getCallingUid()) |
| 8176 | .setMethod("getServiceStateForSubscriber") |
| 8177 | .setLogAsInfo(true) |
| 8178 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 8179 | .setMinSdkVersionForFine(Integer.MAX_VALUE) |
| 8180 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 8181 | .build()); |
| 8182 | hasCoarsePermission = |
| 8183 | coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 8184 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 8185 | |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 8186 | final Phone phone = getPhone(subId); |
| 8187 | if (phone == null) { |
| 8188 | return null; |
| 8189 | } |
| 8190 | |
Jordan Liu | 0f2bc44 | 2020-11-18 16:47:37 -0800 | [diff] [blame] | 8191 | final long identity = Binder.clearCallingIdentity(); |
| 8192 | |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 8193 | boolean isCallingPackageDataService = phone.getDataServicePackages() |
| 8194 | .contains(callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8195 | try { |
Jordan Liu | c437b19 | 2020-08-17 10:59:12 -0700 | [diff] [blame] | 8196 | // isActiveSubId requires READ_PHONE_STATE, which we already check for above |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 8197 | if (PhoneFactory.isSubscriptionManagerServiceEnabled()) { |
| 8198 | SubscriptionInfoInternal subInfo = SubscriptionManagerService.getInstance() |
| 8199 | .getSubscriptionInfoInternal(subId); |
| 8200 | if (subInfo == null || !subInfo.isActive()) { |
| 8201 | Rlog.d(LOG_TAG, "getServiceStateForSubscriber returning null for inactive " |
| 8202 | + "subId=" + subId); |
| 8203 | return null; |
| 8204 | } |
| 8205 | } else { |
| 8206 | if (!mSubscriptionController.isActiveSubId(subId, callingPackage, |
| 8207 | callingFeatureId)) { |
| 8208 | Rlog.d(LOG_TAG, "getServiceStateForSubscriber returning null for inactive " |
| 8209 | + "subId=" + subId); |
| 8210 | return null; |
| 8211 | } |
Jordan Liu | c437b19 | 2020-08-17 10:59:12 -0700 | [diff] [blame] | 8212 | } |
| 8213 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 8214 | ServiceState ss = phone.getServiceState(); |
| 8215 | |
| 8216 | // Scrub out the location info in ServiceState depending on what level of access |
| 8217 | // the caller has. |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 8218 | if (hasFinePermission || isCallingPackageDataService) return ss; |
Malcolm Chen | 5052de6 | 2019-12-30 13:56:38 -0800 | [diff] [blame] | 8219 | if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false); |
| 8220 | return ss.createLocationInfoSanitizedCopy(true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8221 | } finally { |
| 8222 | Binder.restoreCallingIdentity(identity); |
| 8223 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8224 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8225 | |
| 8226 | /** |
| 8227 | * Returns the URI for the per-account voicemail ringtone set in Phone settings. |
| 8228 | * |
| 8229 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 8230 | * voicemail ringtone. |
| 8231 | * @return The URI for the ringtone to play when receiving a voicemail from a specific |
| 8232 | * PhoneAccount. |
| 8233 | */ |
| 8234 | @Override |
| 8235 | public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8236 | final long identity = Binder.clearCallingIdentity(); |
| 8237 | try { |
| 8238 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 8239 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8240 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8241 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8242 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8243 | return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext()); |
| 8244 | } finally { |
| 8245 | Binder.restoreCallingIdentity(identity); |
| 8246 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8247 | } |
| 8248 | |
| 8249 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8250 | * Sets the per-account voicemail ringtone. |
| 8251 | * |
| 8252 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 8253 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 8254 | * |
| 8255 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 8256 | * voicemail ringtone. |
| 8257 | * @param uri The URI for the ringtone to play when receiving a voicemail from a specific |
| 8258 | * PhoneAccount. |
| 8259 | */ |
| 8260 | @Override |
| 8261 | public void setVoicemailRingtoneUri(String callingPackage, |
| 8262 | PhoneAccountHandle phoneAccountHandle, Uri uri) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8263 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8264 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 8265 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 8266 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8267 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8268 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 8269 | "setVoicemailRingtoneUri"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8270 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8271 | |
| 8272 | final long identity = Binder.clearCallingIdentity(); |
| 8273 | try { |
| 8274 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 8275 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8276 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8277 | } |
| 8278 | VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri); |
| 8279 | } finally { |
| 8280 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8281 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8282 | } |
| 8283 | |
| 8284 | /** |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8285 | * Returns whether vibration is set for voicemail notification in Phone settings. |
| 8286 | * |
| 8287 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 8288 | * voicemail vibration setting. |
| 8289 | * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise. |
| 8290 | */ |
| 8291 | @Override |
| 8292 | public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8293 | final long identity = Binder.clearCallingIdentity(); |
| 8294 | try { |
| 8295 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 8296 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8297 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8298 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8299 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8300 | return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext()); |
| 8301 | } finally { |
| 8302 | Binder.restoreCallingIdentity(identity); |
| 8303 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8304 | } |
| 8305 | |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8306 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8307 | * Sets the per-account voicemail vibration. |
| 8308 | * |
| 8309 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 8310 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 8311 | * |
| 8312 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 8313 | * voicemail vibration setting. |
| 8314 | * @param enabled Whether to enable or disable vibration for voicemail notifications from a |
| 8315 | * specific PhoneAccount. |
| 8316 | */ |
| 8317 | @Override |
| 8318 | public void setVoicemailVibrationEnabled(String callingPackage, |
| 8319 | PhoneAccountHandle phoneAccountHandle, boolean enabled) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8320 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8321 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 8322 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 8323 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8324 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8325 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 8326 | "setVoicemailVibrationEnabled"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8327 | } |
| 8328 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8329 | final long identity = Binder.clearCallingIdentity(); |
| 8330 | try { |
| 8331 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 8332 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8333 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8334 | } |
| 8335 | VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled); |
| 8336 | } finally { |
| 8337 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8338 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8339 | } |
| 8340 | |
| 8341 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8342 | * Make sure either called from same process as self (phone) or IPC caller has read privilege. |
| 8343 | * |
| 8344 | * @throws SecurityException if the caller does not have the required permission |
| 8345 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8346 | private void enforceReadPrivilegedPermission(String message) { |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8347 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8348 | message); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8349 | } |
| 8350 | |
| 8351 | /** |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 8352 | * Make sure either called from same process as self (phone) or IPC caller has send SMS |
| 8353 | * permission. |
| 8354 | * |
| 8355 | * @throws SecurityException if the caller does not have the required permission |
| 8356 | */ |
| 8357 | private void enforceSendSmsPermission() { |
| 8358 | mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null); |
| 8359 | } |
| 8360 | |
| 8361 | /** |
Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame] | 8362 | * Make sure either called from same process as self (phone) or IPC caller has interact across |
| 8363 | * users permission. |
| 8364 | * |
| 8365 | * @throws SecurityException if the caller does not have the required permission |
| 8366 | */ |
| 8367 | private void enforceInteractAcrossUsersPermission(String message) { |
| 8368 | mApp.enforceCallingOrSelfPermission(permission.INTERACT_ACROSS_USERS, message); |
| 8369 | } |
| 8370 | |
| 8371 | /** |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 8372 | * Make sure called from the package in charge of visual voicemail. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 8373 | * |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 8374 | * @throws SecurityException if the caller is not the visual voicemail package. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 8375 | */ |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 8376 | private void enforceVisualVoicemailPackage(String callingPackage, int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8377 | final long identity = Binder.clearCallingIdentity(); |
| 8378 | try { |
| 8379 | ComponentName componentName = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8380 | RemoteVvmTaskManager.getRemotePackage(mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8381 | if (componentName == null) { |
| 8382 | throw new SecurityException( |
| 8383 | "Caller not current active visual voicemail package[null]"); |
| 8384 | } |
| 8385 | String vvmPackage = componentName.getPackageName(); |
| 8386 | if (!callingPackage.equals(vvmPackage)) { |
Hui Wang | 7f65755 | 2022-08-16 16:58:25 +0000 | [diff] [blame] | 8387 | throw new SecurityException("Caller not current active visual voicemail package"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8388 | } |
| 8389 | } finally { |
| 8390 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 8391 | } |
| 8392 | } |
| 8393 | |
| 8394 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8395 | * Return the application ID for the app type. |
| 8396 | * |
| 8397 | * @param subId the subscription ID that this request applies to. |
| 8398 | * @param appType the uicc app type. |
| 8399 | * @return Application ID for specificied app type, or null if no uicc. |
| 8400 | */ |
| 8401 | @Override |
| 8402 | public String getAidForAppType(int subId, int appType) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8403 | enforceReadPrivilegedPermission("getAidForAppType"); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8404 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8405 | |
| 8406 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8407 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8408 | if (phone == null) { |
| 8409 | return null; |
| 8410 | } |
| 8411 | String aid = null; |
| 8412 | try { |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 8413 | aid = UiccController.getInstance().getUiccPort(phone.getPhoneId()) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8414 | .getApplicationByType(appType).getAid(); |
| 8415 | } catch (Exception e) { |
| 8416 | Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e); |
| 8417 | } |
| 8418 | return aid; |
| 8419 | } finally { |
| 8420 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8421 | } |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8422 | } |
| 8423 | |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8424 | /** |
| 8425 | * Return the Electronic Serial Number. |
| 8426 | * |
| 8427 | * @param subId the subscription ID that this request applies to. |
| 8428 | * @return ESN or null if error. |
| 8429 | */ |
| 8430 | @Override |
| 8431 | public String getEsn(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8432 | enforceReadPrivilegedPermission("getEsn"); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8433 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8434 | |
| 8435 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8436 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8437 | if (phone == null) { |
| 8438 | return null; |
| 8439 | } |
| 8440 | String esn = null; |
| 8441 | try { |
| 8442 | esn = phone.getEsn(); |
| 8443 | } catch (Exception e) { |
| 8444 | Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e); |
| 8445 | } |
| 8446 | return esn; |
| 8447 | } finally { |
| 8448 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8449 | } |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8450 | } |
| 8451 | |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 8452 | /** |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8453 | * Return the Preferred Roaming List Version. |
| 8454 | * |
| 8455 | * @param subId the subscription ID that this request applies to. |
| 8456 | * @return PRLVersion or null if error. |
| 8457 | */ |
| 8458 | @Override |
| 8459 | public String getCdmaPrlVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8460 | enforceReadPrivilegedPermission("getCdmaPrlVersion"); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8461 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8462 | |
| 8463 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8464 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8465 | if (phone == null) { |
| 8466 | return null; |
| 8467 | } |
| 8468 | String cdmaPrlVersion = null; |
| 8469 | try { |
| 8470 | cdmaPrlVersion = phone.getCdmaPrlVersion(); |
| 8471 | } catch (Exception e) { |
| 8472 | Log.e(LOG_TAG, "Not getting PRLVersion", e); |
| 8473 | } |
| 8474 | return cdmaPrlVersion; |
| 8475 | } finally { |
| 8476 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8477 | } |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8478 | } |
| 8479 | |
| 8480 | /** |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 8481 | * Get snapshot of Telephony histograms |
| 8482 | * @return List of Telephony histograms |
| 8483 | * @hide |
| 8484 | */ |
| 8485 | @Override |
| 8486 | public List<TelephonyHistogram> getTelephonyHistograms() { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8487 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8488 | mApp, getDefaultSubscription(), "getTelephonyHistograms"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8489 | |
| 8490 | final long identity = Binder.clearCallingIdentity(); |
| 8491 | try { |
| 8492 | return RIL.getTelephonyRILTimingHistograms(); |
| 8493 | } finally { |
| 8494 | Binder.restoreCallingIdentity(identity); |
| 8495 | } |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 8496 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8497 | |
| 8498 | /** |
| 8499 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8500 | * Set the allowed carrier list and the excluded carrier list, indicating the priority between |
| 8501 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8502 | * Require system privileges. In the future we may add this to carrier APIs. |
| 8503 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8504 | * @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] | 8505 | */ |
| 8506 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8507 | @TelephonyManager.SetCarrierRestrictionResult |
| 8508 | public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) { |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8509 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8510 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8511 | |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8512 | if (carrierRestrictionRules == null) { |
| 8513 | throw new NullPointerException("carrier restriction cannot be null"); |
Meng Wang | 9b7c4e9 | 2017-02-17 11:41:27 -0800 | [diff] [blame] | 8514 | } |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8515 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8516 | final long identity = Binder.clearCallingIdentity(); |
| 8517 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8518 | return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8519 | workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8520 | } finally { |
| 8521 | Binder.restoreCallingIdentity(identity); |
| 8522 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8523 | } |
| 8524 | |
| 8525 | /** |
| 8526 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8527 | * Get the allowed carrier list and the excluded carrier list, including the priority between |
| 8528 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8529 | * Require system privileges. In the future we may add this to carrier APIs. |
| 8530 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8531 | * @return {@link android.telephony.CarrierRestrictionRules} |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8532 | */ |
| 8533 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8534 | public CarrierRestrictionRules getAllowedCarriers() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8535 | enforceReadPrivilegedPermission("getAllowedCarriers"); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8536 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8537 | |
| 8538 | final long identity = Binder.clearCallingIdentity(); |
| 8539 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8540 | Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource); |
| 8541 | if (response instanceof CarrierRestrictionRules) { |
| 8542 | return (CarrierRestrictionRules) response; |
| 8543 | } |
| 8544 | // Response is an Exception of some kind, |
| 8545 | // which is signalled to the user as a NULL retval |
| 8546 | return null; |
| 8547 | } catch (Exception e) { |
| 8548 | Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e); |
| 8549 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8550 | } finally { |
| 8551 | Binder.restoreCallingIdentity(identity); |
| 8552 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8553 | } |
| 8554 | |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 8555 | /** |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 8556 | * Action set from carrier signalling broadcast receivers to enable/disable radio |
| 8557 | * @param subId the subscription ID that this action applies to. |
| 8558 | * @param enabled control enable or disable radio. |
| 8559 | * {@hide} |
| 8560 | */ |
| 8561 | @Override |
| 8562 | public void carrierActionSetRadioEnabled(int subId, boolean enabled) { |
| 8563 | enforceModifyPermission(); |
| 8564 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8565 | |
| 8566 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 8567 | if (phone == null) { |
| 8568 | loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId); |
| 8569 | return; |
| 8570 | } |
| 8571 | try { |
| 8572 | phone.carrierActionSetRadioEnabled(enabled); |
| 8573 | } catch (Exception e) { |
| 8574 | Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8575 | } finally { |
| 8576 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 8577 | } |
| 8578 | } |
| 8579 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 8580 | /** |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 8581 | * Enable or disable Voice over NR (VoNR) |
| 8582 | * @param subId the subscription ID that this action applies to. |
| 8583 | * @param enabled enable or disable VoNR. |
| 8584 | * @return operation result. |
| 8585 | */ |
| 8586 | @Override |
| 8587 | public int setVoNrEnabled(int subId, boolean enabled) { |
| 8588 | enforceModifyPermission(); |
| 8589 | final Phone phone = getPhone(subId); |
| 8590 | |
| 8591 | final long identity = Binder.clearCallingIdentity(); |
| 8592 | if (phone == null) { |
| 8593 | loge("setVoNrEnabled fails with no phone object for subId: " + subId); |
| 8594 | return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE; |
| 8595 | } |
| 8596 | |
| 8597 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8598 | try { |
| 8599 | int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId, |
| 8600 | workSource); |
| 8601 | if (DBG) log("setVoNrEnabled result: " + result); |
Gary Jian | 8dd305f | 2021-10-14 16:31:35 +0800 | [diff] [blame] | 8602 | |
| 8603 | if (result == TelephonyManager.ENABLE_VONR_SUCCESS) { |
| 8604 | if (DBG) { |
| 8605 | log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled); |
| 8606 | } |
| 8607 | SubscriptionManager.setSubscriptionProperty( |
| 8608 | subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED, |
| 8609 | (enabled ? "1" : "0")); |
| 8610 | } |
| 8611 | |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 8612 | return result; |
| 8613 | } finally { |
| 8614 | Binder.restoreCallingIdentity(identity); |
| 8615 | } |
| 8616 | } |
| 8617 | |
| 8618 | /** |
| 8619 | * Is voice over NR enabled |
| 8620 | * @return true if VoNR is enabled else false |
| 8621 | */ |
| 8622 | @Override |
| 8623 | public boolean isVoNrEnabled(int subId) { |
| 8624 | enforceReadPrivilegedPermission("isVoNrEnabled"); |
| 8625 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8626 | final long identity = Binder.clearCallingIdentity(); |
| 8627 | try { |
| 8628 | boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED, |
| 8629 | null, subId, workSource); |
| 8630 | if (DBG) log("isVoNrEnabled: " + isEnabled); |
| 8631 | return isEnabled; |
| 8632 | } finally { |
| 8633 | Binder.restoreCallingIdentity(identity); |
| 8634 | } |
| 8635 | } |
| 8636 | |
| 8637 | /** |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 8638 | * Action set from carrier signalling broadcast receivers to start/stop reporting the default |
| 8639 | * network status based on which carrier apps could apply actions accordingly, |
| 8640 | * enable/disable default url handler for example. |
| 8641 | * |
| 8642 | * @param subId the subscription ID that this action applies to. |
| 8643 | * @param report control start/stop reporting the default network status. |
| 8644 | * {@hide} |
| 8645 | */ |
| 8646 | @Override |
| 8647 | public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) { |
| 8648 | enforceModifyPermission(); |
| 8649 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8650 | |
| 8651 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 8652 | if (phone == null) { |
| 8653 | loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId); |
| 8654 | return; |
| 8655 | } |
| 8656 | try { |
| 8657 | phone.carrierActionReportDefaultNetworkStatus(report); |
| 8658 | } catch (Exception e) { |
| 8659 | Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8660 | } finally { |
| 8661 | Binder.restoreCallingIdentity(identity); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 8662 | } |
| 8663 | } |
| 8664 | |
| 8665 | /** |
fionaxu | d962228 | 2017-07-17 17:51:30 -0700 | [diff] [blame] | 8666 | * Action set from carrier signalling broadcast receivers to reset all carrier actions |
| 8667 | * @param subId the subscription ID that this action applies to. |
| 8668 | * {@hide} |
| 8669 | */ |
| 8670 | @Override |
| 8671 | public void carrierActionResetAll(int subId) { |
| 8672 | enforceModifyPermission(); |
| 8673 | final Phone phone = getPhone(subId); |
| 8674 | if (phone == null) { |
| 8675 | loge("carrierAction: ResetAll fails with invalid sibId: " + subId); |
| 8676 | return; |
| 8677 | } |
| 8678 | try { |
| 8679 | phone.carrierActionResetAll(); |
| 8680 | } catch (Exception e) { |
| 8681 | Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e); |
| 8682 | } |
| 8683 | } |
| 8684 | |
| 8685 | /** |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 8686 | * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a |
| 8687 | * bug report is being generated. |
| 8688 | */ |
| 8689 | @Override |
Ta-wei Yen | 99282e0 | 2016-06-21 18:19:35 -0700 | [diff] [blame] | 8690 | protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8691 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 8692 | != PackageManager.PERMISSION_GRANTED) { |
dcashman | 22b950d | 2016-06-27 11:39:02 -0700 | [diff] [blame] | 8693 | writer.println("Permission Denial: can't dump Phone from pid=" |
| 8694 | + Binder.getCallingPid() |
| 8695 | + ", uid=" + Binder.getCallingUid() |
| 8696 | + "without permission " |
| 8697 | + android.Manifest.permission.DUMP); |
| 8698 | return; |
| 8699 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8700 | DumpsysHandler.dump(mApp, fd, writer, args); |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 8701 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 8702 | |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 8703 | @Override |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 8704 | public int handleShellCommand(@NonNull ParcelFileDescriptor in, |
| 8705 | @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err, |
| 8706 | @NonNull String[] args) { |
| 8707 | return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec( |
| 8708 | this, in.getFileDescriptor(), out.getFileDescriptor(), |
| 8709 | err.getFileDescriptor(), args); |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 8710 | } |
| 8711 | |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 8712 | /** |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8713 | * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason} |
Greg Kaiser | 17f4175 | 2020-05-05 16:47:47 +0000 | [diff] [blame] | 8714 | * @param subId Subscription index |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 8715 | * @param reason The reason the data enable change is taking place. |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8716 | * @param enabled True if enabling the data, otherwise disabling. |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 8717 | * @param callingPackage The package that changed the data enabled state. |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8718 | * @hide |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 8719 | */ |
| 8720 | @Override |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 8721 | public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 8722 | boolean enabled, String callingPackage) { |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8723 | if (reason == TelephonyManager.DATA_ENABLED_REASON_USER |
| 8724 | || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 8725 | try { |
| 8726 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 8727 | mApp, subId, "setDataEnabledForReason"); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8728 | } catch (SecurityException se) { |
| 8729 | enforceModifyPermission(); |
| 8730 | } |
| 8731 | } else { |
| 8732 | enforceModifyPermission(); |
| 8733 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8734 | |
| 8735 | final long identity = Binder.clearCallingIdentity(); |
| 8736 | try { |
| 8737 | Phone phone = getPhone(subId); |
| 8738 | if (phone != null) { |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8739 | if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 8740 | phone.carrierActionSetMeteredApnsEnabled(enabled); |
| 8741 | } else { |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 8742 | phone.getDataSettingsManager().setDataEnabled( |
| 8743 | reason, enabled, callingPackage); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8744 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8745 | } |
| 8746 | } finally { |
| 8747 | Binder.restoreCallingIdentity(identity); |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 8748 | } |
| 8749 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8750 | |
| 8751 | /** |
| 8752 | * Get Client request stats |
| 8753 | * @return List of Client Request Stats |
| 8754 | * @hide |
| 8755 | */ |
| 8756 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8757 | public List<ClientRequestStats> getClientRequestStats(String callingPackage, |
| 8758 | String callingFeatureId, int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8759 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8760 | mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) { |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8761 | return null; |
| 8762 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8763 | Phone phone = getPhone(subId); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8764 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8765 | final long identity = Binder.clearCallingIdentity(); |
| 8766 | try { |
| 8767 | if (phone != null) { |
| 8768 | return phone.getClientRequestStats(); |
| 8769 | } |
| 8770 | |
| 8771 | return null; |
| 8772 | } finally { |
| 8773 | Binder.restoreCallingIdentity(identity); |
| 8774 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8775 | } |
| 8776 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 8777 | private WorkSource getWorkSource(int uid) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8778 | String packageName = mApp.getPackageManager().getNameForUid(uid); |
Hunter Knepshield | d03383b | 2022-03-29 22:47:54 +0000 | [diff] [blame] | 8779 | if (uid == Process.ROOT_UID && packageName == null) { |
| 8780 | // Downstream WorkSource attribution inside the RIL requires both a UID and package name |
| 8781 | // to be set for wakelock tracking, otherwise RIL requests fail with a runtime |
| 8782 | // exception. ROOT_UID seems not to have a valid package name returned by |
| 8783 | // PackageManager, so just fake it here to avoid issues when running telephony shell |
| 8784 | // commands that plumb through the RIL as root, like so: |
| 8785 | // $ adb root |
| 8786 | // $ adb shell cmd phone ... |
| 8787 | packageName = "root"; |
| 8788 | } |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 8789 | return new WorkSource(uid, packageName); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8790 | } |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8791 | |
| 8792 | /** |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 8793 | * Set SIM card power state. |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8794 | * |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8795 | * @param slotIndex SIM slot id. |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 8796 | * @param state State of SIM (power down, power up, pass through) |
| 8797 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 8798 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 8799 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8800 | * |
| 8801 | **/ |
| 8802 | @Override |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 8803 | public void setSimPowerStateForSlot(int slotIndex, int state) { |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8804 | enforceModifyPermission(); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8805 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8806 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8807 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8808 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8809 | final long identity = Binder.clearCallingIdentity(); |
| 8810 | try { |
| 8811 | if (phone != null) { |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 8812 | phone.setSimPowerState(state, null, workSource); |
| 8813 | } |
| 8814 | } finally { |
| 8815 | Binder.restoreCallingIdentity(identity); |
| 8816 | } |
| 8817 | } |
| 8818 | |
| 8819 | /** |
| 8820 | * Set SIM card power state. |
| 8821 | * |
| 8822 | * @param slotIndex SIM slot id. |
| 8823 | * @param state State of SIM (power down, power up, pass through) |
| 8824 | * @param callback callback to trigger after success or failure |
| 8825 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 8826 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 8827 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
| 8828 | * |
| 8829 | **/ |
| 8830 | @Override |
| 8831 | public void setSimPowerStateForSlotWithCallback(int slotIndex, int state, |
| 8832 | IIntegerConsumer callback) { |
| 8833 | enforceModifyPermission(); |
| 8834 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8835 | |
| 8836 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8837 | |
| 8838 | final long identity = Binder.clearCallingIdentity(); |
| 8839 | try { |
| 8840 | if (phone != null) { |
| 8841 | Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback); |
| 8842 | sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8843 | } |
| 8844 | } finally { |
| 8845 | Binder.restoreCallingIdentity(identity); |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8846 | } |
| 8847 | } |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8848 | |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 8849 | private boolean isUssdApiAllowed(int subId) { |
| 8850 | CarrierConfigManager configManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8851 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 8852 | if (configManager == null) { |
| 8853 | return false; |
| 8854 | } |
| 8855 | PersistableBundle pb = configManager.getConfigForSubId(subId); |
| 8856 | if (pb == null) { |
| 8857 | return false; |
| 8858 | } |
| 8859 | return pb.getBoolean( |
| 8860 | CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL); |
| 8861 | } |
| 8862 | |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8863 | /** |
| 8864 | * Check if phone is in emergency callback mode |
| 8865 | * @return true if phone is in emergency callback mode |
| 8866 | * @param subId sub id |
| 8867 | */ |
goneil | 9c5f487 | 2017-12-05 14:07:56 -0800 | [diff] [blame] | 8868 | @Override |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8869 | public boolean getEmergencyCallbackMode(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8870 | enforceReadPrivilegedPermission("getEmergencyCallbackMode"); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8871 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8872 | |
| 8873 | final long identity = Binder.clearCallingIdentity(); |
| 8874 | try { |
| 8875 | if (phone != null) { |
| 8876 | return phone.isInEcm(); |
| 8877 | } else { |
| 8878 | return false; |
| 8879 | } |
| 8880 | } finally { |
| 8881 | Binder.restoreCallingIdentity(identity); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8882 | } |
| 8883 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 8884 | |
| 8885 | /** |
| 8886 | * Get the current signal strength information for the given subscription. |
| 8887 | * Because this information is not updated when the device is in a low power state |
| 8888 | * it should not be relied-upon to be current. |
| 8889 | * @param subId Subscription index |
| 8890 | * @return the most recent cached signal strength info from the modem |
| 8891 | */ |
| 8892 | @Override |
| 8893 | public SignalStrength getSignalStrength(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8894 | final long identity = Binder.clearCallingIdentity(); |
| 8895 | try { |
| 8896 | Phone p = getPhone(subId); |
| 8897 | if (p == null) { |
| 8898 | return null; |
| 8899 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 8900 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8901 | return p.getSignalStrength(); |
| 8902 | } finally { |
| 8903 | Binder.restoreCallingIdentity(identity); |
| 8904 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 8905 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8906 | |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8907 | /** |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8908 | * Get the current modem radio state for the given slot. |
| 8909 | * @param slotIndex slot index. |
| 8910 | * @param callingPackage the name of the package making the call. |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8911 | * @param callingFeatureId The feature in the package. |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8912 | * @return the current radio power state from the modem |
| 8913 | */ |
| 8914 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8915 | public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8916 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8917 | if (phone != null) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8918 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(), |
| 8919 | callingPackage, callingFeatureId, "getRadioPowerState")) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8920 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 8921 | } |
| 8922 | |
| 8923 | final long identity = Binder.clearCallingIdentity(); |
| 8924 | try { |
| 8925 | return phone.getRadioPowerState(); |
| 8926 | } finally { |
| 8927 | Binder.restoreCallingIdentity(identity); |
| 8928 | } |
| 8929 | } |
| 8930 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 8931 | } |
| 8932 | |
| 8933 | /** |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8934 | * Checks if data roaming is enabled on the subscription with id {@code subId}. |
| 8935 | * |
| 8936 | * <p>Requires one of the following permissions: |
| 8937 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}, |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 8938 | * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE}, |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8939 | * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier |
| 8940 | * privileges. |
| 8941 | * |
| 8942 | * @param subId subscription id |
| 8943 | * @return {@code true} if data roaming is enabled on this subscription, otherwise return |
| 8944 | * {@code false}. |
| 8945 | */ |
| 8946 | @Override |
| 8947 | public boolean isDataRoamingEnabled(int subId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 8948 | String functionName = "isDataRoamingEnabled"; |
Shuo Qian | 093013d | 2020-08-13 15:42:55 -0700 | [diff] [blame] | 8949 | try { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 8950 | try { |
| 8951 | mApp.enforceCallingOrSelfPermission( |
| 8952 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 8953 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 8954 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 8955 | mApp.enforceCallingOrSelfPermission( |
| 8956 | permission.READ_BASIC_PHONE_STATE, functionName); |
| 8957 | } |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 8958 | } catch (SecurityException e) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 8959 | TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 8960 | mApp, subId, functionName); |
Shuo Qian | 093013d | 2020-08-13 15:42:55 -0700 | [diff] [blame] | 8961 | } |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 8962 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8963 | boolean isEnabled = false; |
| 8964 | final long identity = Binder.clearCallingIdentity(); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8965 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8966 | Phone phone = getPhone(subId); |
| 8967 | isEnabled = phone != null ? phone.getDataRoamingEnabled() : false; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8968 | } finally { |
| 8969 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8970 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8971 | return isEnabled; |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8972 | } |
| 8973 | |
| 8974 | |
| 8975 | /** |
| 8976 | * Enables/Disables the data roaming on the subscription with id {@code subId}. |
| 8977 | * |
| 8978 | * <p> Requires permission: |
| 8979 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier |
| 8980 | * privileges. |
| 8981 | * |
| 8982 | * @param subId subscription id |
| 8983 | * @param isEnabled {@code true} means enable, {@code false} means disable. |
| 8984 | */ |
| 8985 | @Override |
| 8986 | public void setDataRoamingEnabled(int subId, boolean isEnabled) { |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 8987 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8988 | mApp, subId, "setDataRoamingEnabled"); |
| 8989 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8990 | final long identity = Binder.clearCallingIdentity(); |
| 8991 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8992 | Phone phone = getPhone(subId); |
| 8993 | if (phone != null) { |
| 8994 | phone.setDataRoamingEnabled(isEnabled); |
| 8995 | } |
| 8996 | } finally { |
| 8997 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8998 | } |
| 8999 | } |
| 9000 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9001 | @Override |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 9002 | public boolean isManualNetworkSelectionAllowed(int subId) { |
tom hsu | c91afc7 | 2020-01-06 23:46:07 +0800 | [diff] [blame] | 9003 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9004 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 9005 | mApp, subId, "isManualNetworkSelectionAllowed"); |
| 9006 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 9007 | boolean isAllowed = true; |
| 9008 | final long identity = Binder.clearCallingIdentity(); |
| 9009 | try { |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 9010 | Phone phone = getPhone(subId); |
| 9011 | if (phone != null) { |
| 9012 | isAllowed = phone.isCspPlmnEnabled(); |
| 9013 | } |
| 9014 | } finally { |
| 9015 | Binder.restoreCallingIdentity(identity); |
| 9016 | } |
| 9017 | return isAllowed; |
| 9018 | } |
| 9019 | |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9020 | private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) { |
| 9021 | UiccProfile profile = port.getUiccProfile(); |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 9022 | if (profile == null) { |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9023 | return false; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9024 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 9025 | Phone phone = PhoneFactory.getPhone(profile.getPhoneId()); |
| 9026 | if (phone == null) { |
| 9027 | return false; |
| 9028 | } |
| 9029 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 9030 | return cpt != null && cpt.getCarrierPrivilegeStatusForPackage(callingPackage) |
| 9031 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9032 | } |
| 9033 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 9034 | @Override |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 9035 | public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) { |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9036 | // Verify that the callingPackage belongs to the calling UID |
Jordan Liu | 4cda455 | 2020-03-23 11:55:07 -0700 | [diff] [blame] | 9037 | mApp.getSystemService(AppOpsManager.class) |
| 9038 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 9039 | |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9040 | boolean hasReadPermission = false; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9041 | boolean isIccIdAccessRestricted = false; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 9042 | try { |
| 9043 | enforceReadPrivilegedPermission("getUiccCardsInfo"); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9044 | hasReadPermission = true; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 9045 | } catch (SecurityException e) { |
| 9046 | // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller |
| 9047 | // has carrier privileges on an active UICC |
Rambo Wang | e7209ce | 2022-02-23 13:41:02 -0800 | [diff] [blame] | 9048 | if (checkCarrierPrivilegesForPackageAnyPhoneWithPermission(callingPackage) |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 9049 | != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9050 | throw new SecurityException("Caller does not have permission."); |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 9051 | } |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 9052 | } |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9053 | // checking compatibility, if calling app's target SDK is T and beyond. |
| 9054 | if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO, |
| 9055 | Binder.getCallingUid())) { |
| 9056 | isIccIdAccessRestricted = true; |
| 9057 | } |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 9058 | final long identity = Binder.clearCallingIdentity(); |
| 9059 | try { |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 9060 | UiccController uiccController = UiccController.getInstance(); |
| 9061 | ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos(); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9062 | if (hasReadPermission) { |
| 9063 | return cardInfos; |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 9064 | } |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9065 | |
| 9066 | // Remove private info if the caller doesn't have access |
| 9067 | ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>(); |
| 9068 | for (UiccCardInfo cardInfo : cardInfos) { |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9069 | //setting the value after compatibility check |
| 9070 | cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9071 | // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo |
| 9072 | // is available |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9073 | UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex()); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9074 | if (card == null) { |
| 9075 | // assume no access if the card is unavailable |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9076 | filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo)); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9077 | continue; |
| 9078 | } |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9079 | Collection<UiccPortInfo> portInfos = cardInfo.getPorts(); |
| 9080 | if (portInfos.isEmpty()) { |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9081 | filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo)); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9082 | continue; |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9083 | } |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9084 | List<UiccPortInfo> uiccPortInfos = new ArrayList<>(); |
| 9085 | for (UiccPortInfo portInfo : portInfos) { |
| 9086 | UiccPort port = uiccController.getUiccPortForSlot( |
| 9087 | cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex()); |
| 9088 | if (port == null) { |
| 9089 | // assume no access if port is null |
| 9090 | uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo)); |
| 9091 | continue; |
| 9092 | } |
| 9093 | if (haveCarrierPrivilegeAccess(port, callingPackage)) { |
| 9094 | uiccPortInfos.add(portInfo); |
| 9095 | } else { |
| 9096 | uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo)); |
| 9097 | } |
| 9098 | } |
| 9099 | filteredInfos.add(new UiccCardInfo( |
| 9100 | cardInfo.isEuicc(), |
| 9101 | cardInfo.getCardId(), |
| 9102 | null, |
| 9103 | cardInfo.getPhysicalSlotIndex(), |
| 9104 | cardInfo.isRemovable(), |
| 9105 | cardInfo.isMultipleEnabledProfilesSupported(), |
| 9106 | uiccPortInfos)); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9107 | } |
| 9108 | return filteredInfos; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 9109 | } finally { |
| 9110 | Binder.restoreCallingIdentity(identity); |
| 9111 | } |
| 9112 | } |
| 9113 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9114 | /** |
| 9115 | * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are |
| 9116 | * generally private and require carrier privileges to view. |
| 9117 | * |
| 9118 | * @hide |
| 9119 | */ |
| 9120 | @NonNull |
| 9121 | public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) { |
| 9122 | List<UiccPortInfo> portinfo = new ArrayList<>(); |
| 9123 | for (UiccPortInfo portinfos : cardInfo.getPorts()) { |
| 9124 | portinfo.add(getUiccPortInfoUnPrivileged(portinfos)); |
| 9125 | } |
| 9126 | return new UiccCardInfo( |
| 9127 | cardInfo.isEuicc(), |
| 9128 | cardInfo.getCardId(), |
| 9129 | null, |
| 9130 | cardInfo.getPhysicalSlotIndex(), |
| 9131 | cardInfo.isRemovable(), |
| 9132 | cardInfo.isMultipleEnabledProfilesSupported(), |
| 9133 | portinfo |
| 9134 | ); |
| 9135 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9136 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9137 | /** |
| 9138 | * @hide |
| 9139 | * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}. |
| 9140 | * These values are generally private and require carrier privileges to view. |
| 9141 | */ |
| 9142 | @NonNull |
| 9143 | public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) { |
| 9144 | return new UiccPortInfo( |
| 9145 | UiccPortInfo.ICCID_REDACTED, |
| 9146 | portInfo.getPortIndex(), |
| 9147 | portInfo.getLogicalSlotIndex(), |
| 9148 | portInfo.isActive() |
| 9149 | ); |
| 9150 | } |
| 9151 | @Override |
| 9152 | public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) { |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9153 | // Verify that the callingPackage belongs to the calling UID |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9154 | mApp.getSystemService(AppOpsManager.class) |
| 9155 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 9156 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9157 | boolean isLogicalSlotAccessRestricted = false; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9158 | |
Aman Gupta | f3c90b3 | 2022-03-17 04:54:16 +0000 | [diff] [blame] | 9159 | // This will make sure caller has the READ_PRIVILEGED_PHONE_STATE. Do not remove this as |
| 9160 | // we are reading iccId which is PII data. |
| 9161 | enforceReadPrivilegedPermission("getUiccSlotsInfo"); |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9162 | |
| 9163 | // checking compatibility, if calling app's target SDK is T and beyond. |
| 9164 | if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO, |
| 9165 | Binder.getCallingUid())) { |
| 9166 | isLogicalSlotAccessRestricted = true; |
| 9167 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9168 | final long identity = Binder.clearCallingIdentity(); |
| 9169 | try { |
| 9170 | UiccSlot[] slots = UiccController.getInstance().getUiccSlots(); |
Muralidhar Reddy | d196bbf | 2022-01-17 17:56:30 +0000 | [diff] [blame] | 9171 | if (slots == null || slots.length == 0) { |
| 9172 | Rlog.i(LOG_TAG, "slots is null or empty."); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9173 | return null; |
| 9174 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9175 | UiccSlotInfo[] infos = new UiccSlotInfo[slots.length]; |
| 9176 | for (int i = 0; i < slots.length; i++) { |
| 9177 | UiccSlot slot = slots[i]; |
| 9178 | if (slot == null) { |
| 9179 | continue; |
| 9180 | } |
| 9181 | |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 9182 | String cardId; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9183 | UiccCard card = slot.getUiccCard(); |
| 9184 | if (card != null) { |
| 9185 | cardId = card.getCardId(); |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 9186 | } else { |
Jordan Liu | 01bd00d | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 9187 | cardId = slot.getEid(); |
| 9188 | if (TextUtils.isEmpty(cardId)) { |
Aman Gupta | f3c90b3 | 2022-03-17 04:54:16 +0000 | [diff] [blame] | 9189 | // If cardId is null, use iccId of default port as cardId. |
| 9190 | cardId = slot.getIccId(TelephonyManager.DEFAULT_PORT_INDEX); |
Jordan Liu | 01bd00d | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 9191 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9192 | } |
| 9193 | |
Jordan Liu | 857451f | 2019-05-09 16:35:35 -0700 | [diff] [blame] | 9194 | if (cardId != null) { |
| 9195 | // if cardId is an ICCID, strip off trailing Fs before exposing to user |
| 9196 | // if cardId is an EID, it's all digits so this is fine |
| 9197 | cardId = IccUtils.stripTrailingFs(cardId); |
| 9198 | } |
| 9199 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9200 | int cardState = 0; |
| 9201 | switch (slot.getCardState()) { |
| 9202 | case CARDSTATE_ABSENT: |
| 9203 | cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT; |
| 9204 | break; |
| 9205 | case CARDSTATE_PRESENT: |
| 9206 | cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT; |
| 9207 | break; |
| 9208 | case CARDSTATE_ERROR: |
| 9209 | cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR; |
| 9210 | break; |
| 9211 | case CARDSTATE_RESTRICTED: |
| 9212 | cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED; |
| 9213 | break; |
| 9214 | default: |
| 9215 | break; |
| 9216 | |
| 9217 | } |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9218 | List<UiccPortInfo> portInfos = new ArrayList<>(); |
| 9219 | int[] portIndexes = slot.getPortList(); |
| 9220 | for (int portIdx : portIndexes) { |
| 9221 | String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx, |
Aman Gupta | f3c90b3 | 2022-03-17 04:54:16 +0000 | [diff] [blame] | 9222 | callingPackage, /* hasReadPermission= */ true)); |
Muralidhar Reddy | fbcff0c | 2022-01-19 13:07:57 +0000 | [diff] [blame] | 9223 | portInfos.add(new UiccPortInfo(iccId, portIdx, |
| 9224 | slot.getPhoneIdFromPortIndex(portIdx), slot.isPortActive(portIdx))); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9225 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9226 | infos[i] = new UiccSlotInfo( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9227 | slot.isEuicc(), |
| 9228 | cardId, |
| 9229 | cardState, |
Jordan Liu | a261958 | 2019-02-14 12:56:40 -0800 | [diff] [blame] | 9230 | slot.isExtendedApduSupported(), |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9231 | slot.isRemovable(), portInfos); |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9232 | //setting the value after compatibility check |
| 9233 | infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9234 | } |
| 9235 | return infos; |
| 9236 | } finally { |
| 9237 | Binder.restoreCallingIdentity(identity); |
Holly Jiuyu Sun | 1d957c5 | 2018-04-04 13:52:42 -0700 | [diff] [blame] | 9238 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9239 | } |
| 9240 | |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9241 | /* Returns null if doesn't have read permission or carrier privilege access. */ |
| 9242 | private String getIccId(UiccSlot slot, int portIndex, String callingPackage, |
| 9243 | boolean hasReadPermission) { |
| 9244 | String iccId = slot.getIccId(portIndex); |
| 9245 | if (hasReadPermission) { // if has read permission |
| 9246 | return iccId; |
| 9247 | } else { |
| 9248 | if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) { |
| 9249 | UiccPort port = slot.getUiccCard().getUiccPort(portIndex); |
| 9250 | // if no read permission, checking carrier privilege access |
| 9251 | if (haveCarrierPrivilegeAccess(port, callingPackage)) { |
| 9252 | return iccId; |
| 9253 | } |
| 9254 | } |
| 9255 | } |
| 9256 | // No read permission or carrier privilege access. |
| 9257 | return UiccPortInfo.ICCID_REDACTED; |
| 9258 | } |
| 9259 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9260 | @Override |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9261 | @Deprecated |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9262 | public boolean switchSlots(int[] physicalSlots) { |
| 9263 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9264 | |
| 9265 | final long identity = Binder.clearCallingIdentity(); |
| 9266 | try { |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9267 | List<UiccSlotMapping> slotMappings = new ArrayList<>(); |
| 9268 | for (int i = 0; i < physicalSlots.length; i++) { |
| 9269 | // Deprecated API, hence MEP is not supported. Adding default portIndex 0. |
| 9270 | slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX, |
| 9271 | physicalSlots[i], i)); |
| 9272 | } |
| 9273 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9274 | } finally { |
| 9275 | Binder.restoreCallingIdentity(identity); |
| 9276 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9277 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 9278 | |
| 9279 | @Override |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9280 | @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 9281 | public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) { |
| 9282 | enforceModifyPermission(); |
| 9283 | |
| 9284 | final long identity = Binder.clearCallingIdentity(); |
| 9285 | try { |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9286 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping); |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9287 | } finally { |
| 9288 | Binder.restoreCallingIdentity(identity); |
| 9289 | } |
| 9290 | } |
| 9291 | |
| 9292 | @Override |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 9293 | public int getCardIdForDefaultEuicc(int subId, String callingPackage) { |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 9294 | final long identity = Binder.clearCallingIdentity(); |
| 9295 | try { |
| 9296 | return UiccController.getInstance().getCardIdForDefaultEuicc(); |
| 9297 | } finally { |
| 9298 | Binder.restoreCallingIdentity(identity); |
| 9299 | } |
| 9300 | } |
| 9301 | |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9302 | /** |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 9303 | * A test API to reload the UICC profile. |
| 9304 | * |
| 9305 | * <p>Requires that the calling app has permission |
| 9306 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 9307 | * @hide |
| 9308 | */ |
| 9309 | @Override |
| 9310 | public void refreshUiccProfile(int subId) { |
| 9311 | enforceModifyPermission(); |
| 9312 | |
| 9313 | final long identity = Binder.clearCallingIdentity(); |
| 9314 | try { |
| 9315 | Phone phone = getPhone(subId); |
| 9316 | if (phone == null) { |
| 9317 | return; |
| 9318 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9319 | UiccPort uiccPort = phone.getUiccPort(); |
| 9320 | if (uiccPort == null) { |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 9321 | return; |
| 9322 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9323 | UiccProfile uiccProfile = uiccPort.getUiccProfile(); |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 9324 | if (uiccProfile == null) { |
| 9325 | return; |
| 9326 | } |
| 9327 | uiccProfile.refresh(); |
| 9328 | } finally { |
| 9329 | Binder.restoreCallingIdentity(identity); |
| 9330 | } |
| 9331 | } |
| 9332 | |
| 9333 | /** |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9334 | * Returns false if the mobile data is disabled by default, otherwise return true. |
| 9335 | */ |
| 9336 | private boolean getDefaultDataEnabled() { |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 9337 | return TelephonyProperties.mobile_data().orElse(true); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9338 | } |
| 9339 | |
| 9340 | /** |
| 9341 | * Returns true if the data roaming is enabled by default, i.e the system property |
| 9342 | * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of |
| 9343 | * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true. |
| 9344 | */ |
| 9345 | private boolean getDefaultDataRoamingEnabled(int subId) { |
| 9346 | final CarrierConfigManager configMgr = (CarrierConfigManager) |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9347 | mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Shuo Qian | 1d84a0e | 2020-07-15 12:36:44 -0700 | [diff] [blame] | 9348 | boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9349 | isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean( |
| 9350 | CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL); |
| 9351 | return isDataRoamingEnabled; |
| 9352 | } |
| 9353 | |
| 9354 | /** |
| 9355 | * Returns the default network type for the given {@code subId}, if the default network type is |
| 9356 | * not set, return {@link Phone#PREFERRED_NT_MODE}. |
| 9357 | */ |
| 9358 | private int getDefaultNetworkType(int subId) { |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 9359 | List<Integer> list = TelephonyProperties.default_network(); |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 9360 | int phoneId = SubscriptionManager.getPhoneId(subId); |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 9361 | if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) { |
| 9362 | return list.get(phoneId); |
| 9363 | } |
| 9364 | return Phone.PREFERRED_NT_MODE; |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9365 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9366 | |
| 9367 | @Override |
| 9368 | public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 9369 | gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) { |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9370 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9371 | |
| 9372 | final long identity = Binder.clearCallingIdentity(); |
| 9373 | try { |
| 9374 | final Phone phone = getPhone(subId); |
| 9375 | if (phone == null) { |
| 9376 | loge("setCarrierTestOverride fails with invalid subId: " + subId); |
| 9377 | return; |
| 9378 | } |
Rambo Wang | 9c9ffdd | 2022-01-13 21:51:44 -0800 | [diff] [blame] | 9379 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 9380 | if (cpt != null) { |
| 9381 | cpt.setTestOverrideCarrierPrivilegeRules(carrierPrivilegeRules); |
| 9382 | } |
| 9383 | // 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] | 9384 | phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn, |
| 9385 | carrierPrivilegeRules, apn); |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 9386 | if (carrierPrivilegeRules == null) { |
| 9387 | mCarrierPrivilegeTestOverrideSubIds.remove(subId); |
| 9388 | } else { |
| 9389 | mCarrierPrivilegeTestOverrideSubIds.add(subId); |
| 9390 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9391 | } finally { |
| 9392 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9393 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9394 | } |
| 9395 | |
| 9396 | @Override |
| 9397 | public int getCarrierIdListVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 9398 | enforceReadPrivilegedPermission("getCarrierIdListVersion"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9399 | |
| 9400 | final long identity = Binder.clearCallingIdentity(); |
| 9401 | try { |
| 9402 | final Phone phone = getPhone(subId); |
| 9403 | if (phone == null) { |
| 9404 | loge("getCarrierIdListVersion fails with invalid subId: " + subId); |
| 9405 | return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION; |
| 9406 | } |
| 9407 | return phone.getCarrierIdListVersion(); |
| 9408 | } finally { |
| 9409 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9410 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9411 | } |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 9412 | |
| 9413 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9414 | public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage, |
| 9415 | String callingFeatureId) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 9416 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9417 | mApp, subId, callingPackage, callingFeatureId, |
| 9418 | "getNumberOfModemsWithSimultaneousDataConnections")) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 9419 | return -1; |
| 9420 | } |
| 9421 | |
| 9422 | final long identity = Binder.clearCallingIdentity(); |
| 9423 | try { |
| 9424 | return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections(); |
| 9425 | } finally { |
| 9426 | Binder.restoreCallingIdentity(identity); |
| 9427 | } |
| 9428 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9429 | |
| 9430 | @Override |
| 9431 | public int getCdmaRoamingMode(int subId) { |
zoey chen | 7e6d4e5 | 2019-12-17 18:18:59 +0800 | [diff] [blame] | 9432 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9433 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9434 | mApp, subId, "getCdmaRoamingMode"); |
| 9435 | |
| 9436 | final long identity = Binder.clearCallingIdentity(); |
| 9437 | try { |
| 9438 | return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId); |
| 9439 | } finally { |
| 9440 | Binder.restoreCallingIdentity(identity); |
| 9441 | } |
| 9442 | } |
| 9443 | |
| 9444 | @Override |
| 9445 | public boolean setCdmaRoamingMode(int subId, int mode) { |
| 9446 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9447 | mApp, subId, "setCdmaRoamingMode"); |
| 9448 | |
| 9449 | final long identity = Binder.clearCallingIdentity(); |
| 9450 | try { |
| 9451 | return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId); |
| 9452 | } finally { |
| 9453 | Binder.restoreCallingIdentity(identity); |
| 9454 | } |
| 9455 | } |
| 9456 | |
| 9457 | @Override |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 9458 | public int getCdmaSubscriptionMode(int subId) { |
| 9459 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9460 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 9461 | mApp, subId, "getCdmaSubscriptionMode"); |
| 9462 | |
| 9463 | final long identity = Binder.clearCallingIdentity(); |
| 9464 | try { |
| 9465 | return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId); |
| 9466 | } finally { |
| 9467 | Binder.restoreCallingIdentity(identity); |
| 9468 | } |
| 9469 | } |
| 9470 | |
| 9471 | @Override |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9472 | public boolean setCdmaSubscriptionMode(int subId, int mode) { |
| 9473 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9474 | mApp, subId, "setCdmaSubscriptionMode"); |
| 9475 | |
| 9476 | final long identity = Binder.clearCallingIdentity(); |
| 9477 | try { |
| 9478 | return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId); |
| 9479 | } finally { |
| 9480 | Binder.restoreCallingIdentity(identity); |
| 9481 | } |
| 9482 | } |
Makoto Onuki | da3bf79 | 2018-09-18 16:06:29 -0700 | [diff] [blame] | 9483 | |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 9484 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 9485 | public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9486 | String callingPackage, String callingFeatureId) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9487 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9488 | mApp, getDefaultSubscription(), callingPackage, callingFeatureId, |
| 9489 | "getEmergencyNumberList")) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9490 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 9491 | } |
| 9492 | final long identity = Binder.clearCallingIdentity(); |
| 9493 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 9494 | Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>(); |
| 9495 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9496 | if (phone.getEmergencyNumberTracker() != null |
| 9497 | && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) { |
| 9498 | emergencyNumberListInternal.put( |
| 9499 | phone.getSubId(), |
| 9500 | phone.getEmergencyNumberTracker().getEmergencyNumberList()); |
| 9501 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9502 | } |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 9503 | return emergencyNumberListInternal; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9504 | } finally { |
| 9505 | Binder.restoreCallingIdentity(identity); |
| 9506 | } |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 9507 | } |
| 9508 | |
| 9509 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 9510 | public boolean isEmergencyNumber(String number, boolean exactMatch) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9511 | final Phone defaultPhone = getDefaultPhone(); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9512 | if (!exactMatch) { |
| 9513 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9514 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 9515 | mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)"); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9516 | } |
| 9517 | final long identity = Binder.clearCallingIdentity(); |
| 9518 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 9519 | for (Phone phone: PhoneFactory.getPhones()) { |
Chinmay Dhodapkar | d521bb1 | 2022-08-16 15:49:54 -0700 | [diff] [blame] | 9520 | //Note: we ignore passed in param exactMatch. We can remove it once |
| 9521 | // TelephonyManager#isPotentialEmergencyNumber is removed completely |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 9522 | if (phone.getEmergencyNumberTracker() != null |
Taesu Lee | e050c00 | 2020-10-13 17:19:35 +0900 | [diff] [blame] | 9523 | && phone.getEmergencyNumberTracker() |
Chinmay Dhodapkar | d521bb1 | 2022-08-16 15:49:54 -0700 | [diff] [blame] | 9524 | .isEmergencyNumber(number)) { |
Taesu Lee | e050c00 | 2020-10-13 17:19:35 +0900 | [diff] [blame] | 9525 | return true; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9526 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9527 | } |
| 9528 | return false; |
| 9529 | } finally { |
| 9530 | Binder.restoreCallingIdentity(identity); |
| 9531 | } |
| 9532 | } |
| 9533 | |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 9534 | /** |
Shuo Qian | ccbaf74 | 2021-02-22 18:32:21 -0800 | [diff] [blame] | 9535 | * Start emergency callback mode for GsmCdmaPhone for testing. |
| 9536 | */ |
| 9537 | @Override |
| 9538 | public void startEmergencyCallbackMode() { |
| 9539 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9540 | "startEmergencyCallbackMode"); |
| 9541 | enforceModifyPermission(); |
| 9542 | final long identity = Binder.clearCallingIdentity(); |
| 9543 | try { |
| 9544 | for (Phone phone : PhoneFactory.getPhones()) { |
| 9545 | Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType()); |
| 9546 | if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM) |
| 9547 | || (phone.getPhoneType() == PHONE_TYPE_CDMA))) { |
| 9548 | GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone; |
| 9549 | gsmCdmaPhone.obtainMessage( |
| 9550 | GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget(); |
| 9551 | Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered"); |
| 9552 | } |
| 9553 | } |
| 9554 | } finally { |
| 9555 | Binder.restoreCallingIdentity(identity); |
| 9556 | } |
| 9557 | } |
| 9558 | |
| 9559 | /** |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 9560 | * Update emergency number list for test mode. |
| 9561 | */ |
| 9562 | @Override |
| 9563 | public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) { |
| 9564 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9565 | "updateEmergencyNumberListTestMode"); |
| 9566 | |
| 9567 | final long identity = Binder.clearCallingIdentity(); |
| 9568 | try { |
| 9569 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9570 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9571 | if (tracker != null) { |
| 9572 | tracker.executeEmergencyNumberTestModeCommand(action, num); |
| 9573 | } |
| 9574 | } |
| 9575 | } finally { |
| 9576 | Binder.restoreCallingIdentity(identity); |
| 9577 | } |
| 9578 | } |
| 9579 | |
| 9580 | /** |
| 9581 | * Get the full emergency number list for test mode. |
| 9582 | */ |
| 9583 | @Override |
| 9584 | public List<String> getEmergencyNumberListTestMode() { |
| 9585 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9586 | "getEmergencyNumberListTestMode"); |
| 9587 | |
| 9588 | final long identity = Binder.clearCallingIdentity(); |
| 9589 | try { |
| 9590 | Set<String> emergencyNumbers = new HashSet<>(); |
| 9591 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9592 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9593 | if (tracker != null) { |
| 9594 | for (EmergencyNumber num : tracker.getEmergencyNumberList()) { |
| 9595 | emergencyNumbers.add(num.getNumber()); |
| 9596 | } |
| 9597 | } |
| 9598 | } |
| 9599 | return new ArrayList<>(emergencyNumbers); |
| 9600 | } finally { |
| 9601 | Binder.restoreCallingIdentity(identity); |
| 9602 | } |
| 9603 | } |
| 9604 | |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 9605 | @Override |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 9606 | public int getEmergencyNumberDbVersion(int subId) { |
| 9607 | enforceReadPrivilegedPermission("getEmergencyNumberDbVersion"); |
| 9608 | |
| 9609 | final long identity = Binder.clearCallingIdentity(); |
| 9610 | try { |
| 9611 | final Phone phone = getPhone(subId); |
| 9612 | if (phone == null) { |
| 9613 | loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId); |
| 9614 | return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION; |
| 9615 | } |
| 9616 | return phone.getEmergencyNumberDbVersion(); |
| 9617 | } finally { |
| 9618 | Binder.restoreCallingIdentity(identity); |
| 9619 | } |
| 9620 | } |
| 9621 | |
| 9622 | @Override |
| 9623 | public void notifyOtaEmergencyNumberDbInstalled() { |
| 9624 | enforceModifyPermission(); |
| 9625 | |
| 9626 | final long identity = Binder.clearCallingIdentity(); |
| 9627 | try { |
| 9628 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9629 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9630 | if (tracker != null) { |
| 9631 | tracker.updateOtaEmergencyNumberDatabase(); |
| 9632 | } |
| 9633 | } |
| 9634 | } finally { |
| 9635 | Binder.restoreCallingIdentity(identity); |
| 9636 | } |
| 9637 | } |
| 9638 | |
| 9639 | @Override |
Shuo Qian | c373f11 | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 9640 | public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) { |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 9641 | enforceActiveEmergencySessionPermission(); |
| 9642 | |
| 9643 | final long identity = Binder.clearCallingIdentity(); |
| 9644 | try { |
| 9645 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9646 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9647 | if (tracker != null) { |
Shuo Qian | c373f11 | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 9648 | tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor); |
| 9649 | } |
| 9650 | } |
| 9651 | } finally { |
| 9652 | Binder.restoreCallingIdentity(identity); |
| 9653 | } |
| 9654 | } |
| 9655 | |
| 9656 | @Override |
| 9657 | public void resetOtaEmergencyNumberDbFilePath() { |
| 9658 | enforceActiveEmergencySessionPermission(); |
| 9659 | |
| 9660 | final long identity = Binder.clearCallingIdentity(); |
| 9661 | try { |
| 9662 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9663 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9664 | if (tracker != null) { |
| 9665 | tracker.resetOtaEmergencyNumberDbFilePath(); |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 9666 | } |
| 9667 | } |
| 9668 | } finally { |
| 9669 | Binder.restoreCallingIdentity(identity); |
| 9670 | } |
| 9671 | } |
| 9672 | |
| 9673 | @Override |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 9674 | public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) { |
| 9675 | enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules"); |
| 9676 | Phone phone = getPhone(subId); |
| 9677 | if (phone == null) { |
| 9678 | return null; |
| 9679 | } |
| 9680 | final long identity = Binder.clearCallingIdentity(); |
| 9681 | try { |
| 9682 | UiccProfile profile = UiccController.getInstance() |
| 9683 | .getUiccProfileForPhone(phone.getPhoneId()); |
| 9684 | if (profile != null) { |
| 9685 | return profile.getCertsFromCarrierPrivilegeAccessRules(); |
| 9686 | } |
| 9687 | } finally { |
| 9688 | Binder.restoreCallingIdentity(identity); |
| 9689 | } |
| 9690 | return null; |
| 9691 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 9692 | |
| 9693 | /** |
| 9694 | * Enable or disable a modem stack. |
| 9695 | */ |
| 9696 | @Override |
| 9697 | public boolean enableModemForSlot(int slotIndex, boolean enable) { |
| 9698 | enforceModifyPermission(); |
| 9699 | |
| 9700 | final long identity = Binder.clearCallingIdentity(); |
| 9701 | try { |
| 9702 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 9703 | if (phone == null) { |
| 9704 | return false; |
| 9705 | } else { |
| 9706 | return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null); |
| 9707 | } |
| 9708 | } finally { |
| 9709 | Binder.restoreCallingIdentity(identity); |
| 9710 | } |
| 9711 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9712 | |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 9713 | /** |
| 9714 | * Whether a modem stack is enabled or not. |
| 9715 | */ |
| 9716 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9717 | public boolean isModemEnabledForSlot(int slotIndex, String callingPackage, |
| 9718 | String callingFeatureId) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 9719 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 9720 | if (phone == null) return false; |
| 9721 | |
| 9722 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9723 | mApp, phone.getSubId(), callingPackage, callingFeatureId, |
| 9724 | "isModemEnabledForSlot")) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 9725 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 9726 | } |
| 9727 | |
| 9728 | final long identity = Binder.clearCallingIdentity(); |
| 9729 | try { |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 9730 | try { |
| 9731 | return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId()); |
| 9732 | } catch (NoSuchElementException ex) { |
| 9733 | return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null); |
| 9734 | } |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 9735 | } finally { |
| 9736 | Binder.restoreCallingIdentity(identity); |
| 9737 | } |
| 9738 | } |
| 9739 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9740 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9741 | public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) { |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9742 | enforceModifyPermission(); |
| 9743 | |
| 9744 | final long identity = Binder.clearCallingIdentity(); |
| 9745 | try { |
| 9746 | mTelephonySharedPreferences.edit() |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9747 | .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted) |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9748 | .commit(); |
| 9749 | } finally { |
| 9750 | Binder.restoreCallingIdentity(identity); |
| 9751 | } |
| 9752 | } |
| 9753 | |
| 9754 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9755 | @TelephonyManager.IsMultiSimSupportedResult |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9756 | public int isMultiSimSupported(String callingPackage, String callingFeatureId) { |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 9757 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9758 | getDefaultPhone().getSubId(), callingPackage, callingFeatureId, |
| 9759 | "isMultiSimSupported")) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9760 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 9761 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9762 | |
| 9763 | final long identity = Binder.clearCallingIdentity(); |
| 9764 | try { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9765 | return isMultiSimSupportedInternal(); |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9766 | } finally { |
| 9767 | Binder.restoreCallingIdentity(identity); |
| 9768 | } |
| 9769 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9770 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9771 | @TelephonyManager.IsMultiSimSupportedResult |
| 9772 | private int isMultiSimSupportedInternal() { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9773 | // If the device has less than 2 SIM cards, indicate that multisim is restricted. |
| 9774 | int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length; |
| 9775 | if (numPhysicalSlots < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9776 | loge("isMultiSimSupportedInternal: requires at least 2 cards"); |
| 9777 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9778 | } |
| 9779 | // Check if the hardware supports multisim functionality. If usage of multisim is not |
| 9780 | // supported by the modem, indicate that it is restricted. |
| 9781 | PhoneCapability staticCapability = |
| 9782 | mPhoneConfigurationManager.getStaticPhoneCapability(); |
| 9783 | if (staticCapability == null) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9784 | loge("isMultiSimSupportedInternal: no static configuration available"); |
| 9785 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9786 | } |
SongFerngWang | 8236caa | 2021-01-17 21:51:44 +0800 | [diff] [blame] | 9787 | if (staticCapability.getLogicalModemList().size() < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9788 | loge("isMultiSimSupportedInternal: maximum number of modem is < 2"); |
| 9789 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9790 | } |
| 9791 | // Check if support of multiple SIMs is restricted by carrier |
| 9792 | if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9793 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9794 | } |
| 9795 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9796 | return TelephonyManager.MULTISIM_ALLOWED; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9797 | } |
| 9798 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9799 | /** |
| 9800 | * Switch configs to enable multi-sim or switch back to single-sim |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 9801 | * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE |
| 9802 | * permission, but the other way around is possible with either MODIFY_PHONE_STATE |
| 9803 | * or carrier privileges |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9804 | * @param numOfSims number of active sims we want to switch to |
| 9805 | */ |
| 9806 | @Override |
| 9807 | public void switchMultiSimConfig(int numOfSims) { |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 9808 | if (numOfSims == 1) { |
| 9809 | enforceModifyPermission(); |
| 9810 | } else { |
| 9811 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9812 | mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig"); |
| 9813 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9814 | final long identity = Binder.clearCallingIdentity(); |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9815 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9816 | try { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9817 | //only proceed if multi-sim is not restricted |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9818 | if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9819 | loge("switchMultiSimConfig not possible. It is restricted or not supported."); |
| 9820 | return; |
| 9821 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9822 | mPhoneConfigurationManager.switchMultiSimConfig(numOfSims); |
| 9823 | } finally { |
| 9824 | Binder.restoreCallingIdentity(identity); |
| 9825 | } |
| 9826 | } |
| 9827 | |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 9828 | @Override |
| 9829 | public boolean isApplicationOnUicc(int subId, int appType) { |
| 9830 | enforceReadPrivilegedPermission("isApplicationOnUicc"); |
| 9831 | Phone phone = getPhone(subId); |
| 9832 | if (phone == null) { |
| 9833 | return false; |
| 9834 | } |
| 9835 | final long identity = Binder.clearCallingIdentity(); |
| 9836 | try { |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9837 | UiccPort uiccPort = phone.getUiccPort(); |
| 9838 | if (uiccPort == null) { |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 9839 | return false; |
| 9840 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9841 | UiccProfile uiccProfile = uiccPort.getUiccProfile(); |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 9842 | if (uiccProfile == null) { |
| 9843 | return false; |
| 9844 | } |
| 9845 | if (TelephonyManager.APPTYPE_SIM <= appType |
| 9846 | && appType <= TelephonyManager.APPTYPE_ISIM) { |
| 9847 | return uiccProfile.isApplicationOnIcc(AppType.values()[appType]); |
| 9848 | } |
| 9849 | return false; |
| 9850 | } finally { |
| 9851 | Binder.restoreCallingIdentity(identity); |
| 9852 | } |
| 9853 | } |
| 9854 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9855 | /** |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 9856 | * Get whether making changes to modem configurations will trigger reboot. |
| 9857 | * Return value defaults to true. |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 9858 | */ |
| 9859 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9860 | public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage, |
| 9861 | String callingFeatureId) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 9862 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9863 | mApp, subId, callingPackage, callingFeatureId, |
| 9864 | "doesSwitchMultiSimConfigTriggerReboot")) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 9865 | return false; |
| 9866 | } |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 9867 | final long identity = Binder.clearCallingIdentity(); |
| 9868 | try { |
| 9869 | return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange(); |
| 9870 | } finally { |
| 9871 | Binder.restoreCallingIdentity(identity); |
| 9872 | } |
| 9873 | } |
| 9874 | |
Nathan Harold | 29f5f05 | 2019-02-15 13:41:57 -0800 | [diff] [blame] | 9875 | private void updateModemStateMetrics() { |
| 9876 | TelephonyMetrics metrics = TelephonyMetrics.getInstance(); |
| 9877 | // TODO: check the state for each modem if the api is ready. |
| 9878 | metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1); |
| 9879 | } |
| 9880 | |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 9881 | @Override |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9882 | public List<UiccSlotMapping> getSlotsMapping(String callingPackage) { |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 9883 | enforceReadPrivilegedPermission("getSlotsMapping"); |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9884 | // Verify that the callingPackage belongs to the calling UID |
| 9885 | mApp.getSystemService(AppOpsManager.class) |
| 9886 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 9887 | final long identity = Binder.clearCallingIdentity(); |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9888 | List<UiccSlotMapping> slotMap = new ArrayList<>(); |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 9889 | try { |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9890 | UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName()); |
| 9891 | if (slotInfos != null) { |
| 9892 | for (int i = 0; i < slotInfos.length; i++) { |
| 9893 | for (UiccPortInfo portInfo : slotInfos[i].getPorts()) { |
| 9894 | if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) { |
| 9895 | slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i, |
| 9896 | portInfo.getLogicalSlotIndex())); |
| 9897 | } |
| 9898 | } |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 9899 | } |
| 9900 | } |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9901 | return slotMap; |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 9902 | } finally { |
| 9903 | Binder.restoreCallingIdentity(identity); |
| 9904 | } |
| 9905 | } |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 9906 | |
| 9907 | /** |
| 9908 | * Get the IRadio HAL Version |
jimsun | f9ec162 | 2022-09-13 21:18:43 +0800 | [diff] [blame] | 9909 | * @deprecated use getHalVersion instead |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 9910 | */ |
jimsun | f9ec162 | 2022-09-13 21:18:43 +0800 | [diff] [blame] | 9911 | @Deprecated |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 9912 | @Override |
| 9913 | public int getRadioHalVersion() { |
jimsun | f9ec162 | 2022-09-13 21:18:43 +0800 | [diff] [blame] | 9914 | return getHalVersion(HAL_SERVICE_RADIO); |
| 9915 | } |
| 9916 | |
| 9917 | /** |
| 9918 | * Get the HAL Version of a specific service |
| 9919 | */ |
| 9920 | @Override |
| 9921 | public int getHalVersion(int service) { |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 9922 | Phone phone = getDefaultPhone(); |
| 9923 | if (phone == null) return -1; |
jimsun | f9ec162 | 2022-09-13 21:18:43 +0800 | [diff] [blame] | 9924 | HalVersion hv = phone.getHalVersion(service); |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 9925 | if (hv.equals(HalVersion.UNKNOWN)) return -1; |
| 9926 | return hv.major * 100 + hv.minor; |
| 9927 | } |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9928 | |
| 9929 | /** |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 9930 | * Get the current calling package name. |
| 9931 | * @return the current calling package name |
| 9932 | */ |
| 9933 | @Override |
| 9934 | public String getCurrentPackageName() { |
| 9935 | return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0]; |
| 9936 | } |
| 9937 | |
| 9938 | /** |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9939 | * Return whether data is enabled for certain APN type. This will tell if framework will accept |
| 9940 | * corresponding network requests on a subId. |
| 9941 | * |
| 9942 | * Data is enabled if: |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9943 | * 1) user data is turned on, or |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9944 | * 2) APN is un-metered for this subscription, or |
| 9945 | * 3) APN type is whitelisted. E.g. MMS is whitelisted if |
Hall Liu | 746e03c | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 9946 | * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled. |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9947 | * |
| 9948 | * @return whether data is allowed for a apn type. |
| 9949 | * |
| 9950 | * @hide |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9951 | */ |
| 9952 | @Override |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9953 | public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) { |
Amit Mahajan | 5d4e192 | 2019-10-07 16:20:43 -0700 | [diff] [blame] | 9954 | enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for " |
| 9955 | + "isDataEnabledForApn"); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9956 | |
| 9957 | // Now that all security checks passes, perform the operation as ourselves. |
| 9958 | final long identity = Binder.clearCallingIdentity(); |
| 9959 | try { |
| 9960 | Phone phone = getPhone(subId); |
| 9961 | if (phone == null) return false; |
| 9962 | |
Jack Yu | 27422a5 | 2022-03-21 10:38:05 -0700 | [diff] [blame] | 9963 | boolean isMetered; |
Jack Yu | 99e8733 | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 9964 | boolean isDataEnabled; |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 9965 | isMetered = phone.getDataNetworkController().getDataConfigManager() |
| 9966 | .isMeteredCapability(DataUtils.apnTypeToNetworkCapability(apnType), |
| 9967 | phone.getServiceState().getDataRoaming()); |
| 9968 | isDataEnabled = phone.getDataSettingsManager().isDataEnabled(apnType); |
Jack Yu | 99e8733 | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 9969 | return !isMetered || isDataEnabled; |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9970 | } finally { |
| 9971 | Binder.restoreCallingIdentity(identity); |
| 9972 | } |
| 9973 | } |
| 9974 | |
| 9975 | @Override |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 9976 | public boolean isApnMetered(@ApnType int apnType, int subId) { |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9977 | enforceReadPrivilegedPermission("isApnMetered"); |
| 9978 | |
| 9979 | // Now that all security checks passes, perform the operation as ourselves. |
| 9980 | final long identity = Binder.clearCallingIdentity(); |
| 9981 | try { |
| 9982 | Phone phone = getPhone(subId); |
| 9983 | if (phone == null) return true; // By default return true. |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 9984 | return phone.getDataNetworkController().getDataConfigManager().isMeteredCapability( |
| 9985 | DataUtils.apnTypeToNetworkCapability(apnType), |
| 9986 | phone.getServiceState().getDataRoaming()); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9987 | } finally { |
| 9988 | Binder.restoreCallingIdentity(identity); |
| 9989 | } |
| 9990 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 9991 | |
| 9992 | @Override |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 9993 | public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers, |
| 9994 | int subscriptionId, IBooleanConsumer resultCallback) { |
| 9995 | enforceModifyPermission(); |
| 9996 | long token = Binder.clearCallingIdentity(); |
| 9997 | try { |
| 9998 | Phone phone = getPhone(subscriptionId); |
| 9999 | if (phone == null) { |
| 10000 | try { |
| 10001 | if (resultCallback != null) { |
| 10002 | resultCallback.accept(false); |
| 10003 | } |
| 10004 | } catch (RemoteException e) { |
| 10005 | // ignore |
| 10006 | } |
| 10007 | return; |
| 10008 | } |
| 10009 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument = |
| 10010 | Pair.create(specifiers, (x) -> { |
| 10011 | try { |
| 10012 | if (resultCallback != null) { |
| 10013 | resultCallback.accept(x); |
| 10014 | } |
| 10015 | } catch (RemoteException e) { |
| 10016 | // ignore |
| 10017 | } |
| 10018 | }); |
| 10019 | sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null); |
| 10020 | } finally { |
| 10021 | Binder.restoreCallingIdentity(token); |
| 10022 | } |
| 10023 | } |
| 10024 | |
| 10025 | @Override |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 10026 | public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) { |
| 10027 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 10028 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 10029 | mApp, subId, "getSystemSelectionChannels"); |
| 10030 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 10031 | final long identity = Binder.clearCallingIdentity(); |
| 10032 | try { |
Sarah Chin | 428d1d6 | 2021-03-13 03:17:40 -0800 | [diff] [blame] | 10033 | Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource); |
| 10034 | if (result instanceof IllegalStateException) { |
| 10035 | throw (IllegalStateException) result; |
| 10036 | } |
| 10037 | List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 10038 | if (DBG) log("getSystemSelectionChannels: " + specifiers); |
| 10039 | return specifiers; |
| 10040 | } finally { |
| 10041 | Binder.restoreCallingIdentity(identity); |
| 10042 | } |
| 10043 | } |
| 10044 | |
| 10045 | @Override |
Jack Yu | 8b766fc | 2022-03-21 09:42:33 -0700 | [diff] [blame] | 10046 | public boolean isMvnoMatched(int slotIndex, int mvnoType, @NonNull String mvnoMatchData) { |
changbetty | ca3d40d | 2020-03-03 16:27:31 +0800 | [diff] [blame] | 10047 | enforceReadPrivilegedPermission("isMvnoMatched"); |
Jack Yu | 8b766fc | 2022-03-21 09:42:33 -0700 | [diff] [blame] | 10048 | return UiccController.getInstance().mvnoMatches(slotIndex, mvnoType, mvnoMatchData); |
changbetty | 7157e9e | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 10049 | } |
| 10050 | |
| 10051 | @Override |
Philip P. Moltmann | d02b737 | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 10052 | public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag, |
| 10053 | IIntegerConsumer pendingSubIdResult) { |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 10054 | if (callingPackage == null) { |
| 10055 | callingPackage = getCurrentPackageName(); |
| 10056 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 10057 | SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp, |
| 10058 | (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE)); |
Philip P. Moltmann | d02b737 | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 10059 | if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag, |
| 10060 | "Sending message")) { |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 10061 | throw new SecurityException("Requires SEND_SMS permission to perform this operation"); |
| 10062 | } |
| 10063 | PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult); |
| 10064 | Intent intent = new Intent(); |
| 10065 | intent.setClass(mApp, PickSmsSubscriptionActivity.class); |
| 10066 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 10067 | // Bring up choose default SMS subscription dialog right now |
| 10068 | intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY, |
| 10069 | PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE); |
| 10070 | mApp.startActivity(intent); |
| 10071 | } |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 10072 | |
| 10073 | @Override |
| 10074 | public String getMmsUAProfUrl(int subId) { |
| 10075 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 10076 | final long identity = Binder.clearCallingIdentity(); |
| 10077 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 10078 | String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString( |
| 10079 | CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING); |
| 10080 | if (!TextUtils.isEmpty(carrierUAProfUrl)) { |
| 10081 | return carrierUAProfUrl; |
| 10082 | } |
Daniel Bright | ebb4eb7 | 2020-02-18 15:16:33 -0800 | [diff] [blame] | 10083 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 10084 | .getString(com.android.internal.R.string.config_mms_user_agent_profile_url); |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 10085 | } finally { |
| 10086 | Binder.restoreCallingIdentity(identity); |
| 10087 | } |
| 10088 | } |
| 10089 | |
| 10090 | @Override |
| 10091 | public String getMmsUserAgent(int subId) { |
| 10092 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 10093 | final long identity = Binder.clearCallingIdentity(); |
| 10094 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 10095 | String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString( |
| 10096 | CarrierConfigManager.KEY_MMS_USER_AGENT_STRING); |
| 10097 | if (!TextUtils.isEmpty(carrierUserAgent)) { |
| 10098 | return carrierUserAgent; |
| 10099 | } |
Daniel Bright | ebb4eb7 | 2020-02-18 15:16:33 -0800 | [diff] [blame] | 10100 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 10101 | .getString(com.android.internal.R.string.config_mms_user_agent); |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 10102 | } finally { |
| 10103 | Binder.restoreCallingIdentity(identity); |
| 10104 | } |
| 10105 | } |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 10106 | |
| 10107 | @Override |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 10108 | public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) { |
| 10109 | enforceReadPrivilegedPermission("isMobileDataPolicyEnabled"); |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 10110 | |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 10111 | final long identity = Binder.clearCallingIdentity(); |
| 10112 | try { |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 10113 | Phone phone = getPhone(subscriptionId); |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 10114 | if (phone == null) return false; |
| 10115 | |
Ling Ma | f188d50 | 2022-09-16 15:22:36 -0700 | [diff] [blame] | 10116 | return phone.getDataSettingsManager().isMobileDataPolicyEnabled(policy); |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 10117 | } finally { |
| 10118 | Binder.restoreCallingIdentity(identity); |
| 10119 | } |
| 10120 | } |
| 10121 | |
| 10122 | @Override |
Hall Liu | c66bb11 | 2021-02-02 12:09:32 -0800 | [diff] [blame] | 10123 | public void setMobileDataPolicyEnabled(int subscriptionId, int policy, |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 10124 | boolean enabled) { |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 10125 | enforceModifyPermission(); |
| 10126 | |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 10127 | final long identity = Binder.clearCallingIdentity(); |
| 10128 | try { |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 10129 | Phone phone = getPhone(subscriptionId); |
| 10130 | if (phone == null) return; |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 10131 | |
Ling Ma | f188d50 | 2022-09-16 15:22:36 -0700 | [diff] [blame] | 10132 | phone.getDataSettingsManager().setMobileDataPolicy(policy, enabled); |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 10133 | } finally { |
| 10134 | Binder.restoreCallingIdentity(identity); |
| 10135 | } |
| 10136 | } |
| 10137 | |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 10138 | /** |
Hall Liu | 746e03c | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 10139 | * Updates whether conference event package handling is enabled. |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 10140 | * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false} |
| 10141 | * otherwise. |
| 10142 | */ |
| 10143 | @Override |
| 10144 | public void setCepEnabled(boolean isCepEnabled) { |
| 10145 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled"); |
| 10146 | |
| 10147 | final long identity = Binder.clearCallingIdentity(); |
| 10148 | try { |
| 10149 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled); |
| 10150 | for (Phone phone : PhoneFactory.getPhones()) { |
| 10151 | Phone defaultPhone = phone.getImsPhone(); |
| 10152 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 10153 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 10154 | ImsPhoneCallTracker imsPhoneCallTracker = |
| 10155 | (ImsPhoneCallTracker) imsPhone.getCallTracker(); |
| 10156 | imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled); |
| 10157 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone " |
| 10158 | + imsPhone.getMsisdn()); |
| 10159 | } |
| 10160 | } |
| 10161 | } finally { |
| 10162 | Binder.restoreCallingIdentity(identity); |
| 10163 | } |
| 10164 | } |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 10165 | |
| 10166 | /** |
| 10167 | * Notify that an RCS autoconfiguration XML file has been received for provisioning. |
| 10168 | * |
| 10169 | * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed. |
| 10170 | * @param isCompressed The XML file is compressed in gzip format and must be decompressed |
| 10171 | * before being read. |
| 10172 | */ |
| 10173 | @Override |
| 10174 | public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean |
| 10175 | isCompressed) { |
| 10176 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 10177 | mApp, subId, "notifyRcsAutoConfigurationReceived"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10178 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10179 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10180 | } |
| 10181 | if (!isImsAvailableOnDevice()) { |
| 10182 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 10183 | "IMS not available on device."); |
| 10184 | } |
| 10185 | |
| 10186 | final long identity = Binder.clearCallingIdentity(); |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 10187 | try { |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10188 | RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed); |
| 10189 | } finally { |
| 10190 | Binder.restoreCallingIdentity(identity); |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 10191 | } |
| 10192 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 10193 | |
| 10194 | @Override |
| 10195 | public boolean isIccLockEnabled(int subId) { |
| 10196 | enforceReadPrivilegedPermission("isIccLockEnabled"); |
| 10197 | |
| 10198 | // Now that all security checks passes, perform the operation as ourselves. |
| 10199 | final long identity = Binder.clearCallingIdentity(); |
| 10200 | try { |
| 10201 | Phone phone = getPhone(subId); |
| 10202 | if (phone != null && phone.getIccCard() != null) { |
| 10203 | return phone.getIccCard().getIccLockEnabled(); |
| 10204 | } else { |
| 10205 | return false; |
| 10206 | } |
| 10207 | } finally { |
| 10208 | Binder.restoreCallingIdentity(identity); |
| 10209 | } |
| 10210 | } |
| 10211 | |
| 10212 | /** |
| 10213 | * Set the ICC pin lock enabled or disabled. |
| 10214 | * |
| 10215 | * @return an integer representing the status of IccLock enabled or disabled in the following |
| 10216 | * three cases: |
| 10217 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock |
| 10218 | * successfully. |
| 10219 | * - Positive number and zero for remaining password attempts. |
| 10220 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
| 10221 | * |
| 10222 | */ |
| 10223 | @Override |
| 10224 | public int setIccLockEnabled(int subId, boolean enabled, String password) { |
| 10225 | enforceModifyPermission(); |
| 10226 | |
| 10227 | Phone phone = getPhone(subId); |
| 10228 | if (phone == null) { |
| 10229 | return 0; |
| 10230 | } |
| 10231 | // Now that all security checks passes, perform the operation as ourselves. |
| 10232 | final long identity = Binder.clearCallingIdentity(); |
| 10233 | try { |
| 10234 | int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED, |
| 10235 | new Pair<Boolean, String>(enabled, password), phone, null); |
| 10236 | return attemptsRemaining; |
| 10237 | |
| 10238 | } catch (Exception e) { |
| 10239 | Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e); |
| 10240 | } finally { |
| 10241 | Binder.restoreCallingIdentity(identity); |
| 10242 | } |
| 10243 | return 0; |
| 10244 | } |
| 10245 | |
| 10246 | /** |
| 10247 | * Change the ICC password used in ICC pin lock. |
| 10248 | * |
| 10249 | * @return an integer representing the status of IccLock changed in the following three cases: |
| 10250 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully. |
| 10251 | * - Positive number and zero for remaining password attempts. |
| 10252 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
| 10253 | * |
| 10254 | */ |
| 10255 | @Override |
| 10256 | public int changeIccLockPassword(int subId, String oldPassword, String newPassword) { |
| 10257 | enforceModifyPermission(); |
| 10258 | |
| 10259 | Phone phone = getPhone(subId); |
| 10260 | if (phone == null) { |
| 10261 | return 0; |
| 10262 | } |
| 10263 | // Now that all security checks passes, perform the operation as ourselves. |
| 10264 | final long identity = Binder.clearCallingIdentity(); |
| 10265 | try { |
| 10266 | int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD, |
| 10267 | new Pair<String, String>(oldPassword, newPassword), phone, null); |
| 10268 | return attemptsRemaining; |
| 10269 | |
| 10270 | } catch (Exception e) { |
| 10271 | Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e); |
| 10272 | } finally { |
| 10273 | Binder.restoreCallingIdentity(identity); |
| 10274 | } |
| 10275 | return 0; |
| 10276 | } |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 10277 | |
| 10278 | /** |
| 10279 | * Request for receiving user activity notification |
| 10280 | */ |
| 10281 | @Override |
| 10282 | public void requestUserActivityNotification() { |
| 10283 | if (!mNotifyUserActivity.get() |
| 10284 | && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) { |
| 10285 | mNotifyUserActivity.set(true); |
| 10286 | } |
| 10287 | } |
| 10288 | |
| 10289 | /** |
| 10290 | * Called when userActivity is signalled in the power manager. |
| 10291 | * This is safe to call from any thread, with any window manager locks held or not. |
| 10292 | */ |
| 10293 | @Override |
| 10294 | public void userActivity() { |
| 10295 | // *************************************** |
| 10296 | // * Inherited from PhoneWindowManager * |
| 10297 | // *************************************** |
| 10298 | // THIS IS CALLED FROM DEEP IN THE POWER MANAGER |
| 10299 | // WITH ITS LOCKS HELD. |
| 10300 | // |
| 10301 | // This code must be VERY careful about the locks |
| 10302 | // it acquires. |
| 10303 | // In fact, the current code acquires way too many, |
| 10304 | // and probably has lurking deadlocks. |
| 10305 | |
| 10306 | if (Binder.getCallingUid() != Process.SYSTEM_UID) { |
| 10307 | throw new SecurityException("Only the OS may call notifyUserActivity()"); |
| 10308 | } |
| 10309 | |
| 10310 | if (mNotifyUserActivity.getAndSet(false)) { |
| 10311 | mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY, |
| 10312 | USER_ACTIVITY_NOTIFICATION_DELAY); |
| 10313 | } |
| 10314 | } |
Malcolm Chen | 4639c56 | 2020-04-13 11:59:40 -0700 | [diff] [blame] | 10315 | |
| 10316 | @Override |
| 10317 | public boolean canConnectTo5GInDsdsMode() { |
| 10318 | return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode); |
| 10319 | } |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 10320 | |
| 10321 | @Override |
| 10322 | public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage, |
| 10323 | String callingFeatureId) { |
| 10324 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 10325 | mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) { |
| 10326 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 10327 | } |
| 10328 | |
| 10329 | Phone phone = getPhone(subId); |
| 10330 | if (phone == null) { |
| 10331 | throw new RuntimeException("phone is not available"); |
| 10332 | } |
| 10333 | // Now that all security checks passes, perform the operation as ourselves. |
| 10334 | final long identity = Binder.clearCallingIdentity(); |
| 10335 | try { |
| 10336 | return phone.getEquivalentHomePlmns(); |
| 10337 | } finally { |
| 10338 | Binder.restoreCallingIdentity(identity); |
| 10339 | } |
| 10340 | } |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 10341 | |
| 10342 | @Override |
| 10343 | public boolean isRadioInterfaceCapabilitySupported( |
Daniel Bright | 95a4c1f | 2021-02-11 09:57:16 -0800 | [diff] [blame] | 10344 | final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) { |
| 10345 | Set<String> radioInterfaceCapabilities = |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 10346 | mRadioInterfaceCapabilities.getCapabilities(); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 10347 | if (radioInterfaceCapabilities == null) { |
| 10348 | throw new RuntimeException("radio interface capabilities are not available"); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 10349 | } |
Daniel Bright | 95a4c1f | 2021-02-11 09:57:16 -0800 | [diff] [blame] | 10350 | return radioInterfaceCapabilities.contains(capability); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 10351 | } |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10352 | |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 10353 | @Override |
| 10354 | public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl, |
| 10355 | UaSecurityProtocolIdentifier securityProtocol, |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10356 | boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) { |
| 10357 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 10358 | Binder.getCallingUid(), "bootstrapAuthenticationRequest", |
| 10359 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 10360 | Manifest.permission.MODIFY_PHONE_STATE); |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 10361 | if (DBG) { |
| 10362 | log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:" |
| 10363 | + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol |
| 10364 | + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback); |
| 10365 | } |
| 10366 | |
| 10367 | if (!SubscriptionManager.isValidSubscriptionId(subId) |
| 10368 | || appType < TelephonyManager.APPTYPE_UNKNOWN |
| 10369 | || appType > TelephonyManager.APPTYPE_ISIM |
| 10370 | || nafUrl == null || securityProtocol == null || callback == null) { |
| 10371 | Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters"); |
| 10372 | if (callback != null) { |
| 10373 | try { |
| 10374 | callback.onAuthenticationFailure( |
| 10375 | 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED); |
| 10376 | } catch (RemoteException exception) { |
| 10377 | log("Fail to notify onAuthenticationFailure due to " + exception); |
| 10378 | } |
| 10379 | return; |
| 10380 | } |
| 10381 | } |
| 10382 | |
| 10383 | final long token = Binder.clearCallingIdentity(); |
| 10384 | try { |
| 10385 | getGbaManager(subId).bootstrapAuthenticationRequest( |
| 10386 | new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(), |
| 10387 | forceBootStrapping, callback)); |
| 10388 | } finally { |
| 10389 | Binder.restoreCallingIdentity(token); |
| 10390 | } |
| 10391 | } |
| 10392 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10393 | /** |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10394 | * Attempts to set the radio power state for all phones for thermal reason. |
| 10395 | * This does not guarantee that the |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10396 | * requested radio power state will actually be set. See {@link |
| 10397 | * PhoneInternalInterface#setRadioPowerForReason} for more details. |
| 10398 | * |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10399 | * @param enable {@code true} if trying to turn radio on. |
| 10400 | * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code |
| 10401 | * false}. |
| 10402 | */ |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10403 | private boolean setRadioPowerForThermal(boolean enable) { |
| 10404 | boolean isPhoneAvailable = false; |
| 10405 | for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) { |
| 10406 | Phone phone = PhoneFactory.getPhone(i); |
| 10407 | if (phone != null) { |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 10408 | phone.setRadioPowerForReason(enable, TelephonyManager.RADIO_POWER_REASON_THERMAL); |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10409 | isPhoneAvailable = true; |
| 10410 | } |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10411 | } |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10412 | |
| 10413 | // return true if successfully informed the phone object about the thermal radio power |
| 10414 | // request. |
| 10415 | return isPhoneAvailable; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10416 | } |
| 10417 | |
| 10418 | private int handleDataThrottlingRequest(int subId, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 10419 | DataThrottlingRequest dataThrottlingRequest, String callingPackage) { |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10420 | boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported( |
| 10421 | TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING); |
| 10422 | if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction() |
| 10423 | != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) { |
| 10424 | throw new IllegalArgumentException("modem does not support data throttling"); |
| 10425 | } |
| 10426 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10427 | // Ensure that radio is on. If not able to power on due to phone being unavailable, return |
| 10428 | // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10429 | if (!setRadioPowerForThermal(true)) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10430 | return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 10431 | } |
| 10432 | |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 10433 | setDataEnabledForReason( |
| 10434 | subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true, callingPackage); |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10435 | |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10436 | if (isDataThrottlingSupported) { |
| 10437 | int thermalMitigationResult = |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10438 | (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId); |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10439 | if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) { |
| 10440 | throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS"); |
| 10441 | } else if (thermalMitigationResult |
| 10442 | == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) { |
Jack Nudelman | 760d096 | 2021-05-20 13:57:30 -0700 | [diff] [blame] | 10443 | log("Modem likely does not support data throttling on secondary carrier. Data " + |
| 10444 | "throttling action = " + dataThrottlingRequest.getDataThrottlingAction()); |
| 10445 | return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10446 | } |
| 10447 | return thermalMitigationResult; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10448 | } |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10449 | |
| 10450 | return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10451 | } |
| 10452 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10453 | private static List<String> getThermalMitigationAllowlist(Context context) { |
| 10454 | if (sThermalMitigationAllowlistedPackages.isEmpty()) { |
| 10455 | for (String pckg : context.getResources() |
| 10456 | .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) { |
| 10457 | sThermalMitigationAllowlistedPackages.add(pckg); |
| 10458 | } |
| 10459 | } |
| 10460 | |
| 10461 | return sThermalMitigationAllowlistedPackages; |
| 10462 | } |
| 10463 | |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 10464 | private boolean isAnyPhoneInEmergencyState() { |
| 10465 | TelecomManager tm = mApp.getSystemService(TelecomManager.class); |
| 10466 | if (tm.isInEmergencyCall()) { |
| 10467 | Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call"); |
| 10468 | return true; |
| 10469 | } |
| 10470 | for (Phone phone : PhoneFactory.getPhones()) { |
| 10471 | if (phone.isInEmergencySmsMode() || phone.isInEcm()) { |
| 10472 | Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = " |
| 10473 | + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = " |
| 10474 | + phone.isInEcm()); |
| 10475 | return true; |
| 10476 | } |
| 10477 | } |
| 10478 | |
| 10479 | return false; |
| 10480 | } |
| 10481 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10482 | /** |
| 10483 | * Used by shell commands to add an authorized package name for thermal mitigation. |
| 10484 | * @param packageName name of package to be allowlisted |
| 10485 | * @param context |
| 10486 | */ |
| 10487 | static void addPackageToThermalMitigationAllowlist(String packageName, Context context) { |
| 10488 | sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context); |
| 10489 | sThermalMitigationAllowlistedPackages.add(packageName); |
| 10490 | } |
| 10491 | |
| 10492 | /** |
| 10493 | * Used by shell commands to remove an authorized package name for thermal mitigation. |
| 10494 | * @param packageName name of package to remove from allowlist |
| 10495 | * @param context |
| 10496 | */ |
| 10497 | static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) { |
| 10498 | sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context); |
| 10499 | sThermalMitigationAllowlistedPackages.remove(packageName); |
| 10500 | } |
| 10501 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10502 | /** |
| 10503 | * Thermal mitigation request to control functionalities at modem. |
| 10504 | * |
| 10505 | * @param subId the id of the subscription. |
| 10506 | * @param thermalMitigationRequest holds all necessary information to be passed down to modem. |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10507 | * @param callingPackage the package name of the calling package. |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10508 | * |
| 10509 | * @return thermalMitigationResult enum as defined in android.telephony.Annotation. |
| 10510 | */ |
| 10511 | @Override |
| 10512 | @ThermalMitigationResult |
| 10513 | public int sendThermalMitigationRequest( |
| 10514 | int subId, |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10515 | ThermalMitigationRequest thermalMitigationRequest, |
| 10516 | String callingPackage) throws IllegalArgumentException { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10517 | enforceModifyPermission(); |
| 10518 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10519 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 10520 | if (!getThermalMitigationAllowlist(getDefaultPhone().getContext()) |
| 10521 | .contains(callingPackage)) { |
| 10522 | throw new SecurityException("Calling package must be configured in the device config. " |
| 10523 | + "calling package: " + callingPackage); |
| 10524 | } |
| 10525 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10526 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 10527 | final long identity = Binder.clearCallingIdentity(); |
| 10528 | |
| 10529 | int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR; |
| 10530 | try { |
| 10531 | int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction(); |
| 10532 | switch (thermalMitigationAction) { |
| 10533 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING: |
| 10534 | thermalMitigationResult = |
| 10535 | handleDataThrottlingRequest(subId, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 10536 | thermalMitigationRequest.getDataThrottlingRequest(), |
| 10537 | callingPackage); |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10538 | break; |
| 10539 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY: |
| 10540 | if (thermalMitigationRequest.getDataThrottlingRequest() != null) { |
| 10541 | throw new IllegalArgumentException("dataThrottlingRequest must be null for " |
| 10542 | + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY"); |
| 10543 | } |
| 10544 | |
| 10545 | // Ensure that radio is on. If not able to power on due to phone being |
| 10546 | // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10547 | if (!setRadioPowerForThermal(true)) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10548 | thermalMitigationResult = |
| 10549 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 10550 | break; |
| 10551 | } |
| 10552 | |
| 10553 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 10554 | false, callingPackage); |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10555 | thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 10556 | break; |
| 10557 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF: |
| 10558 | if (thermalMitigationRequest.getDataThrottlingRequest() != null) { |
| 10559 | throw new IllegalArgumentException("dataThrottlingRequest must be null for" |
| 10560 | + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF"); |
| 10561 | } |
| 10562 | |
| 10563 | TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null); |
| 10564 | if (registry != null) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10565 | Phone phone = getPhone(subId); |
| 10566 | if (phone == null) { |
| 10567 | thermalMitigationResult = |
| 10568 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 10569 | break; |
| 10570 | } |
| 10571 | |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 10572 | TelephonyConnectionService service = |
| 10573 | registry.getTelephonyConnectionService(); |
Jack Nudelman | b30ac30 | 2021-06-17 15:39:58 -0700 | [diff] [blame] | 10574 | if (service != null && service.isEmergencyCallPending()) { |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 10575 | Log.e(LOG_TAG, "An emergency call is pending"); |
| 10576 | thermalMitigationResult = |
| 10577 | TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE; |
| 10578 | break; |
| 10579 | } else if (isAnyPhoneInEmergencyState()) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10580 | thermalMitigationResult = |
| 10581 | TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE; |
| 10582 | break; |
| 10583 | } |
| 10584 | } else { |
| 10585 | thermalMitigationResult = |
| 10586 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 10587 | break; |
| 10588 | } |
| 10589 | |
| 10590 | // Turn radio off. If not able to power off due to phone being unavailable, |
| 10591 | // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10592 | if (!setRadioPowerForThermal(false)) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10593 | thermalMitigationResult = |
| 10594 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 10595 | break; |
| 10596 | } |
| 10597 | thermalMitigationResult = |
| 10598 | TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 10599 | break; |
| 10600 | default: |
| 10601 | throw new IllegalArgumentException("the requested thermalMitigationAction does " |
| 10602 | + "not exist. Requested action: " + thermalMitigationAction); |
| 10603 | } |
| 10604 | } catch (IllegalArgumentException e) { |
| 10605 | throw e; |
| 10606 | } catch (Exception e) { |
| 10607 | Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e); |
| 10608 | thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 10609 | } finally { |
| 10610 | Binder.restoreCallingIdentity(identity); |
| 10611 | } |
| 10612 | |
| 10613 | if (DBG) { |
| 10614 | log("thermalMitigationRequest returning with thermalMitigationResult: " |
| 10615 | + thermalMitigationResult); |
| 10616 | } |
| 10617 | |
| 10618 | return thermalMitigationResult; |
| 10619 | } |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 10620 | |
| 10621 | /** |
| 10622 | * Set the GbaService Package Name that Telephony will bind to. |
| 10623 | * |
| 10624 | * @param subId The sim that the GbaService is associated with. |
| 10625 | * @param packageName The name of the package to be replaced with. |
| 10626 | * @return true if setting the GbaService to bind to succeeded, false if it did not. |
| 10627 | */ |
| 10628 | @Override |
| 10629 | public boolean setBoundGbaServiceOverride(int subId, String packageName) { |
| 10630 | enforceModifyPermission(); |
| 10631 | |
| 10632 | final long identity = Binder.clearCallingIdentity(); |
| 10633 | try { |
| 10634 | return getGbaManager(subId).overrideServicePackage(packageName); |
| 10635 | } finally { |
| 10636 | Binder.restoreCallingIdentity(identity); |
| 10637 | } |
| 10638 | } |
| 10639 | |
| 10640 | /** |
| 10641 | * Return the package name of the currently bound GbaService. |
| 10642 | * |
| 10643 | * @param subId The sim that the GbaService is associated with. |
| 10644 | * @return the package name of the GbaService configuration, null if GBA is not supported. |
| 10645 | */ |
| 10646 | @Override |
| 10647 | public String getBoundGbaService(int subId) { |
| 10648 | enforceReadPrivilegedPermission("getBoundGbaServicePackage"); |
| 10649 | |
| 10650 | final long identity = Binder.clearCallingIdentity(); |
| 10651 | try { |
| 10652 | return getGbaManager(subId).getServicePackage(); |
| 10653 | } finally { |
| 10654 | Binder.restoreCallingIdentity(identity); |
| 10655 | } |
| 10656 | } |
| 10657 | |
| 10658 | /** |
| 10659 | * Set the release time for telephony to unbind GbaService. |
| 10660 | * |
| 10661 | * @param subId The sim that the GbaService is associated with. |
| 10662 | * @param interval The release time to unbind GbaService by millisecond. |
| 10663 | * @return true if setting the GbaService to bind to succeeded, false if it did not. |
| 10664 | */ |
| 10665 | @Override |
| 10666 | public boolean setGbaReleaseTimeOverride(int subId, int interval) { |
| 10667 | enforceModifyPermission(); |
| 10668 | |
| 10669 | final long identity = Binder.clearCallingIdentity(); |
| 10670 | try { |
| 10671 | return getGbaManager(subId).overrideReleaseTime(interval); |
| 10672 | } finally { |
| 10673 | Binder.restoreCallingIdentity(identity); |
| 10674 | } |
| 10675 | } |
| 10676 | |
| 10677 | /** |
| 10678 | * Return the release time for telephony to unbind GbaService. |
| 10679 | * |
| 10680 | * @param subId The sim that the GbaService is associated with. |
| 10681 | * @return The release time to unbind GbaService by millisecond. |
| 10682 | */ |
| 10683 | @Override |
| 10684 | public int getGbaReleaseTime(int subId) { |
| 10685 | enforceReadPrivilegedPermission("getGbaReleaseTime"); |
| 10686 | |
| 10687 | final long identity = Binder.clearCallingIdentity(); |
| 10688 | try { |
| 10689 | return getGbaManager(subId).getReleaseTime(); |
| 10690 | } finally { |
| 10691 | Binder.restoreCallingIdentity(identity); |
| 10692 | } |
| 10693 | } |
| 10694 | |
| 10695 | private GbaManager getGbaManager(int subId) { |
| 10696 | GbaManager instance = GbaManager.getInstance(subId); |
| 10697 | if (instance == null) { |
| 10698 | String packageName = mApp.getResources().getString(R.string.config_gba_package); |
| 10699 | int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time); |
| 10700 | instance = GbaManager.make(mApp, subId, packageName, releaseTime); |
| 10701 | } |
| 10702 | return instance; |
| 10703 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10704 | |
| 10705 | /** |
| 10706 | * indicate whether the device and the carrier can support |
| 10707 | * RCS VoLTE single registration. |
| 10708 | */ |
| 10709 | @Override |
| 10710 | public boolean isRcsVolteSingleRegistrationCapable(int subId) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10711 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 10712 | Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable", |
| 10713 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 10714 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10715 | |
| 10716 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10717 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10718 | } |
| 10719 | |
| 10720 | final long identity = Binder.clearCallingIdentity(); |
| 10721 | try { |
| 10722 | RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance(); |
| 10723 | if (rpm != null) { |
Hui Wang | 67af90e | 2021-06-04 16:57:15 -0700 | [diff] [blame] | 10724 | Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId); |
| 10725 | if (isCapable != null) { |
| 10726 | return isCapable; |
| 10727 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10728 | } |
Hui Wang | 67af90e | 2021-06-04 16:57:15 -0700 | [diff] [blame] | 10729 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE, |
| 10730 | "service is temporarily unavailable."); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10731 | } finally { |
| 10732 | Binder.restoreCallingIdentity(identity); |
| 10733 | } |
| 10734 | } |
| 10735 | |
| 10736 | /** |
| 10737 | * Register RCS provisioning callback. |
| 10738 | */ |
| 10739 | @Override |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10740 | public void registerRcsProvisioningCallback(int subId, |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10741 | IRcsConfigCallback callback) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10742 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10743 | Binder.getCallingUid(), "registerRcsProvisioningCallback", |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10744 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 10745 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10746 | |
| 10747 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10748 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10749 | } |
| 10750 | if (!isImsAvailableOnDevice()) { |
| 10751 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 10752 | "IMS not available on device."); |
| 10753 | } |
| 10754 | |
| 10755 | final long identity = Binder.clearCallingIdentity(); |
| 10756 | try { |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 10757 | if (!RcsProvisioningMonitor.getInstance() |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10758 | .registerRcsProvisioningCallback(subId, callback)) { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 10759 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION, |
| 10760 | "Active subscription not found."); |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 10761 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10762 | } finally { |
| 10763 | Binder.restoreCallingIdentity(identity); |
| 10764 | } |
| 10765 | } |
| 10766 | |
| 10767 | /** |
| 10768 | * Unregister RCS provisioning callback. |
| 10769 | */ |
| 10770 | @Override |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10771 | public void unregisterRcsProvisioningCallback(int subId, |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10772 | IRcsConfigCallback callback) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10773 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10774 | Binder.getCallingUid(), "unregisterRcsProvisioningCallback", |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10775 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 10776 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10777 | |
| 10778 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10779 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10780 | } |
| 10781 | if (!isImsAvailableOnDevice()) { |
| 10782 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 10783 | "IMS not available on device."); |
| 10784 | } |
| 10785 | |
| 10786 | final long identity = Binder.clearCallingIdentity(); |
| 10787 | try { |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 10788 | RcsProvisioningMonitor.getInstance() |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10789 | .unregisterRcsProvisioningCallback(subId, callback); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10790 | } finally { |
| 10791 | Binder.restoreCallingIdentity(identity); |
| 10792 | } |
| 10793 | } |
| 10794 | |
| 10795 | /** |
| 10796 | * trigger RCS reconfiguration. |
| 10797 | */ |
| 10798 | public void triggerRcsReconfiguration(int subId) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10799 | TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(), |
| 10800 | "triggerRcsReconfiguration", |
| 10801 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10802 | |
| 10803 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10804 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10805 | } |
| 10806 | if (!isImsAvailableOnDevice()) { |
| 10807 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 10808 | "IMS not available on device."); |
| 10809 | } |
| 10810 | |
| 10811 | final long identity = Binder.clearCallingIdentity(); |
| 10812 | try { |
| 10813 | RcsProvisioningMonitor.getInstance().requestReconfig(subId); |
| 10814 | } finally { |
| 10815 | Binder.restoreCallingIdentity(identity); |
| 10816 | } |
| 10817 | } |
| 10818 | |
| 10819 | /** |
| 10820 | * Provide the client configuration parameters of the RCS application. |
| 10821 | */ |
| 10822 | public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10823 | TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(), |
| 10824 | "setRcsClientConfiguration", |
| 10825 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10826 | |
| 10827 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10828 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10829 | } |
| 10830 | if (!isImsAvailableOnDevice()) { |
| 10831 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 10832 | "IMS not available on device."); |
| 10833 | } |
| 10834 | |
| 10835 | final long identity = Binder.clearCallingIdentity(); |
| 10836 | |
| 10837 | try { |
| 10838 | IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS); |
| 10839 | if (configBinder == null) { |
| 10840 | Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration"); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 10841 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION, |
| 10842 | "could not find the requested subscription"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10843 | } else { |
| 10844 | configBinder.setRcsClientConfiguration(rcc); |
| 10845 | } |
joonhunshin | 3e15424 | 2021-09-17 06:33:39 +0000 | [diff] [blame] | 10846 | |
| 10847 | RcsStats.getInstance().onRcsClientProvisioningStats(subId, |
| 10848 | RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10849 | } catch (RemoteException e) { |
| 10850 | Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage()); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 10851 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE, |
| 10852 | "service is temporarily unavailable."); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10853 | } finally { |
| 10854 | Binder.restoreCallingIdentity(identity); |
| 10855 | } |
| 10856 | } |
| 10857 | |
| 10858 | /** |
Hui Wang | baaee6a | 2021-02-19 20:45:36 -0800 | [diff] [blame] | 10859 | * Enables or disables the test mode for RCS VoLTE single registration. |
| 10860 | */ |
| 10861 | @Override |
| 10862 | public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) { |
| 10863 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10864 | "setRcsSingleRegistrationTestModeEnabled"); |
| 10865 | |
| 10866 | RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled); |
| 10867 | } |
| 10868 | |
| 10869 | /** |
| 10870 | * Gets the test mode for RCS VoLTE single registration. |
| 10871 | */ |
| 10872 | @Override |
| 10873 | public boolean getRcsSingleRegistrationTestModeEnabled() { |
| 10874 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10875 | "getRcsSingleRegistrationTestModeEnabled"); |
| 10876 | |
| 10877 | return RcsProvisioningMonitor.getInstance().getTestModeEnabled(); |
| 10878 | } |
| 10879 | |
| 10880 | /** |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10881 | * Overrides the config of RCS VoLTE single registration enabled for the device. |
| 10882 | */ |
| 10883 | @Override |
| 10884 | public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) { |
| 10885 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10886 | "setDeviceSingleRegistrationEnabledOverride"); |
| 10887 | enforceModifyPermission(); |
| 10888 | |
| 10889 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 10890 | : Boolean.parseBoolean(enabledStr); |
| 10891 | RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled); |
Brad Ebinger | 49a72b4 | 2021-01-29 00:55:24 +0000 | [diff] [blame] | 10892 | mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10893 | } |
| 10894 | |
| 10895 | /** |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 10896 | * Sends a device to device communication message. Only usable via shell. |
| 10897 | * @param message message to send. |
| 10898 | * @param value message value. |
| 10899 | */ |
| 10900 | @Override |
| 10901 | public void sendDeviceToDeviceMessage(int message, int value) { |
| 10902 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
Tyler Gunn | babbda0 | 2021-02-10 11:05:02 -0800 | [diff] [blame] | 10903 | "sendDeviceToDeviceMessage"); |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 10904 | enforceModifyPermission(); |
| 10905 | |
| 10906 | final long identity = Binder.clearCallingIdentity(); |
| 10907 | try { |
| 10908 | TelephonyConnectionService service = |
| 10909 | TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService(); |
| 10910 | if (service == null) { |
| 10911 | Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call."); |
| 10912 | return; |
| 10913 | } |
| 10914 | service.sendTestDeviceToDeviceMessage(message, value); |
| 10915 | } finally { |
| 10916 | Binder.restoreCallingIdentity(identity); |
| 10917 | } |
| 10918 | } |
| 10919 | |
Tyler Gunn | babbda0 | 2021-02-10 11:05:02 -0800 | [diff] [blame] | 10920 | /** |
| 10921 | * Sets the specified device to device transport active. |
| 10922 | * @param transport The transport to set active. |
| 10923 | */ |
| 10924 | @Override |
| 10925 | public void setActiveDeviceToDeviceTransport(@NonNull String transport) { |
| 10926 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10927 | "setActiveDeviceToDeviceTransport"); |
| 10928 | enforceModifyPermission(); |
| 10929 | |
| 10930 | final long identity = Binder.clearCallingIdentity(); |
| 10931 | try { |
| 10932 | TelephonyConnectionService service = |
| 10933 | TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService(); |
| 10934 | if (service == null) { |
| 10935 | Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call."); |
| 10936 | return; |
| 10937 | } |
| 10938 | service.setActiveDeviceToDeviceTransport(transport); |
| 10939 | } finally { |
| 10940 | Binder.restoreCallingIdentity(identity); |
| 10941 | } |
| 10942 | } |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 10943 | |
Tyler Gunn | d433926 | 2021-05-03 14:46:49 -0700 | [diff] [blame] | 10944 | @Override |
| 10945 | public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) { |
| 10946 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10947 | "setDeviceToDeviceForceEnabled"); |
| 10948 | |
| 10949 | final long identity = Binder.clearCallingIdentity(); |
| 10950 | try { |
| 10951 | Arrays.stream(PhoneFactory.getPhones()).forEach( |
| 10952 | p -> { |
| 10953 | Phone thePhone = p.getImsPhone(); |
| 10954 | if (thePhone != null && thePhone instanceof ImsPhone) { |
| 10955 | ImsPhone imsPhone = (ImsPhone) thePhone; |
| 10956 | CallTracker tracker = imsPhone.getCallTracker(); |
| 10957 | if (tracker != null && tracker instanceof ImsPhoneCallTracker) { |
| 10958 | ImsPhoneCallTracker imsPhoneCallTracker = |
| 10959 | (ImsPhoneCallTracker) tracker; |
| 10960 | imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled); |
| 10961 | } |
| 10962 | } |
| 10963 | } |
| 10964 | ); |
| 10965 | } finally { |
| 10966 | Binder.restoreCallingIdentity(identity); |
| 10967 | } |
| 10968 | } |
| 10969 | |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 10970 | /** |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10971 | * Gets the config of RCS VoLTE single registration enabled for the device. |
| 10972 | */ |
| 10973 | @Override |
| 10974 | public boolean getDeviceSingleRegistrationEnabled() { |
| 10975 | enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled"); |
| 10976 | return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled(); |
| 10977 | } |
| 10978 | |
| 10979 | /** |
| 10980 | * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription. |
| 10981 | */ |
| 10982 | @Override |
| 10983 | public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) { |
| 10984 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10985 | "setCarrierSingleRegistrationEnabledOverride"); |
| 10986 | enforceModifyPermission(); |
| 10987 | |
| 10988 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 10989 | : Boolean.parseBoolean(enabledStr); |
| 10990 | return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled( |
| 10991 | subId, enabled); |
| 10992 | } |
| 10993 | |
| 10994 | /** |
| 10995 | * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription. |
| 10996 | */ |
| 10997 | @Override |
| 10998 | public boolean getCarrierSingleRegistrationEnabled(int subId) { |
| 10999 | enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled"); |
| 11000 | return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId); |
| 11001 | } |
Chiachang Wang | d6d3477 | 2020-12-22 11:38:27 +0800 | [diff] [blame] | 11002 | |
| 11003 | /** |
Hui Wang | b647abe | 2021-02-26 09:33:38 -0800 | [diff] [blame] | 11004 | * Overrides the ims feature validation result |
| 11005 | */ |
| 11006 | @Override |
| 11007 | public boolean setImsFeatureValidationOverride(int subId, String enabledStr) { |
| 11008 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11009 | "setImsFeatureValidationOverride"); |
| 11010 | |
| 11011 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 11012 | : Boolean.parseBoolean(enabledStr); |
| 11013 | return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation( |
| 11014 | subId, enabled); |
| 11015 | } |
| 11016 | |
| 11017 | /** |
| 11018 | * Gets the ims feature validation override value |
| 11019 | */ |
| 11020 | @Override |
| 11021 | public boolean getImsFeatureValidationOverride(int subId) { |
| 11022 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11023 | "getImsFeatureValidationOverride"); |
| 11024 | return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId); |
| 11025 | } |
| 11026 | |
| 11027 | /** |
Chiachang Wang | d6d3477 | 2020-12-22 11:38:27 +0800 | [diff] [blame] | 11028 | * Get the mobile provisioning url that is used to launch a browser to allow users to manage |
| 11029 | * their mobile plan. |
| 11030 | */ |
| 11031 | @Override |
| 11032 | public String getMobileProvisioningUrl() { |
| 11033 | enforceReadPrivilegedPermission("getMobileProvisioningUrl"); |
| 11034 | final long identity = Binder.clearCallingIdentity(); |
| 11035 | try { |
| 11036 | return getDefaultPhone().getMobileProvisioningUrl(); |
| 11037 | } finally { |
| 11038 | Binder.restoreCallingIdentity(identity); |
| 11039 | } |
| 11040 | } |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11041 | |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 11042 | /** |
calvinpan | e4a8a1d | 2021-01-25 13:51:18 +0800 | [diff] [blame] | 11043 | * Get the EAB contact from the EAB database. |
| 11044 | */ |
| 11045 | @Override |
| 11046 | public String getContactFromEab(String contact) { |
| 11047 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab"); |
| 11048 | enforceModifyPermission(); |
| 11049 | final long identity = Binder.clearCallingIdentity(); |
| 11050 | try { |
| 11051 | return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact); |
| 11052 | } finally { |
| 11053 | Binder.restoreCallingIdentity(identity); |
| 11054 | } |
| 11055 | } |
| 11056 | |
| 11057 | /** |
Calvin Pan | a143432 | 2021-07-01 19:27:01 +0800 | [diff] [blame] | 11058 | * Get the EAB capability from the EAB database. |
| 11059 | */ |
| 11060 | @Override |
| 11061 | public String getCapabilityFromEab(String contact) { |
| 11062 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab"); |
| 11063 | enforceModifyPermission(); |
| 11064 | final long identity = Binder.clearCallingIdentity(); |
| 11065 | try { |
| 11066 | return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact); |
| 11067 | } finally { |
| 11068 | Binder.restoreCallingIdentity(identity); |
| 11069 | } |
| 11070 | } |
| 11071 | |
| 11072 | /** |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 11073 | * Remove the EAB contacts from the EAB database. |
| 11074 | */ |
| 11075 | @Override |
| 11076 | public int removeContactFromEab(int subId, String contacts) { |
| 11077 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab"); |
| 11078 | enforceModifyPermission(); |
| 11079 | final long identity = Binder.clearCallingIdentity(); |
| 11080 | try { |
| 11081 | return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext()); |
| 11082 | } finally { |
| 11083 | Binder.restoreCallingIdentity(identity); |
| 11084 | } |
| 11085 | } |
| 11086 | |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11087 | @Override |
James.cf Lin | 4b784aa | 2021-01-31 03:25:15 +0800 | [diff] [blame] | 11088 | public boolean getDeviceUceEnabled() { |
| 11089 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled"); |
| 11090 | final long identity = Binder.clearCallingIdentity(); |
| 11091 | try { |
| 11092 | return mApp.getDeviceUceEnabled(); |
| 11093 | } finally { |
| 11094 | Binder.restoreCallingIdentity(identity); |
| 11095 | } |
| 11096 | } |
| 11097 | |
| 11098 | @Override |
| 11099 | public void setDeviceUceEnabled(boolean isEnabled) { |
| 11100 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled"); |
| 11101 | final long identity = Binder.clearCallingIdentity(); |
| 11102 | try { |
| 11103 | mApp.setDeviceUceEnabled(isEnabled); |
| 11104 | } finally { |
| 11105 | Binder.restoreCallingIdentity(identity); |
| 11106 | } |
| 11107 | } |
| 11108 | |
Brad Ebinger | 14d467f | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 11109 | /** |
| 11110 | * Add new feature tags to the Set used to calculate the capabilities in PUBLISH. |
| 11111 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 11112 | */ |
| 11113 | // Used for SHELL command only right now. |
| 11114 | @Override |
| 11115 | public RcsContactUceCapability addUceRegistrationOverrideShell(int subId, |
| 11116 | List<String> featureTags) { |
| 11117 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11118 | "addUceRegistrationOverrideShell"); |
| 11119 | final long identity = Binder.clearCallingIdentity(); |
| 11120 | try { |
| 11121 | return mApp.imsRcsController.addUceRegistrationOverrideShell(subId, |
| 11122 | new ArraySet<>(featureTags)); |
| 11123 | } catch (ImsException e) { |
| 11124 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 11125 | } finally { |
| 11126 | Binder.restoreCallingIdentity(identity); |
| 11127 | } |
| 11128 | } |
| 11129 | |
| 11130 | /** |
| 11131 | * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH. |
| 11132 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 11133 | */ |
| 11134 | // Used for SHELL command only right now. |
| 11135 | @Override |
| 11136 | public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId, |
| 11137 | List<String> featureTags) { |
| 11138 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11139 | "removeUceRegistrationOverrideShell"); |
| 11140 | final long identity = Binder.clearCallingIdentity(); |
| 11141 | try { |
| 11142 | return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId, |
| 11143 | new ArraySet<>(featureTags)); |
| 11144 | } catch (ImsException e) { |
| 11145 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 11146 | } finally { |
| 11147 | Binder.restoreCallingIdentity(identity); |
| 11148 | } |
| 11149 | } |
| 11150 | |
| 11151 | /** |
| 11152 | * Clear all overrides in the Set used to calculate the capabilities in PUBLISH. |
| 11153 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 11154 | */ |
| 11155 | // Used for SHELL command only right now. |
| 11156 | @Override |
| 11157 | public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) { |
| 11158 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11159 | "clearUceRegistrationOverrideShell"); |
| 11160 | final long identity = Binder.clearCallingIdentity(); |
| 11161 | try { |
| 11162 | return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId); |
| 11163 | } catch (ImsException e) { |
| 11164 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 11165 | } finally { |
| 11166 | Binder.restoreCallingIdentity(identity); |
| 11167 | } |
| 11168 | } |
| 11169 | |
| 11170 | /** |
| 11171 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 11172 | */ |
| 11173 | // Used for SHELL command only right now. |
| 11174 | @Override |
| 11175 | public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) { |
| 11176 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11177 | "getLatestRcsContactUceCapabilityShell"); |
| 11178 | final long identity = Binder.clearCallingIdentity(); |
| 11179 | try { |
| 11180 | return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId); |
| 11181 | } catch (ImsException e) { |
| 11182 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 11183 | } finally { |
| 11184 | Binder.restoreCallingIdentity(identity); |
| 11185 | } |
| 11186 | } |
| 11187 | |
| 11188 | /** |
| 11189 | * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the |
| 11190 | * device does not have an active PUBLISH. |
| 11191 | */ |
| 11192 | // Used for SHELL command only right now. |
| 11193 | @Override |
| 11194 | public String getLastUcePidfXmlShell(int subId) { |
| 11195 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml"); |
| 11196 | final long identity = Binder.clearCallingIdentity(); |
| 11197 | try { |
| 11198 | return mApp.imsRcsController.getLastUcePidfXmlShell(subId); |
| 11199 | } catch (ImsException e) { |
| 11200 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 11201 | } finally { |
| 11202 | Binder.restoreCallingIdentity(identity); |
| 11203 | } |
| 11204 | } |
| 11205 | |
James.cf Lin | e8713a4 | 2021-04-29 16:04:26 +0800 | [diff] [blame] | 11206 | /** |
| 11207 | * Remove UCE requests cannot be sent to the network status. |
| 11208 | */ |
| 11209 | // Used for SHELL command only right now. |
| 11210 | @Override |
| 11211 | public boolean removeUceRequestDisallowedStatus(int subId) { |
| 11212 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus"); |
| 11213 | final long identity = Binder.clearCallingIdentity(); |
| 11214 | try { |
| 11215 | return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId); |
| 11216 | } catch (ImsException e) { |
| 11217 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 11218 | } finally { |
| 11219 | Binder.restoreCallingIdentity(identity); |
| 11220 | } |
| 11221 | } |
| 11222 | |
James.cf Lin | 18bb900 | 2021-05-25 01:37:38 +0800 | [diff] [blame] | 11223 | /** |
| 11224 | * Remove UCE requests cannot be sent to the network status. |
| 11225 | */ |
| 11226 | // Used for SHELL command only. |
| 11227 | @Override |
| 11228 | public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) { |
| 11229 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout"); |
| 11230 | final long identity = Binder.clearCallingIdentity(); |
| 11231 | try { |
| 11232 | return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs); |
| 11233 | } catch (ImsException e) { |
| 11234 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 11235 | } finally { |
| 11236 | Binder.restoreCallingIdentity(identity); |
| 11237 | } |
| 11238 | } |
Brad Ebinger | 14d467f | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 11239 | |
James.cf Lin | 4b784aa | 2021-01-31 03:25:15 +0800 | [diff] [blame] | 11240 | @Override |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11241 | public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request, |
| 11242 | String callingPackage) { |
| 11243 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 11244 | mApp, subId, "setSignalStrengthUpdateRequest"); |
| 11245 | |
| 11246 | final int callingUid = Binder.getCallingUid(); |
| 11247 | // Verify that tha callingPackage belongs to the calling UID |
| 11248 | mApp.getSystemService(AppOpsManager.class) |
| 11249 | .checkPackage(callingUid, callingPackage); |
| 11250 | |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 11251 | validateSignalStrengthUpdateRequest(mApp, request, callingUid); |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11252 | |
| 11253 | final long identity = Binder.clearCallingIdentity(); |
| 11254 | try { |
| 11255 | Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST, |
| 11256 | new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId); |
| 11257 | |
| 11258 | if (result instanceof IllegalStateException) { |
| 11259 | throw (IllegalStateException) result; |
| 11260 | } |
| 11261 | } finally { |
| 11262 | Binder.restoreCallingIdentity(identity); |
| 11263 | } |
| 11264 | } |
| 11265 | |
| 11266 | @Override |
| 11267 | public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request, |
| 11268 | String callingPackage) { |
| 11269 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 11270 | mApp, subId, "clearSignalStrengthUpdateRequest"); |
| 11271 | |
| 11272 | final int callingUid = Binder.getCallingUid(); |
| 11273 | // Verify that tha callingPackage belongs to the calling UID |
| 11274 | mApp.getSystemService(AppOpsManager.class) |
| 11275 | .checkPackage(callingUid, callingPackage); |
| 11276 | |
| 11277 | final long identity = Binder.clearCallingIdentity(); |
| 11278 | try { |
| 11279 | Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST, |
| 11280 | new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId); |
| 11281 | |
| 11282 | if (result instanceof IllegalStateException) { |
| 11283 | throw (IllegalStateException) result; |
| 11284 | } |
| 11285 | } finally { |
| 11286 | Binder.restoreCallingIdentity(identity); |
| 11287 | } |
| 11288 | } |
| 11289 | |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 11290 | private static void validateSignalStrengthUpdateRequest(Context context, |
| 11291 | SignalStrengthUpdateRequest request, int callingUid) { |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11292 | if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) { |
| 11293 | // phone/system process do not have further restriction on request |
| 11294 | return; |
| 11295 | } |
| 11296 | |
| 11297 | // Applications has restrictions on how to use the request: |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 11298 | // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11299 | if (request.isSystemThresholdReportingRequestedWhileIdle()) { |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 11300 | context.enforceCallingOrSelfPermission( |
| 11301 | android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH, |
| 11302 | "validateSignalStrengthUpdateRequest"); |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11303 | } |
| 11304 | |
| 11305 | for (SignalThresholdInfo info : request.getSignalThresholdInfos()) { |
| 11306 | // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled. |
| 11307 | if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED |
| 11308 | || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED |
| 11309 | || info.isEnabled()) { |
| 11310 | throw new IllegalArgumentException( |
| 11311 | "Only system can set hide fields in SignalThresholdInfo"); |
| 11312 | } |
| 11313 | |
| 11314 | // Thresholds length for each RAN need in range. This has been validated in |
| 11315 | // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method |
| 11316 | // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds |
| 11317 | final int[] thresholds = info.getThresholds(); |
| 11318 | Objects.requireNonNull(thresholds); |
| 11319 | if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed() |
| 11320 | || thresholds.length |
| 11321 | > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) { |
| 11322 | throw new IllegalArgumentException( |
| 11323 | "thresholds length is out of range: " + thresholds.length); |
| 11324 | } |
| 11325 | } |
| 11326 | } |
SongFerngWang | 8236caa | 2021-01-17 21:51:44 +0800 | [diff] [blame] | 11327 | |
| 11328 | /** |
| 11329 | * Gets the current phone capability. |
| 11330 | * |
| 11331 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 11332 | * @return the PhoneCapability which describes the data connection capability of modem. |
| 11333 | * It's used to evaluate possible phone config change, for example from single |
| 11334 | * SIM device to multi-SIM device. |
| 11335 | */ |
| 11336 | @Override |
| 11337 | public PhoneCapability getPhoneCapability() { |
| 11338 | enforceReadPrivilegedPermission("getPhoneCapability"); |
| 11339 | final long identity = Binder.clearCallingIdentity(); |
| 11340 | try { |
| 11341 | return mPhoneConfigurationManager.getCurrentPhoneCapability(); |
| 11342 | } finally { |
| 11343 | Binder.restoreCallingIdentity(identity); |
| 11344 | } |
| 11345 | } |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 11346 | |
| 11347 | /** |
| 11348 | * Prepare TelephonyManager for an unattended reboot. The reboot is |
| 11349 | * required to be done shortly after the API is invoked. |
| 11350 | */ |
| 11351 | @Override |
| 11352 | @TelephonyManager.PrepareUnattendedRebootResult |
| 11353 | public int prepareForUnattendedReboot() { |
Rafael Higuera Silva | d963064 | 2021-09-20 15:32:01 +0000 | [diff] [blame] | 11354 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 11355 | enforceRebootPermission(); |
| 11356 | |
| 11357 | final long identity = Binder.clearCallingIdentity(); |
| 11358 | try { |
Rafael Higuera Silva | d963064 | 2021-09-20 15:32:01 +0000 | [diff] [blame] | 11359 | return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 11360 | } finally { |
| 11361 | Binder.restoreCallingIdentity(identity); |
| 11362 | } |
| 11363 | } |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 11364 | |
| 11365 | /** |
| 11366 | * Request to get the current slicing configuration including URSP rules and |
| 11367 | * NSSAIs (configured, allowed and rejected). |
| 11368 | * |
| 11369 | * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission. |
| 11370 | */ |
| 11371 | @Override |
| 11372 | public void getSlicingConfig(ResultReceiver callback) { |
Hongbo Zeng | 1b2063d | 2022-02-21 01:33:03 +0000 | [diff] [blame] | 11373 | TelephonyPermissions |
| 11374 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 11375 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, "getSlicingConfig"); |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 11376 | |
| 11377 | final long identity = Binder.clearCallingIdentity(); |
| 11378 | try { |
| 11379 | Phone phone = getDefaultPhone(); |
| 11380 | sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null); |
| 11381 | } finally { |
| 11382 | Binder.restoreCallingIdentity(identity); |
| 11383 | } |
| 11384 | } |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 11385 | |
| 11386 | /** |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 11387 | * Check whether the given premium capability is available for purchase from the carrier. |
| 11388 | * |
| 11389 | * @param capability The premium capability to check. |
| 11390 | * @param subId The subId to check the premium capability for. |
| 11391 | * |
| 11392 | * @return Whether the given premium capability is available to purchase. |
| 11393 | */ |
| 11394 | @Override |
| 11395 | public boolean isPremiumCapabilityAvailableForPurchase(int capability, int subId) { |
| 11396 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 11397 | mApp, "isPremiumCapabilityAvailableForPurchase")) { |
| 11398 | log("Premium capability " |
| 11399 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 11400 | + " is not available for purchase due to missing permissions."); |
| 11401 | throw new SecurityException("isPremiumCapabilityAvailableForPurchase requires " |
| 11402 | + "permission READ_BASIC_PHONE_STATE."); |
| 11403 | } |
| 11404 | |
| 11405 | Phone phone = getPhone(subId); |
Thomas Nguyen | 7216ed6 | 2022-11-29 16:45:31 -0800 | [diff] [blame] | 11406 | if (phone == null) { |
| 11407 | loge("isPremiumCapabilityAvailableForPurchase: phone is null, subId=" + subId); |
| 11408 | return false; |
| 11409 | } |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 11410 | final long identity = Binder.clearCallingIdentity(); |
| 11411 | try { |
Sarah Chin | 46355ba | 2022-11-01 23:51:16 -0700 | [diff] [blame] | 11412 | return SlicePurchaseController.getInstance(phone) |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 11413 | .isPremiumCapabilityAvailableForPurchase(capability); |
| 11414 | } finally { |
| 11415 | Binder.restoreCallingIdentity(identity); |
| 11416 | } |
| 11417 | } |
| 11418 | |
| 11419 | /** |
| 11420 | * Purchase the given premium capability from the carrier. |
| 11421 | * |
| 11422 | * @param capability The premium capability to purchase. |
| 11423 | * @param callback The result of the purchase request. |
| 11424 | * @param subId The subId to purchase the premium capability for. |
| 11425 | */ |
| 11426 | @Override |
| 11427 | public void purchasePremiumCapability(int capability, IIntegerConsumer callback, int subId) { |
| 11428 | log("purchasePremiumCapability: capability=" |
| 11429 | + TelephonyManager.convertPremiumCapabilityToString(capability) + ", caller=" |
| 11430 | + getCurrentPackageName()); |
| 11431 | |
| 11432 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 11433 | mApp, "purchasePremiumCapability")) { |
| 11434 | log("purchasePremiumCapability " |
| 11435 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 11436 | + " failed due to missing permissions."); |
| 11437 | throw new SecurityException("purchasePremiumCapability requires permission " |
| 11438 | + "READ_BASIC_PHONE_STATE."); |
| 11439 | } |
| 11440 | |
| 11441 | Phone phone = getPhone(subId); |
Sarah Chin | 1969411 | 2022-12-06 15:41:37 -0800 | [diff] [blame] | 11442 | if (phone == null) { |
| 11443 | try { |
| 11444 | int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_REQUEST_FAILED; |
| 11445 | callback.accept(result); |
| 11446 | loge("purchasePremiumCapability: phone is null, subId=" + subId); |
| 11447 | } catch (RemoteException e) { |
| 11448 | String logStr = "Purchase premium capability " |
| 11449 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 11450 | + " failed due to RemoteException handling null phone: " + e; |
| 11451 | if (DBG) log(logStr); |
| 11452 | AnomalyReporter.reportAnomaly( |
| 11453 | UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr); |
| 11454 | } |
| 11455 | return; |
| 11456 | } |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 11457 | String appName; |
| 11458 | try { |
| 11459 | appName = mApp.getPackageManager().getApplicationLabel(mApp.getPackageManager() |
| 11460 | .getApplicationInfo(getCurrentPackageName(), 0)).toString(); |
| 11461 | } catch (PackageManager.NameNotFoundException e) { |
| 11462 | appName = "An application"; |
| 11463 | } |
| 11464 | sendRequestAsync(CMD_PURCHASE_PREMIUM_CAPABILITY, |
| 11465 | new PurchasePremiumCapabilityArgument(capability, appName, callback), phone, null); |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 11466 | } |
| 11467 | |
| 11468 | /** |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 11469 | * Register an IMS connection state callback |
| 11470 | */ |
| 11471 | @Override |
Hunsuk Choi | 89bd22c | 2021-11-01 13:04:54 +0000 | [diff] [blame] | 11472 | public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb, |
| 11473 | String callingPackage) { |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 11474 | if (feature == ImsFeature.FEATURE_MMTEL) { |
| 11475 | // ImsMmTelManager |
| 11476 | // The following also checks READ_PRIVILEGED_PHONE_STATE. |
| 11477 | TelephonyPermissions |
| 11478 | .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 11479 | mApp, subId, "registerImsStateCallback"); |
| 11480 | } else if (feature == ImsFeature.FEATURE_RCS) { |
| 11481 | // ImsRcsManager or SipDelegateManager |
| 11482 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 11483 | Binder.getCallingUid(), "registerImsStateCallback", |
| 11484 | Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
| 11485 | Manifest.permission.READ_PRECISE_PHONE_STATE, |
| 11486 | Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE, |
| 11487 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
| 11488 | } |
| 11489 | |
| 11490 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 11491 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 11492 | "IMS not available on device."); |
| 11493 | } |
| 11494 | |
| 11495 | if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) { |
| 11496 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 11497 | } |
| 11498 | |
| 11499 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 11500 | if (controller == null) { |
| 11501 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 11502 | "IMS not available on device."); |
| 11503 | } |
| 11504 | |
Hunsuk Choi | 89bd22c | 2021-11-01 13:04:54 +0000 | [diff] [blame] | 11505 | if (callingPackage == null) { |
| 11506 | callingPackage = getCurrentPackageName(); |
| 11507 | } |
| 11508 | |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 11509 | final long token = Binder.clearCallingIdentity(); |
| 11510 | try { |
| 11511 | int slotId = getSlotIndexOrException(subId); |
Hunsuk Choi | 89bd22c | 2021-11-01 13:04:54 +0000 | [diff] [blame] | 11512 | controller.registerImsStateCallback(subId, feature, cb, callingPackage); |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 11513 | } catch (ImsException e) { |
| 11514 | throw new ServiceSpecificException(e.getCode()); |
| 11515 | } finally { |
| 11516 | Binder.restoreCallingIdentity(token); |
| 11517 | } |
| 11518 | } |
| 11519 | |
| 11520 | /** |
| 11521 | * Unregister an IMS connection state callback |
| 11522 | */ |
| 11523 | @Override |
| 11524 | public void unregisterImsStateCallback(IImsStateCallback cb) { |
| 11525 | final long token = Binder.clearCallingIdentity(); |
| 11526 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 11527 | if (controller == null) { |
| 11528 | return; |
| 11529 | } |
| 11530 | try { |
| 11531 | controller.unregisterImsStateCallback(cb); |
| 11532 | } finally { |
| 11533 | Binder.restoreCallingIdentity(token); |
| 11534 | } |
| 11535 | } |
Sooraj Sasindran | fae41b3 | 2021-10-26 02:10:05 -0700 | [diff] [blame] | 11536 | |
| 11537 | /** |
| 11538 | * @return {@CellIdentity} last known cell identity {@CellIdentity}. |
| 11539 | * |
| 11540 | * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and |
| 11541 | * com.android.phone.permission.ACCESS_LAST_KNOWN_CELL_ID, otherwise throws |
| 11542 | * SecurityException. |
| 11543 | * If there is current registered network this value will be same as the registered cell |
| 11544 | * identity. If the device goes out of service the previous cell identity is cached and |
| 11545 | * will be returned. If the cache age of the Cell identity is more than 24 hours |
| 11546 | * it will be cleared and null will be returned. |
| 11547 | * |
| 11548 | */ |
| 11549 | @Override |
| 11550 | public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage, |
| 11551 | String callingFeatureId) { |
| 11552 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 11553 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 11554 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 11555 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 11556 | .setCallingPackage(callingPackage) |
| 11557 | .setCallingFeatureId(callingFeatureId) |
| 11558 | .setCallingPid(Binder.getCallingPid()) |
| 11559 | .setCallingUid(Binder.getCallingUid()) |
| 11560 | .setMethod("getLastKnownCellIdentity") |
| 11561 | .setLogAsInfo(true) |
| 11562 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 11563 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 11564 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 11565 | .build()); |
| 11566 | |
| 11567 | boolean hasFinePermission = |
| 11568 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 11569 | if (!hasFinePermission |
| 11570 | || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) { |
| 11571 | throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION " |
Rambo Wang | 918993a | 2022-04-27 09:08:36 -0700 | [diff] [blame] | 11572 | + "and ACCESS_LAST_KNOWN_CELL_ID permission."); |
Sooraj Sasindran | fae41b3 | 2021-10-26 02:10:05 -0700 | [diff] [blame] | 11573 | } |
| 11574 | |
| 11575 | final long identity = Binder.clearCallingIdentity(); |
| 11576 | try { |
| 11577 | Phone phone = getPhone(subId); |
| 11578 | if (phone == null) return null; |
| 11579 | ServiceStateTracker sst = phone.getServiceStateTracker(); |
| 11580 | if (sst == null) return null; |
| 11581 | return sst.getLastKnownCellIdentity(); |
| 11582 | } finally { |
| 11583 | Binder.restoreCallingIdentity(identity); |
| 11584 | } |
| 11585 | } |
Jack Yu | 4c0a550 | 2021-12-03 23:58:26 -0800 | [diff] [blame] | 11586 | |
jimsun | 3b9ccac | 2021-10-26 15:01:23 +0800 | [diff] [blame] | 11587 | /** |
| 11588 | * Sets the modem service class Name that Telephony will bind to. |
| 11589 | * |
| 11590 | * @param serviceName The class name of the modem service. |
| 11591 | * @return true if the operation is succeed, otherwise false. |
| 11592 | */ |
| 11593 | public boolean setModemService(String serviceName) { |
| 11594 | Log.d(LOG_TAG, "setModemService - " + serviceName); |
| 11595 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService"); |
| 11596 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 11597 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 11598 | "setModemService"); |
| 11599 | return mPhoneConfigurationManager.setModemService(serviceName); |
| 11600 | } |
| 11601 | |
| 11602 | /** |
| 11603 | * Return the class name of the currently bounded modem service. |
| 11604 | * |
| 11605 | * @return the class name of the modem service. |
| 11606 | */ |
| 11607 | public String getModemService() { |
| 11608 | String result; |
| 11609 | Log.d(LOG_TAG, "getModemService"); |
| 11610 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService"); |
| 11611 | TelephonyPermissions |
| 11612 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 11613 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 11614 | "getModemService"); |
| 11615 | result = mPhoneConfigurationManager.getModemService(); |
| 11616 | Log.d(LOG_TAG, "result = " + result); |
| 11617 | return result; |
| 11618 | } |
Hunter Knepshield | 2b076fa | 2022-01-19 02:26:22 -0800 | [diff] [blame] | 11619 | |
| 11620 | @Override |
| 11621 | public void setVoiceServiceStateOverride(int subId, boolean hasService, String callingPackage) { |
| 11622 | // Only telecom (and shell, for CTS purposes) is allowed to call this method. |
| 11623 | mApp.enforceCallingOrSelfPermission( |
| 11624 | permission.BIND_TELECOM_CONNECTION_SERVICE, "setVoiceServiceStateOverride"); |
| 11625 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 11626 | |
| 11627 | final long identity = Binder.clearCallingIdentity(); |
| 11628 | try { |
| 11629 | Phone phone = getPhone(subId); |
| 11630 | if (phone == null) return; |
| 11631 | phone.setVoiceServiceStateOverride(hasService); |
| 11632 | } finally { |
| 11633 | Binder.restoreCallingIdentity(identity); |
| 11634 | } |
| 11635 | } |
Muralidhar Reddy | 4e5a801 | 2022-05-11 14:49:00 +0000 | [diff] [blame] | 11636 | |
| 11637 | /** |
| 11638 | * set removable eSIM as default eUICC. |
| 11639 | * |
| 11640 | * @hide |
| 11641 | */ |
| 11642 | @Override |
| 11643 | public void setRemovableEsimAsDefaultEuicc(boolean isDefault, String callingPackage) { |
| 11644 | enforceModifyPermission(); |
| 11645 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 11646 | |
| 11647 | final long identity = Binder.clearCallingIdentity(); |
| 11648 | try { |
| 11649 | UiccController.getInstance().setRemovableEsimAsDefaultEuicc(isDefault); |
| 11650 | } finally { |
| 11651 | Binder.restoreCallingIdentity(identity); |
| 11652 | } |
| 11653 | } |
| 11654 | |
| 11655 | /** |
| 11656 | * Returns whether the removable eSIM is default eUICC or not. |
| 11657 | * |
| 11658 | * @hide |
| 11659 | */ |
| 11660 | @Override |
| 11661 | public boolean isRemovableEsimDefaultEuicc(String callingPackage) { |
| 11662 | enforceReadPrivilegedPermission("isRemovableEsimDefaultEuicc"); |
| 11663 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 11664 | |
| 11665 | final long identity = Binder.clearCallingIdentity(); |
| 11666 | try { |
| 11667 | return UiccController.getInstance().isRemovableEsimDefaultEuicc(); |
| 11668 | } finally { |
| 11669 | Binder.restoreCallingIdentity(identity); |
| 11670 | } |
| 11671 | } |
| 11672 | |
Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame] | 11673 | /** |
| 11674 | * Get the component name of the default app to direct respond-via-message intent for the |
| 11675 | * user associated with this subscription, update the cache if there is no respond-via-message |
| 11676 | * application currently configured for this user. |
| 11677 | * @return component name of the app and class to direct Respond Via Message intent to, or |
| 11678 | * {@code null} if the functionality is not supported. |
| 11679 | * @hide |
| 11680 | */ |
| 11681 | @Override |
| 11682 | public @Nullable ComponentName getDefaultRespondViaMessageApplication(int subId, |
| 11683 | boolean updateIfNeeded) { |
| 11684 | enforceInteractAcrossUsersPermission("getDefaultRespondViaMessageApplication"); |
Muralidhar Reddy | 4e5a801 | 2022-05-11 14:49:00 +0000 | [diff] [blame] | 11685 | |
Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame] | 11686 | Context context = getPhone(subId).getContext(); |
| 11687 | UserHandle userHandle = null; |
| 11688 | final long identity = Binder.clearCallingIdentity(); |
| 11689 | try { |
| 11690 | userHandle = TelephonyUtils.getSubscriptionUserHandle(context, subId); |
| 11691 | } finally { |
| 11692 | Binder.restoreCallingIdentity(identity); |
| 11693 | } |
| 11694 | return SmsApplication.getDefaultRespondViaMessageApplicationAsUser(context, |
| 11695 | updateIfNeeded, userHandle); |
| 11696 | } |
Jack Yu | f5badd9 | 2022-12-08 00:50:53 -0800 | [diff] [blame] | 11697 | |
| 11698 | /** |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 11699 | * Set whether the device is able to connect with null ciphering or integrity |
| 11700 | * algorithms. This is a global setting and will apply to all active subscriptions |
| 11701 | * and all new subscriptions after this. |
| 11702 | * |
| 11703 | * @param enabled when true, null cipher and integrity algorithms are allowed. |
| 11704 | * @hide |
| 11705 | */ |
| 11706 | @Override |
| 11707 | @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 11708 | public void setNullCipherAndIntegrityEnabled(boolean enabled) { |
| 11709 | enforceModifyPermission(); |
| 11710 | checkForNullCipherAndIntegritySupport(); |
| 11711 | |
| 11712 | // Persist the state of our preference. Each GsmCdmaPhone instance is responsible |
| 11713 | // for listening to these preference changes and applying them immediately. |
| 11714 | SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 11715 | editor.putBoolean(Phone.PREF_NULL_CIPHER_AND_INTEGRITY_ENABLED, enabled); |
| 11716 | editor.apply(); |
| 11717 | |
| 11718 | for (Phone phone: PhoneFactory.getPhones()) { |
| 11719 | phone.handleNullCipherEnabledChange(); |
| 11720 | } |
| 11721 | } |
| 11722 | |
| 11723 | |
| 11724 | /** |
| 11725 | * Get whether the device is able to connect with null ciphering or integrity |
| 11726 | * algorithms. Note that this retrieves the phone-global preference and not |
| 11727 | * the state of the radio. |
| 11728 | * |
| 11729 | * @throws SecurityException if {@link permission#MODIFY_PHONE_STATE} is not satisfied |
| 11730 | * @throws UnsupportedOperationException if the device does not support the minimum HAL |
| 11731 | * version for this feature. |
| 11732 | * @hide |
| 11733 | */ |
| 11734 | @Override |
| 11735 | @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) |
| 11736 | public boolean isNullCipherAndIntegrityPreferenceEnabled() { |
| 11737 | enforceReadPermission(); |
| 11738 | checkForNullCipherAndIntegritySupport(); |
| 11739 | return getDefaultPhone().getNullCipherAndIntegrityEnabledPreference(); |
| 11740 | } |
| 11741 | |
| 11742 | private void checkForNullCipherAndIntegritySupport() { |
| 11743 | if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_NULL_CIPHER_AND_INTEGRITY_VERSION) { |
| 11744 | throw new UnsupportedOperationException( |
| 11745 | "Null cipher and integrity operations require HAL 2.1 or above"); |
| 11746 | } |
| 11747 | } |
| 11748 | |
| 11749 | /** |
Jack Yu | f5badd9 | 2022-12-08 00:50:53 -0800 | [diff] [blame] | 11750 | * Get the SIM state for the slot index. |
| 11751 | * For Remote-SIMs, this method returns {@link IccCardConstants.State#UNKNOWN} |
| 11752 | * |
| 11753 | * @return SIM state as the ordinal of {@link IccCardConstants.State} |
| 11754 | */ |
| 11755 | @Override |
| 11756 | @SimState |
| 11757 | public int getSimStateForSlotIndex(int slotIndex) { |
| 11758 | IccCardConstants.State simState; |
| 11759 | if (slotIndex < 0) { |
| 11760 | simState = IccCardConstants.State.UNKNOWN; |
| 11761 | } else { |
| 11762 | Phone phone = null; |
| 11763 | try { |
| 11764 | phone = PhoneFactory.getPhone(slotIndex); |
| 11765 | } catch (IllegalStateException e) { |
| 11766 | // ignore |
| 11767 | } |
| 11768 | if (phone == null) { |
| 11769 | simState = IccCardConstants.State.UNKNOWN; |
| 11770 | } else { |
| 11771 | IccCard icc = phone.getIccCard(); |
| 11772 | if (icc == null) { |
| 11773 | simState = IccCardConstants.State.UNKNOWN; |
| 11774 | } else { |
| 11775 | simState = icc.getState(); |
| 11776 | } |
| 11777 | } |
| 11778 | } |
| 11779 | return simState.ordinal(); |
| 11780 | } |
Hui Wang | 9b5793a | 2022-12-05 14:38:06 -0600 | [diff] [blame] | 11781 | |
| 11782 | /** |
| 11783 | * Get current cell broadcast ranges. |
| 11784 | */ |
| 11785 | @Override |
| 11786 | @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS) |
| 11787 | public List<CellBroadcastIdRange> getCellBroadcastIdRanges(int subId) { |
| 11788 | mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS, |
| 11789 | "getCellBroadcastIdRanges"); |
| 11790 | final long identity = Binder.clearCallingIdentity(); |
| 11791 | try { |
| 11792 | return getPhone(subId).getCellBroadcastIdRanges(); |
| 11793 | } finally { |
| 11794 | Binder.restoreCallingIdentity(identity); |
| 11795 | } |
| 11796 | } |
| 11797 | |
| 11798 | /** |
| 11799 | * Set reception of cell broadcast messages with the list of the given ranges |
| 11800 | * |
| 11801 | * @param ranges the list of {@link CellBroadcastIdRange} to be enabled |
| 11802 | */ |
| 11803 | @Override |
| 11804 | @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS) |
| 11805 | public void setCellBroadcastIdRanges(int subId, @NonNull List<CellBroadcastIdRange> ranges, |
| 11806 | @Nullable IIntegerConsumer callback) { |
| 11807 | mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS, |
| 11808 | "setCellBroadcastIdRanges"); |
| 11809 | final long identity = Binder.clearCallingIdentity(); |
| 11810 | try { |
| 11811 | Phone phone = getPhoneFromSubId(subId); |
| 11812 | if (DBG) { |
| 11813 | log("setCellBroadcastIdRanges for subId :" + subId + ", phone:" + phone); |
| 11814 | } |
| 11815 | phone.setCellBroadcastIdRanges(ranges, result -> { |
| 11816 | if (callback != null) { |
| 11817 | try { |
| 11818 | callback.accept(result); |
| 11819 | } catch (RemoteException e) { |
| 11820 | Log.w(LOG_TAG, "setCellBroadcastIdRanges: callback not available."); |
| 11821 | } |
| 11822 | } |
| 11823 | }); |
| 11824 | } finally { |
| 11825 | Binder.restoreCallingIdentity(identity); |
| 11826 | } |
| 11827 | } |
Hunsuk Choi | 42cc62a | 2022-10-16 06:03:40 +0000 | [diff] [blame] | 11828 | |
| 11829 | /** |
| 11830 | * Returns whether the device supports the domain selection service. |
| 11831 | * |
| 11832 | * @return {@code true} if the device supports the domain selection service. |
| 11833 | */ |
| 11834 | @Override |
| 11835 | public boolean isDomainSelectionSupported() { |
| 11836 | mApp.enforceCallingOrSelfPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
| 11837 | "isDomainSelectionSupported"); |
| 11838 | |
| 11839 | final long identity = Binder.clearCallingIdentity(); |
| 11840 | try { |
| 11841 | return DomainSelectionResolver.getInstance().isDomainSelectionSupported(); |
| 11842 | } finally { |
| 11843 | Binder.restoreCallingIdentity(identity); |
| 11844 | } |
| 11845 | } |
arunvoddu | d5c6ce0 | 2022-12-11 06:03:12 +0000 | [diff] [blame^] | 11846 | |
| 11847 | /** |
| 11848 | * Check whether the caller (or self, if not processing an IPC) can read device identifiers. |
| 11849 | * |
| 11850 | * <p>This method behaves in one of the following ways: |
| 11851 | * <ul> |
| 11852 | * <li>return true : if the calling package has the appop permission {@link |
| 11853 | * Manifest.permission#USE_ICC_AUTH_WITH_DEVICE_IDENTIFIER} in the manifest </> |
| 11854 | * <li>return true : if any one subscription has the READ_PRIVILEGED_PHONE_STATE |
| 11855 | * permission, the calling package passes a DevicePolicyManager Device Owner / Profile |
| 11856 | * Owner device identifier access check, or the calling package has carrier privileges</> |
| 11857 | * <li>throw SecurityException: if the caller does not meet any of the requirements. |
| 11858 | * </ul> |
| 11859 | */ |
| 11860 | private static boolean checkCallingOrSelfReadDeviceIdentifiersForAnySub(Context context, |
| 11861 | String callingPackage, @Nullable String callingFeatureId, String message) { |
| 11862 | for (Phone phone : PhoneFactory.getPhones()) { |
| 11863 | if (TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(context, |
| 11864 | phone.getSubId(), callingPackage, callingFeatureId, message)) { |
| 11865 | return true; |
| 11866 | } |
| 11867 | } |
| 11868 | return false; |
| 11869 | } |
| 11870 | } |