Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2006 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.phone; |
| 18 | |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 19 | import static android.content.pm.PackageManager.PERMISSION_GRANTED; |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 20 | import static android.telephony.TelephonyManager.HAL_SERVICE_NETWORK; |
jimsun | f9ec162 | 2022-09-13 21:18:43 +0800 | [diff] [blame] | 21 | import static android.telephony.TelephonyManager.HAL_SERVICE_RADIO; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 22 | |
Shuo Qian | ccbaf74 | 2021-02-22 18:32:21 -0800 | [diff] [blame] | 23 | import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_CDMA; |
| 24 | import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_GSM; |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 25 | import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_IMS; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 26 | import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY; |
joonhunshin | 3e15424 | 2021-09-17 06:33:39 +0000 | [diff] [blame] | 27 | import static com.android.internal.telephony.TelephonyStatsLog.RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 28 | |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 29 | import android.Manifest; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 30 | import android.Manifest.permission; |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 31 | import android.annotation.NonNull; |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 32 | import android.annotation.Nullable; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 33 | import android.annotation.RequiresPermission; |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 34 | import android.app.ActivityManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 35 | import android.app.AppOpsManager; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 36 | import android.app.PendingIntent; |
Tyler Gunn | 64144d9 | 2022-03-17 14:16:41 -0700 | [diff] [blame] | 37 | import android.app.PropertyInvalidatedCache; |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 38 | import android.app.compat.CompatChanges; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 39 | import android.app.role.RoleManager; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 40 | import android.compat.annotation.ChangeId; |
| 41 | import android.compat.annotation.EnabledSince; |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 42 | import android.content.ComponentName; |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 43 | import android.content.ContentResolver; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 44 | import android.content.Context; |
| 45 | import android.content.Intent; |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 46 | import android.content.SharedPreferences; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 47 | import android.content.pm.ComponentInfo; |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 48 | import android.content.pm.PackageManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 49 | import android.net.Uri; |
| 50 | import android.os.AsyncResult; |
| 51 | import android.os.Binder; |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 52 | import android.os.Build; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 53 | import android.os.Bundle; |
| 54 | import android.os.Handler; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 55 | import android.os.IBinder; |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 56 | import android.os.LocaleList; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 57 | import android.os.Looper; |
| 58 | import android.os.Message; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 59 | import android.os.Messenger; |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 60 | import android.os.ParcelFileDescriptor; |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 61 | import android.os.ParcelUuid; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 62 | import android.os.PersistableBundle; |
Shuo Qian | cd19c46 | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 63 | import android.os.Process; |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 64 | import android.os.RemoteException; |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 65 | import android.os.ResultReceiver; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 66 | import android.os.ServiceSpecificException; |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 67 | import android.os.SystemClock; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 68 | import android.os.UserHandle; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 69 | import android.os.UserManager; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 70 | import android.os.WorkSource; |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 71 | import android.preference.PreferenceManager; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 72 | import android.provider.DeviceConfig; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 73 | import android.provider.Settings; |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 74 | import android.provider.Telephony; |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 75 | import android.service.carrier.CarrierIdentifier; |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 76 | import android.sysprop.TelephonyProperties; |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 77 | import android.telecom.PhoneAccount; |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 78 | import android.telecom.PhoneAccountHandle; |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 79 | import android.telecom.TelecomManager; |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 80 | import android.telephony.AccessNetworkConstants; |
| 81 | import android.telephony.ActivityStatsTechSpecificInfo; |
Chen Xu | 227e06f | 2019-09-26 22:48:11 -0700 | [diff] [blame] | 82 | import android.telephony.Annotation.ApnType; |
Jack Yu | 0eda684 | 2022-04-18 00:34:46 -0700 | [diff] [blame] | 83 | import android.telephony.Annotation.DataActivityType; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 84 | import android.telephony.Annotation.ThermalMitigationResult; |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 85 | import android.telephony.AnomalyReporter; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 86 | import android.telephony.CallForwardingInfo; |
Junda Liu | 12f7d80 | 2015-05-01 12:06:44 -0700 | [diff] [blame] | 87 | import android.telephony.CarrierConfigManager; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 88 | import android.telephony.CarrierRestrictionRules; |
Hui Wang | 9b5793a | 2022-12-05 14:38:06 -0600 | [diff] [blame] | 89 | import android.telephony.CellBroadcastIdRange; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 90 | import android.telephony.CellIdentity; |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 91 | import android.telephony.CellIdentityCdma; |
| 92 | import android.telephony.CellIdentityGsm; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 93 | import android.telephony.CellInfo; |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 94 | import android.telephony.CellInfoGsm; |
| 95 | import android.telephony.CellInfoWcdma; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 96 | import android.telephony.ClientRequestStats; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 97 | import android.telephony.DataThrottlingRequest; |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 98 | import android.telephony.IBootstrapAuthenticationCallback; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 99 | import android.telephony.ICellInfoCallback; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 100 | import android.telephony.IccOpenLogicalChannelResponse; |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 101 | import android.telephony.LocationAccessPolicy; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 102 | import android.telephony.ModemActivityInfo; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 103 | import android.telephony.NeighboringCellInfo; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 104 | import android.telephony.NetworkScanRequest; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 105 | import android.telephony.PhoneCapability; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 106 | import android.telephony.PhoneNumberRange; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 107 | import android.telephony.RadioAccessFamily; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 108 | import android.telephony.RadioAccessSpecifier; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 109 | import android.telephony.ServiceState; |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 110 | import android.telephony.SignalStrength; |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 111 | import android.telephony.SignalStrengthUpdateRequest; |
| 112 | import android.telephony.SignalThresholdInfo; |
Wink Saville | 0f3b5fc | 2014-11-11 08:40:49 -0800 | [diff] [blame] | 113 | import android.telephony.SubscriptionInfo; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 114 | import android.telephony.SubscriptionManager; |
Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 115 | import android.telephony.TelephonyFrameworkInitializer; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 116 | import android.telephony.TelephonyHistogram; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 117 | import android.telephony.TelephonyManager; |
Jack Yu | f5badd9 | 2022-12-08 00:50:53 -0800 | [diff] [blame] | 118 | import android.telephony.TelephonyManager.SimState; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 119 | import android.telephony.TelephonyScanManager; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 120 | import android.telephony.ThermalMitigationRequest; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 121 | import android.telephony.UiccCardInfo; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 122 | import android.telephony.UiccPortInfo; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 123 | import android.telephony.UiccSlotInfo; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 124 | import android.telephony.UiccSlotMapping; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 125 | import android.telephony.UssdResponse; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 126 | import android.telephony.VisualVoicemailSmsFilterSettings; |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 127 | import android.telephony.data.NetworkSlicingConfig; |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 128 | import android.telephony.emergency.EmergencyNumber; |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 129 | import android.telephony.gba.GbaAuthRequest; |
| 130 | import android.telephony.gba.UaSecurityProtocolIdentifier; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 131 | import android.telephony.ims.ImsException; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 132 | import android.telephony.ims.ProvisioningManager; |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 133 | import android.telephony.ims.RcsClientConfiguration; |
Brad Ebinger | 14d467f | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 134 | import android.telephony.ims.RcsContactUceCapability; |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 135 | import android.telephony.ims.RegistrationManager; |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 136 | import android.telephony.ims.aidl.IFeatureProvisioningCallback; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 137 | import android.telephony.ims.aidl.IImsCapabilityCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 138 | import android.telephony.ims.aidl.IImsConfig; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 139 | import android.telephony.ims.aidl.IImsConfigCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 140 | import android.telephony.ims.aidl.IImsRegistration; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 141 | import android.telephony.ims.aidl.IImsRegistrationCallback; |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 142 | import android.telephony.ims.aidl.IRcsConfigCallback; |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 143 | import android.telephony.ims.feature.ImsFeature; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 144 | import android.telephony.ims.stub.ImsConfigImplBase; |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 145 | import android.telephony.ims.stub.ImsRegistrationImplBase; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 146 | import android.text.TextUtils; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 147 | import android.util.ArraySet; |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 148 | import android.util.EventLog; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 149 | import android.util.Log; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 150 | import android.util.Pair; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 151 | |
Andrew Lee | 312e817 | 2014-10-23 17:01:36 -0700 | [diff] [blame] | 152 | import com.android.ims.ImsManager; |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 153 | import com.android.ims.internal.IImsServiceFeatureCallback; |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 154 | import com.android.ims.rcs.uce.eab.EabUtil; |
SongFerngWang | fd89b10 | 2021-05-27 22:44:54 +0800 | [diff] [blame] | 155 | import com.android.internal.annotations.VisibleForTesting; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 156 | import com.android.internal.telephony.CallForwardInfo; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 157 | import com.android.internal.telephony.CallManager; |
Tyler Gunn | 52dcf77 | 2017-04-26 11:30:31 -0700 | [diff] [blame] | 158 | import com.android.internal.telephony.CallStateException; |
Tyler Gunn | d433926 | 2021-05-03 14:46:49 -0700 | [diff] [blame] | 159 | import com.android.internal.telephony.CallTracker; |
Rambo Wang | 9c9ffdd | 2022-01-13 21:51:44 -0800 | [diff] [blame] | 160 | import com.android.internal.telephony.CarrierPrivilegesTracker; |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 161 | import com.android.internal.telephony.CarrierResolver; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 162 | import com.android.internal.telephony.CellNetworkScanResult; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 163 | import com.android.internal.telephony.CommandException; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 164 | import com.android.internal.telephony.CommandsInterface; |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 165 | import com.android.internal.telephony.GbaManager; |
Shuo Qian | ccbaf74 | 2021-02-22 18:32:21 -0800 | [diff] [blame] | 166 | import com.android.internal.telephony.GsmCdmaPhone; |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 167 | import com.android.internal.telephony.HalVersion; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 168 | import com.android.internal.telephony.IBooleanConsumer; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 169 | import com.android.internal.telephony.ICallForwardingInfoCallback; |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 170 | import com.android.internal.telephony.IImsStateCallback; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 171 | import com.android.internal.telephony.IIntegerConsumer; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 172 | import com.android.internal.telephony.INumberVerificationCallback; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 173 | import com.android.internal.telephony.ITelephony; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 174 | import com.android.internal.telephony.IccCard; |
Jack Yu | f5badd9 | 2022-12-08 00:50:53 -0800 | [diff] [blame] | 175 | import com.android.internal.telephony.IccCardConstants; |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 176 | import com.android.internal.telephony.IccLogicalChannelRequest; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 177 | import com.android.internal.telephony.LocaleTracker; |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 178 | import com.android.internal.telephony.NetworkScanRequestTracker; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 179 | import com.android.internal.telephony.OperatorInfo; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 180 | import com.android.internal.telephony.Phone; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 181 | import com.android.internal.telephony.PhoneConfigurationManager; |
Nathan Harold | a667c15 | 2016-12-14 11:27:20 -0800 | [diff] [blame] | 182 | import com.android.internal.telephony.PhoneConstantConversions; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 183 | import com.android.internal.telephony.PhoneConstants; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 184 | import com.android.internal.telephony.PhoneFactory; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 185 | import com.android.internal.telephony.ProxyController; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 186 | import com.android.internal.telephony.RIL; |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 187 | import com.android.internal.telephony.RILConstants; |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 188 | import com.android.internal.telephony.RadioInterfaceCapabilityController; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 189 | import com.android.internal.telephony.ServiceStateTracker; |
Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame] | 190 | import com.android.internal.telephony.SmsApplication; |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 191 | import com.android.internal.telephony.SmsController; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 192 | import com.android.internal.telephony.SmsPermissions; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 193 | import com.android.internal.telephony.SubscriptionController; |
Peter Wang | 59571be | 2020-01-27 12:35:15 +0800 | [diff] [blame] | 194 | import com.android.internal.telephony.TelephonyIntents; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 195 | import com.android.internal.telephony.TelephonyPermissions; |
Jack Yu | 27422a5 | 2022-03-21 10:38:05 -0700 | [diff] [blame] | 196 | import com.android.internal.telephony.data.DataUtils; |
Hunsuk Choi | 42cc62a | 2022-10-16 06:03:40 +0000 | [diff] [blame] | 197 | import com.android.internal.telephony.domainselection.DomainSelectionResolver; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 198 | import com.android.internal.telephony.emergency.EmergencyNumberTracker; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 199 | import com.android.internal.telephony.euicc.EuiccConnector; |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 200 | import com.android.internal.telephony.ims.ImsResolver; |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 201 | import com.android.internal.telephony.imsphone.ImsPhone; |
| 202 | import com.android.internal.telephony.imsphone.ImsPhoneCallTracker; |
joonhunshin | 3e15424 | 2021-09-17 06:33:39 +0000 | [diff] [blame] | 203 | import com.android.internal.telephony.metrics.RcsStats; |
Pengquan Meng | 6c2dc9f | 2019-02-06 11:12:53 -0800 | [diff] [blame] | 204 | import com.android.internal.telephony.metrics.TelephonyMetrics; |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 205 | import com.android.internal.telephony.subscription.SubscriptionInfoInternal; |
| 206 | import com.android.internal.telephony.subscription.SubscriptionManagerService; |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 207 | import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 208 | import com.android.internal.telephony.uicc.IccIoResult; |
| 209 | import com.android.internal.telephony.uicc.IccUtils; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 210 | import com.android.internal.telephony.uicc.SIMRecords; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 211 | import com.android.internal.telephony.uicc.UiccCard; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 212 | import com.android.internal.telephony.uicc.UiccCardApplication; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 213 | import com.android.internal.telephony.uicc.UiccController; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 214 | import com.android.internal.telephony.uicc.UiccPort; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 215 | import com.android.internal.telephony.uicc.UiccProfile; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 216 | import com.android.internal.telephony.uicc.UiccSlot; |
zoey chen | c730df8 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 217 | import com.android.internal.telephony.util.LocaleUtils; |
Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame] | 218 | import com.android.internal.telephony.util.TelephonyUtils; |
fionaxu | 7ed723d | 2017-05-30 18:58:54 -0700 | [diff] [blame] | 219 | import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 220 | import com.android.internal.util.FunctionalUtils; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 221 | import com.android.internal.util.HexDump; |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 222 | import com.android.phone.callcomposer.CallComposerPictureManager; |
| 223 | import com.android.phone.callcomposer.CallComposerPictureTransfer; |
| 224 | import com.android.phone.callcomposer.ImageData; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 225 | import com.android.phone.settings.PickSmsSubscriptionActivity; |
Sarah Chin | 46355ba | 2022-11-01 23:51:16 -0700 | [diff] [blame] | 226 | import com.android.phone.slice.SlicePurchaseController; |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 227 | import com.android.phone.utils.CarrierAllowListInfo; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 228 | import com.android.phone.vvm.PhoneAccountHandleConverter; |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 229 | import com.android.phone.vvm.RemoteVvmTaskManager; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 230 | import com.android.phone.vvm.VisualVoicemailSettingsUtil; |
Ta-wei Yen | c890531 | 2017-03-28 11:14:45 -0700 | [diff] [blame] | 231 | import com.android.phone.vvm.VisualVoicemailSmsFilterConfig; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 232 | import com.android.services.telephony.TelecomAccountRegistry; |
| 233 | import com.android.services.telephony.TelephonyConnectionService; |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 234 | import com.android.telephony.Rlog; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 235 | |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 236 | import java.io.ByteArrayOutputStream; |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 237 | import java.io.FileDescriptor; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 238 | import java.io.IOException; |
| 239 | import java.io.InputStream; |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 240 | import java.io.PrintWriter; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 241 | import java.util.ArrayList; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 242 | import java.util.Arrays; |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 243 | import java.util.Collection; |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 244 | import java.util.Collections; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 245 | import java.util.HashMap; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 246 | import java.util.HashSet; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 247 | import java.util.List; |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 248 | import java.util.Locale; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 249 | import java.util.Map; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 250 | import java.util.NoSuchElementException; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 251 | import java.util.Objects; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 252 | import java.util.Set; |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 253 | import java.util.UUID; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 254 | import java.util.concurrent.Executors; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 255 | import java.util.concurrent.atomic.AtomicBoolean; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 256 | import java.util.function.Consumer; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 257 | |
| 258 | /** |
| 259 | * Implementation of the ITelephony interface. |
| 260 | */ |
Santos Cordon | 117fee7 | 2014-05-16 17:56:12 -0700 | [diff] [blame] | 261 | public class PhoneInterfaceManager extends ITelephony.Stub { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 262 | private static final String LOG_TAG = "PhoneInterfaceManager"; |
| 263 | private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2); |
| 264 | private static final boolean DBG_LOC = false; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 265 | private static final boolean DBG_MERGE = false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 266 | |
| 267 | // Message codes used with mMainThreadHandler |
| 268 | private static final int CMD_HANDLE_PIN_MMI = 1; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 269 | private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7; |
| 270 | private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 271 | private static final int CMD_OPEN_CHANNEL = 9; |
| 272 | private static final int EVENT_OPEN_CHANNEL_DONE = 10; |
| 273 | private static final int CMD_CLOSE_CHANNEL = 11; |
| 274 | private static final int EVENT_CLOSE_CHANNEL_DONE = 12; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 275 | private static final int CMD_NV_READ_ITEM = 13; |
| 276 | private static final int EVENT_NV_READ_ITEM_DONE = 14; |
| 277 | private static final int CMD_NV_WRITE_ITEM = 15; |
| 278 | private static final int EVENT_NV_WRITE_ITEM_DONE = 16; |
| 279 | private static final int CMD_NV_WRITE_CDMA_PRL = 17; |
| 280 | private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 281 | private static final int CMD_RESET_MODEM_CONFIG = 19; |
| 282 | private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 283 | private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21; |
| 284 | private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22; |
Sailesh Nepal | 35b5945 | 2014-03-06 09:26:56 -0800 | [diff] [blame] | 285 | private static final int CMD_SEND_ENVELOPE = 25; |
| 286 | private static final int EVENT_SEND_ENVELOPE_DONE = 26; |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 287 | private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27; |
| 288 | private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28; |
Derek Tan | 6b088ee | 2014-09-05 14:15:18 -0700 | [diff] [blame] | 289 | private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29; |
| 290 | private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30; |
| 291 | private static final int CMD_EXCHANGE_SIM_IO = 31; |
| 292 | private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 293 | private static final int CMD_SET_VOICEMAIL_NUMBER = 33; |
| 294 | private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 295 | private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35; |
| 296 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 297 | private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37; |
| 298 | private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 299 | private static final int CMD_PERFORM_NETWORK_SCAN = 39; |
| 300 | private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40; |
| 301 | private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41; |
| 302 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 303 | private static final int CMD_SET_ALLOWED_CARRIERS = 43; |
| 304 | private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44; |
| 305 | private static final int CMD_GET_ALLOWED_CARRIERS = 45; |
| 306 | private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 307 | private static final int CMD_HANDLE_USSD_REQUEST = 47; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 308 | private static final int CMD_GET_FORBIDDEN_PLMNS = 48; |
| 309 | private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 310 | private static final int CMD_SWITCH_SLOTS = 50; |
| 311 | private static final int EVENT_SWITCH_SLOTS_DONE = 51; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 312 | private static final int CMD_GET_NETWORK_SELECTION_MODE = 52; |
| 313 | private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53; |
| 314 | private static final int CMD_GET_CDMA_ROAMING_MODE = 54; |
| 315 | private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55; |
| 316 | private static final int CMD_SET_CDMA_ROAMING_MODE = 56; |
| 317 | private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57; |
| 318 | private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58; |
| 319 | private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 320 | private static final int CMD_GET_ALL_CELL_INFO = 60; |
| 321 | private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61; |
| 322 | private static final int CMD_GET_CELL_LOCATION = 62; |
| 323 | private static final int EVENT_GET_CELL_LOCATION_DONE = 63; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 324 | private static final int CMD_MODEM_REBOOT = 64; |
| 325 | private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 326 | private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66; |
| 327 | private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 328 | private static final int CMD_REQUEST_ENABLE_MODEM = 68; |
| 329 | private static final int EVENT_ENABLE_MODEM_DONE = 69; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 330 | private static final int CMD_GET_MODEM_STATUS = 70; |
| 331 | private static final int EVENT_GET_MODEM_STATUS_DONE = 71; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 332 | private static final int CMD_SET_FORBIDDEN_PLMNS = 72; |
| 333 | private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 334 | private static final int CMD_ERASE_MODEM_CONFIG = 74; |
| 335 | private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75; |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 336 | private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76; |
| 337 | private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77; |
| 338 | private static final int CMD_SET_ICC_LOCK_ENABLED = 78; |
| 339 | private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 340 | private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80; |
| 341 | private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 342 | private static final int MSG_NOTIFY_USER_ACTIVITY = 82; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 343 | private static final int CMD_GET_CALL_FORWARDING = 83; |
| 344 | private static final int EVENT_GET_CALL_FORWARDING_DONE = 84; |
| 345 | private static final int CMD_SET_CALL_FORWARDING = 85; |
| 346 | private static final int EVENT_SET_CALL_FORWARDING_DONE = 86; |
| 347 | private static final int CMD_GET_CALL_WAITING = 87; |
| 348 | private static final int EVENT_GET_CALL_WAITING_DONE = 88; |
| 349 | private static final int CMD_SET_CALL_WAITING = 89; |
| 350 | private static final int EVENT_SET_CALL_WAITING_DONE = 90; |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 351 | private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91; |
| 352 | private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92; |
| 353 | private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93; |
| 354 | private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 355 | private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95; |
| 356 | private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 357 | private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97; |
| 358 | private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 359 | private static final int CMD_SET_DATA_THROTTLING = 99; |
| 360 | private static final int EVENT_SET_DATA_THROTTLING_DONE = 100; |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 361 | private static final int CMD_SET_SIM_POWER = 101; |
| 362 | private static final int EVENT_SET_SIM_POWER_DONE = 102; |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 363 | private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103; |
| 364 | private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104; |
| 365 | private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105; |
| 366 | private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 367 | private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107; |
| 368 | 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] | 369 | private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 370 | private static final int CMD_GET_SLICING_CONFIG = 110; |
| 371 | private static final int EVENT_GET_SLICING_CONFIG_DONE = 111; |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 372 | private static final int CMD_ERASE_DATA_SHARED_PREFERENCES = 112; |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 373 | private static final int CMD_ENABLE_VONR = 113; |
| 374 | private static final int EVENT_ENABLE_VONR_DONE = 114; |
| 375 | private static final int CMD_IS_VONR_ENABLED = 115; |
| 376 | private static final int EVENT_IS_VONR_ENABLED_DONE = 116; |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 377 | private static final int CMD_PURCHASE_PREMIUM_CAPABILITY = 117; |
| 378 | private static final int EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE = 118; |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 379 | // Parameters of select command. |
| 380 | private static final int SELECT_COMMAND = 0xA4; |
| 381 | private static final int SELECT_P1 = 0x04; |
| 382 | private static final int SELECT_P2 = 0; |
| 383 | private static final int SELECT_P3 = 0x10; |
| 384 | |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 385 | // Toggling null cipher and integrity support was added in IRadioNetwork 2.1 |
| 386 | private static final int MIN_NULL_CIPHER_AND_INTEGRITY_VERSION = 201; |
| 387 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 388 | /** The singleton instance. */ |
| 389 | private static PhoneInterfaceManager sInstance; |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 390 | private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 391 | |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 392 | private PhoneGlobals mApp; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 393 | private CallManager mCM; |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 394 | private ImsResolver mImsResolver; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 395 | private UserManager mUserManager; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 396 | private AppOpsManager mAppOps; |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 397 | private PackageManager mPm; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 398 | private MainThreadHandler mMainThreadHandler; |
Jack Yu | e37dd26 | 2022-12-16 11:53:37 -0800 | [diff] [blame] | 399 | private final SubscriptionController mSubscriptionController; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 400 | private SharedPreferences mTelephonySharedPreferences; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 401 | private PhoneConfigurationManager mPhoneConfigurationManager; |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 402 | private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities; |
Gil Cukierman | 6dac5eb | 2022-09-19 16:09:04 +0000 | [diff] [blame] | 403 | private final Telephony2gUpdater mTelephony2gUpdater; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 404 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 405 | /** User Activity */ |
| 406 | private AtomicBoolean mNotifyUserActivity; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 407 | private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200; |
| 408 | |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 409 | private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>(); |
| 410 | |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 411 | private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_"; |
| 412 | private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_"; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 413 | private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_"; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 414 | private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_"; |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 415 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 416 | // String to store multi SIM allowed |
| 417 | private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted"; |
| 418 | |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 419 | // The AID of ISD-R. |
| 420 | private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100"; |
| 421 | |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 422 | private NetworkScanRequestTracker mNetworkScanRequestTracker; |
| 423 | |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 424 | private static final int TYPE_ALLOCATION_CODE_LENGTH = 8; |
| 425 | private static final int MANUFACTURER_CODE_LENGTH = 8; |
| 426 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 427 | private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1; |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 428 | 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] | 429 | |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 430 | private static final String PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID = |
| 431 | "24bf97a6-e8a6-44d8-a6a4-255d7548733c"; |
| 432 | |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 433 | /** |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 434 | * Experiment flag to enable erase modem config on reset network, default value is false |
| 435 | */ |
| 436 | public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED = |
| 437 | "reset_network_erase_modem_config_enabled"; |
| 438 | |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 439 | 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] | 440 | |
Gary Jian | 76280a4 | 2022-12-07 16:18:33 +0800 | [diff] [blame] | 441 | private static final int MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS = 50; |
| 442 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 443 | /** |
| 444 | * With support for MEP(multiple enabled profile) in Android T, a SIM card can have more than |
| 445 | * one ICCID active at the same time. |
| 446 | * Apps should use below API signatures if targeting SDK is T and beyond. |
| 447 | * |
| 448 | * @hide |
| 449 | */ |
| 450 | @ChangeId |
| 451 | @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU) |
| 452 | public static final long GET_API_SIGNATURES_FROM_UICC_PORT_INFO = 202110963L; |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 453 | |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 454 | /** |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 455 | * Apps targeting on Android T and beyond will get exception whenever icc close channel |
| 456 | * operation fails. |
| 457 | */ |
| 458 | @ChangeId |
| 459 | @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU) |
| 460 | public static final long ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE = 208739934L; |
| 461 | |
| 462 | /** |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 463 | * A request object to use for transmitting data to an ICC. |
| 464 | */ |
| 465 | private static final class IccAPDUArgument { |
| 466 | public int channel, cla, command, p1, p2, p3; |
| 467 | public String data; |
| 468 | |
| 469 | public IccAPDUArgument(int channel, int cla, int command, |
| 470 | int p1, int p2, int p3, String data) { |
| 471 | this.channel = channel; |
| 472 | this.cla = cla; |
| 473 | this.command = command; |
| 474 | this.p1 = p1; |
| 475 | this.p2 = p2; |
| 476 | this.p3 = p3; |
| 477 | this.data = data; |
| 478 | } |
| 479 | } |
| 480 | |
| 481 | /** |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 482 | * A request object to use for transmitting data to an ICC. |
| 483 | */ |
| 484 | private static final class ManualNetworkSelectionArgument { |
| 485 | public OperatorInfo operatorInfo; |
| 486 | public boolean persistSelection; |
| 487 | |
| 488 | public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) { |
| 489 | this.operatorInfo = operatorInfo; |
| 490 | this.persistSelection = persistSelection; |
| 491 | } |
| 492 | } |
| 493 | |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 494 | private static final class PurchasePremiumCapabilityArgument { |
| 495 | public @TelephonyManager.PremiumCapability int capability; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 496 | public @NonNull IIntegerConsumer callback; |
| 497 | |
| 498 | PurchasePremiumCapabilityArgument(@TelephonyManager.PremiumCapability int capability, |
Sarah Chin | b8218c2 | 2023-01-04 13:35:29 -0800 | [diff] [blame] | 499 | @NonNull IIntegerConsumer callback) { |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 500 | this.capability = capability; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 501 | this.callback = callback; |
| 502 | } |
| 503 | } |
| 504 | |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 505 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 506 | * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the |
| 507 | * request after sending. The main thread will notify the request when it is complete. |
| 508 | */ |
| 509 | private static final class MainThreadRequest { |
| 510 | /** The argument to use for the request */ |
| 511 | public Object argument; |
| 512 | /** The result of the request that is run on the main thread */ |
| 513 | public Object result; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 514 | // The subscriber id that this request applies to. Defaults to |
| 515 | // SubscriptionManager.INVALID_SUBSCRIPTION_ID |
| 516 | public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 517 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 518 | // In cases where subId is unavailable, the caller needs to specify the phone. |
| 519 | public Phone phone; |
| 520 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 521 | public WorkSource workSource; |
| 522 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 523 | public MainThreadRequest(Object argument) { |
| 524 | this.argument = argument; |
| 525 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 526 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 527 | MainThreadRequest(Object argument, Phone phone, WorkSource workSource) { |
| 528 | this.argument = argument; |
| 529 | if (phone != null) { |
| 530 | this.phone = phone; |
| 531 | } |
| 532 | this.workSource = workSource; |
| 533 | } |
| 534 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 535 | MainThreadRequest(Object argument, Integer subId, WorkSource workSource) { |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 536 | this.argument = argument; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 537 | if (subId != null) { |
| 538 | this.subId = subId; |
| 539 | } |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 540 | this.workSource = workSource; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 541 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 542 | } |
| 543 | |
Sailesh Nepal | cc0375f | 2013-11-13 09:15:18 -0800 | [diff] [blame] | 544 | private static final class IncomingThirdPartyCallArgs { |
| 545 | public final ComponentName component; |
| 546 | public final String callId; |
| 547 | public final String callerDisplayName; |
| 548 | |
| 549 | public IncomingThirdPartyCallArgs(ComponentName component, String callId, |
| 550 | String callerDisplayName) { |
| 551 | this.component = component; |
| 552 | this.callId = callId; |
| 553 | this.callerDisplayName = callerDisplayName; |
| 554 | } |
| 555 | } |
| 556 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 557 | /** |
| 558 | * A handler that processes messages on the main thread in the phone process. Since many |
| 559 | * of the Phone calls are not thread safe this is needed to shuttle the requests from the |
| 560 | * inbound binder threads to the main thread in the phone process. The Binder thread |
| 561 | * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting |
| 562 | * on, which will be notified when the operation completes and will contain the result of the |
| 563 | * request. |
| 564 | * |
| 565 | * <p>If a MainThreadRequest object is provided in the msg.obj field, |
| 566 | * note that request.result must be set to something non-null for the calling thread to |
| 567 | * unblock. |
| 568 | */ |
| 569 | private final class MainThreadHandler extends Handler { |
| 570 | @Override |
| 571 | public void handleMessage(Message msg) { |
| 572 | MainThreadRequest request; |
| 573 | Message onCompleted; |
| 574 | AsyncResult ar; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 575 | UiccPort uiccPort; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 576 | IccAPDUArgument iccArgument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 577 | final Phone defaultPhone = getDefaultPhone(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 578 | |
| 579 | switch (msg.what) { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 580 | case CMD_HANDLE_USSD_REQUEST: { |
| 581 | request = (MainThreadRequest) msg.obj; |
| 582 | final Phone phone = getPhoneFromRequest(request); |
| 583 | Pair<String, ResultReceiver> ussdObject = (Pair) request.argument; |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 584 | String ussdRequest = ussdObject.first; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 585 | ResultReceiver wrappedCallback = ussdObject.second; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 586 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 587 | if (!isUssdApiAllowed(request.subId)) { |
| 588 | // Carrier does not support use of this API, return failure. |
| 589 | Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis."); |
| 590 | UssdResponse response = new UssdResponse(ussdRequest, null); |
| 591 | Bundle returnData = new Bundle(); |
| 592 | returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response); |
| 593 | wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 594 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 595 | request.result = true; |
| 596 | notifyRequester(request); |
| 597 | return; |
| 598 | } |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 599 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 600 | try { |
| 601 | request.result = phone != null |
| 602 | ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false; |
| 603 | } catch (CallStateException cse) { |
| 604 | request.result = false; |
| 605 | } |
| 606 | // Wake up the requesting thread |
| 607 | notifyRequester(request); |
| 608 | break; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 609 | } |
| 610 | |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 611 | case CMD_HANDLE_PIN_MMI: { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 612 | request = (MainThreadRequest) msg.obj; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 613 | final Phone phone = getPhoneFromRequest(request); |
| 614 | request.result = phone != null ? |
| 615 | getPhoneFromRequest(request).handlePinMmi((String) request.argument) |
| 616 | : false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 617 | // Wake up the requesting thread |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 618 | notifyRequester(request); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 619 | break; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 620 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 621 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 622 | case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 623 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 624 | iccArgument = (IccAPDUArgument) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 625 | uiccPort = getUiccPortFromRequest(request); |
| 626 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 627 | loge("iccTransmitApduLogicalChannel: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 628 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 629 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 630 | } else { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 631 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE, |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 632 | request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 633 | uiccPort.iccTransmitApduLogicalChannel( |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 634 | iccArgument.channel, iccArgument.cla, iccArgument.command, |
| 635 | iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data, |
| 636 | onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 637 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 638 | break; |
| 639 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 640 | case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 641 | ar = (AsyncResult) msg.obj; |
| 642 | request = (MainThreadRequest) ar.userObj; |
| 643 | if (ar.exception == null && ar.result != null) { |
| 644 | request.result = ar.result; |
| 645 | } else { |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 646 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 647 | if (ar.result == null) { |
| 648 | loge("iccTransmitApduLogicalChannel: Empty response"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 649 | } else if (ar.exception instanceof CommandException) { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 650 | loge("iccTransmitApduLogicalChannel: CommandException: " + |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 651 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 652 | } else { |
| 653 | loge("iccTransmitApduLogicalChannel: Unknown exception"); |
| 654 | } |
| 655 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 656 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 657 | break; |
| 658 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 659 | case CMD_TRANSMIT_APDU_BASIC_CHANNEL: |
| 660 | request = (MainThreadRequest) msg.obj; |
| 661 | iccArgument = (IccAPDUArgument) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 662 | uiccPort = getUiccPortFromRequest(request); |
| 663 | if (uiccPort == null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 664 | loge("iccTransmitApduBasicChannel: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 665 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 666 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 667 | } else { |
| 668 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE, |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 669 | request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 670 | uiccPort.iccTransmitApduBasicChannel( |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 671 | iccArgument.cla, iccArgument.command, iccArgument.p1, |
| 672 | iccArgument.p2, |
| 673 | iccArgument.p3, iccArgument.data, onCompleted); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 674 | } |
| 675 | break; |
| 676 | |
| 677 | case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE: |
| 678 | ar = (AsyncResult) msg.obj; |
| 679 | request = (MainThreadRequest) ar.userObj; |
| 680 | if (ar.exception == null && ar.result != null) { |
| 681 | request.result = ar.result; |
| 682 | } else { |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 683 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 684 | if (ar.result == null) { |
| 685 | loge("iccTransmitApduBasicChannel: Empty response"); |
| 686 | } else if (ar.exception instanceof CommandException) { |
| 687 | loge("iccTransmitApduBasicChannel: CommandException: " + |
| 688 | ar.exception); |
| 689 | } else { |
| 690 | loge("iccTransmitApduBasicChannel: Unknown exception"); |
| 691 | } |
| 692 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 693 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 694 | break; |
| 695 | |
| 696 | case CMD_EXCHANGE_SIM_IO: |
| 697 | request = (MainThreadRequest) msg.obj; |
| 698 | iccArgument = (IccAPDUArgument) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 699 | uiccPort = getUiccPortFromRequest(request); |
| 700 | if (uiccPort == null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 701 | loge("iccExchangeSimIO: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 702 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 703 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 704 | } else { |
| 705 | onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE, |
| 706 | request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 707 | uiccPort.iccExchangeSimIO(iccArgument.cla, /* fileID */ |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 708 | iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3, |
| 709 | iccArgument.data, onCompleted); |
| 710 | } |
| 711 | break; |
| 712 | |
| 713 | case EVENT_EXCHANGE_SIM_IO_DONE: |
| 714 | ar = (AsyncResult) msg.obj; |
| 715 | request = (MainThreadRequest) ar.userObj; |
| 716 | if (ar.exception == null && ar.result != null) { |
| 717 | request.result = ar.result; |
| 718 | } else { |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 719 | request.result = new IccIoResult(0x6f, 0, (byte[]) null); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 720 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 721 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 722 | break; |
| 723 | |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 724 | case CMD_SEND_ENVELOPE: |
| 725 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 726 | uiccPort = getUiccPortFromRequest(request); |
| 727 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 728 | loge("sendEnvelopeWithStatus: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 729 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 730 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 731 | } else { |
| 732 | onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 733 | uiccPort.sendEnvelopeWithStatus((String) request.argument, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 734 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 735 | break; |
| 736 | |
| 737 | case EVENT_SEND_ENVELOPE_DONE: |
| 738 | ar = (AsyncResult) msg.obj; |
| 739 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 740 | if (ar.exception == null && ar.result != null) { |
| 741 | request.result = ar.result; |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 742 | } else { |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 743 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 744 | if (ar.result == null) { |
| 745 | loge("sendEnvelopeWithStatus: Empty response"); |
| 746 | } else if (ar.exception instanceof CommandException) { |
| 747 | loge("sendEnvelopeWithStatus: CommandException: " + |
| 748 | ar.exception); |
| 749 | } else { |
| 750 | loge("sendEnvelopeWithStatus: exception:" + ar.exception); |
| 751 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 752 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 753 | notifyRequester(request); |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 754 | break; |
| 755 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 756 | case CMD_OPEN_CHANNEL: |
| 757 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 758 | uiccPort = getUiccPortFromRequest(request); |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 759 | IccLogicalChannelRequest openChannelRequest = |
| 760 | (IccLogicalChannelRequest) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 761 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 762 | loge("iccOpenLogicalChannel: No UICC"); |
Shishir Agrawal | fc0492a | 2016-02-17 11:15:33 -0800 | [diff] [blame] | 763 | request.result = new IccOpenLogicalChannelResponse(-1, |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 764 | IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 765 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 766 | } else { |
| 767 | onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request); |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 768 | uiccPort.iccOpenLogicalChannel(openChannelRequest.aid, |
| 769 | openChannelRequest.p2, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 770 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 771 | break; |
| 772 | |
| 773 | case EVENT_OPEN_CHANNEL_DONE: |
| 774 | ar = (AsyncResult) msg.obj; |
| 775 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 776 | IccOpenLogicalChannelResponse openChannelResp; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 777 | if (ar.exception == null && ar.result != null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 778 | int[] result = (int[]) ar.result; |
| 779 | int channelId = result[0]; |
| 780 | byte[] selectResponse = null; |
| 781 | if (result.length > 1) { |
| 782 | selectResponse = new byte[result.length - 1]; |
| 783 | for (int i = 1; i < result.length; ++i) { |
| 784 | selectResponse[i - 1] = (byte) result[i]; |
| 785 | } |
| 786 | } |
| 787 | openChannelResp = new IccOpenLogicalChannelResponse(channelId, |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 788 | IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse); |
Rambo Wang | 3b77c4c | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 789 | |
| 790 | uiccPort = getUiccPortFromRequest(request); |
Rambo Wang | e53e07d | 2022-05-10 13:01:13 -0700 | [diff] [blame] | 791 | if (uiccPort == null) { |
| 792 | loge("EVENT_OPEN_CHANNEL_DONE: UiccPort is null"); |
| 793 | } else { |
| 794 | IccLogicalChannelRequest channelRequest = |
| 795 | (IccLogicalChannelRequest) request.argument; |
| 796 | channelRequest.channel = channelId; |
| 797 | uiccPort.onLogicalChannelOpened(channelRequest); |
| 798 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 799 | } else { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 800 | if (ar.result == null) { |
| 801 | loge("iccOpenLogicalChannel: Empty response"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 802 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 803 | if (ar.exception != null) { |
| 804 | loge("iccOpenLogicalChannel: Exception: " + ar.exception); |
| 805 | } |
| 806 | |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 807 | int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 808 | if (ar.exception instanceof CommandException) { |
| 809 | CommandException.Error error = |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 810 | ((CommandException) (ar.exception)).getCommandError(); |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 811 | if (error == CommandException.Error.MISSING_RESOURCE) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 812 | errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 813 | } else if (error == CommandException.Error.NO_SUCH_ELEMENT) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 814 | errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 815 | } |
| 816 | } |
| 817 | openChannelResp = new IccOpenLogicalChannelResponse( |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 818 | IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 819 | } |
Shishir Agrawal | 82c8a46 | 2014-07-31 18:13:17 -0700 | [diff] [blame] | 820 | request.result = openChannelResp; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 821 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 822 | break; |
| 823 | |
| 824 | case CMD_CLOSE_CHANNEL: |
| 825 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 826 | uiccPort = getUiccPortFromRequest(request); |
| 827 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 828 | loge("iccCloseLogicalChannel: No UICC"); |
Chen Xu | a8f0dff | 2022-02-12 00:34:15 -0800 | [diff] [blame] | 829 | request.result = new IllegalArgumentException( |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 830 | "iccCloseLogicalChannel: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 831 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 832 | } else { |
| 833 | onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 834 | uiccPort.iccCloseLogicalChannel((Integer) request.argument, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 835 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 836 | break; |
| 837 | |
| 838 | case EVENT_CLOSE_CHANNEL_DONE: |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 839 | ar = (AsyncResult) msg.obj; |
| 840 | request = (MainThreadRequest) ar.userObj; |
| 841 | if (ar.exception == null) { |
| 842 | request.result = true; |
Rambo Wang | 3b77c4c | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 843 | uiccPort = getUiccPortFromRequest(request); |
Rambo Wang | e53e07d | 2022-05-10 13:01:13 -0700 | [diff] [blame] | 844 | if (uiccPort == null) { |
| 845 | loge("EVENT_CLOSE_CHANNEL_DONE: UiccPort is null"); |
| 846 | } else { |
| 847 | final int channelId = (Integer) request.argument; |
| 848 | uiccPort.onLogicalChannelClosed(channelId); |
| 849 | } |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 850 | } else { |
| 851 | request.result = false; |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 852 | Exception exception = null; |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 853 | if (ar.exception instanceof CommandException) { |
| 854 | loge("iccCloseLogicalChannel: CommandException: " + ar.exception); |
| 855 | CommandException.Error error = |
| 856 | ((CommandException) (ar.exception)).getCommandError(); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 857 | if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 858 | // should only throw exceptions from the binder threads. |
| 859 | exception = new IllegalArgumentException( |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 860 | "iccCloseLogicalChannel: invalid argument "); |
| 861 | } |
| 862 | } else { |
| 863 | loge("iccCloseLogicalChannel: Unknown exception"); |
| 864 | } |
Chen Xu | a8f0dff | 2022-02-12 00:34:15 -0800 | [diff] [blame] | 865 | request.result = (exception != null) ? exception : |
| 866 | new IllegalStateException( |
| 867 | "exception from modem to close iccLogical Channel"); |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 868 | } |
| 869 | notifyRequester(request); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 870 | break; |
| 871 | |
| 872 | case CMD_NV_READ_ITEM: |
| 873 | request = (MainThreadRequest) msg.obj; |
| 874 | onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 875 | defaultPhone.nvReadItem((Integer) request.argument, onCompleted, |
| 876 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 877 | break; |
| 878 | |
| 879 | case EVENT_NV_READ_ITEM_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 880 | ar = (AsyncResult) msg.obj; |
| 881 | request = (MainThreadRequest) ar.userObj; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 882 | if (ar.exception == null && ar.result != null) { |
| 883 | request.result = ar.result; // String |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 884 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 885 | request.result = ""; |
| 886 | if (ar.result == null) { |
| 887 | loge("nvReadItem: Empty response"); |
| 888 | } else if (ar.exception instanceof CommandException) { |
| 889 | loge("nvReadItem: CommandException: " + |
| 890 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 891 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 892 | loge("nvReadItem: Unknown exception"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 893 | } |
| 894 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 895 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 896 | break; |
| 897 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 898 | case CMD_NV_WRITE_ITEM: |
| 899 | request = (MainThreadRequest) msg.obj; |
| 900 | onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request); |
| 901 | Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 902 | defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 903 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 904 | break; |
| 905 | |
| 906 | case EVENT_NV_WRITE_ITEM_DONE: |
| 907 | handleNullReturnEvent(msg, "nvWriteItem"); |
| 908 | break; |
| 909 | |
| 910 | case CMD_NV_WRITE_CDMA_PRL: |
| 911 | request = (MainThreadRequest) msg.obj; |
| 912 | onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 913 | defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 914 | break; |
| 915 | |
| 916 | case EVENT_NV_WRITE_CDMA_PRL_DONE: |
| 917 | handleNullReturnEvent(msg, "nvWriteCdmaPrl"); |
| 918 | break; |
| 919 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 920 | case CMD_RESET_MODEM_CONFIG: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 921 | request = (MainThreadRequest) msg.obj; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 922 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 923 | defaultPhone.resetModemConfig(onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 924 | break; |
| 925 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 926 | case EVENT_RESET_MODEM_CONFIG_DONE: |
| 927 | handleNullReturnEvent(msg, "resetModemConfig"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 928 | break; |
| 929 | |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 930 | case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: { |
| 931 | request = (MainThreadRequest) msg.obj; |
| 932 | onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE, |
| 933 | request); |
| 934 | Phone phone = getPhoneFromRequest(request); |
| 935 | if (phone != null) { |
| 936 | phone.isNrDualConnectivityEnabled(onCompleted, request.workSource); |
| 937 | } else { |
| 938 | loge("isNRDualConnectivityEnabled: No phone object"); |
| 939 | request.result = false; |
| 940 | notifyRequester(request); |
| 941 | } |
| 942 | break; |
| 943 | } |
| 944 | |
| 945 | case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE: |
| 946 | ar = (AsyncResult) msg.obj; |
| 947 | request = (MainThreadRequest) ar.userObj; |
| 948 | if (ar.exception == null && ar.result != null) { |
| 949 | request.result = ar.result; |
| 950 | } else { |
| 951 | // request.result must be set to something non-null |
| 952 | // for the calling thread to unblock |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 953 | if (ar.result != null) { |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 954 | request.result = ar.result; |
| 955 | } else { |
| 956 | request.result = false; |
| 957 | } |
| 958 | if (ar.result == null) { |
| 959 | loge("isNRDualConnectivityEnabled: Empty response"); |
| 960 | } else if (ar.exception instanceof CommandException) { |
| 961 | loge("isNRDualConnectivityEnabled: CommandException: " |
| 962 | + ar.exception); |
| 963 | } else { |
| 964 | loge("isNRDualConnectivityEnabled: Unknown exception"); |
| 965 | } |
| 966 | } |
| 967 | notifyRequester(request); |
| 968 | break; |
| 969 | |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 970 | case CMD_IS_VONR_ENABLED: { |
| 971 | request = (MainThreadRequest) msg.obj; |
| 972 | onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE, |
| 973 | request); |
| 974 | Phone phone = getPhoneFromRequest(request); |
| 975 | if (phone != null) { |
| 976 | phone.isVoNrEnabled(onCompleted, request.workSource); |
| 977 | } else { |
| 978 | loge("isVoNrEnabled: No phone object"); |
| 979 | request.result = false; |
| 980 | notifyRequester(request); |
| 981 | } |
| 982 | break; |
| 983 | } |
| 984 | |
| 985 | case EVENT_IS_VONR_ENABLED_DONE: |
| 986 | ar = (AsyncResult) msg.obj; |
| 987 | request = (MainThreadRequest) ar.userObj; |
| 988 | if (ar.exception == null && ar.result != null) { |
| 989 | request.result = ar.result; |
| 990 | } else { |
| 991 | // request.result must be set to something non-null |
| 992 | // for the calling thread to unblock |
| 993 | if (ar.result != null) { |
| 994 | request.result = ar.result; |
| 995 | } else { |
| 996 | request.result = false; |
| 997 | } |
| 998 | if (ar.result == null) { |
| 999 | loge("isVoNrEnabled: Empty response"); |
| 1000 | } else if (ar.exception instanceof CommandException) { |
| 1001 | loge("isVoNrEnabled: CommandException: " |
| 1002 | + ar.exception); |
| 1003 | } else { |
| 1004 | loge("isVoNrEnabled: Unknown exception"); |
| 1005 | } |
| 1006 | } |
| 1007 | notifyRequester(request); |
| 1008 | break; |
| 1009 | |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 1010 | case CMD_ENABLE_NR_DUAL_CONNECTIVITY: { |
| 1011 | request = (MainThreadRequest) msg.obj; |
| 1012 | onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request); |
| 1013 | Phone phone = getPhoneFromRequest(request); |
| 1014 | if (phone != null) { |
| 1015 | phone.setNrDualConnectivityState((int) request.argument, onCompleted, |
| 1016 | request.workSource); |
| 1017 | } else { |
| 1018 | loge("enableNrDualConnectivity: No phone object"); |
| 1019 | request.result = |
| 1020 | TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE; |
| 1021 | notifyRequester(request); |
| 1022 | } |
| 1023 | break; |
| 1024 | } |
| 1025 | |
| 1026 | case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: { |
| 1027 | ar = (AsyncResult) msg.obj; |
| 1028 | request = (MainThreadRequest) ar.userObj; |
| 1029 | if (ar.exception == null) { |
| 1030 | request.result = |
| 1031 | TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS; |
| 1032 | } else { |
| 1033 | request.result = |
| 1034 | TelephonyManager |
| 1035 | .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR; |
| 1036 | if (ar.exception instanceof CommandException) { |
| 1037 | CommandException.Error error = |
| 1038 | ((CommandException) (ar.exception)).getCommandError(); |
| 1039 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1040 | request.result = |
| 1041 | TelephonyManager |
| 1042 | .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE; |
Sooraj Sasindran | 2965416 | 2021-03-03 23:00:01 +0000 | [diff] [blame] | 1043 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1044 | request.result = |
| 1045 | TelephonyManager |
| 1046 | .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED; |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 1047 | } |
| 1048 | loge("enableNrDualConnectivity" + ": CommandException: " |
| 1049 | + ar.exception); |
| 1050 | } else { |
| 1051 | loge("enableNrDualConnectivity" + ": Unknown exception"); |
| 1052 | } |
| 1053 | } |
| 1054 | notifyRequester(request); |
| 1055 | break; |
| 1056 | } |
| 1057 | |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 1058 | case CMD_ENABLE_VONR: { |
| 1059 | request = (MainThreadRequest) msg.obj; |
| 1060 | onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request); |
| 1061 | Phone phone = getPhoneFromRequest(request); |
| 1062 | if (phone != null) { |
| 1063 | phone.setVoNrEnabled((boolean) request.argument, onCompleted, |
| 1064 | request.workSource); |
| 1065 | } else { |
| 1066 | loge("setVoNrEnabled: No phone object"); |
| 1067 | request.result = |
| 1068 | TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE; |
| 1069 | notifyRequester(request); |
| 1070 | } |
| 1071 | break; |
| 1072 | } |
| 1073 | |
| 1074 | case EVENT_ENABLE_VONR_DONE: { |
| 1075 | ar = (AsyncResult) msg.obj; |
| 1076 | request = (MainThreadRequest) ar.userObj; |
| 1077 | if (ar.exception == null) { |
| 1078 | request.result = TelephonyManager.ENABLE_VONR_SUCCESS; |
| 1079 | } else { |
| 1080 | request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR; |
| 1081 | if (ar.exception instanceof CommandException) { |
| 1082 | CommandException.Error error = |
| 1083 | ((CommandException) (ar.exception)).getCommandError(); |
| 1084 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1085 | request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE; |
| 1086 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1087 | request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED; |
| 1088 | } else { |
| 1089 | request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR; |
| 1090 | } |
| 1091 | loge("setVoNrEnabled" + ": CommandException: " |
| 1092 | + ar.exception); |
| 1093 | } else { |
| 1094 | loge("setVoNrEnabled" + ": Unknown exception"); |
| 1095 | } |
| 1096 | } |
| 1097 | notifyRequester(request); |
| 1098 | break; |
| 1099 | } |
| 1100 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1101 | case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1102 | request = (MainThreadRequest) msg.obj; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1103 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE, |
| 1104 | request); |
| 1105 | getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1106 | break; |
| 1107 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1108 | case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1109 | ar = (AsyncResult) msg.obj; |
| 1110 | request = (MainThreadRequest) ar.userObj; |
| 1111 | if (ar.exception == null && ar.result != null) { |
| 1112 | request.result = ar.result; // Integer |
| 1113 | } else { |
Nazish Tabassum | e8ba43a | 2020-07-28 14:49:25 +0530 | [diff] [blame] | 1114 | // request.result must be set to something non-null |
| 1115 | // for the calling thread to unblock |
| 1116 | request.result = new int[]{-1}; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1117 | if (ar.result == null) { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1118 | loge("getAllowedNetworkTypesBitmask: Empty response"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1119 | } else if (ar.exception instanceof CommandException) { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1120 | loge("getAllowedNetworkTypesBitmask: CommandException: " |
| 1121 | + ar.exception); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1122 | } else { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1123 | loge("getAllowedNetworkTypesBitmask: Unknown exception"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1124 | } |
| 1125 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1126 | notifyRequester(request); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1127 | break; |
| 1128 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1129 | case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1130 | request = (MainThreadRequest) msg.obj; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1131 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE, |
| 1132 | request); |
| 1133 | Pair<Integer, Long> reasonWithNetworkTypes = |
| 1134 | (Pair<Integer, Long>) request.argument; |
| 1135 | getPhoneFromRequest(request).setAllowedNetworkTypes( |
| 1136 | reasonWithNetworkTypes.first, |
| 1137 | reasonWithNetworkTypes.second, |
| 1138 | onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1139 | break; |
| 1140 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1141 | case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE: |
| 1142 | handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1143 | break; |
| 1144 | |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 1145 | case CMD_INVOKE_OEM_RIL_REQUEST_RAW: |
| 1146 | request = (MainThreadRequest)msg.obj; |
| 1147 | onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1148 | defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 1149 | break; |
| 1150 | |
| 1151 | case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE: |
| 1152 | ar = (AsyncResult)msg.obj; |
| 1153 | request = (MainThreadRequest)ar.userObj; |
| 1154 | request.result = ar; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1155 | notifyRequester(request); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 1156 | break; |
| 1157 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1158 | case CMD_SET_VOICEMAIL_NUMBER: |
| 1159 | request = (MainThreadRequest) msg.obj; |
| 1160 | onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request); |
| 1161 | Pair<String, String> tagNum = (Pair<String, String>) request.argument; |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1162 | getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second, |
| 1163 | onCompleted); |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1164 | break; |
| 1165 | |
| 1166 | case EVENT_SET_VOICEMAIL_NUMBER_DONE: |
| 1167 | handleNullReturnEvent(msg, "setVoicemailNumber"); |
| 1168 | break; |
| 1169 | |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 1170 | case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC: |
| 1171 | request = (MainThreadRequest) msg.obj; |
| 1172 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE, |
| 1173 | request); |
| 1174 | getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted); |
| 1175 | break; |
| 1176 | |
| 1177 | case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE: |
| 1178 | handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic"); |
| 1179 | break; |
| 1180 | |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1181 | case CMD_PERFORM_NETWORK_SCAN: |
| 1182 | request = (MainThreadRequest) msg.obj; |
| 1183 | onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request); |
| 1184 | getPhoneFromRequest(request).getAvailableNetworks(onCompleted); |
| 1185 | break; |
| 1186 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1187 | case CMD_GET_CALL_FORWARDING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1188 | request = (MainThreadRequest) msg.obj; |
| 1189 | onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1190 | Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args = |
| 1191 | (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>) |
| 1192 | request.argument; |
| 1193 | int callForwardingReason = args.first; |
| 1194 | request.phone.getCallForwardingOption(callForwardingReason, onCompleted); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1195 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1196 | } |
| 1197 | case EVENT_GET_CALL_FORWARDING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1198 | ar = (AsyncResult) msg.obj; |
| 1199 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1200 | TelephonyManager.CallForwardingInfoCallback callback = |
| 1201 | ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>) |
| 1202 | request.argument).second; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1203 | if (ar.exception == null && ar.result != null) { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1204 | CallForwardingInfo callForwardingInfo = null; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1205 | CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result; |
| 1206 | for (CallForwardInfo callForwardInfo : callForwardInfos) { |
| 1207 | // Service Class is a bit mask per 3gpp 27.007. Search for |
| 1208 | // any service for voice call. |
| 1209 | if ((callForwardInfo.serviceClass |
| 1210 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0) { |
Yuchen Dong | 69cc141 | 2021-09-27 20:27:01 +0800 | [diff] [blame] | 1211 | callForwardingInfo = new CallForwardingInfo( |
| 1212 | callForwardInfo.status |
| 1213 | == CommandsInterface.CF_ACTION_ENABLE, |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1214 | callForwardInfo.reason, |
| 1215 | callForwardInfo.number, |
| 1216 | callForwardInfo.timeSeconds); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1217 | break; |
| 1218 | } |
| 1219 | } |
| 1220 | // Didn't find a call forward info for voice call. |
| 1221 | if (callForwardingInfo == null) { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1222 | callForwardingInfo = new CallForwardingInfo(false /* enabled */, |
| 1223 | 0 /* reason */, null /* number */, 0 /* timeout */); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1224 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1225 | callback.onCallForwardingInfoAvailable(callForwardingInfo); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1226 | } else { |
| 1227 | if (ar.result == null) { |
| 1228 | loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response"); |
| 1229 | } |
| 1230 | if (ar.exception != null) { |
| 1231 | loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception); |
| 1232 | } |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1233 | int errorCode = TelephonyManager |
| 1234 | .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1235 | if (ar.exception instanceof CommandException) { |
| 1236 | CommandException.Error error = |
| 1237 | ((CommandException) (ar.exception)).getCommandError(); |
| 1238 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1239 | errorCode = TelephonyManager |
| 1240 | .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1241 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1242 | errorCode = TelephonyManager |
| 1243 | .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1244 | } |
| 1245 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1246 | callback.onError(errorCode); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1247 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1248 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1249 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1250 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1251 | case CMD_SET_CALL_FORWARDING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1252 | request = (MainThreadRequest) msg.obj; |
| 1253 | onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1254 | request = (MainThreadRequest) msg.obj; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1255 | CallForwardingInfo callForwardingInfoToSet = |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1256 | ((Pair<CallForwardingInfo, Consumer<Integer>>) |
| 1257 | request.argument).first; |
| 1258 | request.phone.setCallForwardingOption( |
| 1259 | callForwardingInfoToSet.isEnabled() |
Calvin Pan | 258f1f7 | 2021-07-28 21:46:56 +0800 | [diff] [blame] | 1260 | ? CommandsInterface.CF_ACTION_REGISTRATION |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1261 | : CommandsInterface.CF_ACTION_DISABLE, |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1262 | callForwardingInfoToSet.getReason(), |
| 1263 | callForwardingInfoToSet.getNumber(), |
| 1264 | callForwardingInfoToSet.getTimeoutSeconds(), onCompleted); |
| 1265 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1266 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1267 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1268 | case EVENT_SET_CALL_FORWARDING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1269 | ar = (AsyncResult) msg.obj; |
| 1270 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1271 | Consumer<Integer> callback = |
| 1272 | ((Pair<CallForwardingInfo, Consumer<Integer>>) |
| 1273 | request.argument).second; |
| 1274 | if (ar.exception != null) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1275 | loge("setCallForwarding exception: " + ar.exception); |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1276 | int errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1277 | .RESULT_ERROR_UNKNOWN; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1278 | if (ar.exception instanceof CommandException) { |
| 1279 | CommandException.Error error = |
| 1280 | ((CommandException) (ar.exception)).getCommandError(); |
| 1281 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1282 | errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1283 | .RESULT_ERROR_FDN_CHECK_FAILURE; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1284 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1285 | errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1286 | .RESULT_ERROR_NOT_SUPPORTED; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1287 | } |
| 1288 | } |
| 1289 | callback.accept(errorCode); |
| 1290 | } else { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1291 | callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1292 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1293 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1294 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1295 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1296 | case CMD_GET_CALL_WAITING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1297 | request = (MainThreadRequest) msg.obj; |
| 1298 | onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request); |
| 1299 | getPhoneFromRequest(request).getCallWaiting(onCompleted); |
| 1300 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1301 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1302 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1303 | case EVENT_GET_CALL_WAITING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1304 | ar = (AsyncResult) msg.obj; |
| 1305 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1306 | Consumer<Integer> callback = (Consumer<Integer>) request.argument; |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1307 | int callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1308 | if (ar.exception == null && ar.result != null) { |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1309 | int[] callForwardResults = (int[]) ar.result; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1310 | // Service Class is a bit mask per 3gpp 27.007. |
| 1311 | // Search for any service for voice call. |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1312 | if (callForwardResults.length > 1 |
| 1313 | && ((callForwardResults[1] |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1314 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) { |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1315 | callWaitingStatus = callForwardResults[0] == 0 |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1316 | ? TelephonyManager.CALL_WAITING_STATUS_DISABLED |
| 1317 | : TelephonyManager.CALL_WAITING_STATUS_ENABLED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1318 | } else { |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1319 | callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1320 | } |
| 1321 | } else { |
| 1322 | if (ar.result == null) { |
| 1323 | loge("EVENT_GET_CALL_WAITING_DONE: Empty response"); |
| 1324 | } |
| 1325 | if (ar.exception != null) { |
| 1326 | loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception); |
| 1327 | } |
| 1328 | if (ar.exception instanceof CommandException) { |
| 1329 | CommandException.Error error = |
| 1330 | ((CommandException) (ar.exception)).getCommandError(); |
| 1331 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1332 | callWaitingStatus = |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1333 | TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED; |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1334 | } else if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
| 1335 | callWaitingStatus = |
| 1336 | TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1337 | } |
| 1338 | } |
| 1339 | } |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1340 | callback.accept(callWaitingStatus); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1341 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1342 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1343 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1344 | case CMD_SET_CALL_WAITING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1345 | request = (MainThreadRequest) msg.obj; |
| 1346 | onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1347 | boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first; |
| 1348 | getPhoneFromRequest(request).setCallWaiting(enable, onCompleted); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1349 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1350 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1351 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1352 | case EVENT_SET_CALL_WAITING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1353 | ar = (AsyncResult) msg.obj; |
| 1354 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1355 | boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first; |
| 1356 | Consumer<Integer> callback = |
| 1357 | ((Pair<Boolean, Consumer<Integer>>) request.argument).second; |
| 1358 | if (ar.exception != null) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1359 | loge("setCallWaiting exception: " + ar.exception); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1360 | if (ar.exception instanceof CommandException) { |
| 1361 | CommandException.Error error = |
| 1362 | ((CommandException) (ar.exception)).getCommandError(); |
| 1363 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1364 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED); |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1365 | } else if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
| 1366 | callback.accept( |
| 1367 | TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1368 | } else { |
| 1369 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 1370 | } |
| 1371 | } else { |
| 1372 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 1373 | } |
| 1374 | } else { |
| 1375 | callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED |
| 1376 | : TelephonyManager.CALL_WAITING_STATUS_DISABLED); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1377 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1378 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1379 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1380 | case EVENT_PERFORM_NETWORK_SCAN_DONE: |
| 1381 | ar = (AsyncResult) msg.obj; |
| 1382 | request = (MainThreadRequest) ar.userObj; |
| 1383 | CellNetworkScanResult cellScanResult; |
| 1384 | if (ar.exception == null && ar.result != null) { |
| 1385 | cellScanResult = new CellNetworkScanResult( |
| 1386 | CellNetworkScanResult.STATUS_SUCCESS, |
| 1387 | (List<OperatorInfo>) ar.result); |
| 1388 | } else { |
| 1389 | if (ar.result == null) { |
| 1390 | loge("getCellNetworkScanResults: Empty response"); |
| 1391 | } |
| 1392 | if (ar.exception != null) { |
| 1393 | loge("getCellNetworkScanResults: Exception: " + ar.exception); |
| 1394 | } |
| 1395 | int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR; |
| 1396 | if (ar.exception instanceof CommandException) { |
| 1397 | CommandException.Error error = |
| 1398 | ((CommandException) (ar.exception)).getCommandError(); |
| 1399 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1400 | errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE; |
| 1401 | } else if (error == CommandException.Error.GENERIC_FAILURE) { |
| 1402 | errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE; |
| 1403 | } |
| 1404 | } |
| 1405 | cellScanResult = new CellNetworkScanResult(errorCode, null); |
| 1406 | } |
| 1407 | request.result = cellScanResult; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1408 | notifyRequester(request); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1409 | break; |
| 1410 | |
| 1411 | case CMD_SET_NETWORK_SELECTION_MODE_MANUAL: |
| 1412 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1413 | ManualNetworkSelectionArgument selArg = |
| 1414 | (ManualNetworkSelectionArgument) request.argument; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1415 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE, |
| 1416 | request); |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1417 | getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo, |
| 1418 | selArg.persistSelection, onCompleted); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1419 | break; |
| 1420 | |
| 1421 | case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE: |
Pengquan Meng | e3d01e2 | 2018-09-20 15:25:35 -0700 | [diff] [blame] | 1422 | ar = (AsyncResult) msg.obj; |
| 1423 | request = (MainThreadRequest) ar.userObj; |
| 1424 | if (ar.exception == null) { |
| 1425 | request.result = true; |
| 1426 | } else { |
| 1427 | request.result = false; |
| 1428 | loge("setNetworkSelectionModeManual " + ar.exception); |
| 1429 | } |
| 1430 | notifyRequester(request); |
| 1431 | mApp.onNetworkSelectionChanged(request.subId); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1432 | break; |
| 1433 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1434 | case CMD_GET_MODEM_ACTIVITY_INFO: |
| 1435 | request = (MainThreadRequest) msg.obj; |
| 1436 | onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1437 | if (defaultPhone != null) { |
| 1438 | defaultPhone.getModemActivityInfo(onCompleted, request.workSource); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1439 | } else { |
| 1440 | ResultReceiver result = (ResultReceiver) request.argument; |
| 1441 | Bundle bundle = new Bundle(); |
| 1442 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 1443 | new ModemActivityInfo(0, 0, 0, |
| 1444 | new int[ModemActivityInfo.getNumTxPowerLevels()], 0)); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1445 | result.send(0, bundle); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1446 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1447 | break; |
| 1448 | |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1449 | case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: { |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1450 | ar = (AsyncResult) msg.obj; |
| 1451 | request = (MainThreadRequest) ar.userObj; |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1452 | ResultReceiver result = (ResultReceiver) request.argument; |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1453 | int error = 0; |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 1454 | ModemActivityInfo ret = null; |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1455 | if (mLastModemActivityInfo == null) { |
| 1456 | mLastModemActivitySpecificInfo = new ActivityStatsTechSpecificInfo[1]; |
| 1457 | mLastModemActivitySpecificInfo[0] = |
| 1458 | new ActivityStatsTechSpecificInfo( |
| 1459 | 0, |
| 1460 | 0, |
| 1461 | new int[ModemActivityInfo.getNumTxPowerLevels()], |
| 1462 | 0); |
| 1463 | mLastModemActivityInfo = |
| 1464 | new ModemActivityInfo(0, 0, 0, mLastModemActivitySpecificInfo); |
| 1465 | } |
| 1466 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1467 | if (ar.exception == null && ar.result != null) { |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1468 | // Update the last modem activity info and the result of the request. |
| 1469 | ModemActivityInfo info = (ModemActivityInfo) ar.result; |
| 1470 | if (isModemActivityInfoValid(info)) { |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1471 | mergeModemActivityInfo(info); |
Gary Jian | 76280a4 | 2022-12-07 16:18:33 +0800 | [diff] [blame] | 1472 | } else { |
| 1473 | loge("queryModemActivityInfo: invalid response"); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1474 | } |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 1475 | // This is needed to decouple ret from mLastModemActivityInfo |
| 1476 | // We don't want to return mLastModemActivityInfo which is updated |
| 1477 | // inside mergeModemActivityInfo() |
| 1478 | ret = new ModemActivityInfo( |
| 1479 | mLastModemActivityInfo.getTimestampMillis(), |
| 1480 | mLastModemActivityInfo.getSleepTimeMillis(), |
| 1481 | mLastModemActivityInfo.getIdleTimeMillis(), |
| 1482 | deepCopyModemActivitySpecificInfo(mLastModemActivitySpecificInfo)); |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1483 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1484 | } else { |
| 1485 | if (ar.result == null) { |
| 1486 | loge("queryModemActivityInfo: Empty response"); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1487 | error = TelephonyManager.ModemActivityInfoException |
| 1488 | .ERROR_INVALID_INFO_RECEIVED; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1489 | } else if (ar.exception instanceof CommandException) { |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1490 | loge("queryModemActivityInfo: CommandException: " + ar.exception); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1491 | error = TelephonyManager.ModemActivityInfoException |
| 1492 | .ERROR_MODEM_RESPONSE_ERROR; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1493 | } else { |
| 1494 | loge("queryModemActivityInfo: Unknown exception"); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1495 | error = TelephonyManager.ModemActivityInfoException |
| 1496 | .ERROR_UNKNOWN; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1497 | } |
| 1498 | } |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1499 | Bundle bundle = new Bundle(); |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 1500 | if (ret != null) { |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1501 | bundle.putParcelable( |
| 1502 | TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 1503 | ret); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1504 | } else { |
| 1505 | bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error); |
| 1506 | } |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1507 | result.send(0, bundle); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1508 | notifyRequester(request); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1509 | break; |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1510 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1511 | |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1512 | case CMD_SET_ALLOWED_CARRIERS: |
| 1513 | request = (MainThreadRequest) msg.obj; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1514 | CarrierRestrictionRules argument = |
| 1515 | (CarrierRestrictionRules) request.argument; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1516 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request); |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1517 | defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1518 | break; |
| 1519 | |
| 1520 | case EVENT_SET_ALLOWED_CARRIERS_DONE: |
| 1521 | ar = (AsyncResult) msg.obj; |
| 1522 | request = (MainThreadRequest) ar.userObj; |
| 1523 | if (ar.exception == null && ar.result != null) { |
| 1524 | request.result = ar.result; |
| 1525 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1526 | request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR; |
| 1527 | if (ar.exception instanceof CommandException) { |
| 1528 | loge("setAllowedCarriers: CommandException: " + ar.exception); |
| 1529 | CommandException.Error error = |
| 1530 | ((CommandException) (ar.exception)).getCommandError(); |
| 1531 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1532 | request.result = |
| 1533 | TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED; |
| 1534 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1535 | } else { |
| 1536 | loge("setAllowedCarriers: Unknown exception"); |
| 1537 | } |
| 1538 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1539 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1540 | break; |
| 1541 | |
| 1542 | case CMD_GET_ALLOWED_CARRIERS: |
| 1543 | request = (MainThreadRequest) msg.obj; |
| 1544 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1545 | defaultPhone.getAllowedCarriers(onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1546 | break; |
| 1547 | |
| 1548 | case EVENT_GET_ALLOWED_CARRIERS_DONE: |
| 1549 | ar = (AsyncResult) msg.obj; |
| 1550 | request = (MainThreadRequest) ar.userObj; |
| 1551 | if (ar.exception == null && ar.result != null) { |
| 1552 | request.result = ar.result; |
| 1553 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1554 | request.result = new IllegalStateException( |
| 1555 | "Failed to get carrier restrictions"); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1556 | if (ar.result == null) { |
| 1557 | loge("getAllowedCarriers: Empty response"); |
| 1558 | } else if (ar.exception instanceof CommandException) { |
| 1559 | loge("getAllowedCarriers: CommandException: " + |
| 1560 | ar.exception); |
| 1561 | } else { |
| 1562 | loge("getAllowedCarriers: Unknown exception"); |
| 1563 | } |
| 1564 | } |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 1565 | if (request.argument != null) { |
| 1566 | // This is for the implementation of carrierRestrictionStatus. |
| 1567 | CallerCallbackInfo callbackInfo = (CallerCallbackInfo) request.argument; |
| 1568 | Consumer<Integer> callback = callbackInfo.getConsumer(); |
| 1569 | int callerCarrierId = callbackInfo.getCarrierId(); |
| 1570 | int lockStatus = TelephonyManager.CARRIER_RESTRICTION_STATUS_UNKNOWN; |
| 1571 | if (ar.exception == null && ar.result instanceof CarrierRestrictionRules) { |
| 1572 | CarrierRestrictionRules carrierRestrictionRules = |
| 1573 | (CarrierRestrictionRules) ar.result; |
| 1574 | int carrierId = -1; |
| 1575 | try { |
| 1576 | CarrierIdentifier carrierIdentifier = |
| 1577 | carrierRestrictionRules.getAllowedCarriers().get(0); |
| 1578 | carrierId = CarrierResolver.getCarrierIdFromIdentifier(mApp, |
| 1579 | carrierIdentifier); |
| 1580 | } catch (NullPointerException | IndexOutOfBoundsException ex) { |
| 1581 | Rlog.e(LOG_TAG, "CarrierIdentifier exception = " + ex); |
| 1582 | } |
| 1583 | lockStatus = carrierRestrictionRules.getCarrierRestrictionStatus(); |
| 1584 | if (carrierId != -1 && callerCarrierId == carrierId && lockStatus |
| 1585 | == TelephonyManager.CARRIER_RESTRICTION_STATUS_RESTRICTED) { |
| 1586 | lockStatus = |
| 1587 | TelephonyManager.CARRIER_RESTRICTION_STATUS_RESTRICTED_TO_CALLER; |
| 1588 | } |
| 1589 | } else { |
| 1590 | Rlog.e(LOG_TAG, |
| 1591 | "getCarrierRestrictionStatus: exception ex = " + ar.exception); |
| 1592 | } |
| 1593 | callback.accept(lockStatus); |
| 1594 | } else { |
| 1595 | // This is for the implementation of getAllowedCarriers. |
| 1596 | notifyRequester(request); |
| 1597 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1598 | break; |
| 1599 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1600 | case EVENT_GET_FORBIDDEN_PLMNS_DONE: |
| 1601 | ar = (AsyncResult) msg.obj; |
| 1602 | request = (MainThreadRequest) ar.userObj; |
| 1603 | if (ar.exception == null && ar.result != null) { |
| 1604 | request.result = ar.result; |
| 1605 | } else { |
| 1606 | request.result = new IllegalArgumentException( |
| 1607 | "Failed to retrieve Forbidden Plmns"); |
| 1608 | if (ar.result == null) { |
| 1609 | loge("getForbiddenPlmns: Empty response"); |
| 1610 | } else { |
| 1611 | loge("getForbiddenPlmns: Unknown exception"); |
| 1612 | } |
| 1613 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1614 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1615 | break; |
| 1616 | |
| 1617 | case CMD_GET_FORBIDDEN_PLMNS: |
| 1618 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1619 | uiccPort = getUiccPortFromRequest(request); |
| 1620 | if (uiccPort == null) { |
| 1621 | loge("getForbiddenPlmns() UiccPort is null"); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1622 | request.result = new IllegalArgumentException( |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1623 | "getForbiddenPlmns() UiccPort is null"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1624 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1625 | break; |
| 1626 | } |
| 1627 | Integer appType = (Integer) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1628 | UiccCardApplication uiccApp = uiccPort.getApplicationByType(appType); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1629 | if (uiccApp == null) { |
| 1630 | loge("getForbiddenPlmns() no app with specified type -- " |
| 1631 | + appType); |
| 1632 | request.result = new IllegalArgumentException("Failed to get UICC App"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1633 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1634 | break; |
| 1635 | } else { |
| 1636 | if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid() |
| 1637 | + " specified type -- " + appType); |
| 1638 | } |
| 1639 | onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request); |
| 1640 | ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns( |
| 1641 | onCompleted); |
| 1642 | break; |
| 1643 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1644 | case CMD_SWITCH_SLOTS: |
| 1645 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 1646 | List<UiccSlotMapping> slotMapping = (List<UiccSlotMapping>) request.argument; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1647 | onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 1648 | UiccController.getInstance().switchSlots(slotMapping, onCompleted); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1649 | break; |
| 1650 | |
| 1651 | case EVENT_SWITCH_SLOTS_DONE: |
| 1652 | ar = (AsyncResult) msg.obj; |
| 1653 | request = (MainThreadRequest) ar.userObj; |
| 1654 | request.result = (ar.exception == null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1655 | notifyRequester(request); |
| 1656 | break; |
| 1657 | case CMD_GET_NETWORK_SELECTION_MODE: |
| 1658 | request = (MainThreadRequest) msg.obj; |
| 1659 | onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request); |
| 1660 | getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted); |
| 1661 | break; |
| 1662 | |
| 1663 | case EVENT_GET_NETWORK_SELECTION_MODE_DONE: |
| 1664 | ar = (AsyncResult) msg.obj; |
| 1665 | request = (MainThreadRequest) ar.userObj; |
| 1666 | if (ar.exception != null) { |
| 1667 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 1668 | } else { |
| 1669 | int mode = ((int[]) ar.result)[0]; |
| 1670 | if (mode == 0) { |
| 1671 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO; |
| 1672 | } else { |
| 1673 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL; |
| 1674 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1675 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1676 | notifyRequester(request); |
| 1677 | break; |
| 1678 | case CMD_GET_CDMA_ROAMING_MODE: |
| 1679 | request = (MainThreadRequest) msg.obj; |
| 1680 | onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request); |
| 1681 | getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted); |
| 1682 | break; |
| 1683 | case EVENT_GET_CDMA_ROAMING_MODE_DONE: |
| 1684 | ar = (AsyncResult) msg.obj; |
| 1685 | request = (MainThreadRequest) ar.userObj; |
| 1686 | if (ar.exception != null) { |
| 1687 | request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT; |
| 1688 | } else { |
| 1689 | request.result = ((int[]) ar.result)[0]; |
| 1690 | } |
| 1691 | notifyRequester(request); |
| 1692 | break; |
| 1693 | case CMD_SET_CDMA_ROAMING_MODE: |
| 1694 | request = (MainThreadRequest) msg.obj; |
| 1695 | onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request); |
| 1696 | int mode = (int) request.argument; |
| 1697 | getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted); |
| 1698 | break; |
| 1699 | case EVENT_SET_CDMA_ROAMING_MODE_DONE: |
| 1700 | ar = (AsyncResult) msg.obj; |
| 1701 | request = (MainThreadRequest) ar.userObj; |
| 1702 | request.result = ar.exception == null; |
| 1703 | notifyRequester(request); |
| 1704 | break; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 1705 | case CMD_GET_CDMA_SUBSCRIPTION_MODE: |
| 1706 | request = (MainThreadRequest) msg.obj; |
| 1707 | onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1708 | getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted); |
| 1709 | break; |
| 1710 | case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1711 | ar = (AsyncResult) msg.obj; |
| 1712 | request = (MainThreadRequest) ar.userObj; |
| 1713 | if (ar.exception != null) { |
| 1714 | request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM; |
| 1715 | } else { |
| 1716 | request.result = ((int[]) ar.result)[0]; |
| 1717 | } |
| 1718 | notifyRequester(request); |
| 1719 | break; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1720 | case CMD_SET_CDMA_SUBSCRIPTION_MODE: |
| 1721 | request = (MainThreadRequest) msg.obj; |
| 1722 | onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1723 | int subscriptionMode = (int) request.argument; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 1724 | getPhoneFromRequest(request).setCdmaSubscriptionMode( |
| 1725 | subscriptionMode, onCompleted); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1726 | break; |
| 1727 | case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1728 | ar = (AsyncResult) msg.obj; |
| 1729 | request = (MainThreadRequest) ar.userObj; |
| 1730 | request.result = ar.exception == null; |
| 1731 | notifyRequester(request); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1732 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1733 | case CMD_GET_ALL_CELL_INFO: |
| 1734 | request = (MainThreadRequest) msg.obj; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1735 | onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1736 | request.phone.requestCellInfoUpdate(request.workSource, onCompleted); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1737 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1738 | case EVENT_GET_ALL_CELL_INFO_DONE: |
| 1739 | ar = (AsyncResult) msg.obj; |
| 1740 | request = (MainThreadRequest) ar.userObj; |
Nathan Harold | 8d0f174 | 2018-10-02 12:14:47 -0700 | [diff] [blame] | 1741 | // If a timeout occurs, the response will be null |
| 1742 | request.result = (ar.exception == null && ar.result != null) |
| 1743 | ? ar.result : new ArrayList<CellInfo>(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1744 | synchronized (request) { |
| 1745 | request.notifyAll(); |
| 1746 | } |
| 1747 | break; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1748 | case CMD_REQUEST_CELL_INFO_UPDATE: |
| 1749 | request = (MainThreadRequest) msg.obj; |
| 1750 | request.phone.requestCellInfoUpdate(request.workSource, |
| 1751 | obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request)); |
| 1752 | break; |
| 1753 | case EVENT_REQUEST_CELL_INFO_UPDATE_DONE: |
| 1754 | ar = (AsyncResult) msg.obj; |
| 1755 | request = (MainThreadRequest) ar.userObj; |
| 1756 | ICellInfoCallback cb = (ICellInfoCallback) request.argument; |
| 1757 | try { |
| 1758 | if (ar.exception != null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1759 | Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception); |
Meng Wang | d8921f4 | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1760 | cb.onError( |
| 1761 | TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR, |
| 1762 | ar.exception.getClass().getName(), |
| 1763 | ar.exception.toString()); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1764 | } else if (ar.result == null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1765 | Log.w(LOG_TAG, "Timeout Waiting for CellInfo!"); |
Meng Wang | d8921f4 | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1766 | cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1767 | } else { |
| 1768 | // use the result as returned |
| 1769 | cb.onCellInfo((List<CellInfo>) ar.result); |
| 1770 | } |
| 1771 | } catch (RemoteException re) { |
| 1772 | Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException"); |
| 1773 | } |
| 1774 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1775 | case CMD_GET_CELL_LOCATION: { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1776 | request = (MainThreadRequest) msg.obj; |
| 1777 | WorkSource ws = (WorkSource) request.argument; |
| 1778 | Phone phone = getPhoneFromRequest(request); |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1779 | phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request)); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1780 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1781 | } |
| 1782 | case EVENT_GET_CELL_LOCATION_DONE: { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1783 | ar = (AsyncResult) msg.obj; |
| 1784 | request = (MainThreadRequest) ar.userObj; |
| 1785 | if (ar.exception == null) { |
| 1786 | request.result = ar.result; |
| 1787 | } else { |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1788 | Phone phone = getPhoneFromRequest(request); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1789 | request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1790 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1791 | } |
| 1792 | |
| 1793 | synchronized (request) { |
| 1794 | request.notifyAll(); |
| 1795 | } |
| 1796 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1797 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1798 | case CMD_MODEM_REBOOT: |
| 1799 | request = (MainThreadRequest) msg.obj; |
| 1800 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1801 | defaultPhone.rebootModem(onCompleted); |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1802 | break; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1803 | case EVENT_CMD_MODEM_REBOOT_DONE: |
| 1804 | handleNullReturnEvent(msg, "rebootModem"); |
| 1805 | break; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1806 | case CMD_REQUEST_ENABLE_MODEM: |
| 1807 | request = (MainThreadRequest) msg.obj; |
| 1808 | boolean enable = (boolean) request.argument; |
| 1809 | onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1810 | onCompleted.arg1 = enable ? 1 : 0; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1811 | PhoneConfigurationManager.getInstance() |
| 1812 | .enablePhone(request.phone, enable, onCompleted); |
| 1813 | break; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1814 | case EVENT_ENABLE_MODEM_DONE: { |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1815 | ar = (AsyncResult) msg.obj; |
| 1816 | request = (MainThreadRequest) ar.userObj; |
| 1817 | request.result = (ar.exception == null); |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1818 | int phoneId = request.phone.getPhoneId(); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1819 | //update the cache as modem status has changed |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1820 | if ((boolean) request.result) { |
| 1821 | mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1); |
| 1822 | updateModemStateMetrics(); |
| 1823 | } else { |
| 1824 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1825 | + ar.exception); |
| 1826 | } |
| 1827 | notifyRequester(request); |
| 1828 | break; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1829 | } |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1830 | case CMD_GET_MODEM_STATUS: |
| 1831 | request = (MainThreadRequest) msg.obj; |
| 1832 | onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request); |
| 1833 | PhoneConfigurationManager.getInstance() |
| 1834 | .getPhoneStatusFromModem(request.phone, onCompleted); |
| 1835 | break; |
| 1836 | case EVENT_GET_MODEM_STATUS_DONE: |
| 1837 | ar = (AsyncResult) msg.obj; |
| 1838 | request = (MainThreadRequest) ar.userObj; |
| 1839 | int id = request.phone.getPhoneId(); |
| 1840 | if (ar.exception == null && ar.result != null) { |
| 1841 | request.result = ar.result; |
| 1842 | //update the cache as modem status has changed |
| 1843 | mPhoneConfigurationManager.addToPhoneStatusCache(id, |
| 1844 | (boolean) request.result); |
| 1845 | } else { |
| 1846 | // Return true if modem status cannot be retrieved. For most cases, |
| 1847 | // modem status is on. And for older version modems, GET_MODEM_STATUS |
| 1848 | // and disable modem are not supported. Modem is always on. |
| 1849 | // TODO: this should be fixed in R to support a third |
| 1850 | // status UNKNOWN b/131631629 |
| 1851 | request.result = true; |
| 1852 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1853 | + ar.exception); |
| 1854 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1855 | notifyRequester(request); |
| 1856 | break; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 1857 | case CMD_SET_SYSTEM_SELECTION_CHANNELS: { |
| 1858 | request = (MainThreadRequest) msg.obj; |
| 1859 | onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request); |
| 1860 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 1861 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 1862 | request.phone.setSystemSelectionChannels(args.first, onCompleted); |
| 1863 | break; |
| 1864 | } |
| 1865 | case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: { |
| 1866 | ar = (AsyncResult) msg.obj; |
| 1867 | request = (MainThreadRequest) ar.userObj; |
| 1868 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 1869 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 1870 | args.second.accept(ar.exception == null); |
| 1871 | notifyRequester(request); |
| 1872 | break; |
| 1873 | } |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1874 | case CMD_GET_SYSTEM_SELECTION_CHANNELS: { |
| 1875 | request = (MainThreadRequest) msg.obj; |
| 1876 | onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request); |
| 1877 | Phone phone = getPhoneFromRequest(request); |
| 1878 | if (phone != null) { |
| 1879 | phone.getSystemSelectionChannels(onCompleted); |
| 1880 | } else { |
| 1881 | loge("getSystemSelectionChannels: No phone object"); |
| 1882 | request.result = new ArrayList<RadioAccessSpecifier>(); |
| 1883 | notifyRequester(request); |
| 1884 | } |
| 1885 | break; |
| 1886 | } |
| 1887 | case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE: |
| 1888 | ar = (AsyncResult) msg.obj; |
| 1889 | request = (MainThreadRequest) ar.userObj; |
| 1890 | if (ar.exception == null && ar.result != null) { |
| 1891 | request.result = ar.result; |
| 1892 | } else { |
Sarah Chin | 428d1d6 | 2021-03-13 03:17:40 -0800 | [diff] [blame] | 1893 | request.result = new IllegalStateException( |
| 1894 | "Failed to retrieve system selecton channels"); |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1895 | if (ar.result == null) { |
| 1896 | loge("getSystemSelectionChannels: Empty response"); |
| 1897 | } else { |
| 1898 | loge("getSystemSelectionChannels: Unknown exception"); |
| 1899 | } |
| 1900 | } |
| 1901 | notifyRequester(request); |
| 1902 | break; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1903 | case EVENT_SET_FORBIDDEN_PLMNS_DONE: |
| 1904 | ar = (AsyncResult) msg.obj; |
| 1905 | request = (MainThreadRequest) ar.userObj; |
| 1906 | if (ar.exception == null && ar.result != null) { |
| 1907 | request.result = ar.result; |
| 1908 | } else { |
| 1909 | request.result = -1; |
| 1910 | loge("Failed to set Forbidden Plmns"); |
| 1911 | if (ar.result == null) { |
| 1912 | loge("setForbidenPlmns: Empty response"); |
| 1913 | } else if (ar.exception != null) { |
| 1914 | loge("setForbiddenPlmns: Exception: " + ar.exception); |
| 1915 | request.result = -1; |
| 1916 | } else { |
| 1917 | loge("setForbiddenPlmns: Unknown exception"); |
| 1918 | } |
| 1919 | } |
| 1920 | notifyRequester(request); |
| 1921 | break; |
| 1922 | case CMD_SET_FORBIDDEN_PLMNS: |
| 1923 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1924 | uiccPort = getUiccPortFromRequest(request); |
| 1925 | if (uiccPort == null) { |
| 1926 | loge("setForbiddenPlmns: UiccPort is null"); |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1927 | request.result = -1; |
| 1928 | notifyRequester(request); |
| 1929 | break; |
| 1930 | } |
| 1931 | Pair<Integer, List<String>> setFplmnsArgs = |
| 1932 | (Pair<Integer, List<String>>) request.argument; |
| 1933 | appType = setFplmnsArgs.first; |
| 1934 | List<String> fplmns = setFplmnsArgs.second; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1935 | uiccApp = uiccPort.getApplicationByType(appType); |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1936 | if (uiccApp == null) { |
| 1937 | loge("setForbiddenPlmns: no app with specified type -- " + appType); |
| 1938 | request.result = -1; |
| 1939 | loge("Failed to get UICC App"); |
| 1940 | notifyRequester(request); |
| 1941 | } else { |
| 1942 | onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request); |
| 1943 | ((SIMRecords) uiccApp.getIccRecords()) |
| 1944 | .setForbiddenPlmns(onCompleted, fplmns); |
| 1945 | } |
yinchengzhao | 4d163c0 | 2019-12-12 15:21:47 -0800 | [diff] [blame] | 1946 | break; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 1947 | case CMD_ERASE_MODEM_CONFIG: |
| 1948 | request = (MainThreadRequest) msg.obj; |
| 1949 | onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request); |
| 1950 | defaultPhone.eraseModemConfig(onCompleted); |
| 1951 | break; |
| 1952 | case EVENT_ERASE_MODEM_CONFIG_DONE: |
| 1953 | handleNullReturnEvent(msg, "eraseModemConfig"); |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1954 | break; |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1955 | |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 1956 | case CMD_ERASE_DATA_SHARED_PREFERENCES: |
| 1957 | request = (MainThreadRequest) msg.obj; |
| 1958 | request.result = defaultPhone.eraseDataInSharedPreferences(); |
| 1959 | notifyRequester(request); |
| 1960 | break; |
| 1961 | |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1962 | case CMD_CHANGE_ICC_LOCK_PASSWORD: |
| 1963 | request = (MainThreadRequest) msg.obj; |
| 1964 | onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request); |
| 1965 | Pair<String, String> changed = (Pair<String, String>) request.argument; |
| 1966 | getPhoneFromRequest(request).getIccCard().changeIccLockPassword( |
| 1967 | changed.first, changed.second, onCompleted); |
| 1968 | break; |
| 1969 | case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE: |
| 1970 | ar = (AsyncResult) msg.obj; |
| 1971 | request = (MainThreadRequest) ar.userObj; |
| 1972 | if (ar.exception == null) { |
| 1973 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1974 | // If the operation is successful, update the PIN storage |
| 1975 | Pair<String, String> passwords = (Pair<String, String>) request.argument; |
| 1976 | int phoneId = getPhoneFromRequest(request).getPhoneId(); |
Jon Spivack | 9c3bc76 | 2021-10-06 20:53:09 +0000 | [diff] [blame] | 1977 | UiccController.getInstance().getPinStorage() |
| 1978 | .storePin(passwords.second, phoneId); |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1979 | } else { |
| 1980 | request.result = msg.arg1; |
| 1981 | } |
| 1982 | notifyRequester(request); |
| 1983 | break; |
| 1984 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1985 | case CMD_SET_ICC_LOCK_ENABLED: { |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1986 | request = (MainThreadRequest) msg.obj; |
| 1987 | onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request); |
| 1988 | Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument; |
| 1989 | getPhoneFromRequest(request).getIccCard().setIccLockEnabled( |
| 1990 | enabled.first, enabled.second, onCompleted); |
| 1991 | break; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1992 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1993 | case EVENT_SET_ICC_LOCK_ENABLED_DONE: |
| 1994 | ar = (AsyncResult) msg.obj; |
| 1995 | request = (MainThreadRequest) ar.userObj; |
| 1996 | if (ar.exception == null) { |
| 1997 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1998 | // If the operation is successful, update the PIN storage |
| 1999 | Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument; |
| 2000 | int phoneId = getPhoneFromRequest(request).getPhoneId(); |
| 2001 | if (enabled.first) { |
Jon Spivack | 9c3bc76 | 2021-10-06 20:53:09 +0000 | [diff] [blame] | 2002 | UiccController.getInstance().getPinStorage() |
| 2003 | .storePin(enabled.second, phoneId); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2004 | } else { |
| 2005 | UiccController.getInstance().getPinStorage().clearPin(phoneId); |
| 2006 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 2007 | } else { |
| 2008 | request.result = msg.arg1; |
| 2009 | } |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2010 | |
| 2011 | |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 2012 | notifyRequester(request); |
| 2013 | break; |
| 2014 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 2015 | case MSG_NOTIFY_USER_ACTIVITY: |
| 2016 | removeMessages(MSG_NOTIFY_USER_ACTIVITY); |
Peter Wang | 59571be | 2020-01-27 12:35:15 +0800 | [diff] [blame] | 2017 | Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION); |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 2018 | intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY); |
| 2019 | getDefaultPhone().getContext().sendBroadcastAsUser( |
| 2020 | intent, UserHandle.ALL, permission.USER_ACTIVITY); |
| 2021 | break; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 2022 | |
| 2023 | case CMD_SET_DATA_THROTTLING: { |
| 2024 | request = (MainThreadRequest) msg.obj; |
| 2025 | onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request); |
| 2026 | DataThrottlingRequest dataThrottlingRequest = |
| 2027 | (DataThrottlingRequest) request.argument; |
| 2028 | Phone phone = getPhoneFromRequest(request); |
| 2029 | if (phone != null) { |
| 2030 | phone.setDataThrottling(onCompleted, |
| 2031 | request.workSource, dataThrottlingRequest.getDataThrottlingAction(), |
| 2032 | dataThrottlingRequest.getCompletionDurationMillis()); |
| 2033 | } else { |
| 2034 | loge("setDataThrottling: No phone object"); |
| 2035 | request.result = |
| 2036 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 2037 | notifyRequester(request); |
| 2038 | } |
| 2039 | |
| 2040 | break; |
| 2041 | } |
| 2042 | case EVENT_SET_DATA_THROTTLING_DONE: |
| 2043 | ar = (AsyncResult) msg.obj; |
| 2044 | request = (MainThreadRequest) ar.userObj; |
| 2045 | |
| 2046 | if (ar.exception == null) { |
| 2047 | request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 2048 | } else if (ar.exception instanceof CommandException) { |
| 2049 | loge("setDataThrottling: CommandException: " + ar.exception); |
| 2050 | CommandException.Error error = |
| 2051 | ((CommandException) (ar.exception)).getCommandError(); |
| 2052 | |
| 2053 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 2054 | request.result = TelephonyManager |
| 2055 | .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 2056 | } else if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 2057 | request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS; |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 2058 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 2059 | request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 2060 | } else { |
| 2061 | request.result = |
| 2062 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 2063 | } |
| 2064 | } else { |
| 2065 | request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 2066 | } |
| 2067 | Log.w(LOG_TAG, "DataThrottlingResult = " + request.result); |
| 2068 | notifyRequester(request); |
| 2069 | break; |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 2070 | |
| 2071 | case CMD_SET_SIM_POWER: { |
| 2072 | request = (MainThreadRequest) msg.obj; |
| 2073 | onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request); |
| 2074 | request = (MainThreadRequest) msg.obj; |
| 2075 | int stateToSet = |
| 2076 | ((Pair<Integer, IIntegerConsumer>) |
| 2077 | request.argument).first; |
| 2078 | request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource); |
| 2079 | break; |
| 2080 | } |
| 2081 | case EVENT_SET_SIM_POWER_DONE: { |
| 2082 | ar = (AsyncResult) msg.obj; |
| 2083 | request = (MainThreadRequest) ar.userObj; |
| 2084 | IIntegerConsumer callback = |
| 2085 | ((Pair<Integer, IIntegerConsumer>) request.argument).second; |
| 2086 | if (ar.exception != null) { |
| 2087 | loge("setSimPower exception: " + ar.exception); |
| 2088 | int errorCode = TelephonyManager.CallForwardingInfoCallback |
| 2089 | .RESULT_ERROR_UNKNOWN; |
| 2090 | if (ar.exception instanceof CommandException) { |
| 2091 | CommandException.Error error = |
| 2092 | ((CommandException) (ar.exception)).getCommandError(); |
| 2093 | if (error == CommandException.Error.SIM_ERR) { |
| 2094 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR; |
| 2095 | } else if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 2096 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE; |
| 2097 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 2098 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED; |
| 2099 | } else { |
| 2100 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR; |
| 2101 | } |
| 2102 | } |
| 2103 | try { |
| 2104 | callback.accept(errorCode); |
| 2105 | } catch (RemoteException e) { |
| 2106 | // Ignore if the remote process is no longer available to call back. |
| 2107 | Log.w(LOG_TAG, "setSimPower: callback not available."); |
| 2108 | } |
| 2109 | } else { |
| 2110 | try { |
| 2111 | callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS); |
| 2112 | } catch (RemoteException e) { |
| 2113 | // Ignore if the remote process is no longer available to call back. |
| 2114 | Log.w(LOG_TAG, "setSimPower: callback not available."); |
| 2115 | } |
| 2116 | } |
| 2117 | break; |
| 2118 | } |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 2119 | case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: { |
| 2120 | request = (MainThreadRequest) msg.obj; |
| 2121 | |
| 2122 | final Phone phone = getPhoneFromRequest(request); |
| 2123 | if (phone == null || phone.getServiceStateTracker() == null) { |
| 2124 | request.result = new IllegalStateException("Phone or SST is null"); |
| 2125 | notifyRequester(request); |
| 2126 | break; |
| 2127 | } |
| 2128 | |
| 2129 | Pair<Integer, SignalStrengthUpdateRequest> pair = |
| 2130 | (Pair<Integer, SignalStrengthUpdateRequest>) request.argument; |
| 2131 | onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE, |
| 2132 | request); |
Rambo Wang | 6568f17 | 2021-02-03 16:56:47 -0800 | [diff] [blame] | 2133 | phone.getSignalStrengthController().setSignalStrengthUpdateRequest( |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 2134 | request.subId, pair.first /*callingUid*/, |
| 2135 | pair.second /*request*/, onCompleted); |
| 2136 | break; |
| 2137 | } |
| 2138 | case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: { |
| 2139 | ar = (AsyncResult) msg.obj; |
| 2140 | request = (MainThreadRequest) ar.userObj; |
| 2141 | // request.result will be the exception of ar if present, true otherwise. |
| 2142 | // Be cautious not to leave result null which will wait() forever |
| 2143 | request.result = ar.exception != null ? ar.exception : true; |
| 2144 | notifyRequester(request); |
| 2145 | break; |
| 2146 | } |
| 2147 | case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: { |
| 2148 | request = (MainThreadRequest) msg.obj; |
| 2149 | |
| 2150 | Phone phone = getPhoneFromRequest(request); |
| 2151 | if (phone == null || phone.getServiceStateTracker() == null) { |
| 2152 | request.result = new IllegalStateException("Phone or SST is null"); |
| 2153 | notifyRequester(request); |
| 2154 | break; |
| 2155 | } |
| 2156 | |
| 2157 | Pair<Integer, SignalStrengthUpdateRequest> pair = |
| 2158 | (Pair<Integer, SignalStrengthUpdateRequest>) request.argument; |
| 2159 | onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE, |
| 2160 | request); |
Rambo Wang | 6568f17 | 2021-02-03 16:56:47 -0800 | [diff] [blame] | 2161 | phone.getSignalStrengthController().clearSignalStrengthUpdateRequest( |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 2162 | request.subId, pair.first /*callingUid*/, |
| 2163 | pair.second /*request*/, onCompleted); |
| 2164 | break; |
| 2165 | } |
| 2166 | case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: { |
| 2167 | ar = (AsyncResult) msg.obj; |
| 2168 | request = (MainThreadRequest) ar.userObj; |
| 2169 | request.result = ar.exception != null ? ar.exception : true; |
| 2170 | notifyRequester(request); |
| 2171 | break; |
| 2172 | } |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 2173 | |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2174 | case CMD_GET_SLICING_CONFIG: { |
| 2175 | request = (MainThreadRequest) msg.obj; |
| 2176 | onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request); |
| 2177 | request.phone.getSlicingConfig(onCompleted); |
| 2178 | break; |
| 2179 | } |
| 2180 | case EVENT_GET_SLICING_CONFIG_DONE: { |
| 2181 | ar = (AsyncResult) msg.obj; |
| 2182 | request = (MainThreadRequest) ar.userObj; |
| 2183 | ResultReceiver result = (ResultReceiver) request.argument; |
| 2184 | |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2185 | NetworkSlicingConfig slicingConfig = null; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2186 | Bundle bundle = new Bundle(); |
| 2187 | int resultCode = 0; |
| 2188 | if (ar.exception != null) { |
| 2189 | Log.e(LOG_TAG, "Exception retrieving slicing configuration=" |
| 2190 | + ar.exception); |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2191 | resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2192 | } else if (ar.result == null) { |
| 2193 | Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!"); |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2194 | resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2195 | } else { |
| 2196 | // use the result as returned |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2197 | resultCode = TelephonyManager.NetworkSlicingException.SUCCESS; |
| 2198 | slicingConfig = (NetworkSlicingConfig) ar.result; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2199 | } |
| 2200 | |
| 2201 | if (slicingConfig == null) { |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2202 | slicingConfig = new NetworkSlicingConfig(); |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2203 | } |
| 2204 | bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig); |
| 2205 | result.send(resultCode, bundle); |
| 2206 | notifyRequester(request); |
| 2207 | break; |
| 2208 | } |
| 2209 | |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2210 | case CMD_PURCHASE_PREMIUM_CAPABILITY: { |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2211 | request = (MainThreadRequest) msg.obj; |
| 2212 | onCompleted = obtainMessage(EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE, request); |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2213 | PurchasePremiumCapabilityArgument arg = |
| 2214 | (PurchasePremiumCapabilityArgument) request.argument; |
Sarah Chin | 46355ba | 2022-11-01 23:51:16 -0700 | [diff] [blame] | 2215 | SlicePurchaseController.getInstance(request.phone).purchasePremiumCapability( |
Sarah Chin | b8218c2 | 2023-01-04 13:35:29 -0800 | [diff] [blame] | 2216 | arg.capability, onCompleted); |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2217 | break; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2218 | } |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2219 | |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2220 | case EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE: { |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2221 | ar = (AsyncResult) msg.obj; |
| 2222 | request = (MainThreadRequest) ar.userObj; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2223 | PurchasePremiumCapabilityArgument arg = |
| 2224 | (PurchasePremiumCapabilityArgument) request.argument; |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2225 | try { |
| 2226 | int result = (int) ar.result; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2227 | arg.callback.accept(result); |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2228 | log("purchasePremiumCapability: capability=" |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2229 | + TelephonyManager.convertPremiumCapabilityToString(arg.capability) |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2230 | + ", result= " |
| 2231 | + TelephonyManager.convertPurchaseResultToString(result)); |
| 2232 | } catch (RemoteException e) { |
| 2233 | String logStr = "Purchase premium capability " |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2234 | + TelephonyManager.convertPremiumCapabilityToString(arg.capability) |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2235 | + " failed: " + e; |
| 2236 | if (DBG) log(logStr); |
| 2237 | AnomalyReporter.reportAnomaly( |
| 2238 | UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr); |
| 2239 | } |
| 2240 | break; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2241 | } |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2242 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2243 | case CMD_PREPARE_UNATTENDED_REBOOT: |
| 2244 | request = (MainThreadRequest) msg.obj; |
| 2245 | request.result = |
Rafael Higuera Silva | d963064 | 2021-09-20 15:32:01 +0000 | [diff] [blame] | 2246 | UiccController.getInstance().getPinStorage() |
| 2247 | .prepareUnattendedReboot(request.workSource); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2248 | notifyRequester(request); |
| 2249 | break; |
| 2250 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2251 | default: |
| 2252 | Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what); |
| 2253 | break; |
| 2254 | } |
| 2255 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2256 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 2257 | private void notifyRequester(MainThreadRequest request) { |
| 2258 | synchronized (request) { |
| 2259 | request.notifyAll(); |
| 2260 | } |
| 2261 | } |
| 2262 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2263 | private void handleNullReturnEvent(Message msg, String command) { |
| 2264 | AsyncResult ar = (AsyncResult) msg.obj; |
| 2265 | MainThreadRequest request = (MainThreadRequest) ar.userObj; |
| 2266 | if (ar.exception == null) { |
| 2267 | request.result = true; |
| 2268 | } else { |
| 2269 | request.result = false; |
| 2270 | if (ar.exception instanceof CommandException) { |
| 2271 | loge(command + ": CommandException: " + ar.exception); |
| 2272 | } else { |
| 2273 | loge(command + ": Unknown exception"); |
| 2274 | } |
| 2275 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 2276 | notifyRequester(request); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2277 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2278 | } |
| 2279 | |
| 2280 | /** |
| 2281 | * Posts the specified command to be executed on the main thread, |
| 2282 | * waits for the request to complete, and returns the result. |
| 2283 | * @see #sendRequestAsync |
| 2284 | */ |
| 2285 | private Object sendRequest(int command, Object argument) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2286 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, |
| 2287 | null, -1 /*timeoutInMs*/); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 2288 | } |
| 2289 | |
| 2290 | /** |
| 2291 | * Posts the specified command to be executed on the main thread, |
| 2292 | * waits for the request to complete, and returns the result. |
| 2293 | * @see #sendRequestAsync |
| 2294 | */ |
| 2295 | private Object sendRequest(int command, Object argument, WorkSource workSource) { |
| 2296 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2297 | null, workSource, -1 /*timeoutInMs*/); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2298 | } |
| 2299 | |
| 2300 | /** |
| 2301 | * Posts the specified command to be executed on the main thread, |
| 2302 | * waits for the request to complete, and returns the result. |
| 2303 | * @see #sendRequestAsync |
| 2304 | */ |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2305 | private Object sendRequest(int command, Object argument, Integer subId) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2306 | return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/); |
| 2307 | } |
| 2308 | |
| 2309 | /** |
| 2310 | * Posts the specified command to be executed on the main thread, |
| 2311 | * waits for the request to complete for at most {@code timeoutInMs}, and returns the result |
| 2312 | * if not timeout or null otherwise. |
| 2313 | * @see #sendRequestAsync |
| 2314 | */ |
| 2315 | private @Nullable Object sendRequest(int command, Object argument, Integer subId, |
| 2316 | long timeoutInMs) { |
| 2317 | return sendRequest(command, argument, subId, null, null, timeoutInMs); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 2318 | } |
| 2319 | |
| 2320 | /** |
| 2321 | * Posts the specified command to be executed on the main thread, |
| 2322 | * waits for the request to complete, and returns the result. |
| 2323 | * @see #sendRequestAsync |
| 2324 | */ |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2325 | private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2326 | return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2327 | } |
| 2328 | |
| 2329 | /** |
| 2330 | * Posts the specified command to be executed on the main thread, |
| 2331 | * waits for the request to complete, and returns the result. |
| 2332 | * @see #sendRequestAsync |
| 2333 | */ |
| 2334 | private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2335 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, |
| 2336 | workSource, -1 /*timeoutInMs*/); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2337 | } |
| 2338 | |
| 2339 | /** |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2340 | * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is |
| 2341 | * negative, waits for the request to complete, and returns the result. Otherwise, wait for |
| 2342 | * maximum of {@code timeoutInMs} milliseconds, interrupt and return null. |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2343 | * @see #sendRequestAsync |
| 2344 | */ |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2345 | private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone, |
| 2346 | WorkSource workSource, long timeoutInMs) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2347 | if (Looper.myLooper() == mMainThreadHandler.getLooper()) { |
| 2348 | throw new RuntimeException("This method will deadlock if called from the main thread."); |
| 2349 | } |
| 2350 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2351 | MainThreadRequest request = null; |
| 2352 | if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) { |
| 2353 | throw new IllegalArgumentException("subId and phone cannot both be specified!"); |
| 2354 | } else if (phone != null) { |
| 2355 | request = new MainThreadRequest(argument, phone, workSource); |
| 2356 | } else { |
| 2357 | request = new MainThreadRequest(argument, subId, workSource); |
| 2358 | } |
| 2359 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2360 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 2361 | msg.sendToTarget(); |
| 2362 | |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2363 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2364 | synchronized (request) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2365 | if (timeoutInMs >= 0) { |
| 2366 | // Wait for at least timeoutInMs before returning null request result |
| 2367 | long now = SystemClock.elapsedRealtime(); |
| 2368 | long deadline = now + timeoutInMs; |
Grace Jia | 8a0a1e8 | 2021-05-23 22:59:52 -0700 | [diff] [blame] | 2369 | while (request.result == null && now < deadline) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2370 | try { |
| 2371 | request.wait(deadline - now); |
| 2372 | } catch (InterruptedException e) { |
| 2373 | // Do nothing, go back and check if request is completed or timeout |
| 2374 | } finally { |
| 2375 | now = SystemClock.elapsedRealtime(); |
| 2376 | } |
| 2377 | } |
| 2378 | } else { |
| 2379 | // Wait for the request to complete |
| 2380 | while (request.result == null) { |
| 2381 | try { |
| 2382 | request.wait(); |
| 2383 | } catch (InterruptedException e) { |
| 2384 | // Do nothing, go back and wait until the request is complete |
| 2385 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2386 | } |
| 2387 | } |
| 2388 | } |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2389 | if (request.result == null) { |
| 2390 | Log.wtf(LOG_TAG, |
| 2391 | "sendRequest: Blocking command timed out. Something has gone terribly wrong."); |
| 2392 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2393 | return request.result; |
| 2394 | } |
| 2395 | |
| 2396 | /** |
| 2397 | * Asynchronous ("fire and forget") version of sendRequest(): |
| 2398 | * Posts the specified command to be executed on the main thread, and |
| 2399 | * returns immediately. |
| 2400 | * @see #sendRequest |
| 2401 | */ |
| 2402 | private void sendRequestAsync(int command) { |
| 2403 | mMainThreadHandler.sendEmptyMessage(command); |
| 2404 | } |
| 2405 | |
| 2406 | /** |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2407 | * Same as {@link #sendRequestAsync(int)} except it takes an argument. |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2408 | * @see {@link #sendRequest(int)} |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2409 | */ |
| 2410 | private void sendRequestAsync(int command, Object argument) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2411 | sendRequestAsync(command, argument, null, null); |
| 2412 | } |
| 2413 | |
| 2414 | /** |
| 2415 | * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource. |
| 2416 | * @see {@link #sendRequest(int,Object)} |
| 2417 | */ |
| 2418 | private void sendRequestAsync( |
| 2419 | int command, Object argument, Phone phone, WorkSource workSource) { |
| 2420 | MainThreadRequest request = new MainThreadRequest(argument, phone, workSource); |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2421 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 2422 | msg.sendToTarget(); |
| 2423 | } |
| 2424 | |
| 2425 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2426 | * Initialize the singleton PhoneInterfaceManager instance. |
| 2427 | * This is only done once, at startup, from PhoneApp.onCreate(). |
| 2428 | */ |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2429 | /* package */ static PhoneInterfaceManager init(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2430 | synchronized (PhoneInterfaceManager.class) { |
| 2431 | if (sInstance == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2432 | sInstance = new PhoneInterfaceManager(app); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2433 | } else { |
| 2434 | Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance); |
| 2435 | } |
| 2436 | return sInstance; |
| 2437 | } |
| 2438 | } |
| 2439 | |
| 2440 | /** Private constructor; @see init() */ |
Jordan Liu | 1979a04 | 2020-03-20 21:39:35 +0000 | [diff] [blame] | 2441 | private PhoneInterfaceManager(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2442 | mApp = app; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2443 | mCM = PhoneGlobals.getInstance().mCM; |
Brad Ebinger | d1947d8 | 2021-05-17 20:54:49 +0000 | [diff] [blame] | 2444 | mImsResolver = ImsResolver.getInstance(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 2445 | mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2446 | mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 2447 | mPm = app.getSystemService(PackageManager.class); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2448 | mMainThreadHandler = new MainThreadHandler(); |
Jack Yu | e37dd26 | 2022-12-16 11:53:37 -0800 | [diff] [blame] | 2449 | if (!PhoneFactory.isSubscriptionManagerServiceEnabled()) { |
| 2450 | mSubscriptionController = SubscriptionController.getInstance(); |
| 2451 | } else { |
| 2452 | mSubscriptionController = null; |
| 2453 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2454 | mTelephonySharedPreferences = |
| 2455 | PreferenceManager.getDefaultSharedPreferences(mApp); |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 2456 | mNetworkScanRequestTracker = new NetworkScanRequestTracker(); |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 2457 | mPhoneConfigurationManager = PhoneConfigurationManager.getInstance(); |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 2458 | mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance(); |
Peter Wang | a3cf4ac | 2020-01-27 09:39:46 +0800 | [diff] [blame] | 2459 | mNotifyUserActivity = new AtomicBoolean(false); |
Tyler Gunn | 64144d9 | 2022-03-17 14:16:41 -0700 | [diff] [blame] | 2460 | PropertyInvalidatedCache.invalidateCache(TelephonyManager.CACHE_KEY_PHONE_ACCOUNT_TO_SUBID); |
Gil Cukierman | d6cae88 | 2022-12-29 12:02:31 -0500 | [diff] [blame] | 2461 | mTelephony2gUpdater = new Telephony2gUpdater(mApp); |
Gil Cukierman | 6dac5eb | 2022-09-19 16:09:04 +0000 | [diff] [blame] | 2462 | mTelephony2gUpdater.init(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2463 | publish(); |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 2464 | CarrierAllowListInfo.loadInstance(mApp); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2465 | } |
| 2466 | |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 2467 | @VisibleForTesting |
| 2468 | public SharedPreferences getSharedPreferences() { |
| 2469 | return mTelephonySharedPreferences; |
| 2470 | } |
| 2471 | |
Gil Cukierman | 92cc7db | 2023-01-06 19:25:53 +0000 | [diff] [blame] | 2472 | /** |
| 2473 | * Get the default phone for this device. |
| 2474 | */ |
| 2475 | @VisibleForTesting |
| 2476 | public Phone getDefaultPhone() { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2477 | Phone thePhone = getPhone(getDefaultSubscription()); |
| 2478 | return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone(); |
| 2479 | } |
| 2480 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2481 | private void publish() { |
| 2482 | if (DBG) log("publish: " + this); |
| 2483 | |
Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 2484 | TelephonyFrameworkInitializer |
| 2485 | .getTelephonyServiceManager() |
| 2486 | .getTelephonyServiceRegisterer() |
| 2487 | .register(this); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2488 | } |
| 2489 | |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 2490 | private Phone getPhoneFromRequest(MainThreadRequest request) { |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 2491 | if (request.phone != null) { |
| 2492 | return request.phone; |
| 2493 | } else { |
| 2494 | return getPhoneFromSubId(request.subId); |
| 2495 | } |
| 2496 | } |
| 2497 | |
| 2498 | private Phone getPhoneFromSubId(int subId) { |
| 2499 | return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) |
| 2500 | ? getDefaultPhone() : getPhone(subId); |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 2501 | } |
| 2502 | |
Aishwarya Mallampati | 5e581e1 | 2023-01-17 21:57:06 +0000 | [diff] [blame] | 2503 | /** |
| 2504 | * Get phone object associated with a subscription. |
| 2505 | * Return default phone if phone object associated with subscription is null |
| 2506 | * @param subId - subscriptionId |
| 2507 | * @return phone object associated with a subscription or default phone if null. |
| 2508 | */ |
| 2509 | private Phone getPhoneFromSubIdOrDefault(int subId) { |
| 2510 | Phone phone = getPhoneFromSubId(subId); |
| 2511 | if (phone == null) { |
| 2512 | phone = getDefaultPhone(); |
| 2513 | } |
| 2514 | return phone; |
| 2515 | } |
| 2516 | |
Rambo Wang | e53e07d | 2022-05-10 13:01:13 -0700 | [diff] [blame] | 2517 | @Nullable |
| 2518 | private UiccPort getUiccPortFromRequest(@NonNull MainThreadRequest request) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2519 | Phone phone = getPhoneFromRequest(request); |
| 2520 | return phone == null ? null : |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 2521 | UiccController.getInstance().getUiccPort(phone.getPhoneId()); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2522 | } |
| 2523 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2524 | // returns phone associated with the subId. |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2525 | private Phone getPhone(int subId) { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 2526 | return PhoneFactory.getPhone(SubscriptionManager.getPhoneId(subId)); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2527 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2528 | |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 2529 | private void sendEraseModemConfig(@NonNull Phone phone) { |
| 2530 | Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null); |
| 2531 | if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 2532 | } |
| 2533 | |
| 2534 | private void sendEraseDataInSharedPreferences(@NonNull Phone phone) { |
| 2535 | Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null); |
| 2536 | if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail")); |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 2537 | } |
| 2538 | |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 2539 | private boolean isImsAvailableOnDevice() { |
| 2540 | PackageManager pm = getDefaultPhone().getContext().getPackageManager(); |
| 2541 | if (pm == null) { |
| 2542 | // For some reason package manger is not available.. This will fail internally anyway, |
| 2543 | // so do not throw error and allow. |
| 2544 | return true; |
| 2545 | } |
| 2546 | return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0); |
| 2547 | } |
| 2548 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2549 | public void dial(String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2550 | dialForSubscriber(getPreferredVoiceSubscription(), number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2551 | } |
| 2552 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2553 | public void dialForSubscriber(int subId, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2554 | if (DBG) log("dial: " + number); |
| 2555 | // No permission check needed here: This is just a wrapper around the |
| 2556 | // ACTION_DIAL intent, which is available to any app since it puts up |
| 2557 | // the UI before it does anything. |
| 2558 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2559 | final long identity = Binder.clearCallingIdentity(); |
| 2560 | try { |
| 2561 | String url = createTelUrl(number); |
| 2562 | if (url == null) { |
| 2563 | return; |
| 2564 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2565 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2566 | // PENDING: should we just silently fail if phone is offhook or ringing? |
| 2567 | PhoneConstants.State state = mCM.getState(subId); |
| 2568 | if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) { |
| 2569 | Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url)); |
| 2570 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2571 | mApp.startActivity(intent); |
| 2572 | } |
| 2573 | } finally { |
| 2574 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2575 | } |
| 2576 | } |
| 2577 | |
| 2578 | public void call(String callingPackage, String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2579 | callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2580 | } |
| 2581 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2582 | public void callForSubscriber(int subId, String callingPackage, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2583 | if (DBG) log("call: " + number); |
| 2584 | |
| 2585 | // This is just a wrapper around the ACTION_CALL intent, but we still |
| 2586 | // need to do a permission check since we're calling startActivity() |
| 2587 | // from the context of the phone app. |
| 2588 | enforceCallPermission(); |
| 2589 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 2590 | if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage) |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2591 | != AppOpsManager.MODE_ALLOWED) { |
| 2592 | return; |
| 2593 | } |
| 2594 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2595 | final long identity = Binder.clearCallingIdentity(); |
| 2596 | try { |
| 2597 | String url = createTelUrl(number); |
| 2598 | if (url == null) { |
| 2599 | return; |
| 2600 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2601 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2602 | boolean isValid = false; |
| 2603 | final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged(); |
| 2604 | if (slist != null) { |
| 2605 | for (SubscriptionInfo subInfoRecord : slist) { |
| 2606 | if (subInfoRecord.getSubscriptionId() == subId) { |
| 2607 | isValid = true; |
| 2608 | break; |
| 2609 | } |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 2610 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 2611 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2612 | if (!isValid) { |
| 2613 | return; |
| 2614 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 2615 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2616 | Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url)); |
| 2617 | intent.putExtra(SUBSCRIPTION_KEY, subId); |
| 2618 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2619 | mApp.startActivity(intent); |
| 2620 | } finally { |
| 2621 | Binder.restoreCallingIdentity(identity); |
| 2622 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2623 | } |
| 2624 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2625 | public boolean supplyPinForSubscriber(int subId, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2626 | int [] resultArray = supplyPinReportResultForSubscriber(subId, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2627 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 2628 | } |
| 2629 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2630 | public boolean supplyPukForSubscriber(int subId, String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2631 | int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2632 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 2633 | } |
| 2634 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2635 | public int[] supplyPinReportResultForSubscriber(int subId, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2636 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2637 | |
| 2638 | final long identity = Binder.clearCallingIdentity(); |
| 2639 | try { |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2640 | Phone phone = getPhone(subId); |
| 2641 | final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2642 | checkSimPin.start(); |
| 2643 | return checkSimPin.unlockSim(null, pin); |
| 2644 | } finally { |
| 2645 | Binder.restoreCallingIdentity(identity); |
| 2646 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2647 | } |
| 2648 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2649 | public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2650 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2651 | |
| 2652 | final long identity = Binder.clearCallingIdentity(); |
| 2653 | try { |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2654 | Phone phone = getPhone(subId); |
| 2655 | final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2656 | checkSimPuk.start(); |
| 2657 | return checkSimPuk.unlockSim(puk, pin); |
| 2658 | } finally { |
| 2659 | Binder.restoreCallingIdentity(identity); |
| 2660 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2661 | } |
| 2662 | |
| 2663 | /** |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2664 | * Helper thread to turn async call to SimCard#supplyPin into |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2665 | * a synchronous one. |
| 2666 | */ |
| 2667 | private static class UnlockSim extends Thread { |
| 2668 | |
| 2669 | private final IccCard mSimCard; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2670 | private final int mPhoneId; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2671 | |
| 2672 | private boolean mDone = false; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2673 | private int mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 2674 | private int mRetryCount = -1; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2675 | |
| 2676 | // For replies from SimCard interface |
| 2677 | private Handler mHandler; |
| 2678 | |
| 2679 | // For async handler to identify request type |
| 2680 | private static final int SUPPLY_PIN_COMPLETE = 100; |
| 2681 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2682 | UnlockSim(int phoneId, IccCard simCard) { |
| 2683 | mPhoneId = phoneId; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2684 | mSimCard = simCard; |
| 2685 | } |
| 2686 | |
| 2687 | @Override |
| 2688 | public void run() { |
| 2689 | Looper.prepare(); |
| 2690 | synchronized (UnlockSim.this) { |
| 2691 | mHandler = new Handler() { |
| 2692 | @Override |
| 2693 | public void handleMessage(Message msg) { |
| 2694 | AsyncResult ar = (AsyncResult) msg.obj; |
| 2695 | switch (msg.what) { |
| 2696 | case SUPPLY_PIN_COMPLETE: |
| 2697 | Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE"); |
| 2698 | synchronized (UnlockSim.this) { |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2699 | mRetryCount = msg.arg1; |
| 2700 | if (ar.exception != null) { |
| 2701 | if (ar.exception instanceof CommandException && |
| 2702 | ((CommandException)(ar.exception)).getCommandError() |
| 2703 | == CommandException.Error.PASSWORD_INCORRECT) { |
| 2704 | mResult = PhoneConstants.PIN_PASSWORD_INCORRECT; |
vivi.li | b5e9ada | 2019-09-12 16:04:24 +0800 | [diff] [blame] | 2705 | } //When UiccCardApp dispose,handle message and return exception |
| 2706 | else if (ar.exception instanceof CommandException && |
| 2707 | ((CommandException) (ar.exception)).getCommandError() |
| 2708 | == CommandException.Error.ABORTED) { |
| 2709 | mResult = PhoneConstants.PIN_OPERATION_ABORTED; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2710 | } else { |
| 2711 | mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 2712 | } |
| 2713 | } else { |
| 2714 | mResult = PhoneConstants.PIN_RESULT_SUCCESS; |
| 2715 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2716 | mDone = true; |
| 2717 | UnlockSim.this.notifyAll(); |
| 2718 | } |
| 2719 | break; |
| 2720 | } |
| 2721 | } |
| 2722 | }; |
| 2723 | UnlockSim.this.notifyAll(); |
| 2724 | } |
| 2725 | Looper.loop(); |
| 2726 | } |
| 2727 | |
| 2728 | /* |
| 2729 | * Use PIN or PUK to unlock SIM card |
| 2730 | * |
| 2731 | * If PUK is null, unlock SIM card with PIN |
| 2732 | * |
| 2733 | * If PUK is not null, unlock SIM card with PUK and set PIN code |
| 2734 | */ |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2735 | synchronized int[] unlockSim(String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2736 | |
| 2737 | while (mHandler == null) { |
| 2738 | try { |
| 2739 | wait(); |
| 2740 | } catch (InterruptedException e) { |
| 2741 | Thread.currentThread().interrupt(); |
| 2742 | } |
| 2743 | } |
| 2744 | Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE); |
| 2745 | |
| 2746 | if (puk == null) { |
| 2747 | mSimCard.supplyPin(pin, callback); |
| 2748 | } else { |
| 2749 | mSimCard.supplyPuk(puk, pin, callback); |
| 2750 | } |
| 2751 | |
| 2752 | while (!mDone) { |
| 2753 | try { |
| 2754 | Log.d(LOG_TAG, "wait for done"); |
| 2755 | wait(); |
| 2756 | } catch (InterruptedException e) { |
| 2757 | // Restore the interrupted status |
| 2758 | Thread.currentThread().interrupt(); |
| 2759 | } |
| 2760 | } |
| 2761 | Log.d(LOG_TAG, "done"); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2762 | int[] resultArray = new int[2]; |
| 2763 | resultArray[0] = mResult; |
| 2764 | resultArray[1] = mRetryCount; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2765 | |
| 2766 | if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) { |
Jon Spivack | 9c3bc76 | 2021-10-06 20:53:09 +0000 | [diff] [blame] | 2767 | UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2768 | } |
| 2769 | |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2770 | return resultArray; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2771 | } |
| 2772 | } |
| 2773 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2774 | /** |
| 2775 | * This method has been removed due to privacy and stability concerns. |
| 2776 | */ |
| 2777 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2778 | public void updateServiceLocation() { |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2779 | Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()"); |
| 2780 | return; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2781 | } |
| 2782 | |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2783 | @Override |
| 2784 | public void updateServiceLocationWithPackageName(String callingPackage) { |
| 2785 | mApp.getSystemService(AppOpsManager.class) |
| 2786 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 2787 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 2788 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2789 | if (targetSdk > android.os.Build.VERSION_CODES.R) { |
| 2790 | // Callers targeting S have no business invoking this method. |
| 2791 | return; |
| 2792 | } |
| 2793 | |
| 2794 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2795 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2796 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2797 | .setCallingPackage(callingPackage) |
| 2798 | .setCallingFeatureId(null) |
| 2799 | .setCallingPid(Binder.getCallingPid()) |
| 2800 | .setCallingUid(Binder.getCallingUid()) |
| 2801 | .setMethod("updateServiceLocation") |
| 2802 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
| 2803 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2804 | .build()); |
| 2805 | // Apps that lack location permission have no business calling this method; |
| 2806 | // however, because no permission was declared in the public API, denials must |
| 2807 | // all be "soft". |
| 2808 | switch (locationResult) { |
| 2809 | case DENIED_HARD: /* fall through */ |
| 2810 | case DENIED_SOFT: |
| 2811 | return; |
| 2812 | } |
| 2813 | |
| 2814 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2815 | final long identity = Binder.clearCallingIdentity(); |
| 2816 | try { |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2817 | final Phone phone = getPhone(getDefaultSubscription()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2818 | if (phone != null) { |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2819 | phone.updateServiceLocation(workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2820 | } |
| 2821 | } finally { |
| 2822 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2823 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2824 | } |
| 2825 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2826 | @Deprecated |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2827 | @Override |
| 2828 | public boolean isRadioOn(String callingPackage) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2829 | return isRadioOnWithFeature(callingPackage, null); |
| 2830 | } |
| 2831 | |
| 2832 | |
| 2833 | @Override |
| 2834 | public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) { |
| 2835 | return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage, |
| 2836 | callingFeatureId); |
| 2837 | } |
| 2838 | |
| 2839 | @Deprecated |
| 2840 | @Override |
| 2841 | public boolean isRadioOnForSubscriber(int subId, String callingPackage) { |
| 2842 | return isRadioOnForSubscriberWithFeature(subId, callingPackage, null); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2843 | } |
| 2844 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2845 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2846 | public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage, |
| 2847 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2848 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2849 | mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2850 | return false; |
| 2851 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2852 | |
| 2853 | final long identity = Binder.clearCallingIdentity(); |
| 2854 | try { |
| 2855 | return isRadioOnForSubscriber(subId); |
| 2856 | } finally { |
| 2857 | Binder.restoreCallingIdentity(identity); |
| 2858 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2859 | } |
| 2860 | |
| 2861 | private boolean isRadioOnForSubscriber(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2862 | final long identity = Binder.clearCallingIdentity(); |
| 2863 | try { |
| 2864 | final Phone phone = getPhone(subId); |
| 2865 | if (phone != null) { |
| 2866 | return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF; |
| 2867 | } else { |
| 2868 | return false; |
| 2869 | } |
| 2870 | } finally { |
| 2871 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2872 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2873 | } |
| 2874 | |
| 2875 | public void toggleRadioOnOff() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2876 | toggleRadioOnOffForSubscriber(getDefaultSubscription()); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2877 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2878 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2879 | public void toggleRadioOnOffForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2880 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2881 | |
| 2882 | final long identity = Binder.clearCallingIdentity(); |
| 2883 | try { |
| 2884 | final Phone phone = getPhone(subId); |
| 2885 | if (phone != null) { |
| 2886 | phone.setRadioPower(!isRadioOnForSubscriber(subId)); |
| 2887 | } |
| 2888 | } finally { |
| 2889 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2890 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2891 | } |
| 2892 | |
| 2893 | public boolean setRadio(boolean turnOn) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2894 | return setRadioForSubscriber(getDefaultSubscription(), turnOn); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2895 | } |
| 2896 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2897 | public boolean setRadioForSubscriber(int subId, boolean turnOn) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -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 phone = getPhone(subId); |
| 2903 | if (phone == null) { |
| 2904 | return false; |
| 2905 | } |
| 2906 | if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) { |
| 2907 | toggleRadioOnOffForSubscriber(subId); |
| 2908 | } |
| 2909 | return true; |
| 2910 | } finally { |
| 2911 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2912 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2913 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2914 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2915 | public boolean needMobileRadioShutdown() { |
Shuo Qian | fa7b6b3 | 2019-12-10 10:40:38 -0800 | [diff] [blame] | 2916 | enforceReadPrivilegedPermission("needMobileRadioShutdown"); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2917 | /* |
| 2918 | * If any of the Radios are available, it will need to be |
| 2919 | * shutdown. So return true if any Radio is available. |
| 2920 | */ |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2921 | final long identity = Binder.clearCallingIdentity(); |
| 2922 | try { |
| 2923 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 2924 | Phone phone = PhoneFactory.getPhone(i); |
| 2925 | if (phone != null && phone.isRadioAvailable()) return true; |
| 2926 | } |
| 2927 | logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown."); |
| 2928 | return false; |
| 2929 | } finally { |
| 2930 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2931 | } |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2932 | } |
| 2933 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2934 | @Override |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2935 | public void shutdownMobileRadios() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2936 | enforceModifyPermission(); |
| 2937 | |
| 2938 | final long identity = Binder.clearCallingIdentity(); |
| 2939 | try { |
| 2940 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 2941 | logv("Shutting down Phone " + i); |
| 2942 | shutdownRadioUsingPhoneId(i); |
| 2943 | } |
| 2944 | } finally { |
| 2945 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2946 | } |
| 2947 | } |
| 2948 | |
| 2949 | private void shutdownRadioUsingPhoneId(int phoneId) { |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2950 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 2951 | if (phone != null && phone.isRadioAvailable()) { |
| 2952 | phone.shutdownRadio(); |
| 2953 | } |
| 2954 | } |
| 2955 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2956 | public boolean setRadioPower(boolean turnOn) { |
Jack Yu | b4e1616 | 2017-05-15 12:48:40 -0700 | [diff] [blame] | 2957 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2958 | |
| 2959 | final long identity = Binder.clearCallingIdentity(); |
| 2960 | try { |
| 2961 | final Phone defaultPhone = PhoneFactory.getDefaultPhone(); |
| 2962 | if (defaultPhone != null) { |
| 2963 | defaultPhone.setRadioPower(turnOn); |
| 2964 | return true; |
| 2965 | } else { |
| 2966 | loge("There's no default phone."); |
| 2967 | return false; |
| 2968 | } |
| 2969 | } finally { |
| 2970 | Binder.restoreCallingIdentity(identity); |
Wei Liu | 9ae2a06 | 2016-08-08 11:09:34 -0700 | [diff] [blame] | 2971 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2972 | } |
| 2973 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2974 | public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2975 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2976 | |
| 2977 | final long identity = Binder.clearCallingIdentity(); |
| 2978 | try { |
| 2979 | final Phone phone = getPhone(subId); |
| 2980 | if (phone != null) { |
| 2981 | phone.setRadioPower(turnOn); |
| 2982 | return true; |
| 2983 | } else { |
| 2984 | return false; |
| 2985 | } |
| 2986 | } finally { |
| 2987 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2988 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2989 | } |
| 2990 | |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 2991 | /** |
| 2992 | * Vote on powering off the radio for a reason. The radio will be turned on only when there is |
| 2993 | * no reason to power it off. When any of the voters want to power it off, it will be turned |
| 2994 | * off. In case of emergency, the radio will be turned on even if there are some reasons for |
| 2995 | * powering it off, and these radio off votes will be cleared. |
| 2996 | * Multiple apps can vote for the same reason and the last vote will take effect. Each app is |
| 2997 | * responsible for its vote. A powering-off vote of a reason will be maintained until it is |
| 2998 | * cleared by calling {@link clearRadioPowerOffForReason} for that reason, or an emergency call |
| 2999 | * is made, or the device is rebooted. When an app comes backup from a crash, it needs to make |
| 3000 | * sure if its vote is as expected. An app can use the API {@link getRadioPowerOffReasons} to |
| 3001 | * check its vote. |
| 3002 | * |
| 3003 | * @param subId The subscription ID. |
| 3004 | * @param reason The reason for powering off radio. |
| 3005 | * @return true on success and false on failure. |
| 3006 | */ |
| 3007 | public boolean requestRadioPowerOffForReason(int subId, |
| 3008 | @TelephonyManager.RadioPowerReason int reason) { |
| 3009 | enforceModifyPermission(); |
| 3010 | |
| 3011 | final long identity = Binder.clearCallingIdentity(); |
| 3012 | try { |
| 3013 | final Phone phone = getPhone(subId); |
| 3014 | if (phone != null) { |
| 3015 | phone.setRadioPowerForReason(false, reason); |
| 3016 | return true; |
| 3017 | } else { |
| 3018 | return false; |
| 3019 | } |
| 3020 | } finally { |
| 3021 | Binder.restoreCallingIdentity(identity); |
| 3022 | } |
| 3023 | } |
| 3024 | |
| 3025 | /** |
| 3026 | * Remove the vote on powering off the radio for a reason, as requested by |
| 3027 | * {@link requestRadioPowerOffForReason}. |
| 3028 | * |
| 3029 | * @param subId The subscription ID. |
| 3030 | * @param reason The reason for powering off radio. |
| 3031 | * @return true on success and false on failure. |
| 3032 | */ |
| 3033 | public boolean clearRadioPowerOffForReason(int subId, |
| 3034 | @TelephonyManager.RadioPowerReason int reason) { |
| 3035 | enforceModifyPermission(); |
| 3036 | |
| 3037 | final long identity = Binder.clearCallingIdentity(); |
| 3038 | try { |
| 3039 | final Phone phone = getPhone(subId); |
| 3040 | if (phone != null) { |
| 3041 | phone.setRadioPowerForReason(true, reason); |
| 3042 | return true; |
| 3043 | } else { |
| 3044 | return false; |
| 3045 | } |
| 3046 | } finally { |
| 3047 | Binder.restoreCallingIdentity(identity); |
| 3048 | } |
| 3049 | } |
| 3050 | |
| 3051 | /** |
| 3052 | * Get reasons for powering off radio, as requested by {@link requestRadioPowerOffForReason}. |
| 3053 | * |
| 3054 | * @param subId The subscription ID. |
| 3055 | * @param callingPackage The package making the call. |
| 3056 | * @param callingFeatureId The feature in the package. |
| 3057 | * @return List of reasons for powering off radio. |
| 3058 | */ |
| 3059 | public List getRadioPowerOffReasons(int subId, String callingPackage, String callingFeatureId) { |
| 3060 | enforceReadPrivilegedPermission("getRadioPowerOffReasons"); |
| 3061 | |
| 3062 | final long identity = Binder.clearCallingIdentity(); |
| 3063 | List result = new ArrayList(); |
| 3064 | try { |
| 3065 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, |
| 3066 | callingPackage, callingFeatureId, "getRadioPowerOffReasons")) { |
| 3067 | return result; |
| 3068 | } |
| 3069 | |
| 3070 | final Phone phone = getPhone(subId); |
| 3071 | if (phone != null) { |
| 3072 | result.addAll(phone.getRadioPowerOffReasons()); |
| 3073 | } |
| 3074 | } finally { |
| 3075 | Binder.restoreCallingIdentity(identity); |
| 3076 | } |
| 3077 | return result; |
| 3078 | } |
| 3079 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3080 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3081 | @Override |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 3082 | public boolean enableDataConnectivity(String callingPackage) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3083 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3084 | |
| 3085 | final long identity = Binder.clearCallingIdentity(); |
| 3086 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3087 | int subId = SubscriptionManager.getDefaultDataSubscriptionId(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3088 | final Phone phone = getPhone(subId); |
| 3089 | if (phone != null) { |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 3090 | phone.getDataSettingsManager().setDataEnabled( |
| 3091 | TelephonyManager.DATA_ENABLED_REASON_USER, true, callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3092 | return true; |
| 3093 | } else { |
| 3094 | return false; |
| 3095 | } |
| 3096 | } finally { |
| 3097 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3098 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3099 | } |
| 3100 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3101 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3102 | @Override |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 3103 | public boolean disableDataConnectivity(String callingPackage) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3104 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3105 | |
| 3106 | final long identity = Binder.clearCallingIdentity(); |
| 3107 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3108 | int subId = SubscriptionManager.getDefaultDataSubscriptionId(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3109 | final Phone phone = getPhone(subId); |
| 3110 | if (phone != null) { |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 3111 | phone.getDataSettingsManager().setDataEnabled( |
| 3112 | TelephonyManager.DATA_ENABLED_REASON_USER, false, callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3113 | return true; |
| 3114 | } else { |
| 3115 | return false; |
| 3116 | } |
| 3117 | } finally { |
| 3118 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3119 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3120 | } |
| 3121 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3122 | @Override |
Jack Yu | acf8a13 | 2017-05-01 17:00:48 -0700 | [diff] [blame] | 3123 | public boolean isDataConnectivityPossible(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3124 | final long identity = Binder.clearCallingIdentity(); |
| 3125 | try { |
| 3126 | final Phone phone = getPhone(subId); |
| 3127 | if (phone != null) { |
Jack Yu | 59824e1 | 2022-03-23 01:42:44 -0700 | [diff] [blame] | 3128 | return phone.isDataAllowed(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3129 | } else { |
| 3130 | return false; |
| 3131 | } |
| 3132 | } finally { |
| 3133 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3134 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3135 | } |
| 3136 | |
| 3137 | public boolean handlePinMmi(String dialString) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 3138 | return handlePinMmiForSubscriber(getDefaultSubscription(), dialString); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3139 | } |
| 3140 | |
pkanwar | ae03a6b | 2016-11-06 20:37:09 -0800 | [diff] [blame] | 3141 | public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3142 | enforceCallPermission(); |
| 3143 | |
| 3144 | final long identity = Binder.clearCallingIdentity(); |
| 3145 | try { |
| 3146 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3147 | return; |
| 3148 | } |
| 3149 | Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback); |
| 3150 | sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId); |
| 3151 | } finally { |
| 3152 | Binder.restoreCallingIdentity(identity); |
| 3153 | } |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 3154 | }; |
| 3155 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3156 | public boolean handlePinMmiForSubscriber(int subId, String dialString) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3157 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3158 | |
| 3159 | final long identity = Binder.clearCallingIdentity(); |
| 3160 | try { |
| 3161 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3162 | return false; |
| 3163 | } |
| 3164 | return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId); |
| 3165 | } finally { |
| 3166 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3167 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3168 | } |
| 3169 | |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 3170 | /** |
| 3171 | * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage |
| 3172 | * tag on getCallState Binder call. |
| 3173 | */ |
| 3174 | @Deprecated |
| 3175 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3176 | public int getCallState() { |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 3177 | if (CompatChanges.isChangeEnabled( |
| 3178 | TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION, |
| 3179 | Binder.getCallingUid())) { |
| 3180 | // Do not allow this API to be called on API version 31+, it should only be |
| 3181 | // called on old apps using this Binder call directly. |
| 3182 | throw new SecurityException("This method can only be used for applications " |
| 3183 | + "targeting API version 30 or less."); |
| 3184 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3185 | final long identity = Binder.clearCallingIdentity(); |
| 3186 | try { |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 3187 | Phone phone = getPhone(getDefaultSubscription()); |
| 3188 | return phone == null ? TelephonyManager.CALL_STATE_IDLE : |
| 3189 | PhoneConstantConversions.convertCallState(phone.getState()); |
| 3190 | } finally { |
| 3191 | Binder.restoreCallingIdentity(identity); |
| 3192 | } |
| 3193 | } |
| 3194 | |
| 3195 | @Override |
| 3196 | public int getCallStateForSubscription(int subId, String callingPackage, String featureId) { |
| 3197 | if (CompatChanges.isChangeEnabled( |
| 3198 | TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION, |
| 3199 | Binder.getCallingUid())) { |
| 3200 | // Check READ_PHONE_STATE for API version 31+ |
| 3201 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage, |
| 3202 | featureId, "getCallStateForSubscription")) { |
| 3203 | throw new SecurityException("getCallState requires READ_PHONE_STATE for apps " |
| 3204 | + "targeting API level 31+."); |
| 3205 | } |
| 3206 | } |
| 3207 | final long identity = Binder.clearCallingIdentity(); |
| 3208 | try { |
| 3209 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3210 | return phone == null ? TelephonyManager.CALL_STATE_IDLE : |
| 3211 | PhoneConstantConversions.convertCallState(phone.getState()); |
| 3212 | } finally { |
| 3213 | Binder.restoreCallingIdentity(identity); |
| 3214 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3215 | } |
| 3216 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3217 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 3218 | public int getDataState() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3219 | return getDataStateForSubId(SubscriptionManager.getDefaultDataSubscriptionId()); |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 3220 | } |
| 3221 | |
| 3222 | @Override |
| 3223 | public int getDataStateForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3224 | final long identity = Binder.clearCallingIdentity(); |
| 3225 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 3226 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3227 | if (phone != null) { |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 3228 | return phone.getDataNetworkController().getInternetDataNetworkState(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3229 | } else { |
| 3230 | return PhoneConstantConversions.convertDataState( |
| 3231 | PhoneConstants.DataState.DISCONNECTED); |
| 3232 | } |
| 3233 | } finally { |
| 3234 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3235 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3236 | } |
| 3237 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3238 | @Override |
Jack Yu | 0eda684 | 2022-04-18 00:34:46 -0700 | [diff] [blame] | 3239 | public @DataActivityType int getDataActivity() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3240 | return getDataActivityForSubId(SubscriptionManager.getDefaultDataSubscriptionId()); |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 3241 | } |
| 3242 | |
| 3243 | @Override |
Jack Yu | 0eda684 | 2022-04-18 00:34:46 -0700 | [diff] [blame] | 3244 | public @DataActivityType int getDataActivityForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3245 | final long identity = Binder.clearCallingIdentity(); |
| 3246 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 3247 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3248 | if (phone != null) { |
Jack Yu | 0eda684 | 2022-04-18 00:34:46 -0700 | [diff] [blame] | 3249 | return phone.getDataActivityState(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3250 | } else { |
| 3251 | return TelephonyManager.DATA_ACTIVITY_NONE; |
| 3252 | } |
| 3253 | } finally { |
| 3254 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3255 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3256 | } |
| 3257 | |
| 3258 | @Override |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 3259 | public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3260 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 3261 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3262 | |
| 3263 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 3264 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 3265 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 3266 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3267 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3268 | .setCallingPid(Binder.getCallingPid()) |
| 3269 | .setCallingUid(Binder.getCallingUid()) |
| 3270 | .setMethod("getCellLocation") |
Hall Liu | 773ba02 | 2020-01-24 18:07:12 -0800 | [diff] [blame] | 3271 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3272 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 3273 | .build()); |
| 3274 | switch (locationResult) { |
| 3275 | case DENIED_HARD: |
| 3276 | throw new SecurityException("Not allowed to access cell location"); |
| 3277 | case DENIED_SOFT: |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 3278 | return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
| 3279 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3280 | } |
| 3281 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 3282 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3283 | final long identity = Binder.clearCallingIdentity(); |
| 3284 | try { |
| 3285 | if (DBG_LOC) log("getCellLocation: is active user"); |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3286 | int subId = SubscriptionManager.getDefaultDataSubscriptionId(); |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 3287 | return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3288 | } finally { |
| 3289 | Binder.restoreCallingIdentity(identity); |
| 3290 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 3291 | } |
| 3292 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3293 | @Override |
Jack Yu | eb1e7fe | 2020-02-22 19:38:58 -0800 | [diff] [blame] | 3294 | public String getNetworkCountryIsoForPhone(int phoneId) { |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3295 | // Reporting the correct network country is ambiguous when IWLAN could conflict with |
| 3296 | // registered cell info, so return a NULL country instead. |
| 3297 | final long identity = Binder.clearCallingIdentity(); |
| 3298 | try { |
Malcolm Chen | 3732c2b | 2018-07-18 20:15:24 -0700 | [diff] [blame] | 3299 | if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) { |
| 3300 | // Get default phone in this case. |
| 3301 | phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX; |
| 3302 | } |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3303 | final int subId = SubscriptionManager.getSubscriptionId(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3304 | Phone phone = PhoneFactory.getPhone(phoneId); |
Nathan Harold | 532f51c | 2020-04-21 19:31:10 -0700 | [diff] [blame] | 3305 | if (phone == null) return ""; |
| 3306 | ServiceStateTracker sst = phone.getServiceStateTracker(); |
| 3307 | if (sst == null) return ""; |
| 3308 | LocaleTracker lt = sst.getLocaleTracker(); |
| 3309 | if (lt == null) return ""; |
Shuo Qian | 9418a92 | 2021-03-09 11:21:16 -0800 | [diff] [blame] | 3310 | return lt.getCurrentCountry(); |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3311 | } finally { |
| 3312 | Binder.restoreCallingIdentity(identity); |
| 3313 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3314 | } |
| 3315 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 3316 | /** |
| 3317 | * This method was removed due to potential issues caused by performing partial |
| 3318 | * updates of service state, and lack of a credible use case. |
| 3319 | * |
| 3320 | * This has the ability to break the telephony implementation by disabling notification of |
| 3321 | * changes in device connectivity. DO NOT USE THIS! |
| 3322 | */ |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3323 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3324 | public void enableLocationUpdates() { |
| 3325 | mApp.enforceCallingOrSelfPermission( |
| 3326 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3327 | } |
| 3328 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 3329 | /** |
| 3330 | * This method was removed due to potential issues caused by performing partial |
| 3331 | * updates of service state, and lack of a credible use case. |
| 3332 | * |
| 3333 | * This has the ability to break the telephony implementation by disabling notification of |
| 3334 | * changes in device connectivity. DO NOT USE THIS! |
| 3335 | */ |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3336 | @Override |
| 3337 | public void disableLocationUpdates() { |
| 3338 | mApp.enforceCallingOrSelfPermission( |
| 3339 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3340 | } |
| 3341 | |
| 3342 | @Override |
| 3343 | @SuppressWarnings("unchecked") |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3344 | public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage, |
| 3345 | String callingFeatureId) { |
Nathan Harold | b55f63b | 2021-07-27 11:27:38 -0700 | [diff] [blame] | 3346 | try { |
| 3347 | mApp.getSystemService(AppOpsManager.class) |
| 3348 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 3349 | } catch (SecurityException e) { |
| 3350 | EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid()); |
| 3351 | throw e; |
| 3352 | } |
| 3353 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3354 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | dbea45a | 2018-08-30 14:35:07 -0700 | [diff] [blame] | 3355 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 3356 | throw new SecurityException( |
| 3357 | "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels."); |
| 3358 | } |
Nathan Harold | b4d5561 | 2018-07-20 13:13:08 -0700 | [diff] [blame] | 3359 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 3360 | if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(), |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3361 | callingPackage) != AppOpsManager.MODE_ALLOWED) { |
| 3362 | return null; |
| 3363 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 3364 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 3365 | if (DBG_LOC) log("getNeighboringCellInfo: is active user"); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3366 | |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3367 | List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId); |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 3368 | if (info == null) return null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3369 | |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 3370 | List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>(); |
| 3371 | for (CellInfo ci : info) { |
| 3372 | if (ci instanceof CellInfoGsm) { |
| 3373 | neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci)); |
| 3374 | } else if (ci instanceof CellInfoWcdma) { |
| 3375 | neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci)); |
| 3376 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3377 | } |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 3378 | return (neighbors.size()) > 0 ? neighbors : null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3379 | } |
| 3380 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3381 | private List<CellInfo> getCachedCellInfo() { |
| 3382 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 3383 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3384 | List<CellInfo> info = phone.getAllCellInfo(); |
| 3385 | if (info != null) cellInfos.addAll(info); |
| 3386 | } |
| 3387 | return cellInfos; |
| 3388 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3389 | |
| 3390 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3391 | public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3392 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 3393 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3394 | |
| 3395 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 3396 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 3397 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 3398 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3399 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3400 | .setCallingPid(Binder.getCallingPid()) |
| 3401 | .setCallingUid(Binder.getCallingUid()) |
| 3402 | .setMethod("getAllCellInfo") |
Nathan Harold | 5ae50b5 | 2019-02-20 15:46:36 -0800 | [diff] [blame] | 3403 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3404 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 3405 | .build()); |
| 3406 | switch (locationResult) { |
| 3407 | case DENIED_HARD: |
| 3408 | throw new SecurityException("Not allowed to access cell info"); |
| 3409 | case DENIED_SOFT: |
| 3410 | return new ArrayList<>(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3411 | } |
| 3412 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3413 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3414 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 3415 | return getCachedCellInfo(); |
| 3416 | } |
| 3417 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 3418 | if (DBG_LOC) log("getAllCellInfo: is active user"); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 3419 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3420 | final long identity = Binder.clearCallingIdentity(); |
| 3421 | try { |
| 3422 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 3423 | for (Phone phone : PhoneFactory.getPhones()) { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 3424 | final List<CellInfo> info = (List<CellInfo>) sendRequest( |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 3425 | CMD_GET_ALL_CELL_INFO, null, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3426 | if (info != null) cellInfos.addAll(info); |
| 3427 | } |
| 3428 | return cellInfos; |
| 3429 | } finally { |
| 3430 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3431 | } |
| 3432 | } |
| 3433 | |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 3434 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3435 | public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage, |
| 3436 | String callingFeatureId) { |
| 3437 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, |
| 3438 | getWorkSource(Binder.getCallingUid())); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3439 | } |
| 3440 | |
| 3441 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3442 | public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb, |
| 3443 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3444 | enforceModifyPermission(); |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3445 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3446 | } |
| 3447 | |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3448 | private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb, |
| 3449 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3450 | mApp.getSystemService(AppOpsManager.class) |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3451 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3452 | |
| 3453 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 3454 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 3455 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 3456 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3457 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3458 | .setCallingPid(Binder.getCallingPid()) |
| 3459 | .setCallingUid(Binder.getCallingUid()) |
| 3460 | .setMethod("requestCellInfoUpdate") |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 3461 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
| 3462 | .setMinSdkVersionForFine(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3463 | .build()); |
| 3464 | switch (locationResult) { |
| 3465 | case DENIED_HARD: |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3466 | if (TelephonyPermissions |
| 3467 | .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) { |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 3468 | // Safetynet logging for b/154934934 |
| 3469 | EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid()); |
| 3470 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3471 | throw new SecurityException("Not allowed to access cell info"); |
| 3472 | case DENIED_SOFT: |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3473 | if (TelephonyPermissions |
| 3474 | .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) { |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 3475 | // Safetynet logging for b/154934934 |
| 3476 | EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid()); |
| 3477 | } |
Nathan Harold | 5320c42 | 2019-05-09 10:26:08 -0700 | [diff] [blame] | 3478 | try { |
| 3479 | cb.onCellInfo(new ArrayList<CellInfo>()); |
| 3480 | } catch (RemoteException re) { |
| 3481 | // Drop without consequences |
| 3482 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3483 | return; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3484 | } |
| 3485 | |
Nathan Harold | a939a96 | 2019-05-09 10:13:47 -0700 | [diff] [blame] | 3486 | |
| 3487 | final Phone phone = getPhoneFromSubId(subId); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3488 | if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
| 3489 | |
| 3490 | sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource); |
| 3491 | } |
| 3492 | |
| 3493 | @Override |
Aishwarya Mallampati | 0603fb1 | 2022-08-24 21:16:56 +0000 | [diff] [blame] | 3494 | public void setCellInfoListRate(int rateInMillis, int subId) { |
Jack Yu | a8d8cb8 | 2017-01-16 10:15:34 -0800 | [diff] [blame] | 3495 | enforceModifyPermission(); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 3496 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3497 | |
| 3498 | final long identity = Binder.clearCallingIdentity(); |
| 3499 | try { |
Aishwarya Mallampati | 0603fb1 | 2022-08-24 21:16:56 +0000 | [diff] [blame] | 3500 | Phone phone = getPhone(subId); |
| 3501 | if (phone == null) { |
| 3502 | getDefaultPhone().setCellInfoListRate(rateInMillis, workSource); |
| 3503 | } else { |
| 3504 | phone.setCellInfoListRate(rateInMillis, workSource); |
| 3505 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3506 | } finally { |
| 3507 | Binder.restoreCallingIdentity(identity); |
| 3508 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3509 | } |
| 3510 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3511 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3512 | public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3513 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3514 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3515 | return null; |
| 3516 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3517 | int subId = phone.getSubId(); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3518 | enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot"); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 3519 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3520 | callingPackage, callingFeatureId, "getImeiForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3521 | return null; |
| 3522 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3523 | |
| 3524 | final long identity = Binder.clearCallingIdentity(); |
| 3525 | try { |
| 3526 | return phone.getImei(); |
| 3527 | } finally { |
| 3528 | Binder.restoreCallingIdentity(identity); |
| 3529 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3530 | } |
| 3531 | |
| 3532 | @Override |
arunvoddu | d5c6ce0 | 2022-12-11 06:03:12 +0000 | [diff] [blame] | 3533 | public String getPrimaryImei(String callingPackage, String callingFeatureId) { |
| 3534 | enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getPrimaryImei"); |
| 3535 | if (!checkCallingOrSelfReadDeviceIdentifiersForAnySub(mApp, callingPackage, |
| 3536 | callingFeatureId, "getPrimaryImei")) { |
| 3537 | throw new SecurityException("Caller does not have permission"); |
| 3538 | } |
| 3539 | final long identity = Binder.clearCallingIdentity(); |
| 3540 | try { |
| 3541 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3542 | if (phone.getImeiType() == Phone.IMEI_TYPE_PRIMARY) { |
| 3543 | return phone.getImei(); |
| 3544 | } |
| 3545 | } |
| 3546 | throw new UnsupportedOperationException("Operation not supported"); |
| 3547 | } finally { |
| 3548 | Binder.restoreCallingIdentity(identity); |
| 3549 | } |
| 3550 | } |
| 3551 | |
| 3552 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3553 | public String getTypeAllocationCodeForSlot(int slotIndex) { |
| 3554 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3555 | String tac = null; |
| 3556 | if (phone != null) { |
| 3557 | String imei = phone.getImei(); |
Vala Zadeh | ab00555 | 2021-09-21 15:54:29 -0700 | [diff] [blame] | 3558 | try { |
| 3559 | tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH); |
| 3560 | } catch (IndexOutOfBoundsException e) { |
| 3561 | Log.e(LOG_TAG, "IMEI length shorter than upper index."); |
| 3562 | return null; |
| 3563 | } |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3564 | } |
| 3565 | return tac; |
| 3566 | } |
| 3567 | |
| 3568 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3569 | public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Shuo Qian | 13d8915 | 2021-05-10 23:58:11 -0700 | [diff] [blame] | 3570 | try { |
| 3571 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 3572 | } catch (SecurityException se) { |
| 3573 | EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid()); |
| 3574 | throw new SecurityException("Package " + callingPackage + " does not belong to " |
| 3575 | + Binder.getCallingUid()); |
| 3576 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3577 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3578 | if (phone == null) { |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 3579 | return null; |
| 3580 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3581 | |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3582 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 3583 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3584 | callingPackage, callingFeatureId, "getMeidForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3585 | return null; |
| 3586 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3587 | |
| 3588 | final long identity = Binder.clearCallingIdentity(); |
| 3589 | try { |
| 3590 | return phone.getMeid(); |
| 3591 | } finally { |
| 3592 | Binder.restoreCallingIdentity(identity); |
| 3593 | } |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 3594 | } |
| 3595 | |
| 3596 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3597 | public String getManufacturerCodeForSlot(int slotIndex) { |
| 3598 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3599 | String manufacturerCode = null; |
| 3600 | if (phone != null) { |
| 3601 | String meid = phone.getMeid(); |
Vala Zadeh | ab00555 | 2021-09-21 15:54:29 -0700 | [diff] [blame] | 3602 | try { |
| 3603 | manufacturerCode = |
| 3604 | meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH); |
| 3605 | } catch (IndexOutOfBoundsException e) { |
| 3606 | Log.e(LOG_TAG, "MEID length shorter than upper index."); |
| 3607 | return null; |
| 3608 | } |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3609 | } |
| 3610 | return manufacturerCode; |
| 3611 | } |
| 3612 | |
| 3613 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3614 | public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage, |
| 3615 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3616 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3617 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3618 | return null; |
| 3619 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3620 | int subId = phone.getSubId(); |
| 3621 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3622 | mApp, subId, callingPackage, callingFeatureId, |
| 3623 | "getDeviceSoftwareVersionForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3624 | return null; |
| 3625 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3626 | |
| 3627 | final long identity = Binder.clearCallingIdentity(); |
| 3628 | try { |
| 3629 | return phone.getDeviceSvn(); |
| 3630 | } finally { |
| 3631 | Binder.restoreCallingIdentity(identity); |
| 3632 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3633 | } |
| 3634 | |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3635 | @Override |
| 3636 | public int getSubscriptionCarrierId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3637 | final long identity = Binder.clearCallingIdentity(); |
| 3638 | try { |
| 3639 | final Phone phone = getPhone(subId); |
| 3640 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId(); |
| 3641 | } finally { |
| 3642 | Binder.restoreCallingIdentity(identity); |
| 3643 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3644 | } |
| 3645 | |
| 3646 | @Override |
| 3647 | public String getSubscriptionCarrierName(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3648 | final long identity = Binder.clearCallingIdentity(); |
| 3649 | try { |
| 3650 | final Phone phone = getPhone(subId); |
| 3651 | return phone == null ? null : phone.getCarrierName(); |
| 3652 | } finally { |
| 3653 | Binder.restoreCallingIdentity(identity); |
| 3654 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3655 | } |
| 3656 | |
calvinpan | ffe225e | 2018-11-01 19:43:06 +0800 | [diff] [blame] | 3657 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3658 | public int getSubscriptionSpecificCarrierId(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3659 | final long identity = Binder.clearCallingIdentity(); |
| 3660 | try { |
| 3661 | final Phone phone = getPhone(subId); |
| 3662 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3663 | : phone.getSpecificCarrierId(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3664 | } finally { |
| 3665 | Binder.restoreCallingIdentity(identity); |
| 3666 | } |
| 3667 | } |
| 3668 | |
| 3669 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3670 | public String getSubscriptionSpecificCarrierName(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3671 | final long identity = Binder.clearCallingIdentity(); |
| 3672 | try { |
| 3673 | final Phone phone = getPhone(subId); |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3674 | return phone == null ? null : phone.getSpecificCarrierName(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3675 | } finally { |
| 3676 | Binder.restoreCallingIdentity(identity); |
| 3677 | } |
| 3678 | } |
| 3679 | |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 3680 | @Override |
chen xu | 864e11c | 2018-12-06 22:10:03 -0800 | [diff] [blame] | 3681 | public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) { |
| 3682 | if (!isSubscriptionMccMnc) { |
| 3683 | enforceReadPrivilegedPermission("getCarrierIdFromMccMnc"); |
| 3684 | } |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 3685 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3686 | if (phone == null) { |
| 3687 | return TelephonyManager.UNKNOWN_CARRIER_ID; |
| 3688 | } |
| 3689 | final long identity = Binder.clearCallingIdentity(); |
| 3690 | try { |
| 3691 | return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc); |
| 3692 | } finally { |
| 3693 | Binder.restoreCallingIdentity(identity); |
| 3694 | } |
| 3695 | } |
| 3696 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3697 | // |
| 3698 | // Internal helper methods. |
| 3699 | // |
| 3700 | |
Sanket Padawe | ee13a9b | 2016-03-08 17:30:28 -0800 | [diff] [blame] | 3701 | /** |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3702 | * Make sure the caller is the calling package itself |
| 3703 | * |
| 3704 | * @throws SecurityException if the caller is not the calling package |
| 3705 | */ |
| 3706 | private void enforceCallingPackage(String callingPackage, int callingUid, String message) { |
| 3707 | int packageUid = -1; |
Grace Jia | dbefca0 | 2021-04-26 15:13:31 -0700 | [diff] [blame] | 3708 | PackageManager pm = mApp.getBaseContext().createContextAsUser( |
| 3709 | UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager(); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3710 | try { |
Grace Jia | dbefca0 | 2021-04-26 15:13:31 -0700 | [diff] [blame] | 3711 | packageUid = pm.getPackageUid(callingPackage, 0); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3712 | } catch (PackageManager.NameNotFoundException e) { |
| 3713 | // packageUid is -1 |
| 3714 | } |
| 3715 | if (packageUid != callingUid) { |
| 3716 | throw new SecurityException(message + ": Package " + callingPackage |
| 3717 | + " does not belong to " + callingUid); |
| 3718 | } |
| 3719 | } |
| 3720 | |
| 3721 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3722 | * Make sure the caller has the MODIFY_PHONE_STATE permission. |
| 3723 | * |
| 3724 | * @throws SecurityException if the caller does not have the required permission |
| 3725 | */ |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 3726 | @VisibleForTesting |
| 3727 | public void enforceModifyPermission() { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3728 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null); |
| 3729 | } |
| 3730 | |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 3731 | /** |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 3732 | * Make sure the caller has the READ_PHONE_STATE permission. |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 3733 | * |
| 3734 | * @throws SecurityException if the caller does not have the required permission |
| 3735 | */ |
| 3736 | @VisibleForTesting |
| 3737 | public void enforceReadPermission() { |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 3738 | enforceReadPermission(null); |
| 3739 | } |
| 3740 | |
| 3741 | /** |
| 3742 | * Make sure the caller has the READ_PHONE_STATE permissions. |
| 3743 | * |
| 3744 | * @throws SecurityException if the caller does not have the READ_PHONE_STATE permission. |
| 3745 | */ |
| 3746 | @VisibleForTesting |
| 3747 | public void enforceReadPermission(String msg) { |
| 3748 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, msg); |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 3749 | } |
| 3750 | |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 3751 | private void enforceActiveEmergencySessionPermission() { |
| 3752 | mApp.enforceCallingOrSelfPermission( |
| 3753 | android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null); |
| 3754 | } |
| 3755 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3756 | /** |
| 3757 | * Make sure the caller has the CALL_PHONE permission. |
| 3758 | * |
| 3759 | * @throws SecurityException if the caller does not have the required permission |
| 3760 | */ |
| 3761 | private void enforceCallPermission() { |
| 3762 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null); |
| 3763 | } |
| 3764 | |
paulhu | 5a77360 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 3765 | private void enforceSettingsPermission() { |
| 3766 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 3767 | } |
| 3768 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 3769 | private void enforceRebootPermission() { |
| 3770 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null); |
| 3771 | } |
| 3772 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3773 | private String createTelUrl(String number) { |
| 3774 | if (TextUtils.isEmpty(number)) { |
| 3775 | return null; |
| 3776 | } |
| 3777 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3778 | return "tel:" + number; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3779 | } |
| 3780 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3781 | private static void log(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3782 | Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 3783 | } |
| 3784 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3785 | private static void logv(String msg) { |
| 3786 | Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 3787 | } |
| 3788 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3789 | private static void loge(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3790 | Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 3791 | } |
| 3792 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3793 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3794 | public int getActivePhoneType() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3795 | return getActivePhoneTypeForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3796 | } |
| 3797 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3798 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3799 | public int getActivePhoneTypeForSlot(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3800 | final long identity = Binder.clearCallingIdentity(); |
| 3801 | try { |
| 3802 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3803 | if (phone == null) { |
| 3804 | return PhoneConstants.PHONE_TYPE_NONE; |
| 3805 | } else { |
| 3806 | return phone.getPhoneType(); |
| 3807 | } |
| 3808 | } finally { |
| 3809 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3810 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3811 | } |
| 3812 | |
| 3813 | /** |
| 3814 | * Returns the CDMA ERI icon index to display |
| 3815 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3816 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3817 | public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) { |
| 3818 | return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage, |
| 3819 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3820 | } |
| 3821 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3822 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3823 | public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage, |
| 3824 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3825 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3826 | mApp, subId, callingPackage, callingFeatureId, |
| 3827 | "getCdmaEriIconIndexForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3828 | return -1; |
| 3829 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3830 | |
| 3831 | final long identity = Binder.clearCallingIdentity(); |
| 3832 | try { |
| 3833 | final Phone phone = getPhone(subId); |
| 3834 | if (phone != null) { |
| 3835 | return phone.getCdmaEriIconIndex(); |
| 3836 | } else { |
| 3837 | return -1; |
| 3838 | } |
| 3839 | } finally { |
| 3840 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3841 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3842 | } |
| 3843 | |
| 3844 | /** |
| 3845 | * Returns the CDMA ERI icon mode, |
| 3846 | * 0 - ON |
| 3847 | * 1 - FLASHING |
| 3848 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3849 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3850 | public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) { |
| 3851 | return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 3852 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3853 | } |
| 3854 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3855 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3856 | public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage, |
| 3857 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3858 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3859 | mApp, subId, callingPackage, callingFeatureId, |
| 3860 | "getCdmaEriIconModeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3861 | return -1; |
| 3862 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3863 | |
| 3864 | final long identity = Binder.clearCallingIdentity(); |
| 3865 | try { |
| 3866 | final Phone phone = getPhone(subId); |
| 3867 | if (phone != null) { |
| 3868 | return phone.getCdmaEriIconMode(); |
| 3869 | } else { |
| 3870 | return -1; |
| 3871 | } |
| 3872 | } finally { |
| 3873 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3874 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3875 | } |
| 3876 | |
| 3877 | /** |
| 3878 | * Returns the CDMA ERI text, |
| 3879 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3880 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3881 | public String getCdmaEriText(String callingPackage, String callingFeatureId) { |
| 3882 | return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage, |
| 3883 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3884 | } |
| 3885 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3886 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3887 | public String getCdmaEriTextForSubscriber(int subId, String callingPackage, |
| 3888 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3889 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3890 | mApp, subId, callingPackage, callingFeatureId, |
| 3891 | "getCdmaEriIconTextForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3892 | return null; |
| 3893 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3894 | |
| 3895 | final long identity = Binder.clearCallingIdentity(); |
| 3896 | try { |
| 3897 | final Phone phone = getPhone(subId); |
| 3898 | if (phone != null) { |
| 3899 | return phone.getCdmaEriText(); |
| 3900 | } else { |
| 3901 | return null; |
| 3902 | } |
| 3903 | } finally { |
| 3904 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3905 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3906 | } |
| 3907 | |
| 3908 | /** |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3909 | * Returns the CDMA MDN. |
| 3910 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3911 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3912 | public String getCdmaMdn(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3913 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3914 | mApp, subId, "getCdmaMdn"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3915 | |
| 3916 | final long identity = Binder.clearCallingIdentity(); |
| 3917 | try { |
| 3918 | final Phone phone = getPhone(subId); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3919 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3920 | return phone.getLine1Number(); |
| 3921 | } else { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3922 | loge("getCdmaMdn: no phone found. Invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3923 | return null; |
| 3924 | } |
| 3925 | } finally { |
| 3926 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3927 | } |
| 3928 | } |
| 3929 | |
| 3930 | /** |
| 3931 | * Returns the CDMA MIN. |
| 3932 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3933 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3934 | public String getCdmaMin(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3935 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3936 | mApp, subId, "getCdmaMin"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3937 | |
| 3938 | final long identity = Binder.clearCallingIdentity(); |
| 3939 | try { |
| 3940 | final Phone phone = getPhone(subId); |
| 3941 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
| 3942 | return phone.getCdmaMin(); |
| 3943 | } else { |
| 3944 | return null; |
| 3945 | } |
| 3946 | } finally { |
| 3947 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3948 | } |
| 3949 | } |
| 3950 | |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3951 | @Override |
| 3952 | public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis, |
| 3953 | INumberVerificationCallback callback, String callingPackage) { |
| 3954 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 3955 | != PERMISSION_GRANTED) { |
| 3956 | throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission"); |
| 3957 | } |
| 3958 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 3959 | |
| 3960 | String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp); |
| 3961 | if (!TextUtils.equals(callingPackage, authorizedPackage)) { |
Hall Liu | b9d8feb | 2021-01-13 10:28:04 -0800 | [diff] [blame] | 3962 | throw new SecurityException("Calling package must be configured in the device config: " |
| 3963 | + "calling package: " + callingPackage |
| 3964 | + ", configured package: " + authorizedPackage); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3965 | } |
| 3966 | |
| 3967 | if (range == null) { |
| 3968 | throw new NullPointerException("Range must be non-null"); |
| 3969 | } |
| 3970 | |
| 3971 | timeoutMillis = Math.min(timeoutMillis, |
Hall Liu | bd069e3 | 2019-02-28 18:56:30 -0800 | [diff] [blame] | 3972 | TelephonyManager.getMaxNumberVerificationTimeoutMillis()); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3973 | |
| 3974 | NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis); |
| 3975 | } |
| 3976 | |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3977 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3978 | * Returns true if CDMA provisioning needs to run. |
| 3979 | */ |
| 3980 | public boolean needsOtaServiceProvisioning() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3981 | final long identity = Binder.clearCallingIdentity(); |
| 3982 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3983 | return getDefaultPhone().needsOtaServiceProvisioning(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3984 | } finally { |
| 3985 | Binder.restoreCallingIdentity(identity); |
| 3986 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3987 | } |
| 3988 | |
| 3989 | /** |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3990 | * Sets the voice mail number of a given subId. |
| 3991 | */ |
| 3992 | @Override |
| 3993 | public boolean setVoiceMailNumber(int subId, String alphaTag, String number) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 3994 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 3995 | mApp, subId, "setVoiceMailNumber"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3996 | |
| 3997 | final long identity = Binder.clearCallingIdentity(); |
| 3998 | try { |
| 3999 | Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER, |
| 4000 | new Pair<String, String>(alphaTag, number), new Integer(subId)); |
| 4001 | return success; |
| 4002 | } finally { |
| 4003 | Binder.restoreCallingIdentity(identity); |
| 4004 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 4005 | } |
| 4006 | |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 4007 | @Override |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 4008 | public Bundle getVisualVoicemailSettings(String callingPackage, int subId) { |
| 4009 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 4010 | TelecomManager tm = mApp.getSystemService(TelecomManager.class); |
| 4011 | String systemDialer = tm.getSystemDialerPackage(); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 4012 | if (!TextUtils.equals(callingPackage, systemDialer)) { |
| 4013 | throw new SecurityException("caller must be system dialer"); |
| 4014 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4015 | |
| 4016 | final long identity = Binder.clearCallingIdentity(); |
| 4017 | try { |
| 4018 | PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId); |
| 4019 | if (phoneAccountHandle == null) { |
| 4020 | return null; |
| 4021 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4022 | return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4023 | } finally { |
| 4024 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 4025 | } |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 4026 | } |
| 4027 | |
| 4028 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4029 | public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId, |
| 4030 | int subId) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 4031 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4032 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4033 | mApp, subId, callingPackage, callingFeatureId, |
| 4034 | "getVisualVoicemailPackageName")) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 4035 | return null; |
| 4036 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4037 | |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 4038 | final long identity = Binder.clearCallingIdentity(); |
| 4039 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4040 | return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName(); |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 4041 | } finally { |
| 4042 | Binder.restoreCallingIdentity(identity); |
| 4043 | } |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 4044 | } |
| 4045 | |
| 4046 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 4047 | public void enableVisualVoicemailSmsFilter(String callingPackage, int subId, |
| 4048 | VisualVoicemailSmsFilterSettings settings) { |
| 4049 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4050 | |
| 4051 | final long identity = Binder.clearCallingIdentity(); |
| 4052 | try { |
| 4053 | VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4054 | mApp, callingPackage, subId, settings); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4055 | } finally { |
| 4056 | Binder.restoreCallingIdentity(identity); |
| 4057 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 4058 | } |
| 4059 | |
| 4060 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 4061 | public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) { |
| 4062 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4063 | |
| 4064 | final long identity = Binder.clearCallingIdentity(); |
| 4065 | try { |
| 4066 | VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4067 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4068 | } finally { |
| 4069 | Binder.restoreCallingIdentity(identity); |
| 4070 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 4071 | } |
| 4072 | |
| 4073 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 4074 | public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings( |
| 4075 | String callingPackage, int subId) { |
| 4076 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4077 | |
| 4078 | final long identity = Binder.clearCallingIdentity(); |
| 4079 | try { |
| 4080 | return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4081 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4082 | } finally { |
| 4083 | Binder.restoreCallingIdentity(identity); |
| 4084 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 4085 | } |
| 4086 | |
| 4087 | @Override |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 4088 | public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4089 | enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4090 | |
| 4091 | final long identity = Binder.clearCallingIdentity(); |
| 4092 | try { |
| 4093 | return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4094 | mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4095 | } finally { |
| 4096 | Binder.restoreCallingIdentity(identity); |
| 4097 | } |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 4098 | } |
| 4099 | |
| 4100 | @Override |
Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 4101 | public void sendVisualVoicemailSmsForSubscriber(String callingPackage, |
| 4102 | String callingAttributionTag, int subId, String number, int port, String text, |
| 4103 | PendingIntent sentIntent) { |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 4104 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 4105 | enforceVisualVoicemailPackage(callingPackage, subId); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 4106 | enforceSendSmsPermission(); |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 4107 | SmsController smsController = PhoneFactory.getSmsController(); |
Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 4108 | smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag, |
| 4109 | subId, number, port, text, sentIntent); |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 4110 | } |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 4111 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 4112 | /** |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4113 | * Sets the voice activation state of a given subId. |
| 4114 | */ |
| 4115 | @Override |
| 4116 | public void setVoiceActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4117 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4118 | mApp, subId, "setVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4119 | |
| 4120 | final long identity = Binder.clearCallingIdentity(); |
| 4121 | try { |
| 4122 | final Phone phone = getPhone(subId); |
| 4123 | if (phone != null) { |
| 4124 | phone.setVoiceActivationState(activationState); |
| 4125 | } else { |
| 4126 | loge("setVoiceActivationState fails with invalid subId: " + subId); |
| 4127 | } |
| 4128 | } finally { |
| 4129 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4130 | } |
| 4131 | } |
| 4132 | |
| 4133 | /** |
| 4134 | * Sets the data activation state of a given subId. |
| 4135 | */ |
| 4136 | @Override |
| 4137 | public void setDataActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4138 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4139 | mApp, subId, "setDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4140 | |
| 4141 | final long identity = Binder.clearCallingIdentity(); |
| 4142 | try { |
| 4143 | final Phone phone = getPhone(subId); |
| 4144 | if (phone != null) { |
| 4145 | phone.setDataActivationState(activationState); |
| 4146 | } else { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 4147 | loge("setDataActivationState fails with invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4148 | } |
| 4149 | } finally { |
| 4150 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4151 | } |
| 4152 | } |
| 4153 | |
| 4154 | /** |
| 4155 | * Returns the voice activation state of a given subId. |
| 4156 | */ |
| 4157 | @Override |
| 4158 | public int getVoiceActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4159 | enforceReadPrivilegedPermission("getVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4160 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4161 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4162 | final long identity = Binder.clearCallingIdentity(); |
| 4163 | try { |
| 4164 | if (phone != null) { |
| 4165 | return phone.getVoiceActivationState(); |
| 4166 | } else { |
| 4167 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 4168 | } |
| 4169 | } finally { |
| 4170 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4171 | } |
| 4172 | } |
| 4173 | |
| 4174 | /** |
| 4175 | * Returns the data activation state of a given subId. |
| 4176 | */ |
| 4177 | @Override |
| 4178 | public int getDataActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4179 | enforceReadPrivilegedPermission("getDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4180 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4181 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4182 | final long identity = Binder.clearCallingIdentity(); |
| 4183 | try { |
| 4184 | if (phone != null) { |
| 4185 | return phone.getDataActivationState(); |
| 4186 | } else { |
| 4187 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 4188 | } |
| 4189 | } finally { |
| 4190 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4191 | } |
| 4192 | } |
| 4193 | |
| 4194 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4195 | * Returns the unread count of voicemails for a subId |
| 4196 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4197 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4198 | public int getVoiceMessageCountForSubscriber(int subId, String callingPackage, |
| 4199 | String callingFeatureId) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 4200 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4201 | mApp, subId, callingPackage, callingFeatureId, |
| 4202 | "getVoiceMessageCountForSubscriber")) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 4203 | return 0; |
| 4204 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4205 | final long identity = Binder.clearCallingIdentity(); |
| 4206 | try { |
| 4207 | final Phone phone = getPhone(subId); |
| 4208 | if (phone != null) { |
| 4209 | return phone.getVoiceMessageCount(); |
| 4210 | } else { |
| 4211 | return 0; |
| 4212 | } |
| 4213 | } finally { |
| 4214 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4215 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4216 | } |
| 4217 | |
| 4218 | /** |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 4219 | * returns true, if the device is in a state where both voice and data |
| 4220 | * are supported simultaneously. This can change based on location or network condition. |
| 4221 | */ |
| 4222 | @Override |
| 4223 | public boolean isConcurrentVoiceAndDataAllowed(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4224 | final long identity = Binder.clearCallingIdentity(); |
| 4225 | try { |
| 4226 | final Phone phone = getPhone(subId); |
| 4227 | return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed()); |
| 4228 | } finally { |
| 4229 | Binder.restoreCallingIdentity(identity); |
| 4230 | } |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 4231 | } |
| 4232 | |
| 4233 | /** |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4234 | * Send the dialer code if called from the current default dialer or the caller has |
| 4235 | * carrier privilege. |
| 4236 | * @param inputCode The dialer code to send |
| 4237 | */ |
| 4238 | @Override |
| 4239 | public void sendDialerSpecialCode(String callingPackage, String inputCode) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4240 | final Phone defaultPhone = getDefaultPhone(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4241 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 4242 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 4243 | String defaultDialer = tm.getDefaultDialerPackage(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4244 | if (!TextUtils.equals(callingPackage, defaultDialer)) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 4245 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4246 | getDefaultSubscription(), "sendDialerSpecialCode"); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4247 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4248 | |
| 4249 | final long identity = Binder.clearCallingIdentity(); |
| 4250 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4251 | defaultPhone.sendDialerSpecialCode(inputCode); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4252 | } finally { |
| 4253 | Binder.restoreCallingIdentity(identity); |
| 4254 | } |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4255 | } |
| 4256 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 4257 | @Override |
| 4258 | public int getNetworkSelectionMode(int subId) { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 4259 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4260 | .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 4261 | mApp, subId, "getNetworkSelectionMode"); |
| 4262 | final long identity = Binder.clearCallingIdentity(); |
| 4263 | try { |
| 4264 | if (!isActiveSubscription(subId)) { |
| 4265 | return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 4266 | } |
| 4267 | return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId); |
| 4268 | } finally { |
| 4269 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 4270 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 4271 | } |
| 4272 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4273 | @Override |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 4274 | public boolean isInEmergencySmsMode() { |
| 4275 | enforceReadPrivilegedPermission("isInEmergencySmsMode"); |
| 4276 | final long identity = Binder.clearCallingIdentity(); |
| 4277 | try { |
| 4278 | for (Phone phone : PhoneFactory.getPhones()) { |
| 4279 | if (phone.isInEmergencySmsMode()) { |
| 4280 | return true; |
| 4281 | } |
| 4282 | } |
| 4283 | } finally { |
| 4284 | Binder.restoreCallingIdentity(identity); |
| 4285 | } |
| 4286 | return false; |
| 4287 | } |
| 4288 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4289 | /** |
| 4290 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4291 | * @param subId The subscription to use to check the configuration. |
| 4292 | * @param c The callback that will be used to send the result. |
| 4293 | */ |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 4294 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4295 | public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c) |
| 4296 | throws RemoteException { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4297 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4298 | mApp, subId, "registerImsRegistrationCallback"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4299 | |
| 4300 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4301 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4302 | "IMS not available on device."); |
| 4303 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4304 | final long token = Binder.clearCallingIdentity(); |
| 4305 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4306 | int slotId = getSlotIndexOrException(subId); |
| 4307 | verifyImsMmTelConfiguredOrThrow(slotId); |
joonhunshin | 49f0aed | 2022-08-05 08:33:05 +0000 | [diff] [blame] | 4308 | |
| 4309 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4310 | if (controller != null) { |
| 4311 | ImsManager imsManager = controller.getImsManager(subId); |
| 4312 | if (imsManager != null) { |
| 4313 | imsManager.addRegistrationCallbackForSubscription(c, subId); |
| 4314 | } else { |
| 4315 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE); |
| 4316 | } |
| 4317 | } else { |
| 4318 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION); |
| 4319 | } |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4320 | } catch (ImsException e) { |
| 4321 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4322 | } finally { |
| 4323 | Binder.restoreCallingIdentity(token); |
| 4324 | } |
| 4325 | } |
| 4326 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4327 | /** |
| 4328 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4329 | * @param subId The subscription to use to check the configuration. |
| 4330 | * @param c The callback that will be used to send the result. |
| 4331 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4332 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4333 | public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4334 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4335 | mApp, subId, "unregisterImsRegistrationCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4336 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4337 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4338 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4339 | final long token = Binder.clearCallingIdentity(); |
joonhunshin | 49f0aed | 2022-08-05 08:33:05 +0000 | [diff] [blame] | 4340 | |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4341 | try { |
joonhunshin | 49f0aed | 2022-08-05 08:33:05 +0000 | [diff] [blame] | 4342 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4343 | if (controller != null) { |
| 4344 | ImsManager imsManager = controller.getImsManager(subId); |
| 4345 | if (imsManager != null) { |
| 4346 | imsManager.removeRegistrationCallbackForSubscription(c, subId); |
| 4347 | } else { |
| 4348 | Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId |
| 4349 | + "is inactive, ignoring unregister."); |
| 4350 | // If the ImsManager is not valid, just return, since the callback |
| 4351 | // will already have been removed internally. |
| 4352 | } |
| 4353 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4354 | } finally { |
| 4355 | Binder.restoreCallingIdentity(token); |
| 4356 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4357 | } |
| 4358 | |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 4359 | /** |
| 4360 | * Get the IMS service registration state for the MmTelFeature associated with this sub id. |
| 4361 | */ |
| 4362 | @Override |
| 4363 | public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) { |
| 4364 | enforceReadPrivilegedPermission("getImsMmTelRegistrationState"); |
| 4365 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4366 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4367 | "IMS not available on device."); |
| 4368 | } |
| 4369 | final long token = Binder.clearCallingIdentity(); |
| 4370 | try { |
| 4371 | Phone phone = getPhone(subId); |
| 4372 | if (phone == null) { |
| 4373 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 4374 | + subId + "'"); |
| 4375 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 4376 | } |
| 4377 | phone.getImsRegistrationState(regState -> { |
| 4378 | try { |
| 4379 | consumer.accept((regState == null) |
| 4380 | ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState); |
| 4381 | } catch (RemoteException e) { |
| 4382 | // Ignore if the remote process is no longer available to call back. |
| 4383 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 4384 | } |
| 4385 | }); |
| 4386 | } finally { |
| 4387 | Binder.restoreCallingIdentity(token); |
| 4388 | } |
| 4389 | } |
| 4390 | |
| 4391 | /** |
| 4392 | * Get the transport type for the IMS service registration state. |
| 4393 | */ |
| 4394 | @Override |
| 4395 | public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4396 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4397 | mApp, subId, "getImsMmTelRegistrationTransportType"); |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 4398 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4399 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4400 | "IMS not available on device."); |
| 4401 | } |
| 4402 | final long token = Binder.clearCallingIdentity(); |
| 4403 | try { |
| 4404 | Phone phone = getPhone(subId); |
| 4405 | if (phone == null) { |
| 4406 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 4407 | + subId + "'"); |
| 4408 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 4409 | } |
| 4410 | phone.getImsRegistrationTech(regTech -> { |
| 4411 | // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager |
| 4412 | int regTechConverted = (regTech == null) |
| 4413 | ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech; |
| 4414 | regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get( |
| 4415 | regTechConverted); |
| 4416 | try { |
| 4417 | consumer.accept(regTechConverted); |
| 4418 | } catch (RemoteException e) { |
| 4419 | // Ignore if the remote process is no longer available to call back. |
| 4420 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 4421 | } |
| 4422 | }); |
| 4423 | } finally { |
| 4424 | Binder.restoreCallingIdentity(token); |
| 4425 | } |
| 4426 | } |
| 4427 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4428 | /** |
| 4429 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4430 | * @param subId The subscription to use to check the configuration. |
| 4431 | * @param c The callback that will be used to send the result. |
| 4432 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4433 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4434 | public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) |
| 4435 | throws RemoteException { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4436 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4437 | mApp, subId, "registerMmTelCapabilityCallback"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4438 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4439 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4440 | "IMS not available on device."); |
| 4441 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4442 | final long token = Binder.clearCallingIdentity(); |
| 4443 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4444 | int slotId = getSlotIndexOrException(subId); |
| 4445 | verifyImsMmTelConfiguredOrThrow(slotId); |
Hwangoo Park | 8646b0d | 2023-01-13 02:42:34 +0000 | [diff] [blame] | 4446 | |
| 4447 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4448 | if (controller != null) { |
| 4449 | ImsManager imsManager = controller.getImsManager(subId); |
| 4450 | if (imsManager != null) { |
| 4451 | imsManager.addCapabilitiesCallbackForSubscription(c, subId); |
| 4452 | } else { |
| 4453 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE); |
| 4454 | } |
| 4455 | } else { |
| 4456 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION); |
| 4457 | } |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4458 | } catch (ImsException e) { |
| 4459 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4460 | } finally { |
| 4461 | Binder.restoreCallingIdentity(token); |
| 4462 | } |
| 4463 | } |
| 4464 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4465 | /** |
| 4466 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4467 | * @param subId The subscription to use to check the configuration. |
| 4468 | * @param c The callback that will be used to send the result. |
| 4469 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4470 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4471 | public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4472 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4473 | mApp, subId, "unregisterMmTelCapabilityCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4474 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4475 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4476 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4477 | |
| 4478 | final long token = Binder.clearCallingIdentity(); |
| 4479 | try { |
Hwangoo Park | 8646b0d | 2023-01-13 02:42:34 +0000 | [diff] [blame] | 4480 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4481 | if (controller != null) { |
| 4482 | ImsManager imsManager = controller.getImsManager(subId); |
| 4483 | if (imsManager != null) { |
| 4484 | imsManager.removeCapabilitiesCallbackForSubscription(c, subId); |
| 4485 | } else { |
| 4486 | Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId |
| 4487 | + " is inactive, ignoring unregister."); |
| 4488 | // If the ImsManager is not valid, just return, since the callback |
| 4489 | // will already have been removed internally. |
| 4490 | } |
| 4491 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4492 | } finally { |
| 4493 | Binder.restoreCallingIdentity(token); |
| 4494 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4495 | } |
| 4496 | |
| 4497 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4498 | public boolean isCapable(int subId, int capability, int regTech) { |
| 4499 | enforceReadPrivilegedPermission("isCapable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4500 | final long token = Binder.clearCallingIdentity(); |
| 4501 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4502 | int slotId = getSlotIndexOrException(subId); |
| 4503 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 4504 | return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech); |
| 4505 | } catch (com.android.ims.ImsException e) { |
| 4506 | Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage()); |
| 4507 | return false; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4508 | } catch (ImsException e) { |
Brad Ebinger | 6b5ac22 | 2019-02-04 14:36:52 -0800 | [diff] [blame] | 4509 | Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false."); |
| 4510 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4511 | } finally { |
| 4512 | Binder.restoreCallingIdentity(token); |
| 4513 | } |
| 4514 | } |
| 4515 | |
| 4516 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4517 | public boolean isAvailable(int subId, int capability, int regTech) { |
| 4518 | enforceReadPrivilegedPermission("isAvailable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4519 | final long token = Binder.clearCallingIdentity(); |
| 4520 | try { |
| 4521 | Phone phone = getPhone(subId); |
| 4522 | if (phone == null) return false; |
| 4523 | return phone.isImsCapabilityAvailable(capability, regTech); |
Daniel Bright | 5e40e4e | 2020-03-11 16:35:39 -0700 | [diff] [blame] | 4524 | } catch (com.android.ims.ImsException e) { |
| 4525 | Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage()); |
| 4526 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4527 | } finally { |
| 4528 | Binder.restoreCallingIdentity(token); |
| 4529 | } |
| 4530 | } |
| 4531 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4532 | /** |
| 4533 | * Determines if the MmTel feature capability is supported by the carrier configuration for this |
| 4534 | * subscription. |
| 4535 | * @param subId The subscription to use to check the configuration. |
| 4536 | * @param callback The callback that will be used to send the result. |
| 4537 | * @param capability The MmTelFeature capability that will be used to send the result. |
| 4538 | * @param transportType The transport type of the MmTelFeature capability. |
| 4539 | */ |
| 4540 | @Override |
| 4541 | public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability, |
| 4542 | int transportType) { |
| 4543 | enforceReadPrivilegedPermission("isMmTelCapabilitySupported"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4544 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4545 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4546 | "IMS not available on device."); |
| 4547 | } |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4548 | final long token = Binder.clearCallingIdentity(); |
| 4549 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4550 | int slotId = getSlotIndex(subId); |
| 4551 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4552 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '" |
| 4553 | + subId + "'"); |
| 4554 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 4555 | } |
| 4556 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 4557 | ImsManager.getInstance(mApp, slotId).isSupported(capability, |
| 4558 | transportType, aBoolean -> { |
| 4559 | try { |
| 4560 | callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0)); |
| 4561 | } catch (RemoteException e) { |
| 4562 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not " |
| 4563 | + "running. Ignore"); |
| 4564 | } |
| 4565 | }); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4566 | } catch (ImsException e) { |
| 4567 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4568 | } finally { |
| 4569 | Binder.restoreCallingIdentity(token); |
| 4570 | } |
| 4571 | } |
| 4572 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4573 | /** |
| 4574 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4575 | * @param subId The subscription to use to check the configuration. |
| 4576 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4577 | @Override |
| 4578 | public boolean isAdvancedCallingSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4579 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4580 | mApp, subId, "isAdvancedCallingSettingEnabled"); |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4581 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4582 | final long token = Binder.clearCallingIdentity(); |
| 4583 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4584 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4585 | // 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] | 4586 | return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4587 | } catch (ImsException e) { |
| 4588 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4589 | } finally { |
| 4590 | Binder.restoreCallingIdentity(token); |
| 4591 | } |
| 4592 | } |
| 4593 | |
| 4594 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4595 | public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4596 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4597 | "setAdvancedCallingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4598 | final long identity = Binder.clearCallingIdentity(); |
| 4599 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4600 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4601 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4602 | // 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] | 4603 | ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4604 | } catch (ImsException e) { |
| 4605 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4606 | } finally { |
| 4607 | Binder.restoreCallingIdentity(identity); |
| 4608 | } |
| 4609 | } |
| 4610 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4611 | /** |
| 4612 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4613 | * @param subId The subscription to use to check the configuration. |
| 4614 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4615 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4616 | public boolean isVtSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4617 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4618 | mApp, subId, "isVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4619 | final long identity = Binder.clearCallingIdentity(); |
| 4620 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4621 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4622 | // 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] | 4623 | return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4624 | } catch (ImsException e) { |
| 4625 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4626 | } finally { |
| 4627 | Binder.restoreCallingIdentity(identity); |
| 4628 | } |
| 4629 | } |
| 4630 | |
| 4631 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4632 | public void setVtSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4633 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4634 | "setVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4635 | final long identity = Binder.clearCallingIdentity(); |
| 4636 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4637 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4638 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4639 | // 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] | 4640 | ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4641 | } catch (ImsException e) { |
| 4642 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4643 | } finally { |
| 4644 | Binder.restoreCallingIdentity(identity); |
| 4645 | } |
| 4646 | } |
| 4647 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4648 | /** |
| 4649 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4650 | * @param subId The subscription to use to check the configuration. |
| 4651 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4652 | @Override |
| 4653 | public boolean isVoWiFiSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4654 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4655 | mApp, subId, "isVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4656 | final long identity = Binder.clearCallingIdentity(); |
| 4657 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4658 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4659 | // 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] | 4660 | return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4661 | } catch (ImsException e) { |
| 4662 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4663 | } finally { |
| 4664 | Binder.restoreCallingIdentity(identity); |
| 4665 | } |
| 4666 | } |
| 4667 | |
| 4668 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4669 | public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4670 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4671 | "setVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4672 | final long identity = Binder.clearCallingIdentity(); |
| 4673 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4674 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4675 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4676 | // 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] | 4677 | ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4678 | } catch (ImsException e) { |
| 4679 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4680 | } finally { |
| 4681 | Binder.restoreCallingIdentity(identity); |
| 4682 | } |
| 4683 | } |
| 4684 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4685 | /** |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 4686 | * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not |
| 4687 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4688 | * @param subId The subscription to use to check the configuration. |
| 4689 | */ |
| 4690 | @Override |
| 4691 | public boolean isCrossSimCallingEnabledByUser(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4692 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 4693 | mApp, subId, "isCrossSimCallingEnabledByUser"); |
| 4694 | final long identity = Binder.clearCallingIdentity(); |
| 4695 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4696 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4697 | // 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] | 4698 | return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser(); |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 4699 | } catch (ImsException e) { |
| 4700 | throw new ServiceSpecificException(e.getCode()); |
| 4701 | } finally { |
| 4702 | Binder.restoreCallingIdentity(identity); |
| 4703 | } |
| 4704 | } |
| 4705 | |
| 4706 | /** |
| 4707 | * Sets the user's setting for whether or not Voice over Cross SIM is enabled. |
| 4708 | * Requires MODIFY_PHONE_STATE permission. |
| 4709 | * @param subId The subscription to use to check the configuration. |
| 4710 | * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled, |
| 4711 | * false otherwise |
| 4712 | */ |
| 4713 | @Override |
| 4714 | public void setCrossSimCallingEnabled(int subId, boolean isEnabled) { |
| 4715 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4716 | "setCrossSimCallingEnabled"); |
| 4717 | final long identity = Binder.clearCallingIdentity(); |
| 4718 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4719 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4720 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4721 | // 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] | 4722 | ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled); |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 4723 | } catch (ImsException e) { |
| 4724 | throw new ServiceSpecificException(e.getCode()); |
| 4725 | } finally { |
| 4726 | Binder.restoreCallingIdentity(identity); |
| 4727 | } |
| 4728 | } |
| 4729 | |
| 4730 | /** |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4731 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4732 | * @param subId The subscription to use to check the configuration. |
| 4733 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4734 | @Override |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4735 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4736 | public boolean isVoWiFiRoamingSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4737 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4738 | mApp, subId, "isVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4739 | final long identity = Binder.clearCallingIdentity(); |
| 4740 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4741 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4742 | // 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] | 4743 | return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4744 | } catch (ImsException e) { |
| 4745 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4746 | } finally { |
| 4747 | Binder.restoreCallingIdentity(identity); |
| 4748 | } |
| 4749 | } |
| 4750 | |
| 4751 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4752 | public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4753 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4754 | "setVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4755 | final long identity = Binder.clearCallingIdentity(); |
| 4756 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4757 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4758 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4759 | // 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] | 4760 | ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4761 | } catch (ImsException e) { |
| 4762 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4763 | } finally { |
| 4764 | Binder.restoreCallingIdentity(identity); |
| 4765 | } |
| 4766 | } |
| 4767 | |
| 4768 | @Override |
| 4769 | public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) { |
| 4770 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4771 | "setVoWiFiNonPersistent"); |
| 4772 | final long identity = Binder.clearCallingIdentity(); |
| 4773 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4774 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4775 | // This setting will be ignored if the ImsService isn't up. |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4776 | ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4777 | } catch (ImsException e) { |
| 4778 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4779 | } finally { |
| 4780 | Binder.restoreCallingIdentity(identity); |
| 4781 | } |
| 4782 | } |
| 4783 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4784 | /** |
| 4785 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4786 | * @param subId The subscription to use to check the configuration. |
| 4787 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4788 | @Override |
| 4789 | public int getVoWiFiModeSetting(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4790 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4791 | mApp, subId, "getVoWiFiModeSetting"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4792 | final long identity = Binder.clearCallingIdentity(); |
| 4793 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4794 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4795 | // 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] | 4796 | return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4797 | } catch (ImsException e) { |
| 4798 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4799 | } finally { |
| 4800 | Binder.restoreCallingIdentity(identity); |
| 4801 | } |
| 4802 | } |
| 4803 | |
| 4804 | @Override |
| 4805 | public void setVoWiFiModeSetting(int subId, int mode) { |
| 4806 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4807 | "setVoWiFiModeSetting"); |
| 4808 | final long identity = Binder.clearCallingIdentity(); |
| 4809 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4810 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4811 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4812 | // 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] | 4813 | ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4814 | } catch (ImsException e) { |
| 4815 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4816 | } finally { |
| 4817 | Binder.restoreCallingIdentity(identity); |
| 4818 | } |
| 4819 | } |
| 4820 | |
| 4821 | @Override |
| 4822 | public int getVoWiFiRoamingModeSetting(int subId) { |
| 4823 | enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting"); |
| 4824 | final long identity = Binder.clearCallingIdentity(); |
| 4825 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4826 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4827 | // 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] | 4828 | return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4829 | } catch (ImsException e) { |
| 4830 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4831 | } finally { |
| 4832 | Binder.restoreCallingIdentity(identity); |
| 4833 | } |
| 4834 | } |
| 4835 | |
| 4836 | @Override |
| 4837 | public void setVoWiFiRoamingModeSetting(int subId, int mode) { |
| 4838 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4839 | "setVoWiFiRoamingModeSetting"); |
| 4840 | final long identity = Binder.clearCallingIdentity(); |
| 4841 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4842 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4843 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4844 | // 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] | 4845 | ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4846 | } catch (ImsException e) { |
| 4847 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4848 | } finally { |
| 4849 | Binder.restoreCallingIdentity(identity); |
| 4850 | } |
| 4851 | } |
| 4852 | |
| 4853 | @Override |
| 4854 | public void setRttCapabilitySetting(int subId, boolean isEnabled) { |
| 4855 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4856 | "setRttCapabilityEnabled"); |
| 4857 | final long identity = Binder.clearCallingIdentity(); |
| 4858 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4859 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4860 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4861 | // 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] | 4862 | ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4863 | } catch (ImsException e) { |
| 4864 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4865 | } finally { |
| 4866 | Binder.restoreCallingIdentity(identity); |
| 4867 | } |
| 4868 | } |
| 4869 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4870 | /** |
| 4871 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4872 | * @param subId The subscription to use to check the configuration. |
| 4873 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4874 | @Override |
| 4875 | public boolean isTtyOverVolteEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4876 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4877 | mApp, subId, "isTtyOverVolteEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4878 | final long identity = Binder.clearCallingIdentity(); |
| 4879 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4880 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4881 | // 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] | 4882 | return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4883 | } catch (ImsException e) { |
| 4884 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4885 | } finally { |
| 4886 | Binder.restoreCallingIdentity(identity); |
| 4887 | } |
| 4888 | } |
| 4889 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4890 | @Override |
| 4891 | public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 4892 | enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4893 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4894 | final long identity = Binder.clearCallingIdentity(); |
| 4895 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4896 | if (!isImsAvailableOnDevice()) { |
| 4897 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4898 | "IMS not available on device."); |
| 4899 | } |
| 4900 | int slotId = getSlotIndexOrException(subId); |
| 4901 | verifyImsMmTelConfiguredOrThrow(slotId); |
Hwangoo Park | 8646b0d | 2023-01-13 02:42:34 +0000 | [diff] [blame] | 4902 | |
| 4903 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4904 | if (controller != null) { |
| 4905 | ImsManager imsManager = controller.getImsManager(subId); |
| 4906 | if (imsManager != null) { |
| 4907 | imsManager.addProvisioningCallbackForSubscription(callback, subId); |
| 4908 | } else { |
| 4909 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE); |
| 4910 | } |
| 4911 | } else { |
| 4912 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION); |
| 4913 | } |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4914 | } catch (ImsException e) { |
| 4915 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4916 | } finally { |
| 4917 | Binder.restoreCallingIdentity(identity); |
| 4918 | } |
| 4919 | } |
| 4920 | |
| 4921 | @Override |
| 4922 | public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 4923 | enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4924 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4925 | final long identity = Binder.clearCallingIdentity(); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4926 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4927 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4928 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4929 | try { |
Hwangoo Park | 8646b0d | 2023-01-13 02:42:34 +0000 | [diff] [blame] | 4930 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4931 | if (controller != null) { |
| 4932 | ImsManager imsManager = controller.getImsManager(subId); |
| 4933 | if (imsManager != null) { |
| 4934 | imsManager.removeProvisioningCallbackForSubscription(callback, subId); |
| 4935 | } else { |
| 4936 | Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId |
| 4937 | + " is inactive, ignoring unregister."); |
| 4938 | // If the ImsManager is not valid, just return, since the callback will already |
| 4939 | // have been removed internally. |
| 4940 | } |
| 4941 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4942 | } finally { |
| 4943 | Binder.restoreCallingIdentity(identity); |
| 4944 | } |
| 4945 | } |
| 4946 | |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4947 | @Override |
| 4948 | public void registerFeatureProvisioningChangedCallback(int subId, |
| 4949 | IFeatureProvisioningCallback callback) { |
| 4950 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4951 | mApp, subId, "registerFeatureProvisioningChangedCallback"); |
| 4952 | |
| 4953 | final long identity = Binder.clearCallingIdentity(); |
| 4954 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4955 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4956 | } |
| 4957 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 4958 | try { |
| 4959 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 4960 | if (controller == null) { |
| 4961 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4962 | "Device does not support IMS"); |
| 4963 | } |
| 4964 | controller.addFeatureProvisioningChangedCallback(subId, callback); |
| 4965 | } finally { |
| 4966 | Binder.restoreCallingIdentity(identity); |
| 4967 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4968 | } |
| 4969 | |
| 4970 | @Override |
| 4971 | public void unregisterFeatureProvisioningChangedCallback(int subId, |
| 4972 | IFeatureProvisioningCallback callback) { |
| 4973 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4974 | mApp, subId, "unregisterFeatureProvisioningChangedCallback"); |
| 4975 | |
| 4976 | final long identity = Binder.clearCallingIdentity(); |
| 4977 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4978 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4979 | } |
| 4980 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 4981 | try { |
| 4982 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 4983 | if (controller == null) { |
| 4984 | loge("unregisterFeatureProvisioningChangedCallback: Device does not support IMS"); |
| 4985 | return; |
| 4986 | } |
| 4987 | controller.removeFeatureProvisioningChangedCallback(subId, callback); |
| 4988 | } finally { |
| 4989 | Binder.restoreCallingIdentity(identity); |
| 4990 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4991 | } |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4992 | |
| 4993 | private void checkModifyPhoneStatePermission(int subId, String message) { |
| 4994 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4995 | message); |
| 4996 | } |
| 4997 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4998 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4999 | public void setRcsProvisioningStatusForCapability(int subId, int capability, int tech, |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5000 | boolean isProvisioned) { |
| 5001 | checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability"); |
| 5002 | |
| 5003 | final long identity = Binder.clearCallingIdentity(); |
| 5004 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5005 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5006 | if (controller == null) { |
| 5007 | loge("setRcsProvisioningStatusForCapability: Device does not support IMS"); |
| 5008 | return; |
| 5009 | } |
| 5010 | controller.setRcsProvisioningStatusForCapability( |
| 5011 | subId, capability, tech, isProvisioned); |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5012 | } finally { |
| 5013 | Binder.restoreCallingIdentity(identity); |
| 5014 | } |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5015 | } |
| 5016 | |
| 5017 | |
| 5018 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5019 | public boolean getRcsProvisioningStatusForCapability(int subId, int capability, int tech) { |
| 5020 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5021 | mApp, subId, "getRcsProvisioningStatusForCapability"); |
| 5022 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5023 | final long identity = Binder.clearCallingIdentity(); |
| 5024 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5025 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5026 | if (controller == null) { |
| 5027 | loge("getRcsProvisioningStatusForCapability: Device does not support IMS"); |
| 5028 | |
| 5029 | // device does not support IMS, this method will return true always. |
| 5030 | return true; |
| 5031 | } |
| 5032 | return controller.getRcsProvisioningStatusForCapability(subId, capability, tech); |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5033 | } finally { |
| 5034 | Binder.restoreCallingIdentity(identity); |
| 5035 | } |
| 5036 | } |
| 5037 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5038 | @Override |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5039 | public void setImsProvisioningStatusForCapability(int subId, int capability, int tech, |
| 5040 | boolean isProvisioned) { |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5041 | checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5042 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5043 | final long identity = Binder.clearCallingIdentity(); |
| 5044 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5045 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5046 | if (controller == null) { |
| 5047 | loge("setImsProvisioningStatusForCapability: Device does not support IMS"); |
| 5048 | return; |
| 5049 | } |
| 5050 | controller.setImsProvisioningStatusForCapability( |
| 5051 | subId, capability, tech, isProvisioned); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5052 | } finally { |
| 5053 | Binder.restoreCallingIdentity(identity); |
| 5054 | } |
| 5055 | } |
| 5056 | |
| 5057 | @Override |
| 5058 | public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) { |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5059 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5060 | mApp, subId, "getProvisioningStatusForCapability"); |
| 5061 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5062 | final long identity = Binder.clearCallingIdentity(); |
| 5063 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5064 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5065 | if (controller == null) { |
| 5066 | loge("getImsProvisioningStatusForCapability: Device does not support IMS"); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5067 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5068 | // device does not support IMS, this method will return true always. |
| 5069 | return true; |
| 5070 | } |
| 5071 | return controller.getImsProvisioningStatusForCapability(subId, capability, tech); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5072 | } finally { |
| 5073 | Binder.restoreCallingIdentity(identity); |
| 5074 | } |
| 5075 | } |
| 5076 | |
| 5077 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5078 | public boolean isProvisioningRequiredForCapability(int subId, int capability, int tech) { |
| 5079 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5080 | mApp, subId, "isProvisioningRequiredForCapability"); |
| 5081 | |
| 5082 | final long identity = Binder.clearCallingIdentity(); |
| 5083 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5084 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5085 | if (controller == null) { |
| 5086 | loge("isProvisioningRequiredForCapability: Device does not support IMS"); |
| 5087 | |
| 5088 | // device does not support IMS, this method will return false |
| 5089 | return false; |
| 5090 | } |
| 5091 | return controller.isImsProvisioningRequiredForCapability(subId, capability, tech); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5092 | } finally { |
| 5093 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5094 | } |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5095 | } |
| 5096 | |
| 5097 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5098 | public boolean isRcsProvisioningRequiredForCapability(int subId, int capability, int tech) { |
| 5099 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5100 | mApp, subId, "isProvisioningRequiredForCapability"); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5101 | |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5102 | final long identity = Binder.clearCallingIdentity(); |
| 5103 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5104 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5105 | if (controller == null) { |
| 5106 | loge("isRcsProvisioningRequiredForCapability: Device does not support IMS"); |
| 5107 | |
| 5108 | // device does not support IMS, this method will return false |
| 5109 | return false; |
| 5110 | } |
| 5111 | return controller.isRcsProvisioningRequiredForCapability(subId, capability, tech); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5112 | } finally { |
| 5113 | Binder.restoreCallingIdentity(identity); |
| 5114 | } |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5115 | } |
| 5116 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5117 | @Override |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5118 | public int getImsProvisioningInt(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5119 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5120 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 5121 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5122 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5123 | mApp, subId, "getImsProvisioningInt"); |
| 5124 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5125 | final long identity = Binder.clearCallingIdentity(); |
| 5126 | try { |
| 5127 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5128 | int slotId = getSlotIndex(subId); |
| 5129 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5130 | Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '" |
| 5131 | + subId + "' for key:" + key); |
| 5132 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
| 5133 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5134 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5135 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5136 | if (controller == null) { |
| 5137 | loge("getImsProvisioningInt: Device does not support IMS"); |
| 5138 | |
| 5139 | // device does not support IMS, this method will return CONFIG_RESULT_UNKNOWN. |
| 5140 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
| 5141 | } |
| 5142 | int retVal = controller.getProvisioningValue(subId, key); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5143 | if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) { |
| 5144 | return retVal; |
| 5145 | } |
| 5146 | |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5147 | return ImsManager.getInstance(mApp, slotId).getConfigInt(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5148 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5149 | Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '" |
| 5150 | + subId + "' for key:" + key); |
| 5151 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5152 | } finally { |
| 5153 | Binder.restoreCallingIdentity(identity); |
| 5154 | } |
| 5155 | } |
| 5156 | |
| 5157 | @Override |
| 5158 | public String getImsProvisioningString(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5159 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5160 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 5161 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5162 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5163 | mApp, subId, "getImsProvisioningString"); |
| 5164 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5165 | final long identity = Binder.clearCallingIdentity(); |
| 5166 | try { |
| 5167 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5168 | int slotId = getSlotIndex(subId); |
| 5169 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5170 | Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '" |
| 5171 | + subId + "' for key:" + key); |
| 5172 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC; |
| 5173 | } |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5174 | return ImsManager.getInstance(mApp, slotId).getConfigString(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5175 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5176 | Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '" |
| 5177 | + subId + "' for key:" + key); |
| 5178 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5179 | } finally { |
| 5180 | Binder.restoreCallingIdentity(identity); |
| 5181 | } |
| 5182 | } |
| 5183 | |
| 5184 | @Override |
| 5185 | public int setImsProvisioningInt(int subId, int key, int value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5186 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5187 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 5188 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 5189 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5190 | "setImsProvisioningInt"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5191 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5192 | final long identity = Binder.clearCallingIdentity(); |
| 5193 | try { |
| 5194 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5195 | int slotId = getSlotIndex(subId); |
| 5196 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5197 | Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '" |
| 5198 | + subId + "' for key:" + key); |
| 5199 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 5200 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5201 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5202 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5203 | if (controller == null) { |
| 5204 | loge("setImsProvisioningInt: Device does not support IMS"); |
| 5205 | |
| 5206 | // device does not support IMS, this method will return CONFIG_RESULT_FAILED. |
| 5207 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 5208 | } |
| 5209 | int retVal = controller.setProvisioningValue(subId, key, value); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5210 | if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) { |
| 5211 | return retVal; |
| 5212 | } |
| 5213 | |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5214 | return ImsManager.getInstance(mApp, slotId).setConfig(key, value); |
| 5215 | } catch (com.android.ims.ImsException | RemoteException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5216 | Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5217 | + "' for key:" + key, e); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5218 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5219 | } finally { |
| 5220 | Binder.restoreCallingIdentity(identity); |
| 5221 | } |
| 5222 | } |
| 5223 | |
| 5224 | @Override |
| 5225 | public int setImsProvisioningString(int subId, int key, String value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5226 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5227 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 5228 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 5229 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5230 | "setImsProvisioningString"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5231 | final long identity = Binder.clearCallingIdentity(); |
| 5232 | try { |
| 5233 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5234 | int slotId = getSlotIndex(subId); |
| 5235 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5236 | Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '" |
| 5237 | + subId + "' for key:" + key); |
| 5238 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 5239 | } |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5240 | return ImsManager.getInstance(mApp, slotId).setConfig(key, value); |
| 5241 | } catch (com.android.ims.ImsException | RemoteException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5242 | Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5243 | + "' for key:" + key, e); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5244 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5245 | } finally { |
| 5246 | Binder.restoreCallingIdentity(identity); |
| 5247 | } |
| 5248 | } |
| 5249 | |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5250 | /** |
| 5251 | * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL |
| 5252 | * for the given slot ID or no ImsResolver instance has been created. |
| 5253 | * @param slotId The slot ID that the IMS service is created for. |
| 5254 | * @throws ImsException If there is no ImsService configured for this slot. |
| 5255 | */ |
| 5256 | private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException { |
| 5257 | if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId, |
| 5258 | ImsFeature.FEATURE_MMTEL)) { |
| 5259 | throw new ImsException("This subscription does not support MMTEL over IMS", |
| 5260 | ImsException.CODE_ERROR_UNSUPPORTED_OPERATION); |
| 5261 | } |
| 5262 | } |
| 5263 | |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5264 | private int getSlotIndexOrException(int subId) throws ImsException { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5265 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 5266 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5267 | throw new ImsException("Invalid Subscription Id, subId=" + subId, |
| 5268 | ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5269 | } |
| 5270 | return slotId; |
| 5271 | } |
| 5272 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5273 | private int getSlotIndex(int subId) { |
| 5274 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 5275 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
| 5276 | return SubscriptionManager.INVALID_SIM_SLOT_INDEX; |
| 5277 | } |
| 5278 | return slotId; |
| 5279 | } |
| 5280 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5281 | /** |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 5282 | * Returns the data network type for a subId; does not throw SecurityException. |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5283 | */ |
| 5284 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5285 | public int getNetworkTypeForSubscriber(int subId, String callingPackage, |
| 5286 | String callingFeatureId) { |
Shuo Qian | 13d8915 | 2021-05-10 23:58:11 -0700 | [diff] [blame] | 5287 | try { |
| 5288 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 5289 | } catch (SecurityException se) { |
| 5290 | EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid()); |
| 5291 | throw new SecurityException("Package " + callingPackage + " does not belong to " |
| 5292 | + Binder.getCallingUid()); |
| 5293 | } |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 5294 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 5295 | if (targetSdk > android.os.Build.VERSION_CODES.Q) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5296 | return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 5297 | } else if (targetSdk == android.os.Build.VERSION_CODES.Q |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 5298 | && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5299 | mApp, subId, callingPackage, callingFeatureId, |
| 5300 | "getNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5301 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5302 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 5303 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5304 | final long identity = Binder.clearCallingIdentity(); |
| 5305 | try { |
| 5306 | final Phone phone = getPhone(subId); |
| 5307 | if (phone != null) { |
| 5308 | return phone.getServiceState().getDataNetworkType(); |
| 5309 | } else { |
| 5310 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5311 | } |
| 5312 | } finally { |
| 5313 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5314 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5315 | } |
| 5316 | |
| 5317 | /** |
| 5318 | * Returns the data network type |
| 5319 | */ |
| 5320 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5321 | public int getDataNetworkType(String callingPackage, String callingFeatureId) { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5322 | return getDataNetworkTypeForSubscriber(SubscriptionManager.getDefaultDataSubscriptionId(), |
Zoey Chen | fd61f7f | 2021-04-21 13:42:10 +0800 | [diff] [blame] | 5323 | callingPackage, callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5324 | } |
| 5325 | |
| 5326 | /** |
| 5327 | * Returns the data network type for a subId |
| 5328 | */ |
| 5329 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5330 | public int getDataNetworkTypeForSubscriber(int subId, String callingPackage, |
| 5331 | String callingFeatureId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 5332 | String functionName = "getDataNetworkTypeForSubscriber"; |
| 5333 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 5334 | mApp, functionName)) { |
| 5335 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 5336 | mApp, subId, callingPackage, callingFeatureId, functionName)) { |
| 5337 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5338 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5339 | } |
| 5340 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5341 | final long identity = Binder.clearCallingIdentity(); |
| 5342 | try { |
| 5343 | final Phone phone = getPhone(subId); |
| 5344 | if (phone != null) { |
| 5345 | return phone.getServiceState().getDataNetworkType(); |
| 5346 | } else { |
| 5347 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5348 | } |
| 5349 | } finally { |
| 5350 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5351 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5352 | } |
| 5353 | |
| 5354 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5355 | * Returns the Voice network type for a subId |
| 5356 | */ |
| 5357 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5358 | public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage, |
| 5359 | String callingFeatureId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 5360 | String functionName = "getVoiceNetworkTypeForSubscriber"; |
| 5361 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 5362 | mApp, functionName)) { |
| 5363 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 5364 | mApp, subId, callingPackage, callingFeatureId, functionName)) { |
| 5365 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5366 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 5367 | } |
| 5368 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5369 | final long identity = Binder.clearCallingIdentity(); |
| 5370 | try { |
| 5371 | final Phone phone = getPhone(subId); |
| 5372 | if (phone != null) { |
| 5373 | return phone.getServiceState().getVoiceNetworkType(); |
| 5374 | } else { |
| 5375 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5376 | } |
| 5377 | } finally { |
| 5378 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5379 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5380 | } |
| 5381 | |
| 5382 | /** |
| 5383 | * @return true if a ICC card is present |
| 5384 | */ |
| 5385 | public boolean hasIccCard() { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5386 | // FIXME Make changes to pass defaultSimId of type int |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5387 | return hasIccCardUsingSlotIndex(SubscriptionManager.getSlotIndex( |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5388 | getDefaultSubscription())); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5389 | } |
| 5390 | |
| 5391 | /** |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5392 | * @return true if a ICC card is present for a slotIndex |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5393 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5394 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5395 | public boolean hasIccCardUsingSlotIndex(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5396 | final long identity = Binder.clearCallingIdentity(); |
| 5397 | try { |
| 5398 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5399 | if (phone != null) { |
| 5400 | return phone.getIccCard().hasIccCard(); |
| 5401 | } else { |
| 5402 | return false; |
| 5403 | } |
| 5404 | } finally { |
| 5405 | Binder.restoreCallingIdentity(identity); |
Amit Mahajan | a6fc2a8 | 2015-01-06 11:53:51 -0800 | [diff] [blame] | 5406 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5407 | } |
| 5408 | |
| 5409 | /** |
| 5410 | * Return if the current radio is LTE on CDMA. This |
| 5411 | * is a tri-state return value as for a period of time |
| 5412 | * the mode may be unknown. |
| 5413 | * |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5414 | * @param callingPackage the name of the package making the call. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5415 | * @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] | 5416 | * or {@link Phone#LTE_ON_CDMA_TRUE} |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5417 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5418 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5419 | public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) { |
| 5420 | return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 5421 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5422 | } |
| 5423 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5424 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5425 | public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage, |
| 5426 | String callingFeatureId) { |
Sarah Chin | 790d292 | 2020-01-16 12:17:23 -0800 | [diff] [blame] | 5427 | try { |
| 5428 | enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber"); |
| 5429 | } catch (SecurityException e) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5430 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 5431 | } |
| 5432 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5433 | final long identity = Binder.clearCallingIdentity(); |
| 5434 | try { |
| 5435 | final Phone phone = getPhone(subId); |
| 5436 | if (phone == null) { |
| 5437 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 5438 | } else { |
Nathan Harold | 05ad633 | 2020-07-10 11:54:36 -0700 | [diff] [blame] | 5439 | return TelephonyProperties.lte_on_cdma_device() |
| 5440 | .orElse(PhoneConstants.LTE_ON_CDMA_FALSE); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5441 | } |
| 5442 | } finally { |
| 5443 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5444 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5445 | } |
| 5446 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5447 | /** |
| 5448 | * {@hide} |
| 5449 | * Returns Default subId, 0 in the case of single standby. |
| 5450 | */ |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 5451 | private int getDefaultSubscription() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5452 | return SubscriptionManager.getDefaultSubscriptionId(); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5453 | } |
| 5454 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 5455 | private int getSlotForDefaultSubscription() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5456 | return SubscriptionManager.getPhoneId(getDefaultSubscription()); |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 5457 | } |
| 5458 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 5459 | private int getPreferredVoiceSubscription() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5460 | return SubscriptionManager.getDefaultVoiceSubscriptionId(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5461 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5462 | |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 5463 | private boolean isActiveSubscription(int subId) { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5464 | if (PhoneFactory.isSubscriptionManagerServiceEnabled()) { |
| 5465 | return SubscriptionManagerService.getInstance().isActiveSubId(subId, |
| 5466 | mApp.getOpPackageName(), mApp.getFeatureId()); |
| 5467 | } |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 5468 | return mSubscriptionController.isActiveSubId(subId); |
| 5469 | } |
| 5470 | |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5471 | /** |
| 5472 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 5473 | */ |
| 5474 | public int getWhenToMakeWifiCalls() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5475 | final long identity = Binder.clearCallingIdentity(); |
| 5476 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5477 | return Settings.System.getInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5478 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, |
| 5479 | getWhenToMakeWifiCallsDefaultPreference()); |
| 5480 | } finally { |
| 5481 | Binder.restoreCallingIdentity(identity); |
| 5482 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5483 | } |
| 5484 | |
| 5485 | /** |
| 5486 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 5487 | */ |
| 5488 | public void setWhenToMakeWifiCalls(int preference) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5489 | final long identity = Binder.clearCallingIdentity(); |
| 5490 | try { |
| 5491 | if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5492 | Settings.System.putInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5493 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference); |
| 5494 | } finally { |
| 5495 | Binder.restoreCallingIdentity(identity); |
| 5496 | } |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 5497 | } |
| 5498 | |
Sailesh Nepal | d1e6815 | 2013-12-12 19:08:02 -0800 | [diff] [blame] | 5499 | private static int getWhenToMakeWifiCallsDefaultPreference() { |
Santos Cordon | da120f4 | 2014-08-06 04:44:34 -0700 | [diff] [blame] | 5500 | // TODO: Use a build property to choose this value. |
Evan Charlton | 9829e88 | 2013-12-19 15:30:38 -0800 | [diff] [blame] | 5501 | return TelephonyManager.WifiCallingChoices.ALWAYS_USE; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5502 | } |
Shishir Agrawal | 69f6812 | 2013-12-16 17:25:49 -0800 | [diff] [blame] | 5503 | |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5504 | private Phone getPhoneFromSlotPortIndexOrThrowException(int slotIndex, int portIndex) { |
| 5505 | int phoneId = UiccController.getInstance().getPhoneIdFromSlotPortIndex(slotIndex, |
| 5506 | portIndex); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5507 | if (phoneId == -1) { |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5508 | throw new IllegalArgumentException("Given slot index: " + slotIndex + " port index: " |
| 5509 | + portIndex + " does not correspond to an active phone"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5510 | } |
| 5511 | return PhoneFactory.getPhone(phoneId); |
| 5512 | } |
| 5513 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5514 | @Override |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 5515 | public IccOpenLogicalChannelResponse iccOpenLogicalChannel( |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5516 | @NonNull IccLogicalChannelRequest request) { |
| 5517 | Phone phone = getPhoneFromValidIccLogicalChannelRequest(request, |
| 5518 | /*message=*/ "iccOpenLogicalChannel"); |
| 5519 | |
| 5520 | if (DBG) log("iccOpenLogicalChannel: request=" + request); |
| 5521 | // Verify that the callingPackage in the request belongs to the calling UID |
| 5522 | mAppOps.checkPackage(Binder.getCallingUid(), request.callingPackage); |
| 5523 | |
| 5524 | return iccOpenLogicalChannelWithPermission(phone, request); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5525 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5526 | |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5527 | private Phone getPhoneFromValidIccLogicalChannelRequest( |
| 5528 | @NonNull IccLogicalChannelRequest request, String message) { |
| 5529 | Phone phone; |
| 5530 | if (request.subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) { |
| 5531 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5532 | mApp, request.subId, message); |
| 5533 | phone = getPhoneFromSubId(request.subId); |
| 5534 | } else if (request.slotIndex != SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5535 | enforceModifyPermission(); |
| 5536 | phone = getPhoneFromSlotPortIndexOrThrowException(request.slotIndex, request.portIndex); |
| 5537 | } else { |
| 5538 | throw new IllegalArgumentException("Both subId and slotIndex in request are invalid."); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5539 | } |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5540 | return phone; |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5541 | } |
| 5542 | |
| 5543 | private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone, |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5544 | IccLogicalChannelRequest channelRequest) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5545 | final long identity = Binder.clearCallingIdentity(); |
| 5546 | try { |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5547 | if (TextUtils.equals(ISDR_AID, channelRequest.aid)) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5548 | // Only allows LPA to open logical channel to ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5549 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 5550 | .getContext().getPackageManager()); |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5551 | if (bestComponent == null || !TextUtils.equals(channelRequest.callingPackage, |
| 5552 | bestComponent.packageName)) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5553 | loge("The calling package is not allowed to access ISD-R."); |
| 5554 | throw new SecurityException( |
| 5555 | "The calling package is not allowed to access ISD-R."); |
| 5556 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 5557 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 5558 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5559 | IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest( |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5560 | CMD_OPEN_CHANNEL, channelRequest, phone, null /* workSource */); |
| 5561 | if (DBG) log("iccOpenLogicalChannelWithPermission: response=" + response); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5562 | return response; |
| 5563 | } finally { |
| 5564 | Binder.restoreCallingIdentity(identity); |
| 5565 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5566 | } |
| 5567 | |
| 5568 | @Override |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5569 | public boolean iccCloseLogicalChannel(@NonNull IccLogicalChannelRequest request) { |
| 5570 | Phone phone = getPhoneFromValidIccLogicalChannelRequest(request, |
| 5571 | /*message=*/"iccCloseLogicalChannel"); |
| 5572 | |
| 5573 | if (DBG) log("iccCloseLogicalChannel: request=" + request); |
| 5574 | |
| 5575 | return iccCloseLogicalChannelWithPermission(phone, request); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5576 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5577 | |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5578 | private boolean iccCloseLogicalChannelWithPermission(Phone phone, |
| 5579 | IccLogicalChannelRequest request) { |
Chen Xu | a8f0dff | 2022-02-12 00:34:15 -0800 | [diff] [blame] | 5580 | // before this feature is enabled, this API should only return false if |
| 5581 | // the operation fails instead of throwing runtime exception for |
| 5582 | // backward-compatibility. |
| 5583 | final boolean shouldThrowExceptionOnFailure = CompatChanges.isChangeEnabled( |
| 5584 | ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE, Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5585 | final long identity = Binder.clearCallingIdentity(); |
| 5586 | try { |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5587 | if (request.channel < 0) { |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 5588 | throw new IllegalArgumentException("request.channel is less than 0"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5589 | } |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 5590 | Object result = sendRequest(CMD_CLOSE_CHANNEL, request.channel, phone, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5591 | null /* workSource */); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 5592 | Boolean success = false; |
| 5593 | if (result instanceof RuntimeException) { |
| 5594 | // if there is an exception returned, throw from the binder thread here. |
Chen Xu | a8f0dff | 2022-02-12 00:34:15 -0800 | [diff] [blame] | 5595 | if (shouldThrowExceptionOnFailure) { |
| 5596 | throw (RuntimeException) result; |
| 5597 | } else { |
| 5598 | return false; |
| 5599 | } |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 5600 | } else if (result instanceof Boolean) { |
| 5601 | success = (Boolean) result; |
| 5602 | } else { |
| 5603 | loge("iccCloseLogicalChannelWithPermission: supported return type " + result); |
| 5604 | } |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5605 | if (DBG) log("iccCloseLogicalChannelWithPermission: success=" + success); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5606 | return success; |
| 5607 | } finally { |
| 5608 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5609 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5610 | } |
| 5611 | |
| 5612 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5613 | public String iccTransmitApduLogicalChannel(int subId, int channel, int cla, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5614 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5615 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5616 | mApp, subId, "iccTransmitApduLogicalChannel"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5617 | if (DBG) { |
| 5618 | log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel |
| 5619 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 5620 | + p3 + " data=" + data); |
| 5621 | } |
| 5622 | return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla, |
| 5623 | command, p1, p2, p3, data); |
| 5624 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5625 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5626 | @Override |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5627 | public String iccTransmitApduLogicalChannelByPort(int slotIndex, int portIndex, int channel, |
| 5628 | int cla, int command, int p1, int p2, int p3, String data) { |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5629 | enforceModifyPermission(); |
| 5630 | if (DBG) { |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5631 | log("iccTransmitApduLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex=" |
| 5632 | + portIndex + " chnl=" + channel + " cla=" + cla + " cmd=" + command + " p1=" |
| 5633 | + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5634 | } |
| 5635 | return iccTransmitApduLogicalChannelWithPermission( |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5636 | getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel, cla, |
| 5637 | command, p1, p2, p3, data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5638 | } |
| 5639 | |
| 5640 | private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla, |
| 5641 | int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5642 | final long identity = Binder.clearCallingIdentity(); |
| 5643 | try { |
Hall Liu | 4fd771b | 2019-05-02 09:16:29 -0700 | [diff] [blame] | 5644 | if (channel <= 0) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5645 | return ""; |
| 5646 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5647 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5648 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5649 | new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone, |
| 5650 | null /* workSource */); |
| 5651 | if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5652 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5653 | // Append the returned status code to the end of the response payload. |
| 5654 | String s = Integer.toHexString( |
| 5655 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 5656 | if (response.payload != null) { |
| 5657 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 5658 | } |
| 5659 | return s; |
| 5660 | } finally { |
| 5661 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 5662 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5663 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5664 | |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5665 | @Override |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 5666 | public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla, |
| 5667 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5668 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5669 | mApp, subId, "iccTransmitApduBasicChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5670 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5671 | if (DBG) { |
| 5672 | log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" |
| 5673 | + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
| 5674 | } |
| 5675 | return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage, |
| 5676 | cla, command, p1, p2, p3, data); |
| 5677 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5678 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5679 | @Override |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5680 | public String iccTransmitApduBasicChannelByPort(int slotIndex, int portIndex, |
| 5681 | 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] | 5682 | enforceModifyPermission(); |
| 5683 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 5684 | if (DBG) { |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5685 | log("iccTransmitApduBasicChannelByPort: slotIndex=" + slotIndex + " portIndex=" |
| 5686 | + portIndex + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" |
| 5687 | + p2 + " p3=" + p3 + " data=" + data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5688 | } |
| 5689 | |
| 5690 | return iccTransmitApduBasicChannelWithPermission( |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5691 | getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), callingPackage, |
| 5692 | cla, command, p1, p2, p3, data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5693 | } |
| 5694 | |
| 5695 | // open APDU basic channel assuming the caller has sufficient permissions |
| 5696 | private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage, |
| 5697 | int cla, int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5698 | final long identity = Binder.clearCallingIdentity(); |
| 5699 | try { |
| 5700 | if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3 |
| 5701 | && TextUtils.equals(ISDR_AID, data)) { |
| 5702 | // Only allows LPA to select ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5703 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 5704 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5705 | if (bestComponent == null |
| 5706 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 5707 | loge("The calling package is not allowed to select ISD-R."); |
| 5708 | throw new SecurityException( |
| 5709 | "The calling package is not allowed to select ISD-R."); |
| 5710 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 5711 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 5712 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5713 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5714 | new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone, |
| 5715 | null /* workSource */); |
| 5716 | if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5717 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5718 | // Append the returned status code to the end of the response payload. |
| 5719 | String s = Integer.toHexString( |
| 5720 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 5721 | if (response.payload != null) { |
| 5722 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 5723 | } |
| 5724 | return s; |
| 5725 | } finally { |
| 5726 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 5727 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5728 | } |
| 5729 | |
| 5730 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5731 | 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] | 5732 | String filePath) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5733 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5734 | mApp, subId, "iccExchangeSimIO"); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5735 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5736 | final long identity = Binder.clearCallingIdentity(); |
| 5737 | try { |
| 5738 | if (DBG) { |
| 5739 | log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " |
| 5740 | + p1 + " " + p2 + " " + p3 + ":" + filePath); |
| 5741 | } |
| 5742 | |
| 5743 | IccIoResult response = |
| 5744 | (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO, |
| 5745 | new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath), |
| 5746 | subId); |
| 5747 | |
| 5748 | if (DBG) { |
| 5749 | log("Exchange SIM_IO [R]" + response); |
| 5750 | } |
| 5751 | |
| 5752 | byte[] result = null; |
| 5753 | int length = 2; |
| 5754 | if (response.payload != null) { |
| 5755 | length = 2 + response.payload.length; |
| 5756 | result = new byte[length]; |
| 5757 | System.arraycopy(response.payload, 0, result, 0, response.payload.length); |
| 5758 | } else { |
| 5759 | result = new byte[length]; |
| 5760 | } |
| 5761 | |
| 5762 | result[length - 1] = (byte) response.sw2; |
| 5763 | result[length - 2] = (byte) response.sw1; |
| 5764 | return result; |
| 5765 | } finally { |
| 5766 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5767 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5768 | } |
| 5769 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5770 | /** |
| 5771 | * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM) |
| 5772 | * on a particular subscription |
| 5773 | */ |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5774 | public String[] getForbiddenPlmns(int subId, int appType, String callingPackage, |
| 5775 | String callingFeatureId) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 5776 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5777 | mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 5778 | return null; |
| 5779 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5780 | |
| 5781 | final long identity = Binder.clearCallingIdentity(); |
| 5782 | try { |
| 5783 | if (appType != TelephonyManager.APPTYPE_USIM |
| 5784 | && appType != TelephonyManager.APPTYPE_SIM) { |
| 5785 | loge("getForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 5786 | return null; |
| 5787 | } |
| 5788 | Object response = sendRequest( |
| 5789 | CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId); |
| 5790 | if (response instanceof String[]) { |
| 5791 | return (String[]) response; |
| 5792 | } |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5793 | // Response is an Exception of some kind |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5794 | // which is signalled to the user as a NULL retval |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5795 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5796 | } finally { |
| 5797 | Binder.restoreCallingIdentity(identity); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5798 | } |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5799 | } |
| 5800 | |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5801 | /** |
| 5802 | * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular |
| 5803 | * subscription. |
| 5804 | * |
| 5805 | * @param subId the id of the subscription. |
| 5806 | * @param appType the uicc app type, must be USIM or SIM. |
| 5807 | * @param fplmns the Forbiden plmns list that needed to be written to the SIM. |
| 5808 | * @param callingPackage the op Package name. |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5809 | * @param callingFeatureId the feature in the package. |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5810 | * @return number of fplmns that is successfully written to the SIM. |
| 5811 | */ |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5812 | public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage, |
| 5813 | String callingFeatureId) { |
Jayachandran C | 5b0d75a | 2021-10-21 22:15:27 -0700 | [diff] [blame] | 5814 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5815 | mApp, subId, "setForbiddenPlmns"); |
| 5816 | |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5817 | if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) { |
| 5818 | loge("setForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 5819 | throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM"); |
| 5820 | } |
| 5821 | if (fplmns == null) { |
| 5822 | throw new IllegalArgumentException("Fplmn List provided is null"); |
| 5823 | } |
| 5824 | for (String fplmn : fplmns) { |
| 5825 | if (!CellIdentity.isValidPlmn(fplmn)) { |
| 5826 | throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn); |
| 5827 | } |
| 5828 | } |
| 5829 | final long identity = Binder.clearCallingIdentity(); |
| 5830 | try { |
| 5831 | Object response = sendRequest( |
| 5832 | CMD_SET_FORBIDDEN_PLMNS, |
| 5833 | new Pair<Integer, List<String>>(new Integer(appType), fplmns), |
| 5834 | subId); |
| 5835 | return (int) response; |
| 5836 | } finally { |
| 5837 | Binder.restoreCallingIdentity(identity); |
| 5838 | } |
| 5839 | } |
| 5840 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5841 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5842 | public String sendEnvelopeWithStatus(int subId, String content) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5843 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5844 | mApp, subId, "sendEnvelopeWithStatus"); |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5845 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5846 | final long identity = Binder.clearCallingIdentity(); |
| 5847 | try { |
| 5848 | IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId); |
| 5849 | if (response.payload == null) { |
| 5850 | return ""; |
| 5851 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5852 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5853 | // Append the returned status code to the end of the response payload. |
| 5854 | String s = Integer.toHexString( |
| 5855 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 5856 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 5857 | return s; |
| 5858 | } finally { |
| 5859 | Binder.restoreCallingIdentity(identity); |
| 5860 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5861 | } |
| 5862 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5863 | /** |
| 5864 | * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 5865 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 5866 | * |
| 5867 | * @param itemID the ID of the item to read |
| 5868 | * @return the NV item as a String, or null on error. |
| 5869 | */ |
| 5870 | @Override |
| 5871 | public String nvReadItem(int itemID) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5872 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5873 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5874 | mApp, getDefaultSubscription(), "nvReadItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5875 | |
| 5876 | final long identity = Binder.clearCallingIdentity(); |
| 5877 | try { |
| 5878 | if (DBG) log("nvReadItem: item " + itemID); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5879 | String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5880 | if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"'); |
| 5881 | return value; |
| 5882 | } finally { |
| 5883 | Binder.restoreCallingIdentity(identity); |
| 5884 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5885 | } |
| 5886 | |
| 5887 | /** |
| 5888 | * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 5889 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 5890 | * |
| 5891 | * @param itemID the ID of the item to read |
| 5892 | * @param itemValue the value to write, as a String |
| 5893 | * @return true on success; false on any failure |
| 5894 | */ |
| 5895 | @Override |
| 5896 | public boolean nvWriteItem(int itemID, String itemValue) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5897 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5898 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5899 | mApp, getDefaultSubscription(), "nvWriteItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5900 | |
| 5901 | final long identity = Binder.clearCallingIdentity(); |
| 5902 | try { |
| 5903 | if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"'); |
| 5904 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5905 | new Pair<Integer, String>(itemID, itemValue), workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5906 | if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail")); |
| 5907 | return success; |
| 5908 | } finally { |
| 5909 | Binder.restoreCallingIdentity(identity); |
| 5910 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5911 | } |
| 5912 | |
| 5913 | /** |
| 5914 | * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage. |
| 5915 | * Used for device configuration by some CDMA operators. |
| 5916 | * |
| 5917 | * @param preferredRoamingList byte array containing the new PRL |
| 5918 | * @return true on success; false on any failure |
| 5919 | */ |
| 5920 | @Override |
| 5921 | public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5922 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5923 | mApp, getDefaultSubscription(), "nvWriteCdmaPrl"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5924 | |
| 5925 | final long identity = Binder.clearCallingIdentity(); |
| 5926 | try { |
| 5927 | if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList)); |
| 5928 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList); |
| 5929 | if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail")); |
| 5930 | return success; |
| 5931 | } finally { |
| 5932 | Binder.restoreCallingIdentity(identity); |
| 5933 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5934 | } |
| 5935 | |
| 5936 | /** |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5937 | * 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] | 5938 | * Used for device configuration by some CDMA operators. |
| 5939 | * |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5940 | * @param slotIndex - device slot. |
| 5941 | * |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5942 | * @return true on success; false on any failure |
| 5943 | */ |
| 5944 | @Override |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5945 | public boolean resetModemConfig(int slotIndex) { |
| 5946 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5947 | if (phone != null) { |
| 5948 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5949 | mApp, phone.getSubId(), "resetModemConfig"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5950 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5951 | final long identity = Binder.clearCallingIdentity(); |
| 5952 | try { |
| 5953 | Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null); |
| 5954 | if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 5955 | return success; |
| 5956 | } finally { |
| 5957 | Binder.restoreCallingIdentity(identity); |
| 5958 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5959 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5960 | return false; |
| 5961 | } |
| 5962 | |
| 5963 | /** |
| 5964 | * Generate a radio modem reset. Used for device configuration by some CDMA operators. |
| 5965 | * |
| 5966 | * @param slotIndex - device slot. |
| 5967 | * |
| 5968 | * @return true on success; false on any failure |
| 5969 | */ |
| 5970 | @Override |
| 5971 | public boolean rebootModem(int slotIndex) { |
| 5972 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5973 | if (phone != null) { |
| 5974 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5975 | mApp, phone.getSubId(), "rebootModem"); |
| 5976 | |
| 5977 | final long identity = Binder.clearCallingIdentity(); |
| 5978 | try { |
| 5979 | Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null); |
| 5980 | if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail")); |
| 5981 | return success; |
| 5982 | } finally { |
| 5983 | Binder.restoreCallingIdentity(identity); |
| 5984 | } |
| 5985 | } |
| 5986 | return false; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5987 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5988 | |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5989 | /** |
Grace Jia | aa2eb6b | 2020-01-09 16:26:08 -0800 | [diff] [blame] | 5990 | * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and |
| 5991 | * {@link #disableIms(int)}. |
| 5992 | * @param slotIndex device slot. |
| 5993 | */ |
| 5994 | public void resetIms(int slotIndex) { |
| 5995 | enforceModifyPermission(); |
| 5996 | |
| 5997 | final long identity = Binder.clearCallingIdentity(); |
| 5998 | try { |
| 5999 | if (mImsResolver == null) { |
| 6000 | // may happen if the does not support IMS. |
| 6001 | return; |
| 6002 | } |
Hyunho | a17ac7c | 2022-08-30 12:03:04 +0000 | [diff] [blame] | 6003 | mImsResolver.resetIms(slotIndex); |
Grace Jia | aa2eb6b | 2020-01-09 16:26:08 -0800 | [diff] [blame] | 6004 | } finally { |
| 6005 | Binder.restoreCallingIdentity(identity); |
| 6006 | } |
| 6007 | } |
| 6008 | |
| 6009 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6010 | * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability |
| 6011 | * status updates, if not already enabled. |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 6012 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6013 | public void enableIms(int slotId) { |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 6014 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6015 | |
| 6016 | final long identity = Binder.clearCallingIdentity(); |
| 6017 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6018 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6019 | // may happen if the device does not support IMS. |
| 6020 | return; |
| 6021 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6022 | mImsResolver.enableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6023 | } finally { |
| 6024 | Binder.restoreCallingIdentity(identity); |
| 6025 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 6026 | } |
| 6027 | |
| 6028 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6029 | * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature |
| 6030 | * status updates to disabled. |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 6031 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6032 | public void disableIms(int slotId) { |
| 6033 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6034 | |
| 6035 | final long identity = Binder.clearCallingIdentity(); |
| 6036 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6037 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6038 | // may happen if the device does not support IMS. |
| 6039 | return; |
| 6040 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6041 | mImsResolver.disableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6042 | } finally { |
| 6043 | Binder.restoreCallingIdentity(identity); |
| 6044 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6045 | } |
| 6046 | |
| 6047 | /** |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 6048 | * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback |
| 6049 | * callback. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6050 | */ |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 6051 | @Override |
Brad Ebinger | f6aca00 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 6052 | public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) { |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 6053 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6054 | |
| 6055 | final long identity = Binder.clearCallingIdentity(); |
| 6056 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6057 | if (mImsResolver == null) { |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 6058 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 6059 | "Device does not support IMS"); |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6060 | } |
Brad Ebinger | f6aca00 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 6061 | mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6062 | } finally { |
| 6063 | Binder.restoreCallingIdentity(identity); |
| 6064 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 6065 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 6066 | /** |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 6067 | * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature. |
| 6068 | */ |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 6069 | @Override |
| 6070 | public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) { |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 6071 | enforceModifyPermission(); |
| 6072 | |
| 6073 | final long identity = Binder.clearCallingIdentity(); |
| 6074 | try { |
| 6075 | if (mImsResolver == null) return; |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 6076 | mImsResolver.unregisterImsFeatureCallback(callback); |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 6077 | } finally { |
| 6078 | Binder.restoreCallingIdentity(identity); |
| 6079 | } |
| 6080 | } |
| 6081 | |
| 6082 | /** |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 6083 | * Returns the {@link IImsRegistration} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6084 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 6085 | */ |
| 6086 | public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException { |
| 6087 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6088 | |
| 6089 | final long identity = Binder.clearCallingIdentity(); |
| 6090 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6091 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6092 | // may happen if the device does not support IMS. |
| 6093 | return null; |
| 6094 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6095 | return mImsResolver.getImsRegistration(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6096 | } finally { |
| 6097 | Binder.restoreCallingIdentity(identity); |
| 6098 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 6099 | } |
| 6100 | |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6101 | /** |
| 6102 | * Returns the {@link IImsConfig} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6103 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6104 | */ |
| 6105 | public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException { |
| 6106 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6107 | |
| 6108 | final long identity = Binder.clearCallingIdentity(); |
| 6109 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6110 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6111 | // may happen if the device does not support IMS. |
| 6112 | return null; |
| 6113 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6114 | return mImsResolver.getImsConfig(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6115 | } finally { |
| 6116 | Binder.restoreCallingIdentity(identity); |
| 6117 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6118 | } |
| 6119 | |
Brad Ebinger | 884c07b | 2018-02-15 16:17:40 -0800 | [diff] [blame] | 6120 | /** |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6121 | * Sets the ImsService Package Name that Telephony will bind to. |
| 6122 | * |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6123 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 6124 | * @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] | 6125 | * ImsService is the device default ImsService. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6126 | * @param featureTypes An integer array of feature types associated with a packageName. |
| 6127 | * @param packageName The name of the package that the current configuration will be replaced |
| 6128 | * with. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6129 | * @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] | 6130 | */ |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6131 | public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService, |
| 6132 | int[] featureTypes, String packageName) { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6133 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 6134 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
Jack Yu | 00ece8c | 2022-11-19 22:29:12 -0800 | [diff] [blame] | 6135 | SubscriptionManager.getSubscriptionId(slotIndex), "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 6136 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6137 | final long identity = Binder.clearCallingIdentity(); |
| 6138 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6139 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6140 | // may happen if the device does not support IMS. |
| 6141 | return false; |
| 6142 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6143 | Map<Integer, String> featureConfig = new HashMap<>(); |
| 6144 | for (int featureType : featureTypes) { |
| 6145 | featureConfig.put(featureType, packageName); |
| 6146 | } |
| 6147 | return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService, |
| 6148 | featureConfig); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6149 | } finally { |
| 6150 | Binder.restoreCallingIdentity(identity); |
| 6151 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6152 | } |
| 6153 | |
| 6154 | /** |
Brad Ebinger | 999d330 | 2020-11-25 14:31:39 -0800 | [diff] [blame] | 6155 | * Clears any carrier ImsService overrides for the slot index specified that were previously |
| 6156 | * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}. |
| 6157 | * |
| 6158 | * This should only be used for testing. |
| 6159 | * |
| 6160 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 6161 | * @return true if clearing the carrier ImsService override succeeded or false if it did not. |
| 6162 | */ |
| 6163 | @Override |
| 6164 | public boolean clearCarrierImsServiceOverride(int slotIndex) { |
Brad Ebinger | 999d330 | 2020-11-25 14:31:39 -0800 | [diff] [blame] | 6165 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 6166 | "clearCarrierImsServiceOverride"); |
| 6167 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
Jack Yu | 00ece8c | 2022-11-19 22:29:12 -0800 | [diff] [blame] | 6168 | SubscriptionManager.getSubscriptionId(slotIndex), "clearCarrierImsServiceOverride"); |
Brad Ebinger | 999d330 | 2020-11-25 14:31:39 -0800 | [diff] [blame] | 6169 | |
| 6170 | final long identity = Binder.clearCallingIdentity(); |
| 6171 | try { |
| 6172 | if (mImsResolver == null) { |
| 6173 | // may happen if the device does not support IMS. |
| 6174 | return false; |
| 6175 | } |
| 6176 | return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex); |
| 6177 | } finally { |
| 6178 | Binder.restoreCallingIdentity(identity); |
| 6179 | } |
| 6180 | } |
| 6181 | |
| 6182 | /** |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6183 | * Return the package name of the currently bound ImsService. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6184 | * |
| 6185 | * @param slotId The slot that the ImsService is associated with. |
| 6186 | * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is |
| 6187 | * the device default. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6188 | * @param featureType The feature associated with the queried configuration. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6189 | * @return the package name of the ImsService configuration. |
| 6190 | */ |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6191 | public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService, |
| 6192 | @ImsFeature.FeatureType int featureType) { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6193 | TelephonyPermissions |
Jack Yu | 00ece8c | 2022-11-19 22:29:12 -0800 | [diff] [blame] | 6194 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(mApp, |
| 6195 | SubscriptionManager.getSubscriptionId(slotId), "getBoundImsServicePackage"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 6196 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6197 | final long identity = Binder.clearCallingIdentity(); |
| 6198 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6199 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6200 | // may happen if the device does not support IMS. |
| 6201 | return ""; |
| 6202 | } |
Brad Ebinger | a80c331 | 2019-12-02 10:59:39 -0800 | [diff] [blame] | 6203 | // TODO: change API to query RCS separately. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6204 | return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService, |
| 6205 | featureType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6206 | } finally { |
| 6207 | Binder.restoreCallingIdentity(identity); |
| 6208 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6209 | } |
| 6210 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6211 | /** |
| 6212 | * Get the MmTelFeature state associated with the requested subscription id. |
| 6213 | * @param subId The subscription that the MmTelFeature is associated with. |
| 6214 | * @param callback A callback with an integer containing the |
| 6215 | * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature. |
| 6216 | */ |
| 6217 | @Override |
| 6218 | public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) { |
| 6219 | enforceReadPrivilegedPermission("getImsMmTelFeatureState"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 6220 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 6221 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 6222 | "IMS not available on device."); |
| 6223 | } |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6224 | final long token = Binder.clearCallingIdentity(); |
| 6225 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 6226 | int slotId = getSlotIndex(subId); |
| 6227 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 6228 | Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '" |
| 6229 | + subId + "'"); |
| 6230 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 6231 | } |
| 6232 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 6233 | ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> { |
| 6234 | try { |
| 6235 | callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger); |
| 6236 | } catch (RemoteException e) { |
| 6237 | Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. " |
| 6238 | + "Ignore"); |
| 6239 | } |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6240 | }); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 6241 | } catch (ImsException e) { |
| 6242 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6243 | } finally { |
| 6244 | Binder.restoreCallingIdentity(token); |
| 6245 | } |
| 6246 | } |
| 6247 | |
Daniel Bright | bb5840b | 2021-01-12 15:48:18 -0800 | [diff] [blame] | 6248 | /** |
| 6249 | * Sets the ims registration state on all valid {@link Phone}s. |
| 6250 | */ |
| 6251 | public void setImsRegistrationState(final boolean registered) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 6252 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6253 | |
| 6254 | final long identity = Binder.clearCallingIdentity(); |
| 6255 | try { |
Daniel Bright | bb5840b | 2021-01-12 15:48:18 -0800 | [diff] [blame] | 6256 | // NOTE: Before S, this method only set the default phone. |
| 6257 | for (final Phone phone : PhoneFactory.getPhones()) { |
| 6258 | if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) { |
| 6259 | phone.setImsRegistrationState(registered); |
| 6260 | } |
| 6261 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6262 | } finally { |
| 6263 | Binder.restoreCallingIdentity(identity); |
| 6264 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 6265 | } |
| 6266 | |
| 6267 | /** |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 6268 | * Set the network selection mode to automatic. |
| 6269 | * |
| 6270 | */ |
| 6271 | @Override |
| 6272 | public void setNetworkSelectionModeAutomatic(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6273 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6274 | mApp, subId, "setNetworkSelectionModeAutomatic"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6275 | |
| 6276 | final long identity = Binder.clearCallingIdentity(); |
| 6277 | try { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 6278 | if (!isActiveSubscription(subId)) { |
| 6279 | return; |
| 6280 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6281 | if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId); |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 6282 | sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId, |
| 6283 | SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6284 | } finally { |
| 6285 | Binder.restoreCallingIdentity(identity); |
| 6286 | } |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 6287 | } |
| 6288 | |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 6289 | /** |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6290 | * Ask the radio to connect to the input network and change selection mode to manual. |
| 6291 | * |
| 6292 | * @param subId the id of the subscription. |
| 6293 | * @param operatorInfo the operator information, included the PLMN, long name and short name of |
| 6294 | * the operator to attach to. |
| 6295 | * @param persistSelection whether the selection will persist until reboot. If true, only allows |
| 6296 | * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume |
| 6297 | * normal network selection next time. |
| 6298 | * @return {@code true} on success; {@code true} on any failure. |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6299 | */ |
| 6300 | @Override |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6301 | public boolean setNetworkSelectionModeManual( |
| 6302 | int subId, OperatorInfo operatorInfo, boolean persistSelection) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6303 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6304 | mApp, subId, "setNetworkSelectionModeManual"); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 6305 | |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 6306 | final long identity = Binder.clearCallingIdentity(); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 6307 | if (!isActiveSubscription(subId)) { |
| 6308 | return false; |
| 6309 | } |
| 6310 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6311 | try { |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6312 | ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6313 | persistSelection); |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6314 | if (DBG) { |
| 6315 | log("setNetworkSelectionModeManual: subId: " + subId |
| 6316 | + " operator: " + operatorInfo); |
| 6317 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6318 | return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId); |
| 6319 | } finally { |
| 6320 | Binder.restoreCallingIdentity(identity); |
| 6321 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6322 | } |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6323 | /** |
| 6324 | * Get the manual network selection |
| 6325 | * |
| 6326 | * @param subId the id of the subscription. |
| 6327 | * |
| 6328 | * @return the previously saved user selected PLMN |
| 6329 | */ |
| 6330 | @Override |
| 6331 | public String getManualNetworkSelectionPlmn(int subId) { |
| 6332 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 6333 | .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6334 | mApp, subId, "getManualNetworkSelectionPlmn"); |
| 6335 | |
| 6336 | final long identity = Binder.clearCallingIdentity(); |
| 6337 | try { |
| 6338 | if (!isActiveSubscription(subId)) { |
shilu | fa1c259 | 2020-03-10 10:59:43 -0700 | [diff] [blame] | 6339 | throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6340 | } |
| 6341 | |
| 6342 | final Phone phone = getPhone(subId); |
| 6343 | if (phone == null) { |
shilu | fa1c259 | 2020-03-10 10:59:43 -0700 | [diff] [blame] | 6344 | throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6345 | } |
| 6346 | OperatorInfo networkSelection = phone.getSavedNetworkSelection(); |
| 6347 | return TextUtils.isEmpty(networkSelection.getOperatorNumeric()) |
| 6348 | ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric(); |
| 6349 | } finally { |
| 6350 | Binder.restoreCallingIdentity(identity); |
| 6351 | } |
| 6352 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6353 | |
| 6354 | /** |
| 6355 | * Scans for available networks. |
| 6356 | */ |
| 6357 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6358 | public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage, |
| 6359 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6360 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6361 | mApp, subId, "getCellNetworkScanResults"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6362 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 6363 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 6364 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 6365 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6366 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6367 | .setCallingPid(Binder.getCallingPid()) |
| 6368 | .setCallingUid(Binder.getCallingUid()) |
| 6369 | .setMethod("getCellNetworkScanResults") |
| 6370 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
Hall Liu | c4a3e42 | 2020-05-26 17:18:03 -0700 | [diff] [blame] | 6371 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 6372 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6373 | .build()); |
| 6374 | switch (locationResult) { |
| 6375 | case DENIED_HARD: |
| 6376 | throw new SecurityException("Not allowed to access scan results -- location"); |
| 6377 | case DENIED_SOFT: |
| 6378 | return null; |
| 6379 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6380 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6381 | long identity = Binder.clearCallingIdentity(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6382 | try { |
| 6383 | if (DBG) log("getCellNetworkScanResults: subId " + subId); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6384 | return (CellNetworkScanResult) sendRequest( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6385 | CMD_PERFORM_NETWORK_SCAN, null, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6386 | } finally { |
| 6387 | Binder.restoreCallingIdentity(identity); |
| 6388 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6389 | } |
| 6390 | |
| 6391 | /** |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6392 | * Get the call forwarding info, given the call forwarding reason. |
| 6393 | */ |
| 6394 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6395 | public void getCallForwarding(int subId, int callForwardingReason, |
| 6396 | ICallForwardingInfoCallback callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6397 | enforceReadPrivilegedPermission("getCallForwarding"); |
| 6398 | long identity = Binder.clearCallingIdentity(); |
| 6399 | try { |
| 6400 | if (DBG) { |
| 6401 | log("getCallForwarding: subId " + subId |
| 6402 | + " callForwardingReason" + callForwardingReason); |
| 6403 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6404 | |
| 6405 | Phone phone = getPhone(subId); |
| 6406 | if (phone == null) { |
| 6407 | try { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 6408 | callback.onError( |
| 6409 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6410 | } catch (RemoteException e) { |
| 6411 | // ignore |
| 6412 | } |
| 6413 | return; |
| 6414 | } |
| 6415 | |
| 6416 | Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create( |
| 6417 | callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() { |
| 6418 | @Override |
| 6419 | public void onCallForwardingInfoAvailable(CallForwardingInfo info) { |
| 6420 | try { |
| 6421 | callback.onCallForwardingInfoAvailable(info); |
| 6422 | } catch (RemoteException e) { |
| 6423 | // ignore |
| 6424 | } |
| 6425 | } |
| 6426 | |
| 6427 | @Override |
| 6428 | public void onError(int error) { |
| 6429 | try { |
| 6430 | callback.onError(error); |
| 6431 | } catch (RemoteException e) { |
| 6432 | // ignore |
| 6433 | } |
| 6434 | } |
| 6435 | }); |
| 6436 | sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6437 | } finally { |
| 6438 | Binder.restoreCallingIdentity(identity); |
| 6439 | } |
| 6440 | } |
| 6441 | |
| 6442 | /** |
| 6443 | * Sets the voice call forwarding info including status (enable/disable), call forwarding |
| 6444 | * reason, the number to forward, and the timeout before the forwarding is attempted. |
| 6445 | */ |
| 6446 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6447 | public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo, |
| 6448 | IIntegerConsumer callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6449 | enforceModifyPermission(); |
| 6450 | long identity = Binder.clearCallingIdentity(); |
| 6451 | try { |
| 6452 | if (DBG) { |
| 6453 | log("setCallForwarding: subId " + subId |
| 6454 | + " callForwardingInfo" + callForwardingInfo); |
| 6455 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6456 | |
| 6457 | Phone phone = getPhone(subId); |
| 6458 | if (phone == null) { |
| 6459 | try { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 6460 | callback.accept( |
| 6461 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6462 | } catch (RemoteException e) { |
| 6463 | // ignore |
| 6464 | } |
| 6465 | return; |
| 6466 | } |
| 6467 | |
| 6468 | Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo, |
| 6469 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 6470 | |
| 6471 | sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6472 | } finally { |
| 6473 | Binder.restoreCallingIdentity(identity); |
| 6474 | } |
| 6475 | } |
| 6476 | |
| 6477 | /** |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6478 | * Get the call waiting status for a subId. |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6479 | */ |
| 6480 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6481 | public void getCallWaitingStatus(int subId, IIntegerConsumer callback) { |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6482 | enforceReadPrivilegedPermission("getCallWaitingStatus"); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6483 | long identity = Binder.clearCallingIdentity(); |
| 6484 | try { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6485 | Phone phone = getPhone(subId); |
| 6486 | if (phone == null) { |
| 6487 | try { |
| 6488 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 6489 | } catch (RemoteException e) { |
| 6490 | // ignore |
| 6491 | } |
| 6492 | return; |
| 6493 | } |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6494 | CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext()); |
| 6495 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 6496 | boolean requireUssd = c.getBoolean( |
| 6497 | CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6498 | |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6499 | if (DBG) log("getCallWaitingStatus: subId " + subId); |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6500 | if (requireUssd) { |
| 6501 | CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(), |
| 6502 | getSubscriptionCarrierId(subId)); |
| 6503 | String newUssdCommand = ""; |
| 6504 | try { |
| 6505 | newUssdCommand = carrierXmlParser.getFeature( |
| 6506 | CarrierXmlParser.FEATURE_CALL_WAITING) |
| 6507 | .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null); |
| 6508 | } catch (NullPointerException e) { |
| 6509 | loge("Failed to generate USSD number" + e); |
| 6510 | } |
| 6511 | ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver( |
| 6512 | mMainThreadHandler, callback, carrierXmlParser, |
| 6513 | CarrierXmlParser.SsEntry.SSAction.QUERY); |
| 6514 | final String ussdCommand = newUssdCommand; |
| 6515 | Executors.newSingleThreadExecutor().execute(() -> { |
| 6516 | handleUssdRequest(subId, ussdCommand, wrappedCallback); |
| 6517 | }); |
| 6518 | } else { |
| 6519 | Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException( |
| 6520 | callback::accept); |
| 6521 | sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null); |
| 6522 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6523 | } finally { |
| 6524 | Binder.restoreCallingIdentity(identity); |
| 6525 | } |
| 6526 | } |
| 6527 | |
| 6528 | /** |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6529 | * Sets whether call waiting is enabled for a given subId. |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6530 | */ |
| 6531 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6532 | public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6533 | enforceModifyPermission(); |
| 6534 | long identity = Binder.clearCallingIdentity(); |
| 6535 | try { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6536 | if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable); |
| 6537 | |
| 6538 | Phone phone = getPhone(subId); |
| 6539 | if (phone == null) { |
| 6540 | try { |
| 6541 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 6542 | } catch (RemoteException e) { |
| 6543 | // ignore |
| 6544 | } |
| 6545 | return; |
| 6546 | } |
| 6547 | |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6548 | CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext()); |
| 6549 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 6550 | boolean requireUssd = c.getBoolean( |
| 6551 | CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6552 | |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6553 | if (DBG) log("getCallWaitingStatus: subId " + subId); |
| 6554 | if (requireUssd) { |
| 6555 | CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(), |
| 6556 | getSubscriptionCarrierId(subId)); |
| 6557 | CarrierXmlParser.SsEntry.SSAction ssAction = |
| 6558 | enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE |
| 6559 | : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE; |
| 6560 | String newUssdCommand = ""; |
| 6561 | try { |
| 6562 | newUssdCommand = carrierXmlParser.getFeature( |
| 6563 | CarrierXmlParser.FEATURE_CALL_WAITING) |
| 6564 | .makeCommand(ssAction, null); |
| 6565 | } catch (NullPointerException e) { |
| 6566 | loge("Failed to generate USSD number" + e); |
| 6567 | } |
| 6568 | ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver( |
| 6569 | mMainThreadHandler, callback, carrierXmlParser, ssAction); |
| 6570 | final String ussdCommand = newUssdCommand; |
| 6571 | Executors.newSingleThreadExecutor().execute(() -> { |
| 6572 | handleUssdRequest(subId, ussdCommand, wrappedCallback); |
| 6573 | }); |
| 6574 | } else { |
| 6575 | Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable, |
| 6576 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 6577 | |
| 6578 | sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null); |
| 6579 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6580 | } finally { |
| 6581 | Binder.restoreCallingIdentity(identity); |
| 6582 | } |
| 6583 | } |
| 6584 | |
| 6585 | /** |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 6586 | * Starts a new network scan and returns the id of this scan. |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6587 | * |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 6588 | * @param subId id of the subscription |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 6589 | * @param renounceFineLocationAccess Set this to true if the caller would not like to receive |
| 6590 | * location related information which will be sent if the caller already possess |
| 6591 | * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 6592 | * @param request contains the radio access networks with bands/channels to scan |
| 6593 | * @param messenger callback messenger for scan results or errors |
| 6594 | * @param binder for the purpose of auto clean when the user thread crashes |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6595 | * @return the id of the requested scan which can be used to stop the scan. |
| 6596 | */ |
| 6597 | @Override |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 6598 | public int requestNetworkScan(int subId, boolean renounceFineLocationAccess, |
| 6599 | NetworkScanRequest request, Messenger messenger, |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6600 | IBinder binder, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6601 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6602 | mApp, subId, "requestNetworkScan"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6603 | LocationAccessPolicy.LocationPermissionResult locationResult = |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 6604 | LocationAccessPolicy.LocationPermissionResult.DENIED_HARD; |
| 6605 | if (!renounceFineLocationAccess) { |
| 6606 | locationResult = LocationAccessPolicy.checkLocationPermission(mApp, |
| 6607 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 6608 | .setCallingPackage(callingPackage) |
| 6609 | .setCallingFeatureId(callingFeatureId) |
| 6610 | .setCallingPid(Binder.getCallingPid()) |
| 6611 | .setCallingUid(Binder.getCallingUid()) |
| 6612 | .setMethod("requestNetworkScan") |
| 6613 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 6614 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 6615 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 6616 | .build()); |
| 6617 | } |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6618 | if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) { |
Nathan Harold | 1c11dba | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 6619 | SecurityException e = checkNetworkRequestForSanitizedLocationAccess( |
| 6620 | request, subId, callingPackage); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6621 | if (e != null) { |
| 6622 | if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) { |
| 6623 | throw e; |
| 6624 | } else { |
Hall Liu | 0e5abaf | 2019-04-04 01:25:30 -0700 | [diff] [blame] | 6625 | loge(e.getMessage()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6626 | return TelephonyScanManager.INVALID_SCAN_ID; |
| 6627 | } |
| 6628 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6629 | } |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6630 | int callingUid = Binder.getCallingUid(); |
| 6631 | int callingPid = Binder.getCallingPid(); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 6632 | final long identity = Binder.clearCallingIdentity(); |
| 6633 | try { |
| 6634 | return mNetworkScanRequestTracker.startNetworkScan( |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 6635 | renounceFineLocationAccess, request, messenger, binder, getPhone(subId), |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6636 | callingUid, callingPid, callingPackage); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 6637 | } finally { |
| 6638 | Binder.restoreCallingIdentity(identity); |
| 6639 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6640 | } |
| 6641 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6642 | private SecurityException checkNetworkRequestForSanitizedLocationAccess( |
Nathan Harold | 1c11dba | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 6643 | NetworkScanRequest request, int subId, String callingPackage) { |
Rambo Wang | 3dee30a | 2022-10-20 16:52:29 +0000 | [diff] [blame] | 6644 | boolean hasCarrierPriv; |
| 6645 | final long identity = Binder.clearCallingIdentity(); |
| 6646 | try { |
| 6647 | hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage) |
| 6648 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 6649 | } finally { |
| 6650 | Binder.restoreCallingIdentity(identity); |
| 6651 | } |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 6652 | boolean hasNetworkScanPermission = |
| 6653 | mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN) |
| 6654 | == PERMISSION_GRANTED; |
| 6655 | |
| 6656 | if (!hasCarrierPriv && !hasNetworkScanPermission) { |
| 6657 | return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed" |
| 6658 | + " for network scans without location access."); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6659 | } |
| 6660 | |
| 6661 | if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) { |
| 6662 | for (RadioAccessSpecifier ras : request.getSpecifiers()) { |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6663 | if (ras.getChannels() != null && ras.getChannels().length > 0) { |
| 6664 | return new SecurityException("Specific channels must not be" |
| 6665 | + " scanned without location access."); |
| 6666 | } |
| 6667 | } |
| 6668 | } |
| 6669 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6670 | return null; |
| 6671 | } |
| 6672 | |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6673 | /** |
| 6674 | * Stops an existing network scan with the given scanId. |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 6675 | * |
| 6676 | * @param subId id of the subscription |
| 6677 | * @param scanId id of the scan that needs to be stopped |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6678 | */ |
| 6679 | @Override |
| 6680 | public void stopNetworkScan(int subId, int scanId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6681 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6682 | mApp, subId, "stopNetworkScan"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6683 | |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6684 | int callingUid = Binder.getCallingUid(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6685 | final long identity = Binder.clearCallingIdentity(); |
| 6686 | try { |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6687 | mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6688 | } finally { |
| 6689 | Binder.restoreCallingIdentity(identity); |
| 6690 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6691 | } |
| 6692 | |
| 6693 | /** |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6694 | * Get the allowed network types bitmask. |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 6695 | * |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6696 | * @return the allowed network types bitmask, defined in RILConstants.java. |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 6697 | */ |
| 6698 | @Override |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6699 | public int getAllowedNetworkTypesBitmask(int subId) { |
Pengquan Meng | a4009cb | 2018-12-20 11:00:24 -0800 | [diff] [blame] | 6700 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 6701 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6702 | mApp, subId, "getAllowedNetworkTypesBitmask"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6703 | |
| 6704 | final long identity = Binder.clearCallingIdentity(); |
| 6705 | try { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6706 | if (DBG) log("getAllowedNetworkTypesBitmask"); |
| 6707 | int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId); |
| 6708 | int networkTypesBitmask = (result != null ? result[0] : -1); |
| 6709 | if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask); |
| 6710 | return networkTypesBitmask; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6711 | } finally { |
| 6712 | Binder.restoreCallingIdentity(identity); |
| 6713 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 6714 | } |
| 6715 | |
| 6716 | /** |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6717 | * Get the allowed network types for certain reason. |
| 6718 | * |
| 6719 | * @param subId the id of the subscription. |
| 6720 | * @param reason the reason the allowed network type change is taking place |
| 6721 | * @return the allowed network types. |
| 6722 | */ |
| 6723 | @Override |
| 6724 | public long getAllowedNetworkTypesForReason(int subId, |
| 6725 | @TelephonyManager.AllowedNetworkTypesReason int reason) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 6726 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 6727 | mApp, subId, "getAllowedNetworkTypesForReason"); |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6728 | final long identity = Binder.clearCallingIdentity(); |
| 6729 | try { |
| 6730 | return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason); |
| 6731 | } finally { |
| 6732 | Binder.restoreCallingIdentity(identity); |
| 6733 | } |
| 6734 | } |
| 6735 | |
| 6736 | /** |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6737 | * Enable/Disable E-UTRA-NR Dual Connectivity |
| 6738 | * @param subId subscription id of the sim card |
| 6739 | * @param nrDualConnectivityState expected NR dual connectivity state |
| 6740 | * This can be passed following states |
| 6741 | * <ol> |
| 6742 | * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE} |
| 6743 | * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE} |
| 6744 | * <li>Disable NR dual connectivity and force secondary cell to be released |
| 6745 | * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE} |
| 6746 | * </ol> |
| 6747 | * @return operation result. |
| 6748 | */ |
| 6749 | @Override |
| 6750 | public int setNrDualConnectivityState(int subId, |
| 6751 | @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) { |
| 6752 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6753 | mApp, subId, "enableNRDualConnectivity"); |
Sooraj Sasindran | 0e4e00a | 2021-03-16 18:02:32 -0700 | [diff] [blame] | 6754 | if (!isRadioInterfaceCapabilitySupported( |
Sooraj Sasindran | dfd595b | 2021-03-11 17:38:13 -0800 | [diff] [blame] | 6755 | TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) { |
| 6756 | return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED; |
| 6757 | } |
| 6758 | |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6759 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 6760 | final long identity = Binder.clearCallingIdentity(); |
| 6761 | try { |
| 6762 | int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY, |
| 6763 | nrDualConnectivityState, subId, |
| 6764 | workSource); |
| 6765 | if (DBG) log("enableNRDualConnectivity result: " + result); |
| 6766 | return result; |
| 6767 | } finally { |
| 6768 | Binder.restoreCallingIdentity(identity); |
| 6769 | } |
| 6770 | } |
| 6771 | |
| 6772 | /** |
| 6773 | * Is E-UTRA-NR Dual Connectivity enabled |
| 6774 | * @return true if dual connectivity is enabled else false |
| 6775 | */ |
| 6776 | @Override |
| 6777 | public boolean isNrDualConnectivityEnabled(int subId) { |
| 6778 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 6779 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6780 | mApp, subId, "isNRDualConnectivityEnabled"); |
Sooraj Sasindran | 0e4e00a | 2021-03-16 18:02:32 -0700 | [diff] [blame] | 6781 | if (!isRadioInterfaceCapabilitySupported( |
Sooraj Sasindran | dfd595b | 2021-03-11 17:38:13 -0800 | [diff] [blame] | 6782 | TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) { |
| 6783 | return false; |
| 6784 | } |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6785 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 6786 | final long identity = Binder.clearCallingIdentity(); |
| 6787 | try { |
| 6788 | boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED, |
| 6789 | null, subId, workSource); |
| 6790 | if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled); |
| 6791 | return isEnabled; |
| 6792 | } finally { |
| 6793 | Binder.restoreCallingIdentity(identity); |
| 6794 | } |
| 6795 | } |
| 6796 | |
| 6797 | /** |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6798 | * Set the allowed network types of the device and |
| 6799 | * provide the reason triggering the allowed network change. |
| 6800 | * |
| 6801 | * @param subId the id of the subscription. |
| 6802 | * @param reason the reason the allowed network type change is taking place |
| 6803 | * @param allowedNetworkTypes the allowed network types. |
| 6804 | * @return true on success; false on any failure. |
| 6805 | */ |
| 6806 | @Override |
| 6807 | public boolean setAllowedNetworkTypesForReason(int subId, |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6808 | @TelephonyManager.AllowedNetworkTypesReason int reason, |
| 6809 | @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) { |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6810 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6811 | mApp, subId, "setAllowedNetworkTypesForReason"); |
Gil Cukierman | 1d3d375 | 2022-10-03 21:31:33 +0000 | [diff] [blame] | 6812 | // If the caller only has carrier privileges, then they should not be able to override |
| 6813 | // any network types which were set for security reasons. |
| 6814 | if (mApp.checkCallingOrSelfPermission(Manifest.permission.MODIFY_PHONE_STATE) |
| 6815 | != PERMISSION_GRANTED |
| 6816 | && (reason == TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_ENABLE_2G |
| 6817 | || reason == TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER_RESTRICTIONS)) { |
| 6818 | throw new SecurityException( |
| 6819 | "setAllowedNetworkTypesForReason cannot be called with carrier privileges for" |
| 6820 | + " reason " |
Jack Yu | 5b49433 | 2023-01-23 18:18:04 +0000 | [diff] [blame^] | 6821 | + reason); |
Gil Cukierman | 1d3d375 | 2022-10-03 21:31:33 +0000 | [diff] [blame] | 6822 | } |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6823 | if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) { |
Jack Yu | 5b49433 | 2023-01-23 18:18:04 +0000 | [diff] [blame^] | 6824 | loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason); |
SongFerngWang | 7ffc273 | 2021-04-15 19:46:33 +0800 | [diff] [blame] | 6825 | return false; |
| 6826 | } |
| 6827 | if (!SubscriptionManager.isUsableSubscriptionId(subId)) { |
| 6828 | loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId); |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6829 | return false; |
| 6830 | } |
| 6831 | |
Jack Yu | 5b49433 | 2023-01-23 18:18:04 +0000 | [diff] [blame^] | 6832 | log("setAllowedNetworkTypesForReason: subId=" + subId + ", reason=" + reason + " value: " |
| 6833 | + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes)); |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 6834 | |
Jack Yu | e37dd26 | 2022-12-16 11:53:37 -0800 | [diff] [blame] | 6835 | Phone phone = getPhone(subId); |
| 6836 | if (phone == null) { |
| 6837 | return false; |
| 6838 | } |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 6839 | |
Jack Yu | e37dd26 | 2022-12-16 11:53:37 -0800 | [diff] [blame] | 6840 | if (allowedNetworkTypes == phone.getAllowedNetworkTypes(reason)) { |
Jack Yu | 5b49433 | 2023-01-23 18:18:04 +0000 | [diff] [blame^] | 6841 | log("setAllowedNetworkTypesForReason: " + reason + "does not change value"); |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 6842 | return true; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6843 | } |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 6844 | |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6845 | final long identity = Binder.clearCallingIdentity(); |
| 6846 | try { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6847 | Boolean success = (Boolean) sendRequest( |
| 6848 | CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON, |
| 6849 | new Pair<Integer, Long>(reason, allowedNetworkTypes), subId); |
| 6850 | |
| 6851 | if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail")); |
| 6852 | return success; |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6853 | } finally { |
| 6854 | Binder.restoreCallingIdentity(identity); |
| 6855 | } |
| 6856 | } |
| 6857 | |
| 6858 | /** |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6859 | * Check whether DUN APN is required for tethering with subId. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6860 | * |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6861 | * @param subId the id of the subscription to require tethering. |
Amit Mahajan | fe58cdf | 2017-07-11 12:01:53 -0700 | [diff] [blame] | 6862 | * @return {@code true} if DUN APN is required for tethering. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6863 | * @hide |
| 6864 | */ |
| 6865 | @Override |
SongFerngWang | f08d812 | 2019-11-15 14:58:44 +0800 | [diff] [blame] | 6866 | public boolean isTetheringApnRequiredForSubscriber(int subId) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6867 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6868 | final long identity = Binder.clearCallingIdentity(); |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6869 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6870 | try { |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6871 | if (phone != null) { |
| 6872 | return phone.hasMatchedTetherApnSetting(); |
| 6873 | } else { |
| 6874 | return false; |
| 6875 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6876 | } finally { |
| 6877 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6878 | } |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6879 | } |
| 6880 | |
| 6881 | /** |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6882 | * Get the user enabled state of Mobile Data. |
| 6883 | * |
| 6884 | * TODO: remove and use isUserDataEnabled. |
| 6885 | * This can't be removed now because some vendor codes |
| 6886 | * calls through ITelephony directly while they should |
| 6887 | * use TelephonyManager. |
| 6888 | * |
| 6889 | * @return true on enabled |
| 6890 | */ |
| 6891 | @Override |
| 6892 | public boolean getDataEnabled(int subId) { |
| 6893 | return isUserDataEnabled(subId); |
| 6894 | } |
| 6895 | |
| 6896 | /** |
| 6897 | * Get whether mobile data is enabled per user setting. |
| 6898 | * |
| 6899 | * There are other factors deciding whether mobile data is actually enabled, but they are |
| 6900 | * not considered here. See {@link #isDataEnabled(int)} for more details. |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6901 | * |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6902 | * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE |
| 6903 | * or carrier privileges. |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 6904 | * |
| 6905 | * @return {@code true} if data is enabled else {@code false} |
| 6906 | */ |
| 6907 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6908 | public boolean isUserDataEnabled(int subId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6909 | String functionName = "isUserDataEnabled"; |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6910 | try { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6911 | try { |
| 6912 | mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE, |
| 6913 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 6914 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6915 | mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName); |
| 6916 | } |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 6917 | } catch (SecurityException e) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6918 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6919 | mApp, subId, functionName); |
| 6920 | |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6921 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6922 | |
| 6923 | final long identity = Binder.clearCallingIdentity(); |
| 6924 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 6925 | int phoneId = SubscriptionManager.getPhoneId(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6926 | if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 6927 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6928 | if (phone != null) { |
| 6929 | boolean retVal = phone.isUserDataEnabled(); |
| 6930 | if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 6931 | return retVal; |
| 6932 | } else { |
| 6933 | if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 6934 | return false; |
| 6935 | } |
| 6936 | } finally { |
| 6937 | Binder.restoreCallingIdentity(identity); |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6938 | } |
| 6939 | } |
| 6940 | |
| 6941 | /** |
Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 6942 | * Checks if the device is capable of mobile data by considering whether whether the |
| 6943 | * user has enabled mobile data, whether the carrier has enabled mobile data, and |
| 6944 | * whether the network policy allows data connections. |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6945 | * |
Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 6946 | * @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] | 6947 | */ |
| 6948 | @Override |
| 6949 | public boolean isDataEnabled(int subId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6950 | String functionName = "isDataEnabled"; |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6951 | try { |
| 6952 | try { |
| 6953 | mApp.enforceCallingOrSelfPermission( |
| 6954 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6955 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 6956 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6957 | try { |
| 6958 | mApp.enforceCallingOrSelfPermission( |
| 6959 | android.Manifest.permission.READ_PHONE_STATE, |
| 6960 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 6961 | } catch (SecurityException e2) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6962 | mApp.enforceCallingOrSelfPermission( |
| 6963 | permission.READ_BASIC_PHONE_STATE, functionName); |
| 6964 | } |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6965 | } |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 6966 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6967 | enforceReadPrivilegedPermission(functionName); |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6968 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6969 | |
| 6970 | final long identity = Binder.clearCallingIdentity(); |
| 6971 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 6972 | int phoneId = SubscriptionManager.getPhoneId(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6973 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6974 | if (phone != null) { |
Sarah Chin | e04784a | 2022-10-31 20:32:34 -0700 | [diff] [blame] | 6975 | boolean retVal = phone.getDataSettingsManager().isDataEnabled(); |
Jack Yu | 4ad64e5 | 2021-12-03 14:23:53 -0800 | [diff] [blame] | 6976 | if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6977 | return retVal; |
| 6978 | } else { |
| 6979 | if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 6980 | return false; |
| 6981 | } |
| 6982 | } finally { |
| 6983 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 6984 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 6985 | } |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6986 | |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6987 | /** |
| 6988 | * Check if data is enabled for a specific reason |
| 6989 | * @param subId Subscription index |
| 6990 | * @param reason the reason the data enable change is taking place |
| 6991 | * @return {@code true} if the overall data is enabled; {@code false} if not. |
| 6992 | */ |
| 6993 | @Override |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6994 | public boolean isDataEnabledForReason(int subId, |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6995 | @TelephonyManager.DataEnabledReason int reason) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6996 | String functionName = "isDataEnabledForReason"; |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6997 | try { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6998 | try { |
| 6999 | mApp.enforceCallingOrSelfPermission( |
| 7000 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 7001 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7002 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7003 | mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE, |
| 7004 | functionName); |
| 7005 | } |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7006 | } catch (SecurityException e) { |
Sooraj Sasindran | 0d909a0 | 2021-11-08 12:01:16 -0800 | [diff] [blame] | 7007 | try { |
| 7008 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7009 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7010 | } catch (SecurityException e2) { |
Sooraj Sasindran | 0d909a0 | 2021-11-08 12:01:16 -0800 | [diff] [blame] | 7011 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7012 | mApp, subId, functionName); |
Sooraj Sasindran | 0d909a0 | 2021-11-08 12:01:16 -0800 | [diff] [blame] | 7013 | } |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7014 | } |
| 7015 | |
| 7016 | |
| 7017 | final long identity = Binder.clearCallingIdentity(); |
| 7018 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 7019 | int phoneId = SubscriptionManager.getPhoneId(subId); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7020 | if (DBG) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7021 | log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7022 | + " reason=" + reason); |
| 7023 | } |
| 7024 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 7025 | if (phone != null) { |
| 7026 | boolean retVal; |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 7027 | retVal = phone.getDataSettingsManager().isDataEnabledForReason(reason); |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7028 | if (DBG) log("isDataEnabledForReason: retVal=" + retVal); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7029 | return retVal; |
| 7030 | } else { |
| 7031 | if (DBG) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7032 | loge("isDataEnabledForReason: no phone subId=" |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7033 | + subId + " retVal=false"); |
| 7034 | } |
| 7035 | return false; |
| 7036 | } |
| 7037 | } finally { |
| 7038 | Binder.restoreCallingIdentity(identity); |
| 7039 | } |
| 7040 | } |
| 7041 | |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 7042 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7043 | public int getCarrierPrivilegeStatus(int subId) { |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7044 | // No permission needed; this only lets the caller inspect their own status. |
| 7045 | return getCarrierPrivilegeStatusForUidWithPermission(subId, Binder.getCallingUid()); |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 7046 | } |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 7047 | |
| 7048 | @Override |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7049 | public int getCarrierPrivilegeStatusForUid(int subId, int uid) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 7050 | enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid"); |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7051 | return getCarrierPrivilegeStatusForUidWithPermission(subId, uid); |
| 7052 | } |
| 7053 | |
| 7054 | private int getCarrierPrivilegeStatusForUidWithPermission(int subId, int uid) { |
| 7055 | Phone phone = getPhone(subId); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7056 | if (phone == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 7057 | loge("getCarrierPrivilegeStatusForUid: Invalid subId"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7058 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 7059 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7060 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7061 | if (cpt == null) { |
| 7062 | loge("getCarrierPrivilegeStatusForUid: No CarrierPrivilegesTracker"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7063 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 7064 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7065 | return cpt.getCarrierPrivilegeStatusForUid(uid); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7066 | } |
| 7067 | |
| 7068 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7069 | public int checkCarrierPrivilegesForPackage(int subId, String pkgName) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 7070 | enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage"); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7071 | if (TextUtils.isEmpty(pkgName)) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 7072 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7073 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7074 | Phone phone = getPhone(subId); |
| 7075 | if (phone == null) { |
| 7076 | loge("checkCarrierPrivilegesForPackage: Invalid subId"); |
| 7077 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 7078 | } |
| 7079 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7080 | if (cpt == null) { |
| 7081 | loge("checkCarrierPrivilegesForPackage: No CarrierPrivilegesTracker"); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 7082 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 7083 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7084 | return cpt.getCarrierPrivilegeStatusForPackage(pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 7085 | } |
| 7086 | |
| 7087 | @Override |
| 7088 | public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) { |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7089 | enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackageAnyPhone"); |
Rambo Wang | e7209ce | 2022-02-23 13:41:02 -0800 | [diff] [blame] | 7090 | return checkCarrierPrivilegesForPackageAnyPhoneWithPermission(pkgName); |
| 7091 | } |
| 7092 | |
| 7093 | private int checkCarrierPrivilegesForPackageAnyPhoneWithPermission(String pkgName) { |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7094 | if (TextUtils.isEmpty(pkgName)) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 7095 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7096 | } |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 7097 | int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7098 | for (int phoneId = 0; phoneId < TelephonyManager.getDefault().getPhoneCount(); phoneId++) { |
| 7099 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 7100 | if (phone == null) { |
| 7101 | continue; |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 7102 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7103 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7104 | if (cpt == null) { |
| 7105 | continue; |
| 7106 | } |
| 7107 | result = cpt.getCarrierPrivilegeStatusForPackage(pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 7108 | if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 7109 | break; |
| 7110 | } |
| 7111 | } |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 7112 | return result; |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 7113 | } |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 7114 | |
| 7115 | @Override |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 7116 | public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 7117 | enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone"); |
Rambo Wang | 8a247eb | 2022-02-08 21:11:18 +0000 | [diff] [blame] | 7118 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 7119 | if (phone == null) { |
| 7120 | return Collections.emptyList(); |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 7121 | } |
Rambo Wang | 8a247eb | 2022-02-08 21:11:18 +0000 | [diff] [blame] | 7122 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7123 | if (cpt == null) { |
| 7124 | return Collections.emptyList(); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 7125 | } |
Rambo Wang | 8a247eb | 2022-02-08 21:11:18 +0000 | [diff] [blame] | 7126 | return cpt.getCarrierPackageNamesForIntent(intent); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 7127 | } |
| 7128 | |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 7129 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7130 | public List<String> getPackagesWithCarrierPrivileges(int phoneId) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 7131 | enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges"); |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7132 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 7133 | if (phone == null) { |
| 7134 | return Collections.emptyList(); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 7135 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7136 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7137 | if (cpt == null) { |
| 7138 | return Collections.emptyList(); |
| 7139 | } |
| 7140 | return new ArrayList<>(cpt.getPackagesWithCarrierPrivileges()); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 7141 | } |
| 7142 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7143 | @Override |
| 7144 | public List<String> getPackagesWithCarrierPrivilegesForAllPhones() { |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 7145 | enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones"); |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7146 | Set<String> privilegedPackages = new ArraySet<>(); |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 7147 | final long identity = Binder.clearCallingIdentity(); |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 7148 | try { |
| 7149 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 7150 | privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i)); |
| 7151 | } |
| 7152 | } finally { |
| 7153 | Binder.restoreCallingIdentity(identity); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7154 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7155 | return new ArrayList<>(privilegedPackages); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7156 | } |
| 7157 | |
Rambo Wang | 6812ffb | 2022-03-15 16:54:17 -0700 | [diff] [blame] | 7158 | @Override |
| 7159 | public @Nullable String getCarrierServicePackageNameForLogicalSlot(int logicalSlotIndex) { |
| 7160 | enforceReadPrivilegedPermission("getCarrierServicePackageNameForLogicalSlot"); |
| 7161 | |
| 7162 | final Phone phone = PhoneFactory.getPhone(logicalSlotIndex); |
| 7163 | if (phone == null) { |
| 7164 | return null; |
| 7165 | } |
| 7166 | final CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7167 | if (cpt == null) { |
| 7168 | return null; |
| 7169 | } |
| 7170 | return cpt.getCarrierServicePackageName(); |
| 7171 | } |
| 7172 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 7173 | private String getIccId(int subId) { |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 7174 | final Phone phone = getPhone(subId); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 7175 | UiccPort port = phone == null ? null : phone.getUiccPort(); |
| 7176 | if (port == null) { |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7177 | return null; |
| 7178 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 7179 | String iccId = port.getIccId(); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7180 | if (TextUtils.isEmpty(iccId)) { |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7181 | return null; |
| 7182 | } |
| 7183 | return iccId; |
| 7184 | } |
| 7185 | |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 7186 | @Override |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 7187 | public void setCallComposerStatus(int subId, int status) { |
| 7188 | enforceModifyPermission(); |
| 7189 | |
| 7190 | final long identity = Binder.clearCallingIdentity(); |
| 7191 | try { |
| 7192 | Phone phone = getPhone(subId); |
| 7193 | if (phone != null) { |
| 7194 | Phone defaultPhone = phone.getImsPhone(); |
| 7195 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 7196 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 7197 | imsPhone.setCallComposerStatus(status); |
Shuo Qian | 284ae75 | 2020-12-22 19:10:14 -0800 | [diff] [blame] | 7198 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| 7199 | .updateImsServiceConfig(); |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 7200 | } |
| 7201 | } |
Shuo Qian | 284ae75 | 2020-12-22 19:10:14 -0800 | [diff] [blame] | 7202 | } catch (ImsException e) { |
| 7203 | throw new ServiceSpecificException(e.getCode()); |
| 7204 | } finally { |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 7205 | Binder.restoreCallingIdentity(identity); |
| 7206 | } |
| 7207 | } |
| 7208 | |
| 7209 | @Override |
| 7210 | public int getCallComposerStatus(int subId) { |
| 7211 | enforceReadPrivilegedPermission("getCallComposerStatus"); |
| 7212 | |
| 7213 | final long identity = Binder.clearCallingIdentity(); |
| 7214 | try { |
| 7215 | Phone phone = getPhone(subId); |
| 7216 | if (phone != null) { |
| 7217 | Phone defaultPhone = phone.getImsPhone(); |
| 7218 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 7219 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 7220 | return imsPhone.getCallComposerStatus(); |
| 7221 | } |
| 7222 | } |
| 7223 | } finally { |
| 7224 | Binder.restoreCallingIdentity(identity); |
| 7225 | } |
| 7226 | return TelephonyManager.CALL_COMPOSER_STATUS_OFF; |
| 7227 | } |
| 7228 | |
| 7229 | @Override |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7230 | public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag, |
| 7231 | String number) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 7232 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7233 | subId, "setLine1NumberForDisplayForSubscriber"); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7234 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7235 | final long identity = Binder.clearCallingIdentity(); |
| 7236 | try { |
| 7237 | final String iccId = getIccId(subId); |
| 7238 | final Phone phone = getPhone(subId); |
| 7239 | if (phone == null) { |
| 7240 | return false; |
| 7241 | } |
| 7242 | final String subscriberId = phone.getSubscriberId(); |
| 7243 | |
| 7244 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 7245 | Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId=" |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7246 | + subscriberId + " to " + number); |
| 7247 | } |
| 7248 | |
| 7249 | if (TextUtils.isEmpty(iccId)) { |
| 7250 | return false; |
| 7251 | } |
| 7252 | |
| 7253 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 7254 | |
| 7255 | final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 7256 | if (alphaTag == null) { |
| 7257 | editor.remove(alphaTagPrefKey); |
| 7258 | } else { |
| 7259 | editor.putString(alphaTagPrefKey, alphaTag); |
| 7260 | } |
| 7261 | |
| 7262 | // Record both the line number and IMSI for this ICCID, since we need to |
| 7263 | // track all merged IMSIs based on line number |
| 7264 | final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 7265 | final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 7266 | if (number == null) { |
| 7267 | editor.remove(numberPrefKey); |
| 7268 | editor.remove(subscriberPrefKey); |
| 7269 | } else { |
| 7270 | editor.putString(numberPrefKey, number); |
| 7271 | editor.putString(subscriberPrefKey, subscriberId); |
| 7272 | } |
| 7273 | |
| 7274 | editor.commit(); |
| 7275 | return true; |
| 7276 | } finally { |
| 7277 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 7278 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7279 | } |
| 7280 | |
| 7281 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7282 | public String getLine1NumberForDisplay(int subId, String callingPackage, |
| 7283 | String callingFeatureId) { |
Makoto Onuki | fee6934 | 2015-06-29 14:44:50 -0700 | [diff] [blame] | 7284 | // This is open to apps with WRITE_SMS. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7285 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7286 | mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) { |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 7287 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission"); |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 7288 | return null; |
| 7289 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7290 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7291 | final long identity = Binder.clearCallingIdentity(); |
| 7292 | try { |
| 7293 | String iccId = getIccId(subId); |
| 7294 | if (iccId != null) { |
| 7295 | String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 7296 | if (DBG_MERGE) { |
| 7297 | log("getLine1NumberForDisplay returning " |
| 7298 | + mTelephonySharedPreferences.getString(numberPrefKey, null)); |
| 7299 | } |
| 7300 | return mTelephonySharedPreferences.getString(numberPrefKey, null); |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 7301 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7302 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null"); |
| 7303 | return null; |
| 7304 | } finally { |
| 7305 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7306 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7307 | } |
| 7308 | |
| 7309 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7310 | public String getLine1AlphaTagForDisplay(int subId, String callingPackage, |
| 7311 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7312 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7313 | mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 7314 | return null; |
| 7315 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7316 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7317 | final long identity = Binder.clearCallingIdentity(); |
| 7318 | try { |
| 7319 | String iccId = getIccId(subId); |
| 7320 | if (iccId != null) { |
| 7321 | String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 7322 | return mTelephonySharedPreferences.getString(alphaTagPrefKey, null); |
| 7323 | } |
| 7324 | return null; |
| 7325 | } finally { |
| 7326 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7327 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7328 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 7329 | |
| 7330 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7331 | public String[] getMergedSubscriberIds(int subId, String callingPackage, |
| 7332 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7333 | // This API isn't public, so no need to provide a valid subscription ID - we're not worried |
| 7334 | // about carrier-privileged callers not having access. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7335 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7336 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7337 | callingFeatureId, "getMergedSubscriberIds")) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7338 | return null; |
| 7339 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7340 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 7341 | // Clear calling identity, when calling TelephonyManager, because callerUid must be |
| 7342 | // the process, where TelephonyManager was instantiated. |
| 7343 | // Otherwise AppOps check will fail. |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7344 | final long identity = Binder.clearCallingIdentity(); |
| 7345 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7346 | final Context context = mApp; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7347 | final TelephonyManager tele = TelephonyManager.from(context); |
| 7348 | final SubscriptionManager sub = SubscriptionManager.from(context); |
| 7349 | |
| 7350 | // Figure out what subscribers are currently active |
| 7351 | final ArraySet<String> activeSubscriberIds = new ArraySet<>(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7352 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 7353 | // Only consider subs which match the current subId |
| 7354 | // This logic can be simplified. See b/131189269 for progress. |
| 7355 | if (isActiveSubscription(subId)) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7356 | activeSubscriberIds.add(tele.getSubscriberId(subId)); |
| 7357 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7358 | |
| 7359 | // First pass, find a number override for an active subscriber |
| 7360 | String mergeNumber = null; |
| 7361 | final Map<String, ?> prefs = mTelephonySharedPreferences.getAll(); |
| 7362 | for (String key : prefs.keySet()) { |
| 7363 | if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) { |
| 7364 | final String subscriberId = (String) prefs.get(key); |
| 7365 | if (activeSubscriberIds.contains(subscriberId)) { |
| 7366 | final String iccId = key.substring( |
| 7367 | PREF_CARRIERS_SUBSCRIBER_PREFIX.length()); |
| 7368 | final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 7369 | mergeNumber = (String) prefs.get(numberKey); |
| 7370 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 7371 | Rlog.d(LOG_TAG, "Found line number " + mergeNumber |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7372 | + " for active subscriber " + subscriberId); |
| 7373 | } |
| 7374 | if (!TextUtils.isEmpty(mergeNumber)) { |
| 7375 | break; |
| 7376 | } |
| 7377 | } |
| 7378 | } |
| 7379 | } |
| 7380 | |
| 7381 | // Shortcut when no active merged subscribers |
| 7382 | if (TextUtils.isEmpty(mergeNumber)) { |
| 7383 | return null; |
| 7384 | } |
| 7385 | |
| 7386 | // Second pass, find all subscribers under that line override |
| 7387 | final ArraySet<String> result = new ArraySet<>(); |
| 7388 | for (String key : prefs.keySet()) { |
| 7389 | if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) { |
| 7390 | final String number = (String) prefs.get(key); |
| 7391 | if (mergeNumber.equals(number)) { |
| 7392 | final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length()); |
| 7393 | final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 7394 | final String subscriberId = (String) prefs.get(subscriberKey); |
| 7395 | if (!TextUtils.isEmpty(subscriberId)) { |
| 7396 | result.add(subscriberId); |
| 7397 | } |
| 7398 | } |
| 7399 | } |
| 7400 | } |
| 7401 | |
| 7402 | final String[] resultArray = result.toArray(new String[result.size()]); |
| 7403 | Arrays.sort(resultArray); |
| 7404 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 7405 | Rlog.d(LOG_TAG, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7406 | "Found subscribers " + Arrays.toString(resultArray) + " after merge"); |
| 7407 | } |
| 7408 | return resultArray; |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7409 | } finally { |
| 7410 | Binder.restoreCallingIdentity(identity); |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7411 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7412 | } |
| 7413 | |
| 7414 | @Override |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 7415 | public String[] getMergedImsisFromGroup(int subId, String callingPackage) { |
| 7416 | enforceReadPrivilegedPermission("getMergedImsisFromGroup"); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7417 | |
| 7418 | final long identity = Binder.clearCallingIdentity(); |
| 7419 | try { |
| 7420 | final TelephonyManager telephonyManager = mApp.getSystemService( |
| 7421 | TelephonyManager.class); |
| 7422 | String subscriberId = telephonyManager.getSubscriberId(subId); |
| 7423 | if (subscriberId == null) { |
| 7424 | if (DBG) { |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 7425 | log("getMergedImsisFromGroup can't find subscriberId for subId " |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7426 | + subId); |
| 7427 | } |
| 7428 | return null; |
| 7429 | } |
| 7430 | |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 7431 | ParcelUuid groupUuid; |
| 7432 | if (PhoneFactory.isSubscriptionManagerServiceEnabled()) { |
| 7433 | final SubscriptionInfo info = SubscriptionManagerService.getInstance() |
| 7434 | .getSubscriptionInfo(subId); |
| 7435 | groupUuid = info.getGroupUuid(); |
| 7436 | } else { |
| 7437 | final SubscriptionInfo info = mSubscriptionController |
| 7438 | .getSubscriptionInfo(subId); |
| 7439 | groupUuid = info.getGroupUuid(); |
| 7440 | } |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7441 | // If it doesn't belong to any group, return just subscriberId of itself. |
| 7442 | if (groupUuid == null) { |
| 7443 | return new String[]{subscriberId}; |
| 7444 | } |
| 7445 | |
| 7446 | // Get all subscriberIds from the group. |
| 7447 | final List<String> mergedSubscriberIds = new ArrayList<>(); |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 7448 | List<SubscriptionInfo> groupInfos; |
| 7449 | if (PhoneFactory.isSubscriptionManagerServiceEnabled()) { |
| 7450 | groupInfos = SubscriptionManagerService.getInstance() |
| 7451 | .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(), |
| 7452 | mApp.getAttributionTag()); |
| 7453 | } else { |
| 7454 | groupInfos = mSubscriptionController |
| 7455 | .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(), |
| 7456 | mApp.getAttributionTag()); |
| 7457 | } |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7458 | for (SubscriptionInfo subInfo : groupInfos) { |
| 7459 | subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId()); |
| 7460 | if (subscriberId != null) { |
| 7461 | mergedSubscriberIds.add(subscriberId); |
| 7462 | } |
| 7463 | } |
| 7464 | |
| 7465 | return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]); |
| 7466 | } finally { |
| 7467 | Binder.restoreCallingIdentity(identity); |
| 7468 | |
| 7469 | } |
| 7470 | } |
| 7471 | |
| 7472 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7473 | public boolean setOperatorBrandOverride(int subId, String brand) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 7474 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7475 | subId, "setOperatorBrandOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7476 | |
| 7477 | final long identity = Binder.clearCallingIdentity(); |
| 7478 | try { |
| 7479 | final Phone phone = getPhone(subId); |
| 7480 | return phone == null ? false : phone.setOperatorBrandOverride(brand); |
| 7481 | } finally { |
| 7482 | Binder.restoreCallingIdentity(identity); |
| 7483 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 7484 | } |
Steven Liu | 4bf01bc | 2014-07-17 11:05:29 -0500 | [diff] [blame] | 7485 | |
| 7486 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7487 | public boolean setRoamingOverride(int subId, List<String> gsmRoamingList, |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 7488 | List<String> gsmNonRoamingList, List<String> cdmaRoamingList, |
| 7489 | List<String> cdmaNonRoamingList) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 7490 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 7491 | mApp, subId, "setRoamingOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7492 | |
| 7493 | final long identity = Binder.clearCallingIdentity(); |
| 7494 | try { |
| 7495 | final Phone phone = getPhone(subId); |
| 7496 | if (phone == null) { |
| 7497 | return false; |
| 7498 | } |
| 7499 | return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList, |
| 7500 | cdmaNonRoamingList); |
| 7501 | } finally { |
| 7502 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7503 | } |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 7504 | } |
| 7505 | |
| 7506 | @Override |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 7507 | @Deprecated |
| 7508 | public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) { |
| 7509 | enforceModifyPermission(); |
| 7510 | |
| 7511 | int returnValue = 0; |
| 7512 | try { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7513 | AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 7514 | if(result.exception == null) { |
| 7515 | if (result.result != null) { |
| 7516 | byte[] responseData = (byte[])(result.result); |
| 7517 | if(responseData.length > oemResp.length) { |
| 7518 | Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " + |
| 7519 | responseData.length + "bytes. Buffer Size is " + |
| 7520 | oemResp.length + "bytes."); |
| 7521 | } |
| 7522 | System.arraycopy(responseData, 0, oemResp, 0, responseData.length); |
| 7523 | returnValue = responseData.length; |
| 7524 | } |
| 7525 | } else { |
| 7526 | CommandException ex = (CommandException) result.exception; |
| 7527 | returnValue = ex.getCommandError().ordinal(); |
| 7528 | if(returnValue > 0) returnValue *= -1; |
| 7529 | } |
| 7530 | } catch (RuntimeException e) { |
| 7531 | Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception"); |
| 7532 | returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal()); |
| 7533 | if(returnValue > 0) returnValue *= -1; |
| 7534 | } |
| 7535 | |
| 7536 | return returnValue; |
| 7537 | } |
| 7538 | |
| 7539 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 7540 | public int getRadioAccessFamily(int phoneId, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7541 | Phone phone = PhoneFactory.getPhone(phoneId); |
Shuo Qian | dee5340 | 2020-05-29 14:08:15 -0700 | [diff] [blame] | 7542 | try { |
| 7543 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 7544 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Shuo Qian | dee5340 | 2020-05-29 14:08:15 -0700 | [diff] [blame] | 7545 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 7546 | } catch (SecurityException e) { |
| 7547 | EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission"); |
| 7548 | throw e; |
| 7549 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7550 | int raf = RadioAccessFamily.RAF_UNKNOWN; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7551 | if (phone == null) { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7552 | return raf; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7553 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7554 | final long identity = Binder.clearCallingIdentity(); |
| 7555 | try { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7556 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 7557 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7558 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 7559 | raf = ProxyController.getInstance().getRadioAccessFamily(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7560 | } finally { |
| 7561 | Binder.restoreCallingIdentity(identity); |
| 7562 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7563 | return raf; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 7564 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7565 | |
| 7566 | @Override |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7567 | public void uploadCallComposerPicture(int subscriptionId, String callingPackage, |
Hall Liu | e31bac6 | 2020-12-23 19:16:10 -0800 | [diff] [blame] | 7568 | String contentType, ParcelFileDescriptor fd, ResultReceiver callback) { |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7569 | try { |
| 7570 | if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0), |
| 7571 | Binder.getCallingUid())) { |
Tyler Gunn | b87925a | 2021-06-10 14:54:27 -0700 | [diff] [blame] | 7572 | throw new SecurityException("Invalid package:" + callingPackage); |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7573 | } |
| 7574 | } catch (PackageManager.NameNotFoundException e) { |
Tyler Gunn | b87925a | 2021-06-10 14:54:27 -0700 | [diff] [blame] | 7575 | throw new SecurityException("Invalid package:" + callingPackage); |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7576 | } |
| 7577 | RoleManager rm = mApp.getSystemService(RoleManager.class); |
| 7578 | List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER); |
| 7579 | if (!dialerRoleHolders.contains(callingPackage)) { |
| 7580 | throw new SecurityException("App must be the dialer role holder to" |
| 7581 | + " upload a call composer pic"); |
| 7582 | } |
| 7583 | |
| 7584 | Executors.newSingleThreadExecutor().execute(() -> { |
| 7585 | ByteArrayOutputStream output = new ByteArrayOutputStream( |
| 7586 | (int) TelephonyManager.getMaximumCallComposerPictureSize()); |
| 7587 | InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd); |
| 7588 | boolean readUntilEnd = false; |
| 7589 | int totalBytesRead = 0; |
| 7590 | byte[] buffer = new byte[16 * 1024]; |
| 7591 | while (true) { |
| 7592 | int numRead; |
| 7593 | try { |
| 7594 | numRead = input.read(buffer); |
| 7595 | } catch (IOException e) { |
| 7596 | try { |
| 7597 | fd.checkError(); |
| 7598 | callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED, |
| 7599 | null); |
| 7600 | } catch (IOException e1) { |
| 7601 | // This means that the other side closed explicitly with an error. If this |
| 7602 | // happens, log and ignore. |
| 7603 | loge("Remote end of call composer picture pipe closed: " + e1); |
| 7604 | } |
| 7605 | break; |
| 7606 | } |
| 7607 | if (numRead == -1) { |
| 7608 | readUntilEnd = true; |
| 7609 | break; |
| 7610 | } |
| 7611 | totalBytesRead += numRead; |
| 7612 | if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) { |
| 7613 | loge("Too many bytes read for call composer picture: " + totalBytesRead); |
| 7614 | try { |
| 7615 | input.close(); |
| 7616 | } catch (IOException e) { |
| 7617 | // ignore |
| 7618 | } |
| 7619 | break; |
| 7620 | } |
| 7621 | output.write(buffer, 0, numRead); |
| 7622 | } |
| 7623 | // Generally, the remote end will close the file descriptors. The only case where we |
| 7624 | // close is above, where the picture size is too big. |
| 7625 | |
| 7626 | try { |
| 7627 | fd.checkError(); |
| 7628 | } catch (IOException e) { |
| 7629 | loge("Remote end for call composer closed with an error: " + e); |
| 7630 | return; |
| 7631 | } |
| 7632 | |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 7633 | if (!readUntilEnd) { |
| 7634 | loge("Did not finish reading entire image; aborting"); |
| 7635 | return; |
| 7636 | } |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7637 | |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 7638 | ImageData imageData = new ImageData(output.toByteArray(), contentType, null); |
| 7639 | CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer( |
| 7640 | new CallComposerPictureTransfer.Factory() {}, |
| 7641 | imageData, |
| 7642 | (result) -> { |
| 7643 | if (result.first != null) { |
| 7644 | ParcelUuid parcelUuid = new ParcelUuid(result.first); |
| 7645 | Bundle outputResult = new Bundle(); |
| 7646 | outputResult.putParcelable( |
| 7647 | TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid); |
| 7648 | callback.send(TelephonyManager.CallComposerException.SUCCESS, |
| 7649 | outputResult); |
| 7650 | } else { |
| 7651 | callback.send(result.second, null); |
| 7652 | } |
| 7653 | } |
| 7654 | ); |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7655 | }); |
| 7656 | } |
| 7657 | |
| 7658 | @Override |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7659 | public void enableVideoCalling(boolean enable) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7660 | final Phone defaultPhone = getDefaultPhone(); |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7661 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7662 | |
| 7663 | final long identity = Binder.clearCallingIdentity(); |
| 7664 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7665 | ImsManager.getInstance(defaultPhone.getContext(), |
| 7666 | defaultPhone.getPhoneId()).setVtSetting(enable); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7667 | } finally { |
| 7668 | Binder.restoreCallingIdentity(identity); |
| 7669 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7670 | } |
| 7671 | |
| 7672 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7673 | public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7674 | final Phone defaultPhone = getDefaultPhone(); |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7675 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 7676 | callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 7677 | return false; |
| 7678 | } |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 7679 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7680 | final long identity = Binder.clearCallingIdentity(); |
| 7681 | try { |
| 7682 | // Check the user preference and the system-level IMS setting. Even if the user has |
| 7683 | // enabled video calling, if IMS is disabled we aren't able to support video calling. |
| 7684 | // In the long run, we may instead need to check if there exists a connection service |
| 7685 | // which can support video calling. |
| 7686 | ImsManager imsManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7687 | ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7688 | return imsManager.isVtEnabledByPlatform() |
| 7689 | && imsManager.isEnhanced4gLteModeSettingEnabledByUser() |
| 7690 | && imsManager.isVtEnabledByUser(); |
| 7691 | } finally { |
| 7692 | Binder.restoreCallingIdentity(identity); |
| 7693 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7694 | } |
Libin.Tang@motorola.com | afe8264 | 2014-12-18 13:27:53 -0600 | [diff] [blame] | 7695 | |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7696 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7697 | public boolean canChangeDtmfToneLength(int subId, String callingPackage, |
| 7698 | String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7699 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7700 | mApp, subId, callingPackage, callingFeatureId, |
| 7701 | "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7702 | return false; |
| 7703 | } |
| 7704 | |
| 7705 | final long identity = Binder.clearCallingIdentity(); |
| 7706 | try { |
| 7707 | CarrierConfigManager configManager = |
| 7708 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7709 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7710 | .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL); |
| 7711 | } finally { |
| 7712 | Binder.restoreCallingIdentity(identity); |
| 7713 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7714 | } |
| 7715 | |
| 7716 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7717 | public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7718 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7719 | mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7720 | return false; |
| 7721 | } |
| 7722 | |
| 7723 | final long identity = Binder.clearCallingIdentity(); |
| 7724 | try { |
| 7725 | CarrierConfigManager configManager = |
| 7726 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7727 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7728 | .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL); |
| 7729 | } finally { |
| 7730 | Binder.restoreCallingIdentity(identity); |
| 7731 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7732 | } |
| 7733 | |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7734 | @Override |
| 7735 | public boolean isTtyModeSupported() { |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 7736 | TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class); |
Wooki Wu | 1f82f7a | 2016-02-15 15:59:58 +0800 | [diff] [blame] | 7737 | return telecomManager.isTtySupported(); |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7738 | } |
| 7739 | |
| 7740 | @Override |
| 7741 | public boolean isHearingAidCompatibilitySupported() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7742 | final long identity = Binder.clearCallingIdentity(); |
| 7743 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7744 | return mApp.getResources().getBoolean(R.bool.hac_enabled); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7745 | } finally { |
| 7746 | Binder.restoreCallingIdentity(identity); |
| 7747 | } |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7748 | } |
| 7749 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 7750 | /** |
| 7751 | * Determines whether the device currently supports RTT (Real-time text). Based both on carrier |
| 7752 | * support for the feature and device firmware support. |
| 7753 | * |
| 7754 | * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise. |
| 7755 | */ |
| 7756 | @Override |
| 7757 | public boolean isRttSupported(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7758 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7759 | final Phone phone = getPhone(subscriptionId); |
| 7760 | if (phone == null) { |
| 7761 | loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId); |
| 7762 | return false; |
| 7763 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7764 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7765 | boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7766 | CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL); |
| 7767 | boolean isDeviceSupported = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7768 | phone.getContext().getResources().getBoolean(R.bool.config_support_rtt); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7769 | return isCarrierSupported && isDeviceSupported; |
| 7770 | } finally { |
| 7771 | Binder.restoreCallingIdentity(identity); |
| 7772 | } |
Hall Liu | 9818758 | 2018-01-22 19:15:32 -0800 | [diff] [blame] | 7773 | } |
| 7774 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 7775 | /** |
Hall Liu | f2daa02 | 2019-07-23 18:39:00 -0700 | [diff] [blame] | 7776 | * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set |
| 7777 | * RTT setting, will return true if the device and carrier both support RTT. |
| 7778 | * 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] | 7779 | */ |
| 7780 | public boolean isRttEnabled(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7781 | final long identity = Binder.clearCallingIdentity(); |
| 7782 | try { |
Hall Liu | 5bab75c | 2019-12-11 23:58:20 +0000 | [diff] [blame] | 7783 | boolean isRttSupported = isRttSupported(subscriptionId); |
| 7784 | boolean isUserRttSettingOn = Settings.Secure.getInt( |
| 7785 | mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0; |
| 7786 | boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId) |
| 7787 | .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL); |
| 7788 | return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7789 | } finally { |
| 7790 | Binder.restoreCallingIdentity(identity); |
| 7791 | } |
Hall Liu | 3ad5f01 | 2018-04-06 16:23:39 -0700 | [diff] [blame] | 7792 | } |
| 7793 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7794 | @Deprecated |
| 7795 | @Override |
| 7796 | public String getDeviceId(String callingPackage) { |
| 7797 | return getDeviceIdWithFeature(callingPackage, null); |
| 7798 | } |
| 7799 | |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7800 | /** |
| 7801 | * Returns the unique device ID of phone, for example, the IMEI for |
| 7802 | * GSM and the MEID for CDMA phones. Return null if device ID is not available. |
| 7803 | * |
| 7804 | * <p>Requires Permission: |
| 7805 | * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} |
| 7806 | */ |
| 7807 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7808 | public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) { |
Shuo Qian | 13d8915 | 2021-05-10 23:58:11 -0700 | [diff] [blame] | 7809 | try { |
| 7810 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 7811 | } catch (SecurityException se) { |
| 7812 | EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid()); |
| 7813 | throw new SecurityException("Package " + callingPackage + " does not belong to " |
| 7814 | + Binder.getCallingUid()); |
| 7815 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7816 | final Phone phone = PhoneFactory.getPhone(0); |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7817 | if (phone == null) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7818 | return null; |
| 7819 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7820 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 7821 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7822 | callingPackage, callingFeatureId, "getDeviceId")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7823 | return null; |
| 7824 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7825 | |
| 7826 | final long identity = Binder.clearCallingIdentity(); |
| 7827 | try { |
| 7828 | return phone.getDeviceId(); |
| 7829 | } finally { |
| 7830 | Binder.restoreCallingIdentity(identity); |
| 7831 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7832 | } |
| 7833 | |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 7834 | /** |
| 7835 | * {@hide} |
| 7836 | * Returns the IMS Registration Status on a particular subid |
| 7837 | * |
| 7838 | * @param subId |
| 7839 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7840 | public boolean isImsRegistered(int subId) { |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 7841 | Phone phone = getPhone(subId); |
| 7842 | if (phone != null) { |
| 7843 | return phone.isImsRegistered(); |
| 7844 | } else { |
| 7845 | return false; |
| 7846 | } |
| 7847 | } |
| 7848 | |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 7849 | @Override |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7850 | public int getSubIdForPhoneAccountHandle( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7851 | PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) { |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7852 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(), |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7853 | callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) { |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7854 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 7855 | } |
| 7856 | final long identity = Binder.clearCallingIdentity(); |
| 7857 | try { |
| 7858 | return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle); |
| 7859 | } finally { |
| 7860 | Binder.restoreCallingIdentity(identity); |
| 7861 | } |
| 7862 | } |
| 7863 | |
| 7864 | @Override |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 7865 | public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) { |
Alireza Forouzan | 4ac4f98 | 2021-03-16 22:18:52 -0700 | [diff] [blame] | 7866 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 7867 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Alireza Forouzan | 4ac4f98 | 2021-03-16 22:18:52 -0700 | [diff] [blame] | 7868 | mApp, |
| 7869 | subscriptionId, |
| 7870 | "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: " + subscriptionId); |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 7871 | final long identity = Binder.clearCallingIdentity(); |
| 7872 | try { |
| 7873 | Phone phone = getPhone(subscriptionId); |
| 7874 | if (phone == null) { |
| 7875 | return null; |
| 7876 | } |
| 7877 | return PhoneUtils.makePstnPhoneAccountHandle(phone); |
| 7878 | } finally { |
| 7879 | Binder.restoreCallingIdentity(identity); |
| 7880 | } |
| 7881 | } |
| 7882 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7883 | /** |
| 7884 | * @return the VoWiFi calling availability. |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 7885 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7886 | public boolean isWifiCallingAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7887 | final long identity = Binder.clearCallingIdentity(); |
| 7888 | try { |
| 7889 | Phone phone = getPhone(subId); |
| 7890 | if (phone != null) { |
| 7891 | return phone.isWifiCallingEnabled(); |
| 7892 | } else { |
| 7893 | return false; |
| 7894 | } |
| 7895 | } finally { |
| 7896 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7897 | } |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 7898 | } |
| 7899 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7900 | /** |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7901 | * @return the VT calling availability. |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 7902 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7903 | public boolean isVideoTelephonyAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7904 | final long identity = Binder.clearCallingIdentity(); |
| 7905 | try { |
| 7906 | Phone phone = getPhone(subId); |
| 7907 | if (phone != null) { |
| 7908 | return phone.isVideoEnabled(); |
| 7909 | } else { |
| 7910 | return false; |
| 7911 | } |
| 7912 | } finally { |
| 7913 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7914 | } |
| 7915 | } |
| 7916 | |
| 7917 | /** |
| 7918 | * @return the IMS registration technology for the MMTEL feature. Valid return values are |
| 7919 | * defined in {@link ImsRegistrationImplBase}. |
| 7920 | */ |
| 7921 | public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7922 | final long identity = Binder.clearCallingIdentity(); |
| 7923 | try { |
| 7924 | Phone phone = getPhone(subId); |
| 7925 | if (phone != null) { |
| 7926 | return phone.getImsRegistrationTech(); |
| 7927 | } else { |
| 7928 | return ImsRegistrationImplBase.REGISTRATION_TECH_NONE; |
| 7929 | } |
| 7930 | } finally { |
| 7931 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7932 | } |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 7933 | } |
| 7934 | |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 7935 | @Override |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 7936 | public void factoryReset(int subId, String callingPackage) { |
paulhu | 5a77360 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 7937 | enforceSettingsPermission(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 7938 | if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) { |
| 7939 | return; |
| 7940 | } |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 7941 | Phone defaultPhone = getDefaultPhone(); |
| 7942 | if (defaultPhone != null) { |
| 7943 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7944 | mApp, getDefaultPhone().getSubId(), "factoryReset"); |
| 7945 | } |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7946 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7947 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7948 | try { |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 7949 | if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction( |
| 7950 | UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7951 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 7952 | getDefaultDataEnabled(), callingPackage); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7953 | setNetworkSelectionModeAutomatic(subId); |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 7954 | Phone phone = getPhone(subId); |
SongFerngWang | fd89b10 | 2021-05-27 22:44:54 +0800 | [diff] [blame] | 7955 | cleanUpAllowedNetworkTypes(phone, subId); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7956 | setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId)); |
Jordan Liu | 857e73a | 2021-03-05 16:24:04 -0800 | [diff] [blame] | 7957 | getPhone(subId).resetCarrierKeysForImsiEncryption(); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7958 | } |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 7959 | // There has been issues when Sms raw table somehow stores orphan |
| 7960 | // fragments. They lead to garbled message when new fragments come |
| 7961 | // in and combined with those stale ones. In case this happens again, |
| 7962 | // user can reset all network settings which will clean up this table. |
| 7963 | cleanUpSmsRawTable(getDefaultPhone().getContext()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 7964 | // Clean up IMS settings as well here. |
| 7965 | int slotId = getSlotIndex(subId); |
| 7966 | if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 7967 | ImsManager.getInstance(mApp, slotId).factoryReset(); |
| 7968 | } |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 7969 | |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 7970 | if (defaultPhone == null) { |
| 7971 | return; |
| 7972 | } |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 7973 | // Erase modem config if erase modem on network setting is enabled. |
| 7974 | String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY, |
| 7975 | RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED); |
| 7976 | if (configValue != null && Boolean.parseBoolean(configValue)) { |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 7977 | sendEraseModemConfig(defaultPhone); |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 7978 | } |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 7979 | |
| 7980 | sendEraseDataInSharedPreferences(defaultPhone); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7981 | } finally { |
| 7982 | Binder.restoreCallingIdentity(identity); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 7983 | } |
| 7984 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7985 | |
SongFerngWang | fd89b10 | 2021-05-27 22:44:54 +0800 | [diff] [blame] | 7986 | @VisibleForTesting |
| 7987 | void cleanUpAllowedNetworkTypes(Phone phone, int subId) { |
| 7988 | if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) { |
| 7989 | return; |
| 7990 | } |
| 7991 | long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType( |
| 7992 | RILConstants.PREFERRED_NETWORK_MODE); |
| 7993 | SubscriptionManager.setSubscriptionProperty(subId, |
| 7994 | SubscriptionManager.ALLOWED_NETWORK_TYPES, |
| 7995 | "user=" + defaultNetworkType); |
| 7996 | phone.loadAllowedNetworksFromSubscriptionDatabase(); |
| 7997 | phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER, |
| 7998 | defaultNetworkType, null); |
| 7999 | } |
| 8000 | |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 8001 | private void cleanUpSmsRawTable(Context context) { |
| 8002 | ContentResolver resolver = context.getContentResolver(); |
| 8003 | Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete"); |
| 8004 | resolver.delete(uri, null, null); |
| 8005 | } |
| 8006 | |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 8007 | @Override |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 8008 | public String getSimLocaleForSubscriber(int subId) { |
| 8009 | enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId); |
| 8010 | final Phone phone = getPhone(subId); |
| 8011 | if (phone == null) { |
| 8012 | log("getSimLocaleForSubscriber, invalid subId"); |
chen xu | 2bb91e4 | 2019-01-24 14:35:54 -0800 | [diff] [blame] | 8013 | return null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 8014 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8015 | final long identity = Binder.clearCallingIdentity(); |
| 8016 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 8017 | SubscriptionInfo info; |
| 8018 | if (PhoneFactory.isSubscriptionManagerServiceEnabled()) { |
| 8019 | info = SubscriptionManagerService.getInstance().getActiveSubscriptionInfo(subId, |
| 8020 | phone.getContext().getOpPackageName(), |
| 8021 | phone.getContext().getAttributionTag()); |
| 8022 | if (info == null) { |
| 8023 | log("getSimLocaleForSubscriber, inactive subId: " + subId); |
| 8024 | return null; |
| 8025 | } |
| 8026 | } else { |
| 8027 | info = mSubscriptionController.getActiveSubscriptionInfo(subId, |
| 8028 | phone.getContext().getOpPackageName(), |
| 8029 | phone.getContext().getAttributionTag()); |
| 8030 | if (info == null) { |
| 8031 | log("getSimLocaleForSubscriber, inactive subId: " + subId); |
| 8032 | return null; |
| 8033 | } |
chen xu | 6291c47 | 2019-02-04 12:55:53 -0800 | [diff] [blame] | 8034 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8035 | // Try and fetch the locale from the carrier properties or from the SIM language |
| 8036 | // preferences (EF-PL and EF-LI)... |
| 8037 | final int mcc = info.getMcc(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8038 | String simLanguage = null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 8039 | final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs(); |
| 8040 | if (localeFromDefaultSim != null) { |
| 8041 | if (!localeFromDefaultSim.getCountry().isEmpty()) { |
| 8042 | if (DBG) log("Using locale from subId: " + subId + " locale: " |
| 8043 | + localeFromDefaultSim); |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 8044 | return matchLocaleFromSupportedLocaleList(phone, localeFromDefaultSim); |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 8045 | } else { |
| 8046 | simLanguage = localeFromDefaultSim.getLanguage(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8047 | } |
| 8048 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 8049 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8050 | // The SIM language preferences only store a language (e.g. fr = French), not an |
| 8051 | // exact locale (e.g. fr_FR = French/France). So, if the locale returned from |
| 8052 | // the SIM and carrier preferences does not include a country we add the country |
| 8053 | // determined from the SIM MCC to provide an exact locale. |
zoey chen | c730df8 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 8054 | final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8055 | if (mccLocale != null) { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 8056 | if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale); |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 8057 | return matchLocaleFromSupportedLocaleList(phone, mccLocale); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8058 | } |
| 8059 | |
| 8060 | if (DBG) log("No locale found - returning null"); |
| 8061 | return null; |
| 8062 | } finally { |
| 8063 | Binder.restoreCallingIdentity(identity); |
| 8064 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 8065 | } |
| 8066 | |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 8067 | @VisibleForTesting |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 8068 | String matchLocaleFromSupportedLocaleList(Phone phone, @NonNull Locale inputLocale) { |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 8069 | String[] supportedLocale = com.android.internal.app.LocalePicker.getSupportedLocales( |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 8070 | phone.getContext()); |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 8071 | for (String localeTag : supportedLocale) { |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 8072 | if (LocaleList.matchesLanguageAndScript(inputLocale, Locale.forLanguageTag(localeTag)) |
| 8073 | && TextUtils.equals(inputLocale.getCountry(), |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 8074 | Locale.forLanguageTag(localeTag).getCountry())) { |
| 8075 | return localeTag; |
| 8076 | } |
| 8077 | } |
| 8078 | return inputLocale.toLanguageTag(); |
| 8079 | } |
| 8080 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8081 | /** |
| 8082 | * NOTE: this method assumes permission checks are done and caller identity has been cleared. |
| 8083 | */ |
| 8084 | private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 8085 | if (PhoneFactory.isSubscriptionManagerServiceEnabled()) { |
| 8086 | return SubscriptionManagerService.getInstance().getActiveSubscriptionInfoList( |
| 8087 | mApp.getOpPackageName(), mApp.getAttributionTag()); |
| 8088 | } |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8089 | return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(), |
Philip P. Moltmann | 8d34f0c | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 8090 | mApp.getAttributionTag()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 8091 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 8092 | |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8093 | private ActivityStatsTechSpecificInfo[] mLastModemActivitySpecificInfo = null; |
| 8094 | private ModemActivityInfo mLastModemActivityInfo = null; |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 8095 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 8096 | /** |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 8097 | * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object |
| 8098 | * representing the state of the modem. |
| 8099 | * |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 8100 | * NOTE: The underlying implementation clears the modem state, so there should only ever be one |
| 8101 | * caller to it. Everyone should call this class to get cumulative data. |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 8102 | * @hide |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 8103 | */ |
| 8104 | @Override |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 8105 | public void requestModemActivityInfo(ResultReceiver result) { |
| 8106 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8107 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8108 | |
| 8109 | final long identity = Binder.clearCallingIdentity(); |
| 8110 | try { |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 8111 | sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8112 | } finally { |
| 8113 | Binder.restoreCallingIdentity(identity); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 8114 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 8115 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8116 | |
Gary Jian | 76280a4 | 2022-12-07 16:18:33 +0800 | [diff] [blame] | 8117 | // Checks that ModemActivityInfo is valid. Sleep time and Idle time should be |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 8118 | // less than total activity duration. |
| 8119 | private boolean isModemActivityInfoValid(ModemActivityInfo info) { |
| 8120 | if (info == null) { |
| 8121 | return false; |
| 8122 | } |
| 8123 | int activityDurationMs = |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 8124 | (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis()); |
Gary Jian | 76280a4 | 2022-12-07 16:18:33 +0800 | [diff] [blame] | 8125 | activityDurationMs += MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS; |
| 8126 | |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 8127 | int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum(); |
| 8128 | |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 8129 | return (info.isValid() |
| 8130 | && (info.getSleepTimeMillis() <= activityDurationMs) |
Gary Jian | 76280a4 | 2022-12-07 16:18:33 +0800 | [diff] [blame] | 8131 | && (info.getIdleTimeMillis() <= activityDurationMs)); |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 8132 | } |
| 8133 | |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8134 | private void updateLastModemActivityInfo(ModemActivityInfo info, int rat, int freq) { |
| 8135 | int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()]; |
| 8136 | int[] txTimeMs = info.getTransmitTimeMillis(rat, freq); |
| 8137 | int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat, freq); |
| 8138 | |
| 8139 | for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) { |
| 8140 | mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl]; |
| 8141 | } |
| 8142 | |
| 8143 | mLastModemActivityInfo.setTransmitTimeMillis(rat, freq, mergedTxTimeMs); |
| 8144 | mLastModemActivityInfo.setReceiveTimeMillis( |
| 8145 | rat, |
| 8146 | freq, |
| 8147 | info.getReceiveTimeMillis(rat, freq) |
| 8148 | + mLastModemActivityInfo.getReceiveTimeMillis(rat, freq)); |
| 8149 | } |
| 8150 | |
| 8151 | private void updateLastModemActivityInfo(ModemActivityInfo info, int rat) { |
| 8152 | int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()]; |
| 8153 | int[] txTimeMs = info.getTransmitTimeMillis(rat); |
| 8154 | int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat); |
| 8155 | |
| 8156 | for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) { |
| 8157 | mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl]; |
| 8158 | } |
| 8159 | mLastModemActivityInfo.setTransmitTimeMillis(rat, mergedTxTimeMs); |
| 8160 | mLastModemActivityInfo.setReceiveTimeMillis( |
| 8161 | rat, |
| 8162 | info.getReceiveTimeMillis(rat) + mLastModemActivityInfo.getReceiveTimeMillis(rat)); |
| 8163 | } |
| 8164 | |
| 8165 | /** |
| 8166 | * Merge this ModemActivityInfo with mLastModemActivitySpecificInfo |
| 8167 | * @param info recent ModemActivityInfo |
| 8168 | */ |
| 8169 | private void mergeModemActivityInfo(ModemActivityInfo info) { |
| 8170 | List<ActivityStatsTechSpecificInfo> merged = new ArrayList<>(); |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 8171 | ActivityStatsTechSpecificInfo deltaSpecificInfo; |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8172 | boolean matched; |
| 8173 | for (int i = 0; i < info.getSpecificInfoLength(); i++) { |
| 8174 | matched = false; |
| 8175 | int rat = info.getSpecificInfoRat(i); |
| 8176 | int freq = info.getSpecificInfoFrequencyRange(i); |
| 8177 | //Check each ActivityStatsTechSpecificInfo in this ModemActivityInfo for new rat returns |
| 8178 | //Add a new ActivityStatsTechSpecificInfo if is a new rat, and merge with the original |
| 8179 | //if it already exists |
| 8180 | for (int j = 0; j < mLastModemActivitySpecificInfo.length; j++) { |
| 8181 | if (rat == mLastModemActivityInfo.getSpecificInfoRat(j) && !matched) { |
| 8182 | //Merged based on frequency range (MMWAVE vs SUB6) for 5G |
| 8183 | if (rat == AccessNetworkConstants.AccessNetworkType.NGRAN) { |
| 8184 | if (freq == mLastModemActivityInfo.getSpecificInfoFrequencyRange(j)) { |
| 8185 | updateLastModemActivityInfo(info, rat, freq); |
| 8186 | matched = true; |
| 8187 | } |
| 8188 | } else { |
| 8189 | updateLastModemActivityInfo(info, rat); |
| 8190 | matched = true; |
| 8191 | } |
| 8192 | } |
| 8193 | } |
| 8194 | |
| 8195 | if (!matched) { |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 8196 | deltaSpecificInfo = |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8197 | new ActivityStatsTechSpecificInfo( |
| 8198 | rat, |
| 8199 | freq, |
| 8200 | info.getTransmitTimeMillis(rat, freq), |
| 8201 | (int) info.getReceiveTimeMillis(rat, freq)); |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 8202 | merged.addAll(Arrays.asList(deltaSpecificInfo)); |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8203 | } |
| 8204 | } |
| 8205 | merged.addAll(Arrays.asList(mLastModemActivitySpecificInfo)); |
| 8206 | mLastModemActivitySpecificInfo = |
| 8207 | new ActivityStatsTechSpecificInfo[merged.size()]; |
| 8208 | merged.toArray(mLastModemActivitySpecificInfo); |
| 8209 | |
| 8210 | mLastModemActivityInfo.setTimestamp(info.getTimestampMillis()); |
| 8211 | mLastModemActivityInfo.setSleepTimeMillis( |
| 8212 | info.getSleepTimeMillis() |
| 8213 | + mLastModemActivityInfo.getSleepTimeMillis()); |
| 8214 | mLastModemActivityInfo.setIdleTimeMillis( |
| 8215 | info.getIdleTimeMillis() |
| 8216 | + mLastModemActivityInfo.getIdleTimeMillis()); |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 8217 | |
| 8218 | mLastModemActivityInfo = |
| 8219 | new ModemActivityInfo( |
| 8220 | mLastModemActivityInfo.getTimestampMillis(), |
| 8221 | mLastModemActivityInfo.getSleepTimeMillis(), |
| 8222 | mLastModemActivityInfo.getIdleTimeMillis(), |
| 8223 | mLastModemActivitySpecificInfo); |
| 8224 | } |
| 8225 | |
| 8226 | private ActivityStatsTechSpecificInfo[] deepCopyModemActivitySpecificInfo( |
| 8227 | ActivityStatsTechSpecificInfo[] info) { |
| 8228 | int infoSize = info.length; |
| 8229 | ActivityStatsTechSpecificInfo[] ret = new ActivityStatsTechSpecificInfo[infoSize]; |
| 8230 | for (int i = 0; i < infoSize; i++) { |
| 8231 | ret[i] = new ActivityStatsTechSpecificInfo( |
| 8232 | info[i].getRat(), info[i].getFrequencyRange(), |
| 8233 | info[i].getTransmitTimeMillis(), |
| 8234 | (int) info[i].getReceiveTimeMillis()); |
| 8235 | } |
| 8236 | return ret; |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8237 | } |
| 8238 | |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8239 | /** |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8240 | * Returns the service state information on specified subscription. |
| 8241 | */ |
| 8242 | @Override |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 8243 | public ServiceState getServiceStateForSubscriber(int subId, |
| 8244 | boolean renounceFineLocationAccess, boolean renounceCoarseLocationAccess, |
| 8245 | String callingPackage, String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8246 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8247 | mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) { |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8248 | return null; |
| 8249 | } |
| 8250 | |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 8251 | boolean hasFinePermission = false; |
| 8252 | boolean hasCoarsePermission = false; |
| 8253 | if (!renounceFineLocationAccess) { |
| 8254 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 8255 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 8256 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 8257 | .setCallingPackage(callingPackage) |
| 8258 | .setCallingFeatureId(callingFeatureId) |
| 8259 | .setCallingPid(Binder.getCallingPid()) |
| 8260 | .setCallingUid(Binder.getCallingUid()) |
| 8261 | .setMethod("getServiceStateForSubscriber") |
| 8262 | .setLogAsInfo(true) |
| 8263 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 8264 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 8265 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 8266 | .build()); |
| 8267 | hasFinePermission = |
| 8268 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 8269 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 8270 | |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 8271 | if (!renounceCoarseLocationAccess) { |
| 8272 | LocationAccessPolicy.LocationPermissionResult coarseLocationResult = |
| 8273 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 8274 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 8275 | .setCallingPackage(callingPackage) |
| 8276 | .setCallingFeatureId(callingFeatureId) |
| 8277 | .setCallingPid(Binder.getCallingPid()) |
| 8278 | .setCallingUid(Binder.getCallingUid()) |
| 8279 | .setMethod("getServiceStateForSubscriber") |
| 8280 | .setLogAsInfo(true) |
| 8281 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 8282 | .setMinSdkVersionForFine(Integer.MAX_VALUE) |
| 8283 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 8284 | .build()); |
| 8285 | hasCoarsePermission = |
| 8286 | coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 8287 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 8288 | |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 8289 | final Phone phone = getPhone(subId); |
| 8290 | if (phone == null) { |
| 8291 | return null; |
| 8292 | } |
| 8293 | |
Jordan Liu | 0f2bc44 | 2020-11-18 16:47:37 -0800 | [diff] [blame] | 8294 | final long identity = Binder.clearCallingIdentity(); |
| 8295 | |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 8296 | boolean isCallingPackageDataService = phone.getDataServicePackages() |
| 8297 | .contains(callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8298 | try { |
Jordan Liu | c437b19 | 2020-08-17 10:59:12 -0700 | [diff] [blame] | 8299 | // isActiveSubId requires READ_PHONE_STATE, which we already check for above |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 8300 | if (PhoneFactory.isSubscriptionManagerServiceEnabled()) { |
| 8301 | SubscriptionInfoInternal subInfo = SubscriptionManagerService.getInstance() |
| 8302 | .getSubscriptionInfoInternal(subId); |
| 8303 | if (subInfo == null || !subInfo.isActive()) { |
| 8304 | Rlog.d(LOG_TAG, "getServiceStateForSubscriber returning null for inactive " |
| 8305 | + "subId=" + subId); |
| 8306 | return null; |
| 8307 | } |
| 8308 | } else { |
| 8309 | if (!mSubscriptionController.isActiveSubId(subId, callingPackage, |
| 8310 | callingFeatureId)) { |
| 8311 | Rlog.d(LOG_TAG, "getServiceStateForSubscriber returning null for inactive " |
| 8312 | + "subId=" + subId); |
| 8313 | return null; |
| 8314 | } |
Jordan Liu | c437b19 | 2020-08-17 10:59:12 -0700 | [diff] [blame] | 8315 | } |
| 8316 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 8317 | ServiceState ss = phone.getServiceState(); |
| 8318 | |
| 8319 | // Scrub out the location info in ServiceState depending on what level of access |
| 8320 | // the caller has. |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 8321 | if (hasFinePermission || isCallingPackageDataService) return ss; |
Malcolm Chen | 5052de6 | 2019-12-30 13:56:38 -0800 | [diff] [blame] | 8322 | if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false); |
| 8323 | return ss.createLocationInfoSanitizedCopy(true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8324 | } finally { |
| 8325 | Binder.restoreCallingIdentity(identity); |
| 8326 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8327 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8328 | |
| 8329 | /** |
| 8330 | * Returns the URI for the per-account voicemail ringtone set in Phone settings. |
| 8331 | * |
| 8332 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 8333 | * voicemail ringtone. |
| 8334 | * @return The URI for the ringtone to play when receiving a voicemail from a specific |
| 8335 | * PhoneAccount. |
| 8336 | */ |
| 8337 | @Override |
| 8338 | public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8339 | final long identity = Binder.clearCallingIdentity(); |
| 8340 | try { |
| 8341 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 8342 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8343 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8344 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8345 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8346 | return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext()); |
| 8347 | } finally { |
| 8348 | Binder.restoreCallingIdentity(identity); |
| 8349 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8350 | } |
| 8351 | |
| 8352 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8353 | * Sets the per-account voicemail ringtone. |
| 8354 | * |
| 8355 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 8356 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 8357 | * |
| 8358 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 8359 | * voicemail ringtone. |
| 8360 | * @param uri The URI for the ringtone to play when receiving a voicemail from a specific |
| 8361 | * PhoneAccount. |
| 8362 | */ |
| 8363 | @Override |
| 8364 | public void setVoicemailRingtoneUri(String callingPackage, |
| 8365 | PhoneAccountHandle phoneAccountHandle, Uri uri) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8366 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8367 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 8368 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 8369 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8370 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8371 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 8372 | "setVoicemailRingtoneUri"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8373 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8374 | |
| 8375 | final long identity = Binder.clearCallingIdentity(); |
| 8376 | try { |
| 8377 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 8378 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8379 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8380 | } |
| 8381 | VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri); |
| 8382 | } finally { |
| 8383 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8384 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8385 | } |
| 8386 | |
| 8387 | /** |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8388 | * Returns whether vibration is set for voicemail notification in Phone settings. |
| 8389 | * |
| 8390 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 8391 | * voicemail vibration setting. |
| 8392 | * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise. |
| 8393 | */ |
| 8394 | @Override |
| 8395 | public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8396 | final long identity = Binder.clearCallingIdentity(); |
| 8397 | try { |
| 8398 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 8399 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8400 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8401 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8402 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8403 | return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext()); |
| 8404 | } finally { |
| 8405 | Binder.restoreCallingIdentity(identity); |
| 8406 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8407 | } |
| 8408 | |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8409 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8410 | * Sets the per-account voicemail vibration. |
| 8411 | * |
| 8412 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 8413 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 8414 | * |
| 8415 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 8416 | * voicemail vibration setting. |
| 8417 | * @param enabled Whether to enable or disable vibration for voicemail notifications from a |
| 8418 | * specific PhoneAccount. |
| 8419 | */ |
| 8420 | @Override |
| 8421 | public void setVoicemailVibrationEnabled(String callingPackage, |
| 8422 | PhoneAccountHandle phoneAccountHandle, boolean enabled) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8423 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8424 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 8425 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 8426 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8427 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8428 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 8429 | "setVoicemailVibrationEnabled"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8430 | } |
| 8431 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8432 | final long identity = Binder.clearCallingIdentity(); |
| 8433 | try { |
| 8434 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 8435 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8436 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8437 | } |
| 8438 | VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled); |
| 8439 | } finally { |
| 8440 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8441 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8442 | } |
| 8443 | |
| 8444 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8445 | * Make sure either called from same process as self (phone) or IPC caller has read privilege. |
| 8446 | * |
| 8447 | * @throws SecurityException if the caller does not have the required permission |
| 8448 | */ |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 8449 | @VisibleForTesting |
| 8450 | public void enforceReadPrivilegedPermission(String message) { |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8451 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8452 | message); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8453 | } |
| 8454 | |
| 8455 | /** |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 8456 | * Make sure either called from same process as self (phone) or IPC caller has send SMS |
| 8457 | * permission. |
| 8458 | * |
| 8459 | * @throws SecurityException if the caller does not have the required permission |
| 8460 | */ |
| 8461 | private void enforceSendSmsPermission() { |
| 8462 | mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null); |
| 8463 | } |
| 8464 | |
| 8465 | /** |
Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame] | 8466 | * Make sure either called from same process as self (phone) or IPC caller has interact across |
| 8467 | * users permission. |
| 8468 | * |
| 8469 | * @throws SecurityException if the caller does not have the required permission |
| 8470 | */ |
| 8471 | private void enforceInteractAcrossUsersPermission(String message) { |
| 8472 | mApp.enforceCallingOrSelfPermission(permission.INTERACT_ACROSS_USERS, message); |
| 8473 | } |
| 8474 | |
| 8475 | /** |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 8476 | * Make sure called from the package in charge of visual voicemail. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 8477 | * |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 8478 | * @throws SecurityException if the caller is not the visual voicemail package. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 8479 | */ |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 8480 | private void enforceVisualVoicemailPackage(String callingPackage, int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8481 | final long identity = Binder.clearCallingIdentity(); |
| 8482 | try { |
| 8483 | ComponentName componentName = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8484 | RemoteVvmTaskManager.getRemotePackage(mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8485 | if (componentName == null) { |
| 8486 | throw new SecurityException( |
| 8487 | "Caller not current active visual voicemail package[null]"); |
| 8488 | } |
| 8489 | String vvmPackage = componentName.getPackageName(); |
| 8490 | if (!callingPackage.equals(vvmPackage)) { |
Hui Wang | 7f65755 | 2022-08-16 16:58:25 +0000 | [diff] [blame] | 8491 | throw new SecurityException("Caller not current active visual voicemail package"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8492 | } |
| 8493 | } finally { |
| 8494 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 8495 | } |
| 8496 | } |
| 8497 | |
| 8498 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8499 | * Return the application ID for the app type. |
| 8500 | * |
| 8501 | * @param subId the subscription ID that this request applies to. |
| 8502 | * @param appType the uicc app type. |
| 8503 | * @return Application ID for specificied app type, or null if no uicc. |
| 8504 | */ |
| 8505 | @Override |
| 8506 | public String getAidForAppType(int subId, int appType) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8507 | enforceReadPrivilegedPermission("getAidForAppType"); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8508 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8509 | |
| 8510 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8511 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8512 | if (phone == null) { |
| 8513 | return null; |
| 8514 | } |
| 8515 | String aid = null; |
| 8516 | try { |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 8517 | aid = UiccController.getInstance().getUiccPort(phone.getPhoneId()) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8518 | .getApplicationByType(appType).getAid(); |
| 8519 | } catch (Exception e) { |
| 8520 | Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e); |
| 8521 | } |
| 8522 | return aid; |
| 8523 | } finally { |
| 8524 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8525 | } |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8526 | } |
| 8527 | |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8528 | /** |
| 8529 | * Return the Electronic Serial Number. |
| 8530 | * |
| 8531 | * @param subId the subscription ID that this request applies to. |
| 8532 | * @return ESN or null if error. |
| 8533 | */ |
| 8534 | @Override |
| 8535 | public String getEsn(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8536 | enforceReadPrivilegedPermission("getEsn"); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8537 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8538 | |
| 8539 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8540 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8541 | if (phone == null) { |
| 8542 | return null; |
| 8543 | } |
| 8544 | String esn = null; |
| 8545 | try { |
| 8546 | esn = phone.getEsn(); |
| 8547 | } catch (Exception e) { |
| 8548 | Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e); |
| 8549 | } |
| 8550 | return esn; |
| 8551 | } finally { |
| 8552 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8553 | } |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8554 | } |
| 8555 | |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 8556 | /** |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8557 | * Return the Preferred Roaming List Version. |
| 8558 | * |
| 8559 | * @param subId the subscription ID that this request applies to. |
| 8560 | * @return PRLVersion or null if error. |
| 8561 | */ |
| 8562 | @Override |
| 8563 | public String getCdmaPrlVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8564 | enforceReadPrivilegedPermission("getCdmaPrlVersion"); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8565 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8566 | |
| 8567 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8568 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8569 | if (phone == null) { |
| 8570 | return null; |
| 8571 | } |
| 8572 | String cdmaPrlVersion = null; |
| 8573 | try { |
| 8574 | cdmaPrlVersion = phone.getCdmaPrlVersion(); |
| 8575 | } catch (Exception e) { |
| 8576 | Log.e(LOG_TAG, "Not getting PRLVersion", e); |
| 8577 | } |
| 8578 | return cdmaPrlVersion; |
| 8579 | } finally { |
| 8580 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8581 | } |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8582 | } |
| 8583 | |
| 8584 | /** |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 8585 | * Get snapshot of Telephony histograms |
| 8586 | * @return List of Telephony histograms |
| 8587 | * @hide |
| 8588 | */ |
| 8589 | @Override |
| 8590 | public List<TelephonyHistogram> getTelephonyHistograms() { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8591 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8592 | mApp, getDefaultSubscription(), "getTelephonyHistograms"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8593 | |
| 8594 | final long identity = Binder.clearCallingIdentity(); |
| 8595 | try { |
| 8596 | return RIL.getTelephonyRILTimingHistograms(); |
| 8597 | } finally { |
| 8598 | Binder.restoreCallingIdentity(identity); |
| 8599 | } |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 8600 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8601 | |
| 8602 | /** |
| 8603 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8604 | * Set the allowed carrier list and the excluded carrier list, indicating the priority between |
| 8605 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8606 | * Require system privileges. In the future we may add this to carrier APIs. |
| 8607 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8608 | * @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] | 8609 | */ |
| 8610 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8611 | @TelephonyManager.SetCarrierRestrictionResult |
| 8612 | public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) { |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8613 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8614 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8615 | |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8616 | if (carrierRestrictionRules == null) { |
| 8617 | throw new NullPointerException("carrier restriction cannot be null"); |
Meng Wang | 9b7c4e9 | 2017-02-17 11:41:27 -0800 | [diff] [blame] | 8618 | } |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8619 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8620 | final long identity = Binder.clearCallingIdentity(); |
| 8621 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8622 | return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8623 | workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8624 | } finally { |
| 8625 | Binder.restoreCallingIdentity(identity); |
| 8626 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8627 | } |
| 8628 | |
| 8629 | /** |
| 8630 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8631 | * Get the allowed carrier list and the excluded carrier list, including the priority between |
| 8632 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8633 | * Require system privileges. In the future we may add this to carrier APIs. |
| 8634 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8635 | * @return {@link android.telephony.CarrierRestrictionRules} |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8636 | */ |
| 8637 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8638 | public CarrierRestrictionRules getAllowedCarriers() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8639 | enforceReadPrivilegedPermission("getAllowedCarriers"); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8640 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8641 | |
| 8642 | final long identity = Binder.clearCallingIdentity(); |
| 8643 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8644 | Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource); |
| 8645 | if (response instanceof CarrierRestrictionRules) { |
| 8646 | return (CarrierRestrictionRules) response; |
| 8647 | } |
| 8648 | // Response is an Exception of some kind, |
| 8649 | // which is signalled to the user as a NULL retval |
| 8650 | return null; |
| 8651 | } catch (Exception e) { |
| 8652 | Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e); |
| 8653 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8654 | } finally { |
| 8655 | Binder.restoreCallingIdentity(identity); |
| 8656 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8657 | } |
| 8658 | |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 8659 | /** |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 8660 | * Fetches the carrier restriction status of the device and sends the status to the caller |
| 8661 | * through the callback. |
| 8662 | * |
| 8663 | * @param callback The callback that will be used to send the result. |
| 8664 | * @throws SecurityException if the caller does not have the required permission/privileges or |
| 8665 | * the caller is not allowlisted. |
| 8666 | */ |
| 8667 | @Override |
| 8668 | public void getCarrierRestrictionStatus(IIntegerConsumer callback, String packageName) { |
| 8669 | enforceReadPermission("getCarrierRestrictionStatus"); |
| 8670 | int carrierId = validateCallerAndGetCarrierId(packageName); |
| 8671 | if (carrierId == CarrierAllowListInfo.INVALID_CARRIER_ID) { |
| 8672 | Rlog.e(LOG_TAG, "getCarrierRestrictionStatus: caller is not registered"); |
| 8673 | throw new SecurityException("Not an authorized caller"); |
| 8674 | } |
| 8675 | final long identity = Binder.clearCallingIdentity(); |
| 8676 | try { |
| 8677 | Consumer<Integer> consumer = FunctionalUtils.ignoreRemoteException(callback::accept); |
| 8678 | CallerCallbackInfo callbackInfo = new CallerCallbackInfo(consumer, carrierId); |
| 8679 | sendRequestAsync(CMD_GET_ALLOWED_CARRIERS, callbackInfo); |
| 8680 | } finally { |
| 8681 | Binder.restoreCallingIdentity(identity); |
| 8682 | } |
| 8683 | } |
| 8684 | |
| 8685 | @VisibleForTesting |
| 8686 | public int validateCallerAndGetCarrierId(String packageName) { |
| 8687 | CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp); |
| 8688 | return allowListInfo.validateCallerAndGetCarrierId(packageName); |
| 8689 | } |
| 8690 | |
| 8691 | /** |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 8692 | * Action set from carrier signalling broadcast receivers to enable/disable radio |
| 8693 | * @param subId the subscription ID that this action applies to. |
| 8694 | * @param enabled control enable or disable radio. |
| 8695 | * {@hide} |
| 8696 | */ |
| 8697 | @Override |
| 8698 | public void carrierActionSetRadioEnabled(int subId, boolean enabled) { |
| 8699 | enforceModifyPermission(); |
| 8700 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8701 | |
| 8702 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 8703 | if (phone == null) { |
| 8704 | loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId); |
| 8705 | return; |
| 8706 | } |
| 8707 | try { |
| 8708 | phone.carrierActionSetRadioEnabled(enabled); |
| 8709 | } catch (Exception e) { |
| 8710 | Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8711 | } finally { |
| 8712 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 8713 | } |
| 8714 | } |
| 8715 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 8716 | /** |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 8717 | * Enable or disable Voice over NR (VoNR) |
| 8718 | * @param subId the subscription ID that this action applies to. |
| 8719 | * @param enabled enable or disable VoNR. |
| 8720 | * @return operation result. |
| 8721 | */ |
| 8722 | @Override |
| 8723 | public int setVoNrEnabled(int subId, boolean enabled) { |
| 8724 | enforceModifyPermission(); |
| 8725 | final Phone phone = getPhone(subId); |
| 8726 | |
| 8727 | final long identity = Binder.clearCallingIdentity(); |
| 8728 | if (phone == null) { |
| 8729 | loge("setVoNrEnabled fails with no phone object for subId: " + subId); |
| 8730 | return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE; |
| 8731 | } |
| 8732 | |
| 8733 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8734 | try { |
| 8735 | int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId, |
| 8736 | workSource); |
| 8737 | if (DBG) log("setVoNrEnabled result: " + result); |
Gary Jian | 8dd305f | 2021-10-14 16:31:35 +0800 | [diff] [blame] | 8738 | |
| 8739 | if (result == TelephonyManager.ENABLE_VONR_SUCCESS) { |
| 8740 | if (DBG) { |
| 8741 | log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled); |
| 8742 | } |
| 8743 | SubscriptionManager.setSubscriptionProperty( |
| 8744 | subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED, |
| 8745 | (enabled ? "1" : "0")); |
| 8746 | } |
| 8747 | |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 8748 | return result; |
| 8749 | } finally { |
| 8750 | Binder.restoreCallingIdentity(identity); |
| 8751 | } |
| 8752 | } |
| 8753 | |
| 8754 | /** |
| 8755 | * Is voice over NR enabled |
| 8756 | * @return true if VoNR is enabled else false |
| 8757 | */ |
| 8758 | @Override |
| 8759 | public boolean isVoNrEnabled(int subId) { |
| 8760 | enforceReadPrivilegedPermission("isVoNrEnabled"); |
| 8761 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8762 | final long identity = Binder.clearCallingIdentity(); |
| 8763 | try { |
| 8764 | boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED, |
| 8765 | null, subId, workSource); |
| 8766 | if (DBG) log("isVoNrEnabled: " + isEnabled); |
| 8767 | return isEnabled; |
| 8768 | } finally { |
| 8769 | Binder.restoreCallingIdentity(identity); |
| 8770 | } |
| 8771 | } |
| 8772 | |
| 8773 | /** |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 8774 | * Action set from carrier signalling broadcast receivers to start/stop reporting the default |
| 8775 | * network status based on which carrier apps could apply actions accordingly, |
| 8776 | * enable/disable default url handler for example. |
| 8777 | * |
| 8778 | * @param subId the subscription ID that this action applies to. |
| 8779 | * @param report control start/stop reporting the default network status. |
| 8780 | * {@hide} |
| 8781 | */ |
| 8782 | @Override |
| 8783 | public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) { |
| 8784 | enforceModifyPermission(); |
| 8785 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8786 | |
| 8787 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 8788 | if (phone == null) { |
| 8789 | loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId); |
| 8790 | return; |
| 8791 | } |
| 8792 | try { |
| 8793 | phone.carrierActionReportDefaultNetworkStatus(report); |
| 8794 | } catch (Exception e) { |
| 8795 | Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8796 | } finally { |
| 8797 | Binder.restoreCallingIdentity(identity); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 8798 | } |
| 8799 | } |
| 8800 | |
| 8801 | /** |
fionaxu | d962228 | 2017-07-17 17:51:30 -0700 | [diff] [blame] | 8802 | * Action set from carrier signalling broadcast receivers to reset all carrier actions |
| 8803 | * @param subId the subscription ID that this action applies to. |
| 8804 | * {@hide} |
| 8805 | */ |
| 8806 | @Override |
| 8807 | public void carrierActionResetAll(int subId) { |
| 8808 | enforceModifyPermission(); |
| 8809 | final Phone phone = getPhone(subId); |
| 8810 | if (phone == null) { |
| 8811 | loge("carrierAction: ResetAll fails with invalid sibId: " + subId); |
| 8812 | return; |
| 8813 | } |
| 8814 | try { |
| 8815 | phone.carrierActionResetAll(); |
| 8816 | } catch (Exception e) { |
| 8817 | Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e); |
| 8818 | } |
| 8819 | } |
| 8820 | |
| 8821 | /** |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 8822 | * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a |
| 8823 | * bug report is being generated. |
| 8824 | */ |
| 8825 | @Override |
Ta-wei Yen | 99282e0 | 2016-06-21 18:19:35 -0700 | [diff] [blame] | 8826 | protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8827 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 8828 | != PackageManager.PERMISSION_GRANTED) { |
dcashman | 22b950d | 2016-06-27 11:39:02 -0700 | [diff] [blame] | 8829 | writer.println("Permission Denial: can't dump Phone from pid=" |
| 8830 | + Binder.getCallingPid() |
| 8831 | + ", uid=" + Binder.getCallingUid() |
| 8832 | + "without permission " |
| 8833 | + android.Manifest.permission.DUMP); |
| 8834 | return; |
| 8835 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8836 | DumpsysHandler.dump(mApp, fd, writer, args); |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 8837 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 8838 | |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 8839 | @Override |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 8840 | public int handleShellCommand(@NonNull ParcelFileDescriptor in, |
| 8841 | @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err, |
| 8842 | @NonNull String[] args) { |
| 8843 | return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec( |
| 8844 | this, in.getFileDescriptor(), out.getFileDescriptor(), |
| 8845 | err.getFileDescriptor(), args); |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 8846 | } |
| 8847 | |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 8848 | /** |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8849 | * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason} |
Greg Kaiser | 17f4175 | 2020-05-05 16:47:47 +0000 | [diff] [blame] | 8850 | * @param subId Subscription index |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 8851 | * @param reason The reason the data enable change is taking place. |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8852 | * @param enabled True if enabling the data, otherwise disabling. |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 8853 | * @param callingPackage The package that changed the data enabled state. |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8854 | * @hide |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 8855 | */ |
| 8856 | @Override |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 8857 | public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 8858 | boolean enabled, String callingPackage) { |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8859 | if (reason == TelephonyManager.DATA_ENABLED_REASON_USER |
| 8860 | || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 8861 | try { |
| 8862 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 8863 | mApp, subId, "setDataEnabledForReason"); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8864 | } catch (SecurityException se) { |
| 8865 | enforceModifyPermission(); |
| 8866 | } |
| 8867 | } else { |
| 8868 | enforceModifyPermission(); |
| 8869 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8870 | |
| 8871 | final long identity = Binder.clearCallingIdentity(); |
| 8872 | try { |
| 8873 | Phone phone = getPhone(subId); |
| 8874 | if (phone != null) { |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8875 | if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 8876 | phone.carrierActionSetMeteredApnsEnabled(enabled); |
| 8877 | } else { |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 8878 | phone.getDataSettingsManager().setDataEnabled( |
| 8879 | reason, enabled, callingPackage); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8880 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8881 | } |
| 8882 | } finally { |
| 8883 | Binder.restoreCallingIdentity(identity); |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 8884 | } |
| 8885 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8886 | |
| 8887 | /** |
| 8888 | * Get Client request stats |
| 8889 | * @return List of Client Request Stats |
| 8890 | * @hide |
| 8891 | */ |
| 8892 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8893 | public List<ClientRequestStats> getClientRequestStats(String callingPackage, |
| 8894 | String callingFeatureId, int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8895 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8896 | mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) { |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8897 | return null; |
| 8898 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8899 | Phone phone = getPhone(subId); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8900 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8901 | final long identity = Binder.clearCallingIdentity(); |
| 8902 | try { |
| 8903 | if (phone != null) { |
| 8904 | return phone.getClientRequestStats(); |
| 8905 | } |
| 8906 | |
| 8907 | return null; |
| 8908 | } finally { |
| 8909 | Binder.restoreCallingIdentity(identity); |
| 8910 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8911 | } |
| 8912 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 8913 | private WorkSource getWorkSource(int uid) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8914 | String packageName = mApp.getPackageManager().getNameForUid(uid); |
Hunter Knepshield | d03383b | 2022-03-29 22:47:54 +0000 | [diff] [blame] | 8915 | if (uid == Process.ROOT_UID && packageName == null) { |
| 8916 | // Downstream WorkSource attribution inside the RIL requires both a UID and package name |
| 8917 | // to be set for wakelock tracking, otherwise RIL requests fail with a runtime |
| 8918 | // exception. ROOT_UID seems not to have a valid package name returned by |
| 8919 | // PackageManager, so just fake it here to avoid issues when running telephony shell |
| 8920 | // commands that plumb through the RIL as root, like so: |
| 8921 | // $ adb root |
| 8922 | // $ adb shell cmd phone ... |
| 8923 | packageName = "root"; |
| 8924 | } |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 8925 | return new WorkSource(uid, packageName); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8926 | } |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8927 | |
| 8928 | /** |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 8929 | * Set SIM card power state. |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8930 | * |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8931 | * @param slotIndex SIM slot id. |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 8932 | * @param state State of SIM (power down, power up, pass through) |
| 8933 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 8934 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 8935 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8936 | * |
| 8937 | **/ |
| 8938 | @Override |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 8939 | public void setSimPowerStateForSlot(int slotIndex, int state) { |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8940 | enforceModifyPermission(); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8941 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8942 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8943 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8944 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8945 | final long identity = Binder.clearCallingIdentity(); |
| 8946 | try { |
| 8947 | if (phone != null) { |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 8948 | phone.setSimPowerState(state, null, workSource); |
| 8949 | } |
| 8950 | } finally { |
| 8951 | Binder.restoreCallingIdentity(identity); |
| 8952 | } |
| 8953 | } |
| 8954 | |
| 8955 | /** |
| 8956 | * Set SIM card power state. |
| 8957 | * |
| 8958 | * @param slotIndex SIM slot id. |
| 8959 | * @param state State of SIM (power down, power up, pass through) |
| 8960 | * @param callback callback to trigger after success or failure |
| 8961 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 8962 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 8963 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
| 8964 | * |
| 8965 | **/ |
| 8966 | @Override |
| 8967 | public void setSimPowerStateForSlotWithCallback(int slotIndex, int state, |
| 8968 | IIntegerConsumer callback) { |
| 8969 | enforceModifyPermission(); |
| 8970 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8971 | |
| 8972 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8973 | |
| 8974 | final long identity = Binder.clearCallingIdentity(); |
| 8975 | try { |
| 8976 | if (phone != null) { |
| 8977 | Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback); |
| 8978 | sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8979 | } |
| 8980 | } finally { |
| 8981 | Binder.restoreCallingIdentity(identity); |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8982 | } |
| 8983 | } |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8984 | |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 8985 | private boolean isUssdApiAllowed(int subId) { |
| 8986 | CarrierConfigManager configManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8987 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 8988 | if (configManager == null) { |
| 8989 | return false; |
| 8990 | } |
| 8991 | PersistableBundle pb = configManager.getConfigForSubId(subId); |
| 8992 | if (pb == null) { |
| 8993 | return false; |
| 8994 | } |
| 8995 | return pb.getBoolean( |
| 8996 | CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL); |
| 8997 | } |
| 8998 | |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8999 | /** |
| 9000 | * Check if phone is in emergency callback mode |
| 9001 | * @return true if phone is in emergency callback mode |
| 9002 | * @param subId sub id |
| 9003 | */ |
goneil | 9c5f487 | 2017-12-05 14:07:56 -0800 | [diff] [blame] | 9004 | @Override |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 9005 | public boolean getEmergencyCallbackMode(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 9006 | enforceReadPrivilegedPermission("getEmergencyCallbackMode"); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 9007 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9008 | |
| 9009 | final long identity = Binder.clearCallingIdentity(); |
| 9010 | try { |
| 9011 | if (phone != null) { |
| 9012 | return phone.isInEcm(); |
| 9013 | } else { |
| 9014 | return false; |
| 9015 | } |
| 9016 | } finally { |
| 9017 | Binder.restoreCallingIdentity(identity); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 9018 | } |
| 9019 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 9020 | |
| 9021 | /** |
| 9022 | * Get the current signal strength information for the given subscription. |
| 9023 | * Because this information is not updated when the device is in a low power state |
| 9024 | * it should not be relied-upon to be current. |
| 9025 | * @param subId Subscription index |
| 9026 | * @return the most recent cached signal strength info from the modem |
| 9027 | */ |
| 9028 | @Override |
| 9029 | public SignalStrength getSignalStrength(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9030 | final long identity = Binder.clearCallingIdentity(); |
| 9031 | try { |
| 9032 | Phone p = getPhone(subId); |
| 9033 | if (p == null) { |
| 9034 | return null; |
| 9035 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 9036 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9037 | return p.getSignalStrength(); |
| 9038 | } finally { |
| 9039 | Binder.restoreCallingIdentity(identity); |
| 9040 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 9041 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9042 | |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9043 | /** |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 9044 | * Get the current modem radio state for the given slot. |
| 9045 | * @param slotIndex slot index. |
| 9046 | * @param callingPackage the name of the package making the call. |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9047 | * @param callingFeatureId The feature in the package. |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 9048 | * @return the current radio power state from the modem |
| 9049 | */ |
| 9050 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9051 | public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 9052 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 9053 | if (phone != null) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9054 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(), |
| 9055 | callingPackage, callingFeatureId, "getRadioPowerState")) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 9056 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 9057 | } |
| 9058 | |
| 9059 | final long identity = Binder.clearCallingIdentity(); |
| 9060 | try { |
| 9061 | return phone.getRadioPowerState(); |
| 9062 | } finally { |
| 9063 | Binder.restoreCallingIdentity(identity); |
| 9064 | } |
| 9065 | } |
| 9066 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 9067 | } |
| 9068 | |
| 9069 | /** |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9070 | * Checks if data roaming is enabled on the subscription with id {@code subId}. |
| 9071 | * |
| 9072 | * <p>Requires one of the following permissions: |
| 9073 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}, |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 9074 | * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE}, |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9075 | * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier |
| 9076 | * privileges. |
| 9077 | * |
| 9078 | * @param subId subscription id |
| 9079 | * @return {@code true} if data roaming is enabled on this subscription, otherwise return |
| 9080 | * {@code false}. |
| 9081 | */ |
| 9082 | @Override |
| 9083 | public boolean isDataRoamingEnabled(int subId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 9084 | String functionName = "isDataRoamingEnabled"; |
Shuo Qian | 093013d | 2020-08-13 15:42:55 -0700 | [diff] [blame] | 9085 | try { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 9086 | try { |
| 9087 | mApp.enforceCallingOrSelfPermission( |
| 9088 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 9089 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 9090 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 9091 | mApp.enforceCallingOrSelfPermission( |
| 9092 | permission.READ_BASIC_PHONE_STATE, functionName); |
| 9093 | } |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 9094 | } catch (SecurityException e) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9095 | TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 9096 | mApp, subId, functionName); |
Shuo Qian | 093013d | 2020-08-13 15:42:55 -0700 | [diff] [blame] | 9097 | } |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 9098 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9099 | boolean isEnabled = false; |
| 9100 | final long identity = Binder.clearCallingIdentity(); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9101 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9102 | Phone phone = getPhone(subId); |
| 9103 | isEnabled = phone != null ? phone.getDataRoamingEnabled() : false; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9104 | } finally { |
| 9105 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9106 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9107 | return isEnabled; |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9108 | } |
| 9109 | |
| 9110 | |
| 9111 | /** |
| 9112 | * Enables/Disables the data roaming on the subscription with id {@code subId}. |
| 9113 | * |
| 9114 | * <p> Requires permission: |
| 9115 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier |
| 9116 | * privileges. |
| 9117 | * |
| 9118 | * @param subId subscription id |
| 9119 | * @param isEnabled {@code true} means enable, {@code false} means disable. |
| 9120 | */ |
| 9121 | @Override |
| 9122 | public void setDataRoamingEnabled(int subId, boolean isEnabled) { |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 9123 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9124 | mApp, subId, "setDataRoamingEnabled"); |
| 9125 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9126 | final long identity = Binder.clearCallingIdentity(); |
| 9127 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9128 | Phone phone = getPhone(subId); |
| 9129 | if (phone != null) { |
| 9130 | phone.setDataRoamingEnabled(isEnabled); |
| 9131 | } |
| 9132 | } finally { |
| 9133 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9134 | } |
| 9135 | } |
| 9136 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9137 | @Override |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 9138 | public boolean isManualNetworkSelectionAllowed(int subId) { |
tom hsu | c91afc7 | 2020-01-06 23:46:07 +0800 | [diff] [blame] | 9139 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9140 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 9141 | mApp, subId, "isManualNetworkSelectionAllowed"); |
| 9142 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 9143 | boolean isAllowed = true; |
| 9144 | final long identity = Binder.clearCallingIdentity(); |
| 9145 | try { |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 9146 | Phone phone = getPhone(subId); |
| 9147 | if (phone != null) { |
| 9148 | isAllowed = phone.isCspPlmnEnabled(); |
| 9149 | } |
| 9150 | } finally { |
| 9151 | Binder.restoreCallingIdentity(identity); |
| 9152 | } |
| 9153 | return isAllowed; |
| 9154 | } |
| 9155 | |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9156 | private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) { |
| 9157 | UiccProfile profile = port.getUiccProfile(); |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 9158 | if (profile == null) { |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9159 | return false; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9160 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 9161 | Phone phone = PhoneFactory.getPhone(profile.getPhoneId()); |
| 9162 | if (phone == null) { |
| 9163 | return false; |
| 9164 | } |
| 9165 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 9166 | return cpt != null && cpt.getCarrierPrivilegeStatusForPackage(callingPackage) |
| 9167 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9168 | } |
| 9169 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 9170 | @Override |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 9171 | public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) { |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9172 | // Verify that the callingPackage belongs to the calling UID |
Jordan Liu | 4cda455 | 2020-03-23 11:55:07 -0700 | [diff] [blame] | 9173 | mApp.getSystemService(AppOpsManager.class) |
| 9174 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 9175 | |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9176 | boolean hasReadPermission = false; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9177 | boolean isIccIdAccessRestricted = false; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 9178 | try { |
| 9179 | enforceReadPrivilegedPermission("getUiccCardsInfo"); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9180 | hasReadPermission = true; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 9181 | } catch (SecurityException e) { |
| 9182 | // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller |
| 9183 | // has carrier privileges on an active UICC |
Rambo Wang | e7209ce | 2022-02-23 13:41:02 -0800 | [diff] [blame] | 9184 | if (checkCarrierPrivilegesForPackageAnyPhoneWithPermission(callingPackage) |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 9185 | != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9186 | throw new SecurityException("Caller does not have permission."); |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 9187 | } |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 9188 | } |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9189 | // checking compatibility, if calling app's target SDK is T and beyond. |
| 9190 | if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO, |
| 9191 | Binder.getCallingUid())) { |
| 9192 | isIccIdAccessRestricted = true; |
| 9193 | } |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 9194 | final long identity = Binder.clearCallingIdentity(); |
| 9195 | try { |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 9196 | UiccController uiccController = UiccController.getInstance(); |
| 9197 | ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos(); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9198 | if (hasReadPermission) { |
| 9199 | return cardInfos; |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 9200 | } |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9201 | |
| 9202 | // Remove private info if the caller doesn't have access |
| 9203 | ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>(); |
| 9204 | for (UiccCardInfo cardInfo : cardInfos) { |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9205 | //setting the value after compatibility check |
| 9206 | cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9207 | // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo |
| 9208 | // is available |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9209 | UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex()); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9210 | if (card == null) { |
| 9211 | // assume no access if the card is unavailable |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9212 | filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo)); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9213 | continue; |
| 9214 | } |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9215 | Collection<UiccPortInfo> portInfos = cardInfo.getPorts(); |
| 9216 | if (portInfos.isEmpty()) { |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9217 | filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo)); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9218 | continue; |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9219 | } |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9220 | List<UiccPortInfo> uiccPortInfos = new ArrayList<>(); |
| 9221 | for (UiccPortInfo portInfo : portInfos) { |
| 9222 | UiccPort port = uiccController.getUiccPortForSlot( |
| 9223 | cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex()); |
| 9224 | if (port == null) { |
| 9225 | // assume no access if port is null |
| 9226 | uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo)); |
| 9227 | continue; |
| 9228 | } |
| 9229 | if (haveCarrierPrivilegeAccess(port, callingPackage)) { |
| 9230 | uiccPortInfos.add(portInfo); |
| 9231 | } else { |
| 9232 | uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo)); |
| 9233 | } |
| 9234 | } |
| 9235 | filteredInfos.add(new UiccCardInfo( |
| 9236 | cardInfo.isEuicc(), |
| 9237 | cardInfo.getCardId(), |
| 9238 | null, |
| 9239 | cardInfo.getPhysicalSlotIndex(), |
| 9240 | cardInfo.isRemovable(), |
| 9241 | cardInfo.isMultipleEnabledProfilesSupported(), |
| 9242 | uiccPortInfos)); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9243 | } |
| 9244 | return filteredInfos; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 9245 | } finally { |
| 9246 | Binder.restoreCallingIdentity(identity); |
| 9247 | } |
| 9248 | } |
| 9249 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9250 | /** |
| 9251 | * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are |
| 9252 | * generally private and require carrier privileges to view. |
| 9253 | * |
| 9254 | * @hide |
| 9255 | */ |
| 9256 | @NonNull |
| 9257 | public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) { |
| 9258 | List<UiccPortInfo> portinfo = new ArrayList<>(); |
| 9259 | for (UiccPortInfo portinfos : cardInfo.getPorts()) { |
| 9260 | portinfo.add(getUiccPortInfoUnPrivileged(portinfos)); |
| 9261 | } |
| 9262 | return new UiccCardInfo( |
| 9263 | cardInfo.isEuicc(), |
| 9264 | cardInfo.getCardId(), |
| 9265 | null, |
| 9266 | cardInfo.getPhysicalSlotIndex(), |
| 9267 | cardInfo.isRemovable(), |
| 9268 | cardInfo.isMultipleEnabledProfilesSupported(), |
| 9269 | portinfo |
| 9270 | ); |
| 9271 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9272 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9273 | /** |
| 9274 | * @hide |
| 9275 | * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}. |
| 9276 | * These values are generally private and require carrier privileges to view. |
| 9277 | */ |
| 9278 | @NonNull |
| 9279 | public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) { |
| 9280 | return new UiccPortInfo( |
| 9281 | UiccPortInfo.ICCID_REDACTED, |
| 9282 | portInfo.getPortIndex(), |
| 9283 | portInfo.getLogicalSlotIndex(), |
| 9284 | portInfo.isActive() |
| 9285 | ); |
| 9286 | } |
| 9287 | @Override |
| 9288 | public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) { |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9289 | // Verify that the callingPackage belongs to the calling UID |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9290 | mApp.getSystemService(AppOpsManager.class) |
| 9291 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 9292 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9293 | boolean isLogicalSlotAccessRestricted = false; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9294 | |
Aman Gupta | f3c90b3 | 2022-03-17 04:54:16 +0000 | [diff] [blame] | 9295 | // This will make sure caller has the READ_PRIVILEGED_PHONE_STATE. Do not remove this as |
| 9296 | // we are reading iccId which is PII data. |
| 9297 | enforceReadPrivilegedPermission("getUiccSlotsInfo"); |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9298 | |
| 9299 | // checking compatibility, if calling app's target SDK is T and beyond. |
| 9300 | if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO, |
| 9301 | Binder.getCallingUid())) { |
| 9302 | isLogicalSlotAccessRestricted = true; |
| 9303 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9304 | final long identity = Binder.clearCallingIdentity(); |
| 9305 | try { |
| 9306 | UiccSlot[] slots = UiccController.getInstance().getUiccSlots(); |
Muralidhar Reddy | d196bbf | 2022-01-17 17:56:30 +0000 | [diff] [blame] | 9307 | if (slots == null || slots.length == 0) { |
| 9308 | Rlog.i(LOG_TAG, "slots is null or empty."); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9309 | return null; |
| 9310 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9311 | UiccSlotInfo[] infos = new UiccSlotInfo[slots.length]; |
| 9312 | for (int i = 0; i < slots.length; i++) { |
| 9313 | UiccSlot slot = slots[i]; |
| 9314 | if (slot == null) { |
| 9315 | continue; |
| 9316 | } |
| 9317 | |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 9318 | String cardId; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9319 | UiccCard card = slot.getUiccCard(); |
| 9320 | if (card != null) { |
| 9321 | cardId = card.getCardId(); |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 9322 | } else { |
Jordan Liu | 01bd00d | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 9323 | cardId = slot.getEid(); |
| 9324 | if (TextUtils.isEmpty(cardId)) { |
Aman Gupta | f3c90b3 | 2022-03-17 04:54:16 +0000 | [diff] [blame] | 9325 | // If cardId is null, use iccId of default port as cardId. |
| 9326 | cardId = slot.getIccId(TelephonyManager.DEFAULT_PORT_INDEX); |
Jordan Liu | 01bd00d | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 9327 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9328 | } |
| 9329 | |
Jordan Liu | 857451f | 2019-05-09 16:35:35 -0700 | [diff] [blame] | 9330 | if (cardId != null) { |
| 9331 | // if cardId is an ICCID, strip off trailing Fs before exposing to user |
| 9332 | // if cardId is an EID, it's all digits so this is fine |
| 9333 | cardId = IccUtils.stripTrailingFs(cardId); |
| 9334 | } |
| 9335 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9336 | int cardState = 0; |
| 9337 | switch (slot.getCardState()) { |
| 9338 | case CARDSTATE_ABSENT: |
| 9339 | cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT; |
| 9340 | break; |
| 9341 | case CARDSTATE_PRESENT: |
| 9342 | cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT; |
| 9343 | break; |
| 9344 | case CARDSTATE_ERROR: |
| 9345 | cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR; |
| 9346 | break; |
| 9347 | case CARDSTATE_RESTRICTED: |
| 9348 | cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED; |
| 9349 | break; |
| 9350 | default: |
| 9351 | break; |
| 9352 | |
| 9353 | } |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9354 | List<UiccPortInfo> portInfos = new ArrayList<>(); |
| 9355 | int[] portIndexes = slot.getPortList(); |
| 9356 | for (int portIdx : portIndexes) { |
| 9357 | String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx, |
Aman Gupta | f3c90b3 | 2022-03-17 04:54:16 +0000 | [diff] [blame] | 9358 | callingPackage, /* hasReadPermission= */ true)); |
Muralidhar Reddy | fbcff0c | 2022-01-19 13:07:57 +0000 | [diff] [blame] | 9359 | portInfos.add(new UiccPortInfo(iccId, portIdx, |
| 9360 | slot.getPhoneIdFromPortIndex(portIdx), slot.isPortActive(portIdx))); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9361 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9362 | infos[i] = new UiccSlotInfo( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9363 | slot.isEuicc(), |
| 9364 | cardId, |
| 9365 | cardState, |
Jordan Liu | a261958 | 2019-02-14 12:56:40 -0800 | [diff] [blame] | 9366 | slot.isExtendedApduSupported(), |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9367 | slot.isRemovable(), portInfos); |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9368 | //setting the value after compatibility check |
| 9369 | infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9370 | } |
| 9371 | return infos; |
| 9372 | } finally { |
| 9373 | Binder.restoreCallingIdentity(identity); |
Holly Jiuyu Sun | 1d957c5 | 2018-04-04 13:52:42 -0700 | [diff] [blame] | 9374 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9375 | } |
| 9376 | |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9377 | /* Returns null if doesn't have read permission or carrier privilege access. */ |
| 9378 | private String getIccId(UiccSlot slot, int portIndex, String callingPackage, |
| 9379 | boolean hasReadPermission) { |
| 9380 | String iccId = slot.getIccId(portIndex); |
| 9381 | if (hasReadPermission) { // if has read permission |
| 9382 | return iccId; |
| 9383 | } else { |
| 9384 | if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) { |
| 9385 | UiccPort port = slot.getUiccCard().getUiccPort(portIndex); |
| 9386 | // if no read permission, checking carrier privilege access |
| 9387 | if (haveCarrierPrivilegeAccess(port, callingPackage)) { |
| 9388 | return iccId; |
| 9389 | } |
| 9390 | } |
| 9391 | } |
| 9392 | // No read permission or carrier privilege access. |
| 9393 | return UiccPortInfo.ICCID_REDACTED; |
| 9394 | } |
| 9395 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9396 | @Override |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9397 | @Deprecated |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9398 | public boolean switchSlots(int[] physicalSlots) { |
| 9399 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9400 | |
| 9401 | final long identity = Binder.clearCallingIdentity(); |
| 9402 | try { |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9403 | List<UiccSlotMapping> slotMappings = new ArrayList<>(); |
| 9404 | for (int i = 0; i < physicalSlots.length; i++) { |
| 9405 | // Deprecated API, hence MEP is not supported. Adding default portIndex 0. |
| 9406 | slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX, |
| 9407 | physicalSlots[i], i)); |
| 9408 | } |
| 9409 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9410 | } finally { |
| 9411 | Binder.restoreCallingIdentity(identity); |
| 9412 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9413 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 9414 | |
| 9415 | @Override |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9416 | @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 9417 | public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) { |
| 9418 | enforceModifyPermission(); |
| 9419 | |
| 9420 | final long identity = Binder.clearCallingIdentity(); |
| 9421 | try { |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9422 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping); |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9423 | } finally { |
| 9424 | Binder.restoreCallingIdentity(identity); |
| 9425 | } |
| 9426 | } |
| 9427 | |
| 9428 | @Override |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 9429 | public int getCardIdForDefaultEuicc(int subId, String callingPackage) { |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 9430 | final long identity = Binder.clearCallingIdentity(); |
| 9431 | try { |
| 9432 | return UiccController.getInstance().getCardIdForDefaultEuicc(); |
| 9433 | } finally { |
| 9434 | Binder.restoreCallingIdentity(identity); |
| 9435 | } |
| 9436 | } |
| 9437 | |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9438 | /** |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 9439 | * A test API to reload the UICC profile. |
| 9440 | * |
| 9441 | * <p>Requires that the calling app has permission |
| 9442 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 9443 | * @hide |
| 9444 | */ |
| 9445 | @Override |
| 9446 | public void refreshUiccProfile(int subId) { |
| 9447 | enforceModifyPermission(); |
| 9448 | |
| 9449 | final long identity = Binder.clearCallingIdentity(); |
| 9450 | try { |
| 9451 | Phone phone = getPhone(subId); |
| 9452 | if (phone == null) { |
| 9453 | return; |
| 9454 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9455 | UiccPort uiccPort = phone.getUiccPort(); |
| 9456 | if (uiccPort == null) { |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 9457 | return; |
| 9458 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9459 | UiccProfile uiccProfile = uiccPort.getUiccProfile(); |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 9460 | if (uiccProfile == null) { |
| 9461 | return; |
| 9462 | } |
| 9463 | uiccProfile.refresh(); |
| 9464 | } finally { |
| 9465 | Binder.restoreCallingIdentity(identity); |
| 9466 | } |
| 9467 | } |
| 9468 | |
| 9469 | /** |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9470 | * Returns false if the mobile data is disabled by default, otherwise return true. |
| 9471 | */ |
| 9472 | private boolean getDefaultDataEnabled() { |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 9473 | return TelephonyProperties.mobile_data().orElse(true); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9474 | } |
| 9475 | |
| 9476 | /** |
| 9477 | * Returns true if the data roaming is enabled by default, i.e the system property |
| 9478 | * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of |
| 9479 | * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true. |
| 9480 | */ |
| 9481 | private boolean getDefaultDataRoamingEnabled(int subId) { |
| 9482 | final CarrierConfigManager configMgr = (CarrierConfigManager) |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9483 | mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Shuo Qian | 1d84a0e | 2020-07-15 12:36:44 -0700 | [diff] [blame] | 9484 | boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9485 | isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean( |
| 9486 | CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL); |
| 9487 | return isDataRoamingEnabled; |
| 9488 | } |
| 9489 | |
| 9490 | /** |
| 9491 | * Returns the default network type for the given {@code subId}, if the default network type is |
| 9492 | * not set, return {@link Phone#PREFERRED_NT_MODE}. |
| 9493 | */ |
| 9494 | private int getDefaultNetworkType(int subId) { |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 9495 | List<Integer> list = TelephonyProperties.default_network(); |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 9496 | int phoneId = SubscriptionManager.getPhoneId(subId); |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 9497 | if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) { |
| 9498 | return list.get(phoneId); |
| 9499 | } |
| 9500 | return Phone.PREFERRED_NT_MODE; |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9501 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9502 | |
| 9503 | @Override |
| 9504 | public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 9505 | gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) { |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9506 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9507 | |
| 9508 | final long identity = Binder.clearCallingIdentity(); |
| 9509 | try { |
| 9510 | final Phone phone = getPhone(subId); |
| 9511 | if (phone == null) { |
| 9512 | loge("setCarrierTestOverride fails with invalid subId: " + subId); |
| 9513 | return; |
| 9514 | } |
Rambo Wang | 9c9ffdd | 2022-01-13 21:51:44 -0800 | [diff] [blame] | 9515 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 9516 | if (cpt != null) { |
| 9517 | cpt.setTestOverrideCarrierPrivilegeRules(carrierPrivilegeRules); |
| 9518 | } |
| 9519 | // 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] | 9520 | phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn, |
| 9521 | carrierPrivilegeRules, apn); |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 9522 | if (carrierPrivilegeRules == null) { |
| 9523 | mCarrierPrivilegeTestOverrideSubIds.remove(subId); |
| 9524 | } else { |
| 9525 | mCarrierPrivilegeTestOverrideSubIds.add(subId); |
| 9526 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9527 | } finally { |
| 9528 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9529 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9530 | } |
| 9531 | |
| 9532 | @Override |
| 9533 | public int getCarrierIdListVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 9534 | enforceReadPrivilegedPermission("getCarrierIdListVersion"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9535 | |
| 9536 | final long identity = Binder.clearCallingIdentity(); |
| 9537 | try { |
| 9538 | final Phone phone = getPhone(subId); |
| 9539 | if (phone == null) { |
| 9540 | loge("getCarrierIdListVersion fails with invalid subId: " + subId); |
| 9541 | return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION; |
| 9542 | } |
| 9543 | return phone.getCarrierIdListVersion(); |
| 9544 | } finally { |
| 9545 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9546 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9547 | } |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 9548 | |
| 9549 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9550 | public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage, |
| 9551 | String callingFeatureId) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 9552 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9553 | mApp, subId, callingPackage, callingFeatureId, |
| 9554 | "getNumberOfModemsWithSimultaneousDataConnections")) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 9555 | return -1; |
| 9556 | } |
| 9557 | |
| 9558 | final long identity = Binder.clearCallingIdentity(); |
| 9559 | try { |
| 9560 | return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections(); |
| 9561 | } finally { |
| 9562 | Binder.restoreCallingIdentity(identity); |
| 9563 | } |
| 9564 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9565 | |
| 9566 | @Override |
| 9567 | public int getCdmaRoamingMode(int subId) { |
zoey chen | 7e6d4e5 | 2019-12-17 18:18:59 +0800 | [diff] [blame] | 9568 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9569 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9570 | mApp, subId, "getCdmaRoamingMode"); |
| 9571 | |
| 9572 | final long identity = Binder.clearCallingIdentity(); |
| 9573 | try { |
| 9574 | return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId); |
| 9575 | } finally { |
| 9576 | Binder.restoreCallingIdentity(identity); |
| 9577 | } |
| 9578 | } |
| 9579 | |
| 9580 | @Override |
| 9581 | public boolean setCdmaRoamingMode(int subId, int mode) { |
| 9582 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9583 | mApp, subId, "setCdmaRoamingMode"); |
| 9584 | |
| 9585 | final long identity = Binder.clearCallingIdentity(); |
| 9586 | try { |
| 9587 | return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId); |
| 9588 | } finally { |
| 9589 | Binder.restoreCallingIdentity(identity); |
| 9590 | } |
| 9591 | } |
| 9592 | |
| 9593 | @Override |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 9594 | public int getCdmaSubscriptionMode(int subId) { |
| 9595 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9596 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 9597 | mApp, subId, "getCdmaSubscriptionMode"); |
| 9598 | |
| 9599 | final long identity = Binder.clearCallingIdentity(); |
| 9600 | try { |
| 9601 | return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId); |
| 9602 | } finally { |
| 9603 | Binder.restoreCallingIdentity(identity); |
| 9604 | } |
| 9605 | } |
| 9606 | |
| 9607 | @Override |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9608 | public boolean setCdmaSubscriptionMode(int subId, int mode) { |
| 9609 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9610 | mApp, subId, "setCdmaSubscriptionMode"); |
| 9611 | |
| 9612 | final long identity = Binder.clearCallingIdentity(); |
| 9613 | try { |
| 9614 | return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId); |
| 9615 | } finally { |
| 9616 | Binder.restoreCallingIdentity(identity); |
| 9617 | } |
| 9618 | } |
Makoto Onuki | da3bf79 | 2018-09-18 16:06:29 -0700 | [diff] [blame] | 9619 | |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 9620 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 9621 | public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9622 | String callingPackage, String callingFeatureId) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9623 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9624 | mApp, getDefaultSubscription(), callingPackage, callingFeatureId, |
| 9625 | "getEmergencyNumberList")) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9626 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 9627 | } |
| 9628 | final long identity = Binder.clearCallingIdentity(); |
| 9629 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 9630 | Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>(); |
| 9631 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9632 | if (phone.getEmergencyNumberTracker() != null |
| 9633 | && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) { |
| 9634 | emergencyNumberListInternal.put( |
| 9635 | phone.getSubId(), |
| 9636 | phone.getEmergencyNumberTracker().getEmergencyNumberList()); |
| 9637 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9638 | } |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 9639 | return emergencyNumberListInternal; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9640 | } finally { |
| 9641 | Binder.restoreCallingIdentity(identity); |
| 9642 | } |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 9643 | } |
| 9644 | |
| 9645 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 9646 | public boolean isEmergencyNumber(String number, boolean exactMatch) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9647 | final Phone defaultPhone = getDefaultPhone(); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9648 | if (!exactMatch) { |
| 9649 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9650 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 9651 | mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)"); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9652 | } |
| 9653 | final long identity = Binder.clearCallingIdentity(); |
| 9654 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 9655 | for (Phone phone: PhoneFactory.getPhones()) { |
Chinmay Dhodapkar | d521bb1 | 2022-08-16 15:49:54 -0700 | [diff] [blame] | 9656 | //Note: we ignore passed in param exactMatch. We can remove it once |
| 9657 | // TelephonyManager#isPotentialEmergencyNumber is removed completely |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 9658 | if (phone.getEmergencyNumberTracker() != null |
Taesu Lee | e050c00 | 2020-10-13 17:19:35 +0900 | [diff] [blame] | 9659 | && phone.getEmergencyNumberTracker() |
Chinmay Dhodapkar | d521bb1 | 2022-08-16 15:49:54 -0700 | [diff] [blame] | 9660 | .isEmergencyNumber(number)) { |
Taesu Lee | e050c00 | 2020-10-13 17:19:35 +0900 | [diff] [blame] | 9661 | return true; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9662 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9663 | } |
| 9664 | return false; |
| 9665 | } finally { |
| 9666 | Binder.restoreCallingIdentity(identity); |
| 9667 | } |
| 9668 | } |
| 9669 | |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 9670 | /** |
Shuo Qian | ccbaf74 | 2021-02-22 18:32:21 -0800 | [diff] [blame] | 9671 | * Start emergency callback mode for GsmCdmaPhone for testing. |
| 9672 | */ |
| 9673 | @Override |
| 9674 | public void startEmergencyCallbackMode() { |
| 9675 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9676 | "startEmergencyCallbackMode"); |
| 9677 | enforceModifyPermission(); |
| 9678 | final long identity = Binder.clearCallingIdentity(); |
| 9679 | try { |
| 9680 | for (Phone phone : PhoneFactory.getPhones()) { |
| 9681 | Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType()); |
| 9682 | if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM) |
| 9683 | || (phone.getPhoneType() == PHONE_TYPE_CDMA))) { |
| 9684 | GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone; |
| 9685 | gsmCdmaPhone.obtainMessage( |
| 9686 | GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget(); |
| 9687 | Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered"); |
| 9688 | } |
| 9689 | } |
| 9690 | } finally { |
| 9691 | Binder.restoreCallingIdentity(identity); |
| 9692 | } |
| 9693 | } |
| 9694 | |
| 9695 | /** |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 9696 | * Update emergency number list for test mode. |
| 9697 | */ |
| 9698 | @Override |
| 9699 | public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) { |
| 9700 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9701 | "updateEmergencyNumberListTestMode"); |
| 9702 | |
| 9703 | final long identity = Binder.clearCallingIdentity(); |
| 9704 | try { |
| 9705 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9706 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9707 | if (tracker != null) { |
| 9708 | tracker.executeEmergencyNumberTestModeCommand(action, num); |
| 9709 | } |
| 9710 | } |
| 9711 | } finally { |
| 9712 | Binder.restoreCallingIdentity(identity); |
| 9713 | } |
| 9714 | } |
| 9715 | |
| 9716 | /** |
| 9717 | * Get the full emergency number list for test mode. |
| 9718 | */ |
| 9719 | @Override |
| 9720 | public List<String> getEmergencyNumberListTestMode() { |
| 9721 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9722 | "getEmergencyNumberListTestMode"); |
| 9723 | |
| 9724 | final long identity = Binder.clearCallingIdentity(); |
| 9725 | try { |
| 9726 | Set<String> emergencyNumbers = new HashSet<>(); |
| 9727 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9728 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9729 | if (tracker != null) { |
| 9730 | for (EmergencyNumber num : tracker.getEmergencyNumberList()) { |
| 9731 | emergencyNumbers.add(num.getNumber()); |
| 9732 | } |
| 9733 | } |
| 9734 | } |
| 9735 | return new ArrayList<>(emergencyNumbers); |
| 9736 | } finally { |
| 9737 | Binder.restoreCallingIdentity(identity); |
| 9738 | } |
| 9739 | } |
| 9740 | |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 9741 | @Override |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 9742 | public int getEmergencyNumberDbVersion(int subId) { |
| 9743 | enforceReadPrivilegedPermission("getEmergencyNumberDbVersion"); |
| 9744 | |
| 9745 | final long identity = Binder.clearCallingIdentity(); |
| 9746 | try { |
| 9747 | final Phone phone = getPhone(subId); |
| 9748 | if (phone == null) { |
| 9749 | loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId); |
| 9750 | return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION; |
| 9751 | } |
| 9752 | return phone.getEmergencyNumberDbVersion(); |
| 9753 | } finally { |
| 9754 | Binder.restoreCallingIdentity(identity); |
| 9755 | } |
| 9756 | } |
| 9757 | |
| 9758 | @Override |
| 9759 | public void notifyOtaEmergencyNumberDbInstalled() { |
| 9760 | enforceModifyPermission(); |
| 9761 | |
| 9762 | final long identity = Binder.clearCallingIdentity(); |
| 9763 | try { |
| 9764 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9765 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9766 | if (tracker != null) { |
| 9767 | tracker.updateOtaEmergencyNumberDatabase(); |
| 9768 | } |
| 9769 | } |
| 9770 | } finally { |
| 9771 | Binder.restoreCallingIdentity(identity); |
| 9772 | } |
| 9773 | } |
| 9774 | |
| 9775 | @Override |
Shuo Qian | c373f11 | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 9776 | public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) { |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 9777 | enforceActiveEmergencySessionPermission(); |
| 9778 | |
| 9779 | final long identity = Binder.clearCallingIdentity(); |
| 9780 | try { |
| 9781 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9782 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9783 | if (tracker != null) { |
Shuo Qian | c373f11 | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 9784 | tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor); |
| 9785 | } |
| 9786 | } |
| 9787 | } finally { |
| 9788 | Binder.restoreCallingIdentity(identity); |
| 9789 | } |
| 9790 | } |
| 9791 | |
| 9792 | @Override |
| 9793 | public void resetOtaEmergencyNumberDbFilePath() { |
| 9794 | enforceActiveEmergencySessionPermission(); |
| 9795 | |
| 9796 | final long identity = Binder.clearCallingIdentity(); |
| 9797 | try { |
| 9798 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9799 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9800 | if (tracker != null) { |
| 9801 | tracker.resetOtaEmergencyNumberDbFilePath(); |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 9802 | } |
| 9803 | } |
| 9804 | } finally { |
| 9805 | Binder.restoreCallingIdentity(identity); |
| 9806 | } |
| 9807 | } |
| 9808 | |
| 9809 | @Override |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 9810 | public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) { |
| 9811 | enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules"); |
| 9812 | Phone phone = getPhone(subId); |
| 9813 | if (phone == null) { |
| 9814 | return null; |
| 9815 | } |
| 9816 | final long identity = Binder.clearCallingIdentity(); |
| 9817 | try { |
| 9818 | UiccProfile profile = UiccController.getInstance() |
| 9819 | .getUiccProfileForPhone(phone.getPhoneId()); |
| 9820 | if (profile != null) { |
| 9821 | return profile.getCertsFromCarrierPrivilegeAccessRules(); |
| 9822 | } |
| 9823 | } finally { |
| 9824 | Binder.restoreCallingIdentity(identity); |
| 9825 | } |
| 9826 | return null; |
| 9827 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 9828 | |
| 9829 | /** |
| 9830 | * Enable or disable a modem stack. |
| 9831 | */ |
| 9832 | @Override |
| 9833 | public boolean enableModemForSlot(int slotIndex, boolean enable) { |
| 9834 | enforceModifyPermission(); |
| 9835 | |
| 9836 | final long identity = Binder.clearCallingIdentity(); |
| 9837 | try { |
| 9838 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 9839 | if (phone == null) { |
| 9840 | return false; |
| 9841 | } else { |
| 9842 | return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null); |
| 9843 | } |
| 9844 | } finally { |
| 9845 | Binder.restoreCallingIdentity(identity); |
| 9846 | } |
| 9847 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9848 | |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 9849 | /** |
| 9850 | * Whether a modem stack is enabled or not. |
| 9851 | */ |
| 9852 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9853 | public boolean isModemEnabledForSlot(int slotIndex, String callingPackage, |
| 9854 | String callingFeatureId) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 9855 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 9856 | if (phone == null) return false; |
| 9857 | |
| 9858 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9859 | mApp, phone.getSubId(), callingPackage, callingFeatureId, |
| 9860 | "isModemEnabledForSlot")) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 9861 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 9862 | } |
| 9863 | |
| 9864 | final long identity = Binder.clearCallingIdentity(); |
| 9865 | try { |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 9866 | try { |
| 9867 | return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId()); |
| 9868 | } catch (NoSuchElementException ex) { |
| 9869 | return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null); |
| 9870 | } |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 9871 | } finally { |
| 9872 | Binder.restoreCallingIdentity(identity); |
| 9873 | } |
| 9874 | } |
| 9875 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9876 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9877 | public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) { |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9878 | enforceModifyPermission(); |
| 9879 | |
| 9880 | final long identity = Binder.clearCallingIdentity(); |
| 9881 | try { |
| 9882 | mTelephonySharedPreferences.edit() |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9883 | .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted) |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9884 | .commit(); |
| 9885 | } finally { |
| 9886 | Binder.restoreCallingIdentity(identity); |
| 9887 | } |
| 9888 | } |
| 9889 | |
| 9890 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9891 | @TelephonyManager.IsMultiSimSupportedResult |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9892 | public int isMultiSimSupported(String callingPackage, String callingFeatureId) { |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 9893 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9894 | getDefaultPhone().getSubId(), callingPackage, callingFeatureId, |
| 9895 | "isMultiSimSupported")) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9896 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 9897 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9898 | |
| 9899 | final long identity = Binder.clearCallingIdentity(); |
| 9900 | try { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9901 | return isMultiSimSupportedInternal(); |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9902 | } finally { |
| 9903 | Binder.restoreCallingIdentity(identity); |
| 9904 | } |
| 9905 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9906 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9907 | @TelephonyManager.IsMultiSimSupportedResult |
| 9908 | private int isMultiSimSupportedInternal() { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9909 | // If the device has less than 2 SIM cards, indicate that multisim is restricted. |
| 9910 | int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length; |
| 9911 | if (numPhysicalSlots < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9912 | loge("isMultiSimSupportedInternal: requires at least 2 cards"); |
| 9913 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9914 | } |
| 9915 | // Check if the hardware supports multisim functionality. If usage of multisim is not |
| 9916 | // supported by the modem, indicate that it is restricted. |
| 9917 | PhoneCapability staticCapability = |
| 9918 | mPhoneConfigurationManager.getStaticPhoneCapability(); |
| 9919 | if (staticCapability == null) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9920 | loge("isMultiSimSupportedInternal: no static configuration available"); |
| 9921 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9922 | } |
SongFerngWang | 8236caa | 2021-01-17 21:51:44 +0800 | [diff] [blame] | 9923 | if (staticCapability.getLogicalModemList().size() < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9924 | loge("isMultiSimSupportedInternal: maximum number of modem is < 2"); |
| 9925 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9926 | } |
| 9927 | // Check if support of multiple SIMs is restricted by carrier |
| 9928 | if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9929 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9930 | } |
| 9931 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9932 | return TelephonyManager.MULTISIM_ALLOWED; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9933 | } |
| 9934 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9935 | /** |
| 9936 | * Switch configs to enable multi-sim or switch back to single-sim |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 9937 | * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE |
| 9938 | * permission, but the other way around is possible with either MODIFY_PHONE_STATE |
| 9939 | * or carrier privileges |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9940 | * @param numOfSims number of active sims we want to switch to |
| 9941 | */ |
| 9942 | @Override |
| 9943 | public void switchMultiSimConfig(int numOfSims) { |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 9944 | if (numOfSims == 1) { |
| 9945 | enforceModifyPermission(); |
| 9946 | } else { |
| 9947 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9948 | mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig"); |
| 9949 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9950 | final long identity = Binder.clearCallingIdentity(); |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9951 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9952 | try { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9953 | //only proceed if multi-sim is not restricted |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9954 | if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9955 | loge("switchMultiSimConfig not possible. It is restricted or not supported."); |
| 9956 | return; |
| 9957 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9958 | mPhoneConfigurationManager.switchMultiSimConfig(numOfSims); |
| 9959 | } finally { |
| 9960 | Binder.restoreCallingIdentity(identity); |
| 9961 | } |
| 9962 | } |
| 9963 | |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 9964 | @Override |
| 9965 | public boolean isApplicationOnUicc(int subId, int appType) { |
| 9966 | enforceReadPrivilegedPermission("isApplicationOnUicc"); |
| 9967 | Phone phone = getPhone(subId); |
| 9968 | if (phone == null) { |
| 9969 | return false; |
| 9970 | } |
| 9971 | final long identity = Binder.clearCallingIdentity(); |
| 9972 | try { |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9973 | UiccPort uiccPort = phone.getUiccPort(); |
| 9974 | if (uiccPort == null) { |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 9975 | return false; |
| 9976 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9977 | UiccProfile uiccProfile = uiccPort.getUiccProfile(); |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 9978 | if (uiccProfile == null) { |
| 9979 | return false; |
| 9980 | } |
| 9981 | if (TelephonyManager.APPTYPE_SIM <= appType |
| 9982 | && appType <= TelephonyManager.APPTYPE_ISIM) { |
| 9983 | return uiccProfile.isApplicationOnIcc(AppType.values()[appType]); |
| 9984 | } |
| 9985 | return false; |
| 9986 | } finally { |
| 9987 | Binder.restoreCallingIdentity(identity); |
| 9988 | } |
| 9989 | } |
| 9990 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9991 | /** |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 9992 | * Get whether making changes to modem configurations will trigger reboot. |
| 9993 | * Return value defaults to true. |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 9994 | */ |
| 9995 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9996 | public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage, |
| 9997 | String callingFeatureId) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 9998 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9999 | mApp, subId, callingPackage, callingFeatureId, |
| 10000 | "doesSwitchMultiSimConfigTriggerReboot")) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 10001 | return false; |
| 10002 | } |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 10003 | final long identity = Binder.clearCallingIdentity(); |
| 10004 | try { |
| 10005 | return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange(); |
| 10006 | } finally { |
| 10007 | Binder.restoreCallingIdentity(identity); |
| 10008 | } |
| 10009 | } |
| 10010 | |
Nathan Harold | 29f5f05 | 2019-02-15 13:41:57 -0800 | [diff] [blame] | 10011 | private void updateModemStateMetrics() { |
| 10012 | TelephonyMetrics metrics = TelephonyMetrics.getInstance(); |
| 10013 | // TODO: check the state for each modem if the api is ready. |
| 10014 | metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1); |
| 10015 | } |
| 10016 | |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10017 | @Override |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 10018 | public List<UiccSlotMapping> getSlotsMapping(String callingPackage) { |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10019 | enforceReadPrivilegedPermission("getSlotsMapping"); |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 10020 | // Verify that the callingPackage belongs to the calling UID |
| 10021 | mApp.getSystemService(AppOpsManager.class) |
| 10022 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10023 | final long identity = Binder.clearCallingIdentity(); |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 10024 | List<UiccSlotMapping> slotMap = new ArrayList<>(); |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10025 | try { |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 10026 | UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName()); |
| 10027 | if (slotInfos != null) { |
| 10028 | for (int i = 0; i < slotInfos.length; i++) { |
| 10029 | for (UiccPortInfo portInfo : slotInfos[i].getPorts()) { |
| 10030 | if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) { |
| 10031 | slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i, |
| 10032 | portInfo.getLogicalSlotIndex())); |
| 10033 | } |
| 10034 | } |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10035 | } |
| 10036 | } |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 10037 | return slotMap; |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10038 | } finally { |
| 10039 | Binder.restoreCallingIdentity(identity); |
| 10040 | } |
| 10041 | } |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 10042 | |
| 10043 | /** |
| 10044 | * Get the IRadio HAL Version |
jimsun | f9ec162 | 2022-09-13 21:18:43 +0800 | [diff] [blame] | 10045 | * @deprecated use getHalVersion instead |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 10046 | */ |
jimsun | f9ec162 | 2022-09-13 21:18:43 +0800 | [diff] [blame] | 10047 | @Deprecated |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 10048 | @Override |
| 10049 | public int getRadioHalVersion() { |
jimsun | f9ec162 | 2022-09-13 21:18:43 +0800 | [diff] [blame] | 10050 | return getHalVersion(HAL_SERVICE_RADIO); |
| 10051 | } |
| 10052 | |
| 10053 | /** |
| 10054 | * Get the HAL Version of a specific service |
| 10055 | */ |
| 10056 | @Override |
| 10057 | public int getHalVersion(int service) { |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 10058 | Phone phone = getDefaultPhone(); |
| 10059 | if (phone == null) return -1; |
jimsun | f9ec162 | 2022-09-13 21:18:43 +0800 | [diff] [blame] | 10060 | HalVersion hv = phone.getHalVersion(service); |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 10061 | if (hv.equals(HalVersion.UNKNOWN)) return -1; |
| 10062 | return hv.major * 100 + hv.minor; |
| 10063 | } |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 10064 | |
| 10065 | /** |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 10066 | * Get the current calling package name. |
| 10067 | * @return the current calling package name |
| 10068 | */ |
| 10069 | @Override |
| 10070 | public String getCurrentPackageName() { |
| 10071 | return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0]; |
| 10072 | } |
| 10073 | |
| 10074 | /** |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10075 | * Return whether data is enabled for certain APN type. This will tell if framework will accept |
| 10076 | * corresponding network requests on a subId. |
| 10077 | * |
| 10078 | * Data is enabled if: |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 10079 | * 1) user data is turned on, or |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10080 | * 2) APN is un-metered for this subscription, or |
| 10081 | * 3) APN type is whitelisted. E.g. MMS is whitelisted if |
Hall Liu | 746e03c | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 10082 | * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled. |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10083 | * |
| 10084 | * @return whether data is allowed for a apn type. |
| 10085 | * |
| 10086 | * @hide |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 10087 | */ |
| 10088 | @Override |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10089 | public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) { |
Amit Mahajan | 5d4e192 | 2019-10-07 16:20:43 -0700 | [diff] [blame] | 10090 | enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for " |
| 10091 | + "isDataEnabledForApn"); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 10092 | |
| 10093 | // Now that all security checks passes, perform the operation as ourselves. |
| 10094 | final long identity = Binder.clearCallingIdentity(); |
| 10095 | try { |
| 10096 | Phone phone = getPhone(subId); |
| 10097 | if (phone == null) return false; |
| 10098 | |
Jack Yu | 27422a5 | 2022-03-21 10:38:05 -0700 | [diff] [blame] | 10099 | boolean isMetered; |
Jack Yu | 99e8733 | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 10100 | boolean isDataEnabled; |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 10101 | isMetered = phone.getDataNetworkController().getDataConfigManager() |
| 10102 | .isMeteredCapability(DataUtils.apnTypeToNetworkCapability(apnType), |
| 10103 | phone.getServiceState().getDataRoaming()); |
| 10104 | isDataEnabled = phone.getDataSettingsManager().isDataEnabled(apnType); |
Jack Yu | 99e8733 | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 10105 | return !isMetered || isDataEnabled; |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10106 | } finally { |
| 10107 | Binder.restoreCallingIdentity(identity); |
| 10108 | } |
| 10109 | } |
| 10110 | |
| 10111 | @Override |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 10112 | public boolean isApnMetered(@ApnType int apnType, int subId) { |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10113 | enforceReadPrivilegedPermission("isApnMetered"); |
| 10114 | |
| 10115 | // Now that all security checks passes, perform the operation as ourselves. |
| 10116 | final long identity = Binder.clearCallingIdentity(); |
| 10117 | try { |
| 10118 | Phone phone = getPhone(subId); |
| 10119 | if (phone == null) return true; // By default return true. |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 10120 | return phone.getDataNetworkController().getDataConfigManager().isMeteredCapability( |
| 10121 | DataUtils.apnTypeToNetworkCapability(apnType), |
| 10122 | phone.getServiceState().getDataRoaming()); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 10123 | } finally { |
| 10124 | Binder.restoreCallingIdentity(identity); |
| 10125 | } |
| 10126 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 10127 | |
| 10128 | @Override |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 10129 | public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers, |
| 10130 | int subscriptionId, IBooleanConsumer resultCallback) { |
| 10131 | enforceModifyPermission(); |
| 10132 | long token = Binder.clearCallingIdentity(); |
| 10133 | try { |
| 10134 | Phone phone = getPhone(subscriptionId); |
| 10135 | if (phone == null) { |
| 10136 | try { |
| 10137 | if (resultCallback != null) { |
| 10138 | resultCallback.accept(false); |
| 10139 | } |
| 10140 | } catch (RemoteException e) { |
| 10141 | // ignore |
| 10142 | } |
| 10143 | return; |
| 10144 | } |
| 10145 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument = |
| 10146 | Pair.create(specifiers, (x) -> { |
| 10147 | try { |
| 10148 | if (resultCallback != null) { |
| 10149 | resultCallback.accept(x); |
| 10150 | } |
| 10151 | } catch (RemoteException e) { |
| 10152 | // ignore |
| 10153 | } |
| 10154 | }); |
| 10155 | sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null); |
| 10156 | } finally { |
| 10157 | Binder.restoreCallingIdentity(token); |
| 10158 | } |
| 10159 | } |
| 10160 | |
| 10161 | @Override |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 10162 | public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) { |
| 10163 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 10164 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 10165 | mApp, subId, "getSystemSelectionChannels"); |
| 10166 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 10167 | final long identity = Binder.clearCallingIdentity(); |
| 10168 | try { |
Sarah Chin | 428d1d6 | 2021-03-13 03:17:40 -0800 | [diff] [blame] | 10169 | Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource); |
| 10170 | if (result instanceof IllegalStateException) { |
| 10171 | throw (IllegalStateException) result; |
| 10172 | } |
| 10173 | List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 10174 | if (DBG) log("getSystemSelectionChannels: " + specifiers); |
| 10175 | return specifiers; |
| 10176 | } finally { |
| 10177 | Binder.restoreCallingIdentity(identity); |
| 10178 | } |
| 10179 | } |
| 10180 | |
| 10181 | @Override |
Jack Yu | 8b766fc | 2022-03-21 09:42:33 -0700 | [diff] [blame] | 10182 | public boolean isMvnoMatched(int slotIndex, int mvnoType, @NonNull String mvnoMatchData) { |
changbetty | ca3d40d | 2020-03-03 16:27:31 +0800 | [diff] [blame] | 10183 | enforceReadPrivilegedPermission("isMvnoMatched"); |
Jack Yu | 8b766fc | 2022-03-21 09:42:33 -0700 | [diff] [blame] | 10184 | return UiccController.getInstance().mvnoMatches(slotIndex, mvnoType, mvnoMatchData); |
changbetty | 7157e9e | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 10185 | } |
| 10186 | |
| 10187 | @Override |
Philip P. Moltmann | d02b737 | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 10188 | public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag, |
| 10189 | IIntegerConsumer pendingSubIdResult) { |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 10190 | if (callingPackage == null) { |
| 10191 | callingPackage = getCurrentPackageName(); |
| 10192 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 10193 | SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp, |
| 10194 | (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE)); |
Philip P. Moltmann | d02b737 | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 10195 | if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag, |
| 10196 | "Sending message")) { |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 10197 | throw new SecurityException("Requires SEND_SMS permission to perform this operation"); |
| 10198 | } |
| 10199 | PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult); |
| 10200 | Intent intent = new Intent(); |
| 10201 | intent.setClass(mApp, PickSmsSubscriptionActivity.class); |
| 10202 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 10203 | // Bring up choose default SMS subscription dialog right now |
| 10204 | intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY, |
| 10205 | PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE); |
| 10206 | mApp.startActivity(intent); |
| 10207 | } |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 10208 | |
| 10209 | @Override |
| 10210 | public String getMmsUAProfUrl(int subId) { |
| 10211 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 10212 | final long identity = Binder.clearCallingIdentity(); |
| 10213 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 10214 | String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString( |
| 10215 | CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING); |
| 10216 | if (!TextUtils.isEmpty(carrierUAProfUrl)) { |
| 10217 | return carrierUAProfUrl; |
| 10218 | } |
Daniel Bright | ebb4eb7 | 2020-02-18 15:16:33 -0800 | [diff] [blame] | 10219 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 10220 | .getString(com.android.internal.R.string.config_mms_user_agent_profile_url); |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 10221 | } finally { |
| 10222 | Binder.restoreCallingIdentity(identity); |
| 10223 | } |
| 10224 | } |
| 10225 | |
| 10226 | @Override |
| 10227 | public String getMmsUserAgent(int subId) { |
| 10228 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 10229 | final long identity = Binder.clearCallingIdentity(); |
| 10230 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 10231 | String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString( |
| 10232 | CarrierConfigManager.KEY_MMS_USER_AGENT_STRING); |
| 10233 | if (!TextUtils.isEmpty(carrierUserAgent)) { |
| 10234 | return carrierUserAgent; |
| 10235 | } |
Daniel Bright | ebb4eb7 | 2020-02-18 15:16:33 -0800 | [diff] [blame] | 10236 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 10237 | .getString(com.android.internal.R.string.config_mms_user_agent); |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 10238 | } finally { |
| 10239 | Binder.restoreCallingIdentity(identity); |
| 10240 | } |
| 10241 | } |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 10242 | |
| 10243 | @Override |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 10244 | public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) { |
| 10245 | enforceReadPrivilegedPermission("isMobileDataPolicyEnabled"); |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 10246 | |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 10247 | final long identity = Binder.clearCallingIdentity(); |
| 10248 | try { |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 10249 | Phone phone = getPhone(subscriptionId); |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 10250 | if (phone == null) return false; |
| 10251 | |
Ling Ma | f188d50 | 2022-09-16 15:22:36 -0700 | [diff] [blame] | 10252 | return phone.getDataSettingsManager().isMobileDataPolicyEnabled(policy); |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 10253 | } finally { |
| 10254 | Binder.restoreCallingIdentity(identity); |
| 10255 | } |
| 10256 | } |
| 10257 | |
| 10258 | @Override |
Hall Liu | c66bb11 | 2021-02-02 12:09:32 -0800 | [diff] [blame] | 10259 | public void setMobileDataPolicyEnabled(int subscriptionId, int policy, |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 10260 | boolean enabled) { |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 10261 | enforceModifyPermission(); |
| 10262 | |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 10263 | final long identity = Binder.clearCallingIdentity(); |
| 10264 | try { |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 10265 | Phone phone = getPhone(subscriptionId); |
| 10266 | if (phone == null) return; |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 10267 | |
Ling Ma | f188d50 | 2022-09-16 15:22:36 -0700 | [diff] [blame] | 10268 | phone.getDataSettingsManager().setMobileDataPolicy(policy, enabled); |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 10269 | } finally { |
| 10270 | Binder.restoreCallingIdentity(identity); |
| 10271 | } |
| 10272 | } |
| 10273 | |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 10274 | /** |
Hall Liu | 746e03c | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 10275 | * Updates whether conference event package handling is enabled. |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 10276 | * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false} |
| 10277 | * otherwise. |
| 10278 | */ |
| 10279 | @Override |
| 10280 | public void setCepEnabled(boolean isCepEnabled) { |
| 10281 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled"); |
| 10282 | |
| 10283 | final long identity = Binder.clearCallingIdentity(); |
| 10284 | try { |
| 10285 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled); |
| 10286 | for (Phone phone : PhoneFactory.getPhones()) { |
| 10287 | Phone defaultPhone = phone.getImsPhone(); |
| 10288 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 10289 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 10290 | ImsPhoneCallTracker imsPhoneCallTracker = |
| 10291 | (ImsPhoneCallTracker) imsPhone.getCallTracker(); |
| 10292 | imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled); |
| 10293 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone " |
| 10294 | + imsPhone.getMsisdn()); |
| 10295 | } |
| 10296 | } |
| 10297 | } finally { |
| 10298 | Binder.restoreCallingIdentity(identity); |
| 10299 | } |
| 10300 | } |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 10301 | |
| 10302 | /** |
| 10303 | * Notify that an RCS autoconfiguration XML file has been received for provisioning. |
| 10304 | * |
| 10305 | * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed. |
| 10306 | * @param isCompressed The XML file is compressed in gzip format and must be decompressed |
| 10307 | * before being read. |
| 10308 | */ |
| 10309 | @Override |
| 10310 | public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean |
| 10311 | isCompressed) { |
| 10312 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 10313 | mApp, subId, "notifyRcsAutoConfigurationReceived"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10314 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10315 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10316 | } |
| 10317 | if (!isImsAvailableOnDevice()) { |
joonhunshin | 46b49a3 | 2022-12-21 05:33:23 +0000 | [diff] [blame] | 10318 | // ProvisioningManager can not handle ServiceSpecificException. |
| 10319 | // Throw the IllegalStateException and annotate ProvisioningManager. |
| 10320 | throw new IllegalStateException("IMS not available on device."); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10321 | } |
| 10322 | |
| 10323 | final long identity = Binder.clearCallingIdentity(); |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 10324 | try { |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10325 | RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed); |
| 10326 | } finally { |
| 10327 | Binder.restoreCallingIdentity(identity); |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 10328 | } |
| 10329 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 10330 | |
| 10331 | @Override |
| 10332 | public boolean isIccLockEnabled(int subId) { |
| 10333 | enforceReadPrivilegedPermission("isIccLockEnabled"); |
| 10334 | |
| 10335 | // Now that all security checks passes, perform the operation as ourselves. |
| 10336 | final long identity = Binder.clearCallingIdentity(); |
| 10337 | try { |
| 10338 | Phone phone = getPhone(subId); |
| 10339 | if (phone != null && phone.getIccCard() != null) { |
| 10340 | return phone.getIccCard().getIccLockEnabled(); |
| 10341 | } else { |
| 10342 | return false; |
| 10343 | } |
| 10344 | } finally { |
| 10345 | Binder.restoreCallingIdentity(identity); |
| 10346 | } |
| 10347 | } |
| 10348 | |
| 10349 | /** |
| 10350 | * Set the ICC pin lock enabled or disabled. |
| 10351 | * |
| 10352 | * @return an integer representing the status of IccLock enabled or disabled in the following |
| 10353 | * three cases: |
| 10354 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock |
| 10355 | * successfully. |
| 10356 | * - Positive number and zero for remaining password attempts. |
| 10357 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
| 10358 | * |
| 10359 | */ |
| 10360 | @Override |
| 10361 | public int setIccLockEnabled(int subId, boolean enabled, String password) { |
| 10362 | enforceModifyPermission(); |
| 10363 | |
| 10364 | Phone phone = getPhone(subId); |
| 10365 | if (phone == null) { |
| 10366 | return 0; |
| 10367 | } |
| 10368 | // Now that all security checks passes, perform the operation as ourselves. |
| 10369 | final long identity = Binder.clearCallingIdentity(); |
| 10370 | try { |
| 10371 | int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED, |
| 10372 | new Pair<Boolean, String>(enabled, password), phone, null); |
| 10373 | return attemptsRemaining; |
| 10374 | |
| 10375 | } catch (Exception e) { |
| 10376 | Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e); |
| 10377 | } finally { |
| 10378 | Binder.restoreCallingIdentity(identity); |
| 10379 | } |
| 10380 | return 0; |
| 10381 | } |
| 10382 | |
| 10383 | /** |
| 10384 | * Change the ICC password used in ICC pin lock. |
| 10385 | * |
| 10386 | * @return an integer representing the status of IccLock changed in the following three cases: |
| 10387 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully. |
| 10388 | * - Positive number and zero for remaining password attempts. |
| 10389 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
| 10390 | * |
| 10391 | */ |
| 10392 | @Override |
| 10393 | public int changeIccLockPassword(int subId, String oldPassword, String newPassword) { |
| 10394 | enforceModifyPermission(); |
| 10395 | |
| 10396 | Phone phone = getPhone(subId); |
| 10397 | if (phone == null) { |
| 10398 | return 0; |
| 10399 | } |
| 10400 | // Now that all security checks passes, perform the operation as ourselves. |
| 10401 | final long identity = Binder.clearCallingIdentity(); |
| 10402 | try { |
| 10403 | int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD, |
| 10404 | new Pair<String, String>(oldPassword, newPassword), phone, null); |
| 10405 | return attemptsRemaining; |
| 10406 | |
| 10407 | } catch (Exception e) { |
| 10408 | Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e); |
| 10409 | } finally { |
| 10410 | Binder.restoreCallingIdentity(identity); |
| 10411 | } |
| 10412 | return 0; |
| 10413 | } |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 10414 | |
| 10415 | /** |
| 10416 | * Request for receiving user activity notification |
| 10417 | */ |
| 10418 | @Override |
| 10419 | public void requestUserActivityNotification() { |
| 10420 | if (!mNotifyUserActivity.get() |
| 10421 | && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) { |
| 10422 | mNotifyUserActivity.set(true); |
| 10423 | } |
| 10424 | } |
| 10425 | |
| 10426 | /** |
| 10427 | * Called when userActivity is signalled in the power manager. |
| 10428 | * This is safe to call from any thread, with any window manager locks held or not. |
| 10429 | */ |
| 10430 | @Override |
| 10431 | public void userActivity() { |
| 10432 | // *************************************** |
| 10433 | // * Inherited from PhoneWindowManager * |
| 10434 | // *************************************** |
| 10435 | // THIS IS CALLED FROM DEEP IN THE POWER MANAGER |
| 10436 | // WITH ITS LOCKS HELD. |
| 10437 | // |
| 10438 | // This code must be VERY careful about the locks |
| 10439 | // it acquires. |
| 10440 | // In fact, the current code acquires way too many, |
| 10441 | // and probably has lurking deadlocks. |
| 10442 | |
| 10443 | if (Binder.getCallingUid() != Process.SYSTEM_UID) { |
| 10444 | throw new SecurityException("Only the OS may call notifyUserActivity()"); |
| 10445 | } |
| 10446 | |
| 10447 | if (mNotifyUserActivity.getAndSet(false)) { |
| 10448 | mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY, |
| 10449 | USER_ACTIVITY_NOTIFICATION_DELAY); |
| 10450 | } |
| 10451 | } |
Malcolm Chen | 4639c56 | 2020-04-13 11:59:40 -0700 | [diff] [blame] | 10452 | |
| 10453 | @Override |
| 10454 | public boolean canConnectTo5GInDsdsMode() { |
| 10455 | return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode); |
| 10456 | } |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 10457 | |
| 10458 | @Override |
| 10459 | public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage, |
| 10460 | String callingFeatureId) { |
| 10461 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 10462 | mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) { |
| 10463 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 10464 | } |
| 10465 | |
| 10466 | Phone phone = getPhone(subId); |
| 10467 | if (phone == null) { |
| 10468 | throw new RuntimeException("phone is not available"); |
| 10469 | } |
| 10470 | // Now that all security checks passes, perform the operation as ourselves. |
| 10471 | final long identity = Binder.clearCallingIdentity(); |
| 10472 | try { |
| 10473 | return phone.getEquivalentHomePlmns(); |
| 10474 | } finally { |
| 10475 | Binder.restoreCallingIdentity(identity); |
| 10476 | } |
| 10477 | } |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 10478 | |
| 10479 | @Override |
| 10480 | public boolean isRadioInterfaceCapabilitySupported( |
Daniel Bright | 95a4c1f | 2021-02-11 09:57:16 -0800 | [diff] [blame] | 10481 | final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) { |
| 10482 | Set<String> radioInterfaceCapabilities = |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 10483 | mRadioInterfaceCapabilities.getCapabilities(); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 10484 | if (radioInterfaceCapabilities == null) { |
| 10485 | throw new RuntimeException("radio interface capabilities are not available"); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 10486 | } |
Daniel Bright | 95a4c1f | 2021-02-11 09:57:16 -0800 | [diff] [blame] | 10487 | return radioInterfaceCapabilities.contains(capability); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 10488 | } |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10489 | |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 10490 | @Override |
| 10491 | public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl, |
| 10492 | UaSecurityProtocolIdentifier securityProtocol, |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10493 | boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) { |
| 10494 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 10495 | Binder.getCallingUid(), "bootstrapAuthenticationRequest", |
| 10496 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 10497 | Manifest.permission.MODIFY_PHONE_STATE); |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 10498 | if (DBG) { |
| 10499 | log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:" |
| 10500 | + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol |
| 10501 | + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback); |
| 10502 | } |
| 10503 | |
| 10504 | if (!SubscriptionManager.isValidSubscriptionId(subId) |
| 10505 | || appType < TelephonyManager.APPTYPE_UNKNOWN |
| 10506 | || appType > TelephonyManager.APPTYPE_ISIM |
| 10507 | || nafUrl == null || securityProtocol == null || callback == null) { |
| 10508 | Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters"); |
| 10509 | if (callback != null) { |
| 10510 | try { |
| 10511 | callback.onAuthenticationFailure( |
| 10512 | 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED); |
| 10513 | } catch (RemoteException exception) { |
| 10514 | log("Fail to notify onAuthenticationFailure due to " + exception); |
| 10515 | } |
| 10516 | return; |
| 10517 | } |
| 10518 | } |
| 10519 | |
| 10520 | final long token = Binder.clearCallingIdentity(); |
| 10521 | try { |
| 10522 | getGbaManager(subId).bootstrapAuthenticationRequest( |
| 10523 | new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(), |
| 10524 | forceBootStrapping, callback)); |
| 10525 | } finally { |
| 10526 | Binder.restoreCallingIdentity(token); |
| 10527 | } |
| 10528 | } |
| 10529 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10530 | /** |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10531 | * Attempts to set the radio power state for all phones for thermal reason. |
| 10532 | * This does not guarantee that the |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10533 | * requested radio power state will actually be set. See {@link |
| 10534 | * PhoneInternalInterface#setRadioPowerForReason} for more details. |
| 10535 | * |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10536 | * @param enable {@code true} if trying to turn radio on. |
| 10537 | * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code |
| 10538 | * false}. |
| 10539 | */ |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10540 | private boolean setRadioPowerForThermal(boolean enable) { |
| 10541 | boolean isPhoneAvailable = false; |
| 10542 | for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) { |
| 10543 | Phone phone = PhoneFactory.getPhone(i); |
| 10544 | if (phone != null) { |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 10545 | phone.setRadioPowerForReason(enable, TelephonyManager.RADIO_POWER_REASON_THERMAL); |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10546 | isPhoneAvailable = true; |
| 10547 | } |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10548 | } |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10549 | |
| 10550 | // return true if successfully informed the phone object about the thermal radio power |
| 10551 | // request. |
| 10552 | return isPhoneAvailable; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10553 | } |
| 10554 | |
| 10555 | private int handleDataThrottlingRequest(int subId, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 10556 | DataThrottlingRequest dataThrottlingRequest, String callingPackage) { |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10557 | boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported( |
| 10558 | TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING); |
| 10559 | if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction() |
| 10560 | != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) { |
| 10561 | throw new IllegalArgumentException("modem does not support data throttling"); |
| 10562 | } |
| 10563 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10564 | // Ensure that radio is on. If not able to power on due to phone being unavailable, return |
| 10565 | // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10566 | if (!setRadioPowerForThermal(true)) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10567 | return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 10568 | } |
| 10569 | |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 10570 | setDataEnabledForReason( |
| 10571 | subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true, callingPackage); |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10572 | |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10573 | if (isDataThrottlingSupported) { |
| 10574 | int thermalMitigationResult = |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10575 | (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId); |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10576 | if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) { |
| 10577 | throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS"); |
| 10578 | } else if (thermalMitigationResult |
| 10579 | == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) { |
Jack Nudelman | 760d096 | 2021-05-20 13:57:30 -0700 | [diff] [blame] | 10580 | log("Modem likely does not support data throttling on secondary carrier. Data " + |
| 10581 | "throttling action = " + dataThrottlingRequest.getDataThrottlingAction()); |
| 10582 | return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10583 | } |
| 10584 | return thermalMitigationResult; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10585 | } |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10586 | |
| 10587 | return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10588 | } |
| 10589 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10590 | private static List<String> getThermalMitigationAllowlist(Context context) { |
| 10591 | if (sThermalMitigationAllowlistedPackages.isEmpty()) { |
| 10592 | for (String pckg : context.getResources() |
| 10593 | .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) { |
| 10594 | sThermalMitigationAllowlistedPackages.add(pckg); |
| 10595 | } |
| 10596 | } |
| 10597 | |
| 10598 | return sThermalMitigationAllowlistedPackages; |
| 10599 | } |
| 10600 | |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 10601 | private boolean isAnyPhoneInEmergencyState() { |
| 10602 | TelecomManager tm = mApp.getSystemService(TelecomManager.class); |
| 10603 | if (tm.isInEmergencyCall()) { |
| 10604 | Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call"); |
| 10605 | return true; |
| 10606 | } |
| 10607 | for (Phone phone : PhoneFactory.getPhones()) { |
| 10608 | if (phone.isInEmergencySmsMode() || phone.isInEcm()) { |
| 10609 | Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = " |
| 10610 | + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = " |
| 10611 | + phone.isInEcm()); |
| 10612 | return true; |
| 10613 | } |
| 10614 | } |
| 10615 | |
| 10616 | return false; |
| 10617 | } |
| 10618 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10619 | /** |
| 10620 | * Used by shell commands to add an authorized package name for thermal mitigation. |
| 10621 | * @param packageName name of package to be allowlisted |
| 10622 | * @param context |
| 10623 | */ |
| 10624 | static void addPackageToThermalMitigationAllowlist(String packageName, Context context) { |
| 10625 | sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context); |
| 10626 | sThermalMitigationAllowlistedPackages.add(packageName); |
| 10627 | } |
| 10628 | |
| 10629 | /** |
| 10630 | * Used by shell commands to remove an authorized package name for thermal mitigation. |
| 10631 | * @param packageName name of package to remove from allowlist |
| 10632 | * @param context |
| 10633 | */ |
| 10634 | static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) { |
| 10635 | sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context); |
| 10636 | sThermalMitigationAllowlistedPackages.remove(packageName); |
| 10637 | } |
| 10638 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10639 | /** |
| 10640 | * Thermal mitigation request to control functionalities at modem. |
| 10641 | * |
| 10642 | * @param subId the id of the subscription. |
| 10643 | * @param thermalMitigationRequest holds all necessary information to be passed down to modem. |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10644 | * @param callingPackage the package name of the calling package. |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10645 | * |
| 10646 | * @return thermalMitigationResult enum as defined in android.telephony.Annotation. |
| 10647 | */ |
| 10648 | @Override |
| 10649 | @ThermalMitigationResult |
| 10650 | public int sendThermalMitigationRequest( |
| 10651 | int subId, |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10652 | ThermalMitigationRequest thermalMitigationRequest, |
| 10653 | String callingPackage) throws IllegalArgumentException { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10654 | enforceModifyPermission(); |
| 10655 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10656 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 10657 | if (!getThermalMitigationAllowlist(getDefaultPhone().getContext()) |
| 10658 | .contains(callingPackage)) { |
| 10659 | throw new SecurityException("Calling package must be configured in the device config. " |
| 10660 | + "calling package: " + callingPackage); |
| 10661 | } |
| 10662 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10663 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 10664 | final long identity = Binder.clearCallingIdentity(); |
| 10665 | |
| 10666 | int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR; |
| 10667 | try { |
| 10668 | int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction(); |
| 10669 | switch (thermalMitigationAction) { |
| 10670 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING: |
| 10671 | thermalMitigationResult = |
| 10672 | handleDataThrottlingRequest(subId, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 10673 | thermalMitigationRequest.getDataThrottlingRequest(), |
| 10674 | callingPackage); |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10675 | break; |
| 10676 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY: |
| 10677 | if (thermalMitigationRequest.getDataThrottlingRequest() != null) { |
| 10678 | throw new IllegalArgumentException("dataThrottlingRequest must be null for " |
| 10679 | + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY"); |
| 10680 | } |
| 10681 | |
| 10682 | // Ensure that radio is on. If not able to power on due to phone being |
| 10683 | // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10684 | if (!setRadioPowerForThermal(true)) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10685 | thermalMitigationResult = |
| 10686 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 10687 | break; |
| 10688 | } |
| 10689 | |
| 10690 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 10691 | false, callingPackage); |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10692 | thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 10693 | break; |
| 10694 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF: |
| 10695 | if (thermalMitigationRequest.getDataThrottlingRequest() != null) { |
| 10696 | throw new IllegalArgumentException("dataThrottlingRequest must be null for" |
| 10697 | + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF"); |
| 10698 | } |
| 10699 | |
| 10700 | TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null); |
| 10701 | if (registry != null) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10702 | Phone phone = getPhone(subId); |
| 10703 | if (phone == null) { |
| 10704 | thermalMitigationResult = |
| 10705 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 10706 | break; |
| 10707 | } |
| 10708 | |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 10709 | TelephonyConnectionService service = |
| 10710 | registry.getTelephonyConnectionService(); |
Jack Nudelman | b30ac30 | 2021-06-17 15:39:58 -0700 | [diff] [blame] | 10711 | if (service != null && service.isEmergencyCallPending()) { |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 10712 | Log.e(LOG_TAG, "An emergency call is pending"); |
| 10713 | thermalMitigationResult = |
| 10714 | TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE; |
| 10715 | break; |
| 10716 | } else if (isAnyPhoneInEmergencyState()) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10717 | thermalMitigationResult = |
| 10718 | TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE; |
| 10719 | break; |
| 10720 | } |
| 10721 | } else { |
| 10722 | thermalMitigationResult = |
| 10723 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 10724 | break; |
| 10725 | } |
| 10726 | |
| 10727 | // Turn radio off. If not able to power off due to phone being unavailable, |
| 10728 | // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10729 | if (!setRadioPowerForThermal(false)) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10730 | thermalMitigationResult = |
| 10731 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 10732 | break; |
| 10733 | } |
| 10734 | thermalMitigationResult = |
| 10735 | TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 10736 | break; |
| 10737 | default: |
| 10738 | throw new IllegalArgumentException("the requested thermalMitigationAction does " |
| 10739 | + "not exist. Requested action: " + thermalMitigationAction); |
| 10740 | } |
| 10741 | } catch (IllegalArgumentException e) { |
| 10742 | throw e; |
| 10743 | } catch (Exception e) { |
| 10744 | Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e); |
| 10745 | thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 10746 | } finally { |
| 10747 | Binder.restoreCallingIdentity(identity); |
| 10748 | } |
| 10749 | |
| 10750 | if (DBG) { |
| 10751 | log("thermalMitigationRequest returning with thermalMitigationResult: " |
| 10752 | + thermalMitigationResult); |
| 10753 | } |
| 10754 | |
| 10755 | return thermalMitigationResult; |
| 10756 | } |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 10757 | |
| 10758 | /** |
| 10759 | * Set the GbaService Package Name that Telephony will bind to. |
| 10760 | * |
| 10761 | * @param subId The sim that the GbaService is associated with. |
| 10762 | * @param packageName The name of the package to be replaced with. |
| 10763 | * @return true if setting the GbaService to bind to succeeded, false if it did not. |
| 10764 | */ |
| 10765 | @Override |
| 10766 | public boolean setBoundGbaServiceOverride(int subId, String packageName) { |
| 10767 | enforceModifyPermission(); |
| 10768 | |
| 10769 | final long identity = Binder.clearCallingIdentity(); |
| 10770 | try { |
| 10771 | return getGbaManager(subId).overrideServicePackage(packageName); |
| 10772 | } finally { |
| 10773 | Binder.restoreCallingIdentity(identity); |
| 10774 | } |
| 10775 | } |
| 10776 | |
| 10777 | /** |
| 10778 | * Return the package name of the currently bound GbaService. |
| 10779 | * |
| 10780 | * @param subId The sim that the GbaService is associated with. |
| 10781 | * @return the package name of the GbaService configuration, null if GBA is not supported. |
| 10782 | */ |
| 10783 | @Override |
| 10784 | public String getBoundGbaService(int subId) { |
| 10785 | enforceReadPrivilegedPermission("getBoundGbaServicePackage"); |
| 10786 | |
| 10787 | final long identity = Binder.clearCallingIdentity(); |
| 10788 | try { |
| 10789 | return getGbaManager(subId).getServicePackage(); |
| 10790 | } finally { |
| 10791 | Binder.restoreCallingIdentity(identity); |
| 10792 | } |
| 10793 | } |
| 10794 | |
| 10795 | /** |
| 10796 | * Set the release time for telephony to unbind GbaService. |
| 10797 | * |
| 10798 | * @param subId The sim that the GbaService is associated with. |
| 10799 | * @param interval The release time to unbind GbaService by millisecond. |
| 10800 | * @return true if setting the GbaService to bind to succeeded, false if it did not. |
| 10801 | */ |
| 10802 | @Override |
| 10803 | public boolean setGbaReleaseTimeOverride(int subId, int interval) { |
| 10804 | enforceModifyPermission(); |
| 10805 | |
| 10806 | final long identity = Binder.clearCallingIdentity(); |
| 10807 | try { |
| 10808 | return getGbaManager(subId).overrideReleaseTime(interval); |
| 10809 | } finally { |
| 10810 | Binder.restoreCallingIdentity(identity); |
| 10811 | } |
| 10812 | } |
| 10813 | |
| 10814 | /** |
| 10815 | * Return the release time for telephony to unbind GbaService. |
| 10816 | * |
| 10817 | * @param subId The sim that the GbaService is associated with. |
| 10818 | * @return The release time to unbind GbaService by millisecond. |
| 10819 | */ |
| 10820 | @Override |
| 10821 | public int getGbaReleaseTime(int subId) { |
| 10822 | enforceReadPrivilegedPermission("getGbaReleaseTime"); |
| 10823 | |
| 10824 | final long identity = Binder.clearCallingIdentity(); |
| 10825 | try { |
| 10826 | return getGbaManager(subId).getReleaseTime(); |
| 10827 | } finally { |
| 10828 | Binder.restoreCallingIdentity(identity); |
| 10829 | } |
| 10830 | } |
| 10831 | |
| 10832 | private GbaManager getGbaManager(int subId) { |
| 10833 | GbaManager instance = GbaManager.getInstance(subId); |
| 10834 | if (instance == null) { |
| 10835 | String packageName = mApp.getResources().getString(R.string.config_gba_package); |
| 10836 | int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time); |
| 10837 | instance = GbaManager.make(mApp, subId, packageName, releaseTime); |
| 10838 | } |
| 10839 | return instance; |
| 10840 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10841 | |
| 10842 | /** |
| 10843 | * indicate whether the device and the carrier can support |
| 10844 | * RCS VoLTE single registration. |
| 10845 | */ |
| 10846 | @Override |
| 10847 | public boolean isRcsVolteSingleRegistrationCapable(int subId) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10848 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 10849 | Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable", |
| 10850 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 10851 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10852 | |
| 10853 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10854 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10855 | } |
| 10856 | |
| 10857 | final long identity = Binder.clearCallingIdentity(); |
| 10858 | try { |
| 10859 | RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance(); |
| 10860 | if (rpm != null) { |
Hui Wang | 67af90e | 2021-06-04 16:57:15 -0700 | [diff] [blame] | 10861 | Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId); |
| 10862 | if (isCapable != null) { |
| 10863 | return isCapable; |
| 10864 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10865 | } |
Hui Wang | 67af90e | 2021-06-04 16:57:15 -0700 | [diff] [blame] | 10866 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE, |
| 10867 | "service is temporarily unavailable."); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10868 | } finally { |
| 10869 | Binder.restoreCallingIdentity(identity); |
| 10870 | } |
| 10871 | } |
| 10872 | |
| 10873 | /** |
| 10874 | * Register RCS provisioning callback. |
| 10875 | */ |
| 10876 | @Override |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10877 | public void registerRcsProvisioningCallback(int subId, |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10878 | IRcsConfigCallback callback) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10879 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10880 | Binder.getCallingUid(), "registerRcsProvisioningCallback", |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10881 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 10882 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10883 | |
| 10884 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10885 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10886 | } |
| 10887 | if (!isImsAvailableOnDevice()) { |
| 10888 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 10889 | "IMS not available on device."); |
| 10890 | } |
| 10891 | |
| 10892 | final long identity = Binder.clearCallingIdentity(); |
| 10893 | try { |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 10894 | if (!RcsProvisioningMonitor.getInstance() |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10895 | .registerRcsProvisioningCallback(subId, callback)) { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 10896 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION, |
| 10897 | "Active subscription not found."); |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 10898 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10899 | } finally { |
| 10900 | Binder.restoreCallingIdentity(identity); |
| 10901 | } |
| 10902 | } |
| 10903 | |
| 10904 | /** |
| 10905 | * Unregister RCS provisioning callback. |
| 10906 | */ |
| 10907 | @Override |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10908 | public void unregisterRcsProvisioningCallback(int subId, |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10909 | IRcsConfigCallback callback) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10910 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10911 | Binder.getCallingUid(), "unregisterRcsProvisioningCallback", |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10912 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 10913 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10914 | |
| 10915 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10916 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10917 | } |
| 10918 | if (!isImsAvailableOnDevice()) { |
joonhunshin | 46b49a3 | 2022-12-21 05:33:23 +0000 | [diff] [blame] | 10919 | // operation failed silently |
| 10920 | Rlog.w(LOG_TAG, "IMS not available on device."); |
| 10921 | return; |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10922 | } |
| 10923 | |
| 10924 | final long identity = Binder.clearCallingIdentity(); |
| 10925 | try { |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 10926 | RcsProvisioningMonitor.getInstance() |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10927 | .unregisterRcsProvisioningCallback(subId, callback); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10928 | } finally { |
| 10929 | Binder.restoreCallingIdentity(identity); |
| 10930 | } |
| 10931 | } |
| 10932 | |
| 10933 | /** |
| 10934 | * trigger RCS reconfiguration. |
| 10935 | */ |
| 10936 | public void triggerRcsReconfiguration(int subId) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10937 | TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(), |
| 10938 | "triggerRcsReconfiguration", |
| 10939 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10940 | |
| 10941 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10942 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10943 | } |
| 10944 | if (!isImsAvailableOnDevice()) { |
joonhunshin | 46b49a3 | 2022-12-21 05:33:23 +0000 | [diff] [blame] | 10945 | // ProvisioningManager can not handle ServiceSpecificException. |
| 10946 | // Throw the IllegalStateException and annotate ProvisioningManager. |
| 10947 | throw new IllegalStateException("IMS not available on device."); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10948 | } |
| 10949 | |
| 10950 | final long identity = Binder.clearCallingIdentity(); |
| 10951 | try { |
| 10952 | RcsProvisioningMonitor.getInstance().requestReconfig(subId); |
| 10953 | } finally { |
| 10954 | Binder.restoreCallingIdentity(identity); |
| 10955 | } |
| 10956 | } |
| 10957 | |
| 10958 | /** |
| 10959 | * Provide the client configuration parameters of the RCS application. |
| 10960 | */ |
| 10961 | public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10962 | TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(), |
| 10963 | "setRcsClientConfiguration", |
| 10964 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10965 | |
| 10966 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10967 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10968 | } |
| 10969 | if (!isImsAvailableOnDevice()) { |
| 10970 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 10971 | "IMS not available on device."); |
| 10972 | } |
| 10973 | |
| 10974 | final long identity = Binder.clearCallingIdentity(); |
| 10975 | |
| 10976 | try { |
| 10977 | IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS); |
| 10978 | if (configBinder == null) { |
| 10979 | Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration"); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 10980 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION, |
| 10981 | "could not find the requested subscription"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10982 | } else { |
| 10983 | configBinder.setRcsClientConfiguration(rcc); |
| 10984 | } |
joonhunshin | 3e15424 | 2021-09-17 06:33:39 +0000 | [diff] [blame] | 10985 | |
| 10986 | RcsStats.getInstance().onRcsClientProvisioningStats(subId, |
| 10987 | RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10988 | } catch (RemoteException e) { |
| 10989 | Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage()); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 10990 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE, |
| 10991 | "service is temporarily unavailable."); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10992 | } finally { |
| 10993 | Binder.restoreCallingIdentity(identity); |
| 10994 | } |
| 10995 | } |
| 10996 | |
| 10997 | /** |
Hui Wang | baaee6a | 2021-02-19 20:45:36 -0800 | [diff] [blame] | 10998 | * Enables or disables the test mode for RCS VoLTE single registration. |
| 10999 | */ |
| 11000 | @Override |
| 11001 | public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) { |
| 11002 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11003 | "setRcsSingleRegistrationTestModeEnabled"); |
| 11004 | |
| 11005 | RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled); |
| 11006 | } |
| 11007 | |
| 11008 | /** |
| 11009 | * Gets the test mode for RCS VoLTE single registration. |
| 11010 | */ |
| 11011 | @Override |
| 11012 | public boolean getRcsSingleRegistrationTestModeEnabled() { |
| 11013 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11014 | "getRcsSingleRegistrationTestModeEnabled"); |
| 11015 | |
| 11016 | return RcsProvisioningMonitor.getInstance().getTestModeEnabled(); |
| 11017 | } |
| 11018 | |
| 11019 | /** |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11020 | * Overrides the config of RCS VoLTE single registration enabled for the device. |
| 11021 | */ |
| 11022 | @Override |
| 11023 | public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) { |
| 11024 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11025 | "setDeviceSingleRegistrationEnabledOverride"); |
| 11026 | enforceModifyPermission(); |
| 11027 | |
| 11028 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 11029 | : Boolean.parseBoolean(enabledStr); |
| 11030 | RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled); |
Brad Ebinger | 49a72b4 | 2021-01-29 00:55:24 +0000 | [diff] [blame] | 11031 | mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11032 | } |
| 11033 | |
| 11034 | /** |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 11035 | * Sends a device to device communication message. Only usable via shell. |
| 11036 | * @param message message to send. |
| 11037 | * @param value message value. |
| 11038 | */ |
| 11039 | @Override |
| 11040 | public void sendDeviceToDeviceMessage(int message, int value) { |
| 11041 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
Tyler Gunn | babbda0 | 2021-02-10 11:05:02 -0800 | [diff] [blame] | 11042 | "sendDeviceToDeviceMessage"); |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 11043 | enforceModifyPermission(); |
| 11044 | |
| 11045 | final long identity = Binder.clearCallingIdentity(); |
| 11046 | try { |
| 11047 | TelephonyConnectionService service = |
| 11048 | TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService(); |
| 11049 | if (service == null) { |
| 11050 | Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call."); |
| 11051 | return; |
| 11052 | } |
| 11053 | service.sendTestDeviceToDeviceMessage(message, value); |
| 11054 | } finally { |
| 11055 | Binder.restoreCallingIdentity(identity); |
| 11056 | } |
| 11057 | } |
| 11058 | |
Tyler Gunn | babbda0 | 2021-02-10 11:05:02 -0800 | [diff] [blame] | 11059 | /** |
| 11060 | * Sets the specified device to device transport active. |
| 11061 | * @param transport The transport to set active. |
| 11062 | */ |
| 11063 | @Override |
| 11064 | public void setActiveDeviceToDeviceTransport(@NonNull String transport) { |
| 11065 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11066 | "setActiveDeviceToDeviceTransport"); |
| 11067 | enforceModifyPermission(); |
| 11068 | |
| 11069 | final long identity = Binder.clearCallingIdentity(); |
| 11070 | try { |
| 11071 | TelephonyConnectionService service = |
| 11072 | TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService(); |
| 11073 | if (service == null) { |
| 11074 | Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call."); |
| 11075 | return; |
| 11076 | } |
| 11077 | service.setActiveDeviceToDeviceTransport(transport); |
| 11078 | } finally { |
| 11079 | Binder.restoreCallingIdentity(identity); |
| 11080 | } |
| 11081 | } |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 11082 | |
Tyler Gunn | d433926 | 2021-05-03 14:46:49 -0700 | [diff] [blame] | 11083 | @Override |
| 11084 | public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) { |
| 11085 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11086 | "setDeviceToDeviceForceEnabled"); |
| 11087 | |
| 11088 | final long identity = Binder.clearCallingIdentity(); |
| 11089 | try { |
| 11090 | Arrays.stream(PhoneFactory.getPhones()).forEach( |
| 11091 | p -> { |
| 11092 | Phone thePhone = p.getImsPhone(); |
| 11093 | if (thePhone != null && thePhone instanceof ImsPhone) { |
| 11094 | ImsPhone imsPhone = (ImsPhone) thePhone; |
| 11095 | CallTracker tracker = imsPhone.getCallTracker(); |
| 11096 | if (tracker != null && tracker instanceof ImsPhoneCallTracker) { |
| 11097 | ImsPhoneCallTracker imsPhoneCallTracker = |
| 11098 | (ImsPhoneCallTracker) tracker; |
| 11099 | imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled); |
| 11100 | } |
| 11101 | } |
| 11102 | } |
| 11103 | ); |
| 11104 | } finally { |
| 11105 | Binder.restoreCallingIdentity(identity); |
| 11106 | } |
| 11107 | } |
| 11108 | |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 11109 | /** |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11110 | * Gets the config of RCS VoLTE single registration enabled for the device. |
| 11111 | */ |
| 11112 | @Override |
| 11113 | public boolean getDeviceSingleRegistrationEnabled() { |
| 11114 | enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled"); |
| 11115 | return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled(); |
| 11116 | } |
| 11117 | |
| 11118 | /** |
| 11119 | * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription. |
| 11120 | */ |
| 11121 | @Override |
| 11122 | public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) { |
| 11123 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11124 | "setCarrierSingleRegistrationEnabledOverride"); |
| 11125 | enforceModifyPermission(); |
| 11126 | |
| 11127 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 11128 | : Boolean.parseBoolean(enabledStr); |
| 11129 | return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled( |
| 11130 | subId, enabled); |
| 11131 | } |
| 11132 | |
| 11133 | /** |
| 11134 | * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription. |
| 11135 | */ |
| 11136 | @Override |
| 11137 | public boolean getCarrierSingleRegistrationEnabled(int subId) { |
| 11138 | enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled"); |
| 11139 | return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId); |
| 11140 | } |
Chiachang Wang | d6d3477 | 2020-12-22 11:38:27 +0800 | [diff] [blame] | 11141 | |
| 11142 | /** |
Hui Wang | b647abe | 2021-02-26 09:33:38 -0800 | [diff] [blame] | 11143 | * Overrides the ims feature validation result |
| 11144 | */ |
| 11145 | @Override |
| 11146 | public boolean setImsFeatureValidationOverride(int subId, String enabledStr) { |
| 11147 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11148 | "setImsFeatureValidationOverride"); |
| 11149 | |
| 11150 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 11151 | : Boolean.parseBoolean(enabledStr); |
| 11152 | return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation( |
| 11153 | subId, enabled); |
| 11154 | } |
| 11155 | |
| 11156 | /** |
| 11157 | * Gets the ims feature validation override value |
| 11158 | */ |
| 11159 | @Override |
| 11160 | public boolean getImsFeatureValidationOverride(int subId) { |
| 11161 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11162 | "getImsFeatureValidationOverride"); |
| 11163 | return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId); |
| 11164 | } |
| 11165 | |
| 11166 | /** |
Chiachang Wang | d6d3477 | 2020-12-22 11:38:27 +0800 | [diff] [blame] | 11167 | * Get the mobile provisioning url that is used to launch a browser to allow users to manage |
| 11168 | * their mobile plan. |
| 11169 | */ |
| 11170 | @Override |
| 11171 | public String getMobileProvisioningUrl() { |
| 11172 | enforceReadPrivilegedPermission("getMobileProvisioningUrl"); |
| 11173 | final long identity = Binder.clearCallingIdentity(); |
| 11174 | try { |
| 11175 | return getDefaultPhone().getMobileProvisioningUrl(); |
| 11176 | } finally { |
| 11177 | Binder.restoreCallingIdentity(identity); |
| 11178 | } |
| 11179 | } |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11180 | |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 11181 | /** |
calvinpan | e4a8a1d | 2021-01-25 13:51:18 +0800 | [diff] [blame] | 11182 | * Get the EAB contact from the EAB database. |
| 11183 | */ |
| 11184 | @Override |
| 11185 | public String getContactFromEab(String contact) { |
| 11186 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab"); |
| 11187 | enforceModifyPermission(); |
| 11188 | final long identity = Binder.clearCallingIdentity(); |
| 11189 | try { |
| 11190 | return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact); |
| 11191 | } finally { |
| 11192 | Binder.restoreCallingIdentity(identity); |
| 11193 | } |
| 11194 | } |
| 11195 | |
| 11196 | /** |
Calvin Pan | a143432 | 2021-07-01 19:27:01 +0800 | [diff] [blame] | 11197 | * Get the EAB capability from the EAB database. |
| 11198 | */ |
| 11199 | @Override |
| 11200 | public String getCapabilityFromEab(String contact) { |
| 11201 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab"); |
| 11202 | enforceModifyPermission(); |
| 11203 | final long identity = Binder.clearCallingIdentity(); |
| 11204 | try { |
| 11205 | return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact); |
| 11206 | } finally { |
| 11207 | Binder.restoreCallingIdentity(identity); |
| 11208 | } |
| 11209 | } |
| 11210 | |
| 11211 | /** |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 11212 | * Remove the EAB contacts from the EAB database. |
| 11213 | */ |
| 11214 | @Override |
| 11215 | public int removeContactFromEab(int subId, String contacts) { |
| 11216 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab"); |
| 11217 | enforceModifyPermission(); |
| 11218 | final long identity = Binder.clearCallingIdentity(); |
| 11219 | try { |
| 11220 | return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext()); |
| 11221 | } finally { |
| 11222 | Binder.restoreCallingIdentity(identity); |
| 11223 | } |
| 11224 | } |
| 11225 | |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11226 | @Override |
James.cf Lin | 4b784aa | 2021-01-31 03:25:15 +0800 | [diff] [blame] | 11227 | public boolean getDeviceUceEnabled() { |
| 11228 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled"); |
| 11229 | final long identity = Binder.clearCallingIdentity(); |
| 11230 | try { |
| 11231 | return mApp.getDeviceUceEnabled(); |
| 11232 | } finally { |
| 11233 | Binder.restoreCallingIdentity(identity); |
| 11234 | } |
| 11235 | } |
| 11236 | |
| 11237 | @Override |
| 11238 | public void setDeviceUceEnabled(boolean isEnabled) { |
| 11239 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled"); |
| 11240 | final long identity = Binder.clearCallingIdentity(); |
| 11241 | try { |
| 11242 | mApp.setDeviceUceEnabled(isEnabled); |
| 11243 | } finally { |
| 11244 | Binder.restoreCallingIdentity(identity); |
| 11245 | } |
| 11246 | } |
| 11247 | |
Brad Ebinger | 14d467f | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 11248 | /** |
| 11249 | * Add new feature tags to the Set used to calculate the capabilities in PUBLISH. |
| 11250 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 11251 | */ |
| 11252 | // Used for SHELL command only right now. |
| 11253 | @Override |
| 11254 | public RcsContactUceCapability addUceRegistrationOverrideShell(int subId, |
| 11255 | List<String> featureTags) { |
| 11256 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11257 | "addUceRegistrationOverrideShell"); |
| 11258 | final long identity = Binder.clearCallingIdentity(); |
| 11259 | try { |
| 11260 | return mApp.imsRcsController.addUceRegistrationOverrideShell(subId, |
| 11261 | new ArraySet<>(featureTags)); |
| 11262 | } catch (ImsException e) { |
| 11263 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 11264 | } finally { |
| 11265 | Binder.restoreCallingIdentity(identity); |
| 11266 | } |
| 11267 | } |
| 11268 | |
| 11269 | /** |
| 11270 | * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH. |
| 11271 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 11272 | */ |
| 11273 | // Used for SHELL command only right now. |
| 11274 | @Override |
| 11275 | public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId, |
| 11276 | List<String> featureTags) { |
| 11277 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11278 | "removeUceRegistrationOverrideShell"); |
| 11279 | final long identity = Binder.clearCallingIdentity(); |
| 11280 | try { |
| 11281 | return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId, |
| 11282 | new ArraySet<>(featureTags)); |
| 11283 | } catch (ImsException e) { |
| 11284 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 11285 | } finally { |
| 11286 | Binder.restoreCallingIdentity(identity); |
| 11287 | } |
| 11288 | } |
| 11289 | |
| 11290 | /** |
| 11291 | * Clear all overrides in the Set used to calculate the capabilities in PUBLISH. |
| 11292 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 11293 | */ |
| 11294 | // Used for SHELL command only right now. |
| 11295 | @Override |
| 11296 | public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) { |
| 11297 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11298 | "clearUceRegistrationOverrideShell"); |
| 11299 | final long identity = Binder.clearCallingIdentity(); |
| 11300 | try { |
| 11301 | return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId); |
| 11302 | } catch (ImsException e) { |
| 11303 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 11304 | } finally { |
| 11305 | Binder.restoreCallingIdentity(identity); |
| 11306 | } |
| 11307 | } |
| 11308 | |
| 11309 | /** |
| 11310 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 11311 | */ |
| 11312 | // Used for SHELL command only right now. |
| 11313 | @Override |
| 11314 | public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) { |
| 11315 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11316 | "getLatestRcsContactUceCapabilityShell"); |
| 11317 | final long identity = Binder.clearCallingIdentity(); |
| 11318 | try { |
| 11319 | return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId); |
| 11320 | } catch (ImsException e) { |
| 11321 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 11322 | } finally { |
| 11323 | Binder.restoreCallingIdentity(identity); |
| 11324 | } |
| 11325 | } |
| 11326 | |
| 11327 | /** |
| 11328 | * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the |
| 11329 | * device does not have an active PUBLISH. |
| 11330 | */ |
| 11331 | // Used for SHELL command only right now. |
| 11332 | @Override |
| 11333 | public String getLastUcePidfXmlShell(int subId) { |
| 11334 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml"); |
| 11335 | final long identity = Binder.clearCallingIdentity(); |
| 11336 | try { |
| 11337 | return mApp.imsRcsController.getLastUcePidfXmlShell(subId); |
| 11338 | } catch (ImsException e) { |
| 11339 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 11340 | } finally { |
| 11341 | Binder.restoreCallingIdentity(identity); |
| 11342 | } |
| 11343 | } |
| 11344 | |
James.cf Lin | e8713a4 | 2021-04-29 16:04:26 +0800 | [diff] [blame] | 11345 | /** |
| 11346 | * Remove UCE requests cannot be sent to the network status. |
| 11347 | */ |
| 11348 | // Used for SHELL command only right now. |
| 11349 | @Override |
| 11350 | public boolean removeUceRequestDisallowedStatus(int subId) { |
| 11351 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus"); |
| 11352 | final long identity = Binder.clearCallingIdentity(); |
| 11353 | try { |
| 11354 | return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId); |
| 11355 | } catch (ImsException e) { |
| 11356 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 11357 | } finally { |
| 11358 | Binder.restoreCallingIdentity(identity); |
| 11359 | } |
| 11360 | } |
| 11361 | |
James.cf Lin | 18bb900 | 2021-05-25 01:37:38 +0800 | [diff] [blame] | 11362 | /** |
| 11363 | * Remove UCE requests cannot be sent to the network status. |
| 11364 | */ |
| 11365 | // Used for SHELL command only. |
| 11366 | @Override |
| 11367 | public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) { |
| 11368 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout"); |
| 11369 | final long identity = Binder.clearCallingIdentity(); |
| 11370 | try { |
| 11371 | return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs); |
| 11372 | } catch (ImsException e) { |
| 11373 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 11374 | } finally { |
| 11375 | Binder.restoreCallingIdentity(identity); |
| 11376 | } |
| 11377 | } |
Brad Ebinger | 14d467f | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 11378 | |
James.cf Lin | 4b784aa | 2021-01-31 03:25:15 +0800 | [diff] [blame] | 11379 | @Override |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11380 | public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request, |
| 11381 | String callingPackage) { |
| 11382 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 11383 | mApp, subId, "setSignalStrengthUpdateRequest"); |
| 11384 | |
| 11385 | final int callingUid = Binder.getCallingUid(); |
| 11386 | // Verify that tha callingPackage belongs to the calling UID |
| 11387 | mApp.getSystemService(AppOpsManager.class) |
| 11388 | .checkPackage(callingUid, callingPackage); |
| 11389 | |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 11390 | validateSignalStrengthUpdateRequest(mApp, request, callingUid); |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11391 | |
| 11392 | final long identity = Binder.clearCallingIdentity(); |
| 11393 | try { |
| 11394 | Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST, |
| 11395 | new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId); |
| 11396 | |
| 11397 | if (result instanceof IllegalStateException) { |
| 11398 | throw (IllegalStateException) result; |
| 11399 | } |
| 11400 | } finally { |
| 11401 | Binder.restoreCallingIdentity(identity); |
| 11402 | } |
| 11403 | } |
| 11404 | |
| 11405 | @Override |
| 11406 | public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request, |
| 11407 | String callingPackage) { |
| 11408 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 11409 | mApp, subId, "clearSignalStrengthUpdateRequest"); |
| 11410 | |
| 11411 | final int callingUid = Binder.getCallingUid(); |
| 11412 | // Verify that tha callingPackage belongs to the calling UID |
| 11413 | mApp.getSystemService(AppOpsManager.class) |
| 11414 | .checkPackage(callingUid, callingPackage); |
| 11415 | |
| 11416 | final long identity = Binder.clearCallingIdentity(); |
| 11417 | try { |
| 11418 | Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST, |
| 11419 | new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId); |
| 11420 | |
| 11421 | if (result instanceof IllegalStateException) { |
| 11422 | throw (IllegalStateException) result; |
| 11423 | } |
| 11424 | } finally { |
| 11425 | Binder.restoreCallingIdentity(identity); |
| 11426 | } |
| 11427 | } |
| 11428 | |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 11429 | private static void validateSignalStrengthUpdateRequest(Context context, |
| 11430 | SignalStrengthUpdateRequest request, int callingUid) { |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11431 | if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) { |
| 11432 | // phone/system process do not have further restriction on request |
| 11433 | return; |
| 11434 | } |
| 11435 | |
| 11436 | // Applications has restrictions on how to use the request: |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 11437 | // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11438 | if (request.isSystemThresholdReportingRequestedWhileIdle()) { |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 11439 | context.enforceCallingOrSelfPermission( |
| 11440 | android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH, |
| 11441 | "validateSignalStrengthUpdateRequest"); |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11442 | } |
| 11443 | |
| 11444 | for (SignalThresholdInfo info : request.getSignalThresholdInfos()) { |
Nagendra Prasad Nagarle Basavaraju | fee544c | 2022-12-07 16:34:52 +0000 | [diff] [blame] | 11445 | // Only system caller can set mHysteresisMs/mIsEnabled. |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11446 | if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11447 | || info.isEnabled()) { |
| 11448 | throw new IllegalArgumentException( |
| 11449 | "Only system can set hide fields in SignalThresholdInfo"); |
| 11450 | } |
| 11451 | |
| 11452 | // Thresholds length for each RAN need in range. This has been validated in |
| 11453 | // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method |
| 11454 | // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds |
| 11455 | final int[] thresholds = info.getThresholds(); |
| 11456 | Objects.requireNonNull(thresholds); |
| 11457 | if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed() |
| 11458 | || thresholds.length |
| 11459 | > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) { |
| 11460 | throw new IllegalArgumentException( |
| 11461 | "thresholds length is out of range: " + thresholds.length); |
| 11462 | } |
| 11463 | } |
| 11464 | } |
SongFerngWang | 8236caa | 2021-01-17 21:51:44 +0800 | [diff] [blame] | 11465 | |
| 11466 | /** |
| 11467 | * Gets the current phone capability. |
| 11468 | * |
| 11469 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 11470 | * @return the PhoneCapability which describes the data connection capability of modem. |
| 11471 | * It's used to evaluate possible phone config change, for example from single |
| 11472 | * SIM device to multi-SIM device. |
| 11473 | */ |
| 11474 | @Override |
| 11475 | public PhoneCapability getPhoneCapability() { |
| 11476 | enforceReadPrivilegedPermission("getPhoneCapability"); |
| 11477 | final long identity = Binder.clearCallingIdentity(); |
| 11478 | try { |
| 11479 | return mPhoneConfigurationManager.getCurrentPhoneCapability(); |
| 11480 | } finally { |
| 11481 | Binder.restoreCallingIdentity(identity); |
| 11482 | } |
| 11483 | } |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 11484 | |
| 11485 | /** |
| 11486 | * Prepare TelephonyManager for an unattended reboot. The reboot is |
| 11487 | * required to be done shortly after the API is invoked. |
| 11488 | */ |
| 11489 | @Override |
| 11490 | @TelephonyManager.PrepareUnattendedRebootResult |
| 11491 | public int prepareForUnattendedReboot() { |
Rafael Higuera Silva | d963064 | 2021-09-20 15:32:01 +0000 | [diff] [blame] | 11492 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 11493 | enforceRebootPermission(); |
| 11494 | |
| 11495 | final long identity = Binder.clearCallingIdentity(); |
| 11496 | try { |
Rafael Higuera Silva | d963064 | 2021-09-20 15:32:01 +0000 | [diff] [blame] | 11497 | return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 11498 | } finally { |
| 11499 | Binder.restoreCallingIdentity(identity); |
| 11500 | } |
| 11501 | } |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 11502 | |
| 11503 | /** |
| 11504 | * Request to get the current slicing configuration including URSP rules and |
| 11505 | * NSSAIs (configured, allowed and rejected). |
| 11506 | * |
| 11507 | * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission. |
| 11508 | */ |
| 11509 | @Override |
| 11510 | public void getSlicingConfig(ResultReceiver callback) { |
Hongbo Zeng | 1b2063d | 2022-02-21 01:33:03 +0000 | [diff] [blame] | 11511 | TelephonyPermissions |
| 11512 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 11513 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, "getSlicingConfig"); |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 11514 | |
| 11515 | final long identity = Binder.clearCallingIdentity(); |
| 11516 | try { |
| 11517 | Phone phone = getDefaultPhone(); |
| 11518 | sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null); |
| 11519 | } finally { |
| 11520 | Binder.restoreCallingIdentity(identity); |
| 11521 | } |
| 11522 | } |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 11523 | |
| 11524 | /** |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 11525 | * Check whether the given premium capability is available for purchase from the carrier. |
| 11526 | * |
| 11527 | * @param capability The premium capability to check. |
| 11528 | * @param subId The subId to check the premium capability for. |
| 11529 | * |
| 11530 | * @return Whether the given premium capability is available to purchase. |
| 11531 | */ |
| 11532 | @Override |
| 11533 | public boolean isPremiumCapabilityAvailableForPurchase(int capability, int subId) { |
| 11534 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 11535 | mApp, "isPremiumCapabilityAvailableForPurchase")) { |
| 11536 | log("Premium capability " |
| 11537 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 11538 | + " is not available for purchase due to missing permissions."); |
| 11539 | throw new SecurityException("isPremiumCapabilityAvailableForPurchase requires " |
| 11540 | + "permission READ_BASIC_PHONE_STATE."); |
| 11541 | } |
| 11542 | |
| 11543 | Phone phone = getPhone(subId); |
Thomas Nguyen | 7216ed6 | 2022-11-29 16:45:31 -0800 | [diff] [blame] | 11544 | if (phone == null) { |
| 11545 | loge("isPremiumCapabilityAvailableForPurchase: phone is null, subId=" + subId); |
| 11546 | return false; |
| 11547 | } |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 11548 | final long identity = Binder.clearCallingIdentity(); |
| 11549 | try { |
Sarah Chin | 46355ba | 2022-11-01 23:51:16 -0700 | [diff] [blame] | 11550 | return SlicePurchaseController.getInstance(phone) |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 11551 | .isPremiumCapabilityAvailableForPurchase(capability); |
| 11552 | } finally { |
| 11553 | Binder.restoreCallingIdentity(identity); |
| 11554 | } |
| 11555 | } |
| 11556 | |
| 11557 | /** |
| 11558 | * Purchase the given premium capability from the carrier. |
| 11559 | * |
| 11560 | * @param capability The premium capability to purchase. |
| 11561 | * @param callback The result of the purchase request. |
| 11562 | * @param subId The subId to purchase the premium capability for. |
| 11563 | */ |
| 11564 | @Override |
| 11565 | public void purchasePremiumCapability(int capability, IIntegerConsumer callback, int subId) { |
| 11566 | log("purchasePremiumCapability: capability=" |
| 11567 | + TelephonyManager.convertPremiumCapabilityToString(capability) + ", caller=" |
| 11568 | + getCurrentPackageName()); |
| 11569 | |
| 11570 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 11571 | mApp, "purchasePremiumCapability")) { |
| 11572 | log("purchasePremiumCapability " |
| 11573 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 11574 | + " failed due to missing permissions."); |
| 11575 | throw new SecurityException("purchasePremiumCapability requires permission " |
| 11576 | + "READ_BASIC_PHONE_STATE."); |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 11577 | } else if (!TelephonyPermissions.checkInternetPermissionNoThrow( |
| 11578 | mApp, "purchasePremiumCapability")) { |
| 11579 | log("purchasePremiumCapability " |
| 11580 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 11581 | + " failed due to missing permissions."); |
| 11582 | throw new SecurityException("purchasePremiumCapability requires permission INTERNET."); |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 11583 | } |
| 11584 | |
| 11585 | Phone phone = getPhone(subId); |
Sarah Chin | 1969411 | 2022-12-06 15:41:37 -0800 | [diff] [blame] | 11586 | if (phone == null) { |
| 11587 | try { |
| 11588 | int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_REQUEST_FAILED; |
| 11589 | callback.accept(result); |
| 11590 | loge("purchasePremiumCapability: phone is null, subId=" + subId); |
| 11591 | } catch (RemoteException e) { |
| 11592 | String logStr = "Purchase premium capability " |
| 11593 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 11594 | + " failed due to RemoteException handling null phone: " + e; |
| 11595 | if (DBG) log(logStr); |
| 11596 | AnomalyReporter.reportAnomaly( |
| 11597 | UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr); |
| 11598 | } |
| 11599 | return; |
| 11600 | } |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 11601 | |
| 11602 | String callingProcess; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 11603 | try { |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 11604 | callingProcess = mApp.getPackageManager().getApplicationInfo( |
| 11605 | getCurrentPackageName(), 0).processName; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 11606 | } catch (PackageManager.NameNotFoundException e) { |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 11607 | callingProcess = getCurrentPackageName(); |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 11608 | } |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 11609 | |
| 11610 | boolean isVisible = false; |
| 11611 | ActivityManager am = mApp.getSystemService(ActivityManager.class); |
| 11612 | if (am != null) { |
| 11613 | List<ActivityManager.RunningAppProcessInfo> processes = am.getRunningAppProcesses(); |
| 11614 | if (processes != null) { |
| 11615 | for (ActivityManager.RunningAppProcessInfo process : processes) { |
| 11616 | log("purchasePremiumCapability: process " + process.processName |
| 11617 | + "has importance " + process.importance); |
| 11618 | if (process.processName.equals(callingProcess) && process.importance |
| 11619 | <= ActivityManager.RunningAppProcessInfo.IMPORTANCE_VISIBLE) { |
| 11620 | isVisible = true; |
| 11621 | break; |
| 11622 | } |
| 11623 | } |
| 11624 | } |
| 11625 | } |
| 11626 | |
| 11627 | if (!isVisible) { |
| 11628 | try { |
| 11629 | int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_NOT_FOREGROUND; |
| 11630 | callback.accept(result); |
| 11631 | loge("purchasePremiumCapability: " + callingProcess + " is not in the foreground."); |
| 11632 | } catch (RemoteException e) { |
| 11633 | String logStr = "Purchase premium capability " |
| 11634 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 11635 | + " failed due to RemoteException handling background application: " + e; |
| 11636 | if (DBG) log(logStr); |
| 11637 | AnomalyReporter.reportAnomaly( |
| 11638 | UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr); |
| 11639 | } |
| 11640 | return; |
| 11641 | } |
| 11642 | |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 11643 | sendRequestAsync(CMD_PURCHASE_PREMIUM_CAPABILITY, |
Sarah Chin | b8218c2 | 2023-01-04 13:35:29 -0800 | [diff] [blame] | 11644 | new PurchasePremiumCapabilityArgument(capability, callback), phone, null); |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 11645 | } |
| 11646 | |
| 11647 | /** |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 11648 | * Register an IMS connection state callback |
| 11649 | */ |
| 11650 | @Override |
Hunsuk Choi | 89bd22c | 2021-11-01 13:04:54 +0000 | [diff] [blame] | 11651 | public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb, |
| 11652 | String callingPackage) { |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 11653 | if (feature == ImsFeature.FEATURE_MMTEL) { |
| 11654 | // ImsMmTelManager |
| 11655 | // The following also checks READ_PRIVILEGED_PHONE_STATE. |
| 11656 | TelephonyPermissions |
| 11657 | .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 11658 | mApp, subId, "registerImsStateCallback"); |
| 11659 | } else if (feature == ImsFeature.FEATURE_RCS) { |
| 11660 | // ImsRcsManager or SipDelegateManager |
| 11661 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 11662 | Binder.getCallingUid(), "registerImsStateCallback", |
| 11663 | Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
| 11664 | Manifest.permission.READ_PRECISE_PHONE_STATE, |
| 11665 | Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE, |
| 11666 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
| 11667 | } |
| 11668 | |
| 11669 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 11670 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 11671 | "IMS not available on device."); |
| 11672 | } |
| 11673 | |
| 11674 | if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) { |
| 11675 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 11676 | } |
| 11677 | |
| 11678 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 11679 | if (controller == null) { |
| 11680 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 11681 | "IMS not available on device."); |
| 11682 | } |
| 11683 | |
Hunsuk Choi | 89bd22c | 2021-11-01 13:04:54 +0000 | [diff] [blame] | 11684 | if (callingPackage == null) { |
| 11685 | callingPackage = getCurrentPackageName(); |
| 11686 | } |
| 11687 | |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 11688 | final long token = Binder.clearCallingIdentity(); |
| 11689 | try { |
| 11690 | int slotId = getSlotIndexOrException(subId); |
Hunsuk Choi | 89bd22c | 2021-11-01 13:04:54 +0000 | [diff] [blame] | 11691 | controller.registerImsStateCallback(subId, feature, cb, callingPackage); |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 11692 | } catch (ImsException e) { |
| 11693 | throw new ServiceSpecificException(e.getCode()); |
| 11694 | } finally { |
| 11695 | Binder.restoreCallingIdentity(token); |
| 11696 | } |
| 11697 | } |
| 11698 | |
| 11699 | /** |
| 11700 | * Unregister an IMS connection state callback |
| 11701 | */ |
| 11702 | @Override |
| 11703 | public void unregisterImsStateCallback(IImsStateCallback cb) { |
| 11704 | final long token = Binder.clearCallingIdentity(); |
| 11705 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 11706 | if (controller == null) { |
| 11707 | return; |
| 11708 | } |
| 11709 | try { |
| 11710 | controller.unregisterImsStateCallback(cb); |
| 11711 | } finally { |
| 11712 | Binder.restoreCallingIdentity(token); |
| 11713 | } |
| 11714 | } |
Sooraj Sasindran | fae41b3 | 2021-10-26 02:10:05 -0700 | [diff] [blame] | 11715 | |
| 11716 | /** |
| 11717 | * @return {@CellIdentity} last known cell identity {@CellIdentity}. |
| 11718 | * |
| 11719 | * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and |
| 11720 | * com.android.phone.permission.ACCESS_LAST_KNOWN_CELL_ID, otherwise throws |
| 11721 | * SecurityException. |
| 11722 | * If there is current registered network this value will be same as the registered cell |
| 11723 | * identity. If the device goes out of service the previous cell identity is cached and |
| 11724 | * will be returned. If the cache age of the Cell identity is more than 24 hours |
| 11725 | * it will be cleared and null will be returned. |
| 11726 | * |
| 11727 | */ |
| 11728 | @Override |
| 11729 | public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage, |
| 11730 | String callingFeatureId) { |
| 11731 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 11732 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 11733 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 11734 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 11735 | .setCallingPackage(callingPackage) |
| 11736 | .setCallingFeatureId(callingFeatureId) |
| 11737 | .setCallingPid(Binder.getCallingPid()) |
| 11738 | .setCallingUid(Binder.getCallingUid()) |
| 11739 | .setMethod("getLastKnownCellIdentity") |
| 11740 | .setLogAsInfo(true) |
| 11741 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 11742 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 11743 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 11744 | .build()); |
| 11745 | |
| 11746 | boolean hasFinePermission = |
| 11747 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 11748 | if (!hasFinePermission |
| 11749 | || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) { |
| 11750 | throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION " |
Rambo Wang | 918993a | 2022-04-27 09:08:36 -0700 | [diff] [blame] | 11751 | + "and ACCESS_LAST_KNOWN_CELL_ID permission."); |
Sooraj Sasindran | fae41b3 | 2021-10-26 02:10:05 -0700 | [diff] [blame] | 11752 | } |
| 11753 | |
| 11754 | final long identity = Binder.clearCallingIdentity(); |
| 11755 | try { |
| 11756 | Phone phone = getPhone(subId); |
| 11757 | if (phone == null) return null; |
| 11758 | ServiceStateTracker sst = phone.getServiceStateTracker(); |
| 11759 | if (sst == null) return null; |
| 11760 | return sst.getLastKnownCellIdentity(); |
| 11761 | } finally { |
| 11762 | Binder.restoreCallingIdentity(identity); |
| 11763 | } |
| 11764 | } |
Jack Yu | 4c0a550 | 2021-12-03 23:58:26 -0800 | [diff] [blame] | 11765 | |
jimsun | 3b9ccac | 2021-10-26 15:01:23 +0800 | [diff] [blame] | 11766 | /** |
| 11767 | * Sets the modem service class Name that Telephony will bind to. |
| 11768 | * |
| 11769 | * @param serviceName The class name of the modem service. |
| 11770 | * @return true if the operation is succeed, otherwise false. |
| 11771 | */ |
| 11772 | public boolean setModemService(String serviceName) { |
| 11773 | Log.d(LOG_TAG, "setModemService - " + serviceName); |
| 11774 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService"); |
| 11775 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 11776 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 11777 | "setModemService"); |
| 11778 | return mPhoneConfigurationManager.setModemService(serviceName); |
| 11779 | } |
| 11780 | |
| 11781 | /** |
| 11782 | * Return the class name of the currently bounded modem service. |
| 11783 | * |
| 11784 | * @return the class name of the modem service. |
| 11785 | */ |
| 11786 | public String getModemService() { |
| 11787 | String result; |
| 11788 | Log.d(LOG_TAG, "getModemService"); |
| 11789 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService"); |
| 11790 | TelephonyPermissions |
| 11791 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 11792 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 11793 | "getModemService"); |
| 11794 | result = mPhoneConfigurationManager.getModemService(); |
| 11795 | Log.d(LOG_TAG, "result = " + result); |
| 11796 | return result; |
| 11797 | } |
Hunter Knepshield | 2b076fa | 2022-01-19 02:26:22 -0800 | [diff] [blame] | 11798 | |
| 11799 | @Override |
| 11800 | public void setVoiceServiceStateOverride(int subId, boolean hasService, String callingPackage) { |
| 11801 | // Only telecom (and shell, for CTS purposes) is allowed to call this method. |
| 11802 | mApp.enforceCallingOrSelfPermission( |
| 11803 | permission.BIND_TELECOM_CONNECTION_SERVICE, "setVoiceServiceStateOverride"); |
| 11804 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 11805 | |
| 11806 | final long identity = Binder.clearCallingIdentity(); |
| 11807 | try { |
| 11808 | Phone phone = getPhone(subId); |
| 11809 | if (phone == null) return; |
| 11810 | phone.setVoiceServiceStateOverride(hasService); |
| 11811 | } finally { |
| 11812 | Binder.restoreCallingIdentity(identity); |
| 11813 | } |
| 11814 | } |
Muralidhar Reddy | 4e5a801 | 2022-05-11 14:49:00 +0000 | [diff] [blame] | 11815 | |
| 11816 | /** |
| 11817 | * set removable eSIM as default eUICC. |
| 11818 | * |
| 11819 | * @hide |
| 11820 | */ |
| 11821 | @Override |
| 11822 | public void setRemovableEsimAsDefaultEuicc(boolean isDefault, String callingPackage) { |
| 11823 | enforceModifyPermission(); |
| 11824 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 11825 | |
| 11826 | final long identity = Binder.clearCallingIdentity(); |
| 11827 | try { |
| 11828 | UiccController.getInstance().setRemovableEsimAsDefaultEuicc(isDefault); |
| 11829 | } finally { |
| 11830 | Binder.restoreCallingIdentity(identity); |
| 11831 | } |
| 11832 | } |
| 11833 | |
| 11834 | /** |
| 11835 | * Returns whether the removable eSIM is default eUICC or not. |
| 11836 | * |
| 11837 | * @hide |
| 11838 | */ |
| 11839 | @Override |
| 11840 | public boolean isRemovableEsimDefaultEuicc(String callingPackage) { |
| 11841 | enforceReadPrivilegedPermission("isRemovableEsimDefaultEuicc"); |
| 11842 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 11843 | |
| 11844 | final long identity = Binder.clearCallingIdentity(); |
| 11845 | try { |
| 11846 | return UiccController.getInstance().isRemovableEsimDefaultEuicc(); |
| 11847 | } finally { |
| 11848 | Binder.restoreCallingIdentity(identity); |
| 11849 | } |
| 11850 | } |
| 11851 | |
Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame] | 11852 | /** |
| 11853 | * Get the component name of the default app to direct respond-via-message intent for the |
| 11854 | * user associated with this subscription, update the cache if there is no respond-via-message |
| 11855 | * application currently configured for this user. |
| 11856 | * @return component name of the app and class to direct Respond Via Message intent to, or |
| 11857 | * {@code null} if the functionality is not supported. |
| 11858 | * @hide |
| 11859 | */ |
| 11860 | @Override |
| 11861 | public @Nullable ComponentName getDefaultRespondViaMessageApplication(int subId, |
| 11862 | boolean updateIfNeeded) { |
| 11863 | enforceInteractAcrossUsersPermission("getDefaultRespondViaMessageApplication"); |
Muralidhar Reddy | 4e5a801 | 2022-05-11 14:49:00 +0000 | [diff] [blame] | 11864 | |
Aishwarya Mallampati | 5e581e1 | 2023-01-17 21:57:06 +0000 | [diff] [blame] | 11865 | Context context = getPhoneFromSubIdOrDefault(subId).getContext(); |
| 11866 | |
Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame] | 11867 | UserHandle userHandle = null; |
| 11868 | final long identity = Binder.clearCallingIdentity(); |
| 11869 | try { |
| 11870 | userHandle = TelephonyUtils.getSubscriptionUserHandle(context, subId); |
| 11871 | } finally { |
| 11872 | Binder.restoreCallingIdentity(identity); |
| 11873 | } |
| 11874 | return SmsApplication.getDefaultRespondViaMessageApplicationAsUser(context, |
| 11875 | updateIfNeeded, userHandle); |
| 11876 | } |
Jack Yu | f5badd9 | 2022-12-08 00:50:53 -0800 | [diff] [blame] | 11877 | |
| 11878 | /** |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 11879 | * Set whether the device is able to connect with null ciphering or integrity |
| 11880 | * algorithms. This is a global setting and will apply to all active subscriptions |
| 11881 | * and all new subscriptions after this. |
| 11882 | * |
| 11883 | * @param enabled when true, null cipher and integrity algorithms are allowed. |
| 11884 | * @hide |
| 11885 | */ |
| 11886 | @Override |
| 11887 | @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 11888 | public void setNullCipherAndIntegrityEnabled(boolean enabled) { |
| 11889 | enforceModifyPermission(); |
| 11890 | checkForNullCipherAndIntegritySupport(); |
| 11891 | |
| 11892 | // Persist the state of our preference. Each GsmCdmaPhone instance is responsible |
| 11893 | // for listening to these preference changes and applying them immediately. |
| 11894 | SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 11895 | editor.putBoolean(Phone.PREF_NULL_CIPHER_AND_INTEGRITY_ENABLED, enabled); |
| 11896 | editor.apply(); |
| 11897 | |
| 11898 | for (Phone phone: PhoneFactory.getPhones()) { |
| 11899 | phone.handleNullCipherEnabledChange(); |
| 11900 | } |
| 11901 | } |
| 11902 | |
| 11903 | |
| 11904 | /** |
| 11905 | * Get whether the device is able to connect with null ciphering or integrity |
| 11906 | * algorithms. Note that this retrieves the phone-global preference and not |
| 11907 | * the state of the radio. |
| 11908 | * |
| 11909 | * @throws SecurityException if {@link permission#MODIFY_PHONE_STATE} is not satisfied |
| 11910 | * @throws UnsupportedOperationException if the device does not support the minimum HAL |
| 11911 | * version for this feature. |
| 11912 | * @hide |
| 11913 | */ |
| 11914 | @Override |
| 11915 | @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) |
| 11916 | public boolean isNullCipherAndIntegrityPreferenceEnabled() { |
| 11917 | enforceReadPermission(); |
| 11918 | checkForNullCipherAndIntegritySupport(); |
| 11919 | return getDefaultPhone().getNullCipherAndIntegrityEnabledPreference(); |
| 11920 | } |
| 11921 | |
| 11922 | private void checkForNullCipherAndIntegritySupport() { |
| 11923 | if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_NULL_CIPHER_AND_INTEGRITY_VERSION) { |
| 11924 | throw new UnsupportedOperationException( |
| 11925 | "Null cipher and integrity operations require HAL 2.1 or above"); |
| 11926 | } |
Gil Cukierman | 92cc7db | 2023-01-06 19:25:53 +0000 | [diff] [blame] | 11927 | if (!getDefaultPhone().isNullCipherAndIntegritySupported()) { |
| 11928 | throw new UnsupportedOperationException( |
| 11929 | "Null cipher and integrity operations unsupported by modem"); |
| 11930 | } |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 11931 | } |
| 11932 | |
| 11933 | /** |
Jack Yu | f5badd9 | 2022-12-08 00:50:53 -0800 | [diff] [blame] | 11934 | * Get the SIM state for the slot index. |
| 11935 | * For Remote-SIMs, this method returns {@link IccCardConstants.State#UNKNOWN} |
| 11936 | * |
| 11937 | * @return SIM state as the ordinal of {@link IccCardConstants.State} |
| 11938 | */ |
| 11939 | @Override |
| 11940 | @SimState |
| 11941 | public int getSimStateForSlotIndex(int slotIndex) { |
| 11942 | IccCardConstants.State simState; |
| 11943 | if (slotIndex < 0) { |
| 11944 | simState = IccCardConstants.State.UNKNOWN; |
| 11945 | } else { |
| 11946 | Phone phone = null; |
| 11947 | try { |
| 11948 | phone = PhoneFactory.getPhone(slotIndex); |
| 11949 | } catch (IllegalStateException e) { |
| 11950 | // ignore |
| 11951 | } |
| 11952 | if (phone == null) { |
| 11953 | simState = IccCardConstants.State.UNKNOWN; |
| 11954 | } else { |
| 11955 | IccCard icc = phone.getIccCard(); |
| 11956 | if (icc == null) { |
| 11957 | simState = IccCardConstants.State.UNKNOWN; |
| 11958 | } else { |
| 11959 | simState = icc.getState(); |
| 11960 | } |
| 11961 | } |
| 11962 | } |
| 11963 | return simState.ordinal(); |
| 11964 | } |
Hui Wang | 9b5793a | 2022-12-05 14:38:06 -0600 | [diff] [blame] | 11965 | |
| 11966 | /** |
| 11967 | * Get current cell broadcast ranges. |
| 11968 | */ |
| 11969 | @Override |
| 11970 | @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS) |
| 11971 | public List<CellBroadcastIdRange> getCellBroadcastIdRanges(int subId) { |
| 11972 | mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS, |
| 11973 | "getCellBroadcastIdRanges"); |
| 11974 | final long identity = Binder.clearCallingIdentity(); |
| 11975 | try { |
| 11976 | return getPhone(subId).getCellBroadcastIdRanges(); |
| 11977 | } finally { |
| 11978 | Binder.restoreCallingIdentity(identity); |
| 11979 | } |
| 11980 | } |
| 11981 | |
| 11982 | /** |
| 11983 | * Set reception of cell broadcast messages with the list of the given ranges |
| 11984 | * |
| 11985 | * @param ranges the list of {@link CellBroadcastIdRange} to be enabled |
| 11986 | */ |
| 11987 | @Override |
| 11988 | @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS) |
| 11989 | public void setCellBroadcastIdRanges(int subId, @NonNull List<CellBroadcastIdRange> ranges, |
| 11990 | @Nullable IIntegerConsumer callback) { |
| 11991 | mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS, |
| 11992 | "setCellBroadcastIdRanges"); |
| 11993 | final long identity = Binder.clearCallingIdentity(); |
| 11994 | try { |
| 11995 | Phone phone = getPhoneFromSubId(subId); |
| 11996 | if (DBG) { |
| 11997 | log("setCellBroadcastIdRanges for subId :" + subId + ", phone:" + phone); |
| 11998 | } |
| 11999 | phone.setCellBroadcastIdRanges(ranges, result -> { |
| 12000 | if (callback != null) { |
| 12001 | try { |
| 12002 | callback.accept(result); |
| 12003 | } catch (RemoteException e) { |
| 12004 | Log.w(LOG_TAG, "setCellBroadcastIdRanges: callback not available."); |
| 12005 | } |
| 12006 | } |
| 12007 | }); |
| 12008 | } finally { |
| 12009 | Binder.restoreCallingIdentity(identity); |
| 12010 | } |
| 12011 | } |
Hunsuk Choi | 42cc62a | 2022-10-16 06:03:40 +0000 | [diff] [blame] | 12012 | |
| 12013 | /** |
| 12014 | * Returns whether the device supports the domain selection service. |
| 12015 | * |
| 12016 | * @return {@code true} if the device supports the domain selection service. |
| 12017 | */ |
| 12018 | @Override |
| 12019 | public boolean isDomainSelectionSupported() { |
| 12020 | mApp.enforceCallingOrSelfPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
| 12021 | "isDomainSelectionSupported"); |
| 12022 | |
| 12023 | final long identity = Binder.clearCallingIdentity(); |
| 12024 | try { |
| 12025 | return DomainSelectionResolver.getInstance().isDomainSelectionSupported(); |
| 12026 | } finally { |
| 12027 | Binder.restoreCallingIdentity(identity); |
| 12028 | } |
| 12029 | } |
arunvoddu | d5c6ce0 | 2022-12-11 06:03:12 +0000 | [diff] [blame] | 12030 | |
| 12031 | /** |
| 12032 | * Check whether the caller (or self, if not processing an IPC) can read device identifiers. |
| 12033 | * |
| 12034 | * <p>This method behaves in one of the following ways: |
| 12035 | * <ul> |
| 12036 | * <li>return true : if the calling package has the appop permission {@link |
| 12037 | * Manifest.permission#USE_ICC_AUTH_WITH_DEVICE_IDENTIFIER} in the manifest </> |
| 12038 | * <li>return true : if any one subscription has the READ_PRIVILEGED_PHONE_STATE |
| 12039 | * permission, the calling package passes a DevicePolicyManager Device Owner / Profile |
| 12040 | * Owner device identifier access check, or the calling package has carrier privileges</> |
| 12041 | * <li>throw SecurityException: if the caller does not meet any of the requirements. |
| 12042 | * </ul> |
| 12043 | */ |
| 12044 | private static boolean checkCallingOrSelfReadDeviceIdentifiersForAnySub(Context context, |
| 12045 | String callingPackage, @Nullable String callingFeatureId, String message) { |
| 12046 | for (Phone phone : PhoneFactory.getPhones()) { |
| 12047 | if (TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(context, |
| 12048 | phone.getSubId(), callingPackage, callingFeatureId, message)) { |
| 12049 | return true; |
| 12050 | } |
| 12051 | } |
| 12052 | return false; |
| 12053 | } |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 12054 | |
| 12055 | /** |
| 12056 | * Class binds the consumer[callback] and carrierId. |
| 12057 | */ |
| 12058 | private static class CallerCallbackInfo { |
| 12059 | private final Consumer<Integer> mConsumer; |
| 12060 | private final int mCarrierId; |
| 12061 | |
| 12062 | public CallerCallbackInfo(Consumer<Integer> consumer, int carrierId) { |
| 12063 | mConsumer = consumer; |
| 12064 | mCarrierId = carrierId; |
| 12065 | } |
| 12066 | |
| 12067 | public Consumer<Integer> getConsumer() { |
| 12068 | return mConsumer; |
| 12069 | } |
| 12070 | |
| 12071 | public int getCarrierId() { |
| 12072 | return mCarrierId; |
| 12073 | } |
| 12074 | } |
arunvoddu | d5c6ce0 | 2022-12-11 06:03:12 +0000 | [diff] [blame] | 12075 | } |