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; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 195 | import com.android.internal.telephony.emergency.EmergencyNumberTracker; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 196 | import com.android.internal.telephony.euicc.EuiccConnector; |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 197 | import com.android.internal.telephony.ims.ImsResolver; |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 198 | import com.android.internal.telephony.imsphone.ImsPhone; |
| 199 | import com.android.internal.telephony.imsphone.ImsPhoneCallTracker; |
joonhunshin | 3e15424 | 2021-09-17 06:33:39 +0000 | [diff] [blame] | 200 | import com.android.internal.telephony.metrics.RcsStats; |
Pengquan Meng | 6c2dc9f | 2019-02-06 11:12:53 -0800 | [diff] [blame] | 201 | import com.android.internal.telephony.metrics.TelephonyMetrics; |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 202 | import com.android.internal.telephony.subscription.SubscriptionInfoInternal; |
| 203 | import com.android.internal.telephony.subscription.SubscriptionManagerService; |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 204 | import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 205 | import com.android.internal.telephony.uicc.IccIoResult; |
| 206 | import com.android.internal.telephony.uicc.IccUtils; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 207 | import com.android.internal.telephony.uicc.SIMRecords; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 208 | import com.android.internal.telephony.uicc.UiccCard; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 209 | import com.android.internal.telephony.uicc.UiccCardApplication; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 210 | import com.android.internal.telephony.uicc.UiccController; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 211 | import com.android.internal.telephony.uicc.UiccPort; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 212 | import com.android.internal.telephony.uicc.UiccProfile; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 213 | import com.android.internal.telephony.uicc.UiccSlot; |
zoey chen | c730df8 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 214 | import com.android.internal.telephony.util.LocaleUtils; |
Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame] | 215 | import com.android.internal.telephony.util.TelephonyUtils; |
fionaxu | 7ed723d | 2017-05-30 18:58:54 -0700 | [diff] [blame] | 216 | import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 217 | import com.android.internal.util.FunctionalUtils; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 218 | import com.android.internal.util.HexDump; |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 219 | import com.android.phone.callcomposer.CallComposerPictureManager; |
| 220 | import com.android.phone.callcomposer.CallComposerPictureTransfer; |
| 221 | import com.android.phone.callcomposer.ImageData; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 222 | import com.android.phone.settings.PickSmsSubscriptionActivity; |
Sarah Chin | 46355ba | 2022-11-01 23:51:16 -0700 | [diff] [blame] | 223 | import com.android.phone.slice.SlicePurchaseController; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 224 | import com.android.phone.vvm.PhoneAccountHandleConverter; |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 225 | import com.android.phone.vvm.RemoteVvmTaskManager; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 226 | import com.android.phone.vvm.VisualVoicemailSettingsUtil; |
Ta-wei Yen | c890531 | 2017-03-28 11:14:45 -0700 | [diff] [blame] | 227 | import com.android.phone.vvm.VisualVoicemailSmsFilterConfig; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 228 | import com.android.services.telephony.TelecomAccountRegistry; |
| 229 | import com.android.services.telephony.TelephonyConnectionService; |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 230 | import com.android.telephony.Rlog; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 231 | |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 232 | import java.io.ByteArrayOutputStream; |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 233 | import java.io.FileDescriptor; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 234 | import java.io.IOException; |
| 235 | import java.io.InputStream; |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 236 | import java.io.PrintWriter; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 237 | import java.util.ArrayList; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 238 | import java.util.Arrays; |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 239 | import java.util.Collection; |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 240 | import java.util.Collections; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 241 | import java.util.HashMap; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 242 | import java.util.HashSet; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 243 | import java.util.List; |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 244 | import java.util.Locale; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 245 | import java.util.Map; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 246 | import java.util.NoSuchElementException; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 247 | import java.util.Objects; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 248 | import java.util.Set; |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 249 | import java.util.UUID; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 250 | import java.util.concurrent.Executors; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 251 | import java.util.concurrent.atomic.AtomicBoolean; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 252 | import java.util.function.Consumer; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 253 | |
| 254 | /** |
| 255 | * Implementation of the ITelephony interface. |
| 256 | */ |
Santos Cordon | 117fee7 | 2014-05-16 17:56:12 -0700 | [diff] [blame] | 257 | public class PhoneInterfaceManager extends ITelephony.Stub { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 258 | private static final String LOG_TAG = "PhoneInterfaceManager"; |
| 259 | private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2); |
| 260 | private static final boolean DBG_LOC = false; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 261 | private static final boolean DBG_MERGE = false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 262 | |
| 263 | // Message codes used with mMainThreadHandler |
| 264 | private static final int CMD_HANDLE_PIN_MMI = 1; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 265 | private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7; |
| 266 | private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 267 | private static final int CMD_OPEN_CHANNEL = 9; |
| 268 | private static final int EVENT_OPEN_CHANNEL_DONE = 10; |
| 269 | private static final int CMD_CLOSE_CHANNEL = 11; |
| 270 | private static final int EVENT_CLOSE_CHANNEL_DONE = 12; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 271 | private static final int CMD_NV_READ_ITEM = 13; |
| 272 | private static final int EVENT_NV_READ_ITEM_DONE = 14; |
| 273 | private static final int CMD_NV_WRITE_ITEM = 15; |
| 274 | private static final int EVENT_NV_WRITE_ITEM_DONE = 16; |
| 275 | private static final int CMD_NV_WRITE_CDMA_PRL = 17; |
| 276 | private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 277 | private static final int CMD_RESET_MODEM_CONFIG = 19; |
| 278 | private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 279 | private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21; |
| 280 | private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22; |
Sailesh Nepal | 35b5945 | 2014-03-06 09:26:56 -0800 | [diff] [blame] | 281 | private static final int CMD_SEND_ENVELOPE = 25; |
| 282 | private static final int EVENT_SEND_ENVELOPE_DONE = 26; |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 283 | private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27; |
| 284 | private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28; |
Derek Tan | 6b088ee | 2014-09-05 14:15:18 -0700 | [diff] [blame] | 285 | private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29; |
| 286 | private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30; |
| 287 | private static final int CMD_EXCHANGE_SIM_IO = 31; |
| 288 | private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 289 | private static final int CMD_SET_VOICEMAIL_NUMBER = 33; |
| 290 | private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 291 | private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35; |
| 292 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 293 | private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37; |
| 294 | private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 295 | private static final int CMD_PERFORM_NETWORK_SCAN = 39; |
| 296 | private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40; |
| 297 | private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41; |
| 298 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 299 | private static final int CMD_SET_ALLOWED_CARRIERS = 43; |
| 300 | private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44; |
| 301 | private static final int CMD_GET_ALLOWED_CARRIERS = 45; |
| 302 | private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 303 | private static final int CMD_HANDLE_USSD_REQUEST = 47; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 304 | private static final int CMD_GET_FORBIDDEN_PLMNS = 48; |
| 305 | private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 306 | private static final int CMD_SWITCH_SLOTS = 50; |
| 307 | private static final int EVENT_SWITCH_SLOTS_DONE = 51; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 308 | private static final int CMD_GET_NETWORK_SELECTION_MODE = 52; |
| 309 | private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53; |
| 310 | private static final int CMD_GET_CDMA_ROAMING_MODE = 54; |
| 311 | private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55; |
| 312 | private static final int CMD_SET_CDMA_ROAMING_MODE = 56; |
| 313 | private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57; |
| 314 | private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58; |
| 315 | private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 316 | private static final int CMD_GET_ALL_CELL_INFO = 60; |
| 317 | private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61; |
| 318 | private static final int CMD_GET_CELL_LOCATION = 62; |
| 319 | private static final int EVENT_GET_CELL_LOCATION_DONE = 63; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 320 | private static final int CMD_MODEM_REBOOT = 64; |
| 321 | private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 322 | private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66; |
| 323 | private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 324 | private static final int CMD_REQUEST_ENABLE_MODEM = 68; |
| 325 | private static final int EVENT_ENABLE_MODEM_DONE = 69; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 326 | private static final int CMD_GET_MODEM_STATUS = 70; |
| 327 | private static final int EVENT_GET_MODEM_STATUS_DONE = 71; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 328 | private static final int CMD_SET_FORBIDDEN_PLMNS = 72; |
| 329 | private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 330 | private static final int CMD_ERASE_MODEM_CONFIG = 74; |
| 331 | private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75; |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 332 | private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76; |
| 333 | private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77; |
| 334 | private static final int CMD_SET_ICC_LOCK_ENABLED = 78; |
| 335 | private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 336 | private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80; |
| 337 | private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 338 | private static final int MSG_NOTIFY_USER_ACTIVITY = 82; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 339 | private static final int CMD_GET_CALL_FORWARDING = 83; |
| 340 | private static final int EVENT_GET_CALL_FORWARDING_DONE = 84; |
| 341 | private static final int CMD_SET_CALL_FORWARDING = 85; |
| 342 | private static final int EVENT_SET_CALL_FORWARDING_DONE = 86; |
| 343 | private static final int CMD_GET_CALL_WAITING = 87; |
| 344 | private static final int EVENT_GET_CALL_WAITING_DONE = 88; |
| 345 | private static final int CMD_SET_CALL_WAITING = 89; |
| 346 | private static final int EVENT_SET_CALL_WAITING_DONE = 90; |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 347 | private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91; |
| 348 | private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92; |
| 349 | private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93; |
| 350 | private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 351 | private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95; |
| 352 | private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 353 | private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97; |
| 354 | private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 355 | private static final int CMD_SET_DATA_THROTTLING = 99; |
| 356 | private static final int EVENT_SET_DATA_THROTTLING_DONE = 100; |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 357 | private static final int CMD_SET_SIM_POWER = 101; |
| 358 | private static final int EVENT_SET_SIM_POWER_DONE = 102; |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 359 | private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103; |
| 360 | private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104; |
| 361 | private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105; |
| 362 | private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 363 | private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107; |
| 364 | 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] | 365 | private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 366 | private static final int CMD_GET_SLICING_CONFIG = 110; |
| 367 | private static final int EVENT_GET_SLICING_CONFIG_DONE = 111; |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 368 | private static final int CMD_ERASE_DATA_SHARED_PREFERENCES = 112; |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 369 | private static final int CMD_ENABLE_VONR = 113; |
| 370 | private static final int EVENT_ENABLE_VONR_DONE = 114; |
| 371 | private static final int CMD_IS_VONR_ENABLED = 115; |
| 372 | private static final int EVENT_IS_VONR_ENABLED_DONE = 116; |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 373 | private static final int CMD_PURCHASE_PREMIUM_CAPABILITY = 117; |
| 374 | private static final int EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE = 118; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 375 | |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 376 | // Parameters of select command. |
| 377 | private static final int SELECT_COMMAND = 0xA4; |
| 378 | private static final int SELECT_P1 = 0x04; |
| 379 | private static final int SELECT_P2 = 0; |
| 380 | private static final int SELECT_P3 = 0x10; |
| 381 | |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 382 | // Toggling null cipher and integrity support was added in IRadioNetwork 2.1 |
| 383 | private static final int MIN_NULL_CIPHER_AND_INTEGRITY_VERSION = 201; |
| 384 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 385 | /** The singleton instance. */ |
| 386 | private static PhoneInterfaceManager sInstance; |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 387 | private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 388 | |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 389 | private PhoneGlobals mApp; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 390 | private CallManager mCM; |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 391 | private ImsResolver mImsResolver; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 392 | private UserManager mUserManager; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 393 | private AppOpsManager mAppOps; |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 394 | private PackageManager mPm; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 395 | private MainThreadHandler mMainThreadHandler; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 396 | private SubscriptionController mSubscriptionController; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 397 | private SharedPreferences mTelephonySharedPreferences; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 398 | private PhoneConfigurationManager mPhoneConfigurationManager; |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 399 | private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities; |
Gil Cukierman | 6dac5eb | 2022-09-19 16:09:04 +0000 | [diff] [blame] | 400 | private final Telephony2gUpdater mTelephony2gUpdater; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 401 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 402 | /** User Activity */ |
| 403 | private AtomicBoolean mNotifyUserActivity; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 404 | private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200; |
| 405 | |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 406 | private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>(); |
| 407 | |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 408 | private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_"; |
| 409 | private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_"; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 410 | private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_"; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 411 | private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_"; |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 412 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 413 | // String to store multi SIM allowed |
| 414 | private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted"; |
| 415 | |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 416 | // The AID of ISD-R. |
| 417 | private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100"; |
| 418 | |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 419 | private NetworkScanRequestTracker mNetworkScanRequestTracker; |
| 420 | |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 421 | private static final int TYPE_ALLOCATION_CODE_LENGTH = 8; |
| 422 | private static final int MANUFACTURER_CODE_LENGTH = 8; |
| 423 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 424 | private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1; |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 425 | 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] | 426 | |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 427 | private static final String PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID = |
| 428 | "24bf97a6-e8a6-44d8-a6a4-255d7548733c"; |
| 429 | |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 430 | /** |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 431 | * Experiment flag to enable erase modem config on reset network, default value is false |
| 432 | */ |
| 433 | public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED = |
| 434 | "reset_network_erase_modem_config_enabled"; |
| 435 | |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 436 | 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] | 437 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 438 | /** |
| 439 | * With support for MEP(multiple enabled profile) in Android T, a SIM card can have more than |
| 440 | * one ICCID active at the same time. |
| 441 | * Apps should use below API signatures if targeting SDK is T and beyond. |
| 442 | * |
| 443 | * @hide |
| 444 | */ |
| 445 | @ChangeId |
| 446 | @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU) |
| 447 | public static final long GET_API_SIGNATURES_FROM_UICC_PORT_INFO = 202110963L; |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 448 | |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 449 | /** |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 450 | * Apps targeting on Android T and beyond will get exception whenever icc close channel |
| 451 | * operation fails. |
| 452 | */ |
| 453 | @ChangeId |
| 454 | @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU) |
| 455 | public static final long ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE = 208739934L; |
| 456 | |
| 457 | /** |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 458 | * A request object to use for transmitting data to an ICC. |
| 459 | */ |
| 460 | private static final class IccAPDUArgument { |
| 461 | public int channel, cla, command, p1, p2, p3; |
| 462 | public String data; |
| 463 | |
| 464 | public IccAPDUArgument(int channel, int cla, int command, |
| 465 | int p1, int p2, int p3, String data) { |
| 466 | this.channel = channel; |
| 467 | this.cla = cla; |
| 468 | this.command = command; |
| 469 | this.p1 = p1; |
| 470 | this.p2 = p2; |
| 471 | this.p3 = p3; |
| 472 | this.data = data; |
| 473 | } |
| 474 | } |
| 475 | |
| 476 | /** |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 477 | * A request object to use for transmitting data to an ICC. |
| 478 | */ |
| 479 | private static final class ManualNetworkSelectionArgument { |
| 480 | public OperatorInfo operatorInfo; |
| 481 | public boolean persistSelection; |
| 482 | |
| 483 | public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) { |
| 484 | this.operatorInfo = operatorInfo; |
| 485 | this.persistSelection = persistSelection; |
| 486 | } |
| 487 | } |
| 488 | |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 489 | private static final class PurchasePremiumCapabilityArgument { |
| 490 | public @TelephonyManager.PremiumCapability int capability; |
| 491 | public @NonNull String appName; |
| 492 | public @NonNull IIntegerConsumer callback; |
| 493 | |
| 494 | PurchasePremiumCapabilityArgument(@TelephonyManager.PremiumCapability int capability, |
| 495 | @NonNull String appName, @NonNull IIntegerConsumer callback) { |
| 496 | this.capability = capability; |
| 497 | this.appName = appName; |
| 498 | this.callback = callback; |
| 499 | } |
| 500 | } |
| 501 | |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 502 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 503 | * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the |
| 504 | * request after sending. The main thread will notify the request when it is complete. |
| 505 | */ |
| 506 | private static final class MainThreadRequest { |
| 507 | /** The argument to use for the request */ |
| 508 | public Object argument; |
| 509 | /** The result of the request that is run on the main thread */ |
| 510 | public Object result; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 511 | // The subscriber id that this request applies to. Defaults to |
| 512 | // SubscriptionManager.INVALID_SUBSCRIPTION_ID |
| 513 | public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 514 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 515 | // In cases where subId is unavailable, the caller needs to specify the phone. |
| 516 | public Phone phone; |
| 517 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 518 | public WorkSource workSource; |
| 519 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 520 | public MainThreadRequest(Object argument) { |
| 521 | this.argument = argument; |
| 522 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 523 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 524 | MainThreadRequest(Object argument, Phone phone, WorkSource workSource) { |
| 525 | this.argument = argument; |
| 526 | if (phone != null) { |
| 527 | this.phone = phone; |
| 528 | } |
| 529 | this.workSource = workSource; |
| 530 | } |
| 531 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 532 | MainThreadRequest(Object argument, Integer subId, WorkSource workSource) { |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 533 | this.argument = argument; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 534 | if (subId != null) { |
| 535 | this.subId = subId; |
| 536 | } |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 537 | this.workSource = workSource; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 538 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 539 | } |
| 540 | |
Sailesh Nepal | cc0375f | 2013-11-13 09:15:18 -0800 | [diff] [blame] | 541 | private static final class IncomingThirdPartyCallArgs { |
| 542 | public final ComponentName component; |
| 543 | public final String callId; |
| 544 | public final String callerDisplayName; |
| 545 | |
| 546 | public IncomingThirdPartyCallArgs(ComponentName component, String callId, |
| 547 | String callerDisplayName) { |
| 548 | this.component = component; |
| 549 | this.callId = callId; |
| 550 | this.callerDisplayName = callerDisplayName; |
| 551 | } |
| 552 | } |
| 553 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 554 | /** |
| 555 | * A handler that processes messages on the main thread in the phone process. Since many |
| 556 | * of the Phone calls are not thread safe this is needed to shuttle the requests from the |
| 557 | * inbound binder threads to the main thread in the phone process. The Binder thread |
| 558 | * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting |
| 559 | * on, which will be notified when the operation completes and will contain the result of the |
| 560 | * request. |
| 561 | * |
| 562 | * <p>If a MainThreadRequest object is provided in the msg.obj field, |
| 563 | * note that request.result must be set to something non-null for the calling thread to |
| 564 | * unblock. |
| 565 | */ |
| 566 | private final class MainThreadHandler extends Handler { |
| 567 | @Override |
| 568 | public void handleMessage(Message msg) { |
| 569 | MainThreadRequest request; |
| 570 | Message onCompleted; |
| 571 | AsyncResult ar; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 572 | UiccPort uiccPort; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 573 | IccAPDUArgument iccArgument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 574 | final Phone defaultPhone = getDefaultPhone(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 575 | |
| 576 | switch (msg.what) { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 577 | case CMD_HANDLE_USSD_REQUEST: { |
| 578 | request = (MainThreadRequest) msg.obj; |
| 579 | final Phone phone = getPhoneFromRequest(request); |
| 580 | Pair<String, ResultReceiver> ussdObject = (Pair) request.argument; |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 581 | String ussdRequest = ussdObject.first; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 582 | ResultReceiver wrappedCallback = ussdObject.second; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 583 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 584 | if (!isUssdApiAllowed(request.subId)) { |
| 585 | // Carrier does not support use of this API, return failure. |
| 586 | Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis."); |
| 587 | UssdResponse response = new UssdResponse(ussdRequest, null); |
| 588 | Bundle returnData = new Bundle(); |
| 589 | returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response); |
| 590 | wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 591 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 592 | request.result = true; |
| 593 | notifyRequester(request); |
| 594 | return; |
| 595 | } |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 596 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 597 | try { |
| 598 | request.result = phone != null |
| 599 | ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false; |
| 600 | } catch (CallStateException cse) { |
| 601 | request.result = false; |
| 602 | } |
| 603 | // Wake up the requesting thread |
| 604 | notifyRequester(request); |
| 605 | break; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 606 | } |
| 607 | |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 608 | case CMD_HANDLE_PIN_MMI: { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 609 | request = (MainThreadRequest) msg.obj; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 610 | final Phone phone = getPhoneFromRequest(request); |
| 611 | request.result = phone != null ? |
| 612 | getPhoneFromRequest(request).handlePinMmi((String) request.argument) |
| 613 | : false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 614 | // Wake up the requesting thread |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 615 | notifyRequester(request); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 616 | break; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 617 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 618 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 619 | case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 620 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 621 | iccArgument = (IccAPDUArgument) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 622 | uiccPort = getUiccPortFromRequest(request); |
| 623 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 624 | loge("iccTransmitApduLogicalChannel: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 625 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 626 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 627 | } else { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 628 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE, |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 629 | request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 630 | uiccPort.iccTransmitApduLogicalChannel( |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 631 | iccArgument.channel, iccArgument.cla, iccArgument.command, |
| 632 | iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data, |
| 633 | onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 634 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 635 | break; |
| 636 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 637 | case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 638 | ar = (AsyncResult) msg.obj; |
| 639 | request = (MainThreadRequest) ar.userObj; |
| 640 | if (ar.exception == null && ar.result != null) { |
| 641 | request.result = ar.result; |
| 642 | } else { |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 643 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 644 | if (ar.result == null) { |
| 645 | loge("iccTransmitApduLogicalChannel: Empty response"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 646 | } else if (ar.exception instanceof CommandException) { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 647 | loge("iccTransmitApduLogicalChannel: CommandException: " + |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 648 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 649 | } else { |
| 650 | loge("iccTransmitApduLogicalChannel: Unknown exception"); |
| 651 | } |
| 652 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 653 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 654 | break; |
| 655 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 656 | case CMD_TRANSMIT_APDU_BASIC_CHANNEL: |
| 657 | request = (MainThreadRequest) msg.obj; |
| 658 | iccArgument = (IccAPDUArgument) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 659 | uiccPort = getUiccPortFromRequest(request); |
| 660 | if (uiccPort == null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 661 | loge("iccTransmitApduBasicChannel: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 662 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 663 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 664 | } else { |
| 665 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE, |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 666 | request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 667 | uiccPort.iccTransmitApduBasicChannel( |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 668 | iccArgument.cla, iccArgument.command, iccArgument.p1, |
| 669 | iccArgument.p2, |
| 670 | iccArgument.p3, iccArgument.data, onCompleted); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 671 | } |
| 672 | break; |
| 673 | |
| 674 | case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE: |
| 675 | ar = (AsyncResult) msg.obj; |
| 676 | request = (MainThreadRequest) ar.userObj; |
| 677 | if (ar.exception == null && ar.result != null) { |
| 678 | request.result = ar.result; |
| 679 | } else { |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 680 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 681 | if (ar.result == null) { |
| 682 | loge("iccTransmitApduBasicChannel: Empty response"); |
| 683 | } else if (ar.exception instanceof CommandException) { |
| 684 | loge("iccTransmitApduBasicChannel: CommandException: " + |
| 685 | ar.exception); |
| 686 | } else { |
| 687 | loge("iccTransmitApduBasicChannel: Unknown exception"); |
| 688 | } |
| 689 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 690 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 691 | break; |
| 692 | |
| 693 | case CMD_EXCHANGE_SIM_IO: |
| 694 | request = (MainThreadRequest) msg.obj; |
| 695 | iccArgument = (IccAPDUArgument) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 696 | uiccPort = getUiccPortFromRequest(request); |
| 697 | if (uiccPort == null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 698 | loge("iccExchangeSimIO: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 699 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 700 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 701 | } else { |
| 702 | onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE, |
| 703 | request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 704 | uiccPort.iccExchangeSimIO(iccArgument.cla, /* fileID */ |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 705 | iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3, |
| 706 | iccArgument.data, onCompleted); |
| 707 | } |
| 708 | break; |
| 709 | |
| 710 | case EVENT_EXCHANGE_SIM_IO_DONE: |
| 711 | ar = (AsyncResult) msg.obj; |
| 712 | request = (MainThreadRequest) ar.userObj; |
| 713 | if (ar.exception == null && ar.result != null) { |
| 714 | request.result = ar.result; |
| 715 | } else { |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 716 | request.result = new IccIoResult(0x6f, 0, (byte[]) null); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 717 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 718 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 719 | break; |
| 720 | |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 721 | case CMD_SEND_ENVELOPE: |
| 722 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 723 | uiccPort = getUiccPortFromRequest(request); |
| 724 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 725 | loge("sendEnvelopeWithStatus: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 726 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 727 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 728 | } else { |
| 729 | onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 730 | uiccPort.sendEnvelopeWithStatus((String) request.argument, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 731 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 732 | break; |
| 733 | |
| 734 | case EVENT_SEND_ENVELOPE_DONE: |
| 735 | ar = (AsyncResult) msg.obj; |
| 736 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 737 | if (ar.exception == null && ar.result != null) { |
| 738 | request.result = ar.result; |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 739 | } else { |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 740 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 741 | if (ar.result == null) { |
| 742 | loge("sendEnvelopeWithStatus: Empty response"); |
| 743 | } else if (ar.exception instanceof CommandException) { |
| 744 | loge("sendEnvelopeWithStatus: CommandException: " + |
| 745 | ar.exception); |
| 746 | } else { |
| 747 | loge("sendEnvelopeWithStatus: exception:" + ar.exception); |
| 748 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 749 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 750 | notifyRequester(request); |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 751 | break; |
| 752 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 753 | case CMD_OPEN_CHANNEL: |
| 754 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 755 | uiccPort = getUiccPortFromRequest(request); |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 756 | IccLogicalChannelRequest openChannelRequest = |
| 757 | (IccLogicalChannelRequest) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 758 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 759 | loge("iccOpenLogicalChannel: No UICC"); |
Shishir Agrawal | fc0492a | 2016-02-17 11:15:33 -0800 | [diff] [blame] | 760 | request.result = new IccOpenLogicalChannelResponse(-1, |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 761 | IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 762 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 763 | } else { |
| 764 | onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request); |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 765 | uiccPort.iccOpenLogicalChannel(openChannelRequest.aid, |
| 766 | openChannelRequest.p2, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 767 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 768 | break; |
| 769 | |
| 770 | case EVENT_OPEN_CHANNEL_DONE: |
| 771 | ar = (AsyncResult) msg.obj; |
| 772 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 773 | IccOpenLogicalChannelResponse openChannelResp; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 774 | if (ar.exception == null && ar.result != null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 775 | int[] result = (int[]) ar.result; |
| 776 | int channelId = result[0]; |
| 777 | byte[] selectResponse = null; |
| 778 | if (result.length > 1) { |
| 779 | selectResponse = new byte[result.length - 1]; |
| 780 | for (int i = 1; i < result.length; ++i) { |
| 781 | selectResponse[i - 1] = (byte) result[i]; |
| 782 | } |
| 783 | } |
| 784 | openChannelResp = new IccOpenLogicalChannelResponse(channelId, |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 785 | IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse); |
Rambo Wang | 3b77c4c | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 786 | |
| 787 | uiccPort = getUiccPortFromRequest(request); |
Rambo Wang | e53e07d | 2022-05-10 13:01:13 -0700 | [diff] [blame] | 788 | if (uiccPort == null) { |
| 789 | loge("EVENT_OPEN_CHANNEL_DONE: UiccPort is null"); |
| 790 | } else { |
| 791 | IccLogicalChannelRequest channelRequest = |
| 792 | (IccLogicalChannelRequest) request.argument; |
| 793 | channelRequest.channel = channelId; |
| 794 | uiccPort.onLogicalChannelOpened(channelRequest); |
| 795 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 796 | } else { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 797 | if (ar.result == null) { |
| 798 | loge("iccOpenLogicalChannel: Empty response"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 799 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 800 | if (ar.exception != null) { |
| 801 | loge("iccOpenLogicalChannel: Exception: " + ar.exception); |
| 802 | } |
| 803 | |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 804 | int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 805 | if (ar.exception instanceof CommandException) { |
| 806 | CommandException.Error error = |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 807 | ((CommandException) (ar.exception)).getCommandError(); |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 808 | if (error == CommandException.Error.MISSING_RESOURCE) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 809 | errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 810 | } else if (error == CommandException.Error.NO_SUCH_ELEMENT) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 811 | errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 812 | } |
| 813 | } |
| 814 | openChannelResp = new IccOpenLogicalChannelResponse( |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 815 | IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 816 | } |
Shishir Agrawal | 82c8a46 | 2014-07-31 18:13:17 -0700 | [diff] [blame] | 817 | request.result = openChannelResp; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 818 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 819 | break; |
| 820 | |
| 821 | case CMD_CLOSE_CHANNEL: |
| 822 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 823 | uiccPort = getUiccPortFromRequest(request); |
| 824 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 825 | loge("iccCloseLogicalChannel: No UICC"); |
Chen Xu | a8f0dff | 2022-02-12 00:34:15 -0800 | [diff] [blame] | 826 | request.result = new IllegalArgumentException( |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 827 | "iccCloseLogicalChannel: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 828 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 829 | } else { |
| 830 | onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 831 | uiccPort.iccCloseLogicalChannel((Integer) request.argument, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 832 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 833 | break; |
| 834 | |
| 835 | case EVENT_CLOSE_CHANNEL_DONE: |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 836 | ar = (AsyncResult) msg.obj; |
| 837 | request = (MainThreadRequest) ar.userObj; |
| 838 | if (ar.exception == null) { |
| 839 | request.result = true; |
Rambo Wang | 3b77c4c | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 840 | uiccPort = getUiccPortFromRequest(request); |
Rambo Wang | e53e07d | 2022-05-10 13:01:13 -0700 | [diff] [blame] | 841 | if (uiccPort == null) { |
| 842 | loge("EVENT_CLOSE_CHANNEL_DONE: UiccPort is null"); |
| 843 | } else { |
| 844 | final int channelId = (Integer) request.argument; |
| 845 | uiccPort.onLogicalChannelClosed(channelId); |
| 846 | } |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 847 | } else { |
| 848 | request.result = false; |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 849 | Exception exception = null; |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 850 | if (ar.exception instanceof CommandException) { |
| 851 | loge("iccCloseLogicalChannel: CommandException: " + ar.exception); |
| 852 | CommandException.Error error = |
| 853 | ((CommandException) (ar.exception)).getCommandError(); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 854 | if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 855 | // should only throw exceptions from the binder threads. |
| 856 | exception = new IllegalArgumentException( |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 857 | "iccCloseLogicalChannel: invalid argument "); |
| 858 | } |
| 859 | } else { |
| 860 | loge("iccCloseLogicalChannel: Unknown exception"); |
| 861 | } |
Chen Xu | a8f0dff | 2022-02-12 00:34:15 -0800 | [diff] [blame] | 862 | request.result = (exception != null) ? exception : |
| 863 | new IllegalStateException( |
| 864 | "exception from modem to close iccLogical Channel"); |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 865 | } |
| 866 | notifyRequester(request); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 867 | break; |
| 868 | |
| 869 | case CMD_NV_READ_ITEM: |
| 870 | request = (MainThreadRequest) msg.obj; |
| 871 | onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 872 | defaultPhone.nvReadItem((Integer) request.argument, onCompleted, |
| 873 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 874 | break; |
| 875 | |
| 876 | case EVENT_NV_READ_ITEM_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 877 | ar = (AsyncResult) msg.obj; |
| 878 | request = (MainThreadRequest) ar.userObj; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 879 | if (ar.exception == null && ar.result != null) { |
| 880 | request.result = ar.result; // String |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 881 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 882 | request.result = ""; |
| 883 | if (ar.result == null) { |
| 884 | loge("nvReadItem: Empty response"); |
| 885 | } else if (ar.exception instanceof CommandException) { |
| 886 | loge("nvReadItem: CommandException: " + |
| 887 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 888 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 889 | loge("nvReadItem: Unknown exception"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 890 | } |
| 891 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 892 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 893 | break; |
| 894 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 895 | case CMD_NV_WRITE_ITEM: |
| 896 | request = (MainThreadRequest) msg.obj; |
| 897 | onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request); |
| 898 | Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 899 | defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 900 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 901 | break; |
| 902 | |
| 903 | case EVENT_NV_WRITE_ITEM_DONE: |
| 904 | handleNullReturnEvent(msg, "nvWriteItem"); |
| 905 | break; |
| 906 | |
| 907 | case CMD_NV_WRITE_CDMA_PRL: |
| 908 | request = (MainThreadRequest) msg.obj; |
| 909 | onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 910 | defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 911 | break; |
| 912 | |
| 913 | case EVENT_NV_WRITE_CDMA_PRL_DONE: |
| 914 | handleNullReturnEvent(msg, "nvWriteCdmaPrl"); |
| 915 | break; |
| 916 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 917 | case CMD_RESET_MODEM_CONFIG: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 918 | request = (MainThreadRequest) msg.obj; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 919 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 920 | defaultPhone.resetModemConfig(onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 921 | break; |
| 922 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 923 | case EVENT_RESET_MODEM_CONFIG_DONE: |
| 924 | handleNullReturnEvent(msg, "resetModemConfig"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 925 | break; |
| 926 | |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 927 | case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: { |
| 928 | request = (MainThreadRequest) msg.obj; |
| 929 | onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE, |
| 930 | request); |
| 931 | Phone phone = getPhoneFromRequest(request); |
| 932 | if (phone != null) { |
| 933 | phone.isNrDualConnectivityEnabled(onCompleted, request.workSource); |
| 934 | } else { |
| 935 | loge("isNRDualConnectivityEnabled: No phone object"); |
| 936 | request.result = false; |
| 937 | notifyRequester(request); |
| 938 | } |
| 939 | break; |
| 940 | } |
| 941 | |
| 942 | case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE: |
| 943 | ar = (AsyncResult) msg.obj; |
| 944 | request = (MainThreadRequest) ar.userObj; |
| 945 | if (ar.exception == null && ar.result != null) { |
| 946 | request.result = ar.result; |
| 947 | } else { |
| 948 | // request.result must be set to something non-null |
| 949 | // for the calling thread to unblock |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 950 | if (ar.result != null) { |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 951 | request.result = ar.result; |
| 952 | } else { |
| 953 | request.result = false; |
| 954 | } |
| 955 | if (ar.result == null) { |
| 956 | loge("isNRDualConnectivityEnabled: Empty response"); |
| 957 | } else if (ar.exception instanceof CommandException) { |
| 958 | loge("isNRDualConnectivityEnabled: CommandException: " |
| 959 | + ar.exception); |
| 960 | } else { |
| 961 | loge("isNRDualConnectivityEnabled: Unknown exception"); |
| 962 | } |
| 963 | } |
| 964 | notifyRequester(request); |
| 965 | break; |
| 966 | |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 967 | case CMD_IS_VONR_ENABLED: { |
| 968 | request = (MainThreadRequest) msg.obj; |
| 969 | onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE, |
| 970 | request); |
| 971 | Phone phone = getPhoneFromRequest(request); |
| 972 | if (phone != null) { |
| 973 | phone.isVoNrEnabled(onCompleted, request.workSource); |
| 974 | } else { |
| 975 | loge("isVoNrEnabled: No phone object"); |
| 976 | request.result = false; |
| 977 | notifyRequester(request); |
| 978 | } |
| 979 | break; |
| 980 | } |
| 981 | |
| 982 | case EVENT_IS_VONR_ENABLED_DONE: |
| 983 | ar = (AsyncResult) msg.obj; |
| 984 | request = (MainThreadRequest) ar.userObj; |
| 985 | if (ar.exception == null && ar.result != null) { |
| 986 | request.result = ar.result; |
| 987 | } else { |
| 988 | // request.result must be set to something non-null |
| 989 | // for the calling thread to unblock |
| 990 | if (ar.result != null) { |
| 991 | request.result = ar.result; |
| 992 | } else { |
| 993 | request.result = false; |
| 994 | } |
| 995 | if (ar.result == null) { |
| 996 | loge("isVoNrEnabled: Empty response"); |
| 997 | } else if (ar.exception instanceof CommandException) { |
| 998 | loge("isVoNrEnabled: CommandException: " |
| 999 | + ar.exception); |
| 1000 | } else { |
| 1001 | loge("isVoNrEnabled: Unknown exception"); |
| 1002 | } |
| 1003 | } |
| 1004 | notifyRequester(request); |
| 1005 | break; |
| 1006 | |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 1007 | case CMD_ENABLE_NR_DUAL_CONNECTIVITY: { |
| 1008 | request = (MainThreadRequest) msg.obj; |
| 1009 | onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request); |
| 1010 | Phone phone = getPhoneFromRequest(request); |
| 1011 | if (phone != null) { |
| 1012 | phone.setNrDualConnectivityState((int) request.argument, onCompleted, |
| 1013 | request.workSource); |
| 1014 | } else { |
| 1015 | loge("enableNrDualConnectivity: No phone object"); |
| 1016 | request.result = |
| 1017 | TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE; |
| 1018 | notifyRequester(request); |
| 1019 | } |
| 1020 | break; |
| 1021 | } |
| 1022 | |
| 1023 | case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: { |
| 1024 | ar = (AsyncResult) msg.obj; |
| 1025 | request = (MainThreadRequest) ar.userObj; |
| 1026 | if (ar.exception == null) { |
| 1027 | request.result = |
| 1028 | TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS; |
| 1029 | } else { |
| 1030 | request.result = |
| 1031 | TelephonyManager |
| 1032 | .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR; |
| 1033 | if (ar.exception instanceof CommandException) { |
| 1034 | CommandException.Error error = |
| 1035 | ((CommandException) (ar.exception)).getCommandError(); |
| 1036 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1037 | request.result = |
| 1038 | TelephonyManager |
| 1039 | .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE; |
Sooraj Sasindran | 2965416 | 2021-03-03 23:00:01 +0000 | [diff] [blame] | 1040 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1041 | request.result = |
| 1042 | TelephonyManager |
| 1043 | .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED; |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 1044 | } |
| 1045 | loge("enableNrDualConnectivity" + ": CommandException: " |
| 1046 | + ar.exception); |
| 1047 | } else { |
| 1048 | loge("enableNrDualConnectivity" + ": Unknown exception"); |
| 1049 | } |
| 1050 | } |
| 1051 | notifyRequester(request); |
| 1052 | break; |
| 1053 | } |
| 1054 | |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 1055 | case CMD_ENABLE_VONR: { |
| 1056 | request = (MainThreadRequest) msg.obj; |
| 1057 | onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request); |
| 1058 | Phone phone = getPhoneFromRequest(request); |
| 1059 | if (phone != null) { |
| 1060 | phone.setVoNrEnabled((boolean) request.argument, onCompleted, |
| 1061 | request.workSource); |
| 1062 | } else { |
| 1063 | loge("setVoNrEnabled: No phone object"); |
| 1064 | request.result = |
| 1065 | TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE; |
| 1066 | notifyRequester(request); |
| 1067 | } |
| 1068 | break; |
| 1069 | } |
| 1070 | |
| 1071 | case EVENT_ENABLE_VONR_DONE: { |
| 1072 | ar = (AsyncResult) msg.obj; |
| 1073 | request = (MainThreadRequest) ar.userObj; |
| 1074 | if (ar.exception == null) { |
| 1075 | request.result = TelephonyManager.ENABLE_VONR_SUCCESS; |
| 1076 | } else { |
| 1077 | request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR; |
| 1078 | if (ar.exception instanceof CommandException) { |
| 1079 | CommandException.Error error = |
| 1080 | ((CommandException) (ar.exception)).getCommandError(); |
| 1081 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1082 | request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE; |
| 1083 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1084 | request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED; |
| 1085 | } else { |
| 1086 | request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR; |
| 1087 | } |
| 1088 | loge("setVoNrEnabled" + ": CommandException: " |
| 1089 | + ar.exception); |
| 1090 | } else { |
| 1091 | loge("setVoNrEnabled" + ": Unknown exception"); |
| 1092 | } |
| 1093 | } |
| 1094 | notifyRequester(request); |
| 1095 | break; |
| 1096 | } |
| 1097 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1098 | case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1099 | request = (MainThreadRequest) msg.obj; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1100 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE, |
| 1101 | request); |
| 1102 | getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1103 | break; |
| 1104 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1105 | case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1106 | ar = (AsyncResult) msg.obj; |
| 1107 | request = (MainThreadRequest) ar.userObj; |
| 1108 | if (ar.exception == null && ar.result != null) { |
| 1109 | request.result = ar.result; // Integer |
| 1110 | } else { |
Nazish Tabassum | e8ba43a | 2020-07-28 14:49:25 +0530 | [diff] [blame] | 1111 | // request.result must be set to something non-null |
| 1112 | // for the calling thread to unblock |
| 1113 | request.result = new int[]{-1}; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1114 | if (ar.result == null) { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1115 | loge("getAllowedNetworkTypesBitmask: Empty response"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1116 | } else if (ar.exception instanceof CommandException) { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1117 | loge("getAllowedNetworkTypesBitmask: CommandException: " |
| 1118 | + ar.exception); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1119 | } else { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1120 | loge("getAllowedNetworkTypesBitmask: Unknown exception"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1121 | } |
| 1122 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1123 | notifyRequester(request); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1124 | break; |
| 1125 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1126 | case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1127 | request = (MainThreadRequest) msg.obj; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1128 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE, |
| 1129 | request); |
| 1130 | Pair<Integer, Long> reasonWithNetworkTypes = |
| 1131 | (Pair<Integer, Long>) request.argument; |
| 1132 | getPhoneFromRequest(request).setAllowedNetworkTypes( |
| 1133 | reasonWithNetworkTypes.first, |
| 1134 | reasonWithNetworkTypes.second, |
| 1135 | onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1136 | break; |
| 1137 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1138 | case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE: |
| 1139 | handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1140 | break; |
| 1141 | |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 1142 | case CMD_INVOKE_OEM_RIL_REQUEST_RAW: |
| 1143 | request = (MainThreadRequest)msg.obj; |
| 1144 | onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1145 | defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 1146 | break; |
| 1147 | |
| 1148 | case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE: |
| 1149 | ar = (AsyncResult)msg.obj; |
| 1150 | request = (MainThreadRequest)ar.userObj; |
| 1151 | request.result = ar; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1152 | notifyRequester(request); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 1153 | break; |
| 1154 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1155 | case CMD_SET_VOICEMAIL_NUMBER: |
| 1156 | request = (MainThreadRequest) msg.obj; |
| 1157 | onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request); |
| 1158 | Pair<String, String> tagNum = (Pair<String, String>) request.argument; |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1159 | getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second, |
| 1160 | onCompleted); |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1161 | break; |
| 1162 | |
| 1163 | case EVENT_SET_VOICEMAIL_NUMBER_DONE: |
| 1164 | handleNullReturnEvent(msg, "setVoicemailNumber"); |
| 1165 | break; |
| 1166 | |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 1167 | case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC: |
| 1168 | request = (MainThreadRequest) msg.obj; |
| 1169 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE, |
| 1170 | request); |
| 1171 | getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted); |
| 1172 | break; |
| 1173 | |
| 1174 | case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE: |
| 1175 | handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic"); |
| 1176 | break; |
| 1177 | |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1178 | case CMD_PERFORM_NETWORK_SCAN: |
| 1179 | request = (MainThreadRequest) msg.obj; |
| 1180 | onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request); |
| 1181 | getPhoneFromRequest(request).getAvailableNetworks(onCompleted); |
| 1182 | break; |
| 1183 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1184 | case CMD_GET_CALL_FORWARDING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1185 | request = (MainThreadRequest) msg.obj; |
| 1186 | onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1187 | Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args = |
| 1188 | (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>) |
| 1189 | request.argument; |
| 1190 | int callForwardingReason = args.first; |
| 1191 | request.phone.getCallForwardingOption(callForwardingReason, onCompleted); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1192 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1193 | } |
| 1194 | case EVENT_GET_CALL_FORWARDING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1195 | ar = (AsyncResult) msg.obj; |
| 1196 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1197 | TelephonyManager.CallForwardingInfoCallback callback = |
| 1198 | ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>) |
| 1199 | request.argument).second; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1200 | if (ar.exception == null && ar.result != null) { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1201 | CallForwardingInfo callForwardingInfo = null; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1202 | CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result; |
| 1203 | for (CallForwardInfo callForwardInfo : callForwardInfos) { |
| 1204 | // Service Class is a bit mask per 3gpp 27.007. Search for |
| 1205 | // any service for voice call. |
| 1206 | if ((callForwardInfo.serviceClass |
| 1207 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0) { |
Yuchen Dong | 69cc141 | 2021-09-27 20:27:01 +0800 | [diff] [blame] | 1208 | callForwardingInfo = new CallForwardingInfo( |
| 1209 | callForwardInfo.status |
| 1210 | == CommandsInterface.CF_ACTION_ENABLE, |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1211 | callForwardInfo.reason, |
| 1212 | callForwardInfo.number, |
| 1213 | callForwardInfo.timeSeconds); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1214 | break; |
| 1215 | } |
| 1216 | } |
| 1217 | // Didn't find a call forward info for voice call. |
| 1218 | if (callForwardingInfo == null) { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1219 | callForwardingInfo = new CallForwardingInfo(false /* enabled */, |
| 1220 | 0 /* reason */, null /* number */, 0 /* timeout */); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1221 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1222 | callback.onCallForwardingInfoAvailable(callForwardingInfo); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1223 | } else { |
| 1224 | if (ar.result == null) { |
| 1225 | loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response"); |
| 1226 | } |
| 1227 | if (ar.exception != null) { |
| 1228 | loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception); |
| 1229 | } |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1230 | int errorCode = TelephonyManager |
| 1231 | .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1232 | if (ar.exception instanceof CommandException) { |
| 1233 | CommandException.Error error = |
| 1234 | ((CommandException) (ar.exception)).getCommandError(); |
| 1235 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1236 | errorCode = TelephonyManager |
| 1237 | .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1238 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1239 | errorCode = TelephonyManager |
| 1240 | .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1241 | } |
| 1242 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1243 | callback.onError(errorCode); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1244 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1245 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1246 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1247 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1248 | case CMD_SET_CALL_FORWARDING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1249 | request = (MainThreadRequest) msg.obj; |
| 1250 | onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1251 | request = (MainThreadRequest) msg.obj; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1252 | CallForwardingInfo callForwardingInfoToSet = |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1253 | ((Pair<CallForwardingInfo, Consumer<Integer>>) |
| 1254 | request.argument).first; |
| 1255 | request.phone.setCallForwardingOption( |
| 1256 | callForwardingInfoToSet.isEnabled() |
Calvin Pan | 258f1f7 | 2021-07-28 21:46:56 +0800 | [diff] [blame] | 1257 | ? CommandsInterface.CF_ACTION_REGISTRATION |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1258 | : CommandsInterface.CF_ACTION_DISABLE, |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1259 | callForwardingInfoToSet.getReason(), |
| 1260 | callForwardingInfoToSet.getNumber(), |
| 1261 | callForwardingInfoToSet.getTimeoutSeconds(), onCompleted); |
| 1262 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1263 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1264 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1265 | case EVENT_SET_CALL_FORWARDING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1266 | ar = (AsyncResult) msg.obj; |
| 1267 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1268 | Consumer<Integer> callback = |
| 1269 | ((Pair<CallForwardingInfo, Consumer<Integer>>) |
| 1270 | request.argument).second; |
| 1271 | if (ar.exception != null) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1272 | loge("setCallForwarding exception: " + ar.exception); |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1273 | int errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1274 | .RESULT_ERROR_UNKNOWN; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1275 | if (ar.exception instanceof CommandException) { |
| 1276 | CommandException.Error error = |
| 1277 | ((CommandException) (ar.exception)).getCommandError(); |
| 1278 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1279 | errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1280 | .RESULT_ERROR_FDN_CHECK_FAILURE; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1281 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1282 | errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1283 | .RESULT_ERROR_NOT_SUPPORTED; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1284 | } |
| 1285 | } |
| 1286 | callback.accept(errorCode); |
| 1287 | } else { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1288 | callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1289 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1290 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1291 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1292 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1293 | case CMD_GET_CALL_WAITING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1294 | request = (MainThreadRequest) msg.obj; |
| 1295 | onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request); |
| 1296 | getPhoneFromRequest(request).getCallWaiting(onCompleted); |
| 1297 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1298 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1299 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1300 | case EVENT_GET_CALL_WAITING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1301 | ar = (AsyncResult) msg.obj; |
| 1302 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1303 | Consumer<Integer> callback = (Consumer<Integer>) request.argument; |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1304 | int callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1305 | if (ar.exception == null && ar.result != null) { |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1306 | int[] callForwardResults = (int[]) ar.result; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1307 | // Service Class is a bit mask per 3gpp 27.007. |
| 1308 | // Search for any service for voice call. |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1309 | if (callForwardResults.length > 1 |
| 1310 | && ((callForwardResults[1] |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1311 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) { |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1312 | callWaitingStatus = callForwardResults[0] == 0 |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1313 | ? TelephonyManager.CALL_WAITING_STATUS_DISABLED |
| 1314 | : TelephonyManager.CALL_WAITING_STATUS_ENABLED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1315 | } else { |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1316 | callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1317 | } |
| 1318 | } else { |
| 1319 | if (ar.result == null) { |
| 1320 | loge("EVENT_GET_CALL_WAITING_DONE: Empty response"); |
| 1321 | } |
| 1322 | if (ar.exception != null) { |
| 1323 | loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception); |
| 1324 | } |
| 1325 | if (ar.exception instanceof CommandException) { |
| 1326 | CommandException.Error error = |
| 1327 | ((CommandException) (ar.exception)).getCommandError(); |
| 1328 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1329 | callWaitingStatus = |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1330 | TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED; |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1331 | } else if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
| 1332 | callWaitingStatus = |
| 1333 | TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1334 | } |
| 1335 | } |
| 1336 | } |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1337 | callback.accept(callWaitingStatus); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1338 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1339 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1340 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1341 | case CMD_SET_CALL_WAITING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1342 | request = (MainThreadRequest) msg.obj; |
| 1343 | onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1344 | boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first; |
| 1345 | getPhoneFromRequest(request).setCallWaiting(enable, onCompleted); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1346 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1347 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1348 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1349 | case EVENT_SET_CALL_WAITING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1350 | ar = (AsyncResult) msg.obj; |
| 1351 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1352 | boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first; |
| 1353 | Consumer<Integer> callback = |
| 1354 | ((Pair<Boolean, Consumer<Integer>>) request.argument).second; |
| 1355 | if (ar.exception != null) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1356 | loge("setCallWaiting exception: " + ar.exception); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1357 | if (ar.exception instanceof CommandException) { |
| 1358 | CommandException.Error error = |
| 1359 | ((CommandException) (ar.exception)).getCommandError(); |
| 1360 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1361 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED); |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1362 | } else if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
| 1363 | callback.accept( |
| 1364 | TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1365 | } else { |
| 1366 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 1367 | } |
| 1368 | } else { |
| 1369 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 1370 | } |
| 1371 | } else { |
| 1372 | callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED |
| 1373 | : TelephonyManager.CALL_WAITING_STATUS_DISABLED); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1374 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1375 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1376 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1377 | case EVENT_PERFORM_NETWORK_SCAN_DONE: |
| 1378 | ar = (AsyncResult) msg.obj; |
| 1379 | request = (MainThreadRequest) ar.userObj; |
| 1380 | CellNetworkScanResult cellScanResult; |
| 1381 | if (ar.exception == null && ar.result != null) { |
| 1382 | cellScanResult = new CellNetworkScanResult( |
| 1383 | CellNetworkScanResult.STATUS_SUCCESS, |
| 1384 | (List<OperatorInfo>) ar.result); |
| 1385 | } else { |
| 1386 | if (ar.result == null) { |
| 1387 | loge("getCellNetworkScanResults: Empty response"); |
| 1388 | } |
| 1389 | if (ar.exception != null) { |
| 1390 | loge("getCellNetworkScanResults: Exception: " + ar.exception); |
| 1391 | } |
| 1392 | int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR; |
| 1393 | if (ar.exception instanceof CommandException) { |
| 1394 | CommandException.Error error = |
| 1395 | ((CommandException) (ar.exception)).getCommandError(); |
| 1396 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1397 | errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE; |
| 1398 | } else if (error == CommandException.Error.GENERIC_FAILURE) { |
| 1399 | errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE; |
| 1400 | } |
| 1401 | } |
| 1402 | cellScanResult = new CellNetworkScanResult(errorCode, null); |
| 1403 | } |
| 1404 | request.result = cellScanResult; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1405 | notifyRequester(request); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1406 | break; |
| 1407 | |
| 1408 | case CMD_SET_NETWORK_SELECTION_MODE_MANUAL: |
| 1409 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1410 | ManualNetworkSelectionArgument selArg = |
| 1411 | (ManualNetworkSelectionArgument) request.argument; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1412 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE, |
| 1413 | request); |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1414 | getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo, |
| 1415 | selArg.persistSelection, onCompleted); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1416 | break; |
| 1417 | |
| 1418 | case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE: |
Pengquan Meng | e3d01e2 | 2018-09-20 15:25:35 -0700 | [diff] [blame] | 1419 | ar = (AsyncResult) msg.obj; |
| 1420 | request = (MainThreadRequest) ar.userObj; |
| 1421 | if (ar.exception == null) { |
| 1422 | request.result = true; |
| 1423 | } else { |
| 1424 | request.result = false; |
| 1425 | loge("setNetworkSelectionModeManual " + ar.exception); |
| 1426 | } |
| 1427 | notifyRequester(request); |
| 1428 | mApp.onNetworkSelectionChanged(request.subId); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1429 | break; |
| 1430 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1431 | case CMD_GET_MODEM_ACTIVITY_INFO: |
| 1432 | request = (MainThreadRequest) msg.obj; |
| 1433 | onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1434 | if (defaultPhone != null) { |
| 1435 | defaultPhone.getModemActivityInfo(onCompleted, request.workSource); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1436 | } else { |
| 1437 | ResultReceiver result = (ResultReceiver) request.argument; |
| 1438 | Bundle bundle = new Bundle(); |
| 1439 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 1440 | new ModemActivityInfo(0, 0, 0, |
| 1441 | new int[ModemActivityInfo.getNumTxPowerLevels()], 0)); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1442 | result.send(0, bundle); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1443 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1444 | break; |
| 1445 | |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1446 | case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: { |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1447 | ar = (AsyncResult) msg.obj; |
| 1448 | request = (MainThreadRequest) ar.userObj; |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1449 | ResultReceiver result = (ResultReceiver) request.argument; |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1450 | int error = 0; |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 1451 | ModemActivityInfo ret = null; |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1452 | if (mLastModemActivityInfo == null) { |
| 1453 | mLastModemActivitySpecificInfo = new ActivityStatsTechSpecificInfo[1]; |
| 1454 | mLastModemActivitySpecificInfo[0] = |
| 1455 | new ActivityStatsTechSpecificInfo( |
| 1456 | 0, |
| 1457 | 0, |
| 1458 | new int[ModemActivityInfo.getNumTxPowerLevels()], |
| 1459 | 0); |
| 1460 | mLastModemActivityInfo = |
| 1461 | new ModemActivityInfo(0, 0, 0, mLastModemActivitySpecificInfo); |
| 1462 | } |
| 1463 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1464 | if (ar.exception == null && ar.result != null) { |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1465 | // Update the last modem activity info and the result of the request. |
| 1466 | ModemActivityInfo info = (ModemActivityInfo) ar.result; |
| 1467 | if (isModemActivityInfoValid(info)) { |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1468 | mergeModemActivityInfo(info); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1469 | } |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 1470 | // This is needed to decouple ret from mLastModemActivityInfo |
| 1471 | // We don't want to return mLastModemActivityInfo which is updated |
| 1472 | // inside mergeModemActivityInfo() |
| 1473 | ret = new ModemActivityInfo( |
| 1474 | mLastModemActivityInfo.getTimestampMillis(), |
| 1475 | mLastModemActivityInfo.getSleepTimeMillis(), |
| 1476 | mLastModemActivityInfo.getIdleTimeMillis(), |
| 1477 | deepCopyModemActivitySpecificInfo(mLastModemActivitySpecificInfo)); |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1478 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1479 | } else { |
| 1480 | if (ar.result == null) { |
| 1481 | loge("queryModemActivityInfo: Empty response"); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1482 | error = TelephonyManager.ModemActivityInfoException |
| 1483 | .ERROR_INVALID_INFO_RECEIVED; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1484 | } else if (ar.exception instanceof CommandException) { |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1485 | loge("queryModemActivityInfo: CommandException: " + ar.exception); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1486 | error = TelephonyManager.ModemActivityInfoException |
| 1487 | .ERROR_MODEM_RESPONSE_ERROR; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1488 | } else { |
| 1489 | loge("queryModemActivityInfo: Unknown exception"); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1490 | error = TelephonyManager.ModemActivityInfoException |
| 1491 | .ERROR_UNKNOWN; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1492 | } |
| 1493 | } |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1494 | Bundle bundle = new Bundle(); |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 1495 | if (ret != null) { |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1496 | bundle.putParcelable( |
| 1497 | TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 1498 | ret); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1499 | } else { |
| 1500 | bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error); |
| 1501 | } |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1502 | result.send(0, bundle); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1503 | notifyRequester(request); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1504 | break; |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1505 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1506 | |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1507 | case CMD_SET_ALLOWED_CARRIERS: |
| 1508 | request = (MainThreadRequest) msg.obj; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1509 | CarrierRestrictionRules argument = |
| 1510 | (CarrierRestrictionRules) request.argument; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1511 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request); |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1512 | defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1513 | break; |
| 1514 | |
| 1515 | case EVENT_SET_ALLOWED_CARRIERS_DONE: |
| 1516 | ar = (AsyncResult) msg.obj; |
| 1517 | request = (MainThreadRequest) ar.userObj; |
| 1518 | if (ar.exception == null && ar.result != null) { |
| 1519 | request.result = ar.result; |
| 1520 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1521 | request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR; |
| 1522 | if (ar.exception instanceof CommandException) { |
| 1523 | loge("setAllowedCarriers: CommandException: " + ar.exception); |
| 1524 | CommandException.Error error = |
| 1525 | ((CommandException) (ar.exception)).getCommandError(); |
| 1526 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1527 | request.result = |
| 1528 | TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED; |
| 1529 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1530 | } else { |
| 1531 | loge("setAllowedCarriers: Unknown exception"); |
| 1532 | } |
| 1533 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1534 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1535 | break; |
| 1536 | |
| 1537 | case CMD_GET_ALLOWED_CARRIERS: |
| 1538 | request = (MainThreadRequest) msg.obj; |
| 1539 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1540 | defaultPhone.getAllowedCarriers(onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1541 | break; |
| 1542 | |
| 1543 | case EVENT_GET_ALLOWED_CARRIERS_DONE: |
| 1544 | ar = (AsyncResult) msg.obj; |
| 1545 | request = (MainThreadRequest) ar.userObj; |
| 1546 | if (ar.exception == null && ar.result != null) { |
| 1547 | request.result = ar.result; |
| 1548 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1549 | request.result = new IllegalStateException( |
| 1550 | "Failed to get carrier restrictions"); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1551 | if (ar.result == null) { |
| 1552 | loge("getAllowedCarriers: Empty response"); |
| 1553 | } else if (ar.exception instanceof CommandException) { |
| 1554 | loge("getAllowedCarriers: CommandException: " + |
| 1555 | ar.exception); |
| 1556 | } else { |
| 1557 | loge("getAllowedCarriers: Unknown exception"); |
| 1558 | } |
| 1559 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1560 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1561 | break; |
| 1562 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1563 | case EVENT_GET_FORBIDDEN_PLMNS_DONE: |
| 1564 | ar = (AsyncResult) msg.obj; |
| 1565 | request = (MainThreadRequest) ar.userObj; |
| 1566 | if (ar.exception == null && ar.result != null) { |
| 1567 | request.result = ar.result; |
| 1568 | } else { |
| 1569 | request.result = new IllegalArgumentException( |
| 1570 | "Failed to retrieve Forbidden Plmns"); |
| 1571 | if (ar.result == null) { |
| 1572 | loge("getForbiddenPlmns: Empty response"); |
| 1573 | } else { |
| 1574 | loge("getForbiddenPlmns: Unknown exception"); |
| 1575 | } |
| 1576 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1577 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1578 | break; |
| 1579 | |
| 1580 | case CMD_GET_FORBIDDEN_PLMNS: |
| 1581 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1582 | uiccPort = getUiccPortFromRequest(request); |
| 1583 | if (uiccPort == null) { |
| 1584 | loge("getForbiddenPlmns() UiccPort is null"); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1585 | request.result = new IllegalArgumentException( |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1586 | "getForbiddenPlmns() UiccPort is null"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1587 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1588 | break; |
| 1589 | } |
| 1590 | Integer appType = (Integer) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1591 | UiccCardApplication uiccApp = uiccPort.getApplicationByType(appType); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1592 | if (uiccApp == null) { |
| 1593 | loge("getForbiddenPlmns() no app with specified type -- " |
| 1594 | + appType); |
| 1595 | request.result = new IllegalArgumentException("Failed to get UICC App"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1596 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1597 | break; |
| 1598 | } else { |
| 1599 | if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid() |
| 1600 | + " specified type -- " + appType); |
| 1601 | } |
| 1602 | onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request); |
| 1603 | ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns( |
| 1604 | onCompleted); |
| 1605 | break; |
| 1606 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1607 | case CMD_SWITCH_SLOTS: |
| 1608 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 1609 | List<UiccSlotMapping> slotMapping = (List<UiccSlotMapping>) request.argument; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1610 | onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 1611 | UiccController.getInstance().switchSlots(slotMapping, onCompleted); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1612 | break; |
| 1613 | |
| 1614 | case EVENT_SWITCH_SLOTS_DONE: |
| 1615 | ar = (AsyncResult) msg.obj; |
| 1616 | request = (MainThreadRequest) ar.userObj; |
| 1617 | request.result = (ar.exception == null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1618 | notifyRequester(request); |
| 1619 | break; |
| 1620 | case CMD_GET_NETWORK_SELECTION_MODE: |
| 1621 | request = (MainThreadRequest) msg.obj; |
| 1622 | onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request); |
| 1623 | getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted); |
| 1624 | break; |
| 1625 | |
| 1626 | case EVENT_GET_NETWORK_SELECTION_MODE_DONE: |
| 1627 | ar = (AsyncResult) msg.obj; |
| 1628 | request = (MainThreadRequest) ar.userObj; |
| 1629 | if (ar.exception != null) { |
| 1630 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 1631 | } else { |
| 1632 | int mode = ((int[]) ar.result)[0]; |
| 1633 | if (mode == 0) { |
| 1634 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO; |
| 1635 | } else { |
| 1636 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL; |
| 1637 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1638 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1639 | notifyRequester(request); |
| 1640 | break; |
| 1641 | case CMD_GET_CDMA_ROAMING_MODE: |
| 1642 | request = (MainThreadRequest) msg.obj; |
| 1643 | onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request); |
| 1644 | getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted); |
| 1645 | break; |
| 1646 | case EVENT_GET_CDMA_ROAMING_MODE_DONE: |
| 1647 | ar = (AsyncResult) msg.obj; |
| 1648 | request = (MainThreadRequest) ar.userObj; |
| 1649 | if (ar.exception != null) { |
| 1650 | request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT; |
| 1651 | } else { |
| 1652 | request.result = ((int[]) ar.result)[0]; |
| 1653 | } |
| 1654 | notifyRequester(request); |
| 1655 | break; |
| 1656 | case CMD_SET_CDMA_ROAMING_MODE: |
| 1657 | request = (MainThreadRequest) msg.obj; |
| 1658 | onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request); |
| 1659 | int mode = (int) request.argument; |
| 1660 | getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted); |
| 1661 | break; |
| 1662 | case EVENT_SET_CDMA_ROAMING_MODE_DONE: |
| 1663 | ar = (AsyncResult) msg.obj; |
| 1664 | request = (MainThreadRequest) ar.userObj; |
| 1665 | request.result = ar.exception == null; |
| 1666 | notifyRequester(request); |
| 1667 | break; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 1668 | case CMD_GET_CDMA_SUBSCRIPTION_MODE: |
| 1669 | request = (MainThreadRequest) msg.obj; |
| 1670 | onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1671 | getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted); |
| 1672 | break; |
| 1673 | case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1674 | ar = (AsyncResult) msg.obj; |
| 1675 | request = (MainThreadRequest) ar.userObj; |
| 1676 | if (ar.exception != null) { |
| 1677 | request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM; |
| 1678 | } else { |
| 1679 | request.result = ((int[]) ar.result)[0]; |
| 1680 | } |
| 1681 | notifyRequester(request); |
| 1682 | break; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1683 | case CMD_SET_CDMA_SUBSCRIPTION_MODE: |
| 1684 | request = (MainThreadRequest) msg.obj; |
| 1685 | onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1686 | int subscriptionMode = (int) request.argument; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 1687 | getPhoneFromRequest(request).setCdmaSubscriptionMode( |
| 1688 | subscriptionMode, onCompleted); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1689 | break; |
| 1690 | case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1691 | ar = (AsyncResult) msg.obj; |
| 1692 | request = (MainThreadRequest) ar.userObj; |
| 1693 | request.result = ar.exception == null; |
| 1694 | notifyRequester(request); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1695 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1696 | case CMD_GET_ALL_CELL_INFO: |
| 1697 | request = (MainThreadRequest) msg.obj; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1698 | onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1699 | request.phone.requestCellInfoUpdate(request.workSource, onCompleted); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1700 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1701 | case EVENT_GET_ALL_CELL_INFO_DONE: |
| 1702 | ar = (AsyncResult) msg.obj; |
| 1703 | request = (MainThreadRequest) ar.userObj; |
Nathan Harold | 8d0f174 | 2018-10-02 12:14:47 -0700 | [diff] [blame] | 1704 | // If a timeout occurs, the response will be null |
| 1705 | request.result = (ar.exception == null && ar.result != null) |
| 1706 | ? ar.result : new ArrayList<CellInfo>(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1707 | synchronized (request) { |
| 1708 | request.notifyAll(); |
| 1709 | } |
| 1710 | break; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1711 | case CMD_REQUEST_CELL_INFO_UPDATE: |
| 1712 | request = (MainThreadRequest) msg.obj; |
| 1713 | request.phone.requestCellInfoUpdate(request.workSource, |
| 1714 | obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request)); |
| 1715 | break; |
| 1716 | case EVENT_REQUEST_CELL_INFO_UPDATE_DONE: |
| 1717 | ar = (AsyncResult) msg.obj; |
| 1718 | request = (MainThreadRequest) ar.userObj; |
| 1719 | ICellInfoCallback cb = (ICellInfoCallback) request.argument; |
| 1720 | try { |
| 1721 | if (ar.exception != null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1722 | Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception); |
Meng Wang | d8921f4 | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1723 | cb.onError( |
| 1724 | TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR, |
| 1725 | ar.exception.getClass().getName(), |
| 1726 | ar.exception.toString()); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1727 | } else if (ar.result == null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1728 | Log.w(LOG_TAG, "Timeout Waiting for CellInfo!"); |
Meng Wang | d8921f4 | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1729 | cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1730 | } else { |
| 1731 | // use the result as returned |
| 1732 | cb.onCellInfo((List<CellInfo>) ar.result); |
| 1733 | } |
| 1734 | } catch (RemoteException re) { |
| 1735 | Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException"); |
| 1736 | } |
| 1737 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1738 | case CMD_GET_CELL_LOCATION: { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1739 | request = (MainThreadRequest) msg.obj; |
| 1740 | WorkSource ws = (WorkSource) request.argument; |
| 1741 | Phone phone = getPhoneFromRequest(request); |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1742 | phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request)); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1743 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1744 | } |
| 1745 | case EVENT_GET_CELL_LOCATION_DONE: { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1746 | ar = (AsyncResult) msg.obj; |
| 1747 | request = (MainThreadRequest) ar.userObj; |
| 1748 | if (ar.exception == null) { |
| 1749 | request.result = ar.result; |
| 1750 | } else { |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1751 | Phone phone = getPhoneFromRequest(request); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1752 | request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1753 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1754 | } |
| 1755 | |
| 1756 | synchronized (request) { |
| 1757 | request.notifyAll(); |
| 1758 | } |
| 1759 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1760 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1761 | case CMD_MODEM_REBOOT: |
| 1762 | request = (MainThreadRequest) msg.obj; |
| 1763 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1764 | defaultPhone.rebootModem(onCompleted); |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1765 | break; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1766 | case EVENT_CMD_MODEM_REBOOT_DONE: |
| 1767 | handleNullReturnEvent(msg, "rebootModem"); |
| 1768 | break; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1769 | case CMD_REQUEST_ENABLE_MODEM: |
| 1770 | request = (MainThreadRequest) msg.obj; |
| 1771 | boolean enable = (boolean) request.argument; |
| 1772 | onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1773 | onCompleted.arg1 = enable ? 1 : 0; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1774 | PhoneConfigurationManager.getInstance() |
| 1775 | .enablePhone(request.phone, enable, onCompleted); |
| 1776 | break; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1777 | case EVENT_ENABLE_MODEM_DONE: { |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1778 | ar = (AsyncResult) msg.obj; |
| 1779 | request = (MainThreadRequest) ar.userObj; |
| 1780 | request.result = (ar.exception == null); |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1781 | int phoneId = request.phone.getPhoneId(); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1782 | //update the cache as modem status has changed |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1783 | if ((boolean) request.result) { |
| 1784 | mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1); |
| 1785 | updateModemStateMetrics(); |
| 1786 | } else { |
| 1787 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1788 | + ar.exception); |
| 1789 | } |
| 1790 | notifyRequester(request); |
| 1791 | break; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1792 | } |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1793 | case CMD_GET_MODEM_STATUS: |
| 1794 | request = (MainThreadRequest) msg.obj; |
| 1795 | onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request); |
| 1796 | PhoneConfigurationManager.getInstance() |
| 1797 | .getPhoneStatusFromModem(request.phone, onCompleted); |
| 1798 | break; |
| 1799 | case EVENT_GET_MODEM_STATUS_DONE: |
| 1800 | ar = (AsyncResult) msg.obj; |
| 1801 | request = (MainThreadRequest) ar.userObj; |
| 1802 | int id = request.phone.getPhoneId(); |
| 1803 | if (ar.exception == null && ar.result != null) { |
| 1804 | request.result = ar.result; |
| 1805 | //update the cache as modem status has changed |
| 1806 | mPhoneConfigurationManager.addToPhoneStatusCache(id, |
| 1807 | (boolean) request.result); |
| 1808 | } else { |
| 1809 | // Return true if modem status cannot be retrieved. For most cases, |
| 1810 | // modem status is on. And for older version modems, GET_MODEM_STATUS |
| 1811 | // and disable modem are not supported. Modem is always on. |
| 1812 | // TODO: this should be fixed in R to support a third |
| 1813 | // status UNKNOWN b/131631629 |
| 1814 | request.result = true; |
| 1815 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1816 | + ar.exception); |
| 1817 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1818 | notifyRequester(request); |
| 1819 | break; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 1820 | case CMD_SET_SYSTEM_SELECTION_CHANNELS: { |
| 1821 | request = (MainThreadRequest) msg.obj; |
| 1822 | onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request); |
| 1823 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 1824 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 1825 | request.phone.setSystemSelectionChannels(args.first, onCompleted); |
| 1826 | break; |
| 1827 | } |
| 1828 | case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: { |
| 1829 | ar = (AsyncResult) msg.obj; |
| 1830 | request = (MainThreadRequest) ar.userObj; |
| 1831 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 1832 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 1833 | args.second.accept(ar.exception == null); |
| 1834 | notifyRequester(request); |
| 1835 | break; |
| 1836 | } |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1837 | case CMD_GET_SYSTEM_SELECTION_CHANNELS: { |
| 1838 | request = (MainThreadRequest) msg.obj; |
| 1839 | onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request); |
| 1840 | Phone phone = getPhoneFromRequest(request); |
| 1841 | if (phone != null) { |
| 1842 | phone.getSystemSelectionChannels(onCompleted); |
| 1843 | } else { |
| 1844 | loge("getSystemSelectionChannels: No phone object"); |
| 1845 | request.result = new ArrayList<RadioAccessSpecifier>(); |
| 1846 | notifyRequester(request); |
| 1847 | } |
| 1848 | break; |
| 1849 | } |
| 1850 | case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE: |
| 1851 | ar = (AsyncResult) msg.obj; |
| 1852 | request = (MainThreadRequest) ar.userObj; |
| 1853 | if (ar.exception == null && ar.result != null) { |
| 1854 | request.result = ar.result; |
| 1855 | } else { |
Sarah Chin | 428d1d6 | 2021-03-13 03:17:40 -0800 | [diff] [blame] | 1856 | request.result = new IllegalStateException( |
| 1857 | "Failed to retrieve system selecton channels"); |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1858 | if (ar.result == null) { |
| 1859 | loge("getSystemSelectionChannels: Empty response"); |
| 1860 | } else { |
| 1861 | loge("getSystemSelectionChannels: Unknown exception"); |
| 1862 | } |
| 1863 | } |
| 1864 | notifyRequester(request); |
| 1865 | break; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1866 | case EVENT_SET_FORBIDDEN_PLMNS_DONE: |
| 1867 | ar = (AsyncResult) msg.obj; |
| 1868 | request = (MainThreadRequest) ar.userObj; |
| 1869 | if (ar.exception == null && ar.result != null) { |
| 1870 | request.result = ar.result; |
| 1871 | } else { |
| 1872 | request.result = -1; |
| 1873 | loge("Failed to set Forbidden Plmns"); |
| 1874 | if (ar.result == null) { |
| 1875 | loge("setForbidenPlmns: Empty response"); |
| 1876 | } else if (ar.exception != null) { |
| 1877 | loge("setForbiddenPlmns: Exception: " + ar.exception); |
| 1878 | request.result = -1; |
| 1879 | } else { |
| 1880 | loge("setForbiddenPlmns: Unknown exception"); |
| 1881 | } |
| 1882 | } |
| 1883 | notifyRequester(request); |
| 1884 | break; |
| 1885 | case CMD_SET_FORBIDDEN_PLMNS: |
| 1886 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1887 | uiccPort = getUiccPortFromRequest(request); |
| 1888 | if (uiccPort == null) { |
| 1889 | loge("setForbiddenPlmns: UiccPort is null"); |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1890 | request.result = -1; |
| 1891 | notifyRequester(request); |
| 1892 | break; |
| 1893 | } |
| 1894 | Pair<Integer, List<String>> setFplmnsArgs = |
| 1895 | (Pair<Integer, List<String>>) request.argument; |
| 1896 | appType = setFplmnsArgs.first; |
| 1897 | List<String> fplmns = setFplmnsArgs.second; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1898 | uiccApp = uiccPort.getApplicationByType(appType); |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1899 | if (uiccApp == null) { |
| 1900 | loge("setForbiddenPlmns: no app with specified type -- " + appType); |
| 1901 | request.result = -1; |
| 1902 | loge("Failed to get UICC App"); |
| 1903 | notifyRequester(request); |
| 1904 | } else { |
| 1905 | onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request); |
| 1906 | ((SIMRecords) uiccApp.getIccRecords()) |
| 1907 | .setForbiddenPlmns(onCompleted, fplmns); |
| 1908 | } |
yinchengzhao | 4d163c0 | 2019-12-12 15:21:47 -0800 | [diff] [blame] | 1909 | break; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 1910 | case CMD_ERASE_MODEM_CONFIG: |
| 1911 | request = (MainThreadRequest) msg.obj; |
| 1912 | onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request); |
| 1913 | defaultPhone.eraseModemConfig(onCompleted); |
| 1914 | break; |
| 1915 | case EVENT_ERASE_MODEM_CONFIG_DONE: |
| 1916 | handleNullReturnEvent(msg, "eraseModemConfig"); |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1917 | break; |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1918 | |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 1919 | case CMD_ERASE_DATA_SHARED_PREFERENCES: |
| 1920 | request = (MainThreadRequest) msg.obj; |
| 1921 | request.result = defaultPhone.eraseDataInSharedPreferences(); |
| 1922 | notifyRequester(request); |
| 1923 | break; |
| 1924 | |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1925 | case CMD_CHANGE_ICC_LOCK_PASSWORD: |
| 1926 | request = (MainThreadRequest) msg.obj; |
| 1927 | onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request); |
| 1928 | Pair<String, String> changed = (Pair<String, String>) request.argument; |
| 1929 | getPhoneFromRequest(request).getIccCard().changeIccLockPassword( |
| 1930 | changed.first, changed.second, onCompleted); |
| 1931 | break; |
| 1932 | case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE: |
| 1933 | ar = (AsyncResult) msg.obj; |
| 1934 | request = (MainThreadRequest) ar.userObj; |
| 1935 | if (ar.exception == null) { |
| 1936 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1937 | // If the operation is successful, update the PIN storage |
| 1938 | Pair<String, String> passwords = (Pair<String, String>) request.argument; |
| 1939 | int phoneId = getPhoneFromRequest(request).getPhoneId(); |
Jon Spivack | 9c3bc76 | 2021-10-06 20:53:09 +0000 | [diff] [blame] | 1940 | UiccController.getInstance().getPinStorage() |
| 1941 | .storePin(passwords.second, phoneId); |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1942 | } else { |
| 1943 | request.result = msg.arg1; |
| 1944 | } |
| 1945 | notifyRequester(request); |
| 1946 | break; |
| 1947 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1948 | case CMD_SET_ICC_LOCK_ENABLED: { |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1949 | request = (MainThreadRequest) msg.obj; |
| 1950 | onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request); |
| 1951 | Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument; |
| 1952 | getPhoneFromRequest(request).getIccCard().setIccLockEnabled( |
| 1953 | enabled.first, enabled.second, onCompleted); |
| 1954 | break; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1955 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1956 | case EVENT_SET_ICC_LOCK_ENABLED_DONE: |
| 1957 | ar = (AsyncResult) msg.obj; |
| 1958 | request = (MainThreadRequest) ar.userObj; |
| 1959 | if (ar.exception == null) { |
| 1960 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1961 | // If the operation is successful, update the PIN storage |
| 1962 | Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument; |
| 1963 | int phoneId = getPhoneFromRequest(request).getPhoneId(); |
| 1964 | if (enabled.first) { |
Jon Spivack | 9c3bc76 | 2021-10-06 20:53:09 +0000 | [diff] [blame] | 1965 | UiccController.getInstance().getPinStorage() |
| 1966 | .storePin(enabled.second, phoneId); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1967 | } else { |
| 1968 | UiccController.getInstance().getPinStorage().clearPin(phoneId); |
| 1969 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1970 | } else { |
| 1971 | request.result = msg.arg1; |
| 1972 | } |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1973 | |
| 1974 | |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1975 | notifyRequester(request); |
| 1976 | break; |
| 1977 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 1978 | case MSG_NOTIFY_USER_ACTIVITY: |
| 1979 | removeMessages(MSG_NOTIFY_USER_ACTIVITY); |
Peter Wang | 59571be | 2020-01-27 12:35:15 +0800 | [diff] [blame] | 1980 | Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION); |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 1981 | intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY); |
| 1982 | getDefaultPhone().getContext().sendBroadcastAsUser( |
| 1983 | intent, UserHandle.ALL, permission.USER_ACTIVITY); |
| 1984 | break; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 1985 | |
| 1986 | case CMD_SET_DATA_THROTTLING: { |
| 1987 | request = (MainThreadRequest) msg.obj; |
| 1988 | onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request); |
| 1989 | DataThrottlingRequest dataThrottlingRequest = |
| 1990 | (DataThrottlingRequest) request.argument; |
| 1991 | Phone phone = getPhoneFromRequest(request); |
| 1992 | if (phone != null) { |
| 1993 | phone.setDataThrottling(onCompleted, |
| 1994 | request.workSource, dataThrottlingRequest.getDataThrottlingAction(), |
| 1995 | dataThrottlingRequest.getCompletionDurationMillis()); |
| 1996 | } else { |
| 1997 | loge("setDataThrottling: No phone object"); |
| 1998 | request.result = |
| 1999 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 2000 | notifyRequester(request); |
| 2001 | } |
| 2002 | |
| 2003 | break; |
| 2004 | } |
| 2005 | case EVENT_SET_DATA_THROTTLING_DONE: |
| 2006 | ar = (AsyncResult) msg.obj; |
| 2007 | request = (MainThreadRequest) ar.userObj; |
| 2008 | |
| 2009 | if (ar.exception == null) { |
| 2010 | request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 2011 | } else if (ar.exception instanceof CommandException) { |
| 2012 | loge("setDataThrottling: CommandException: " + ar.exception); |
| 2013 | CommandException.Error error = |
| 2014 | ((CommandException) (ar.exception)).getCommandError(); |
| 2015 | |
| 2016 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 2017 | request.result = TelephonyManager |
| 2018 | .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 2019 | } else if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 2020 | request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS; |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 2021 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 2022 | request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 2023 | } else { |
| 2024 | request.result = |
| 2025 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 2026 | } |
| 2027 | } else { |
| 2028 | request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 2029 | } |
| 2030 | Log.w(LOG_TAG, "DataThrottlingResult = " + request.result); |
| 2031 | notifyRequester(request); |
| 2032 | break; |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 2033 | |
| 2034 | case CMD_SET_SIM_POWER: { |
| 2035 | request = (MainThreadRequest) msg.obj; |
| 2036 | onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request); |
| 2037 | request = (MainThreadRequest) msg.obj; |
| 2038 | int stateToSet = |
| 2039 | ((Pair<Integer, IIntegerConsumer>) |
| 2040 | request.argument).first; |
| 2041 | request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource); |
| 2042 | break; |
| 2043 | } |
| 2044 | case EVENT_SET_SIM_POWER_DONE: { |
| 2045 | ar = (AsyncResult) msg.obj; |
| 2046 | request = (MainThreadRequest) ar.userObj; |
| 2047 | IIntegerConsumer callback = |
| 2048 | ((Pair<Integer, IIntegerConsumer>) request.argument).second; |
| 2049 | if (ar.exception != null) { |
| 2050 | loge("setSimPower exception: " + ar.exception); |
| 2051 | int errorCode = TelephonyManager.CallForwardingInfoCallback |
| 2052 | .RESULT_ERROR_UNKNOWN; |
| 2053 | if (ar.exception instanceof CommandException) { |
| 2054 | CommandException.Error error = |
| 2055 | ((CommandException) (ar.exception)).getCommandError(); |
| 2056 | if (error == CommandException.Error.SIM_ERR) { |
| 2057 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR; |
| 2058 | } else if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 2059 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE; |
| 2060 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 2061 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED; |
| 2062 | } else { |
| 2063 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR; |
| 2064 | } |
| 2065 | } |
| 2066 | try { |
| 2067 | callback.accept(errorCode); |
| 2068 | } catch (RemoteException e) { |
| 2069 | // Ignore if the remote process is no longer available to call back. |
| 2070 | Log.w(LOG_TAG, "setSimPower: callback not available."); |
| 2071 | } |
| 2072 | } else { |
| 2073 | try { |
| 2074 | callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS); |
| 2075 | } catch (RemoteException e) { |
| 2076 | // Ignore if the remote process is no longer available to call back. |
| 2077 | Log.w(LOG_TAG, "setSimPower: callback not available."); |
| 2078 | } |
| 2079 | } |
| 2080 | break; |
| 2081 | } |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 2082 | case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: { |
| 2083 | request = (MainThreadRequest) msg.obj; |
| 2084 | |
| 2085 | final Phone phone = getPhoneFromRequest(request); |
| 2086 | if (phone == null || phone.getServiceStateTracker() == null) { |
| 2087 | request.result = new IllegalStateException("Phone or SST is null"); |
| 2088 | notifyRequester(request); |
| 2089 | break; |
| 2090 | } |
| 2091 | |
| 2092 | Pair<Integer, SignalStrengthUpdateRequest> pair = |
| 2093 | (Pair<Integer, SignalStrengthUpdateRequest>) request.argument; |
| 2094 | onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE, |
| 2095 | request); |
Rambo Wang | 6568f17 | 2021-02-03 16:56:47 -0800 | [diff] [blame] | 2096 | phone.getSignalStrengthController().setSignalStrengthUpdateRequest( |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 2097 | request.subId, pair.first /*callingUid*/, |
| 2098 | pair.second /*request*/, onCompleted); |
| 2099 | break; |
| 2100 | } |
| 2101 | case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: { |
| 2102 | ar = (AsyncResult) msg.obj; |
| 2103 | request = (MainThreadRequest) ar.userObj; |
| 2104 | // request.result will be the exception of ar if present, true otherwise. |
| 2105 | // Be cautious not to leave result null which will wait() forever |
| 2106 | request.result = ar.exception != null ? ar.exception : true; |
| 2107 | notifyRequester(request); |
| 2108 | break; |
| 2109 | } |
| 2110 | case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: { |
| 2111 | request = (MainThreadRequest) msg.obj; |
| 2112 | |
| 2113 | Phone phone = getPhoneFromRequest(request); |
| 2114 | if (phone == null || phone.getServiceStateTracker() == null) { |
| 2115 | request.result = new IllegalStateException("Phone or SST is null"); |
| 2116 | notifyRequester(request); |
| 2117 | break; |
| 2118 | } |
| 2119 | |
| 2120 | Pair<Integer, SignalStrengthUpdateRequest> pair = |
| 2121 | (Pair<Integer, SignalStrengthUpdateRequest>) request.argument; |
| 2122 | onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE, |
| 2123 | request); |
Rambo Wang | 6568f17 | 2021-02-03 16:56:47 -0800 | [diff] [blame] | 2124 | phone.getSignalStrengthController().clearSignalStrengthUpdateRequest( |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 2125 | request.subId, pair.first /*callingUid*/, |
| 2126 | pair.second /*request*/, onCompleted); |
| 2127 | break; |
| 2128 | } |
| 2129 | case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: { |
| 2130 | ar = (AsyncResult) msg.obj; |
| 2131 | request = (MainThreadRequest) ar.userObj; |
| 2132 | request.result = ar.exception != null ? ar.exception : true; |
| 2133 | notifyRequester(request); |
| 2134 | break; |
| 2135 | } |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 2136 | |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2137 | case CMD_GET_SLICING_CONFIG: { |
| 2138 | request = (MainThreadRequest) msg.obj; |
| 2139 | onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request); |
| 2140 | request.phone.getSlicingConfig(onCompleted); |
| 2141 | break; |
| 2142 | } |
| 2143 | case EVENT_GET_SLICING_CONFIG_DONE: { |
| 2144 | ar = (AsyncResult) msg.obj; |
| 2145 | request = (MainThreadRequest) ar.userObj; |
| 2146 | ResultReceiver result = (ResultReceiver) request.argument; |
| 2147 | |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2148 | NetworkSlicingConfig slicingConfig = null; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2149 | Bundle bundle = new Bundle(); |
| 2150 | int resultCode = 0; |
| 2151 | if (ar.exception != null) { |
| 2152 | Log.e(LOG_TAG, "Exception retrieving slicing configuration=" |
| 2153 | + ar.exception); |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2154 | resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2155 | } else if (ar.result == null) { |
| 2156 | Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!"); |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2157 | resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2158 | } else { |
| 2159 | // use the result as returned |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2160 | resultCode = TelephonyManager.NetworkSlicingException.SUCCESS; |
| 2161 | slicingConfig = (NetworkSlicingConfig) ar.result; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2162 | } |
| 2163 | |
| 2164 | if (slicingConfig == null) { |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2165 | slicingConfig = new NetworkSlicingConfig(); |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2166 | } |
| 2167 | bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig); |
| 2168 | result.send(resultCode, bundle); |
| 2169 | notifyRequester(request); |
| 2170 | break; |
| 2171 | } |
| 2172 | |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2173 | case CMD_PURCHASE_PREMIUM_CAPABILITY: { |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2174 | request = (MainThreadRequest) msg.obj; |
| 2175 | onCompleted = obtainMessage(EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE, request); |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2176 | PurchasePremiumCapabilityArgument arg = |
| 2177 | (PurchasePremiumCapabilityArgument) request.argument; |
Sarah Chin | 46355ba | 2022-11-01 23:51:16 -0700 | [diff] [blame] | 2178 | SlicePurchaseController.getInstance(request.phone).purchasePremiumCapability( |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2179 | arg.capability, arg.appName, onCompleted); |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2180 | break; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2181 | } |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2182 | |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2183 | case EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE: { |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2184 | ar = (AsyncResult) msg.obj; |
| 2185 | request = (MainThreadRequest) ar.userObj; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2186 | PurchasePremiumCapabilityArgument arg = |
| 2187 | (PurchasePremiumCapabilityArgument) request.argument; |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2188 | try { |
| 2189 | int result = (int) ar.result; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2190 | arg.callback.accept(result); |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2191 | log("purchasePremiumCapability: capability=" |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2192 | + TelephonyManager.convertPremiumCapabilityToString(arg.capability) |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2193 | + ", result= " |
| 2194 | + TelephonyManager.convertPurchaseResultToString(result)); |
| 2195 | } catch (RemoteException e) { |
| 2196 | String logStr = "Purchase premium capability " |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2197 | + TelephonyManager.convertPremiumCapabilityToString(arg.capability) |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2198 | + " failed: " + e; |
| 2199 | if (DBG) log(logStr); |
| 2200 | AnomalyReporter.reportAnomaly( |
| 2201 | UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr); |
| 2202 | } |
| 2203 | break; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2204 | } |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2205 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2206 | case CMD_PREPARE_UNATTENDED_REBOOT: |
| 2207 | request = (MainThreadRequest) msg.obj; |
| 2208 | request.result = |
Rafael Higuera Silva | d963064 | 2021-09-20 15:32:01 +0000 | [diff] [blame] | 2209 | UiccController.getInstance().getPinStorage() |
| 2210 | .prepareUnattendedReboot(request.workSource); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2211 | notifyRequester(request); |
| 2212 | break; |
| 2213 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2214 | default: |
| 2215 | Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what); |
| 2216 | break; |
| 2217 | } |
| 2218 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2219 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 2220 | private void notifyRequester(MainThreadRequest request) { |
| 2221 | synchronized (request) { |
| 2222 | request.notifyAll(); |
| 2223 | } |
| 2224 | } |
| 2225 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2226 | private void handleNullReturnEvent(Message msg, String command) { |
| 2227 | AsyncResult ar = (AsyncResult) msg.obj; |
| 2228 | MainThreadRequest request = (MainThreadRequest) ar.userObj; |
| 2229 | if (ar.exception == null) { |
| 2230 | request.result = true; |
| 2231 | } else { |
| 2232 | request.result = false; |
| 2233 | if (ar.exception instanceof CommandException) { |
| 2234 | loge(command + ": CommandException: " + ar.exception); |
| 2235 | } else { |
| 2236 | loge(command + ": Unknown exception"); |
| 2237 | } |
| 2238 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 2239 | notifyRequester(request); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2240 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2241 | } |
| 2242 | |
| 2243 | /** |
| 2244 | * Posts the specified command to be executed on the main thread, |
| 2245 | * waits for the request to complete, and returns the result. |
| 2246 | * @see #sendRequestAsync |
| 2247 | */ |
| 2248 | private Object sendRequest(int command, Object argument) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2249 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, |
| 2250 | null, -1 /*timeoutInMs*/); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 2251 | } |
| 2252 | |
| 2253 | /** |
| 2254 | * Posts the specified command to be executed on the main thread, |
| 2255 | * waits for the request to complete, and returns the result. |
| 2256 | * @see #sendRequestAsync |
| 2257 | */ |
| 2258 | private Object sendRequest(int command, Object argument, WorkSource workSource) { |
| 2259 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2260 | null, workSource, -1 /*timeoutInMs*/); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2261 | } |
| 2262 | |
| 2263 | /** |
| 2264 | * Posts the specified command to be executed on the main thread, |
| 2265 | * waits for the request to complete, and returns the result. |
| 2266 | * @see #sendRequestAsync |
| 2267 | */ |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2268 | private Object sendRequest(int command, Object argument, Integer subId) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2269 | return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/); |
| 2270 | } |
| 2271 | |
| 2272 | /** |
| 2273 | * Posts the specified command to be executed on the main thread, |
| 2274 | * waits for the request to complete for at most {@code timeoutInMs}, and returns the result |
| 2275 | * if not timeout or null otherwise. |
| 2276 | * @see #sendRequestAsync |
| 2277 | */ |
| 2278 | private @Nullable Object sendRequest(int command, Object argument, Integer subId, |
| 2279 | long timeoutInMs) { |
| 2280 | return sendRequest(command, argument, subId, null, null, timeoutInMs); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 2281 | } |
| 2282 | |
| 2283 | /** |
| 2284 | * Posts the specified command to be executed on the main thread, |
| 2285 | * waits for the request to complete, and returns the result. |
| 2286 | * @see #sendRequestAsync |
| 2287 | */ |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2288 | private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2289 | return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2290 | } |
| 2291 | |
| 2292 | /** |
| 2293 | * Posts the specified command to be executed on the main thread, |
| 2294 | * waits for the request to complete, and returns the result. |
| 2295 | * @see #sendRequestAsync |
| 2296 | */ |
| 2297 | private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2298 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, |
| 2299 | workSource, -1 /*timeoutInMs*/); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2300 | } |
| 2301 | |
| 2302 | /** |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2303 | * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is |
| 2304 | * negative, waits for the request to complete, and returns the result. Otherwise, wait for |
| 2305 | * maximum of {@code timeoutInMs} milliseconds, interrupt and return null. |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2306 | * @see #sendRequestAsync |
| 2307 | */ |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2308 | private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone, |
| 2309 | WorkSource workSource, long timeoutInMs) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2310 | if (Looper.myLooper() == mMainThreadHandler.getLooper()) { |
| 2311 | throw new RuntimeException("This method will deadlock if called from the main thread."); |
| 2312 | } |
| 2313 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2314 | MainThreadRequest request = null; |
| 2315 | if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) { |
| 2316 | throw new IllegalArgumentException("subId and phone cannot both be specified!"); |
| 2317 | } else if (phone != null) { |
| 2318 | request = new MainThreadRequest(argument, phone, workSource); |
| 2319 | } else { |
| 2320 | request = new MainThreadRequest(argument, subId, workSource); |
| 2321 | } |
| 2322 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2323 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 2324 | msg.sendToTarget(); |
| 2325 | |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2326 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2327 | synchronized (request) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2328 | if (timeoutInMs >= 0) { |
| 2329 | // Wait for at least timeoutInMs before returning null request result |
| 2330 | long now = SystemClock.elapsedRealtime(); |
| 2331 | long deadline = now + timeoutInMs; |
Grace Jia | 8a0a1e8 | 2021-05-23 22:59:52 -0700 | [diff] [blame] | 2332 | while (request.result == null && now < deadline) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2333 | try { |
| 2334 | request.wait(deadline - now); |
| 2335 | } catch (InterruptedException e) { |
| 2336 | // Do nothing, go back and check if request is completed or timeout |
| 2337 | } finally { |
| 2338 | now = SystemClock.elapsedRealtime(); |
| 2339 | } |
| 2340 | } |
| 2341 | } else { |
| 2342 | // Wait for the request to complete |
| 2343 | while (request.result == null) { |
| 2344 | try { |
| 2345 | request.wait(); |
| 2346 | } catch (InterruptedException e) { |
| 2347 | // Do nothing, go back and wait until the request is complete |
| 2348 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2349 | } |
| 2350 | } |
| 2351 | } |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2352 | if (request.result == null) { |
| 2353 | Log.wtf(LOG_TAG, |
| 2354 | "sendRequest: Blocking command timed out. Something has gone terribly wrong."); |
| 2355 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2356 | return request.result; |
| 2357 | } |
| 2358 | |
| 2359 | /** |
| 2360 | * Asynchronous ("fire and forget") version of sendRequest(): |
| 2361 | * Posts the specified command to be executed on the main thread, and |
| 2362 | * returns immediately. |
| 2363 | * @see #sendRequest |
| 2364 | */ |
| 2365 | private void sendRequestAsync(int command) { |
| 2366 | mMainThreadHandler.sendEmptyMessage(command); |
| 2367 | } |
| 2368 | |
| 2369 | /** |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2370 | * Same as {@link #sendRequestAsync(int)} except it takes an argument. |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2371 | * @see {@link #sendRequest(int)} |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2372 | */ |
| 2373 | private void sendRequestAsync(int command, Object argument) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2374 | sendRequestAsync(command, argument, null, null); |
| 2375 | } |
| 2376 | |
| 2377 | /** |
| 2378 | * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource. |
| 2379 | * @see {@link #sendRequest(int,Object)} |
| 2380 | */ |
| 2381 | private void sendRequestAsync( |
| 2382 | int command, Object argument, Phone phone, WorkSource workSource) { |
| 2383 | MainThreadRequest request = new MainThreadRequest(argument, phone, workSource); |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2384 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 2385 | msg.sendToTarget(); |
| 2386 | } |
| 2387 | |
| 2388 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2389 | * Initialize the singleton PhoneInterfaceManager instance. |
| 2390 | * This is only done once, at startup, from PhoneApp.onCreate(). |
| 2391 | */ |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2392 | /* package */ static PhoneInterfaceManager init(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2393 | synchronized (PhoneInterfaceManager.class) { |
| 2394 | if (sInstance == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2395 | sInstance = new PhoneInterfaceManager(app); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2396 | } else { |
| 2397 | Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance); |
| 2398 | } |
| 2399 | return sInstance; |
| 2400 | } |
| 2401 | } |
| 2402 | |
| 2403 | /** Private constructor; @see init() */ |
Jordan Liu | 1979a04 | 2020-03-20 21:39:35 +0000 | [diff] [blame] | 2404 | private PhoneInterfaceManager(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2405 | mApp = app; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2406 | mCM = PhoneGlobals.getInstance().mCM; |
Brad Ebinger | d1947d8 | 2021-05-17 20:54:49 +0000 | [diff] [blame] | 2407 | mImsResolver = ImsResolver.getInstance(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 2408 | mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2409 | mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 2410 | mPm = app.getSystemService(PackageManager.class); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2411 | mMainThreadHandler = new MainThreadHandler(); |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 2412 | mSubscriptionController = SubscriptionController.getInstance(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2413 | mTelephonySharedPreferences = |
| 2414 | PreferenceManager.getDefaultSharedPreferences(mApp); |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 2415 | mNetworkScanRequestTracker = new NetworkScanRequestTracker(); |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 2416 | mPhoneConfigurationManager = PhoneConfigurationManager.getInstance(); |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 2417 | mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance(); |
Peter Wang | a3cf4ac | 2020-01-27 09:39:46 +0800 | [diff] [blame] | 2418 | mNotifyUserActivity = new AtomicBoolean(false); |
Tyler Gunn | 64144d9 | 2022-03-17 14:16:41 -0700 | [diff] [blame] | 2419 | PropertyInvalidatedCache.invalidateCache(TelephonyManager.CACHE_KEY_PHONE_ACCOUNT_TO_SUBID); |
Gil Cukierman | 6dac5eb | 2022-09-19 16:09:04 +0000 | [diff] [blame] | 2420 | mTelephony2gUpdater = new Telephony2gUpdater( |
| 2421 | Executors.newSingleThreadExecutor(), mApp); |
| 2422 | mTelephony2gUpdater.init(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2423 | publish(); |
| 2424 | } |
| 2425 | |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 2426 | @VisibleForTesting |
| 2427 | public SharedPreferences getSharedPreferences() { |
| 2428 | return mTelephonySharedPreferences; |
| 2429 | } |
| 2430 | |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2431 | private Phone getDefaultPhone() { |
| 2432 | Phone thePhone = getPhone(getDefaultSubscription()); |
| 2433 | return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone(); |
| 2434 | } |
| 2435 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2436 | private void publish() { |
| 2437 | if (DBG) log("publish: " + this); |
| 2438 | |
Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 2439 | TelephonyFrameworkInitializer |
| 2440 | .getTelephonyServiceManager() |
| 2441 | .getTelephonyServiceRegisterer() |
| 2442 | .register(this); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2443 | } |
| 2444 | |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 2445 | private Phone getPhoneFromRequest(MainThreadRequest request) { |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 2446 | if (request.phone != null) { |
| 2447 | return request.phone; |
| 2448 | } else { |
| 2449 | return getPhoneFromSubId(request.subId); |
| 2450 | } |
| 2451 | } |
| 2452 | |
| 2453 | private Phone getPhoneFromSubId(int subId) { |
| 2454 | return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) |
| 2455 | ? getDefaultPhone() : getPhone(subId); |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 2456 | } |
| 2457 | |
Rambo Wang | e53e07d | 2022-05-10 13:01:13 -0700 | [diff] [blame] | 2458 | @Nullable |
| 2459 | private UiccPort getUiccPortFromRequest(@NonNull MainThreadRequest request) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2460 | Phone phone = getPhoneFromRequest(request); |
| 2461 | return phone == null ? null : |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 2462 | UiccController.getInstance().getUiccPort(phone.getPhoneId()); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2463 | } |
| 2464 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2465 | // returns phone associated with the subId. |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2466 | private Phone getPhone(int subId) { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 2467 | return PhoneFactory.getPhone(SubscriptionManager.getPhoneId(subId)); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2468 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2469 | |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 2470 | private void sendEraseModemConfig(@NonNull Phone phone) { |
| 2471 | Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null); |
| 2472 | if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 2473 | } |
| 2474 | |
| 2475 | private void sendEraseDataInSharedPreferences(@NonNull Phone phone) { |
| 2476 | Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null); |
| 2477 | if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail")); |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 2478 | } |
| 2479 | |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 2480 | private boolean isImsAvailableOnDevice() { |
| 2481 | PackageManager pm = getDefaultPhone().getContext().getPackageManager(); |
| 2482 | if (pm == null) { |
| 2483 | // For some reason package manger is not available.. This will fail internally anyway, |
| 2484 | // so do not throw error and allow. |
| 2485 | return true; |
| 2486 | } |
| 2487 | return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0); |
| 2488 | } |
| 2489 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2490 | public void dial(String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2491 | dialForSubscriber(getPreferredVoiceSubscription(), number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2492 | } |
| 2493 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2494 | public void dialForSubscriber(int subId, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2495 | if (DBG) log("dial: " + number); |
| 2496 | // No permission check needed here: This is just a wrapper around the |
| 2497 | // ACTION_DIAL intent, which is available to any app since it puts up |
| 2498 | // the UI before it does anything. |
| 2499 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2500 | final long identity = Binder.clearCallingIdentity(); |
| 2501 | try { |
| 2502 | String url = createTelUrl(number); |
| 2503 | if (url == null) { |
| 2504 | return; |
| 2505 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2506 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2507 | // PENDING: should we just silently fail if phone is offhook or ringing? |
| 2508 | PhoneConstants.State state = mCM.getState(subId); |
| 2509 | if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) { |
| 2510 | Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url)); |
| 2511 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2512 | mApp.startActivity(intent); |
| 2513 | } |
| 2514 | } finally { |
| 2515 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2516 | } |
| 2517 | } |
| 2518 | |
| 2519 | public void call(String callingPackage, String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2520 | callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2521 | } |
| 2522 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2523 | public void callForSubscriber(int subId, String callingPackage, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2524 | if (DBG) log("call: " + number); |
| 2525 | |
| 2526 | // This is just a wrapper around the ACTION_CALL intent, but we still |
| 2527 | // need to do a permission check since we're calling startActivity() |
| 2528 | // from the context of the phone app. |
| 2529 | enforceCallPermission(); |
| 2530 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 2531 | if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage) |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2532 | != AppOpsManager.MODE_ALLOWED) { |
| 2533 | return; |
| 2534 | } |
| 2535 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2536 | final long identity = Binder.clearCallingIdentity(); |
| 2537 | try { |
| 2538 | String url = createTelUrl(number); |
| 2539 | if (url == null) { |
| 2540 | return; |
| 2541 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2542 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2543 | boolean isValid = false; |
| 2544 | final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged(); |
| 2545 | if (slist != null) { |
| 2546 | for (SubscriptionInfo subInfoRecord : slist) { |
| 2547 | if (subInfoRecord.getSubscriptionId() == subId) { |
| 2548 | isValid = true; |
| 2549 | break; |
| 2550 | } |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 2551 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 2552 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2553 | if (!isValid) { |
| 2554 | return; |
| 2555 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 2556 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2557 | Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url)); |
| 2558 | intent.putExtra(SUBSCRIPTION_KEY, subId); |
| 2559 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2560 | mApp.startActivity(intent); |
| 2561 | } finally { |
| 2562 | Binder.restoreCallingIdentity(identity); |
| 2563 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2564 | } |
| 2565 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2566 | public boolean supplyPinForSubscriber(int subId, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2567 | int [] resultArray = supplyPinReportResultForSubscriber(subId, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2568 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 2569 | } |
| 2570 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2571 | public boolean supplyPukForSubscriber(int subId, String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2572 | int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2573 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 2574 | } |
| 2575 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2576 | public int[] supplyPinReportResultForSubscriber(int subId, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2577 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2578 | |
| 2579 | final long identity = Binder.clearCallingIdentity(); |
| 2580 | try { |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2581 | Phone phone = getPhone(subId); |
| 2582 | final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2583 | checkSimPin.start(); |
| 2584 | return checkSimPin.unlockSim(null, pin); |
| 2585 | } finally { |
| 2586 | Binder.restoreCallingIdentity(identity); |
| 2587 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2588 | } |
| 2589 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2590 | public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2591 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2592 | |
| 2593 | final long identity = Binder.clearCallingIdentity(); |
| 2594 | try { |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2595 | Phone phone = getPhone(subId); |
| 2596 | final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2597 | checkSimPuk.start(); |
| 2598 | return checkSimPuk.unlockSim(puk, pin); |
| 2599 | } finally { |
| 2600 | Binder.restoreCallingIdentity(identity); |
| 2601 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2602 | } |
| 2603 | |
| 2604 | /** |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2605 | * Helper thread to turn async call to SimCard#supplyPin into |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2606 | * a synchronous one. |
| 2607 | */ |
| 2608 | private static class UnlockSim extends Thread { |
| 2609 | |
| 2610 | private final IccCard mSimCard; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2611 | private final int mPhoneId; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2612 | |
| 2613 | private boolean mDone = false; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2614 | private int mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 2615 | private int mRetryCount = -1; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2616 | |
| 2617 | // For replies from SimCard interface |
| 2618 | private Handler mHandler; |
| 2619 | |
| 2620 | // For async handler to identify request type |
| 2621 | private static final int SUPPLY_PIN_COMPLETE = 100; |
| 2622 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2623 | UnlockSim(int phoneId, IccCard simCard) { |
| 2624 | mPhoneId = phoneId; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2625 | mSimCard = simCard; |
| 2626 | } |
| 2627 | |
| 2628 | @Override |
| 2629 | public void run() { |
| 2630 | Looper.prepare(); |
| 2631 | synchronized (UnlockSim.this) { |
| 2632 | mHandler = new Handler() { |
| 2633 | @Override |
| 2634 | public void handleMessage(Message msg) { |
| 2635 | AsyncResult ar = (AsyncResult) msg.obj; |
| 2636 | switch (msg.what) { |
| 2637 | case SUPPLY_PIN_COMPLETE: |
| 2638 | Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE"); |
| 2639 | synchronized (UnlockSim.this) { |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2640 | mRetryCount = msg.arg1; |
| 2641 | if (ar.exception != null) { |
| 2642 | if (ar.exception instanceof CommandException && |
| 2643 | ((CommandException)(ar.exception)).getCommandError() |
| 2644 | == CommandException.Error.PASSWORD_INCORRECT) { |
| 2645 | mResult = PhoneConstants.PIN_PASSWORD_INCORRECT; |
vivi.li | b5e9ada | 2019-09-12 16:04:24 +0800 | [diff] [blame] | 2646 | } //When UiccCardApp dispose,handle message and return exception |
| 2647 | else if (ar.exception instanceof CommandException && |
| 2648 | ((CommandException) (ar.exception)).getCommandError() |
| 2649 | == CommandException.Error.ABORTED) { |
| 2650 | mResult = PhoneConstants.PIN_OPERATION_ABORTED; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2651 | } else { |
| 2652 | mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 2653 | } |
| 2654 | } else { |
| 2655 | mResult = PhoneConstants.PIN_RESULT_SUCCESS; |
| 2656 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2657 | mDone = true; |
| 2658 | UnlockSim.this.notifyAll(); |
| 2659 | } |
| 2660 | break; |
| 2661 | } |
| 2662 | } |
| 2663 | }; |
| 2664 | UnlockSim.this.notifyAll(); |
| 2665 | } |
| 2666 | Looper.loop(); |
| 2667 | } |
| 2668 | |
| 2669 | /* |
| 2670 | * Use PIN or PUK to unlock SIM card |
| 2671 | * |
| 2672 | * If PUK is null, unlock SIM card with PIN |
| 2673 | * |
| 2674 | * If PUK is not null, unlock SIM card with PUK and set PIN code |
| 2675 | */ |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2676 | synchronized int[] unlockSim(String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2677 | |
| 2678 | while (mHandler == null) { |
| 2679 | try { |
| 2680 | wait(); |
| 2681 | } catch (InterruptedException e) { |
| 2682 | Thread.currentThread().interrupt(); |
| 2683 | } |
| 2684 | } |
| 2685 | Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE); |
| 2686 | |
| 2687 | if (puk == null) { |
| 2688 | mSimCard.supplyPin(pin, callback); |
| 2689 | } else { |
| 2690 | mSimCard.supplyPuk(puk, pin, callback); |
| 2691 | } |
| 2692 | |
| 2693 | while (!mDone) { |
| 2694 | try { |
| 2695 | Log.d(LOG_TAG, "wait for done"); |
| 2696 | wait(); |
| 2697 | } catch (InterruptedException e) { |
| 2698 | // Restore the interrupted status |
| 2699 | Thread.currentThread().interrupt(); |
| 2700 | } |
| 2701 | } |
| 2702 | Log.d(LOG_TAG, "done"); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2703 | int[] resultArray = new int[2]; |
| 2704 | resultArray[0] = mResult; |
| 2705 | resultArray[1] = mRetryCount; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2706 | |
| 2707 | if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) { |
Jon Spivack | 9c3bc76 | 2021-10-06 20:53:09 +0000 | [diff] [blame] | 2708 | UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2709 | } |
| 2710 | |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2711 | return resultArray; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2712 | } |
| 2713 | } |
| 2714 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2715 | /** |
| 2716 | * This method has been removed due to privacy and stability concerns. |
| 2717 | */ |
| 2718 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2719 | public void updateServiceLocation() { |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2720 | Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()"); |
| 2721 | return; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2722 | } |
| 2723 | |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2724 | @Override |
| 2725 | public void updateServiceLocationWithPackageName(String callingPackage) { |
| 2726 | mApp.getSystemService(AppOpsManager.class) |
| 2727 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 2728 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 2729 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2730 | if (targetSdk > android.os.Build.VERSION_CODES.R) { |
| 2731 | // Callers targeting S have no business invoking this method. |
| 2732 | return; |
| 2733 | } |
| 2734 | |
| 2735 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2736 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2737 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2738 | .setCallingPackage(callingPackage) |
| 2739 | .setCallingFeatureId(null) |
| 2740 | .setCallingPid(Binder.getCallingPid()) |
| 2741 | .setCallingUid(Binder.getCallingUid()) |
| 2742 | .setMethod("updateServiceLocation") |
| 2743 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
| 2744 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2745 | .build()); |
| 2746 | // Apps that lack location permission have no business calling this method; |
| 2747 | // however, because no permission was declared in the public API, denials must |
| 2748 | // all be "soft". |
| 2749 | switch (locationResult) { |
| 2750 | case DENIED_HARD: /* fall through */ |
| 2751 | case DENIED_SOFT: |
| 2752 | return; |
| 2753 | } |
| 2754 | |
| 2755 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2756 | final long identity = Binder.clearCallingIdentity(); |
| 2757 | try { |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2758 | final Phone phone = getPhone(getDefaultSubscription()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2759 | if (phone != null) { |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2760 | phone.updateServiceLocation(workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2761 | } |
| 2762 | } finally { |
| 2763 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2764 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2765 | } |
| 2766 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2767 | @Deprecated |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2768 | @Override |
| 2769 | public boolean isRadioOn(String callingPackage) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2770 | return isRadioOnWithFeature(callingPackage, null); |
| 2771 | } |
| 2772 | |
| 2773 | |
| 2774 | @Override |
| 2775 | public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) { |
| 2776 | return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage, |
| 2777 | callingFeatureId); |
| 2778 | } |
| 2779 | |
| 2780 | @Deprecated |
| 2781 | @Override |
| 2782 | public boolean isRadioOnForSubscriber(int subId, String callingPackage) { |
| 2783 | return isRadioOnForSubscriberWithFeature(subId, callingPackage, null); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2784 | } |
| 2785 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2786 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2787 | public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage, |
| 2788 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2789 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2790 | mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2791 | return false; |
| 2792 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2793 | |
| 2794 | final long identity = Binder.clearCallingIdentity(); |
| 2795 | try { |
| 2796 | return isRadioOnForSubscriber(subId); |
| 2797 | } finally { |
| 2798 | Binder.restoreCallingIdentity(identity); |
| 2799 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2800 | } |
| 2801 | |
| 2802 | private boolean isRadioOnForSubscriber(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2803 | final long identity = Binder.clearCallingIdentity(); |
| 2804 | try { |
| 2805 | final Phone phone = getPhone(subId); |
| 2806 | if (phone != null) { |
| 2807 | return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF; |
| 2808 | } else { |
| 2809 | return false; |
| 2810 | } |
| 2811 | } finally { |
| 2812 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2813 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2814 | } |
| 2815 | |
| 2816 | public void toggleRadioOnOff() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2817 | toggleRadioOnOffForSubscriber(getDefaultSubscription()); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2818 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2819 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2820 | public void toggleRadioOnOffForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2821 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2822 | |
| 2823 | final long identity = Binder.clearCallingIdentity(); |
| 2824 | try { |
| 2825 | final Phone phone = getPhone(subId); |
| 2826 | if (phone != null) { |
| 2827 | phone.setRadioPower(!isRadioOnForSubscriber(subId)); |
| 2828 | } |
| 2829 | } finally { |
| 2830 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2831 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2832 | } |
| 2833 | |
| 2834 | public boolean setRadio(boolean turnOn) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2835 | return setRadioForSubscriber(getDefaultSubscription(), turnOn); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2836 | } |
| 2837 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2838 | public boolean setRadioForSubscriber(int subId, boolean turnOn) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2839 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2840 | |
| 2841 | final long identity = Binder.clearCallingIdentity(); |
| 2842 | try { |
| 2843 | final Phone phone = getPhone(subId); |
| 2844 | if (phone == null) { |
| 2845 | return false; |
| 2846 | } |
| 2847 | if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) { |
| 2848 | toggleRadioOnOffForSubscriber(subId); |
| 2849 | } |
| 2850 | return true; |
| 2851 | } finally { |
| 2852 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2853 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2854 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2855 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2856 | public boolean needMobileRadioShutdown() { |
Shuo Qian | fa7b6b3 | 2019-12-10 10:40:38 -0800 | [diff] [blame] | 2857 | enforceReadPrivilegedPermission("needMobileRadioShutdown"); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2858 | /* |
| 2859 | * If any of the Radios are available, it will need to be |
| 2860 | * shutdown. So return true if any Radio is available. |
| 2861 | */ |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2862 | final long identity = Binder.clearCallingIdentity(); |
| 2863 | try { |
| 2864 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 2865 | Phone phone = PhoneFactory.getPhone(i); |
| 2866 | if (phone != null && phone.isRadioAvailable()) return true; |
| 2867 | } |
| 2868 | logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown."); |
| 2869 | return false; |
| 2870 | } finally { |
| 2871 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2872 | } |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2873 | } |
| 2874 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2875 | @Override |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2876 | public void shutdownMobileRadios() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2877 | enforceModifyPermission(); |
| 2878 | |
| 2879 | final long identity = Binder.clearCallingIdentity(); |
| 2880 | try { |
| 2881 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 2882 | logv("Shutting down Phone " + i); |
| 2883 | shutdownRadioUsingPhoneId(i); |
| 2884 | } |
| 2885 | } finally { |
| 2886 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2887 | } |
| 2888 | } |
| 2889 | |
| 2890 | private void shutdownRadioUsingPhoneId(int phoneId) { |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2891 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 2892 | if (phone != null && phone.isRadioAvailable()) { |
| 2893 | phone.shutdownRadio(); |
| 2894 | } |
| 2895 | } |
| 2896 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2897 | public boolean setRadioPower(boolean turnOn) { |
Jack Yu | b4e1616 | 2017-05-15 12:48:40 -0700 | [diff] [blame] | 2898 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2899 | |
| 2900 | final long identity = Binder.clearCallingIdentity(); |
| 2901 | try { |
| 2902 | final Phone defaultPhone = PhoneFactory.getDefaultPhone(); |
| 2903 | if (defaultPhone != null) { |
| 2904 | defaultPhone.setRadioPower(turnOn); |
| 2905 | return true; |
| 2906 | } else { |
| 2907 | loge("There's no default phone."); |
| 2908 | return false; |
| 2909 | } |
| 2910 | } finally { |
| 2911 | Binder.restoreCallingIdentity(identity); |
Wei Liu | 9ae2a06 | 2016-08-08 11:09:34 -0700 | [diff] [blame] | 2912 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2913 | } |
| 2914 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2915 | public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2916 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2917 | |
| 2918 | final long identity = Binder.clearCallingIdentity(); |
| 2919 | try { |
| 2920 | final Phone phone = getPhone(subId); |
| 2921 | if (phone != null) { |
| 2922 | phone.setRadioPower(turnOn); |
| 2923 | return true; |
| 2924 | } else { |
| 2925 | return false; |
| 2926 | } |
| 2927 | } finally { |
| 2928 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2929 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2930 | } |
| 2931 | |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 2932 | /** |
| 2933 | * Vote on powering off the radio for a reason. The radio will be turned on only when there is |
| 2934 | * no reason to power it off. When any of the voters want to power it off, it will be turned |
| 2935 | * off. In case of emergency, the radio will be turned on even if there are some reasons for |
| 2936 | * powering it off, and these radio off votes will be cleared. |
| 2937 | * Multiple apps can vote for the same reason and the last vote will take effect. Each app is |
| 2938 | * responsible for its vote. A powering-off vote of a reason will be maintained until it is |
| 2939 | * cleared by calling {@link clearRadioPowerOffForReason} for that reason, or an emergency call |
| 2940 | * is made, or the device is rebooted. When an app comes backup from a crash, it needs to make |
| 2941 | * sure if its vote is as expected. An app can use the API {@link getRadioPowerOffReasons} to |
| 2942 | * check its vote. |
| 2943 | * |
| 2944 | * @param subId The subscription ID. |
| 2945 | * @param reason The reason for powering off radio. |
| 2946 | * @return true on success and false on failure. |
| 2947 | */ |
| 2948 | public boolean requestRadioPowerOffForReason(int subId, |
| 2949 | @TelephonyManager.RadioPowerReason int reason) { |
| 2950 | enforceModifyPermission(); |
| 2951 | |
| 2952 | final long identity = Binder.clearCallingIdentity(); |
| 2953 | try { |
| 2954 | final Phone phone = getPhone(subId); |
| 2955 | if (phone != null) { |
| 2956 | phone.setRadioPowerForReason(false, reason); |
| 2957 | return true; |
| 2958 | } else { |
| 2959 | return false; |
| 2960 | } |
| 2961 | } finally { |
| 2962 | Binder.restoreCallingIdentity(identity); |
| 2963 | } |
| 2964 | } |
| 2965 | |
| 2966 | /** |
| 2967 | * Remove the vote on powering off the radio for a reason, as requested by |
| 2968 | * {@link requestRadioPowerOffForReason}. |
| 2969 | * |
| 2970 | * @param subId The subscription ID. |
| 2971 | * @param reason The reason for powering off radio. |
| 2972 | * @return true on success and false on failure. |
| 2973 | */ |
| 2974 | public boolean clearRadioPowerOffForReason(int subId, |
| 2975 | @TelephonyManager.RadioPowerReason int reason) { |
| 2976 | enforceModifyPermission(); |
| 2977 | |
| 2978 | final long identity = Binder.clearCallingIdentity(); |
| 2979 | try { |
| 2980 | final Phone phone = getPhone(subId); |
| 2981 | if (phone != null) { |
| 2982 | phone.setRadioPowerForReason(true, reason); |
| 2983 | return true; |
| 2984 | } else { |
| 2985 | return false; |
| 2986 | } |
| 2987 | } finally { |
| 2988 | Binder.restoreCallingIdentity(identity); |
| 2989 | } |
| 2990 | } |
| 2991 | |
| 2992 | /** |
| 2993 | * Get reasons for powering off radio, as requested by {@link requestRadioPowerOffForReason}. |
| 2994 | * |
| 2995 | * @param subId The subscription ID. |
| 2996 | * @param callingPackage The package making the call. |
| 2997 | * @param callingFeatureId The feature in the package. |
| 2998 | * @return List of reasons for powering off radio. |
| 2999 | */ |
| 3000 | public List getRadioPowerOffReasons(int subId, String callingPackage, String callingFeatureId) { |
| 3001 | enforceReadPrivilegedPermission("getRadioPowerOffReasons"); |
| 3002 | |
| 3003 | final long identity = Binder.clearCallingIdentity(); |
| 3004 | List result = new ArrayList(); |
| 3005 | try { |
| 3006 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, |
| 3007 | callingPackage, callingFeatureId, "getRadioPowerOffReasons")) { |
| 3008 | return result; |
| 3009 | } |
| 3010 | |
| 3011 | final Phone phone = getPhone(subId); |
| 3012 | if (phone != null) { |
| 3013 | result.addAll(phone.getRadioPowerOffReasons()); |
| 3014 | } |
| 3015 | } finally { |
| 3016 | Binder.restoreCallingIdentity(identity); |
| 3017 | } |
| 3018 | return result; |
| 3019 | } |
| 3020 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3021 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3022 | @Override |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 3023 | public boolean enableDataConnectivity(String callingPackage) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3024 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3025 | |
| 3026 | final long identity = Binder.clearCallingIdentity(); |
| 3027 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3028 | int subId = SubscriptionManager.getDefaultDataSubscriptionId(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3029 | final Phone phone = getPhone(subId); |
| 3030 | if (phone != null) { |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 3031 | phone.getDataSettingsManager().setDataEnabled( |
| 3032 | TelephonyManager.DATA_ENABLED_REASON_USER, true, callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3033 | return true; |
| 3034 | } else { |
| 3035 | return false; |
| 3036 | } |
| 3037 | } finally { |
| 3038 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3039 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3040 | } |
| 3041 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3042 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3043 | @Override |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 3044 | public boolean disableDataConnectivity(String callingPackage) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3045 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3046 | |
| 3047 | final long identity = Binder.clearCallingIdentity(); |
| 3048 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3049 | int subId = SubscriptionManager.getDefaultDataSubscriptionId(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3050 | final Phone phone = getPhone(subId); |
| 3051 | if (phone != null) { |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 3052 | phone.getDataSettingsManager().setDataEnabled( |
| 3053 | TelephonyManager.DATA_ENABLED_REASON_USER, false, callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3054 | return true; |
| 3055 | } else { |
| 3056 | return false; |
| 3057 | } |
| 3058 | } finally { |
| 3059 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3060 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3061 | } |
| 3062 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3063 | @Override |
Jack Yu | acf8a13 | 2017-05-01 17:00:48 -0700 | [diff] [blame] | 3064 | public boolean isDataConnectivityPossible(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3065 | final long identity = Binder.clearCallingIdentity(); |
| 3066 | try { |
| 3067 | final Phone phone = getPhone(subId); |
| 3068 | if (phone != null) { |
Jack Yu | 59824e1 | 2022-03-23 01:42:44 -0700 | [diff] [blame] | 3069 | return phone.isDataAllowed(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3070 | } else { |
| 3071 | return false; |
| 3072 | } |
| 3073 | } finally { |
| 3074 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3075 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3076 | } |
| 3077 | |
| 3078 | public boolean handlePinMmi(String dialString) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 3079 | return handlePinMmiForSubscriber(getDefaultSubscription(), dialString); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3080 | } |
| 3081 | |
pkanwar | ae03a6b | 2016-11-06 20:37:09 -0800 | [diff] [blame] | 3082 | public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3083 | enforceCallPermission(); |
| 3084 | |
| 3085 | final long identity = Binder.clearCallingIdentity(); |
| 3086 | try { |
| 3087 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3088 | return; |
| 3089 | } |
| 3090 | Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback); |
| 3091 | sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId); |
| 3092 | } finally { |
| 3093 | Binder.restoreCallingIdentity(identity); |
| 3094 | } |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 3095 | }; |
| 3096 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3097 | public boolean handlePinMmiForSubscriber(int subId, String dialString) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3098 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3099 | |
| 3100 | final long identity = Binder.clearCallingIdentity(); |
| 3101 | try { |
| 3102 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3103 | return false; |
| 3104 | } |
| 3105 | return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId); |
| 3106 | } finally { |
| 3107 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3108 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3109 | } |
| 3110 | |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 3111 | /** |
| 3112 | * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage |
| 3113 | * tag on getCallState Binder call. |
| 3114 | */ |
| 3115 | @Deprecated |
| 3116 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3117 | public int getCallState() { |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 3118 | if (CompatChanges.isChangeEnabled( |
| 3119 | TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION, |
| 3120 | Binder.getCallingUid())) { |
| 3121 | // Do not allow this API to be called on API version 31+, it should only be |
| 3122 | // called on old apps using this Binder call directly. |
| 3123 | throw new SecurityException("This method can only be used for applications " |
| 3124 | + "targeting API version 30 or less."); |
| 3125 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3126 | final long identity = Binder.clearCallingIdentity(); |
| 3127 | try { |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 3128 | Phone phone = getPhone(getDefaultSubscription()); |
| 3129 | return phone == null ? TelephonyManager.CALL_STATE_IDLE : |
| 3130 | PhoneConstantConversions.convertCallState(phone.getState()); |
| 3131 | } finally { |
| 3132 | Binder.restoreCallingIdentity(identity); |
| 3133 | } |
| 3134 | } |
| 3135 | |
| 3136 | @Override |
| 3137 | public int getCallStateForSubscription(int subId, String callingPackage, String featureId) { |
| 3138 | if (CompatChanges.isChangeEnabled( |
| 3139 | TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION, |
| 3140 | Binder.getCallingUid())) { |
| 3141 | // Check READ_PHONE_STATE for API version 31+ |
| 3142 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage, |
| 3143 | featureId, "getCallStateForSubscription")) { |
| 3144 | throw new SecurityException("getCallState requires READ_PHONE_STATE for apps " |
| 3145 | + "targeting API level 31+."); |
| 3146 | } |
| 3147 | } |
| 3148 | final long identity = Binder.clearCallingIdentity(); |
| 3149 | try { |
| 3150 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3151 | return phone == null ? TelephonyManager.CALL_STATE_IDLE : |
| 3152 | PhoneConstantConversions.convertCallState(phone.getState()); |
| 3153 | } finally { |
| 3154 | Binder.restoreCallingIdentity(identity); |
| 3155 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3156 | } |
| 3157 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3158 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 3159 | public int getDataState() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3160 | return getDataStateForSubId(SubscriptionManager.getDefaultDataSubscriptionId()); |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 3161 | } |
| 3162 | |
| 3163 | @Override |
| 3164 | public int getDataStateForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3165 | final long identity = Binder.clearCallingIdentity(); |
| 3166 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 3167 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3168 | if (phone != null) { |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 3169 | return phone.getDataNetworkController().getInternetDataNetworkState(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3170 | } else { |
| 3171 | return PhoneConstantConversions.convertDataState( |
| 3172 | PhoneConstants.DataState.DISCONNECTED); |
| 3173 | } |
| 3174 | } finally { |
| 3175 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3176 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3177 | } |
| 3178 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3179 | @Override |
Jack Yu | 0eda684 | 2022-04-18 00:34:46 -0700 | [diff] [blame] | 3180 | public @DataActivityType int getDataActivity() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3181 | return getDataActivityForSubId(SubscriptionManager.getDefaultDataSubscriptionId()); |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 3182 | } |
| 3183 | |
| 3184 | @Override |
Jack Yu | 0eda684 | 2022-04-18 00:34:46 -0700 | [diff] [blame] | 3185 | public @DataActivityType int getDataActivityForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3186 | final long identity = Binder.clearCallingIdentity(); |
| 3187 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 3188 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3189 | if (phone != null) { |
Jack Yu | 0eda684 | 2022-04-18 00:34:46 -0700 | [diff] [blame] | 3190 | return phone.getDataActivityState(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3191 | } else { |
| 3192 | return TelephonyManager.DATA_ACTIVITY_NONE; |
| 3193 | } |
| 3194 | } finally { |
| 3195 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3196 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3197 | } |
| 3198 | |
| 3199 | @Override |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 3200 | public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3201 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 3202 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3203 | |
| 3204 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 3205 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 3206 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 3207 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3208 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3209 | .setCallingPid(Binder.getCallingPid()) |
| 3210 | .setCallingUid(Binder.getCallingUid()) |
| 3211 | .setMethod("getCellLocation") |
Hall Liu | 773ba02 | 2020-01-24 18:07:12 -0800 | [diff] [blame] | 3212 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3213 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 3214 | .build()); |
| 3215 | switch (locationResult) { |
| 3216 | case DENIED_HARD: |
| 3217 | throw new SecurityException("Not allowed to access cell location"); |
| 3218 | case DENIED_SOFT: |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 3219 | return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
| 3220 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3221 | } |
| 3222 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 3223 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3224 | final long identity = Binder.clearCallingIdentity(); |
| 3225 | try { |
| 3226 | if (DBG_LOC) log("getCellLocation: is active user"); |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3227 | int subId = SubscriptionManager.getDefaultDataSubscriptionId(); |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 3228 | return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3229 | } finally { |
| 3230 | Binder.restoreCallingIdentity(identity); |
| 3231 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 3232 | } |
| 3233 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3234 | @Override |
Jack Yu | eb1e7fe | 2020-02-22 19:38:58 -0800 | [diff] [blame] | 3235 | public String getNetworkCountryIsoForPhone(int phoneId) { |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3236 | // Reporting the correct network country is ambiguous when IWLAN could conflict with |
| 3237 | // registered cell info, so return a NULL country instead. |
| 3238 | final long identity = Binder.clearCallingIdentity(); |
| 3239 | try { |
Malcolm Chen | 3732c2b | 2018-07-18 20:15:24 -0700 | [diff] [blame] | 3240 | if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) { |
| 3241 | // Get default phone in this case. |
| 3242 | phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX; |
| 3243 | } |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3244 | final int subId = SubscriptionManager.getSubscriptionId(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3245 | Phone phone = PhoneFactory.getPhone(phoneId); |
Nathan Harold | 532f51c | 2020-04-21 19:31:10 -0700 | [diff] [blame] | 3246 | if (phone == null) return ""; |
| 3247 | ServiceStateTracker sst = phone.getServiceStateTracker(); |
| 3248 | if (sst == null) return ""; |
| 3249 | LocaleTracker lt = sst.getLocaleTracker(); |
| 3250 | if (lt == null) return ""; |
Shuo Qian | 9418a92 | 2021-03-09 11:21:16 -0800 | [diff] [blame] | 3251 | return lt.getCurrentCountry(); |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3252 | } finally { |
| 3253 | Binder.restoreCallingIdentity(identity); |
| 3254 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3255 | } |
| 3256 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 3257 | /** |
| 3258 | * This method was removed due to potential issues caused by performing partial |
| 3259 | * updates of service state, and lack of a credible use case. |
| 3260 | * |
| 3261 | * This has the ability to break the telephony implementation by disabling notification of |
| 3262 | * changes in device connectivity. DO NOT USE THIS! |
| 3263 | */ |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3264 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3265 | public void enableLocationUpdates() { |
| 3266 | mApp.enforceCallingOrSelfPermission( |
| 3267 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3268 | } |
| 3269 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 3270 | /** |
| 3271 | * This method was removed due to potential issues caused by performing partial |
| 3272 | * updates of service state, and lack of a credible use case. |
| 3273 | * |
| 3274 | * This has the ability to break the telephony implementation by disabling notification of |
| 3275 | * changes in device connectivity. DO NOT USE THIS! |
| 3276 | */ |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3277 | @Override |
| 3278 | public void disableLocationUpdates() { |
| 3279 | mApp.enforceCallingOrSelfPermission( |
| 3280 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3281 | } |
| 3282 | |
| 3283 | @Override |
| 3284 | @SuppressWarnings("unchecked") |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3285 | public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage, |
| 3286 | String callingFeatureId) { |
Nathan Harold | b55f63b | 2021-07-27 11:27:38 -0700 | [diff] [blame] | 3287 | try { |
| 3288 | mApp.getSystemService(AppOpsManager.class) |
| 3289 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 3290 | } catch (SecurityException e) { |
| 3291 | EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid()); |
| 3292 | throw e; |
| 3293 | } |
| 3294 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3295 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | dbea45a | 2018-08-30 14:35:07 -0700 | [diff] [blame] | 3296 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 3297 | throw new SecurityException( |
| 3298 | "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels."); |
| 3299 | } |
Nathan Harold | b4d5561 | 2018-07-20 13:13:08 -0700 | [diff] [blame] | 3300 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 3301 | if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(), |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3302 | callingPackage) != AppOpsManager.MODE_ALLOWED) { |
| 3303 | return null; |
| 3304 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 3305 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 3306 | if (DBG_LOC) log("getNeighboringCellInfo: is active user"); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3307 | |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3308 | List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId); |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 3309 | if (info == null) return null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3310 | |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 3311 | List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>(); |
| 3312 | for (CellInfo ci : info) { |
| 3313 | if (ci instanceof CellInfoGsm) { |
| 3314 | neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci)); |
| 3315 | } else if (ci instanceof CellInfoWcdma) { |
| 3316 | neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci)); |
| 3317 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3318 | } |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 3319 | return (neighbors.size()) > 0 ? neighbors : null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3320 | } |
| 3321 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3322 | private List<CellInfo> getCachedCellInfo() { |
| 3323 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 3324 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3325 | List<CellInfo> info = phone.getAllCellInfo(); |
| 3326 | if (info != null) cellInfos.addAll(info); |
| 3327 | } |
| 3328 | return cellInfos; |
| 3329 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3330 | |
| 3331 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3332 | public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3333 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 3334 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3335 | |
| 3336 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 3337 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 3338 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 3339 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3340 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3341 | .setCallingPid(Binder.getCallingPid()) |
| 3342 | .setCallingUid(Binder.getCallingUid()) |
| 3343 | .setMethod("getAllCellInfo") |
Nathan Harold | 5ae50b5 | 2019-02-20 15:46:36 -0800 | [diff] [blame] | 3344 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3345 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 3346 | .build()); |
| 3347 | switch (locationResult) { |
| 3348 | case DENIED_HARD: |
| 3349 | throw new SecurityException("Not allowed to access cell info"); |
| 3350 | case DENIED_SOFT: |
| 3351 | return new ArrayList<>(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3352 | } |
| 3353 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3354 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3355 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 3356 | return getCachedCellInfo(); |
| 3357 | } |
| 3358 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 3359 | if (DBG_LOC) log("getAllCellInfo: is active user"); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 3360 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3361 | final long identity = Binder.clearCallingIdentity(); |
| 3362 | try { |
| 3363 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 3364 | for (Phone phone : PhoneFactory.getPhones()) { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 3365 | final List<CellInfo> info = (List<CellInfo>) sendRequest( |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 3366 | CMD_GET_ALL_CELL_INFO, null, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3367 | if (info != null) cellInfos.addAll(info); |
| 3368 | } |
| 3369 | return cellInfos; |
| 3370 | } finally { |
| 3371 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3372 | } |
| 3373 | } |
| 3374 | |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 3375 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3376 | public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage, |
| 3377 | String callingFeatureId) { |
| 3378 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, |
| 3379 | getWorkSource(Binder.getCallingUid())); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3380 | } |
| 3381 | |
| 3382 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3383 | public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb, |
| 3384 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3385 | enforceModifyPermission(); |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3386 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3387 | } |
| 3388 | |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3389 | private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb, |
| 3390 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3391 | mApp.getSystemService(AppOpsManager.class) |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3392 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3393 | |
| 3394 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 3395 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 3396 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 3397 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3398 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3399 | .setCallingPid(Binder.getCallingPid()) |
| 3400 | .setCallingUid(Binder.getCallingUid()) |
| 3401 | .setMethod("requestCellInfoUpdate") |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 3402 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
| 3403 | .setMinSdkVersionForFine(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3404 | .build()); |
| 3405 | switch (locationResult) { |
| 3406 | case DENIED_HARD: |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3407 | if (TelephonyPermissions |
| 3408 | .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) { |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 3409 | // Safetynet logging for b/154934934 |
| 3410 | EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid()); |
| 3411 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3412 | throw new SecurityException("Not allowed to access cell info"); |
| 3413 | case DENIED_SOFT: |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3414 | if (TelephonyPermissions |
| 3415 | .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) { |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 3416 | // Safetynet logging for b/154934934 |
| 3417 | EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid()); |
| 3418 | } |
Nathan Harold | 5320c42 | 2019-05-09 10:26:08 -0700 | [diff] [blame] | 3419 | try { |
| 3420 | cb.onCellInfo(new ArrayList<CellInfo>()); |
| 3421 | } catch (RemoteException re) { |
| 3422 | // Drop without consequences |
| 3423 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3424 | return; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3425 | } |
| 3426 | |
Nathan Harold | a939a96 | 2019-05-09 10:13:47 -0700 | [diff] [blame] | 3427 | |
| 3428 | final Phone phone = getPhoneFromSubId(subId); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3429 | if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
| 3430 | |
| 3431 | sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource); |
| 3432 | } |
| 3433 | |
| 3434 | @Override |
Aishwarya Mallampati | 0603fb1 | 2022-08-24 21:16:56 +0000 | [diff] [blame] | 3435 | public void setCellInfoListRate(int rateInMillis, int subId) { |
Jack Yu | a8d8cb8 | 2017-01-16 10:15:34 -0800 | [diff] [blame] | 3436 | enforceModifyPermission(); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 3437 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3438 | |
| 3439 | final long identity = Binder.clearCallingIdentity(); |
| 3440 | try { |
Aishwarya Mallampati | 0603fb1 | 2022-08-24 21:16:56 +0000 | [diff] [blame] | 3441 | Phone phone = getPhone(subId); |
| 3442 | if (phone == null) { |
| 3443 | getDefaultPhone().setCellInfoListRate(rateInMillis, workSource); |
| 3444 | } else { |
| 3445 | phone.setCellInfoListRate(rateInMillis, workSource); |
| 3446 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3447 | } finally { |
| 3448 | Binder.restoreCallingIdentity(identity); |
| 3449 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3450 | } |
| 3451 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3452 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3453 | public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3454 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3455 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3456 | return null; |
| 3457 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3458 | int subId = phone.getSubId(); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3459 | enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot"); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 3460 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3461 | callingPackage, callingFeatureId, "getImeiForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3462 | return null; |
| 3463 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3464 | |
| 3465 | final long identity = Binder.clearCallingIdentity(); |
| 3466 | try { |
| 3467 | return phone.getImei(); |
| 3468 | } finally { |
| 3469 | Binder.restoreCallingIdentity(identity); |
| 3470 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3471 | } |
| 3472 | |
| 3473 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3474 | public String getTypeAllocationCodeForSlot(int slotIndex) { |
| 3475 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3476 | String tac = null; |
| 3477 | if (phone != null) { |
| 3478 | String imei = phone.getImei(); |
Vala Zadeh | ab00555 | 2021-09-21 15:54:29 -0700 | [diff] [blame] | 3479 | try { |
| 3480 | tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH); |
| 3481 | } catch (IndexOutOfBoundsException e) { |
| 3482 | Log.e(LOG_TAG, "IMEI length shorter than upper index."); |
| 3483 | return null; |
| 3484 | } |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3485 | } |
| 3486 | return tac; |
| 3487 | } |
| 3488 | |
| 3489 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3490 | public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Shuo Qian | 13d8915 | 2021-05-10 23:58:11 -0700 | [diff] [blame] | 3491 | try { |
| 3492 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 3493 | } catch (SecurityException se) { |
| 3494 | EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid()); |
| 3495 | throw new SecurityException("Package " + callingPackage + " does not belong to " |
| 3496 | + Binder.getCallingUid()); |
| 3497 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3498 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3499 | if (phone == null) { |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 3500 | return null; |
| 3501 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3502 | |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3503 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 3504 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3505 | callingPackage, callingFeatureId, "getMeidForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3506 | return null; |
| 3507 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3508 | |
| 3509 | final long identity = Binder.clearCallingIdentity(); |
| 3510 | try { |
| 3511 | return phone.getMeid(); |
| 3512 | } finally { |
| 3513 | Binder.restoreCallingIdentity(identity); |
| 3514 | } |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 3515 | } |
| 3516 | |
| 3517 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3518 | public String getManufacturerCodeForSlot(int slotIndex) { |
| 3519 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3520 | String manufacturerCode = null; |
| 3521 | if (phone != null) { |
| 3522 | String meid = phone.getMeid(); |
Vala Zadeh | ab00555 | 2021-09-21 15:54:29 -0700 | [diff] [blame] | 3523 | try { |
| 3524 | manufacturerCode = |
| 3525 | meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH); |
| 3526 | } catch (IndexOutOfBoundsException e) { |
| 3527 | Log.e(LOG_TAG, "MEID length shorter than upper index."); |
| 3528 | return null; |
| 3529 | } |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3530 | } |
| 3531 | return manufacturerCode; |
| 3532 | } |
| 3533 | |
| 3534 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3535 | public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage, |
| 3536 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3537 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3538 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3539 | return null; |
| 3540 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3541 | int subId = phone.getSubId(); |
| 3542 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3543 | mApp, subId, callingPackage, callingFeatureId, |
| 3544 | "getDeviceSoftwareVersionForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3545 | return null; |
| 3546 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3547 | |
| 3548 | final long identity = Binder.clearCallingIdentity(); |
| 3549 | try { |
| 3550 | return phone.getDeviceSvn(); |
| 3551 | } finally { |
| 3552 | Binder.restoreCallingIdentity(identity); |
| 3553 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3554 | } |
| 3555 | |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3556 | @Override |
| 3557 | public int getSubscriptionCarrierId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3558 | final long identity = Binder.clearCallingIdentity(); |
| 3559 | try { |
| 3560 | final Phone phone = getPhone(subId); |
| 3561 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId(); |
| 3562 | } finally { |
| 3563 | Binder.restoreCallingIdentity(identity); |
| 3564 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3565 | } |
| 3566 | |
| 3567 | @Override |
| 3568 | public String getSubscriptionCarrierName(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3569 | final long identity = Binder.clearCallingIdentity(); |
| 3570 | try { |
| 3571 | final Phone phone = getPhone(subId); |
| 3572 | return phone == null ? null : phone.getCarrierName(); |
| 3573 | } finally { |
| 3574 | Binder.restoreCallingIdentity(identity); |
| 3575 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3576 | } |
| 3577 | |
calvinpan | ffe225e | 2018-11-01 19:43:06 +0800 | [diff] [blame] | 3578 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3579 | public int getSubscriptionSpecificCarrierId(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3580 | final long identity = Binder.clearCallingIdentity(); |
| 3581 | try { |
| 3582 | final Phone phone = getPhone(subId); |
| 3583 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3584 | : phone.getSpecificCarrierId(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3585 | } finally { |
| 3586 | Binder.restoreCallingIdentity(identity); |
| 3587 | } |
| 3588 | } |
| 3589 | |
| 3590 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3591 | public String getSubscriptionSpecificCarrierName(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3592 | final long identity = Binder.clearCallingIdentity(); |
| 3593 | try { |
| 3594 | final Phone phone = getPhone(subId); |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3595 | return phone == null ? null : phone.getSpecificCarrierName(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3596 | } finally { |
| 3597 | Binder.restoreCallingIdentity(identity); |
| 3598 | } |
| 3599 | } |
| 3600 | |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 3601 | @Override |
chen xu | 864e11c | 2018-12-06 22:10:03 -0800 | [diff] [blame] | 3602 | public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) { |
| 3603 | if (!isSubscriptionMccMnc) { |
| 3604 | enforceReadPrivilegedPermission("getCarrierIdFromMccMnc"); |
| 3605 | } |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 3606 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3607 | if (phone == null) { |
| 3608 | return TelephonyManager.UNKNOWN_CARRIER_ID; |
| 3609 | } |
| 3610 | final long identity = Binder.clearCallingIdentity(); |
| 3611 | try { |
| 3612 | return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc); |
| 3613 | } finally { |
| 3614 | Binder.restoreCallingIdentity(identity); |
| 3615 | } |
| 3616 | } |
| 3617 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3618 | // |
| 3619 | // Internal helper methods. |
| 3620 | // |
| 3621 | |
Sanket Padawe | ee13a9b | 2016-03-08 17:30:28 -0800 | [diff] [blame] | 3622 | /** |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3623 | * Make sure the caller is the calling package itself |
| 3624 | * |
| 3625 | * @throws SecurityException if the caller is not the calling package |
| 3626 | */ |
| 3627 | private void enforceCallingPackage(String callingPackage, int callingUid, String message) { |
| 3628 | int packageUid = -1; |
Grace Jia | dbefca0 | 2021-04-26 15:13:31 -0700 | [diff] [blame] | 3629 | PackageManager pm = mApp.getBaseContext().createContextAsUser( |
| 3630 | UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager(); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3631 | try { |
Grace Jia | dbefca0 | 2021-04-26 15:13:31 -0700 | [diff] [blame] | 3632 | packageUid = pm.getPackageUid(callingPackage, 0); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3633 | } catch (PackageManager.NameNotFoundException e) { |
| 3634 | // packageUid is -1 |
| 3635 | } |
| 3636 | if (packageUid != callingUid) { |
| 3637 | throw new SecurityException(message + ": Package " + callingPackage |
| 3638 | + " does not belong to " + callingUid); |
| 3639 | } |
| 3640 | } |
| 3641 | |
| 3642 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3643 | * Make sure the caller has the MODIFY_PHONE_STATE permission. |
| 3644 | * |
| 3645 | * @throws SecurityException if the caller does not have the required permission |
| 3646 | */ |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 3647 | @VisibleForTesting |
| 3648 | public void enforceModifyPermission() { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3649 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null); |
| 3650 | } |
| 3651 | |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 3652 | /** |
| 3653 | * Make sure the caller has the MODIFY_PHONE_STATE permission. |
| 3654 | * |
| 3655 | * @throws SecurityException if the caller does not have the required permission |
| 3656 | */ |
| 3657 | @VisibleForTesting |
| 3658 | public void enforceReadPermission() { |
| 3659 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, null); |
| 3660 | } |
| 3661 | |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 3662 | private void enforceActiveEmergencySessionPermission() { |
| 3663 | mApp.enforceCallingOrSelfPermission( |
| 3664 | android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null); |
| 3665 | } |
| 3666 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3667 | /** |
| 3668 | * Make sure the caller has the CALL_PHONE permission. |
| 3669 | * |
| 3670 | * @throws SecurityException if the caller does not have the required permission |
| 3671 | */ |
| 3672 | private void enforceCallPermission() { |
| 3673 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null); |
| 3674 | } |
| 3675 | |
paulhu | 5a77360 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 3676 | private void enforceSettingsPermission() { |
| 3677 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 3678 | } |
| 3679 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 3680 | private void enforceRebootPermission() { |
| 3681 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null); |
| 3682 | } |
| 3683 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3684 | private String createTelUrl(String number) { |
| 3685 | if (TextUtils.isEmpty(number)) { |
| 3686 | return null; |
| 3687 | } |
| 3688 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3689 | return "tel:" + number; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3690 | } |
| 3691 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3692 | private static void log(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3693 | Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 3694 | } |
| 3695 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3696 | private static void logv(String msg) { |
| 3697 | Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 3698 | } |
| 3699 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3700 | private static void loge(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3701 | Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 3702 | } |
| 3703 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3704 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3705 | public int getActivePhoneType() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3706 | return getActivePhoneTypeForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3707 | } |
| 3708 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3709 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3710 | public int getActivePhoneTypeForSlot(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3711 | final long identity = Binder.clearCallingIdentity(); |
| 3712 | try { |
| 3713 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3714 | if (phone == null) { |
| 3715 | return PhoneConstants.PHONE_TYPE_NONE; |
| 3716 | } else { |
| 3717 | return phone.getPhoneType(); |
| 3718 | } |
| 3719 | } finally { |
| 3720 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3721 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3722 | } |
| 3723 | |
| 3724 | /** |
| 3725 | * Returns the CDMA ERI icon index to display |
| 3726 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3727 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3728 | public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) { |
| 3729 | return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage, |
| 3730 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3731 | } |
| 3732 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3733 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3734 | public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage, |
| 3735 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3736 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3737 | mApp, subId, callingPackage, callingFeatureId, |
| 3738 | "getCdmaEriIconIndexForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3739 | return -1; |
| 3740 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3741 | |
| 3742 | final long identity = Binder.clearCallingIdentity(); |
| 3743 | try { |
| 3744 | final Phone phone = getPhone(subId); |
| 3745 | if (phone != null) { |
| 3746 | return phone.getCdmaEriIconIndex(); |
| 3747 | } else { |
| 3748 | return -1; |
| 3749 | } |
| 3750 | } finally { |
| 3751 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3752 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3753 | } |
| 3754 | |
| 3755 | /** |
| 3756 | * Returns the CDMA ERI icon mode, |
| 3757 | * 0 - ON |
| 3758 | * 1 - FLASHING |
| 3759 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3760 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3761 | public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) { |
| 3762 | return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 3763 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3764 | } |
| 3765 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3766 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3767 | public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage, |
| 3768 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3769 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3770 | mApp, subId, callingPackage, callingFeatureId, |
| 3771 | "getCdmaEriIconModeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3772 | return -1; |
| 3773 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3774 | |
| 3775 | final long identity = Binder.clearCallingIdentity(); |
| 3776 | try { |
| 3777 | final Phone phone = getPhone(subId); |
| 3778 | if (phone != null) { |
| 3779 | return phone.getCdmaEriIconMode(); |
| 3780 | } else { |
| 3781 | return -1; |
| 3782 | } |
| 3783 | } finally { |
| 3784 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3785 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3786 | } |
| 3787 | |
| 3788 | /** |
| 3789 | * Returns the CDMA ERI text, |
| 3790 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3791 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3792 | public String getCdmaEriText(String callingPackage, String callingFeatureId) { |
| 3793 | return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage, |
| 3794 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3795 | } |
| 3796 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3797 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3798 | public String getCdmaEriTextForSubscriber(int subId, String callingPackage, |
| 3799 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3800 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3801 | mApp, subId, callingPackage, callingFeatureId, |
| 3802 | "getCdmaEriIconTextForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3803 | return null; |
| 3804 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3805 | |
| 3806 | final long identity = Binder.clearCallingIdentity(); |
| 3807 | try { |
| 3808 | final Phone phone = getPhone(subId); |
| 3809 | if (phone != null) { |
| 3810 | return phone.getCdmaEriText(); |
| 3811 | } else { |
| 3812 | return null; |
| 3813 | } |
| 3814 | } finally { |
| 3815 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3816 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3817 | } |
| 3818 | |
| 3819 | /** |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3820 | * Returns the CDMA MDN. |
| 3821 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3822 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3823 | public String getCdmaMdn(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3824 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3825 | mApp, subId, "getCdmaMdn"); |
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); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3830 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3831 | return phone.getLine1Number(); |
| 3832 | } else { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3833 | loge("getCdmaMdn: no phone found. Invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3834 | return null; |
| 3835 | } |
| 3836 | } finally { |
| 3837 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3838 | } |
| 3839 | } |
| 3840 | |
| 3841 | /** |
| 3842 | * Returns the CDMA MIN. |
| 3843 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3844 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3845 | public String getCdmaMin(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3846 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3847 | mApp, subId, "getCdmaMin"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3848 | |
| 3849 | final long identity = Binder.clearCallingIdentity(); |
| 3850 | try { |
| 3851 | final Phone phone = getPhone(subId); |
| 3852 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
| 3853 | return phone.getCdmaMin(); |
| 3854 | } else { |
| 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 | |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3862 | @Override |
| 3863 | public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis, |
| 3864 | INumberVerificationCallback callback, String callingPackage) { |
| 3865 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 3866 | != PERMISSION_GRANTED) { |
| 3867 | throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission"); |
| 3868 | } |
| 3869 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 3870 | |
| 3871 | String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp); |
| 3872 | if (!TextUtils.equals(callingPackage, authorizedPackage)) { |
Hall Liu | b9d8feb | 2021-01-13 10:28:04 -0800 | [diff] [blame] | 3873 | throw new SecurityException("Calling package must be configured in the device config: " |
| 3874 | + "calling package: " + callingPackage |
| 3875 | + ", configured package: " + authorizedPackage); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3876 | } |
| 3877 | |
| 3878 | if (range == null) { |
| 3879 | throw new NullPointerException("Range must be non-null"); |
| 3880 | } |
| 3881 | |
| 3882 | timeoutMillis = Math.min(timeoutMillis, |
Hall Liu | bd069e3 | 2019-02-28 18:56:30 -0800 | [diff] [blame] | 3883 | TelephonyManager.getMaxNumberVerificationTimeoutMillis()); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3884 | |
| 3885 | NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis); |
| 3886 | } |
| 3887 | |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3888 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3889 | * Returns true if CDMA provisioning needs to run. |
| 3890 | */ |
| 3891 | public boolean needsOtaServiceProvisioning() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3892 | final long identity = Binder.clearCallingIdentity(); |
| 3893 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3894 | return getDefaultPhone().needsOtaServiceProvisioning(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3895 | } finally { |
| 3896 | Binder.restoreCallingIdentity(identity); |
| 3897 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3898 | } |
| 3899 | |
| 3900 | /** |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3901 | * Sets the voice mail number of a given subId. |
| 3902 | */ |
| 3903 | @Override |
| 3904 | public boolean setVoiceMailNumber(int subId, String alphaTag, String number) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 3905 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 3906 | mApp, subId, "setVoiceMailNumber"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3907 | |
| 3908 | final long identity = Binder.clearCallingIdentity(); |
| 3909 | try { |
| 3910 | Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER, |
| 3911 | new Pair<String, String>(alphaTag, number), new Integer(subId)); |
| 3912 | return success; |
| 3913 | } finally { |
| 3914 | Binder.restoreCallingIdentity(identity); |
| 3915 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3916 | } |
| 3917 | |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3918 | @Override |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3919 | public Bundle getVisualVoicemailSettings(String callingPackage, int subId) { |
| 3920 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 3921 | TelecomManager tm = mApp.getSystemService(TelecomManager.class); |
| 3922 | String systemDialer = tm.getSystemDialerPackage(); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3923 | if (!TextUtils.equals(callingPackage, systemDialer)) { |
| 3924 | throw new SecurityException("caller must be system dialer"); |
| 3925 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3926 | |
| 3927 | final long identity = Binder.clearCallingIdentity(); |
| 3928 | try { |
| 3929 | PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId); |
| 3930 | if (phoneAccountHandle == null) { |
| 3931 | return null; |
| 3932 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3933 | return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3934 | } finally { |
| 3935 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3936 | } |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3937 | } |
| 3938 | |
| 3939 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3940 | public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId, |
| 3941 | int subId) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3942 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3943 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3944 | mApp, subId, callingPackage, callingFeatureId, |
| 3945 | "getVisualVoicemailPackageName")) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3946 | return null; |
| 3947 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3948 | |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 3949 | final long identity = Binder.clearCallingIdentity(); |
| 3950 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3951 | return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName(); |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 3952 | } finally { |
| 3953 | Binder.restoreCallingIdentity(identity); |
| 3954 | } |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3955 | } |
| 3956 | |
| 3957 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3958 | public void enableVisualVoicemailSmsFilter(String callingPackage, int subId, |
| 3959 | VisualVoicemailSmsFilterSettings settings) { |
| 3960 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3961 | |
| 3962 | final long identity = Binder.clearCallingIdentity(); |
| 3963 | try { |
| 3964 | VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3965 | mApp, callingPackage, subId, settings); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3966 | } finally { |
| 3967 | Binder.restoreCallingIdentity(identity); |
| 3968 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3969 | } |
| 3970 | |
| 3971 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3972 | public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) { |
| 3973 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3974 | |
| 3975 | final long identity = Binder.clearCallingIdentity(); |
| 3976 | try { |
| 3977 | VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3978 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3979 | } finally { |
| 3980 | Binder.restoreCallingIdentity(identity); |
| 3981 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3982 | } |
| 3983 | |
| 3984 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3985 | public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings( |
| 3986 | String callingPackage, int subId) { |
| 3987 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3988 | |
| 3989 | final long identity = Binder.clearCallingIdentity(); |
| 3990 | try { |
| 3991 | return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3992 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3993 | } finally { |
| 3994 | Binder.restoreCallingIdentity(identity); |
| 3995 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3996 | } |
| 3997 | |
| 3998 | @Override |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3999 | public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4000 | enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4001 | |
| 4002 | final long identity = Binder.clearCallingIdentity(); |
| 4003 | try { |
| 4004 | return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4005 | mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4006 | } finally { |
| 4007 | Binder.restoreCallingIdentity(identity); |
| 4008 | } |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 4009 | } |
| 4010 | |
| 4011 | @Override |
Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 4012 | public void sendVisualVoicemailSmsForSubscriber(String callingPackage, |
| 4013 | String callingAttributionTag, int subId, String number, int port, String text, |
| 4014 | PendingIntent sentIntent) { |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 4015 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 4016 | enforceVisualVoicemailPackage(callingPackage, subId); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 4017 | enforceSendSmsPermission(); |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 4018 | SmsController smsController = PhoneFactory.getSmsController(); |
Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 4019 | smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag, |
| 4020 | subId, number, port, text, sentIntent); |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 4021 | } |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 4022 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 4023 | /** |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4024 | * Sets the voice activation state of a given subId. |
| 4025 | */ |
| 4026 | @Override |
| 4027 | public void setVoiceActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4028 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4029 | mApp, subId, "setVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4030 | |
| 4031 | final long identity = Binder.clearCallingIdentity(); |
| 4032 | try { |
| 4033 | final Phone phone = getPhone(subId); |
| 4034 | if (phone != null) { |
| 4035 | phone.setVoiceActivationState(activationState); |
| 4036 | } else { |
| 4037 | loge("setVoiceActivationState fails with invalid subId: " + subId); |
| 4038 | } |
| 4039 | } finally { |
| 4040 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4041 | } |
| 4042 | } |
| 4043 | |
| 4044 | /** |
| 4045 | * Sets the data activation state of a given subId. |
| 4046 | */ |
| 4047 | @Override |
| 4048 | public void setDataActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4049 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4050 | mApp, subId, "setDataActivationState"); |
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.setDataActivationState(activationState); |
| 4057 | } else { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 4058 | loge("setDataActivationState fails with invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4059 | } |
| 4060 | } finally { |
| 4061 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4062 | } |
| 4063 | } |
| 4064 | |
| 4065 | /** |
| 4066 | * Returns the voice activation state of a given subId. |
| 4067 | */ |
| 4068 | @Override |
| 4069 | public int getVoiceActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4070 | enforceReadPrivilegedPermission("getVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4071 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4072 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4073 | final long identity = Binder.clearCallingIdentity(); |
| 4074 | try { |
| 4075 | if (phone != null) { |
| 4076 | return phone.getVoiceActivationState(); |
| 4077 | } else { |
| 4078 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 4079 | } |
| 4080 | } finally { |
| 4081 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4082 | } |
| 4083 | } |
| 4084 | |
| 4085 | /** |
| 4086 | * Returns the data activation state of a given subId. |
| 4087 | */ |
| 4088 | @Override |
| 4089 | public int getDataActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4090 | enforceReadPrivilegedPermission("getDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4091 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4092 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4093 | final long identity = Binder.clearCallingIdentity(); |
| 4094 | try { |
| 4095 | if (phone != null) { |
| 4096 | return phone.getDataActivationState(); |
| 4097 | } else { |
| 4098 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 4099 | } |
| 4100 | } finally { |
| 4101 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4102 | } |
| 4103 | } |
| 4104 | |
| 4105 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4106 | * Returns the unread count of voicemails for a subId |
| 4107 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4108 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4109 | public int getVoiceMessageCountForSubscriber(int subId, String callingPackage, |
| 4110 | String callingFeatureId) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 4111 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4112 | mApp, subId, callingPackage, callingFeatureId, |
| 4113 | "getVoiceMessageCountForSubscriber")) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 4114 | return 0; |
| 4115 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4116 | final long identity = Binder.clearCallingIdentity(); |
| 4117 | try { |
| 4118 | final Phone phone = getPhone(subId); |
| 4119 | if (phone != null) { |
| 4120 | return phone.getVoiceMessageCount(); |
| 4121 | } else { |
| 4122 | return 0; |
| 4123 | } |
| 4124 | } finally { |
| 4125 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4126 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4127 | } |
| 4128 | |
| 4129 | /** |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 4130 | * returns true, if the device is in a state where both voice and data |
| 4131 | * are supported simultaneously. This can change based on location or network condition. |
| 4132 | */ |
| 4133 | @Override |
| 4134 | public boolean isConcurrentVoiceAndDataAllowed(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4135 | final long identity = Binder.clearCallingIdentity(); |
| 4136 | try { |
| 4137 | final Phone phone = getPhone(subId); |
| 4138 | return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed()); |
| 4139 | } finally { |
| 4140 | Binder.restoreCallingIdentity(identity); |
| 4141 | } |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 4142 | } |
| 4143 | |
| 4144 | /** |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4145 | * Send the dialer code if called from the current default dialer or the caller has |
| 4146 | * carrier privilege. |
| 4147 | * @param inputCode The dialer code to send |
| 4148 | */ |
| 4149 | @Override |
| 4150 | public void sendDialerSpecialCode(String callingPackage, String inputCode) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4151 | final Phone defaultPhone = getDefaultPhone(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4152 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 4153 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 4154 | String defaultDialer = tm.getDefaultDialerPackage(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4155 | if (!TextUtils.equals(callingPackage, defaultDialer)) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 4156 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4157 | getDefaultSubscription(), "sendDialerSpecialCode"); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4158 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4159 | |
| 4160 | final long identity = Binder.clearCallingIdentity(); |
| 4161 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4162 | defaultPhone.sendDialerSpecialCode(inputCode); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4163 | } finally { |
| 4164 | Binder.restoreCallingIdentity(identity); |
| 4165 | } |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4166 | } |
| 4167 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 4168 | @Override |
| 4169 | public int getNetworkSelectionMode(int subId) { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 4170 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4171 | .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 4172 | mApp, subId, "getNetworkSelectionMode"); |
| 4173 | final long identity = Binder.clearCallingIdentity(); |
| 4174 | try { |
| 4175 | if (!isActiveSubscription(subId)) { |
| 4176 | return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 4177 | } |
| 4178 | return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId); |
| 4179 | } finally { |
| 4180 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 4181 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 4182 | } |
| 4183 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4184 | @Override |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 4185 | public boolean isInEmergencySmsMode() { |
| 4186 | enforceReadPrivilegedPermission("isInEmergencySmsMode"); |
| 4187 | final long identity = Binder.clearCallingIdentity(); |
| 4188 | try { |
| 4189 | for (Phone phone : PhoneFactory.getPhones()) { |
| 4190 | if (phone.isInEmergencySmsMode()) { |
| 4191 | return true; |
| 4192 | } |
| 4193 | } |
| 4194 | } finally { |
| 4195 | Binder.restoreCallingIdentity(identity); |
| 4196 | } |
| 4197 | return false; |
| 4198 | } |
| 4199 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4200 | /** |
| 4201 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4202 | * @param subId The subscription to use to check the configuration. |
| 4203 | * @param c The callback that will be used to send the result. |
| 4204 | */ |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 4205 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4206 | public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c) |
| 4207 | throws RemoteException { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4208 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4209 | mApp, subId, "registerImsRegistrationCallback"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4210 | |
| 4211 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4212 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4213 | "IMS not available on device."); |
| 4214 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4215 | final long token = Binder.clearCallingIdentity(); |
| 4216 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4217 | int slotId = getSlotIndexOrException(subId); |
| 4218 | verifyImsMmTelConfiguredOrThrow(slotId); |
joonhunshin | 49f0aed | 2022-08-05 08:33:05 +0000 | [diff] [blame] | 4219 | |
| 4220 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4221 | if (controller != null) { |
| 4222 | ImsManager imsManager = controller.getImsManager(subId); |
| 4223 | if (imsManager != null) { |
| 4224 | imsManager.addRegistrationCallbackForSubscription(c, subId); |
| 4225 | } else { |
| 4226 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE); |
| 4227 | } |
| 4228 | } else { |
| 4229 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION); |
| 4230 | } |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4231 | } catch (ImsException e) { |
| 4232 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4233 | } finally { |
| 4234 | Binder.restoreCallingIdentity(token); |
| 4235 | } |
| 4236 | } |
| 4237 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4238 | /** |
| 4239 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4240 | * @param subId The subscription to use to check the configuration. |
| 4241 | * @param c The callback that will be used to send the result. |
| 4242 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4243 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4244 | public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4245 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4246 | mApp, subId, "unregisterImsRegistrationCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4247 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4248 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4249 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4250 | final long token = Binder.clearCallingIdentity(); |
joonhunshin | 49f0aed | 2022-08-05 08:33:05 +0000 | [diff] [blame] | 4251 | |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4252 | try { |
joonhunshin | 49f0aed | 2022-08-05 08:33:05 +0000 | [diff] [blame] | 4253 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4254 | if (controller != null) { |
| 4255 | ImsManager imsManager = controller.getImsManager(subId); |
| 4256 | if (imsManager != null) { |
| 4257 | imsManager.removeRegistrationCallbackForSubscription(c, subId); |
| 4258 | } else { |
| 4259 | Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId |
| 4260 | + "is inactive, ignoring unregister."); |
| 4261 | // If the ImsManager is not valid, just return, since the callback |
| 4262 | // will already have been removed internally. |
| 4263 | } |
| 4264 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4265 | } finally { |
| 4266 | Binder.restoreCallingIdentity(token); |
| 4267 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4268 | } |
| 4269 | |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 4270 | /** |
| 4271 | * Get the IMS service registration state for the MmTelFeature associated with this sub id. |
| 4272 | */ |
| 4273 | @Override |
| 4274 | public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) { |
| 4275 | enforceReadPrivilegedPermission("getImsMmTelRegistrationState"); |
| 4276 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4277 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4278 | "IMS not available on device."); |
| 4279 | } |
| 4280 | final long token = Binder.clearCallingIdentity(); |
| 4281 | try { |
| 4282 | Phone phone = getPhone(subId); |
| 4283 | if (phone == null) { |
| 4284 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 4285 | + subId + "'"); |
| 4286 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 4287 | } |
| 4288 | phone.getImsRegistrationState(regState -> { |
| 4289 | try { |
| 4290 | consumer.accept((regState == null) |
| 4291 | ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState); |
| 4292 | } catch (RemoteException e) { |
| 4293 | // Ignore if the remote process is no longer available to call back. |
| 4294 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 4295 | } |
| 4296 | }); |
| 4297 | } finally { |
| 4298 | Binder.restoreCallingIdentity(token); |
| 4299 | } |
| 4300 | } |
| 4301 | |
| 4302 | /** |
| 4303 | * Get the transport type for the IMS service registration state. |
| 4304 | */ |
| 4305 | @Override |
| 4306 | public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4307 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4308 | mApp, subId, "getImsMmTelRegistrationTransportType"); |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 4309 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4310 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4311 | "IMS not available on device."); |
| 4312 | } |
| 4313 | final long token = Binder.clearCallingIdentity(); |
| 4314 | try { |
| 4315 | Phone phone = getPhone(subId); |
| 4316 | if (phone == null) { |
| 4317 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 4318 | + subId + "'"); |
| 4319 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 4320 | } |
| 4321 | phone.getImsRegistrationTech(regTech -> { |
| 4322 | // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager |
| 4323 | int regTechConverted = (regTech == null) |
| 4324 | ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech; |
| 4325 | regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get( |
| 4326 | regTechConverted); |
| 4327 | try { |
| 4328 | consumer.accept(regTechConverted); |
| 4329 | } catch (RemoteException e) { |
| 4330 | // Ignore if the remote process is no longer available to call back. |
| 4331 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 4332 | } |
| 4333 | }); |
| 4334 | } finally { |
| 4335 | Binder.restoreCallingIdentity(token); |
| 4336 | } |
| 4337 | } |
| 4338 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4339 | /** |
| 4340 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4341 | * @param subId The subscription to use to check the configuration. |
| 4342 | * @param c The callback that will be used to send the result. |
| 4343 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4344 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4345 | public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) |
| 4346 | throws RemoteException { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4347 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4348 | mApp, subId, "registerMmTelCapabilityCallback"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4349 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4350 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4351 | "IMS not available on device."); |
| 4352 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4353 | final long token = Binder.clearCallingIdentity(); |
| 4354 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4355 | int slotId = getSlotIndexOrException(subId); |
| 4356 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 4357 | ImsManager.getInstance(mApp, slotId).addCapabilitiesCallbackForSubscription(c, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4358 | } catch (ImsException e) { |
| 4359 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4360 | } finally { |
| 4361 | Binder.restoreCallingIdentity(token); |
| 4362 | } |
| 4363 | } |
| 4364 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4365 | /** |
| 4366 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4367 | * @param subId The subscription to use to check the configuration. |
| 4368 | * @param c The callback that will be used to send the result. |
| 4369 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4370 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4371 | public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4372 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4373 | mApp, subId, "unregisterMmTelCapabilityCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4374 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4375 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4376 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4377 | |
| 4378 | final long token = Binder.clearCallingIdentity(); |
| 4379 | try { |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4380 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4381 | .removeCapabilitiesCallbackForSubscription(c, subId); |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4382 | } catch (ImsException e) { |
| 4383 | Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId |
| 4384 | + "is inactive, ignoring unregister."); |
| 4385 | // If the subscription is no longer active, just return, since the callback |
| 4386 | // will already have been removed internally. |
| 4387 | } finally { |
| 4388 | Binder.restoreCallingIdentity(token); |
| 4389 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4390 | } |
| 4391 | |
| 4392 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4393 | public boolean isCapable(int subId, int capability, int regTech) { |
| 4394 | enforceReadPrivilegedPermission("isCapable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4395 | final long token = Binder.clearCallingIdentity(); |
| 4396 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4397 | int slotId = getSlotIndexOrException(subId); |
| 4398 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 4399 | return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech); |
| 4400 | } catch (com.android.ims.ImsException e) { |
| 4401 | Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage()); |
| 4402 | return false; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4403 | } catch (ImsException e) { |
Brad Ebinger | 6b5ac22 | 2019-02-04 14:36:52 -0800 | [diff] [blame] | 4404 | Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false."); |
| 4405 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4406 | } finally { |
| 4407 | Binder.restoreCallingIdentity(token); |
| 4408 | } |
| 4409 | } |
| 4410 | |
| 4411 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4412 | public boolean isAvailable(int subId, int capability, int regTech) { |
| 4413 | enforceReadPrivilegedPermission("isAvailable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4414 | final long token = Binder.clearCallingIdentity(); |
| 4415 | try { |
| 4416 | Phone phone = getPhone(subId); |
| 4417 | if (phone == null) return false; |
| 4418 | return phone.isImsCapabilityAvailable(capability, regTech); |
Daniel Bright | 5e40e4e | 2020-03-11 16:35:39 -0700 | [diff] [blame] | 4419 | } catch (com.android.ims.ImsException e) { |
| 4420 | Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage()); |
| 4421 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4422 | } finally { |
| 4423 | Binder.restoreCallingIdentity(token); |
| 4424 | } |
| 4425 | } |
| 4426 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4427 | /** |
| 4428 | * Determines if the MmTel feature capability is supported by the carrier configuration for this |
| 4429 | * subscription. |
| 4430 | * @param subId The subscription to use to check the configuration. |
| 4431 | * @param callback The callback that will be used to send the result. |
| 4432 | * @param capability The MmTelFeature capability that will be used to send the result. |
| 4433 | * @param transportType The transport type of the MmTelFeature capability. |
| 4434 | */ |
| 4435 | @Override |
| 4436 | public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability, |
| 4437 | int transportType) { |
| 4438 | enforceReadPrivilegedPermission("isMmTelCapabilitySupported"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4439 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4440 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4441 | "IMS not available on device."); |
| 4442 | } |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4443 | final long token = Binder.clearCallingIdentity(); |
| 4444 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4445 | int slotId = getSlotIndex(subId); |
| 4446 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4447 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '" |
| 4448 | + subId + "'"); |
| 4449 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 4450 | } |
| 4451 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 4452 | ImsManager.getInstance(mApp, slotId).isSupported(capability, |
| 4453 | transportType, aBoolean -> { |
| 4454 | try { |
| 4455 | callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0)); |
| 4456 | } catch (RemoteException e) { |
| 4457 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not " |
| 4458 | + "running. Ignore"); |
| 4459 | } |
| 4460 | }); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4461 | } catch (ImsException e) { |
| 4462 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4463 | } finally { |
| 4464 | Binder.restoreCallingIdentity(token); |
| 4465 | } |
| 4466 | } |
| 4467 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4468 | /** |
| 4469 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4470 | * @param subId The subscription to use to check the configuration. |
| 4471 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4472 | @Override |
| 4473 | public boolean isAdvancedCallingSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4474 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4475 | mApp, subId, "isAdvancedCallingSettingEnabled"); |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4476 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4477 | final long token = Binder.clearCallingIdentity(); |
| 4478 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4479 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4480 | // 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] | 4481 | return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4482 | } catch (ImsException e) { |
| 4483 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4484 | } finally { |
| 4485 | Binder.restoreCallingIdentity(token); |
| 4486 | } |
| 4487 | } |
| 4488 | |
| 4489 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4490 | public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4491 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4492 | "setAdvancedCallingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4493 | final long identity = Binder.clearCallingIdentity(); |
| 4494 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4495 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4496 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4497 | // 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] | 4498 | ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4499 | } catch (ImsException e) { |
| 4500 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4501 | } finally { |
| 4502 | Binder.restoreCallingIdentity(identity); |
| 4503 | } |
| 4504 | } |
| 4505 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4506 | /** |
| 4507 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4508 | * @param subId The subscription to use to check the configuration. |
| 4509 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4510 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4511 | public boolean isVtSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4512 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4513 | mApp, subId, "isVtSettingEnabled"); |
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. |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4518 | return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4519 | } catch (ImsException e) { |
| 4520 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4521 | } finally { |
| 4522 | Binder.restoreCallingIdentity(identity); |
| 4523 | } |
| 4524 | } |
| 4525 | |
| 4526 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4527 | public void setVtSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4528 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4529 | "setVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4530 | final long identity = Binder.clearCallingIdentity(); |
| 4531 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4532 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4533 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4534 | // 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] | 4535 | ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4536 | } catch (ImsException e) { |
| 4537 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4538 | } finally { |
| 4539 | Binder.restoreCallingIdentity(identity); |
| 4540 | } |
| 4541 | } |
| 4542 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4543 | /** |
| 4544 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4545 | * @param subId The subscription to use to check the configuration. |
| 4546 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4547 | @Override |
| 4548 | public boolean isVoWiFiSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4549 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4550 | mApp, subId, "isVoWiFiSettingEnabled"); |
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. |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4555 | return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4556 | } catch (ImsException e) { |
| 4557 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4558 | } finally { |
| 4559 | Binder.restoreCallingIdentity(identity); |
| 4560 | } |
| 4561 | } |
| 4562 | |
| 4563 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4564 | public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4565 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4566 | "setVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4567 | final long identity = Binder.clearCallingIdentity(); |
| 4568 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4569 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4570 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4571 | // 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] | 4572 | ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4573 | } catch (ImsException e) { |
| 4574 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4575 | } finally { |
| 4576 | Binder.restoreCallingIdentity(identity); |
| 4577 | } |
| 4578 | } |
| 4579 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4580 | /** |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 4581 | * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not |
| 4582 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4583 | * @param subId The subscription to use to check the configuration. |
| 4584 | */ |
| 4585 | @Override |
| 4586 | public boolean isCrossSimCallingEnabledByUser(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4587 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 4588 | mApp, subId, "isCrossSimCallingEnabledByUser"); |
| 4589 | final long identity = Binder.clearCallingIdentity(); |
| 4590 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4591 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4592 | // 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] | 4593 | return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser(); |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 4594 | } catch (ImsException e) { |
| 4595 | throw new ServiceSpecificException(e.getCode()); |
| 4596 | } finally { |
| 4597 | Binder.restoreCallingIdentity(identity); |
| 4598 | } |
| 4599 | } |
| 4600 | |
| 4601 | /** |
| 4602 | * Sets the user's setting for whether or not Voice over Cross SIM is enabled. |
| 4603 | * Requires MODIFY_PHONE_STATE permission. |
| 4604 | * @param subId The subscription to use to check the configuration. |
| 4605 | * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled, |
| 4606 | * false otherwise |
| 4607 | */ |
| 4608 | @Override |
| 4609 | public void setCrossSimCallingEnabled(int subId, boolean isEnabled) { |
| 4610 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4611 | "setCrossSimCallingEnabled"); |
| 4612 | final long identity = Binder.clearCallingIdentity(); |
| 4613 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4614 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4615 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4616 | // 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] | 4617 | ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled); |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 4618 | } catch (ImsException e) { |
| 4619 | throw new ServiceSpecificException(e.getCode()); |
| 4620 | } finally { |
| 4621 | Binder.restoreCallingIdentity(identity); |
| 4622 | } |
| 4623 | } |
| 4624 | |
| 4625 | /** |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4626 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4627 | * @param subId The subscription to use to check the configuration. |
| 4628 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4629 | @Override |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4630 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4631 | public boolean isVoWiFiRoamingSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4632 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4633 | mApp, subId, "isVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4634 | final long identity = Binder.clearCallingIdentity(); |
| 4635 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4636 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4637 | // 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] | 4638 | return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4639 | } catch (ImsException e) { |
| 4640 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4641 | } finally { |
| 4642 | Binder.restoreCallingIdentity(identity); |
| 4643 | } |
| 4644 | } |
| 4645 | |
| 4646 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4647 | public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4648 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4649 | "setVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4650 | final long identity = Binder.clearCallingIdentity(); |
| 4651 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4652 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4653 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4654 | // 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] | 4655 | ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4656 | } catch (ImsException e) { |
| 4657 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4658 | } finally { |
| 4659 | Binder.restoreCallingIdentity(identity); |
| 4660 | } |
| 4661 | } |
| 4662 | |
| 4663 | @Override |
| 4664 | public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) { |
| 4665 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4666 | "setVoWiFiNonPersistent"); |
| 4667 | final long identity = Binder.clearCallingIdentity(); |
| 4668 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4669 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4670 | // This setting will be ignored if the ImsService isn't up. |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4671 | ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4672 | } catch (ImsException e) { |
| 4673 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4674 | } finally { |
| 4675 | Binder.restoreCallingIdentity(identity); |
| 4676 | } |
| 4677 | } |
| 4678 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4679 | /** |
| 4680 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4681 | * @param subId The subscription to use to check the configuration. |
| 4682 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4683 | @Override |
| 4684 | public int getVoWiFiModeSetting(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4685 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4686 | mApp, subId, "getVoWiFiModeSetting"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4687 | final long identity = Binder.clearCallingIdentity(); |
| 4688 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4689 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4690 | // 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] | 4691 | return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4692 | } catch (ImsException e) { |
| 4693 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4694 | } finally { |
| 4695 | Binder.restoreCallingIdentity(identity); |
| 4696 | } |
| 4697 | } |
| 4698 | |
| 4699 | @Override |
| 4700 | public void setVoWiFiModeSetting(int subId, int mode) { |
| 4701 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4702 | "setVoWiFiModeSetting"); |
| 4703 | final long identity = Binder.clearCallingIdentity(); |
| 4704 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4705 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4706 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4707 | // 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] | 4708 | ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4709 | } catch (ImsException e) { |
| 4710 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4711 | } finally { |
| 4712 | Binder.restoreCallingIdentity(identity); |
| 4713 | } |
| 4714 | } |
| 4715 | |
| 4716 | @Override |
| 4717 | public int getVoWiFiRoamingModeSetting(int subId) { |
| 4718 | enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting"); |
| 4719 | final long identity = Binder.clearCallingIdentity(); |
| 4720 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4721 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4722 | // This setting doesn't require an active ImsService connection, so do not verify. |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4723 | return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4724 | } catch (ImsException e) { |
| 4725 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4726 | } finally { |
| 4727 | Binder.restoreCallingIdentity(identity); |
| 4728 | } |
| 4729 | } |
| 4730 | |
| 4731 | @Override |
| 4732 | public void setVoWiFiRoamingModeSetting(int subId, int mode) { |
| 4733 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4734 | "setVoWiFiRoamingModeSetting"); |
| 4735 | final long identity = Binder.clearCallingIdentity(); |
| 4736 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4737 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4738 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4739 | // new setting will be picked up when the ImsService comes up next if it isn't up. |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4740 | ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4741 | } catch (ImsException e) { |
| 4742 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4743 | } finally { |
| 4744 | Binder.restoreCallingIdentity(identity); |
| 4745 | } |
| 4746 | } |
| 4747 | |
| 4748 | @Override |
| 4749 | public void setRttCapabilitySetting(int subId, boolean isEnabled) { |
| 4750 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4751 | "setRttCapabilityEnabled"); |
| 4752 | final long identity = Binder.clearCallingIdentity(); |
| 4753 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4754 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4755 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4756 | // 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] | 4757 | ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4758 | } catch (ImsException e) { |
| 4759 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4760 | } finally { |
| 4761 | Binder.restoreCallingIdentity(identity); |
| 4762 | } |
| 4763 | } |
| 4764 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4765 | /** |
| 4766 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4767 | * @param subId The subscription to use to check the configuration. |
| 4768 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4769 | @Override |
| 4770 | public boolean isTtyOverVolteEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4771 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4772 | mApp, subId, "isTtyOverVolteEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 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. |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4777 | return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4778 | } catch (ImsException e) { |
| 4779 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4780 | } finally { |
| 4781 | Binder.restoreCallingIdentity(identity); |
| 4782 | } |
| 4783 | } |
| 4784 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4785 | @Override |
| 4786 | public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 4787 | enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4788 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4789 | final long identity = Binder.clearCallingIdentity(); |
| 4790 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4791 | if (!isImsAvailableOnDevice()) { |
| 4792 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4793 | "IMS not available on device."); |
| 4794 | } |
| 4795 | int slotId = getSlotIndexOrException(subId); |
| 4796 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 4797 | ImsManager.getInstance(mApp, slotId) |
| 4798 | .addProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4799 | } catch (ImsException e) { |
| 4800 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4801 | } finally { |
| 4802 | Binder.restoreCallingIdentity(identity); |
| 4803 | } |
| 4804 | } |
| 4805 | |
| 4806 | @Override |
| 4807 | public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 4808 | enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback"); |
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(); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4811 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4812 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4813 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4814 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4815 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4816 | .removeProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4817 | } catch (ImsException e) { |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4818 | Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId |
| 4819 | + "is inactive, ignoring unregister."); |
| 4820 | // If the subscription is no longer active, just return, since the callback will already |
| 4821 | // have been removed internally. |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4822 | } finally { |
| 4823 | Binder.restoreCallingIdentity(identity); |
| 4824 | } |
| 4825 | } |
| 4826 | |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4827 | @Override |
| 4828 | public void registerFeatureProvisioningChangedCallback(int subId, |
| 4829 | IFeatureProvisioningCallback callback) { |
| 4830 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4831 | mApp, subId, "registerFeatureProvisioningChangedCallback"); |
| 4832 | |
| 4833 | final long identity = Binder.clearCallingIdentity(); |
| 4834 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4835 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4836 | } |
| 4837 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 4838 | try { |
| 4839 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 4840 | if (controller == null) { |
| 4841 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4842 | "Device does not support IMS"); |
| 4843 | } |
| 4844 | controller.addFeatureProvisioningChangedCallback(subId, callback); |
| 4845 | } finally { |
| 4846 | Binder.restoreCallingIdentity(identity); |
| 4847 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4848 | } |
| 4849 | |
| 4850 | @Override |
| 4851 | public void unregisterFeatureProvisioningChangedCallback(int subId, |
| 4852 | IFeatureProvisioningCallback callback) { |
| 4853 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4854 | mApp, subId, "unregisterFeatureProvisioningChangedCallback"); |
| 4855 | |
| 4856 | final long identity = Binder.clearCallingIdentity(); |
| 4857 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4858 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4859 | } |
| 4860 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 4861 | try { |
| 4862 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 4863 | if (controller == null) { |
| 4864 | loge("unregisterFeatureProvisioningChangedCallback: Device does not support IMS"); |
| 4865 | return; |
| 4866 | } |
| 4867 | controller.removeFeatureProvisioningChangedCallback(subId, callback); |
| 4868 | } finally { |
| 4869 | Binder.restoreCallingIdentity(identity); |
| 4870 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4871 | } |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4872 | |
| 4873 | private void checkModifyPhoneStatePermission(int subId, String message) { |
| 4874 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4875 | message); |
| 4876 | } |
| 4877 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4878 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4879 | public void setRcsProvisioningStatusForCapability(int subId, int capability, int tech, |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4880 | boolean isProvisioned) { |
| 4881 | checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability"); |
| 4882 | |
| 4883 | final long identity = Binder.clearCallingIdentity(); |
| 4884 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 4885 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 4886 | if (controller == null) { |
| 4887 | loge("setRcsProvisioningStatusForCapability: Device does not support IMS"); |
| 4888 | return; |
| 4889 | } |
| 4890 | controller.setRcsProvisioningStatusForCapability( |
| 4891 | subId, capability, tech, isProvisioned); |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4892 | } finally { |
| 4893 | Binder.restoreCallingIdentity(identity); |
| 4894 | } |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4895 | } |
| 4896 | |
| 4897 | |
| 4898 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4899 | public boolean getRcsProvisioningStatusForCapability(int subId, int capability, int tech) { |
| 4900 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4901 | mApp, subId, "getRcsProvisioningStatusForCapability"); |
| 4902 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4903 | final long identity = Binder.clearCallingIdentity(); |
| 4904 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 4905 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 4906 | if (controller == null) { |
| 4907 | loge("getRcsProvisioningStatusForCapability: Device does not support IMS"); |
| 4908 | |
| 4909 | // device does not support IMS, this method will return true always. |
| 4910 | return true; |
| 4911 | } |
| 4912 | return controller.getRcsProvisioningStatusForCapability(subId, capability, tech); |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4913 | } finally { |
| 4914 | Binder.restoreCallingIdentity(identity); |
| 4915 | } |
| 4916 | } |
| 4917 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4918 | @Override |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4919 | public void setImsProvisioningStatusForCapability(int subId, int capability, int tech, |
| 4920 | boolean isProvisioned) { |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4921 | checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4922 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4923 | final long identity = Binder.clearCallingIdentity(); |
| 4924 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 4925 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 4926 | if (controller == null) { |
| 4927 | loge("setImsProvisioningStatusForCapability: Device does not support IMS"); |
| 4928 | return; |
| 4929 | } |
| 4930 | controller.setImsProvisioningStatusForCapability( |
| 4931 | subId, capability, tech, isProvisioned); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4932 | } finally { |
| 4933 | Binder.restoreCallingIdentity(identity); |
| 4934 | } |
| 4935 | } |
| 4936 | |
| 4937 | @Override |
| 4938 | public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) { |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4939 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4940 | mApp, subId, "getProvisioningStatusForCapability"); |
| 4941 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4942 | final long identity = Binder.clearCallingIdentity(); |
| 4943 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 4944 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 4945 | if (controller == null) { |
| 4946 | loge("getImsProvisioningStatusForCapability: Device does not support IMS"); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4947 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 4948 | // device does not support IMS, this method will return true always. |
| 4949 | return true; |
| 4950 | } |
| 4951 | return controller.getImsProvisioningStatusForCapability(subId, capability, tech); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4952 | } finally { |
| 4953 | Binder.restoreCallingIdentity(identity); |
| 4954 | } |
| 4955 | } |
| 4956 | |
| 4957 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4958 | public boolean isProvisioningRequiredForCapability(int subId, int capability, int tech) { |
| 4959 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4960 | mApp, subId, "isProvisioningRequiredForCapability"); |
| 4961 | |
| 4962 | final long identity = Binder.clearCallingIdentity(); |
| 4963 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 4964 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 4965 | if (controller == null) { |
| 4966 | loge("isProvisioningRequiredForCapability: Device does not support IMS"); |
| 4967 | |
| 4968 | // device does not support IMS, this method will return false |
| 4969 | return false; |
| 4970 | } |
| 4971 | return controller.isImsProvisioningRequiredForCapability(subId, capability, tech); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4972 | } finally { |
| 4973 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4974 | } |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4975 | } |
| 4976 | |
| 4977 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4978 | public boolean isRcsProvisioningRequiredForCapability(int subId, int capability, int tech) { |
| 4979 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4980 | mApp, subId, "isProvisioningRequiredForCapability"); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4981 | |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4982 | final long identity = Binder.clearCallingIdentity(); |
| 4983 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 4984 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 4985 | if (controller == null) { |
| 4986 | loge("isRcsProvisioningRequiredForCapability: Device does not support IMS"); |
| 4987 | |
| 4988 | // device does not support IMS, this method will return false |
| 4989 | return false; |
| 4990 | } |
| 4991 | return controller.isRcsProvisioningRequiredForCapability(subId, capability, tech); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4992 | } finally { |
| 4993 | Binder.restoreCallingIdentity(identity); |
| 4994 | } |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4995 | } |
| 4996 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4997 | @Override |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4998 | public int getImsProvisioningInt(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4999 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5000 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 5001 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5002 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5003 | mApp, subId, "getImsProvisioningInt"); |
| 5004 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5005 | final long identity = Binder.clearCallingIdentity(); |
| 5006 | try { |
| 5007 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5008 | int slotId = getSlotIndex(subId); |
| 5009 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5010 | Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '" |
| 5011 | + subId + "' for key:" + key); |
| 5012 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
| 5013 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5014 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5015 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5016 | if (controller == null) { |
| 5017 | loge("getImsProvisioningInt: Device does not support IMS"); |
| 5018 | |
| 5019 | // device does not support IMS, this method will return CONFIG_RESULT_UNKNOWN. |
| 5020 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
| 5021 | } |
| 5022 | int retVal = controller.getProvisioningValue(subId, key); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5023 | if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) { |
| 5024 | return retVal; |
| 5025 | } |
| 5026 | |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5027 | return ImsManager.getInstance(mApp, slotId).getConfigInt(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5028 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5029 | Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '" |
| 5030 | + subId + "' for key:" + key); |
| 5031 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5032 | } finally { |
| 5033 | Binder.restoreCallingIdentity(identity); |
| 5034 | } |
| 5035 | } |
| 5036 | |
| 5037 | @Override |
| 5038 | public String getImsProvisioningString(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5039 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5040 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 5041 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5042 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5043 | mApp, subId, "getImsProvisioningString"); |
| 5044 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5045 | final long identity = Binder.clearCallingIdentity(); |
| 5046 | try { |
| 5047 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5048 | int slotId = getSlotIndex(subId); |
| 5049 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5050 | Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '" |
| 5051 | + subId + "' for key:" + key); |
| 5052 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC; |
| 5053 | } |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5054 | return ImsManager.getInstance(mApp, slotId).getConfigString(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5055 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5056 | Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '" |
| 5057 | + subId + "' for key:" + key); |
| 5058 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5059 | } finally { |
| 5060 | Binder.restoreCallingIdentity(identity); |
| 5061 | } |
| 5062 | } |
| 5063 | |
| 5064 | @Override |
| 5065 | public int setImsProvisioningInt(int subId, int key, int value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5066 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5067 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 5068 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 5069 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5070 | "setImsProvisioningInt"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5071 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5072 | final long identity = Binder.clearCallingIdentity(); |
| 5073 | try { |
| 5074 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5075 | int slotId = getSlotIndex(subId); |
| 5076 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5077 | Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '" |
| 5078 | + subId + "' for key:" + key); |
| 5079 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 5080 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5081 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5082 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5083 | if (controller == null) { |
| 5084 | loge("setImsProvisioningInt: Device does not support IMS"); |
| 5085 | |
| 5086 | // device does not support IMS, this method will return CONFIG_RESULT_FAILED. |
| 5087 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 5088 | } |
| 5089 | int retVal = controller.setProvisioningValue(subId, key, value); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5090 | if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) { |
| 5091 | return retVal; |
| 5092 | } |
| 5093 | |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5094 | return ImsManager.getInstance(mApp, slotId).setConfig(key, value); |
| 5095 | } catch (com.android.ims.ImsException | RemoteException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5096 | Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5097 | + "' for key:" + key, e); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5098 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5099 | } finally { |
| 5100 | Binder.restoreCallingIdentity(identity); |
| 5101 | } |
| 5102 | } |
| 5103 | |
| 5104 | @Override |
| 5105 | public int setImsProvisioningString(int subId, int key, String value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5106 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5107 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 5108 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 5109 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5110 | "setImsProvisioningString"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5111 | final long identity = Binder.clearCallingIdentity(); |
| 5112 | try { |
| 5113 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5114 | int slotId = getSlotIndex(subId); |
| 5115 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5116 | Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '" |
| 5117 | + subId + "' for key:" + key); |
| 5118 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 5119 | } |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5120 | return ImsManager.getInstance(mApp, slotId).setConfig(key, value); |
| 5121 | } catch (com.android.ims.ImsException | RemoteException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5122 | Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5123 | + "' for key:" + key, e); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5124 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5125 | } finally { |
| 5126 | Binder.restoreCallingIdentity(identity); |
| 5127 | } |
| 5128 | } |
| 5129 | |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5130 | /** |
| 5131 | * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL |
| 5132 | * for the given slot ID or no ImsResolver instance has been created. |
| 5133 | * @param slotId The slot ID that the IMS service is created for. |
| 5134 | * @throws ImsException If there is no ImsService configured for this slot. |
| 5135 | */ |
| 5136 | private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException { |
| 5137 | if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId, |
| 5138 | ImsFeature.FEATURE_MMTEL)) { |
| 5139 | throw new ImsException("This subscription does not support MMTEL over IMS", |
| 5140 | ImsException.CODE_ERROR_UNSUPPORTED_OPERATION); |
| 5141 | } |
| 5142 | } |
| 5143 | |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5144 | private int getSlotIndexOrException(int subId) throws ImsException { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5145 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 5146 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5147 | throw new ImsException("Invalid Subscription Id, subId=" + subId, |
| 5148 | ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5149 | } |
| 5150 | return slotId; |
| 5151 | } |
| 5152 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5153 | private int getSlotIndex(int subId) { |
| 5154 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 5155 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
| 5156 | return SubscriptionManager.INVALID_SIM_SLOT_INDEX; |
| 5157 | } |
| 5158 | return slotId; |
| 5159 | } |
| 5160 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5161 | /** |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 5162 | * Returns the data network type for a subId; does not throw SecurityException. |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5163 | */ |
| 5164 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5165 | public int getNetworkTypeForSubscriber(int subId, String callingPackage, |
| 5166 | String callingFeatureId) { |
Shuo Qian | 13d8915 | 2021-05-10 23:58:11 -0700 | [diff] [blame] | 5167 | try { |
| 5168 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 5169 | } catch (SecurityException se) { |
| 5170 | EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid()); |
| 5171 | throw new SecurityException("Package " + callingPackage + " does not belong to " |
| 5172 | + Binder.getCallingUid()); |
| 5173 | } |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 5174 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 5175 | if (targetSdk > android.os.Build.VERSION_CODES.Q) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5176 | return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 5177 | } else if (targetSdk == android.os.Build.VERSION_CODES.Q |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 5178 | && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5179 | mApp, subId, callingPackage, callingFeatureId, |
| 5180 | "getNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5181 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5182 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 5183 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5184 | final long identity = Binder.clearCallingIdentity(); |
| 5185 | try { |
| 5186 | final Phone phone = getPhone(subId); |
| 5187 | if (phone != null) { |
| 5188 | return phone.getServiceState().getDataNetworkType(); |
| 5189 | } else { |
| 5190 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5191 | } |
| 5192 | } finally { |
| 5193 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5194 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5195 | } |
| 5196 | |
| 5197 | /** |
| 5198 | * Returns the data network type |
| 5199 | */ |
| 5200 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5201 | public int getDataNetworkType(String callingPackage, String callingFeatureId) { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5202 | return getDataNetworkTypeForSubscriber(SubscriptionManager.getDefaultDataSubscriptionId(), |
Zoey Chen | fd61f7f | 2021-04-21 13:42:10 +0800 | [diff] [blame] | 5203 | callingPackage, callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5204 | } |
| 5205 | |
| 5206 | /** |
| 5207 | * Returns the data network type for a subId |
| 5208 | */ |
| 5209 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5210 | public int getDataNetworkTypeForSubscriber(int subId, String callingPackage, |
| 5211 | String callingFeatureId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 5212 | String functionName = "getDataNetworkTypeForSubscriber"; |
| 5213 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 5214 | mApp, functionName)) { |
| 5215 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 5216 | mApp, subId, callingPackage, callingFeatureId, functionName)) { |
| 5217 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5218 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5219 | } |
| 5220 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5221 | final long identity = Binder.clearCallingIdentity(); |
| 5222 | try { |
| 5223 | final Phone phone = getPhone(subId); |
| 5224 | if (phone != null) { |
| 5225 | return phone.getServiceState().getDataNetworkType(); |
| 5226 | } else { |
| 5227 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5228 | } |
| 5229 | } finally { |
| 5230 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5231 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5232 | } |
| 5233 | |
| 5234 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5235 | * Returns the Voice network type for a subId |
| 5236 | */ |
| 5237 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5238 | public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage, |
| 5239 | String callingFeatureId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 5240 | String functionName = "getVoiceNetworkTypeForSubscriber"; |
| 5241 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 5242 | mApp, functionName)) { |
| 5243 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 5244 | mApp, subId, callingPackage, callingFeatureId, functionName)) { |
| 5245 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5246 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 5247 | } |
| 5248 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5249 | final long identity = Binder.clearCallingIdentity(); |
| 5250 | try { |
| 5251 | final Phone phone = getPhone(subId); |
| 5252 | if (phone != null) { |
| 5253 | return phone.getServiceState().getVoiceNetworkType(); |
| 5254 | } else { |
| 5255 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5256 | } |
| 5257 | } finally { |
| 5258 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5259 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5260 | } |
| 5261 | |
| 5262 | /** |
| 5263 | * @return true if a ICC card is present |
| 5264 | */ |
| 5265 | public boolean hasIccCard() { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5266 | // FIXME Make changes to pass defaultSimId of type int |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5267 | return hasIccCardUsingSlotIndex(SubscriptionManager.getSlotIndex( |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5268 | getDefaultSubscription())); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5269 | } |
| 5270 | |
| 5271 | /** |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5272 | * @return true if a ICC card is present for a slotIndex |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5273 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5274 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5275 | public boolean hasIccCardUsingSlotIndex(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5276 | final long identity = Binder.clearCallingIdentity(); |
| 5277 | try { |
| 5278 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5279 | if (phone != null) { |
| 5280 | return phone.getIccCard().hasIccCard(); |
| 5281 | } else { |
| 5282 | return false; |
| 5283 | } |
| 5284 | } finally { |
| 5285 | Binder.restoreCallingIdentity(identity); |
Amit Mahajan | a6fc2a8 | 2015-01-06 11:53:51 -0800 | [diff] [blame] | 5286 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5287 | } |
| 5288 | |
| 5289 | /** |
| 5290 | * Return if the current radio is LTE on CDMA. This |
| 5291 | * is a tri-state return value as for a period of time |
| 5292 | * the mode may be unknown. |
| 5293 | * |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5294 | * @param callingPackage the name of the package making the call. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5295 | * @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] | 5296 | * or {@link Phone#LTE_ON_CDMA_TRUE} |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5297 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5298 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5299 | public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) { |
| 5300 | return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 5301 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5302 | } |
| 5303 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5304 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5305 | public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage, |
| 5306 | String callingFeatureId) { |
Sarah Chin | 790d292 | 2020-01-16 12:17:23 -0800 | [diff] [blame] | 5307 | try { |
| 5308 | enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber"); |
| 5309 | } catch (SecurityException e) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5310 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 5311 | } |
| 5312 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5313 | final long identity = Binder.clearCallingIdentity(); |
| 5314 | try { |
| 5315 | final Phone phone = getPhone(subId); |
| 5316 | if (phone == null) { |
| 5317 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 5318 | } else { |
Nathan Harold | 05ad633 | 2020-07-10 11:54:36 -0700 | [diff] [blame] | 5319 | return TelephonyProperties.lte_on_cdma_device() |
| 5320 | .orElse(PhoneConstants.LTE_ON_CDMA_FALSE); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5321 | } |
| 5322 | } finally { |
| 5323 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5324 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5325 | } |
| 5326 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5327 | /** |
| 5328 | * {@hide} |
| 5329 | * Returns Default subId, 0 in the case of single standby. |
| 5330 | */ |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 5331 | private int getDefaultSubscription() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5332 | return SubscriptionManager.getDefaultSubscriptionId(); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5333 | } |
| 5334 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 5335 | private int getSlotForDefaultSubscription() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5336 | return SubscriptionManager.getPhoneId(getDefaultSubscription()); |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 5337 | } |
| 5338 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 5339 | private int getPreferredVoiceSubscription() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5340 | return SubscriptionManager.getDefaultVoiceSubscriptionId(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5341 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5342 | |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 5343 | private boolean isActiveSubscription(int subId) { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5344 | if (PhoneFactory.isSubscriptionManagerServiceEnabled()) { |
| 5345 | return SubscriptionManagerService.getInstance().isActiveSubId(subId, |
| 5346 | mApp.getOpPackageName(), mApp.getFeatureId()); |
| 5347 | } |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 5348 | return mSubscriptionController.isActiveSubId(subId); |
| 5349 | } |
| 5350 | |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5351 | /** |
| 5352 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 5353 | */ |
| 5354 | public int getWhenToMakeWifiCalls() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5355 | final long identity = Binder.clearCallingIdentity(); |
| 5356 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5357 | return Settings.System.getInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5358 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, |
| 5359 | getWhenToMakeWifiCallsDefaultPreference()); |
| 5360 | } finally { |
| 5361 | Binder.restoreCallingIdentity(identity); |
| 5362 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5363 | } |
| 5364 | |
| 5365 | /** |
| 5366 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 5367 | */ |
| 5368 | public void setWhenToMakeWifiCalls(int preference) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5369 | final long identity = Binder.clearCallingIdentity(); |
| 5370 | try { |
| 5371 | if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5372 | Settings.System.putInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5373 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference); |
| 5374 | } finally { |
| 5375 | Binder.restoreCallingIdentity(identity); |
| 5376 | } |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 5377 | } |
| 5378 | |
Sailesh Nepal | d1e6815 | 2013-12-12 19:08:02 -0800 | [diff] [blame] | 5379 | private static int getWhenToMakeWifiCallsDefaultPreference() { |
Santos Cordon | da120f4 | 2014-08-06 04:44:34 -0700 | [diff] [blame] | 5380 | // TODO: Use a build property to choose this value. |
Evan Charlton | 9829e88 | 2013-12-19 15:30:38 -0800 | [diff] [blame] | 5381 | return TelephonyManager.WifiCallingChoices.ALWAYS_USE; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5382 | } |
Shishir Agrawal | 69f6812 | 2013-12-16 17:25:49 -0800 | [diff] [blame] | 5383 | |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5384 | private Phone getPhoneFromSlotPortIndexOrThrowException(int slotIndex, int portIndex) { |
| 5385 | int phoneId = UiccController.getInstance().getPhoneIdFromSlotPortIndex(slotIndex, |
| 5386 | portIndex); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5387 | if (phoneId == -1) { |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5388 | throw new IllegalArgumentException("Given slot index: " + slotIndex + " port index: " |
| 5389 | + portIndex + " does not correspond to an active phone"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5390 | } |
| 5391 | return PhoneFactory.getPhone(phoneId); |
| 5392 | } |
| 5393 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5394 | @Override |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 5395 | public IccOpenLogicalChannelResponse iccOpenLogicalChannel( |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5396 | @NonNull IccLogicalChannelRequest request) { |
| 5397 | Phone phone = getPhoneFromValidIccLogicalChannelRequest(request, |
| 5398 | /*message=*/ "iccOpenLogicalChannel"); |
| 5399 | |
| 5400 | if (DBG) log("iccOpenLogicalChannel: request=" + request); |
| 5401 | // Verify that the callingPackage in the request belongs to the calling UID |
| 5402 | mAppOps.checkPackage(Binder.getCallingUid(), request.callingPackage); |
| 5403 | |
| 5404 | return iccOpenLogicalChannelWithPermission(phone, request); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5405 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5406 | |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5407 | private Phone getPhoneFromValidIccLogicalChannelRequest( |
| 5408 | @NonNull IccLogicalChannelRequest request, String message) { |
| 5409 | Phone phone; |
| 5410 | if (request.subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) { |
| 5411 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5412 | mApp, request.subId, message); |
| 5413 | phone = getPhoneFromSubId(request.subId); |
| 5414 | } else if (request.slotIndex != SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5415 | enforceModifyPermission(); |
| 5416 | phone = getPhoneFromSlotPortIndexOrThrowException(request.slotIndex, request.portIndex); |
| 5417 | } else { |
| 5418 | throw new IllegalArgumentException("Both subId and slotIndex in request are invalid."); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5419 | } |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5420 | return phone; |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5421 | } |
| 5422 | |
| 5423 | private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone, |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5424 | IccLogicalChannelRequest channelRequest) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5425 | final long identity = Binder.clearCallingIdentity(); |
| 5426 | try { |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5427 | if (TextUtils.equals(ISDR_AID, channelRequest.aid)) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5428 | // Only allows LPA to open logical channel to ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5429 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 5430 | .getContext().getPackageManager()); |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5431 | if (bestComponent == null || !TextUtils.equals(channelRequest.callingPackage, |
| 5432 | bestComponent.packageName)) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5433 | loge("The calling package is not allowed to access ISD-R."); |
| 5434 | throw new SecurityException( |
| 5435 | "The calling package is not allowed to access ISD-R."); |
| 5436 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 5437 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 5438 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5439 | IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest( |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5440 | CMD_OPEN_CHANNEL, channelRequest, phone, null /* workSource */); |
| 5441 | if (DBG) log("iccOpenLogicalChannelWithPermission: response=" + response); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5442 | return response; |
| 5443 | } finally { |
| 5444 | Binder.restoreCallingIdentity(identity); |
| 5445 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5446 | } |
| 5447 | |
| 5448 | @Override |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5449 | public boolean iccCloseLogicalChannel(@NonNull IccLogicalChannelRequest request) { |
| 5450 | Phone phone = getPhoneFromValidIccLogicalChannelRequest(request, |
| 5451 | /*message=*/"iccCloseLogicalChannel"); |
| 5452 | |
| 5453 | if (DBG) log("iccCloseLogicalChannel: request=" + request); |
| 5454 | |
| 5455 | return iccCloseLogicalChannelWithPermission(phone, request); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5456 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5457 | |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5458 | private boolean iccCloseLogicalChannelWithPermission(Phone phone, |
| 5459 | IccLogicalChannelRequest request) { |
Chen Xu | a8f0dff | 2022-02-12 00:34:15 -0800 | [diff] [blame] | 5460 | // before this feature is enabled, this API should only return false if |
| 5461 | // the operation fails instead of throwing runtime exception for |
| 5462 | // backward-compatibility. |
| 5463 | final boolean shouldThrowExceptionOnFailure = CompatChanges.isChangeEnabled( |
| 5464 | ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE, Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5465 | final long identity = Binder.clearCallingIdentity(); |
| 5466 | try { |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5467 | if (request.channel < 0) { |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 5468 | throw new IllegalArgumentException("request.channel is less than 0"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5469 | } |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 5470 | Object result = sendRequest(CMD_CLOSE_CHANNEL, request.channel, phone, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5471 | null /* workSource */); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 5472 | Boolean success = false; |
| 5473 | if (result instanceof RuntimeException) { |
| 5474 | // if there is an exception returned, throw from the binder thread here. |
Chen Xu | a8f0dff | 2022-02-12 00:34:15 -0800 | [diff] [blame] | 5475 | if (shouldThrowExceptionOnFailure) { |
| 5476 | throw (RuntimeException) result; |
| 5477 | } else { |
| 5478 | return false; |
| 5479 | } |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 5480 | } else if (result instanceof Boolean) { |
| 5481 | success = (Boolean) result; |
| 5482 | } else { |
| 5483 | loge("iccCloseLogicalChannelWithPermission: supported return type " + result); |
| 5484 | } |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5485 | if (DBG) log("iccCloseLogicalChannelWithPermission: success=" + success); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5486 | return success; |
| 5487 | } finally { |
| 5488 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5489 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5490 | } |
| 5491 | |
| 5492 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5493 | public String iccTransmitApduLogicalChannel(int subId, int channel, int cla, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5494 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5495 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5496 | mApp, subId, "iccTransmitApduLogicalChannel"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5497 | if (DBG) { |
| 5498 | log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel |
| 5499 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 5500 | + p3 + " data=" + data); |
| 5501 | } |
| 5502 | return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla, |
| 5503 | command, p1, p2, p3, data); |
| 5504 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5505 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5506 | @Override |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5507 | public String iccTransmitApduLogicalChannelByPort(int slotIndex, int portIndex, int channel, |
| 5508 | int cla, int command, int p1, int p2, int p3, String data) { |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5509 | enforceModifyPermission(); |
| 5510 | if (DBG) { |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5511 | log("iccTransmitApduLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex=" |
| 5512 | + portIndex + " chnl=" + channel + " cla=" + cla + " cmd=" + command + " p1=" |
| 5513 | + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5514 | } |
| 5515 | return iccTransmitApduLogicalChannelWithPermission( |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5516 | getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel, cla, |
| 5517 | command, p1, p2, p3, data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5518 | } |
| 5519 | |
| 5520 | private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla, |
| 5521 | int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5522 | final long identity = Binder.clearCallingIdentity(); |
| 5523 | try { |
Hall Liu | 4fd771b | 2019-05-02 09:16:29 -0700 | [diff] [blame] | 5524 | if (channel <= 0) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5525 | return ""; |
| 5526 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5527 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5528 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5529 | new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone, |
| 5530 | null /* workSource */); |
| 5531 | if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5532 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5533 | // Append the returned status code to the end of the response payload. |
| 5534 | String s = Integer.toHexString( |
| 5535 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 5536 | if (response.payload != null) { |
| 5537 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 5538 | } |
| 5539 | return s; |
| 5540 | } finally { |
| 5541 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 5542 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5543 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5544 | |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5545 | @Override |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 5546 | public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla, |
| 5547 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5548 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5549 | mApp, subId, "iccTransmitApduBasicChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5550 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5551 | if (DBG) { |
| 5552 | log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" |
| 5553 | + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
| 5554 | } |
| 5555 | return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage, |
| 5556 | cla, command, p1, p2, p3, data); |
| 5557 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5558 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5559 | @Override |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5560 | public String iccTransmitApduBasicChannelByPort(int slotIndex, int portIndex, |
| 5561 | 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] | 5562 | enforceModifyPermission(); |
| 5563 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 5564 | if (DBG) { |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5565 | log("iccTransmitApduBasicChannelByPort: slotIndex=" + slotIndex + " portIndex=" |
| 5566 | + portIndex + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" |
| 5567 | + p2 + " p3=" + p3 + " data=" + data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5568 | } |
| 5569 | |
| 5570 | return iccTransmitApduBasicChannelWithPermission( |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5571 | getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), callingPackage, |
| 5572 | cla, command, p1, p2, p3, data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5573 | } |
| 5574 | |
| 5575 | // open APDU basic channel assuming the caller has sufficient permissions |
| 5576 | private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage, |
| 5577 | int cla, int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5578 | final long identity = Binder.clearCallingIdentity(); |
| 5579 | try { |
| 5580 | if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3 |
| 5581 | && TextUtils.equals(ISDR_AID, data)) { |
| 5582 | // Only allows LPA to select ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5583 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 5584 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5585 | if (bestComponent == null |
| 5586 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 5587 | loge("The calling package is not allowed to select ISD-R."); |
| 5588 | throw new SecurityException( |
| 5589 | "The calling package is not allowed to select ISD-R."); |
| 5590 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 5591 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 5592 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5593 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5594 | new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone, |
| 5595 | null /* workSource */); |
| 5596 | if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5597 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5598 | // Append the returned status code to the end of the response payload. |
| 5599 | String s = Integer.toHexString( |
| 5600 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 5601 | if (response.payload != null) { |
| 5602 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 5603 | } |
| 5604 | return s; |
| 5605 | } finally { |
| 5606 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 5607 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5608 | } |
| 5609 | |
| 5610 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5611 | 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] | 5612 | String filePath) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5613 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5614 | mApp, subId, "iccExchangeSimIO"); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5615 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5616 | final long identity = Binder.clearCallingIdentity(); |
| 5617 | try { |
| 5618 | if (DBG) { |
| 5619 | log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " |
| 5620 | + p1 + " " + p2 + " " + p3 + ":" + filePath); |
| 5621 | } |
| 5622 | |
| 5623 | IccIoResult response = |
| 5624 | (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO, |
| 5625 | new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath), |
| 5626 | subId); |
| 5627 | |
| 5628 | if (DBG) { |
| 5629 | log("Exchange SIM_IO [R]" + response); |
| 5630 | } |
| 5631 | |
| 5632 | byte[] result = null; |
| 5633 | int length = 2; |
| 5634 | if (response.payload != null) { |
| 5635 | length = 2 + response.payload.length; |
| 5636 | result = new byte[length]; |
| 5637 | System.arraycopy(response.payload, 0, result, 0, response.payload.length); |
| 5638 | } else { |
| 5639 | result = new byte[length]; |
| 5640 | } |
| 5641 | |
| 5642 | result[length - 1] = (byte) response.sw2; |
| 5643 | result[length - 2] = (byte) response.sw1; |
| 5644 | return result; |
| 5645 | } finally { |
| 5646 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5647 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5648 | } |
| 5649 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5650 | /** |
| 5651 | * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM) |
| 5652 | * on a particular subscription |
| 5653 | */ |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5654 | public String[] getForbiddenPlmns(int subId, int appType, String callingPackage, |
| 5655 | String callingFeatureId) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 5656 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5657 | mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 5658 | return null; |
| 5659 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5660 | |
| 5661 | final long identity = Binder.clearCallingIdentity(); |
| 5662 | try { |
| 5663 | if (appType != TelephonyManager.APPTYPE_USIM |
| 5664 | && appType != TelephonyManager.APPTYPE_SIM) { |
| 5665 | loge("getForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 5666 | return null; |
| 5667 | } |
| 5668 | Object response = sendRequest( |
| 5669 | CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId); |
| 5670 | if (response instanceof String[]) { |
| 5671 | return (String[]) response; |
| 5672 | } |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5673 | // Response is an Exception of some kind |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5674 | // which is signalled to the user as a NULL retval |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5675 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5676 | } finally { |
| 5677 | Binder.restoreCallingIdentity(identity); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5678 | } |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5679 | } |
| 5680 | |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5681 | /** |
| 5682 | * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular |
| 5683 | * subscription. |
| 5684 | * |
| 5685 | * @param subId the id of the subscription. |
| 5686 | * @param appType the uicc app type, must be USIM or SIM. |
| 5687 | * @param fplmns the Forbiden plmns list that needed to be written to the SIM. |
| 5688 | * @param callingPackage the op Package name. |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5689 | * @param callingFeatureId the feature in the package. |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5690 | * @return number of fplmns that is successfully written to the SIM. |
| 5691 | */ |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5692 | public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage, |
| 5693 | String callingFeatureId) { |
Jayachandran C | 5b0d75a | 2021-10-21 22:15:27 -0700 | [diff] [blame] | 5694 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5695 | mApp, subId, "setForbiddenPlmns"); |
| 5696 | |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5697 | if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) { |
| 5698 | loge("setForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 5699 | throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM"); |
| 5700 | } |
| 5701 | if (fplmns == null) { |
| 5702 | throw new IllegalArgumentException("Fplmn List provided is null"); |
| 5703 | } |
| 5704 | for (String fplmn : fplmns) { |
| 5705 | if (!CellIdentity.isValidPlmn(fplmn)) { |
| 5706 | throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn); |
| 5707 | } |
| 5708 | } |
| 5709 | final long identity = Binder.clearCallingIdentity(); |
| 5710 | try { |
| 5711 | Object response = sendRequest( |
| 5712 | CMD_SET_FORBIDDEN_PLMNS, |
| 5713 | new Pair<Integer, List<String>>(new Integer(appType), fplmns), |
| 5714 | subId); |
| 5715 | return (int) response; |
| 5716 | } finally { |
| 5717 | Binder.restoreCallingIdentity(identity); |
| 5718 | } |
| 5719 | } |
| 5720 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5721 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5722 | public String sendEnvelopeWithStatus(int subId, String content) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5723 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5724 | mApp, subId, "sendEnvelopeWithStatus"); |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5725 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5726 | final long identity = Binder.clearCallingIdentity(); |
| 5727 | try { |
| 5728 | IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId); |
| 5729 | if (response.payload == null) { |
| 5730 | return ""; |
| 5731 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5732 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5733 | // Append the returned status code to the end of the response payload. |
| 5734 | String s = Integer.toHexString( |
| 5735 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 5736 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 5737 | return s; |
| 5738 | } finally { |
| 5739 | Binder.restoreCallingIdentity(identity); |
| 5740 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5741 | } |
| 5742 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5743 | /** |
| 5744 | * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 5745 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 5746 | * |
| 5747 | * @param itemID the ID of the item to read |
| 5748 | * @return the NV item as a String, or null on error. |
| 5749 | */ |
| 5750 | @Override |
| 5751 | public String nvReadItem(int itemID) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5752 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5753 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5754 | mApp, getDefaultSubscription(), "nvReadItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5755 | |
| 5756 | final long identity = Binder.clearCallingIdentity(); |
| 5757 | try { |
| 5758 | if (DBG) log("nvReadItem: item " + itemID); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5759 | String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5760 | if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"'); |
| 5761 | return value; |
| 5762 | } finally { |
| 5763 | Binder.restoreCallingIdentity(identity); |
| 5764 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5765 | } |
| 5766 | |
| 5767 | /** |
| 5768 | * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 5769 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 5770 | * |
| 5771 | * @param itemID the ID of the item to read |
| 5772 | * @param itemValue the value to write, as a String |
| 5773 | * @return true on success; false on any failure |
| 5774 | */ |
| 5775 | @Override |
| 5776 | public boolean nvWriteItem(int itemID, String itemValue) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5777 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5778 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5779 | mApp, getDefaultSubscription(), "nvWriteItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5780 | |
| 5781 | final long identity = Binder.clearCallingIdentity(); |
| 5782 | try { |
| 5783 | if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"'); |
| 5784 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5785 | new Pair<Integer, String>(itemID, itemValue), workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5786 | if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail")); |
| 5787 | return success; |
| 5788 | } finally { |
| 5789 | Binder.restoreCallingIdentity(identity); |
| 5790 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5791 | } |
| 5792 | |
| 5793 | /** |
| 5794 | * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage. |
| 5795 | * Used for device configuration by some CDMA operators. |
| 5796 | * |
| 5797 | * @param preferredRoamingList byte array containing the new PRL |
| 5798 | * @return true on success; false on any failure |
| 5799 | */ |
| 5800 | @Override |
| 5801 | public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5802 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5803 | mApp, getDefaultSubscription(), "nvWriteCdmaPrl"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5804 | |
| 5805 | final long identity = Binder.clearCallingIdentity(); |
| 5806 | try { |
| 5807 | if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList)); |
| 5808 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList); |
| 5809 | if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail")); |
| 5810 | return success; |
| 5811 | } finally { |
| 5812 | Binder.restoreCallingIdentity(identity); |
| 5813 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5814 | } |
| 5815 | |
| 5816 | /** |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5817 | * 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] | 5818 | * Used for device configuration by some CDMA operators. |
| 5819 | * |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5820 | * @param slotIndex - device slot. |
| 5821 | * |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5822 | * @return true on success; false on any failure |
| 5823 | */ |
| 5824 | @Override |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5825 | public boolean resetModemConfig(int slotIndex) { |
| 5826 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5827 | if (phone != null) { |
| 5828 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5829 | mApp, phone.getSubId(), "resetModemConfig"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5830 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5831 | final long identity = Binder.clearCallingIdentity(); |
| 5832 | try { |
| 5833 | Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null); |
| 5834 | if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 5835 | return success; |
| 5836 | } finally { |
| 5837 | Binder.restoreCallingIdentity(identity); |
| 5838 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5839 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5840 | return false; |
| 5841 | } |
| 5842 | |
| 5843 | /** |
| 5844 | * Generate a radio modem reset. Used for device configuration by some CDMA operators. |
| 5845 | * |
| 5846 | * @param slotIndex - device slot. |
| 5847 | * |
| 5848 | * @return true on success; false on any failure |
| 5849 | */ |
| 5850 | @Override |
| 5851 | public boolean rebootModem(int slotIndex) { |
| 5852 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5853 | if (phone != null) { |
| 5854 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5855 | mApp, phone.getSubId(), "rebootModem"); |
| 5856 | |
| 5857 | final long identity = Binder.clearCallingIdentity(); |
| 5858 | try { |
| 5859 | Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null); |
| 5860 | if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail")); |
| 5861 | return success; |
| 5862 | } finally { |
| 5863 | Binder.restoreCallingIdentity(identity); |
| 5864 | } |
| 5865 | } |
| 5866 | return false; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5867 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5868 | |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5869 | /** |
Grace Jia | aa2eb6b | 2020-01-09 16:26:08 -0800 | [diff] [blame] | 5870 | * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and |
| 5871 | * {@link #disableIms(int)}. |
| 5872 | * @param slotIndex device slot. |
| 5873 | */ |
| 5874 | public void resetIms(int slotIndex) { |
| 5875 | enforceModifyPermission(); |
| 5876 | |
| 5877 | final long identity = Binder.clearCallingIdentity(); |
| 5878 | try { |
| 5879 | if (mImsResolver == null) { |
| 5880 | // may happen if the does not support IMS. |
| 5881 | return; |
| 5882 | } |
Hyunho | a17ac7c | 2022-08-30 12:03:04 +0000 | [diff] [blame] | 5883 | mImsResolver.resetIms(slotIndex); |
Grace Jia | aa2eb6b | 2020-01-09 16:26:08 -0800 | [diff] [blame] | 5884 | } finally { |
| 5885 | Binder.restoreCallingIdentity(identity); |
| 5886 | } |
| 5887 | } |
| 5888 | |
| 5889 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5890 | * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability |
| 5891 | * status updates, if not already enabled. |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5892 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5893 | public void enableIms(int slotId) { |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5894 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5895 | |
| 5896 | final long identity = Binder.clearCallingIdentity(); |
| 5897 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5898 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5899 | // may happen if the device does not support IMS. |
| 5900 | return; |
| 5901 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5902 | mImsResolver.enableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5903 | } finally { |
| 5904 | Binder.restoreCallingIdentity(identity); |
| 5905 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5906 | } |
| 5907 | |
| 5908 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5909 | * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature |
| 5910 | * status updates to disabled. |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5911 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5912 | public void disableIms(int slotId) { |
| 5913 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5914 | |
| 5915 | final long identity = Binder.clearCallingIdentity(); |
| 5916 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5917 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5918 | // may happen if the device does not support IMS. |
| 5919 | return; |
| 5920 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5921 | mImsResolver.disableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5922 | } finally { |
| 5923 | Binder.restoreCallingIdentity(identity); |
| 5924 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5925 | } |
| 5926 | |
| 5927 | /** |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5928 | * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback |
| 5929 | * callback. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5930 | */ |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5931 | @Override |
Brad Ebinger | f6aca00 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 5932 | public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) { |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5933 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5934 | |
| 5935 | final long identity = Binder.clearCallingIdentity(); |
| 5936 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5937 | if (mImsResolver == null) { |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5938 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 5939 | "Device does not support IMS"); |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5940 | } |
Brad Ebinger | f6aca00 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 5941 | mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5942 | } finally { |
| 5943 | Binder.restoreCallingIdentity(identity); |
| 5944 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5945 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5946 | /** |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5947 | * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature. |
| 5948 | */ |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5949 | @Override |
| 5950 | public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) { |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5951 | enforceModifyPermission(); |
| 5952 | |
| 5953 | final long identity = Binder.clearCallingIdentity(); |
| 5954 | try { |
| 5955 | if (mImsResolver == null) return; |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5956 | mImsResolver.unregisterImsFeatureCallback(callback); |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5957 | } finally { |
| 5958 | Binder.restoreCallingIdentity(identity); |
| 5959 | } |
| 5960 | } |
| 5961 | |
| 5962 | /** |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5963 | * Returns the {@link IImsRegistration} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5964 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5965 | */ |
| 5966 | public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException { |
| 5967 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5968 | |
| 5969 | final long identity = Binder.clearCallingIdentity(); |
| 5970 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5971 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5972 | // may happen if the device does not support IMS. |
| 5973 | return null; |
| 5974 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5975 | return mImsResolver.getImsRegistration(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5976 | } finally { |
| 5977 | Binder.restoreCallingIdentity(identity); |
| 5978 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5979 | } |
| 5980 | |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5981 | /** |
| 5982 | * Returns the {@link IImsConfig} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5983 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5984 | */ |
| 5985 | public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException { |
| 5986 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5987 | |
| 5988 | final long identity = Binder.clearCallingIdentity(); |
| 5989 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5990 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5991 | // may happen if the device does not support IMS. |
| 5992 | return null; |
| 5993 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5994 | return mImsResolver.getImsConfig(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5995 | } finally { |
| 5996 | Binder.restoreCallingIdentity(identity); |
| 5997 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5998 | } |
| 5999 | |
Brad Ebinger | 884c07b | 2018-02-15 16:17:40 -0800 | [diff] [blame] | 6000 | /** |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6001 | * Sets the ImsService Package Name that Telephony will bind to. |
| 6002 | * |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6003 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 6004 | * @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] | 6005 | * ImsService is the device default ImsService. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6006 | * @param featureTypes An integer array of feature types associated with a packageName. |
| 6007 | * @param packageName The name of the package that the current configuration will be replaced |
| 6008 | * with. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6009 | * @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] | 6010 | */ |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6011 | public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService, |
| 6012 | int[] featureTypes, String packageName) { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6013 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 6014 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
Jack Yu | 00ece8c | 2022-11-19 22:29:12 -0800 | [diff] [blame] | 6015 | SubscriptionManager.getSubscriptionId(slotIndex), "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 6016 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6017 | final long identity = Binder.clearCallingIdentity(); |
| 6018 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6019 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6020 | // may happen if the device does not support IMS. |
| 6021 | return false; |
| 6022 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6023 | Map<Integer, String> featureConfig = new HashMap<>(); |
| 6024 | for (int featureType : featureTypes) { |
| 6025 | featureConfig.put(featureType, packageName); |
| 6026 | } |
| 6027 | return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService, |
| 6028 | featureConfig); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6029 | } finally { |
| 6030 | Binder.restoreCallingIdentity(identity); |
| 6031 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6032 | } |
| 6033 | |
| 6034 | /** |
Brad Ebinger | 999d330 | 2020-11-25 14:31:39 -0800 | [diff] [blame] | 6035 | * Clears any carrier ImsService overrides for the slot index specified that were previously |
| 6036 | * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}. |
| 6037 | * |
| 6038 | * This should only be used for testing. |
| 6039 | * |
| 6040 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 6041 | * @return true if clearing the carrier ImsService override succeeded or false if it did not. |
| 6042 | */ |
| 6043 | @Override |
| 6044 | public boolean clearCarrierImsServiceOverride(int slotIndex) { |
Brad Ebinger | 999d330 | 2020-11-25 14:31:39 -0800 | [diff] [blame] | 6045 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 6046 | "clearCarrierImsServiceOverride"); |
| 6047 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
Jack Yu | 00ece8c | 2022-11-19 22:29:12 -0800 | [diff] [blame] | 6048 | SubscriptionManager.getSubscriptionId(slotIndex), "clearCarrierImsServiceOverride"); |
Brad Ebinger | 999d330 | 2020-11-25 14:31:39 -0800 | [diff] [blame] | 6049 | |
| 6050 | final long identity = Binder.clearCallingIdentity(); |
| 6051 | try { |
| 6052 | if (mImsResolver == null) { |
| 6053 | // may happen if the device does not support IMS. |
| 6054 | return false; |
| 6055 | } |
| 6056 | return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex); |
| 6057 | } finally { |
| 6058 | Binder.restoreCallingIdentity(identity); |
| 6059 | } |
| 6060 | } |
| 6061 | |
| 6062 | /** |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6063 | * Return the package name of the currently bound ImsService. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6064 | * |
| 6065 | * @param slotId The slot that the ImsService is associated with. |
| 6066 | * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is |
| 6067 | * the device default. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6068 | * @param featureType The feature associated with the queried configuration. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6069 | * @return the package name of the ImsService configuration. |
| 6070 | */ |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6071 | public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService, |
| 6072 | @ImsFeature.FeatureType int featureType) { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6073 | TelephonyPermissions |
Jack Yu | 00ece8c | 2022-11-19 22:29:12 -0800 | [diff] [blame] | 6074 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(mApp, |
| 6075 | SubscriptionManager.getSubscriptionId(slotId), "getBoundImsServicePackage"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 6076 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6077 | final long identity = Binder.clearCallingIdentity(); |
| 6078 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6079 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6080 | // may happen if the device does not support IMS. |
| 6081 | return ""; |
| 6082 | } |
Brad Ebinger | a80c331 | 2019-12-02 10:59:39 -0800 | [diff] [blame] | 6083 | // TODO: change API to query RCS separately. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6084 | return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService, |
| 6085 | featureType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6086 | } finally { |
| 6087 | Binder.restoreCallingIdentity(identity); |
| 6088 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6089 | } |
| 6090 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6091 | /** |
| 6092 | * Get the MmTelFeature state associated with the requested subscription id. |
| 6093 | * @param subId The subscription that the MmTelFeature is associated with. |
| 6094 | * @param callback A callback with an integer containing the |
| 6095 | * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature. |
| 6096 | */ |
| 6097 | @Override |
| 6098 | public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) { |
| 6099 | enforceReadPrivilegedPermission("getImsMmTelFeatureState"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 6100 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 6101 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 6102 | "IMS not available on device."); |
| 6103 | } |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6104 | final long token = Binder.clearCallingIdentity(); |
| 6105 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 6106 | int slotId = getSlotIndex(subId); |
| 6107 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 6108 | Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '" |
| 6109 | + subId + "'"); |
| 6110 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 6111 | } |
| 6112 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 6113 | ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> { |
| 6114 | try { |
| 6115 | callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger); |
| 6116 | } catch (RemoteException e) { |
| 6117 | Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. " |
| 6118 | + "Ignore"); |
| 6119 | } |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6120 | }); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 6121 | } catch (ImsException e) { |
| 6122 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6123 | } finally { |
| 6124 | Binder.restoreCallingIdentity(token); |
| 6125 | } |
| 6126 | } |
| 6127 | |
Daniel Bright | bb5840b | 2021-01-12 15:48:18 -0800 | [diff] [blame] | 6128 | /** |
| 6129 | * Sets the ims registration state on all valid {@link Phone}s. |
| 6130 | */ |
| 6131 | public void setImsRegistrationState(final boolean registered) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 6132 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6133 | |
| 6134 | final long identity = Binder.clearCallingIdentity(); |
| 6135 | try { |
Daniel Bright | bb5840b | 2021-01-12 15:48:18 -0800 | [diff] [blame] | 6136 | // NOTE: Before S, this method only set the default phone. |
| 6137 | for (final Phone phone : PhoneFactory.getPhones()) { |
| 6138 | if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) { |
| 6139 | phone.setImsRegistrationState(registered); |
| 6140 | } |
| 6141 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6142 | } finally { |
| 6143 | Binder.restoreCallingIdentity(identity); |
| 6144 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 6145 | } |
| 6146 | |
| 6147 | /** |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 6148 | * Set the network selection mode to automatic. |
| 6149 | * |
| 6150 | */ |
| 6151 | @Override |
| 6152 | public void setNetworkSelectionModeAutomatic(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6153 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6154 | mApp, subId, "setNetworkSelectionModeAutomatic"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6155 | |
| 6156 | final long identity = Binder.clearCallingIdentity(); |
| 6157 | try { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 6158 | if (!isActiveSubscription(subId)) { |
| 6159 | return; |
| 6160 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6161 | if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId); |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 6162 | sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId, |
| 6163 | SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6164 | } finally { |
| 6165 | Binder.restoreCallingIdentity(identity); |
| 6166 | } |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 6167 | } |
| 6168 | |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 6169 | /** |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6170 | * Ask the radio to connect to the input network and change selection mode to manual. |
| 6171 | * |
| 6172 | * @param subId the id of the subscription. |
| 6173 | * @param operatorInfo the operator information, included the PLMN, long name and short name of |
| 6174 | * the operator to attach to. |
| 6175 | * @param persistSelection whether the selection will persist until reboot. If true, only allows |
| 6176 | * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume |
| 6177 | * normal network selection next time. |
| 6178 | * @return {@code true} on success; {@code true} on any failure. |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6179 | */ |
| 6180 | @Override |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6181 | public boolean setNetworkSelectionModeManual( |
| 6182 | int subId, OperatorInfo operatorInfo, boolean persistSelection) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6183 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6184 | mApp, subId, "setNetworkSelectionModeManual"); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 6185 | |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 6186 | final long identity = Binder.clearCallingIdentity(); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 6187 | if (!isActiveSubscription(subId)) { |
| 6188 | return false; |
| 6189 | } |
| 6190 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6191 | try { |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6192 | ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6193 | persistSelection); |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6194 | if (DBG) { |
| 6195 | log("setNetworkSelectionModeManual: subId: " + subId |
| 6196 | + " operator: " + operatorInfo); |
| 6197 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6198 | return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId); |
| 6199 | } finally { |
| 6200 | Binder.restoreCallingIdentity(identity); |
| 6201 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6202 | } |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6203 | /** |
| 6204 | * Get the manual network selection |
| 6205 | * |
| 6206 | * @param subId the id of the subscription. |
| 6207 | * |
| 6208 | * @return the previously saved user selected PLMN |
| 6209 | */ |
| 6210 | @Override |
| 6211 | public String getManualNetworkSelectionPlmn(int subId) { |
| 6212 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 6213 | .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6214 | mApp, subId, "getManualNetworkSelectionPlmn"); |
| 6215 | |
| 6216 | final long identity = Binder.clearCallingIdentity(); |
| 6217 | try { |
| 6218 | if (!isActiveSubscription(subId)) { |
shilu | fa1c259 | 2020-03-10 10:59:43 -0700 | [diff] [blame] | 6219 | throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6220 | } |
| 6221 | |
| 6222 | final Phone phone = getPhone(subId); |
| 6223 | if (phone == null) { |
shilu | fa1c259 | 2020-03-10 10:59:43 -0700 | [diff] [blame] | 6224 | throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6225 | } |
| 6226 | OperatorInfo networkSelection = phone.getSavedNetworkSelection(); |
| 6227 | return TextUtils.isEmpty(networkSelection.getOperatorNumeric()) |
| 6228 | ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric(); |
| 6229 | } finally { |
| 6230 | Binder.restoreCallingIdentity(identity); |
| 6231 | } |
| 6232 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6233 | |
| 6234 | /** |
| 6235 | * Scans for available networks. |
| 6236 | */ |
| 6237 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6238 | public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage, |
| 6239 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6240 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6241 | mApp, subId, "getCellNetworkScanResults"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6242 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 6243 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 6244 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 6245 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6246 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6247 | .setCallingPid(Binder.getCallingPid()) |
| 6248 | .setCallingUid(Binder.getCallingUid()) |
| 6249 | .setMethod("getCellNetworkScanResults") |
| 6250 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
Hall Liu | c4a3e42 | 2020-05-26 17:18:03 -0700 | [diff] [blame] | 6251 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 6252 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6253 | .build()); |
| 6254 | switch (locationResult) { |
| 6255 | case DENIED_HARD: |
| 6256 | throw new SecurityException("Not allowed to access scan results -- location"); |
| 6257 | case DENIED_SOFT: |
| 6258 | return null; |
| 6259 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6260 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6261 | long identity = Binder.clearCallingIdentity(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6262 | try { |
| 6263 | if (DBG) log("getCellNetworkScanResults: subId " + subId); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6264 | return (CellNetworkScanResult) sendRequest( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6265 | CMD_PERFORM_NETWORK_SCAN, null, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6266 | } finally { |
| 6267 | Binder.restoreCallingIdentity(identity); |
| 6268 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6269 | } |
| 6270 | |
| 6271 | /** |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6272 | * Get the call forwarding info, given the call forwarding reason. |
| 6273 | */ |
| 6274 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6275 | public void getCallForwarding(int subId, int callForwardingReason, |
| 6276 | ICallForwardingInfoCallback callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6277 | enforceReadPrivilegedPermission("getCallForwarding"); |
| 6278 | long identity = Binder.clearCallingIdentity(); |
| 6279 | try { |
| 6280 | if (DBG) { |
| 6281 | log("getCallForwarding: subId " + subId |
| 6282 | + " callForwardingReason" + callForwardingReason); |
| 6283 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6284 | |
| 6285 | Phone phone = getPhone(subId); |
| 6286 | if (phone == null) { |
| 6287 | try { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 6288 | callback.onError( |
| 6289 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6290 | } catch (RemoteException e) { |
| 6291 | // ignore |
| 6292 | } |
| 6293 | return; |
| 6294 | } |
| 6295 | |
| 6296 | Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create( |
| 6297 | callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() { |
| 6298 | @Override |
| 6299 | public void onCallForwardingInfoAvailable(CallForwardingInfo info) { |
| 6300 | try { |
| 6301 | callback.onCallForwardingInfoAvailable(info); |
| 6302 | } catch (RemoteException e) { |
| 6303 | // ignore |
| 6304 | } |
| 6305 | } |
| 6306 | |
| 6307 | @Override |
| 6308 | public void onError(int error) { |
| 6309 | try { |
| 6310 | callback.onError(error); |
| 6311 | } catch (RemoteException e) { |
| 6312 | // ignore |
| 6313 | } |
| 6314 | } |
| 6315 | }); |
| 6316 | sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6317 | } finally { |
| 6318 | Binder.restoreCallingIdentity(identity); |
| 6319 | } |
| 6320 | } |
| 6321 | |
| 6322 | /** |
| 6323 | * Sets the voice call forwarding info including status (enable/disable), call forwarding |
| 6324 | * reason, the number to forward, and the timeout before the forwarding is attempted. |
| 6325 | */ |
| 6326 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6327 | public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo, |
| 6328 | IIntegerConsumer callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6329 | enforceModifyPermission(); |
| 6330 | long identity = Binder.clearCallingIdentity(); |
| 6331 | try { |
| 6332 | if (DBG) { |
| 6333 | log("setCallForwarding: subId " + subId |
| 6334 | + " callForwardingInfo" + callForwardingInfo); |
| 6335 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6336 | |
| 6337 | Phone phone = getPhone(subId); |
| 6338 | if (phone == null) { |
| 6339 | try { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 6340 | callback.accept( |
| 6341 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6342 | } catch (RemoteException e) { |
| 6343 | // ignore |
| 6344 | } |
| 6345 | return; |
| 6346 | } |
| 6347 | |
| 6348 | Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo, |
| 6349 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 6350 | |
| 6351 | sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6352 | } finally { |
| 6353 | Binder.restoreCallingIdentity(identity); |
| 6354 | } |
| 6355 | } |
| 6356 | |
| 6357 | /** |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6358 | * Get the call waiting status for a subId. |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6359 | */ |
| 6360 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6361 | public void getCallWaitingStatus(int subId, IIntegerConsumer callback) { |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6362 | enforceReadPrivilegedPermission("getCallWaitingStatus"); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6363 | long identity = Binder.clearCallingIdentity(); |
| 6364 | try { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6365 | Phone phone = getPhone(subId); |
| 6366 | if (phone == null) { |
| 6367 | try { |
| 6368 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 6369 | } catch (RemoteException e) { |
| 6370 | // ignore |
| 6371 | } |
| 6372 | return; |
| 6373 | } |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6374 | CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext()); |
| 6375 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 6376 | boolean requireUssd = c.getBoolean( |
| 6377 | CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6378 | |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6379 | if (DBG) log("getCallWaitingStatus: subId " + subId); |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6380 | if (requireUssd) { |
| 6381 | CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(), |
| 6382 | getSubscriptionCarrierId(subId)); |
| 6383 | String newUssdCommand = ""; |
| 6384 | try { |
| 6385 | newUssdCommand = carrierXmlParser.getFeature( |
| 6386 | CarrierXmlParser.FEATURE_CALL_WAITING) |
| 6387 | .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null); |
| 6388 | } catch (NullPointerException e) { |
| 6389 | loge("Failed to generate USSD number" + e); |
| 6390 | } |
| 6391 | ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver( |
| 6392 | mMainThreadHandler, callback, carrierXmlParser, |
| 6393 | CarrierXmlParser.SsEntry.SSAction.QUERY); |
| 6394 | final String ussdCommand = newUssdCommand; |
| 6395 | Executors.newSingleThreadExecutor().execute(() -> { |
| 6396 | handleUssdRequest(subId, ussdCommand, wrappedCallback); |
| 6397 | }); |
| 6398 | } else { |
| 6399 | Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException( |
| 6400 | callback::accept); |
| 6401 | sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null); |
| 6402 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6403 | } finally { |
| 6404 | Binder.restoreCallingIdentity(identity); |
| 6405 | } |
| 6406 | } |
| 6407 | |
| 6408 | /** |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6409 | * Sets whether call waiting is enabled for a given subId. |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6410 | */ |
| 6411 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6412 | public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6413 | enforceModifyPermission(); |
| 6414 | long identity = Binder.clearCallingIdentity(); |
| 6415 | try { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6416 | if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable); |
| 6417 | |
| 6418 | Phone phone = getPhone(subId); |
| 6419 | if (phone == null) { |
| 6420 | try { |
| 6421 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 6422 | } catch (RemoteException e) { |
| 6423 | // ignore |
| 6424 | } |
| 6425 | return; |
| 6426 | } |
| 6427 | |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6428 | CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext()); |
| 6429 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 6430 | boolean requireUssd = c.getBoolean( |
| 6431 | CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6432 | |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6433 | if (DBG) log("getCallWaitingStatus: subId " + subId); |
| 6434 | if (requireUssd) { |
| 6435 | CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(), |
| 6436 | getSubscriptionCarrierId(subId)); |
| 6437 | CarrierXmlParser.SsEntry.SSAction ssAction = |
| 6438 | enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE |
| 6439 | : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE; |
| 6440 | String newUssdCommand = ""; |
| 6441 | try { |
| 6442 | newUssdCommand = carrierXmlParser.getFeature( |
| 6443 | CarrierXmlParser.FEATURE_CALL_WAITING) |
| 6444 | .makeCommand(ssAction, null); |
| 6445 | } catch (NullPointerException e) { |
| 6446 | loge("Failed to generate USSD number" + e); |
| 6447 | } |
| 6448 | ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver( |
| 6449 | mMainThreadHandler, callback, carrierXmlParser, ssAction); |
| 6450 | final String ussdCommand = newUssdCommand; |
| 6451 | Executors.newSingleThreadExecutor().execute(() -> { |
| 6452 | handleUssdRequest(subId, ussdCommand, wrappedCallback); |
| 6453 | }); |
| 6454 | } else { |
| 6455 | Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable, |
| 6456 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 6457 | |
| 6458 | sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null); |
| 6459 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6460 | } finally { |
| 6461 | Binder.restoreCallingIdentity(identity); |
| 6462 | } |
| 6463 | } |
| 6464 | |
| 6465 | /** |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 6466 | * Starts a new network scan and returns the id of this scan. |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6467 | * |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 6468 | * @param subId id of the subscription |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 6469 | * @param renounceFineLocationAccess Set this to true if the caller would not like to receive |
| 6470 | * location related information which will be sent if the caller already possess |
| 6471 | * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 6472 | * @param request contains the radio access networks with bands/channels to scan |
| 6473 | * @param messenger callback messenger for scan results or errors |
| 6474 | * @param binder for the purpose of auto clean when the user thread crashes |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6475 | * @return the id of the requested scan which can be used to stop the scan. |
| 6476 | */ |
| 6477 | @Override |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 6478 | public int requestNetworkScan(int subId, boolean renounceFineLocationAccess, |
| 6479 | NetworkScanRequest request, Messenger messenger, |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6480 | IBinder binder, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6481 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6482 | mApp, subId, "requestNetworkScan"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6483 | LocationAccessPolicy.LocationPermissionResult locationResult = |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 6484 | LocationAccessPolicy.LocationPermissionResult.DENIED_HARD; |
| 6485 | if (!renounceFineLocationAccess) { |
| 6486 | locationResult = LocationAccessPolicy.checkLocationPermission(mApp, |
| 6487 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 6488 | .setCallingPackage(callingPackage) |
| 6489 | .setCallingFeatureId(callingFeatureId) |
| 6490 | .setCallingPid(Binder.getCallingPid()) |
| 6491 | .setCallingUid(Binder.getCallingUid()) |
| 6492 | .setMethod("requestNetworkScan") |
| 6493 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 6494 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 6495 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 6496 | .build()); |
| 6497 | } |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6498 | if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) { |
Nathan Harold | 1c11dba | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 6499 | SecurityException e = checkNetworkRequestForSanitizedLocationAccess( |
| 6500 | request, subId, callingPackage); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6501 | if (e != null) { |
| 6502 | if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) { |
| 6503 | throw e; |
| 6504 | } else { |
Hall Liu | 0e5abaf | 2019-04-04 01:25:30 -0700 | [diff] [blame] | 6505 | loge(e.getMessage()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6506 | return TelephonyScanManager.INVALID_SCAN_ID; |
| 6507 | } |
| 6508 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6509 | } |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6510 | int callingUid = Binder.getCallingUid(); |
| 6511 | int callingPid = Binder.getCallingPid(); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 6512 | final long identity = Binder.clearCallingIdentity(); |
| 6513 | try { |
| 6514 | return mNetworkScanRequestTracker.startNetworkScan( |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 6515 | renounceFineLocationAccess, request, messenger, binder, getPhone(subId), |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6516 | callingUid, callingPid, callingPackage); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 6517 | } finally { |
| 6518 | Binder.restoreCallingIdentity(identity); |
| 6519 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6520 | } |
| 6521 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6522 | private SecurityException checkNetworkRequestForSanitizedLocationAccess( |
Nathan Harold | 1c11dba | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 6523 | NetworkScanRequest request, int subId, String callingPackage) { |
Rambo Wang | 3dee30a | 2022-10-20 16:52:29 +0000 | [diff] [blame] | 6524 | boolean hasCarrierPriv; |
| 6525 | final long identity = Binder.clearCallingIdentity(); |
| 6526 | try { |
| 6527 | hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage) |
| 6528 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 6529 | } finally { |
| 6530 | Binder.restoreCallingIdentity(identity); |
| 6531 | } |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 6532 | boolean hasNetworkScanPermission = |
| 6533 | mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN) |
| 6534 | == PERMISSION_GRANTED; |
| 6535 | |
| 6536 | if (!hasCarrierPriv && !hasNetworkScanPermission) { |
| 6537 | return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed" |
| 6538 | + " for network scans without location access."); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6539 | } |
| 6540 | |
| 6541 | if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) { |
| 6542 | for (RadioAccessSpecifier ras : request.getSpecifiers()) { |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6543 | if (ras.getChannels() != null && ras.getChannels().length > 0) { |
| 6544 | return new SecurityException("Specific channels must not be" |
| 6545 | + " scanned without location access."); |
| 6546 | } |
| 6547 | } |
| 6548 | } |
| 6549 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6550 | return null; |
| 6551 | } |
| 6552 | |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6553 | /** |
| 6554 | * Stops an existing network scan with the given scanId. |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 6555 | * |
| 6556 | * @param subId id of the subscription |
| 6557 | * @param scanId id of the scan that needs to be stopped |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6558 | */ |
| 6559 | @Override |
| 6560 | public void stopNetworkScan(int subId, int scanId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6561 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6562 | mApp, subId, "stopNetworkScan"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6563 | |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6564 | int callingUid = Binder.getCallingUid(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6565 | final long identity = Binder.clearCallingIdentity(); |
| 6566 | try { |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6567 | mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6568 | } finally { |
| 6569 | Binder.restoreCallingIdentity(identity); |
| 6570 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6571 | } |
| 6572 | |
| 6573 | /** |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6574 | * Get the allowed network types bitmask. |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 6575 | * |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6576 | * @return the allowed network types bitmask, defined in RILConstants.java. |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 6577 | */ |
| 6578 | @Override |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6579 | public int getAllowedNetworkTypesBitmask(int subId) { |
Pengquan Meng | a4009cb | 2018-12-20 11:00:24 -0800 | [diff] [blame] | 6580 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 6581 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6582 | mApp, subId, "getAllowedNetworkTypesBitmask"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6583 | |
| 6584 | final long identity = Binder.clearCallingIdentity(); |
| 6585 | try { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6586 | if (DBG) log("getAllowedNetworkTypesBitmask"); |
| 6587 | int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId); |
| 6588 | int networkTypesBitmask = (result != null ? result[0] : -1); |
| 6589 | if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask); |
| 6590 | return networkTypesBitmask; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6591 | } finally { |
| 6592 | Binder.restoreCallingIdentity(identity); |
| 6593 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 6594 | } |
| 6595 | |
| 6596 | /** |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6597 | * Get the allowed network types for certain reason. |
| 6598 | * |
| 6599 | * @param subId the id of the subscription. |
| 6600 | * @param reason the reason the allowed network type change is taking place |
| 6601 | * @return the allowed network types. |
| 6602 | */ |
| 6603 | @Override |
| 6604 | public long getAllowedNetworkTypesForReason(int subId, |
| 6605 | @TelephonyManager.AllowedNetworkTypesReason int reason) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 6606 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 6607 | mApp, subId, "getAllowedNetworkTypesForReason"); |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6608 | final long identity = Binder.clearCallingIdentity(); |
| 6609 | try { |
| 6610 | return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason); |
| 6611 | } finally { |
| 6612 | Binder.restoreCallingIdentity(identity); |
| 6613 | } |
| 6614 | } |
| 6615 | |
| 6616 | /** |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6617 | * Enable/Disable E-UTRA-NR Dual Connectivity |
| 6618 | * @param subId subscription id of the sim card |
| 6619 | * @param nrDualConnectivityState expected NR dual connectivity state |
| 6620 | * This can be passed following states |
| 6621 | * <ol> |
| 6622 | * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE} |
| 6623 | * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE} |
| 6624 | * <li>Disable NR dual connectivity and force secondary cell to be released |
| 6625 | * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE} |
| 6626 | * </ol> |
| 6627 | * @return operation result. |
| 6628 | */ |
| 6629 | @Override |
| 6630 | public int setNrDualConnectivityState(int subId, |
| 6631 | @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) { |
| 6632 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6633 | mApp, subId, "enableNRDualConnectivity"); |
Sooraj Sasindran | 0e4e00a | 2021-03-16 18:02:32 -0700 | [diff] [blame] | 6634 | if (!isRadioInterfaceCapabilitySupported( |
Sooraj Sasindran | dfd595b | 2021-03-11 17:38:13 -0800 | [diff] [blame] | 6635 | TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) { |
| 6636 | return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED; |
| 6637 | } |
| 6638 | |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6639 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 6640 | final long identity = Binder.clearCallingIdentity(); |
| 6641 | try { |
| 6642 | int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY, |
| 6643 | nrDualConnectivityState, subId, |
| 6644 | workSource); |
| 6645 | if (DBG) log("enableNRDualConnectivity result: " + result); |
| 6646 | return result; |
| 6647 | } finally { |
| 6648 | Binder.restoreCallingIdentity(identity); |
| 6649 | } |
| 6650 | } |
| 6651 | |
| 6652 | /** |
| 6653 | * Is E-UTRA-NR Dual Connectivity enabled |
| 6654 | * @return true if dual connectivity is enabled else false |
| 6655 | */ |
| 6656 | @Override |
| 6657 | public boolean isNrDualConnectivityEnabled(int subId) { |
| 6658 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 6659 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6660 | mApp, subId, "isNRDualConnectivityEnabled"); |
Sooraj Sasindran | 0e4e00a | 2021-03-16 18:02:32 -0700 | [diff] [blame] | 6661 | if (!isRadioInterfaceCapabilitySupported( |
Sooraj Sasindran | dfd595b | 2021-03-11 17:38:13 -0800 | [diff] [blame] | 6662 | TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) { |
| 6663 | return false; |
| 6664 | } |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6665 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 6666 | final long identity = Binder.clearCallingIdentity(); |
| 6667 | try { |
| 6668 | boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED, |
| 6669 | null, subId, workSource); |
| 6670 | if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled); |
| 6671 | return isEnabled; |
| 6672 | } finally { |
| 6673 | Binder.restoreCallingIdentity(identity); |
| 6674 | } |
| 6675 | } |
| 6676 | |
| 6677 | /** |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6678 | * Set the allowed network types of the device and |
| 6679 | * provide the reason triggering the allowed network change. |
| 6680 | * |
| 6681 | * @param subId the id of the subscription. |
| 6682 | * @param reason the reason the allowed network type change is taking place |
| 6683 | * @param allowedNetworkTypes the allowed network types. |
| 6684 | * @return true on success; false on any failure. |
| 6685 | */ |
| 6686 | @Override |
| 6687 | public boolean setAllowedNetworkTypesForReason(int subId, |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6688 | @TelephonyManager.AllowedNetworkTypesReason int reason, |
| 6689 | @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) { |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6690 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6691 | mApp, subId, "setAllowedNetworkTypesForReason"); |
Gil Cukierman | 1d3d375 | 2022-10-03 21:31:33 +0000 | [diff] [blame] | 6692 | // If the caller only has carrier privileges, then they should not be able to override |
| 6693 | // any network types which were set for security reasons. |
| 6694 | if (mApp.checkCallingOrSelfPermission(Manifest.permission.MODIFY_PHONE_STATE) |
| 6695 | != PERMISSION_GRANTED |
| 6696 | && (reason == TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_ENABLE_2G |
| 6697 | || reason == TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER_RESTRICTIONS)) { |
| 6698 | throw new SecurityException( |
| 6699 | "setAllowedNetworkTypesForReason cannot be called with carrier privileges for" |
| 6700 | + " reason " |
| 6701 | + reason); |
| 6702 | } |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6703 | if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) { |
SongFerngWang | 7ffc273 | 2021-04-15 19:46:33 +0800 | [diff] [blame] | 6704 | loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason); |
| 6705 | return false; |
| 6706 | } |
| 6707 | if (!SubscriptionManager.isUsableSubscriptionId(subId)) { |
| 6708 | loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId); |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6709 | return false; |
| 6710 | } |
| 6711 | |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 6712 | log("setAllowedNetworkTypesForReason: " + reason + " value: " |
| 6713 | + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes)); |
| 6714 | |
| 6715 | |
| 6716 | if (allowedNetworkTypes == getPhoneFromSubId(subId).getAllowedNetworkTypes(reason)) { |
| 6717 | log("setAllowedNetworkTypesForReason: " + reason + "does not change value"); |
| 6718 | return true; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6719 | } |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 6720 | |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6721 | final long identity = Binder.clearCallingIdentity(); |
| 6722 | try { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6723 | Boolean success = (Boolean) sendRequest( |
| 6724 | CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON, |
| 6725 | new Pair<Integer, Long>(reason, allowedNetworkTypes), subId); |
| 6726 | |
| 6727 | if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail")); |
| 6728 | return success; |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6729 | } finally { |
| 6730 | Binder.restoreCallingIdentity(identity); |
| 6731 | } |
| 6732 | } |
| 6733 | |
| 6734 | /** |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6735 | * Check whether DUN APN is required for tethering with subId. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6736 | * |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6737 | * @param subId the id of the subscription to require tethering. |
Amit Mahajan | fe58cdf | 2017-07-11 12:01:53 -0700 | [diff] [blame] | 6738 | * @return {@code true} if DUN APN is required for tethering. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6739 | * @hide |
| 6740 | */ |
| 6741 | @Override |
SongFerngWang | f08d812 | 2019-11-15 14:58:44 +0800 | [diff] [blame] | 6742 | public boolean isTetheringApnRequiredForSubscriber(int subId) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6743 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6744 | final long identity = Binder.clearCallingIdentity(); |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6745 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6746 | try { |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6747 | if (phone != null) { |
| 6748 | return phone.hasMatchedTetherApnSetting(); |
| 6749 | } else { |
| 6750 | return false; |
| 6751 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6752 | } finally { |
| 6753 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6754 | } |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6755 | } |
| 6756 | |
| 6757 | /** |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6758 | * Get the user enabled state of Mobile Data. |
| 6759 | * |
| 6760 | * TODO: remove and use isUserDataEnabled. |
| 6761 | * This can't be removed now because some vendor codes |
| 6762 | * calls through ITelephony directly while they should |
| 6763 | * use TelephonyManager. |
| 6764 | * |
| 6765 | * @return true on enabled |
| 6766 | */ |
| 6767 | @Override |
| 6768 | public boolean getDataEnabled(int subId) { |
| 6769 | return isUserDataEnabled(subId); |
| 6770 | } |
| 6771 | |
| 6772 | /** |
| 6773 | * Get whether mobile data is enabled per user setting. |
| 6774 | * |
| 6775 | * There are other factors deciding whether mobile data is actually enabled, but they are |
| 6776 | * not considered here. See {@link #isDataEnabled(int)} for more details. |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6777 | * |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6778 | * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE |
| 6779 | * or carrier privileges. |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 6780 | * |
| 6781 | * @return {@code true} if data is enabled else {@code false} |
| 6782 | */ |
| 6783 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6784 | public boolean isUserDataEnabled(int subId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6785 | String functionName = "isUserDataEnabled"; |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6786 | try { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6787 | try { |
| 6788 | mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE, |
| 6789 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 6790 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6791 | mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName); |
| 6792 | } |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 6793 | } catch (SecurityException e) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6794 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6795 | mApp, subId, functionName); |
| 6796 | |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6797 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6798 | |
| 6799 | final long identity = Binder.clearCallingIdentity(); |
| 6800 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 6801 | int phoneId = SubscriptionManager.getPhoneId(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6802 | if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 6803 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6804 | if (phone != null) { |
| 6805 | boolean retVal = phone.isUserDataEnabled(); |
| 6806 | if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 6807 | return retVal; |
| 6808 | } else { |
| 6809 | if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 6810 | return false; |
| 6811 | } |
| 6812 | } finally { |
| 6813 | Binder.restoreCallingIdentity(identity); |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6814 | } |
| 6815 | } |
| 6816 | |
| 6817 | /** |
Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 6818 | * Checks if the device is capable of mobile data by considering whether whether the |
| 6819 | * user has enabled mobile data, whether the carrier has enabled mobile data, and |
| 6820 | * whether the network policy allows data connections. |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6821 | * |
Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 6822 | * @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] | 6823 | */ |
| 6824 | @Override |
| 6825 | public boolean isDataEnabled(int subId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6826 | String functionName = "isDataEnabled"; |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6827 | try { |
| 6828 | try { |
| 6829 | mApp.enforceCallingOrSelfPermission( |
| 6830 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6831 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 6832 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6833 | try { |
| 6834 | mApp.enforceCallingOrSelfPermission( |
| 6835 | android.Manifest.permission.READ_PHONE_STATE, |
| 6836 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 6837 | } catch (SecurityException e2) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6838 | mApp.enforceCallingOrSelfPermission( |
| 6839 | permission.READ_BASIC_PHONE_STATE, functionName); |
| 6840 | } |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6841 | } |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 6842 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6843 | enforceReadPrivilegedPermission(functionName); |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6844 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6845 | |
| 6846 | final long identity = Binder.clearCallingIdentity(); |
| 6847 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 6848 | int phoneId = SubscriptionManager.getPhoneId(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6849 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6850 | if (phone != null) { |
Sarah Chin | e04784a | 2022-10-31 20:32:34 -0700 | [diff] [blame] | 6851 | boolean retVal = phone.getDataSettingsManager().isDataEnabled(); |
Jack Yu | 4ad64e5 | 2021-12-03 14:23:53 -0800 | [diff] [blame] | 6852 | if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6853 | return retVal; |
| 6854 | } else { |
| 6855 | if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 6856 | return false; |
| 6857 | } |
| 6858 | } finally { |
| 6859 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 6860 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 6861 | } |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6862 | |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6863 | /** |
| 6864 | * Check if data is enabled for a specific reason |
| 6865 | * @param subId Subscription index |
| 6866 | * @param reason the reason the data enable change is taking place |
| 6867 | * @return {@code true} if the overall data is enabled; {@code false} if not. |
| 6868 | */ |
| 6869 | @Override |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6870 | public boolean isDataEnabledForReason(int subId, |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6871 | @TelephonyManager.DataEnabledReason int reason) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6872 | String functionName = "isDataEnabledForReason"; |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6873 | try { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6874 | try { |
| 6875 | mApp.enforceCallingOrSelfPermission( |
| 6876 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 6877 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 6878 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6879 | mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE, |
| 6880 | functionName); |
| 6881 | } |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 6882 | } catch (SecurityException e) { |
Sooraj Sasindran | 0d909a0 | 2021-11-08 12:01:16 -0800 | [diff] [blame] | 6883 | try { |
| 6884 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6885 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 6886 | } catch (SecurityException e2) { |
Sooraj Sasindran | 0d909a0 | 2021-11-08 12:01:16 -0800 | [diff] [blame] | 6887 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6888 | mApp, subId, functionName); |
Sooraj Sasindran | 0d909a0 | 2021-11-08 12:01:16 -0800 | [diff] [blame] | 6889 | } |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6890 | } |
| 6891 | |
| 6892 | |
| 6893 | final long identity = Binder.clearCallingIdentity(); |
| 6894 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 6895 | int phoneId = SubscriptionManager.getPhoneId(subId); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6896 | if (DBG) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6897 | log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6898 | + " reason=" + reason); |
| 6899 | } |
| 6900 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6901 | if (phone != null) { |
| 6902 | boolean retVal; |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 6903 | retVal = phone.getDataSettingsManager().isDataEnabledForReason(reason); |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6904 | if (DBG) log("isDataEnabledForReason: retVal=" + retVal); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6905 | return retVal; |
| 6906 | } else { |
| 6907 | if (DBG) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6908 | loge("isDataEnabledForReason: no phone subId=" |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6909 | + subId + " retVal=false"); |
| 6910 | } |
| 6911 | return false; |
| 6912 | } |
| 6913 | } finally { |
| 6914 | Binder.restoreCallingIdentity(identity); |
| 6915 | } |
| 6916 | } |
| 6917 | |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6918 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6919 | public int getCarrierPrivilegeStatus(int subId) { |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6920 | // No permission needed; this only lets the caller inspect their own status. |
| 6921 | return getCarrierPrivilegeStatusForUidWithPermission(subId, Binder.getCallingUid()); |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6922 | } |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 6923 | |
| 6924 | @Override |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6925 | public int getCarrierPrivilegeStatusForUid(int subId, int uid) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6926 | enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid"); |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6927 | return getCarrierPrivilegeStatusForUidWithPermission(subId, uid); |
| 6928 | } |
| 6929 | |
| 6930 | private int getCarrierPrivilegeStatusForUidWithPermission(int subId, int uid) { |
| 6931 | Phone phone = getPhone(subId); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6932 | if (phone == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 6933 | loge("getCarrierPrivilegeStatusForUid: Invalid subId"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6934 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 6935 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6936 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 6937 | if (cpt == null) { |
| 6938 | loge("getCarrierPrivilegeStatusForUid: No CarrierPrivilegesTracker"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6939 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6940 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6941 | return cpt.getCarrierPrivilegeStatusForUid(uid); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6942 | } |
| 6943 | |
| 6944 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6945 | public int checkCarrierPrivilegesForPackage(int subId, String pkgName) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 6946 | enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage"); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6947 | if (TextUtils.isEmpty(pkgName)) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 6948 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6949 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6950 | Phone phone = getPhone(subId); |
| 6951 | if (phone == null) { |
| 6952 | loge("checkCarrierPrivilegesForPackage: Invalid subId"); |
| 6953 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 6954 | } |
| 6955 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 6956 | if (cpt == null) { |
| 6957 | loge("checkCarrierPrivilegesForPackage: No CarrierPrivilegesTracker"); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 6958 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6959 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6960 | return cpt.getCarrierPrivilegeStatusForPackage(pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6961 | } |
| 6962 | |
| 6963 | @Override |
| 6964 | public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) { |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6965 | enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackageAnyPhone"); |
Rambo Wang | e7209ce | 2022-02-23 13:41:02 -0800 | [diff] [blame] | 6966 | return checkCarrierPrivilegesForPackageAnyPhoneWithPermission(pkgName); |
| 6967 | } |
| 6968 | |
| 6969 | private int checkCarrierPrivilegesForPackageAnyPhoneWithPermission(String pkgName) { |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6970 | if (TextUtils.isEmpty(pkgName)) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 6971 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6972 | } |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6973 | int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6974 | for (int phoneId = 0; phoneId < TelephonyManager.getDefault().getPhoneCount(); phoneId++) { |
| 6975 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6976 | if (phone == null) { |
| 6977 | continue; |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6978 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6979 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 6980 | if (cpt == null) { |
| 6981 | continue; |
| 6982 | } |
| 6983 | result = cpt.getCarrierPrivilegeStatusForPackage(pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6984 | if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 6985 | break; |
| 6986 | } |
| 6987 | } |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6988 | return result; |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 6989 | } |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 6990 | |
| 6991 | @Override |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 6992 | public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 6993 | enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone"); |
Rambo Wang | 8a247eb | 2022-02-08 21:11:18 +0000 | [diff] [blame] | 6994 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6995 | if (phone == null) { |
| 6996 | return Collections.emptyList(); |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 6997 | } |
Rambo Wang | 8a247eb | 2022-02-08 21:11:18 +0000 | [diff] [blame] | 6998 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 6999 | if (cpt == null) { |
| 7000 | return Collections.emptyList(); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 7001 | } |
Rambo Wang | 8a247eb | 2022-02-08 21:11:18 +0000 | [diff] [blame] | 7002 | return cpt.getCarrierPackageNamesForIntent(intent); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 7003 | } |
| 7004 | |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 7005 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7006 | public List<String> getPackagesWithCarrierPrivileges(int phoneId) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 7007 | enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges"); |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7008 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 7009 | if (phone == null) { |
| 7010 | return Collections.emptyList(); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 7011 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7012 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7013 | if (cpt == null) { |
| 7014 | return Collections.emptyList(); |
| 7015 | } |
| 7016 | return new ArrayList<>(cpt.getPackagesWithCarrierPrivileges()); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 7017 | } |
| 7018 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7019 | @Override |
| 7020 | public List<String> getPackagesWithCarrierPrivilegesForAllPhones() { |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 7021 | enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones"); |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7022 | Set<String> privilegedPackages = new ArraySet<>(); |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 7023 | final long identity = Binder.clearCallingIdentity(); |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 7024 | try { |
| 7025 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 7026 | privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i)); |
| 7027 | } |
| 7028 | } finally { |
| 7029 | Binder.restoreCallingIdentity(identity); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7030 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7031 | return new ArrayList<>(privilegedPackages); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7032 | } |
| 7033 | |
Rambo Wang | 6812ffb | 2022-03-15 16:54:17 -0700 | [diff] [blame] | 7034 | @Override |
| 7035 | public @Nullable String getCarrierServicePackageNameForLogicalSlot(int logicalSlotIndex) { |
| 7036 | enforceReadPrivilegedPermission("getCarrierServicePackageNameForLogicalSlot"); |
| 7037 | |
| 7038 | final Phone phone = PhoneFactory.getPhone(logicalSlotIndex); |
| 7039 | if (phone == null) { |
| 7040 | return null; |
| 7041 | } |
| 7042 | final CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7043 | if (cpt == null) { |
| 7044 | return null; |
| 7045 | } |
| 7046 | return cpt.getCarrierServicePackageName(); |
| 7047 | } |
| 7048 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 7049 | private String getIccId(int subId) { |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 7050 | final Phone phone = getPhone(subId); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 7051 | UiccPort port = phone == null ? null : phone.getUiccPort(); |
| 7052 | if (port == null) { |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7053 | return null; |
| 7054 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 7055 | String iccId = port.getIccId(); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7056 | if (TextUtils.isEmpty(iccId)) { |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7057 | return null; |
| 7058 | } |
| 7059 | return iccId; |
| 7060 | } |
| 7061 | |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 7062 | @Override |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 7063 | public void setCallComposerStatus(int subId, int status) { |
| 7064 | enforceModifyPermission(); |
| 7065 | |
| 7066 | final long identity = Binder.clearCallingIdentity(); |
| 7067 | try { |
| 7068 | Phone phone = getPhone(subId); |
| 7069 | if (phone != null) { |
| 7070 | Phone defaultPhone = phone.getImsPhone(); |
| 7071 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 7072 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 7073 | imsPhone.setCallComposerStatus(status); |
Shuo Qian | 284ae75 | 2020-12-22 19:10:14 -0800 | [diff] [blame] | 7074 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| 7075 | .updateImsServiceConfig(); |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 7076 | } |
| 7077 | } |
Shuo Qian | 284ae75 | 2020-12-22 19:10:14 -0800 | [diff] [blame] | 7078 | } catch (ImsException e) { |
| 7079 | throw new ServiceSpecificException(e.getCode()); |
| 7080 | } finally { |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 7081 | Binder.restoreCallingIdentity(identity); |
| 7082 | } |
| 7083 | } |
| 7084 | |
| 7085 | @Override |
| 7086 | public int getCallComposerStatus(int subId) { |
| 7087 | enforceReadPrivilegedPermission("getCallComposerStatus"); |
| 7088 | |
| 7089 | final long identity = Binder.clearCallingIdentity(); |
| 7090 | try { |
| 7091 | Phone phone = getPhone(subId); |
| 7092 | if (phone != null) { |
| 7093 | Phone defaultPhone = phone.getImsPhone(); |
| 7094 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 7095 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 7096 | return imsPhone.getCallComposerStatus(); |
| 7097 | } |
| 7098 | } |
| 7099 | } finally { |
| 7100 | Binder.restoreCallingIdentity(identity); |
| 7101 | } |
| 7102 | return TelephonyManager.CALL_COMPOSER_STATUS_OFF; |
| 7103 | } |
| 7104 | |
| 7105 | @Override |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7106 | public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag, |
| 7107 | String number) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 7108 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7109 | subId, "setLine1NumberForDisplayForSubscriber"); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7110 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7111 | final long identity = Binder.clearCallingIdentity(); |
| 7112 | try { |
| 7113 | final String iccId = getIccId(subId); |
| 7114 | final Phone phone = getPhone(subId); |
| 7115 | if (phone == null) { |
| 7116 | return false; |
| 7117 | } |
| 7118 | final String subscriberId = phone.getSubscriberId(); |
| 7119 | |
| 7120 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 7121 | Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId=" |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7122 | + subscriberId + " to " + number); |
| 7123 | } |
| 7124 | |
| 7125 | if (TextUtils.isEmpty(iccId)) { |
| 7126 | return false; |
| 7127 | } |
| 7128 | |
| 7129 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 7130 | |
| 7131 | final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 7132 | if (alphaTag == null) { |
| 7133 | editor.remove(alphaTagPrefKey); |
| 7134 | } else { |
| 7135 | editor.putString(alphaTagPrefKey, alphaTag); |
| 7136 | } |
| 7137 | |
| 7138 | // Record both the line number and IMSI for this ICCID, since we need to |
| 7139 | // track all merged IMSIs based on line number |
| 7140 | final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 7141 | final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 7142 | if (number == null) { |
| 7143 | editor.remove(numberPrefKey); |
| 7144 | editor.remove(subscriberPrefKey); |
| 7145 | } else { |
| 7146 | editor.putString(numberPrefKey, number); |
| 7147 | editor.putString(subscriberPrefKey, subscriberId); |
| 7148 | } |
| 7149 | |
| 7150 | editor.commit(); |
| 7151 | return true; |
| 7152 | } finally { |
| 7153 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 7154 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7155 | } |
| 7156 | |
| 7157 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7158 | public String getLine1NumberForDisplay(int subId, String callingPackage, |
| 7159 | String callingFeatureId) { |
Makoto Onuki | fee6934 | 2015-06-29 14:44:50 -0700 | [diff] [blame] | 7160 | // This is open to apps with WRITE_SMS. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7161 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7162 | mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) { |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 7163 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission"); |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 7164 | return null; |
| 7165 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7166 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7167 | final long identity = Binder.clearCallingIdentity(); |
| 7168 | try { |
| 7169 | String iccId = getIccId(subId); |
| 7170 | if (iccId != null) { |
| 7171 | String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 7172 | if (DBG_MERGE) { |
| 7173 | log("getLine1NumberForDisplay returning " |
| 7174 | + mTelephonySharedPreferences.getString(numberPrefKey, null)); |
| 7175 | } |
| 7176 | return mTelephonySharedPreferences.getString(numberPrefKey, null); |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 7177 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7178 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null"); |
| 7179 | return null; |
| 7180 | } finally { |
| 7181 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7182 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7183 | } |
| 7184 | |
| 7185 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7186 | public String getLine1AlphaTagForDisplay(int subId, String callingPackage, |
| 7187 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7188 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7189 | mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 7190 | return null; |
| 7191 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7192 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7193 | final long identity = Binder.clearCallingIdentity(); |
| 7194 | try { |
| 7195 | String iccId = getIccId(subId); |
| 7196 | if (iccId != null) { |
| 7197 | String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 7198 | return mTelephonySharedPreferences.getString(alphaTagPrefKey, null); |
| 7199 | } |
| 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 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 7205 | |
| 7206 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7207 | public String[] getMergedSubscriberIds(int subId, String callingPackage, |
| 7208 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7209 | // This API isn't public, so no need to provide a valid subscription ID - we're not worried |
| 7210 | // about carrier-privileged callers not having access. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7211 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7212 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7213 | callingFeatureId, "getMergedSubscriberIds")) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7214 | return null; |
| 7215 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7216 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 7217 | // Clear calling identity, when calling TelephonyManager, because callerUid must be |
| 7218 | // the process, where TelephonyManager was instantiated. |
| 7219 | // Otherwise AppOps check will fail. |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7220 | final long identity = Binder.clearCallingIdentity(); |
| 7221 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7222 | final Context context = mApp; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7223 | final TelephonyManager tele = TelephonyManager.from(context); |
| 7224 | final SubscriptionManager sub = SubscriptionManager.from(context); |
| 7225 | |
| 7226 | // Figure out what subscribers are currently active |
| 7227 | final ArraySet<String> activeSubscriberIds = new ArraySet<>(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7228 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 7229 | // Only consider subs which match the current subId |
| 7230 | // This logic can be simplified. See b/131189269 for progress. |
| 7231 | if (isActiveSubscription(subId)) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7232 | activeSubscriberIds.add(tele.getSubscriberId(subId)); |
| 7233 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7234 | |
| 7235 | // First pass, find a number override for an active subscriber |
| 7236 | String mergeNumber = null; |
| 7237 | final Map<String, ?> prefs = mTelephonySharedPreferences.getAll(); |
| 7238 | for (String key : prefs.keySet()) { |
| 7239 | if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) { |
| 7240 | final String subscriberId = (String) prefs.get(key); |
| 7241 | if (activeSubscriberIds.contains(subscriberId)) { |
| 7242 | final String iccId = key.substring( |
| 7243 | PREF_CARRIERS_SUBSCRIBER_PREFIX.length()); |
| 7244 | final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 7245 | mergeNumber = (String) prefs.get(numberKey); |
| 7246 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 7247 | Rlog.d(LOG_TAG, "Found line number " + mergeNumber |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7248 | + " for active subscriber " + subscriberId); |
| 7249 | } |
| 7250 | if (!TextUtils.isEmpty(mergeNumber)) { |
| 7251 | break; |
| 7252 | } |
| 7253 | } |
| 7254 | } |
| 7255 | } |
| 7256 | |
| 7257 | // Shortcut when no active merged subscribers |
| 7258 | if (TextUtils.isEmpty(mergeNumber)) { |
| 7259 | return null; |
| 7260 | } |
| 7261 | |
| 7262 | // Second pass, find all subscribers under that line override |
| 7263 | final ArraySet<String> result = new ArraySet<>(); |
| 7264 | for (String key : prefs.keySet()) { |
| 7265 | if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) { |
| 7266 | final String number = (String) prefs.get(key); |
| 7267 | if (mergeNumber.equals(number)) { |
| 7268 | final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length()); |
| 7269 | final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 7270 | final String subscriberId = (String) prefs.get(subscriberKey); |
| 7271 | if (!TextUtils.isEmpty(subscriberId)) { |
| 7272 | result.add(subscriberId); |
| 7273 | } |
| 7274 | } |
| 7275 | } |
| 7276 | } |
| 7277 | |
| 7278 | final String[] resultArray = result.toArray(new String[result.size()]); |
| 7279 | Arrays.sort(resultArray); |
| 7280 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 7281 | Rlog.d(LOG_TAG, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7282 | "Found subscribers " + Arrays.toString(resultArray) + " after merge"); |
| 7283 | } |
| 7284 | return resultArray; |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7285 | } finally { |
| 7286 | Binder.restoreCallingIdentity(identity); |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7287 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7288 | } |
| 7289 | |
| 7290 | @Override |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 7291 | public String[] getMergedImsisFromGroup(int subId, String callingPackage) { |
| 7292 | enforceReadPrivilegedPermission("getMergedImsisFromGroup"); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7293 | |
| 7294 | final long identity = Binder.clearCallingIdentity(); |
| 7295 | try { |
| 7296 | final TelephonyManager telephonyManager = mApp.getSystemService( |
| 7297 | TelephonyManager.class); |
| 7298 | String subscriberId = telephonyManager.getSubscriberId(subId); |
| 7299 | if (subscriberId == null) { |
| 7300 | if (DBG) { |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 7301 | log("getMergedImsisFromGroup can't find subscriberId for subId " |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7302 | + subId); |
| 7303 | } |
| 7304 | return null; |
| 7305 | } |
| 7306 | |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 7307 | ParcelUuid groupUuid; |
| 7308 | if (PhoneFactory.isSubscriptionManagerServiceEnabled()) { |
| 7309 | final SubscriptionInfo info = SubscriptionManagerService.getInstance() |
| 7310 | .getSubscriptionInfo(subId); |
| 7311 | groupUuid = info.getGroupUuid(); |
| 7312 | } else { |
| 7313 | final SubscriptionInfo info = mSubscriptionController |
| 7314 | .getSubscriptionInfo(subId); |
| 7315 | groupUuid = info.getGroupUuid(); |
| 7316 | } |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7317 | // If it doesn't belong to any group, return just subscriberId of itself. |
| 7318 | if (groupUuid == null) { |
| 7319 | return new String[]{subscriberId}; |
| 7320 | } |
| 7321 | |
| 7322 | // Get all subscriberIds from the group. |
| 7323 | final List<String> mergedSubscriberIds = new ArrayList<>(); |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 7324 | List<SubscriptionInfo> groupInfos; |
| 7325 | if (PhoneFactory.isSubscriptionManagerServiceEnabled()) { |
| 7326 | groupInfos = SubscriptionManagerService.getInstance() |
| 7327 | .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(), |
| 7328 | mApp.getAttributionTag()); |
| 7329 | } else { |
| 7330 | groupInfos = mSubscriptionController |
| 7331 | .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(), |
| 7332 | mApp.getAttributionTag()); |
| 7333 | } |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7334 | for (SubscriptionInfo subInfo : groupInfos) { |
| 7335 | subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId()); |
| 7336 | if (subscriberId != null) { |
| 7337 | mergedSubscriberIds.add(subscriberId); |
| 7338 | } |
| 7339 | } |
| 7340 | |
| 7341 | return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]); |
| 7342 | } finally { |
| 7343 | Binder.restoreCallingIdentity(identity); |
| 7344 | |
| 7345 | } |
| 7346 | } |
| 7347 | |
| 7348 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7349 | public boolean setOperatorBrandOverride(int subId, String brand) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 7350 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7351 | subId, "setOperatorBrandOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7352 | |
| 7353 | final long identity = Binder.clearCallingIdentity(); |
| 7354 | try { |
| 7355 | final Phone phone = getPhone(subId); |
| 7356 | return phone == null ? false : phone.setOperatorBrandOverride(brand); |
| 7357 | } finally { |
| 7358 | Binder.restoreCallingIdentity(identity); |
| 7359 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 7360 | } |
Steven Liu | 4bf01bc | 2014-07-17 11:05:29 -0500 | [diff] [blame] | 7361 | |
| 7362 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7363 | public boolean setRoamingOverride(int subId, List<String> gsmRoamingList, |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 7364 | List<String> gsmNonRoamingList, List<String> cdmaRoamingList, |
| 7365 | List<String> cdmaNonRoamingList) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 7366 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 7367 | mApp, subId, "setRoamingOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7368 | |
| 7369 | final long identity = Binder.clearCallingIdentity(); |
| 7370 | try { |
| 7371 | final Phone phone = getPhone(subId); |
| 7372 | if (phone == null) { |
| 7373 | return false; |
| 7374 | } |
| 7375 | return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList, |
| 7376 | cdmaNonRoamingList); |
| 7377 | } finally { |
| 7378 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7379 | } |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 7380 | } |
| 7381 | |
| 7382 | @Override |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 7383 | @Deprecated |
| 7384 | public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) { |
| 7385 | enforceModifyPermission(); |
| 7386 | |
| 7387 | int returnValue = 0; |
| 7388 | try { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7389 | AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 7390 | if(result.exception == null) { |
| 7391 | if (result.result != null) { |
| 7392 | byte[] responseData = (byte[])(result.result); |
| 7393 | if(responseData.length > oemResp.length) { |
| 7394 | Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " + |
| 7395 | responseData.length + "bytes. Buffer Size is " + |
| 7396 | oemResp.length + "bytes."); |
| 7397 | } |
| 7398 | System.arraycopy(responseData, 0, oemResp, 0, responseData.length); |
| 7399 | returnValue = responseData.length; |
| 7400 | } |
| 7401 | } else { |
| 7402 | CommandException ex = (CommandException) result.exception; |
| 7403 | returnValue = ex.getCommandError().ordinal(); |
| 7404 | if(returnValue > 0) returnValue *= -1; |
| 7405 | } |
| 7406 | } catch (RuntimeException e) { |
| 7407 | Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception"); |
| 7408 | returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal()); |
| 7409 | if(returnValue > 0) returnValue *= -1; |
| 7410 | } |
| 7411 | |
| 7412 | return returnValue; |
| 7413 | } |
| 7414 | |
| 7415 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 7416 | public int getRadioAccessFamily(int phoneId, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7417 | Phone phone = PhoneFactory.getPhone(phoneId); |
Shuo Qian | dee5340 | 2020-05-29 14:08:15 -0700 | [diff] [blame] | 7418 | try { |
| 7419 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 7420 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Shuo Qian | dee5340 | 2020-05-29 14:08:15 -0700 | [diff] [blame] | 7421 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 7422 | } catch (SecurityException e) { |
| 7423 | EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission"); |
| 7424 | throw e; |
| 7425 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7426 | int raf = RadioAccessFamily.RAF_UNKNOWN; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7427 | if (phone == null) { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7428 | return raf; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7429 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7430 | final long identity = Binder.clearCallingIdentity(); |
| 7431 | try { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7432 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 7433 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7434 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 7435 | raf = ProxyController.getInstance().getRadioAccessFamily(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7436 | } finally { |
| 7437 | Binder.restoreCallingIdentity(identity); |
| 7438 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7439 | return raf; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 7440 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7441 | |
| 7442 | @Override |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7443 | public void uploadCallComposerPicture(int subscriptionId, String callingPackage, |
Hall Liu | e31bac6 | 2020-12-23 19:16:10 -0800 | [diff] [blame] | 7444 | String contentType, ParcelFileDescriptor fd, ResultReceiver callback) { |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7445 | try { |
| 7446 | if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0), |
| 7447 | Binder.getCallingUid())) { |
Tyler Gunn | b87925a | 2021-06-10 14:54:27 -0700 | [diff] [blame] | 7448 | throw new SecurityException("Invalid package:" + callingPackage); |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7449 | } |
| 7450 | } catch (PackageManager.NameNotFoundException e) { |
Tyler Gunn | b87925a | 2021-06-10 14:54:27 -0700 | [diff] [blame] | 7451 | throw new SecurityException("Invalid package:" + callingPackage); |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7452 | } |
| 7453 | RoleManager rm = mApp.getSystemService(RoleManager.class); |
| 7454 | List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER); |
| 7455 | if (!dialerRoleHolders.contains(callingPackage)) { |
| 7456 | throw new SecurityException("App must be the dialer role holder to" |
| 7457 | + " upload a call composer pic"); |
| 7458 | } |
| 7459 | |
| 7460 | Executors.newSingleThreadExecutor().execute(() -> { |
| 7461 | ByteArrayOutputStream output = new ByteArrayOutputStream( |
| 7462 | (int) TelephonyManager.getMaximumCallComposerPictureSize()); |
| 7463 | InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd); |
| 7464 | boolean readUntilEnd = false; |
| 7465 | int totalBytesRead = 0; |
| 7466 | byte[] buffer = new byte[16 * 1024]; |
| 7467 | while (true) { |
| 7468 | int numRead; |
| 7469 | try { |
| 7470 | numRead = input.read(buffer); |
| 7471 | } catch (IOException e) { |
| 7472 | try { |
| 7473 | fd.checkError(); |
| 7474 | callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED, |
| 7475 | null); |
| 7476 | } catch (IOException e1) { |
| 7477 | // This means that the other side closed explicitly with an error. If this |
| 7478 | // happens, log and ignore. |
| 7479 | loge("Remote end of call composer picture pipe closed: " + e1); |
| 7480 | } |
| 7481 | break; |
| 7482 | } |
| 7483 | if (numRead == -1) { |
| 7484 | readUntilEnd = true; |
| 7485 | break; |
| 7486 | } |
| 7487 | totalBytesRead += numRead; |
| 7488 | if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) { |
| 7489 | loge("Too many bytes read for call composer picture: " + totalBytesRead); |
| 7490 | try { |
| 7491 | input.close(); |
| 7492 | } catch (IOException e) { |
| 7493 | // ignore |
| 7494 | } |
| 7495 | break; |
| 7496 | } |
| 7497 | output.write(buffer, 0, numRead); |
| 7498 | } |
| 7499 | // Generally, the remote end will close the file descriptors. The only case where we |
| 7500 | // close is above, where the picture size is too big. |
| 7501 | |
| 7502 | try { |
| 7503 | fd.checkError(); |
| 7504 | } catch (IOException e) { |
| 7505 | loge("Remote end for call composer closed with an error: " + e); |
| 7506 | return; |
| 7507 | } |
| 7508 | |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 7509 | if (!readUntilEnd) { |
| 7510 | loge("Did not finish reading entire image; aborting"); |
| 7511 | return; |
| 7512 | } |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7513 | |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 7514 | ImageData imageData = new ImageData(output.toByteArray(), contentType, null); |
| 7515 | CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer( |
| 7516 | new CallComposerPictureTransfer.Factory() {}, |
| 7517 | imageData, |
| 7518 | (result) -> { |
| 7519 | if (result.first != null) { |
| 7520 | ParcelUuid parcelUuid = new ParcelUuid(result.first); |
| 7521 | Bundle outputResult = new Bundle(); |
| 7522 | outputResult.putParcelable( |
| 7523 | TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid); |
| 7524 | callback.send(TelephonyManager.CallComposerException.SUCCESS, |
| 7525 | outputResult); |
| 7526 | } else { |
| 7527 | callback.send(result.second, null); |
| 7528 | } |
| 7529 | } |
| 7530 | ); |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7531 | }); |
| 7532 | } |
| 7533 | |
| 7534 | @Override |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7535 | public void enableVideoCalling(boolean enable) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7536 | final Phone defaultPhone = getDefaultPhone(); |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7537 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7538 | |
| 7539 | final long identity = Binder.clearCallingIdentity(); |
| 7540 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7541 | ImsManager.getInstance(defaultPhone.getContext(), |
| 7542 | defaultPhone.getPhoneId()).setVtSetting(enable); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7543 | } finally { |
| 7544 | Binder.restoreCallingIdentity(identity); |
| 7545 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7546 | } |
| 7547 | |
| 7548 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7549 | public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7550 | final Phone defaultPhone = getDefaultPhone(); |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7551 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 7552 | callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 7553 | return false; |
| 7554 | } |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 7555 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7556 | final long identity = Binder.clearCallingIdentity(); |
| 7557 | try { |
| 7558 | // Check the user preference and the system-level IMS setting. Even if the user has |
| 7559 | // enabled video calling, if IMS is disabled we aren't able to support video calling. |
| 7560 | // In the long run, we may instead need to check if there exists a connection service |
| 7561 | // which can support video calling. |
| 7562 | ImsManager imsManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7563 | ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7564 | return imsManager.isVtEnabledByPlatform() |
| 7565 | && imsManager.isEnhanced4gLteModeSettingEnabledByUser() |
| 7566 | && imsManager.isVtEnabledByUser(); |
| 7567 | } finally { |
| 7568 | Binder.restoreCallingIdentity(identity); |
| 7569 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7570 | } |
Libin.Tang@motorola.com | afe8264 | 2014-12-18 13:27:53 -0600 | [diff] [blame] | 7571 | |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7572 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7573 | public boolean canChangeDtmfToneLength(int subId, String callingPackage, |
| 7574 | String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7575 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7576 | mApp, subId, callingPackage, callingFeatureId, |
| 7577 | "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7578 | return false; |
| 7579 | } |
| 7580 | |
| 7581 | final long identity = Binder.clearCallingIdentity(); |
| 7582 | try { |
| 7583 | CarrierConfigManager configManager = |
| 7584 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7585 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7586 | .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL); |
| 7587 | } finally { |
| 7588 | Binder.restoreCallingIdentity(identity); |
| 7589 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7590 | } |
| 7591 | |
| 7592 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7593 | public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7594 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7595 | mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7596 | return false; |
| 7597 | } |
| 7598 | |
| 7599 | final long identity = Binder.clearCallingIdentity(); |
| 7600 | try { |
| 7601 | CarrierConfigManager configManager = |
| 7602 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7603 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7604 | .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL); |
| 7605 | } finally { |
| 7606 | Binder.restoreCallingIdentity(identity); |
| 7607 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7608 | } |
| 7609 | |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7610 | @Override |
| 7611 | public boolean isTtyModeSupported() { |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 7612 | TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class); |
Wooki Wu | 1f82f7a | 2016-02-15 15:59:58 +0800 | [diff] [blame] | 7613 | return telecomManager.isTtySupported(); |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7614 | } |
| 7615 | |
| 7616 | @Override |
| 7617 | public boolean isHearingAidCompatibilitySupported() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7618 | final long identity = Binder.clearCallingIdentity(); |
| 7619 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7620 | return mApp.getResources().getBoolean(R.bool.hac_enabled); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7621 | } finally { |
| 7622 | Binder.restoreCallingIdentity(identity); |
| 7623 | } |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7624 | } |
| 7625 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 7626 | /** |
| 7627 | * Determines whether the device currently supports RTT (Real-time text). Based both on carrier |
| 7628 | * support for the feature and device firmware support. |
| 7629 | * |
| 7630 | * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise. |
| 7631 | */ |
| 7632 | @Override |
| 7633 | public boolean isRttSupported(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7634 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7635 | final Phone phone = getPhone(subscriptionId); |
| 7636 | if (phone == null) { |
| 7637 | loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId); |
| 7638 | return false; |
| 7639 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7640 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7641 | boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7642 | CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL); |
| 7643 | boolean isDeviceSupported = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7644 | phone.getContext().getResources().getBoolean(R.bool.config_support_rtt); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7645 | return isCarrierSupported && isDeviceSupported; |
| 7646 | } finally { |
| 7647 | Binder.restoreCallingIdentity(identity); |
| 7648 | } |
Hall Liu | 9818758 | 2018-01-22 19:15:32 -0800 | [diff] [blame] | 7649 | } |
| 7650 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 7651 | /** |
Hall Liu | f2daa02 | 2019-07-23 18:39:00 -0700 | [diff] [blame] | 7652 | * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set |
| 7653 | * RTT setting, will return true if the device and carrier both support RTT. |
| 7654 | * 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] | 7655 | */ |
| 7656 | public boolean isRttEnabled(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7657 | final long identity = Binder.clearCallingIdentity(); |
| 7658 | try { |
Hall Liu | 5bab75c | 2019-12-11 23:58:20 +0000 | [diff] [blame] | 7659 | boolean isRttSupported = isRttSupported(subscriptionId); |
| 7660 | boolean isUserRttSettingOn = Settings.Secure.getInt( |
| 7661 | mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0; |
| 7662 | boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId) |
| 7663 | .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL); |
| 7664 | return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7665 | } finally { |
| 7666 | Binder.restoreCallingIdentity(identity); |
| 7667 | } |
Hall Liu | 3ad5f01 | 2018-04-06 16:23:39 -0700 | [diff] [blame] | 7668 | } |
| 7669 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7670 | @Deprecated |
| 7671 | @Override |
| 7672 | public String getDeviceId(String callingPackage) { |
| 7673 | return getDeviceIdWithFeature(callingPackage, null); |
| 7674 | } |
| 7675 | |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7676 | /** |
| 7677 | * Returns the unique device ID of phone, for example, the IMEI for |
| 7678 | * GSM and the MEID for CDMA phones. Return null if device ID is not available. |
| 7679 | * |
| 7680 | * <p>Requires Permission: |
| 7681 | * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} |
| 7682 | */ |
| 7683 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7684 | public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) { |
Shuo Qian | 13d8915 | 2021-05-10 23:58:11 -0700 | [diff] [blame] | 7685 | try { |
| 7686 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 7687 | } catch (SecurityException se) { |
| 7688 | EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid()); |
| 7689 | throw new SecurityException("Package " + callingPackage + " does not belong to " |
| 7690 | + Binder.getCallingUid()); |
| 7691 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7692 | final Phone phone = PhoneFactory.getPhone(0); |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7693 | if (phone == null) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7694 | return null; |
| 7695 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7696 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 7697 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7698 | callingPackage, callingFeatureId, "getDeviceId")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7699 | return null; |
| 7700 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7701 | |
| 7702 | final long identity = Binder.clearCallingIdentity(); |
| 7703 | try { |
| 7704 | return phone.getDeviceId(); |
| 7705 | } finally { |
| 7706 | Binder.restoreCallingIdentity(identity); |
| 7707 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7708 | } |
| 7709 | |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 7710 | /** |
| 7711 | * {@hide} |
| 7712 | * Returns the IMS Registration Status on a particular subid |
| 7713 | * |
| 7714 | * @param subId |
| 7715 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7716 | public boolean isImsRegistered(int subId) { |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 7717 | Phone phone = getPhone(subId); |
| 7718 | if (phone != null) { |
| 7719 | return phone.isImsRegistered(); |
| 7720 | } else { |
| 7721 | return false; |
| 7722 | } |
| 7723 | } |
| 7724 | |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 7725 | @Override |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7726 | public int getSubIdForPhoneAccountHandle( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7727 | PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) { |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7728 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(), |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7729 | callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) { |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7730 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 7731 | } |
| 7732 | final long identity = Binder.clearCallingIdentity(); |
| 7733 | try { |
| 7734 | return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle); |
| 7735 | } finally { |
| 7736 | Binder.restoreCallingIdentity(identity); |
| 7737 | } |
| 7738 | } |
| 7739 | |
| 7740 | @Override |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 7741 | public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) { |
Alireza Forouzan | 4ac4f98 | 2021-03-16 22:18:52 -0700 | [diff] [blame] | 7742 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 7743 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Alireza Forouzan | 4ac4f98 | 2021-03-16 22:18:52 -0700 | [diff] [blame] | 7744 | mApp, |
| 7745 | subscriptionId, |
| 7746 | "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: " + subscriptionId); |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 7747 | final long identity = Binder.clearCallingIdentity(); |
| 7748 | try { |
| 7749 | Phone phone = getPhone(subscriptionId); |
| 7750 | if (phone == null) { |
| 7751 | return null; |
| 7752 | } |
| 7753 | return PhoneUtils.makePstnPhoneAccountHandle(phone); |
| 7754 | } finally { |
| 7755 | Binder.restoreCallingIdentity(identity); |
| 7756 | } |
| 7757 | } |
| 7758 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7759 | /** |
| 7760 | * @return the VoWiFi calling availability. |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 7761 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7762 | public boolean isWifiCallingAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7763 | final long identity = Binder.clearCallingIdentity(); |
| 7764 | try { |
| 7765 | Phone phone = getPhone(subId); |
| 7766 | if (phone != null) { |
| 7767 | return phone.isWifiCallingEnabled(); |
| 7768 | } else { |
| 7769 | return false; |
| 7770 | } |
| 7771 | } finally { |
| 7772 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7773 | } |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 7774 | } |
| 7775 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7776 | /** |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7777 | * @return the VT calling availability. |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 7778 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7779 | public boolean isVideoTelephonyAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7780 | final long identity = Binder.clearCallingIdentity(); |
| 7781 | try { |
| 7782 | Phone phone = getPhone(subId); |
| 7783 | if (phone != null) { |
| 7784 | return phone.isVideoEnabled(); |
| 7785 | } else { |
| 7786 | return false; |
| 7787 | } |
| 7788 | } finally { |
| 7789 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7790 | } |
| 7791 | } |
| 7792 | |
| 7793 | /** |
| 7794 | * @return the IMS registration technology for the MMTEL feature. Valid return values are |
| 7795 | * defined in {@link ImsRegistrationImplBase}. |
| 7796 | */ |
| 7797 | public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7798 | final long identity = Binder.clearCallingIdentity(); |
| 7799 | try { |
| 7800 | Phone phone = getPhone(subId); |
| 7801 | if (phone != null) { |
| 7802 | return phone.getImsRegistrationTech(); |
| 7803 | } else { |
| 7804 | return ImsRegistrationImplBase.REGISTRATION_TECH_NONE; |
| 7805 | } |
| 7806 | } finally { |
| 7807 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7808 | } |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 7809 | } |
| 7810 | |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 7811 | @Override |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 7812 | public void factoryReset(int subId, String callingPackage) { |
paulhu | 5a77360 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 7813 | enforceSettingsPermission(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 7814 | if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) { |
| 7815 | return; |
| 7816 | } |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 7817 | Phone defaultPhone = getDefaultPhone(); |
| 7818 | if (defaultPhone != null) { |
| 7819 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7820 | mApp, getDefaultPhone().getSubId(), "factoryReset"); |
| 7821 | } |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7822 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7823 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7824 | try { |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 7825 | if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction( |
| 7826 | UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7827 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 7828 | getDefaultDataEnabled(), callingPackage); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7829 | setNetworkSelectionModeAutomatic(subId); |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 7830 | Phone phone = getPhone(subId); |
SongFerngWang | fd89b10 | 2021-05-27 22:44:54 +0800 | [diff] [blame] | 7831 | cleanUpAllowedNetworkTypes(phone, subId); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7832 | setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId)); |
Jordan Liu | 857e73a | 2021-03-05 16:24:04 -0800 | [diff] [blame] | 7833 | getPhone(subId).resetCarrierKeysForImsiEncryption(); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7834 | } |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 7835 | // There has been issues when Sms raw table somehow stores orphan |
| 7836 | // fragments. They lead to garbled message when new fragments come |
| 7837 | // in and combined with those stale ones. In case this happens again, |
| 7838 | // user can reset all network settings which will clean up this table. |
| 7839 | cleanUpSmsRawTable(getDefaultPhone().getContext()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 7840 | // Clean up IMS settings as well here. |
| 7841 | int slotId = getSlotIndex(subId); |
| 7842 | if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 7843 | ImsManager.getInstance(mApp, slotId).factoryReset(); |
| 7844 | } |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 7845 | |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 7846 | if (defaultPhone == null) { |
| 7847 | return; |
| 7848 | } |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 7849 | // Erase modem config if erase modem on network setting is enabled. |
| 7850 | String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY, |
| 7851 | RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED); |
| 7852 | if (configValue != null && Boolean.parseBoolean(configValue)) { |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 7853 | sendEraseModemConfig(defaultPhone); |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 7854 | } |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 7855 | |
| 7856 | sendEraseDataInSharedPreferences(defaultPhone); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7857 | } finally { |
| 7858 | Binder.restoreCallingIdentity(identity); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 7859 | } |
| 7860 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7861 | |
SongFerngWang | fd89b10 | 2021-05-27 22:44:54 +0800 | [diff] [blame] | 7862 | @VisibleForTesting |
| 7863 | void cleanUpAllowedNetworkTypes(Phone phone, int subId) { |
| 7864 | if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) { |
| 7865 | return; |
| 7866 | } |
| 7867 | long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType( |
| 7868 | RILConstants.PREFERRED_NETWORK_MODE); |
| 7869 | SubscriptionManager.setSubscriptionProperty(subId, |
| 7870 | SubscriptionManager.ALLOWED_NETWORK_TYPES, |
| 7871 | "user=" + defaultNetworkType); |
| 7872 | phone.loadAllowedNetworksFromSubscriptionDatabase(); |
| 7873 | phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER, |
| 7874 | defaultNetworkType, null); |
| 7875 | } |
| 7876 | |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 7877 | private void cleanUpSmsRawTable(Context context) { |
| 7878 | ContentResolver resolver = context.getContentResolver(); |
| 7879 | Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete"); |
| 7880 | resolver.delete(uri, null, null); |
| 7881 | } |
| 7882 | |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7883 | @Override |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7884 | public String getSimLocaleForSubscriber(int subId) { |
| 7885 | enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId); |
| 7886 | final Phone phone = getPhone(subId); |
| 7887 | if (phone == null) { |
| 7888 | log("getSimLocaleForSubscriber, invalid subId"); |
chen xu | 2bb91e4 | 2019-01-24 14:35:54 -0800 | [diff] [blame] | 7889 | return null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7890 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7891 | final long identity = Binder.clearCallingIdentity(); |
| 7892 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 7893 | SubscriptionInfo info; |
| 7894 | if (PhoneFactory.isSubscriptionManagerServiceEnabled()) { |
| 7895 | info = SubscriptionManagerService.getInstance().getActiveSubscriptionInfo(subId, |
| 7896 | phone.getContext().getOpPackageName(), |
| 7897 | phone.getContext().getAttributionTag()); |
| 7898 | if (info == null) { |
| 7899 | log("getSimLocaleForSubscriber, inactive subId: " + subId); |
| 7900 | return null; |
| 7901 | } |
| 7902 | } else { |
| 7903 | info = mSubscriptionController.getActiveSubscriptionInfo(subId, |
| 7904 | phone.getContext().getOpPackageName(), |
| 7905 | phone.getContext().getAttributionTag()); |
| 7906 | if (info == null) { |
| 7907 | log("getSimLocaleForSubscriber, inactive subId: " + subId); |
| 7908 | return null; |
| 7909 | } |
chen xu | 6291c47 | 2019-02-04 12:55:53 -0800 | [diff] [blame] | 7910 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7911 | // Try and fetch the locale from the carrier properties or from the SIM language |
| 7912 | // preferences (EF-PL and EF-LI)... |
| 7913 | final int mcc = info.getMcc(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7914 | String simLanguage = null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7915 | final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs(); |
| 7916 | if (localeFromDefaultSim != null) { |
| 7917 | if (!localeFromDefaultSim.getCountry().isEmpty()) { |
| 7918 | if (DBG) log("Using locale from subId: " + subId + " locale: " |
| 7919 | + localeFromDefaultSim); |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 7920 | return matchLocaleFromSupportedLocaleList(phone, localeFromDefaultSim); |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7921 | } else { |
| 7922 | simLanguage = localeFromDefaultSim.getLanguage(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7923 | } |
| 7924 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7925 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7926 | // The SIM language preferences only store a language (e.g. fr = French), not an |
| 7927 | // exact locale (e.g. fr_FR = French/France). So, if the locale returned from |
| 7928 | // the SIM and carrier preferences does not include a country we add the country |
| 7929 | // determined from the SIM MCC to provide an exact locale. |
zoey chen | c730df8 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 7930 | final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7931 | if (mccLocale != null) { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7932 | if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale); |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 7933 | return matchLocaleFromSupportedLocaleList(phone, mccLocale); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7934 | } |
| 7935 | |
| 7936 | if (DBG) log("No locale found - returning null"); |
| 7937 | return null; |
| 7938 | } finally { |
| 7939 | Binder.restoreCallingIdentity(identity); |
| 7940 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7941 | } |
| 7942 | |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 7943 | @VisibleForTesting |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 7944 | String matchLocaleFromSupportedLocaleList(Phone phone, @NonNull Locale inputLocale) { |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 7945 | String[] supportedLocale = com.android.internal.app.LocalePicker.getSupportedLocales( |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 7946 | phone.getContext()); |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 7947 | for (String localeTag : supportedLocale) { |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 7948 | if (LocaleList.matchesLanguageAndScript(inputLocale, Locale.forLanguageTag(localeTag)) |
| 7949 | && TextUtils.equals(inputLocale.getCountry(), |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 7950 | Locale.forLanguageTag(localeTag).getCountry())) { |
| 7951 | return localeTag; |
| 7952 | } |
| 7953 | } |
| 7954 | return inputLocale.toLanguageTag(); |
| 7955 | } |
| 7956 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7957 | /** |
| 7958 | * NOTE: this method assumes permission checks are done and caller identity has been cleared. |
| 7959 | */ |
| 7960 | private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 7961 | if (PhoneFactory.isSubscriptionManagerServiceEnabled()) { |
| 7962 | return SubscriptionManagerService.getInstance().getActiveSubscriptionInfoList( |
| 7963 | mApp.getOpPackageName(), mApp.getAttributionTag()); |
| 7964 | } |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7965 | return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(), |
Philip P. Moltmann | 8d34f0c | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7966 | mApp.getAttributionTag()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7967 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7968 | |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 7969 | private ActivityStatsTechSpecificInfo[] mLastModemActivitySpecificInfo = null; |
| 7970 | private ModemActivityInfo mLastModemActivityInfo = null; |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7971 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7972 | /** |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 7973 | * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object |
| 7974 | * representing the state of the modem. |
| 7975 | * |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7976 | * NOTE: The underlying implementation clears the modem state, so there should only ever be one |
| 7977 | * caller to it. Everyone should call this class to get cumulative data. |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 7978 | * @hide |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7979 | */ |
| 7980 | @Override |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 7981 | public void requestModemActivityInfo(ResultReceiver result) { |
| 7982 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7983 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7984 | |
| 7985 | final long identity = Binder.clearCallingIdentity(); |
| 7986 | try { |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 7987 | sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7988 | } finally { |
| 7989 | Binder.restoreCallingIdentity(identity); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7990 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7991 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7992 | |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 7993 | // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be |
| 7994 | // less than total activity duration. |
| 7995 | private boolean isModemActivityInfoValid(ModemActivityInfo info) { |
| 7996 | if (info == null) { |
| 7997 | return false; |
| 7998 | } |
| 7999 | int activityDurationMs = |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 8000 | (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis()); |
| 8001 | int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum(); |
| 8002 | |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 8003 | return (info.isValid() |
| 8004 | && (info.getSleepTimeMillis() <= activityDurationMs) |
| 8005 | && (info.getIdleTimeMillis() <= activityDurationMs) |
Chen Xu | d78231e | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 8006 | && (info.getReceiveTimeMillis() <= activityDurationMs) |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 8007 | && (totalTxTimeMs <= activityDurationMs)); |
| 8008 | } |
| 8009 | |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8010 | private void updateLastModemActivityInfo(ModemActivityInfo info, int rat, int freq) { |
| 8011 | int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()]; |
| 8012 | int[] txTimeMs = info.getTransmitTimeMillis(rat, freq); |
| 8013 | int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat, freq); |
| 8014 | |
| 8015 | for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) { |
| 8016 | mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl]; |
| 8017 | } |
| 8018 | |
| 8019 | mLastModemActivityInfo.setTransmitTimeMillis(rat, freq, mergedTxTimeMs); |
| 8020 | mLastModemActivityInfo.setReceiveTimeMillis( |
| 8021 | rat, |
| 8022 | freq, |
| 8023 | info.getReceiveTimeMillis(rat, freq) |
| 8024 | + mLastModemActivityInfo.getReceiveTimeMillis(rat, freq)); |
| 8025 | } |
| 8026 | |
| 8027 | private void updateLastModemActivityInfo(ModemActivityInfo info, int rat) { |
| 8028 | int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()]; |
| 8029 | int[] txTimeMs = info.getTransmitTimeMillis(rat); |
| 8030 | int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat); |
| 8031 | |
| 8032 | for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) { |
| 8033 | mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl]; |
| 8034 | } |
| 8035 | mLastModemActivityInfo.setTransmitTimeMillis(rat, mergedTxTimeMs); |
| 8036 | mLastModemActivityInfo.setReceiveTimeMillis( |
| 8037 | rat, |
| 8038 | info.getReceiveTimeMillis(rat) + mLastModemActivityInfo.getReceiveTimeMillis(rat)); |
| 8039 | } |
| 8040 | |
| 8041 | /** |
| 8042 | * Merge this ModemActivityInfo with mLastModemActivitySpecificInfo |
| 8043 | * @param info recent ModemActivityInfo |
| 8044 | */ |
| 8045 | private void mergeModemActivityInfo(ModemActivityInfo info) { |
| 8046 | List<ActivityStatsTechSpecificInfo> merged = new ArrayList<>(); |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 8047 | ActivityStatsTechSpecificInfo deltaSpecificInfo; |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8048 | boolean matched; |
| 8049 | for (int i = 0; i < info.getSpecificInfoLength(); i++) { |
| 8050 | matched = false; |
| 8051 | int rat = info.getSpecificInfoRat(i); |
| 8052 | int freq = info.getSpecificInfoFrequencyRange(i); |
| 8053 | //Check each ActivityStatsTechSpecificInfo in this ModemActivityInfo for new rat returns |
| 8054 | //Add a new ActivityStatsTechSpecificInfo if is a new rat, and merge with the original |
| 8055 | //if it already exists |
| 8056 | for (int j = 0; j < mLastModemActivitySpecificInfo.length; j++) { |
| 8057 | if (rat == mLastModemActivityInfo.getSpecificInfoRat(j) && !matched) { |
| 8058 | //Merged based on frequency range (MMWAVE vs SUB6) for 5G |
| 8059 | if (rat == AccessNetworkConstants.AccessNetworkType.NGRAN) { |
| 8060 | if (freq == mLastModemActivityInfo.getSpecificInfoFrequencyRange(j)) { |
| 8061 | updateLastModemActivityInfo(info, rat, freq); |
| 8062 | matched = true; |
| 8063 | } |
| 8064 | } else { |
| 8065 | updateLastModemActivityInfo(info, rat); |
| 8066 | matched = true; |
| 8067 | } |
| 8068 | } |
| 8069 | } |
| 8070 | |
| 8071 | if (!matched) { |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 8072 | deltaSpecificInfo = |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8073 | new ActivityStatsTechSpecificInfo( |
| 8074 | rat, |
| 8075 | freq, |
| 8076 | info.getTransmitTimeMillis(rat, freq), |
| 8077 | (int) info.getReceiveTimeMillis(rat, freq)); |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 8078 | merged.addAll(Arrays.asList(deltaSpecificInfo)); |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8079 | } |
| 8080 | } |
| 8081 | merged.addAll(Arrays.asList(mLastModemActivitySpecificInfo)); |
| 8082 | mLastModemActivitySpecificInfo = |
| 8083 | new ActivityStatsTechSpecificInfo[merged.size()]; |
| 8084 | merged.toArray(mLastModemActivitySpecificInfo); |
| 8085 | |
| 8086 | mLastModemActivityInfo.setTimestamp(info.getTimestampMillis()); |
| 8087 | mLastModemActivityInfo.setSleepTimeMillis( |
| 8088 | info.getSleepTimeMillis() |
| 8089 | + mLastModemActivityInfo.getSleepTimeMillis()); |
| 8090 | mLastModemActivityInfo.setIdleTimeMillis( |
| 8091 | info.getIdleTimeMillis() |
| 8092 | + mLastModemActivityInfo.getIdleTimeMillis()); |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 8093 | |
| 8094 | mLastModemActivityInfo = |
| 8095 | new ModemActivityInfo( |
| 8096 | mLastModemActivityInfo.getTimestampMillis(), |
| 8097 | mLastModemActivityInfo.getSleepTimeMillis(), |
| 8098 | mLastModemActivityInfo.getIdleTimeMillis(), |
| 8099 | mLastModemActivitySpecificInfo); |
| 8100 | } |
| 8101 | |
| 8102 | private ActivityStatsTechSpecificInfo[] deepCopyModemActivitySpecificInfo( |
| 8103 | ActivityStatsTechSpecificInfo[] info) { |
| 8104 | int infoSize = info.length; |
| 8105 | ActivityStatsTechSpecificInfo[] ret = new ActivityStatsTechSpecificInfo[infoSize]; |
| 8106 | for (int i = 0; i < infoSize; i++) { |
| 8107 | ret[i] = new ActivityStatsTechSpecificInfo( |
| 8108 | info[i].getRat(), info[i].getFrequencyRange(), |
| 8109 | info[i].getTransmitTimeMillis(), |
| 8110 | (int) info[i].getReceiveTimeMillis()); |
| 8111 | } |
| 8112 | return ret; |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8113 | } |
| 8114 | |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8115 | /** |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8116 | * Returns the service state information on specified subscription. |
| 8117 | */ |
| 8118 | @Override |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 8119 | public ServiceState getServiceStateForSubscriber(int subId, |
| 8120 | boolean renounceFineLocationAccess, boolean renounceCoarseLocationAccess, |
| 8121 | String callingPackage, String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8122 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8123 | mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) { |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8124 | return null; |
| 8125 | } |
| 8126 | |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 8127 | boolean hasFinePermission = false; |
| 8128 | boolean hasCoarsePermission = false; |
| 8129 | if (!renounceFineLocationAccess) { |
| 8130 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 8131 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 8132 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 8133 | .setCallingPackage(callingPackage) |
| 8134 | .setCallingFeatureId(callingFeatureId) |
| 8135 | .setCallingPid(Binder.getCallingPid()) |
| 8136 | .setCallingUid(Binder.getCallingUid()) |
| 8137 | .setMethod("getServiceStateForSubscriber") |
| 8138 | .setLogAsInfo(true) |
| 8139 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 8140 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 8141 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 8142 | .build()); |
| 8143 | hasFinePermission = |
| 8144 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 8145 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 8146 | |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 8147 | if (!renounceCoarseLocationAccess) { |
| 8148 | LocationAccessPolicy.LocationPermissionResult coarseLocationResult = |
| 8149 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 8150 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 8151 | .setCallingPackage(callingPackage) |
| 8152 | .setCallingFeatureId(callingFeatureId) |
| 8153 | .setCallingPid(Binder.getCallingPid()) |
| 8154 | .setCallingUid(Binder.getCallingUid()) |
| 8155 | .setMethod("getServiceStateForSubscriber") |
| 8156 | .setLogAsInfo(true) |
| 8157 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 8158 | .setMinSdkVersionForFine(Integer.MAX_VALUE) |
| 8159 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 8160 | .build()); |
| 8161 | hasCoarsePermission = |
| 8162 | coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 8163 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 8164 | |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 8165 | final Phone phone = getPhone(subId); |
| 8166 | if (phone == null) { |
| 8167 | return null; |
| 8168 | } |
| 8169 | |
Jordan Liu | 0f2bc44 | 2020-11-18 16:47:37 -0800 | [diff] [blame] | 8170 | final long identity = Binder.clearCallingIdentity(); |
| 8171 | |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 8172 | boolean isCallingPackageDataService = phone.getDataServicePackages() |
| 8173 | .contains(callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8174 | try { |
Jordan Liu | c437b19 | 2020-08-17 10:59:12 -0700 | [diff] [blame] | 8175 | // isActiveSubId requires READ_PHONE_STATE, which we already check for above |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 8176 | if (PhoneFactory.isSubscriptionManagerServiceEnabled()) { |
| 8177 | SubscriptionInfoInternal subInfo = SubscriptionManagerService.getInstance() |
| 8178 | .getSubscriptionInfoInternal(subId); |
| 8179 | if (subInfo == null || !subInfo.isActive()) { |
| 8180 | Rlog.d(LOG_TAG, "getServiceStateForSubscriber returning null for inactive " |
| 8181 | + "subId=" + subId); |
| 8182 | return null; |
| 8183 | } |
| 8184 | } else { |
| 8185 | if (!mSubscriptionController.isActiveSubId(subId, callingPackage, |
| 8186 | callingFeatureId)) { |
| 8187 | Rlog.d(LOG_TAG, "getServiceStateForSubscriber returning null for inactive " |
| 8188 | + "subId=" + subId); |
| 8189 | return null; |
| 8190 | } |
Jordan Liu | c437b19 | 2020-08-17 10:59:12 -0700 | [diff] [blame] | 8191 | } |
| 8192 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 8193 | ServiceState ss = phone.getServiceState(); |
| 8194 | |
| 8195 | // Scrub out the location info in ServiceState depending on what level of access |
| 8196 | // the caller has. |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 8197 | if (hasFinePermission || isCallingPackageDataService) return ss; |
Malcolm Chen | 5052de6 | 2019-12-30 13:56:38 -0800 | [diff] [blame] | 8198 | if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false); |
| 8199 | return ss.createLocationInfoSanitizedCopy(true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8200 | } finally { |
| 8201 | Binder.restoreCallingIdentity(identity); |
| 8202 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8203 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8204 | |
| 8205 | /** |
| 8206 | * Returns the URI for the per-account voicemail ringtone set in Phone settings. |
| 8207 | * |
| 8208 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 8209 | * voicemail ringtone. |
| 8210 | * @return The URI for the ringtone to play when receiving a voicemail from a specific |
| 8211 | * PhoneAccount. |
| 8212 | */ |
| 8213 | @Override |
| 8214 | public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8215 | final long identity = Binder.clearCallingIdentity(); |
| 8216 | try { |
| 8217 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 8218 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8219 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8220 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8221 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8222 | return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext()); |
| 8223 | } finally { |
| 8224 | Binder.restoreCallingIdentity(identity); |
| 8225 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8226 | } |
| 8227 | |
| 8228 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8229 | * Sets the per-account voicemail ringtone. |
| 8230 | * |
| 8231 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 8232 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 8233 | * |
| 8234 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 8235 | * voicemail ringtone. |
| 8236 | * @param uri The URI for the ringtone to play when receiving a voicemail from a specific |
| 8237 | * PhoneAccount. |
| 8238 | */ |
| 8239 | @Override |
| 8240 | public void setVoicemailRingtoneUri(String callingPackage, |
| 8241 | PhoneAccountHandle phoneAccountHandle, Uri uri) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8242 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8243 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 8244 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 8245 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8246 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8247 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 8248 | "setVoicemailRingtoneUri"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8249 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8250 | |
| 8251 | final long identity = Binder.clearCallingIdentity(); |
| 8252 | try { |
| 8253 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 8254 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8255 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8256 | } |
| 8257 | VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri); |
| 8258 | } finally { |
| 8259 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8260 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8261 | } |
| 8262 | |
| 8263 | /** |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8264 | * Returns whether vibration is set for voicemail notification in Phone settings. |
| 8265 | * |
| 8266 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 8267 | * voicemail vibration setting. |
| 8268 | * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise. |
| 8269 | */ |
| 8270 | @Override |
| 8271 | public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8272 | final long identity = Binder.clearCallingIdentity(); |
| 8273 | try { |
| 8274 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 8275 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8276 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8277 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8278 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8279 | return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext()); |
| 8280 | } finally { |
| 8281 | Binder.restoreCallingIdentity(identity); |
| 8282 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8283 | } |
| 8284 | |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8285 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8286 | * Sets the per-account voicemail vibration. |
| 8287 | * |
| 8288 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 8289 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 8290 | * |
| 8291 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 8292 | * voicemail vibration setting. |
| 8293 | * @param enabled Whether to enable or disable vibration for voicemail notifications from a |
| 8294 | * specific PhoneAccount. |
| 8295 | */ |
| 8296 | @Override |
| 8297 | public void setVoicemailVibrationEnabled(String callingPackage, |
| 8298 | PhoneAccountHandle phoneAccountHandle, boolean enabled) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8299 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8300 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 8301 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 8302 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8303 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8304 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 8305 | "setVoicemailVibrationEnabled"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8306 | } |
| 8307 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8308 | final long identity = Binder.clearCallingIdentity(); |
| 8309 | try { |
| 8310 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 8311 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8312 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8313 | } |
| 8314 | VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled); |
| 8315 | } finally { |
| 8316 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8317 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8318 | } |
| 8319 | |
| 8320 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8321 | * Make sure either called from same process as self (phone) or IPC caller has read privilege. |
| 8322 | * |
| 8323 | * @throws SecurityException if the caller does not have the required permission |
| 8324 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8325 | private void enforceReadPrivilegedPermission(String message) { |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8326 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8327 | message); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8328 | } |
| 8329 | |
| 8330 | /** |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 8331 | * Make sure either called from same process as self (phone) or IPC caller has send SMS |
| 8332 | * permission. |
| 8333 | * |
| 8334 | * @throws SecurityException if the caller does not have the required permission |
| 8335 | */ |
| 8336 | private void enforceSendSmsPermission() { |
| 8337 | mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null); |
| 8338 | } |
| 8339 | |
| 8340 | /** |
Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame] | 8341 | * Make sure either called from same process as self (phone) or IPC caller has interact across |
| 8342 | * users permission. |
| 8343 | * |
| 8344 | * @throws SecurityException if the caller does not have the required permission |
| 8345 | */ |
| 8346 | private void enforceInteractAcrossUsersPermission(String message) { |
| 8347 | mApp.enforceCallingOrSelfPermission(permission.INTERACT_ACROSS_USERS, message); |
| 8348 | } |
| 8349 | |
| 8350 | /** |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 8351 | * Make sure called from the package in charge of visual voicemail. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 8352 | * |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 8353 | * @throws SecurityException if the caller is not the visual voicemail package. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 8354 | */ |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 8355 | private void enforceVisualVoicemailPackage(String callingPackage, int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8356 | final long identity = Binder.clearCallingIdentity(); |
| 8357 | try { |
| 8358 | ComponentName componentName = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8359 | RemoteVvmTaskManager.getRemotePackage(mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8360 | if (componentName == null) { |
| 8361 | throw new SecurityException( |
| 8362 | "Caller not current active visual voicemail package[null]"); |
| 8363 | } |
| 8364 | String vvmPackage = componentName.getPackageName(); |
| 8365 | if (!callingPackage.equals(vvmPackage)) { |
Hui Wang | 7f65755 | 2022-08-16 16:58:25 +0000 | [diff] [blame] | 8366 | throw new SecurityException("Caller not current active visual voicemail package"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8367 | } |
| 8368 | } finally { |
| 8369 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 8370 | } |
| 8371 | } |
| 8372 | |
| 8373 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8374 | * Return the application ID for the app type. |
| 8375 | * |
| 8376 | * @param subId the subscription ID that this request applies to. |
| 8377 | * @param appType the uicc app type. |
| 8378 | * @return Application ID for specificied app type, or null if no uicc. |
| 8379 | */ |
| 8380 | @Override |
| 8381 | public String getAidForAppType(int subId, int appType) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8382 | enforceReadPrivilegedPermission("getAidForAppType"); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8383 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8384 | |
| 8385 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8386 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8387 | if (phone == null) { |
| 8388 | return null; |
| 8389 | } |
| 8390 | String aid = null; |
| 8391 | try { |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 8392 | aid = UiccController.getInstance().getUiccPort(phone.getPhoneId()) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8393 | .getApplicationByType(appType).getAid(); |
| 8394 | } catch (Exception e) { |
| 8395 | Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e); |
| 8396 | } |
| 8397 | return aid; |
| 8398 | } finally { |
| 8399 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8400 | } |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8401 | } |
| 8402 | |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8403 | /** |
| 8404 | * Return the Electronic Serial Number. |
| 8405 | * |
| 8406 | * @param subId the subscription ID that this request applies to. |
| 8407 | * @return ESN or null if error. |
| 8408 | */ |
| 8409 | @Override |
| 8410 | public String getEsn(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8411 | enforceReadPrivilegedPermission("getEsn"); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8412 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8413 | |
| 8414 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8415 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8416 | if (phone == null) { |
| 8417 | return null; |
| 8418 | } |
| 8419 | String esn = null; |
| 8420 | try { |
| 8421 | esn = phone.getEsn(); |
| 8422 | } catch (Exception e) { |
| 8423 | Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e); |
| 8424 | } |
| 8425 | return esn; |
| 8426 | } finally { |
| 8427 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8428 | } |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8429 | } |
| 8430 | |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 8431 | /** |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8432 | * Return the Preferred Roaming List Version. |
| 8433 | * |
| 8434 | * @param subId the subscription ID that this request applies to. |
| 8435 | * @return PRLVersion or null if error. |
| 8436 | */ |
| 8437 | @Override |
| 8438 | public String getCdmaPrlVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8439 | enforceReadPrivilegedPermission("getCdmaPrlVersion"); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8440 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8441 | |
| 8442 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8443 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8444 | if (phone == null) { |
| 8445 | return null; |
| 8446 | } |
| 8447 | String cdmaPrlVersion = null; |
| 8448 | try { |
| 8449 | cdmaPrlVersion = phone.getCdmaPrlVersion(); |
| 8450 | } catch (Exception e) { |
| 8451 | Log.e(LOG_TAG, "Not getting PRLVersion", e); |
| 8452 | } |
| 8453 | return cdmaPrlVersion; |
| 8454 | } finally { |
| 8455 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8456 | } |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8457 | } |
| 8458 | |
| 8459 | /** |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 8460 | * Get snapshot of Telephony histograms |
| 8461 | * @return List of Telephony histograms |
| 8462 | * @hide |
| 8463 | */ |
| 8464 | @Override |
| 8465 | public List<TelephonyHistogram> getTelephonyHistograms() { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8466 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8467 | mApp, getDefaultSubscription(), "getTelephonyHistograms"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8468 | |
| 8469 | final long identity = Binder.clearCallingIdentity(); |
| 8470 | try { |
| 8471 | return RIL.getTelephonyRILTimingHistograms(); |
| 8472 | } finally { |
| 8473 | Binder.restoreCallingIdentity(identity); |
| 8474 | } |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 8475 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8476 | |
| 8477 | /** |
| 8478 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8479 | * Set the allowed carrier list and the excluded carrier list, indicating the priority between |
| 8480 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8481 | * Require system privileges. In the future we may add this to carrier APIs. |
| 8482 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8483 | * @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] | 8484 | */ |
| 8485 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8486 | @TelephonyManager.SetCarrierRestrictionResult |
| 8487 | public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) { |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8488 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8489 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8490 | |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8491 | if (carrierRestrictionRules == null) { |
| 8492 | throw new NullPointerException("carrier restriction cannot be null"); |
Meng Wang | 9b7c4e9 | 2017-02-17 11:41:27 -0800 | [diff] [blame] | 8493 | } |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8494 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8495 | final long identity = Binder.clearCallingIdentity(); |
| 8496 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8497 | return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8498 | workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8499 | } finally { |
| 8500 | Binder.restoreCallingIdentity(identity); |
| 8501 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8502 | } |
| 8503 | |
| 8504 | /** |
| 8505 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8506 | * Get the allowed carrier list and the excluded carrier list, including the priority between |
| 8507 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8508 | * Require system privileges. In the future we may add this to carrier APIs. |
| 8509 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8510 | * @return {@link android.telephony.CarrierRestrictionRules} |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8511 | */ |
| 8512 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8513 | public CarrierRestrictionRules getAllowedCarriers() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8514 | enforceReadPrivilegedPermission("getAllowedCarriers"); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8515 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8516 | |
| 8517 | final long identity = Binder.clearCallingIdentity(); |
| 8518 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8519 | Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource); |
| 8520 | if (response instanceof CarrierRestrictionRules) { |
| 8521 | return (CarrierRestrictionRules) response; |
| 8522 | } |
| 8523 | // Response is an Exception of some kind, |
| 8524 | // which is signalled to the user as a NULL retval |
| 8525 | return null; |
| 8526 | } catch (Exception e) { |
| 8527 | Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e); |
| 8528 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8529 | } finally { |
| 8530 | Binder.restoreCallingIdentity(identity); |
| 8531 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8532 | } |
| 8533 | |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 8534 | /** |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 8535 | * Action set from carrier signalling broadcast receivers to enable/disable radio |
| 8536 | * @param subId the subscription ID that this action applies to. |
| 8537 | * @param enabled control enable or disable radio. |
| 8538 | * {@hide} |
| 8539 | */ |
| 8540 | @Override |
| 8541 | public void carrierActionSetRadioEnabled(int subId, boolean enabled) { |
| 8542 | enforceModifyPermission(); |
| 8543 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8544 | |
| 8545 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 8546 | if (phone == null) { |
| 8547 | loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId); |
| 8548 | return; |
| 8549 | } |
| 8550 | try { |
| 8551 | phone.carrierActionSetRadioEnabled(enabled); |
| 8552 | } catch (Exception e) { |
| 8553 | Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8554 | } finally { |
| 8555 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 8556 | } |
| 8557 | } |
| 8558 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 8559 | /** |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 8560 | * Enable or disable Voice over NR (VoNR) |
| 8561 | * @param subId the subscription ID that this action applies to. |
| 8562 | * @param enabled enable or disable VoNR. |
| 8563 | * @return operation result. |
| 8564 | */ |
| 8565 | @Override |
| 8566 | public int setVoNrEnabled(int subId, boolean enabled) { |
| 8567 | enforceModifyPermission(); |
| 8568 | final Phone phone = getPhone(subId); |
| 8569 | |
| 8570 | final long identity = Binder.clearCallingIdentity(); |
| 8571 | if (phone == null) { |
| 8572 | loge("setVoNrEnabled fails with no phone object for subId: " + subId); |
| 8573 | return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE; |
| 8574 | } |
| 8575 | |
| 8576 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8577 | try { |
| 8578 | int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId, |
| 8579 | workSource); |
| 8580 | if (DBG) log("setVoNrEnabled result: " + result); |
Gary Jian | 8dd305f | 2021-10-14 16:31:35 +0800 | [diff] [blame] | 8581 | |
| 8582 | if (result == TelephonyManager.ENABLE_VONR_SUCCESS) { |
| 8583 | if (DBG) { |
| 8584 | log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled); |
| 8585 | } |
| 8586 | SubscriptionManager.setSubscriptionProperty( |
| 8587 | subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED, |
| 8588 | (enabled ? "1" : "0")); |
| 8589 | } |
| 8590 | |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 8591 | return result; |
| 8592 | } finally { |
| 8593 | Binder.restoreCallingIdentity(identity); |
| 8594 | } |
| 8595 | } |
| 8596 | |
| 8597 | /** |
| 8598 | * Is voice over NR enabled |
| 8599 | * @return true if VoNR is enabled else false |
| 8600 | */ |
| 8601 | @Override |
| 8602 | public boolean isVoNrEnabled(int subId) { |
| 8603 | enforceReadPrivilegedPermission("isVoNrEnabled"); |
| 8604 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8605 | final long identity = Binder.clearCallingIdentity(); |
| 8606 | try { |
| 8607 | boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED, |
| 8608 | null, subId, workSource); |
| 8609 | if (DBG) log("isVoNrEnabled: " + isEnabled); |
| 8610 | return isEnabled; |
| 8611 | } finally { |
| 8612 | Binder.restoreCallingIdentity(identity); |
| 8613 | } |
| 8614 | } |
| 8615 | |
| 8616 | /** |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 8617 | * Action set from carrier signalling broadcast receivers to start/stop reporting the default |
| 8618 | * network status based on which carrier apps could apply actions accordingly, |
| 8619 | * enable/disable default url handler for example. |
| 8620 | * |
| 8621 | * @param subId the subscription ID that this action applies to. |
| 8622 | * @param report control start/stop reporting the default network status. |
| 8623 | * {@hide} |
| 8624 | */ |
| 8625 | @Override |
| 8626 | public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) { |
| 8627 | enforceModifyPermission(); |
| 8628 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8629 | |
| 8630 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 8631 | if (phone == null) { |
| 8632 | loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId); |
| 8633 | return; |
| 8634 | } |
| 8635 | try { |
| 8636 | phone.carrierActionReportDefaultNetworkStatus(report); |
| 8637 | } catch (Exception e) { |
| 8638 | Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8639 | } finally { |
| 8640 | Binder.restoreCallingIdentity(identity); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 8641 | } |
| 8642 | } |
| 8643 | |
| 8644 | /** |
fionaxu | d962228 | 2017-07-17 17:51:30 -0700 | [diff] [blame] | 8645 | * Action set from carrier signalling broadcast receivers to reset all carrier actions |
| 8646 | * @param subId the subscription ID that this action applies to. |
| 8647 | * {@hide} |
| 8648 | */ |
| 8649 | @Override |
| 8650 | public void carrierActionResetAll(int subId) { |
| 8651 | enforceModifyPermission(); |
| 8652 | final Phone phone = getPhone(subId); |
| 8653 | if (phone == null) { |
| 8654 | loge("carrierAction: ResetAll fails with invalid sibId: " + subId); |
| 8655 | return; |
| 8656 | } |
| 8657 | try { |
| 8658 | phone.carrierActionResetAll(); |
| 8659 | } catch (Exception e) { |
| 8660 | Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e); |
| 8661 | } |
| 8662 | } |
| 8663 | |
| 8664 | /** |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 8665 | * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a |
| 8666 | * bug report is being generated. |
| 8667 | */ |
| 8668 | @Override |
Ta-wei Yen | 99282e0 | 2016-06-21 18:19:35 -0700 | [diff] [blame] | 8669 | protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8670 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 8671 | != PackageManager.PERMISSION_GRANTED) { |
dcashman | 22b950d | 2016-06-27 11:39:02 -0700 | [diff] [blame] | 8672 | writer.println("Permission Denial: can't dump Phone from pid=" |
| 8673 | + Binder.getCallingPid() |
| 8674 | + ", uid=" + Binder.getCallingUid() |
| 8675 | + "without permission " |
| 8676 | + android.Manifest.permission.DUMP); |
| 8677 | return; |
| 8678 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8679 | DumpsysHandler.dump(mApp, fd, writer, args); |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 8680 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 8681 | |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 8682 | @Override |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 8683 | public int handleShellCommand(@NonNull ParcelFileDescriptor in, |
| 8684 | @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err, |
| 8685 | @NonNull String[] args) { |
| 8686 | return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec( |
| 8687 | this, in.getFileDescriptor(), out.getFileDescriptor(), |
| 8688 | err.getFileDescriptor(), args); |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 8689 | } |
| 8690 | |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 8691 | /** |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8692 | * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason} |
Greg Kaiser | 17f4175 | 2020-05-05 16:47:47 +0000 | [diff] [blame] | 8693 | * @param subId Subscription index |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 8694 | * @param reason The reason the data enable change is taking place. |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8695 | * @param enabled True if enabling the data, otherwise disabling. |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 8696 | * @param callingPackage The package that changed the data enabled state. |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8697 | * @hide |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 8698 | */ |
| 8699 | @Override |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 8700 | public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 8701 | boolean enabled, String callingPackage) { |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8702 | if (reason == TelephonyManager.DATA_ENABLED_REASON_USER |
| 8703 | || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 8704 | try { |
| 8705 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 8706 | mApp, subId, "setDataEnabledForReason"); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8707 | } catch (SecurityException se) { |
| 8708 | enforceModifyPermission(); |
| 8709 | } |
| 8710 | } else { |
| 8711 | enforceModifyPermission(); |
| 8712 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8713 | |
| 8714 | final long identity = Binder.clearCallingIdentity(); |
| 8715 | try { |
| 8716 | Phone phone = getPhone(subId); |
| 8717 | if (phone != null) { |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8718 | if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 8719 | phone.carrierActionSetMeteredApnsEnabled(enabled); |
| 8720 | } else { |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 8721 | phone.getDataSettingsManager().setDataEnabled( |
| 8722 | reason, enabled, callingPackage); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8723 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8724 | } |
| 8725 | } finally { |
| 8726 | Binder.restoreCallingIdentity(identity); |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 8727 | } |
| 8728 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8729 | |
| 8730 | /** |
| 8731 | * Get Client request stats |
| 8732 | * @return List of Client Request Stats |
| 8733 | * @hide |
| 8734 | */ |
| 8735 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8736 | public List<ClientRequestStats> getClientRequestStats(String callingPackage, |
| 8737 | String callingFeatureId, int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8738 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8739 | mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) { |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8740 | return null; |
| 8741 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8742 | Phone phone = getPhone(subId); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8743 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8744 | final long identity = Binder.clearCallingIdentity(); |
| 8745 | try { |
| 8746 | if (phone != null) { |
| 8747 | return phone.getClientRequestStats(); |
| 8748 | } |
| 8749 | |
| 8750 | return null; |
| 8751 | } finally { |
| 8752 | Binder.restoreCallingIdentity(identity); |
| 8753 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8754 | } |
| 8755 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 8756 | private WorkSource getWorkSource(int uid) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8757 | String packageName = mApp.getPackageManager().getNameForUid(uid); |
Hunter Knepshield | d03383b | 2022-03-29 22:47:54 +0000 | [diff] [blame] | 8758 | if (uid == Process.ROOT_UID && packageName == null) { |
| 8759 | // Downstream WorkSource attribution inside the RIL requires both a UID and package name |
| 8760 | // to be set for wakelock tracking, otherwise RIL requests fail with a runtime |
| 8761 | // exception. ROOT_UID seems not to have a valid package name returned by |
| 8762 | // PackageManager, so just fake it here to avoid issues when running telephony shell |
| 8763 | // commands that plumb through the RIL as root, like so: |
| 8764 | // $ adb root |
| 8765 | // $ adb shell cmd phone ... |
| 8766 | packageName = "root"; |
| 8767 | } |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 8768 | return new WorkSource(uid, packageName); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8769 | } |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8770 | |
| 8771 | /** |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 8772 | * Set SIM card power state. |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8773 | * |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8774 | * @param slotIndex SIM slot id. |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 8775 | * @param state State of SIM (power down, power up, pass through) |
| 8776 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 8777 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 8778 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8779 | * |
| 8780 | **/ |
| 8781 | @Override |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 8782 | public void setSimPowerStateForSlot(int slotIndex, int state) { |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8783 | enforceModifyPermission(); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8784 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8785 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8786 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8787 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8788 | final long identity = Binder.clearCallingIdentity(); |
| 8789 | try { |
| 8790 | if (phone != null) { |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 8791 | phone.setSimPowerState(state, null, workSource); |
| 8792 | } |
| 8793 | } finally { |
| 8794 | Binder.restoreCallingIdentity(identity); |
| 8795 | } |
| 8796 | } |
| 8797 | |
| 8798 | /** |
| 8799 | * Set SIM card power state. |
| 8800 | * |
| 8801 | * @param slotIndex SIM slot id. |
| 8802 | * @param state State of SIM (power down, power up, pass through) |
| 8803 | * @param callback callback to trigger after success or failure |
| 8804 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 8805 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 8806 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
| 8807 | * |
| 8808 | **/ |
| 8809 | @Override |
| 8810 | public void setSimPowerStateForSlotWithCallback(int slotIndex, int state, |
| 8811 | IIntegerConsumer callback) { |
| 8812 | enforceModifyPermission(); |
| 8813 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8814 | |
| 8815 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8816 | |
| 8817 | final long identity = Binder.clearCallingIdentity(); |
| 8818 | try { |
| 8819 | if (phone != null) { |
| 8820 | Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback); |
| 8821 | sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8822 | } |
| 8823 | } finally { |
| 8824 | Binder.restoreCallingIdentity(identity); |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8825 | } |
| 8826 | } |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8827 | |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 8828 | private boolean isUssdApiAllowed(int subId) { |
| 8829 | CarrierConfigManager configManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8830 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 8831 | if (configManager == null) { |
| 8832 | return false; |
| 8833 | } |
| 8834 | PersistableBundle pb = configManager.getConfigForSubId(subId); |
| 8835 | if (pb == null) { |
| 8836 | return false; |
| 8837 | } |
| 8838 | return pb.getBoolean( |
| 8839 | CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL); |
| 8840 | } |
| 8841 | |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8842 | /** |
| 8843 | * Check if phone is in emergency callback mode |
| 8844 | * @return true if phone is in emergency callback mode |
| 8845 | * @param subId sub id |
| 8846 | */ |
goneil | 9c5f487 | 2017-12-05 14:07:56 -0800 | [diff] [blame] | 8847 | @Override |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8848 | public boolean getEmergencyCallbackMode(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8849 | enforceReadPrivilegedPermission("getEmergencyCallbackMode"); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8850 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8851 | |
| 8852 | final long identity = Binder.clearCallingIdentity(); |
| 8853 | try { |
| 8854 | if (phone != null) { |
| 8855 | return phone.isInEcm(); |
| 8856 | } else { |
| 8857 | return false; |
| 8858 | } |
| 8859 | } finally { |
| 8860 | Binder.restoreCallingIdentity(identity); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8861 | } |
| 8862 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 8863 | |
| 8864 | /** |
| 8865 | * Get the current signal strength information for the given subscription. |
| 8866 | * Because this information is not updated when the device is in a low power state |
| 8867 | * it should not be relied-upon to be current. |
| 8868 | * @param subId Subscription index |
| 8869 | * @return the most recent cached signal strength info from the modem |
| 8870 | */ |
| 8871 | @Override |
| 8872 | public SignalStrength getSignalStrength(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8873 | final long identity = Binder.clearCallingIdentity(); |
| 8874 | try { |
| 8875 | Phone p = getPhone(subId); |
| 8876 | if (p == null) { |
| 8877 | return null; |
| 8878 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 8879 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8880 | return p.getSignalStrength(); |
| 8881 | } finally { |
| 8882 | Binder.restoreCallingIdentity(identity); |
| 8883 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 8884 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8885 | |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8886 | /** |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8887 | * Get the current modem radio state for the given slot. |
| 8888 | * @param slotIndex slot index. |
| 8889 | * @param callingPackage the name of the package making the call. |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8890 | * @param callingFeatureId The feature in the package. |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8891 | * @return the current radio power state from the modem |
| 8892 | */ |
| 8893 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8894 | public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8895 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8896 | if (phone != null) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8897 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(), |
| 8898 | callingPackage, callingFeatureId, "getRadioPowerState")) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8899 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 8900 | } |
| 8901 | |
| 8902 | final long identity = Binder.clearCallingIdentity(); |
| 8903 | try { |
| 8904 | return phone.getRadioPowerState(); |
| 8905 | } finally { |
| 8906 | Binder.restoreCallingIdentity(identity); |
| 8907 | } |
| 8908 | } |
| 8909 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 8910 | } |
| 8911 | |
| 8912 | /** |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8913 | * Checks if data roaming is enabled on the subscription with id {@code subId}. |
| 8914 | * |
| 8915 | * <p>Requires one of the following permissions: |
| 8916 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}, |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 8917 | * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE}, |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8918 | * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier |
| 8919 | * privileges. |
| 8920 | * |
| 8921 | * @param subId subscription id |
| 8922 | * @return {@code true} if data roaming is enabled on this subscription, otherwise return |
| 8923 | * {@code false}. |
| 8924 | */ |
| 8925 | @Override |
| 8926 | public boolean isDataRoamingEnabled(int subId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 8927 | String functionName = "isDataRoamingEnabled"; |
Shuo Qian | 093013d | 2020-08-13 15:42:55 -0700 | [diff] [blame] | 8928 | try { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 8929 | try { |
| 8930 | mApp.enforceCallingOrSelfPermission( |
| 8931 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 8932 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 8933 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 8934 | mApp.enforceCallingOrSelfPermission( |
| 8935 | permission.READ_BASIC_PHONE_STATE, functionName); |
| 8936 | } |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 8937 | } catch (SecurityException e) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 8938 | TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 8939 | mApp, subId, functionName); |
Shuo Qian | 093013d | 2020-08-13 15:42:55 -0700 | [diff] [blame] | 8940 | } |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 8941 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8942 | boolean isEnabled = false; |
| 8943 | final long identity = Binder.clearCallingIdentity(); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8944 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8945 | Phone phone = getPhone(subId); |
| 8946 | isEnabled = phone != null ? phone.getDataRoamingEnabled() : false; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8947 | } finally { |
| 8948 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8949 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8950 | return isEnabled; |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8951 | } |
| 8952 | |
| 8953 | |
| 8954 | /** |
| 8955 | * Enables/Disables the data roaming on the subscription with id {@code subId}. |
| 8956 | * |
| 8957 | * <p> Requires permission: |
| 8958 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier |
| 8959 | * privileges. |
| 8960 | * |
| 8961 | * @param subId subscription id |
| 8962 | * @param isEnabled {@code true} means enable, {@code false} means disable. |
| 8963 | */ |
| 8964 | @Override |
| 8965 | public void setDataRoamingEnabled(int subId, boolean isEnabled) { |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 8966 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8967 | mApp, subId, "setDataRoamingEnabled"); |
| 8968 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8969 | final long identity = Binder.clearCallingIdentity(); |
| 8970 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8971 | Phone phone = getPhone(subId); |
| 8972 | if (phone != null) { |
| 8973 | phone.setDataRoamingEnabled(isEnabled); |
| 8974 | } |
| 8975 | } finally { |
| 8976 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8977 | } |
| 8978 | } |
| 8979 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8980 | @Override |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 8981 | public boolean isManualNetworkSelectionAllowed(int subId) { |
tom hsu | c91afc7 | 2020-01-06 23:46:07 +0800 | [diff] [blame] | 8982 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 8983 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 8984 | mApp, subId, "isManualNetworkSelectionAllowed"); |
| 8985 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 8986 | boolean isAllowed = true; |
| 8987 | final long identity = Binder.clearCallingIdentity(); |
| 8988 | try { |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 8989 | Phone phone = getPhone(subId); |
| 8990 | if (phone != null) { |
| 8991 | isAllowed = phone.isCspPlmnEnabled(); |
| 8992 | } |
| 8993 | } finally { |
| 8994 | Binder.restoreCallingIdentity(identity); |
| 8995 | } |
| 8996 | return isAllowed; |
| 8997 | } |
| 8998 | |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 8999 | private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) { |
| 9000 | UiccProfile profile = port.getUiccProfile(); |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 9001 | if (profile == null) { |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9002 | return false; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9003 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 9004 | Phone phone = PhoneFactory.getPhone(profile.getPhoneId()); |
| 9005 | if (phone == null) { |
| 9006 | return false; |
| 9007 | } |
| 9008 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 9009 | return cpt != null && cpt.getCarrierPrivilegeStatusForPackage(callingPackage) |
| 9010 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9011 | } |
| 9012 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 9013 | @Override |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 9014 | public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) { |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9015 | // Verify that the callingPackage belongs to the calling UID |
Jordan Liu | 4cda455 | 2020-03-23 11:55:07 -0700 | [diff] [blame] | 9016 | mApp.getSystemService(AppOpsManager.class) |
| 9017 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 9018 | |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9019 | boolean hasReadPermission = false; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9020 | boolean isIccIdAccessRestricted = false; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 9021 | try { |
| 9022 | enforceReadPrivilegedPermission("getUiccCardsInfo"); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9023 | hasReadPermission = true; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 9024 | } catch (SecurityException e) { |
| 9025 | // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller |
| 9026 | // has carrier privileges on an active UICC |
Rambo Wang | e7209ce | 2022-02-23 13:41:02 -0800 | [diff] [blame] | 9027 | if (checkCarrierPrivilegesForPackageAnyPhoneWithPermission(callingPackage) |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 9028 | != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9029 | throw new SecurityException("Caller does not have permission."); |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 9030 | } |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 9031 | } |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9032 | // checking compatibility, if calling app's target SDK is T and beyond. |
| 9033 | if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO, |
| 9034 | Binder.getCallingUid())) { |
| 9035 | isIccIdAccessRestricted = true; |
| 9036 | } |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 9037 | final long identity = Binder.clearCallingIdentity(); |
| 9038 | try { |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 9039 | UiccController uiccController = UiccController.getInstance(); |
| 9040 | ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos(); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9041 | if (hasReadPermission) { |
| 9042 | return cardInfos; |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 9043 | } |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9044 | |
| 9045 | // Remove private info if the caller doesn't have access |
| 9046 | ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>(); |
| 9047 | for (UiccCardInfo cardInfo : cardInfos) { |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9048 | //setting the value after compatibility check |
| 9049 | cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9050 | // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo |
| 9051 | // is available |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9052 | UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex()); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9053 | if (card == null) { |
| 9054 | // assume no access if the card is unavailable |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9055 | filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo)); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9056 | continue; |
| 9057 | } |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9058 | Collection<UiccPortInfo> portInfos = cardInfo.getPorts(); |
| 9059 | if (portInfos.isEmpty()) { |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9060 | filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo)); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9061 | continue; |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9062 | } |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9063 | List<UiccPortInfo> uiccPortInfos = new ArrayList<>(); |
| 9064 | for (UiccPortInfo portInfo : portInfos) { |
| 9065 | UiccPort port = uiccController.getUiccPortForSlot( |
| 9066 | cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex()); |
| 9067 | if (port == null) { |
| 9068 | // assume no access if port is null |
| 9069 | uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo)); |
| 9070 | continue; |
| 9071 | } |
| 9072 | if (haveCarrierPrivilegeAccess(port, callingPackage)) { |
| 9073 | uiccPortInfos.add(portInfo); |
| 9074 | } else { |
| 9075 | uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo)); |
| 9076 | } |
| 9077 | } |
| 9078 | filteredInfos.add(new UiccCardInfo( |
| 9079 | cardInfo.isEuicc(), |
| 9080 | cardInfo.getCardId(), |
| 9081 | null, |
| 9082 | cardInfo.getPhysicalSlotIndex(), |
| 9083 | cardInfo.isRemovable(), |
| 9084 | cardInfo.isMultipleEnabledProfilesSupported(), |
| 9085 | uiccPortInfos)); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9086 | } |
| 9087 | return filteredInfos; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 9088 | } finally { |
| 9089 | Binder.restoreCallingIdentity(identity); |
| 9090 | } |
| 9091 | } |
| 9092 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9093 | /** |
| 9094 | * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are |
| 9095 | * generally private and require carrier privileges to view. |
| 9096 | * |
| 9097 | * @hide |
| 9098 | */ |
| 9099 | @NonNull |
| 9100 | public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) { |
| 9101 | List<UiccPortInfo> portinfo = new ArrayList<>(); |
| 9102 | for (UiccPortInfo portinfos : cardInfo.getPorts()) { |
| 9103 | portinfo.add(getUiccPortInfoUnPrivileged(portinfos)); |
| 9104 | } |
| 9105 | return new UiccCardInfo( |
| 9106 | cardInfo.isEuicc(), |
| 9107 | cardInfo.getCardId(), |
| 9108 | null, |
| 9109 | cardInfo.getPhysicalSlotIndex(), |
| 9110 | cardInfo.isRemovable(), |
| 9111 | cardInfo.isMultipleEnabledProfilesSupported(), |
| 9112 | portinfo |
| 9113 | ); |
| 9114 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9115 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9116 | /** |
| 9117 | * @hide |
| 9118 | * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}. |
| 9119 | * These values are generally private and require carrier privileges to view. |
| 9120 | */ |
| 9121 | @NonNull |
| 9122 | public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) { |
| 9123 | return new UiccPortInfo( |
| 9124 | UiccPortInfo.ICCID_REDACTED, |
| 9125 | portInfo.getPortIndex(), |
| 9126 | portInfo.getLogicalSlotIndex(), |
| 9127 | portInfo.isActive() |
| 9128 | ); |
| 9129 | } |
| 9130 | @Override |
| 9131 | public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) { |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9132 | // Verify that the callingPackage belongs to the calling UID |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9133 | mApp.getSystemService(AppOpsManager.class) |
| 9134 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 9135 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9136 | boolean isLogicalSlotAccessRestricted = false; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9137 | |
Aman Gupta | f3c90b3 | 2022-03-17 04:54:16 +0000 | [diff] [blame] | 9138 | // This will make sure caller has the READ_PRIVILEGED_PHONE_STATE. Do not remove this as |
| 9139 | // we are reading iccId which is PII data. |
| 9140 | enforceReadPrivilegedPermission("getUiccSlotsInfo"); |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9141 | |
| 9142 | // checking compatibility, if calling app's target SDK is T and beyond. |
| 9143 | if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO, |
| 9144 | Binder.getCallingUid())) { |
| 9145 | isLogicalSlotAccessRestricted = true; |
| 9146 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9147 | final long identity = Binder.clearCallingIdentity(); |
| 9148 | try { |
| 9149 | UiccSlot[] slots = UiccController.getInstance().getUiccSlots(); |
Muralidhar Reddy | d196bbf | 2022-01-17 17:56:30 +0000 | [diff] [blame] | 9150 | if (slots == null || slots.length == 0) { |
| 9151 | Rlog.i(LOG_TAG, "slots is null or empty."); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9152 | return null; |
| 9153 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9154 | UiccSlotInfo[] infos = new UiccSlotInfo[slots.length]; |
| 9155 | for (int i = 0; i < slots.length; i++) { |
| 9156 | UiccSlot slot = slots[i]; |
| 9157 | if (slot == null) { |
| 9158 | continue; |
| 9159 | } |
| 9160 | |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 9161 | String cardId; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9162 | UiccCard card = slot.getUiccCard(); |
| 9163 | if (card != null) { |
| 9164 | cardId = card.getCardId(); |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 9165 | } else { |
Jordan Liu | 01bd00d | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 9166 | cardId = slot.getEid(); |
| 9167 | if (TextUtils.isEmpty(cardId)) { |
Aman Gupta | f3c90b3 | 2022-03-17 04:54:16 +0000 | [diff] [blame] | 9168 | // If cardId is null, use iccId of default port as cardId. |
| 9169 | cardId = slot.getIccId(TelephonyManager.DEFAULT_PORT_INDEX); |
Jordan Liu | 01bd00d | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 9170 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9171 | } |
| 9172 | |
Jordan Liu | 857451f | 2019-05-09 16:35:35 -0700 | [diff] [blame] | 9173 | if (cardId != null) { |
| 9174 | // if cardId is an ICCID, strip off trailing Fs before exposing to user |
| 9175 | // if cardId is an EID, it's all digits so this is fine |
| 9176 | cardId = IccUtils.stripTrailingFs(cardId); |
| 9177 | } |
| 9178 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9179 | int cardState = 0; |
| 9180 | switch (slot.getCardState()) { |
| 9181 | case CARDSTATE_ABSENT: |
| 9182 | cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT; |
| 9183 | break; |
| 9184 | case CARDSTATE_PRESENT: |
| 9185 | cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT; |
| 9186 | break; |
| 9187 | case CARDSTATE_ERROR: |
| 9188 | cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR; |
| 9189 | break; |
| 9190 | case CARDSTATE_RESTRICTED: |
| 9191 | cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED; |
| 9192 | break; |
| 9193 | default: |
| 9194 | break; |
| 9195 | |
| 9196 | } |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9197 | List<UiccPortInfo> portInfos = new ArrayList<>(); |
| 9198 | int[] portIndexes = slot.getPortList(); |
| 9199 | for (int portIdx : portIndexes) { |
| 9200 | String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx, |
Aman Gupta | f3c90b3 | 2022-03-17 04:54:16 +0000 | [diff] [blame] | 9201 | callingPackage, /* hasReadPermission= */ true)); |
Muralidhar Reddy | fbcff0c | 2022-01-19 13:07:57 +0000 | [diff] [blame] | 9202 | portInfos.add(new UiccPortInfo(iccId, portIdx, |
| 9203 | slot.getPhoneIdFromPortIndex(portIdx), slot.isPortActive(portIdx))); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9204 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9205 | infos[i] = new UiccSlotInfo( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9206 | slot.isEuicc(), |
| 9207 | cardId, |
| 9208 | cardState, |
Jordan Liu | a261958 | 2019-02-14 12:56:40 -0800 | [diff] [blame] | 9209 | slot.isExtendedApduSupported(), |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9210 | slot.isRemovable(), portInfos); |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9211 | //setting the value after compatibility check |
| 9212 | infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9213 | } |
| 9214 | return infos; |
| 9215 | } finally { |
| 9216 | Binder.restoreCallingIdentity(identity); |
Holly Jiuyu Sun | 1d957c5 | 2018-04-04 13:52:42 -0700 | [diff] [blame] | 9217 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9218 | } |
| 9219 | |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9220 | /* Returns null if doesn't have read permission or carrier privilege access. */ |
| 9221 | private String getIccId(UiccSlot slot, int portIndex, String callingPackage, |
| 9222 | boolean hasReadPermission) { |
| 9223 | String iccId = slot.getIccId(portIndex); |
| 9224 | if (hasReadPermission) { // if has read permission |
| 9225 | return iccId; |
| 9226 | } else { |
| 9227 | if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) { |
| 9228 | UiccPort port = slot.getUiccCard().getUiccPort(portIndex); |
| 9229 | // if no read permission, checking carrier privilege access |
| 9230 | if (haveCarrierPrivilegeAccess(port, callingPackage)) { |
| 9231 | return iccId; |
| 9232 | } |
| 9233 | } |
| 9234 | } |
| 9235 | // No read permission or carrier privilege access. |
| 9236 | return UiccPortInfo.ICCID_REDACTED; |
| 9237 | } |
| 9238 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9239 | @Override |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9240 | @Deprecated |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9241 | public boolean switchSlots(int[] physicalSlots) { |
| 9242 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9243 | |
| 9244 | final long identity = Binder.clearCallingIdentity(); |
| 9245 | try { |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9246 | List<UiccSlotMapping> slotMappings = new ArrayList<>(); |
| 9247 | for (int i = 0; i < physicalSlots.length; i++) { |
| 9248 | // Deprecated API, hence MEP is not supported. Adding default portIndex 0. |
| 9249 | slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX, |
| 9250 | physicalSlots[i], i)); |
| 9251 | } |
| 9252 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9253 | } finally { |
| 9254 | Binder.restoreCallingIdentity(identity); |
| 9255 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9256 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 9257 | |
| 9258 | @Override |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9259 | @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 9260 | public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) { |
| 9261 | enforceModifyPermission(); |
| 9262 | |
| 9263 | final long identity = Binder.clearCallingIdentity(); |
| 9264 | try { |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9265 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping); |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9266 | } finally { |
| 9267 | Binder.restoreCallingIdentity(identity); |
| 9268 | } |
| 9269 | } |
| 9270 | |
| 9271 | @Override |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 9272 | public int getCardIdForDefaultEuicc(int subId, String callingPackage) { |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 9273 | final long identity = Binder.clearCallingIdentity(); |
| 9274 | try { |
| 9275 | return UiccController.getInstance().getCardIdForDefaultEuicc(); |
| 9276 | } finally { |
| 9277 | Binder.restoreCallingIdentity(identity); |
| 9278 | } |
| 9279 | } |
| 9280 | |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9281 | /** |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 9282 | * A test API to reload the UICC profile. |
| 9283 | * |
| 9284 | * <p>Requires that the calling app has permission |
| 9285 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 9286 | * @hide |
| 9287 | */ |
| 9288 | @Override |
| 9289 | public void refreshUiccProfile(int subId) { |
| 9290 | enforceModifyPermission(); |
| 9291 | |
| 9292 | final long identity = Binder.clearCallingIdentity(); |
| 9293 | try { |
| 9294 | Phone phone = getPhone(subId); |
| 9295 | if (phone == null) { |
| 9296 | return; |
| 9297 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9298 | UiccPort uiccPort = phone.getUiccPort(); |
| 9299 | if (uiccPort == null) { |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 9300 | return; |
| 9301 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9302 | UiccProfile uiccProfile = uiccPort.getUiccProfile(); |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 9303 | if (uiccProfile == null) { |
| 9304 | return; |
| 9305 | } |
| 9306 | uiccProfile.refresh(); |
| 9307 | } finally { |
| 9308 | Binder.restoreCallingIdentity(identity); |
| 9309 | } |
| 9310 | } |
| 9311 | |
| 9312 | /** |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9313 | * Returns false if the mobile data is disabled by default, otherwise return true. |
| 9314 | */ |
| 9315 | private boolean getDefaultDataEnabled() { |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 9316 | return TelephonyProperties.mobile_data().orElse(true); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9317 | } |
| 9318 | |
| 9319 | /** |
| 9320 | * Returns true if the data roaming is enabled by default, i.e the system property |
| 9321 | * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of |
| 9322 | * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true. |
| 9323 | */ |
| 9324 | private boolean getDefaultDataRoamingEnabled(int subId) { |
| 9325 | final CarrierConfigManager configMgr = (CarrierConfigManager) |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9326 | mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Shuo Qian | 1d84a0e | 2020-07-15 12:36:44 -0700 | [diff] [blame] | 9327 | boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9328 | isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean( |
| 9329 | CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL); |
| 9330 | return isDataRoamingEnabled; |
| 9331 | } |
| 9332 | |
| 9333 | /** |
| 9334 | * Returns the default network type for the given {@code subId}, if the default network type is |
| 9335 | * not set, return {@link Phone#PREFERRED_NT_MODE}. |
| 9336 | */ |
| 9337 | private int getDefaultNetworkType(int subId) { |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 9338 | List<Integer> list = TelephonyProperties.default_network(); |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 9339 | int phoneId = SubscriptionManager.getPhoneId(subId); |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 9340 | if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) { |
| 9341 | return list.get(phoneId); |
| 9342 | } |
| 9343 | return Phone.PREFERRED_NT_MODE; |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9344 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9345 | |
| 9346 | @Override |
| 9347 | public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 9348 | gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) { |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9349 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9350 | |
| 9351 | final long identity = Binder.clearCallingIdentity(); |
| 9352 | try { |
| 9353 | final Phone phone = getPhone(subId); |
| 9354 | if (phone == null) { |
| 9355 | loge("setCarrierTestOverride fails with invalid subId: " + subId); |
| 9356 | return; |
| 9357 | } |
Rambo Wang | 9c9ffdd | 2022-01-13 21:51:44 -0800 | [diff] [blame] | 9358 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 9359 | if (cpt != null) { |
| 9360 | cpt.setTestOverrideCarrierPrivilegeRules(carrierPrivilegeRules); |
| 9361 | } |
| 9362 | // 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] | 9363 | phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn, |
| 9364 | carrierPrivilegeRules, apn); |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 9365 | if (carrierPrivilegeRules == null) { |
| 9366 | mCarrierPrivilegeTestOverrideSubIds.remove(subId); |
| 9367 | } else { |
| 9368 | mCarrierPrivilegeTestOverrideSubIds.add(subId); |
| 9369 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9370 | } finally { |
| 9371 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9372 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9373 | } |
| 9374 | |
| 9375 | @Override |
| 9376 | public int getCarrierIdListVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 9377 | enforceReadPrivilegedPermission("getCarrierIdListVersion"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9378 | |
| 9379 | final long identity = Binder.clearCallingIdentity(); |
| 9380 | try { |
| 9381 | final Phone phone = getPhone(subId); |
| 9382 | if (phone == null) { |
| 9383 | loge("getCarrierIdListVersion fails with invalid subId: " + subId); |
| 9384 | return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION; |
| 9385 | } |
| 9386 | return phone.getCarrierIdListVersion(); |
| 9387 | } finally { |
| 9388 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9389 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9390 | } |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 9391 | |
| 9392 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9393 | public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage, |
| 9394 | String callingFeatureId) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 9395 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9396 | mApp, subId, callingPackage, callingFeatureId, |
| 9397 | "getNumberOfModemsWithSimultaneousDataConnections")) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 9398 | return -1; |
| 9399 | } |
| 9400 | |
| 9401 | final long identity = Binder.clearCallingIdentity(); |
| 9402 | try { |
| 9403 | return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections(); |
| 9404 | } finally { |
| 9405 | Binder.restoreCallingIdentity(identity); |
| 9406 | } |
| 9407 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9408 | |
| 9409 | @Override |
| 9410 | public int getCdmaRoamingMode(int subId) { |
zoey chen | 7e6d4e5 | 2019-12-17 18:18:59 +0800 | [diff] [blame] | 9411 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9412 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9413 | mApp, subId, "getCdmaRoamingMode"); |
| 9414 | |
| 9415 | final long identity = Binder.clearCallingIdentity(); |
| 9416 | try { |
| 9417 | return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId); |
| 9418 | } finally { |
| 9419 | Binder.restoreCallingIdentity(identity); |
| 9420 | } |
| 9421 | } |
| 9422 | |
| 9423 | @Override |
| 9424 | public boolean setCdmaRoamingMode(int subId, int mode) { |
| 9425 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9426 | mApp, subId, "setCdmaRoamingMode"); |
| 9427 | |
| 9428 | final long identity = Binder.clearCallingIdentity(); |
| 9429 | try { |
| 9430 | return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId); |
| 9431 | } finally { |
| 9432 | Binder.restoreCallingIdentity(identity); |
| 9433 | } |
| 9434 | } |
| 9435 | |
| 9436 | @Override |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 9437 | public int getCdmaSubscriptionMode(int subId) { |
| 9438 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9439 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 9440 | mApp, subId, "getCdmaSubscriptionMode"); |
| 9441 | |
| 9442 | final long identity = Binder.clearCallingIdentity(); |
| 9443 | try { |
| 9444 | return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId); |
| 9445 | } finally { |
| 9446 | Binder.restoreCallingIdentity(identity); |
| 9447 | } |
| 9448 | } |
| 9449 | |
| 9450 | @Override |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9451 | public boolean setCdmaSubscriptionMode(int subId, int mode) { |
| 9452 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9453 | mApp, subId, "setCdmaSubscriptionMode"); |
| 9454 | |
| 9455 | final long identity = Binder.clearCallingIdentity(); |
| 9456 | try { |
| 9457 | return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId); |
| 9458 | } finally { |
| 9459 | Binder.restoreCallingIdentity(identity); |
| 9460 | } |
| 9461 | } |
Makoto Onuki | da3bf79 | 2018-09-18 16:06:29 -0700 | [diff] [blame] | 9462 | |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 9463 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 9464 | public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9465 | String callingPackage, String callingFeatureId) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9466 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9467 | mApp, getDefaultSubscription(), callingPackage, callingFeatureId, |
| 9468 | "getEmergencyNumberList")) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9469 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 9470 | } |
| 9471 | final long identity = Binder.clearCallingIdentity(); |
| 9472 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 9473 | Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>(); |
| 9474 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9475 | if (phone.getEmergencyNumberTracker() != null |
| 9476 | && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) { |
| 9477 | emergencyNumberListInternal.put( |
| 9478 | phone.getSubId(), |
| 9479 | phone.getEmergencyNumberTracker().getEmergencyNumberList()); |
| 9480 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9481 | } |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 9482 | return emergencyNumberListInternal; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9483 | } finally { |
| 9484 | Binder.restoreCallingIdentity(identity); |
| 9485 | } |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 9486 | } |
| 9487 | |
| 9488 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 9489 | public boolean isEmergencyNumber(String number, boolean exactMatch) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9490 | final Phone defaultPhone = getDefaultPhone(); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9491 | if (!exactMatch) { |
| 9492 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9493 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 9494 | mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)"); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9495 | } |
| 9496 | final long identity = Binder.clearCallingIdentity(); |
| 9497 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 9498 | for (Phone phone: PhoneFactory.getPhones()) { |
Chinmay Dhodapkar | d521bb1 | 2022-08-16 15:49:54 -0700 | [diff] [blame] | 9499 | //Note: we ignore passed in param exactMatch. We can remove it once |
| 9500 | // TelephonyManager#isPotentialEmergencyNumber is removed completely |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 9501 | if (phone.getEmergencyNumberTracker() != null |
Taesu Lee | e050c00 | 2020-10-13 17:19:35 +0900 | [diff] [blame] | 9502 | && phone.getEmergencyNumberTracker() |
Chinmay Dhodapkar | d521bb1 | 2022-08-16 15:49:54 -0700 | [diff] [blame] | 9503 | .isEmergencyNumber(number)) { |
Taesu Lee | e050c00 | 2020-10-13 17:19:35 +0900 | [diff] [blame] | 9504 | return true; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9505 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9506 | } |
| 9507 | return false; |
| 9508 | } finally { |
| 9509 | Binder.restoreCallingIdentity(identity); |
| 9510 | } |
| 9511 | } |
| 9512 | |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 9513 | /** |
Shuo Qian | ccbaf74 | 2021-02-22 18:32:21 -0800 | [diff] [blame] | 9514 | * Start emergency callback mode for GsmCdmaPhone for testing. |
| 9515 | */ |
| 9516 | @Override |
| 9517 | public void startEmergencyCallbackMode() { |
| 9518 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9519 | "startEmergencyCallbackMode"); |
| 9520 | enforceModifyPermission(); |
| 9521 | final long identity = Binder.clearCallingIdentity(); |
| 9522 | try { |
| 9523 | for (Phone phone : PhoneFactory.getPhones()) { |
| 9524 | Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType()); |
| 9525 | if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM) |
| 9526 | || (phone.getPhoneType() == PHONE_TYPE_CDMA))) { |
| 9527 | GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone; |
| 9528 | gsmCdmaPhone.obtainMessage( |
| 9529 | GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget(); |
| 9530 | Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered"); |
| 9531 | } |
| 9532 | } |
| 9533 | } finally { |
| 9534 | Binder.restoreCallingIdentity(identity); |
| 9535 | } |
| 9536 | } |
| 9537 | |
| 9538 | /** |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 9539 | * Update emergency number list for test mode. |
| 9540 | */ |
| 9541 | @Override |
| 9542 | public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) { |
| 9543 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9544 | "updateEmergencyNumberListTestMode"); |
| 9545 | |
| 9546 | final long identity = Binder.clearCallingIdentity(); |
| 9547 | try { |
| 9548 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9549 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9550 | if (tracker != null) { |
| 9551 | tracker.executeEmergencyNumberTestModeCommand(action, num); |
| 9552 | } |
| 9553 | } |
| 9554 | } finally { |
| 9555 | Binder.restoreCallingIdentity(identity); |
| 9556 | } |
| 9557 | } |
| 9558 | |
| 9559 | /** |
| 9560 | * Get the full emergency number list for test mode. |
| 9561 | */ |
| 9562 | @Override |
| 9563 | public List<String> getEmergencyNumberListTestMode() { |
| 9564 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9565 | "getEmergencyNumberListTestMode"); |
| 9566 | |
| 9567 | final long identity = Binder.clearCallingIdentity(); |
| 9568 | try { |
| 9569 | Set<String> emergencyNumbers = new HashSet<>(); |
| 9570 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9571 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9572 | if (tracker != null) { |
| 9573 | for (EmergencyNumber num : tracker.getEmergencyNumberList()) { |
| 9574 | emergencyNumbers.add(num.getNumber()); |
| 9575 | } |
| 9576 | } |
| 9577 | } |
| 9578 | return new ArrayList<>(emergencyNumbers); |
| 9579 | } finally { |
| 9580 | Binder.restoreCallingIdentity(identity); |
| 9581 | } |
| 9582 | } |
| 9583 | |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 9584 | @Override |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 9585 | public int getEmergencyNumberDbVersion(int subId) { |
| 9586 | enforceReadPrivilegedPermission("getEmergencyNumberDbVersion"); |
| 9587 | |
| 9588 | final long identity = Binder.clearCallingIdentity(); |
| 9589 | try { |
| 9590 | final Phone phone = getPhone(subId); |
| 9591 | if (phone == null) { |
| 9592 | loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId); |
| 9593 | return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION; |
| 9594 | } |
| 9595 | return phone.getEmergencyNumberDbVersion(); |
| 9596 | } finally { |
| 9597 | Binder.restoreCallingIdentity(identity); |
| 9598 | } |
| 9599 | } |
| 9600 | |
| 9601 | @Override |
| 9602 | public void notifyOtaEmergencyNumberDbInstalled() { |
| 9603 | enforceModifyPermission(); |
| 9604 | |
| 9605 | final long identity = Binder.clearCallingIdentity(); |
| 9606 | try { |
| 9607 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9608 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9609 | if (tracker != null) { |
| 9610 | tracker.updateOtaEmergencyNumberDatabase(); |
| 9611 | } |
| 9612 | } |
| 9613 | } finally { |
| 9614 | Binder.restoreCallingIdentity(identity); |
| 9615 | } |
| 9616 | } |
| 9617 | |
| 9618 | @Override |
Shuo Qian | c373f11 | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 9619 | public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) { |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 9620 | enforceActiveEmergencySessionPermission(); |
| 9621 | |
| 9622 | final long identity = Binder.clearCallingIdentity(); |
| 9623 | try { |
| 9624 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9625 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9626 | if (tracker != null) { |
Shuo Qian | c373f11 | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 9627 | tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor); |
| 9628 | } |
| 9629 | } |
| 9630 | } finally { |
| 9631 | Binder.restoreCallingIdentity(identity); |
| 9632 | } |
| 9633 | } |
| 9634 | |
| 9635 | @Override |
| 9636 | public void resetOtaEmergencyNumberDbFilePath() { |
| 9637 | enforceActiveEmergencySessionPermission(); |
| 9638 | |
| 9639 | final long identity = Binder.clearCallingIdentity(); |
| 9640 | try { |
| 9641 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9642 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9643 | if (tracker != null) { |
| 9644 | tracker.resetOtaEmergencyNumberDbFilePath(); |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 9645 | } |
| 9646 | } |
| 9647 | } finally { |
| 9648 | Binder.restoreCallingIdentity(identity); |
| 9649 | } |
| 9650 | } |
| 9651 | |
| 9652 | @Override |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 9653 | public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) { |
| 9654 | enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules"); |
| 9655 | Phone phone = getPhone(subId); |
| 9656 | if (phone == null) { |
| 9657 | return null; |
| 9658 | } |
| 9659 | final long identity = Binder.clearCallingIdentity(); |
| 9660 | try { |
| 9661 | UiccProfile profile = UiccController.getInstance() |
| 9662 | .getUiccProfileForPhone(phone.getPhoneId()); |
| 9663 | if (profile != null) { |
| 9664 | return profile.getCertsFromCarrierPrivilegeAccessRules(); |
| 9665 | } |
| 9666 | } finally { |
| 9667 | Binder.restoreCallingIdentity(identity); |
| 9668 | } |
| 9669 | return null; |
| 9670 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 9671 | |
| 9672 | /** |
| 9673 | * Enable or disable a modem stack. |
| 9674 | */ |
| 9675 | @Override |
| 9676 | public boolean enableModemForSlot(int slotIndex, boolean enable) { |
| 9677 | enforceModifyPermission(); |
| 9678 | |
| 9679 | final long identity = Binder.clearCallingIdentity(); |
| 9680 | try { |
| 9681 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 9682 | if (phone == null) { |
| 9683 | return false; |
| 9684 | } else { |
| 9685 | return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null); |
| 9686 | } |
| 9687 | } finally { |
| 9688 | Binder.restoreCallingIdentity(identity); |
| 9689 | } |
| 9690 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9691 | |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 9692 | /** |
| 9693 | * Whether a modem stack is enabled or not. |
| 9694 | */ |
| 9695 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9696 | public boolean isModemEnabledForSlot(int slotIndex, String callingPackage, |
| 9697 | String callingFeatureId) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 9698 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 9699 | if (phone == null) return false; |
| 9700 | |
| 9701 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9702 | mApp, phone.getSubId(), callingPackage, callingFeatureId, |
| 9703 | "isModemEnabledForSlot")) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 9704 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 9705 | } |
| 9706 | |
| 9707 | final long identity = Binder.clearCallingIdentity(); |
| 9708 | try { |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 9709 | try { |
| 9710 | return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId()); |
| 9711 | } catch (NoSuchElementException ex) { |
| 9712 | return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null); |
| 9713 | } |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 9714 | } finally { |
| 9715 | Binder.restoreCallingIdentity(identity); |
| 9716 | } |
| 9717 | } |
| 9718 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9719 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9720 | public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) { |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9721 | enforceModifyPermission(); |
| 9722 | |
| 9723 | final long identity = Binder.clearCallingIdentity(); |
| 9724 | try { |
| 9725 | mTelephonySharedPreferences.edit() |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9726 | .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted) |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9727 | .commit(); |
| 9728 | } finally { |
| 9729 | Binder.restoreCallingIdentity(identity); |
| 9730 | } |
| 9731 | } |
| 9732 | |
| 9733 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9734 | @TelephonyManager.IsMultiSimSupportedResult |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9735 | public int isMultiSimSupported(String callingPackage, String callingFeatureId) { |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 9736 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9737 | getDefaultPhone().getSubId(), callingPackage, callingFeatureId, |
| 9738 | "isMultiSimSupported")) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9739 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 9740 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9741 | |
| 9742 | final long identity = Binder.clearCallingIdentity(); |
| 9743 | try { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9744 | return isMultiSimSupportedInternal(); |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9745 | } finally { |
| 9746 | Binder.restoreCallingIdentity(identity); |
| 9747 | } |
| 9748 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9749 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9750 | @TelephonyManager.IsMultiSimSupportedResult |
| 9751 | private int isMultiSimSupportedInternal() { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9752 | // If the device has less than 2 SIM cards, indicate that multisim is restricted. |
| 9753 | int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length; |
| 9754 | if (numPhysicalSlots < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9755 | loge("isMultiSimSupportedInternal: requires at least 2 cards"); |
| 9756 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9757 | } |
| 9758 | // Check if the hardware supports multisim functionality. If usage of multisim is not |
| 9759 | // supported by the modem, indicate that it is restricted. |
| 9760 | PhoneCapability staticCapability = |
| 9761 | mPhoneConfigurationManager.getStaticPhoneCapability(); |
| 9762 | if (staticCapability == null) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9763 | loge("isMultiSimSupportedInternal: no static configuration available"); |
| 9764 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9765 | } |
SongFerngWang | 8236caa | 2021-01-17 21:51:44 +0800 | [diff] [blame] | 9766 | if (staticCapability.getLogicalModemList().size() < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9767 | loge("isMultiSimSupportedInternal: maximum number of modem is < 2"); |
| 9768 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9769 | } |
| 9770 | // Check if support of multiple SIMs is restricted by carrier |
| 9771 | if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9772 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9773 | } |
| 9774 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9775 | return TelephonyManager.MULTISIM_ALLOWED; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9776 | } |
| 9777 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9778 | /** |
| 9779 | * Switch configs to enable multi-sim or switch back to single-sim |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 9780 | * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE |
| 9781 | * permission, but the other way around is possible with either MODIFY_PHONE_STATE |
| 9782 | * or carrier privileges |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9783 | * @param numOfSims number of active sims we want to switch to |
| 9784 | */ |
| 9785 | @Override |
| 9786 | public void switchMultiSimConfig(int numOfSims) { |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 9787 | if (numOfSims == 1) { |
| 9788 | enforceModifyPermission(); |
| 9789 | } else { |
| 9790 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9791 | mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig"); |
| 9792 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9793 | final long identity = Binder.clearCallingIdentity(); |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9794 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9795 | try { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9796 | //only proceed if multi-sim is not restricted |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9797 | if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9798 | loge("switchMultiSimConfig not possible. It is restricted or not supported."); |
| 9799 | return; |
| 9800 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9801 | mPhoneConfigurationManager.switchMultiSimConfig(numOfSims); |
| 9802 | } finally { |
| 9803 | Binder.restoreCallingIdentity(identity); |
| 9804 | } |
| 9805 | } |
| 9806 | |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 9807 | @Override |
| 9808 | public boolean isApplicationOnUicc(int subId, int appType) { |
| 9809 | enforceReadPrivilegedPermission("isApplicationOnUicc"); |
| 9810 | Phone phone = getPhone(subId); |
| 9811 | if (phone == null) { |
| 9812 | return false; |
| 9813 | } |
| 9814 | final long identity = Binder.clearCallingIdentity(); |
| 9815 | try { |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9816 | UiccPort uiccPort = phone.getUiccPort(); |
| 9817 | if (uiccPort == null) { |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 9818 | return false; |
| 9819 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9820 | UiccProfile uiccProfile = uiccPort.getUiccProfile(); |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 9821 | if (uiccProfile == null) { |
| 9822 | return false; |
| 9823 | } |
| 9824 | if (TelephonyManager.APPTYPE_SIM <= appType |
| 9825 | && appType <= TelephonyManager.APPTYPE_ISIM) { |
| 9826 | return uiccProfile.isApplicationOnIcc(AppType.values()[appType]); |
| 9827 | } |
| 9828 | return false; |
| 9829 | } finally { |
| 9830 | Binder.restoreCallingIdentity(identity); |
| 9831 | } |
| 9832 | } |
| 9833 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9834 | /** |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 9835 | * Get whether making changes to modem configurations will trigger reboot. |
| 9836 | * Return value defaults to true. |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 9837 | */ |
| 9838 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9839 | public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage, |
| 9840 | String callingFeatureId) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 9841 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9842 | mApp, subId, callingPackage, callingFeatureId, |
| 9843 | "doesSwitchMultiSimConfigTriggerReboot")) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 9844 | return false; |
| 9845 | } |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 9846 | final long identity = Binder.clearCallingIdentity(); |
| 9847 | try { |
| 9848 | return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange(); |
| 9849 | } finally { |
| 9850 | Binder.restoreCallingIdentity(identity); |
| 9851 | } |
| 9852 | } |
| 9853 | |
Nathan Harold | 29f5f05 | 2019-02-15 13:41:57 -0800 | [diff] [blame] | 9854 | private void updateModemStateMetrics() { |
| 9855 | TelephonyMetrics metrics = TelephonyMetrics.getInstance(); |
| 9856 | // TODO: check the state for each modem if the api is ready. |
| 9857 | metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1); |
| 9858 | } |
| 9859 | |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 9860 | @Override |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9861 | public List<UiccSlotMapping> getSlotsMapping(String callingPackage) { |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 9862 | enforceReadPrivilegedPermission("getSlotsMapping"); |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9863 | // Verify that the callingPackage belongs to the calling UID |
| 9864 | mApp.getSystemService(AppOpsManager.class) |
| 9865 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 9866 | final long identity = Binder.clearCallingIdentity(); |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9867 | List<UiccSlotMapping> slotMap = new ArrayList<>(); |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 9868 | try { |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9869 | UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName()); |
| 9870 | if (slotInfos != null) { |
| 9871 | for (int i = 0; i < slotInfos.length; i++) { |
| 9872 | for (UiccPortInfo portInfo : slotInfos[i].getPorts()) { |
| 9873 | if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) { |
| 9874 | slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i, |
| 9875 | portInfo.getLogicalSlotIndex())); |
| 9876 | } |
| 9877 | } |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 9878 | } |
| 9879 | } |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9880 | return slotMap; |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 9881 | } finally { |
| 9882 | Binder.restoreCallingIdentity(identity); |
| 9883 | } |
| 9884 | } |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 9885 | |
| 9886 | /** |
| 9887 | * Get the IRadio HAL Version |
jimsun | f9ec162 | 2022-09-13 21:18:43 +0800 | [diff] [blame] | 9888 | * @deprecated use getHalVersion instead |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 9889 | */ |
jimsun | f9ec162 | 2022-09-13 21:18:43 +0800 | [diff] [blame] | 9890 | @Deprecated |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 9891 | @Override |
| 9892 | public int getRadioHalVersion() { |
jimsun | f9ec162 | 2022-09-13 21:18:43 +0800 | [diff] [blame] | 9893 | return getHalVersion(HAL_SERVICE_RADIO); |
| 9894 | } |
| 9895 | |
| 9896 | /** |
| 9897 | * Get the HAL Version of a specific service |
| 9898 | */ |
| 9899 | @Override |
| 9900 | public int getHalVersion(int service) { |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 9901 | Phone phone = getDefaultPhone(); |
| 9902 | if (phone == null) return -1; |
jimsun | f9ec162 | 2022-09-13 21:18:43 +0800 | [diff] [blame] | 9903 | HalVersion hv = phone.getHalVersion(service); |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 9904 | if (hv.equals(HalVersion.UNKNOWN)) return -1; |
| 9905 | return hv.major * 100 + hv.minor; |
| 9906 | } |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9907 | |
| 9908 | /** |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 9909 | * Get the current calling package name. |
| 9910 | * @return the current calling package name |
| 9911 | */ |
| 9912 | @Override |
| 9913 | public String getCurrentPackageName() { |
| 9914 | return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0]; |
| 9915 | } |
| 9916 | |
| 9917 | /** |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9918 | * Return whether data is enabled for certain APN type. This will tell if framework will accept |
| 9919 | * corresponding network requests on a subId. |
| 9920 | * |
| 9921 | * Data is enabled if: |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9922 | * 1) user data is turned on, or |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9923 | * 2) APN is un-metered for this subscription, or |
| 9924 | * 3) APN type is whitelisted. E.g. MMS is whitelisted if |
Hall Liu | 746e03c | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 9925 | * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled. |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9926 | * |
| 9927 | * @return whether data is allowed for a apn type. |
| 9928 | * |
| 9929 | * @hide |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9930 | */ |
| 9931 | @Override |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9932 | public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) { |
Amit Mahajan | 5d4e192 | 2019-10-07 16:20:43 -0700 | [diff] [blame] | 9933 | enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for " |
| 9934 | + "isDataEnabledForApn"); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9935 | |
| 9936 | // Now that all security checks passes, perform the operation as ourselves. |
| 9937 | final long identity = Binder.clearCallingIdentity(); |
| 9938 | try { |
| 9939 | Phone phone = getPhone(subId); |
| 9940 | if (phone == null) return false; |
| 9941 | |
Jack Yu | 27422a5 | 2022-03-21 10:38:05 -0700 | [diff] [blame] | 9942 | boolean isMetered; |
Jack Yu | 99e8733 | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 9943 | boolean isDataEnabled; |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 9944 | isMetered = phone.getDataNetworkController().getDataConfigManager() |
| 9945 | .isMeteredCapability(DataUtils.apnTypeToNetworkCapability(apnType), |
| 9946 | phone.getServiceState().getDataRoaming()); |
| 9947 | isDataEnabled = phone.getDataSettingsManager().isDataEnabled(apnType); |
Jack Yu | 99e8733 | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 9948 | return !isMetered || isDataEnabled; |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9949 | } finally { |
| 9950 | Binder.restoreCallingIdentity(identity); |
| 9951 | } |
| 9952 | } |
| 9953 | |
| 9954 | @Override |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 9955 | public boolean isApnMetered(@ApnType int apnType, int subId) { |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9956 | enforceReadPrivilegedPermission("isApnMetered"); |
| 9957 | |
| 9958 | // Now that all security checks passes, perform the operation as ourselves. |
| 9959 | final long identity = Binder.clearCallingIdentity(); |
| 9960 | try { |
| 9961 | Phone phone = getPhone(subId); |
| 9962 | if (phone == null) return true; // By default return true. |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 9963 | return phone.getDataNetworkController().getDataConfigManager().isMeteredCapability( |
| 9964 | DataUtils.apnTypeToNetworkCapability(apnType), |
| 9965 | phone.getServiceState().getDataRoaming()); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9966 | } finally { |
| 9967 | Binder.restoreCallingIdentity(identity); |
| 9968 | } |
| 9969 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 9970 | |
| 9971 | @Override |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 9972 | public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers, |
| 9973 | int subscriptionId, IBooleanConsumer resultCallback) { |
| 9974 | enforceModifyPermission(); |
| 9975 | long token = Binder.clearCallingIdentity(); |
| 9976 | try { |
| 9977 | Phone phone = getPhone(subscriptionId); |
| 9978 | if (phone == null) { |
| 9979 | try { |
| 9980 | if (resultCallback != null) { |
| 9981 | resultCallback.accept(false); |
| 9982 | } |
| 9983 | } catch (RemoteException e) { |
| 9984 | // ignore |
| 9985 | } |
| 9986 | return; |
| 9987 | } |
| 9988 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument = |
| 9989 | Pair.create(specifiers, (x) -> { |
| 9990 | try { |
| 9991 | if (resultCallback != null) { |
| 9992 | resultCallback.accept(x); |
| 9993 | } |
| 9994 | } catch (RemoteException e) { |
| 9995 | // ignore |
| 9996 | } |
| 9997 | }); |
| 9998 | sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null); |
| 9999 | } finally { |
| 10000 | Binder.restoreCallingIdentity(token); |
| 10001 | } |
| 10002 | } |
| 10003 | |
| 10004 | @Override |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 10005 | public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) { |
| 10006 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 10007 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 10008 | mApp, subId, "getSystemSelectionChannels"); |
| 10009 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 10010 | final long identity = Binder.clearCallingIdentity(); |
| 10011 | try { |
Sarah Chin | 428d1d6 | 2021-03-13 03:17:40 -0800 | [diff] [blame] | 10012 | Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource); |
| 10013 | if (result instanceof IllegalStateException) { |
| 10014 | throw (IllegalStateException) result; |
| 10015 | } |
| 10016 | List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 10017 | if (DBG) log("getSystemSelectionChannels: " + specifiers); |
| 10018 | return specifiers; |
| 10019 | } finally { |
| 10020 | Binder.restoreCallingIdentity(identity); |
| 10021 | } |
| 10022 | } |
| 10023 | |
| 10024 | @Override |
Jack Yu | 8b766fc | 2022-03-21 09:42:33 -0700 | [diff] [blame] | 10025 | public boolean isMvnoMatched(int slotIndex, int mvnoType, @NonNull String mvnoMatchData) { |
changbetty | ca3d40d | 2020-03-03 16:27:31 +0800 | [diff] [blame] | 10026 | enforceReadPrivilegedPermission("isMvnoMatched"); |
Jack Yu | 8b766fc | 2022-03-21 09:42:33 -0700 | [diff] [blame] | 10027 | return UiccController.getInstance().mvnoMatches(slotIndex, mvnoType, mvnoMatchData); |
changbetty | 7157e9e | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 10028 | } |
| 10029 | |
| 10030 | @Override |
Philip P. Moltmann | d02b737 | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 10031 | public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag, |
| 10032 | IIntegerConsumer pendingSubIdResult) { |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 10033 | if (callingPackage == null) { |
| 10034 | callingPackage = getCurrentPackageName(); |
| 10035 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 10036 | SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp, |
| 10037 | (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE)); |
Philip P. Moltmann | d02b737 | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 10038 | if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag, |
| 10039 | "Sending message")) { |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 10040 | throw new SecurityException("Requires SEND_SMS permission to perform this operation"); |
| 10041 | } |
| 10042 | PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult); |
| 10043 | Intent intent = new Intent(); |
| 10044 | intent.setClass(mApp, PickSmsSubscriptionActivity.class); |
| 10045 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 10046 | // Bring up choose default SMS subscription dialog right now |
| 10047 | intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY, |
| 10048 | PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE); |
| 10049 | mApp.startActivity(intent); |
| 10050 | } |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 10051 | |
| 10052 | @Override |
| 10053 | public String getMmsUAProfUrl(int subId) { |
| 10054 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 10055 | final long identity = Binder.clearCallingIdentity(); |
| 10056 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 10057 | String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString( |
| 10058 | CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING); |
| 10059 | if (!TextUtils.isEmpty(carrierUAProfUrl)) { |
| 10060 | return carrierUAProfUrl; |
| 10061 | } |
Daniel Bright | ebb4eb7 | 2020-02-18 15:16:33 -0800 | [diff] [blame] | 10062 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 10063 | .getString(com.android.internal.R.string.config_mms_user_agent_profile_url); |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 10064 | } finally { |
| 10065 | Binder.restoreCallingIdentity(identity); |
| 10066 | } |
| 10067 | } |
| 10068 | |
| 10069 | @Override |
| 10070 | public String getMmsUserAgent(int subId) { |
| 10071 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 10072 | final long identity = Binder.clearCallingIdentity(); |
| 10073 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 10074 | String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString( |
| 10075 | CarrierConfigManager.KEY_MMS_USER_AGENT_STRING); |
| 10076 | if (!TextUtils.isEmpty(carrierUserAgent)) { |
| 10077 | return carrierUserAgent; |
| 10078 | } |
Daniel Bright | ebb4eb7 | 2020-02-18 15:16:33 -0800 | [diff] [blame] | 10079 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 10080 | .getString(com.android.internal.R.string.config_mms_user_agent); |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 10081 | } finally { |
| 10082 | Binder.restoreCallingIdentity(identity); |
| 10083 | } |
| 10084 | } |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 10085 | |
| 10086 | @Override |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 10087 | public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) { |
| 10088 | enforceReadPrivilegedPermission("isMobileDataPolicyEnabled"); |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 10089 | |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 10090 | final long identity = Binder.clearCallingIdentity(); |
| 10091 | try { |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 10092 | Phone phone = getPhone(subscriptionId); |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 10093 | if (phone == null) return false; |
| 10094 | |
Ling Ma | f188d50 | 2022-09-16 15:22:36 -0700 | [diff] [blame] | 10095 | return phone.getDataSettingsManager().isMobileDataPolicyEnabled(policy); |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 10096 | } finally { |
| 10097 | Binder.restoreCallingIdentity(identity); |
| 10098 | } |
| 10099 | } |
| 10100 | |
| 10101 | @Override |
Hall Liu | c66bb11 | 2021-02-02 12:09:32 -0800 | [diff] [blame] | 10102 | public void setMobileDataPolicyEnabled(int subscriptionId, int policy, |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 10103 | boolean enabled) { |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 10104 | enforceModifyPermission(); |
| 10105 | |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 10106 | final long identity = Binder.clearCallingIdentity(); |
| 10107 | try { |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 10108 | Phone phone = getPhone(subscriptionId); |
| 10109 | if (phone == null) return; |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 10110 | |
Ling Ma | f188d50 | 2022-09-16 15:22:36 -0700 | [diff] [blame] | 10111 | phone.getDataSettingsManager().setMobileDataPolicy(policy, enabled); |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 10112 | } finally { |
| 10113 | Binder.restoreCallingIdentity(identity); |
| 10114 | } |
| 10115 | } |
| 10116 | |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 10117 | /** |
Hall Liu | 746e03c | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 10118 | * Updates whether conference event package handling is enabled. |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 10119 | * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false} |
| 10120 | * otherwise. |
| 10121 | */ |
| 10122 | @Override |
| 10123 | public void setCepEnabled(boolean isCepEnabled) { |
| 10124 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled"); |
| 10125 | |
| 10126 | final long identity = Binder.clearCallingIdentity(); |
| 10127 | try { |
| 10128 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled); |
| 10129 | for (Phone phone : PhoneFactory.getPhones()) { |
| 10130 | Phone defaultPhone = phone.getImsPhone(); |
| 10131 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 10132 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 10133 | ImsPhoneCallTracker imsPhoneCallTracker = |
| 10134 | (ImsPhoneCallTracker) imsPhone.getCallTracker(); |
| 10135 | imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled); |
| 10136 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone " |
| 10137 | + imsPhone.getMsisdn()); |
| 10138 | } |
| 10139 | } |
| 10140 | } finally { |
| 10141 | Binder.restoreCallingIdentity(identity); |
| 10142 | } |
| 10143 | } |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 10144 | |
| 10145 | /** |
| 10146 | * Notify that an RCS autoconfiguration XML file has been received for provisioning. |
| 10147 | * |
| 10148 | * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed. |
| 10149 | * @param isCompressed The XML file is compressed in gzip format and must be decompressed |
| 10150 | * before being read. |
| 10151 | */ |
| 10152 | @Override |
| 10153 | public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean |
| 10154 | isCompressed) { |
| 10155 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 10156 | mApp, subId, "notifyRcsAutoConfigurationReceived"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10157 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10158 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10159 | } |
| 10160 | if (!isImsAvailableOnDevice()) { |
| 10161 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 10162 | "IMS not available on device."); |
| 10163 | } |
| 10164 | |
| 10165 | final long identity = Binder.clearCallingIdentity(); |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 10166 | try { |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10167 | RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed); |
| 10168 | } finally { |
| 10169 | Binder.restoreCallingIdentity(identity); |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 10170 | } |
| 10171 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 10172 | |
| 10173 | @Override |
| 10174 | public boolean isIccLockEnabled(int subId) { |
| 10175 | enforceReadPrivilegedPermission("isIccLockEnabled"); |
| 10176 | |
| 10177 | // Now that all security checks passes, perform the operation as ourselves. |
| 10178 | final long identity = Binder.clearCallingIdentity(); |
| 10179 | try { |
| 10180 | Phone phone = getPhone(subId); |
| 10181 | if (phone != null && phone.getIccCard() != null) { |
| 10182 | return phone.getIccCard().getIccLockEnabled(); |
| 10183 | } else { |
| 10184 | return false; |
| 10185 | } |
| 10186 | } finally { |
| 10187 | Binder.restoreCallingIdentity(identity); |
| 10188 | } |
| 10189 | } |
| 10190 | |
| 10191 | /** |
| 10192 | * Set the ICC pin lock enabled or disabled. |
| 10193 | * |
| 10194 | * @return an integer representing the status of IccLock enabled or disabled in the following |
| 10195 | * three cases: |
| 10196 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock |
| 10197 | * successfully. |
| 10198 | * - Positive number and zero for remaining password attempts. |
| 10199 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
| 10200 | * |
| 10201 | */ |
| 10202 | @Override |
| 10203 | public int setIccLockEnabled(int subId, boolean enabled, String password) { |
| 10204 | enforceModifyPermission(); |
| 10205 | |
| 10206 | Phone phone = getPhone(subId); |
| 10207 | if (phone == null) { |
| 10208 | return 0; |
| 10209 | } |
| 10210 | // Now that all security checks passes, perform the operation as ourselves. |
| 10211 | final long identity = Binder.clearCallingIdentity(); |
| 10212 | try { |
| 10213 | int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED, |
| 10214 | new Pair<Boolean, String>(enabled, password), phone, null); |
| 10215 | return attemptsRemaining; |
| 10216 | |
| 10217 | } catch (Exception e) { |
| 10218 | Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e); |
| 10219 | } finally { |
| 10220 | Binder.restoreCallingIdentity(identity); |
| 10221 | } |
| 10222 | return 0; |
| 10223 | } |
| 10224 | |
| 10225 | /** |
| 10226 | * Change the ICC password used in ICC pin lock. |
| 10227 | * |
| 10228 | * @return an integer representing the status of IccLock changed in the following three cases: |
| 10229 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully. |
| 10230 | * - Positive number and zero for remaining password attempts. |
| 10231 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
| 10232 | * |
| 10233 | */ |
| 10234 | @Override |
| 10235 | public int changeIccLockPassword(int subId, String oldPassword, String newPassword) { |
| 10236 | enforceModifyPermission(); |
| 10237 | |
| 10238 | Phone phone = getPhone(subId); |
| 10239 | if (phone == null) { |
| 10240 | return 0; |
| 10241 | } |
| 10242 | // Now that all security checks passes, perform the operation as ourselves. |
| 10243 | final long identity = Binder.clearCallingIdentity(); |
| 10244 | try { |
| 10245 | int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD, |
| 10246 | new Pair<String, String>(oldPassword, newPassword), phone, null); |
| 10247 | return attemptsRemaining; |
| 10248 | |
| 10249 | } catch (Exception e) { |
| 10250 | Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e); |
| 10251 | } finally { |
| 10252 | Binder.restoreCallingIdentity(identity); |
| 10253 | } |
| 10254 | return 0; |
| 10255 | } |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 10256 | |
| 10257 | /** |
| 10258 | * Request for receiving user activity notification |
| 10259 | */ |
| 10260 | @Override |
| 10261 | public void requestUserActivityNotification() { |
| 10262 | if (!mNotifyUserActivity.get() |
| 10263 | && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) { |
| 10264 | mNotifyUserActivity.set(true); |
| 10265 | } |
| 10266 | } |
| 10267 | |
| 10268 | /** |
| 10269 | * Called when userActivity is signalled in the power manager. |
| 10270 | * This is safe to call from any thread, with any window manager locks held or not. |
| 10271 | */ |
| 10272 | @Override |
| 10273 | public void userActivity() { |
| 10274 | // *************************************** |
| 10275 | // * Inherited from PhoneWindowManager * |
| 10276 | // *************************************** |
| 10277 | // THIS IS CALLED FROM DEEP IN THE POWER MANAGER |
| 10278 | // WITH ITS LOCKS HELD. |
| 10279 | // |
| 10280 | // This code must be VERY careful about the locks |
| 10281 | // it acquires. |
| 10282 | // In fact, the current code acquires way too many, |
| 10283 | // and probably has lurking deadlocks. |
| 10284 | |
| 10285 | if (Binder.getCallingUid() != Process.SYSTEM_UID) { |
| 10286 | throw new SecurityException("Only the OS may call notifyUserActivity()"); |
| 10287 | } |
| 10288 | |
| 10289 | if (mNotifyUserActivity.getAndSet(false)) { |
| 10290 | mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY, |
| 10291 | USER_ACTIVITY_NOTIFICATION_DELAY); |
| 10292 | } |
| 10293 | } |
Malcolm Chen | 4639c56 | 2020-04-13 11:59:40 -0700 | [diff] [blame] | 10294 | |
| 10295 | @Override |
| 10296 | public boolean canConnectTo5GInDsdsMode() { |
| 10297 | return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode); |
| 10298 | } |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 10299 | |
| 10300 | @Override |
| 10301 | public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage, |
| 10302 | String callingFeatureId) { |
| 10303 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 10304 | mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) { |
| 10305 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 10306 | } |
| 10307 | |
| 10308 | Phone phone = getPhone(subId); |
| 10309 | if (phone == null) { |
| 10310 | throw new RuntimeException("phone is not available"); |
| 10311 | } |
| 10312 | // Now that all security checks passes, perform the operation as ourselves. |
| 10313 | final long identity = Binder.clearCallingIdentity(); |
| 10314 | try { |
| 10315 | return phone.getEquivalentHomePlmns(); |
| 10316 | } finally { |
| 10317 | Binder.restoreCallingIdentity(identity); |
| 10318 | } |
| 10319 | } |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 10320 | |
| 10321 | @Override |
| 10322 | public boolean isRadioInterfaceCapabilitySupported( |
Daniel Bright | 95a4c1f | 2021-02-11 09:57:16 -0800 | [diff] [blame] | 10323 | final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) { |
| 10324 | Set<String> radioInterfaceCapabilities = |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 10325 | mRadioInterfaceCapabilities.getCapabilities(); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 10326 | if (radioInterfaceCapabilities == null) { |
| 10327 | throw new RuntimeException("radio interface capabilities are not available"); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 10328 | } |
Daniel Bright | 95a4c1f | 2021-02-11 09:57:16 -0800 | [diff] [blame] | 10329 | return radioInterfaceCapabilities.contains(capability); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 10330 | } |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10331 | |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 10332 | @Override |
| 10333 | public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl, |
| 10334 | UaSecurityProtocolIdentifier securityProtocol, |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10335 | boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) { |
| 10336 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 10337 | Binder.getCallingUid(), "bootstrapAuthenticationRequest", |
| 10338 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 10339 | Manifest.permission.MODIFY_PHONE_STATE); |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 10340 | if (DBG) { |
| 10341 | log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:" |
| 10342 | + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol |
| 10343 | + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback); |
| 10344 | } |
| 10345 | |
| 10346 | if (!SubscriptionManager.isValidSubscriptionId(subId) |
| 10347 | || appType < TelephonyManager.APPTYPE_UNKNOWN |
| 10348 | || appType > TelephonyManager.APPTYPE_ISIM |
| 10349 | || nafUrl == null || securityProtocol == null || callback == null) { |
| 10350 | Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters"); |
| 10351 | if (callback != null) { |
| 10352 | try { |
| 10353 | callback.onAuthenticationFailure( |
| 10354 | 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED); |
| 10355 | } catch (RemoteException exception) { |
| 10356 | log("Fail to notify onAuthenticationFailure due to " + exception); |
| 10357 | } |
| 10358 | return; |
| 10359 | } |
| 10360 | } |
| 10361 | |
| 10362 | final long token = Binder.clearCallingIdentity(); |
| 10363 | try { |
| 10364 | getGbaManager(subId).bootstrapAuthenticationRequest( |
| 10365 | new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(), |
| 10366 | forceBootStrapping, callback)); |
| 10367 | } finally { |
| 10368 | Binder.restoreCallingIdentity(token); |
| 10369 | } |
| 10370 | } |
| 10371 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10372 | /** |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10373 | * Attempts to set the radio power state for all phones for thermal reason. |
| 10374 | * This does not guarantee that the |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10375 | * requested radio power state will actually be set. See {@link |
| 10376 | * PhoneInternalInterface#setRadioPowerForReason} for more details. |
| 10377 | * |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10378 | * @param enable {@code true} if trying to turn radio on. |
| 10379 | * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code |
| 10380 | * false}. |
| 10381 | */ |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10382 | private boolean setRadioPowerForThermal(boolean enable) { |
| 10383 | boolean isPhoneAvailable = false; |
| 10384 | for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) { |
| 10385 | Phone phone = PhoneFactory.getPhone(i); |
| 10386 | if (phone != null) { |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 10387 | phone.setRadioPowerForReason(enable, TelephonyManager.RADIO_POWER_REASON_THERMAL); |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10388 | isPhoneAvailable = true; |
| 10389 | } |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10390 | } |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10391 | |
| 10392 | // return true if successfully informed the phone object about the thermal radio power |
| 10393 | // request. |
| 10394 | return isPhoneAvailable; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10395 | } |
| 10396 | |
| 10397 | private int handleDataThrottlingRequest(int subId, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 10398 | DataThrottlingRequest dataThrottlingRequest, String callingPackage) { |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10399 | boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported( |
| 10400 | TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING); |
| 10401 | if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction() |
| 10402 | != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) { |
| 10403 | throw new IllegalArgumentException("modem does not support data throttling"); |
| 10404 | } |
| 10405 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10406 | // Ensure that radio is on. If not able to power on due to phone being unavailable, return |
| 10407 | // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10408 | if (!setRadioPowerForThermal(true)) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10409 | return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 10410 | } |
| 10411 | |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 10412 | setDataEnabledForReason( |
| 10413 | subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true, callingPackage); |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10414 | |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10415 | if (isDataThrottlingSupported) { |
| 10416 | int thermalMitigationResult = |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10417 | (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId); |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10418 | if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) { |
| 10419 | throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS"); |
| 10420 | } else if (thermalMitigationResult |
| 10421 | == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) { |
Jack Nudelman | 760d096 | 2021-05-20 13:57:30 -0700 | [diff] [blame] | 10422 | log("Modem likely does not support data throttling on secondary carrier. Data " + |
| 10423 | "throttling action = " + dataThrottlingRequest.getDataThrottlingAction()); |
| 10424 | return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10425 | } |
| 10426 | return thermalMitigationResult; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10427 | } |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10428 | |
| 10429 | return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10430 | } |
| 10431 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10432 | private static List<String> getThermalMitigationAllowlist(Context context) { |
| 10433 | if (sThermalMitigationAllowlistedPackages.isEmpty()) { |
| 10434 | for (String pckg : context.getResources() |
| 10435 | .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) { |
| 10436 | sThermalMitigationAllowlistedPackages.add(pckg); |
| 10437 | } |
| 10438 | } |
| 10439 | |
| 10440 | return sThermalMitigationAllowlistedPackages; |
| 10441 | } |
| 10442 | |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 10443 | private boolean isAnyPhoneInEmergencyState() { |
| 10444 | TelecomManager tm = mApp.getSystemService(TelecomManager.class); |
| 10445 | if (tm.isInEmergencyCall()) { |
| 10446 | Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call"); |
| 10447 | return true; |
| 10448 | } |
| 10449 | for (Phone phone : PhoneFactory.getPhones()) { |
| 10450 | if (phone.isInEmergencySmsMode() || phone.isInEcm()) { |
| 10451 | Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = " |
| 10452 | + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = " |
| 10453 | + phone.isInEcm()); |
| 10454 | return true; |
| 10455 | } |
| 10456 | } |
| 10457 | |
| 10458 | return false; |
| 10459 | } |
| 10460 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10461 | /** |
| 10462 | * Used by shell commands to add an authorized package name for thermal mitigation. |
| 10463 | * @param packageName name of package to be allowlisted |
| 10464 | * @param context |
| 10465 | */ |
| 10466 | static void addPackageToThermalMitigationAllowlist(String packageName, Context context) { |
| 10467 | sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context); |
| 10468 | sThermalMitigationAllowlistedPackages.add(packageName); |
| 10469 | } |
| 10470 | |
| 10471 | /** |
| 10472 | * Used by shell commands to remove an authorized package name for thermal mitigation. |
| 10473 | * @param packageName name of package to remove from allowlist |
| 10474 | * @param context |
| 10475 | */ |
| 10476 | static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) { |
| 10477 | sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context); |
| 10478 | sThermalMitigationAllowlistedPackages.remove(packageName); |
| 10479 | } |
| 10480 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10481 | /** |
| 10482 | * Thermal mitigation request to control functionalities at modem. |
| 10483 | * |
| 10484 | * @param subId the id of the subscription. |
| 10485 | * @param thermalMitigationRequest holds all necessary information to be passed down to modem. |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10486 | * @param callingPackage the package name of the calling package. |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10487 | * |
| 10488 | * @return thermalMitigationResult enum as defined in android.telephony.Annotation. |
| 10489 | */ |
| 10490 | @Override |
| 10491 | @ThermalMitigationResult |
| 10492 | public int sendThermalMitigationRequest( |
| 10493 | int subId, |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10494 | ThermalMitigationRequest thermalMitigationRequest, |
| 10495 | String callingPackage) throws IllegalArgumentException { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10496 | enforceModifyPermission(); |
| 10497 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10498 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 10499 | if (!getThermalMitigationAllowlist(getDefaultPhone().getContext()) |
| 10500 | .contains(callingPackage)) { |
| 10501 | throw new SecurityException("Calling package must be configured in the device config. " |
| 10502 | + "calling package: " + callingPackage); |
| 10503 | } |
| 10504 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10505 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 10506 | final long identity = Binder.clearCallingIdentity(); |
| 10507 | |
| 10508 | int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR; |
| 10509 | try { |
| 10510 | int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction(); |
| 10511 | switch (thermalMitigationAction) { |
| 10512 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING: |
| 10513 | thermalMitigationResult = |
| 10514 | handleDataThrottlingRequest(subId, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 10515 | thermalMitigationRequest.getDataThrottlingRequest(), |
| 10516 | callingPackage); |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10517 | break; |
| 10518 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY: |
| 10519 | if (thermalMitigationRequest.getDataThrottlingRequest() != null) { |
| 10520 | throw new IllegalArgumentException("dataThrottlingRequest must be null for " |
| 10521 | + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY"); |
| 10522 | } |
| 10523 | |
| 10524 | // Ensure that radio is on. If not able to power on due to phone being |
| 10525 | // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10526 | if (!setRadioPowerForThermal(true)) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10527 | thermalMitigationResult = |
| 10528 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 10529 | break; |
| 10530 | } |
| 10531 | |
| 10532 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 10533 | false, callingPackage); |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10534 | thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 10535 | break; |
| 10536 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF: |
| 10537 | if (thermalMitigationRequest.getDataThrottlingRequest() != null) { |
| 10538 | throw new IllegalArgumentException("dataThrottlingRequest must be null for" |
| 10539 | + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF"); |
| 10540 | } |
| 10541 | |
| 10542 | TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null); |
| 10543 | if (registry != null) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10544 | Phone phone = getPhone(subId); |
| 10545 | if (phone == null) { |
| 10546 | thermalMitigationResult = |
| 10547 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 10548 | break; |
| 10549 | } |
| 10550 | |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 10551 | TelephonyConnectionService service = |
| 10552 | registry.getTelephonyConnectionService(); |
Jack Nudelman | b30ac30 | 2021-06-17 15:39:58 -0700 | [diff] [blame] | 10553 | if (service != null && service.isEmergencyCallPending()) { |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 10554 | Log.e(LOG_TAG, "An emergency call is pending"); |
| 10555 | thermalMitigationResult = |
| 10556 | TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE; |
| 10557 | break; |
| 10558 | } else if (isAnyPhoneInEmergencyState()) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10559 | thermalMitigationResult = |
| 10560 | TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE; |
| 10561 | break; |
| 10562 | } |
| 10563 | } else { |
| 10564 | thermalMitigationResult = |
| 10565 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 10566 | break; |
| 10567 | } |
| 10568 | |
| 10569 | // Turn radio off. If not able to power off due to phone being unavailable, |
| 10570 | // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10571 | if (!setRadioPowerForThermal(false)) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10572 | thermalMitigationResult = |
| 10573 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 10574 | break; |
| 10575 | } |
| 10576 | thermalMitigationResult = |
| 10577 | TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 10578 | break; |
| 10579 | default: |
| 10580 | throw new IllegalArgumentException("the requested thermalMitigationAction does " |
| 10581 | + "not exist. Requested action: " + thermalMitigationAction); |
| 10582 | } |
| 10583 | } catch (IllegalArgumentException e) { |
| 10584 | throw e; |
| 10585 | } catch (Exception e) { |
| 10586 | Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e); |
| 10587 | thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 10588 | } finally { |
| 10589 | Binder.restoreCallingIdentity(identity); |
| 10590 | } |
| 10591 | |
| 10592 | if (DBG) { |
| 10593 | log("thermalMitigationRequest returning with thermalMitigationResult: " |
| 10594 | + thermalMitigationResult); |
| 10595 | } |
| 10596 | |
| 10597 | return thermalMitigationResult; |
| 10598 | } |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 10599 | |
| 10600 | /** |
| 10601 | * Set the GbaService Package Name that Telephony will bind to. |
| 10602 | * |
| 10603 | * @param subId The sim that the GbaService is associated with. |
| 10604 | * @param packageName The name of the package to be replaced with. |
| 10605 | * @return true if setting the GbaService to bind to succeeded, false if it did not. |
| 10606 | */ |
| 10607 | @Override |
| 10608 | public boolean setBoundGbaServiceOverride(int subId, String packageName) { |
| 10609 | enforceModifyPermission(); |
| 10610 | |
| 10611 | final long identity = Binder.clearCallingIdentity(); |
| 10612 | try { |
| 10613 | return getGbaManager(subId).overrideServicePackage(packageName); |
| 10614 | } finally { |
| 10615 | Binder.restoreCallingIdentity(identity); |
| 10616 | } |
| 10617 | } |
| 10618 | |
| 10619 | /** |
| 10620 | * Return the package name of the currently bound GbaService. |
| 10621 | * |
| 10622 | * @param subId The sim that the GbaService is associated with. |
| 10623 | * @return the package name of the GbaService configuration, null if GBA is not supported. |
| 10624 | */ |
| 10625 | @Override |
| 10626 | public String getBoundGbaService(int subId) { |
| 10627 | enforceReadPrivilegedPermission("getBoundGbaServicePackage"); |
| 10628 | |
| 10629 | final long identity = Binder.clearCallingIdentity(); |
| 10630 | try { |
| 10631 | return getGbaManager(subId).getServicePackage(); |
| 10632 | } finally { |
| 10633 | Binder.restoreCallingIdentity(identity); |
| 10634 | } |
| 10635 | } |
| 10636 | |
| 10637 | /** |
| 10638 | * Set the release time for telephony to unbind GbaService. |
| 10639 | * |
| 10640 | * @param subId The sim that the GbaService is associated with. |
| 10641 | * @param interval The release time to unbind GbaService by millisecond. |
| 10642 | * @return true if setting the GbaService to bind to succeeded, false if it did not. |
| 10643 | */ |
| 10644 | @Override |
| 10645 | public boolean setGbaReleaseTimeOverride(int subId, int interval) { |
| 10646 | enforceModifyPermission(); |
| 10647 | |
| 10648 | final long identity = Binder.clearCallingIdentity(); |
| 10649 | try { |
| 10650 | return getGbaManager(subId).overrideReleaseTime(interval); |
| 10651 | } finally { |
| 10652 | Binder.restoreCallingIdentity(identity); |
| 10653 | } |
| 10654 | } |
| 10655 | |
| 10656 | /** |
| 10657 | * Return the release time for telephony to unbind GbaService. |
| 10658 | * |
| 10659 | * @param subId The sim that the GbaService is associated with. |
| 10660 | * @return The release time to unbind GbaService by millisecond. |
| 10661 | */ |
| 10662 | @Override |
| 10663 | public int getGbaReleaseTime(int subId) { |
| 10664 | enforceReadPrivilegedPermission("getGbaReleaseTime"); |
| 10665 | |
| 10666 | final long identity = Binder.clearCallingIdentity(); |
| 10667 | try { |
| 10668 | return getGbaManager(subId).getReleaseTime(); |
| 10669 | } finally { |
| 10670 | Binder.restoreCallingIdentity(identity); |
| 10671 | } |
| 10672 | } |
| 10673 | |
| 10674 | private GbaManager getGbaManager(int subId) { |
| 10675 | GbaManager instance = GbaManager.getInstance(subId); |
| 10676 | if (instance == null) { |
| 10677 | String packageName = mApp.getResources().getString(R.string.config_gba_package); |
| 10678 | int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time); |
| 10679 | instance = GbaManager.make(mApp, subId, packageName, releaseTime); |
| 10680 | } |
| 10681 | return instance; |
| 10682 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10683 | |
| 10684 | /** |
| 10685 | * indicate whether the device and the carrier can support |
| 10686 | * RCS VoLTE single registration. |
| 10687 | */ |
| 10688 | @Override |
| 10689 | public boolean isRcsVolteSingleRegistrationCapable(int subId) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10690 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 10691 | Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable", |
| 10692 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 10693 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10694 | |
| 10695 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10696 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10697 | } |
| 10698 | |
| 10699 | final long identity = Binder.clearCallingIdentity(); |
| 10700 | try { |
| 10701 | RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance(); |
| 10702 | if (rpm != null) { |
Hui Wang | 67af90e | 2021-06-04 16:57:15 -0700 | [diff] [blame] | 10703 | Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId); |
| 10704 | if (isCapable != null) { |
| 10705 | return isCapable; |
| 10706 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10707 | } |
Hui Wang | 67af90e | 2021-06-04 16:57:15 -0700 | [diff] [blame] | 10708 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE, |
| 10709 | "service is temporarily unavailable."); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10710 | } finally { |
| 10711 | Binder.restoreCallingIdentity(identity); |
| 10712 | } |
| 10713 | } |
| 10714 | |
| 10715 | /** |
| 10716 | * Register RCS provisioning callback. |
| 10717 | */ |
| 10718 | @Override |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10719 | public void registerRcsProvisioningCallback(int subId, |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10720 | IRcsConfigCallback callback) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10721 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10722 | Binder.getCallingUid(), "registerRcsProvisioningCallback", |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10723 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 10724 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10725 | |
| 10726 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10727 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10728 | } |
| 10729 | if (!isImsAvailableOnDevice()) { |
| 10730 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 10731 | "IMS not available on device."); |
| 10732 | } |
| 10733 | |
| 10734 | final long identity = Binder.clearCallingIdentity(); |
| 10735 | try { |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 10736 | if (!RcsProvisioningMonitor.getInstance() |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10737 | .registerRcsProvisioningCallback(subId, callback)) { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 10738 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION, |
| 10739 | "Active subscription not found."); |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 10740 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10741 | } finally { |
| 10742 | Binder.restoreCallingIdentity(identity); |
| 10743 | } |
| 10744 | } |
| 10745 | |
| 10746 | /** |
| 10747 | * Unregister RCS provisioning callback. |
| 10748 | */ |
| 10749 | @Override |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10750 | public void unregisterRcsProvisioningCallback(int subId, |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10751 | IRcsConfigCallback callback) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10752 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10753 | Binder.getCallingUid(), "unregisterRcsProvisioningCallback", |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10754 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 10755 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10756 | |
| 10757 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10758 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10759 | } |
| 10760 | if (!isImsAvailableOnDevice()) { |
| 10761 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 10762 | "IMS not available on device."); |
| 10763 | } |
| 10764 | |
| 10765 | final long identity = Binder.clearCallingIdentity(); |
| 10766 | try { |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 10767 | RcsProvisioningMonitor.getInstance() |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10768 | .unregisterRcsProvisioningCallback(subId, callback); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10769 | } finally { |
| 10770 | Binder.restoreCallingIdentity(identity); |
| 10771 | } |
| 10772 | } |
| 10773 | |
| 10774 | /** |
| 10775 | * trigger RCS reconfiguration. |
| 10776 | */ |
| 10777 | public void triggerRcsReconfiguration(int subId) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10778 | TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(), |
| 10779 | "triggerRcsReconfiguration", |
| 10780 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10781 | |
| 10782 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10783 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10784 | } |
| 10785 | if (!isImsAvailableOnDevice()) { |
| 10786 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 10787 | "IMS not available on device."); |
| 10788 | } |
| 10789 | |
| 10790 | final long identity = Binder.clearCallingIdentity(); |
| 10791 | try { |
| 10792 | RcsProvisioningMonitor.getInstance().requestReconfig(subId); |
| 10793 | } finally { |
| 10794 | Binder.restoreCallingIdentity(identity); |
| 10795 | } |
| 10796 | } |
| 10797 | |
| 10798 | /** |
| 10799 | * Provide the client configuration parameters of the RCS application. |
| 10800 | */ |
| 10801 | public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10802 | TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(), |
| 10803 | "setRcsClientConfiguration", |
| 10804 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10805 | |
| 10806 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10807 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10808 | } |
| 10809 | if (!isImsAvailableOnDevice()) { |
| 10810 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 10811 | "IMS not available on device."); |
| 10812 | } |
| 10813 | |
| 10814 | final long identity = Binder.clearCallingIdentity(); |
| 10815 | |
| 10816 | try { |
| 10817 | IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS); |
| 10818 | if (configBinder == null) { |
| 10819 | Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration"); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 10820 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION, |
| 10821 | "could not find the requested subscription"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10822 | } else { |
| 10823 | configBinder.setRcsClientConfiguration(rcc); |
| 10824 | } |
joonhunshin | 3e15424 | 2021-09-17 06:33:39 +0000 | [diff] [blame] | 10825 | |
| 10826 | RcsStats.getInstance().onRcsClientProvisioningStats(subId, |
| 10827 | RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10828 | } catch (RemoteException e) { |
| 10829 | Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage()); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 10830 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE, |
| 10831 | "service is temporarily unavailable."); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10832 | } finally { |
| 10833 | Binder.restoreCallingIdentity(identity); |
| 10834 | } |
| 10835 | } |
| 10836 | |
| 10837 | /** |
Hui Wang | baaee6a | 2021-02-19 20:45:36 -0800 | [diff] [blame] | 10838 | * Enables or disables the test mode for RCS VoLTE single registration. |
| 10839 | */ |
| 10840 | @Override |
| 10841 | public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) { |
| 10842 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10843 | "setRcsSingleRegistrationTestModeEnabled"); |
| 10844 | |
| 10845 | RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled); |
| 10846 | } |
| 10847 | |
| 10848 | /** |
| 10849 | * Gets the test mode for RCS VoLTE single registration. |
| 10850 | */ |
| 10851 | @Override |
| 10852 | public boolean getRcsSingleRegistrationTestModeEnabled() { |
| 10853 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10854 | "getRcsSingleRegistrationTestModeEnabled"); |
| 10855 | |
| 10856 | return RcsProvisioningMonitor.getInstance().getTestModeEnabled(); |
| 10857 | } |
| 10858 | |
| 10859 | /** |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10860 | * Overrides the config of RCS VoLTE single registration enabled for the device. |
| 10861 | */ |
| 10862 | @Override |
| 10863 | public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) { |
| 10864 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10865 | "setDeviceSingleRegistrationEnabledOverride"); |
| 10866 | enforceModifyPermission(); |
| 10867 | |
| 10868 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 10869 | : Boolean.parseBoolean(enabledStr); |
| 10870 | RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled); |
Brad Ebinger | 49a72b4 | 2021-01-29 00:55:24 +0000 | [diff] [blame] | 10871 | mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10872 | } |
| 10873 | |
| 10874 | /** |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 10875 | * Sends a device to device communication message. Only usable via shell. |
| 10876 | * @param message message to send. |
| 10877 | * @param value message value. |
| 10878 | */ |
| 10879 | @Override |
| 10880 | public void sendDeviceToDeviceMessage(int message, int value) { |
| 10881 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
Tyler Gunn | babbda0 | 2021-02-10 11:05:02 -0800 | [diff] [blame] | 10882 | "sendDeviceToDeviceMessage"); |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 10883 | enforceModifyPermission(); |
| 10884 | |
| 10885 | final long identity = Binder.clearCallingIdentity(); |
| 10886 | try { |
| 10887 | TelephonyConnectionService service = |
| 10888 | TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService(); |
| 10889 | if (service == null) { |
| 10890 | Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call."); |
| 10891 | return; |
| 10892 | } |
| 10893 | service.sendTestDeviceToDeviceMessage(message, value); |
| 10894 | } finally { |
| 10895 | Binder.restoreCallingIdentity(identity); |
| 10896 | } |
| 10897 | } |
| 10898 | |
Tyler Gunn | babbda0 | 2021-02-10 11:05:02 -0800 | [diff] [blame] | 10899 | /** |
| 10900 | * Sets the specified device to device transport active. |
| 10901 | * @param transport The transport to set active. |
| 10902 | */ |
| 10903 | @Override |
| 10904 | public void setActiveDeviceToDeviceTransport(@NonNull String transport) { |
| 10905 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10906 | "setActiveDeviceToDeviceTransport"); |
| 10907 | enforceModifyPermission(); |
| 10908 | |
| 10909 | final long identity = Binder.clearCallingIdentity(); |
| 10910 | try { |
| 10911 | TelephonyConnectionService service = |
| 10912 | TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService(); |
| 10913 | if (service == null) { |
| 10914 | Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call."); |
| 10915 | return; |
| 10916 | } |
| 10917 | service.setActiveDeviceToDeviceTransport(transport); |
| 10918 | } finally { |
| 10919 | Binder.restoreCallingIdentity(identity); |
| 10920 | } |
| 10921 | } |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 10922 | |
Tyler Gunn | d433926 | 2021-05-03 14:46:49 -0700 | [diff] [blame] | 10923 | @Override |
| 10924 | public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) { |
| 10925 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10926 | "setDeviceToDeviceForceEnabled"); |
| 10927 | |
| 10928 | final long identity = Binder.clearCallingIdentity(); |
| 10929 | try { |
| 10930 | Arrays.stream(PhoneFactory.getPhones()).forEach( |
| 10931 | p -> { |
| 10932 | Phone thePhone = p.getImsPhone(); |
| 10933 | if (thePhone != null && thePhone instanceof ImsPhone) { |
| 10934 | ImsPhone imsPhone = (ImsPhone) thePhone; |
| 10935 | CallTracker tracker = imsPhone.getCallTracker(); |
| 10936 | if (tracker != null && tracker instanceof ImsPhoneCallTracker) { |
| 10937 | ImsPhoneCallTracker imsPhoneCallTracker = |
| 10938 | (ImsPhoneCallTracker) tracker; |
| 10939 | imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled); |
| 10940 | } |
| 10941 | } |
| 10942 | } |
| 10943 | ); |
| 10944 | } finally { |
| 10945 | Binder.restoreCallingIdentity(identity); |
| 10946 | } |
| 10947 | } |
| 10948 | |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 10949 | /** |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10950 | * Gets the config of RCS VoLTE single registration enabled for the device. |
| 10951 | */ |
| 10952 | @Override |
| 10953 | public boolean getDeviceSingleRegistrationEnabled() { |
| 10954 | enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled"); |
| 10955 | return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled(); |
| 10956 | } |
| 10957 | |
| 10958 | /** |
| 10959 | * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription. |
| 10960 | */ |
| 10961 | @Override |
| 10962 | public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) { |
| 10963 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10964 | "setCarrierSingleRegistrationEnabledOverride"); |
| 10965 | enforceModifyPermission(); |
| 10966 | |
| 10967 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 10968 | : Boolean.parseBoolean(enabledStr); |
| 10969 | return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled( |
| 10970 | subId, enabled); |
| 10971 | } |
| 10972 | |
| 10973 | /** |
| 10974 | * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription. |
| 10975 | */ |
| 10976 | @Override |
| 10977 | public boolean getCarrierSingleRegistrationEnabled(int subId) { |
| 10978 | enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled"); |
| 10979 | return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId); |
| 10980 | } |
Chiachang Wang | d6d3477 | 2020-12-22 11:38:27 +0800 | [diff] [blame] | 10981 | |
| 10982 | /** |
Hui Wang | b647abe | 2021-02-26 09:33:38 -0800 | [diff] [blame] | 10983 | * Overrides the ims feature validation result |
| 10984 | */ |
| 10985 | @Override |
| 10986 | public boolean setImsFeatureValidationOverride(int subId, String enabledStr) { |
| 10987 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10988 | "setImsFeatureValidationOverride"); |
| 10989 | |
| 10990 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 10991 | : Boolean.parseBoolean(enabledStr); |
| 10992 | return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation( |
| 10993 | subId, enabled); |
| 10994 | } |
| 10995 | |
| 10996 | /** |
| 10997 | * Gets the ims feature validation override value |
| 10998 | */ |
| 10999 | @Override |
| 11000 | public boolean getImsFeatureValidationOverride(int subId) { |
| 11001 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11002 | "getImsFeatureValidationOverride"); |
| 11003 | return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId); |
| 11004 | } |
| 11005 | |
| 11006 | /** |
Chiachang Wang | d6d3477 | 2020-12-22 11:38:27 +0800 | [diff] [blame] | 11007 | * Get the mobile provisioning url that is used to launch a browser to allow users to manage |
| 11008 | * their mobile plan. |
| 11009 | */ |
| 11010 | @Override |
| 11011 | public String getMobileProvisioningUrl() { |
| 11012 | enforceReadPrivilegedPermission("getMobileProvisioningUrl"); |
| 11013 | final long identity = Binder.clearCallingIdentity(); |
| 11014 | try { |
| 11015 | return getDefaultPhone().getMobileProvisioningUrl(); |
| 11016 | } finally { |
| 11017 | Binder.restoreCallingIdentity(identity); |
| 11018 | } |
| 11019 | } |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11020 | |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 11021 | /** |
calvinpan | e4a8a1d | 2021-01-25 13:51:18 +0800 | [diff] [blame] | 11022 | * Get the EAB contact from the EAB database. |
| 11023 | */ |
| 11024 | @Override |
| 11025 | public String getContactFromEab(String contact) { |
| 11026 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab"); |
| 11027 | enforceModifyPermission(); |
| 11028 | final long identity = Binder.clearCallingIdentity(); |
| 11029 | try { |
| 11030 | return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact); |
| 11031 | } finally { |
| 11032 | Binder.restoreCallingIdentity(identity); |
| 11033 | } |
| 11034 | } |
| 11035 | |
| 11036 | /** |
Calvin Pan | a143432 | 2021-07-01 19:27:01 +0800 | [diff] [blame] | 11037 | * Get the EAB capability from the EAB database. |
| 11038 | */ |
| 11039 | @Override |
| 11040 | public String getCapabilityFromEab(String contact) { |
| 11041 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab"); |
| 11042 | enforceModifyPermission(); |
| 11043 | final long identity = Binder.clearCallingIdentity(); |
| 11044 | try { |
| 11045 | return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact); |
| 11046 | } finally { |
| 11047 | Binder.restoreCallingIdentity(identity); |
| 11048 | } |
| 11049 | } |
| 11050 | |
| 11051 | /** |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 11052 | * Remove the EAB contacts from the EAB database. |
| 11053 | */ |
| 11054 | @Override |
| 11055 | public int removeContactFromEab(int subId, String contacts) { |
| 11056 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab"); |
| 11057 | enforceModifyPermission(); |
| 11058 | final long identity = Binder.clearCallingIdentity(); |
| 11059 | try { |
| 11060 | return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext()); |
| 11061 | } finally { |
| 11062 | Binder.restoreCallingIdentity(identity); |
| 11063 | } |
| 11064 | } |
| 11065 | |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11066 | @Override |
James.cf Lin | 4b784aa | 2021-01-31 03:25:15 +0800 | [diff] [blame] | 11067 | public boolean getDeviceUceEnabled() { |
| 11068 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled"); |
| 11069 | final long identity = Binder.clearCallingIdentity(); |
| 11070 | try { |
| 11071 | return mApp.getDeviceUceEnabled(); |
| 11072 | } finally { |
| 11073 | Binder.restoreCallingIdentity(identity); |
| 11074 | } |
| 11075 | } |
| 11076 | |
| 11077 | @Override |
| 11078 | public void setDeviceUceEnabled(boolean isEnabled) { |
| 11079 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled"); |
| 11080 | final long identity = Binder.clearCallingIdentity(); |
| 11081 | try { |
| 11082 | mApp.setDeviceUceEnabled(isEnabled); |
| 11083 | } finally { |
| 11084 | Binder.restoreCallingIdentity(identity); |
| 11085 | } |
| 11086 | } |
| 11087 | |
Brad Ebinger | 14d467f | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 11088 | /** |
| 11089 | * Add new feature tags to the Set used to calculate the capabilities in PUBLISH. |
| 11090 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 11091 | */ |
| 11092 | // Used for SHELL command only right now. |
| 11093 | @Override |
| 11094 | public RcsContactUceCapability addUceRegistrationOverrideShell(int subId, |
| 11095 | List<String> featureTags) { |
| 11096 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11097 | "addUceRegistrationOverrideShell"); |
| 11098 | final long identity = Binder.clearCallingIdentity(); |
| 11099 | try { |
| 11100 | return mApp.imsRcsController.addUceRegistrationOverrideShell(subId, |
| 11101 | new ArraySet<>(featureTags)); |
| 11102 | } catch (ImsException e) { |
| 11103 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 11104 | } finally { |
| 11105 | Binder.restoreCallingIdentity(identity); |
| 11106 | } |
| 11107 | } |
| 11108 | |
| 11109 | /** |
| 11110 | * Remove existing 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 removeUceRegistrationOverrideShell(int subId, |
| 11116 | List<String> featureTags) { |
| 11117 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11118 | "removeUceRegistrationOverrideShell"); |
| 11119 | final long identity = Binder.clearCallingIdentity(); |
| 11120 | try { |
| 11121 | return mApp.imsRcsController.removeUceRegistrationOverrideShell(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 | * Clear all overrides in 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 clearUceRegistrationOverrideShell(int subId) { |
| 11137 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11138 | "clearUceRegistrationOverrideShell"); |
| 11139 | final long identity = Binder.clearCallingIdentity(); |
| 11140 | try { |
| 11141 | return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId); |
| 11142 | } catch (ImsException e) { |
| 11143 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 11144 | } finally { |
| 11145 | Binder.restoreCallingIdentity(identity); |
| 11146 | } |
| 11147 | } |
| 11148 | |
| 11149 | /** |
| 11150 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 11151 | */ |
| 11152 | // Used for SHELL command only right now. |
| 11153 | @Override |
| 11154 | public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) { |
| 11155 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11156 | "getLatestRcsContactUceCapabilityShell"); |
| 11157 | final long identity = Binder.clearCallingIdentity(); |
| 11158 | try { |
| 11159 | return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId); |
| 11160 | } catch (ImsException e) { |
| 11161 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 11162 | } finally { |
| 11163 | Binder.restoreCallingIdentity(identity); |
| 11164 | } |
| 11165 | } |
| 11166 | |
| 11167 | /** |
| 11168 | * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the |
| 11169 | * device does not have an active PUBLISH. |
| 11170 | */ |
| 11171 | // Used for SHELL command only right now. |
| 11172 | @Override |
| 11173 | public String getLastUcePidfXmlShell(int subId) { |
| 11174 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml"); |
| 11175 | final long identity = Binder.clearCallingIdentity(); |
| 11176 | try { |
| 11177 | return mApp.imsRcsController.getLastUcePidfXmlShell(subId); |
| 11178 | } catch (ImsException e) { |
| 11179 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 11180 | } finally { |
| 11181 | Binder.restoreCallingIdentity(identity); |
| 11182 | } |
| 11183 | } |
| 11184 | |
James.cf Lin | e8713a4 | 2021-04-29 16:04:26 +0800 | [diff] [blame] | 11185 | /** |
| 11186 | * Remove UCE requests cannot be sent to the network status. |
| 11187 | */ |
| 11188 | // Used for SHELL command only right now. |
| 11189 | @Override |
| 11190 | public boolean removeUceRequestDisallowedStatus(int subId) { |
| 11191 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus"); |
| 11192 | final long identity = Binder.clearCallingIdentity(); |
| 11193 | try { |
| 11194 | return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId); |
| 11195 | } catch (ImsException e) { |
| 11196 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 11197 | } finally { |
| 11198 | Binder.restoreCallingIdentity(identity); |
| 11199 | } |
| 11200 | } |
| 11201 | |
James.cf Lin | 18bb900 | 2021-05-25 01:37:38 +0800 | [diff] [blame] | 11202 | /** |
| 11203 | * Remove UCE requests cannot be sent to the network status. |
| 11204 | */ |
| 11205 | // Used for SHELL command only. |
| 11206 | @Override |
| 11207 | public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) { |
| 11208 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout"); |
| 11209 | final long identity = Binder.clearCallingIdentity(); |
| 11210 | try { |
| 11211 | return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs); |
| 11212 | } catch (ImsException e) { |
| 11213 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 11214 | } finally { |
| 11215 | Binder.restoreCallingIdentity(identity); |
| 11216 | } |
| 11217 | } |
Brad Ebinger | 14d467f | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 11218 | |
James.cf Lin | 4b784aa | 2021-01-31 03:25:15 +0800 | [diff] [blame] | 11219 | @Override |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11220 | public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request, |
| 11221 | String callingPackage) { |
| 11222 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 11223 | mApp, subId, "setSignalStrengthUpdateRequest"); |
| 11224 | |
| 11225 | final int callingUid = Binder.getCallingUid(); |
| 11226 | // Verify that tha callingPackage belongs to the calling UID |
| 11227 | mApp.getSystemService(AppOpsManager.class) |
| 11228 | .checkPackage(callingUid, callingPackage); |
| 11229 | |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 11230 | validateSignalStrengthUpdateRequest(mApp, request, callingUid); |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11231 | |
| 11232 | final long identity = Binder.clearCallingIdentity(); |
| 11233 | try { |
| 11234 | Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST, |
| 11235 | new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId); |
| 11236 | |
| 11237 | if (result instanceof IllegalStateException) { |
| 11238 | throw (IllegalStateException) result; |
| 11239 | } |
| 11240 | } finally { |
| 11241 | Binder.restoreCallingIdentity(identity); |
| 11242 | } |
| 11243 | } |
| 11244 | |
| 11245 | @Override |
| 11246 | public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request, |
| 11247 | String callingPackage) { |
| 11248 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 11249 | mApp, subId, "clearSignalStrengthUpdateRequest"); |
| 11250 | |
| 11251 | final int callingUid = Binder.getCallingUid(); |
| 11252 | // Verify that tha callingPackage belongs to the calling UID |
| 11253 | mApp.getSystemService(AppOpsManager.class) |
| 11254 | .checkPackage(callingUid, callingPackage); |
| 11255 | |
| 11256 | final long identity = Binder.clearCallingIdentity(); |
| 11257 | try { |
| 11258 | Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST, |
| 11259 | new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId); |
| 11260 | |
| 11261 | if (result instanceof IllegalStateException) { |
| 11262 | throw (IllegalStateException) result; |
| 11263 | } |
| 11264 | } finally { |
| 11265 | Binder.restoreCallingIdentity(identity); |
| 11266 | } |
| 11267 | } |
| 11268 | |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 11269 | private static void validateSignalStrengthUpdateRequest(Context context, |
| 11270 | SignalStrengthUpdateRequest request, int callingUid) { |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11271 | if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) { |
| 11272 | // phone/system process do not have further restriction on request |
| 11273 | return; |
| 11274 | } |
| 11275 | |
| 11276 | // Applications has restrictions on how to use the request: |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 11277 | // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11278 | if (request.isSystemThresholdReportingRequestedWhileIdle()) { |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 11279 | context.enforceCallingOrSelfPermission( |
| 11280 | android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH, |
| 11281 | "validateSignalStrengthUpdateRequest"); |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11282 | } |
| 11283 | |
| 11284 | for (SignalThresholdInfo info : request.getSignalThresholdInfos()) { |
| 11285 | // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled. |
| 11286 | if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED |
| 11287 | || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED |
| 11288 | || info.isEnabled()) { |
| 11289 | throw new IllegalArgumentException( |
| 11290 | "Only system can set hide fields in SignalThresholdInfo"); |
| 11291 | } |
| 11292 | |
| 11293 | // Thresholds length for each RAN need in range. This has been validated in |
| 11294 | // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method |
| 11295 | // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds |
| 11296 | final int[] thresholds = info.getThresholds(); |
| 11297 | Objects.requireNonNull(thresholds); |
| 11298 | if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed() |
| 11299 | || thresholds.length |
| 11300 | > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) { |
| 11301 | throw new IllegalArgumentException( |
| 11302 | "thresholds length is out of range: " + thresholds.length); |
| 11303 | } |
| 11304 | } |
| 11305 | } |
SongFerngWang | 8236caa | 2021-01-17 21:51:44 +0800 | [diff] [blame] | 11306 | |
| 11307 | /** |
| 11308 | * Gets the current phone capability. |
| 11309 | * |
| 11310 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 11311 | * @return the PhoneCapability which describes the data connection capability of modem. |
| 11312 | * It's used to evaluate possible phone config change, for example from single |
| 11313 | * SIM device to multi-SIM device. |
| 11314 | */ |
| 11315 | @Override |
| 11316 | public PhoneCapability getPhoneCapability() { |
| 11317 | enforceReadPrivilegedPermission("getPhoneCapability"); |
| 11318 | final long identity = Binder.clearCallingIdentity(); |
| 11319 | try { |
| 11320 | return mPhoneConfigurationManager.getCurrentPhoneCapability(); |
| 11321 | } finally { |
| 11322 | Binder.restoreCallingIdentity(identity); |
| 11323 | } |
| 11324 | } |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 11325 | |
| 11326 | /** |
| 11327 | * Prepare TelephonyManager for an unattended reboot. The reboot is |
| 11328 | * required to be done shortly after the API is invoked. |
| 11329 | */ |
| 11330 | @Override |
| 11331 | @TelephonyManager.PrepareUnattendedRebootResult |
| 11332 | public int prepareForUnattendedReboot() { |
Rafael Higuera Silva | d963064 | 2021-09-20 15:32:01 +0000 | [diff] [blame] | 11333 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 11334 | enforceRebootPermission(); |
| 11335 | |
| 11336 | final long identity = Binder.clearCallingIdentity(); |
| 11337 | try { |
Rafael Higuera Silva | d963064 | 2021-09-20 15:32:01 +0000 | [diff] [blame] | 11338 | return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 11339 | } finally { |
| 11340 | Binder.restoreCallingIdentity(identity); |
| 11341 | } |
| 11342 | } |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 11343 | |
| 11344 | /** |
| 11345 | * Request to get the current slicing configuration including URSP rules and |
| 11346 | * NSSAIs (configured, allowed and rejected). |
| 11347 | * |
| 11348 | * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission. |
| 11349 | */ |
| 11350 | @Override |
| 11351 | public void getSlicingConfig(ResultReceiver callback) { |
Hongbo Zeng | 1b2063d | 2022-02-21 01:33:03 +0000 | [diff] [blame] | 11352 | TelephonyPermissions |
| 11353 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 11354 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, "getSlicingConfig"); |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 11355 | |
| 11356 | final long identity = Binder.clearCallingIdentity(); |
| 11357 | try { |
| 11358 | Phone phone = getDefaultPhone(); |
| 11359 | sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null); |
| 11360 | } finally { |
| 11361 | Binder.restoreCallingIdentity(identity); |
| 11362 | } |
| 11363 | } |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 11364 | |
| 11365 | /** |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 11366 | * Check whether the given premium capability is available for purchase from the carrier. |
| 11367 | * |
| 11368 | * @param capability The premium capability to check. |
| 11369 | * @param subId The subId to check the premium capability for. |
| 11370 | * |
| 11371 | * @return Whether the given premium capability is available to purchase. |
| 11372 | */ |
| 11373 | @Override |
| 11374 | public boolean isPremiumCapabilityAvailableForPurchase(int capability, int subId) { |
| 11375 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 11376 | mApp, "isPremiumCapabilityAvailableForPurchase")) { |
| 11377 | log("Premium capability " |
| 11378 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 11379 | + " is not available for purchase due to missing permissions."); |
| 11380 | throw new SecurityException("isPremiumCapabilityAvailableForPurchase requires " |
| 11381 | + "permission READ_BASIC_PHONE_STATE."); |
| 11382 | } |
| 11383 | |
| 11384 | Phone phone = getPhone(subId); |
Thomas Nguyen | 7216ed6 | 2022-11-29 16:45:31 -0800 | [diff] [blame] | 11385 | if (phone == null) { |
| 11386 | loge("isPremiumCapabilityAvailableForPurchase: phone is null, subId=" + subId); |
| 11387 | return false; |
| 11388 | } |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 11389 | final long identity = Binder.clearCallingIdentity(); |
| 11390 | try { |
Sarah Chin | 46355ba | 2022-11-01 23:51:16 -0700 | [diff] [blame] | 11391 | return SlicePurchaseController.getInstance(phone) |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 11392 | .isPremiumCapabilityAvailableForPurchase(capability); |
| 11393 | } finally { |
| 11394 | Binder.restoreCallingIdentity(identity); |
| 11395 | } |
| 11396 | } |
| 11397 | |
| 11398 | /** |
| 11399 | * Purchase the given premium capability from the carrier. |
| 11400 | * |
| 11401 | * @param capability The premium capability to purchase. |
| 11402 | * @param callback The result of the purchase request. |
| 11403 | * @param subId The subId to purchase the premium capability for. |
| 11404 | */ |
| 11405 | @Override |
| 11406 | public void purchasePremiumCapability(int capability, IIntegerConsumer callback, int subId) { |
| 11407 | log("purchasePremiumCapability: capability=" |
| 11408 | + TelephonyManager.convertPremiumCapabilityToString(capability) + ", caller=" |
| 11409 | + getCurrentPackageName()); |
| 11410 | |
| 11411 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 11412 | mApp, "purchasePremiumCapability")) { |
| 11413 | log("purchasePremiumCapability " |
| 11414 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 11415 | + " failed due to missing permissions."); |
| 11416 | throw new SecurityException("purchasePremiumCapability requires permission " |
| 11417 | + "READ_BASIC_PHONE_STATE."); |
| 11418 | } |
| 11419 | |
| 11420 | Phone phone = getPhone(subId); |
Sarah Chin | 1969411 | 2022-12-06 15:41:37 -0800 | [diff] [blame] | 11421 | if (phone == null) { |
| 11422 | try { |
| 11423 | int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_REQUEST_FAILED; |
| 11424 | callback.accept(result); |
| 11425 | loge("purchasePremiumCapability: phone is null, subId=" + subId); |
| 11426 | } catch (RemoteException e) { |
| 11427 | String logStr = "Purchase premium capability " |
| 11428 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 11429 | + " failed due to RemoteException handling null phone: " + e; |
| 11430 | if (DBG) log(logStr); |
| 11431 | AnomalyReporter.reportAnomaly( |
| 11432 | UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr); |
| 11433 | } |
| 11434 | return; |
| 11435 | } |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 11436 | String appName; |
| 11437 | try { |
| 11438 | appName = mApp.getPackageManager().getApplicationLabel(mApp.getPackageManager() |
| 11439 | .getApplicationInfo(getCurrentPackageName(), 0)).toString(); |
| 11440 | } catch (PackageManager.NameNotFoundException e) { |
| 11441 | appName = "An application"; |
| 11442 | } |
| 11443 | sendRequestAsync(CMD_PURCHASE_PREMIUM_CAPABILITY, |
| 11444 | new PurchasePremiumCapabilityArgument(capability, appName, callback), phone, null); |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 11445 | } |
| 11446 | |
| 11447 | /** |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 11448 | * Register an IMS connection state callback |
| 11449 | */ |
| 11450 | @Override |
Hunsuk Choi | 89bd22c | 2021-11-01 13:04:54 +0000 | [diff] [blame] | 11451 | public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb, |
| 11452 | String callingPackage) { |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 11453 | if (feature == ImsFeature.FEATURE_MMTEL) { |
| 11454 | // ImsMmTelManager |
| 11455 | // The following also checks READ_PRIVILEGED_PHONE_STATE. |
| 11456 | TelephonyPermissions |
| 11457 | .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 11458 | mApp, subId, "registerImsStateCallback"); |
| 11459 | } else if (feature == ImsFeature.FEATURE_RCS) { |
| 11460 | // ImsRcsManager or SipDelegateManager |
| 11461 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 11462 | Binder.getCallingUid(), "registerImsStateCallback", |
| 11463 | Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
| 11464 | Manifest.permission.READ_PRECISE_PHONE_STATE, |
| 11465 | Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE, |
| 11466 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
| 11467 | } |
| 11468 | |
| 11469 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 11470 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 11471 | "IMS not available on device."); |
| 11472 | } |
| 11473 | |
| 11474 | if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) { |
| 11475 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 11476 | } |
| 11477 | |
| 11478 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 11479 | if (controller == null) { |
| 11480 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 11481 | "IMS not available on device."); |
| 11482 | } |
| 11483 | |
Hunsuk Choi | 89bd22c | 2021-11-01 13:04:54 +0000 | [diff] [blame] | 11484 | if (callingPackage == null) { |
| 11485 | callingPackage = getCurrentPackageName(); |
| 11486 | } |
| 11487 | |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 11488 | final long token = Binder.clearCallingIdentity(); |
| 11489 | try { |
| 11490 | int slotId = getSlotIndexOrException(subId); |
Hunsuk Choi | 89bd22c | 2021-11-01 13:04:54 +0000 | [diff] [blame] | 11491 | controller.registerImsStateCallback(subId, feature, cb, callingPackage); |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 11492 | } catch (ImsException e) { |
| 11493 | throw new ServiceSpecificException(e.getCode()); |
| 11494 | } finally { |
| 11495 | Binder.restoreCallingIdentity(token); |
| 11496 | } |
| 11497 | } |
| 11498 | |
| 11499 | /** |
| 11500 | * Unregister an IMS connection state callback |
| 11501 | */ |
| 11502 | @Override |
| 11503 | public void unregisterImsStateCallback(IImsStateCallback cb) { |
| 11504 | final long token = Binder.clearCallingIdentity(); |
| 11505 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 11506 | if (controller == null) { |
| 11507 | return; |
| 11508 | } |
| 11509 | try { |
| 11510 | controller.unregisterImsStateCallback(cb); |
| 11511 | } finally { |
| 11512 | Binder.restoreCallingIdentity(token); |
| 11513 | } |
| 11514 | } |
Sooraj Sasindran | fae41b3 | 2021-10-26 02:10:05 -0700 | [diff] [blame] | 11515 | |
| 11516 | /** |
| 11517 | * @return {@CellIdentity} last known cell identity {@CellIdentity}. |
| 11518 | * |
| 11519 | * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and |
| 11520 | * com.android.phone.permission.ACCESS_LAST_KNOWN_CELL_ID, otherwise throws |
| 11521 | * SecurityException. |
| 11522 | * If there is current registered network this value will be same as the registered cell |
| 11523 | * identity. If the device goes out of service the previous cell identity is cached and |
| 11524 | * will be returned. If the cache age of the Cell identity is more than 24 hours |
| 11525 | * it will be cleared and null will be returned. |
| 11526 | * |
| 11527 | */ |
| 11528 | @Override |
| 11529 | public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage, |
| 11530 | String callingFeatureId) { |
| 11531 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 11532 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 11533 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 11534 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 11535 | .setCallingPackage(callingPackage) |
| 11536 | .setCallingFeatureId(callingFeatureId) |
| 11537 | .setCallingPid(Binder.getCallingPid()) |
| 11538 | .setCallingUid(Binder.getCallingUid()) |
| 11539 | .setMethod("getLastKnownCellIdentity") |
| 11540 | .setLogAsInfo(true) |
| 11541 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 11542 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 11543 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 11544 | .build()); |
| 11545 | |
| 11546 | boolean hasFinePermission = |
| 11547 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 11548 | if (!hasFinePermission |
| 11549 | || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) { |
| 11550 | throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION " |
Rambo Wang | 918993a | 2022-04-27 09:08:36 -0700 | [diff] [blame] | 11551 | + "and ACCESS_LAST_KNOWN_CELL_ID permission."); |
Sooraj Sasindran | fae41b3 | 2021-10-26 02:10:05 -0700 | [diff] [blame] | 11552 | } |
| 11553 | |
| 11554 | final long identity = Binder.clearCallingIdentity(); |
| 11555 | try { |
| 11556 | Phone phone = getPhone(subId); |
| 11557 | if (phone == null) return null; |
| 11558 | ServiceStateTracker sst = phone.getServiceStateTracker(); |
| 11559 | if (sst == null) return null; |
| 11560 | return sst.getLastKnownCellIdentity(); |
| 11561 | } finally { |
| 11562 | Binder.restoreCallingIdentity(identity); |
| 11563 | } |
| 11564 | } |
Jack Yu | 4c0a550 | 2021-12-03 23:58:26 -0800 | [diff] [blame] | 11565 | |
jimsun | 3b9ccac | 2021-10-26 15:01:23 +0800 | [diff] [blame] | 11566 | /** |
| 11567 | * Sets the modem service class Name that Telephony will bind to. |
| 11568 | * |
| 11569 | * @param serviceName The class name of the modem service. |
| 11570 | * @return true if the operation is succeed, otherwise false. |
| 11571 | */ |
| 11572 | public boolean setModemService(String serviceName) { |
| 11573 | Log.d(LOG_TAG, "setModemService - " + serviceName); |
| 11574 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService"); |
| 11575 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 11576 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 11577 | "setModemService"); |
| 11578 | return mPhoneConfigurationManager.setModemService(serviceName); |
| 11579 | } |
| 11580 | |
| 11581 | /** |
| 11582 | * Return the class name of the currently bounded modem service. |
| 11583 | * |
| 11584 | * @return the class name of the modem service. |
| 11585 | */ |
| 11586 | public String getModemService() { |
| 11587 | String result; |
| 11588 | Log.d(LOG_TAG, "getModemService"); |
| 11589 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService"); |
| 11590 | TelephonyPermissions |
| 11591 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 11592 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 11593 | "getModemService"); |
| 11594 | result = mPhoneConfigurationManager.getModemService(); |
| 11595 | Log.d(LOG_TAG, "result = " + result); |
| 11596 | return result; |
| 11597 | } |
Hunter Knepshield | 2b076fa | 2022-01-19 02:26:22 -0800 | [diff] [blame] | 11598 | |
| 11599 | @Override |
| 11600 | public void setVoiceServiceStateOverride(int subId, boolean hasService, String callingPackage) { |
| 11601 | // Only telecom (and shell, for CTS purposes) is allowed to call this method. |
| 11602 | mApp.enforceCallingOrSelfPermission( |
| 11603 | permission.BIND_TELECOM_CONNECTION_SERVICE, "setVoiceServiceStateOverride"); |
| 11604 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 11605 | |
| 11606 | final long identity = Binder.clearCallingIdentity(); |
| 11607 | try { |
| 11608 | Phone phone = getPhone(subId); |
| 11609 | if (phone == null) return; |
| 11610 | phone.setVoiceServiceStateOverride(hasService); |
| 11611 | } finally { |
| 11612 | Binder.restoreCallingIdentity(identity); |
| 11613 | } |
| 11614 | } |
Muralidhar Reddy | 4e5a801 | 2022-05-11 14:49:00 +0000 | [diff] [blame] | 11615 | |
| 11616 | /** |
| 11617 | * set removable eSIM as default eUICC. |
| 11618 | * |
| 11619 | * @hide |
| 11620 | */ |
| 11621 | @Override |
| 11622 | public void setRemovableEsimAsDefaultEuicc(boolean isDefault, String callingPackage) { |
| 11623 | enforceModifyPermission(); |
| 11624 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 11625 | |
| 11626 | final long identity = Binder.clearCallingIdentity(); |
| 11627 | try { |
| 11628 | UiccController.getInstance().setRemovableEsimAsDefaultEuicc(isDefault); |
| 11629 | } finally { |
| 11630 | Binder.restoreCallingIdentity(identity); |
| 11631 | } |
| 11632 | } |
| 11633 | |
| 11634 | /** |
| 11635 | * Returns whether the removable eSIM is default eUICC or not. |
| 11636 | * |
| 11637 | * @hide |
| 11638 | */ |
| 11639 | @Override |
| 11640 | public boolean isRemovableEsimDefaultEuicc(String callingPackage) { |
| 11641 | enforceReadPrivilegedPermission("isRemovableEsimDefaultEuicc"); |
| 11642 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 11643 | |
| 11644 | final long identity = Binder.clearCallingIdentity(); |
| 11645 | try { |
| 11646 | return UiccController.getInstance().isRemovableEsimDefaultEuicc(); |
| 11647 | } finally { |
| 11648 | Binder.restoreCallingIdentity(identity); |
| 11649 | } |
| 11650 | } |
| 11651 | |
Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame] | 11652 | /** |
| 11653 | * Get the component name of the default app to direct respond-via-message intent for the |
| 11654 | * user associated with this subscription, update the cache if there is no respond-via-message |
| 11655 | * application currently configured for this user. |
| 11656 | * @return component name of the app and class to direct Respond Via Message intent to, or |
| 11657 | * {@code null} if the functionality is not supported. |
| 11658 | * @hide |
| 11659 | */ |
| 11660 | @Override |
| 11661 | public @Nullable ComponentName getDefaultRespondViaMessageApplication(int subId, |
| 11662 | boolean updateIfNeeded) { |
| 11663 | enforceInteractAcrossUsersPermission("getDefaultRespondViaMessageApplication"); |
Muralidhar Reddy | 4e5a801 | 2022-05-11 14:49:00 +0000 | [diff] [blame] | 11664 | |
Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame] | 11665 | Context context = getPhone(subId).getContext(); |
| 11666 | UserHandle userHandle = null; |
| 11667 | final long identity = Binder.clearCallingIdentity(); |
| 11668 | try { |
| 11669 | userHandle = TelephonyUtils.getSubscriptionUserHandle(context, subId); |
| 11670 | } finally { |
| 11671 | Binder.restoreCallingIdentity(identity); |
| 11672 | } |
| 11673 | return SmsApplication.getDefaultRespondViaMessageApplicationAsUser(context, |
| 11674 | updateIfNeeded, userHandle); |
| 11675 | } |
Jack Yu | f5badd9 | 2022-12-08 00:50:53 -0800 | [diff] [blame] | 11676 | |
| 11677 | /** |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 11678 | * Set whether the device is able to connect with null ciphering or integrity |
| 11679 | * algorithms. This is a global setting and will apply to all active subscriptions |
| 11680 | * and all new subscriptions after this. |
| 11681 | * |
| 11682 | * @param enabled when true, null cipher and integrity algorithms are allowed. |
| 11683 | * @hide |
| 11684 | */ |
| 11685 | @Override |
| 11686 | @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 11687 | public void setNullCipherAndIntegrityEnabled(boolean enabled) { |
| 11688 | enforceModifyPermission(); |
| 11689 | checkForNullCipherAndIntegritySupport(); |
| 11690 | |
| 11691 | // Persist the state of our preference. Each GsmCdmaPhone instance is responsible |
| 11692 | // for listening to these preference changes and applying them immediately. |
| 11693 | SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 11694 | editor.putBoolean(Phone.PREF_NULL_CIPHER_AND_INTEGRITY_ENABLED, enabled); |
| 11695 | editor.apply(); |
| 11696 | |
| 11697 | for (Phone phone: PhoneFactory.getPhones()) { |
| 11698 | phone.handleNullCipherEnabledChange(); |
| 11699 | } |
| 11700 | } |
| 11701 | |
| 11702 | |
| 11703 | /** |
| 11704 | * Get whether the device is able to connect with null ciphering or integrity |
| 11705 | * algorithms. Note that this retrieves the phone-global preference and not |
| 11706 | * the state of the radio. |
| 11707 | * |
| 11708 | * @throws SecurityException if {@link permission#MODIFY_PHONE_STATE} is not satisfied |
| 11709 | * @throws UnsupportedOperationException if the device does not support the minimum HAL |
| 11710 | * version for this feature. |
| 11711 | * @hide |
| 11712 | */ |
| 11713 | @Override |
| 11714 | @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) |
| 11715 | public boolean isNullCipherAndIntegrityPreferenceEnabled() { |
| 11716 | enforceReadPermission(); |
| 11717 | checkForNullCipherAndIntegritySupport(); |
| 11718 | return getDefaultPhone().getNullCipherAndIntegrityEnabledPreference(); |
| 11719 | } |
| 11720 | |
| 11721 | private void checkForNullCipherAndIntegritySupport() { |
| 11722 | if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_NULL_CIPHER_AND_INTEGRITY_VERSION) { |
| 11723 | throw new UnsupportedOperationException( |
| 11724 | "Null cipher and integrity operations require HAL 2.1 or above"); |
| 11725 | } |
| 11726 | } |
| 11727 | |
| 11728 | /** |
Jack Yu | f5badd9 | 2022-12-08 00:50:53 -0800 | [diff] [blame] | 11729 | * Get the SIM state for the slot index. |
| 11730 | * For Remote-SIMs, this method returns {@link IccCardConstants.State#UNKNOWN} |
| 11731 | * |
| 11732 | * @return SIM state as the ordinal of {@link IccCardConstants.State} |
| 11733 | */ |
| 11734 | @Override |
| 11735 | @SimState |
| 11736 | public int getSimStateForSlotIndex(int slotIndex) { |
| 11737 | IccCardConstants.State simState; |
| 11738 | if (slotIndex < 0) { |
| 11739 | simState = IccCardConstants.State.UNKNOWN; |
| 11740 | } else { |
| 11741 | Phone phone = null; |
| 11742 | try { |
| 11743 | phone = PhoneFactory.getPhone(slotIndex); |
| 11744 | } catch (IllegalStateException e) { |
| 11745 | // ignore |
| 11746 | } |
| 11747 | if (phone == null) { |
| 11748 | simState = IccCardConstants.State.UNKNOWN; |
| 11749 | } else { |
| 11750 | IccCard icc = phone.getIccCard(); |
| 11751 | if (icc == null) { |
| 11752 | simState = IccCardConstants.State.UNKNOWN; |
| 11753 | } else { |
| 11754 | simState = icc.getState(); |
| 11755 | } |
| 11756 | } |
| 11757 | } |
| 11758 | return simState.ordinal(); |
| 11759 | } |
Hui Wang | 9b5793a | 2022-12-05 14:38:06 -0600 | [diff] [blame] | 11760 | |
| 11761 | /** |
| 11762 | * Get current cell broadcast ranges. |
| 11763 | */ |
| 11764 | @Override |
| 11765 | @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS) |
| 11766 | public List<CellBroadcastIdRange> getCellBroadcastIdRanges(int subId) { |
| 11767 | mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS, |
| 11768 | "getCellBroadcastIdRanges"); |
| 11769 | final long identity = Binder.clearCallingIdentity(); |
| 11770 | try { |
| 11771 | return getPhone(subId).getCellBroadcastIdRanges(); |
| 11772 | } finally { |
| 11773 | Binder.restoreCallingIdentity(identity); |
| 11774 | } |
| 11775 | } |
| 11776 | |
| 11777 | /** |
| 11778 | * Set reception of cell broadcast messages with the list of the given ranges |
| 11779 | * |
| 11780 | * @param ranges the list of {@link CellBroadcastIdRange} to be enabled |
| 11781 | */ |
| 11782 | @Override |
| 11783 | @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS) |
| 11784 | public void setCellBroadcastIdRanges(int subId, @NonNull List<CellBroadcastIdRange> ranges, |
| 11785 | @Nullable IIntegerConsumer callback) { |
| 11786 | mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS, |
| 11787 | "setCellBroadcastIdRanges"); |
| 11788 | final long identity = Binder.clearCallingIdentity(); |
| 11789 | try { |
| 11790 | Phone phone = getPhoneFromSubId(subId); |
| 11791 | if (DBG) { |
| 11792 | log("setCellBroadcastIdRanges for subId :" + subId + ", phone:" + phone); |
| 11793 | } |
| 11794 | phone.setCellBroadcastIdRanges(ranges, result -> { |
| 11795 | if (callback != null) { |
| 11796 | try { |
| 11797 | callback.accept(result); |
| 11798 | } catch (RemoteException e) { |
| 11799 | Log.w(LOG_TAG, "setCellBroadcastIdRanges: callback not available."); |
| 11800 | } |
| 11801 | } |
| 11802 | }); |
| 11803 | } finally { |
| 11804 | Binder.restoreCallingIdentity(identity); |
| 11805 | } |
| 11806 | } |
| 11807 | } |